2001-01-19 00:02:53 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gsttypefind.c:
|
|
|
|
*
|
|
|
|
* 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_private.h"
|
|
|
|
#include "gsttype.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2001-01-19 00:02:53 +00:00
|
|
|
#include "gsttypefind.h"
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
GstElementDetails gst_type_find_details = {
|
2001-01-19 00:02:53 +00:00
|
|
|
"TypeFind",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Generic",
|
2002-09-29 18:12:52 +00:00
|
|
|
"LGPL",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Finds the media type of a stream",
|
2001-01-19 00:02:53 +00:00
|
|
|
VERSION,
|
2002-10-29 17:36:41 +00:00
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>,"
|
2001-01-19 00:02:53 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
/* generic templates */
|
|
|
|
GST_PAD_TEMPLATE_FACTORY (type_find_sink_factory,
|
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
NULL
|
|
|
|
);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
/* TypeFind signals and args */
|
|
|
|
enum {
|
|
|
|
HAVE_TYPE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_CAPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-10-29 17:36:41 +00:00
|
|
|
static void gst_type_find_class_init (GstTypeFindClass *klass);
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_type_find_init (GstTypeFind *typefind);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-10-29 17:36:41 +00:00
|
|
|
static void gst_type_find_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_type_find_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
static void gst_type_find_loopfunc (GstElement *element);
|
2003-01-17 20:41:04 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_type_find_change_state (GstElement *element);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-04-11 20:35:18 +00:00
|
|
|
static guint gst_type_find_signals[LAST_SIGNAL] = { 0 };
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_get_type (void)
|
2001-03-07 21:52:56 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType typefind_type = 0;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
if (!typefind_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo typefind_info = {
|
2001-01-19 00:02:53 +00:00
|
|
|
sizeof(GstTypeFindClass),
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-04-11 20:35:18 +00:00
|
|
|
(GClassInitFunc)gst_type_find_class_init,
|
2001-06-25 01:20:11 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstTypeFind),
|
|
|
|
0,
|
2002-04-11 20:35:18 +00:00
|
|
|
(GInstanceInitFunc)gst_type_find_init,
|
2001-09-14 22:16:47 +00:00
|
|
|
NULL
|
2001-01-19 00:02:53 +00:00
|
|
|
};
|
2003-10-01 13:11:45 +00:00
|
|
|
typefind_type = g_type_register_static (GST_TYPE_ELEMENT,
|
|
|
|
"GstTypeFind",
|
|
|
|
&typefind_info, 0);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
return typefind_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_class_init (GstTypeFindClass *klass)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2003-01-17 20:41:04 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2003-01-17 20:41:04 +00:00
|
|
|
gstelement_class = (GstElementClass*)klass;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2003-01-17 20:41:04 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CAPS,
|
|
|
|
g_param_spec_pointer ("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_signals[HAVE_TYPE] =
|
2003-01-17 20:41:04 +00:00
|
|
|
g_signal_new ("have_type", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
2001-06-25 01:20:11 +00:00
|
|
|
G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
|
2003-07-24 08:59:05 +00:00
|
|
|
G_TYPE_POINTER);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_type_find_set_property);
|
|
|
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_get_property);
|
2003-01-17 20:41:04 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_type_find_change_state);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_type_find_init (GstTypeFind *typefind)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
2003-10-01 13:11:45 +00:00
|
|
|
typefind->sinkpad = gst_pad_new_from_template (
|
|
|
|
GST_PAD_TEMPLATE_GET (type_find_sink_factory), "sink");
|
2001-01-19 00:02:53 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
|
2003-01-17 20:41:04 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
gst_element_set_loop_function (GST_ELEMENT (typefind),
|
|
|
|
gst_type_find_loopfunc);
|
|
|
|
|
2003-01-17 20:41:04 +00:00
|
|
|
typefind->caps = NULL;
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2002-10-29 17:36:41 +00:00
|
|
|
gst_type_find_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
g_return_if_fail (GST_IS_TYPE_FIND (object));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = GST_TYPE_FIND (object);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-01-19 00:02:53 +00:00
|
|
|
default:
|
2003-01-17 20:41:04 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-01-19 00:02:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2002-10-29 17:36:41 +00:00
|
|
|
gst_type_find_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
g_return_if_fail (GST_IS_TYPE_FIND (object));
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = GST_TYPE_FIND (object);
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2001-01-19 00:02:53 +00:00
|
|
|
case ARG_CAPS:
|
2003-01-17 20:41:04 +00:00
|
|
|
g_value_set_pointer (value, typefind->caps);
|
|
|
|
break;
|
2001-01-19 00:02:53 +00:00
|
|
|
default:
|
2003-01-17 20:41:04 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2001-01-19 00:02:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
static void
|
2003-10-01 13:11:45 +00:00
|
|
|
gst_type_find_loopfunc (GstElement *element)
|
2001-01-19 00:02:53 +00:00
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
2003-01-17 20:41:04 +00:00
|
|
|
const GList *type_list;
|
2001-01-19 00:02:53 +00:00
|
|
|
GstType *type;
|
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
typefind = GST_TYPE_FIND (element);
|
2003-01-17 20:41:04 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
GST_DEBUG ("Started typefinding loop in '%s'",
|
|
|
|
GST_OBJECT_NAME (typefind));
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2003-01-17 20:41:04 +00:00
|
|
|
type_list = gst_type_get_list ();
|
2001-01-19 00:02:53 +00:00
|
|
|
|
|
|
|
while (type_list) {
|
2001-08-21 20:16:48 +00:00
|
|
|
GSList *factories;
|
2002-10-29 17:36:41 +00:00
|
|
|
type = (GstType *) type_list->data;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
factories = type->factories;
|
2001-01-19 00:02:53 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
while (factories) {
|
2002-04-11 20:35:18 +00:00
|
|
|
GstTypeFactory *factory = GST_TYPE_FACTORY (factories->data);
|
2003-10-01 13:11:45 +00:00
|
|
|
GstTypeFindFunc typefindfunc = (GstTypeFindFunc) factory->typefindfunc;
|
2001-01-19 00:02:53 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_TYPES, "try type (%p) :%d \"%s\" %p",
|
2002-10-29 17:36:41 +00:00
|
|
|
factory, type->id, type->mime, typefindfunc);
|
2003-10-01 13:11:45 +00:00
|
|
|
if (typefindfunc && (caps = typefindfunc (typefind->bs, factory))) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_TYPES, "found type: %d \"%s\" \"%s\"",
|
2002-10-29 17:36:41 +00:00
|
|
|
caps->id, type->mime, gst_caps_get_name (caps));
|
2003-10-01 13:11:45 +00:00
|
|
|
gst_caps_replace (&typefind->caps, caps);
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
if (gst_pad_try_set_caps (typefind->sinkpad, caps) <= 0) {
|
2002-01-13 22:22:42 +00:00
|
|
|
g_warning ("typefind: found type but peer didn't accept it");
|
|
|
|
}
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
gst_object_ref (GST_OBJECT (typefind));
|
|
|
|
g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE],
|
|
|
|
0, typefind->caps);
|
|
|
|
gst_object_unref (GST_OBJECT (typefind));
|
|
|
|
return;
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
2001-08-21 20:16:48 +00:00
|
|
|
factories = g_slist_next (factories);
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|
|
|
|
type_list = g_list_next (type_list);
|
|
|
|
}
|
2003-01-17 20:41:04 +00:00
|
|
|
|
2003-10-01 13:11:45 +00:00
|
|
|
/* if we get here, nothing worked... :'(. */
|
|
|
|
gst_element_error (GST_ELEMENT (typefind),
|
|
|
|
"media type could not be detected");
|
2003-01-17 20:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_type_find_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstTypeFind *typefind;
|
|
|
|
GstElementStateReturn ret;
|
|
|
|
|
|
|
|
typefind = GST_TYPE_FIND (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2003-10-01 13:11:45 +00:00
|
|
|
typefind->bs = gst_bytestream_new (typefind->sinkpad);
|
2003-01-17 20:41:04 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2003-10-01 13:11:45 +00:00
|
|
|
gst_bytestream_destroy (typefind->bs);
|
|
|
|
gst_caps_replace (&typefind->caps, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
2003-01-17 20:41:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return ret;
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|