]> git.nihav.org Git - nihav.git/commitdiff
use NATimePoint for seeking
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 9 Jul 2020 08:42:42 +0000 (10:42 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 9 Jul 2020 08:42:42 +0000 (10:42 +0200)
nihav-commonfmt/src/demuxers/avi.rs
nihav-commonfmt/src/demuxers/mov.rs
nihav-commonfmt/src/demuxers/wav.rs
nihav-core/src/demuxers/mod.rs
nihav-game/src/demuxers/bmv.rs
nihav-game/src/demuxers/gdv.rs
nihav-game/src/demuxers/vmd.rs
nihav-rad/src/demuxers/bink.rs
nihav-rad/src/demuxers/smacker.rs
nihav-realmedia/src/demuxers/realmedia.rs
nihav-vivo/src/demuxers/vivo.rs

index 43d154a30b487959f8818d597d09f1059258d245..05a0d640c8f4004ea3549ad5868d676003577cb4 100644 (file)
@@ -135,7 +135,7 @@ impl<'a> DemuxCore<'a> for AVIDemuxer<'a> {
         }
     }
 
-    fn seek(&mut self, time: u64, seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, seek_index: &SeekIndex) -> DemuxerResult<()> {
         let ret = seek_index.find_pos(time);
         if ret.is_none() {
             return Err(DemuxerError::SeekError);
index c10bb2dd7a2500ff136081dd51510e51320cc53c..47cfbe3ef0eb9af414d11ee8f006ba46bc88cb75 100644 (file)
@@ -962,7 +962,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> {
         Err(DemuxerError::EOF)
     }
 
-    fn seek(&mut self, time: u64, seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, seek_index: &SeekIndex) -> DemuxerResult<()> {
         let ret = seek_index.find_pos(time);
         if ret.is_none() {
             return Err(DemuxerError::SeekError);
index f9c955154e36d0c69d3700685f5ea6fb58040a43..a57927900f3d752891dd9fda396d4edd57fcff78 100644 (file)
@@ -83,10 +83,16 @@ impl<'a> DemuxCore<'a> for WAVDemuxer<'a> {
         }
     }
 
-    fn seek(&mut self, time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
         if self.block_size != 0 && self.avg_bytes != 0 {
-            let seek_dst = u64::from(self.avg_bytes) * time / 1000;
-            let seek_off = seek_dst / (self.block_size as u64) * (self.block_size as u64);
+            let seek_off = match time {
+                    NATimePoint::Milliseconds(ms) => {
+                        let seek_dst = u64::from(self.avg_bytes) * ms / 1000;
+                        seek_dst / (self.block_size as u64) * (self.block_size as u64)
+                    },
+                    NATimePoint::PTS(pts) => (self.block_size as u64) * pts,
+                    NATimePoint::None => return Ok(()),
+                };
             self.src.seek(SeekFrom::Start(self.data_pos + seek_off))?;
             Ok(())
         } else {
index 9a69abb18c6d3d11c7b6a3241069be90e8706957..352c1605f20050b8f33cb5e9700a4c8d2b1fb97f 100644 (file)
@@ -37,7 +37,7 @@ pub trait DemuxCore<'a>: NAOptionHandler {
     /// Demuxes a packet.
     fn get_frame(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<NAPacket>;
     /// Seeks to the requested time.
-    fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()>;
+    fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()>;
 }
 
 /// An auxiliary trait to make bytestream reader read packet data.
@@ -229,16 +229,31 @@ impl StreamSeekInfo {
         self.entries.push(entry);
     }
     /// Searches for an appropriate seek position before requested time.
-    pub fn find_pos(&self, time: u64) -> Option<SeekEntry> {
+    pub fn find_pos(&self, time: NATimePoint) -> Option<SeekEntry> {
+        if time == NATimePoint::None {
+            return None;
+        }
         if !self.entries.is_empty() {
 // todo something faster like binary search
             let mut cand = None;
             for entry in self.entries.iter() {
-                if entry.time <= time {
-                    cand = Some(*entry);
-                } else {
-                    break;
-                }
+                match time {
+                    NATimePoint::Milliseconds(ms) => {
+                        if entry.time <= ms {
+                            cand = Some(*entry);
+                        } else {
+                            break;
+                        }
+                    },
+                    NATimePoint::PTS(pts) => {
+                        if entry.pts <= pts {
+                            cand = Some(*entry);
+                        } else {
+                            break;
+                        }
+                    },
+                    NATimePoint::None => unreachable!(),
+                };
             }
             cand
         } else {
@@ -309,7 +324,7 @@ impl SeekIndex {
         self.seek_info[idx.unwrap()].filled = true;
     }
     /// Searches for a seek position before requested time.
-    pub fn find_pos(&self, time: u64) -> Option<SeekIndexResult> {
+    pub fn find_pos(&self, time: NATimePoint) -> Option<SeekIndexResult> {
         let mut cand = None;
         for str in self.seek_info.iter() {
             if !str.filled { continue; }
@@ -389,8 +404,8 @@ impl<'a> Demuxer<'a> {
             }
         }
     }
-    /// Seeks to the requested time (in milliseconds) if possible.
-    pub fn seek(&mut self, time: u64) -> DemuxerResult<()> {
+    /// Seeks to the requested time if possible.
+    pub fn seek(&mut self, time: NATimePoint) -> DemuxerResult<()> {
         if self.seek_idx.skip_index {
             return Err(DemuxerError::NotPossible);
         }
index fafd6f0da5d00e698eb415518ec353285385e9bd..83f75b122d8552de85a2242615f21b9f372624bd 100644 (file)
@@ -70,7 +70,7 @@ impl<'a> DemuxCore<'a> for BMVDemuxer<'a> {
         }
     }
 
-    fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
         Err(DemuxerError::NotPossible)
     }
 }
@@ -218,7 +218,7 @@ impl<'a> DemuxCore<'a> for BMV3Demuxer<'a> {
         }
     }
 
-    fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
         Err(DemuxerError::NotPossible)
     }
 }
index 11d7406839b25393d9461ae5180dc05f2fb234b6..af0f8577c8f22ce32b1deca3acba1c6af53ca133 100644 (file)
@@ -110,7 +110,7 @@ impl<'a> DemuxCore<'a> for GremlinVideoDemuxer<'a> {
         }
     }
 
