2002-01-28 01:47:31 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2002 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2002 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
2002-09-12 09:19:00 +00:00
|
|
|
* gstspideridentity.c: identity element for the spider autoplugger
|
2002-01-28 01:47:31 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
#include "gstspideridentity.h"
|
|
|
|
#include "gstspider.h"
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG_CATEGORY (gst_spider_identity_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_spider_identity_debug
|
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
GstElementDetails gst_spider_identity_details = {
|
|
|
|
"SpiderIdentity",
|
2002-09-29 18:12:52 +00:00
|
|
|
"Generic",
|
|
|
|
"LGPL",
|
2003-01-09 22:59:37 +00:00
|
|
|
"Link between spider and outside elements",
|
2002-01-28 01:47:31 +00:00
|
|
|
VERSION,
|
|
|
|
"Benjamin Otte <in7y118@public.uni-hamburg.de>",
|
|
|
|
"(C) 2002",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* generic templates
|
|
|
|
* delete me when meging with spider.c
|
|
|
|
*/
|
2002-04-11 20:35:18 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (spider_src_factory,
|
2002-02-05 17:08:08 +00:00
|
|
|
"src",
|
2002-01-28 01:47:31 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_REQUEST,
|
|
|
|
NULL /* no caps */
|
|
|
|
);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (spider_sink_factory,
|
2002-02-05 17:08:08 +00:00
|
|
|
"sink",
|
2002-01-28 01:47:31 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_REQUEST,
|
|
|
|
NULL /* no caps */
|
|
|
|
);
|
|
|
|
|
|
|
|
/* SpiderIdentity signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* GObject stuff */
|
2002-02-11 08:18:09 +00:00
|
|
|
static void gst_spider_identity_class_init (GstSpiderIdentityClass *klass);
|
|
|
|
static void gst_spider_identity_init (GstSpiderIdentity *spider_identity);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
/* functions set in pads, elements and stuff */
|
2002-02-11 08:18:09 +00:00
|
|
|
static void gst_spider_identity_chain (GstPad *pad, GstBuffer *buf);
|
|
|
|
static GstElementStateReturn gst_spider_identity_change_state (GstElement *element);
|
2003-01-09 22:59:37 +00:00
|
|
|
static GstPadLinkReturn gst_spider_identity_link (GstPad *pad, GstCaps *caps);
|
2002-02-11 08:18:09 +00:00
|
|
|
static GstCaps * gst_spider_identity_getcaps (GstPad *pad, GstCaps *caps);
|
2002-01-28 01:47:31 +00:00
|
|
|
/* loop functions */
|
2002-02-11 08:18:09 +00:00
|
|
|
static void gst_spider_identity_dumb_loop (GstSpiderIdentity *ident);
|
|
|
|
static void gst_spider_identity_src_loop (GstSpiderIdentity *ident);
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_spider_identity_sink_loop_type_finding (GstSpiderIdentity *ident);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-06-08 12:51:11 +00:00
|
|
|
static gboolean gst_spider_identity_handle_src_event (GstPad *pad, GstEvent *event);
|
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
/* other functions */
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_spider_identity_start_type_finding (GstSpiderIdentity *ident);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-02-11 08:18:09 +00:00
|
|
|
static GstElementClass * parent_class = NULL;
|
2002-01-28 01:47:31 +00:00
|
|
|
/* no signals
|
|
|
|
static guint gst_spider_identity_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_spider_identity_get_type (void)
|
|
|
|
{
|
|
|
|
static GType spider_identity_type = 0;
|
|
|
|
|
|
|
|
if (!spider_identity_type) {
|
|
|
|
static const GTypeInfo spider_identity_info = {
|
|
|
|
sizeof(GstSpiderIdentityClass), NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_spider_identity_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstSpiderIdentity),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_spider_identity_init,
|
|
|
|
};
|
|
|
|
spider_identity_type = g_type_register_static (GST_TYPE_ELEMENT, "GstSpiderIdentity", &spider_identity_info, 0);
|
|
|
|
}
|
|
|
|
return spider_identity_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_spider_identity_class_init (GstSpiderIdentityClass *klass)
|
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
/* add our two pad templates */
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class, GST_PAD_TEMPLATE_GET (spider_src_factory));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class, GST_PAD_TEMPLATE_GET (spider_sink_factory));
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR(gst_spider_identity_change_state);
|
|
|
|
gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_spider_identity_request_new_pad);
|
|
|
|
}
|
2002-06-12 22:26:36 +00:00
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
static GstBufferPool*
|
|
|
|
gst_spider_identity_get_bufferpool (GstPad *pad)
|
2002-06-12 22:26:36 +00:00
|
|
|
{
|
|
|
|
GstSpiderIdentity *ident;
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-06-12 22:26:36 +00:00
|
|
|
ident = GST_SPIDER_IDENTITY (gst_pad_get_parent (pad));
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-06-12 22:26:36 +00:00
|
|
|
return gst_pad_get_bufferpool (ident->src);
|
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
static void
|
2002-02-05 17:08:08 +00:00
|
|
|
gst_spider_identity_init (GstSpiderIdentity *ident)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2002-02-05 17:08:08 +00:00
|
|
|
/* sink */
|
2002-04-11 20:35:18 +00:00
|
|
|
ident->sink = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (spider_sink_factory), "sink");
|
2002-02-05 17:08:08 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ident), ident->sink);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_pad_set_link_function (ident->sink, GST_DEBUG_FUNCPTR (gst_spider_identity_link));
|
2002-02-05 17:08:08 +00:00
|
|
|
gst_pad_set_getcaps_function (ident->sink, GST_DEBUG_FUNCPTR (gst_spider_identity_getcaps));
|
2002-06-12 22:26:36 +00:00
|
|
|
gst_pad_set_bufferpool_function (ident->sink, GST_DEBUG_FUNCPTR (gst_spider_identity_get_bufferpool));
|
2002-02-05 17:08:08 +00:00
|
|
|
/* src */
|
2002-04-11 20:35:18 +00:00
|
|
|
ident->src = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (spider_src_factory), "src");
|
2002-02-05 17:08:08 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ident), ident->src);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_pad_set_link_function (ident->src, GST_DEBUG_FUNCPTR (gst_spider_identity_link));
|
2002-02-05 17:08:08 +00:00
|
|
|
gst_pad_set_getcaps_function (ident->src, GST_DEBUG_FUNCPTR (gst_spider_identity_getcaps));
|
2002-06-08 12:51:11 +00:00
|
|
|
gst_pad_set_event_function (ident->src, GST_DEBUG_FUNCPTR (gst_spider_identity_handle_src_event));
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
/* variables */
|
2002-02-05 17:08:08 +00:00
|
|
|
ident->plugged = FALSE;
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_spider_identity_chain (GstPad *pad, GstBuffer *buf)
|
|
|
|
{
|
|
|
|
GstSpiderIdentity *ident;
|
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
/*g_print ("chaining on pad %s:%s with buffer %p\n", GST_DEBUG_PAD_NAME (pad), buf);*/
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
if (buf == NULL) return;
|
|
|
|
|
|
|
|
ident = GST_SPIDER_IDENTITY (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (GST_IS_EVENT (buf)) {
|
2002-02-11 08:18:09 +00:00
|
|
|
/* start hack for current event stuff here */
|
2003-01-09 14:15:37 +00:00
|
|
|
/* check for unlinked elements and send them the EOS event, too */
|
2002-02-11 08:18:09 +00:00
|
|
|
if (GST_EVENT_TYPE (GST_EVENT (buf)) == GST_EVENT_EOS)
|
|
|
|
{
|
|
|
|
GstSpider *spider = (GstSpider *) GST_OBJECT_PARENT (ident);
|
2003-01-09 14:15:37 +00:00
|
|
|
GList *list = spider->links;
|
2002-02-11 08:18:09 +00:00
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
GstSpiderConnection *conn = (GstSpiderConnection *) list->data;
|
|
|
|
list = g_list_next (list);
|
2003-03-18 00:39:34 +00:00
|
|
|
if (conn->current != (GstElement *) conn->src) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ("sending EOS to unconnected element %s from %s",
|
2003-03-18 00:39:34 +00:00
|
|
|
GST_ELEMENT_NAME (conn->src), GST_ELEMENT_NAME (ident));
|
|
|
|
gst_pad_push (conn->src->src, GST_BUFFER (gst_event_new (GST_EVENT_EOS)));
|
2003-04-11 00:00:46 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (conn->src));
|
2003-03-18 00:39:34 +00:00
|
|
|
}
|
2002-02-11 08:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* end hack for current event stuff here */
|
|
|
|
|
2003-05-17 17:08:58 +00:00
|
|
|
gst_pad_event_default (pad, GST_EVENT (buf));
|
2002-01-30 21:54:06 +00:00
|
|
|
return;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ident->src != NULL) && (GST_PAD_PEER (ident->src) != NULL)) {
|
|
|
|
/* g_print("pushing buffer %p (refcount %d - buffersize %d) to pad %s:%s\n", buf, GST_BUFFER_REFCOUNT (buf), GST_BUFFER_SIZE (buf), GST_DEBUG_PAD_NAME (ident->src)); */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_LOG ( "push %p %" G_GINT64_FORMAT, buf, GST_BUFFER_OFFSET (buf));
|
2002-01-28 01:47:31 +00:00
|
|
|
gst_pad_push (ident->src, buf);
|
|
|
|
} else if (GST_IS_BUFFER (buf)) {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GstSpiderIdentity*
|
|
|
|
gst_spider_identity_new_src (gchar *name)
|
|
|
|
{
|
2002-09-12 18:49:22 +00:00
|
|
|
GstSpiderIdentity *ret = (GstSpiderIdentity *) gst_element_factory_make ("spideridentity", name);
|
2002-01-28 01:47:31 +00:00
|
|
|
/* set the right functions */
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ret), (GstElementLoopFunction) GST_DEBUG_FUNCPTR (gst_spider_identity_src_loop));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
GstSpiderIdentity*
|
|
|
|
gst_spider_identity_new_sink (gchar *name)
|
|
|
|
{
|
2002-09-12 18:49:22 +00:00
|
|
|
GstSpiderIdentity *ret = (GstSpiderIdentity *) gst_element_factory_make ("spideridentity", name);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-02-05 17:08:08 +00:00
|
|
|
/* set the right functions */
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ret), (GstElementLoopFunction) GST_DEBUG_FUNCPTR (gst_spider_identity_dumb_loop));
|
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
/* shamelessly stolen from gstqueue.c to get proxy links */
|
2003-01-09 22:59:37 +00:00
|
|
|
static GstPadLinkReturn
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_spider_identity_link (GstPad *pad, GstCaps *caps)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
|
|
|
GstSpiderIdentity *spider_identity = GST_SPIDER_IDENTITY (gst_pad_get_parent (pad));
|
|
|
|
GstPad *otherpad;
|
|
|
|
|
|
|
|
if (pad == spider_identity->src)
|
|
|
|
otherpad = spider_identity->sink;
|
|
|
|
else
|
|
|
|
otherpad = spider_identity->src;
|
|
|
|
|
|
|
|
if (otherpad != NULL)
|
2003-01-09 14:15:37 +00:00
|
|
|
return gst_pad_proxy_link (otherpad, caps);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2003-01-09 20:02:34 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps*
|
|
|
|
gst_spider_identity_getcaps (GstPad *pad, GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstSpiderIdentity *spider_identity = GST_SPIDER_IDENTITY (gst_pad_get_parent (pad));
|
|
|
|
GstPad *otherpad;
|
|
|
|
|
|
|
|
if (pad == spider_identity->src)
|
|
|
|
otherpad = spider_identity->sink;
|
|
|
|
else
|
|
|
|
otherpad = spider_identity->src;
|
|
|
|
|
|
|
|
if (otherpad != NULL)
|
|
|
|
return gst_pad_get_allowed_caps (otherpad);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPad*
|
|
|
|
gst_spider_identity_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *name)
|
|
|
|
{
|
|
|
|
GstSpiderIdentity *ident;
|
|
|
|
|
|
|
|
/*checks */
|
|
|
|
g_return_val_if_fail (templ != NULL, NULL);
|
2002-04-11 20:35:18 +00:00
|
|
|
g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
|
2002-01-28 01:47:31 +00:00
|
|
|
ident = GST_SPIDER_IDENTITY (element);
|
|
|
|
g_return_val_if_fail (ident != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_SPIDER_IDENTITY (ident), NULL);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
switch (GST_PAD_TEMPLATE_DIRECTION (templ))
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
|
|
|
case GST_PAD_SINK:
|
|
|
|
if (ident->sink != NULL) break;
|
|
|
|
/* sink */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ( "element %s requests new sink pad", GST_ELEMENT_NAME(ident));
|
2002-01-28 01:47:31 +00:00
|
|
|
ident->sink = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ident), ident->sink);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_pad_set_link_function (ident->sink, GST_DEBUG_FUNCPTR (gst_spider_identity_link));
|
2002-01-28 01:47:31 +00:00
|
|
|
gst_pad_set_getcaps_function (ident->sink, GST_DEBUG_FUNCPTR (gst_spider_identity_getcaps));
|
2002-06-12 22:26:36 +00:00
|
|
|
gst_pad_set_bufferpool_function (ident->sink, GST_DEBUG_FUNCPTR (gst_spider_identity_get_bufferpool));
|
2002-01-28 01:47:31 +00:00
|
|
|
return ident->sink;
|
|
|
|
case GST_PAD_SRC:
|
|
|
|
/* src */
|
|
|
|
if (ident->src != NULL) break;
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ( "element %s requests new src pad", GST_ELEMENT_NAME(ident));
|
2002-01-28 01:47:31 +00:00
|
|
|
ident->src = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ident), ident->src);
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_pad_set_link_function (ident->src, GST_DEBUG_FUNCPTR (gst_spider_identity_link));
|
2002-01-28 01:47:31 +00:00
|
|
|
gst_pad_set_getcaps_function (ident->src, GST_DEBUG_FUNCPTR (gst_spider_identity_getcaps));
|
2002-06-08 12:51:11 +00:00
|
|
|
gst_pad_set_event_function (ident->src, GST_DEBUG_FUNCPTR (gst_spider_identity_handle_src_event));
|
2002-01-28 01:47:31 +00:00
|
|
|
return ident->src;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ( "element %s requested a new pad but none could be created", GST_ELEMENT_NAME(ident));
|
2002-01-28 01:47:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function has to
|
|
|
|
* - start the autoplugger
|
|
|
|
* - start type finding
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_spider_identity_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstSpiderIdentity *ident;
|
|
|
|
GstSpider *spider;
|
|
|
|
GstElementStateReturn ret = GST_STATE_SUCCESS;
|
|
|
|
|
|
|
|
/* element check */
|
|
|
|
ident = GST_SPIDER_IDENTITY (element);
|
2002-06-07 19:41:35 +00:00
|
|
|
g_return_val_if_fail (ident != NULL, GST_STATE_FAILURE);
|
|
|
|
g_return_val_if_fail (GST_IS_SPIDER_IDENTITY (ident), GST_STATE_FAILURE);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2002-06-07 19:41:35 +00:00
|
|
|
/* autoplugger check */
|
|
|
|
spider = GST_SPIDER (GST_ELEMENT_PARENT (ident));
|
|
|
|
g_return_val_if_fail (spider != NULL, GST_STATE_FAILURE);
|
|
|
|
g_return_val_if_fail (GST_IS_SPIDER (spider), GST_STATE_FAILURE);
|
|
|
|
|
2002-01-28 01:47:31 +00:00
|
|
|
/* start typefinding or plugging */
|
2002-02-05 17:08:08 +00:00
|
|
|
if ((GST_RPAD_PEER (ident->sink) != NULL) && (GST_RPAD_PEER (ident->src) == NULL))
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
|
|
|
if (gst_pad_get_caps ((GstPad *) GST_PAD_PEER (ident->sink)) == NULL)
|
|
|
|
{
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_spider_identity_start_type_finding (ident);
|
2002-01-28 01:47:31 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2002-02-11 08:18:09 +00:00
|
|
|
gst_spider_identity_plug (ident);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* autoplug on src */
|
2002-02-05 17:08:08 +00:00
|
|
|
if ((GST_RPAD_PEER (ident->src) != NULL) && (GST_RPAD_PEER (ident->sink) == NULL))
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2002-02-11 08:18:09 +00:00
|
|
|
gst_spider_identity_plug (ident);
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret != GST_STATE_FAILURE) && (GST_ELEMENT_CLASS (parent_class)->change_state))
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_spider_identity_start_type_finding (GstSpiderIdentity *ident)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2002-12-01 01:37:58 +00:00
|
|
|
/* GstElement* typefind;
|
|
|
|
gchar *name;*/
|
2002-03-02 18:27:45 +00:00
|
|
|
gboolean restart = FALSE;
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ("element %s starts typefinding", GST_ELEMENT_NAME(ident));
|
2002-03-02 18:27:45 +00:00
|
|
|
if (GST_STATE (GST_ELEMENT_PARENT (ident)) == GST_STATE_PLAYING)
|
|
|
|
{
|
|
|
|
gst_element_set_state (GST_ELEMENT (GST_ELEMENT_PARENT (ident)), GST_STATE_PAUSED);
|
|
|
|
restart = TRUE;
|
|
|
|
}
|
2002-12-01 01:37:58 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ident), (GstElementLoopFunction) GST_DEBUG_FUNCPTR (gst_spider_identity_sink_loop_type_finding));
|
2002-03-02 18:27:45 +00:00
|
|
|
|
|
|
|
if (restart)
|
|
|
|
{
|
|
|
|
gst_element_set_state (GST_ELEMENT (GST_ELEMENT_PARENT (ident)), GST_STATE_PLAYING);
|
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* since we can't set the loop function to NULL if there's a cothread for us,
|
|
|
|
* we have to use a dumb one
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_spider_identity_dumb_loop (GstSpiderIdentity *ident)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
g_return_if_fail (ident != NULL);
|
|
|
|
g_return_if_fail (GST_IS_SPIDER_IDENTITY (ident));
|
|
|
|
g_assert (ident->sink != NULL);
|
|
|
|
|
|
|
|
buf = gst_pad_pull (ident->sink);
|
|
|
|
|
|
|
|
gst_spider_identity_chain (ident->sink, buf);
|
|
|
|
}
|
2003-01-09 14:15:37 +00:00
|
|
|
/* do nothing until we're linked - then disable yourself
|
2002-01-28 01:47:31 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
gst_spider_identity_src_loop (GstSpiderIdentity *ident)
|
|
|
|
{
|
|
|
|
/* checks - disable for speed */
|
|
|
|
g_return_if_fail (ident != NULL);
|
|
|
|
g_return_if_fail (GST_IS_SPIDER_IDENTITY (ident));
|
|
|
|
|
|
|
|
/* we don't want a loop function if we're plugged */
|
|
|
|
if (ident->sink && GST_PAD_PEER (ident->sink))
|
|
|
|
{
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ident), (GstElementLoopFunction) GST_DEBUG_FUNCPTR (gst_spider_identity_dumb_loop));
|
|
|
|
gst_spider_identity_dumb_loop (ident);
|
|
|
|
return;
|
|
|
|
}
|
2003-01-12 20:28:08 +00:00
|
|
|
gst_element_interrupt (GST_ELEMENT (ident));
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
/* This loop function is only needed when typefinding.
|
|
|
|
*/
|
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_spider_identity_sink_loop_type_finding (GstSpiderIdentity *ident)
|
2002-01-28 01:47:31 +00:00
|
|
|
{
|
2002-12-01 18:32:34 +00:00
|
|
|
GstBuffer *buf=NULL;
|
2002-12-01 01:37:58 +00:00
|
|
|
GstBuffer *typefindbuf = NULL;
|
|
|
|
gboolean getmorebuf = TRUE;
|
|
|
|
GList *type_list;
|
2003-04-08 08:02:36 +00:00
|
|
|
GstCaps *caps;
|
2002-12-01 01:37:58 +00:00
|
|
|
|
|
|
|
/* this should possibly be a property */
|
|
|
|
guint bufsizelimit = 4096;
|
2002-01-28 01:47:31 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_SPIDER_IDENTITY (ident));
|
2003-04-08 08:02:36 +00:00
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
while (getmorebuf){
|
|
|
|
|
|
|
|
/* check if our buffer is big enough to do a typefind */
|
|
|
|
if (typefindbuf && GST_BUFFER_SIZE(typefindbuf) >= bufsizelimit){
|
|
|
|
getmorebuf = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-30 04:33:01 +00:00
|
|
|
buf = gst_pad_pull (ident->sink);
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
/* if it's an event... */
|
|
|
|
while (GST_IS_EVENT (buf)) {
|
|
|
|
switch (GST_EVENT_TYPE (GST_EVENT (buf))){
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
getmorebuf = FALSE;
|
|
|
|
/* FIXME Notify the srcs that EOS has happened */
|
|
|
|
gst_pad_event_default (ident->sink, GST_EVENT (buf));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (ident->sink, GST_EVENT (buf));
|
|
|
|
buf = gst_pad_pull (ident->sink);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* handle DISCONT events, please */
|
|
|
|
}
|
2002-10-25 23:24:56 +00:00
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
typefindbuf = buf;
|
|
|
|
getmorebuf = FALSE;
|
|
|
|
/* FIXME merging doesn't work for some reason so
|
|
|
|
* we'll just typefind with the first element
|
|
|
|
if (!typefindbuf){
|
|
|
|
typefindbuf = buf;
|
|
|
|
gst_buffer_ref(buf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GstBuffer *oldbuf = typefindbuf;
|
|
|
|
typefindbuf = gst_buffer_merge(typefindbuf, buf);
|
|
|
|
gst_buffer_unref(oldbuf);
|
|
|
|
gst_buffer_unref(buf);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
if (!typefindbuf){
|
|
|
|
goto end;
|
|
|
|
}
|
2002-10-25 23:24:56 +00:00
|
|
|
|
2003-04-08 08:02:36 +00:00
|
|
|
/* maybe there are already valid caps now? */
|
|
|
|
if ((caps = gst_pad_get_caps (ident->sink)) != NULL) {
|
|
|
|
goto plug;
|
|
|
|
}
|
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
/* now do the actual typefinding with the supplied buffer */
|
|
|
|
type_list = (GList *) gst_type_get_list ();
|
2002-01-28 01:47:31 +00:00
|
|
|
|
2002-12-01 01:37:58 +00:00
|
|
|
while (type_list) {
|
|
|
|
GstType *type = (GstType *) type_list->data;
|
|
|
|
GSList *factories = type->factories;
|
|
|
|
|
|
|
|
while (factories) {
|
|
|
|
GstTypeFactory *factory = GST_TYPE_FACTORY (factories->data);
|
|
|
|
GstTypeFindFunc typefindfunc = (GstTypeFindFunc)factory->typefindfunc;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ("trying typefind function %s", GST_PLUGIN_FEATURE_NAME (factory));
|
2002-12-01 01:37:58 +00:00
|
|
|
if (typefindfunc && (caps = typefindfunc (buf, factory))) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_INFO ("typefind function %s found caps", GST_PLUGIN_FEATURE_NAME (factory));
|
2003-05-06 23:47:07 +00:00
|
|
|
if (gst_pad_try_set_caps (ident->src, caps) <= 0) {
|
2002-12-01 01:37:58 +00:00
|
|
|
g_warning ("typefind: found type but peer didn't accept it");
|
2003-04-08 08:02:36 +00:00
|
|
|
gst_caps_sink (caps);
|
|
|
|
} else {
|
|
|
|
goto plug;
|
2002-12-01 01:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
factories = g_slist_next (factories);
|
|
|
|
}
|
|
|
|
type_list = g_list_next (type_list);
|
|
|
|
}
|
|
|
|
gst_element_error(GST_ELEMENT(ident), "Could not find media type", NULL);
|
|
|
|
gst_buffer_unref(buf);
|
|
|
|
buf = GST_BUFFER (gst_event_new (GST_EVENT_EOS));
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
/* remove loop function */
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ident),
|
|
|
|
(GstElementLoopFunction) GST_DEBUG_FUNCPTR (gst_spider_identity_dumb_loop));
|
|
|
|
|
|
|
|
/* push the buffer */
|
|
|
|
gst_spider_identity_chain (ident->sink, buf);
|
2003-04-08 08:02:36 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
plug:
|
|
|
|
|
|
|
|
gst_caps_debug (caps, "spider starting caps");
|
|
|
|
gst_caps_sink (caps);
|
2003-04-11 00:00:46 +00:00
|
|
|
|
2003-04-08 08:02:36 +00:00
|
|
|
gst_spider_identity_plug (ident);
|
|
|
|
|
|
|
|
goto end;
|
2002-01-28 01:47:31 +00:00
|
|
|
}
|
|
|
|
|
2002-06-08 12:51:11 +00:00
|
|
|
static gboolean
|
|
|
|
gst_spider_identity_handle_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSpiderIdentity *ident;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ( "spider_identity src_event");
|
2002-06-08 12:51:11 +00:00
|
|
|
|
|
|
|
ident = GST_SPIDER_IDENTITY (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH:
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
default:
|
2002-06-08 14:58:03 +00:00
|
|
|
res = gst_pad_event_default (pad, event);
|
2002-06-08 12:51:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|