util/time: add time helpers

This commit is contained in:
meh 2015-05-26 20:36:27 +02:00
parent df52ef68d8
commit 883654ebda
3 changed files with 31 additions and 0 deletions

View File

@ -13,6 +13,7 @@ pub use util::media;
pub use util::picture;
pub use util::color;
pub use util::chroma;
pub use util::time;
pub use util::frame::{self, Frame};
#[cfg(feature = "format")]

View File

@ -7,6 +7,7 @@ pub mod color;
pub mod format;
pub mod frame;
pub mod chroma;
pub mod time;
use std::ffi::CStr;
use std::str::from_utf8_unchecked;

29
src/util/time.rs Normal file
View File

@ -0,0 +1,29 @@
use ffi::*;
use ::Error;
pub fn current() -> i64 {
unsafe {
av_gettime() as i64
}
}
pub fn relative() -> i64 {
unsafe {
av_gettime_relative() as i64
}
}
pub fn is_monotonic() -> bool {
unsafe {
av_gettime_relative_is_monotonic() != 0
}
}
pub fn sleep(usec: u32) -> Result<(), Error> {
unsafe {
match av_usleep(usec) {
0 => Ok(()),
e => Err(Error::from(e))
}
}
}