summaryrefslogtreecommitdiff
path: root/gst/aiff
diff options
context:
space:
mode:
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2014-02-04 05:46:16 -0500
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2014-02-04 10:48:55 +0000
commit2ae5adfd539cd080d76a5dd81a4e23388a6cbae7 (patch)
tree68f914e211d8ab83abf337a99b6e70b94ed16f72 /gst/aiff
parent58b077de23f314838f12289193f546e737b1463b (diff)
downloadgstreamer-plugins-bad-2ae5adfd539cd080d76a5dd81a4e23388a6cbae7.tar.gz
aiffparse: adaptive buffer size
Copied from wavparse, helps with CPU usage on high bitrate files.
Diffstat (limited to 'gst/aiff')
-rw-r--r--gst/aiff/aiffparse.c45
-rw-r--r--gst/aiff/aiffparse.h1
2 files changed, 43 insertions, 3 deletions
diff --git a/gst/aiff/aiffparse.c b/gst/aiff/aiffparse.c
index 74da1dbba..1ba9e79e0 100644
--- a/gst/aiff/aiffparse.c
+++ b/gst/aiff/aiffparse.c
@@ -108,6 +108,8 @@ GST_STATIC_PAD_TEMPLATE ("src",
"S32LE, S32BE, F32BE, F64BE }"))
);
+#define MAX_BUFFER_SIZE 4096
+
#define gst_aiff_parse_parent_class parent_class
G_DEFINE_TYPE (GstAiffParse, gst_aiff_parse, GST_TYPE_ELEMENT);
@@ -272,6 +274,32 @@ gst_aiff_parse_stream_init (GstAiffParse * aiff)
return GST_FLOW_OK;
}
+static gboolean
+gst_aiff_parse_time_to_bytepos (GstAiffParse * aiff, gint64 ts,
+ gint64 * bytepos)
+{
+ /* -1 always maps to -1 */
+ if (ts == -1) {
+ *bytepos = -1;
+ return TRUE;
+ }
+
+ /* 0 always maps to 0 */
+ if (ts == 0) {
+ *bytepos = 0;
+ return TRUE;
+ }
+
+ if (aiff->bps > 0) {
+ *bytepos = gst_util_uint64_scale_ceil (ts, (guint64) aiff->bps, GST_SECOND);
+ return TRUE;
+ }
+
+ GST_WARNING_OBJECT (aiff, "No valid bps to convert position");
+
+ return FALSE;
+}
+
/* This function is used to perform seeks on the element in
* pull mode.
*
@@ -1076,6 +1104,19 @@ gst_aiff_parse_stream_headers (GstAiffParse * aiff)
aiff->state = AIFF_PARSE_DATA;
+ /* determine reasonable max buffer size,
+ * that is, buffers not too small either size or time wise
+ * so we do not end up with too many of them */
+ /* var abuse */
+ upstream_size = 0;
+ gst_aiff_parse_time_to_bytepos (aiff, 40 * GST_MSECOND, &upstream_size);
+ aiff->max_buf_size = upstream_size;
+ aiff->max_buf_size = MAX (aiff->max_buf_size, MAX_BUFFER_SIZE);
+ if (aiff->bytes_per_sample > 0)
+ aiff->max_buf_size -= (aiff->max_buf_size % aiff->bytes_per_sample);
+
+ GST_DEBUG_OBJECT (aiff, "max buffer size %u", aiff->max_buf_size);
+
return GST_FLOW_OK;
/* ERROR */
@@ -1197,8 +1238,6 @@ gst_aiff_parse_send_event (GstElement * element, GstEvent * event)
return res;
}
-#define MAX_BUFFER_SIZE 4096
-
static GstFlowReturn
gst_aiff_parse_stream_data (GstAiffParse * aiff)
{
@@ -1221,7 +1260,7 @@ iterate_adapter:
* amounts of data regardless of the playback rate */
desired =
MIN (gst_guint64_to_gdouble (aiff->dataleft),
- MAX_BUFFER_SIZE * ABS (aiff->segment.rate));
+ aiff->max_buf_size * ABS (aiff->segment.rate));
if (desired >= aiff->bytes_per_sample && aiff->bytes_per_sample > 0)
desired -= (desired % aiff->bytes_per_sample);
diff --git a/gst/aiff/aiffparse.h b/gst/aiff/aiffparse.h
index 2243ddc29..4c2a7a15d 100644
--- a/gst/aiff/aiffparse.h
+++ b/gst/aiff/aiffparse.h
@@ -82,6 +82,7 @@ struct _GstAiffParse {
guint32 bps;
guint bytes_per_sample;
+ guint max_buf_size;
guint32 total_frames;