introduce option handling for demuxers
[nihav.git] / nihav-rad / src / demuxers / bink.rs
index bdbf0c5b99ef30525b9f795b42c91c945ef09328..35bdcbf6126234a4030f432412403901e7c9f4e6 100644 (file)
@@ -66,6 +66,8 @@ impl<'a> DemuxCore<'a> for BinkDemuxer<'a> {
         let tb_num                          = src.read_u32le()?;
         validate!((width > 0) && (height > 0) && (width <= 7680) && (height <= 4800));
         validate!((self.frames > 0) && (tb_num > 0) && (tb_den > 0) && (max_size < fsize));
+        self.tb_num = tb_num;
+        self.tb_den = tb_den;
         let mut flags: [u8; 4] = [0; 4];
                                               src.read_buf(&mut flags)?;
         let mut edata: Vec<u8> = vec![0; 8];
@@ -98,20 +100,21 @@ impl<'a> DemuxCore<'a> for BinkDemuxer<'a> {
         }
 
         seek_idx.mode = SeekIndexMode::Present;
-        seek_idx.add_stream(0, tb_num, tb_den);
+        seek_idx.add_stream(0);
         self.frame_pos = Vec::with_capacity(self.frames + 1);
         for fno in 0..=self.frames {
             let pos                         = src.read_u32le()?;
             self.frame_pos.push(pos);
             if (pos & 1) != 0 {
-                seek_idx.seek_info[0].add_entry(SeekEntry { pts: fno as u64, pos: (pos & !1) as u64 });
+                let time = (fno as u64) * 1000 * (tb_num as u64) / (tb_den as u64);
+                seek_idx.seek_info[0].add_entry(SeekEntry { time, pts: fno as u64, pos: (pos & !1) as u64 });
             }
         }
         validate!((src.tell() as u32) == (self.frame_pos[0] & !1));
         seek_idx.seek_info[0].filled = true;
 
         self.cur_frame = 0;
-        
+
         Ok(())
     }
     fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket> {
@@ -162,6 +165,12 @@ impl<'a> DemuxCore<'a> for BinkDemuxer<'a> {
     }
 }
 
+impl<'a> NAOptionHandler for BinkDemuxer<'a> {
+    fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
+    fn set_options(&mut self, _options: &[NAOption]) { }
+    fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
+}
+
 impl<'a> BinkDemuxer<'a> {
     fn new(io: &'a mut ByteReader<'a>) -> Self {
         Self {
@@ -204,7 +213,8 @@ mod test {
         let mut br = ByteReader::new(&mut fr);
         let mut dmx = BinkDemuxer::new(&mut br);
         let mut sm = StreamManager::new();
-        dmx.open(&mut sm).unwrap();
+        let mut si = SeekIndex::new();
+        dmx.open(&mut sm, &mut si).unwrap();
         loop {
             let pktres = dmx.get_frame(&mut sm);
             if let Err(e) = pktres {