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