X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=src%2Fdemuxers%2Fgdv.rs;h=ed77194f8fe9a483b05d2bc17aff53b8a5b2ce05;hb=06fd8c8865256ab5348996a23afeeb512bc45835;hp=897550f19f13983279f2a12dccdf7c55fecc4048;hpb=eb71d98ffafe7cc00bab4c3b7c9c97f813eca6c4;p=nihav.git diff --git a/src/demuxers/gdv.rs b/src/demuxers/gdv.rs index 897550f..ed77194 100644 --- a/src/demuxers/gdv.rs +++ b/src/demuxers/gdv.rs @@ -24,6 +24,32 @@ struct GremlinVideoDemuxer<'a> { v_id: Option, } +struct GDVFixedSizes { + id: u16, + width: u16, + height: u16, +} +const GDV_SIZE_TABLE: &[GDVFixedSizes] = &[ + GDVFixedSizes { id: 0, width: 320, height: 200 }, + GDVFixedSizes { id: 1, width: 640, height: 200 }, + GDVFixedSizes { id: 2, width: 320, height: 167 }, + GDVFixedSizes { id: 3, width: 320, height: 180 }, + GDVFixedSizes { id: 4, width: 320, height: 400 }, + GDVFixedSizes { id: 5, width: 320, height: 170 }, + GDVFixedSizes { id: 6, width: 160, height: 85 }, + GDVFixedSizes { id: 7, width: 160, height: 83 }, + GDVFixedSizes { id: 8, width: 160, height: 90 }, + GDVFixedSizes { id: 9, width: 280, height: 128 }, + GDVFixedSizes { id: 10, width: 320, height: 240 }, + GDVFixedSizes { id: 11, width: 320, height: 201 }, + GDVFixedSizes { id: 16, width: 640, height: 400 }, + GDVFixedSizes { id: 17, width: 640, height: 200 }, + GDVFixedSizes { id: 18, width: 640, height: 180 }, + GDVFixedSizes { id: 19, width: 640, height: 167 }, + GDVFixedSizes { id: 20, width: 640, height: 170 }, + GDVFixedSizes { id: 21, width: 320, height: 240 }, +]; + impl<'a> Demux<'a> for GremlinVideoDemuxer<'a> { #[allow(unused_variables)] fn open(&mut self) -> DemuxerResult<()> { @@ -38,27 +64,42 @@ impl<'a> Demux<'a> for GremlinVideoDemuxer<'a> { let depth = src.read_u16le()?; let max_fs = src.read_u16le()?; src.read_skip(2)?; - let width = src.read_u16le()?; - let height = src.read_u16le()?; + let mut width = src.read_u16le()?; + let mut height = src.read_u16le()?; + if (width == 0) && (height == 0) { + for el in GDV_SIZE_TABLE { + if el.id == id { + width = el.width; + height = el.height; + break; + } + } + if (width == 0) && (height == 0) { return Err(DemuxerError::InvalidData); } + } if max_fs > 0 { + let mut edata: Vec = Vec::with_capacity(768); + if depth == 1 { + edata.resize(768, 0); + src.read_buf(edata.as_mut_slice())?; + } let vhdr = NAVideoInfo::new(width as usize, height as usize, false, PAL8_FORMAT); let vci = NACodecTypeInfo::Video(vhdr); - let vinfo = NACodecInfo::new("video-gdv", vci, None); - self.v_id = self.dmx.add_stream(NAStream::new(StreamType::Video, 0, vinfo)); + let vinfo = NACodecInfo::new("gdv-video", vci, if edata.len() == 0 { None } else { Some(edata) }); + self.v_id = self.dmx.add_stream(NAStream::new(StreamType::Video, 0, vinfo, 1, fps as u32)); } 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("audio-gdv", 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 }; + let depth = if (aflags & 4) != 0 { 16 } else { 8 }; + + let ahdr = NAAudioInfo::new(rate as u32, channels as u8, if depth == 16 { SND_S16_FORMAT } else { SND_U8_FORMAT }, 2); + let ainfo = NACodecInfo::new(if packed != 0 { "gdv-audio" } else { "pcm" }, + NACodecTypeInfo::Audio(ahdr), None); + self.a_id = self.dmx.add_stream(NAStream::new(StreamType::Audio, 1, ainfo, 1, rate as u32)); - 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.asize = (((rate / fps) * channels * (depth / 8)) >> packed) as usize; self.apacked = (aflags & 8) != 0; } - if max_fs > 0 && depth == 1 { - src.read_skip(768)?; - } self.frames = frames; self.opened = true; self.state = GDVState::NewFrame; @@ -109,7 +150,9 @@ pktdta: Vec::new(), fn read_achunk(&mut self) -> DemuxerResult { self.state = GDVState::AudioRead; 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) + let (tb_num, tb_den) = str.get_timebase(); + let ts = NATimeInfo::new(Some(self.cur_frame as u64), None, None, tb_num, tb_den); + self.src.read_packet(str, ts, true, self.asize) } fn read_vchunk(&mut self) -> DemuxerResult { @@ -122,7 +165,9 @@ pktdta: Vec::new(), let flags = (tmp & 0xFF) as usize; self.state = GDVState::NewFrame; self.cur_frame = self.cur_frame + 1; - src.read_packet(str, Some((self.cur_frame - 1) as u64), None, None, if (flags & 64) != 0 { true } else { false }, size) + let (tb_num, tb_den) = str.get_timebase(); + let ts = NATimeInfo::new(Some((self.cur_frame - 1) as u64), None, None, tb_num, tb_den); + src.read_packet(str, ts, if (flags & 64) != 0 { true } else { false }, size) } }