[FFmpeg-devel] [PATCH v3 2/3] avormat/av1dec: add low-overhead bitstream format

Martin Storsjö martin at martin.st
Thu Aug 13 22:25:10 EEST 2020


On Thu, 13 Aug 2020, James Almer wrote:

> On 8/13/2020 3:51 AM, Xu Guangxin wrote:

>> +
>> +    ret = obu_prefetch(s, header, MAX_OBU_HEADER_SIZE);
>> +    if (!ret)
>> +        return AVERROR(EOF);
>
> We use AVERROR_EOF rather than AVERROR(EOF) (Afair, it was done because
> EOF is not portable, but don't quote me on it).

Actually, it's a more severe thing than that.

AVERROR() is used for mapping an errno style error code, EINVAL etc, which 
can be either positive or negative numbers depending on platforms, to the 
AVERROR range (which is negative numbers).

So AVERROR() actually is shorthand for ERRNO_CODE_TO_AVERROR(). On 
platforms where errno codes are positive (most common modern platforms 
except BeOS/Haiku, iirc), it's essentially defined as (-(x)).

Now EOF isn't an errno error code, and is defined to be a negative value 
(often -1). So if you do AVERROR(EOF) on a system where errno codes are 
positive, AVERROR(EOF) evalues to +1, which most caller would 
identify as not an error at all.

TL;DR: AVERROR(EOF) is never correct.

// Martin



More information about the ffmpeg-devel mailing list