15203
|
1 |
--- /dev/null 2008-12-16 15:34:15.000000000 +0800
|
17776
|
2 |
+++ gst-plugins-good-0.10.21/gst/selector/Makefile.am 2008-12-16 15:09:01.090359516 +0800
|
|
3 |
@@ -0,0 +1,24 @@
|
|
4 |
+glib_gen_prefix = gst_selector
|
|
5 |
+glib_gen_basename = gstselector
|
15203
|
6 |
+
|
17776
|
7 |
+include $(top_srcdir)/common/gst-glib-gen.mak
|
15203
|
8 |
+
|
|
9 |
+built_sources = gstselector-marshal.c
|
|
10 |
+built_headers = gstselector-marshal.h
|
|
11 |
+
|
|
12 |
+BUILT_SOURCES = $(built_sources) $(built_headers)
|
|
13 |
+
|
|
14 |
+CLEANFILES = $(BUILT_SOURCES)
|
|
15 |
+
|
|
16 |
+EXTRA_DIST = gstselector-marshal.list
|
|
17 |
+
|
|
18 |
+plugin_LTLIBRARIES = libgstselector.la
|
|
19 |
+
|
|
20 |
+libgstselector_la_SOURCES = gstselector.c gstinputselector.c gstoutputselector.c
|
|
21 |
+nodist_libgstselector_la_SOURCES = $(built_sources)
|
|
22 |
+libgstselector_la_CFLAGS = $(GST_CFLAGS)
|
|
23 |
+libgstselector_la_LIBADD =
|
|
24 |
+libgstselector_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS)
|
15812
|
25 |
+libgstselector_la_LIBTOOLFLAGS = --tag=disable-static
|
15203
|
26 |
+
|
|
27 |
+noinst_HEADERS = gstinputselector.h gstoutputselector.h
|
|
28 |
--- /dev/null 2008-12-16 15:34:15.000000000 +0800
|
17776
|
29 |
+++ gst-plugins-good-0.10.21/gst/selector/gstinputselector.c 2008-12-16 15:09:01.091207753 +0800
|
|
30 |
@@ -0,0 +1,1455 @@
|
15203
|
31 |
+/* GStreamer
|
|
32 |
+ * Copyright (C) 2003 Julien Moutte <[email protected]>
|
|
33 |
+ * Copyright (C) 2005 Ronald S. Bultje <[email protected]>
|
|
34 |
+ * Copyright (C) 2005 Jan Schmidt <[email protected]>
|
|
35 |
+ * Copyright (C) 2007 Wim Taymans <[email protected]>
|
|
36 |
+ * Copyright (C) 2007 Andy Wingo <[email protected]>
|
|
37 |
+ * Copyright (C) 2008 Nokia Corporation. (contact <[email protected]>)
|
|
38 |
+ *
|
|
39 |
+ * This library is free software; you can redistribute it and/or
|
|
40 |
+ * modify it under the terms of the GNU Library General Public
|
|
41 |
+ * License as published by the Free Software Foundation; either
|
|
42 |
+ * version 2 of the License, or (at your option) any later version.
|
|
43 |
+ *
|
|
44 |
+ * This library is distributed in the hope that it will be useful,
|
|
45 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
46 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
47 |
+ * Library General Public License for more details.
|
|
48 |
+ *
|
|
49 |
+ * You should have received a copy of the GNU Library General Public
|
|
50 |
+ * License along with this library; if not, write to the
|
|
51 |
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
52 |
+ * Boston, MA 02111-1307, USA.
|
|
53 |
+ */
|
|
54 |
+
|
|
55 |
+/**
|
|
56 |
+ * SECTION:element-input-selector
|
|
57 |
+ * @see_also: #GstOutputSelector
|
|
58 |
+ *
|
|
59 |
+ * Direct one out of N input streams to the output pad.
|
|
60 |
+ */
|
|
61 |
+
|
|
62 |
+#ifdef HAVE_CONFIG_H
|
|
63 |
+#include "config.h"
|
|
64 |
+#endif
|
|
65 |
+
|
|
66 |
+#include <string.h>
|
|
67 |
+
|
|
68 |
+#include "gstinputselector.h"
|
|
69 |
+#include "gstselector-marshal.h"
|
|
70 |
+
|
|
71 |
+GST_DEBUG_CATEGORY_STATIC (input_selector_debug);
|
|
72 |
+#define GST_CAT_DEFAULT input_selector_debug
|
|
73 |
+
|
|
74 |
+static const GstElementDetails gst_input_selector_details =
|
|
75 |
+GST_ELEMENT_DETAILS ("Input selector",
|
|
76 |
+ "Generic",
|
|
77 |
+ "N-to-1 input stream selectoring",
|
|
78 |
+ "Julien Moutte <[email protected]>\n"
|
|
79 |
+ "Jan Schmidt <[email protected]>\n"
|
|
80 |
+ "Wim Taymans <[email protected]>");
|
|
81 |
+
|
|
82 |
+static GstStaticPadTemplate gst_input_selector_sink_factory =
|
|
83 |
+GST_STATIC_PAD_TEMPLATE ("sink%d",
|
|
84 |
+ GST_PAD_SINK,
|
|
85 |
+ GST_PAD_REQUEST,
|
|
86 |
+ GST_STATIC_CAPS_ANY);
|
|
87 |
+
|
|
88 |
+static GstStaticPadTemplate gst_input_selector_src_factory =
|
|
89 |
+GST_STATIC_PAD_TEMPLATE ("src",
|
|
90 |
+ GST_PAD_SRC,
|
|
91 |
+ GST_PAD_ALWAYS,
|
|
92 |
+ GST_STATIC_CAPS_ANY);
|
|
93 |
+
|
|
94 |
+enum
|
|
95 |
+{
|
|
96 |
+ PROP_0,
|
|
97 |
+ PROP_N_PADS,
|
|
98 |
+ PROP_ACTIVE_PAD,
|
|
99 |
+ PROP_SELECT_ALL,
|
|
100 |
+ PROP_LAST
|
|
101 |
+};
|
|
102 |
+
|
|
103 |
+#define DEFAULT_PAD_ALWAYS_OK TRUE
|
|
104 |
+
|
|
105 |
+enum
|
|
106 |
+{
|
|
107 |
+ PROP_PAD_0,
|
|
108 |
+ PROP_PAD_RUNNING_TIME,
|
|
109 |
+ PROP_PAD_TAGS,
|
|
110 |
+ PROP_PAD_ACTIVE,
|
|
111 |
+ PROP_PAD_ALWAYS_OK,
|
|
112 |
+ PROP_PAD_LAST
|
|
113 |
+};
|
|
114 |
+
|
|
115 |
+enum
|
|
116 |
+{
|
|
117 |
+ /* methods */
|
|
118 |
+ SIGNAL_BLOCK,
|
|
119 |
+ SIGNAL_SWITCH,
|
|
120 |
+ LAST_SIGNAL
|
|
121 |
+};
|
|
122 |
+static guint gst_input_selector_signals[LAST_SIGNAL] = { 0 };
|
|
123 |
+
|
17776
|
124 |
+static inline gboolean gst_input_selector_is_active_sinkpad (GstInputSelector *
|
|
125 |
+ sel, GstPad * pad);
|
15203
|
126 |
+static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel,
|
|
127 |
+ GstPad * pad);
|
|
128 |
+static GstPad *gst_input_selector_get_linked_pad (GstPad * pad,
|
|
129 |
+ gboolean strict);
|
|
130 |
+static gboolean gst_input_selector_check_eos (GstElement * selector);
|
|
131 |
+
|
|
132 |
+#define GST_TYPE_SELECTOR_PAD \
|
|
133 |
+ (gst_selector_pad_get_type())
|
|
134 |
+#define GST_SELECTOR_PAD(obj) \
|
|
135 |
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SELECTOR_PAD, GstSelectorPad))
|
|
136 |
+#define GST_SELECTOR_PAD_CLASS(klass) \
|
|
137 |
+ (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_SELECTOR_PAD, GstSelectorPadClass))
|
|
138 |
+#define GST_IS_SELECTOR_PAD(obj) \
|
|
139 |
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SELECTOR_PAD))
|
|
140 |
+#define GST_IS_SELECTOR_PAD_CLASS(klass) \
|
|
141 |
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_SELECTOR_PAD))
|
|
142 |
+#define GST_SELECTOR_PAD_CAST(obj) \
|
|
143 |
+ ((GstSelectorPad *)(obj))
|
|
144 |
+
|
|
145 |
+typedef struct _GstSelectorPad GstSelectorPad;
|
|
146 |
+typedef struct _GstSelectorPadClass GstSelectorPadClass;
|
|
147 |
+
|
|
148 |
+struct _GstSelectorPad
|
|
149 |
+{
|
|
150 |
+ GstPad parent;
|
|
151 |
+
|
|
152 |
+ gboolean active; /* when buffer have passed the pad */
|
|
153 |
+ gboolean eos; /* when EOS has been received */
|
|
154 |
+ gboolean discont; /* after switching we create a discont */
|
|
155 |
+ gboolean always_ok;
|
|
156 |
+ GstSegment segment; /* the current segment on the pad */
|
|
157 |
+ GstTagList *tags; /* last tags received on the pad */
|
|
158 |
+
|
|
159 |
+ gboolean segment_pending;
|
|
160 |
+};
|
|
161 |
+
|
|
162 |
+struct _GstSelectorPadClass
|
|
163 |
+{
|
|
164 |
+ GstPadClass parent;
|
|
165 |
+};
|
|
166 |
+
|
|
167 |
+static void gst_selector_pad_class_init (GstSelectorPadClass * klass);
|
|
168 |
+static void gst_selector_pad_init (GstSelectorPad * pad);
|
|
169 |
+static void gst_selector_pad_finalize (GObject * object);
|
|
170 |
+static void gst_selector_pad_get_property (GObject * object,
|
|
171 |
+ guint prop_id, GValue * value, GParamSpec * pspec);
|
|
172 |
+static void gst_selector_pad_set_property (GObject * object,
|
|
173 |
+ guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
174 |
+
|
|
175 |
+static GstPadClass *selector_pad_parent_class = NULL;
|
|
176 |
+
|
|
177 |
+static gint64 gst_selector_pad_get_running_time (GstSelectorPad * pad);
|
|
178 |
+static void gst_selector_pad_reset (GstSelectorPad * pad);
|
|
179 |
+static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
|
|
180 |
+static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
|
17776
|
181 |
+static gboolean gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps);
|
|
182 |
+static GstIterator *gst_selector_pad_iterate_linked_pads (GstPad * pad);
|
15203
|
183 |
+static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf);
|
|
184 |
+static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad,
|
|
185 |
+ guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
|
|
186 |
+
|
|
187 |
+static GType
|
|
188 |
+gst_selector_pad_get_type (void)
|
|
189 |
+{
|
|
190 |
+ static GType selector_pad_type = 0;
|
|
191 |
+
|
|
192 |
+ if (!selector_pad_type) {
|
|
193 |
+ static const GTypeInfo selector_pad_info = {
|
|
194 |
+ sizeof (GstSelectorPadClass),
|
|
195 |
+ NULL,
|
|
196 |
+ NULL,
|
|
197 |
+ (GClassInitFunc) gst_selector_pad_class_init,
|
|
198 |
+ NULL,
|
|
199 |
+ NULL,
|
|
200 |
+ sizeof (GstSelectorPad),
|
|
201 |
+ 0,
|
|
202 |
+ (GInstanceInitFunc) gst_selector_pad_init,
|
|
203 |
+ };
|
|
204 |
+
|
|
205 |
+ selector_pad_type =
|
|
206 |
+ g_type_register_static (GST_TYPE_PAD, "GstSelectorPad",
|
|
207 |
+ &selector_pad_info, 0);
|
|
208 |
+ }
|
|
209 |
+ return selector_pad_type;
|
|
210 |
+}
|
|
211 |
+
|
|
212 |
+static void
|
|
213 |
+gst_selector_pad_class_init (GstSelectorPadClass * klass)
|
|
214 |
+{
|
|
215 |
+ GObjectClass *gobject_class;
|
|
216 |
+
|
|
217 |
+ gobject_class = (GObjectClass *) klass;
|
|
218 |
+
|
|
219 |
+ selector_pad_parent_class = g_type_class_peek_parent (klass);
|
|
220 |
+
|
|
221 |
+ gobject_class->finalize = gst_selector_pad_finalize;
|
|
222 |
+
|
17776
|
223 |
+ gobject_class->get_property = gst_selector_pad_get_property;
|
|
224 |
+ gobject_class->set_property = gst_selector_pad_set_property;
|
15203
|
225 |
+
|
|
226 |
+ g_object_class_install_property (gobject_class, PROP_PAD_RUNNING_TIME,
|
|
227 |
+ g_param_spec_int64 ("running-time", "Running time",
|
|
228 |
+ "Running time of stream on pad", 0, G_MAXINT64, 0, G_PARAM_READABLE));
|
|
229 |
+ g_object_class_install_property (gobject_class, PROP_PAD_TAGS,
|
|
230 |
+ g_param_spec_boxed ("tags", "Tags",
|
|
231 |
+ "The currently active tags on the pad", GST_TYPE_TAG_LIST,
|
|
232 |
+ G_PARAM_READABLE));
|
|
233 |
+ g_object_class_install_property (gobject_class, PROP_PAD_ACTIVE,
|
|
234 |
+ g_param_spec_boolean ("active", "Active",
|
|
235 |
+ "If the pad is currently active", FALSE, G_PARAM_READABLE));
|
|
236 |
+ g_object_class_install_property (gobject_class, PROP_PAD_ALWAYS_OK,
|
|
237 |
+ g_param_spec_boolean ("always-ok", "Always OK",
|
|
238 |
+ "Make an inactive pad return OK instead of NOT_LINKED",
|
|
239 |
+ DEFAULT_PAD_ALWAYS_OK, G_PARAM_READWRITE));
|
|
240 |
+}
|
|
241 |
+
|
|
242 |
+static void
|
|
243 |
+gst_selector_pad_init (GstSelectorPad * pad)
|
|
244 |
+{
|
|
245 |
+ pad->always_ok = DEFAULT_PAD_ALWAYS_OK;
|
|
246 |
+ gst_selector_pad_reset (pad);
|
|
247 |
+}
|
|
248 |
+
|
|
249 |
+static void
|
|
250 |
+gst_selector_pad_finalize (GObject * object)
|
|
251 |
+{
|
|
252 |
+ GstSelectorPad *pad;
|
|
253 |
+
|
|
254 |
+ pad = GST_SELECTOR_PAD_CAST (object);
|
|
255 |
+
|
|
256 |
+ if (pad->tags)
|
|
257 |
+ gst_tag_list_free (pad->tags);
|
|
258 |
+
|
|
259 |
+ G_OBJECT_CLASS (selector_pad_parent_class)->finalize (object);
|
|
260 |
+}
|
|
261 |
+
|
|
262 |
+static void
|
|
263 |
+gst_selector_pad_set_property (GObject * object, guint prop_id,
|
|
264 |
+ const GValue * value, GParamSpec * pspec)
|
|
265 |
+{
|
|
266 |
+ GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
|
|
267 |
+
|
|
268 |
+ switch (prop_id) {
|
|
269 |
+ case PROP_PAD_ALWAYS_OK:
|
|
270 |
+ GST_OBJECT_LOCK (object);
|
|
271 |
+ spad->always_ok = g_value_get_boolean (value);
|
|
272 |
+ GST_OBJECT_UNLOCK (object);
|
|
273 |
+ break;
|
|
274 |
+ default:
|
|
275 |
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
276 |
+ break;
|
|
277 |
+ }
|
|
278 |
+}
|
|
279 |
+
|
|
280 |
+static void
|
|
281 |
+gst_selector_pad_get_property (GObject * object, guint prop_id,
|
|
282 |
+ GValue * value, GParamSpec * pspec)
|
|
283 |
+{
|
|
284 |
+ GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
|
|
285 |
+
|
|
286 |
+ switch (prop_id) {
|
|
287 |
+ case PROP_PAD_RUNNING_TIME:
|
|
288 |
+ g_value_set_int64 (value, gst_selector_pad_get_running_time (spad));
|
|
289 |
+ break;
|
|
290 |
+ case PROP_PAD_TAGS:
|
|
291 |
+ GST_OBJECT_LOCK (object);
|
|
292 |
+ g_value_set_boxed (value, spad->tags);
|
|
293 |
+ GST_OBJECT_UNLOCK (object);
|
|
294 |
+ break;
|
|
295 |
+ case PROP_PAD_ACTIVE:
|
|
296 |
+ {
|
|
297 |
+ GstInputSelector *sel;
|
|
298 |
+
|
|
299 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (spad));
|
|
300 |
+ g_value_set_boolean (value, gst_input_selector_is_active_sinkpad (sel,
|
|
301 |
+ GST_PAD_CAST (spad)));
|
|
302 |
+ gst_object_unref (sel);
|
|
303 |
+ break;
|
|
304 |
+ }
|
|
305 |
+ case PROP_PAD_ALWAYS_OK:
|
|
306 |
+ GST_OBJECT_LOCK (object);
|
|
307 |
+ g_value_set_boolean (value, spad->always_ok);
|
|
308 |
+ GST_OBJECT_UNLOCK (object);
|
|
309 |
+ break;
|
|
310 |
+ default:
|
|
311 |
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
312 |
+ break;
|
|
313 |
+ }
|
|
314 |
+}
|
|
315 |
+
|
|
316 |
+static gint64
|
|
317 |
+gst_selector_pad_get_running_time (GstSelectorPad * pad)
|
|
318 |
+{
|
|
319 |
+ gint64 ret = 0;
|
|
320 |
+
|
|
321 |
+ GST_OBJECT_LOCK (pad);
|
|
322 |
+ if (pad->active) {
|
|
323 |
+ gint64 last_stop = pad->segment.last_stop;
|
|
324 |
+
|
|
325 |
+ if (last_stop >= 0)
|
|
326 |
+ ret = gst_segment_to_running_time (&pad->segment, GST_FORMAT_TIME,
|
|
327 |
+ last_stop);
|
|
328 |
+ }
|
|
329 |
+ GST_OBJECT_UNLOCK (pad);
|
|
330 |
+
|
|
331 |
+ GST_DEBUG_OBJECT (pad, "running time: %" GST_TIME_FORMAT,
|
|
332 |
+ GST_TIME_ARGS (ret));
|
|
333 |
+
|
|
334 |
+ return ret;
|
|
335 |
+}
|
|
336 |
+
|
|
337 |
+static void
|
|
338 |
+gst_selector_pad_reset (GstSelectorPad * pad)
|
|
339 |
+{
|
|
340 |
+ GST_OBJECT_LOCK (pad);
|
|
341 |
+ pad->active = FALSE;
|
|
342 |
+ pad->eos = FALSE;
|
|
343 |
+ pad->segment_pending = FALSE;
|
|
344 |
+ pad->discont = FALSE;
|
|
345 |
+ gst_segment_init (&pad->segment, GST_FORMAT_UNDEFINED);
|
|
346 |
+ GST_OBJECT_UNLOCK (pad);
|
|
347 |
+}
|
|
348 |
+
|
|
349 |
+/* strictly get the linked pad from the sinkpad. If the pad is active we return
|
|
350 |
+ * the srcpad else we return NULL */
|
17776
|
351 |
+static GstIterator *
|
|
352 |
+gst_selector_pad_iterate_linked_pads (GstPad * pad)
|
15203
|
353 |
+{
|
17776
|
354 |
+ GstInputSelector *sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
15203
|
355 |
+ GstPad *otherpad;
|
17776
|
356 |
+ GstIterator *it;
|
15203
|
357 |
+
|
|
358 |
+ otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
|
17776
|
359 |
+ it = gst_iterator_new_single (GST_TYPE_PAD, otherpad,
|
|
360 |
+ (GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
|
15203
|
361 |
+
|
17776
|
362 |
+ if (otherpad)
|
|
363 |
+ gst_object_unref (otherpad);
|
|
364 |
+ gst_object_unref (sel);
|
15203
|
365 |
+
|
17776
|
366 |
+ return it;
|
15203
|
367 |
+}
|
|
368 |
+
|
|
369 |
+static gboolean
|
|
370 |
+gst_selector_pad_event (GstPad * pad, GstEvent * event)
|
|
371 |
+{
|
|
372 |
+ gboolean res = TRUE;
|
|
373 |
+ gboolean forward = TRUE;
|
|
374 |
+ GstInputSelector *sel;
|
|
375 |
+ GstSelectorPad *selpad;
|
15812
|
376 |
+ GstPad *prev_active_sinkpad;
|
|
377 |
+ GstPad *active_sinkpad;
|
15203
|
378 |
+
|
|
379 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
380 |
+ selpad = GST_SELECTOR_PAD_CAST (pad);
|
|
381 |
+
|
15812
|
382 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
383 |
+ prev_active_sinkpad = sel->active_sinkpad;
|
|
384 |
+ active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
|
15203
|
385 |
+
|
15812
|
386 |
+ /* only forward if we are dealing with the active sinkpad or if select_all
|
|
387 |
+ * is enabled */
|
|
388 |
+ if (pad != active_sinkpad && !sel->select_all)
|
|
389 |
+ forward = FALSE;
|
|
390 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
391 |
+
|
|
392 |
+ if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad)
|
|
393 |
+ g_object_notify (G_OBJECT (sel), "active-pad");
|
15203
|
394 |
+
|
|
395 |
+ switch (GST_EVENT_TYPE (event)) {
|
|
396 |
+ case GST_EVENT_FLUSH_START:
|
|
397 |
+ /* FIXME, flush out the waiter */
|
|
398 |
+ break;
|
|
399 |
+ case GST_EVENT_FLUSH_STOP:
|
|
400 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
401 |
+ gst_selector_pad_reset (selpad);
|
|
402 |
+ sel->pending_close = FALSE;
|
|
403 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
404 |
+ break;
|
|
405 |
+ case GST_EVENT_NEWSEGMENT:
|
|
406 |
+ {
|
|
407 |
+ gboolean update;
|
|
408 |
+ GstFormat format;
|
|
409 |
+ gdouble rate, arate;
|
|
410 |
+ gint64 start, stop, time;
|
|
411 |
+
|
|
412 |
+ gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
|
|
413 |
+ &start, &stop, &time);
|
|
414 |
+
|
|
415 |
+ GST_DEBUG_OBJECT (pad,
|
|
416 |
+ "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
|
|
417 |
+ "format %d, "
|
|
418 |
+ "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
|
|
419 |
+ G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
|
|
420 |
+
|
|
421 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
422 |
+ GST_OBJECT_LOCK (selpad);
|
|
423 |
+ gst_segment_set_newsegment_full (&selpad->segment, update,
|
|
424 |
+ rate, arate, format, start, stop, time);
|
|
425 |
+ GST_OBJECT_UNLOCK (selpad);
|
15812
|
426 |
+
|
|
427 |
+ /* If we aren't forwarding the event (because the pad is not the
|
|
428 |
+ * active_sinkpad, and select_all is not set, then set the flag on the
|
|
429 |
+ * that says a segment needs sending if/when that pad is activated.
|
|
430 |
+ * For all other cases, we send the event immediately, which makes
|
|
431 |
+ * sparse streams and other segment updates work correctly downstream.
|
|
432 |
+ */
|
|
433 |
+ if (!forward)
|
|
434 |
+ selpad->segment_pending = TRUE;
|
|
435 |
+
|
15203
|
436 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
437 |
+ break;
|
|
438 |
+ }
|
|
439 |
+ case GST_EVENT_TAG:
|
|
440 |
+ {
|
15812
|
441 |
+ GstTagList *tags, *oldtags, *newtags;
|
|
442 |
+
|
|
443 |
+ gst_event_parse_tag (event, &tags);
|
15203
|
444 |
+
|
|
445 |
+ GST_OBJECT_LOCK (selpad);
|
15812
|
446 |
+ oldtags = selpad->tags;
|
|
447 |
+
|
|
448 |
+ newtags = gst_tag_list_merge (oldtags, tags, GST_TAG_MERGE_REPLACE);
|
|
449 |
+ selpad->tags = newtags;
|
|
450 |
+ if (oldtags)
|
|
451 |
+ gst_tag_list_free (oldtags);
|
|
452 |
+ GST_DEBUG_OBJECT (pad, "received tags %" GST_PTR_FORMAT, newtags);
|
15203
|
453 |
+ GST_OBJECT_UNLOCK (selpad);
|
17776
|
454 |
+
|
|
455 |
+ g_object_notify (G_OBJECT (selpad), "tags");
|
15203
|
456 |
+ break;
|
|
457 |
+ }
|
|
458 |
+ case GST_EVENT_EOS:
|
|
459 |
+ selpad->eos = TRUE;
|
|
460 |
+ GST_DEBUG_OBJECT (pad, "received EOS");
|
|
461 |
+ /* don't forward eos in select_all mode until all sink pads have eos */
|
|
462 |
+ if (sel->select_all && !gst_input_selector_check_eos (GST_ELEMENT (sel))) {
|
|
463 |
+ forward = FALSE;
|
|
464 |
+ }
|
|
465 |
+ break;
|
|
466 |
+ default:
|
|
467 |
+ break;
|
|
468 |
+ }
|
|
469 |
+ if (forward) {
|
|
470 |
+ GST_DEBUG_OBJECT (pad, "forwarding event");
|
|
471 |
+ res = gst_pad_push_event (sel->srcpad, event);
|
|
472 |
+ } else
|
|
473 |
+ gst_event_unref (event);
|
|
474 |
+
|
|
475 |
+ gst_object_unref (sel);
|
|
476 |
+
|
|
477 |
+ return res;
|
|
478 |
+}
|
|
479 |
+
|
|
480 |
+static GstCaps *
|
|
481 |
+gst_selector_pad_getcaps (GstPad * pad)
|
|
482 |
+{
|
|
483 |
+ GstInputSelector *sel;
|
|
484 |
+ GstCaps *caps;
|
|
485 |
+
|
|
486 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
487 |
+
|
|
488 |
+ GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer");
|
|
489 |
+ caps = gst_pad_peer_get_caps (sel->srcpad);
|
|
490 |
+ if (caps == NULL)
|
|
491 |
+ caps = gst_caps_new_any ();
|
|
492 |
+
|
|
493 |
+ gst_object_unref (sel);
|
|
494 |
+
|
|
495 |
+ return caps;
|
|
496 |
+}
|
|
497 |
+
|
17776
|
498 |
+static gboolean
|
|
499 |
+gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps)
|
|
500 |
+{
|
|
501 |
+ GstInputSelector *sel;
|
|
502 |
+ gboolean res;
|
|
503 |
+
|
|
504 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
505 |
+
|
|
506 |
+ GST_DEBUG_OBJECT (sel, "Checking acceptcaps of srcpad peer");
|
|
507 |
+ res = gst_pad_peer_accept_caps (sel->srcpad, caps);
|
|
508 |
+ gst_object_unref (sel);
|
|
509 |
+
|
|
510 |
+ return res;
|
|
511 |
+}
|
|
512 |
+
|
15203
|
513 |
+static GstFlowReturn
|
|
514 |
+gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset,
|
|
515 |
+ guint size, GstCaps * caps, GstBuffer ** buf)
|
|
516 |
+{
|
|
517 |
+ GstInputSelector *sel;
|
|
518 |
+ GstFlowReturn result;
|
|
519 |
+ GstPad *active_sinkpad;
|
15812
|
520 |
+ GstPad *prev_active_sinkpad;
|
15203
|
521 |
+ GstSelectorPad *selpad;
|
|
522 |
+
|
|
523 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
524 |
+ selpad = GST_SELECTOR_PAD_CAST (pad);
|
|
525 |
+
|
|
526 |
+ GST_DEBUG_OBJECT (pad, "received alloc");
|
|
527 |
+
|
|
528 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
15812
|
529 |
+ prev_active_sinkpad = sel->active_sinkpad;
|
15203
|
530 |
+ active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
|
|
531 |
+
|
|
532 |
+ if (pad != active_sinkpad)
|
|
533 |
+ goto not_active;
|
|
534 |
+
|
|
535 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
536 |
+
|
15812
|
537 |
+ if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad)
|
|
538 |
+ g_object_notify (G_OBJECT (sel), "active-pad");
|
|
539 |
+
|
15203
|
540 |
+ result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf);
|
|
541 |
+
|
|
542 |
+done:
|
|
543 |
+ gst_object_unref (sel);
|
|
544 |
+
|
|
545 |
+ return result;
|
|
546 |
+
|
|
547 |
+ /* ERRORS */
|
|
548 |
+not_active:
|
|
549 |
+ {
|
|
550 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
551 |
+
|
|
552 |
+ /* unselected pad, perform fallback alloc or return unlinked when
|
|
553 |
+ * asked */
|
|
554 |
+ GST_OBJECT_LOCK (selpad);
|
|
555 |
+ if (selpad->always_ok) {
|
|
556 |
+ GST_DEBUG_OBJECT (pad, "Not selected, performing fallback allocation");
|
|
557 |
+ *buf = NULL;
|
|
558 |
+ result = GST_FLOW_OK;
|
|
559 |
+ } else {
|
|
560 |
+ GST_DEBUG_OBJECT (pad, "Not selected, return NOT_LINKED");
|
|
561 |
+ result = GST_FLOW_NOT_LINKED;
|
|
562 |
+ }
|
|
563 |
+ GST_OBJECT_UNLOCK (selpad);
|
|
564 |
+
|
|
565 |
+ goto done;
|
|
566 |
+ }
|
|
567 |
+}
|
|
568 |
+
|
|
569 |
+/* must be called with the SELECTOR_LOCK, will block while the pad is blocked
|
|
570 |
+ * or return TRUE when flushing */
|
|
571 |
+static gboolean
|
|
572 |
+gst_input_selector_wait (GstInputSelector * self, GstPad * pad)
|
|
573 |
+{
|
|
574 |
+ while (self->blocked && !self->flushing) {
|
|
575 |
+ /* we can be unlocked here when we are shutting down (flushing) or when we
|
|
576 |
+ * get unblocked */
|
|
577 |
+ GST_INPUT_SELECTOR_WAIT (self);
|
|
578 |
+ }
|
|
579 |
+ return self->flushing;
|
|
580 |
+}
|
|
581 |
+
|
|
582 |
+static GstFlowReturn
|
|
583 |
+gst_selector_pad_chain (GstPad * pad, GstBuffer * buf)
|
|
584 |
+{
|
|
585 |
+ GstInputSelector *sel;
|
|
586 |
+ GstFlowReturn res;
|
|
587 |
+ GstPad *active_sinkpad;
|
15812
|
588 |
+ GstPad *prev_active_sinkpad;
|
15203
|
589 |
+ GstSelectorPad *selpad;
|
17776
|
590 |
+ GstClockTime start_time;
|
15203
|
591 |
+ GstSegment *seg;
|
|
592 |
+ GstEvent *close_event = NULL, *start_event = NULL;
|
17776
|
593 |
+ GstCaps *caps;
|
15203
|
594 |
+
|
|
595 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
596 |
+ selpad = GST_SELECTOR_PAD_CAST (pad);
|
|
597 |
+ seg = &selpad->segment;
|
|
598 |
+
|
|
599 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
600 |
+ /* wait or check for flushing */
|
|
601 |
+ if (gst_input_selector_wait (sel, pad))
|
|
602 |
+ goto flushing;
|
|
603 |
+
|
|
604 |
+ GST_DEBUG_OBJECT (pad, "getting active pad");
|
|
605 |
+
|
15812
|
606 |
+ prev_active_sinkpad = sel->active_sinkpad;
|
15203
|
607 |
+ active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
|
|
608 |
+
|
|
609 |
+ /* update the segment on the srcpad */
|
17776
|
610 |
+ start_time = GST_BUFFER_TIMESTAMP (buf);
|
|
611 |
+ if (GST_CLOCK_TIME_IS_VALID (start_time)) {
|
|
612 |
+ GST_DEBUG_OBJECT (pad, "received start time %" GST_TIME_FORMAT,
|
|
613 |
+ GST_TIME_ARGS (start_time));
|
|
614 |
+ if (GST_BUFFER_DURATION_IS_VALID (buf))
|
|
615 |
+ GST_DEBUG_OBJECT (pad, "received end time %" GST_TIME_FORMAT,
|
|
616 |
+ GST_TIME_ARGS (start_time + GST_BUFFER_DURATION (buf)));
|
15203
|
617 |
+
|
|
618 |
+ GST_OBJECT_LOCK (pad);
|
17776
|
619 |
+ gst_segment_set_last_stop (seg, seg->format, start_time);
|
15203
|
620 |
+ GST_OBJECT_UNLOCK (pad);
|
|
621 |
+ }
|
|
622 |
+
|
|
623 |
+ /* Ignore buffers from pads except the selected one */
|
|
624 |
+ if (pad != active_sinkpad)
|
|
625 |
+ goto ignore;
|
|
626 |
+
|
|
627 |
+ if (G_UNLIKELY (sel->pending_close)) {
|
|
628 |
+ GstSegment *cseg = &sel->segment;
|
|
629 |
+
|
|
630 |
+ GST_DEBUG_OBJECT (sel,
|
17776
|
631 |
+ "pushing close NEWSEGMENT update %d, rate %lf, applied rate %lf, "
|
15203
|
632 |
+ "format %d, "
|
|
633 |
+ "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
|
|
634 |
+ G_GINT64_FORMAT, TRUE, cseg->rate, cseg->applied_rate, cseg->format,
|
|
635 |
+ cseg->start, cseg->stop, cseg->time);
|
|
636 |
+
|
|
637 |
+ /* create update segment */
|
|
638 |
+ close_event = gst_event_new_new_segment_full (TRUE, cseg->rate,
|
|
639 |
+ cseg->applied_rate, cseg->format, cseg->start, cseg->stop, cseg->time);
|
|
640 |
+
|
|
641 |
+ sel->pending_close = FALSE;
|
|
642 |
+ }
|
|
643 |
+ /* if we have a pending segment, push it out now */
|
|
644 |
+ if (G_UNLIKELY (selpad->segment_pending)) {
|
|
645 |
+ GST_DEBUG_OBJECT (pad,
|
17776
|
646 |
+ "pushing pending NEWSEGMENT update %d, rate %lf, applied rate %lf, "
|
15203
|
647 |
+ "format %d, "
|
|
648 |
+ "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
|
|
649 |
+ G_GINT64_FORMAT, FALSE, seg->rate, seg->applied_rate, seg->format,
|
|
650 |
+ seg->start, seg->stop, seg->time);
|
|
651 |
+
|
|
652 |
+ start_event = gst_event_new_new_segment_full (FALSE, seg->rate,
|
|
653 |
+ seg->applied_rate, seg->format, seg->start, seg->stop, seg->time);
|
|
654 |
+
|
|
655 |
+ selpad->segment_pending = FALSE;
|
|
656 |
+ }
|
|
657 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
658 |
+
|
15812
|
659 |
+ if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad)
|
|
660 |
+ g_object_notify (G_OBJECT (sel), "active-pad");
|
|
661 |
+
|
15203
|
662 |
+ if (close_event)
|
|
663 |
+ gst_pad_push_event (sel->srcpad, close_event);
|
|
664 |
+
|
|
665 |
+ if (start_event)
|
|
666 |
+ gst_pad_push_event (sel->srcpad, start_event);
|
|
667 |
+
|
|
668 |
+ if (selpad->discont) {
|
|
669 |
+ buf = gst_buffer_make_metadata_writable (buf);
|
|
670 |
+
|
|
671 |
+ GST_DEBUG_OBJECT (pad, "Marking discont buffer %p", buf);
|
|
672 |
+ GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
|
|
673 |
+ selpad->discont = FALSE;
|
|
674 |
+ }
|
|
675 |
+
|
|
676 |
+ /* forward */
|
|
677 |
+ GST_DEBUG_OBJECT (pad, "Forwarding buffer %p from pad %s:%s", buf,
|
|
678 |
+ GST_DEBUG_PAD_NAME (pad));
|
|
679 |
+
|
17776
|
680 |
+ if ((caps = GST_BUFFER_CAPS (buf))) {
|
|
681 |
+ if (GST_PAD_CAPS (sel->srcpad) != caps)
|
|
682 |
+ gst_pad_set_caps (sel->srcpad, caps);
|
|
683 |
+ }
|
|
684 |
+
|
15203
|
685 |
+ res = gst_pad_push (sel->srcpad, buf);
|
|
686 |
+
|
|
687 |
+done:
|
|
688 |
+ gst_object_unref (sel);
|
|
689 |
+ return res;
|
|
690 |
+
|
|
691 |
+ /* dropped buffers */
|
|
692 |
+ignore:
|
|
693 |
+ {
|
|
694 |
+ GST_DEBUG_OBJECT (pad, "Pad not active, discard buffer %p", buf);
|
|
695 |
+ /* when we drop a buffer, we're creating a discont on this pad */
|
|
696 |
+ selpad->discont = TRUE;
|
|
697 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
698 |
+ gst_buffer_unref (buf);
|
|
699 |
+
|
|
700 |
+ /* figure out what to return upstream */
|
|
701 |
+ GST_OBJECT_LOCK (selpad);
|
|
702 |
+ if (selpad->always_ok)
|
|
703 |
+ res = GST_FLOW_OK;
|
|
704 |
+ else
|
|
705 |
+ res = GST_FLOW_NOT_LINKED;
|
|
706 |
+ GST_OBJECT_UNLOCK (selpad);
|
|
707 |
+
|
|
708 |
+ goto done;
|
|
709 |
+ }
|
|
710 |
+flushing:
|
|
711 |
+ {
|
|
712 |
+ GST_DEBUG_OBJECT (pad, "We are flushing, discard buffer %p", buf);
|
|
713 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
714 |
+ gst_buffer_unref (buf);
|
|
715 |
+ res = GST_FLOW_WRONG_STATE;
|
|
716 |
+ goto done;
|
|
717 |
+ }
|
|
718 |
+}
|
|
719 |
+
|
|
720 |
+static void gst_input_selector_init (GstInputSelector * sel);
|
|
721 |
+static void gst_input_selector_base_init (GstInputSelectorClass * klass);
|
|
722 |
+static void gst_input_selector_class_init (GstInputSelectorClass * klass);
|
|
723 |
+
|
|
724 |
+static void gst_input_selector_dispose (GObject * object);
|
|
725 |
+
|
|
726 |
+static void gst_input_selector_set_property (GObject * object,
|
|
727 |
+ guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
728 |
+static void gst_input_selector_get_property (GObject * object,
|
|
729 |
+ guint prop_id, GValue * value, GParamSpec * pspec);
|
|
730 |
+
|
|
731 |
+static GstPad *gst_input_selector_request_new_pad (GstElement * element,
|
|
732 |
+ GstPadTemplate * templ, const gchar * unused);
|
|
733 |
+static void gst_input_selector_release_pad (GstElement * element, GstPad * pad);
|
|
734 |
+
|
|
735 |
+static GstStateChangeReturn gst_input_selector_change_state (GstElement *
|
|
736 |
+ element, GstStateChange transition);
|
|
737 |
+
|
|
738 |
+static GstCaps *gst_input_selector_getcaps (GstPad * pad);
|
|
739 |
+static gboolean gst_input_selector_event (GstPad * pad, GstEvent * event);
|
|
740 |
+static gboolean gst_input_selector_query (GstPad * pad, GstQuery * query);
|
|
741 |
+static gint64 gst_input_selector_block (GstInputSelector * self);
|
|
742 |
+static void gst_input_selector_switch (GstInputSelector * self,
|
|
743 |
+ GstPad * pad, gint64 stop_time, gint64 start_time);
|
|
744 |
+
|
|
745 |
+static GstElementClass *parent_class = NULL;
|
|
746 |
+
|
|
747 |
+GType
|
|
748 |
+gst_input_selector_get_type (void)
|
|
749 |
+{
|
|
750 |
+ static GType input_selector_type = 0;
|
|
751 |
+
|
|
752 |
+ if (!input_selector_type) {
|
|
753 |
+ static const GTypeInfo input_selector_info = {
|
|
754 |
+ sizeof (GstInputSelectorClass),
|
|
755 |
+ (GBaseInitFunc) gst_input_selector_base_init,
|
|
756 |
+ NULL,
|
|
757 |
+ (GClassInitFunc) gst_input_selector_class_init,
|
|
758 |
+ NULL,
|
|
759 |
+ NULL,
|
|
760 |
+ sizeof (GstInputSelector),
|
|
761 |
+ 0,
|
|
762 |
+ (GInstanceInitFunc) gst_input_selector_init,
|
|
763 |
+ };
|
|
764 |
+ input_selector_type =
|
|
765 |
+ g_type_register_static (GST_TYPE_ELEMENT,
|
|
766 |
+ "GstInputSelector", &input_selector_info, 0);
|
|
767 |
+ GST_DEBUG_CATEGORY_INIT (input_selector_debug,
|
|
768 |
+ "input-selector", 0, "An input stream selector element");
|
|
769 |
+ }
|
|
770 |
+
|
|
771 |
+ return input_selector_type;
|
|
772 |
+}
|
|
773 |
+
|
|
774 |
+static void
|
|
775 |
+gst_input_selector_base_init (GstInputSelectorClass * klass)
|
|
776 |
+{
|
|
777 |
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
778 |
+
|
|
779 |
+ gst_element_class_set_details (element_class, &gst_input_selector_details);
|
|
780 |
+ gst_element_class_add_pad_template (element_class,
|
|
781 |
+ gst_static_pad_template_get (&gst_input_selector_sink_factory));
|
|
782 |
+ gst_element_class_add_pad_template (element_class,
|
|
783 |
+ gst_static_pad_template_get (&gst_input_selector_src_factory));
|
|
784 |
+}
|
|
785 |
+
|
|
786 |
+static void
|
|
787 |
+gst_input_selector_class_init (GstInputSelectorClass * klass)
|
|
788 |
+{
|
|
789 |
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
790 |
+ GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
791 |
+
|
|
792 |
+ parent_class = g_type_class_peek_parent (klass);
|
|
793 |
+
|
|
794 |
+ gobject_class->dispose = gst_input_selector_dispose;
|
|
795 |
+
|
17776
|
796 |
+ gobject_class->set_property = gst_input_selector_set_property;
|
|
797 |
+ gobject_class->get_property = gst_input_selector_get_property;
|
15203
|
798 |
+
|
|
799 |
+ g_object_class_install_property (gobject_class, PROP_N_PADS,
|
|
800 |
+ g_param_spec_uint ("n-pads", "Number of Pads",
|
|
801 |
+ "The number of sink pads", 0, G_MAXUINT, 0, G_PARAM_READABLE));
|
|
802 |
+
|
|
803 |
+ g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
|
|
804 |
+ g_param_spec_object ("active-pad", "Active pad",
|
|
805 |
+ "The currently active sink pad", GST_TYPE_PAD, G_PARAM_READWRITE));
|
|
806 |
+
|
|
807 |
+ g_object_class_install_property (gobject_class, PROP_SELECT_ALL,
|
|
808 |
+ g_param_spec_boolean ("select-all", "Select all mode",
|
|
809 |
+ "Forwards data from all input pads", FALSE, G_PARAM_READWRITE));
|
|
810 |
+
|
|
811 |
+ /**
|
|
812 |
+ * GstInputSelector::block:
|
|
813 |
+ * @inputselector: the #GstInputSelector
|
|
814 |
+ *
|
|
815 |
+ * Block all sink pads in preparation for a switch. Returns the stop time of
|
|
816 |
+ * the current switch segment, as a running time, or 0 if there is no current
|
|
817 |
+ * active pad or the current active pad never received data.
|
|
818 |
+ */
|
|
819 |
+ gst_input_selector_signals[SIGNAL_BLOCK] =
|
|
820 |
+ g_signal_new ("block", G_TYPE_FROM_CLASS (klass),
|
|
821 |
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
822 |
+ G_STRUCT_OFFSET (GstInputSelectorClass, block), NULL, NULL,
|
|
823 |
+ gst_selector_marshal_INT64__VOID, G_TYPE_INT64, 0);
|
|
824 |
+ /**
|
|
825 |
+ * GstInputSelector::switch:
|
|
826 |
+ * @inputselector: the #GstInputSelector
|
|
827 |
+ * @pad: the pad to switch to
|
|
828 |
+ * @stop_time: running time at which to close the previous segment, or -1
|
|
829 |
+ * to use the running time of the previously active sink pad
|
|
830 |
+ * @start_time: running time at which to start the new segment, or -1 to
|
|
831 |
+ * use the running time of the newly active sink pad
|
|
832 |
+ *
|
|
833 |
+ * Switch to a new feed. The segment opened by the previously active pad, if
|
|
834 |
+ * any, will be closed, and a new segment opened before data flows again.
|
|
835 |
+ *
|
|
836 |
+ * This signal must be emitted when the element has been blocked via the <link
|
|
837 |
+ * linkend="GstInputSelector-block">block</link> signal.
|
|
838 |
+ *
|
|
839 |
+ * If you have a stream with only one switch element, such as an audio-only
|
|
840 |
+ * stream, a stream switch should be performed by first emitting the block
|
|
841 |
+ * signal, and then emitting the switch signal with -1 for the stop and start
|
|
842 |
+ * time values.
|
|
843 |
+ *
|
|
844 |
+ * The intention of the @stop_time and @start_time arguments is to allow
|
|
845 |
+ * multiple switch elements to switch and maintain stream synchronization.
|
|
846 |
+ * When switching a stream with multiple feeds, you will need as many switch
|
|
847 |
+ * elements as you have feeds. For example, a feed with audio and video will
|
|
848 |
+ * have one switch element between the audio feeds and one for video.
|
|
849 |
+ *
|
|
850 |
+ * A switch over multiple switch elements should be performed as follows:
|
|
851 |
+ * First, emit the <link linkend="GstInputSelector-block">block</link>
|
|
852 |
+ * signal, collecting the returned values. The maximum running time returned
|
|
853 |
+ * by block should then be used as the time at which to close the previous
|
|
854 |
+ * segment.
|
|
855 |
+ *
|
|
856 |
+ * Then, query the running times of the new audio and video pads that you will
|
|
857 |
+ * switch to. Naturally, these pads are on separate switch elements. Take the
|
|
858 |
+ * minimum running time for those streams and use it for the time at which to
|
|
859 |
+ * open the new segment.
|
|
860 |
+ *
|
|
861 |
+ * If @pad is the same as the current active pad, the element will cancel any
|
|
862 |
+ * previous block without adjusting segments.
|
|
863 |
+ *
|
15812
|
864 |
+ * <note><simpara>
|
|
865 |
+ * the signal changed from accepting the pad name to the pad object.
|
|
866 |
+ * </simpara></note>
|
|
867 |
+ *
|
|
868 |
+ * Since: 0.10.7
|
15203
|
869 |
+ */
|
|
870 |
+ gst_input_selector_signals[SIGNAL_SWITCH] =
|
|
871 |
+ g_signal_new ("switch", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
872 |
+ G_STRUCT_OFFSET (GstInputSelectorClass, switch_),
|
|
873 |
+ NULL, NULL, gst_selector_marshal_VOID__OBJECT_INT64_INT64,
|
|
874 |
+ G_TYPE_NONE, 3, GST_TYPE_PAD, G_TYPE_INT64, G_TYPE_INT64);
|
|
875 |
+
|
|
876 |
+ gstelement_class->request_new_pad = gst_input_selector_request_new_pad;
|
|
877 |
+ gstelement_class->release_pad = gst_input_selector_release_pad;
|
|
878 |
+ gstelement_class->change_state = gst_input_selector_change_state;
|
|
879 |
+
|
|
880 |
+ klass->block = GST_DEBUG_FUNCPTR (gst_input_selector_block);
|
|
881 |
+ /* note the underscore because switch is a keyword otherwise */
|
|
882 |
+ klass->switch_ = GST_DEBUG_FUNCPTR (gst_input_selector_switch);
|
|
883 |
+}
|
|
884 |
+
|
|
885 |
+static void
|
|
886 |
+gst_input_selector_init (GstInputSelector * sel)
|
|
887 |
+{
|
|
888 |
+ sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
17776
|
889 |
+ gst_pad_set_iterate_internal_links_function (sel->srcpad,
|
|
890 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
|
15203
|
891 |
+ gst_pad_set_getcaps_function (sel->srcpad,
|
|
892 |
+ GST_DEBUG_FUNCPTR (gst_input_selector_getcaps));
|
|
893 |
+ gst_pad_set_query_function (sel->srcpad,
|
|
894 |
+ GST_DEBUG_FUNCPTR (gst_input_selector_query));
|
|
895 |
+ gst_pad_set_event_function (sel->srcpad,
|
|
896 |
+ GST_DEBUG_FUNCPTR (gst_input_selector_event));
|
|
897 |
+ gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
|
|
898 |
+ /* sinkpad management */
|
|
899 |
+ sel->active_sinkpad = NULL;
|
|
900 |
+ sel->padcount = 0;
|
|
901 |
+ gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
|
|
902 |
+
|
|
903 |
+ sel->lock = g_mutex_new ();
|
|
904 |
+ sel->cond = g_cond_new ();
|
|
905 |
+ sel->blocked = FALSE;
|
|
906 |
+
|
|
907 |
+ sel->select_all = FALSE;
|
|
908 |
+}
|
|
909 |
+
|
|
910 |
+static void
|
|
911 |
+gst_input_selector_dispose (GObject * object)
|
|
912 |
+{
|
|
913 |
+ GstInputSelector *sel = GST_INPUT_SELECTOR (object);
|
|
914 |
+
|
|
915 |
+ if (sel->active_sinkpad) {
|
|
916 |
+ gst_object_unref (sel->active_sinkpad);
|
|
917 |
+ sel->active_sinkpad = NULL;
|
|
918 |
+ }
|
|
919 |
+ if (sel->lock) {
|
|
920 |
+ g_mutex_free (sel->lock);
|
|
921 |
+ sel->lock = NULL;
|
|
922 |
+ }
|
|
923 |
+ if (sel->cond) {
|
|
924 |
+ g_cond_free (sel->cond);
|
|
925 |
+ sel->cond = NULL;
|
|
926 |
+ }
|
|
927 |
+
|
|
928 |
+ G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
929 |
+}
|
|
930 |
+
|
|
931 |
+/* Solve the following equation for B.timestamp, and set that as the segment
|
|
932 |
+ * stop:
|
|
933 |
+ * B.running_time = (B.timestamp - NS.start) / NS.abs_rate + NS.accum
|
|
934 |
+ */
|
|
935 |
+static gint64
|
|
936 |
+gst_segment_get_timestamp (GstSegment * segment, gint64 running_time)
|
|
937 |
+{
|
17776
|
938 |
+ if (running_time <= segment->accum)
|
|
939 |
+ return segment->start;
|
|
940 |
+ else
|
|
941 |
+ return (running_time - segment->accum) * segment->abs_rate + segment->start;
|
15203
|
942 |
+}
|
|
943 |
+
|
|
944 |
+static void
|
|
945 |
+gst_segment_set_stop (GstSegment * segment, gint64 running_time)
|
|
946 |
+{
|
|
947 |
+ segment->stop = gst_segment_get_timestamp (segment, running_time);
|
|
948 |
+ segment->last_stop = -1;
|
|
949 |
+}
|
|
950 |
+
|
|
951 |
+static void
|
|
952 |
+gst_segment_set_start (GstSegment * segment, gint64 running_time)
|
|
953 |
+{
|
|
954 |
+ gint64 new_start, duration;
|
|
955 |
+
|
|
956 |
+ new_start = gst_segment_get_timestamp (segment, running_time);
|
|
957 |
+
|
|
958 |
+ /* this is the duration we skipped */
|
|
959 |
+ duration = new_start - segment->start;
|
|
960 |
+ /* add the duration to the accumulated segment time */
|
|
961 |
+ segment->accum += duration;
|
|
962 |
+ /* move position in the segment */
|
|
963 |
+ segment->time += duration;
|
|
964 |
+ segment->start += duration;
|
|
965 |
+}
|
|
966 |
+
|
|
967 |
+/* this function must be called with the SELECTOR_LOCK. It returns TRUE when the
|
|
968 |
+ * active pad changed. */
|
|
969 |
+static gboolean
|
|
970 |
+gst_input_selector_set_active_pad (GstInputSelector * self,
|
|
971 |
+ GstPad * pad, gint64 stop_time, gint64 start_time)
|
|
972 |
+{
|
|
973 |
+ GstSelectorPad *old, *new;
|
|
974 |
+ GstPad **active_pad_p;
|
|
975 |
+
|
|
976 |
+ if (pad == self->active_sinkpad)
|
|
977 |
+ return FALSE;
|
|
978 |
+
|
|
979 |
+ old = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
|
|
980 |
+ new = GST_SELECTOR_PAD_CAST (pad);
|
|
981 |
+
|
|
982 |
+ GST_DEBUG_OBJECT (self, "setting active pad to %s:%s",
|
|
983 |
+ GST_DEBUG_PAD_NAME (new));
|
|
984 |
+
|
|
985 |
+ if (stop_time == -1 && old) {
|
|
986 |
+ /* no stop time given, get the latest running_time on the active pad to
|
|
987 |
+ * close and open the new segment */
|
|
988 |
+ stop_time = start_time = gst_selector_pad_get_running_time (old);
|
|
989 |
+ GST_DEBUG_OBJECT (self, "using start/stop of %" G_GINT64_FORMAT,
|
|
990 |
+ start_time);
|
|
991 |
+ }
|
|
992 |
+
|
|
993 |
+ if (old && old->active && !self->pending_close && stop_time >= 0) {
|
|
994 |
+ /* schedule a last_stop update if one isn't already scheduled, and a
|
|
995 |
+ segment has been pushed before. */
|
|
996 |
+ memcpy (&self->segment, &old->segment, sizeof (self->segment));
|
15812
|
997 |
+
|
15203
|
998 |
+ GST_DEBUG_OBJECT (self, "setting stop_time to %" G_GINT64_FORMAT,
|
|
999 |
+ stop_time);
|
|
1000 |
+ gst_segment_set_stop (&self->segment, stop_time);
|
|
1001 |
+ self->pending_close = TRUE;
|
|
1002 |
+ }
|
|
1003 |
+
|
|
1004 |
+ if (new && new->active && start_time >= 0) {
|
|
1005 |
+ GST_DEBUG_OBJECT (self, "setting start_time to %" G_GINT64_FORMAT,
|
|
1006 |
+ start_time);
|
|
1007 |
+ /* schedule a new segment push */
|
|
1008 |
+ gst_segment_set_start (&new->segment, start_time);
|
|
1009 |
+ new->segment_pending = TRUE;
|
|
1010 |
+ }
|
|
1011 |
+
|
|
1012 |
+ active_pad_p = &self->active_sinkpad;
|
|
1013 |
+ gst_object_replace ((GstObject **) active_pad_p, GST_OBJECT_CAST (pad));
|
|
1014 |
+ GST_DEBUG_OBJECT (self, "New active pad is %" GST_PTR_FORMAT,
|
|
1015 |
+ self->active_sinkpad);
|
|
1016 |
+
|
|
1017 |
+ return TRUE;
|
|
1018 |
+}
|
|
1019 |
+
|
|
1020 |
+static void
|
|
1021 |
+gst_input_selector_set_property (GObject * object, guint prop_id,
|
|
1022 |
+ const GValue * value, GParamSpec * pspec)
|
|
1023 |
+{
|
|
1024 |
+ GstInputSelector *sel = GST_INPUT_SELECTOR (object);
|
|
1025 |
+
|
|
1026 |
+ switch (prop_id) {
|
|
1027 |
+ case PROP_ACTIVE_PAD:
|
|
1028 |
+ {
|
|
1029 |
+ GstPad *pad;
|
|
1030 |
+
|
|
1031 |
+ pad = g_value_get_object (value);
|
|
1032 |
+
|
|
1033 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1034 |
+ gst_input_selector_set_active_pad (sel, pad,
|
|
1035 |
+ GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
|
|
1036 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1037 |
+ break;
|
|
1038 |
+ }
|
|
1039 |
+ case PROP_SELECT_ALL:
|
|
1040 |
+ GST_INPUT_SELECTOR_LOCK (object);
|
|
1041 |
+ sel->select_all = g_value_get_boolean (value);
|
|
1042 |
+ GST_INPUT_SELECTOR_UNLOCK (object);
|
|
1043 |
+ break;
|
|
1044 |
+ default:
|
|
1045 |
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
1046 |
+ break;
|
|
1047 |
+ }
|
|
1048 |
+}
|
|
1049 |
+
|
|
1050 |
+static void
|
|
1051 |
+gst_input_selector_get_property (GObject * object, guint prop_id,
|
|
1052 |
+ GValue * value, GParamSpec * pspec)
|
|
1053 |
+{
|
|
1054 |
+ GstInputSelector *sel = GST_INPUT_SELECTOR (object);
|
|
1055 |
+
|
|
1056 |
+ switch (prop_id) {
|
|
1057 |
+ case PROP_N_PADS:
|
|
1058 |
+ GST_INPUT_SELECTOR_LOCK (object);
|
|
1059 |
+ g_value_set_uint (value, sel->n_pads);
|
|
1060 |
+ GST_INPUT_SELECTOR_UNLOCK (object);
|
|
1061 |
+ break;
|
|
1062 |
+ case PROP_ACTIVE_PAD:
|
|
1063 |
+ GST_INPUT_SELECTOR_LOCK (object);
|
|
1064 |
+ g_value_set_object (value, sel->active_sinkpad);
|
|
1065 |
+ GST_INPUT_SELECTOR_UNLOCK (object);
|
|
1066 |
+ break;
|
|
1067 |
+ case PROP_SELECT_ALL:
|
|
1068 |
+ GST_INPUT_SELECTOR_LOCK (object);
|
|
1069 |
+ g_value_set_boolean (value, sel->select_all);
|
|
1070 |
+ GST_INPUT_SELECTOR_UNLOCK (object);
|
|
1071 |
+ break;
|
|
1072 |
+ default:
|
|
1073 |
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
1074 |
+ break;
|
|
1075 |
+ }
|
|
1076 |
+}
|
|
1077 |
+
|
|
1078 |
+static GstPad *
|
|
1079 |
+gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict)
|
|
1080 |
+{
|
|
1081 |
+ GstInputSelector *sel;
|
|
1082 |
+ GstPad *otherpad = NULL;
|
|
1083 |
+
|
|
1084 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
1085 |
+
|
|
1086 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1087 |
+ if (pad == sel->srcpad)
|
|
1088 |
+ otherpad = sel->active_sinkpad;
|
|
1089 |
+ else if (pad == sel->active_sinkpad || !strict)
|
|
1090 |
+ otherpad = sel->srcpad;
|
|
1091 |
+ if (otherpad)
|
|
1092 |
+ gst_object_ref (otherpad);
|
|
1093 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1094 |
+
|
|
1095 |
+ gst_object_unref (sel);
|
|
1096 |
+
|
|
1097 |
+ return otherpad;
|
|
1098 |
+}
|
|
1099 |
+
|
|
1100 |
+static gboolean
|
|
1101 |
+gst_input_selector_event (GstPad * pad, GstEvent * event)
|
|
1102 |
+{
|
|
1103 |
+ gboolean res = FALSE;
|
|
1104 |
+ GstPad *otherpad;
|
|
1105 |
+
|
|
1106 |
+ otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
|
|
1107 |
+
|
|
1108 |
+ if (otherpad) {
|
|
1109 |
+ res = gst_pad_push_event (otherpad, event);
|
|
1110 |
+
|
|
1111 |
+ gst_object_unref (otherpad);
|
15812
|
1112 |
+ } else
|
|
1113 |
+ gst_event_unref (event);
|
15203
|
1114 |
+ return res;
|
|
1115 |
+}
|
|
1116 |
+
|
|
1117 |
+/* query on the srcpad. We override this function because by default it will
|
|
1118 |
+ * only forward the query to one random sinkpad */
|
|
1119 |
+static gboolean
|
|
1120 |
+gst_input_selector_query (GstPad * pad, GstQuery * query)
|
|
1121 |
+{
|
|
1122 |
+ gboolean res = TRUE;
|
|
1123 |
+ GstInputSelector *sel;
|
|
1124 |
+ GstPad *otherpad;
|
|
1125 |
+
|
|
1126 |
+ sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
1127 |
+
|
|
1128 |
+ otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
|
|
1129 |
+
|
|
1130 |
+ switch (GST_QUERY_TYPE (query)) {
|
|
1131 |
+ case GST_QUERY_LATENCY:
|
|
1132 |
+ {
|
|
1133 |
+ GList *walk;
|
|
1134 |
+ GstClockTime resmin, resmax;
|
|
1135 |
+ gboolean reslive;
|
|
1136 |
+
|
|
1137 |
+ resmin = 0;
|
|
1138 |
+ resmax = -1;
|
|
1139 |
+ reslive = FALSE;
|
|
1140 |
+
|
|
1141 |
+ /* assume FALSE, we become TRUE if one query succeeds */
|
|
1142 |
+ res = FALSE;
|
|
1143 |
+
|
|
1144 |
+ /* perform the query on all sinkpads and combine the results. We take the
|
|
1145 |
+ * max of min and the min of max for the result latency. */
|
|
1146 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1147 |
+ for (walk = GST_ELEMENT_CAST (sel)->sinkpads; walk;
|
|
1148 |
+ walk = g_list_next (walk)) {
|
|
1149 |
+ GstPad *sinkpad = GST_PAD_CAST (walk->data);
|
|
1150 |
+
|
|
1151 |
+ if (gst_pad_peer_query (sinkpad, query)) {
|
|
1152 |
+ GstClockTime min, max;
|
|
1153 |
+ gboolean live;
|
|
1154 |
+
|
|
1155 |
+ /* one query succeeded, we succeed too */
|
|
1156 |
+ res = TRUE;
|
|
1157 |
+
|
|
1158 |
+ gst_query_parse_latency (query, &live, &min, &max);
|
|
1159 |
+
|
|
1160 |
+ GST_DEBUG_OBJECT (sinkpad,
|
|
1161 |
+ "peer latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
|
|
1162 |
+ ", live %d", GST_TIME_ARGS (min), GST_TIME_ARGS (max), live);
|
|
1163 |
+
|
|
1164 |
+ if (live) {
|
|
1165 |
+ if (min > resmin)
|
|
1166 |
+ resmin = min;
|
|
1167 |
+ if (resmax == -1)
|
|
1168 |
+ resmax = max;
|
|
1169 |
+ else if (max < resmax)
|
|
1170 |
+ resmax = max;
|
|
1171 |
+ if (reslive == FALSE)
|
|
1172 |
+ reslive = live;
|
|
1173 |
+ }
|
|
1174 |
+ }
|
|
1175 |
+ }
|
|
1176 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1177 |
+ if (res) {
|
|
1178 |
+ gst_query_set_latency (query, reslive, resmin, resmax);
|
|
1179 |
+
|
|
1180 |
+ GST_DEBUG_OBJECT (sel,
|
|
1181 |
+ "total latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
|
|
1182 |
+ ", live %d", GST_TIME_ARGS (resmin), GST_TIME_ARGS (resmax),
|
|
1183 |
+ reslive);
|
|
1184 |
+ }
|
|
1185 |
+
|
|
1186 |
+ break;
|
|
1187 |
+ }
|
|
1188 |
+ default:
|
|
1189 |
+ if (otherpad)
|
|
1190 |
+ res = gst_pad_peer_query (otherpad, query);
|
|
1191 |
+ break;
|
|
1192 |
+ }
|
|
1193 |
+ if (otherpad)
|
|
1194 |
+ gst_object_unref (otherpad);
|
|
1195 |
+ gst_object_unref (sel);
|
|
1196 |
+
|
|
1197 |
+ return res;
|
|
1198 |
+}
|
|
1199 |
+
|
|
1200 |
+static GstCaps *
|
|
1201 |
+gst_input_selector_getcaps (GstPad * pad)
|
|
1202 |
+{
|
|
1203 |
+ GstPad *otherpad;
|
|
1204 |
+ GstObject *parent;
|
|
1205 |
+ GstCaps *caps;
|
|
1206 |
+
|
|
1207 |
+ parent = gst_object_get_parent (GST_OBJECT (pad));
|
|
1208 |
+
|
|
1209 |
+ otherpad = gst_input_selector_get_linked_pad (pad, FALSE);
|
|
1210 |
+
|
|
1211 |
+ if (!otherpad) {
|
|
1212 |
+ if (GST_INPUT_SELECTOR (parent)->select_all) {
|
|
1213 |
+ GST_DEBUG_OBJECT (parent,
|
|
1214 |
+ "Pad %s:%s not linked, returning merge of caps",
|
|
1215 |
+ GST_DEBUG_PAD_NAME (pad));
|
|
1216 |
+ caps = gst_pad_proxy_getcaps (pad);
|
|
1217 |
+ } else {
|
|
1218 |
+ GST_DEBUG_OBJECT (parent,
|
|
1219 |
+ "Pad %s:%s not linked, returning ANY", GST_DEBUG_PAD_NAME (pad));
|
|
1220 |
+ caps = gst_caps_new_any ();
|
|
1221 |
+ }
|
|
1222 |
+ } else {
|
|
1223 |
+ GST_DEBUG_OBJECT (parent,
|
|
1224 |
+ "Pad %s:%s is linked (to %s:%s), returning peer caps",
|
|
1225 |
+ GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (otherpad));
|
|
1226 |
+ /* if the peer has caps, use those. If the pad is not linked, this function
|
|
1227 |
+ * returns NULL and we return ANY */
|
|
1228 |
+ if (!(caps = gst_pad_peer_get_caps (otherpad)))
|
|
1229 |
+ caps = gst_caps_new_any ();
|
|
1230 |
+ gst_object_unref (otherpad);
|
|
1231 |
+ }
|
|
1232 |
+
|
|
1233 |
+ gst_object_unref (parent);
|
|
1234 |
+ return caps;
|
|
1235 |
+}
|
|
1236 |
+
|
|
1237 |
+/* check if the pad is the active sinkpad */
|
17776
|
1238 |
+static inline gboolean
|
15203
|
1239 |
+gst_input_selector_is_active_sinkpad (GstInputSelector * sel, GstPad * pad)
|
|
1240 |
+{
|
|
1241 |
+ gboolean res;
|
|
1242 |
+
|
|
1243 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1244 |
+ res = (pad == sel->active_sinkpad);
|
|
1245 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1246 |
+
|
|
1247 |
+ return res;
|
|
1248 |
+}
|
|
1249 |
+
|
|
1250 |
+/* Get or create the active sinkpad, must be called with SELECTOR_LOCK */
|
|
1251 |
+static GstPad *
|
|
1252 |
+gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad)
|
|
1253 |
+{
|
|
1254 |
+ GstPad *active_sinkpad;
|
|
1255 |
+ GstSelectorPad *selpad;
|
|
1256 |
+
|
|
1257 |
+ selpad = GST_SELECTOR_PAD_CAST (pad);
|
|
1258 |
+
|
|
1259 |
+ selpad->active = TRUE;
|
|
1260 |
+ active_sinkpad = sel->active_sinkpad;
|
|
1261 |
+ if (active_sinkpad == NULL || sel->select_all) {
|
|
1262 |
+ /* first pad we get activity on becomes the activated pad by default, if we
|
|
1263 |
+ * select all, we also remember the last used pad. */
|
15812
|
1264 |
+ if (sel->active_sinkpad)
|
|
1265 |
+ gst_object_unref (sel->active_sinkpad);
|
15203
|
1266 |
+ active_sinkpad = sel->active_sinkpad = gst_object_ref (pad);
|
|
1267 |
+ GST_DEBUG_OBJECT (sel, "Activating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
1268 |
+ }
|
|
1269 |
+
|
|
1270 |
+ return active_sinkpad;
|
|
1271 |
+}
|
|
1272 |
+
|
|
1273 |
+static GstPad *
|
|
1274 |
+gst_input_selector_request_new_pad (GstElement * element,
|
|
1275 |
+ GstPadTemplate * templ, const gchar * unused)
|
|
1276 |
+{
|
|
1277 |
+ GstInputSelector *sel;
|
|
1278 |
+ gchar *name = NULL;
|
|
1279 |
+ GstPad *sinkpad = NULL;
|
|
1280 |
+
|
|
1281 |
+ g_return_val_if_fail (templ->direction == GST_PAD_SINK, NULL);
|
|
1282 |
+
|
|
1283 |
+ sel = GST_INPUT_SELECTOR (element);
|
|
1284 |
+
|
|
1285 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1286 |
+
|
|
1287 |
+ GST_LOG_OBJECT (sel, "Creating new pad %d", sel->padcount);
|
|
1288 |
+ name = g_strdup_printf ("sink%d", sel->padcount++);
|
|
1289 |
+ sinkpad = g_object_new (GST_TYPE_SELECTOR_PAD,
|
|
1290 |
+ "name", name, "direction", templ->direction, "template", templ, NULL);
|
|
1291 |
+ g_free (name);
|
|
1292 |
+
|
|
1293 |
+ sel->n_pads++;
|
|
1294 |
+
|
|
1295 |
+ gst_pad_set_event_function (sinkpad,
|
|
1296 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_event));
|
|
1297 |
+ gst_pad_set_getcaps_function (sinkpad,
|
|
1298 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_getcaps));
|
17776
|
1299 |
+ gst_pad_set_acceptcaps_function (sinkpad,
|
|
1300 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_acceptcaps));
|
15203
|
1301 |
+ gst_pad_set_chain_function (sinkpad,
|
|
1302 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
|
17776
|
1303 |
+ gst_pad_set_iterate_internal_links_function (sinkpad,
|
|
1304 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
|
15203
|
1305 |
+ gst_pad_set_bufferalloc_function (sinkpad,
|
|
1306 |
+ GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));
|
|
1307 |
+
|
|
1308 |
+ gst_pad_set_active (sinkpad, TRUE);
|
|
1309 |
+ gst_element_add_pad (GST_ELEMENT (sel), sinkpad);
|
|
1310 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1311 |
+
|
|
1312 |
+ return sinkpad;
|
|
1313 |
+}
|
|
1314 |
+
|
|
1315 |
+static void
|
|
1316 |
+gst_input_selector_release_pad (GstElement * element, GstPad * pad)
|
|
1317 |
+{
|
|
1318 |
+ GstInputSelector *sel;
|
|
1319 |
+
|
|
1320 |
+ sel = GST_INPUT_SELECTOR (element);
|
|
1321 |
+ GST_LOG_OBJECT (sel, "Releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
|
1322 |
+
|
|
1323 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1324 |
+ /* if the pad was the active pad, makes us select a new one */
|
|
1325 |
+ if (sel->active_sinkpad == pad) {
|
|
1326 |
+ GST_DEBUG_OBJECT (sel, "Deactivating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
15812
|
1327 |
+ gst_object_unref (sel->active_sinkpad);
|
15203
|
1328 |
+ sel->active_sinkpad = NULL;
|
|
1329 |
+ }
|
|
1330 |
+ sel->n_pads--;
|
|
1331 |
+
|
|
1332 |
+ gst_pad_set_active (pad, FALSE);
|
|
1333 |
+ gst_element_remove_pad (GST_ELEMENT (sel), pad);
|
|
1334 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1335 |
+}
|
|
1336 |
+
|
|
1337 |
+static void
|
|
1338 |
+gst_input_selector_reset (GstInputSelector * sel)
|
|
1339 |
+{
|
|
1340 |
+ GList *walk;
|
|
1341 |
+
|
|
1342 |
+ GST_INPUT_SELECTOR_LOCK (sel);
|
|
1343 |
+ /* clear active pad */
|
|
1344 |
+ if (sel->active_sinkpad) {
|
|
1345 |
+ gst_object_unref (sel->active_sinkpad);
|
|
1346 |
+ sel->active_sinkpad = NULL;
|
|
1347 |
+ }
|
|
1348 |
+ /* reset segment */
|
|
1349 |
+ gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
|
|
1350 |
+ sel->pending_close = FALSE;
|
|
1351 |
+ /* reset each of our sinkpads state */
|
|
1352 |
+ for (walk = GST_ELEMENT_CAST (sel)->sinkpads; walk; walk = g_list_next (walk)) {
|
|
1353 |
+ GstSelectorPad *selpad = GST_SELECTOR_PAD_CAST (walk->data);
|
|
1354 |
+
|
|
1355 |
+ gst_selector_pad_reset (selpad);
|
|
1356 |
+
|
|
1357 |
+ if (selpad->tags) {
|
|
1358 |
+ gst_tag_list_free (selpad->tags);
|
|
1359 |
+ selpad->tags = NULL;
|
|
1360 |
+ }
|
|
1361 |
+ }
|
|
1362 |
+ GST_INPUT_SELECTOR_UNLOCK (sel);
|
|
1363 |
+}
|
|
1364 |
+
|
|
1365 |
+static GstStateChangeReturn
|
|
1366 |
+gst_input_selector_change_state (GstElement * element,
|
|
1367 |
+ GstStateChange transition)
|
|
1368 |
+{
|
|
1369 |
+ GstInputSelector *self = GST_INPUT_SELECTOR (element);
|
|
1370 |
+ GstStateChangeReturn result;
|
|
1371 |
+
|
|
1372 |
+ switch (transition) {
|
|
1373 |
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
1374 |
+ GST_INPUT_SELECTOR_LOCK (self);
|
|
1375 |
+ self->blocked = FALSE;
|
|
1376 |
+ self->flushing = FALSE;
|
|
1377 |
+ GST_INPUT_SELECTOR_UNLOCK (self);
|
|
1378 |
+ break;
|
|
1379 |
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
1380 |
+ /* first unlock before we call the parent state change function, which
|
|
1381 |
+ * tries to acquire the stream lock when going to ready. */
|
|
1382 |
+ GST_INPUT_SELECTOR_LOCK (self);
|
|
1383 |
+ self->blocked = FALSE;
|
|
1384 |
+ self->flushing = TRUE;
|
|
1385 |
+ GST_INPUT_SELECTOR_BROADCAST (self);
|
|
1386 |
+ GST_INPUT_SELECTOR_UNLOCK (self);
|
|
1387 |
+ break;
|
|
1388 |
+ default:
|
|
1389 |
+ break;
|
|
1390 |
+ }
|
|
1391 |
+
|
|
1392 |
+ result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
1393 |
+
|
|
1394 |
+ switch (transition) {
|
|
1395 |
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
1396 |
+ gst_input_selector_reset (self);
|
|
1397 |
+ break;
|
|
1398 |
+ default:
|
|
1399 |
+ break;
|
|
1400 |
+ }
|
|
1401 |
+
|
|
1402 |
+ return result;
|
|
1403 |
+}
|
|
1404 |
+
|
|
1405 |
+static gint64
|
|
1406 |
+gst_input_selector_block (GstInputSelector * self)
|
|
1407 |
+{
|
|
1408 |
+ gint64 ret = 0;
|
|
1409 |
+ GstSelectorPad *spad;
|
|
1410 |
+
|
|
1411 |
+ GST_INPUT_SELECTOR_LOCK (self);
|
|
1412 |
+
|
|
1413 |
+ if (self->blocked)
|
|
1414 |
+ GST_WARNING_OBJECT (self, "switch already blocked");
|
|
1415 |
+
|
|
1416 |
+ self->blocked = TRUE;
|
|
1417 |
+ spad = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
|
|
1418 |
+
|
|
1419 |
+ if (spad)
|
|
1420 |
+ ret = gst_selector_pad_get_running_time (spad);
|
|
1421 |
+ else
|
|
1422 |
+ GST_DEBUG_OBJECT (self, "no active pad while blocking");
|
|
1423 |
+
|
|
1424 |
+ GST_INPUT_SELECTOR_UNLOCK (self);
|
|
1425 |
+
|
|
1426 |
+ return ret;
|
|
1427 |
+}
|
|
1428 |
+
|
|
1429 |
+/* stop_time and start_time are running times */
|
|
1430 |
+static void
|
|
1431 |
+gst_input_selector_switch (GstInputSelector * self, GstPad * pad,
|
|
1432 |
+ gint64 stop_time, gint64 start_time)
|
|
1433 |
+{
|
|
1434 |
+ gboolean changed;
|
|
1435 |
+
|
|
1436 |
+ g_return_if_fail (self->blocked == TRUE);
|
|
1437 |
+
|
|
1438 |
+ GST_INPUT_SELECTOR_LOCK (self);
|
|
1439 |
+ changed =
|
|
1440 |
+ gst_input_selector_set_active_pad (self, pad, stop_time, start_time);
|
|
1441 |
+
|
|
1442 |
+ self->blocked = FALSE;
|
|
1443 |
+ GST_INPUT_SELECTOR_BROADCAST (self);
|
|
1444 |
+ GST_INPUT_SELECTOR_UNLOCK (self);
|
|
1445 |
+
|
|
1446 |
+ if (changed)
|
|
1447 |
+ g_object_notify (G_OBJECT (self), "active-pad");
|
|
1448 |
+}
|
|
1449 |
+
|
|
1450 |
+static gboolean
|
|
1451 |
+gst_input_selector_check_eos (GstElement * selector)
|
|
1452 |
+{
|
|
1453 |
+ GstIterator *it = gst_element_iterate_sink_pads (selector);
|
|
1454 |
+ GstIteratorResult ires;
|
|
1455 |
+ gpointer item;
|
|
1456 |
+ gboolean done = FALSE, is_eos = FALSE;
|
|
1457 |
+ GstSelectorPad *pad;
|
|
1458 |
+
|
|
1459 |
+ while (!done) {
|
|
1460 |
+ ires = gst_iterator_next (it, &item);
|
|
1461 |
+ switch (ires) {
|
|
1462 |
+ case GST_ITERATOR_DONE:
|
|
1463 |
+ GST_INFO_OBJECT (selector, "all sink pads have eos");
|
|
1464 |
+ done = TRUE;
|
|
1465 |
+ is_eos = TRUE;
|
|
1466 |
+ break;
|
|
1467 |
+ case GST_ITERATOR_OK:
|
|
1468 |
+ pad = GST_SELECTOR_PAD_CAST (item);
|
|
1469 |
+ if (!pad->eos) {
|
|
1470 |
+ done = TRUE;
|
|
1471 |
+ }
|
17776
|
1472 |
+ gst_object_unref (pad);
|
15203
|
1473 |
+ break;
|
|
1474 |
+ case GST_ITERATOR_RESYNC:
|
|
1475 |
+ gst_iterator_resync (it);
|
|
1476 |
+ break;
|
|
1477 |
+ default:
|
|
1478 |
+ done = TRUE;
|
|
1479 |
+ break;
|
|
1480 |
+ }
|
|
1481 |
+ }
|
|
1482 |
+ gst_iterator_free (it);
|
|
1483 |
+
|
|
1484 |
+ return is_eos;
|
|
1485 |
+}
|
|
1486 |
--- /dev/null 2008-12-16 15:34:15.000000000 +0800
|
17776
|
1487 |
+++ gst-plugins-good-0.10.21/gst/selector/gstinputselector.h 2008-12-16 15:09:01.086278737 +0800
|
15203
|
1488 |
@@ -0,0 +1,84 @@
|
|
1489 |
+/* GStreamer
|
|
1490 |
+ * Copyright (C) 2003 Julien Moutte <[email protected]>
|
|
1491 |
+ * Copyright (C) 2005 Ronald S. Bultje <[email protected]>
|
|
1492 |
+ * Copyright (C) 2008 Nokia Corporation. (contact <[email protected]>)
|
|
1493 |
+ *
|
|
1494 |
+ * This library is free software; you can redistribute it and/or
|
|
1495 |
+ * modify it under the terms of the GNU Library General Public
|
|
1496 |
+ * License as published by the Free Software Foundation; either
|
|
1497 |
+ * version 2 of the License, or (at your option) any later version.
|
|
1498 |
+ *
|
|
1499 |
+ * This library is distributed in the hope that it will be useful,
|
|
1500 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1501 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
1502 |
+ * Library General Public License for more details.
|
|
1503 |
+ *
|
|
1504 |
+ * You should have received a copy of the GNU Library General Public
|
|
1505 |
+ * License along with this library; if not, write to the
|
|
1506 |
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
1507 |
+ * Boston, MA 02111-1307, USA.
|
|
1508 |
+ */
|
|
1509 |
+
|
|
1510 |
+#ifndef __GST_INPUT_SELECTOR_H__
|
|
1511 |
+#define __GST_INPUT_SELECTOR_H__
|
|
1512 |
+
|
|
1513 |
+#include <gst/gst.h>
|
|
1514 |
+
|
|
1515 |
+G_BEGIN_DECLS
|
|
1516 |
+
|
|
1517 |
+#define GST_TYPE_INPUT_SELECTOR \
|
|
1518 |
+ (gst_input_selector_get_type())
|
|
1519 |
+#define GST_INPUT_SELECTOR(obj) \
|
|
1520 |
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_INPUT_SELECTOR, GstInputSelector))
|
|
1521 |
+#define GST_INPUT_SELECTOR_CLASS(klass) \
|
|
1522 |
+ (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_INPUT_SELECTOR, GstInputSelectorClass))
|
|
1523 |
+#define GST_IS_INPUT_SELECTOR(obj) \
|
|
1524 |
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_INPUT_SELECTOR))
|
|
1525 |
+#define GST_IS_INPUT_SELECTOR_CLASS(klass) \
|
|
1526 |
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_INPUT_SELECTOR))
|
|
1527 |
+
|
|
1528 |
+typedef struct _GstInputSelector GstInputSelector;
|
|
1529 |
+typedef struct _GstInputSelectorClass GstInputSelectorClass;
|
|
1530 |
+
|
|
1531 |
+#define GST_INPUT_SELECTOR_GET_LOCK(sel) (((GstInputSelector*)(sel))->lock)
|
|
1532 |
+#define GST_INPUT_SELECTOR_GET_COND(sel) (((GstInputSelector*)(sel))->cond)
|
|
1533 |
+#define GST_INPUT_SELECTOR_LOCK(sel) (g_mutex_lock (GST_INPUT_SELECTOR_GET_LOCK(sel)))
|
|
1534 |
+#define GST_INPUT_SELECTOR_UNLOCK(sel) (g_mutex_unlock (GST_INPUT_SELECTOR_GET_LOCK(sel)))
|
|
1535 |
+#define GST_INPUT_SELECTOR_WAIT(sel) (g_cond_wait (GST_INPUT_SELECTOR_GET_COND(sel), \
|
|
1536 |
+ GST_INPUT_SELECTOR_GET_LOCK(sel)))
|
|
1537 |
+#define GST_INPUT_SELECTOR_BROADCAST(sel) (g_cond_broadcast (GST_INPUT_SELECTOR_GET_COND(sel)))
|
|
1538 |
+
|
|
1539 |
+struct _GstInputSelector {
|
|
1540 |
+ GstElement element;
|
|
1541 |
+
|
|
1542 |
+ GstPad *srcpad;
|
|
1543 |
+
|
|
1544 |
+ GstPad *active_sinkpad;
|
|
1545 |
+ guint n_pads;
|
|
1546 |
+ guint padcount;
|
|
1547 |
+
|
|
1548 |
+ GstSegment segment; /* the output segment */
|
|
1549 |
+ gboolean pending_close; /* if we should push a close first */
|
|
1550 |
+
|
|
1551 |
+ GMutex *lock;
|
|
1552 |
+ GCond *cond;
|
|
1553 |
+ gboolean blocked;
|
|
1554 |
+ gboolean flushing;
|
|
1555 |
+
|
|
1556 |
+ /* select all mode, send data from all input pads forward */
|
|
1557 |
+ gboolean select_all;
|
|
1558 |
+};
|
|
1559 |
+
|
|
1560 |
+struct _GstInputSelectorClass {
|
|
1561 |
+ GstElementClass parent_class;
|
|
1562 |
+
|
|
1563 |
+ gint64 (*block) (GstInputSelector *self);
|
|
1564 |
+ void (*switch_) (GstInputSelector *self, GstPad *pad,
|
|
1565 |
+ gint64 stop_time, gint64 start_time);
|
|
1566 |
+};
|
|
1567 |
+
|
|
1568 |
+GType gst_input_selector_get_type (void);
|
|
1569 |
+
|
|
1570 |
+G_END_DECLS
|
|
1571 |
+
|
|
1572 |
+#endif /* __GST_INPUT_SELECTOR_H__ */
|
|
1573 |
--- /dev/null 2008-12-16 15:34:15.000000000 +0800
|
17776
|
1574 |
+++ gst-plugins-good-0.10.21/gst/selector/gstoutputselector.c 2008-12-16 15:09:01.089181384 +0800
|
|
1575 |
@@ -0,0 +1,510 @@
|
15203
|
1576 |
+/* GStreamer
|
|
1577 |
+ * Copyright (C) 2008 Nokia Corporation. (contact <[email protected]>)
|
|
1578 |
+ *
|
|
1579 |
+ * This library is free software; you can redistribute it and/or
|
|
1580 |
+ * modify it under the terms of the GNU Library General Public
|
|
1581 |
+ * License as published by the Free Software Foundation; either
|
|
1582 |
+ * version 2 of the License, or (at your option) any later version.
|
|
1583 |
+ *
|
|
1584 |
+ * This library is distributed in the hope that it will be useful,
|
|
1585 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1586 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
1587 |
+ * Library General Public License for more details.
|
|
1588 |
+ *
|
|
1589 |
+ * You should have received a copy of the GNU Library General Public
|
|
1590 |
+ * License along with this library; if not, write to the
|
|
1591 |
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
1592 |
+ * Boston, MA 02111-1307, USA.
|
|
1593 |
+ */
|
|
1594 |
+
|
|
1595 |
+/**
|
|
1596 |
+ * SECTION:element-output-selector
|
17776
|
1597 |
+ * @see_also: #GstOutputSelector, #GstInputSelector
|
15203
|
1598 |
+ *
|
|
1599 |
+ * Direct input stream to one out of N output pads.
|
|
1600 |
+ */
|
|
1601 |
+
|
|
1602 |
+#ifdef HAVE_CONFIG_H
|
|
1603 |
+#include "config.h"
|
|
1604 |
+#endif
|
|
1605 |
+
|
|
1606 |
+#include <string.h>
|
|
1607 |
+
|
|
1608 |
+#include "gstoutputselector.h"
|
|
1609 |
+
|
|
1610 |
+GST_DEBUG_CATEGORY_STATIC (output_selector_debug);
|
|
1611 |
+#define GST_CAT_DEFAULT output_selector_debug
|
|
1612 |
+
|
|
1613 |
+static const GstElementDetails gst_output_selector_details =
|
|
1614 |
+GST_ELEMENT_DETAILS ("Output selector",
|
|
1615 |
+ "Generic",
|
|
1616 |
+ "1-to-N output stream selectoring",
|
|
1617 |
+ "Stefan Kost <[email protected]>");
|
|
1618 |
+
|
|
1619 |
+static GstStaticPadTemplate gst_output_selector_sink_factory =
|
|
1620 |
+GST_STATIC_PAD_TEMPLATE ("sink",
|
|
1621 |
+ GST_PAD_SINK,
|
|
1622 |
+ GST_PAD_ALWAYS,
|
|
1623 |
+ GST_STATIC_CAPS_ANY);
|
|
1624 |
+
|
|
1625 |
+static GstStaticPadTemplate gst_output_selector_src_factory =
|
|
1626 |
+GST_STATIC_PAD_TEMPLATE ("src%d",
|
|
1627 |
+ GST_PAD_SRC,
|
|
1628 |
+ GST_PAD_REQUEST,
|
|
1629 |
+ GST_STATIC_CAPS_ANY);
|
|
1630 |
+
|
|
1631 |
+enum
|
|
1632 |
+{
|
|
1633 |
+ PROP_0,
|
|
1634 |
+ PROP_ACTIVE_PAD,
|
|
1635 |
+ PROP_RESEND_LATEST,
|
|
1636 |
+ PROP_LAST
|
|
1637 |
+};
|
|
1638 |
+
|
|
1639 |
+GST_BOILERPLATE (GstOutputSelector, gst_output_selector, GstElement,
|
|
1640 |
+ GST_TYPE_ELEMENT);
|
|
1641 |
+
|
|
1642 |
+static void gst_output_selector_dispose (GObject * object);
|
|
1643 |
+static void gst_output_selector_set_property (GObject * object,
|
|
1644 |
+ guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
1645 |
+static void gst_output_selector_get_property (GObject * object,
|
|
1646 |
+ guint prop_id, GValue * value, GParamSpec * pspec);
|
|
1647 |
+static GstPad *gst_output_selector_request_new_pad (GstElement * element,
|
|
1648 |
+ GstPadTemplate * templ, const gchar * unused);
|
|
1649 |
+static void gst_output_selector_release_pad (GstElement * element,
|
|
1650 |
+ GstPad * pad);
|
|
1651 |
+static GstFlowReturn gst_output_selector_chain (GstPad * pad, GstBuffer * buf);
|
17776
|
1652 |
+static GstFlowReturn gst_output_selector_buffer_alloc (GstPad * pad,
|
|
1653 |
+ guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
|
15203
|
1654 |
+static GstStateChangeReturn gst_output_selector_change_state (GstElement *
|
|
1655 |
+ element, GstStateChange transition);
|
|
1656 |
+static gboolean gst_output_selector_handle_sink_event (GstPad * pad,
|
|
1657 |
+ GstEvent * event);
|
|
1658 |
+
|
|
1659 |
+static void
|
|
1660 |
+gst_output_selector_base_init (gpointer g_class)
|
|
1661 |
+{
|
|
1662 |
+ GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
1663 |
+
|
|
1664 |
+ gst_element_class_set_details (element_class, &gst_output_selector_details);
|
|
1665 |
+ gst_element_class_add_pad_template (element_class,
|
|
1666 |
+ gst_static_pad_template_get (&gst_output_selector_sink_factory));
|
|
1667 |
+ gst_element_class_add_pad_template (element_class,
|
|
1668 |
+ gst_static_pad_template_get (&gst_output_selector_src_factory));
|
|
1669 |
+}
|
|
1670 |
+
|
|
1671 |
+static void
|
|
1672 |
+gst_output_selector_class_init (GstOutputSelectorClass * klass)
|
|
1673 |
+{
|
|
1674 |
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
1675 |
+ GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
1676 |
+
|
|
1677 |
+ parent_class = g_type_class_peek_parent (klass);
|
|
1678 |
+
|
|
1679 |
+ gobject_class->dispose = gst_output_selector_dispose;
|
|
1680 |
+
|
|
1681 |
+ gobject_class->set_property =
|
|
1682 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_set_property);
|
|
1683 |
+ gobject_class->get_property =
|
|
1684 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_get_property);
|
|
1685 |
+
|
|
1686 |
+ g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
|
|
1687 |
+ g_param_spec_object ("active-pad", "Active pad",
|
|
1688 |
+ "Currently active src pad", GST_TYPE_PAD, G_PARAM_READWRITE));
|
|
1689 |
+ g_object_class_install_property (gobject_class, PROP_RESEND_LATEST,
|
|
1690 |
+ g_param_spec_boolean ("resend-latest", "Resend latest buffer",
|
|
1691 |
+ "Resend latest buffer after a switch to a new pad", FALSE,
|
|
1692 |
+ G_PARAM_READWRITE));
|
|
1693 |
+
|
|
1694 |
+ gstelement_class->request_new_pad =
|
|
1695 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_request_new_pad);
|
|
1696 |
+ gstelement_class->release_pad =
|
|
1697 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_release_pad);
|
|
1698 |
+
|
|
1699 |
+ gstelement_class->change_state = gst_output_selector_change_state;
|
|
1700 |
+
|
|
1701 |
+ GST_DEBUG_CATEGORY_INIT (output_selector_debug,
|
|
1702 |
+ "output-selector", 0, "An output stream selector element");
|
|
1703 |
+}
|
|
1704 |
+
|
|
1705 |
+static void
|
|
1706 |
+gst_output_selector_init (GstOutputSelector * sel,
|
|
1707 |
+ GstOutputSelectorClass * g_class)
|
|
1708 |
+{
|
|
1709 |
+ sel->sinkpad =
|
|
1710 |
+ gst_pad_new_from_static_template (&gst_output_selector_sink_factory,
|
|
1711 |
+ "sink");
|
|
1712 |
+ gst_pad_set_chain_function (sel->sinkpad,
|
|
1713 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_chain));
|
|
1714 |
+ gst_pad_set_event_function (sel->sinkpad,
|
|
1715 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_handle_sink_event));
|
17776
|
1716 |
+ gst_pad_set_bufferalloc_function (sel->sinkpad,
|
|
1717 |
+ GST_DEBUG_FUNCPTR (gst_output_selector_buffer_alloc));
|
15203
|
1718 |
+ /*
|
|
1719 |
+ gst_pad_set_setcaps_function (sel->sinkpad,
|
|
1720 |
+ GST_DEBUG_FUNCPTR (gst_pad_proxy_setcaps));
|
|
1721 |
+ gst_pad_set_getcaps_function (sel->sinkpad,
|
|
1722 |
+ GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
|
|
1723 |
+ */
|
17776
|
1724 |
+
|
|
1725 |
+ gst_element_add_pad (GST_ELEMENT (sel), sel->sinkpad);
|
|
1726 |
+
|
15203
|
1727 |
+ /* srcpad management */
|
|
1728 |
+ sel->active_srcpad = NULL;
|
|
1729 |
+ sel->nb_srcpads = 0;
|
17776
|
1730 |
+ gst_segment_init (&sel->segment, GST_FORMAT_TIME);
|
15203
|
1731 |
+ sel->pending_srcpad = NULL;
|
|
1732 |
+
|
|
1733 |
+ sel->resend_latest = FALSE;
|
|
1734 |
+ sel->latest_buffer = NULL;
|
|
1735 |
+}
|
|
1736 |
+
|
|
1737 |
+static void
|
15812
|
1738 |
+gst_output_selector_reset (GstOutputSelector * osel)
|
15203
|
1739 |
+{
|
|
1740 |
+ if (osel->pending_srcpad != NULL) {
|
|
1741 |
+ gst_object_unref (osel->pending_srcpad);
|
|
1742 |
+ osel->pending_srcpad = NULL;
|
|
1743 |
+ }
|
|
1744 |
+ if (osel->latest_buffer != NULL) {
|
|
1745 |
+ gst_buffer_unref (osel->latest_buffer);
|
|
1746 |
+ osel->latest_buffer = NULL;
|
|
1747 |
+ }
|
15812
|
1748 |
+ gst_segment_init (&osel->segment, GST_FORMAT_UNDEFINED);
|
|
1749 |
+}
|
|
1750 |
+
|
|
1751 |
+static void
|
|
1752 |
+gst_output_selector_dispose (GObject * object)
|
|
1753 |
+{
|
|
1754 |
+ GstOutputSelector *osel = GST_OUTPUT_SELECTOR (object);
|
|
1755 |
+
|
|
1756 |
+ gst_output_selector_reset (osel);
|
15203
|
1757 |
+
|
|
1758 |
+ G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
1759 |
+}
|
|
1760 |
+
|
|
1761 |
+static void
|
|
1762 |
+gst_output_selector_set_property (GObject * object, guint prop_id,
|
|
1763 |
+ const GValue * value, GParamSpec * pspec)
|
|
1764 |
+{
|
|
1765 |
+ GstOutputSelector *sel = GST_OUTPUT_SELECTOR (object);
|
|
1766 |
+
|
|
1767 |
+ switch (prop_id) {
|
|
1768 |
+ case PROP_ACTIVE_PAD:
|
|
1769 |
+ {
|
|
1770 |
+ GstPad *next_pad;
|
|
1771 |
+
|
|
1772 |
+ next_pad = g_value_get_object (value);
|
|
1773 |
+
|
17776
|
1774 |
+ GST_INFO_OBJECT (sel, "Activating pad %s:%s",
|
15203
|
1775 |
+ GST_DEBUG_PAD_NAME (next_pad));
|
|
1776 |
+
|
|
1777 |
+ GST_OBJECT_LOCK (object);
|
|
1778 |
+ if (next_pad != sel->active_srcpad) {
|
|
1779 |
+ /* switch to new srcpad in next chain run */
|
|
1780 |
+ if (sel->pending_srcpad != NULL) {
|
|
1781 |
+ GST_INFO ("replacing pending switch");
|
|
1782 |
+ gst_object_unref (sel->pending_srcpad);
|
|
1783 |
+ }
|
|
1784 |
+ if (next_pad)
|
|
1785 |
+ gst_object_ref (next_pad);
|
|
1786 |
+ sel->pending_srcpad = next_pad;
|
|
1787 |
+ } else {
|
|
1788 |
+ GST_INFO ("pad already active");
|
|
1789 |
+ if (sel->pending_srcpad != NULL) {
|
|
1790 |
+ gst_object_unref (sel->pending_srcpad);
|
|
1791 |
+ sel->pending_srcpad = NULL;
|
|
1792 |
+ }
|
|
1793 |
+ }
|
|
1794 |
+ GST_OBJECT_UNLOCK (object);
|
|
1795 |
+ break;
|
|
1796 |
+ }
|
|
1797 |
+ case PROP_RESEND_LATEST:{
|
|
1798 |
+ sel->resend_latest = g_value_get_boolean (value);
|
|
1799 |
+ break;
|
|
1800 |
+ }
|
|
1801 |
+ default:
|
|
1802 |
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
1803 |
+ break;
|
|
1804 |
+ }
|
|
1805 |
+}
|
|
1806 |
+
|
|
1807 |
+static void
|
|
1808 |
+gst_output_selector_get_property (GObject * object, guint prop_id,
|
|
1809 |
+ GValue * value, GParamSpec * pspec)
|
|
1810 |
+{
|
|
1811 |
+ GstOutputSelector *sel = GST_OUTPUT_SELECTOR (object);
|
|
1812 |
+
|
|
1813 |
+ switch (prop_id) {
|
|
1814 |
+ case PROP_ACTIVE_PAD:
|
|
1815 |
+ GST_OBJECT_LOCK (object);
|
17776
|
1816 |
+ g_value_set_object (value,
|
|
1817 |
+ sel->pending_srcpad ? sel->pending_srcpad : sel->active_srcpad);
|
15203
|
1818 |
+ GST_OBJECT_UNLOCK (object);
|
|
1819 |
+ break;
|
|
1820 |
+ case PROP_RESEND_LATEST:{
|
|
1821 |
+ GST_OBJECT_LOCK (object);
|
|
1822 |
+ g_value_set_boolean (value, sel->resend_latest);
|
|
1823 |
+ GST_OBJECT_UNLOCK (object);
|
|
1824 |
+ break;
|
|
1825 |
+ }
|
|
1826 |
+ default:
|
|
1827 |
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
1828 |
+ break;
|
|
1829 |
+ }
|
|
1830 |
+}
|
|
1831 |
+
|
17776
|
1832 |
+static GstFlowReturn
|
|
1833 |
+gst_output_selector_buffer_alloc (GstPad * pad, guint64 offset, guint size,
|
|
1834 |
+ GstCaps * caps, GstBuffer ** buf)
|
|
1835 |
+{
|
|
1836 |
+ GstOutputSelector *sel;
|
|
1837 |
+ GstFlowReturn res;
|
|
1838 |
+ GstPad *allocpad;
|
|
1839 |
+
|
|
1840 |
+ sel = GST_OUTPUT_SELECTOR (GST_PAD_PARENT (pad));
|
|
1841 |
+ res = GST_FLOW_NOT_LINKED;
|
|
1842 |
+
|
|
1843 |
+ GST_OBJECT_LOCK (sel);
|
|
1844 |
+ allocpad = sel->pending_srcpad ? sel->pending_srcpad : sel->active_srcpad;
|
|
1845 |
+ if (allocpad) {
|
|
1846 |
+ /* if we had a previous pad we used for allocating a buffer, continue using
|
|
1847 |
+ * it. */
|
|
1848 |
+ GST_DEBUG_OBJECT (sel, "using pad %s:%s for alloc",
|
|
1849 |
+ GST_DEBUG_PAD_NAME (allocpad));
|
|
1850 |
+ gst_object_ref (allocpad);
|
|
1851 |
+ GST_OBJECT_UNLOCK (sel);
|
|
1852 |
+
|
|
1853 |
+ res = gst_pad_alloc_buffer (allocpad, offset, size, caps, buf);
|
|
1854 |
+ gst_object_unref (allocpad);
|
|
1855 |
+
|
|
1856 |
+ GST_OBJECT_LOCK (sel);
|
|
1857 |
+ } else {
|
|
1858 |
+ /* fallback case, allocate a buffer of our own, add pad caps. */
|
|
1859 |
+ GST_DEBUG_OBJECT (pad, "fallback buffer alloc");
|
|
1860 |
+ *buf = NULL;
|
|
1861 |
+ res = GST_FLOW_OK;
|
|
1862 |
+ }
|
|
1863 |
+ GST_OBJECT_UNLOCK (sel);
|
|
1864 |
+
|
|
1865 |
+ GST_DEBUG_OBJECT (sel, "buffer alloc finished: %s", gst_flow_get_name (res));
|
|
1866 |
+
|
|
1867 |
+ return res;
|
|
1868 |
+}
|
|
1869 |
+
|
15203
|
1870 |
+static GstPad *
|
|
1871 |
+gst_output_selector_request_new_pad (GstElement * element,
|
|
1872 |
+ GstPadTemplate * templ, const gchar * name)
|
|
1873 |
+{
|
|
1874 |
+ gchar *padname;
|
|
1875 |
+ GstPad *srcpad;
|
|
1876 |
+ GstOutputSelector *osel;
|
|
1877 |
+
|
|
1878 |
+ osel = GST_OUTPUT_SELECTOR (element);
|
|
1879 |
+
|
|
1880 |
+ GST_DEBUG_OBJECT (osel, "requesting pad");
|
|
1881 |
+
|
|
1882 |
+ GST_OBJECT_LOCK (osel);
|
|
1883 |
+ padname = g_strdup_printf ("src%d", osel->nb_srcpads++);
|
|
1884 |
+ srcpad = gst_pad_new_from_template (templ, padname);
|
|
1885 |
+ GST_OBJECT_UNLOCK (osel);
|
|
1886 |
+
|
|
1887 |
+ gst_pad_set_active (srcpad, TRUE);
|
|
1888 |
+ gst_element_add_pad (GST_ELEMENT (osel), srcpad);
|
|
1889 |
+
|
|
1890 |
+ /* Set the first requested src pad as active by default */
|
|
1891 |
+ if (osel->active_srcpad == NULL) {
|
|
1892 |
+ osel->active_srcpad = srcpad;
|
|
1893 |
+ }
|
|
1894 |
+ g_free (padname);
|
|
1895 |
+
|
|
1896 |
+ return srcpad;
|
|
1897 |
+}
|
|
1898 |
+
|
|
1899 |
+static void
|
|
1900 |
+gst_output_selector_release_pad (GstElement * element, GstPad * pad)
|
|
1901 |
+{
|
|
1902 |
+ GstOutputSelector *osel;
|
|
1903 |
+
|
|
1904 |
+ osel = GST_OUTPUT_SELECTOR (element);
|
|
1905 |
+
|
|
1906 |
+ GST_DEBUG_OBJECT (osel, "releasing pad");
|
|
1907 |
+
|
|
1908 |
+ gst_pad_set_active (pad, FALSE);
|
|
1909 |
+
|
|
1910 |
+ gst_element_remove_pad (GST_ELEMENT_CAST (osel), pad);
|
|
1911 |
+}
|
|
1912 |
+
|
|
1913 |
+static gboolean
|
|
1914 |
+gst_output_selector_switch (GstOutputSelector * osel)
|
|
1915 |
+{
|
17776
|
1916 |
+ gboolean res = FALSE;
|
15203
|
1917 |
+ GstEvent *ev = NULL;
|
|
1918 |
+ GstSegment *seg = NULL;
|
|
1919 |
+ gint64 start = 0, position = 0;
|
|
1920 |
+
|
17776
|
1921 |
+ /* Switch */
|
|
1922 |
+ GST_OBJECT_LOCK (GST_OBJECT (osel));
|
15203
|
1923 |
+ GST_INFO ("switching to pad %" GST_PTR_FORMAT, osel->pending_srcpad);
|
17776
|
1924 |
+ if (gst_pad_is_linked (osel->pending_srcpad)) {
|
|
1925 |
+ osel->active_srcpad = osel->pending_srcpad;
|
|
1926 |
+ res = TRUE;
|
|
1927 |
+ }
|
|
1928 |
+ gst_object_unref (osel->pending_srcpad);
|
|
1929 |
+ osel->pending_srcpad = NULL;
|
|
1930 |
+ GST_OBJECT_UNLOCK (GST_OBJECT (osel));
|
15203
|
1931 |
+
|
17776
|
1932 |
+ /* Send NEWSEGMENT event and latest buffer if switching succeeded */
|
|
1933 |
+ if (res) {
|
15203
|
1934 |
+ /* Send NEWSEGMENT to the pad we are going to switch to */
|
|
1935 |
+ seg = &osel->segment;
|
|
1936 |
+ /* If resending then mark newsegment start and position accordingly */
|
|
1937 |
+ if (osel->resend_latest && osel->latest_buffer &&
|
|
1938 |
+ GST_BUFFER_TIMESTAMP_IS_VALID (osel->latest_buffer)) {
|
|
1939 |
+ start = position = GST_BUFFER_TIMESTAMP (osel->latest_buffer);
|
|
1940 |
+ } else {
|
|
1941 |
+ start = position = seg->last_stop;
|
|
1942 |
+ }
|
|
1943 |
+ ev = gst_event_new_new_segment (TRUE, seg->rate,
|
|
1944 |
+ seg->format, start, seg->stop, position);
|
17776
|
1945 |
+ if (!gst_pad_push_event (osel->active_srcpad, ev)) {
|
15203
|
1946 |
+ GST_WARNING_OBJECT (osel,
|
|
1947 |
+ "newsegment handling failed in %" GST_PTR_FORMAT,
|
17776
|
1948 |
+ osel->active_srcpad);
|
15203
|
1949 |
+ }
|
|
1950 |
+
|
|
1951 |
+ /* Resend latest buffer to newly switched pad */
|
|
1952 |
+ if (osel->resend_latest && osel->latest_buffer) {
|
|
1953 |
+ GST_INFO ("resending latest buffer");
|
17776
|
1954 |
+ gst_pad_push (osel->active_srcpad, osel->latest_buffer);
|
15203
|
1955 |
+ osel->latest_buffer = NULL;
|
|
1956 |
+ }
|
|
1957 |
+ } else {
|
|
1958 |
+ GST_WARNING_OBJECT (osel, "switch failed, pad not linked");
|
|
1959 |
+ }
|
|
1960 |
+
|
|
1961 |
+ return res;
|
|
1962 |
+}
|
|
1963 |
+
|
|
1964 |
+static GstFlowReturn
|
|
1965 |
+gst_output_selector_chain (GstPad * pad, GstBuffer * buf)
|
|
1966 |
+{
|
|
1967 |
+ GstFlowReturn res;
|
|
1968 |
+ GstOutputSelector *osel;
|
|
1969 |
+ GstClockTime last_stop, duration;
|
|
1970 |
+
|
|
1971 |
+ osel = GST_OUTPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
1972 |
+
|
|
1973 |
+ if (osel->pending_srcpad) {
|
|
1974 |
+ /* Do the switch */
|
|
1975 |
+ gst_output_selector_switch (osel);
|
|
1976 |
+ }
|
|
1977 |
+
|
17776
|
1978 |
+ if (osel->latest_buffer) {
|
15203
|
1979 |
+ gst_buffer_unref (osel->latest_buffer);
|
17776
|
1980 |
+ osel->latest_buffer = NULL;
|
|
1981 |
+ }
|
|
1982 |
+
|
|
1983 |
+ if (osel->resend_latest) {
|
|
1984 |
+ /* Keep reference to latest buffer to resend it after switch */
|
|
1985 |
+ osel->latest_buffer = gst_buffer_ref (buf);
|
|
1986 |
+ }
|
15203
|
1987 |
+
|
|
1988 |
+ /* Keep track of last stop and use it in NEWSEGMENT start after
|
|
1989 |
+ switching to a new src pad */
|
|
1990 |
+ last_stop = GST_BUFFER_TIMESTAMP (buf);
|
|
1991 |
+ if (GST_CLOCK_TIME_IS_VALID (last_stop)) {
|
|
1992 |
+ duration = GST_BUFFER_DURATION (buf);
|
|
1993 |
+ if (GST_CLOCK_TIME_IS_VALID (duration)) {
|
|
1994 |
+ last_stop += duration;
|
|
1995 |
+ }
|
|
1996 |
+ GST_LOG_OBJECT (osel, "setting last stop %" GST_TIME_FORMAT,
|
|
1997 |
+ GST_TIME_ARGS (last_stop));
|
|
1998 |
+ gst_segment_set_last_stop (&osel->segment, osel->segment.format, last_stop);
|
|
1999 |
+ }
|
|
2000 |
+
|
|
2001 |
+ GST_LOG_OBJECT (osel, "pushing buffer to %" GST_PTR_FORMAT,
|
|
2002 |
+ osel->active_srcpad);
|
|
2003 |
+ res = gst_pad_push (osel->active_srcpad, buf);
|
|
2004 |
+ gst_object_unref (osel);
|
|
2005 |
+
|
|
2006 |
+ return res;
|
|
2007 |
+}
|
|
2008 |
+
|
|
2009 |
+static GstStateChangeReturn
|
|
2010 |
+gst_output_selector_change_state (GstElement * element,
|
|
2011 |
+ GstStateChange transition)
|
|
2012 |
+{
|
15812
|
2013 |
+ GstOutputSelector *sel;
|
|
2014 |
+ GstStateChangeReturn result;
|
|
2015 |
+
|
|
2016 |
+ sel = GST_OUTPUT_SELECTOR (element);
|
|
2017 |
+
|
|
2018 |
+ switch (transition) {
|
|
2019 |
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
2020 |
+ break;
|
|
2021 |
+ default:
|
|
2022 |
+ break;
|
|
2023 |
+ }
|
|
2024 |
+
|
|
2025 |
+ result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
2026 |
+
|
|
2027 |
+ switch (transition) {
|
|
2028 |
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
2029 |
+ gst_output_selector_reset (sel);
|
|
2030 |
+ break;
|
|
2031 |
+ default:
|
|
2032 |
+ break;
|
|
2033 |
+ }
|
|
2034 |
+
|
|
2035 |
+ return result;
|
15203
|
2036 |
+}
|
|
2037 |
+
|
|
2038 |
+static gboolean
|
|
2039 |
+gst_output_selector_handle_sink_event (GstPad * pad, GstEvent * event)
|
|
2040 |
+{
|
|
2041 |
+ gboolean res = TRUE;
|
|
2042 |
+ GstOutputSelector *sel;
|
|
2043 |
+ GstPad *output_pad = NULL;
|
|
2044 |
+
|
|
2045 |
+ sel = GST_OUTPUT_SELECTOR (gst_pad_get_parent (pad));
|
|
2046 |
+
|
|
2047 |
+ switch (GST_EVENT_TYPE (event)) {
|
|
2048 |
+ case GST_EVENT_NEWSEGMENT:
|
|
2049 |
+ {
|
|
2050 |
+ gboolean update;
|
|
2051 |
+ GstFormat format;
|
|
2052 |
+ gdouble rate, arate;
|
|
2053 |
+ gint64 start, stop, time;
|
|
2054 |
+
|
|
2055 |
+ gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
|
|
2056 |
+ &start, &stop, &time);
|
|
2057 |
+
|
|
2058 |
+ GST_DEBUG_OBJECT (sel,
|
|
2059 |
+ "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
|
|
2060 |
+ "format %d, " "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
|
|
2061 |
+ G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
|
|
2062 |
+
|
|
2063 |
+ gst_segment_set_newsegment_full (&sel->segment, update,
|
|
2064 |
+ rate, arate, format, start, stop, time);
|
|
2065 |
+
|
|
2066 |
+ /* Send newsegment to all src pads */
|
|
2067 |
+ gst_pad_event_default (pad, event);
|
|
2068 |
+ break;
|
|
2069 |
+ }
|
|
2070 |
+ case GST_EVENT_EOS:
|
|
2071 |
+ /* Send eos to all src pads */
|
|
2072 |
+ gst_pad_event_default (pad, event);
|
|
2073 |
+ break;
|
|
2074 |
+ default:
|
|
2075 |
+ /* Send other events to pending or active src pad */
|
|
2076 |
+ output_pad =
|
|
2077 |
+ sel->pending_srcpad ? sel->pending_srcpad : sel->active_srcpad;
|
|
2078 |
+ res = gst_pad_push_event (output_pad, event);
|
|
2079 |
+ break;
|
|
2080 |
+ }
|
|
2081 |
+
|
|
2082 |
+ gst_object_unref (sel);
|
|
2083 |
+
|
|
2084 |
+ return res;
|
|
2085 |
+}
|
|
2086 |
--- /dev/null 2008-12-16 15:34:15.000000000 +0800
|
17776
|
2087 |
+++ gst-plugins-good-0.10.21/gst/selector/gstoutputselector.h 2008-12-16 15:09:01.073579304 +0800
|
15203
|
2088 |
@@ -0,0 +1,66 @@
|
|
2089 |
+/* GStreamer
|
|
2090 |
+ * Copyright (C) 2008 Nokia Corporation. (contact <[email protected]>)
|
|
2091 |
+ *
|
|
2092 |
+ * This library is free software; you can redistribute it and/or
|
|
2093 |
+ * modify it under the terms of the GNU Library General Public
|
|
2094 |
+ * License as published by the Free Software Foundation; either
|
|
2095 |
+ * version 2 of the License, or (at your option) any later version.
|
|
2096 |
+ *
|
|
2097 |
+ * This library is distributed in the hope that it will be useful,
|
|
2098 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2099 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
2100 |
+ * Library General Public License for more details.
|
|
2101 |
+ *
|
|
2102 |
+ * You should have received a copy of the GNU Library General Public
|
|
2103 |
+ * License along with this library; if not, write to the
|
|
2104 |
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
2105 |
+ * Boston, MA 02111-1307, USA.
|
|
2106 |
+ */
|
|
2107 |
+
|
|
2108 |
+#ifndef __GST_OUTPUT_SELECTOR_H__
|
|
2109 |
+#define __GST_OUTPUT_SELECTOR_H__
|
|
2110 |
+
|
|
2111 |
+#include <gst/gst.h>
|
|
2112 |
+
|
|
2113 |
+G_BEGIN_DECLS
|
|
2114 |
+
|
|
2115 |
+#define GST_TYPE_OUTPUT_SELECTOR \
|
|
2116 |
+ (gst_output_selector_get_type())
|
|
2117 |
+#define GST_OUTPUT_SELECTOR(obj) \
|
|
2118 |
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OUTPUT_SELECTOR, GstOutputSelector))
|
|
2119 |
+#define GST_OUTPUT_SELECTOR_CLASS(klass) \
|
|
2120 |
+ (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OUTPUT_SELECTOR, GstOutputSelectorClass))
|
|
2121 |
+#define GST_IS_OUTPUT_SELECTOR(obj) \
|
|
2122 |
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OUTPUT_SELECTOR))
|
|
2123 |
+#define GST_IS_OUTPUT_SELECTOR_CLASS(klass) \
|
|
2124 |
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OUTPUT_SELECTOR))
|
|
2125 |
+
|
|
2126 |
+typedef struct _GstOutputSelector GstOutputSelector;
|
|
2127 |
+typedef struct _GstOutputSelectorClass GstOutputSelectorClass;
|
|
2128 |
+
|
|
2129 |
+struct _GstOutputSelector {
|
|
2130 |
+ GstElement element;
|
|
2131 |
+
|
|
2132 |
+ GstPad *sinkpad;
|
|
2133 |
+
|
|
2134 |
+ GstPad *active_srcpad;
|
|
2135 |
+ GstPad *pending_srcpad;
|
|
2136 |
+ guint nb_srcpads;
|
|
2137 |
+
|
|
2138 |
+ GstSegment segment;
|
|
2139 |
+
|
|
2140 |
+ /* resend latest buffer after switch */
|
|
2141 |
+ gboolean resend_latest;
|
|
2142 |
+ GstBuffer *latest_buffer;
|
|
2143 |
+
|
|
2144 |
+};
|
|
2145 |
+
|
|
2146 |
+struct _GstOutputSelectorClass {
|
|
2147 |
+ GstElementClass parent_class;
|
|
2148 |
+};
|
|
2149 |
+
|
|
2150 |
+GType gst_output_selector_get_type (void);
|
|
2151 |
+
|
|
2152 |
+G_END_DECLS
|
|
2153 |
+
|
|
2154 |
+#endif /* __GST_OUTPUT_SELECTOR_H__ */
|
|
2155 |
--- /dev/null 2008-12-16 15:34:15.000000000 +0800
|
17776
|
2156 |
+++ gst-plugins-good-0.10.21/gst/selector/gstselector.c 2008-12-16 15:09:01.090104873 +0800
|
15203
|
2157 |
@@ -0,0 +1,44 @@
|
|
2158 |
+/* GStreamer
|
|
2159 |
+ * Copyright (C) 2008 Nokia Corporation. (contact <[email protected]>)
|
|
2160 |
+ *
|
|
2161 |
+ * This library is free software; you can redistribute it and/or
|
|
2162 |
+ * modify it under the terms of the GNU Library General Public
|
|
2163 |
+ * License as published by the Free Software Foundation; either
|
|
2164 |
+ * version 2 of the License, or (at your option) any later version.
|
|
2165 |
+ *
|
|
2166 |
+ * This library is distributed in the hope that it will be useful,
|
|
2167 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2168 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
2169 |
+ * Library General Public License for more details.
|
|
2170 |
+ *
|
|
2171 |
+ * You should have received a copy of the GNU Library General Public
|
|
2172 |
+ * License along with this library; if not, write to the
|
|
2173 |
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
2174 |
+ * Boston, MA 02111-1307, USA.
|
|
2175 |
+ */
|
|
2176 |
+
|
|
2177 |
+#ifdef HAVE_CONFIG_H
|
|
2178 |
+#include "config.h"
|
|
2179 |
+#endif
|
|
2180 |
+
|
|
2181 |
+#include <gst/gst.h>
|
|
2182 |
+
|
|
2183 |
+#include "gstinputselector.h"
|
|
2184 |
+#include "gstoutputselector.h"
|
|
2185 |
+
|
|
2186 |
+
|
|
2187 |
+static gboolean
|
|
2188 |
+plugin_init (GstPlugin * plugin)
|
|
2189 |
+{
|
|
2190 |
+
|
|
2191 |
+ return gst_element_register (plugin, "input-selector",
|
|
2192 |
+ GST_RANK_NONE, GST_TYPE_INPUT_SELECTOR) &&
|
|
2193 |
+ gst_element_register (plugin, "output-selector",
|
|
2194 |
+ GST_RANK_NONE, GST_TYPE_OUTPUT_SELECTOR);
|
|
2195 |
+}
|
|
2196 |
+
|
|
2197 |
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
2198 |
+ GST_VERSION_MINOR,
|
|
2199 |
+ "selector",
|
|
2200 |
+ "input/output stream selector elements",
|
|
2201 |
+ plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
|
2202 |
--- /dev/null 2008-12-20 18:00:51.000000000 +0800
|
17776
|
2203 |
+++ gst-plugins-good-0.10.21/gst/selector/gstselector-marshal.list 2008-12-16 15:09:01.089768915 +0800
|
15203
|
2204 |
@@ -0,0 +1,2 @@
|
|
2205 |
+INT64:VOID
|
|
2206 |
+VOID:OBJECT,INT64,INT64
|
17680
|
2207 |
diff -ruN gst-plugins-good-0.10.21.rig/configure.ac gst-plugins-good-0.10.21/configure.ac
|
|
2208 |
--- gst-plugins-good-0.10.21.rig/configure.ac 2010-03-11 23:23:18.783135772 +0000
|
|
2209 |
+++ gst-plugins-good-0.10.21/configure.ac 2010-03-11 23:24:00.041240170 +0000
|
|
2210 |
@@ -316,6 +316,7 @@
|
|
2211 |
AG_GST_CHECK_PLUGIN(rtp)
|
|
2212 |
AG_GST_CHECK_PLUGIN(rtpmanager)
|
|
2213 |
AG_GST_CHECK_PLUGIN(rtsp)
|
|
2214 |
+AG_GST_CHECK_PLUGIN(selector)
|
|
2215 |
AG_GST_CHECK_PLUGIN(shapewipe)
|
|
2216 |
AG_GST_CHECK_PLUGIN(smpte)
|
|
2217 |
AG_GST_CHECK_PLUGIN(spectrum)
|
|
2218 |
@@ -1104,6 +1105,7 @@
|
|
2219 |
gst/rtp/Makefile
|
|
2220 |
gst/rtpmanager/Makefile
|
|
2221 |
gst/rtsp/Makefile
|
|
2222 |
+gst/selector/Makefile
|
|
2223 |
gst/shapewipe/Makefile
|
|
2224 |
gst/smpte/Makefile
|
|
2225 |
gst/spectrum/Makefile
|