• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * GStreamer
4  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include <gst/gst.h>
27 
28 #include "gstglelements.h"
29 #include "gstglmixerbin.h"
30 
31 #define GST_CAT_DEFAULT gst_gl_mixer_bin_debug
32 GST_DEBUG_CATEGORY (gst_gl_mixer_bin_debug);
33 
34 #define DEFAULT_LATENCY        0
35 #define DEFAULT_START_TIME_SELECTION 0
36 #define DEFAULT_START_TIME           (-1)
37 
38 typedef enum
39 {
40   GST_GL_MIXER_BIN_START_TIME_SELECTION_ZERO,
41   GST_GL_MIXER_BIN_START_TIME_SELECTION_FIRST,
42   GST_GL_MIXER_BIN_START_TIME_SELECTION_SET
43 } GstGLMixerBinStartTimeSelection;
44 
45 #define GST_TYPE_GL_MIXER_BIN_START_TIME_SELECTION (gst_gl_mixer_bin_start_time_selection_get_type())
46 static GType
gst_gl_mixer_bin_start_time_selection_get_type(void)47 gst_gl_mixer_bin_start_time_selection_get_type (void)
48 {
49   static GType gtype = 0;
50 
51   if (gtype == 0) {
52     static const GEnumValue values[] = {
53       {GST_GL_MIXER_BIN_START_TIME_SELECTION_ZERO,
54           "Start at 0 running time (default)", "zero"},
55       {GST_GL_MIXER_BIN_START_TIME_SELECTION_FIRST,
56           "Start at first observed input running time", "first"},
57       {GST_GL_MIXER_BIN_START_TIME_SELECTION_SET,
58           "Set start time with start-time property", "set"},
59       {0, NULL, NULL}
60     };
61 
62     gtype = g_enum_register_static ("GstGLMixerBinStartTimeSelection", values);
63   }
64   return gtype;
65 }
66 
67 struct input_chain
68 {
69   GstGLMixerBin *self;
70   GstGhostPad *ghost_pad;
71   GstElement *upload;
72   GstElement *in_convert;
73   GstElement *in_overlay;
74   GstPad *mixer_pad;
75 };
76 
77 static void
_free_input_chain(struct input_chain * chain)78 _free_input_chain (struct input_chain *chain)
79 {
80   if (!chain)
81     return;
82 
83   chain->ghost_pad = NULL;
84 
85   if (chain->upload) {
86     gst_element_set_state (chain->upload, GST_STATE_NULL);
87     gst_bin_remove (GST_BIN (chain->self), chain->upload);
88     chain->upload = NULL;
89   }
90 
91   if (chain->in_convert) {
92     gst_element_set_state (chain->in_convert, GST_STATE_NULL);
93     gst_bin_remove (GST_BIN (chain->self), chain->in_convert);
94     chain->in_convert = NULL;
95   }
96 
97   if (chain->in_overlay) {
98     gst_element_set_state (chain->in_overlay, GST_STATE_NULL);
99     gst_bin_remove (GST_BIN (chain->self), chain->in_overlay);
100     chain->in_overlay = NULL;
101   }
102 
103   if (chain->mixer_pad) {
104     gst_element_release_request_pad (chain->self->mixer, chain->mixer_pad);
105     gst_object_unref (chain->mixer_pad);
106     chain->mixer_pad = NULL;
107   }
108 
109   g_free (chain);
110 }
111 
112 struct _GstGLMixerBinPrivate
113 {
114   gboolean running;
115 
116   GList *input_chains;
117 };
118 
119 enum
120 {
121   PROP_0,
122   PROP_MIXER,
123   PROP_LATENCY,
124   PROP_START_TIME_SELECTION,
125   PROP_START_TIME,
126   PROP_CONTEXT,
127 };
128 
129 enum
130 {
131   SIGNAL_0,
132   SIGNAL_CREATE_ELEMENT,
133   LAST_SIGNAL
134 };
135 
136 static void gst_gl_mixer_bin_child_proxy_init (gpointer g_iface,
137     gpointer iface_data);
138 
139 G_DEFINE_TYPE_WITH_CODE (GstGLMixerBin, gst_gl_mixer_bin, GST_TYPE_BIN,
140     G_ADD_PRIVATE (GstGLMixerBin)
141     G_IMPLEMENT_INTERFACE (GST_TYPE_CHILD_PROXY,
142         gst_gl_mixer_bin_child_proxy_init));
143 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (glmixerbin, "glmixerbin",
144     GST_RANK_NONE, GST_TYPE_GL_MIXER_BIN, gl_element_init (plugin));
145 
146 static guint gst_gl_mixer_bin_signals[LAST_SIGNAL] = { 0 };
147 
148 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
149     GST_PAD_SRC,
150     GST_PAD_ALWAYS,
151     GST_STATIC_CAPS ("video/x-raw(ANY)")
152     );
153 
154 static void gst_gl_mixer_bin_set_property (GObject * object, guint prop_id,
155     const GValue * value, GParamSpec * pspec);
156 static void gst_gl_mixer_bin_get_property (GObject * object, guint prop_id,
157     GValue * value, GParamSpec * pspec);
158 static void gst_gl_mixer_bin_dispose (GObject * object);
159 
160 static GstPad *gst_gl_mixer_bin_request_new_pad (GstElement * element,
161     GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps);
162 static void gst_gl_mixer_bin_release_pad (GstElement * element, GstPad * pad);
163 static GstStateChangeReturn gst_gl_mixer_bin_change_state (GstElement *
164     element, GstStateChange transition);
165 
166 static void
gst_gl_mixer_bin_class_init(GstGLMixerBinClass * klass)167 gst_gl_mixer_bin_class_init (GstGLMixerBinClass * klass)
168 {
169   GObjectClass *gobject_class = (GObjectClass *) klass;
170   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
171   GstCaps *upload_caps;
172 
173   GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "glmixerbin", 0,
174       "opengl mixer bin");
175 
176   element_class->request_new_pad = gst_gl_mixer_bin_request_new_pad;
177   element_class->release_pad = gst_gl_mixer_bin_release_pad;
178   element_class->change_state = gst_gl_mixer_bin_change_state;
179 
180   gobject_class->get_property = gst_gl_mixer_bin_get_property;
181   gobject_class->set_property = gst_gl_mixer_bin_set_property;
182   gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_gl_mixer_bin_dispose);
183 
184   g_object_class_install_property (gobject_class, PROP_MIXER,
185       g_param_spec_object ("mixer",
186           "GL mixer element",
187           "The GL mixer chain to use",
188           GST_TYPE_ELEMENT,
189           GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
190           G_PARAM_STATIC_STRINGS));
191 
192   g_object_class_install_property (gobject_class, PROP_LATENCY,
193       g_param_spec_uint64 ("latency", "Buffer latency",
194           "Additional latency in live mode to allow upstream "
195           "to take longer to produce buffers for the current "
196           "position (in nanoseconds)", 0, G_MAXUINT64,
197           DEFAULT_LATENCY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
198 
199   g_object_class_install_property (gobject_class, PROP_START_TIME_SELECTION,
200       g_param_spec_enum ("start-time-selection", "Start Time Selection",
201           "Decides which start time is output",
202           GST_TYPE_GL_MIXER_BIN_START_TIME_SELECTION,
203           DEFAULT_START_TIME_SELECTION,
204           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
205 
206   g_object_class_install_property (gobject_class, PROP_START_TIME,
207       g_param_spec_uint64 ("start-time", "Start Time",
208           "Start time to use if start-time-selection=set", 0,
209           G_MAXUINT64,
210           DEFAULT_START_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
211 
212   g_object_class_install_property (gobject_class, PROP_CONTEXT,
213       g_param_spec_object ("context",
214           "OpenGL context",
215           "Get OpenGL context",
216           GST_TYPE_GL_CONTEXT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
217 
218   /**
219    * GstMixerBin::create-element:
220    * @object: the #GstGLMixerBin
221    *
222    * Will be emitted when we need the processing element/s that this bin will use
223    *
224    * Returns: a new #GstElement
225    */
226   gst_gl_mixer_bin_signals[SIGNAL_CREATE_ELEMENT] =
227       g_signal_new ("create-element", G_TYPE_FROM_CLASS (klass),
228       G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, GST_TYPE_ELEMENT, 0);
229 
230   gst_element_class_add_static_pad_template (element_class, &src_factory);
231 
232   upload_caps = gst_gl_upload_get_input_template_caps ();
233   gst_element_class_add_pad_template (element_class,
234       gst_pad_template_new ("sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
235           upload_caps));
236   gst_caps_unref (upload_caps);
237 
238   gst_element_class_set_metadata (element_class, "OpenGL video_mixer empty bin",
239       "Bin/Filter/Effect/Video/Mixer", "OpenGL video_mixer empty bin",
240       "Matthew Waters <matthew@centricular.com>");
241 
242   gst_type_mark_as_plugin_api (GST_TYPE_GL_MIXER_BIN_START_TIME_SELECTION, 0);
243 }
244 
245 static void
gst_gl_mixer_bin_init(GstGLMixerBin * self)246 gst_gl_mixer_bin_init (GstGLMixerBin * self)
247 {
248   gboolean res = TRUE;
249   GstPad *pad;
250 
251   self->priv = gst_gl_mixer_bin_get_instance_private (self);
252 
253   self->out_convert = gst_element_factory_make ("glcolorconvert", NULL);
254   self->download = gst_element_factory_make ("gldownload", NULL);
255   res &= gst_bin_add (GST_BIN (self), self->out_convert);
256   res &= gst_bin_add (GST_BIN (self), self->download);
257 
258   res &=
259       gst_element_link_pads (self->out_convert, "src", self->download, "sink");
260 
261   pad = gst_element_get_static_pad (self->download, "src");
262   if (!pad) {
263     res = FALSE;
264   } else {
265     GST_DEBUG_OBJECT (self, "setting target src pad %" GST_PTR_FORMAT, pad);
266     self->srcpad = gst_ghost_pad_new ("src", pad);
267     gst_element_add_pad (GST_ELEMENT_CAST (self), self->srcpad);
268     gst_object_unref (pad);
269   }
270 
271   if (!res)
272     GST_ERROR_OBJECT (self, "failed to create output chain");
273 }
274 
275 static void
gst_gl_mixer_bin_dispose(GObject * object)276 gst_gl_mixer_bin_dispose (GObject * object)
277 {
278   GstGLMixerBin *self = GST_GL_MIXER_BIN (object);
279   GList *l = self->priv->input_chains;
280 
281   while (l) {
282     struct input_chain *chain = l->data;
283 
284     if (self->mixer && chain->mixer_pad) {
285       gst_element_release_request_pad (GST_ELEMENT (self->mixer),
286           chain->mixer_pad);
287       gst_object_unref (chain->mixer_pad);
288       chain->mixer_pad = NULL;
289     }
290 
291     l = l->next;
292   }
293 
294   g_list_free_full (self->priv->input_chains, (GDestroyNotify) g_free);
295 
296   G_OBJECT_CLASS (gst_gl_mixer_bin_parent_class)->dispose (object);
297 }
298 
299 static gboolean
_create_input_chain(GstGLMixerBin * self,struct input_chain * chain,GstPad * mixer_pad)300 _create_input_chain (GstGLMixerBin * self, struct input_chain *chain,
301     GstPad * mixer_pad)
302 {
303   GstGLMixerBinClass *klass = GST_GL_MIXER_BIN_GET_CLASS (self);
304   GstPad *pad;
305   gboolean res = TRUE;
306   gchar *name;
307 
308   chain->self = self;
309   chain->mixer_pad = mixer_pad;
310 
311   chain->upload = gst_element_factory_make ("glupload", NULL);
312   chain->in_convert = gst_element_factory_make ("glcolorconvert", NULL);
313   chain->in_overlay = gst_element_factory_make ("gloverlaycompositor", NULL);
314 
315   res &= gst_bin_add (GST_BIN (self), chain->in_convert);
316   res &= gst_bin_add (GST_BIN (self), chain->in_overlay);
317   res &= gst_bin_add (GST_BIN (self), chain->upload);
318   if (!res) {
319     g_warn_if_reached ();
320     return FALSE;
321   }
322 
323   pad = gst_element_get_static_pad (chain->in_overlay, "src");
324   if (gst_pad_link (pad, mixer_pad) != GST_PAD_LINK_OK) {
325     gst_object_unref (pad);
326     return FALSE;
327   }
328   gst_object_unref (pad);
329   if (!gst_element_link_pads (chain->in_convert, "src", chain->in_overlay,
330           "sink")) {
331     g_warn_if_reached ();
332     return FALSE;
333   }
334   if (!gst_element_link_pads (chain->upload, "src", chain->in_convert, "sink")) {
335     g_warn_if_reached ();
336     return FALSE;
337   }
338 
339   pad = gst_element_get_static_pad (chain->upload, "sink");
340   if (!pad) {
341     return FALSE;
342   } else {
343     GST_DEBUG_OBJECT (self, "setting target sink pad %" GST_PTR_FORMAT, pad);
344     name = gst_object_get_name (GST_OBJECT (mixer_pad));
345     if (klass->create_input_pad) {
346       chain->ghost_pad = klass->create_input_pad (self, chain->mixer_pad);
347       gst_object_set_name (GST_OBJECT (chain->ghost_pad), name);
348       gst_ghost_pad_set_target (chain->ghost_pad, pad);
349     } else {
350       chain->ghost_pad =
351           GST_GHOST_PAD (gst_ghost_pad_new (GST_PAD_NAME (chain->mixer_pad),
352               pad));
353     }
354     g_free (name);
355 
356     GST_OBJECT_LOCK (self);
357     if (self->priv->running)
358       gst_pad_set_active (GST_PAD (chain->ghost_pad), TRUE);
359     GST_OBJECT_UNLOCK (self);
360 
361     gst_element_add_pad (GST_ELEMENT_CAST (self), GST_PAD (chain->ghost_pad));
362     gst_object_unref (pad);
363   }
364 
365   gst_element_sync_state_with_parent (chain->upload);
366   gst_element_sync_state_with_parent (chain->in_convert);
367   gst_element_sync_state_with_parent (chain->in_overlay);
368 
369   return TRUE;
370 }
371 
372 static GstPadTemplate *
_find_element_pad_template(GstElement * element,GstPadDirection direction,GstPadPresence presence)373 _find_element_pad_template (GstElement * element,
374     GstPadDirection direction, GstPadPresence presence)
375 {
376   GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
377   GList *templ_list = gst_element_class_get_pad_template_list (klass);
378   GstPadTemplate *templ;
379 
380   /* find suitable template */
381   while (templ_list) {
382     templ = (GstPadTemplate *) templ_list->data;
383 
384     if (GST_PAD_TEMPLATE_DIRECTION (templ) != direction
385         || GST_PAD_TEMPLATE_PRESENCE (templ) != presence) {
386       templ_list = templ_list->next;
387       templ = NULL;
388       continue;
389     }
390 
391     break;
392   }
393 
394   return templ;
395 }
396 
397 static gboolean
_connect_mixer_element(GstGLMixerBin * self)398 _connect_mixer_element (GstGLMixerBin * self)
399 {
400   gboolean res = TRUE;
401 
402   g_return_val_if_fail (self->priv->input_chains == NULL, FALSE);
403 
404   gst_object_set_name (GST_OBJECT (self->mixer), "mixer");
405   res &= gst_bin_add (GST_BIN (self), self->mixer);
406 
407   res &= gst_element_link_pads (self->mixer, "src", self->out_convert, "sink");
408 
409   if (!res)
410     GST_ERROR_OBJECT (self, "Failed to link mixer element into the pipeline");
411 
412   gst_element_sync_state_with_parent (self->mixer);
413 
414   return res;
415 }
416 
417 void
gst_gl_mixer_bin_finish_init_with_element(GstGLMixerBin * self,GstElement * element)418 gst_gl_mixer_bin_finish_init_with_element (GstGLMixerBin * self,
419     GstElement * element)
420 {
421   g_return_if_fail (GST_IS_ELEMENT (element));
422 
423   self->mixer = element;
424 
425   if (!_connect_mixer_element (self)) {
426     gst_object_unref (self->mixer);
427     self->mixer = NULL;
428   }
429 }
430 
431 void
gst_gl_mixer_bin_finish_init(GstGLMixerBin * self)432 gst_gl_mixer_bin_finish_init (GstGLMixerBin * self)
433 {
434   GstGLMixerBinClass *klass = GST_GL_MIXER_BIN_GET_CLASS (self);
435   GstElement *element = NULL;
436 
437   if (klass->create_element)
438     element = klass->create_element ();
439 
440   if (element)
441     gst_gl_mixer_bin_finish_init_with_element (self, element);
442 }
443 
444 static void
gst_gl_mixer_bin_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)445 gst_gl_mixer_bin_get_property (GObject * object,
446     guint prop_id, GValue * value, GParamSpec * pspec)
447 {
448   GstGLMixerBin *self = GST_GL_MIXER_BIN (object);
449 
450   switch (prop_id) {
451     case PROP_MIXER:
452       g_value_set_object (value, self->mixer);
453       break;
454     default:
455       if (self->mixer)
456         g_object_get_property (G_OBJECT (self->mixer), pspec->name, value);
457       break;
458   }
459 }
460 
461 static void
gst_gl_mixer_bin_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)462 gst_gl_mixer_bin_set_property (GObject * object,
463     guint prop_id, const GValue * value, GParamSpec * pspec)
464 {
465   GstGLMixerBin *self = GST_GL_MIXER_BIN (object);
466 
467   switch (prop_id) {
468     case PROP_MIXER:
469     {
470       GstElement *mixer = g_value_get_object (value);
471       /* FIXME: deal with replacing a mixer */
472       g_return_if_fail (!self->mixer || (self->mixer == mixer));
473       self->mixer = mixer;
474       if (mixer) {
475         gst_object_ref_sink (mixer);
476         _connect_mixer_element (self);
477       }
478       break;
479     }
480     default:
481       if (self->mixer)
482         g_object_set_property (G_OBJECT (self->mixer), pspec->name, value);
483       break;
484   }
485 }
486 
487 static GstPad *
gst_gl_mixer_bin_request_new_pad(GstElement * element,GstPadTemplate * templ,const gchar * req_name,const GstCaps * caps)488 gst_gl_mixer_bin_request_new_pad (GstElement * element, GstPadTemplate * templ,
489     const gchar * req_name, const GstCaps * caps)
490 {
491   GstGLMixerBin *self = GST_GL_MIXER_BIN (element);
492   GstPadTemplate *mixer_templ;
493   struct input_chain *chain;
494   GstPad *mixer_pad;
495 
496   chain = g_new0 (struct input_chain, 1);
497 
498   mixer_templ = _find_element_pad_template (self->mixer,
499       GST_PAD_TEMPLATE_DIRECTION (templ), GST_PAD_TEMPLATE_PRESENCE (templ));
500   g_return_val_if_fail (mixer_templ, NULL);
501 
502   mixer_pad =
503       gst_element_request_pad (self->mixer, mixer_templ, req_name, NULL);
504   g_return_val_if_fail (mixer_pad, NULL);
505 
506   if (!_create_input_chain (self, chain, mixer_pad)) {
507     gst_element_release_request_pad (self->mixer, mixer_pad);
508     _free_input_chain (chain);
509     return NULL;
510   }
511 
512   GST_OBJECT_LOCK (element);
513   self->priv->input_chains = g_list_prepend (self->priv->input_chains, chain);
514   GST_OBJECT_UNLOCK (element);
515 
516   gst_child_proxy_child_added (GST_CHILD_PROXY (self),
517       G_OBJECT (chain->ghost_pad), GST_OBJECT_NAME (chain->ghost_pad));
518 
519   return GST_PAD (chain->ghost_pad);
520 }
521 
522 static void
gst_gl_mixer_bin_release_pad(GstElement * element,GstPad * pad)523 gst_gl_mixer_bin_release_pad (GstElement * element, GstPad * pad)
524 {
525   GstGLMixerBin *self = GST_GL_MIXER_BIN (element);
526   GList *l = self->priv->input_chains;
527   gboolean released = FALSE;
528 
529   GST_OBJECT_LOCK (element);
530   while (l) {
531     struct input_chain *chain = l->data;
532     if (GST_PAD (chain->ghost_pad) == pad) {
533       self->priv->input_chains =
534           g_list_delete_link (self->priv->input_chains, l);
535       GST_OBJECT_UNLOCK (element);
536 
537       _free_input_chain (chain);
538       gst_element_remove_pad (element, pad);
539       released = TRUE;
540       break;
541     }
542     l = l->next;
543   }
544   if (!released)
545     GST_OBJECT_UNLOCK (element);
546 }
547 
548 static GstStateChangeReturn
gst_gl_mixer_bin_change_state(GstElement * element,GstStateChange transition)549 gst_gl_mixer_bin_change_state (GstElement * element, GstStateChange transition)
550 {
551   GstGLMixerBin *self = GST_GL_MIXER_BIN (element);
552   GstGLMixerBinClass *klass = GST_GL_MIXER_BIN_GET_CLASS (self);
553   GstStateChangeReturn ret;
554 
555   switch (transition) {
556     case GST_STATE_CHANGE_NULL_TO_READY:
557       GST_OBJECT_LOCK (element);
558       if (!self->mixer) {
559         if (klass->create_element)
560           self->mixer = klass->create_element ();
561 
562         if (!self->mixer)
563           g_signal_emit (element,
564               gst_gl_mixer_bin_signals[SIGNAL_CREATE_ELEMENT], 0, &self->mixer);
565 
566         if (!self->mixer) {
567           GST_ERROR_OBJECT (element, "Failed to retrieve element");
568           GST_OBJECT_UNLOCK (element);
569           return GST_STATE_CHANGE_FAILURE;
570         }
571         GST_OBJECT_UNLOCK (element);
572         if (!_connect_mixer_element (self))
573           return GST_STATE_CHANGE_FAILURE;
574 
575         GST_OBJECT_LOCK (element);
576       }
577       self->priv->running = TRUE;
578       GST_OBJECT_UNLOCK (element);
579       break;
580     default:
581       break;
582   }
583 
584   ret =
585       GST_ELEMENT_CLASS (gst_gl_mixer_bin_parent_class)->change_state (element,
586       transition);
587   if (ret == GST_STATE_CHANGE_FAILURE)
588     return ret;
589 
590   switch (transition) {
591     case GST_STATE_CHANGE_READY_TO_NULL:
592       GST_OBJECT_LOCK (self);
593       self->priv->running = FALSE;
594       GST_OBJECT_UNLOCK (self);
595     default:
596       break;
597   }
598 
599   return ret;
600 }
601 
602 static GObject *
gst_gl_mixer_bin_child_proxy_get_child_by_index(GstChildProxy * child_proxy,guint index)603 gst_gl_mixer_bin_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
604     guint index)
605 {
606   GstGLMixerBin *mixer = GST_GL_MIXER_BIN (child_proxy);
607   GstBin *bin = GST_BIN_CAST (child_proxy);
608   GObject *res = NULL;
609 
610   GST_OBJECT_LOCK (bin);
611   /* XXX: not exactly thread safe with ordering */
612   if (index < bin->numchildren) {
613     if ((res = g_list_nth_data (bin->children, index)))
614       gst_object_ref (res);
615   } else {
616     struct input_chain *chain;
617     if ((chain =
618             g_list_nth_data (mixer->priv->input_chains,
619                 index - bin->numchildren))) {
620       res = gst_object_ref (chain->ghost_pad);
621     }
622   }
623   GST_OBJECT_UNLOCK (bin);
624 
625   return res;
626 }
627 
628 static guint
gst_gl_mixer_bin_child_proxy_get_children_count(GstChildProxy * child_proxy)629 gst_gl_mixer_bin_child_proxy_get_children_count (GstChildProxy * child_proxy)
630 {
631   GstGLMixerBin *mixer = GST_GL_MIXER_BIN (child_proxy);
632   GstBin *bin = GST_BIN_CAST (child_proxy);
633   guint num;
634 
635   GST_OBJECT_LOCK (bin);
636   num = bin->numchildren + g_list_length (mixer->priv->input_chains);
637   GST_OBJECT_UNLOCK (bin);
638 
639   return num;
640 }
641 
642 static void
gst_gl_mixer_bin_child_proxy_init(gpointer g_iface,gpointer iface_data)643 gst_gl_mixer_bin_child_proxy_init (gpointer g_iface, gpointer iface_data)
644 {
645   GstChildProxyInterface *iface = g_iface;
646 
647   iface->get_children_count = gst_gl_mixer_bin_child_proxy_get_children_count;
648   iface->get_child_by_index = gst_gl_mixer_bin_child_proxy_get_child_by_index;
649 }
650