2001-05-25 21:00:07 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2001 RidgeRun, Inc. (www.ridgerun.com)
|
|
|
|
*
|
|
|
|
* gstautoplugger.c: Data for the dynamic autopluggerger
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
GstElementDetails gst_autoplugger_details = {
|
|
|
|
"Dynamic autoplugger",
|
|
|
|
"Autoplugger",
|
|
|
|
"Magic element that converts from any type to any other",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@temple-baptist.com>",
|
|
|
|
"(C) 2001 RidgeRun, Inc. (www.ridgerun.com)",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_TYPE_AUTOPLUGGER \
|
|
|
|
(gst_autoplugger_get_type())
|
|
|
|
#define GST_AUTOPLUGGER(obj) \
|
2001-06-25 01:20:11 +00:00
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUTOPLUGGER,GstAutoplugger))
|
2001-05-25 21:00:07 +00:00
|
|
|
#define GST_AUTOPLUGGER_CLASS(klass) \
|
2001-06-25 01:20:11 +00:00
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUTOPLUGGER,GstAutopluggerClass))
|
2001-05-25 21:00:07 +00:00
|
|
|
#define GST_IS_AUTOPLUGGER(obj) \
|
2001-06-25 01:20:11 +00:00
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUTOPLUGGER))
|
2001-05-25 21:00:07 +00:00
|
|
|
#define GST_IS_AUTOPLUGGER_CLASS(obj) \
|
2001-06-25 01:20:11 +00:00
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUTOPLUGGER))
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
typedef struct _GstAutoplugger GstAutoplugger;
|
|
|
|
typedef struct _GstAutopluggerClass GstAutopluggerClass;
|
|
|
|
|
|
|
|
struct _GstAutoplugger {
|
|
|
|
GstBin bin;
|
|
|
|
gint paused;
|
|
|
|
|
|
|
|
GstElement *cache;
|
|
|
|
gboolean cache_first_buffer;
|
|
|
|
GstPad *cache_sinkpad, *cache_srcpad;
|
|
|
|
|
|
|
|
GstElement *typefind;
|
|
|
|
GstPad *typefind_sinkpad;
|
|
|
|
|
|
|
|
GstPad *sinkpadpeer, *srcpadpeer;
|
|
|
|
GstCaps *sinkcaps, *srccaps;
|
|
|
|
|
|
|
|
GstCaps *sinktemplatecaps;
|
|
|
|
|
|
|
|
GstAutoplug *autoplug;
|
|
|
|
GstElement *autobin;
|
|
|
|
|
|
|
|
gboolean disable_nocaps;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstAutopluggerClass {
|
|
|
|
GstBinClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* signals and args */
|
|
|
|
enum {
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_autoplugger_class_init (GstAutopluggerClass *klass);
|
|
|
|
static void gst_autoplugger_init (GstAutoplugger *queue);
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
static void gst_autoplugger_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_autoplugger_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/*static GstElementStateReturn gst_autoplugger_change_state (GstElement *element);*/
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void gst_autoplugger_external_sink_caps_changed (GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_external_src_caps_changed (GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_external_sink_caps_nego_failed (GstPad *pad, gboolean *result, GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_external_src_caps_nego_failed (GstPad *pad, gboolean *result, GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_external_sink_connected (GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_external_src_connected (GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger);
|
|
|
|
|
|
|
|
static void gst_autoplugger_cache_first_buffer (GstElement *element,GstBuffer *buf,GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_cache_empty (GstElement *element, GstAutoplugger *autoplugger);
|
|
|
|
static void gst_autoplugger_typefind_have_type (GstElement *element, GstCaps *caps, GstAutoplugger *autoplugger);
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2001-12-17 22:26:56 +00:00
|
|
|
/*static guint gst_autoplugger_signals[LAST_SIGNAL] = { 0 };*/
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_autoplugger_get_type(void) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType autoplugger_type = 0;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
if (!autoplugger_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo autoplugger_info = {
|
2001-05-25 21:00:07 +00:00
|
|
|
sizeof(GstAutopluggerClass),
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_autoplugger_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstAutoplugger),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_autoplugger_init,
|
2001-05-25 21:00:07 +00:00
|
|
|
};
|
2001-06-25 01:20:11 +00:00
|
|
|
autoplugger_type = g_type_register_static (GST_TYPE_BIN, "GstAutoplugger", &autoplugger_info, 0);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
return autoplugger_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_class_init (GstAutopluggerClass *klass)
|
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-05-25 21:00:07 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2001-05-25 21:00:07 +00:00
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
gst_autoplugger_signals[_EMPTY] =
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_new ("_empty", G_OBJECT_TYPE(gobject_class), G_SIGNAL_RUN_LAST,
|
2001-06-25 01:20:11 +00:00
|
|
|
G_STRUCT_OFFSET (GstAutopluggerClass, _empty), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
2001-05-25 21:00:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFFER_COUNT,
|
|
|
|
g_param_spec_int("buffer_count","buffer_count","buffer_count",
|
2002-03-19 04:10:13 +00:00
|
|
|
0,G_MAXINT,0,G_PARAM_READABLE)); * CHECKME! *
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_RESET,
|
|
|
|
g_param_spec_boolean("reset","reset","reset",
|
2002-03-19 04:10:13 +00:00
|
|
|
FALSE,G_PARAM_WRITABLE)); * CHECKME! *
|
2001-05-25 21:00:07 +00:00
|
|
|
*/
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class->set_property = gst_autoplugger_set_property;
|
|
|
|
gobject_class->get_property = gst_autoplugger_get_property;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* gstelement_class->change_state = gst_autoplugger_change_state; */
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_init (GstAutoplugger *autoplugger)
|
|
|
|
{
|
2001-12-17 22:26:56 +00:00
|
|
|
/* create the autoplugger cache, which is the fundamental unit of the autopluggerger */
|
|
|
|
/* FIXME we need to find a way to set element's name before _init */
|
|
|
|
/* FIXME ... so we can name the subelements uniquely */
|
2001-05-25 21:00:07 +00:00
|
|
|
autoplugger->cache = gst_elementfactory_make("autoplugcache", "unnamed_autoplugcache");
|
|
|
|
g_return_if_fail (autoplugger->cache != NULL);
|
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "turning on caps nego proxying in cache");
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_set(G_OBJECT(autoplugger->cache),"caps_proxy",TRUE,NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* attach signals to the cache */
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT (autoplugger->cache), "first_buffer",
|
|
|
|
G_CALLBACK (gst_autoplugger_cache_first_buffer), autoplugger);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* add the cache to self */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add (GST_BIN(autoplugger), autoplugger->cache);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* get the cache's pads so we can attach stuff to them */
|
2001-05-25 21:00:07 +00:00
|
|
|
autoplugger->cache_sinkpad = gst_element_get_pad (autoplugger->cache, "sink");
|
|
|
|
autoplugger->cache_srcpad = gst_element_get_pad (autoplugger->cache, "src");
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* attach handlers to the typefind pads */
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT (autoplugger->cache_sinkpad), "caps_changed",
|
|
|
|
G_CALLBACK (gst_autoplugger_external_sink_caps_changed), autoplugger);
|
|
|
|
g_signal_connect (G_OBJECT (autoplugger->cache_srcpad), "caps_changed",
|
|
|
|
G_CALLBACK (gst_autoplugger_external_src_caps_changed), autoplugger);
|
|
|
|
g_signal_connect (G_OBJECT (autoplugger->cache_sinkpad), "caps_nego_failed",
|
|
|
|
G_CALLBACK (gst_autoplugger_external_sink_caps_nego_failed), autoplugger);
|
|
|
|
g_signal_connect (G_OBJECT (autoplugger->cache_srcpad), "caps_nego_failed",
|
|
|
|
G_CALLBACK (gst_autoplugger_external_src_caps_nego_failed), autoplugger);
|
2001-12-17 22:26:56 +00:00
|
|
|
/* g_signal_connect (G_OBJECT (autoplugger->cache_sinkpad), "connected", */
|
|
|
|
/* gst_autoplugger_external_sink_connected, autoplugger);*/
|
|
|
|
/* g_signal_connect (G_OBJECT (autoplugger->cache_srcpad), "connected", */
|
|
|
|
/* gst_autoplugger_external_src_connected, autoplugger); */
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* ghost both of these pads to the outside world */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_add_ghost_pad (GST_ELEMENT(autoplugger), autoplugger->cache_sinkpad, "sink");
|
|
|
|
gst_element_add_ghost_pad (GST_ELEMENT(autoplugger), autoplugger->cache_srcpad, "src");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-02 13:27:33 +00:00
|
|
|
G_GNUC_UNUSED static void
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_autoplugger_external_sink_connected(GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GstPadTemplate *peertemplate;
|
|
|
|
GstCaps *peercaps, *peertemplatecaps;
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have cache:sink connected");
|
2001-12-17 22:26:56 +00:00
|
|
|
/* autoplugger->sinkpadpeer = peerpad; */
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
if (autoplugger->sinkpadpeer) {
|
|
|
|
peercaps = GST_PAD_CAPS(autoplugger->sinkpadpeer);
|
|
|
|
if (peercaps)
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer: %s",
|
|
|
|
gst_caps_get_mime(peercaps));
|
|
|
|
peertemplate = GST_PAD_PADTEMPLATE(autoplugger->sinkpadpeer);
|
|
|
|
if (peertemplate) {
|
|
|
|
peertemplatecaps = GST_PADTEMPLATE_CAPS(peertemplate);
|
|
|
|
if (peertemplatecaps) {
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer's padtemplate %s",
|
|
|
|
gst_caps_get_mime(peertemplatecaps));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-02 13:27:33 +00:00
|
|
|
G_GNUC_UNUSED static void
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_autoplugger_external_src_connected(GstPad *pad, GstPad *peerpad, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GstPadTemplate *peertemplate;
|
|
|
|
GstCaps *peercaps, *peertemplatecaps;
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have cache:src connected");
|
2001-12-17 22:26:56 +00:00
|
|
|
/* autoplugger->srcpadpeer = peerpad; */
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
if (autoplugger->srcpadpeer) {
|
|
|
|
peercaps = GST_PAD_CAPS(autoplugger->srcpadpeer);
|
|
|
|
if (peercaps)
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer: %s",
|
|
|
|
gst_caps_get_mime(peercaps));
|
|
|
|
peertemplate = GST_PAD_PADTEMPLATE(autoplugger->srcpadpeer);
|
|
|
|
if (peertemplate) {
|
|
|
|
peertemplatecaps = GST_PADTEMPLATE_CAPS(peertemplate);
|
|
|
|
if (peertemplatecaps) {
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "there are some caps on this pad's peer's padtemplate %s",
|
|
|
|
gst_caps_get_mime(peertemplatecaps));
|
|
|
|
autoplugger->sinktemplatecaps = peertemplatecaps;
|
2002-03-24 22:07:09 +00:00
|
|
|
/* GST_DEBUG(GST_CAT_AUTOPLUG, "turning on caps nego proxying in cache"); */
|
2001-12-17 22:26:56 +00:00
|
|
|
/* gtk_object_set(G_OBJECT(autoplugger->cache),"caps_proxy",TRUE,NULL);*/
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_external_sink_caps_changed(GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have cache:sink caps of %s\n",gst_caps_get_mime(caps));
|
|
|
|
autoplugger->sinkcaps = caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_external_src_caps_changed(GstPad *pad, GstCaps *caps, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have cache:src caps of %s\n",gst_caps_get_mime(caps));
|
|
|
|
autoplugger->srccaps = caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_autoplugger_autoplug(GstAutoplugger *autoplugger,GstPad *srcpad,GstCaps *srccaps,GstCaps *sinkcaps)
|
|
|
|
{
|
|
|
|
GstPad *sinkpad;
|
|
|
|
|
|
|
|
sinkpad = GST_PAD(GST_PAD_PEER(srcpad));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG,"disconnecting %s:%s and %s:%s to autoplug between them",
|
2001-05-25 21:00:07 +00:00
|
|
|
GST_DEBUG_PAD_NAME(srcpad),GST_DEBUG_PAD_NAME(sinkpad));
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG,"srcpadcaps are of type %s",gst_caps_get_mime(srccaps));
|
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG,"sinkpadcaps are of type %s",gst_caps_get_mime(sinkcaps));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* disconnect the pads */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting the pads that will be joined by an autobin");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_disconnect(srcpad,sinkpad);
|
|
|
|
|
|
|
|
if (!autoplugger->autoplug) {
|
|
|
|
autoplugger->autoplug = gst_autoplugfactory_make("static");
|
|
|
|
g_return_val_if_fail(autoplugger->autoplug != NULL, FALSE);
|
|
|
|
}
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "building autoplugged bin between caps");
|
2001-05-25 21:00:07 +00:00
|
|
|
autoplugger->autobin = gst_autoplug_to_caps(autoplugger->autoplug,
|
|
|
|
srccaps,sinkcaps,NULL);
|
|
|
|
g_return_val_if_fail(autoplugger->autobin != NULL, FALSE);
|
|
|
|
gst_bin_add(GST_BIN(autoplugger),autoplugger->autobin);
|
|
|
|
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* FIXME this is a hack */
|
2002-03-24 22:07:09 +00:00
|
|
|
/* GST_DEBUG(GST_CAT_AUTOPLUG, "copying failed caps to srcpad %s:%s to ensure renego",GST_DEBUG_PAD_NAME(autoplugger->cache_srcpad)); */
|
2001-12-17 22:26:56 +00:00
|
|
|
/* gst_pad_set_caps(srcpad,srccaps); */
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
if (GST_PAD_CAPS(srcpad) == NULL) GST_DEBUG(GST_CAT_AUTOPLUG,"no caps on cache:src!");
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* attach the autoplugged bin */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "attaching the autoplugged bin between the two pads");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_connect(srcpad,gst_element_get_pad(autoplugger->autobin,"sink"));
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_connect(gst_element_get_pad(autoplugger->autobin,"src_00"),sinkpad);
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* FIXME try to force the renego */
|
2002-03-24 22:07:09 +00:00
|
|
|
/* GST_DEBUG(GST_CAT_AUTOPLUG, "trying to force everyone to nego"); */
|
2001-12-17 22:26:56 +00:00
|
|
|
/* gst_pad_renegotiate(gst_element_get_pad(autoplugger->autobin,"sink")); */
|
|
|
|
/* gst_pad_renegotiate(sinkpad); */
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_external_sink_caps_nego_failed(GstPad *pad, gboolean *result, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GstPad *srcpad_peer;
|
|
|
|
GstPadTemplate *srcpad_peer_template;
|
|
|
|
GstCaps *srcpad_peer_caps;
|
|
|
|
GstPad *sinkpad_peer;
|
|
|
|
GstCaps *sinkpad_peer_caps;
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have caps nego failure on sinkpad %s:%s!!!",GST_DEBUG_PAD_NAME(pad));
|
|
|
|
|
|
|
|
autoplugger->paused++;
|
|
|
|
if (autoplugger->paused == 1)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PAUSE the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
srcpad_peer = GST_PAD(GST_PAD_PEER(autoplugger->cache_srcpad));
|
|
|
|
g_return_if_fail(srcpad_peer != NULL);
|
|
|
|
srcpad_peer_template = GST_PAD_PADTEMPLATE(srcpad_peer);
|
|
|
|
g_return_if_fail(srcpad_peer_template != NULL);
|
|
|
|
srcpad_peer_caps = GST_PADTEMPLATE_CAPS(srcpad_peer_template);
|
|
|
|
g_return_if_fail(srcpad_peer_caps != NULL);
|
|
|
|
|
|
|
|
sinkpad_peer = GST_PAD(GST_PAD_PEER(pad));
|
|
|
|
g_return_if_fail(sinkpad_peer != NULL);
|
|
|
|
sinkpad_peer_caps = GST_PAD_CAPS(sinkpad_peer);
|
|
|
|
g_return_if_fail(sinkpad_peer_caps != NULL);
|
|
|
|
|
|
|
|
if (gst_autoplugger_autoplug(autoplugger,autoplugger->cache_srcpad,sinkpad_peer_caps,srcpad_peer_caps))
|
|
|
|
*result = TRUE;
|
|
|
|
|
|
|
|
autoplugger->paused--;
|
|
|
|
if (autoplugger->paused == 0)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PLAY the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "done dealing with caps nego failure on sinkpad %s:%s",GST_DEBUG_PAD_NAME(pad));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_external_src_caps_nego_failed(GstPad *pad, gboolean *result, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GstCaps *srcpad_caps;
|
|
|
|
GstPad *srcpad_peer;
|
|
|
|
GstPadTemplate *srcpad_peer_template;
|
|
|
|
GstCaps *srcpad_peer_caps;
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have caps nego failure on srcpad %s:%s!!!",GST_DEBUG_PAD_NAME(pad));
|
|
|
|
|
|
|
|
autoplugger->paused++;
|
|
|
|
if (autoplugger->paused == 1)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PAUSE the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
|
|
|
|
|
|
|
|
srcpad_caps = GST_PAD_CAPS(autoplugger->cache_srcpad);
|
|
|
|
|
|
|
|
srcpad_peer = GST_PAD(GST_PAD_PEER(autoplugger->cache_srcpad));
|
|
|
|
g_return_if_fail(srcpad_peer != NULL);
|
|
|
|
srcpad_peer_template = GST_PAD_PADTEMPLATE(srcpad_peer);
|
|
|
|
g_return_if_fail(srcpad_peer_template != NULL);
|
|
|
|
srcpad_peer_caps = GST_PADTEMPLATE_CAPS(srcpad_peer_template);
|
|
|
|
g_return_if_fail(srcpad_peer_caps != NULL);
|
|
|
|
|
|
|
|
if (gst_autoplugger_autoplug(autoplugger,autoplugger->cache_srcpad,srcpad_caps,srcpad_peer_caps))
|
|
|
|
*result = TRUE;
|
|
|
|
|
|
|
|
autoplugger->paused--;
|
|
|
|
if (autoplugger->paused == 0)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PLAY the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
autoplugger->disable_nocaps = TRUE;
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "done dealing with caps nego failure on srcpad %s:%s",GST_DEBUG_PAD_NAME(pad));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_cache_empty(GstElement *element, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GstPad *cache_sinkpad_peer,*cache_srcpad_peer;
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "autoplugger cache has hit empty, we can now remove it");
|
|
|
|
|
|
|
|
autoplugger->paused++;
|
|
|
|
if (autoplugger->paused == 1)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PAUSE the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* disconnect the cache from its peers */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting autoplugcache from its peers");
|
2001-05-25 21:00:07 +00:00
|
|
|
cache_sinkpad_peer = GST_PAD (GST_PAD_PEER(autoplugger->cache_sinkpad));
|
|
|
|
cache_srcpad_peer = GST_PAD (GST_PAD_PEER(autoplugger->cache_srcpad));
|
|
|
|
gst_pad_disconnect(cache_sinkpad_peer,autoplugger->cache_sinkpad);
|
|
|
|
gst_pad_disconnect(autoplugger->cache_srcpad,cache_srcpad_peer);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* remove the cache from self */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "removing the cache from the autoplugger");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_remove (GST_BIN(autoplugger), autoplugger->cache);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* connect the two pads */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "reconnecting the autoplugcache's former peers");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_connect(cache_sinkpad_peer,cache_srcpad_peer);
|
|
|
|
|
|
|
|
autoplugger->paused--;
|
|
|
|
if (autoplugger->paused == 0)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PLAY the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* xmlSaveFile("autoplugger.gst", gst_xml_write(GST_ELEMENT_SCHED(autoplugger)->parent)); */
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "autoplugger_cache_empty finished");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_typefind_have_type(GstElement *element, GstCaps *caps, GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "typefind claims to have a type: %s",gst_caps_get_mime(caps));
|
|
|
|
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
autoplugger->paused++;
|
|
|
|
if (autoplugger->paused == 1)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PAUSE the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* first disconnect the typefind and shut it down */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting typefind from the cache");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_disconnect(autoplugger->cache_srcpad,autoplugger->typefind_sinkpad);
|
|
|
|
gst_bin_remove(GST_BIN(autoplugger),autoplugger->typefind);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* FIXME FIXME now we'd compare caps and see if we need to autoplug something in the middle, but for */
|
|
|
|
/* now we're going to just reconnect where we left off */
|
|
|
|
/* FIXME FIXME FIXME!!!: this should really be done in the caps failure!!! */
|
2001-05-25 21:00:07 +00:00
|
|
|
/*
|
|
|
|
if (!autoplugger->autoplug) {
|
|
|
|
autoplugger->autoplug = gst_autoplugfactory_make("static");
|
|
|
|
}
|
|
|
|
autoplugger->autobin = gst_autoplug_to_caps(autoplugger->autoplug,
|
|
|
|
caps,autoplugger->sinktemplatecaps,NULL);
|
|
|
|
g_return_if_fail(autoplugger->autobin != NULL);
|
|
|
|
gst_bin_add(GST_BIN(autoplugger),autoplugger->autobin);
|
|
|
|
|
2002-03-19 04:10:13 +00:00
|
|
|
* // re-attach the srcpad's original peer to the cache *
|
2002-03-24 22:07:09 +00:00
|
|
|
* GST_DEBUG(GST_CAT_AUTOPLUG, "reconnecting the cache to the downstream peer"); *
|
2002-03-19 04:10:13 +00:00
|
|
|
* gst_pad_connect(autoplugger->cache_srcpad,autoplugger->srcpadpeer); *
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-03-19 04:10:13 +00:00
|
|
|
* attach the autoplugged bin *
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "attaching the autoplugged bin between cache and downstream peer");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_connect(autoplugger->cache_srcpad,gst_element_get_pad(autoplugger->autobin,"sink"));
|
|
|
|
gst_pad_connect(gst_element_get_pad(autoplugger->autobin,"src_00"),autoplugger->srcpadpeer);
|
|
|
|
*/
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* FIXME set the caps on the new connection
|
2002-03-24 22:07:09 +00:00
|
|
|
* GST_DEBUG(GST_CAT_AUTOPLUG,"forcing caps on the typefound pad");
|
2001-12-17 22:26:56 +00:00
|
|
|
* gst_pad_set_caps(autoplugger->cache_srcpad,caps);
|
|
|
|
* reattach the original outside srcpad
|
|
|
|
*/
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG,"re-attaching downstream peer to autoplugcache");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_pad_connect(autoplugger->cache_srcpad,autoplugger->srcpadpeer);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* now reset the autoplugcache */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "resetting the cache to send first buffer(s) again");
|
2001-06-25 01:20:11 +00:00
|
|
|
g_object_set(G_OBJECT(autoplugger->cache),"reset",TRUE,NULL);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* attach the cache_empty handler */
|
|
|
|
/* FIXME this is the wrong place, it shouldn't be done until we get successful caps nego! */
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT(autoplugger->cache),"cache_empty",
|
|
|
|
G_CALLBACK (gst_autoplugger_cache_empty), autoplugger);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
autoplugger->paused--;
|
|
|
|
if (autoplugger->paused == 0)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PLAY the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "typefind_have_type finished");
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_autoplugger_cache_first_buffer(GstElement *element,GstBuffer *buf,GstAutoplugger *autoplugger)
|
|
|
|
{
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have first buffer through cache");
|
|
|
|
autoplugger->cache_first_buffer = TRUE;
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* if there are no established caps, worry */
|
2001-05-25 21:00:07 +00:00
|
|
|
if (!autoplugger->sinkcaps) {
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG, "have no caps for the buffer, Danger Will Robinson!");
|
|
|
|
|
|
|
|
if (autoplugger->disable_nocaps) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "not dealing with lack of caps this time");
|
2001-05-25 21:00:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
autoplugger->paused++;
|
|
|
|
if (autoplugger->paused == 1)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PAUSE the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PAUSED);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* detach the srcpad */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "disconnecting cache from its downstream peer");
|
2001-05-25 21:00:07 +00:00
|
|
|
autoplugger->srcpadpeer = GST_PAD(GST_PAD_PEER(autoplugger->cache_srcpad));
|
|
|
|
gst_pad_disconnect(autoplugger->cache_srcpad,autoplugger->srcpadpeer);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* instantiate the typefind and set up the signal handlers */
|
2001-05-25 21:00:07 +00:00
|
|
|
if (!autoplugger->typefind) {
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "creating typefind and setting signal handler");
|
2001-05-25 21:00:07 +00:00
|
|
|
autoplugger->typefind = gst_elementfactory_make("typefind","unnamed_typefind");
|
|
|
|
autoplugger->typefind_sinkpad = gst_element_get_pad(autoplugger->typefind,"sink");
|
2001-08-13 19:00:13 +00:00
|
|
|
g_signal_connect (G_OBJECT(autoplugger->typefind),"have_type",
|
|
|
|
G_CALLBACK (gst_autoplugger_typefind_have_type), autoplugger);
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
2001-12-17 22:26:56 +00:00
|
|
|
/* add it to self and attach it */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "adding typefind to self and connecting to cache");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_bin_add(GST_BIN(autoplugger),autoplugger->typefind);
|
|
|
|
gst_pad_connect(autoplugger->cache_srcpad,autoplugger->typefind_sinkpad);
|
|
|
|
|
2001-12-17 22:26:56 +00:00
|
|
|
/* bring the typefind into playing state */
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG(GST_CAT_AUTOPLUG, "setting typefind state to PLAYING");
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(autoplugger->cache,GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
autoplugger->paused--;
|
|
|
|
if (autoplugger->paused == 0)
|
2001-12-17 22:26:56 +00:00
|
|
|
/* try to PLAY the whole thing */
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT_SCHED(autoplugger)->parent,GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
GST_INFO(GST_CAT_AUTOPLUG,"here we go into nothingness, hoping the typefind will return us to safety");
|
2001-12-12 12:13:38 +00:00
|
|
|
gst_scheduler_show(GST_ELEMENT_SCHED(autoplugger));
|
2001-05-25 21:00:07 +00:00
|
|
|
} else {
|
2002-03-19 04:10:13 +00:00
|
|
|
/* * attach the cache_empty handler, since the cache simply isn't needed *
|
2001-12-17 22:26:56 +00:00
|
|
|
* g_signal_connect (G_OBJECT(autoplugger->cache),"cache_empty",
|
|
|
|
* gst_autoplugger_cache_empty,autoplugger);
|
|
|
|
*/
|
2001-05-25 21:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_autoplugger_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
|
|
|
GstAutoplugger *autoplugger;
|
|
|
|
|
|
|
|
autoplugger = GST_AUTOPLUGGER (object);
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-05-25 21:00:07 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_autoplugger_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2001-05-25 21:00:07 +00:00
|
|
|
{
|
|
|
|
GstAutoplugger *autoplugger;
|
|
|
|
|
|
|
|
autoplugger = GST_AUTOPLUGGER (object);
|
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-05-25 21:00:07 +00:00
|
|
|
default:
|
2001-06-25 01:20:11 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-05-25 21:00:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
|
|
|
factory = gst_elementfactory_new ("autoplugger", GST_TYPE_AUTOPLUGGER,
|
|
|
|
&gst_autoplugger_details);
|
|
|
|
g_return_val_if_fail (factory != NULL, FALSE);
|
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
2001-05-25 21:00:07 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"autoplugger",
|
|
|
|
plugin_init
|
|
|
|
};
|
|
|
|
|