2 * Copyright (C) 2001 RidgeRun, Inc. (www.ridgerun.com)
4 * gstautoplugger.c: Data for the dynamic autopluggerger
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.
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.
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 GstElementDetails gst_autoplugger_details = {
25 "Dynamic autoplugger",
27 "Magic element that converts from any type to any other",
29 "Erik Walthinsen <omega@temple-baptist.com>",
30 "(C) 2001 RidgeRun, Inc. (www.ridgerun.com)",
33 #define GST_TYPE_AUTOPLUGGER \
34 (gst_autoplugger_get_type())
35 #define GST_AUTOPLUGGER(obj) \
36 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUTOPLUGGER,GstAutoplugger))
37 #define GST_AUTOPLUGGER_CLASS(klass) \
38 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUTOPLUGGER,GstAutopluggerClass))
39 #define GST_IS_AUTOPLUGGER(obj) \
40 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUTOPLUGGER))
41 #define GST_IS_AUTOPLUGGER_CLASS(obj) \
42 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUTOPLUGGER))
44 typedef struct _GstAutoplugger GstAutoplugger;
45 typedef struct _GstAutopluggerClass GstAutopluggerClass;
47 struct _GstAutoplugger {
52 gboolean cache_first_buffer;
53 GstPad *cache_sinkpad, *cache_srcpad;
56 GstPad *typefind_sinkpad;
58 GstPad *sinkpadpeer, *srcpadpeer;
59 GstCaps *sinkcaps, *srccaps;
61 GstCaps *sinktemplatecaps;
63 GstAutoplug *autoplug;
66 gboolean disable_nocaps;
69 struct _GstAutopluggerClass {
70 GstBinClass parent_class;
74 /* signals and args */
84 static void gst_autoplugger_class_init (GstAutopluggerClass *klass);
85 static void gst_autoplugger_init (GstAutoplugger *queue);
87 static void gst_autoplugger_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
88 static void gst_autoplugger_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
90 //static GstElementStateReturn gst_autoplugger_change_state (GstElement *element);
93 static void gst_autoplugger_external_sink_caps_changed (GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger);
94 static void gst_autoplugger_external_src_caps_changed (GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger);
95 static void gst_autoplugger_external_sink_caps_nego_failed (GstPad *pad, gboolean *result, GstAutoplugger *autoplugger);
96 static void gst_autoplugger_external_src_caps_nego_failed (GstPad *pad, gboolean *result, GstAutoplugger *autoplugger);
97 static void gst_autoplugger_external_sink_connected (GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger);
98 static void gst_autoplugger_external_src_connected (GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger);
100 static void gst_autoplugger_cache_first_buffer (GstElement *element,GstBuffer *buf,GstAutoplugger *autoplugger);
101 static void gst_autoplugger_cache_empty (GstElement *element, GstAutoplugger *autoplugger);
102 static void gst_autoplugger_typefind_have_type (GstElement *element, GstCaps *caps, GstAutoplugger *autoplugger);
104 static GstElementClass *parent_class = NULL;
105 //static guint gst_autoplugger_signals[LAST_SIGNAL] = { 0 };
108 gst_autoplugger_get_type(void) {
109 static GType autoplugger_type = 0;
111 if (!autoplugger_type) {
112 static const GTypeInfo autoplugger_info = {
113 sizeof(GstAutopluggerClass),
116 (GClassInitFunc)gst_autoplugger_class_init,
119 sizeof(GstAutoplugger),
121 (GInstanceInitFunc)gst_autoplugger_init,
123 autoplugger_type = g_type_register_static (GST_TYPE_BIN, "GstAutoplugger", &autoplugger_info, 0);
125 return autoplugger_type;
129 gst_autoplugger_class_init (GstAutopluggerClass *klass)
131 GObjectClass *gobject_class;
132 GstElementClass *gstelement_class;
134 gobject_class = (GObjectClass*)klass;
135 gstelement_class = (GstElementClass*)klass;
137 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
140 gst_autoplugger_signals[_EMPTY] =
141 g_signal_new ("_empty", G_OBJECT_TYPE(gobject_class), G_SIGNAL_RUN_LAST,
142 G_STRUCT_OFFSET (GstAutopluggerClass, _empty), NULL, NULL,
143 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
147 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFFER_COUNT,
148 g_param_spec_int("buffer_count","buffer_count","buffer_count",
149 0,G_MAXINT,0,G_PARAM_READABLE)); // CHECKME!
150 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_RESET,
151 g_param_spec_boolean("reset","reset","reset",
152 FALSE,G_PARAM_WRITABLE)); // CHECKME!
155 gobject_class->set_property = gst_autoplugger_set_property;
156 gobject_class->get_property = gst_autoplugger_get_property;
158 // gstelement_class->change_state = gst_autoplugger_change_state;
162 gst_autoplugger_init (GstAutoplugger *autoplugger)
164 // create the autoplugger cache, which is the fundamental unit of the autopluggerger
165 // FIXME we need to find a way to set element's name before _init
166 // FIXME ... so we can name the subelements uniquely
167 autoplugger->cache = gst_elementfactory_make("autoplugcache", "unnamed_autoplugcache");
168 g_return_if_fail (autoplugger->cache != NULL);
170 GST_DEBUG(GST_CAT_AUTOPLUG, "turning on caps nego proxying in cache\n");
171 g_object_set(G_OBJECT(autoplugger->cache),"caps_proxy",TRUE,NULL);
173 // attach signals to the cache
174 g_signal_connect (G_OBJECT (autoplugger->cache), "first_buffer",
175 G_CALLBACK (gst_autoplugger_cache_first_buffer), autoplugger);
177 // add the cache to self
178 gst_bin_add (GST_BIN(autoplugger), autoplugger->cache);
180 // get the cache's pads so we can attach stuff to them
181 autoplugger->cache_sinkpad = gst_element_get_pad (autoplugger->cache, "sink");
182 autoplugger->cache_srcpad = gst_element_get_pad (autoplugger->cache, "src");
184 // attach handlers to the typefind pads
185 g_signal_connect (G_OBJECT (autoplugger->cache_sinkpad), "caps_changed",
186 G_CALLBACK (gst_autoplugger_external_sink_caps_changed), autoplugger);
187 g_signal_connect (G_OBJECT (autoplugger->cache_srcpad), "caps_changed",
188 G_CALLBACK (gst_autoplugger_external_src_caps_changed), autoplugger);
189 g_signal_connect (G_OBJECT (autoplugger->cache_sinkpad), "caps_nego_failed",
190 G_CALLBACK (gst_autoplugger_external_sink_caps_nego_failed), autoplugger);
191 g_signal_connect (G_OBJECT (autoplugger->cache_srcpad), "caps_nego_failed",
192 G_CALLBACK (gst_autoplugger_external_src_caps_nego_failed), autoplugger);
193 // g_signal_connect (G_OBJECT (autoplugger->cache_sinkpad), "connected",
194 // gst_autoplugger_external_sink_connected, autoplugger);
195 // g_signal_connect (G_OBJECT (autoplugger->cache_srcpad), "connected",
196 // gst_autoplugger_external_src_connected, autoplugger);
198 // ghost both of these pads to the outside world
199 gst_element_add_ghost_pad (GST_ELEMENT(autoplugger), autoplugger->cache_sinkpad, "sink");
200 gst_element_add_ghost_pad (GST_ELEMENT(autoplugger), autoplugger->cache_srcpad, "src");
205 gst_autoplugger_external_sink_connected(GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger)
207 GstPadTemplate *peertemplate;
208 GstCaps *peercaps, *peertemplatecaps;
210 GST_INFO(GST_CAT_AUTOPLUG, "have cache:sink connected");
211 // autoplugger->sinkpadpeer = peerpad;
213 if (autoplugger->sinkpadpeer) {
214 peercaps = GST_PAD_CAPS(autoplugger->sinkpadpeer);
216 GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer: %s",
217 gst_caps_get_mime(peercaps));
218 peertemplate = GST_PAD_PADTEMPLATE(autoplugger->sinkpadpeer);
220 peertemplatecaps = GST_PADTEMPLATE_CAPS(peertemplate);
221 if (peertemplatecaps) {
222 GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer's padtemplate %s",
223 gst_caps_get_mime(peertemplatecaps));
230 gst_autoplugger_external_src_connected(GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger)
232 GstPadTemplate *peertemplate;
233 GstCaps *peercaps, *peertemplatecaps;
235 GST_INFO(GST_CAT_AUTOPLUG, "have cache:src connected");
236 // autoplugger->srcpadpeer = peerpad;
238 if (autoplugger->srcpadpeer) {
239 peercaps = GST_PAD_CAPS(autoplugger->srcpadpeer);
241 GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer: %s",
242 gst_caps_get_mime(peercaps));
243 peertemplate = GST_PAD_PADTEMPLATE(autoplugger->srcpadpeer);
245 peertemplatecaps = GST_PADTEMPLATE_CAPS(peertemplate);
246 if (peertemplatecaps) {
247 GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer's padtemplate %s",
248 gst_caps_get_mime(peertemplatecaps));
249 autoplugger->sinktemplatecaps = peertemplatecaps;
250 // GST_DEBUG(GST_CAT_AUTOPLUG, "turning on caps nego proxying in cache\n");
251 // gtk_object_set(G_OBJECT(autoplugger->cache),"caps_proxy",TRUE,NULL);
259 gst_autoplugger_external_sink_caps_changed(GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger)
261 GST_INFO(GST_CAT_AUTOPLUG, "have cache:sink caps of %s\n",gst_caps_get_mime(caps));
262 autoplugger->sinkcaps = caps;
266 gst_autoplugger_external_src_caps_changed(GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger)
268 GST_INFO(GST_CAT_AUTOPLUG, "have cache:src caps of %s\n",gst_caps_get_mime(caps));
269 autoplugger->srccaps = caps;
274 gst_autoplugger_autoplug(GstAutoplugger *autoplugger,GstPad *srcpad,GstCaps *srccaps,GstCaps *sinkcaps)
278 sinkpad = GST_PAD(GST_PAD_PEER(srcpad));
279 GST_DEBUG(GST_CAT_AUTOPLUG,"disconnecting %s:%s and %s:%s to autoplug between them\n",
280 GST_DEBUG_PAD_NAME(srcpad),GST_DEBUG_PAD_NAME(sinkpad));
281 GST_DEBUG(GST_CAT_AUTOPLUG,"srcpadcaps are of type %s\n",gst_caps_get_mime(srccaps));
282 GST_DEBUG(GST_CAT_AUTOPLUG,"sinkpadcaps are of type %s\n",gst_caps_get_mime(sinkcaps));
284 // disconnect the pads
285 GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting the pads that will be joined by an autobin\n");
286 gst_pad_disconnect(srcpad,sinkpad);
288 if (!autoplugger->autoplug) {
289 autoplugger->autoplug = gst_autoplugfactory_make("static");
290 g_return_val_if_fail(autoplugger->autoplug != NULL, FALSE);
292 GST_DEBUG(GST_CAT_AUTOPLUG, "building autoplugged bin between caps\n");
293 autoplugger->autobin = gst_autoplug_to_caps(autoplugger->autoplug,
294 srccaps,sinkcaps,NULL);
295 g_return_val_if_fail(autoplugger->autobin != NULL, FALSE);
296 gst_bin_add(GST_BIN(autoplugger),autoplugger->autobin);
298 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
300 // FIXME this is a hack
301 // GST_DEBUG(GST_CAT_AUTOPLUG, "copying failed caps to srcpad %s:%s to ensure renego\n",GST_DEBUG_PAD_NAME(autoplugger->cache_srcpad));
302 // gst_pad_set_caps(srcpad,srccaps);
304 if (GST_PAD_CAPS(srcpad) == NULL) GST_DEBUG(GST_CAT_AUTOPLUG,"no caps on cache:src!\n");
306 // attach the autoplugged bin
307 GST_DEBUG(GST_CAT_AUTOPLUG, "attaching the autoplugged bin between the two pads\n");
308 gst_pad_connect(srcpad,gst_element_get_pad(autoplugger->autobin,"sink"));
309 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
310 gst_pad_connect(gst_element_get_pad(autoplugger->autobin,"src_00"),sinkpad);
311 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
313 // FIXME try to force the renego
314 // GST_DEBUG(GST_CAT_AUTOPLUG, "trying to force everyone to nego\n");
315 // gst_pad_renegotiate(gst_element_get_pad(autoplugger->autobin,"sink"));
316 // gst_pad_renegotiate(sinkpad);
322 gst_autoplugger_external_sink_caps_nego_failed(GstPad *pad, gboolean *result, GstAutoplugger *autoplugger)
325 GstPadTemplate *srcpad_peer_template;
326 GstCaps *srcpad_peer_caps;
327 GstPad *sinkpad_peer;
328 GstCaps *sinkpad_peer_caps;
330 GST_INFO(GST_CAT_AUTOPLUG, "have caps nego failure on sinkpad %s:%s!!!",GST_DEBUG_PAD_NAME(pad));
332 autoplugger->paused++;
333 if (autoplugger->paused == 1)
334 // try to PAUSE the whole thing
335 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
337 srcpad_peer = GST_PAD(GST_PAD_PEER(autoplugger->cache_srcpad));
338 g_return_if_fail(srcpad_peer != NULL);
339 srcpad_peer_template = GST_PAD_PADTEMPLATE(srcpad_peer);
340 g_return_if_fail(srcpad_peer_template != NULL);
341 srcpad_peer_caps = GST_PADTEMPLATE_CAPS(srcpad_peer_template);
342 g_return_if_fail(srcpad_peer_caps != NULL);
344 sinkpad_peer = GST_PAD(GST_PAD_PEER(pad));
345 g_return_if_fail(sinkpad_peer != NULL);
346 sinkpad_peer_caps = GST_PAD_CAPS(sinkpad_peer);
347 g_return_if_fail(sinkpad_peer_caps != NULL);
349 if (gst_autoplugger_autoplug(autoplugger,autoplugger->cache_srcpad,sinkpad_peer_caps,srcpad_peer_caps))
353 gst_pad_renegotiate(GST_PAD(GST_PAD_PEER(autoplugger->cache_sinkpad)));
355 autoplugger->paused--;
356 if (autoplugger->paused == 0)
357 // try to PLAY the whole thing
358 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
360 GST_INFO(GST_CAT_AUTOPLUG, "done dealing with caps nego failure on sinkpad %s:%s",GST_DEBUG_PAD_NAME(pad));
364 gst_autoplugger_external_src_caps_nego_failed(GstPad *pad, gboolean *result, GstAutoplugger *autoplugger)
366 GstCaps *srcpad_caps;
368 GstPadTemplate *srcpad_peer_template;
369 GstCaps *srcpad_peer_caps;
371 GST_INFO(GST_CAT_AUTOPLUG, "have caps nego failure on srcpad %s:%s!!!",GST_DEBUG_PAD_NAME(pad));
373 autoplugger->paused++;
374 if (autoplugger->paused == 1)
375 // try to PAUSE the whole thing
376 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
378 srcpad_caps = GST_PAD_CAPS(autoplugger->cache_srcpad);
380 srcpad_peer = GST_PAD(GST_PAD_PEER(autoplugger->cache_srcpad));
381 g_return_if_fail(srcpad_peer != NULL);
382 srcpad_peer_template = GST_PAD_PADTEMPLATE(srcpad_peer);
383 g_return_if_fail(srcpad_peer_template != NULL);
384 srcpad_peer_caps = GST_PADTEMPLATE_CAPS(srcpad_peer_template);
385 g_return_if_fail(srcpad_peer_caps != NULL);
387 if (gst_autoplugger_autoplug(autoplugger,autoplugger->cache_srcpad,srcpad_caps,srcpad_peer_caps))
390 autoplugger->paused--;
391 if (autoplugger->paused == 0)
392 // try to PLAY the whole thing
393 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
395 autoplugger->disable_nocaps = TRUE;
397 GST_INFO(GST_CAT_AUTOPLUG, "done dealing with caps nego failure on srcpad %s:%s",GST_DEBUG_PAD_NAME(pad));
402 gst_autoplugger_cache_empty(GstElement *element, GstAutoplugger *autoplugger)
404 GstPad *cache_sinkpad_peer,*cache_srcpad_peer;
406 GST_INFO(GST_CAT_AUTOPLUG, "autoplugger cache has hit empty, we can now remove it");
408 autoplugger->paused++;
409 if (autoplugger->paused == 1)
410 // try to PAUSE the whole thing
411 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
413 // disconnect the cache from its peers
414 GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting autoplugcache from its peers\n");
415 cache_sinkpad_peer = GST_PAD (GST_PAD_PEER(autoplugger->cache_sinkpad));
416 cache_srcpad_peer = GST_PAD (GST_PAD_PEER(autoplugger->cache_srcpad));
417 gst_pad_disconnect(cache_sinkpad_peer,autoplugger->cache_sinkpad);
418 gst_pad_disconnect(autoplugger->cache_srcpad,cache_srcpad_peer);
420 // remove the cache from self
421 GST_DEBUG(GST_CAT_AUTOPLUG, "removing the cache from the autoplugger\n");
422 gst_bin_remove (GST_BIN(autoplugger), autoplugger->cache);
424 // connect the two pads
425 GST_DEBUG(GST_CAT_AUTOPLUG, "reconnecting the autoplugcache's former peers\n");
426 gst_pad_connect(cache_sinkpad_peer,cache_srcpad_peer);
428 autoplugger->paused--;
429 if (autoplugger->paused == 0)
430 // try to PLAY the whole thing
431 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
433 // xmlSaveFile("autoplugger.gst", gst_xml_write(GST_ELEMENT_SCHED(autoplugger)->parent));
435 GST_INFO(GST_CAT_AUTOPLUG, "autoplugger_cache_empty finished");
439 gst_autoplugger_typefind_have_type(GstElement *element, GstCaps *caps, GstAutoplugger *autoplugger)
441 GST_INFO(GST_CAT_AUTOPLUG, "typefind claims to have a type: %s",gst_caps_get_mime(caps));
443 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
445 autoplugger->paused++;
446 if (autoplugger->paused == 1)
447 // try to PAUSE the whole thing
448 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
450 // first disconnect the typefind and shut it down
451 GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting typefind from the cache\n");
452 gst_pad_disconnect(autoplugger->cache_srcpad,autoplugger->typefind_sinkpad);
453 gst_bin_remove(GST_BIN(autoplugger),autoplugger->typefind);
455 // FIXME FIXME now we'd compare caps and see if we need to autoplug something in the middle, but for
456 // now we're going to just reconnect where we left off
457 // FIXME FIXME FIXME!!!: this should really be done in the caps failure!!!
459 if (!autoplugger->autoplug) {
460 autoplugger->autoplug = gst_autoplugfactory_make("static");
462 autoplugger->autobin = gst_autoplug_to_caps(autoplugger->autoplug,
463 caps,autoplugger->sinktemplatecaps,NULL);
464 g_return_if_fail(autoplugger->autobin != NULL);
465 gst_bin_add(GST_BIN(autoplugger),autoplugger->autobin);
467 // // re-attach the srcpad's original peer to the cache
468 // GST_DEBUG(GST_CAT_AUTOPLUG, "reconnecting the cache to the downstream peer\n");
469 // gst_pad_connect(autoplugger->cache_srcpad,autoplugger->srcpadpeer);
471 // attach the autoplugged bin
472 GST_DEBUG(GST_CAT_AUTOPLUG, "attaching the autoplugged bin between cache and downstream peer\n");
473 gst_pad_connect(autoplugger->cache_srcpad,gst_element_get_pad(autoplugger->autobin,"sink"));
474 gst_pad_connect(gst_element_get_pad(autoplugger->autobin,"src_00"),autoplugger->srcpadpeer);
477 // FIXME set the caps on the new connection
478 // GST_DEBUG(GST_CAT_AUTOPLUG,"forcing caps on the typefound pad\n");
479 // gst_pad_set_caps(autoplugger->cache_srcpad,caps);
481 // reattach the original outside srcpad
482 GST_DEBUG(GST_CAT_AUTOPLUG,"re-attaching downstream peer to autoplugcache\n");
483 gst_pad_connect(autoplugger->cache_srcpad,autoplugger->srcpadpeer);
485 // now reset the autoplugcache
486 GST_DEBUG(GST_CAT_AUTOPLUG, "resetting the cache to send first buffer(s) again\n");
487 g_object_set(G_OBJECT(autoplugger->cache),"reset",TRUE,NULL);
489 // attach the cache_empty handler
490 // FIXME this is the wrong place, it shouldn't be done until we get successful caps nego!
491 g_signal_connect (G_OBJECT(autoplugger->cache),"cache_empty",
492 G_CALLBACK (gst_autoplugger_cache_empty), autoplugger);
494 autoplugger->paused--;
495 if (autoplugger->paused == 0)
496 // try to PLAY the whole thing
497 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
499 GST_INFO(GST_CAT_AUTOPLUG, "typefind_have_type finished");
500 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
504 gst_autoplugger_cache_first_buffer(GstElement *element,GstBuffer *buf,GstAutoplugger *autoplugger)
506 GST_INFO(GST_CAT_AUTOPLUG, "have first buffer through cache");
507 autoplugger->cache_first_buffer = TRUE;
509 // if there are no established caps, worry
510 if (!autoplugger->sinkcaps) {
511 GST_INFO(GST_CAT_AUTOPLUG, "have no caps for the buffer, Danger Will Robinson!");
513 if (autoplugger->disable_nocaps) {
514 GST_DEBUG(GST_CAT_AUTOPLUG, "not dealing with lack of caps this time\n");
518 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
520 autoplugger->paused++;
521 if (autoplugger->paused == 1)
522 // try to PAUSE the whole thing
523 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
526 GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting cache from its downstream peer\n");
527 autoplugger->srcpadpeer = GST_PAD(GST_PAD_PEER(autoplugger->cache_srcpad));
528 gst_pad_disconnect(autoplugger->cache_srcpad,autoplugger->srcpadpeer);
530 // instantiate the typefind and set up the signal handlers
531 if (!autoplugger->typefind) {
532 GST_DEBUG(GST_CAT_AUTOPLUG, "creating typefind and setting signal handler\n");
533 autoplugger->typefind = gst_elementfactory_make("typefind","unnamed_typefind");
534 autoplugger->typefind_sinkpad = gst_element_get_pad(autoplugger->typefind,"sink");
535 g_signal_connect (G_OBJECT(autoplugger->typefind),"have_type",
536 G_CALLBACK (gst_autoplugger_typefind_have_type), autoplugger);
538 // add it to self and attach it
539 GST_DEBUG(GST_CAT_AUTOPLUG, "adding typefind to self and connecting to cache\n");
540 gst_bin_add(GST_BIN(autoplugger),autoplugger->typefind);
541 gst_pad_connect(autoplugger->cache_srcpad,autoplugger->typefind_sinkpad);
543 // bring the typefind into playing state
544 GST_DEBUG(GST_CAT_AUTOPLUG, "setting typefind state to PLAYING\n");
545 gst_element_set_state(autoplugger->cache,GST_STATE_PLAYING);
547 autoplugger->paused--;
548 if (autoplugger->paused == 0)
549 // try to PLAY the whole thing
550 gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
552 GST_INFO(GST_CAT_AUTOPLUG,"here we go into nothingness, hoping the typefind will return us to safety");
553 gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
555 // // attach the cache_empty handler, since the cache simply isn't needed
556 // g_signal_connect (G_OBJECT(autoplugger->cache),"cache_empty",
557 // gst_autoplugger_cache_empty,autoplugger);
562 gst_autoplugger_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
564 GstAutoplugger *autoplugger;
566 autoplugger = GST_AUTOPLUGGER (object);
575 gst_autoplugger_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
577 GstAutoplugger *autoplugger;
579 autoplugger = GST_AUTOPLUGGER (object);
583 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
589 plugin_init (GModule *module, GstPlugin *plugin)
591 GstElementFactory *factory;
593 factory = gst_elementfactory_new ("autoplugger", GST_TYPE_AUTOPLUGGER,
594 &gst_autoplugger_details);
595 g_return_val_if_fail (factory != NULL, FALSE);
597 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
602 GstPluginDesc plugin_desc = {