From b69c605c2c4ebd57bf64885aa0860dd06afddcee Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Wed, 23 Feb 2011 16:50:43 +0100 Subject: [PATCH] wavparse: tune output max buffer size to material ... to avoid ending up with tons of short time buffers for e.g. high sample rate audio. --- gst/wavparse/gstwavparse.c | 19 ++++++++++++++++--- gst/wavparse/gstwavparse.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gst/wavparse/gstwavparse.c b/gst/wavparse/gstwavparse.c index 6e56f8ef22..5f8a789c4e 100644 --- a/gst/wavparse/gstwavparse.c +++ b/gst/wavparse/gstwavparse.c @@ -1156,6 +1156,8 @@ gst_waveparse_ignore_chunk (GstWavParse * wav, GstBuffer * buf, guint32 tag, return TRUE; } +#define MAX_BUFFER_SIZE 4096 + static GstFlowReturn gst_wavparse_stream_headers (GstWavParse * wav) { @@ -1578,6 +1580,19 @@ gst_wavparse_stream_headers (GstWavParse * wav) wav->state = GST_WAVPARSE_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_wavparse_time_to_bytepos (wav, 40 * GST_MSECOND, &upstream_size); + wav->max_buf_size = upstream_size; + wav->max_buf_size = MAX (wav->max_buf_size, MAX_BUFFER_SIZE); + if (wav->blockalign > 0) + wav->max_buf_size -= (wav->max_buf_size % wav->blockalign); + + GST_DEBUG_OBJECT (wav, "max buffer size %d", wav->max_buf_size); + return GST_FLOW_OK; /* ERROR */ @@ -1802,8 +1817,6 @@ gst_wavparse_add_src_pad (GstWavParse * wav, GstBuffer * buf) } } -#define MAX_BUFFER_SIZE 4096 - static GstFlowReturn gst_wavparse_stream_data (GstWavParse * wav) { @@ -1826,7 +1839,7 @@ iterate_adapter: * amounts of data regardless of the playback rate */ desired = MIN (gst_guint64_to_gdouble (wav->dataleft), - MAX_BUFFER_SIZE * wav->segment.abs_rate); + wav->max_buf_size * wav->segment.abs_rate); if (desired >= wav->blockalign && wav->blockalign > 0) desired -= (desired % wav->blockalign); diff --git a/gst/wavparse/gstwavparse.h b/gst/wavparse/gstwavparse.h index 29ce814b95..ecac96881e 100644 --- a/gst/wavparse/gstwavparse.h +++ b/gst/wavparse/gstwavparse.h @@ -90,6 +90,7 @@ struct _GstWavParse { gboolean vbr; guint bytes_per_sample; + guint max_buf_size; /* position in data part */ guint64 offset;