1use libc::{c_char, c_int, size_t};
2
3// Note: FFmpeg's AVERROR and AVUNERROR are conditionally defined based on
4// whether EDOM is positive, claiming that "Some platforms have E* and errno
5// already negated". This can be traced to a commit in 2007 where "some
6// platforms" were specifically identified as BeOS (so maybe also Haiku?):
7// https://github.com/FFmpeg/FFmpeg/commit/8fa36ae09dddb1b639b4df5d505c0dbcf4e916e4
8// constness is more valuable than BeOS support, so if someone really needs it,
9// send a patch with cfg_attr.
10
11#[inline(always)]
12pub const fn AVERROR(e: c_int) -> c_int {
13 -e
14}
15
16#[inline(always)]
17pub const fn AVUNERROR(e: c_int) -> c_int {
18 -e
19}
20
21macro_rules! FFERRTAG {
22 ($a:expr, $b:expr, $c:expr, $d:expr) => {
23 -MKTAG!($a, $b, $c, $d) as c_int
24 };
25}
26
27pub const AVERROR_BSF_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'B', b'S', b'F');
28pub const AVERROR_BUG: c_int = FFERRTAG!(b'B', b'U', b'G', b'!');
29pub const AVERROR_BUFFER_TOO_SMALL: c_int = FFERRTAG!(b'B', b'U', b'F', b'S');
30pub const AVERROR_DECODER_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'D', b'E', b'C');
31pub const AVERROR_DEMUXER_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'D', b'E', b'M');
32pub const AVERROR_ENCODER_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'E', b'N', b'C');
33pub const AVERROR_EOF: c_int = FFERRTAG!(b'E', b'O', b'F', b' ');
34pub const AVERROR_EXIT: c_int = FFERRTAG!(b'E', b'X', b'I', b'T');
35pub const AVERROR_EXTERNAL: c_int = FFERRTAG!(b'E', b'X', b'T', b' ');
36pub const AVERROR_FILTER_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'F', b'I', b'L');
37pub const AVERROR_INVALIDDATA: c_int = FFERRTAG!(b'I', b'N', b'D', b'A');
38pub const AVERROR_MUXER_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'M', b'U', b'X');
39pub const AVERROR_OPTION_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'O', b'P', b'T');
40pub const AVERROR_PATCHWELCOME: c_int = FFERRTAG!(b'P', b'A', b'W', b'E');
41pub const AVERROR_PROTOCOL_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'P', b'R', b'O');
42
43pub const AVERROR_STREAM_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'S', b'T', b'R');
44
45pub const AVERROR_BUG2: c_int = FFERRTAG!(b'B', b'U', b'G', b' ');
46pub const AVERROR_UNKNOWN: c_int = FFERRTAG!(b'U', b'N', b'K', b'N');
47
48pub const AVERROR_HTTP_BAD_REQUEST: c_int = FFERRTAG!(0xF8, b'4', b'0', b'0');
49pub const AVERROR_HTTP_UNAUTHORIZED: c_int = FFERRTAG!(0xF8, b'4', b'0', b'1');
50pub const AVERROR_HTTP_FORBIDDEN: c_int = FFERRTAG!(0xF8, b'4', b'0', b'3');
51pub const AVERROR_HTTP_NOT_FOUND: c_int = FFERRTAG!(0xF8, b'4', b'0', b'4');
52pub const AVERROR_HTTP_OTHER_4XX: c_int = FFERRTAG!(0xF8, b'4', b'X', b'X');
53pub const AVERROR_HTTP_SERVER_ERROR: c_int = FFERRTAG!(0xF8, b'5', b'X', b'X');
54
55#[inline(always)]
56pub unsafe fn av_make_error_string(
57 errbuf: *mut c_char,
58 errbuf_size: size_t,
59 errnum: c_int,
60) -> *mut c_char {
61 av_strerror(errnum, errbuf, errbuf_size);
62
63 errbuf
64}
65
66extern "C" {
67 pub fn av_strerror(errnum: c_int, errbuf: *mut c_char, errbuf_size: size_t) -> c_int;
68}
69