-    fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
         Err(DemuxerError::NotPossible)
     }
 }
index 3c6e1526cc365bdac8d19ca27969be44149b0d1e..f693e732ef93376216e57e68e46438cc46b329b9 100644 (file)
@@ -180,7 +180,7 @@ impl<'a> DemuxCore<'a> for VMDDemuxer<'a> {
         Ok(pkt)
     }
 
-    fn seek(&mut self, _time: u64, _seek_index: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, _time: NATimePoint, _seek_index: &SeekIndex) -> DemuxerResult<()> {
         Err(DemuxerError::NotPossible)
     }
 }
index a5d8169240f9159f4bf8f0a244ca711eb50fe989..454290fb1814fca5a853686918ecb412a8d324f7 100644 (file)
@@ -152,7 +152,7 @@ impl<'a> DemuxCore<'a> for BinkDemuxer<'a> {
 
         Ok(pkt)
     }
-    fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
         let ret = seek_idx.find_pos(time);
         if ret.is_none() {
             return Err(DemuxerError::SeekError);
index accbfa51b956ca1a2bcc8c926209111c40bbcd59..6d1173cc2b6350abad16c8397fb849f03244bd44 100644 (file)
@@ -251,8 +251,13 @@ impl<'a> DemuxCore<'a> for SmackerVideoDemuxer<'a> {
 
         Ok(pkt)
     }
-    fn seek(&mut self, time: u64, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
-        if time == 0 {
+    fn seek(&mut self, time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
+        let seek_to_start = match time {
+                NATimePoint::Milliseconds(0) => true,
+                NATimePoint::PTS(0) => true,
+                _ => false,
+            };
+        if seek_to_start {
             let start = self.start;
             self.src.seek(SeekFrom::Start(start))?;
             self.cur_frame = 0;
index 16c4746e5e3419f97a8b46e431f399ea4aba8cca..b37c34faa6510ec827b819464f5530c16cb8695f 100644 (file)
@@ -740,7 +740,7 @@ impl<'a> DemuxCore<'a> for RealMediaDemuxer<'a> {
     }
 
     #[allow(unused_variables)]
-    fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
         self.queued_pkts.clear();
         let ret = seek_idx.find_pos(time);
         if ret.is_none() {
@@ -1263,7 +1263,7 @@ println!(" got ainfo {:?}", ainfo);
     }
 
     #[allow(unused_variables)]
-    fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
         Err(NotImplemented)
     }
 }
@@ -1608,7 +1608,7 @@ println!("R1M kind");
     }
 
     #[allow(unused_variables)]
-    fn seek(&mut self, time: u64, seek_idx: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, time: NATimePoint, seek_idx: &SeekIndex) -> DemuxerResult<()> {
         Err(NotImplemented)
     }
 }
index a060d48da91179680a948d4642b1d5151d81d6e0..3c0ac7d2ee3c05a58a3f0faae91683247e901421 100644 (file)
@@ -129,7 +129,7 @@ impl<'a> DemuxCore<'a> for VivoDemuxer<'a> {
             }
         }
     }
-    fn seek(&mut self, _time: u64, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
+    fn seek(&mut self, _time: NATimePoint, _seek_idx: &SeekIndex) -> DemuxerResult<()> {
         Err(DemuxerError::NotPossible)
     }
 }