From 38953fb529efad1b0b609eec77f7839e62ad2719 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 17 Jan 2019 15:14:02 +0100 Subject: [PATCH] split remaining decoders and demuxer from core --- nihav-allstuff/Cargo.toml | 1 + nihav-allstuff/src/lib.rs | 12 +++-- {nihav-core => nihav-commonfmt}/Cargo.toml | 24 ++++----- .../src/codecs/aac.rs | 20 ++++---- .../src/codecs/atrac3.rs | 18 ++++--- .../src/codecs/clearvideo.rs | 13 +++-- nihav-commonfmt/src/codecs/mod.rs | 43 ++++++++++++++++ .../src/codecs/pcm.rs | 7 ++- .../src/codecs/sipro.rs | 10 ++-- .../src/codecs/ts102366.rs | 12 +++-- .../src/demuxers/avi.rs | 12 ++--- nihav-commonfmt/src/demuxers/mod.rs | 20 ++++++++ nihav-commonfmt/src/lib.rs | 10 ++++ nihav-core/Cargo.toml | 49 +++++++------------ nihav-core/src/codecs/mod.rs | 39 --------------- nihav-core/src/demuxers/mod.rs | 17 +------ 16 files changed, 166 insertions(+), 141 deletions(-) copy {nihav-core => nihav-commonfmt}/Cargo.toml (66%) rename {nihav-core => nihav-commonfmt}/src/codecs/aac.rs (99%) rename {nihav-core => nihav-commonfmt}/src/codecs/atrac3.rs (99%) rename {nihav-core => nihav-commonfmt}/src/codecs/clearvideo.rs (99%) create mode 100644 nihav-commonfmt/src/codecs/mod.rs rename {nihav-core => nihav-commonfmt}/src/codecs/pcm.rs (94%) rename {nihav-core => nihav-commonfmt}/src/codecs/sipro.rs (99%) rename {nihav-core => nihav-commonfmt}/src/codecs/ts102366.rs (99%) rename {nihav-core => nihav-commonfmt}/src/demuxers/avi.rs (98%) create mode 100644 nihav-commonfmt/src/demuxers/mod.rs create mode 100644 nihav-commonfmt/src/lib.rs rewrite nihav-core/Cargo.toml (68%) diff --git a/nihav-allstuff/Cargo.toml b/nihav-allstuff/Cargo.toml index e366f4e..5003f75 100644 --- a/nihav-allstuff/Cargo.toml +++ b/nihav-allstuff/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] nihav_core = { path = "../nihav-core" } +nihav_commonfmt = { path = "../nihav-commonfmt" } nihav_game = { path = "../nihav-game" } nihav_indeo = { path = "../nihav-indeo" } nihav_realmedia = { path = "../nihav-realmedia" } \ No newline at end of file diff --git a/nihav-allstuff/src/lib.rs b/nihav-allstuff/src/lib.rs index cb1e713..667bcd0 100644 --- a/nihav-allstuff/src/lib.rs +++ b/nihav-allstuff/src/lib.rs @@ -1,10 +1,14 @@ extern crate nihav_core; +extern crate nihav_commonfmt; extern crate nihav_game; extern crate nihav_indeo; extern crate nihav_realmedia; -use nihav_core::codecs::{RegisteredDecoders, core_register_all_codecs}; -use nihav_core::demuxers::{RegisteredDemuxers, core_register_all_demuxers}; +use nihav_core::codecs::RegisteredDecoders; +use nihav_core::demuxers::RegisteredDemuxers; + +use nihav_commonfmt::codecs::generic_register_all_codecs; +use nihav_commonfmt::demuxers::generic_register_all_demuxers; use nihav_game::codecs::game_register_all_codecs; use nihav_game::demuxers::game_register_all_demuxers; @@ -15,14 +19,14 @@ use nihav_realmedia::codecs::realmedia_register_all_codecs; use nihav_realmedia::demuxers::realmedia_register_all_demuxers; pub fn nihav_register_all_codecs(rd: &mut RegisteredDecoders) { - core_register_all_codecs(rd); + generic_register_all_codecs(rd); game_register_all_codecs(rd); indeo_register_all_codecs(rd); realmedia_register_all_codecs(rd); } pub fn nihav_register_all_demuxers(rd: &mut RegisteredDemuxers) { - core_register_all_demuxers(rd); + generic_register_all_demuxers(rd); game_register_all_demuxers(rd); realmedia_register_all_demuxers(rd); } diff --git a/nihav-core/Cargo.toml b/nihav-commonfmt/Cargo.toml similarity index 66% copy from nihav-core/Cargo.toml copy to nihav-commonfmt/Cargo.toml index 35657bc..1ab9d0c 100644 --- a/nihav-core/Cargo.toml +++ b/nihav-commonfmt/Cargo.toml @@ -1,23 +1,23 @@ [package] -name = "nihav_core" +name = "nihav_commonfmt" version = "0.1.0" authors = ["Kostya Shishkov "] edition = "2018" +[dependencies.nihav_core] +path = "../nihav-core" +features = ["h263", "mdct", "fft", "dsp_window"] + +[dev-dependencies] +nihav_realmedia = { path = "../nihav-realmedia" } + [features] default = ["all_decoders", "all_demuxers"] +decoders = [] demuxers = [] all_demuxers = ["demuxer_avi"] demuxer_avi = ["demuxers"] -decoders = [] -h263 = [] - -dsp = [] -fft = ["dsp"] -mdct = ["fft", "dsp"] -dsp_window = ["dsp"] - all_decoders = ["all_video_decoders", "all_audio_decoders"] all_video_decoders = ["decoder_clearvideo"] @@ -25,7 +25,7 @@ decoder_clearvideo = ["decoders"] all_audio_decoders = ["decoder_pcm", "decoder_ts102366", "decoder_sipro", "decoder_atrac3", "decoder_aac"] decoder_pcm = ["decoders"] -decoder_ts102366 = ["decoders", "fft"] +decoder_ts102366 = ["decoders"] decoder_sipro = ["decoders"] -decoder_atrac3 = ["decoders", "mdct"] -decoder_aac = ["decoders", "mdct", "dsp_window"] +decoder_atrac3 = ["decoders"] +decoder_aac = ["decoders"] diff --git a/nihav-core/src/codecs/aac.rs b/nihav-commonfmt/src/codecs/aac.rs similarity index 99% rename from nihav-core/src/codecs/aac.rs rename to nihav-commonfmt/src/codecs/aac.rs index 23d6689..b81bdee 100644 --- a/nihav-core/src/codecs/aac.rs +++ b/nihav-commonfmt/src/codecs/aac.rs @@ -1,13 +1,15 @@ -use crate::formats::*; -use crate::frame::*; -use crate::codecs::*; -use crate::dsp::fft::FFTMode; -use crate::dsp::mdct::IMDCT; -use crate::dsp::window::*; -use crate::io::bitreader::*; -use crate::io::codebook::*; +use std::rc::Rc; +use std::cell::RefCell; +use nihav_core::formats::*; +use nihav_core::frame::*; +use nihav_core::codecs::*; +use nihav_core::dsp::fft::FFTMode; +use nihav_core::dsp::mdct::IMDCT; +use nihav_core::dsp::window::*; +use nihav_core::io::bitreader::*; +use nihav_core::io::codebook::*; use std::fmt; -use crate::io::intcode::*; +use nihav_core::io::intcode::*; use std::mem; use std::ptr; use std::str::FromStr; diff --git a/nihav-core/src/codecs/atrac3.rs b/nihav-commonfmt/src/codecs/atrac3.rs similarity index 99% rename from nihav-core/src/codecs/atrac3.rs rename to nihav-commonfmt/src/codecs/atrac3.rs index 5281892..59e690b 100644 --- a/nihav-core/src/codecs/atrac3.rs +++ b/nihav-commonfmt/src/codecs/atrac3.rs @@ -1,11 +1,13 @@ -use crate::formats::*; -use crate::frame::*; -use super::*; -use crate::io::bitreader::*; -use crate::io::byteio::*; -use crate::io::codebook::*; -use crate::dsp::fft::FFTMode; -use crate::dsp::mdct::IMDCT; +use std::rc::Rc; +use std::cell::RefCell; +use nihav_core::formats::*; +use nihav_core::frame::*; +use nihav_core::codecs::*; +use nihav_core::io::bitreader::*; +use nihav_core::io::byteio::*; +use nihav_core::io::codebook::*; +use nihav_core::dsp::fft::FFTMode; +use nihav_core::dsp::mdct::IMDCT; use std::f32::consts; #[derive(Clone,Copy,PartialEq)] diff --git a/nihav-core/src/codecs/clearvideo.rs b/nihav-commonfmt/src/codecs/clearvideo.rs similarity index 99% rename from nihav-core/src/codecs/clearvideo.rs rename to nihav-commonfmt/src/codecs/clearvideo.rs index 8a27006..8543178 100644 --- a/nihav-core/src/codecs/clearvideo.rs +++ b/nihav-commonfmt/src/codecs/clearvideo.rs @@ -1,8 +1,11 @@ -use crate::io::byteio::{ByteReader,MemoryReader}; -use crate::io::bitreader::*; -use crate::io::codebook::*; -use crate::formats; -use super::*; +use std::rc::Rc; +use std::cell::RefCell; +use nihav_core::io::byteio::{ByteReader,MemoryReader}; +use nihav_core::io::bitreader::*; +use nihav_core::io::codebook::*; +use nihav_core::formats; +use nihav_core::codecs::*; +use nihav_core::frame::*; use std::fmt; use std::ops::{Add, Sub}; diff --git a/nihav-commonfmt/src/codecs/mod.rs b/nihav-commonfmt/src/codecs/mod.rs new file mode 100644 index 0000000..886b807 --- /dev/null +++ b/nihav-commonfmt/src/codecs/mod.rs @@ -0,0 +1,43 @@ +use nihav_core::codecs::*; + +macro_rules! validate { + ($a:expr) => { if !$a { println!("check failed at {}:{}", file!(), line!()); return Err(DecoderError::InvalidData); } }; +} + +#[cfg(feature="decoder_clearvideo")] +mod clearvideo; + +#[cfg(feature="decoder_aac")] +mod aac; +#[cfg(feature="decoder_atrac3")] +mod atrac3; +#[cfg(feature="decoder_pcm")] +mod pcm; +#[cfg(feature="decoder_sipro")] +mod sipro; +#[cfg(feature="decoder_ts102366")] +mod ts102366; + +const DECODERS: &[DecoderInfo] = &[ +#[cfg(feature="decoder_clearvideo")] + DecoderInfo { name: "clearvideo", get_decoder: clearvideo::get_decoder }, +#[cfg(feature="decoder_clearvideo")] + DecoderInfo { name: "clearvideo_rm", get_decoder: clearvideo::get_decoder_rm }, + +#[cfg(feature="decoder_pcm")] + DecoderInfo { name: "pcm", get_decoder: pcm::get_decoder }, +#[cfg(feature="decoder_sipro")] + DecoderInfo { name: "sipro", get_decoder: sipro::get_decoder }, +#[cfg(feature="decoder_ts102366")] + DecoderInfo { name: "ac3", get_decoder: ts102366::get_decoder }, +#[cfg(feature="decoder_atrac3")] + DecoderInfo { name: "atrac3", get_decoder: atrac3::get_decoder }, +#[cfg(feature="decoder_aac")] + DecoderInfo { name: "aac", get_decoder: aac::get_decoder }, +]; + +pub fn generic_register_all_codecs(rd: &mut RegisteredDecoders) { + for decoder in DECODERS.into_iter() { + rd.add_decoder(decoder.clone()); + } +} diff --git a/nihav-core/src/codecs/pcm.rs b/nihav-commonfmt/src/codecs/pcm.rs similarity index 94% rename from nihav-core/src/codecs/pcm.rs rename to nihav-commonfmt/src/codecs/pcm.rs index 2a0e510..7a71051 100644 --- a/nihav-core/src/codecs/pcm.rs +++ b/nihav-commonfmt/src/codecs/pcm.rs @@ -1,5 +1,8 @@ -use crate::formats::*; -use super::*; +use std::rc::Rc; +use std::cell::RefCell; +use nihav_core::formats::*; +use nihav_core::codecs::*; +use nihav_core::frame::*; struct PCMDecoder { chmap: NAChannelMap } diff --git a/nihav-core/src/codecs/sipro.rs b/nihav-commonfmt/src/codecs/sipro.rs similarity index 99% rename from nihav-core/src/codecs/sipro.rs rename to nihav-commonfmt/src/codecs/sipro.rs index 882d90c..4f6a866 100644 --- a/nihav-core/src/codecs/sipro.rs +++ b/nihav-commonfmt/src/codecs/sipro.rs @@ -1,7 +1,9 @@ -use crate::formats::*; -use crate::frame::*; -use super::*; -use crate::io::bitreader::*; +use std::rc::Rc; +use std::cell::RefCell; +use nihav_core::formats::*; +use nihav_core::frame::*; +use nihav_core::codecs::*; +use nihav_core::io::bitreader::*; use std::f32::consts::PI; diff --git a/nihav-core/src/codecs/ts102366.rs b/nihav-commonfmt/src/codecs/ts102366.rs similarity index 99% rename from nihav-core/src/codecs/ts102366.rs rename to nihav-commonfmt/src/codecs/ts102366.rs index fb452c5..9c2a094 100644 --- a/nihav-core/src/codecs/ts102366.rs +++ b/nihav-commonfmt/src/codecs/ts102366.rs @@ -1,8 +1,10 @@ -use crate::formats::*; -use crate::frame::*; -use super::*; -use crate::io::bitreader::*; -use crate::dsp::fft::*; +use std::rc::Rc; +use std::cell::RefCell; +use nihav_core::formats::*; +use nihav_core::frame::*; +use nihav_core::codecs::*; +use nihav_core::io::bitreader::*; +use nihav_core::dsp::fft::*; use std::str::FromStr; use std::f32::consts; diff --git a/nihav-core/src/demuxers/avi.rs b/nihav-commonfmt/src/demuxers/avi.rs similarity index 98% rename from nihav-core/src/demuxers/avi.rs rename to nihav-commonfmt/src/demuxers/avi.rs index a326561..d690dd6 100644 --- a/nihav-core/src/demuxers/avi.rs +++ b/nihav-commonfmt/src/demuxers/avi.rs @@ -1,9 +1,9 @@ -use super::*; -use crate::register; -use super::DemuxerError::*; -//use io::byteio::*; -//use frame::*; -use crate::formats::*; +use nihav_core::demuxers::*; +use nihav_core::register; +use nihav_core::demuxers::DemuxerError::*; +use nihav_core::io::byteio::*; +use nihav_core::frame::*; +use nihav_core::formats::*; macro_rules! mktag { ($a:expr, $b:expr, $c:expr, $d:expr) => ({ diff --git a/nihav-commonfmt/src/demuxers/mod.rs b/nihav-commonfmt/src/demuxers/mod.rs new file mode 100644 index 0000000..fa388e3 --- /dev/null +++ b/nihav-commonfmt/src/demuxers/mod.rs @@ -0,0 +1,20 @@ +use nihav_core::demuxers::*; + + +macro_rules! validate { + ($a:expr) => { if !$a { println!("check failed at {}:{}", file!(), line!()); return Err(DemuxerError::InvalidData); } }; +} + +#[cfg(feature="demuxer_avi")] +mod avi; + +const DEMUXERS: &[&'static DemuxerCreator] = &[ +#[cfg(feature="demuxer_avi")] + &avi::AVIDemuxerCreator {}, +]; + +pub fn generic_register_all_demuxers(rd: &mut RegisteredDemuxers) { + for demuxer in DEMUXERS.into_iter() { + rd.add_demuxer(*demuxer); + } +} diff --git a/nihav-commonfmt/src/lib.rs b/nihav-commonfmt/src/lib.rs new file mode 100644 index 0000000..01db994 --- /dev/null +++ b/nihav-commonfmt/src/lib.rs @@ -0,0 +1,10 @@ +extern crate nihav_core; + +#[cfg(feature="decoders")] +pub mod codecs; + +#[cfg(feature="demuxers")] +pub mod demuxers; + +#[cfg(test)] +extern crate nihav_realmedia; diff --git a/nihav-core/Cargo.toml b/nihav-core/Cargo.toml dissimilarity index 68% index 35657bc..e46349d 100644 --- a/nihav-core/Cargo.toml +++ b/nihav-core/Cargo.toml @@ -1,31 +1,18 @@ -[package] -name = "nihav_core" -version = "0.1.0" -authors = ["Kostya Shishkov "] -edition = "2018" - -[features] -default = ["all_decoders", "all_demuxers"] -demuxers = [] -all_demuxers = ["demuxer_avi"] -demuxer_avi = ["demuxers"] - -decoders = [] -h263 = [] - -dsp = [] -fft = ["dsp"] -mdct = ["fft", "dsp"] -dsp_window = ["dsp"] - -all_decoders = ["all_video_decoders", "all_audio_decoders"] - -all_video_decoders = ["decoder_clearvideo"] -decoder_clearvideo = ["decoders"] - -all_audio_decoders = ["decoder_pcm", "decoder_ts102366", "decoder_sipro", "decoder_atrac3", "decoder_aac"] -decoder_pcm = ["decoders"] -decoder_ts102366 = ["decoders", "fft"] -decoder_sipro = ["decoders"] -decoder_atrac3 = ["decoders", "mdct"] -decoder_aac = ["decoders", "mdct", "dsp_window"] +[package] +name = "nihav_core" +version = "0.1.0" +authors = ["Kostya Shishkov "] +edition = "2018" + +[features] +default = ["decoders", "demuxers"] + +decoders = [] +demuxers = [] + +h263 = [] + +dsp = [] +fft = ["dsp"] +mdct = ["fft", "dsp"] +dsp_window = ["dsp"] diff --git a/nihav-core/src/codecs/mod.rs b/nihav-core/src/codecs/mod.rs index f3fabf3..76c683d 100644 --- a/nihav-core/src/codecs/mod.rs +++ b/nihav-core/src/codecs/mod.rs @@ -238,48 +238,9 @@ pub struct DecoderInfo { #[cfg(any(feature="h263"))] pub mod blockdsp; -#[cfg(feature="decoder_clearvideo")] -mod clearvideo; -#[cfg(feature="decoder_gdvvid")] -mod gremlinvideo; #[cfg(feature="h263")] pub mod h263; -#[cfg(feature="decoder_aac")] -mod aac; -#[cfg(feature="decoder_atrac3")] -mod atrac3; -#[cfg(feature="decoder_pcm")] -mod pcm; -#[cfg(feature="decoder_sipro")] -mod sipro; -#[cfg(feature="decoder_ts102366")] -mod ts102366; - -const DECODERS: &[DecoderInfo] = &[ -#[cfg(feature="decoder_clearvideo")] - DecoderInfo { name: "clearvideo", get_decoder: clearvideo::get_decoder }, -#[cfg(feature="decoder_clearvideo")] - DecoderInfo { name: "clearvideo_rm", get_decoder: clearvideo::get_decoder_rm }, - -#[cfg(feature="decoder_pcm")] - DecoderInfo { name: "pcm", get_decoder: pcm::get_decoder }, -#[cfg(feature="decoder_sipro")] - DecoderInfo { name: "sipro", get_decoder: sipro::get_decoder }, -#[cfg(feature="decoder_ts102366")] - DecoderInfo { name: "ac3", get_decoder: ts102366::get_decoder }, -#[cfg(feature="decoder_atrac3")] - DecoderInfo { name: "atrac3", get_decoder: atrac3::get_decoder }, -#[cfg(feature="decoder_aac")] - DecoderInfo { name: "aac", get_decoder: aac::get_decoder }, -]; - -pub fn core_register_all_codecs(rd: &mut RegisteredDecoders) { - for decoder in DECODERS.into_iter() { - rd.add_decoder(decoder.clone()); - } -} - pub struct RegisteredDecoders { decs: Vec, } diff --git a/nihav-core/src/demuxers/mod.rs b/nihav-core/src/demuxers/mod.rs index 56e670d..bfd492a 100644 --- a/nihav-core/src/demuxers/mod.rs +++ b/nihav-core/src/demuxers/mod.rs @@ -204,15 +204,6 @@ macro_rules! validate { ($a:expr) => { if !$a { println!("check failed at {}:{}", file!(), line!()); return Err(DemuxerError::InvalidData); } }; } -#[cfg(feature="demuxer_avi")] -mod avi; - - -const DEMUXERS: &[&'static DemuxerCreator] = &[ -#[cfg(feature="demuxer_avi")] - &avi::AVIDemuxerCreator {}, -]; - pub fn create_demuxer<'a>(dmxcr: &DemuxerCreator, br: &'a mut ByteReader<'a>) -> DemuxerResult> { let mut dmx = dmxcr.new_demuxer(br); let mut str = StreamManager::new(); @@ -239,10 +230,4 @@ impl RegisteredDemuxers { } None } -} - -pub fn core_register_all_demuxers(rd: &mut RegisteredDemuxers) { - for demuxer in DEMUXERS.into_iter() { - rd.add_demuxer(*demuxer); - } -} +} \ No newline at end of file -- 2.39.5