From 0207f453bbe5f2446cc0134c1e985ad7a35fdb3c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 31 Dec 2002 17:03:29 +0000 Subject: [PATCH] Cleanups Original commit message from CVS: Cleanups Add streaminfo --- ext/a52dec/gsta52dec.c | 43 +++++++++++++++++++++++++++++++++++------- ext/a52dec/gsta52dec.h | 39 +++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/ext/a52dec/gsta52dec.c b/ext/a52dec/gsta52dec.c index 56418596ca..21df094377 100644 --- a/ext/a52dec/gsta52dec.c +++ b/ext/a52dec/gsta52dec.c @@ -48,7 +48,8 @@ enum enum { ARG_0, - ARG_DRC + ARG_DRC, + ARG_STREAMINFO }; /* @@ -138,6 +139,9 @@ gst_a52dec_class_init (GstA52DecClass * klass) g_param_spec_boolean ("drc", "Dynamic Range Compression", "Use Dynamic Range Compression", FALSE, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, ARG_STREAMINFO, + g_param_spec_boxed ("streaminfo", "Streaminfo", "Streaminfo", + GST_TYPE_CAPS, G_PARAM_READABLE)); gobject_class->set_property = gst_a52dec_set_property; gobject_class->get_property = gst_a52dec_get_property; @@ -157,6 +161,7 @@ gst_a52dec_init (GstA52Dec * a52dec) gst_element_add_pad (GST_ELEMENT (a52dec), a52dec->srcpad); a52dec->dynamic_range_compression = FALSE; + a52dec->streaminfo = NULL; } /* BEGIN modified a52dec conversion code */ @@ -294,7 +299,7 @@ gst_a52dec_channels (int flags) break; default: /* error */ - fprintf (stderr, "a52dec invalid flags?"); + g_warning ("a52dec invalid flags %d", flags); return 0; } return chans; @@ -379,6 +384,25 @@ gst_a52dec_handle_event (GstA52Dec *a52dec) } } +static void +gst_a52dec_update_streaminfo (GstA52Dec *a52dec) +{ + GstProps *props; + GstPropsEntry *entry; + + props = gst_props_empty_new (); + + entry = gst_props_entry_new ("bitrate", GST_PROPS_INT (a52dec->bit_rate)); + gst_props_add_entry (props, (GstPropsEntry *) entry); + + gst_caps_unref (a52dec->streaminfo); + + a52dec->streaminfo = gst_caps_new ("a52dec_streaminfo", + "application/x-gst-streaminfo", + props); + g_object_notify (G_OBJECT (a52dec), "streaminfo"); +} + static void gst_a52dec_loop (GstElement *element) { @@ -421,8 +445,10 @@ gst_a52dec_loop (GstElement *element) a52dec->stream_channels = flags & A52_CHANNEL_MASK; - /* FIXME: perhaps this change should be announced? */ - a52dec->bit_rate = bit_rate; + if (bit_rate != a52dec->bit_rate) { + a52dec->bit_rate = bit_rate; + gst_a52dec_update_streaminfo (a52dec); + } /* read the header + rest of frame */ got_bytes = gst_bytestream_read (a52dec->bs, &buf, length); @@ -438,7 +464,7 @@ gst_a52dec_loop (GstElement *element) a52dec->level = 1; if (a52_frame (a52dec->state, data, &flags, &a52dec->level, a52dec->bias)) { - fprintf (stderr, "a52dec a52_frame error\n"); + g_warning ("a52dec: a52_frame error\n"); goto end; } @@ -450,7 +476,7 @@ gst_a52dec_loop (GstElement *element) } if (need_reneg == TRUE) { - fprintf (stderr, "a52dec reneg: sample_rate:%d stream_chans:%d using_chans:%d\n", + GST_DEBUG (0, "a52dec reneg: sample_rate:%d stream_chans:%d using_chans:%d\n", a52dec->sample_rate, a52dec->stream_channels, a52dec->using_channels); gst_a52dec_reneg (a52dec->srcpad, gst_a52dec_channels (a52dec->using_channels), a52dec->sample_rate); @@ -472,7 +498,6 @@ gst_a52dec_loop (GstElement *element) } end: - /* FIXME, this is a possible leak */ gst_buffer_unref (buf); } @@ -507,6 +532,7 @@ gst_a52dec_change_state (GstElement * element) a52dec->samples = NULL; a52_free (a52dec->state); a52dec->state = NULL; + gst_caps_unref (a52dec->streaminfo); break; case GST_STATE_READY_TO_NULL: break; @@ -552,6 +578,9 @@ gst_a52dec_get_property (GObject * object, guint prop_id, GValue * value, GParam case ARG_DRC: g_value_set_boolean (value, src->dynamic_range_compression); break; + case ARG_STREAMINFO: + g_value_set_boxed (value, src->streaminfo); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/ext/a52dec/gsta52dec.h b/ext/a52dec/gsta52dec.h index 122121cafd..b1162c6bc8 100644 --- a/ext/a52dec/gsta52dec.h +++ b/ext/a52dec/gsta52dec.h @@ -25,16 +25,14 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +G_BEGIN_DECLS #define GST_TYPE_A52DEC \ (gst_a52dec_get_type()) #define GST_A52DEC(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_A52DEC,GstA52Dec)) #define GST_A52DEC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_A52DEC,GstA52Dec)) + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_A52DEC,GstA52DecClass)) #define GST_IS_A52DEC(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_A52DEC)) #define GST_IS_A52DEC_CLASS(obj) \ @@ -44,29 +42,32 @@ typedef struct _GstA52Dec GstA52Dec; typedef struct _GstA52DecClass GstA52DecClass; struct _GstA52Dec { - GstElement element; + GstElement element; /* pads */ - GstPad *sinkpad,*srcpad; - int bit_rate; - int sample_rate; - int stream_channels; - int request_channels; - int using_channels; - sample_t level; - sample_t bias; - gboolean dynamic_range_compression; - sample_t *samples; - a52_state_t *state; + GstPad *sinkpad, + *srcpad; + int bit_rate; + int sample_rate; + int stream_channels; + int request_channels; + int using_channels; + + sample_t level; + sample_t bias; + gboolean dynamic_range_compression; + sample_t *samples; + a52_state_t *state; + GstByteStream *bs; + + GstCaps *streaminfo; }; struct _GstA52DecClass { GstElementClass parent_class; }; -#ifdef __cplusplus -} -#endif /* __cplusplus */ +G_END_DECLS #endif /* __GST_A52DEC_H__ */