[FFmpeg-devel] [PATCH 33/36] avcodec/dump_extradata_bsf: Store pointer for access

James Almer jamrial at gmail.com
Sat May 30 20:00:49 EEST 2020


On 5/30/2020 1:05 PM, Andreas Rheinhardt wrote:
> Using par->extradata instead of ctx->par_in->extradata makes the code
> more readable and removes an overlong line.
> 
> Furthermore, check for extradata_size instead of for the existence of
> extradata as nothing needs to be done in case extradata_size is zero.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/dump_extradata_bsf.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
> index b6ef8b3e6b..be5e23ba5b 100644
> --- a/libavcodec/dump_extradata_bsf.c
> +++ b/libavcodec/dump_extradata_bsf.c
> @@ -40,6 +40,7 @@ typedef struct DumpExtradataContext {
>  static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
>  {
>      DumpExtradataContext *s = ctx->priv_data;
> +    const AVCodecParameters *par;
>      AVPacket *in = &s->pkt;
>      int ret = 0;
>  
> @@ -47,17 +48,17 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
>      if (ret < 0)
>          return ret;
>  
> -    if (ctx->par_in->extradata &&
> +    if ((par = ctx->par_in)->extradata_size &&

Put the assignment in its own line, please. Saving one line is not worth
making the code less readable.

>          (s->freq == DUMP_FREQ_ALL ||
>           (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) &&
> -         (in->size < ctx->par_in->extradata_size ||
> -          memcmp(in->data, ctx->par_in->extradata, ctx->par_in->extradata_size))) {
> -        if (in->size >= INT_MAX - ctx->par_in->extradata_size) {
> +         (in->size < par->extradata_size ||
> +          memcmp(in->data, par->extradata, par->extradata_size))) {
> +        if (in->size >= INT_MAX - par->extradata_size) {
>              ret = AVERROR(ERANGE);
>              goto fail;
>          }
>  
> -        ret = av_new_packet(out, in->size + ctx->par_in->extradata_size);
> +        ret = av_new_packet(out, in->size + par->extradata_size);
>          if (ret < 0)
>              goto fail;
>  
> @@ -67,8 +68,8 @@ static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
>              goto fail;
>          }
>  
> -        memcpy(out->data, ctx->par_in->extradata, ctx->par_in->extradata_size);
> -        memcpy(out->data + ctx->par_in->extradata_size, in->data, in->size);
> +        memcpy(out->data, par->extradata, par->extradata_size);
> +        memcpy(out->data + par->extradata_size, in->data, in->size);
>      } else {
>          av_packet_move_ref(out, in);
>      }
> 



More information about the ffmpeg-devel mailing list