Skip to main content

oximedia_codec/
lib.rs

1//! Audio and video codec implementations for `OxiMedia`.
2//!
3//! This crate provides encoding and decoding for royalty-free codecs:
4//!
5//! ## Video Codecs
6//!
7//! - **AV1** - Alliance for Open Media codec (primary)
8//! - **VP9** - Google's royalty-free codec
9//! - **VP8** - Google's earlier royalty-free codec
10//! - **Theora** - Xiph.Org Foundation codec (VP3-based)
11//!
12//! ## Audio Codecs
13//!
14//! - **Opus** - Modern low-latency audio codec
15//!
16//! # Architecture
17//!
18//! All codecs implement unified traits:
19//!
20//! - [`VideoDecoder`] - Decode compressed packets to frames
21//! - [`VideoEncoder`] - Encode frames to compressed packets
22//!
23//! # Example
24//!
25//! ```ignore
26//! use oximedia_codec::{VideoDecoder, Av1Decoder};
27//!
28//! let mut decoder = Av1Decoder::new(&codec_params)?;
29//! decoder.send_packet(&packet)?;
30//! while let Some(frame) = decoder.receive_frame()? {
31//!     // Process decoded frame
32//! }
33//! ```
34//!
35//! # Audio Example
36//!
37//! ```ignore
38//! use oximedia_codec::opus::OpusDecoder;
39//!
40//! let mut decoder = OpusDecoder::new(48000, 2)?;
41//! let audio_frame = decoder.decode_packet(&packet_data)?;
42//! ```
43
44#![deny(unsafe_code)]
45#![warn(missing_docs)]
46#![allow(clippy::unused_self)]
47#![allow(clippy::missing_errors_doc)]
48#![allow(clippy::unnecessary_wraps)]
49#![allow(clippy::must_use_candidate)]
50#![allow(clippy::match_same_arms)]
51#![allow(clippy::needless_pass_by_value)]
52#![allow(clippy::doc_markdown)]
53#![allow(clippy::cast_precision_loss)]
54#![allow(clippy::cast_possible_wrap)]
55#![allow(clippy::cast_lossless)]
56#![allow(clippy::trivially_copy_pass_by_ref)]
57#![allow(clippy::unnecessary_cast)]
58#![allow(clippy::struct_field_names)]
59#![allow(clippy::self_assignment)]
60#![allow(clippy::redundant_else)]
61#![allow(clippy::no_effect_underscore_binding)]
62#![allow(clippy::needless_range_loop)]
63#![allow(clippy::missing_panics_doc)]
64#![allow(clippy::map_unwrap_or)]
65#![allow(clippy::manual_div_ceil)]
66#![allow(clippy::if_not_else)]
67#![allow(clippy::derivable_impls)]
68#![allow(clippy::bool_to_int_with_if)]
69#![allow(unused_variables)]
70#![allow(unused_imports)]
71// Additional clippy allows for codec implementation
72#![allow(clippy::unreadable_literal)]
73#![allow(clippy::cast_possible_truncation)]
74#![allow(clippy::cast_sign_loss)]
75#![allow(clippy::similar_names)]
76#![allow(clippy::many_single_char_names)]
77#![allow(clippy::uninlined_format_args)]
78#![allow(clippy::field_reassign_with_default)]
79#![allow(clippy::manual_range_contains)]
80#![allow(clippy::too_many_arguments)]
81#![allow(clippy::missing_const_for_fn)]
82#![allow(clippy::redundant_closure)]
83#![allow(clippy::wildcard_imports)]
84#![allow(clippy::explicit_iter_loop)]
85#![allow(clippy::implicit_clone)]
86#![allow(clippy::assertions_on_constants)]
87#![allow(clippy::no_effect)]
88#![allow(clippy::unnecessary_operation)]
89#![allow(clippy::collapsible_if)]
90#![allow(clippy::manual_strip)]
91#![allow(clippy::fn_params_excessive_bools)]
92#![allow(clippy::struct_excessive_bools)]
93#![allow(dead_code)]
94#![allow(clippy::missing_fields_in_debug)]
95#![allow(clippy::useless_vec)]
96#![allow(clippy::used_underscore_binding)]
97#![allow(clippy::unnecessary_unwrap)]
98#![allow(clippy::needless_late_init)]
99#![allow(clippy::never_loop)]
100#![allow(clippy::while_let_on_iterator)]
101#![allow(clippy::manual_let_else)]
102#![allow(clippy::clone_on_copy)]
103#![allow(clippy::bool_assert_comparison)]
104#![allow(clippy::overly_complex_bool_expr)]
105#![allow(clippy::double_comparisons)]
106#![allow(clippy::needless_borrow)]
107#![allow(clippy::float_cmp)]
108#![allow(clippy::manual_slice_size_calculation)]
109#![allow(clippy::option_as_ref_deref)]
110#![allow(clippy::single_match_else)]
111#![allow(clippy::cast_abs_to_unsigned)]
112#![allow(clippy::semicolon_if_nothing_returned)]
113#![allow(clippy::range_plus_one)]
114#![allow(clippy::only_used_in_recursion)]
115#![allow(clippy::iter_without_into_iter)]
116#![allow(clippy::collapsible_else_if)]
117#![allow(clippy::naive_bytecount)]
118#![allow(clippy::manual_clamp)]
119#![allow(clippy::unnecessary_literal_unwrap)]
120#![allow(clippy::default_trait_access)]
121#![allow(clippy::return_self_not_must_use)]
122#![allow(clippy::match_wildcard_for_single_variants)]
123#![allow(clippy::unnecessary_filter_map)]
124#![allow(clippy::ref_binding_to_reference)]
125#![allow(clippy::manual_memcpy)]
126#![allow(clippy::borrowed_box)]
127#![allow(clippy::needless_question_mark)]
128#![allow(clippy::type_complexity)]
129#![allow(clippy::bind_instead_of_map)]
130#![allow(clippy::redundant_closure_for_method_calls)]
131#![allow(clippy::ref_option)]
132#![allow(clippy::new_without_default)]
133#![allow(clippy::erasing_op)]
134#![allow(clippy::identity_op)]
135#![allow(clippy::op_ref)]
136#![allow(clippy::manual_flatten)]
137#![allow(clippy::while_let_loop)]
138#![allow(clippy::from_over_into)]
139#![allow(clippy::match_like_matches_macro)]
140#![allow(clippy::collapsible_match)]
141#![allow(clippy::inefficient_to_string)]
142#![allow(clippy::items_after_statements)]
143#![allow(clippy::enum_glob_use)]
144#![allow(clippy::cloned_ref_to_slice_refs)]
145#![allow(clippy::verbose_bit_mask)]
146#![allow(clippy::let_and_return)]
147#![allow(clippy::if_same_then_else)]
148#![allow(clippy::comparison_chain)]
149#![allow(clippy::self_only_used_in_recursion)]
150#![allow(clippy::unnecessary_map_or)]
151
152pub mod av1_obu;
153pub mod bitrate_model;
154pub mod bitstream_writer;
155pub mod codec_caps;
156pub mod color_range;
157pub mod entropy_coding;
158pub mod error;
159pub mod frame;
160pub mod frame_types;
161pub mod gop_structure;
162pub mod hdr;
163pub mod intra;
164pub mod motion;
165pub mod multipass;
166pub mod nal_unit;
167pub mod packet_queue;
168pub mod picture_timing;
169pub mod profile_level;
170pub mod rate_control;
171pub mod reconstruct;
172pub mod reference_frames;
173pub mod simd;
174pub mod slice_header;
175pub mod stream_info;
176pub mod tile;
177pub mod tile_encoder;
178pub mod traits;
179
180// Audio support
181pub mod audio;
182
183// Standalone SILK frame decoding types
184pub mod silk;
185
186// Standalone CELT frame decoding types
187pub mod celt;
188
189// PNG codec
190pub mod png;
191
192// GIF codec
193pub mod gif;
194
195// JPEG-XL codec
196#[cfg(feature = "jpegxl")]
197pub mod jpegxl;
198
199// Image I/O support
200#[cfg(feature = "image-io")]
201pub mod image;
202
203#[cfg(feature = "av1")]
204pub mod av1;
205
206#[cfg(feature = "vp9")]
207pub mod vp9;
208
209#[cfg(feature = "vp8")]
210pub mod vp8;
211
212#[cfg(feature = "theora")]
213pub mod theora;
214
215#[cfg(feature = "h263")]
216pub mod h263;
217
218#[cfg(feature = "opus")]
219pub mod opus;
220
221#[cfg(feature = "ffv1")]
222pub mod ffv1;
223
224// Re-exports
225pub use audio::{AudioFrame, ChannelLayout, SampleFormat};
226pub use error::{CodecError, CodecResult};
227pub use frame::{
228    ColorInfo, ColorPrimaries, FrameType, MatrixCoefficients, Plane, TransferCharacteristics,
229    VideoFrame,
230};
231pub use multipass::{
232    allocation::AllocationStrategy, Allocator, Analyzer, Buffer, BufferConfig, ComplexityStats,
233    EncoderConfig as MultiPassConfig, EncoderError, EncodingResult, FrameAllocation,
234    FrameComplexity, LookaheadAnalysis, LookaheadFrame, MultiPassEncoder, PassStats, PassType,
235    SceneChangeDetector, Stats, VbvStatistics,
236};
237pub use rate_control::{
238    AdaptiveQuantization, AllocationResult, AnalysisResult, AqMode, BitrateAllocator, BlockQpMap,
239    BufferModel, CbrController, ComplexityEstimator, ContentAnalyzer, ContentType, CqpController,
240    CrfController, FrameStats, GopAllocationStatus, GopStats, Lookahead, QpResult, QpSelector,
241    QpStrategy, RateControlMode, RateController, RcConfig, RcOutput, SceneChangeThreshold,
242    TextureMetrics, VbrController,
243};
244pub use reconstruct::{
245    BufferPool, CdefApplicator, CdefBlockConfig, CdefFilterResult, ChromaSubsampling,
246    DeblockFilter, DeblockParams, DecoderPipeline, EdgeFilter, FilmGrainParams,
247    FilmGrainSynthesizer, FilterDirection, FilterStrength, FrameBuffer, GrainBlock,
248    LoopFilterPipeline, OutputConfig, OutputFormat, OutputFormatter, PipelineConfig, PipelineStage,
249    PlaneBuffer, PlaneType, ReconstructResult, ReconstructionError, ResidualBuffer, ResidualPlane,
250    StageResult, SuperResConfig, SuperResUpscaler, UpscaleMethod,
251};
252pub use tile::{
253    assemble_tiles, decode_tile_stream, HeaderedTileEncodeOp, RawLumaEncodeOp, TileConfig,
254    TileCoord, TileEncodeOp, TileEncodeStats, TileEncoder, TileResult,
255};
256pub use traits::{
257    BitrateMode, DecoderConfig, EncodedPacket, EncoderConfig, EncoderPreset, VideoDecoder,
258    VideoEncoder,
259};
260
261#[cfg(feature = "av1")]
262pub use av1::{Av1Decoder, Av1Encoder};
263
264#[cfg(feature = "vp9")]
265pub use vp9::Vp9Decoder;
266
267#[cfg(feature = "vp8")]
268pub use vp8::Vp8Decoder;
269
270#[cfg(feature = "theora")]
271pub use theora::{TheoraConfig, TheoraDecoder, TheoraEncoder};
272
273#[cfg(feature = "h263")]
274pub use h263::{H263Decoder, H263Encoder, PictureFormat};
275
276#[cfg(feature = "opus")]
277pub use opus::{OpusDecoder, OpusEncoder, OpusEncoderConfig};
278
279#[cfg(feature = "ffv1")]
280pub use ffv1::{Ffv1Decoder, Ffv1Encoder};
281
282#[cfg(feature = "image-io")]
283pub use image::{
284    convert_rgb_to_yuv420p, convert_yuv420p_to_rgb, rgb_to_yuv, yuv_to_rgb,
285    EncoderConfig as ImageEncoderConfig, ImageDecoder, ImageEncoder, ImageFormat,
286};
287
288pub use png::{
289    batch_encode as batch_encode_png, best_encoder, decode as decode_png,
290    encode_grayscale as encode_png_grayscale, encode_rgb as encode_png_rgb,
291    encode_rgba as encode_png_rgba, encoder_from_profile, fast_encoder, get_info as png_info,
292    is_png, optimize as optimize_png, transcode as transcode_png, validate as validate_png,
293    Chromaticity, ColorType as PngColorType, CompressionLevel as PngCompressionLevel,
294    DecodedImage as PngImage, EncoderBuilder as PngEncoderBuilder,
295    EncoderConfig as PngEncoderConfig, EncodingProfile, EncodingStats, FilterStrategy, FilterType,
296    ImageHeader as PngHeader, PaletteEntry, PaletteOptimizer, ParallelPngEncoder,
297    PhysicalDimensions, PngDecoder, PngDecoderExtended, PngEncoder, PngEncoderExtended, PngInfo,
298    PngMetadata, SignificantBits, TextChunk,
299};
300
301pub use gif::{
302    is_gif, DisposalMethod, DitheringMethod, GifDecoder, GifEncoder, GifEncoderConfig, GifFrame,
303    GifFrameConfig, GraphicsControlExtension, ImageDescriptor, LogicalScreenDescriptor,
304    QuantizationMethod,
305};
306
307#[cfg(feature = "jpegxl")]
308pub use jpegxl::{
309    AnsDecoder, AnsDistribution, AnsEncoder, BitReader as JxlBitReader, BitWriter as JxlBitWriter,
310    DecodedImage as JxlImage, JxlColorSpace, JxlConfig, JxlDecoder, JxlEncoder, JxlFrameEncoding,
311    JxlHeader, ModularDecoder, ModularEncoder,
312};