/
gstplaybin2.c
6096 lines (5265 loc) · 199 KB
/
gstplaybin2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* GStreamer
* Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
* Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) <2013> Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-playbin
* @title: playbin
*
* Playbin provides a stand-alone everything-in-one abstraction for an
* audio and/or video player.
*
* Playbin can handle both audio and video files and features
*
* * automatic file type recognition and based on that automatic
* selection and usage of the right audio/video/subtitle demuxers/decoders
* * visualisations for audio files
* * subtitle support for video files. Subtitles can be store in external
* files.
* * stream selection between different video/audio/subtitles streams
* * meta info (tag) extraction
* * easy access to the last video sample
* * buffering when playing streams over a network
* * volume control with mute option
*
* ## Usage
*
* A playbin element can be created just like any other element using
* gst_element_factory_make(). The file/URI to play should be set via the #GstPlayBin:uri
* property. This must be an absolute URI, relative file paths are not allowed.
* Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
*
* Playbin is a #GstPipeline. It will notify the application of everything
* that's happening (errors, end of stream, tags found, state changes, etc.)
* by posting messages on its #GstBus. The application needs to watch the
* bus.
*
* Playback can be initiated by setting the element to PLAYING state using
* gst_element_set_state(). Note that the state change will take place in
* the background in a separate thread, when the function returns playback
* is probably not happening yet and any errors might not have occurred yet.
* Applications using playbin should ideally be written to deal with things
* completely asynchroneous.
*
* When playback has finished (an EOS message has been received on the bus)
* or an error has occurred (an ERROR message has been received on the bus) or
* the user wants to play a different track, playbin should be set back to
* READY or NULL state, then the #GstPlayBin:uri property should be set to the
* new location and then playbin be set to PLAYING state again.
*
* Seeking can be done using gst_element_seek_simple() or gst_element_seek()
* on the playbin element. Again, the seek will not be executed
* instantaneously, but will be done in a background thread. When the seek
* call returns the seek will most likely still be in process. An application
* may wait for the seek to finish (or fail) using gst_element_get_state() with
* -1 as the timeout, but this will block the user interface and is not
* recommended at all.
*
* Applications may query the current position and duration of the stream
* via gst_element_query_position() and gst_element_query_duration() and
* setting the format passed to GST_FORMAT_TIME. If the query was successful,
* the duration or position will have been returned in units of nanoseconds.
*
* ## Advanced Usage: specifying the audio and video sink
*
* By default, if no audio sink or video sink has been specified via the
* #GstPlayBin:audio-sink or #GstPlayBin:video-sink property, playbin will use the autoaudiosink
* and autovideosink elements to find the first-best available output method.
* This should work in most cases, but is not always desirable. Often either
* the user or application might want to specify more explicitly what to use
* for audio and video output.
*
* If the application wants more control over how audio or video should be
* output, it may create the audio/video sink elements itself (for example
* using gst_element_factory_make()) and provide them to playbin using the
* #GstPlayBin:audio-sink or #GstPlayBin:video-sink property.
*
* GNOME-based applications, for example, will usually want to create
* gconfaudiosink and gconfvideosink elements and make playbin use those,
* so that output happens to whatever the user has configured in the GNOME
* Multimedia System Selector configuration dialog.
*
* The sink elements do not necessarily need to be ready-made sinks. It is
* possible to create container elements that look like a sink to playbin,
* but in reality contain a number of custom elements linked together. This
* can be achieved by creating a #GstBin and putting elements in there and
* linking them, and then creating a sink #GstGhostPad for the bin and pointing
* it to the sink pad of the first element within the bin. This can be used
* for a number of purposes, for example to force output to a particular
* format or to modify or observe the data before it is output.
*
* It is also possible to 'suppress' audio and/or video output by using
* 'fakesink' elements (or capture it from there using the fakesink element's
* "handoff" signal, which, nota bene, is fired from the streaming thread!).
*
* ## Retrieving Tags and Other Meta Data
*
* Most of the common meta data (artist, title, etc.) can be retrieved by
* watching for TAG messages on the pipeline's bus (see above).
*
* Other more specific meta information like width/height/framerate of video
* streams or samplerate/number of channels of audio streams can be obtained
* from the negotiated caps on the sink pads of the sinks.
*
* ## Buffering
* Playbin handles buffering automatically for the most part, but applications
* need to handle parts of the buffering process as well. Whenever playbin is
* buffering, it will post BUFFERING messages on the bus with a percentage
* value that shows the progress of the buffering process. Applications need
* to set playbin to PLAYING or PAUSED state in response to these messages.
* They may also want to convey the buffering progress to the user in some
* way. Here is how to extract the percentage information from the message:
* |[
* switch (GST_MESSAGE_TYPE (msg)) {
* case GST_MESSAGE_BUFFERING: {
* gint percent = 0;
* gst_message_parse_buffering (msg, &percent);
* g_print ("Buffering (%u percent done)", percent);
* break;
* }
* ...
* }
* ]|
*
* Note that applications should keep/set the pipeline in the PAUSED state when
* a BUFFERING message is received with a buffer percent value < 100 and set
* the pipeline back to PLAYING state when a BUFFERING message with a value
* of 100 percent is received (if PLAYING is the desired state, that is).
*
* ## Embedding the video window in your application
* By default, playbin (or rather the video sinks used) will create their own
* window. Applications will usually want to force output to a window of their
* own, however. This can be done using the #GstVideoOverlay interface, which most
* video sinks implement. See the documentation there for more details.
*
* ## Specifying which CD/DVD device to use
* The device to use for CDs/DVDs needs to be set on the source element
* playbin creates before it is opened. The most generic way of doing this
* is to connect to playbin's "source-setup" (or "notify::source") signal,
* which will be emitted by playbin when it has created the source element
* for a particular URI. In the signal callback you can check if the source
* element has a "device" property and set it appropriately. In some cases
* the device can also be set as part of the URI, but it depends on the
* elements involved if this will work or not. For example, for DVD menu
* playback, the following syntax might work (if the resindvd plugin is used):
* dvd://[/path/to/device]
*
* ## Handling redirects
*
* Some elements may post 'redirect' messages on the bus to tell the
* application to open another location. These are element messages containing
* a structure named 'redirect' along with a 'new-location' field of string
* type. The new location may be a relative or an absolute URI. Examples
* for such redirects can be found in many quicktime movie trailers.
*
* NOTE: playbin will internally handle the redirect messages in the case
* that the redirecting stream doesn't contain any tracks and thus
* needs to report an error message on the bus.
*
* ## Examples
* |[
* gst-launch-1.0 -v playbin uri=file:///path/to/somefile.mp4
* ]|
* This will play back the given AVI video file, given that the video and
* audio decoders required to decode the content are installed. Since no
* special audio sink or video sink is supplied (via playbin's audio-sink or
* video-sink properties) playbin will try to find a suitable audio and
* video sink automatically using the autoaudiosink and autovideosink elements.
* |[
* gst-launch-1.0 -v playbin uri=cdda://4
* ]|
* This will play back track 4 on an audio CD in your disc drive (assuming
* the drive is detected automatically by the plugin).
* |[
* gst-launch-1.0 -v playbin uri=dvd://
* ]|
* This will play back the DVD in your disc drive (assuming
* the drive is detected automatically by the plugin).
*
*/
/* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
* with newer GLib versions (>= 2.31.0) */
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <gst/gst.h>
#include <gst/gst-i18n-plugin.h>
#include <gst/pbutils/pbutils.h>
#include <gst/audio/streamvolume.h>
#include <gst/video/video-info.h>
#include <gst/video/video-multiview.h>
#include <gst/video/videooverlay.h>
#include <gst/video/navigation.h>
#include <gst/video/colorbalance.h>
#include "gstplay-enum.h"
#include "gstplaybackelements.h"
#include "gstplaysink.h"
#include "gstsubtitleoverlay.h"
#include "gstplaybackutils.h"
GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
#define GST_CAT_DEFAULT gst_play_bin_debug
#define GST_TYPE_PLAY_BIN (gst_play_bin_get_type())
#define GST_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
#define GST_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
#define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
#define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
#define ULONG_TO_POINTER(number) ((gpointer) (guintptr) (number))
#define POINTER_TO_ULONG(number) ((guintptr) (number))
#define VOLUME_MAX_DOUBLE 10.0
typedef struct _GstPlayBin GstPlayBin;
typedef struct _GstPlayBinClass GstPlayBinClass;
typedef struct _GstSourceGroup GstSourceGroup;
typedef struct _GstSourceCombine GstSourceCombine;
typedef GstCaps *(*SourceCombineGetMediaCapsFunc) (void);
/* has the info for a combiner and provides the link to the sink */
struct _GstSourceCombine
{
const gchar *media_list[8]; /* the media types for the combiner */
SourceCombineGetMediaCapsFunc get_media_caps; /* more complex caps for the combiner */
GstPlaySinkType type; /* the sink pad type of the combiner */
GstElement *combiner; /* the combiner */
GPtrArray *channels;
GstPad *srcpad; /* the source pad of the combiner */
GstPad *sinkpad; /* the sinkpad of the sink when the combiner
* is linked
*/
gulong block_id;
gboolean has_active_pad; /* stream combiner has the "active-pad" property */
gboolean has_always_ok; /* stream combiner's sink pads have the "always-ok" property */
gboolean has_tags; /* stream combiner's sink pads have the "tags" property */
};
#define GST_SOURCE_GROUP_GET_LOCK(group) (&((GstSourceGroup*)(group))->lock)
#define GST_SOURCE_GROUP_LOCK(group) (g_mutex_lock (GST_SOURCE_GROUP_GET_LOCK(group)))
#define GST_SOURCE_GROUP_UNLOCK(group) (g_mutex_unlock (GST_SOURCE_GROUP_GET_LOCK(group)))
enum
{
PLAYBIN_STREAM_AUDIO = 0,
PLAYBIN_STREAM_VIDEO,
PLAYBIN_STREAM_TEXT,
PLAYBIN_STREAM_LAST
};
static void avelements_free (gpointer data);
static GSequence *avelements_create (GstPlayBin * playbin,
gboolean isaudioelement);
/* The GstAudioVideoElement structure holding the audio/video decoder
* and the audio/video sink factories together with field indicating
* the number of common caps features */
typedef struct
{
GstElementFactory *dec; /* audio:video decoder */
GstElementFactory *sink; /* audio:video sink */
guint n_comm_cf; /* number of common caps features */
} GstAVElement;
/* a structure to hold the objects for decoding a uri and the subtitle uri
*/
struct _GstSourceGroup
{
GstPlayBin *playbin;
GMutex lock;
gboolean valid; /* the group has valid info to start playback */
gboolean active; /* the group is active */
/* properties */
gchar *uri;
gchar *suburi;
GValueArray *streaminfo;
GstElement *source;
GPtrArray *video_channels; /* links to combiner pads */
GPtrArray *audio_channels; /* links to combiner pads */
GPtrArray *text_channels; /* links to combiner pads */
/* Sinks for this group. These are initialized with
* the configure or currently used sink, otherwise
* left as NULL and playbin tries to automatically
* select a good sink
*/
GstElement *audio_sink;
GstElement *video_sink;
GstElement *text_sink;
/* uridecodebins for uri and subtitle uri */
GstElement *uridecodebin;
GstElement *suburidecodebin;
gint pending;
gboolean sub_pending;
gboolean have_group_id;
guint group_id;
gulong pad_added_id;
gulong pad_removed_id;
gulong no_more_pads_id;
gulong notify_source_id;
gulong drained_id;
gulong autoplug_factories_id;
gulong autoplug_select_id;
gulong autoplug_continue_id;
gulong autoplug_query_id;
gulong sub_pad_added_id;
gulong sub_pad_removed_id;
gulong sub_no_more_pads_id;
gulong sub_autoplug_continue_id;
gulong sub_autoplug_query_id;
gulong block_id;
GMutex stream_changed_pending_lock;
gboolean stream_changed_pending;
/* to prevent that suburidecodebin seek flushes disrupt playback */
GMutex suburi_flushes_to_drop_lock;
GSList *suburi_flushes_to_drop;
/* buffering message stored for after switching */
GstMessage *pending_buffering_msg;
/* combiners for different streams */
GstSourceCombine combiner[PLAYBIN_STREAM_LAST];
};
#define GST_PLAY_BIN_GET_LOCK(bin) (&((GstPlayBin*)(bin))->lock)
#define GST_PLAY_BIN_LOCK(bin) (g_rec_mutex_lock (GST_PLAY_BIN_GET_LOCK(bin)))
#define GST_PLAY_BIN_UNLOCK(bin) (g_rec_mutex_unlock (GST_PLAY_BIN_GET_LOCK(bin)))
/* lock to protect dynamic callbacks, like no-more-pads */
#define GST_PLAY_BIN_DYN_LOCK(bin) g_mutex_lock (&(bin)->dyn_lock)
#define GST_PLAY_BIN_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->dyn_lock)
/* lock for shutdown */
#define GST_PLAY_BIN_SHUTDOWN_LOCK(bin,label) \
G_STMT_START { \
if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) \
goto label; \
GST_PLAY_BIN_DYN_LOCK (bin); \
if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) { \
GST_PLAY_BIN_DYN_UNLOCK (bin); \
goto label; \
} \
} G_STMT_END
/* unlock for shutdown */
#define GST_PLAY_BIN_SHUTDOWN_UNLOCK(bin) \
GST_PLAY_BIN_DYN_UNLOCK (bin); \
/**
* GstPlayBin:
*
* playbin element structure
*/
struct _GstPlayBin
{
GstPipeline parent;
GRecMutex lock; /* to protect group switching */
/* the groups, we use a double buffer to switch between current and next */
GstSourceGroup groups[2]; /* array with group info */
GstSourceGroup *curr_group; /* pointer to the currently playing group */
GstSourceGroup *next_group; /* pointer to the next group */
/* properties */
guint64 connection_speed; /* connection speed in bits/sec (0 = unknown) */
gint current_video; /* the currently selected stream */
gint current_audio; /* the currently selected stream */
gint current_text; /* the currently selected stream */
guint64 buffer_duration; /* When buffering, the max buffer duration (ns) */
guint buffer_size; /* When buffering, the max buffer size (bytes) */
gboolean force_aspect_ratio;
/* Multiview/stereoscopic overrides */
GstVideoMultiviewFramePacking multiview_mode;
GstVideoMultiviewFlags multiview_flags;
/* our play sink */
GstPlaySink *playsink;
/* the last activated source */
GstElement *source;
/* lock protecting dynamic adding/removing */
GMutex dyn_lock;
/* if we are shutting down or not */
gint shutdown;
gboolean async_pending; /* async-start has been emitted */
GMutex elements_lock;
guint32 elements_cookie;
GList *elements; /* factories we can use for selecting elements */
gboolean have_selector; /* set to FALSE when we fail to create an
* input-selector, so that we only post a
* warning once */
gboolean video_pending_flush_finish; /* whether we are pending to send a custom
* custom-video-flush-finish event
* on pad activation */
gboolean audio_pending_flush_finish; /* whether we are pending to send a custom
* custom-audio-flush-finish event
* on pad activation */
gboolean text_pending_flush_finish; /* whether we are pending to send a custom
* custom-subtitle-flush-finish event
* on pad activation */
GstElement *audio_sink; /* configured audio sink, or NULL */
GstElement *video_sink; /* configured video sink, or NULL */
GstElement *text_sink; /* configured text sink, or NULL */
GstElement *audio_stream_combiner; /* configured audio stream combiner, or NULL */
GstElement *video_stream_combiner; /* configured video stream combiner, or NULL */
GstElement *text_stream_combiner; /* configured text stream combiner, or NULL */
GSequence *aelements; /* a list of GstAVElements for audio stream */
GSequence *velements; /* a list of GstAVElements for video stream */
struct
{
gboolean valid;
GstFormat format;
gint64 duration;
} duration[5]; /* cached durations */
guint64 ring_buffer_max_size; /* 0 means disabled */
GList *contexts;
gboolean is_live;
};
struct _GstPlayBinClass
{
GstPipelineClass parent_class;
/* notify app that the current uri finished decoding and it is possible to
* queue a new one for gapless playback */
void (*about_to_finish) (GstPlayBin * playbin);
/* notify app that number of audio/video/text streams changed */
void (*video_changed) (GstPlayBin * playbin);
void (*audio_changed) (GstPlayBin * playbin);
void (*text_changed) (GstPlayBin * playbin);
/* notify app that the tags of audio/video/text streams changed */
void (*video_tags_changed) (GstPlayBin * playbin, gint stream);
void (*audio_tags_changed) (GstPlayBin * playbin, gint stream);
void (*text_tags_changed) (GstPlayBin * playbin, gint stream);
/* get audio/video/text tags for a stream */
GstTagList *(*get_video_tags) (GstPlayBin * playbin, gint stream);
GstTagList *(*get_audio_tags) (GstPlayBin * playbin, gint stream);
GstTagList *(*get_text_tags) (GstPlayBin * playbin, gint stream);
/* get the last video sample and convert it to the given caps */
GstSample *(*convert_sample) (GstPlayBin * playbin, GstCaps * caps);
/* get audio/video/text pad for a stream */
GstPad *(*get_video_pad) (GstPlayBin * playbin, gint stream);
GstPad *(*get_audio_pad) (GstPlayBin * playbin, gint stream);
GstPad *(*get_text_pad) (GstPlayBin * playbin, gint stream);
};
/* props */
#define DEFAULT_URI NULL
#define DEFAULT_SUBURI NULL
#define DEFAULT_SOURCE NULL
#define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_DEINTERLACE | \
GST_PLAY_FLAG_SOFT_COLORBALANCE
#define DEFAULT_N_VIDEO 0
#define DEFAULT_CURRENT_VIDEO -1
#define DEFAULT_N_AUDIO 0
#define DEFAULT_CURRENT_AUDIO -1
#define DEFAULT_N_TEXT 0
#define DEFAULT_CURRENT_TEXT -1
#define DEFAULT_SUBTITLE_ENCODING NULL
#define DEFAULT_AUDIO_SINK NULL
#define DEFAULT_VIDEO_SINK NULL
#define DEFAULT_VIS_PLUGIN NULL
#define DEFAULT_TEXT_SINK NULL
#define DEFAULT_VOLUME 1.0
#define DEFAULT_MUTE FALSE
#define DEFAULT_FRAME NULL
#define DEFAULT_FONT_DESC NULL
#define DEFAULT_CONNECTION_SPEED 0
#define DEFAULT_BUFFER_DURATION -1
#define DEFAULT_BUFFER_SIZE -1
#define DEFAULT_RING_BUFFER_MAX_SIZE 0
enum
{
PROP_0,
PROP_URI,
PROP_CURRENT_URI,
PROP_SUBURI,
PROP_CURRENT_SUBURI,
PROP_SOURCE,
PROP_FLAGS,
PROP_N_VIDEO,
PROP_CURRENT_VIDEO,
PROP_N_AUDIO,
PROP_CURRENT_AUDIO,
PROP_N_TEXT,
PROP_CURRENT_TEXT,
PROP_SUBTITLE_ENCODING,
PROP_AUDIO_SINK,
PROP_VIDEO_SINK,
PROP_VIS_PLUGIN,
PROP_TEXT_SINK,
PROP_VIDEO_STREAM_COMBINER,
PROP_AUDIO_STREAM_COMBINER,
PROP_TEXT_STREAM_COMBINER,
PROP_VOLUME,
PROP_MUTE,
PROP_SAMPLE,
PROP_FONT_DESC,
PROP_CONNECTION_SPEED,
PROP_BUFFER_SIZE,
PROP_BUFFER_DURATION,
PROP_AV_OFFSET,
PROP_TEXT_OFFSET,
PROP_RING_BUFFER_MAX_SIZE,
PROP_FORCE_ASPECT_RATIO,
PROP_AUDIO_FILTER,
PROP_VIDEO_FILTER,
PROP_MULTIVIEW_MODE,
PROP_MULTIVIEW_FLAGS
};
/* signals */
enum
{
SIGNAL_ABOUT_TO_FINISH,
SIGNAL_CONVERT_SAMPLE,
SIGNAL_VIDEO_CHANGED,
SIGNAL_AUDIO_CHANGED,
SIGNAL_TEXT_CHANGED,
SIGNAL_VIDEO_TAGS_CHANGED,
SIGNAL_AUDIO_TAGS_CHANGED,
SIGNAL_TEXT_TAGS_CHANGED,
SIGNAL_GET_VIDEO_TAGS,
SIGNAL_GET_AUDIO_TAGS,
SIGNAL_GET_TEXT_TAGS,
SIGNAL_GET_VIDEO_PAD,
SIGNAL_GET_AUDIO_PAD,
SIGNAL_GET_TEXT_PAD,
SIGNAL_SOURCE_SETUP,
SIGNAL_ELEMENT_SETUP,
LAST_SIGNAL
};
static GstStaticCaps raw_audio_caps = GST_STATIC_CAPS ("audio/x-raw(ANY)");
static GstStaticCaps raw_video_caps = GST_STATIC_CAPS ("video/x-raw(ANY)");
static void gst_play_bin_finalize (GObject * object);
static void gst_play_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * spec);
static void gst_play_bin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * spec);
static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
GstStateChange transition);
static void gst_play_bin_handle_message (GstBin * bin, GstMessage * message);
static void gst_play_bin_deep_element_added (GstBin * playbin, GstBin * sub_bin,
GstElement * child);
static gboolean gst_play_bin_query (GstElement * element, GstQuery * query);
static void gst_play_bin_set_context (GstElement * element,
GstContext * context);
static gboolean gst_play_bin_send_event (GstElement * element,
GstEvent * event);
static GstTagList *gst_play_bin_get_video_tags (GstPlayBin * playbin,
gint stream);
static GstTagList *gst_play_bin_get_audio_tags (GstPlayBin * playbin,
gint stream);
static GstTagList *gst_play_bin_get_text_tags (GstPlayBin * playbin,
gint stream);
static GstSample *gst_play_bin_convert_sample (GstPlayBin * playbin,
GstCaps * caps);
static GstPad *gst_play_bin_get_video_pad (GstPlayBin * playbin, gint stream);
static GstPad *gst_play_bin_get_audio_pad (GstPlayBin * playbin, gint stream);
static GstPad *gst_play_bin_get_text_pad (GstPlayBin * playbin, gint stream);
static GstStateChangeReturn setup_next_source (GstPlayBin * playbin,
GstState target);
static void no_more_pads_cb (GstElement * decodebin, GstSourceGroup * group);
static void pad_removed_cb (GstElement * decodebin, GstPad * pad,
GstSourceGroup * group);
static void gst_play_bin_suburidecodebin_block (GstSourceGroup * group,
GstElement * suburidecodebin, gboolean block);
static void gst_play_bin_suburidecodebin_seek_to_start (GstSourceGroup * group);
static void
gst_play_bin_update_context (GstPlayBin * playbin, GstContext * context);
static GstElementClass *parent_class;
static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
#define REMOVE_SIGNAL(obj,id) \
if (id) { \
g_signal_handler_disconnect (obj, id); \
id = 0; \
}
static void gst_play_bin_overlay_init (gpointer g_iface, gpointer g_iface_data);
static void gst_play_bin_navigation_init (gpointer g_iface,
gpointer g_iface_data);
static void gst_play_bin_colorbalance_init (gpointer g_iface,
gpointer g_iface_data);
static GType gst_play_bin_get_type (void);
static void
_do_init_type (GType type)
{
static const GInterfaceInfo svol_info = {
NULL, NULL, NULL
};
static const GInterfaceInfo ov_info = {
gst_play_bin_overlay_init,
NULL, NULL
};
static const GInterfaceInfo nav_info = {
gst_play_bin_navigation_init,
NULL, NULL
};
static const GInterfaceInfo col_info = {
gst_play_bin_colorbalance_init,
NULL, NULL
};
g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info);
g_type_add_interface_static (type, GST_TYPE_VIDEO_OVERLAY, &ov_info);
g_type_add_interface_static (type, GST_TYPE_NAVIGATION, &nav_info);
g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &col_info);
}
G_DEFINE_TYPE_WITH_CODE (GstPlayBin, gst_play_bin, GST_TYPE_PIPELINE,
_do_init_type (g_define_type_id));
#define _do_init \
GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");\
playback_element_init (plugin);
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (playbin, "playbin", GST_RANK_NONE,
GST_TYPE_PLAY_BIN, _do_init);
void
gst_play_bin_class_init (GstPlayBinClass * klass)
{
GObjectClass *gobject_klass;
GstElementClass *gstelement_klass;
GstBinClass *gstbin_klass;
gobject_klass = (GObjectClass *) klass;
gstelement_klass = (GstElementClass *) klass;
gstbin_klass = (GstBinClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_klass->set_property = gst_play_bin_set_property;
gobject_klass->get_property = gst_play_bin_get_property;
gobject_klass->finalize = gst_play_bin_finalize;
/**
* GstPlayBin:uri
*
* Set the next URI that playbin will play. This property can be set from the
* about-to-finish signal to queue the next media file.
*/
g_object_class_install_property (gobject_klass, PROP_URI,
g_param_spec_string ("uri", "URI", "URI of the media to play",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:current-uri
*
* The currently playing uri.
*/
g_object_class_install_property (gobject_klass, PROP_CURRENT_URI,
g_param_spec_string ("current-uri", "Current URI",
"The currently playing URI", NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:suburi
*
* Set the next subtitle URI that playbin will play. This property can be
* set from the about-to-finish signal to queue the next subtitle media file.
*/
g_object_class_install_property (gobject_klass, PROP_SUBURI,
g_param_spec_string ("suburi", ".sub-URI", "Optional URI of a subtitle",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:current-suburi
*
* The currently playing subtitle uri.
*/
g_object_class_install_property (gobject_klass, PROP_CURRENT_SUBURI,
g_param_spec_string ("current-suburi", "Current .sub-URI",
"The currently playing URI of a subtitle",
NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_SOURCE,
g_param_spec_object ("source", "Source", "Source element",
GST_TYPE_ELEMENT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:flags
*
* Control the behaviour of playbin.
*/
g_object_class_install_property (gobject_klass, PROP_FLAGS,
g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:n-video
*
* Get the total number of available video streams.
*/
g_object_class_install_property (gobject_klass, PROP_N_VIDEO,
g_param_spec_int ("n-video", "Number Video",
"Total number of video streams", 0, G_MAXINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:current-video
*
* Get or set the currently playing video stream. By default the first video
* stream with data is played.
*/
g_object_class_install_property (gobject_klass, PROP_CURRENT_VIDEO,
g_param_spec_int ("current-video", "Current Video",
"Currently playing video stream (-1 = auto)",
-1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:n-audio
*
* Get the total number of available audio streams.
*/
g_object_class_install_property (gobject_klass, PROP_N_AUDIO,
g_param_spec_int ("n-audio", "Number Audio",
"Total number of audio streams", 0, G_MAXINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:current-audio
*
* Get or set the currently playing audio stream. By default the first audio
* stream with data is played.
*/
g_object_class_install_property (gobject_klass, PROP_CURRENT_AUDIO,
g_param_spec_int ("current-audio", "Current audio",
"Currently playing audio stream (-1 = auto)",
-1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:n-text
*
* Get the total number of available subtitle streams.
*/
g_object_class_install_property (gobject_klass, PROP_N_TEXT,
g_param_spec_int ("n-text", "Number Text",
"Total number of text streams", 0, G_MAXINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:current-text:
*
* Get or set the currently playing subtitle stream. By default the first
* subtitle stream with data is played.
*/
g_object_class_install_property (gobject_klass, PROP_CURRENT_TEXT,
g_param_spec_int ("current-text", "Current Text",
"Currently playing text stream (-1 = auto)",
-1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
g_param_spec_string ("subtitle-encoding", "subtitle encoding",
"Encoding to assume if input subtitles are not in UTF-8 encoding. "
"If not set, the GST_SUBTITLE_ENCODING environment variable will "
"be checked for an encoding to use. If that is not set either, "
"ISO-8859-15 will be assumed.", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_VIDEO_FILTER,
g_param_spec_object ("video-filter", "Video filter",
"the video filter(s) to apply, if possible",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_AUDIO_FILTER,
g_param_spec_object ("audio-filter", "Audio filter",
"the audio filter(s) to apply, if possible",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
g_param_spec_object ("video-sink", "Video Sink",
"the video output element to use (NULL = default sink)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
g_param_spec_object ("audio-sink", "Audio Sink",
"the audio output element to use (NULL = default sink)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
g_param_spec_object ("vis-plugin", "Vis plugin",
"the visualization element to use (NULL = default)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
g_param_spec_object ("text-sink", "Text plugin",
"the text output element to use (NULL = default subtitleoverlay)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:video-stream-combiner
*
* Get or set the current video stream combiner. By default, an input-selector
* is created and deleted as-needed.
*/
g_object_class_install_property (gobject_klass, PROP_VIDEO_STREAM_COMBINER,
g_param_spec_object ("video-stream-combiner", "Video stream combiner",
"Current video stream combiner (NULL = input-selector)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:audio-stream-combiner
*
* Get or set the current audio stream combiner. By default, an input-selector
* is created and deleted as-needed.
*/
g_object_class_install_property (gobject_klass, PROP_AUDIO_STREAM_COMBINER,
g_param_spec_object ("audio-stream-combiner", "Audio stream combiner",
"Current audio stream combiner (NULL = input-selector)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:text-stream-combiner
*
* Get or set the current text stream combiner. By default, an input-selector
* is created and deleted as-needed.
*/
g_object_class_install_property (gobject_klass, PROP_TEXT_STREAM_COMBINER,
g_param_spec_object ("text-stream-combiner", "Text stream combiner",
"Current text stream combiner (NULL = input-selector)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:volume:
*
* Get or set the current audio stream volume. 1.0 means 100%,
* 0.0 means mute. This uses a linear volume scale.
*
*/
g_object_class_install_property (gobject_klass, PROP_VOLUME,
g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
0.0, VOLUME_MAX_DOUBLE, 1.0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_MUTE,
g_param_spec_boolean ("mute", "Mute",
"Mute the audio channel without changing the volume", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:sample:
* @playbin: a #GstPlayBin
*
* Get the currently rendered or prerolled sample in the video sink.
* The #GstCaps in the sample will describe the format of the buffer.
*/
g_object_class_install_property (gobject_klass, PROP_SAMPLE,
g_param_spec_boxed ("sample", "Sample",
"The last sample (NULL = no video available)",
GST_TYPE_SAMPLE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
g_param_spec_string ("subtitle-font-desc",
"Subtitle font description",
"Pango font description of font "
"to be used for subtitle rendering", NULL,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_CONNECTION_SPEED,
g_param_spec_uint64 ("connection-speed", "Connection Speed",
"Network connection speed in kbps (0 = unknown)",
0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_BUFFER_SIZE,
g_param_spec_int ("buffer-size", "Buffer size (bytes)",
"Buffer size when buffering network streams",
-1, G_MAXINT, DEFAULT_BUFFER_SIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_klass, PROP_BUFFER_DURATION,
g_param_spec_int64 ("buffer-duration", "Buffer duration (ns)",
"Buffer duration when buffering network streams",
-1, G_MAXINT64, DEFAULT_BUFFER_DURATION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:av-offset:
*
* Control the synchronisation offset between the audio and video streams.
* Positive values make the audio ahead of the video and negative values make
* the audio go behind the video.
*/
g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
g_param_spec_int64 ("av-offset", "AV Offset",
"The synchronisation offset between audio and video in nanoseconds",
G_MININT64, G_MAXINT64, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:text-offset:
*
* Control the synchronisation offset between the text and video streams.
* Positive values make the text ahead of the video and negative values make
* the text go behind the video.
*/
g_object_class_install_property (gobject_klass, PROP_TEXT_OFFSET,
g_param_spec_int64 ("text-offset", "Text Offset",
"The synchronisation offset between text and video in nanoseconds",
G_MININT64, G_MAXINT64, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin:ring-buffer-max-size:
*
* The maximum size of the ring buffer in bytes. If set to 0, the ring
* buffer is disabled. Default 0.
*/
g_object_class_install_property (gobject_klass, PROP_RING_BUFFER_MAX_SIZE,
g_param_spec_uint64 ("ring-buffer-max-size",
"Max. ring buffer size (bytes)",
"Max. amount of data in the ring buffer (bytes, 0 = ring buffer disabled)",
0, G_MAXUINT, DEFAULT_RING_BUFFER_MAX_SIZE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin::force-aspect-ratio:
*
* Requests the video sink to enforce the video display aspect ratio.
*/
g_object_class_install_property (gobject_klass, PROP_FORCE_ASPECT_RATIO,
g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
"When enabled, scaling will respect original aspect ratio", TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstPlayBin::video-multiview-mode:
*
* Set the stereoscopic mode for video streams that don't contain
* any information in the stream, so they can be correctly played
* as 3D streams. If a video already has multiview information
* encoded, this property can override other modes in the set,
* but cannot be used to re-interpret MVC or mixed-mono streams.
*
* See Also: The #GstPlayBin::video-multiview-flags property
*
*/
g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_MODE,
g_param_spec_enum ("video-multiview-mode",