/
gstdecodebin2.c
5687 lines (4841 loc) · 176 KB
/
gstdecodebin2.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) <2006> Edward Hervey <edward@fluendo.com>
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
* Copyright (C) <2011> Hewlett-Packard Development Company, L.P.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
* 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-decodebin
* @title: decodebin
*
* #GstBin that auto-magically constructs a decoding pipeline using available
* decoders and demuxers via auto-plugging.
*
* decodebin is considered stable now and replaces the old #decodebin element.
* #uridecodebin uses decodebin internally and is often more convenient to
* use, as it creates a suitable source element as well.
*/
/* Implementation notes:
*
* The following section describes how decodebin works internally.
*
* The first part of decodebin is its typefind element, which tries
* to determine the media type of the input stream. If the type is found
* autoplugging starts.
*
* decodebin internally organizes the elements it autoplugged into GstDecodeChains
* and GstDecodeGroups. A decode chain is a single chain of decoding, this
* means that if decodebin every autoplugs an element with two+ srcpads
* (e.g. a demuxer) this will end the chain and everything following this
* demuxer will be put into decode groups below the chain. Otherwise,
* if an element has a single srcpad that outputs raw data the decode chain
* is ended too and a GstDecodePad is stored and blocked.
*
* A decode group combines a number of chains that are created by a
* demuxer element. All those chains are connected through a multiqueue to
* the demuxer. A new group for the same demuxer is only created if the
* demuxer has signaled no-more-pads, in which case all following pads
* create a new chain in the new group.
*
* This continues until the top-level decode chain is complete. A decode
* chain is complete if it either ends with a blocked endpad, if autoplugging
* stopped because no suitable plugins could be found or if the active group
* is complete. A decode group on the other hand is complete if all child
* chains are complete.
*
* If this happens at some point, all endpads of all active groups are exposed.
* For this decodebin adds the endpads, signals no-more-pads and then unblocks
* them. Now playback starts.
*
* If one of the chains that end on a endpad receives EOS decodebin checks
* if all chains and groups are drained. In that case everything goes into EOS.
* If there is a chain where the active group is drained but there exist next
* groups, the active group is hidden (endpads are removed) and the next group
* is exposed. This means that in some cases more pads may be created even
* after the initial no-more-pads signal. This happens for example with
* so-called "chained oggs", most commonly found among ogg/vorbis internet
* radio streams.
*
* Note 1: If we're talking about blocked endpads this really means that the
* *target* pads of the endpads are blocked. Pads that are exposed to the outside
* should never ever be blocked!
*
* Note 2: If a group is complete and the parent's chain demuxer adds new pads
* but never signaled no-more-pads this additional pads will be ignored!
*
*/
/* 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 <gst/gst-i18n-plugin.h>
#include <string.h>
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>
#include "gstplay-enum.h"
#include "gstplaybackelements.h"
#include "gstrawcaps.h"
#include "gstplaybackutils.h"
/* generic templates */
static GstStaticPadTemplate decoder_bin_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
static GstStaticPadTemplate decoder_bin_src_template =
GST_STATIC_PAD_TEMPLATE ("src_%u",
GST_PAD_SRC,
GST_PAD_SOMETIMES,
GST_STATIC_CAPS_ANY);
GST_DEBUG_CATEGORY_STATIC (gst_decode_bin_debug);
#define GST_CAT_DEFAULT gst_decode_bin_debug
typedef struct _GstPendingPad GstPendingPad;
typedef struct _GstDecodeElement GstDecodeElement;
typedef struct _GstDemuxerPad GstDemuxerPad;
typedef struct _GstDecodeChain GstDecodeChain;
typedef struct _GstDecodeGroup GstDecodeGroup;
typedef struct _GstDecodePad GstDecodePad;
typedef GstGhostPadClass GstDecodePadClass;
typedef struct _GstDecodeBin GstDecodeBin;
typedef struct _GstDecodeBinClass GstDecodeBinClass;
#define GST_TYPE_DECODE_BIN (gst_decode_bin_get_type())
#define GST_DECODE_BIN_CAST(obj) ((GstDecodeBin*)(obj))
#define GST_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_BIN,GstDecodeBin))
#define GST_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DECODE_BIN,GstDecodeBinClass))
#define GST_IS_DECODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DECODE_BIN))
#define GST_IS_DECODE_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DECODE_BIN))
/**
* GstDecodeBin:
*
* The opaque #GstDecodeBin data structure
*/
struct _GstDecodeBin
{
GstBin bin; /* we extend GstBin */
/* properties */
GstCaps *caps; /* caps on which to stop decoding */
gchar *encoding; /* encoding of subtitles */
gboolean use_buffering; /* configure buffering on multiqueues */
gboolean force_sw_decoders;
gint low_percent;
gint high_percent;
guint max_size_bytes;
guint max_size_buffers;
guint64 max_size_time;
gboolean post_stream_topology;
guint64 connection_speed;
GstElement *typefind; /* this holds the typefind object */
GMutex expose_lock; /* Protects exposal and removal of groups */
GstDecodeChain *decode_chain; /* Top level decode chain */
guint nbpads; /* unique identifier for source pads */
GMutex factories_lock;
guint32 factories_cookie; /* Cookie from last time when factories was updated */
GList *factories; /* factories we can use for selecting elements */
GMutex subtitle_lock; /* Protects changes to subtitles and encoding */
GList *subtitles; /* List of elements with subtitle-encoding,
* protected by above mutex! */
gboolean have_type; /* if we received the have_type signal */
guint have_type_id; /* signal id for have-type from typefind */
gboolean async_pending; /* async-start has been emitted */
GMutex dyn_lock; /* lock protecting pad blocking */
gboolean shutdown; /* if we are shutting down */
GList *blocked_pads; /* pads that have set to block */
gboolean expose_allstreams; /* Whether to expose unknown type streams or not */
GList *filtered; /* elements for which error messages are filtered */
GList *filtered_errors; /* filtered error messages */
GList *buffering_status; /* element currently buffering messages */
GMutex buffering_lock;
GMutex buffering_post_lock;
GMutex cleanup_lock; /* Mutex used to protect the cleanup thread */
GThread *cleanup_thread; /* thread used to free chains asynchronously.
* We store it to make sure we end up joining it
* before stopping the element.
* Protected by the object lock */
GList *cleanup_groups; /* List of groups to free */
};
struct _GstDecodeBinClass
{
GstBinClass parent_class;
/* signal fired when we found a pad that we cannot decode */
void (*unknown_type) (GstElement * element, GstPad * pad, GstCaps * caps);
/* signal fired to know if we continue trying to decode the given caps */
gboolean (*autoplug_continue) (GstElement * element, GstPad * pad,
GstCaps * caps);
/* signal fired to get a list of factories to try to autoplug */
GValueArray *(*autoplug_factories) (GstElement * element, GstPad * pad,
GstCaps * caps);
/* signal fired to sort the factories */
GValueArray *(*autoplug_sort) (GstElement * element, GstPad * pad,
GstCaps * caps, GValueArray * factories);
/* signal fired to select from the proposed list of factories */
GstAutoplugSelectResult (*autoplug_select) (GstElement * element,
GstPad * pad, GstCaps * caps, GstElementFactory * factory);
/* signal fired when a autoplugged element that is not linked downstream
* or exposed wants to query something */
gboolean (*autoplug_query) (GstElement * element, GstPad * pad,
GstQuery * query);
/* fired when the last group is drained */
void (*drained) (GstElement * element);
};
/* signals */
enum
{
SIGNAL_UNKNOWN_TYPE,
SIGNAL_AUTOPLUG_CONTINUE,
SIGNAL_AUTOPLUG_FACTORIES,
SIGNAL_AUTOPLUG_SELECT,
SIGNAL_AUTOPLUG_SORT,
SIGNAL_AUTOPLUG_QUERY,
SIGNAL_DRAINED,
LAST_SIGNAL
};
/* automatic sizes, while prerolling we buffer up to 2MB, we ignore time
* and buffers in this case. */
#define AUTO_PREROLL_SIZE_BYTES 2 * 1024 * 1024
#define AUTO_PREROLL_SIZE_BUFFERS 0
#define AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME 10 * GST_SECOND
#define AUTO_PREROLL_SEEKABLE_SIZE_TIME 0
/* when playing, keep a max of 2MB of data but try to keep the number of buffers
* as low as possible (try to aim for 5 buffers) */
#define AUTO_PLAY_SIZE_BYTES 2 * 1024 * 1024
#define AUTO_PLAY_SIZE_BUFFERS 5
#define AUTO_PLAY_SIZE_TIME 0
#define DEFAULT_SUBTITLE_ENCODING NULL
#define DEFAULT_USE_BUFFERING FALSE
#define DEFAULT_FORCE_SW_DECODERS FALSE
#define DEFAULT_LOW_PERCENT 10
#define DEFAULT_HIGH_PERCENT 99
/* by default we use the automatic values above */
#define DEFAULT_MAX_SIZE_BYTES 0
#define DEFAULT_MAX_SIZE_BUFFERS 0
#define DEFAULT_MAX_SIZE_TIME 0
#define DEFAULT_POST_STREAM_TOPOLOGY FALSE
#define DEFAULT_EXPOSE_ALL_STREAMS TRUE
#define DEFAULT_CONNECTION_SPEED 0
/* Properties */
enum
{
PROP_0,
PROP_CAPS,
PROP_SUBTITLE_ENCODING,
PROP_SINK_CAPS,
PROP_USE_BUFFERING,
PROP_FORCE_SW_DECODERS,
PROP_LOW_PERCENT,
PROP_HIGH_PERCENT,
PROP_MAX_SIZE_BYTES,
PROP_MAX_SIZE_BUFFERS,
PROP_MAX_SIZE_TIME,
PROP_POST_STREAM_TOPOLOGY,
PROP_EXPOSE_ALL_STREAMS,
PROP_CONNECTION_SPEED
};
static GstBinClass *parent_class;
static guint gst_decode_bin_signals[LAST_SIGNAL] = { 0 };
static GstStaticCaps default_raw_caps = GST_STATIC_CAPS (DEFAULT_RAW_CAPS);
static void do_async_start (GstDecodeBin * dbin);
static void do_async_done (GstDecodeBin * dbin);
static void type_found (GstElement * typefind, guint probability,
GstCaps * caps, GstDecodeBin * decode_bin);
static void decodebin_set_queue_size (GstDecodeBin * dbin,
GstElement * multiqueue, gboolean preroll, gboolean seekable);
static void decodebin_set_queue_size_full (GstDecodeBin * dbin,
GstElement * multiqueue, gboolean use_buffering, gboolean preroll,
gboolean seekable);
static gboolean gst_decode_bin_autoplug_continue (GstElement * element,
GstPad * pad, GstCaps * caps);
static GValueArray *gst_decode_bin_autoplug_factories (GstElement *
element, GstPad * pad, GstCaps * caps);
static GValueArray *gst_decode_bin_autoplug_sort (GstElement * element,
GstPad * pad, GstCaps * caps, GValueArray * factories);
static GstAutoplugSelectResult gst_decode_bin_autoplug_select (GstElement *
element, GstPad * pad, GstCaps * caps, GstElementFactory * factory);
static gboolean gst_decode_bin_autoplug_query (GstElement * element,
GstPad * pad, GstQuery * query);
static void gst_decode_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_decode_bin_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_decode_bin_set_caps (GstDecodeBin * dbin, GstCaps * caps);
static GstCaps *gst_decode_bin_get_caps (GstDecodeBin * dbin);
static void caps_notify_cb (GstPad * pad, GParamSpec * unused,
GstDecodeChain * chain);
static void flush_chain (GstDecodeChain * chain, gboolean flushing);
static void flush_group (GstDecodeGroup * group, gboolean flushing);
static GstPad *find_sink_pad (GstElement * element);
static GstStateChangeReturn gst_decode_bin_change_state (GstElement * element,
GstStateChange transition);
static void gst_decode_bin_handle_message (GstBin * bin, GstMessage * message);
static gboolean gst_decode_bin_remove_element (GstBin * bin,
GstElement * element);
static gboolean check_upstream_seekable (GstDecodeBin * dbin, GstPad * pad);
static GstCaps *get_pad_caps (GstPad * pad);
static void unblock_pads (GstDecodeBin * dbin);
#define EXPOSE_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"expose locking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->expose_lock); \
GST_LOG_OBJECT (dbin, \
"expose locked from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define EXPOSE_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"expose unlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->expose_lock); \
} G_STMT_END
#define DYN_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"dynlocking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
GST_LOG_OBJECT (dbin, \
"dynlocked from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define DYN_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"dynunlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->dyn_lock); \
} G_STMT_END
#define SUBTITLE_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"subtitle locking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
GST_LOG_OBJECT (dbin, \
"subtitle lock from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define SUBTITLE_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"subtitle unlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->subtitle_lock); \
} G_STMT_END
#define BUFFERING_LOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"buffering locking from thread %p", \
g_thread_self ()); \
g_mutex_lock (&GST_DECODE_BIN_CAST(dbin)->buffering_lock); \
GST_LOG_OBJECT (dbin, \
"buffering lock from thread %p", \
g_thread_self ()); \
} G_STMT_END
#define BUFFERING_UNLOCK(dbin) G_STMT_START { \
GST_LOG_OBJECT (dbin, \
"buffering unlocking from thread %p", \
g_thread_self ()); \
g_mutex_unlock (&GST_DECODE_BIN_CAST(dbin)->buffering_lock); \
} G_STMT_END
struct _GstPendingPad
{
GstPad *pad;
GstDecodeChain *chain;
gulong event_probe_id;
gulong notify_caps_id;
};
struct _GstDecodeElement
{
GstElement *element;
GstElement *capsfilter; /* Optional capsfilter for Parser/Convert */
gulong pad_added_id;
gulong pad_removed_id;
gulong no_more_pads_id;
};
struct _GstDemuxerPad
{
GWeakRef weakPad;
gulong event_probe_id;
gulong query_probe_id;
};
/* GstDecodeGroup
*
* Streams belonging to the same group/chain of a media file
*
* When changing something here lock the parent chain!
*/
struct _GstDecodeGroup
{
GstDecodeBin *dbin;
GstDecodeChain *parent;
GstElement *multiqueue; /* Used for linking all child chains */
gulong overrunsig; /* the overrun signal for multiqueue */
gboolean overrun; /* TRUE if the multiqueue signaled overrun. This
* means that we should really expose the group */
gboolean no_more_pads; /* TRUE if the demuxer signaled no-more-pads */
gboolean drained; /* TRUE if the all children are drained */
GList *children; /* List of GstDecodeChains in this group */
GList *demuxer_pad_probe_ids;
GList *reqpads; /* List of RequestPads for multiqueue, there is
* exactly one RequestPad per child chain */
};
struct _GstDecodeChain
{
GstDecodeGroup *parent;
GstDecodeBin *dbin;
gint refs; /* Number of references to this object */
GMutex lock; /* Protects this chain and its groups */
GstPad *pad; /* srcpad that caused creation of this chain */
gulong pad_probe_id; /* id for the demuxer_source_pad_probe probe */
gboolean drained; /* TRUE if the all children are drained */
gboolean demuxer; /* TRUE if elements->data is a demuxer */
gboolean adaptive_demuxer; /* TRUE if elements->data is an adaptive streaming demuxer */
gboolean seekable; /* TRUE if this chain ends on a demuxer and is seekable */
GList *elements; /* All elements in this group, first
is the latest and most downstream element */
/* Note: there are only groups if the last element of this chain
* is a demuxer, otherwise the chain will end with an endpad.
* The other way around this means, that endpad only exists if this
* chain doesn't end with a demuxer! */
GstDecodeGroup *active_group; /* Currently active group */
GList *next_groups; /* head is newest group, tail is next group.
a new group will be created only if the head
group had no-more-pads. If it's only exposed
all new pads will be ignored! */
GList *pending_pads; /* Pads that have no fixed caps yet */
GstDecodePad *current_pad; /* Current ending pad of the chain that can't
* be exposed yet but would be the same as endpad
* once it can be exposed */
GstDecodePad *endpad; /* Pad of this chain that could be exposed */
gboolean deadend; /* This chain is incomplete and can't be completed,
e.g. no suitable decoder could be found
e.g. stream got EOS without buffers
*/
gchar *deadend_details;
GstCaps *endcaps; /* Caps that were used when linking to the endpad
or that resulted in the deadend
*/
/* FIXME: This should be done directly via a thread! */
GList *old_groups; /* Groups that should be freed later */
};
static GstDecodeChain *gst_decode_chain_ref (GstDecodeChain * chain);
static void gst_decode_chain_unref (GstDecodeChain * chain);
static void gst_decode_chain_free (GstDecodeChain * chain);
static GstDecodeChain *gst_decode_chain_new (GstDecodeBin * dbin,
GstDecodeGroup * group, GstPad * pad);
static void gst_decode_group_hide (GstDecodeGroup * group);
static void gst_decode_group_free (GstDecodeGroup * group);
static GstDecodeGroup *gst_decode_group_new (GstDecodeBin * dbin,
GstDecodeChain * chain);
static gboolean gst_decode_chain_is_complete (GstDecodeChain * chain);
static gboolean gst_decode_chain_expose (GstDecodeChain * chain,
GList ** endpads, gboolean * missing_plugin,
GString * missing_plugin_details, gboolean * last_group);
static gboolean gst_decode_chain_is_drained (GstDecodeChain * chain);
static gboolean gst_decode_chain_reset_buffering (GstDecodeChain * chain);
static gboolean gst_decode_group_is_complete (GstDecodeGroup * group);
static GstPad *gst_decode_group_control_demuxer_pad (GstDecodeGroup * group,
GstPad * pad);
static gboolean gst_decode_group_is_drained (GstDecodeGroup * group);
static gboolean gst_decode_group_reset_buffering (GstDecodeGroup * group);
static gboolean gst_decode_bin_expose (GstDecodeBin * dbin);
static void gst_decode_bin_reset_buffering (GstDecodeBin * dbin);
#define CHAIN_MUTEX_LOCK(chain) G_STMT_START { \
GST_LOG_OBJECT (chain->dbin, \
"locking chain %p from thread %p", \
chain, g_thread_self ()); \
g_mutex_lock (&chain->lock); \
GST_LOG_OBJECT (chain->dbin, \
"locked chain %p from thread %p", \
chain, g_thread_self ()); \
} G_STMT_END
#define CHAIN_MUTEX_UNLOCK(chain) G_STMT_START { \
GST_LOG_OBJECT (chain->dbin, \
"unlocking chain %p from thread %p", \
chain, g_thread_self ()); \
g_mutex_unlock (&chain->lock); \
} G_STMT_END
/* GstDecodePad
*
* GstPad private used for source pads of chains
*/
struct _GstDecodePad
{
GstGhostPad parent;
GstDecodeBin *dbin;
GstDecodeChain *chain;
gboolean blocked; /* the *target* pad is blocked */
gboolean exposed; /* the pad is exposed */
gboolean drained; /* an EOS has been seen on the pad */
gulong block_id;
};
GType gst_decode_pad_get_type (void);
G_DEFINE_TYPE (GstDecodePad, gst_decode_pad, GST_TYPE_GHOST_PAD);
#define GST_TYPE_DECODE_PAD (gst_decode_pad_get_type ())
#define GST_DECODE_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECODE_PAD,GstDecodePad))
static GstDecodePad *gst_decode_pad_new (GstDecodeBin * dbin,
GstDecodeChain * chain);
static void gst_decode_pad_activate (GstDecodePad * dpad,
GstDecodeChain * chain);
static void gst_decode_pad_unblock (GstDecodePad * dpad);
static void gst_decode_pad_set_blocked (GstDecodePad * dpad, gboolean blocked);
static gboolean gst_decode_pad_query (GstPad * pad, GstObject * parent,
GstQuery * query);
static gboolean gst_decode_pad_is_exposable (GstDecodePad * endpad);
static void gst_pending_pad_free (GstPendingPad * ppad);
static GstPadProbeReturn pad_event_cb (GstPad * pad, GstPadProbeInfo * info,
gpointer data);
/********************************
* Standard GObject boilerplate *
********************************/
static void gst_decode_bin_dispose (GObject * object);
static void gst_decode_bin_finalize (GObject * object);
/* Register some quarks here for the stream topology message */
static GQuark topology_structure_name = 0;
static GQuark topology_caps = 0;
static GQuark topology_next = 0;
static GQuark topology_pad = 0;
static GQuark topology_element_srcpad = 0;
GType gst_decode_bin_get_type (void);
G_DEFINE_TYPE (GstDecodeBin, gst_decode_bin, GST_TYPE_BIN);
#define _do_init \
GST_DEBUG_CATEGORY_INIT (gst_decode_bin_debug, "decodebin", 0, "decoder bin");\
topology_structure_name = g_quark_from_static_string ("stream-topology"); \
topology_caps = g_quark_from_static_string ("caps");\
topology_next = g_quark_from_static_string ("next");\
topology_pad = g_quark_from_static_string ("pad");\
topology_element_srcpad = g_quark_from_static_string ("element-srcpad");\
playback_element_init (plugin);\
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (decodebin, "decodebin", GST_RANK_NONE,
GST_TYPE_DECODE_BIN, _do_init);
static gboolean
_gst_boolean_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gboolean myboolean;
myboolean = g_value_get_boolean (handler_return);
g_value_set_boolean (return_accu, myboolean);
/* stop emission if FALSE */
return myboolean;
}
static gboolean
_gst_boolean_or_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gboolean myboolean;
gboolean retboolean;
myboolean = g_value_get_boolean (handler_return);
retboolean = g_value_get_boolean (return_accu);
g_value_set_boolean (return_accu, myboolean || retboolean);
return TRUE;
}
/* we collect the first result */
static gboolean
_gst_array_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gpointer array;
array = g_value_get_boxed (handler_return);
g_value_set_boxed (return_accu, array);
return FALSE;
}
static gboolean
_gst_select_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
GstAutoplugSelectResult res;
res = g_value_get_enum (handler_return);
g_value_set_enum (return_accu, res);
/* Call the next handler in the chain (if any) when the current callback
* returns TRY. This makes it possible to register separate autoplug-select
* handlers that implement different TRY/EXPOSE/SKIP strategies.
*/
if (res == GST_AUTOPLUG_SELECT_TRY)
return TRUE;
return FALSE;
}
static gboolean
_gst_array_hasvalue_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gpointer array;
array = g_value_get_boxed (handler_return);
g_value_set_boxed (return_accu, array);
if (array != NULL)
return FALSE;
return TRUE;
}
static void
gst_decode_bin_class_init (GstDecodeBinClass * 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->dispose = gst_decode_bin_dispose;
gobject_klass->finalize = gst_decode_bin_finalize;
gobject_klass->set_property = gst_decode_bin_set_property;
gobject_klass->get_property = gst_decode_bin_get_property;
/**
* GstDecodeBin::unknown-type:
* @bin: The decodebin.
* @pad: The new pad containing caps that cannot be resolved to a 'final'
* stream type.
* @caps: The #GstCaps of the pad that cannot be resolved.
*
* This signal is emitted when a pad for which there is no further possible
* decoding is added to the decodebin.
*/
gst_decode_bin_signals[SIGNAL_UNKNOWN_TYPE] =
g_signal_new ("unknown-type", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, unknown_type),
NULL, NULL, NULL, G_TYPE_NONE, 2, GST_TYPE_PAD, GST_TYPE_CAPS);
/**
* GstDecodeBin::autoplug-continue:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps found.
*
* This signal is emitted whenever decodebin finds a new stream. It is
* emitted before looking for any elements that can handle that stream.
*
* > Invocation of signal handlers stops after the first signal handler
* > returns %FALSE. Signal handlers are invoked in the order they were
* > connected in.
*
* Returns: %TRUE if you wish decodebin to look for elements that can
* handle the given @caps. If %FALSE, those caps will be considered as
* final and the pad will be exposed as such (see 'pad-added' signal of
* #GstElement).
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_CONTINUE] =
g_signal_new ("autoplug-continue", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_continue),
_gst_boolean_accumulator, NULL, NULL, G_TYPE_BOOLEAN, 2, GST_TYPE_PAD,
GST_TYPE_CAPS);
/**
* GstDecodeBin::autoplug-factories:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps found.
*
* This signal is emitted when an array of possible factories for @caps on
* @pad is needed. Decodebin will by default return an array with all
* compatible factories, sorted by rank.
*
* If this function returns NULL, @pad will be exposed as a final caps.
*
* If this function returns an empty array, the pad will be considered as
* having an unhandled type media type.
*
* > Only the signal handler that is connected first will ever by invoked.
* > Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
* > signal, they will never be invoked!
*
* Returns: a #GValueArray* with a list of factories to try. The factories are
* by default tried in the returned order or based on the index returned by
* "autoplug-select".
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_FACTORIES] =
g_signal_new ("autoplug-factories", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass,
autoplug_factories), _gst_array_accumulator, NULL,
NULL, G_TYPE_VALUE_ARRAY, 2, GST_TYPE_PAD, GST_TYPE_CAPS);
/**
* GstDecodeBin::autoplug-sort:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps.
* @factories: A #GValueArray of possible #GstElementFactory to use.
*
* Once decodebin has found the possible #GstElementFactory objects to try
* for @caps on @pad, this signal is emitted. The purpose of the signal is for
* the application to perform additional sorting or filtering on the element
* factory array.
*
* The callee should copy and modify @factories or return %NULL if the
* order should not change.
*
* > Invocation of signal handlers stops after one signal handler has
* > returned something else than %NULL. Signal handlers are invoked in
* > the order they were connected in.
* > Don't connect signal handlers with the #G_CONNECT_AFTER flag to this
* > signal, they will never be invoked!
*
* Returns: A new sorted array of #GstElementFactory objects.
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_SORT] =
g_signal_new ("autoplug-sort", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_sort),
_gst_array_hasvalue_accumulator, NULL,
NULL, G_TYPE_VALUE_ARRAY, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
G_TYPE_VALUE_ARRAY | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GstDecodeBin::autoplug-select:
* @bin: The decodebin.
* @pad: The #GstPad.
* @caps: The #GstCaps.
* @factory: A #GstElementFactory to use.
*
* This signal is emitted once decodebin has found all the possible
* #GstElementFactory that can be used to handle the given @caps. For each of
* those factories, this signal is emitted.
*
* The signal handler should return a #GstAutoplugSelectResult enum
* value indicating what decodebin should do next.
*
* A value of #GstAutoplugSelectResult::try will try to autoplug an element from
* @factory.
*
* A value of #GstAutoplugSelectResult::expose will expose @pad without plugging
* any element to it.
*
* A value of #GstAutoplugSelectResult::skip will skip @factory and move to the
* next factory.
*
* > The signal handler will not be invoked if any of the previously
* > registered signal handlers (if any) return a value other than
* > GST_AUTOPLUG_SELECT_TRY. Which also means that if you return
* > GST_AUTOPLUG_SELECT_TRY from one signal handler, handlers that get
* > registered next (again, if any) can override that decision.
*
* Returns: a #GstAutoplugSelectResult that indicates the required
* operation. the default handler will always return
* #GstAutoplugSelectResult::try.
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_SELECT] =
g_signal_new ("autoplug-select", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_select),
_gst_select_accumulator, NULL,
NULL, GST_TYPE_AUTOPLUG_SELECT_RESULT, 3, GST_TYPE_PAD, GST_TYPE_CAPS,
GST_TYPE_ELEMENT_FACTORY);
/**
* GstDecodeBin::autoplug-query:
* @bin: The decodebin.
* @pad: The #GstPad.
* @child: The child element doing the query
* @query: The #GstQuery.
*
* This signal is emitted whenever an autoplugged element that is
* not linked downstream yet and not exposed does a query. It can
* be used to tell the element about the downstream supported caps
* for example.
*
* Returns: %TRUE if the query was handled, %FALSE otherwise.
*/
gst_decode_bin_signals[SIGNAL_AUTOPLUG_QUERY] =
g_signal_new ("autoplug-query", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, autoplug_query),
_gst_boolean_or_accumulator, NULL, NULL, G_TYPE_BOOLEAN, 3, GST_TYPE_PAD,
GST_TYPE_ELEMENT, GST_TYPE_QUERY | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* GstDecodeBin::drained
* @bin: The decodebin
*
* This signal is emitted once decodebin has finished decoding all the data.
*/
gst_decode_bin_signals[SIGNAL_DRAINED] =
g_signal_new ("drained", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstDecodeBinClass, drained),
NULL, NULL, NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
g_object_class_install_property (gobject_klass, PROP_CAPS,
g_param_spec_boxed ("caps", "Caps", "The caps on which to stop decoding.",
GST_TYPE_CAPS, 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_SINK_CAPS,
g_param_spec_boxed ("sink-caps", "Sink Caps",
"The caps of the input data. (NULL = use typefind element)",
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::use-buffering
*
* Activate buffering in decodebin. This will instruct the multiqueues behind
* decoders to emit BUFFERING messages.
*/
g_object_class_install_property (gobject_klass, PROP_USE_BUFFERING,
g_param_spec_boolean ("use-buffering", "Use Buffering",
"Emit GST_MESSAGE_BUFFERING based on low-/high-percent thresholds",
DEFAULT_USE_BUFFERING, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::force-sw-decoders:
*
* While auto-plugging, if set to %TRUE, those decoders within
* "Hardware" klass will be ignored. Otherwise they will be tried.
*
* Since: 1.18
*/
g_object_class_install_property (gobject_klass, PROP_FORCE_SW_DECODERS,
g_param_spec_boolean ("force-sw-decoders", "Software Docoders Only",
"Use only sofware decoders to process streams",
DEFAULT_FORCE_SW_DECODERS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:low-percent
*
* Low threshold percent for buffering to start.
*/
g_object_class_install_property (gobject_klass, PROP_LOW_PERCENT,
g_param_spec_int ("low-percent", "Low percent",
"Low threshold for buffering to start", 0, 100,
DEFAULT_LOW_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:high-percent
*
* High threshold percent for buffering to finish.
*/
g_object_class_install_property (gobject_klass, PROP_HIGH_PERCENT,
g_param_spec_int ("high-percent", "High percent",
"High threshold for buffering to finish", 0, 100,
DEFAULT_HIGH_PERCENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:max-size-bytes
*
* Max amount of bytes in the queue (0=automatic).
*/
g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BYTES,
g_param_spec_uint ("max-size-bytes", "Max. size (bytes)",
"Max. amount of bytes in the queue (0=automatic)",
0, G_MAXUINT, DEFAULT_MAX_SIZE_BYTES,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:max-size-buffers
*
* Max amount of buffers in the queue (0=automatic).
*/
g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_BUFFERS,
g_param_spec_uint ("max-size-buffers", "Max. size (buffers)",
"Max. number of buffers in the queue (0=automatic)",
0, G_MAXUINT, DEFAULT_MAX_SIZE_BUFFERS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin:max-size-time
*
* Max amount of time in the queue (in ns, 0=automatic).
*/
g_object_class_install_property (gobject_klass, PROP_MAX_SIZE_TIME,
g_param_spec_uint64 ("max-size-time", "Max. size (ns)",
"Max. amount of data in the queue (in ns, 0=automatic)",
0, G_MAXUINT64,
DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::post-stream-topology
*
* Post stream-topology messages on the bus every time the topology changes.
*/
g_object_class_install_property (gobject_klass, PROP_POST_STREAM_TOPOLOGY,
g_param_spec_boolean ("post-stream-topology", "Post Stream Topology",
"Post stream-topology messages",
DEFAULT_POST_STREAM_TOPOLOGY,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin::expose-all-streams
*
* Expose streams of unknown type.
*
* If set to %FALSE, then only the streams that can be decoded to the final
* caps (see 'caps' property) will have a pad exposed. Streams that do not
* match those caps but could have been decoded will not have decoder plugged
* in internally and will not have a pad exposed.
*/
g_object_class_install_property (gobject_klass, PROP_EXPOSE_ALL_STREAMS,
g_param_spec_boolean ("expose-all-streams", "Expose All Streams",
"Expose all streams, including those of unknown type or that don't match the 'caps' property",
DEFAULT_EXPOSE_ALL_STREAMS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* GstDecodeBin2::connection-speed
*
* Network connection speed in kbps (0 = unknownw)
*/
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,