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.
This commit is contained in:
Mark Nauwelaerts 2011-02-23 16:50:43 +01:00
parent 89914439b7
commit b69c605c2c
2 changed files with 17 additions and 3 deletions

View file

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

View file

@ -90,6 +90,7 @@ struct _GstWavParse {
gboolean vbr;
guint bytes_per_sample;
guint max_buf_size;
/* position in data part */
guint64 offset;