]> git.nihav.org Git - nihav.git/blobdiff - nihav-acorn/src/demuxers/armovie.rs
rawvideo: support packed RGB a bit better
[nihav.git] / nihav-acorn / src / demuxers / armovie.rs
index 9b9d8ee4c2f2db636101ee174577cf81af09a457..4b2b3f6c53a3295557eee3e749204351eb9880d2 100644 (file)
@@ -13,6 +13,9 @@ const VIDEO_CODECS: &[(i32, &str)] = &[
     (122, "escape122"),
     (124, "escape124"),
     (130, "escape130"),
+    (600, "msvideo1"),
+    (601, "msvideo1"),
+    (602, "cinepak"),
     (800, "linepack"),
     (802, "movie16_3"),
 ];
@@ -26,7 +29,7 @@ impl<'a> ReadString for ByteReader<'a> {
         let mut res = Vec::new();
         loop {
             let c = self.read_byte()?;
-            if c == b'\n' {
+            if c == b'\n' || c == 0 {
                 break;
             }
             res.push(c);
@@ -218,7 +221,7 @@ impl<'a> RawDemuxCore<'a> for ARMovieDemuxer<'a> {
         let width = parse_int(&width)?;
         let height              = self.src.read_string()?;
         let height = parse_int(&height)?;
-        validate!((video_codec <= 0) ^ (width > 0 && height > 0));
+        validate!((video_codec <= 0) || (width > 0 && height > 0));
         let width  = width as usize;
         let height = height as usize;
         let vformat             = self.src.read_string()?;
@@ -278,7 +281,13 @@ impl<'a> RawDemuxCore<'a> for ARMovieDemuxer<'a> {
             let mut edata = vec![video_codec as u8, (video_codec >> 8) as u8];
             edata.extend_from_slice(&vformat);
 
-            let vci = NACodecTypeInfo::Video(NAVideoInfo::new(width, height, false, YUV420_FORMAT));
+            let fmt = match video_codec {
+                    600 => PAL8_FORMAT,
+                    601 => RGB565_FORMAT,
+                    _ => YUV420_FORMAT,
+                };
+
+            let vci = NACodecTypeInfo::Video(NAVideoInfo::new(width, height, false, fmt));
             let vinfo = NACodecInfo::new(codec_name, vci, Some(edata));
             let ret = strmgr.add_stream(NAStream::new(StreamType::Video, stream_id, vinfo, tb_num, tb_den, (frm_per_chunk * num_chunks) as u64));
             if ret.is_some() {
@@ -296,9 +305,10 @@ impl<'a> RawDemuxCore<'a> for ARMovieDemuxer<'a> {
             for ((&id, &sratestr), (&chan, &fmt)) in sound_ids.iter().zip(srates.iter())
                         .zip(channels.iter().zip(sndformats.iter())) {
                 let codec_id = parse_uint(id)?;
-                let codec_name = if codec_id == 1 { "pcm" } else { "unknown" };
+                let codec_name = if codec_id == 1 { "arm_rawaudio" } else { "unknown" };
                 let channels = parse_uint(chan)?;
                 validate!(channels > 0 && channels < 16);
+                let edata = fmt.to_owned();
                 let bits = parse_uint(fmt)?;
                 let mut srate = parse_uint(sratestr)?;
                 if srate > 0 && srate < 1000 { // probably in microseconds instead of Hertz
@@ -308,7 +318,7 @@ impl<'a> RawDemuxCore<'a> for ARMovieDemuxer<'a> {
                 let fmt = if bits == 8 { SND_U8_FORMAT } else { SND_S16_FORMAT };
 
                 let aci = NACodecTypeInfo::Audio(NAAudioInfo::new(srate, channels as u8, fmt, 0));
-                let ainfo = NACodecInfo::new(codec_name, aci, None);
+                let ainfo = NACodecInfo::new(codec_name, aci, Some(edata));
                 let ret = strmgr.add_stream(NAStream::new(StreamType::Audio, stream_id, ainfo, 1, srate, 0));
                 if let Some(id) = ret {
                     self.audio_ids.push(id);