summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sourceforge.net>2008-10-09 08:43:41 +0000
committerStefan Kost <ensonic@users.sourceforge.net>2008-10-09 08:43:41 +0000
commit93350550688344d76d9f438a976980fb0dc3d6d7 (patch)
tree39cf438688d96895880ce9a5575820361448a167 /ext
parent2dde2ebecc6e6d2187f84ab2b7e14ecdb41d99c3 (diff)
downloadgstreamer-plugins-bad-93350550688344d76d9f438a976980fb0dc3d6d7.tar.gz
ext/amrwb/gstamrwbparse.*: Fix the duration query. Also set caps on the pads and buffers more correctly. Taken from r...
Original commit message from CVS: * ext/amrwb/gstamrwbparse.c: * ext/amrwb/gstamrwbparse.h: Fix the duration query. Also set caps on the pads and buffers more correctly. Taken from recent armnbparse changes.
Diffstat (limited to 'ext')
-rw-r--r--ext/amrwb/gstamrwbparse.c50
-rw-r--r--ext/amrwb/gstamrwbparse.h1
2 files changed, 35 insertions, 16 deletions
diff --git a/ext/amrwb/gstamrwbparse.c b/ext/amrwb/gstamrwbparse.c
index cd162d584..de8e1c6fa 100644
--- a/ext/amrwb/gstamrwbparse.c
+++ b/ext/amrwb/gstamrwbparse.c
@@ -205,19 +205,20 @@ gst_amrwbparse_query (GstPad * pad, GstQuery * query)
}
tot = -1;
+ res = FALSE;
peer = gst_pad_get_peer (amrwbparse->sinkpad);
if (peer) {
GstFormat pformat;
- gint64 pcur, ptot;
+ gint64 ptot;
pformat = GST_FORMAT_BYTES;
- res = gst_pad_query_position (peer, &pformat, &pcur);
res = gst_pad_query_duration (peer, &pformat, &ptot);
- gst_object_unref (GST_OBJECT (peer));
- if (res) {
- tot = amrwbparse->ts * ((gdouble) ptot / pcur);
+ if (res && amrwbparse->block) {
+ tot = gst_util_uint64_scale_int (ptot, 20 * GST_MSECOND,
+ amrwbparse->block);
}
+ gst_object_unref (GST_OBJECT (peer));
}
gst_query_set_duration (query, GST_FORMAT_TIME, tot);
res = TRUE;
@@ -243,7 +244,7 @@ gst_amrwbparse_chain (GstPad * pad, GstBuffer * buffer)
{
GstAmrwbParse *amrwbparse;
GstFlowReturn res = GST_FLOW_OK;
- gint block, mode;
+ gint mode;
const guint8 *data;
GstBuffer *out;
@@ -253,6 +254,8 @@ gst_amrwbparse_chain (GstPad * pad, GstBuffer * buffer)
/* init */
if (amrwbparse->need_header) {
+ GstEvent *segev;
+ GstCaps *caps;
if (gst_adapter_available (amrwbparse->adapter) < 9)
goto done;
@@ -264,6 +267,17 @@ gst_amrwbparse_chain (GstPad * pad, GstBuffer * buffer)
gst_adapter_flush (amrwbparse->adapter, 9);
amrwbparse->need_header = FALSE;
+
+ caps = gst_caps_new_simple ("audio/AMR-WB",
+ "rate", G_TYPE_INT, 16000, "channels", G_TYPE_INT, 1, NULL);
+ gst_pad_set_caps (amrwbparse->srcpad, caps);
+ gst_caps_unref (caps);
+
+ GST_DEBUG_OBJECT (amrwbparse, "Sending first segment");
+ segev = gst_event_new_new_segment_full (FALSE, 1.0, 1.0,
+ GST_FORMAT_TIME, 0, -1, 0);
+
+ gst_pad_push_event (amrwbparse->srcpad, segev);
}
while (TRUE) {
@@ -274,26 +288,30 @@ gst_amrwbparse_chain (GstPad * pad, GstBuffer * buffer)
/* get size */
mode = (data[0] >> 3) & 0x0F;
- block = block_size[mode] + 1; /* add one for the mode */
+ amrwbparse->block = block_size[mode] + 1; /* add one for the mode */
- if (gst_adapter_available (amrwbparse->adapter) < block)
+ if (gst_adapter_available (amrwbparse->adapter) < amrwbparse->block)
break;
- out = gst_buffer_new_and_alloc (block);
+ out = gst_buffer_new_and_alloc (amrwbparse->block);
- data = gst_adapter_peek (amrwbparse->adapter, block);
- memcpy (GST_BUFFER_DATA (out), data, block);
+ data = gst_adapter_peek (amrwbparse->adapter, amrwbparse->block);
+ memcpy (GST_BUFFER_DATA (out), data, amrwbparse->block);
- /* output */
+ /* timestamp, all constants that won't overflow */
GST_BUFFER_DURATION (out) = GST_SECOND * L_FRAME16k / 16000;
GST_BUFFER_TIMESTAMP (out) = amrwbparse->ts;
- amrwbparse->ts += GST_BUFFER_DURATION (out);
- gst_buffer_set_caps (out,
- (GstCaps *) gst_pad_get_pad_template_caps (amrwbparse->srcpad));
+ if (GST_CLOCK_TIME_IS_VALID (amrwbparse->ts))
+ amrwbparse->ts += GST_BUFFER_DURATION (out);
+
+ gst_buffer_set_caps (out, GST_PAD_CAPS (amrwbparse->srcpad));
+
+ GST_DEBUG_OBJECT (amrwbparse, "Pushing %d bytes of data",
+ amrwbparse->block);
res = gst_pad_push (amrwbparse->srcpad, out);
- gst_adapter_flush (amrwbparse->adapter, block);
+ gst_adapter_flush (amrwbparse->adapter, amrwbparse->block);
}
done:
diff --git a/ext/amrwb/gstamrwbparse.h b/ext/amrwb/gstamrwbparse.h
index cec66048b..06ec1d502 100644
--- a/ext/amrwb/gstamrwbparse.h
+++ b/ext/amrwb/gstamrwbparse.h
@@ -53,6 +53,7 @@ struct _GstAmrwbParse {
gboolean seekable;
gboolean need_header;
gint64 offset;
+ gint block;
guint64 ts;
};