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
|
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
* 2005 Andy Wingo <wingo@pobox.com>
* 2006 Edward Hervey <bilboed@bilboed.com>
*
* gstghostpad.c: Proxy pads
*
* 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:gstghostpad
* @title: GstGhostPad
* @short_description: Pseudo link pads
* @see_also: #GstPad
*
* GhostPads are useful when organizing pipelines with #GstBin like elements.
* The idea here is to create hierarchical element graphs. The bin element
* contains a sub-graph. Now one would like to treat the bin-element like any
* other #GstElement. This is where GhostPads come into play. A GhostPad acts as
* a proxy for another pad. Thus the bin can have sink and source ghost-pads
* that are associated with sink and source pads of the child elements.
*
* If the target pad is known at creation time, gst_ghost_pad_new() is the
* function to use to get a ghost-pad. Otherwise one can use gst_ghost_pad_new_no_target()
* to create the ghost-pad and use gst_ghost_pad_set_target() to establish the
* association later on.
*
* Note that GhostPads add overhead to the data processing of a pipeline.
*/
#include "gst_private.h"
#include "gstinfo.h"
#include "gstghostpad.h"
#include "gst.h"
#define GST_CAT_DEFAULT GST_CAT_PADS
#define GST_PROXY_PAD_CAST(obj) ((GstProxyPad *)obj)
#define GST_PROXY_PAD_PRIVATE(obj) (GST_PROXY_PAD_CAST (obj)->priv)
#define GST_PROXY_PAD_TARGET(pad) (GST_PAD_PEER (GST_PROXY_PAD_INTERNAL (pad)))
#define GST_PROXY_PAD_INTERNAL(pad) (GST_PROXY_PAD_PRIVATE (pad)->internal)
#define GST_PROXY_PAD_ACQUIRE_INTERNAL(pad, internal, retval) \
internal = \
GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad))); \
if (internal == NULL) \
return retval;
#define GST_PROXY_PAD_RELEASE_INTERNAL(internal) gst_object_unref (internal);
struct _GstProxyPadPrivate
{
GstPad *internal;
};
G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
static GstPad *gst_proxy_pad_get_target (GstPad * pad);
/**
* gst_proxy_pad_iterate_internal_links_default:
* @pad: the #GstPad to get the internal links of.
* @parent: (allow-none): the parent of @pad or %NULL
*
* Invoke the default iterate internal links function of the proxy pad.
*
* Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
* has no parent. Unref each returned pad with gst_object_unref().
*/
GstIterator *
gst_proxy_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
{
GstIterator *res = NULL;
GstPad *internal;
GValue v = { 0, };
g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, NULL);
g_value_init (&v, GST_TYPE_PAD);
g_value_take_object (&v, internal);
res = gst_iterator_new_single (GST_TYPE_PAD, &v);
g_value_unset (&v);
return res;
}
/**
* gst_proxy_pad_chain_default:
* @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
* @parent: (allow-none): the parent of @pad or %NULL
* @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
* if not.
*
* Invoke the default chain function of the proxy pad.
*
* Returns: a #GstFlowReturn from the pad.
*/
GstFlowReturn
gst_proxy_pad_chain_default (GstPad * pad, GstObject * parent,
GstBuffer * buffer)
{
GstFlowReturn res;
GstPad *internal;
g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
res = gst_pad_push (internal, buffer);
GST_PROXY_PAD_RELEASE_INTERNAL (internal);
return res;
}
/**
* gst_proxy_pad_chain_list_default:
* @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
* @parent: (allow-none): the parent of @pad or %NULL
* @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
* if not.
*
* Invoke the default chain list function of the proxy pad.
*
* Returns: a #GstFlowReturn from the pad.
*/
GstFlowReturn
gst_proxy_pad_chain_list_default (GstPad * pad, GstObject * parent,
GstBufferList * list)
{
GstFlowReturn res;
GstPad *internal;
g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
res = gst_pad_push_list (internal, list);
GST_PROXY_PAD_RELEASE_INTERNAL (internal);
return res;
}
/**
* gst_proxy_pad_getrange_default:
* @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
* @parent: the parent of @pad
* @offset: The start offset of the buffer
* @size: The length of the buffer
* @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
* returns #GST_FLOW_ERROR if %NULL.
*
* Invoke the default getrange function of the proxy pad.
*
* Returns: a #GstFlowReturn from the pad.
*/
GstFlowReturn
gst_proxy_pad_getrange_default (GstPad * pad, GstObject * parent,
guint64 offset, guint size, GstBuffer ** buffer)
{
GstFlowReturn res;
GstPad *internal;
g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
res = gst_pad_pull_range (internal, offset, size, buffer);
GST_PROXY_PAD_RELEASE_INTERNAL (internal);
return res;
}
static GstPad *
gst_proxy_pad_get_target (GstPad * pad)
{
GstPad *target;
GST_OBJECT_LOCK (pad);
target = gst_pad_get_peer (GST_PROXY_PAD_INTERNAL (pad));
GST_OBJECT_UNLOCK (pad);
return target;
}
/**
* gst_proxy_pad_get_internal:
* @pad: the #GstProxyPad
*
* Get the internal pad of @pad. Unref target pad after usage.
*
* The internal pad of a #GstGhostPad is the internally used
* pad of opposite direction, which is used to link to the target.
*
* Returns: (transfer full) (nullable): the target #GstProxyPad, can
* be %NULL. Unref target pad after usage.
*/
GstProxyPad *
gst_proxy_pad_get_internal (GstProxyPad * pad)
{
GstPad *internal;
g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
GST_OBJECT_LOCK (pad);
internal = GST_PROXY_PAD_INTERNAL (pad);
if (internal)
gst_object_ref (internal);
GST_OBJECT_UNLOCK (pad);
return GST_PROXY_PAD_CAST (internal);
}
static void
gst_proxy_pad_class_init (GstProxyPadClass * klass)
{
g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
/* Register common function pointer descriptions */
GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
}
static void
gst_proxy_pad_init (GstProxyPad * ppad)
{
GstPad *pad = (GstPad *) ppad;
GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
gst_pad_set_iterate_internal_links_function (pad,
gst_proxy_pad_iterate_internal_links_default);
GST_PAD_SET_PROXY_CAPS (pad);
GST_PAD_SET_PROXY_SCHEDULING (pad);
GST_PAD_SET_PROXY_ALLOCATION (pad);
}
/***********************************************************************
* Ghost pads, implemented as a pair of proxy pads (sort of)
*/
#define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
struct _GstGhostPadPrivate
{
/* with PROXY_LOCK */
gboolean constructed;
};
G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
static void gst_ghost_pad_dispose (GObject * object);
static gboolean
gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
gboolean active)
{
gboolean ret;
GstPad *other;
GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
(active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
/* in both cases (SRC and SINK) we activate just the internal pad. The targets
* will be activated later (or already in case of a ghost sinkpad). */
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
GST_PROXY_PAD_RELEASE_INTERNAL (other);
return ret;
}
static gboolean
gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
gboolean active)
{
gboolean ret;
GstPad *other;
GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
GST_DEBUG_PAD_NAME (pad));
if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
/* we are activated in pull mode by our peer element, which is a sinkpad
* that wants to operate in pull mode. This activation has to propagate
* upstream through the pipeline. We call the internal activation function,
* which will trigger gst_ghost_pad_activate_pull_default, which propagates even
* further upstream */
GST_LOG_OBJECT (pad, "pad is src, activate internal");
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
GST_PROXY_PAD_RELEASE_INTERNAL (other);
} else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
/* We are SINK, the ghostpad is SRC, we propagate the activation upstream
* since we hold a pointer to the upstream peer. */
GST_LOG_OBJECT (pad, "activating peer");
ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
gst_object_unref (other);
} else if (active) {
/* this is failure, we can't activate pull if there is no peer */
GST_LOG_OBJECT (pad, "not src and no peer, failing");
ret = FALSE;
} else {
GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
ret = TRUE;
}
return ret;
}
/**
* gst_ghost_pad_internal_activate_mode_default:
* @pad: the #GstPad to activate or deactivate.
* @parent: (allow-none): the parent of @pad or %NULL
* @mode: the requested activation mode
* @active: whether the pad should be active or not.
*
* Invoke the default activate mode function of a proxy pad that is
* owned by a ghost pad.
*
* Returns: %TRUE if the operation was successful.
*/
gboolean
gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
GstPadMode mode, gboolean active)
{
gboolean res;
g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
switch (mode) {
case GST_PAD_MODE_PULL:
res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
break;
case GST_PAD_MODE_PUSH:
res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
break;
default:
GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
res = FALSE;
break;
}
return res;
}
static gboolean
gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
gboolean active)
{
gboolean ret;
GstPad *other;
g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
(active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
/* just activate the internal pad */
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
GST_PROXY_PAD_RELEASE_INTERNAL (other);
return ret;
}
static gboolean
gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
gboolean active)
{
gboolean ret;
GstPad *other;
GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
GST_DEBUG_PAD_NAME (pad));
if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
/* the ghostpad is SRC and activated in pull mode by its peer, call the
* activation function of the internal pad to propagate the activation
* upstream */
GST_LOG_OBJECT (pad, "pad is src, activate internal");
GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
GST_PROXY_PAD_RELEASE_INTERNAL (other);
} else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
/* We are SINK and activated by the internal pad, propagate activation
* upstream because we hold a ref to the upstream peer */
GST_LOG_OBJECT (pad, "activating peer");
ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
gst_object_unref (other);
} else if (active) {
/* this is failure, we can't activate pull if there is no peer */
GST_LOG_OBJECT (pad, "not src and no peer, failing");
ret = FALSE;
} else {
GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
ret = TRUE;
}
return ret;
}
/**
* gst_ghost_pad_activate_mode_default:
* @pad: the #GstPad to activate or deactivate.
* @parent: (allow-none): the parent of @pad or %NULL
* @mode: the requested activation mode
* @active: whether the pad should be active or not.
*
* Invoke the default activate mode function of a ghost pad.
*
* Returns: %TRUE if the operation was successful.
*/
gboolean
gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
GstPadMode mode, gboolean active)
{
gboolean res;
g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
switch (mode) {
case GST_PAD_MODE_PULL:
res = gst_ghost_pad_activate_pull_default (pad, parent, active);
break;
case GST_PAD_MODE_PUSH:
res = gst_ghost_pad_activate_push_default (pad, parent, active);
break;
default:
GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
res = FALSE;
break;
}
return res;
}
static void
gst_ghost_pad_class_init (GstGhostPadClass * klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
gobject_class->dispose = gst_ghost_pad_dispose;
GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
}
static void
gst_ghost_pad_init (GstGhostPad * pad)
{
GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
gst_ghost_pad_activate_mode_default);
}
static void
gst_ghost_pad_dispose (GObject * object)
{
GstPad *pad;
GstPad *internal;
GstPad *peer;
pad = GST_PAD (object);
GST_DEBUG_OBJECT (pad, "dispose");
gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
/* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
* gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
peer = gst_pad_get_peer (pad);
if (peer) {
if (GST_PAD_IS_SRC (pad))
gst_pad_unlink (pad, peer);
else
gst_pad_unlink (peer, pad);
gst_object_unref (peer);
}
GST_OBJECT_LOCK (pad);
internal = GST_PROXY_PAD_INTERNAL (pad);
gst_pad_set_activatemode_function (internal, NULL);
/* disposes of the internal pad, since the ghostpad is the only possible object
* that has a refcount on the internal pad. */
gst_object_unparent (GST_OBJECT_CAST (internal));
GST_PROXY_PAD_INTERNAL (pad) = NULL;
GST_OBJECT_UNLOCK (pad);
G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
}
/**
* gst_ghost_pad_construct:
* @gpad: the newly allocated ghost pad
*
* Finish initialization of a newly allocated ghost pad.
*
* This function is most useful in language bindings and when subclassing
* #GstGhostPad; plugin and application developers normally will not call this
* function. Call this function directly after a call to g_object_new
* (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
*
* Returns: %TRUE if the construction succeeds, %FALSE otherwise.
*/
gboolean
gst_ghost_pad_construct (GstGhostPad * gpad)
{
GstPadDirection dir, otherdir;
GstPadTemplate *templ;
GstPad *pad, *internal;
g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
g_return_val_if_fail (!GST_GHOST_PAD_PRIVATE (gpad)->constructed, FALSE);
g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
pad = GST_PAD (gpad);
/* Set directional padfunctions for ghostpad */
if (dir == GST_PAD_SINK) {
gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
} else {
gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
}
/* INTERNAL PAD, it always exists and is child of the ghostpad */
otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
if (templ) {
internal =
g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
"direction", otherdir, "template", templ, NULL);
/* release ref obtained via g_object_get */
gst_object_unref (templ);
} else {
internal =
g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
"direction", otherdir, NULL);
}
GST_PAD_UNSET_FLUSHING (internal);
/* Set directional padfunctions for internal pad */
if (dir == GST_PAD_SRC) {
gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
gst_pad_set_chain_list_function (internal,
gst_proxy_pad_chain_list_default);
} else {
gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
}
GST_OBJECT_LOCK (pad);
/* now make the ghostpad a parent of the internal pad */
if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
GST_OBJECT_CAST (pad)))
goto parent_failed;
/* The ghostpad is the parent of the internal pad and is the only object that
* can have a refcount on the internal pad.
* At this point, the GstGhostPad has a refcount of 1, and the internal pad has
* a refcount of 1.
* When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
* its refcount on the internal pad in the dispose method by un-parenting it.
* This is why we don't take extra refcounts in the assignments below
*/
GST_PROXY_PAD_INTERNAL (pad) = internal;
GST_PROXY_PAD_INTERNAL (internal) = pad;
/* special activation functions for the internal pad */
gst_pad_set_activatemode_function (internal,
gst_ghost_pad_internal_activate_mode_default);
GST_OBJECT_UNLOCK (pad);
GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
return TRUE;
/* ERRORS */
parent_failed:
{
GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
GST_DEBUG_PAD_NAME (internal));
g_critical ("Could not set internal pad %s:%s",
GST_DEBUG_PAD_NAME (internal));
GST_OBJECT_UNLOCK (pad);
gst_object_unref (internal);
return FALSE;
}
}
static GstPad *
gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
GstPadTemplate * templ)
{
GstGhostPad *ret;
g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
/* OBJECT CREATION */
if (templ) {
ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
"direction", dir, "template", templ, NULL);
} else {
ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
"direction", dir, NULL);
}
if (!gst_ghost_pad_construct (ret))
goto construct_failed;
return GST_PAD_CAST (ret);
construct_failed:
/* already logged */
gst_object_unref (ret);
return NULL;
}
/**
* gst_ghost_pad_new_no_target:
* @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
* @dir: the direction of the ghostpad
*
* Create a new ghostpad without a target with the given direction.
* A target can be set on the ghostpad later with the
* gst_ghost_pad_set_target() function.
*
* The created ghostpad will not have a padtemplate.
*
* Returns: (transfer full) (nullable): a new #GstPad, or %NULL in
* case of an error.
*/
GstPad *
gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
{
GstPad *ret;
g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
ret = gst_ghost_pad_new_full (name, dir, NULL);
return ret;
}
/**
* gst_ghost_pad_new:
* @name: (allow-none): the name of the new pad, or %NULL to assign a default name
* @target: (transfer none): the pad to ghost.
*
* Create a new ghostpad with @target as the target. The direction will be taken
* from the target pad. @target must be unlinked.
*
* Will ref the target.
*
* Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
* case of an error.
*/
GstPad *
gst_ghost_pad_new (const gchar * name, GstPad * target)
{
GstPad *ret;
g_return_val_if_fail (GST_IS_PAD (target), NULL);
g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
GST_DEBUG_PAD_NAME (target));
if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
goto set_target_failed;
return ret;
/* ERRORS */
set_target_failed:
{
GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
GST_DEBUG_PAD_NAME (target));
gst_object_unref (ret);
return NULL;
}
}
/**
* gst_ghost_pad_new_from_template:
* @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
* @target: (transfer none): the pad to ghost.
* @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
*
* Create a new ghostpad with @target as the target. The direction will be taken
* from the target pad. The template used on the ghostpad will be @template.
*
* Will ref the target.
*
* Returns: (transfer full) (nullable): a new #GstPad, or %NULL in
* case of an error.
*/
GstPad *
gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
GstPadTemplate * templ)
{
GstPad *ret;
g_return_val_if_fail (GST_IS_PAD (target), NULL);
g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
g_return_val_if_fail (templ != NULL, NULL);
g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
GST_PAD_DIRECTION (target), NULL);
GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
GST_DEBUG_PAD_NAME (target), templ);
if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
goto set_target_failed;
return ret;
/* ERRORS */
set_target_failed:
{
GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
GST_DEBUG_PAD_NAME (target));
gst_object_unref (ret);
return NULL;
}
}
/**
* gst_ghost_pad_new_no_target_from_template:
* @name: (allow-none): the name of the new pad, or %NULL to assign a default name
* @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
*
* Create a new ghostpad based on @templ, without setting a target. The
* direction will be taken from the @templ.
*
* Returns: (transfer full) (nullable): a new #GstPad, or %NULL in
* case of an error.
*/
GstPad *
gst_ghost_pad_new_no_target_from_template (const gchar * name,
GstPadTemplate * templ)
{
GstPad *ret;
g_return_val_if_fail (templ != NULL, NULL);
ret =
gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
return ret;
}
/**
* gst_ghost_pad_get_target:
* @gpad: the #GstGhostPad
*
* Get the target pad of @gpad. Unref target pad after usage.
*
* Returns: (transfer full) (nullable): the target #GstPad, can be
* %NULL if the ghostpad has no target set. Unref target pad after
* usage.
*/
GstPad *
gst_ghost_pad_get_target (GstGhostPad * gpad)
{
GstPad *ret;
g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
return ret;
}
/**
* gst_ghost_pad_set_target:
* @gpad: the #GstGhostPad
* @newtarget: (transfer none) (allow-none): the new pad target
*
* Set the new target of the ghostpad @gpad. Any existing target
* is unlinked and links to the new target are established. if @newtarget is
* %NULL the target will be cleared.
*
* Returns: %TRUE if the new target could be set. This function
* can return %FALSE when the internal pads could not be linked.
*/
gboolean
gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
{
GstPad *internal;
GstPad *oldtarget;
GstPadLinkReturn lret;
g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
GST_OBJECT_LOCK (gpad);
internal = GST_PROXY_PAD_INTERNAL (gpad);
if (newtarget)
GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
else
GST_DEBUG_OBJECT (gpad, "clearing target");
/* clear old target */
if ((oldtarget = gst_pad_get_peer (internal))) {
GST_OBJECT_UNLOCK (gpad);
/* unlink internal pad */
if (GST_PAD_IS_SRC (internal))
gst_pad_unlink (internal, oldtarget);
else
gst_pad_unlink (oldtarget, internal);
gst_object_unref (oldtarget);
} else {
GST_OBJECT_UNLOCK (gpad);
}
if (newtarget) {
/* and link to internal pad without any checks */
GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
GST_PTR_FORMAT, newtarget);
if (GST_PAD_IS_SRC (internal))
lret =
gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
else
lret =
gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
if (lret != GST_PAD_LINK_OK)
goto link_failed;
}
return TRUE;
/* ERRORS */
link_failed:
{
GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%s",
gst_pad_link_get_name (lret));
return FALSE;
}
}
|