[FFmpeg-devel] [PATCH v2 24/36] lavc/cbs: Add JPEG support

James Almer jamrial at gmail.com
Fri Jun 8 07:18:43 EEST 2018


On 6/7/2018 8:43 PM, Mark Thompson wrote:
> +static int cbs_jpeg_write_unit(CodedBitstreamContext *ctx,
> +                                CodedBitstreamUnit *unit)
> +{
> +    CodedBitstreamJPEGContext *priv = ctx->priv_data;
> +    PutBitContext pbc;
> +    int err;
> +
> +    if (!priv->write_buffer) {
> +        // Initial write buffer size is 1MB.
> +        priv->write_buffer_size = 1024 * 1024;
> +
> +    reallocate_and_try_again:
> +        err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);

You could use av_fast_malloc() instead, since you don't care about the
previous contents of the buffer. But it will make no real difference
admittedly since at most it will be reallocated twice or thrice for
really big files and that's it.

I sent a patch implementing this change for the other modules some
weeks, which i guess you didn't see and i forgot about :p

> +        if (err < 0) {
> +            av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
> +                   "sufficiently large write buffer (last attempt "
> +                   "%"SIZE_SPECIFIER" bytes).\n", priv->write_buffer_size);
> +            return err;
> +        }
> +    }



More information about the ffmpeg-devel mailing list