2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include "gst_private.h"
29 #include "gsttypefind.h"
31 /* #define GST_DEBUG_ENABLED */
33 GstElementDetails gst_type_find_details = {
36 "Finds the media type of a stream",
38 "Erik Walthinsen <omega@cse.ogi.edu>"
39 "Wim Taymans <wim.taymans@chello.be>",
44 /* TypeFind signals and args */
56 static void gst_type_find_class_init (GstTypeFindClass *klass);
57 static void gst_type_find_init (GstTypeFind *typefind);
59 static void gst_type_find_set_property (GObject *object, guint prop_id,
60 const GValue *value, GParamSpec *pspec);
61 static void gst_type_find_get_property (GObject *object, guint prop_id,
62 GValue *value, GParamSpec *pspec);
64 static void gst_type_find_chain (GstPad *pad, GstBuffer *buf);
66 static GstElementClass *parent_class = NULL;
67 static guint gst_type_find_signals[LAST_SIGNAL] = { 0 };
70 gst_type_find_get_type (void)
72 static GType typefind_type = 0;
75 static const GTypeInfo typefind_info = {
76 sizeof(GstTypeFindClass),
79 (GClassInitFunc)gst_type_find_class_init,
84 (GInstanceInitFunc)gst_type_find_init,
87 typefind_type = g_type_register_static (GST_TYPE_ELEMENT, "GstTypeFind", &typefind_info, 0);
93 gst_type_find_class_init (GstTypeFindClass *klass)
95 GObjectClass *gobject_class;
97 gobject_class = (GObjectClass*)klass;
99 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
101 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_CAPS,
102 g_param_spec_pointer("caps", "Caps", "Found capabilities", G_PARAM_READABLE));
104 gst_type_find_signals[HAVE_TYPE] =
105 g_signal_new ("have_type", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
106 G_STRUCT_OFFSET (GstTypeFindClass, have_type), NULL, NULL,
107 g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
110 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_type_find_set_property);
111 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_type_find_get_property);
115 gst_type_find_init (GstTypeFind *typefind)
117 typefind->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
118 gst_element_add_pad (GST_ELEMENT (typefind), typefind->sinkpad);
119 gst_pad_set_chain_function (typefind->sinkpad, gst_type_find_chain);
123 gst_type_find_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
125 GstTypeFind *typefind;
127 /* it's not null if we got it, but it might not be ours */
128 g_return_if_fail (GST_IS_TYPE_FIND (object));
130 typefind = GST_TYPE_FIND (object);
139 gst_type_find_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
141 GstTypeFind *typefind;
143 /* it's not null if we got it, but it might not be ours */
144 g_return_if_fail (GST_IS_TYPE_FIND (object));
146 typefind = GST_TYPE_FIND (object);
150 g_value_set_pointer(value, typefind->caps);
158 gst_type_find_chain (GstPad *pad, GstBuffer *buf)
160 GstTypeFind *typefind;
164 g_return_if_fail (pad != NULL);
165 g_return_if_fail (GST_IS_PAD (pad));
166 g_return_if_fail (buf != NULL);
168 typefind = GST_TYPE_FIND (GST_OBJECT_PARENT (pad));
169 GST_DEBUG (0,"got buffer of %d bytes in '%s'",
170 GST_BUFFER_SIZE (buf), GST_OBJECT_NAME (typefind));
172 type_list = (GList *) gst_type_get_list ();
176 type = (GstType *)type_list->data;
178 factories = type->factories;
181 GstTypeFactory *factory = GST_TYPE_FACTORY (factories->data);
182 GstTypeFindFunc typefindfunc = (GstTypeFindFunc)factory->typefindfunc;
185 GST_DEBUG (0,"try type (%p) :%d \"%s\" %p", factory, type->id, type->mime, typefindfunc);
186 if (typefindfunc && (caps = typefindfunc (buf, factory))) {
187 GST_DEBUG (0,"found type :%d \"%s\" \"%s\"", caps->id, type->mime,
188 gst_caps_get_name (caps));
189 typefind->caps = caps;
191 if (!gst_pad_try_set_caps (pad, caps)) {
192 g_warning ("typefind: found type but peer didn't accept it");
196 /* int oldstate = GST_STATE(typefind);*/
197 gst_object_ref (GST_OBJECT (typefind));
198 g_signal_emit (G_OBJECT (typefind), gst_type_find_signals[HAVE_TYPE], 0,
200 /* if (GST_STATE(typefind) != oldstate) {
201 GST_DEBUG(0, "state changed during signal, aborting");
202 gst_element_interrupt (GST_ELEMENT (typefind));
204 gst_object_unref (GST_OBJECT (typefind));
209 factories = g_slist_next (factories);
212 type_list = g_list_next (type_list);
215 gst_buffer_unref (buf);