aiffparse: adaptive buffer size

Copied from wavparse, helps with CPU usage on high bitrate
files.
This commit is contained in:
Vincent Penquerc'h 2014-02-04 05:46:16 -05:00
parent 58b077de23
commit 2ae5adfd53
2 changed files with 43 additions and 3 deletions

View file

@ -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);

View file

@ -82,6 +82,7 @@ struct _GstAiffParse {
guint32 bps;
guint bytes_per_sample;
guint max_buf_size;
guint32 total_frames;