2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gststreaminfo.h"
28 GST_DEBUG_CATEGORY_STATIC (gst_streaminfo_debug);
29 #define GST_CAT_DEFAULT gst_streaminfo_debug
51 static guint gst_stream_info_signals[LAST_SIGNAL] = { 0 };
53 #define GST_TYPE_STREAM_TYPE (gst_stream_type_get_type())
55 gst_stream_type_get_type (void)
57 static GType stream_type_type = 0;
58 static const GEnumValue stream_type[] = {
59 {GST_STREAM_TYPE_UNKNOWN, "Unknown stream", "unknown"},
60 {GST_STREAM_TYPE_AUDIO, "Audio stream", "audio"},
61 {GST_STREAM_TYPE_VIDEO, "Video stream", "video"},
62 {GST_STREAM_TYPE_TEXT, "Text stream", "text"},
63 {GST_STREAM_TYPE_SUBPICTURE, "Subpicture stream", "subpicture"},
64 {GST_STREAM_TYPE_ELEMENT,
65 "Stream handled by element", "element"},
69 if (!stream_type_type) {
70 stream_type_type = g_enum_register_static ("GstStreamType", stream_type);
72 return stream_type_type;
75 static void gst_stream_info_class_init (GstStreamInfoClass * klass);
76 static void gst_stream_info_init (GstStreamInfo * stream_info);
77 static void gst_stream_info_dispose (GObject * object);
79 static void stream_info_change_state (GstElement * element,
80 gint old_state, gint new_state, gpointer data);
82 static void gst_stream_info_set_property (GObject * object, guint prop_id,
83 const GValue * value, GParamSpec * spec);
84 static void gst_stream_info_get_property (GObject * object, guint prop_id,
85 GValue * value, GParamSpec * spec);
87 static GObjectClass *parent_class;
89 //static guint gst_stream_info_signals[LAST_SIGNAL] = { 0 };
92 gst_stream_info_get_type (void)
94 static GType gst_stream_info_type = 0;
96 if (!gst_stream_info_type) {
97 static const GTypeInfo gst_stream_info_info = {
98 sizeof (GstStreamInfoClass),
101 (GClassInitFunc) gst_stream_info_class_init,
104 sizeof (GstStreamInfo),
106 (GInstanceInitFunc) gst_stream_info_init,
109 gst_stream_info_type = g_type_register_static (G_TYPE_OBJECT,
110 "GstStreamInfo", &gst_stream_info_info, 0);
113 return gst_stream_info_type;
117 gst_stream_info_class_init (GstStreamInfoClass * klass)
119 GObjectClass *gobject_klass;
121 gobject_klass = (GObjectClass *) klass;
123 parent_class = g_type_class_peek_parent (klass);
125 gobject_klass->set_property = gst_stream_info_set_property;
126 gobject_klass->get_property = gst_stream_info_get_property;
128 g_object_class_install_property (gobject_klass, ARG_PAD,
129 g_param_spec_object ("object", "object",
130 "Source Pad or object of the stream", GST_TYPE_OBJECT,
131 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
132 g_object_class_install_property (gobject_klass, ARG_TYPE,
133 g_param_spec_enum ("type", "Type", "Type of the stream",
134 GST_TYPE_STREAM_TYPE, GST_STREAM_TYPE_UNKNOWN,
135 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
136 g_object_class_install_property (gobject_klass, ARG_DECODER,
137 g_param_spec_string ("decoder", "Decoder",
138 "The decoder used to decode the stream", NULL,
139 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
140 g_object_class_install_property (gobject_klass, ARG_MUTE,
141 g_param_spec_boolean ("mute", "Mute", "Mute or unmute this stream", FALSE,
142 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
143 g_object_class_install_property (gobject_klass, ARG_CAPS,
144 g_param_spec_boxed ("caps", "Capabilities",
145 "Capabilities (or type) of this stream", GST_TYPE_CAPS,
146 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
147 g_object_class_install_property (gobject_klass, ARG_LANG_CODE,
148 g_param_spec_string ("language-code", "Language code",
149 "Language code for this stream, conforming to ISO-639-1", NULL,
150 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
151 g_object_class_install_property (gobject_klass, ARG_CODEC,
152 g_param_spec_string ("codec", "Codec", "Codec used to encode the stream",
153 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
155 gst_stream_info_signals[SIGNAL_MUTED] =
156 g_signal_new ("muted", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
157 G_STRUCT_OFFSET (GstStreamInfoClass, muted), NULL, NULL,
158 gst_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
160 gobject_klass->dispose = gst_stream_info_dispose;
162 GST_DEBUG_CATEGORY_INIT (gst_streaminfo_debug, "streaminfo", 0,
163 "Playbin Stream Info");
168 gst_stream_info_init (GstStreamInfo * stream_info)
170 stream_info->object = NULL;
171 stream_info->origin = NULL;
172 stream_info->type = GST_STREAM_TYPE_UNKNOWN;
173 stream_info->decoder = NULL;
174 stream_info->mute = FALSE;
175 stream_info->caps = NULL;
179 cb_probe (GstPad * pad, GstEvent * e, gpointer user_data)
181 GstStreamInfo *info = user_data;
183 if (GST_EVENT_TYPE (e) == GST_EVENT_TAG) {
187 gst_event_parse_tag (e, &list);
189 if (info->type != GST_STREAM_TYPE_AUDIO &&
190 gst_tag_list_get_string (list, GST_TAG_VIDEO_CODEC, &codec)) {
191 g_free (info->codec);
193 GST_LOG_OBJECT (pad, "codec = %s (video)", codec);
194 g_object_notify (G_OBJECT (info), "codec");
195 } else if (info->type != GST_STREAM_TYPE_VIDEO &&
196 gst_tag_list_get_string (list, GST_TAG_AUDIO_CODEC, &codec)) {
197 g_free (info->codec);
199 GST_LOG_OBJECT (pad, "codec = %s (audio)", codec);
200 g_object_notify (G_OBJECT (info), "codec");
201 } else if (gst_tag_list_get_string (list, GST_TAG_CODEC, &codec)) {
202 g_free (info->codec);
204 GST_LOG_OBJECT (pad, "codec = %s (generic)", codec);
205 g_object_notify (G_OBJECT (info), "codec");
207 if (gst_tag_list_get_string (list, GST_TAG_LANGUAGE_CODE, &lang)) {
208 g_free (info->langcode);
209 info->langcode = lang;
210 GST_LOG_OBJECT (pad, "language-code = %s", lang);
211 g_object_notify (G_OBJECT (info), "language-code");
219 gst_stream_info_new (GstObject * object,
220 GstStreamType type, const gchar * decoder, const GstCaps * caps)
224 info = g_object_new (GST_TYPE_STREAM_INFO, NULL);
226 gst_object_ref (object);
227 if (GST_IS_PAD (object)) {
228 gst_pad_add_event_probe (GST_PAD_CAST (object),
229 G_CALLBACK (cb_probe), info);
231 info->object = object;
233 info->decoder = g_strdup (decoder);
234 info->origin = object;
236 info->caps = gst_caps_copy (caps);
243 gst_stream_info_dispose (GObject * object)
245 GstStreamInfo *stream_info;
247 stream_info = GST_STREAM_INFO (object);
249 if (stream_info->object) {
252 parent = gst_pad_get_parent_element ((GstPad *)
253 GST_PAD_CAST (stream_info->object));
254 if (parent != NULL) {
255 g_signal_handlers_disconnect_by_func (parent,
256 (gpointer) stream_info_change_state, stream_info);
257 gst_object_unref (parent);
260 gst_object_unref (stream_info->object);
261 stream_info->object = NULL;
263 stream_info->origin = NULL;
264 stream_info->type = GST_STREAM_TYPE_UNKNOWN;
265 g_free (stream_info->decoder);
266 stream_info->decoder = NULL;
267 g_free (stream_info->langcode);
268 stream_info->langcode = NULL;
269 g_free (stream_info->codec);
270 stream_info->codec = NULL;
271 if (stream_info->caps) {
272 gst_caps_unref (stream_info->caps);
273 stream_info->caps = NULL;
276 if (G_OBJECT_CLASS (parent_class)->dispose) {
277 G_OBJECT_CLASS (parent_class)->dispose (object);
282 stream_info_change_state (GstElement * element,
283 gint old_state, gint new_state, gpointer data)
285 GstStreamInfo *stream_info = data;
287 if (new_state == GST_STATE_PLAYING) {
288 /* state change will annoy us */
289 g_return_if_fail (stream_info->mute == TRUE);
290 GST_DEBUG_OBJECT (stream_info, "Re-muting pads after state-change");
291 //gst_pad_set_active_recursive (GST_PAD (stream_info->object), FALSE);
297 gst_stream_info_set_mute (GstStreamInfo * stream_info, gboolean mute)
299 g_return_val_if_fail (GST_IS_STREAM_INFO (stream_info), FALSE);
301 if (stream_info->type == GST_STREAM_TYPE_ELEMENT) {
302 g_warning ("cannot mute element stream");
306 if (mute != stream_info->mute) {
307 /* nothing really happens here. it looks like gstplaybasebin installs a
308 * buffer probe hat drops buffers when muting. but the this removes it self
312 stream_info->mute = mute;
314 gst_pad_set_active ((GstPad *) GST_PAD_CAST (stream_info->object), !mute);
320 element = gst_pad_get_parent_element ((GstPad *)
321 GST_PAD_CAST (stream_info->object));
324 g_signal_connect (element, "state-changed",
325 G_CALLBACK (stream_info_change_state), stream_info);
327 g_signal_handlers_disconnect_by_func (element,
328 G_CALLBACK (stream_info_change_state), stream_info);
330 gst_object_unref (element);
339 gst_stream_info_is_mute (GstStreamInfo * stream_info)
341 g_return_val_if_fail (GST_IS_STREAM_INFO (stream_info), TRUE);
343 return stream_info->mute;
347 gst_stream_info_set_property (GObject * object, guint prop_id,
348 const GValue * value, GParamSpec * pspec)
350 GstStreamInfo *stream_info;
352 g_return_if_fail (GST_IS_STREAM_INFO (object));
354 stream_info = GST_STREAM_INFO (object);
358 gst_stream_info_set_mute (stream_info, g_value_get_boolean (value));
361 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
367 gst_stream_info_get_property (GObject * object, guint prop_id, GValue * value,
370 GstStreamInfo *stream_info;
372 g_return_if_fail (GST_IS_STREAM_INFO (object));
374 stream_info = GST_STREAM_INFO (object);
378 g_value_set_object (value, stream_info->object);
381 g_value_set_enum (value, stream_info->type);
384 g_value_set_string (value, stream_info->decoder);
387 g_value_set_boolean (value, stream_info->mute);
390 g_value_set_boxed (value, stream_info->caps);
393 g_value_set_string (value, stream_info->langcode);
396 g_value_set_string (value, stream_info->codec);
399 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);