[FFmpeg-devel] [PATCH]lavfi/avfiltergraph: Do not return ENOMEM if filter is missing

James Almer jamrial at gmail.com
Mon Feb 5 17:46:00 EET 2018

On 2/5/2018 12:22 PM, Nicolas George wrote:
> James Almer (2018-02-04):
>> -1 is not acceptable for a public function that states it returns an
>> AVERROR value on failure.
>> If the issue is that avfilter_graph_alloc_filter() may fail because of
>> both OOM and an invalid value for filter, then I'm more inclined to use
>> AVERROR_UNKNOWN here instead.
> Sounds reasonable.
>> That being said, based on the above the return value of
>> avfilter_graph_alloc_filter() should have never been an AVFilterContext,
>> but an int instead.
>> Maybe a new function that returns a proper AVERROR value should be
>> whatever corresponds depending on the type of failure.
> I agree.
> In fact, would you support me if I propose to add the following policy:?
> 	Any new function av_something_alloc() should have an API:
> 	ret = av_something_alloc(&ptr, params);
> 	and not:
> 	ptr = av_something_alloc(params);
> even if it can, for the time being, only return AVERROR(ENOMEM).
> Regards,

If it takes a parameter like the type of "something" you want to alloc
then yes, I'd support that policy as there's no way to prevent the
argument passed from being invalid, so NULL in that case will not mean
But if there's no parameters at all, or if the parameter is a size one,
then the failure can only be OOM. In those cases I prefer the latter as
it's more versatile in some situations, like using the function itself
as an argument when calling another function.

More information about the ffmpeg-devel mailing list