Skip to content

Commit

Permalink
Add err2str mirroring av_err2str (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 authored Jan 7, 2024
1 parent e378e80 commit d728f53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/avutil/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::ffi;
use rusty_ffmpeg::ffi::AV_ERROR_MAX_STRING_SIZE;
use std::ffi::{c_int, CStr};

/// Return a description of the AVERROR code errnum.
///
/// Return `Some(description)` on success, a negative value if a description for
/// errnum cannot be found.
pub fn err2str(errnum: c_int) -> Option<String> {
const ERRBUF_SIZE: usize = AV_ERROR_MAX_STRING_SIZE as usize;
let mut errbuf = [0u8; ERRBUF_SIZE];
if unsafe { ffi::av_strerror(errnum, errbuf.as_mut_ptr() as _, ERRBUF_SIZE) } == 0 {
let result = CStr::from_bytes_until_nul(&errbuf).unwrap();
Some(result.to_string_lossy().into_owned())
} else {
None
}
}
2 changes: 2 additions & 0 deletions src/avutil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
mod audio_fifo;
mod channel_layout;
mod dict;
mod error;
mod file;
mod frame;
mod imgutils;
Expand All @@ -18,6 +19,7 @@ mod timestamp;
pub use audio_fifo::*;
pub use channel_layout::*;
pub use dict::*;
pub use error::*;
pub use file::*;
pub use frame::*;
pub use imgutils::*;
Expand Down

0 comments on commit d728f53

Please sign in to comment.