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 avif;
154pub mod bitrate_model;
155pub mod bitstream_filter;
156pub mod bitstream_writer;
157pub mod codec_caps;
158pub mod codec_probe;
159pub mod codec_profile;
160pub mod codec_registry;
161pub mod color_range;
162pub mod entropy_coding;
163pub mod entropy_tables;
164pub mod error;
165pub mod error_concealment;
166pub mod features;
167pub mod flac_codec;
168pub mod frame;
169pub mod frame_queue;
170pub mod frame_types;
171pub mod gop_structure;
172pub mod hdr;
173pub mod intra;
174pub mod motion;
175pub mod multipass;
176pub mod multipass_quality;
177pub mod nal_unit;
178pub mod packet_builder;
179pub mod packet_queue;
180pub mod packet_splitter;
181pub mod picture_timing;
182pub mod profile_level;
183pub mod psycho_visual;
184pub mod quality_metrics;
185pub mod rate_control;
186pub mod rate_control_accuracy;
187pub mod reconstruct;
188pub mod reference_frames;
189pub mod scene_change_idr;
190pub mod sei_nal;
191pub mod simd;
192pub mod slice_header;
193pub mod stats;
194pub mod stream_info;
195pub mod tile;
196pub mod tile_encoder;
197pub mod traits;
198pub mod vbr_twopass;
199
200// Audio support
201pub mod audio;
202
203// Standalone SILK frame decoding types
204pub mod silk;
205
206// Standalone CELT frame decoding types
207pub mod celt;
208
209// PNG codec
210pub mod png;
211
212// APNG (Animated PNG) top-level encoder/decoder
213pub mod apng;
214
215// Vorbis audio codec (encoder + decoder)
216pub mod vorbis;
217pub use vorbis::{
218    SimpleVorbisEncoder, VorbisConfig, VorbisEncConfig, VorbisEncoder, VorbisPacket, VorbisQuality,
219};
220
221// FLAC lossless audio codec (encoder + decoder)
222pub mod flac;
223
224// PCM raw audio codec (encoder + decoder)
225pub mod pcm;
226
227// GIF codec
228pub mod gif;
229
230// WebP codec
231pub mod webp;
232
233// JPEG-XL codec
234#[cfg(feature = "jpegxl")]
235pub mod jpegxl;
236
237// Image I/O support
238#[cfg(feature = "image-io")]
239pub mod image;
240
241#[cfg(feature = "av1")]
242pub mod av1;
243
244#[cfg(feature = "vp9")]
245pub mod vp9;
246
247#[cfg(feature = "vp8")]
248pub mod vp8;
249
250#[cfg(feature = "theora")]
251pub mod theora;
252
253#[cfg(feature = "h263")]
254pub mod h263;
255
256#[cfg(feature = "opus")]
257pub mod opus;
258
259#[cfg(feature = "ffv1")]
260pub mod ffv1;
261
262// Re-exports
263pub use audio::{AudioFrame, ChannelLayout, SampleFormat};
264pub use error::{CodecError, CodecResult};
265pub use frame::{
266    ColorInfo, ColorPrimaries, FrameType, MatrixCoefficients, Plane, TransferCharacteristics,
267    VideoFrame,
268};
269pub use multipass::{
270    allocation::AllocationStrategy, Allocator, Analyzer, Buffer, BufferConfig, ComplexityStats,
271    EncoderConfig as MultiPassConfig, EncoderError, EncodingResult, FrameAllocation,
272    FrameComplexity, LookaheadAnalysis, LookaheadFrame, MultiPassEncoder, PassStats, PassType,
273    SceneChangeDetector, Stats, VbvStatistics,
274};
275pub use rate_control::{
276    AdaptiveAllocation, AdaptiveQuantization, AllocationResult, AnalysisResult, AqMode,
277    BitrateAllocator, BlockQpMap, BufferModel, CbrController, ComplexityEstimator,
278    ContentAdaptiveAllocator, ContentAnalyzer, ContentMetrics, ContentType, CqpController,
279    CrfController, FrameStats, GopAllocationStatus, GopStats, Lookahead, QpResult, QpSelector,
280    QpStrategy, RateControlMode, RateController, RcConfig, RcOutput,
281    SceneChangeDetector as RcSceneChangeDetector, SceneChangeThreshold, SceneContentType,
282    TextureMetrics, VbrController,
283};
284pub use reconstruct::{
285    BufferPool, CdefApplicator, CdefBlockConfig, CdefFilterResult, ChromaSubsampling,
286    DeblockFilter, DeblockParams, DecoderPipeline, EdgeFilter, FilmGrainParams,
287    FilmGrainSynthesizer, FilterDirection, FilterStrength, FrameBuffer, GrainBlock,
288    LoopFilterPipeline, OutputConfig, OutputFormat, OutputFormatter, PipelineConfig, PipelineStage,
289    PlaneBuffer, PlaneType, ReconstructResult, ReconstructionError, ResidualBuffer, ResidualPlane,
290    StageResult, SuperResConfig, SuperResUpscaler, UpscaleMethod,
291};
292pub use tile::{
293    assemble_tiles, decode_tile_stream, decode_tiles_parallel, HeaderedTileEncodeOp,
294    RawLumaEncodeOp, TileConfig, TileCoord, TileDecodeOp, TileDecodeResult, TileEncodeOp,
295    TileEncodeStats, TileEncoder, TileResult,
296};
297
298pub use pcm::{ByteOrder, PcmConfig, PcmDecoder, PcmEncoder, PcmFormat};
299pub use traits::{
300    BitrateMode, DecoderConfig, EncodedPacket, EncoderConfig, EncoderPreset, VideoDecoder,
301    VideoEncoder,
302};
303
304#[cfg(feature = "av1")]
305pub use av1::{Av1Decoder, Av1Encoder};
306
307#[cfg(feature = "vp9")]
308pub use vp9::{
309    SimpleVp9Encoder, Vp9Decoder, Vp9EncConfig, Vp9Encoder, Vp9EncoderConfig, Vp9Packet, Vp9Profile,
310};
311
312#[cfg(feature = "vp8")]
313pub use vp8::{
314    SimpleVp8Encoder, Vp8Decoder, Vp8EncConfig, Vp8Encoder, Vp8EncoderConfig, Vp8Packet,
315};
316
317#[cfg(feature = "theora")]
318pub use theora::{TheoraConfig, TheoraDecoder, TheoraEncoder};
319
320#[cfg(feature = "h263")]
321pub use h263::{H263Decoder, H263Encoder, PictureFormat};
322
323#[cfg(feature = "opus")]
324pub use opus::{OpusDecoder, OpusEncoder, OpusEncoderConfig};
325
326#[cfg(feature = "ffv1")]
327pub use ffv1::{Ffv1Decoder, Ffv1Encoder};
328
329#[cfg(feature = "image-io")]
330pub use image::{
331    convert_rgb_to_yuv420p, convert_yuv420p_to_rgb, rgb_to_yuv, yuv_to_rgb,
332    EncoderConfig as ImageEncoderConfig, ImageDecoder, ImageEncoder, ImageFormat,
333};
334
335pub use png::{
336    batch_encode as batch_encode_png, best_encoder, decode as decode_png,
337    encode_grayscale as encode_png_grayscale, encode_rgb as encode_png_rgb,
338    encode_rgba as encode_png_rgba, encoder_from_profile, fast_encoder, get_info as png_info,
339    is_png, optimize as optimize_png, transcode as transcode_png, validate as validate_png,
340    Chromaticity, ColorType as PngColorType, CompressionLevel as PngCompressionLevel,
341    DecodedImage as PngImage, EncoderBuilder as PngEncoderBuilder,
342    EncoderConfig as PngEncoderConfig, EncodingProfile, EncodingStats, FilterStrategy, FilterType,
343    ImageHeader as PngHeader, PaletteEntry, PaletteOptimizer, ParallelPngEncoder,
344    PhysicalDimensions, PngDecoder, PngDecoderExtended, PngEncoder, PngEncoderExtended, PngInfo,
345    PngMetadata, SignificantBits, TextChunk,
346};
347
348pub use gif::{
349    is_gif, DisposalMethod, DitheringMethod, GifDecoder, GifEncoder, GifEncoderConfig, GifFrame,
350    GifFrameConfig, GraphicsControlExtension, ImageDescriptor, LogicalScreenDescriptor,
351    QuantizationMethod,
352};
353
354#[cfg(feature = "jpegxl")]
355pub use jpegxl::{
356    AnsDecoder, AnsDistribution, AnsEncoder, BitReader as JxlBitReader, BitWriter as JxlBitWriter,
357    DecodedImage as JxlImage, JxlColorSpace, JxlConfig, JxlDecoder, JxlEncoder, JxlFrameEncoding,
358    JxlHeader, ModularDecoder, ModularEncoder,
359};
360
361pub use avif::{AvifConfig, AvifDecoder, AvifEncoder, AvifImage, AvifProbeResult, YuvFormat};