Debian Codegraph @

clutter/deprecated/clutter-media.c

raw
1 /*
2 * Clutter.
3 *
4 * An OpenGL based 'interactive canvas' library.
5 *
6 * Authored By: Matthew Allum <[email protected]>
7 * Emmanuele Bassi <[email protected]>
8 *
9 * Copyright (C) 2006 OpenedHand
10 * Copyright (C) 2009 Intel Corp.
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26 /**
27 * SECTION:clutter-media
28 * @short_description: An interface for controlling playback of media data
29 *
30 * #ClutterMedia is an interface for controlling playback of media sources.
31 *
32 * Clutter core does not provide an implementation of this interface, but
33 * other integration libraries like Clutter-GStreamer implement it to offer
34 * a uniform API for applications.
35 *
36 * #ClutterMedia is available since Clutter 0.2
37 *
38 * #ClutterMedia is deprecated since Clutter 1.12. Use the Clutter-GStreamer
39 * API directly instead.
40 */
41
42 #ifdef HAVE_CONFIG_H
43 #include "config.h"
44 #endif
45
46 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
47
48 #include "clutter-debug.h"
49 #include "clutter-enum-types.h"
50 #include "clutter-marshal.h"
51 #include "clutter-media.h"
52 #include "clutter-main.h"
53 #include "clutter-private.h" /* for DBG */
54
55 enum
56 {
57 EOS_SIGNAL,
58 ERROR_SIGNAL, /* can't be called 'ERROR' otherwise it clashes with wingdi.h */
59
60 LAST_SIGNAL
61 };
62
63 static guint media_signals[LAST_SIGNAL] = { 0, };
64
65 typedef ClutterMediaIface ClutterMediaInterface;
66
67 G_DEFINE_INTERFACE (ClutterMedia, clutter_media, G_TYPE_OBJECT);
68
69 static void
70 clutter_media_default_init (ClutterMediaInterface *iface)
71 {
72 GParamSpec *pspec = NULL;
73
74 /**
75 * ClutterMedia:uri:
76 *
77 * The location of a media file, expressed as a valid URI.
78 *
79 * Since: 0.2
80 *
81 * Deprecated: 1.12
82 */
83 pspec = g_param_spec_string ("uri",
84 P_("URI"),
85 P_("URI of a media file"),
86 NULL,
87 CLUTTER_PARAM_READWRITE |
88 G_PARAM_DEPRECATED);
89 g_object_interface_install_property (iface, pspec);
90
91 /**
92 * ClutterMedia:playing:
93 *
94 * Whether the #ClutterMedia actor is playing.
95 *
96 * Since: 0.2
97 *
98 * Deprecated: 1.12
99 */
100 pspec = g_param_spec_boolean ("playing",
101 P_("Playing"),
102 P_("Whether the actor is playing"),
103 FALSE,
104 CLUTTER_PARAM_READWRITE |
105 G_PARAM_DEPRECATED);
106 g_object_interface_install_property (iface, pspec);
107
108 /**
109 * ClutterMedia:progress:
110 *
111 * The current progress of the playback, as a normalized
112 * value between 0.0 and 1.0.
113 *
114 * Since: 1.0
115 *
116 * Deprecated: 1.12
117 */
118 pspec = g_param_spec_double ("progress",
119 P_("Progress"),
120 P_("Current progress of the playback"),
121 0.0, 1.0, 0.0,
122 CLUTTER_PARAM_READWRITE |
123 G_PARAM_DEPRECATED);
124 g_object_interface_install_property (iface, pspec);
125
126 /**
127 * ClutterMedia:subtitle-uri:
128 *
129 * The location of a subtitle file, expressed as a valid URI.
130 *
131 * Since: 1.2
132 *
133 * Deprecated: 1.12
134 */
135 pspec = g_param_spec_string ("subtitle-uri",
136 P_("Subtitle URI"),
137 P_("URI of a subtitle file"),
138 NULL,
139 CLUTTER_PARAM_READWRITE |
140 G_PARAM_DEPRECATED);
141 g_object_interface_install_property (iface, pspec);
142
143 /**
144 * ClutterMedia:subtitle-font-name:
145 *
146 * The font used to display subtitles. The font description has to
147 * follow the same grammar as the one recognized by
148 * pango_font_description_from_string().
149 *
150 * Since: 1.2
151 *
152 * Deprecated: 1.12
153 */
154 pspec = g_param_spec_string ("subtitle-font-name",
155 P_("Subtitle Font Name"),
156 P_("The font used to display subtitles"),
157 NULL,
158 CLUTTER_PARAM_READWRITE |
159 G_PARAM_DEPRECATED);
160 g_object_interface_install_property (iface, pspec);
161
162 /**
163 * ClutterMedia:audio-volume:
164 *
165 * The volume of the audio, as a normalized value between
166 * 0.0 and 1.0.
167 *
168 * Since: 1.0
169 *
170 * Deprecated: 1.12
171 */
172 pspec = g_param_spec_double ("audio-volume",
173 P_("Audio Volume"),
174 P_("The volume of the audio"),
175 0.0, 1.0, 0.5,
176 CLUTTER_PARAM_READWRITE |
177 G_PARAM_DEPRECATED);
178 g_object_interface_install_property (iface, pspec);
179
180 /**
181 * ClutterMedia:can-seek:
182 *
183 * Whether the current stream is seekable.
184 *
185 * Since: 0.2
186 *
187 * Deprecated: 1.12
188 */
189 pspec = g_param_spec_boolean ("can-seek",
190 P_("Can Seek"),
191 P_("Whether the current stream is seekable"),
192 FALSE,
193 CLUTTER_PARAM_READABLE |
194 G_PARAM_DEPRECATED);
195 g_object_interface_install_property (iface, pspec);
196
197 /**
198 * ClutterMedia:buffer-fill:
199 *
200 * The fill level of the buffer for the current stream,
201 * as a value between 0.0 and 1.0.
202 *
203 * Since: 1.0
204 *
205 * Deprecated: 1.12
206 */
207 pspec = g_param_spec_double ("buffer-fill",
208 P_("Buffer Fill"),
209 P_("The fill level of the buffer"),
210 0.0, 1.0, 0.0,
211 CLUTTER_PARAM_READABLE |
212 G_PARAM_DEPRECATED);
213 g_object_interface_install_property (iface, pspec);
214
215 /**
216 * ClutterMedia:duration:
217 *
218 * The duration of the current stream, in seconds
219 *
220 * Since: 0.2
221 *
222 * Deprecated: 1.12
223 */
224 pspec = g_param_spec_double ("duration",
225 P_("Duration"),
226 P_("The duration of the stream, in seconds"),
227 0, G_MAXDOUBLE, 0,
228 CLUTTER_PARAM_READABLE);
229 g_object_interface_install_property (iface, pspec);
230
231 /**
232 * ClutterMedia::eos:
233 * @media: the #ClutterMedia instance that received the signal
234 *
235 * The ::eos signal is emitted each time the media stream ends.
236 *
237 * Since: 0.2
238 *
239 * Deprecated: 1.12
240 */
241 media_signals[EOS_SIGNAL] =
242 g_signal_new (I_("eos"),
243 CLUTTER_TYPE_MEDIA,
244 G_SIGNAL_RUN_LAST,
245 G_STRUCT_OFFSET (ClutterMediaIface, eos),
246 NULL, NULL,
247 _clutter_marshal_VOID__VOID,
248 G_TYPE_NONE, 0);
249 /**
250 * ClutterMedia::error:
251 * @media: the #ClutterMedia instance that received the signal
252 * @error: the #GError
253 *
254 * The ::error signal is emitted each time an error occurred.
255 *
256 * Since: 0.2
257 *
258 * Deprecated: 1.12
259 */
260 media_signals[ERROR_SIGNAL] =
261 g_signal_new (I_("error"),
262 CLUTTER_TYPE_MEDIA,
263 G_SIGNAL_RUN_LAST,
264 G_STRUCT_OFFSET (ClutterMediaIface, error),
265 NULL, NULL,
266 _clutter_marshal_VOID__BOXED,
267 G_TYPE_NONE, 1,
268 G_TYPE_ERROR);
269 }
270
271
272 /**
273 * clutter_media_set_uri:
274 * @media: a #ClutterMedia
275 * @uri: the URI of the media stream
276 *
277 * Sets the URI of @media to @uri.
278 *
279 * Since: 0.2
280 *
281 * Deprecated: 1.12
282 */
283 void
284 clutter_media_set_uri (ClutterMedia *media,
285 const gchar *uri)
286 {
287 g_return_if_fail (CLUTTER_IS_MEDIA(media));
288
289 g_object_set (G_OBJECT (media), "uri", uri, NULL);
290 }
291
292 /**
293 * clutter_media_get_uri:
294 * @media: a #ClutterMedia
295 *
296 * Retrieves the URI from @media.
297 *
298 * Return value: the URI of the media stream. Use g_free()
299 * to free the returned string
300 *
301 * Since: 0.2
302 *
303 * Deprecated: 1.12
304 */
305 gchar *
306 clutter_media_get_uri (ClutterMedia *media)
307 {
308 gchar *retval = NULL;
309
310 g_return_val_if_fail (CLUTTER_IS_MEDIA(media), NULL);
311
312 g_object_get (G_OBJECT (media), "uri", &retval, NULL);
313
314 return retval;
315 }
316
317 /**
318 * clutter_media_set_playing:
319 * @media: a #ClutterMedia
320 * @playing: %TRUE to start playing
321 *
322 * Starts or stops playing of @media.
323
324 * The implementation might be asynchronous, so the way to know whether
325 * the actual playing state of the @media is to use the #GObject::notify
326 * signal on the #ClutterMedia:playing property and then retrieve the
327 * current state with clutter_media_get_playing(). ClutterGstVideoTexture
328 * in clutter-gst is an example of such an asynchronous implementation.
329 *
330 * Since: 0.2
331 *
332 * Deprecated: 1.12
333 */
334 void
335 clutter_media_set_playing (ClutterMedia *media,
336 gboolean playing)
337 {
338 g_return_if_fail (CLUTTER_IS_MEDIA(media));
339
340 g_object_set (G_OBJECT (media), "playing", playing, NULL);
341 }
342
343 /**
344 * clutter_media_get_playing:
345 * @media: A #ClutterMedia object
346 *
347 * Retrieves the playing status of @media.
348 *
349 * Return value: %TRUE if playing, %FALSE if stopped.
350 *
351 * Since: 0.2
352 *
353 * Deprecated: 1.12
354 */
355 gboolean
356 clutter_media_get_playing (ClutterMedia *media)
357 {
358 gboolean is_playing = FALSE;
359
360 g_return_val_if_fail (CLUTTER_IS_MEDIA (media), FALSE);
361
362 g_object_get (G_OBJECT (media), "playing", &is_playing, NULL);
363
364 return is_playing;
365 }
366
367 /**
368 * clutter_media_set_progress:
369 * @media: a #ClutterMedia
370 * @progress: the progress of the playback, between 0.0 and 1.0
371 *
372 * Sets the playback progress of @media. The @progress is
373 * a normalized value between 0.0 (begin) and 1.0 (end).
374 *
375 * Since: 1.0
376 *
377 * Deprecated: 1.12
378 */
379 void
380 clutter_media_set_progress (ClutterMedia *media,
381 gdouble progress)
382 {
383 g_return_if_fail (CLUTTER_IS_MEDIA (media));
384
385 g_object_set (G_OBJECT (media), "progress", progress, NULL);
386 }
387
388 /**
389 * clutter_media_get_progress:
390 * @media: a #ClutterMedia
391 *
392 * Retrieves the playback progress of @media.
393 *
394 * Return value: the playback progress, between 0.0 and 1.0
395 *
396 * Since: 1.0
397 *
398 * Deprecated: 1.12
399 */
400 gdouble
401 clutter_media_get_progress (ClutterMedia *media)
402 {
403 gdouble retval = 0.0;
404
405 g_return_val_if_fail (CLUTTER_IS_MEDIA (media), 0);
406
407 g_object_get (G_OBJECT (media), "progress", &retval, NULL);
408
409 return retval;
410 }
411
412 /**
413 * clutter_media_set_subtitle_uri:
414 * @media: a #ClutterMedia
415 * @uri: the URI of a subtitle file
416 *
417 * Sets the location of a subtitle file to display while playing @media.
418 *
419 * Since: 1.2
420 *
421 * Deprecated: 1.12
422 */
423 void
424 clutter_media_set_subtitle_uri (ClutterMedia *media,
425 const char *uri)
426 {
427 g_return_if_fail (CLUTTER_IS_MEDIA (media));
428
429 g_object_set (G_OBJECT (media), "subtitle-uri", uri, NULL);
430 }
431
432 /**
433 * clutter_media_get_subtitle_uri:
434 * @media: a #ClutterMedia
435 *
436 * Retrieves the URI of the subtitle file in use.
437 *
438 * Return value: the URI of the subtitle file. Use g_free()
439 * to free the returned string
440 *
441 * Since: 1.2
442 *
443 * Deprecated: 1.12
444 */
445 gchar *
446 clutter_media_get_subtitle_uri (ClutterMedia *media)
447 {
448 gchar *retval = NULL;
449
450 g_return_val_if_fail (CLUTTER_IS_MEDIA(media), NULL);
451
452 g_object_get (G_OBJECT (media), "subtitle-uri", &retval, NULL);
453
454 return retval;
455 }
456
457 /**
458 * clutter_media_set_subtitle_font_name:
459 * @media: a #ClutterMedia
460 * @font_name: a font name, or %NULL to set the default font name
461 *
462 * Sets the font used by the subtitle renderer. The @font_name string must be
463 * either %NULL, which means that the default font name of the underlying
464 * implementation will be used; or must follow the grammar recognized by
465 * pango_font_description_from_string() like:
466 *
467 * |[
468 * clutter_media_set_subtitle_font_name (media, "Sans 24pt");
469 * ]|
470 *
471 * Since: 1.2
472 *
473 * Deprecated: 1.12
474 */
475 void
476 clutter_media_set_subtitle_font_name (ClutterMedia *media,
477 const char *font_name)
478 {
479 g_return_if_fail (CLUTTER_IS_MEDIA (media));
480
481 g_object_set (G_OBJECT (media), "subtitle-font-name", font_name, NULL);
482 }
483
484 /**
485 * clutter_media_get_subtitle_font_name:
486 * @media: a #ClutterMedia
487 *
488 * Retrieves the font name currently used.
489 *
490 * Return value: a string containing the font name. Use g_free()
491 * to free the returned string
492 *
493 * Since: 1.2
494 *
495 * Deprecated: 1.12
496 */
497 gchar *
498 clutter_media_get_subtitle_font_name (ClutterMedia *media)
499 {
500 gchar *retval = NULL;
501
502 g_return_val_if_fail (CLUTTER_IS_MEDIA(media), NULL);
503
504 g_object_get (G_OBJECT (media), "subtitle-font-name", &retval, NULL);
505
506 return retval;
507 }
508
509 /**
510 * clutter_media_set_audio_volume:
511 * @media: a #ClutterMedia
512 * @volume: the volume as a double between 0.0 and 1.0
513 *
514 * Sets the playback volume of @media to @volume.
515 *
516 * Since: 1.0
517 *
518 * Deprecated: 1.12
519 */
520 void
521 clutter_media_set_audio_volume (ClutterMedia *media,
522 gdouble volume)
523 {
524 g_return_if_fail (CLUTTER_IS_MEDIA(media));
525
526 g_object_set (G_OBJECT (media), "audio-volume", volume, NULL);
527 }
528
529 /**
530 * clutter_media_get_audio_volume:
531 * @media: a #ClutterMedia
532 *
533 * Retrieves the playback volume of @media.
534 *
535 * Return value: The playback volume between 0.0 and 1.0
536 *
537 * Since: 1.0
538 *
539 * Deprecated: 1.12
540 */
541 gdouble
542 clutter_media_get_audio_volume (ClutterMedia *media)
543 {
544 gdouble retval = 0.0;
545
546 g_return_val_if_fail (CLUTTER_IS_MEDIA (media), 0.0);
547
548 g_object_get (G_OBJECT (media), "audio-volume", &retval, NULL);
549
550 return retval;
551 }
552
553 /**
554 * clutter_media_get_can_seek:
555 * @media: a #ClutterMedia
556 *
557 * Retrieves whether @media is seekable or not.
558 *
559 * Return value: %TRUE if @media can seek, %FALSE otherwise.
560 *
561 * Since: 0.2
562 *
563 * Deprecated: 1.12
564 */
565 gboolean
566 clutter_media_get_can_seek (ClutterMedia *media)
567 {
568 gboolean retval = FALSE;
569
570 g_return_val_if_fail (CLUTTER_IS_MEDIA (media), FALSE);
571
572 g_object_get (G_OBJECT (media), "can-seek", &retval, NULL);
573
574 return retval;
575 }
576
577 /**
578 * clutter_media_get_buffer_fill:
579 * @media: a #ClutterMedia
580 *
581 * Retrieves the amount of the stream that is buffered.
582 *
583 * Return value: the fill level, between 0.0 and 1.0
584 *
585 * Since: 1.0
586 *
587 * Deprecated: 1.12
588 */
589 gdouble
590 clutter_media_get_buffer_fill (ClutterMedia *media)
591 {
592 gdouble retval = 0.0;
593
594 g_return_val_if_fail (CLUTTER_IS_MEDIA (media), 0);
595
596 g_object_get (G_OBJECT (media), "buffer-fill", &retval, NULL);
597
598 return retval;
599 }
600
601 /**
602 * clutter_media_get_duration:
603 * @media: a #ClutterMedia
604 *
605 * Retrieves the duration of the media stream that @media represents.
606 *
607 * Return value: the duration of the media stream, in seconds
608 *
609 * Since: 0.2
610 *
611 * Deprecated: 1.12
612 */
613 gdouble
614 clutter_media_get_duration (ClutterMedia *media)
615 {
616 gdouble retval = 0;
617
618 g_return_val_if_fail (CLUTTER_IS_MEDIA(media), 0);
619
620 g_object_get (G_OBJECT (media), "duration", &retval, NULL);
621
622 return retval;
623 }
624
625 /* helper funcs */
626
627 /**
628 * clutter_media_set_filename:
629 * @media: a #ClutterMedia
630 * @filename: A filename
631 *
632 * Sets the source of @media using a file path.
633 *
634 * Since: 0.2
635 *
636 * Deprecated: 1.12
637 */
638 void
639 clutter_media_set_filename (ClutterMedia *media,
640 const gchar *filename)
641 {
642 gchar *uri;
643 GError *uri_error = NULL;
644
645 if (!g_path_is_absolute (filename))
646 {
647 gchar *abs_path;
648
649 abs_path = g_build_filename (g_get_current_dir (), filename, NULL);
650 uri = g_filename_to_uri (abs_path, NULL, &uri_error);
651 g_free (abs_path);
652 }
653 else
654 uri = g_filename_to_uri (filename, NULL, &uri_error);
655
656 if (uri_error)
657 {
658 g_signal_emit (media, media_signals[ERROR_SIGNAL], 0, uri_error);
659 g_error_free (uri_error);
660 return;
661 }
662
663 clutter_media_set_uri (media, uri);
664
665 g_free (uri);
666 }