#![warn(missing_docs)]
pub mod common;
pub mod dec;
pub mod enc;
pub mod image;
pub use crate::common::StreamInfo;
pub use crate::dec::{DecodedImage, DecodedImageData, Decoder, DecoderConfig};
pub use crate::enc::{
CompressedFrame, Encoder, EncoderConfig, EncoderFlags, EncoderFrameFlags,
EncodingDeadline, Packet, RateControl, Timebase,
};
pub use crate::image::{ImageFormat, YUVImageData, YUVImageDataOwned};
pub use vpx_sys;
#[doc(hidden)]
#[macro_export]
macro_rules! call_vpx_ptr {
($e: expr, $errenum: expr $(,)?) => {{
#[allow(clippy::macro_metavars_in_unsafe)]
let retval = unsafe { $e };
if !retval.is_null() {
Ok(retval)
} else {
Err($errenum)
}
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! call_vpx {
($e: expr, $errenum: expr $(,)?) => {{
#[allow(clippy::macro_metavars_in_unsafe)]
let err: vpx_sys::vpx_codec_err_t = unsafe { $e };
if err == vpx_sys::VPX_CODEC_OK {
Ok(())
} else {
Err($errenum(err, unsafe {
std::ffi::CStr::from_ptr(vpx_sys::vpx_codec_err_to_string(err))
.to_string_lossy()
.to_string()
}))
}
}};
}
#[derive(Clone, Debug, thiserror::Error, PartialEq, Eq, Hash)]
pub enum Error {
#[error("Codec interface not available")]
CodecInterfaceNotAvailable,
#[error("Codec control call failed: {0:?}: {1}")]
CodecControlFailed(vpx_sys::vpx_codec_err_t, String),
#[error("Failed to initialize the encoder configuration: {0:?}: {1}")]
EncoderConfigInitFailed(vpx_sys::vpx_codec_err_t, String),
#[error("Codec initialization failed with code {0:?}: {1}")]
VpxCodecInitFailed(vpx_sys::vpx_codec_err_t, String),
#[error("Unsupported rate control mode for this codec")]
UnsupportedRateControlMode,
#[error("Error wrapping YUV image")]
ErrorWrappingImage,
#[error("VPX encode failed with {0:?}: {1}")]
ErrorEncodingImage(vpx_sys::vpx_codec_err_t, String),
#[error("Error decoding bitstream: {0:?}: {1}")]
ErrorDecodingBitstream(vpx_sys::vpx_codec_err_t, String),
#[error("Invalid image format ({0:?})")]
InvalidImageFormat(vpx_sys::vpx_img_fmt),
#[error(
"Image data has bad length, expected: {expected}, received: {received}"
)]
ImageDataBadLength {
expected: usize,
received: usize,
},
#[error("Image width isn't a multiple of 2")]
WidthNotMultipleOfTwo,
#[error("Image height isn't a multiple of 2")]
HeightNotMultipleOfTwo,
#[error("Invalid profile selected for codec")]
InvalidProfileSelected,
}
pub type Result<T> = ::core::result::Result<T, Error>;
pub(crate) struct NoDebugWrapper<T: 'static>(T);
impl<T: 'static> std::fmt::Debug for NoDebugWrapper<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::any::TypeId::of::<T>().fmt(f)
}
}