diff --git a/ChangeLog b/ChangeLog index 6a3e8a6416..de61774876 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-08-26 Wim Taymans + + * 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 * gst/audioconvert/audioconvert.c: (if), (float), diff --git a/gst/audioconvert/audioconvert.c b/gst/audioconvert/audioconvert.c index 1b83129c2e..be5a75c6ae 100644 --- a/gst/audioconvert/audioconvert.c +++ b/gst/audioconvert/audioconvert.c @@ -302,36 +302,13 @@ audio_convert_get_sizes (AudioConvertCtx * ctx, gint samples, gint * srcsize, 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 audio_convert_convert (AudioConvertCtx * ctx, gpointer src, gpointer dst, gint samples, gboolean src_writable) { gint insize, outsize; gboolean final; - gpointer buf; - gint bufsize; - gboolean bufwritable; - gpointer tmpdst; - gint tmpsize = 0; + gpointer inbuf, outbuf, tmpbuf; g_return_val_if_fail (ctx != 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; 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. */ - buf = src; - bufsize = insize; - bufwritable = src_writable; + inbuf = src; + outbuf = dst; if (!ctx->in_default) { /* check if final conversion */ final = (ctx->out_default && ctx->mix_passthrough); - if (final) - tmpdst = dst; - else { - tmpsize = insize * 32 / ctx->in.width; - tmpdst = get_temp_buffer (ctx, buf, bufsize, bufwritable, tmpsize); - } + if (!final) + outbuf = tmpbuf; - ctx->unpack (buf, tmpdst, ctx->scale, samples * ctx->in.channels); + ctx->unpack (inbuf, outbuf, ctx->scale, samples * ctx->in.channels); - if (!final) { - /* new source data, it is writable */ - buf = tmpdst; - bufsize = tmpsize; - bufwritable = TRUE; - } + inbuf = outbuf; } if (!ctx->mix_passthrough) { /* see if we need an intermediate step */ final = ctx->out_default; - if (final) - tmpdst = dst; - else { - tmpsize = outsize * 32 / ctx->out.width; - tmpdst = get_temp_buffer (ctx, buf, bufsize, bufwritable, tmpsize); - } + if (!final) + outbuf = tmpbuf; + else + outbuf = dst; /* convert */ - gst_channel_mix_mix (ctx, buf, tmpdst, samples); + gst_channel_mix_mix (ctx, inbuf, outbuf, samples); - if (!final) { - buf = tmpdst; - } + inbuf = outbuf; } if (!ctx->out_default) { - /* output always to dst buffer */ - ctx->pack (buf, dst, ctx->depth, samples * ctx->out.channels); + ctx->pack (inbuf, dst, ctx->depth, samples * ctx->out.channels); } return TRUE;