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"
|
2002-07-08 19:07:30 +00:00
|
|
|
#include "gstlog.h"
|
2001-01-19 00:02:53 +00:00
|
|
|
#include "gsttypefind.h"
|
|
|
|
|
2003-01-17 20:41:04 +00:00
|
|
|
#define DEFAULT_MAX_BUFFERS 1
|
2001-01-19 00:02:53 +00:00
|
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* TypeFind signals and args */
|
|
|
|
enum {
|
|
|
|
HAVE_TYPE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_CAPS,
|
2003-01-17 20:41:04 +00:00
|
|
|
ARG_MAX_BUFFERS,
|
2001-01-19 00:02:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
static void gst_type_find_chain (GstPad *pad, GstBuffer *buf);
|
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
|
|
|
};
|
2001-06-25 01:20:11 +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));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_BUFFERS,
|
|
|
|
g_param_spec_int ("max_buffers",
|
|
|
|
"Max Buffers",
|
|
|
|
"Maximal amount of buffers before giving en error (0 == unlimited)",
|
|
|
|
0, G_MAXINT, DEFAULT_MAX_BUFFERS, G_PARAM_READWRITE));
|
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,
|
|
|
|
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
|
|
|
{
|
|
|
|
typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
|
2002-04-11 20:35:18 +00:00
|
|
|
gst_pad_set_chain_function (typefind->sinkpad, gst_type_find_chain);
|
2003-01-17 20:41:04 +00:00
|
|
|
|
|
|
|
typefind->num_buffer = 0;
|
|
|
|
typefind->max_buffers = DEFAULT_MAX_BUFFERS;
|
|
|
|
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) {
|
2003-01-17 20:41:04 +00:00
|
|
|
case ARG_MAX_BUFFERS:
|
|
|
|
typefind->max_buffers = g_value_get_int (value);
|
|
|
|
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
|
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;
|
|
|
|
case ARG_MAX_BUFFERS:
|
|
|
|
g_value_set_int (value, typefind->max_buffers);
|
2001-01-19 00:02:53 +00:00
|
|
|
break;
|
|
|
|
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-04-11 20:35:18 +00:00
|
|
|
gst_type_find_chain (GstPad *pad, GstBuffer *buf)
|
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;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
typefind = GST_TYPE_FIND (GST_OBJECT_PARENT (pad));
|
2003-01-17 20:41:04 +00:00
|
|
|
|
2002-03-24 22:07:09 +00:00
|
|
|
GST_DEBUG (0,"got buffer of %d bytes in '%s'",
|
2001-01-29 00:06:02 +00:00
|
|
|
GST_BUFFER_SIZE (buf), 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);
|
2001-08-21 20:16:48 +00:00
|
|
|
GstTypeFindFunc typefindfunc = (GstTypeFindFunc)factory->typefindfunc;
|
2001-01-19 00:02:53 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2002-10-29 17:36:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_TYPES, "try type (%p) :%d \"%s\" %p",
|
|
|
|
factory, type->id, type->mime, typefindfunc);
|
2001-08-21 20:16:48 +00:00
|
|
|
if (typefindfunc && (caps = typefindfunc (buf, factory))) {
|
2002-10-29 17:36:41 +00:00
|
|
|
GST_DEBUG (GST_CAT_TYPES, "found type: %d \"%s\" \"%s\"",
|
|
|
|
caps->id, type->mime, gst_caps_get_name (caps));
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind->caps = caps;
|
2001-05-25 21:00:07 +00:00
|
|
|
|
2002-09-10 08:52:58 +00:00
|
|
|
if (gst_pad_try_set_caps (pad, 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
|
|
|
|
2001-12-22 23:19:17 +00:00
|
|
|
{
|
|
|
|
gst_object_ref (GST_OBJECT (typefind));
|
2002-04-11 20:35:18 +00:00
|
|
|
g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE], 0,
|
2001-01-19 00:02:53 +00:00
|
|
|
typefind->caps);
|
2001-05-25 21:00:07 +00:00
|
|
|
gst_object_unref (GST_OBJECT (typefind));
|
2001-12-22 23:19:17 +00:00
|
|
|
goto end;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
typefind->num_buffer++;
|
|
|
|
|
2001-01-19 00:02:53 +00:00
|
|
|
end:
|
|
|
|
gst_buffer_unref (buf);
|
2003-01-17 20:41:04 +00:00
|
|
|
|
|
|
|
if (typefind->num_buffer >= typefind->max_buffers) {
|
|
|
|
gst_element_error (GST_ELEMENT (typefind),
|
|
|
|
"typefind could not determine type after %d buffers", typefind->num_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
typefind->num_buffer = 0;
|
|
|
|
gst_caps_unref (typefind->caps);
|
|
|
|
typefind->caps = NULL;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return ret;
|
2001-01-19 00:02:53 +00:00
|
|
|
}
|