[FFmpeg-devel] Meaningful return codes (was [PATCH 7/9] Replace AVERROR_NOTSUPP by AVERROR(ENOSYS))

François Revol revol
Sat Jul 21 00:46:41 CEST 2007


> I am not saying we'd have to do that. But maybe we could  
> differentiate in some way between different classes of problems.  
> Maybe that's not even needed and we only need to return EINVAL in the  
> cases you describe above, but _certainly_ I think we need to do  
> something different from returning -1 in any case of failure.
> 


I feel obliged to speak on the matter as I was the one who redefined 
AVERROR_* to POSIX errors.

Thing is, libav* was already returning POSIX error codes in most cases, 
those codes were only used in some places. Sometimes also just -1 was 
returned.
When adding the fix for BeOS (where POSIX errors are already negative), 
I changed those to what seemed the closest POSIX code.

There is no way to split the error namespace to stuff either the POSIX 
errors or other specific errors because you can't know the values for 
POSIX errors. (libusb wrongly uses an arbitrary value of 50000 or 
something somewhere... nasty).

On BeOS the POSIX errors are a subset of all system errors, defined 
like this:
#define B_GENERAL_ERROR_BASE            LONG_MIN
#define B_OS_ERROR_BASE                         B_GENERAL_ERROR_BASE + 
0x1000
#define B_APP_ERROR_BASE                        B_GENERAL_ERROR_BASE + 
0x2000
...
#define B_STORAGE_ERROR_BASE            B_GENERAL_ERROR_BASE + 0x6000
#define B_POSIX_ERROR_BASE                      B_GENERAL_ERROR_BASE + 
0x7000
...
#define E2BIG                   (B_POSIX_ERROR_BASE + 1)
#define ECHILD                  (B_POSIX_ERROR_BASE + 2)
...
#define ENOMEM                  B_NO_MEMORY
#define EACCES                  B_PERMISSION_DENIED
Where they either map to a reserved part of the namespace, or existing 
system error.
I think it's the same on win32.
It could be possible to map to non-posix system errors, but it would be 
OS-dependant, which is too much hasle for not much profit.

/*--- Developer-defined errors start at (B_ERRORS_END+1)----*/
#define B_ERRORS_END            (B_GENERAL_ERROR_BASE + 0xffff)
We could use unreserved parts of the namespace though to map extra 
errors, like:

#define AVERROR_NOMEM AVERROR(ENOMEM)
#define AVERROR_NONUM (AVERROR_BASE+0)
#define AVERROR_FMT (AVERROR_BASE+1)

with AVERROR_BASE defined in os_support.h to be in the unreserved part 
of the codes.
On Unix that could be something like libusb's 50000...

But all this is probably overkill.

As for undefined error, EINVAL is probably generic enough, didn't find 
better.

Fran?ois.





More information about the ffmpeg-devel mailing list