forked from Pichuga/gstreamer0.10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgstpad.c
5739 lines (4944 loc) · 161 KB
/
gstpad.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) 1999,2000 Erik Walthinsen <[email protected]>
* 2000 Wim Taymans <[email protected]>
*
* gstpad.c: Pads for linking elements together
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* SECTION:gstpad
* @short_description: Object contained by elements that allows links to
* other elements
* @see_also: #GstPadTemplate, #GstElement, #GstEvent
*
* A #GstElement is linked to other elements via "pads", which are extremely
* light-weight generic link points.
* After two pads are retrieved from an element with gst_element_get_pad(),
* the pads can be link with gst_pad_link(). (For quick links,
* you can also use gst_element_link(), which will make the obvious
* link for you if it's straightforward.)
*
* Pads are typically created from a #GstPadTemplate with
* gst_pad_new_from_template().
*
* Pads have #GstCaps attached to it to describe the media type they are
* capable of dealing with. gst_pad_get_caps() and gst_pad_set_caps() are
* used to manipulate the caps of the pads.
* Pads created from a pad template cannot set capabilities that are
* incompatible with the pad template capabilities.
*
* Pads without pad templates can be created with gst_pad_new(),
* which takes a direction and a name as an argument. If the name is NULL,
* then a guaranteed unique name will be assigned to it.
*
* gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
*
* A #GstElement creating a pad will typically use the various
* gst_pad_set_*_function() calls to register callbacks for various events
* on the pads.
*
* GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
* or pull in a buffer.
*
* To send a #GstEvent on a pad, use gst_pad_send_event() and
* gst_pad_push_event().
*
* Last reviewed on 2006-07-06 (0.10.9)
*/
/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
* with newer GLib versions (>= 2.31.0) */
#define GLIB_DISABLE_DEPRECATION_WARNINGS
#include "gst_private.h"
#include "gstpad.h"
#include "gstpadtemplate.h"
#include "gstenumtypes.h"
#include "gstmarshal.h"
#include "gstutils.h"
#include "gstinfo.h"
#include "gsterror.h"
#include "gstvalue.h"
#include "glib-compat-private.h"
GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
#define GST_CAT_DEFAULT GST_CAT_PADS
/* Pad signals and args */
enum
{
PAD_LINKED,
PAD_UNLINKED,
PAD_REQUEST_LINK,
PAD_HAVE_DATA,
/* FILL ME */
LAST_SIGNAL
};
enum
{
PAD_PROP_0,
PAD_PROP_CAPS,
PAD_PROP_DIRECTION,
PAD_PROP_TEMPLATE,
/* FILL ME */
};
typedef struct _GstPadPushCache GstPadPushCache;
struct _GstPadPushCache
{
GstPad *peer; /* reffed peer pad */
GstCaps *caps; /* caps for this link */
};
static GstPadPushCache _pad_cache_invalid = { NULL, };
#define PAD_CACHE_INVALID (&_pad_cache_invalid)
#define GST_PAD_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
#define GST_PAD_CHAINLISTFUNC(pad) ((pad)->abidata.ABI.priv->chainlistfunc)
struct _GstPadPrivate
{
GstPadChainListFunction chainlistfunc;
GstPadPushCache *cache_ptr;
};
static void gst_pad_dispose (GObject * object);
static void gst_pad_finalize (GObject * object);
static void gst_pad_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_pad_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstFlowReturn handle_pad_block (GstPad * pad);
static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
static gboolean gst_pad_activate_default (GstPad * pad);
static gboolean gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps);
#if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
#ifdef GST_DISABLE_DEPRECATED
#include <libxml/parser.h>
#endif
static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
void gst_pad_load_and_link (xmlNodePtr self, GstObject * parent);
#endif
/* Some deprecated stuff that we need inside here for
* backwards compatibility */
#ifdef GST_DISABLE_DEPRECATED
#ifndef GST_REMOVE_DEPRECATED
#define GST_PAD_INTLINKFUNC(pad) (GST_PAD_CAST(pad)->intlinkfunc)
GList *gst_pad_get_internal_links_default (GstPad * pad);
#endif
#endif
static GstObjectClass *parent_class = NULL;
static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
static GParamSpec *pspec_caps = NULL;
/* quarks for probe signals */
static GQuark buffer_quark;
static GQuark event_quark;
typedef struct
{
const gint ret;
const gchar *name;
GQuark quark;
} GstFlowQuarks;
static GstFlowQuarks flow_quarks[] = {
{GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
{GST_FLOW_RESEND, "resend", 0},
{GST_FLOW_OK, "ok", 0},
{GST_FLOW_NOT_LINKED, "not-linked", 0},
{GST_FLOW_WRONG_STATE, "wrong-state", 0},
{GST_FLOW_UNEXPECTED, "unexpected", 0},
{GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
{GST_FLOW_ERROR, "error", 0},
{GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
{GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
};
/**
* gst_flow_get_name:
* @ret: a #GstFlowReturn to get the name of.
*
* Gets a string representing the given flow return.
*
* Returns: a static string with the name of the flow return.
*/
const gchar *
gst_flow_get_name (GstFlowReturn ret)
{
gint i;
ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
if (ret == flow_quarks[i].ret)
return flow_quarks[i].name;
}
return "unknown";
}
/**
* gst_flow_to_quark:
* @ret: a #GstFlowReturn to get the quark of.
*
* Get the unique quark for the given GstFlowReturn.
*
* Returns: the quark associated with the flow return or 0 if an
* invalid return was specified.
*/
GQuark
gst_flow_to_quark (GstFlowReturn ret)
{
gint i;
ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
if (ret == flow_quarks[i].ret)
return flow_quarks[i].quark;
}
return 0;
}
#define _do_init \
{ \
gint i; \
\
buffer_quark = g_quark_from_static_string ("buffer"); \
event_quark = g_quark_from_static_string ("event"); \
\
for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
} \
\
GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
}
G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
static gboolean
_gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
GValue * return_accu, const GValue * handler_return, gpointer dummy)
{
gboolean ret = g_value_get_boolean (handler_return);
GST_DEBUG ("accumulated %d", ret);
g_value_set_boolean (return_accu, ret);
return ret;
}
static gboolean
default_have_data (GstPad * pad, GstMiniObject * o)
{
return TRUE;
}
static void
gst_pad_class_init (GstPadClass * klass)
{
GObjectClass *gobject_class;
GstObjectClass *gstobject_class;
gobject_class = G_OBJECT_CLASS (klass);
gstobject_class = GST_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (GstPadPrivate));
parent_class = g_type_class_peek_parent (klass);
gobject_class->dispose = gst_pad_dispose;
gobject_class->finalize = gst_pad_finalize;
gobject_class->set_property = gst_pad_set_property;
gobject_class->get_property = gst_pad_get_property;
/**
* GstPad::linked:
* @pad: the pad that emitted the signal
* @peer: the peer pad that has been connected
*
* Signals that a pad has been linked to the peer pad.
*/
gst_pad_signals[PAD_LINKED] =
g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
/**
* GstPad::unlinked:
* @pad: the pad that emitted the signal
* @peer: the peer pad that has been disconnected
*
* Signals that a pad has been unlinked from the peer pad.
*/
gst_pad_signals[PAD_UNLINKED] =
g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
/**
* GstPad::request-link:
* @pad: the pad that emitted the signal
* @peer: the peer pad for which a connection is requested
*
* Signals that a pad connection has been requested.
*/
gst_pad_signals[PAD_REQUEST_LINK] =
g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
/**
* GstPad::have-data:
* @pad: the pad that emitted the signal
* @mini_obj: new data
*
* Signals that new data is available on the pad. This signal is used
* internally for implementing pad probes.
* See gst_pad_add_*_probe functions.
*
* Returns: %TRUE to keep the data, %FALSE to drop it
*/
gst_pad_signals[PAD_HAVE_DATA] =
g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
G_STRUCT_OFFSET (GstPadClass, have_data),
_gst_do_pass_data_accumulator,
NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
GST_TYPE_MINI_OBJECT);
pspec_caps = g_param_spec_boxed ("caps", "Caps",
"The capabilities of the pad", GST_TYPE_CAPS,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
g_param_spec_enum ("direction", "Direction", "The direction of the pad",
GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
/* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
g_param_spec_object ("template", "Template",
"The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
#if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
gstobject_class->save_thyself =
((gpointer (*)(GstObject * object,
gpointer self)) * GST_DEBUG_FUNCPTR (gst_pad_save_thyself));
#endif
gstobject_class->path_string_separator = ".";
/* Register common function pointer descriptions */
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_query_types_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
#ifndef GST_REMOVE_DEPRECATED
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_internal_links_default);
#endif
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_acceptcaps_default);
/* from gstutils.c */
GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_fixed_caps_func);
klass->have_data = default_have_data;
}
static void
gst_pad_init (GstPad * pad)
{
pad->abidata.ABI.priv = GST_PAD_GET_PRIVATE (pad);
GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
GST_PAD_PEER (pad) = NULL;
GST_PAD_CHAINFUNC (pad) = NULL;
GST_PAD_LINKFUNC (pad) = NULL;
GST_PAD_CAPS (pad) = NULL;
GST_PAD_GETCAPSFUNC (pad) = NULL;
GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
GST_PAD_QUERYTYPEFUNC (pad) = gst_pad_get_query_types_default;
GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
#ifndef GST_REMOVE_DEPRECATED
GST_PAD_INTLINKFUNC (pad) = gst_pad_get_internal_links_default;
#endif
GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
GST_PAD_ACCEPTCAPSFUNC (pad) = gst_pad_acceptcaps_default;
pad->do_buffer_signals = 0;
pad->do_event_signals = 0;
GST_PAD_SET_FLUSHING (pad);
pad->preroll_lock = g_mutex_new ();
pad->preroll_cond = g_cond_new ();
/* FIXME 0.11: Store this directly in the instance struct */
pad->stream_rec_lock = g_slice_new (GStaticRecMutex);
g_static_rec_mutex_init (pad->stream_rec_lock);
pad->block_cond = g_cond_new ();
}
static void
gst_pad_dispose (GObject * object)
{
GstPad *pad = GST_PAD_CAST (object);
GstPad *peer;
GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
/* unlink the peer pad */
if ((peer = gst_pad_get_peer (pad))) {
/* window for MT unsafeness, someone else could unlink here
* and then we call unlink with wrong pads. The unlink
* function would catch this and safely return failed. */
if (GST_PAD_IS_SRC (pad))
gst_pad_unlink (pad, peer);
else
gst_pad_unlink (peer, pad);
gst_object_unref (peer);
}
/* clear the caps */
gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
gst_pad_set_pad_template (pad, NULL);
if (pad->block_destroy_data && pad->block_data) {
pad->block_destroy_data (pad->block_data);
pad->block_data = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gst_pad_finalize (GObject * object)
{
GstPad *pad = GST_PAD_CAST (object);
GstTask *task;
/* in case the task is still around, clean it up */
if ((task = GST_PAD_TASK (pad))) {
gst_task_join (task);
GST_PAD_TASK (pad) = NULL;
gst_object_unref (task);
}
if (pad->stream_rec_lock) {
g_static_rec_mutex_free (pad->stream_rec_lock);
g_slice_free (GStaticRecMutex, pad->stream_rec_lock);
pad->stream_rec_lock = NULL;
}
if (pad->preroll_lock) {
g_mutex_free (pad->preroll_lock);
g_cond_free (pad->preroll_cond);
pad->preroll_lock = NULL;
pad->preroll_cond = NULL;
}
if (pad->block_cond) {
g_cond_free (pad->block_cond);
pad->block_cond = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_pad_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
g_return_if_fail (GST_IS_PAD (object));
switch (prop_id) {
case PAD_PROP_DIRECTION:
GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
break;
case PAD_PROP_TEMPLATE:
gst_pad_set_pad_template (GST_PAD_CAST (object),
(GstPadTemplate *) g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_pad_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
g_return_if_fail (GST_IS_PAD (object));
switch (prop_id) {
case PAD_PROP_CAPS:
GST_OBJECT_LOCK (object);
g_value_set_boxed (value, GST_PAD_CAPS (object));
GST_OBJECT_UNLOCK (object);
break;
case PAD_PROP_DIRECTION:
g_value_set_enum (value, GST_PAD_DIRECTION (object));
break;
case PAD_PROP_TEMPLATE:
g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* gst_pad_new:
* @name: the name of the new pad.
* @direction: the #GstPadDirection of the pad.
*
* Creates a new pad with the given name in the given direction.
* If name is NULL, a guaranteed unique name (across all pads)
* will be assigned.
* This function makes a copy of the name so you can safely free the name.
*
* Returns: (transfer full): a new #GstPad, or NULL in case of an error.
*
* MT safe.
*/
GstPad *
gst_pad_new (const gchar * name, GstPadDirection direction)
{
return g_object_new (GST_TYPE_PAD,
"name", name, "direction", direction, NULL);
}
/**
* gst_pad_new_from_template:
* @templ: the pad template to use
* @name: the name of the element
*
* Creates a new pad with the given name from the given template.
* If name is NULL, a guaranteed unique name (across all pads)
* will be assigned.
* This function makes a copy of the name so you can safely free the name.
*
* Returns: (transfer full): a new #GstPad, or NULL in case of an error.
*/
GstPad *
gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
{
g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
return g_object_new (GST_TYPE_PAD,
"name", name, "direction", templ->direction, "template", templ, NULL);
}
/**
* gst_pad_new_from_static_template:
* @templ: the #GstStaticPadTemplate to use
* @name: the name of the element
*
* Creates a new pad with the given name from the given static template.
* If name is NULL, a guaranteed unique name (across all pads)
* will be assigned.
* This function makes a copy of the name so you can safely free the name.
*
* Returns: (transfer full): a new #GstPad, or NULL in case of an error.
*/
GstPad *
gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
const gchar * name)
{
GstPad *pad;
GstPadTemplate *template;
template = gst_static_pad_template_get (templ);
pad = gst_pad_new_from_template (template, name);
gst_object_unref (template);
return pad;
}
/**
* gst_pad_get_direction:
* @pad: a #GstPad to get the direction of.
*
* Gets the direction of the pad. The direction of the pad is
* decided at construction time so this function does not take
* the LOCK.
*
* Returns: the #GstPadDirection of the pad.
*
* MT safe.
*/
GstPadDirection
gst_pad_get_direction (GstPad * pad)
{
GstPadDirection result;
/* PAD_UNKNOWN is a little silly but we need some sort of
* error return value */
g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
result = GST_PAD_DIRECTION (pad);
return result;
}
static gboolean
gst_pad_activate_default (GstPad * pad)
{
return gst_pad_activate_push (pad, TRUE);
}
static void
pre_activate (GstPad * pad, GstActivateMode new_mode)
{
switch (new_mode) {
case GST_ACTIVATE_PUSH:
case GST_ACTIVATE_PULL:
GST_OBJECT_LOCK (pad);
GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
new_mode);
GST_PAD_UNSET_FLUSHING (pad);
GST_PAD_ACTIVATE_MODE (pad) = new_mode;
GST_OBJECT_UNLOCK (pad);
break;
case GST_ACTIVATE_NONE:
GST_OBJECT_LOCK (pad);
GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
_priv_gst_pad_invalidate_cache (pad);
GST_PAD_SET_FLUSHING (pad);
GST_PAD_ACTIVATE_MODE (pad) = new_mode;
/* unlock blocked pads so element can resume and stop */
GST_PAD_BLOCK_BROADCAST (pad);
GST_OBJECT_UNLOCK (pad);
break;
}
}
static void
post_activate (GstPad * pad, GstActivateMode new_mode)
{
switch (new_mode) {
case GST_ACTIVATE_PUSH:
case GST_ACTIVATE_PULL:
/* nop */
break;
case GST_ACTIVATE_NONE:
/* ensures that streaming stops */
GST_PAD_STREAM_LOCK (pad);
GST_DEBUG_OBJECT (pad, "stopped streaming");
GST_PAD_STREAM_UNLOCK (pad);
break;
}
}
/**
* gst_pad_set_active:
* @pad: the #GstPad to activate or deactivate.
* @active: whether or not the pad should be active.
*
* Activates or deactivates the given pad.
* Normally called from within core state change functions.
*
* If @active, makes sure the pad is active. If it is already active, either in
* push or pull mode, just return. Otherwise dispatches to the pad's activate
* function to perform the actual activation.
*
* If not @active, checks the pad's current mode and calls
* gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
* FALSE argument.
*
* Returns: #TRUE if the operation was successful.
*
* MT safe.
*/
gboolean
gst_pad_set_active (GstPad * pad, gboolean active)
{
GstActivateMode old;
gboolean ret = FALSE;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
GST_OBJECT_LOCK (pad);
old = GST_PAD_ACTIVATE_MODE (pad);
GST_OBJECT_UNLOCK (pad);
if (active) {
switch (old) {
case GST_ACTIVATE_PUSH:
GST_DEBUG_OBJECT (pad, "activating pad from push");
ret = TRUE;
break;
case GST_ACTIVATE_PULL:
GST_DEBUG_OBJECT (pad, "activating pad from pull");
ret = TRUE;
break;
case GST_ACTIVATE_NONE:
GST_DEBUG_OBJECT (pad, "activating pad from none");
ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
break;
}
} else {
switch (old) {
case GST_ACTIVATE_PUSH:
GST_DEBUG_OBJECT (pad, "deactivating pad from push");
ret = gst_pad_activate_push (pad, FALSE);
break;
case GST_ACTIVATE_PULL:
GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
ret = gst_pad_activate_pull (pad, FALSE);
break;
case GST_ACTIVATE_NONE:
GST_DEBUG_OBJECT (pad, "deactivating pad from none");
ret = TRUE;
break;
}
}
if (!ret) {
GST_OBJECT_LOCK (pad);
if (!active) {
g_critical ("Failed to deactivate pad %s:%s, very bad",
GST_DEBUG_PAD_NAME (pad));
} else {
GST_WARNING_OBJECT (pad, "Failed to activate pad");
}
GST_OBJECT_UNLOCK (pad);
}
return ret;
}
/**
* gst_pad_activate_pull:
* @pad: the #GstPad to activate or deactivate.
* @active: whether or not the pad should be active.
*
* Activates or deactivates the given pad in pull mode via dispatching to the
* pad's activatepullfunc. For use from within pad activation functions only.
* When called on sink pads, will first proxy the call to the peer pad, which
* is expected to activate its internally linked pads from within its
* activate_pull function.
*
* If you don't know what this is, you probably don't want to call it.
*
* Returns: TRUE if the operation was successful.
*
* MT safe.
*/
gboolean
gst_pad_activate_pull (GstPad * pad, gboolean active)
{
GstActivateMode old, new;
GstPad *peer;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
GST_OBJECT_LOCK (pad);
old = GST_PAD_ACTIVATE_MODE (pad);
GST_OBJECT_UNLOCK (pad);
if (active) {
switch (old) {
case GST_ACTIVATE_PULL:
GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
goto was_ok;
case GST_ACTIVATE_PUSH:
GST_DEBUG_OBJECT (pad,
"activating pad from push, deactivate push first");
/* pad was activate in the wrong direction, deactivate it
* and reactivate it in pull mode */
if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
goto deactivate_failed;
/* fallthrough, pad is deactivated now. */
case GST_ACTIVATE_NONE:
GST_DEBUG_OBJECT (pad, "activating pad from none");
break;
}
} else {
switch (old) {
case GST_ACTIVATE_NONE:
GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
goto was_ok;
case GST_ACTIVATE_PUSH:
GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
/* pad was activated in the other direction, deactivate it
* in push mode, this should not happen... */
if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
goto deactivate_failed;
/* everything is fine now */
goto was_ok;
case GST_ACTIVATE_PULL:
GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
break;
}
}
if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
if ((peer = gst_pad_get_peer (pad))) {
GST_DEBUG_OBJECT (pad, "calling peer");
if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
goto peer_failed;
gst_object_unref (peer);
} else {
/* there is no peer, this is only fatal when we activate. When we
* deactivate, we must assume the application has unlinked the peer and
* will deactivate it eventually. */
if (active)
goto not_linked;
else
GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
}
} else {
if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
goto failure; /* Can't activate pull on a src without a
getrange function */
}
new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
pre_activate (pad, new);
if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
goto failure;
} else {
/* can happen for sinks of passthrough elements */
}
post_activate (pad, new);
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
active ? "activated" : "deactivated");
return TRUE;
was_ok:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
active ? "activated" : "deactivated");
return TRUE;
}
deactivate_failed:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
"failed to %s in switch to pull from mode %d",
(active ? "activate" : "deactivate"), old);
return FALSE;
}
peer_failed:
{
GST_OBJECT_LOCK (peer);
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
"activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
GST_OBJECT_UNLOCK (peer);
gst_object_unref (peer);
return FALSE;
}
not_linked:
{
GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
"pad in pull mode");
return FALSE;
}
failure:
{
GST_OBJECT_LOCK (pad);
GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
active ? "activate" : "deactivate");
_priv_gst_pad_invalidate_cache (pad);
GST_PAD_SET_FLUSHING (pad);
GST_PAD_ACTIVATE_MODE (pad) = old;
GST_OBJECT_UNLOCK (pad);
return FALSE;
}
}
/**
* gst_pad_activate_push:
* @pad: the #GstPad to activate or deactivate.
* @active: whether the pad should be active or not.
*
* Activates or deactivates the given pad in push mode via dispatching to the
* pad's activatepushfunc. For use from within pad activation functions only.
*
* If you don't know what this is, you probably don't want to call it.
*
* Returns: %TRUE if the operation was successful.
*
* MT safe.
*/
gboolean
gst_pad_activate_push (GstPad * pad, gboolean active)
{
GstActivateMode old, new;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
active ? "activated" : "deactivated");
GST_OBJECT_LOCK (pad);
old = GST_PAD_ACTIVATE_MODE (pad);
GST_OBJECT_UNLOCK (pad);
if (active) {
switch (old) {
case GST_ACTIVATE_PUSH:
GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
goto was_ok;
case GST_ACTIVATE_PULL:
GST_DEBUG_OBJECT (pad,
"activating pad from push, deactivating pull first");
/* pad was activate in the wrong direction, deactivate it
* an reactivate it in push mode */
if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
goto deactivate_failed;
/* fallthrough, pad is deactivated now. */
case GST_ACTIVATE_NONE:
GST_DEBUG_OBJECT (pad, "activating pad from none");
break;
}
} else {
switch (old) {
case GST_ACTIVATE_NONE:
GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
goto was_ok;
case GST_ACTIVATE_PULL:
GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
/* pad was activated in the other direction, deactivate it
* in pull mode, this should not happen... */
if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
goto deactivate_failed;
/* everything is fine now */
goto was_ok;
case GST_ACTIVATE_PUSH:
GST_DEBUG_OBJECT (pad, "deactivating pad from push");
break;
}
}
new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
pre_activate (pad, new);
if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
goto failure;
}
} else {
/* quite ok, element relies on state change func to prepare itself */
}
post_activate (pad, new);
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
active ? "activated" : "deactivated");
return TRUE;
was_ok:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
active ? "activated" : "deactivated");
return TRUE;
}
deactivate_failed:
{
GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
"failed to %s in switch to push from mode %d",
(active ? "activate" : "deactivate"), old);
return FALSE;
}
failure:
{
GST_OBJECT_LOCK (pad);
GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
active ? "activate" : "deactivate");
_priv_gst_pad_invalidate_cache (pad);
GST_PAD_SET_FLUSHING (pad);
GST_PAD_ACTIVATE_MODE (pad) = old;
GST_OBJECT_UNLOCK (pad);
return FALSE;
}
}
/**
* gst_pad_is_active:
* @pad: the #GstPad to query
*
* Query if a pad is active
*