saorsa_webrtc_codecs/
lib.rs1#![deny(clippy::panic)]
2#![deny(clippy::unwrap_used)]
3#![deny(clippy::expect_used)]
4#![deny(unsafe_code)]
5
6pub mod openh264;
35pub mod opus;
36
37use bytes::Bytes;
38
39#[derive(Debug, thiserror::Error)]
41pub enum CodecError {
42 #[error("Dimension mismatch: frame ({frame_width}x{frame_height}) vs config ({cfg_width}x{cfg_height})")]
43 DimensionMismatch {
44 frame_width: u32,
45 frame_height: u32,
46 cfg_width: u32,
47 cfg_height: u32,
48 },
49 #[error("Invalid codec data: {0}")]
50 InvalidData(&'static str),
51 #[error("Numeric overflow in codec operation")]
52 Overflow,
53 #[error("Codec initialization failed: {0}")]
54 InitFailed(String),
55 #[error("Feature not implemented: {0}")]
56 NotImplemented(&'static str),
57 #[error("Invalid dimensions: width={0}, height={1}")]
58 InvalidDimensions(u32, u32),
59 #[error("Data size exceeds maximum allowed: {actual} > {max}")]
60 SizeExceeded { actual: usize, max: usize },
61}
62
63pub type Result<T> = std::result::Result<T, CodecError>;
65
66pub const MAX_WIDTH: u32 = 8192;
68pub const MAX_HEIGHT: u32 = 8192;
69pub const MAX_RGB_SIZE: usize = 100 * 1024 * 1024; #[derive(Debug, Clone, Copy)]
73pub enum VideoCodec {
74 H264,
75}
76
77#[derive(Debug, Clone, Copy)]
79pub enum AudioCodec {
80 Opus,
81}
82
83#[derive(Debug, Clone)]
85pub struct VideoFrame {
86 pub data: Vec<u8>,
87 pub width: u32,
88 pub height: u32,
89 pub timestamp: u64,
90}
91
92pub trait VideoEncoder: Send + Sync {
94 fn encode(&mut self, frame: &VideoFrame) -> Result<Bytes>;
95 fn request_keyframe(&mut self);
96}
97
98pub trait VideoDecoder: Send + Sync {
100 fn decode(&mut self, data: &[u8]) -> Result<VideoFrame>;
101}
102
103pub use openh264::{OpenH264Decoder, OpenH264Encoder};
104pub use opus::{AudioFrame, Channels, OpusDecoder, OpusEncoder, OpusEncoderConfig, SampleRate};