summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjep <jep@2b0047a9-a6d8-0310-accf-f7200b2a168c>2012-01-27 14:25:03 +0000
committerjep <jep@2b0047a9-a6d8-0310-accf-f7200b2a168c>2012-01-27 14:25:03 +0000
commitccdfa31fd7ef0784dc8a69c3c7ff153f4f3cbbc1 (patch)
tree8779ae9d52647cbf04777cc00a9c6d84ae89d05e
parent28834dd961eee73274f4a42e44c15bd9ea69599c (diff)
* src/bitstream.c: (bs_free_buffer), (bs_add_buffer):
* src/bitstream.h: * src/flump3dec.c: (gst_flump3dec_decode), (gst_flump3dec_decode_buffer), (gst_flump3dec_sink_chain), (gst_flump3dec_handle_sink_event), (gst_flump3dec_sink_event), (gst_flump3dec_src_convert), (gst_flump3dec_handle_src_query), (gst_flump3dec_src_query), (gst_flump3dec_handle_src_event), (gst_flump3dec_src_event), (gst_flump3dec_init): Change the code to being able build it in current GStreamer 0.11. git-svn-id: https://core.fluendo.com/gstreamer/svn/trunk/gst-fluendo-mp3@2230 2b0047a9-a6d8-0310-accf-f7200b2a168c
-rw-r--r--ChangeLog12
-rw-r--r--src/bitstream.c13
-rw-r--r--src/bitstream.h4
-rw-r--r--src/flump3dec.c203
4 files changed, 186 insertions, 46 deletions
diff --git a/ChangeLog b/ChangeLog
index f1b803c..1257bee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-01-27 Josep Torra <josep@fluendo.com>
+
+ * src/bitstream.c: (bs_free_buffer), (bs_add_buffer):
+ * src/bitstream.h:
+ * src/flump3dec.c: (gst_flump3dec_decode),
+ (gst_flump3dec_decode_buffer), (gst_flump3dec_sink_chain),
+ (gst_flump3dec_handle_sink_event), (gst_flump3dec_sink_event),
+ (gst_flump3dec_src_convert), (gst_flump3dec_handle_src_query),
+ (gst_flump3dec_src_query), (gst_flump3dec_handle_src_event),
+ (gst_flump3dec_src_event), (gst_flump3dec_init):
+ Change the code to being able build it in current GStreamer 0.11.
+
2011-12-05 Release Maker <nomail@fluendo.com>
* configure.ac: Back to TRUNK.
diff --git a/src/bitstream.c b/src/bitstream.c
index 4ada638..8ce94f5 100644
--- a/src/bitstream.c
+++ b/src/bitstream.c
@@ -31,7 +31,7 @@ static inline void
bs_free_buffer (BSBuffer * bsbuf)
{
#if GST_CHECK_VERSION(0,11,0)
- gst_buffer_unmap (GST_BUFFER (bsbuf->ref), bsbuf->data, bsbuf->size);
+ gst_buffer_unmap (GST_BUFFER (bsbuf->ref), &bsbuf->map);
#endif
gst_buffer_unref (GST_BUFFER (bsbuf->ref));
g_free (bsbuf);
@@ -105,15 +105,13 @@ gboolean
bs_add_buffer (Bit_stream_struc * bs, GstBuffer * buffer)
{
BSBuffer *bsbuf;
- guint8 *data;
gsize size;
g_return_val_if_fail (bs != NULL, FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
#if GST_CHECK_VERSION(0,11,0)
- data = (guint8 *) gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
+ size = gst_buffer_get_size (buffer);
#else
- data = GST_BUFFER_DATA (buffer);
size = GST_BUFFER_SIZE (buffer);
#endif
g_return_val_if_fail (size != 0, FALSE);
@@ -122,7 +120,12 @@ bs_add_buffer (Bit_stream_struc * bs, GstBuffer * buffer)
g_return_val_if_fail (bsbuf != NULL, FALSE);
bsbuf->ref = buffer;
- bsbuf->data = data;
+#if GST_CHECK_VERSION(0,11,0)
+ gst_buffer_map (buffer, &bsbuf->map, GST_MAP_READ);
+ bsbuf->data = bsbuf->map.data;
+#else
+ bsbuf->data = GST_BUFFER_DATA (buffer);
+#endif
bsbuf->size = size;
bsbuf->ts = GST_BUFFER_TIMESTAMP (buffer);
diff --git a/src/bitstream.h b/src/bitstream.h
index 9cf8bd0..e8078a4 100644
--- a/src/bitstream.h
+++ b/src/bitstream.h
@@ -37,7 +37,9 @@ typedef struct BSBuffer
/* Caller Reference, passed to the free function */
void *ref;
-
+#if GST_CHECK_VERSION(0,11,0)
+ GstMapInfo map;
+#endif
/* Clock time, if any, associated with this buffer. Returned
* from the decode for the first frame whose sync word starts in
* this buffer
diff --git a/src/flump3dec.c b/src/flump3dec.c
index 3b6ad1b..638125a 100644
--- a/src/flump3dec.c
+++ b/src/flump3dec.c
@@ -46,6 +46,29 @@ GST_STATIC_PAD_TEMPLATE ("sink",
);
/* TODO: higher resolution 24 bit decoding */
+#if GST_CHECK_VERSION(0,11,0)
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define FORMAT_STR "S16LE"
+#else
+#define FORMAT_STR "S16BE"
+#endif
+
+static GstStaticPadTemplate gst_flump3dec_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("audio/x-raw,"
+ "format = (string) " FORMAT_STR ", "
+ "layout = (string) interleaved, "
+ "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
+ "channels = (int) 1;"
+ "audio/x-raw,"
+ "format = (string) " FORMAT_STR ", "
+ "layout = (string) interleaved, "
+ "rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
+ "channels = (int) 2, channel-mask = (bitmask) 0x3")
+ );
+#else
static GstStaticPadTemplate gst_flump3dec_src_factory =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
@@ -57,6 +80,7 @@ GST_STATIC_PAD_TEMPLATE ("src",
"rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
"channels = (int) [ 1, 2 ]")
);
+#endif
static void
gst_flump3dec_reset (GstFluMp3Dec * dec)
@@ -226,6 +250,9 @@ gst_flump3dec_decode (GstFluMp3Dec * dec, gboolean more_data)
guint8 *out_data;
gsize out_size;
gsize frame_size;
+#if GST_CHECK_VERSION(0,11,0)
+ GstMapInfo map;
+#endif
GST_DEBUG_OBJECT (dec, "draining, more: %d", more_data);
@@ -274,11 +301,20 @@ gst_flump3dec_decode (GstFluMp3Dec * dec, gboolean more_data)
} else {
codec = g_strdup_printf ("MPEG %d Audio, Layer %d", ver, mp3hdr->layer);
}
- taglist = gst_tag_list_new ();
- gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_AUDIO_CODEC,
- codec, NULL);
- gst_element_found_tags_for_pad (GST_ELEMENT_CAST (dec),
- dec->srcpad, taglist);
+ if (codec) {
+#if GST_CHECK_VERSION(0,11,0)
+ taglist = gst_tag_list_new_empty ();
+ gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
+ GST_TAG_AUDIO_CODEC, codec, NULL);
+ gst_pad_push_event (dec->srcpad, gst_event_new_tag (taglist));
+#else
+ taglist = gst_tag_list_new ();
+ gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
+ GST_TAG_AUDIO_CODEC, codec, NULL);
+ gst_element_found_tags_for_pad (GST_ELEMENT_CAST (dec),
+ dec->srcpad, taglist);
+#endif
+ }
g_free (codec);
/* end setting the tag */
@@ -299,14 +335,24 @@ gst_flump3dec_decode (GstFluMp3Dec * dec, gboolean more_data)
/* Change the output caps based on the header */
if ((mp3hdr->sample_rate != dec->rate || mp3hdr->channels != dec->channels)) {
- GstCaps *caps = gst_caps_new_simple ("audio/x-raw-int",
+ GstCaps *caps;
+#if GST_CHECK_VERSION(0,11,0)
+ caps = gst_caps_new_simple ("audio/x-raw",
+ "format", G_TYPE_STRING, FORMAT_STR,
+ "layout", G_TYPE_STRING, "interleaved",
+ "rate", G_TYPE_INT, mp3hdr->sample_rate,
+ "channels", G_TYPE_INT, mp3hdr->channels,
+ "channel-mask", GST_TYPE_BITMASK, (mp3hdr->channels == 2 ? 0x3 : 0x0),
+ NULL);
+#else
+ caps = gst_caps_new_simple ("audio/x-raw-int",
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE,
"width", G_TYPE_INT, 16,
"depth", G_TYPE_INT, 16,
"rate", G_TYPE_INT, mp3hdr->sample_rate,
"channels", G_TYPE_INT, mp3hdr->channels, NULL);
-
+#endif
GST_DEBUG_OBJECT (dec, "Caps change, rate: %d->%d channels %d->%d",
dec->rate, mp3hdr->sample_rate, dec->channels, mp3hdr->channels);
if (!gst_pad_set_caps (dec->srcpad, caps)) {
@@ -336,8 +382,9 @@ gst_flump3dec_decode (GstFluMp3Dec * dec, gboolean more_data)
ret = GST_FLOW_ERROR;
goto alloc_error;
}
- out_data =
- (guint8 *) gst_buffer_map (out_buf, &out_size, NULL, GST_MAP_WRITE);
+ gst_buffer_map (out_buf, &map, GST_MAP_WRITE);
+ out_data = map.data;
+ out_size = map.size;
#else
ret = gst_pad_alloc_buffer (dec->srcpad, GST_BUFFER_OFFSET_NONE,
frame_size, GST_PAD_CAPS (dec->srcpad), &out_buf);
@@ -352,7 +399,7 @@ gst_flump3dec_decode (GstFluMp3Dec * dec, gboolean more_data)
result = mp3tl_decode_frame (dec->dec, out_data, out_size, &dec_ts);
#if GST_CHECK_VERSION(0,11,0)
- gst_buffer_unmap (out_buf, out_data, out_size);
+ gst_buffer_unmap (out_buf, &map);
#endif
if (result != MP3TL_ERR_OK) {
/* Free up the buffer we allocated above */
@@ -396,10 +443,17 @@ gst_flump3dec_decode (GstFluMp3Dec * dec, gboolean more_data)
/* Set the bitrate tag if changed (only care about changes over 10kbps) */
if ((dec->last_posted_bitrate / 10240) != (dec->avg_bitrate / 10240)) {
dec->last_posted_bitrate = dec->avg_bitrate;
+#if GST_CHECK_VERSION(0,11,0)
+ taglist = gst_tag_list_new_empty ();
+ gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
+ GST_TAG_BITRATE, dec->last_posted_bitrate, NULL);
+ gst_pad_push_event (dec->srcpad, gst_event_new_tag (taglist));
+#else
taglist = gst_tag_list_new ();
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_BITRATE,
dec->last_posted_bitrate, NULL);
gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, taglist);
+#endif
}
if (GST_CLOCK_TIME_IS_VALID (dec_ts) && dec_ts != dec->last_dec_ts) {
@@ -460,7 +514,7 @@ alloc_error:
return ret;
no_buffer:
- if (ret < GST_FLOW_UNEXPECTED) {
+ if (ret <= GST_FLOW_NOT_NEGOTIATED) {
GST_ELEMENT_ERROR (dec, RESOURCE, FAILED, (NULL),
("Failed to allocate output buffer: reason %s",
gst_flow_get_name (ret)));
@@ -489,16 +543,13 @@ negotiate_error:
}
/* Decode a buffer */
-static GstFlowReturn
-gst_flump3dec_sink_chain (GstPad * pad, GstBuffer * buf)
+static inline GstFlowReturn
+gst_flump3dec_decode_buffer (GstFluMp3Dec * dec, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
- GstFluMp3Dec *dec = NULL;
GstClockTime new_ts;
gboolean discont;
- dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
-
discont = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT);
new_ts = GST_BUFFER_TIMESTAMP (buf);
@@ -526,11 +577,27 @@ gst_flump3dec_sink_chain (GstPad * pad, GstBuffer * buf)
GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buf)))
dec->in_ts = new_ts + GST_BUFFER_DURATION (buf);
- gst_object_unref (dec);
-
return ret;
}
+#if GST_CHECK_VERSION(0,11,0)
+static GstFlowReturn
+gst_flump3dec_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (parent);
+ return gst_flump3dec_decode_buffer (dec, buffer);
+}
+#else
+static GstFlowReturn
+gst_flump3dec_sink_chain (GstPad * pad, GstBuffer * buffer)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
+ GstFlowReturn result = gst_flump3dec_decode_buffer (dec, buffer);
+ gst_object_unref (dec);
+ return result;
+}
+#endif
+
static inline gboolean
conv_bytes_to_time (GstFluMp3Dec * dec, gint64 byteval, GstClockTime * timeval)
{
@@ -547,11 +614,9 @@ conv_bytes_to_time (GstFluMp3Dec * dec, gint64 byteval, GstClockTime * timeval)
}
/* Handle incoming events on the sink pad */
-static gboolean
-gst_flump3dec_sink_event (GstPad * pad, GstEvent * event)
+static inline gboolean
+gst_flump3dec_handle_sink_event (GstFluMp3Dec * dec, GstEvent * event)
{
- GstFluMp3Dec *dec = GST_FLUMP3DEC (GST_PAD_PARENT (pad));
-
switch (GST_EVENT_TYPE (event)) {
#if GST_CHECK_VERSION(0,11,0)
case GST_EVENT_SEGMENT:
@@ -664,6 +729,24 @@ gst_flump3dec_sink_event (GstPad * pad, GstEvent * event)
return gst_pad_push_event (dec->srcpad, event);
}
+#if GST_CHECK_VERSION(0,11,0)
+static gboolean
+gst_flump3dec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (parent);
+ return gst_flump3dec_handle_sink_event (dec, event);
+}
+#else
+static gboolean
+gst_flump3dec_sink_event (GstPad * pad, GstEvent * event)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
+ gboolean result = gst_flump3dec_handle_sink_event (dec, event);
+ gst_object_unref (dec);
+ return result;
+}
+#endif
+
static inline gboolean
gst_flump3dec_total_bytes (GstFluMp3Dec * dec, guint64 * total)
{
@@ -708,10 +791,9 @@ gst_flump3dec_total_time (GstFluMp3Dec * dec, GstClockTime * total)
}
static gboolean
-gst_flump3dec_src_convert (GstPad * pad, GstFormat src_format,
+gst_flump3dec_src_convert (GstFluMp3Dec * dec, GstFormat src_format,
gint64 src_value, GstFormat * dest_format, gint64 * dest_value)
{
- GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
gboolean res = FALSE;
g_return_val_if_fail (dec != NULL, FALSE);
@@ -778,17 +860,15 @@ gst_flump3dec_src_convert (GstPad * pad, GstFormat src_format,
break;
}
- gst_object_unref (dec);
return res;
}
static gboolean
-gst_flump3dec_src_query (GstPad * pad, GstQuery * query)
+gst_flump3dec_handle_src_query (GstFluMp3Dec * dec, GstQuery * query)
{
GstFormat format;
gint64 cur;
guint64 total;
- GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
GstPad *peer;
gboolean res = FALSE;
@@ -816,7 +896,7 @@ gst_flump3dec_src_query (GstPad * pad, GstQuery * query)
cur = dec->next_ts;
if (format != GST_FORMAT_TIME &&
- !gst_flump3dec_src_convert (pad, GST_FORMAT_TIME, cur, &format,
+ !gst_flump3dec_src_convert (dec, GST_FORMAT_TIME, cur, &format,
&cur)) {
gst_query_set_position (query, format, -1);
goto error;
@@ -849,7 +929,7 @@ gst_flump3dec_src_query (GstPad * pad, GstQuery * query)
if (total != -1) {
if (format != GST_FORMAT_TIME &&
- !gst_flump3dec_src_convert (pad, GST_FORMAT_TIME, total,
+ !gst_flump3dec_src_convert (dec, GST_FORMAT_TIME, total,
&format, (gint64 *) & total)) {
gst_query_set_duration (query, format, -1);
goto error;
@@ -861,18 +941,38 @@ gst_flump3dec_src_query (GstPad * pad, GstQuery * query)
break;
}
default:
- res = gst_pad_query_default (pad, query);
+#if GST_CHECK_VERSION(0,11,0)
+ res = gst_pad_query_default (dec->srcpad, GST_OBJECT_CAST (dec), query);
+#else
+ res = gst_pad_query_default (dec->srcpad, query);
+#endif
break;
}
out:
- gst_object_unref (dec);
return res;
error:
- gst_object_unref (dec);
return FALSE;
}
+#if GST_CHECK_VERSION(0,11,0)
+static gboolean
+gst_flump3dec_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (parent);
+ return gst_flump3dec_handle_src_query (dec, query);
+}
+#else
+static gboolean
+gst_flump3dec_src_query (GstPad * pad, GstQuery * query)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
+ gboolean result = gst_flump3dec_handle_src_query (dec, query);
+ gst_object_unref (dec);
+ return result;
+}
+#endif
+
static gboolean
gst_flump3dec_time_to_bytepos (GstFluMp3Dec * dec, GstClockTime ts,
gint64 * bytepos)
@@ -923,10 +1023,9 @@ gst_flump3dec_time_to_bytepos (GstFluMp3Dec * dec, GstClockTime ts,
return TRUE;
}
-static gboolean
-gst_flump3dec_src_event (GstPad * pad, GstEvent * event)
+static inline gboolean
+gst_flump3dec_handle_src_event (GstFluMp3Dec * dec, GstEvent * event)
{
- GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
gboolean result;
g_return_val_if_fail (dec != NULL, FALSE);
@@ -953,9 +1052,9 @@ gst_flump3dec_src_event (GstPad * pad, GstEvent * event)
/* Convert request to time format if we can */
if (in_format == GST_FORMAT_DEFAULT || in_format == GST_FORMAT_BYTES) {
format = GST_FORMAT_TIME;
- if (!gst_flump3dec_src_convert (pad, in_format, start, &format, &start))
+ if (!gst_flump3dec_src_convert (dec, in_format, start, &format, &start))
goto error;
- if (!gst_flump3dec_src_convert (pad, in_format, stop, &format, &stop))
+ if (!gst_flump3dec_src_convert (dec, in_format, stop, &format, &stop))
goto error;
} else {
format = in_format;
@@ -990,18 +1089,38 @@ gst_flump3dec_src_event (GstPad * pad, GstEvent * event)
result = gst_pad_push_event (dec->sinkpad, seek_event);
} else {
- result = gst_pad_event_default (pad, event);
+#if GST_CHECK_VERSION(0,11,0)
+ result = gst_pad_event_default (dec->srcpad, GST_OBJECT_CAST (dec), event);
+#else
+ result = gst_pad_event_default (dec->srcpad, event);
+#endif
}
out:
- gst_object_unref (dec);
return result;
error:
- gst_object_unref (dec);
return FALSE;
}
+#if GST_CHECK_VERSION(0,11,0)
+static gboolean
+gst_flump3dec_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (parent);
+ return gst_flump3dec_handle_src_event (dec, event);
+}
+#else
+static gboolean
+gst_flump3dec_src_event (GstPad * pad, GstEvent * event)
+{
+ GstFluMp3Dec *dec = GST_FLUMP3DEC (gst_pad_get_parent (pad));
+ gboolean result = gst_flump3dec_handle_src_event (dec, event);
+ gst_object_unref (dec);
+ return result;
+}
+#endif
+
static GstStateChangeReturn
gst_flump3dec_change_state (GstElement * element, GstStateChange transition)
{
@@ -1048,6 +1167,7 @@ gst_flump3dec_dispose (GObject * object)
G_OBJECT_CLASS (parent_class)->dispose (object);
}
+#if !GST_CHECK_VERSION(0,11,0)
static const GstQueryType *
gst_flump3dec_get_query_types (GstPad * pad ATTR_UNUSED)
{
@@ -1059,6 +1179,7 @@ gst_flump3dec_get_query_types (GstPad * pad ATTR_UNUSED)
return query_types;
}
+#endif
static void
gst_flump3dec_class_init (GstFluMp3Dec * klass)
@@ -1117,7 +1238,9 @@ gst_flump3dec_init (GstFluMp3Dec * dec)
dec->srcpad =
gst_pad_new_from_static_template (&gst_flump3dec_src_factory, "src");
+#if !GST_CHECK_VERSION(0,11,0)
gst_pad_set_query_type_function (dec->srcpad, gst_flump3dec_get_query_types);
+#endif
gst_pad_set_query_function (dec->srcpad, gst_flump3dec_src_query);
gst_pad_set_event_function (dec->srcpad, gst_flump3dec_src_event);
gst_pad_use_fixed_caps (dec->srcpad);