gst/audioconvert/audioconvert.c: More elegant and working temp buffer selection algo.

Original commit message from CVS:
* gst/audioconvert/audioconvert.c: (if), (float),
(audio_convert_get_func_index), (check_default),
(audio_convert_clean_fmt), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_get_sizes),
(audio_convert_convert):
More elegant and working temp buffer selection algo.
This commit is contained in:
Wim Taymans 2005-08-26 18:43:02 +00:00
parent 123aa7de1a
commit ddec57c089
2 changed files with 47 additions and 52 deletions

View File

@ -1,3 +1,12 @@
2005-08-26 Wim Taymans <wim@fluendo.com>
* gst/audioconvert/audioconvert.c: (if), (float),
(audio_convert_get_func_index), (check_default),
(audio_convert_clean_fmt), (audio_convert_prepare_context),
(audio_convert_clean_context), (audio_convert_get_sizes),
(audio_convert_convert):
More elegant and working temp buffer selection algo.
2005-08-26 Wim Taymans <wim@fluendo.com> 2005-08-26 Wim Taymans <wim@fluendo.com>
* gst/audioconvert/audioconvert.c: (if), (float), * gst/audioconvert/audioconvert.c: (if), (float),

View File

@ -302,36 +302,13 @@ audio_convert_get_sizes (AudioConvertCtx * ctx, gint samples, gint * srcsize,
return TRUE; return TRUE;
} }
static gpointer
get_temp_buffer (AudioConvertCtx * ctx, gpointer src, gint srcsize,
gboolean writable, gint tmpsize)
{
gpointer result;
if (srcsize >= tmpsize && writable) {
result = src;
} else {
if (ctx->tmpbufsize < tmpsize) {
ctx->tmpbuf = g_realloc (ctx->tmpbuf, tmpsize);
ctx->tmpbufsize = tmpsize;
}
result = ctx->tmpbuf;
}
return result;
}
gboolean gboolean
audio_convert_convert (AudioConvertCtx * ctx, gpointer src, audio_convert_convert (AudioConvertCtx * ctx, gpointer src,
gpointer dst, gint samples, gboolean src_writable) gpointer dst, gint samples, gboolean src_writable)
{ {
gint insize, outsize; gint insize, outsize;
gboolean final; gboolean final;
gpointer buf; gpointer inbuf, outbuf, tmpbuf;
gint bufsize;
gboolean bufwritable;
gpointer tmpdst;
gint tmpsize = 0;
g_return_val_if_fail (ctx != NULL, FALSE); g_return_val_if_fail (ctx != NULL, FALSE);
g_return_val_if_fail (src != NULL, FALSE); g_return_val_if_fail (src != NULL, FALSE);
@ -344,54 +321,63 @@ audio_convert_convert (AudioConvertCtx * ctx, gpointer src,
insize = ctx->in.unit_size * samples; insize = ctx->in.unit_size * samples;
outsize = ctx->out.unit_size * samples; outsize = ctx->out.unit_size * samples;
/* find biggest temp buffer size */
{
gint biggest = 0;
if (!ctx->in_default)
biggest = insize * 32 / ctx->in.width;
if (!ctx->mix_passthrough)
biggest = MAX (biggest, outsize * 32 / ctx->out.width);
/* see if one of the buffers can be used as temp */
if (insize >= biggest && src_writable)
tmpbuf = src;
else if (outsize >= biggest)
tmpbuf = dst;
else {
if (biggest > ctx->tmpbufsize) {
ctx->tmpbuf = g_realloc (ctx->tmpbuf, biggest);
ctx->tmpbufsize = biggest;
}
tmpbuf = ctx->tmpbuf;
}
}
/* this is our source data, we start with the input src data. */ /* this is our source data, we start with the input src data. */
buf = src; inbuf = src;
bufsize = insize; outbuf = dst;
bufwritable = src_writable;
if (!ctx->in_default) { if (!ctx->in_default) {
/* check if final conversion */ /* check if final conversion */
final = (ctx->out_default && ctx->mix_passthrough); final = (ctx->out_default && ctx->mix_passthrough);
if (final) if (!final)
tmpdst = dst; outbuf = tmpbuf;
else {
tmpsize = insize * 32 / ctx->in.width;
tmpdst = get_temp_buffer (ctx, buf, bufsize, bufwritable, tmpsize);
}
ctx->unpack (buf, tmpdst, ctx->scale, samples * ctx->in.channels); ctx->unpack (inbuf, outbuf, ctx->scale, samples * ctx->in.channels);
if (!final) { inbuf = outbuf;
/* new source data, it is writable */
buf = tmpdst;
bufsize = tmpsize;
bufwritable = TRUE;
}
} }
if (!ctx->mix_passthrough) { if (!ctx->mix_passthrough) {
/* see if we need an intermediate step */ /* see if we need an intermediate step */
final = ctx->out_default; final = ctx->out_default;
if (final) if (!final)
tmpdst = dst; outbuf = tmpbuf;
else { else
tmpsize = outsize * 32 / ctx->out.width; outbuf = dst;
tmpdst = get_temp_buffer (ctx, buf, bufsize, bufwritable, tmpsize);
}
/* convert */ /* convert */
gst_channel_mix_mix (ctx, buf, tmpdst, samples); gst_channel_mix_mix (ctx, inbuf, outbuf, samples);
if (!final) { inbuf = outbuf;
buf = tmpdst;
}
} }
if (!ctx->out_default) { if (!ctx->out_default) {
/* output always to dst buffer */ ctx->pack (inbuf, dst, ctx->depth, samples * ctx->out.channels);
ctx->pack (buf, dst, ctx->depth, samples * ctx->out.channels);
} }
return TRUE; return TRUE;