[FFmpeg-devel] [PATCH 3/4] avcodec/filter_units_bsf: Use separate contexts for reading/writing

James Almer jamrial at gmail.com
Fri Jul 17 02:53:11 EEST 2020


On 7/16/2020 8:05 PM, Mark Thompson wrote:
> On 08/07/2020 02:29, James Almer wrote:
>> Based on code from 235a5734e0
>>
>> Signed-off-by: James Almer <jamrial at gmail.com>
>> ---
>>   libavcodec/filter_units_bsf.c | 23 ++++++++++++++---------
>>   1 file changed, 14 insertions(+), 9 deletions(-)
>>
>> diff --git a/libavcodec/filter_units_bsf.c
>> b/libavcodec/filter_units_bsf.c
>> index 354594ac50..14960761d2 100644
>> --- a/libavcodec/filter_units_bsf.c
>> +++ b/libavcodec/filter_units_bsf.c
>> @@ -29,7 +29,8 @@
>>   typedef struct FilterUnitsContext {
>>       const AVClass *class;
>>   -    CodedBitstreamContext *cbc;
>> +    CodedBitstreamContext *input;
>> +    CodedBitstreamContext *output;
>>       CodedBitstreamFragment fragment;
>>         const char *pass_types;
>> @@ -112,7 +113,7 @@ static int filter_units_filter(AVBSFContext *bsf,
>> AVPacket *pkt)
>>       if (ctx->mode == NOOP)
>>           return 0;
>>   -    err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
>> +    err = ff_cbs_read_packet(ctx->input, frag, pkt);
>>       if (err < 0) {
>>           av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
>>           goto fail;
>> @@ -134,7 +135,7 @@ static int filter_units_filter(AVBSFContext *bsf,
>> AVPacket *pkt)
>>           goto fail;
>>       }
>>   -    err = ff_cbs_write_packet(ctx->cbc, pkt, frag);
>> +    err = ff_cbs_write_packet(ctx->output, pkt, frag);
>>       if (err < 0) {
>>           av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
>>           goto fail;
>> @@ -179,22 +180,25 @@ static int filter_units_init(AVBSFContext *bsf)
>>           return 0;
>>       }
>>   -    err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf);
>> +    err = ff_cbs_init(&ctx->input, bsf->par_in->codec_id, bsf);
>> +    if (err < 0)
>> +        return err;
>> +    err = ff_cbs_init(&ctx->output, bsf->par_in->codec_id, bsf);
>>       if (err < 0)
>>           return err;
>>         // Don't actually decompose anything, we only want the unit data.
>> -    ctx->cbc->decompose_unit_types    = ctx->type_list;
>> -    ctx->cbc->nb_decompose_unit_types = 0;
>> +    ctx->input->decompose_unit_types    = ctx->type_list;
>> +    ctx->input->nb_decompose_unit_types = 0;
>>         if (bsf->par_in->extradata) {
>>           CodedBitstreamFragment *frag = &ctx->fragment;
>>   -        err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
>> +        err = ff_cbs_read_extradata(ctx->input, frag, bsf->par_in);
>>           if (err < 0) {
>>               av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
>>           } else {
>> -            err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag);
>> +            err = ff_cbs_write_extradata(ctx->output, bsf->par_out,
>> frag);
>>               if (err < 0)
>>                   av_log(bsf, AV_LOG_ERROR, "Failed to write
>> extradata.\n");
>>           }
>> @@ -212,7 +216,8 @@ static void filter_units_close(AVBSFContext *bsf)
>>       av_freep(&ctx->type_list);
>>         ff_cbs_fragment_free(&ctx->fragment);
>> -    ff_cbs_close(&ctx->cbc);
>> +    ff_cbs_close(&ctx->input);
>> +    ff_cbs_close(&ctx->output);
>>   }
>>     #define OFFSET(x) offsetof(FilterUnitsContext, x)
>>
> 
> Given that it never decomposes anything, I don't think that has any
> effect?

Mmh, you're right. Should have realized it when i looked at the
decompose disabling part and noticed i didn't need to duplicate it.

>  Possibly it's a good idea to be consistent anyway - I don't
> really mind.
> 
> The other three patches in this series look right to me in any case.

Will push the rest and drop this one. Thanks.

> 
> Thanks,
> 
> - Mark
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-devel mailing list