[FFmpeg-devel] [PATCH 1/2] avfilter/all: propagate errors of functions from avfilter/formats

Ganesh Ajjanagadde gajjanag at mit.edu
Tue Oct 6 18:45:47 CEST 2015


On Tue, Oct 6, 2015 at 10:40 AM, Nicolas George <george at nsup.org> wrote:
> Le quartidi 14 vendémiaire, an CCXXIV, Ganesh Ajjanagadde a écrit :
>> -    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
>> +    if (!layouts)
>> +        return AVERROR(ENOMEM);
>> +    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0) {
>> +        ff_channel_layouts_unref(&layouts);
>> +        return ret;
>
> This is a pattern that comes frequently, there is probably room for code
> factorization.
>
> How about this: currently, ff_formats_ref() and cousins reject NULL with
> AVERROR_BUG. If it is changed to return AVERROR(ENOMEM) instead, then all
> the "if (!formats) return AVERROR(ENOMEM);" become unnecessary.
>
> Second, if ff_formats_ref() is changed to unref the format list on failure,
> then all the unref become unnecessary. The changed code would be just:
>
>      layouts = ff_all_channel_counts();
> -    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
> +    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
> +        return ret;
>
> That is rather less cluttered.
>
> What do you think about this?

That is a good idea. I had some similar ideas, but did not implement
them as I am not a avfilter expert, and did not know whether changing
the behavior of ff_formats_ref and the like would be acceptable.

I can do the necessary refactoring, but please bear in mind that I am
busy over the next few days. Depending on the criticality of this (and
the relevant CID's), one of you can go ahead and refactor in the best
way possible. In fact, it could lead to less wasted effort overall due
to the better expertise with libavfilter.

>
> Regards,
>
> --
>   Nicolas George
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list