#![allow(clippy::needless_range_loop)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::unusual_byte_groupings)]
#![allow(clippy::unnecessary_cast)]
pub mod block;
pub mod decoder;
pub mod encoder;
pub mod fdct;
pub mod gob;
pub mod idct;
pub mod mb;
pub mod picture;
pub mod quant;
pub mod start_code;
pub mod tables;
use oxideav_core::{CodecCapabilities, CodecId, CodecTag};
use oxideav_core::{CodecInfo, CodecRegistry, RuntimeContext};
pub const CODEC_ID_STR: &str = "h261";
pub fn register_codecs(reg: &mut CodecRegistry) {
let caps = CodecCapabilities::video("h261_sw")
.with_lossy(true)
.with_intra_only(false)
.with_max_size(352, 288);
reg.register(
CodecInfo::new(CodecId::new(CODEC_ID_STR))
.capabilities(caps)
.decoder(decoder::make_decoder)
.encoder(encoder::make_encoder)
.tags([CodecTag::fourcc(b"H261"), CodecTag::fourcc(b"h261")]),
);
}
pub fn register(ctx: &mut RuntimeContext) {
register_codecs(&mut ctx.codecs);
}
oxideav_core::register!("h261", register);
#[cfg(test)]
mod register_tests {
use super::*;
use oxideav_core::{CodecId, CodecParameters, RuntimeContext};
#[test]
fn register_via_runtime_context_installs_codec_factory() {
let mut ctx = RuntimeContext::new();
register(&mut ctx);
let params = CodecParameters::video(CodecId::new(CODEC_ID_STR));
let dec = ctx
.codecs
.first_decoder(¶ms)
.expect("h261 decoder factory");
assert_eq!(dec.codec_id().as_str(), CODEC_ID_STR);
}
#[test]
fn register_via_runtime_context_installs_encoder_factory() {
let mut ctx = RuntimeContext::new();
register(&mut ctx);
let params = CodecParameters::video(CodecId::new(CODEC_ID_STR));
let enc = ctx
.codecs
.first_encoder(¶ms)
.expect("h261 encoder factory");
assert_eq!(enc.codec_id().as_str(), CODEC_ID_STR);
}
#[test]
fn encoder_factory_qcif_defaults() {
let mut ctx = RuntimeContext::new();
register(&mut ctx);
let mut params = CodecParameters::video(CodecId::new(CODEC_ID_STR));
params.width = Some(176);
params.height = Some(144);
let enc = ctx
.codecs
.first_encoder(¶ms)
.expect("h261 encoder factory qcif");
assert_eq!(enc.codec_id().as_str(), CODEC_ID_STR);
let out = enc.output_params();
assert_eq!(out.width, Some(176));
assert_eq!(out.height, Some(144));
}
#[test]
fn encoder_factory_cif() {
let mut ctx = RuntimeContext::new();
register(&mut ctx);
let mut params = CodecParameters::video(CodecId::new(CODEC_ID_STR));
params.width = Some(352);
params.height = Some(288);
let enc = ctx
.codecs
.first_encoder(¶ms)
.expect("h261 encoder factory cif");
assert_eq!(enc.codec_id().as_str(), CODEC_ID_STR);
let out = enc.output_params();
assert_eq!(out.width, Some(352));
assert_eq!(out.height, Some(288));
}
#[test]
fn encoder_factory_rejects_bad_dimensions() {
let mut ctx = RuntimeContext::new();
register(&mut ctx);
let mut params = CodecParameters::video(CodecId::new(CODEC_ID_STR));
params.width = Some(320);
params.height = Some(240);
assert!(
ctx.codecs.first_encoder(¶ms).is_err(),
"should reject 320x240"
);
}
}