[FFmpeg-devel] [PATCH] cllc: simplify/fix swapped data buffer allocation.

Derek Buitenhuis derek.buitenhuis at gmail.com
Sun Aug 26 19:14:08 CEST 2012


On 26/08/2012 7:11 AM, Reimar Döffinger wrote:
> Using the malloc variant avoids pointless memcpy on size
> increase and simplifies handling allocation failure.
> Also change code to ensure that allocation, bswap and bitstream
> reader all use the same size, even when the packet size is odd
> for example.
> 
> Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> ---
>  libavcodec/cllc.c |   30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)

I'm for this patch, but I would like to know if there is a
measurable difference.

> +    data_size = (avpkt->size - info_offset) & ~1;

Won't this technically not meet the requirement of init_get_bits:

"bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger
than the actual read bits because some optimized bitstream readers
read 32 or 64 bit at once and could read over the end."

This could end up only FF_INPUT_BUFFER_PADDING_SIZE - 1 bytes larger.

> +
> +    /* Make sure our bswap16'd buffer is big enough */
> +    av_fast_padded_malloc(&ctx->swapped_buf,
> +                          &ctx->swapped_buf_size, data_size);
> +    if (!ctx->swapped_buf) {
> +        av_log(avctx, AV_LOG_ERROR, "Could not realloc swapped buffer.\n");

Perhaps this should be changed? It's not technically a realloc.

- Derek


More information about the ffmpeg-devel mailing list