gdv: make demuxer set dimensions from ID if they are not provided
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 29 Jun 2017 11:00:16 +0000 (13:00 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 29 Jun 2017 11:00:16 +0000 (13:00 +0200)
src/demuxers/gdv.rs

index daac924275cb0dde480769763bed9babc6f469c3..ed77194f8fe9a483b05d2bc17aff53b8a5b2ce05 100644 (file)
@@ -24,6 +24,32 @@ struct GremlinVideoDemuxer<'a> {
     v_id:       Option<usize>,
 }
 
+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,8 +64,18 @@ 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<u8> = Vec::with_capacity(768);
             if depth == 1 {