• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use libc::c_int;
6 
7 // Equivalent of FFmpeg's `FFERRTAG` macro to generate error codes.
8 #[allow(non_snake_case)]
FFERRTAG(tag: &[u8; 4]) -> c_int9 const fn FFERRTAG(tag: &[u8; 4]) -> c_int {
10     -(tag[0] as c_int | (tag[1] as c_int) << 8 | (tag[2] as c_int) << 16 | (tag[3] as c_int) << 24)
11 }
12 
13 pub const AVERROR_EOF: c_int = FFERRTAG(b"EOF ");
14 pub const AVERROR_INVALIDDATA: c_int = FFERRTAG(b"INDA");
15 pub const AVERROR_EAGAIN: c_int = -11;
16 
17 #[cfg(test)]
18 mod test {
19     use libc::c_char;
20 
21     use super::*;
22     use crate::ffi;
23 
test_averror(averror: c_int, expected_message: &str)24     fn test_averror(averror: c_int, expected_message: &str) {
25         let mut buffer = [0u8; 255];
26         let ret = unsafe {
27             ffi::av_strerror(
28                 averror,
29                 buffer.as_mut_ptr() as *mut c_char,
30                 buffer.len() as usize,
31             )
32         };
33         assert_eq!(ret, 0);
34 
35         let end_of_string = buffer.iter().position(|i| *i == 0).unwrap_or(buffer.len());
36         let error_string = std::str::from_utf8(&buffer[0..end_of_string]).unwrap();
37         assert_eq!(error_string, expected_message);
38     }
39 
40     #[test]
41     // Check that we got our error bindings correctly.
test_error_bindings()42     fn test_error_bindings() {
43         test_averror(AVERROR_EOF, "End of file");
44         test_averror(
45             AVERROR_INVALIDDATA,
46             "Invalid data found when processing input",
47         );
48         test_averror(AVERROR_EAGAIN, "Resource temporarily unavailable");
49     }
50 }
51