X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fdemuxers%2Fgdv.rs;h=9cd62ecac0fec4b42eb97d6bd1fbf796b3a164f4;hb=e5e85f326e9edbfdecb8e93a21834984ae201380;hp=605593802abd5738bbdb83b38a3e9f6e39fc18a4;hpb=e24794ee1808504fd9d2083f5c725bdb8a19fd38;p=nihav.git diff --git a/src/demuxers/gdv.rs b/src/demuxers/gdv.rs index 6055938..9cd62ec 100644 --- a/src/demuxers/gdv.rs +++ b/src/demuxers/gdv.rs @@ -1,6 +1,7 @@ use super::*; use io::byteio::*; use frame::*; +use formats::*; //use std::collections::HashMap; enum GDVState { @@ -9,19 +10,21 @@ enum GDVState { } #[allow(dead_code)] -pub struct GremlinVideoDemuxer<'a> { - opened: bool, - src: &'a mut ByteReader<'a>, - streams: Vec>>, - frames: u16, - cur_frame: u16, - asize: usize, - apacked: bool, - state: GDVState, - pktdta: Vec, +struct GremlinVideoDemuxer<'a> { + opened: bool, + src: &'a mut ByteReader<'a>, + frames: u16, + cur_frame: u16, + asize: usize, + apacked: bool, + state: GDVState, + pktdta: Vec, + dmx: Demuxer, + a_id: Option, + v_id: Option, } -impl<'a> NADemuxer<'a> for GremlinVideoDemuxer<'a> { +impl<'a> Demux<'a> for GremlinVideoDemuxer<'a> { #[allow(unused_variables)] fn open(&mut self) -> DemuxerResult<()> { let src = &mut self.src; @@ -37,25 +40,21 @@ impl<'a> NADemuxer<'a> for GremlinVideoDemuxer<'a> { src.read_skip(2)?; let width = src.read_u16le()?; let height = src.read_u16le()?; -println!("id {} frames {} fps {} sound {} Hz {:X} img {} - {}x{}",id,frames,fps,rate,aflags,depth,width,height); if max_fs > 0 { - let vhdr = NAVideoInfo::new(width as u32, height as u32, false, PAL8_FORMAT); + let vhdr = NAVideoInfo::new(width as usize, height as usize, false, PAL8_FORMAT); let vci = NACodecTypeInfo::Video(vhdr); - let vinfo = NACodecInfo::new(vci, None); - let vstr = NAStream::new(StreamType::Video, 0, vinfo); - self.streams.push(Rc::new(vstr)); + let vinfo = NACodecInfo::new("gdv-video", vci, None); + self.v_id = self.dmx.add_stream(NAStream::new(StreamType::Video, 0, vinfo)); } if (aflags & 1) != 0 { let channels = if (aflags & 2) != 0 { 2 } else { 1 }; let ahdr = NAAudioInfo::new(rate as u32, channels as u8, if (aflags & 4) != 0 { SND_S16_FORMAT } else { SND_U8_FORMAT }, 2); - let ainfo = NACodecInfo::new(NACodecTypeInfo::Audio(ahdr), None); - let astr = NAStream::new(StreamType::Audio, 1, ainfo); - self.streams.push(Rc::new(astr)); + let ainfo = NACodecInfo::new("gdv-audio", NACodecTypeInfo::Audio(ahdr), None); + self.a_id = self.dmx.add_stream(NAStream::new(StreamType::Audio, 1, ainfo)); let packed = if (aflags & 8) != 0 { 1 } else { 0 }; self.asize = (((rate / fps) * channels * (if (aflags & 4) != 0 { 2 } else { 1 })) >> packed) as usize; self.apacked = (aflags & 8) != 0; -println!("audio chunk size {}({:X})",self.asize,self.asize); } if max_fs > 0 && depth == 1 { src.read_skip(768)?; @@ -76,6 +75,9 @@ println!("audio chunk size {}({:X})",self.asize,self.asize); } } + fn get_num_streams(&self) -> usize { self.dmx.get_num_streams() } + fn get_stream(&self, idx: usize) -> Option> { self.dmx.get_stream(idx) } + #[allow(unused_variables)] fn seek(&mut self, time: u64) -> DemuxerResult<()> { if !self.opened { return Err(DemuxerError::NoSuchInput); } @@ -88,7 +90,7 @@ println!("audio chunk size {}({:X})",self.asize,self.asize); } }*/ impl<'a> GremlinVideoDemuxer<'a> { - pub fn new(io: &'a mut ByteReader<'a>) -> Self { + fn new(io: &'a mut ByteReader<'a>) -> Self { GremlinVideoDemuxer { cur_frame: 0, frames: 0, @@ -98,26 +100,20 @@ impl<'a> GremlinVideoDemuxer<'a> { state: GDVState::NewFrame, pktdta: Vec::new(), src: io, - streams: Vec::new() + a_id: None, + v_id: None, + dmx: Demuxer::new() } } - fn find_stream(&mut self, id: u32) -> Rc> { - for i in 0..self.streams.len() { - if self.streams[i].get_id() == id { - return self.streams[i].clone(); - } - } - panic!("stream not found"); - } fn read_achunk(&mut self) -> DemuxerResult { self.state = GDVState::AudioRead; - let str = self.find_stream(1); + let str = self.dmx.get_stream(self.a_id.unwrap()).unwrap(); self.src.read_packet(str, Some(self.cur_frame as u64), None, None, true, self.asize) } fn read_vchunk(&mut self) -> DemuxerResult { - let str = self.find_stream(0); + let str = self.dmx.get_stream(self.v_id.unwrap()).unwrap(); let mut src = &mut self.src; let magic = src.read_u16be()?; if magic != 0x0513 { return Err(DemuxerError::InvalidData); } @@ -130,6 +126,15 @@ pktdta: Vec::new(), } } +pub struct GDVDemuxerCreator { } + +impl DemuxerCreator for GDVDemuxerCreator { + fn new_demuxer<'a>(&self, br: &'a mut ByteReader<'a>) -> Box + 'a> { + Box::new(GremlinVideoDemuxer::new(br)) + } + fn get_name(&self) -> &'static str { "gdv" } +} + #[cfg(test)] mod test { use super::*;