Skip to main content

ffmpeg_sys_the_third/avutil/
error.rs

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
21#[inline(always)]
22pub const fn MKTAG(a: u8, b: u8, c: u8, d: u8) -> u32 {
23    u32::from_le_bytes([a, b, c, d])
24}
25
26#[inline(always)]
27pub const fn MKBETAG(a: u8, b: u8, c: u8, d: u8) -> u32 {
28    u32::from_be_bytes([a, b, c, d])
29}
30
31#[inline(always)]
32pub const fn FFERRTAG(a: u8, b: u8, c: u8, d: u8) -> c_int {
33    let tag = MKTAG(a, b, c, d);
34    assert!(c_int::MAX as u32 >= tag, "error tag must fit inside c_int");
35
36    -(tag as c_int)
37}
38
39pub const AVERROR_BSF_NOT_FOUND: c_int = FFERRTAG(0xF8, b'B', b'S', b'F');
40pub const AVERROR_BUG: c_int = FFERRTAG(b'B', b'U', b'G', b'!');
41pub const AVERROR_BUFFER_TOO_SMALL: c_int = FFERRTAG(b'B', b'U', b'F', b'S');
42pub const AVERROR_DECODER_NOT_FOUND: c_int = FFERRTAG(0xF8, b'D', b'E', b'C');
43pub const AVERROR_DEMUXER_NOT_FOUND: c_int = FFERRTAG(0xF8, b'D', b'E', b'M');
44pub const AVERROR_ENCODER_NOT_FOUND: c_int = FFERRTAG(0xF8, b'E', b'N', b'C');
45pub const AVERROR_EOF: c_int = FFERRTAG(b'E', b'O', b'F', b' ');
46pub const AVERROR_EXIT: c_int = FFERRTAG(b'E', b'X', b'I', b'T');
47pub const AVERROR_EXTERNAL: c_int = FFERRTAG(b'E', b'X', b'T', b' ');
48pub const AVERROR_FILTER_NOT_FOUND: c_int = FFERRTAG(0xF8, b'F', b'I', b'L');
49pub const AVERROR_INVALIDDATA: c_int = FFERRTAG(b'I', b'N', b'D', b'A');
50pub const AVERROR_MUXER_NOT_FOUND: c_int = FFERRTAG(0xF8, b'M', b'U', b'X');
51pub const AVERROR_OPTION_NOT_FOUND: c_int = FFERRTAG(0xF8, b'O', b'P', b'T');
52pub const AVERROR_PATCHWELCOME: c_int = FFERRTAG(b'P', b'A', b'W', b'E');
53pub const AVERROR_PROTOCOL_NOT_FOUND: c_int = FFERRTAG(0xF8, b'P', b'R', b'O');
54
55pub const AVERROR_STREAM_NOT_FOUND: c_int = FFERRTAG(0xF8, b'S', b'T', b'R');
56
57pub const AVERROR_BUG2: c_int = FFERRTAG(b'B', b'U', b'G', b' ');
58pub const AVERROR_UNKNOWN: c_int = FFERRTAG(b'U', b'N', b'K', b'N');
59
60pub const AVERROR_HTTP_BAD_REQUEST: c_int = FFERRTAG(0xF8, b'4', b'0', b'0');
61pub const AVERROR_HTTP_UNAUTHORIZED: c_int = FFERRTAG(0xF8, b'4', b'0', b'1');
62pub const AVERROR_HTTP_FORBIDDEN: c_int = FFERRTAG(0xF8, b'4', b'0', b'3');
63pub const AVERROR_HTTP_NOT_FOUND: c_int = FFERRTAG(0xF8, b'4', b'0', b'4');
64pub const AVERROR_HTTP_OTHER_4XX: c_int = FFERRTAG(0xF8, b'4', b'X', b'X');
65pub const AVERROR_HTTP_SERVER_ERROR: c_int = FFERRTAG(0xF8, b'5', b'X', b'X');
66
67#[inline(always)]
68pub unsafe fn av_make_error_string(
69    errbuf: *mut c_char,
70    errbuf_size: size_t,
71    errnum: c_int,
72) -> *mut c_char {
73    crate::av_strerror(errnum, errbuf, errbuf_size);
74
75    errbuf
76}