From 96b959fc53991df7392acb8f63a9ed3aaaa5ebe8 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 23 Dec 2005 15:48:04 +0000 Subject: [PATCH] gst/iec958/ac3iec.*: Accept audio/x-ac3 and audio/ac3 to ac3iec958 element. Original commit message from CVS: * gst/iec958/ac3iec.c: (ac3iec_init), (ac3iec_setcaps), (ac3iec_chain_dvd): * gst/iec958/ac3iec.h: Accept audio/x-ac3 and audio/ac3 to ac3iec958 element. --- ChangeLog | 7 ++++ gst/iec958/ac3iec.c | 97 ++++++++++++++++++++++++++++----------------- gst/iec958/ac3iec.h | 2 + 3 files changed, 70 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9eddba603b..b8a469ae4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-12-23 Michael Smith + + * gst/iec958/ac3iec.c: (ac3iec_init), (ac3iec_setcaps), + (ac3iec_chain_dvd): + * gst/iec958/ac3iec.h: + Accept audio/x-ac3 and audio/ac3 to ac3iec958 element. + 2005-12-21 Tim-Philipp Müller * ext/mpeg2dec/gstmpeg2dec.c: (gst_mpeg2dec_src_event): diff --git a/gst/iec958/ac3iec.c b/gst/iec958/ac3iec.c index 7b9a3a5281..3d78aea8ec 100644 --- a/gst/iec958/ac3iec.c +++ b/gst/iec958/ac3iec.c @@ -61,10 +61,10 @@ enum static GstStaticPadTemplate ac3iec_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", + GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-private1-ac3") + GST_STATIC_CAPS ("audio/x-private1-ac3; audio/x-ac3; audio/ac3") ); static GstStaticPadTemplate ac3iec_src_template = @@ -84,6 +84,7 @@ static void ac3iec_set_property (GObject * object, static void ac3iec_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static gboolean ac3iec_setcaps (GstPad * pad, GstCaps * caps); static GstFlowReturn ac3iec_chain_dvd (GstPad * pad, GstBuffer * buf); static GstFlowReturn ac3iec_chain_raw (GstPad * pad, GstBuffer * buf); @@ -160,6 +161,7 @@ ac3iec_init (AC3IEC * ac3iec) ac3iec->sink = gst_pad_new_from_template (gst_static_pad_template_get (&ac3iec_sink_template), "sink"); + gst_pad_set_setcaps_function (ac3iec->sink, ac3iec_setcaps); gst_pad_set_chain_function (ac3iec->sink, ac3iec_chain_dvd); gst_element_add_pad (GST_ELEMENT (ac3iec), ac3iec->sink); @@ -199,6 +201,21 @@ ac3iec_set_property (GObject * object, guint prop_id, } } +static gboolean +ac3iec_setcaps (GstPad * pad, GstCaps * caps) +{ + AC3IEC *ac3iec = AC3IEC (gst_pad_get_parent (pad)); + GstStructure *structure = gst_caps_get_structure (caps, 0); + + if (structure && gst_structure_has_name (structure, "audio/x-private1-ac3")) + ac3iec->dvdmode = TRUE; + else + ac3iec->dvdmode = FALSE; + + gst_object_unref (ac3iec); + + return TRUE; +} static void ac3iec_get_property (GObject * object, guint prop_id, @@ -228,54 +245,62 @@ ac3iec_chain_dvd (GstPad * pad, GstBuffer * buf) gint len; GstBuffer *subbuf; GstFlowReturn ret; + AC3IEC *ac3iec = AC3IEC (gst_pad_get_parent (pad)); - size = GST_BUFFER_SIZE (buf); - data = GST_BUFFER_DATA (buf); + if (ac3iec->dvdmode) { + size = GST_BUFFER_SIZE (buf); + data = GST_BUFFER_DATA (buf); - first_access = (data[0] << 8) | data[1]; + first_access = (data[0] << 8) | data[1]; - /* Skip the first_access header */ - offset = 2; + /* Skip the first_access header */ + offset = 2; - if (first_access > 1) { - /* Length of data before first_access */ - len = first_access - 1; + if (first_access > 1) { + /* Length of data before first_access */ + len = first_access - 1; - /* Ensure we don't crash if fed totally invalid data */ - if (offset + len > size) { - ret = GST_FLOW_ERROR; - goto done; - } + /* Ensure we don't crash if fed totally invalid data */ + if (offset + len > size) { + ret = GST_FLOW_ERROR; + goto done; + } + + if (len > 0) { + subbuf = gst_buffer_create_sub (buf, offset, len); + GST_BUFFER_TIMESTAMP (subbuf) = GST_CLOCK_TIME_NONE; + ret = ac3iec_chain_raw (pad, subbuf); + if (ret != GST_FLOW_OK) + goto done; + } + + offset += len; + len = size - offset; - if (len > 0) { subbuf = gst_buffer_create_sub (buf, offset, len); + GST_BUFFER_TIMESTAMP (subbuf) = GST_BUFFER_TIMESTAMP (buf); + + ret = ac3iec_chain_raw (pad, subbuf); + } else { + /* Ensure we don't crash if fed totally invalid data */ + if (size < 2) { + ret = GST_FLOW_ERROR; + goto done; + } + + /* No first_access, so no timestamp */ + subbuf = gst_buffer_create_sub (buf, offset, size - offset); GST_BUFFER_TIMESTAMP (subbuf) = GST_CLOCK_TIME_NONE; ret = ac3iec_chain_raw (pad, subbuf); - if (ret != GST_FLOW_OK) - goto done; } - - offset += len; - len = size - offset; - - subbuf = gst_buffer_create_sub (buf, offset, len); - GST_BUFFER_TIMESTAMP (subbuf) = GST_BUFFER_TIMESTAMP (buf); - - ret = ac3iec_chain_raw (pad, subbuf); } else { - /* Ensure we don't crash if fed totally invalid data */ - if (size < 2) { - ret = GST_FLOW_ERROR; - goto done; - } - - /* No first_access, so no timestamp */ - subbuf = gst_buffer_create_sub (buf, offset, size - offset); - GST_BUFFER_TIMESTAMP (subbuf) = GST_CLOCK_TIME_NONE; - ret = ac3iec_chain_raw (pad, subbuf); + ret = ac3iec_chain_raw (pad, buf); + gst_object_unref (ac3iec); + return ret; } done: + gst_object_unref (ac3iec); gst_buffer_unref (buf); return ret; diff --git a/gst/iec958/ac3iec.h b/gst/iec958/ac3iec.h index 8896bec0a0..eb911cdef6 100644 --- a/gst/iec958/ac3iec.h +++ b/gst/iec958/ac3iec.h @@ -62,6 +62,8 @@ struct _AC3IEC { GstClockTime next_ts; /* Time stamp for the next frame. */ ac3_padder *padder; /* AC3 to SPDIF padder object. */ + + gboolean dvdmode; };