diff --git a/db/db.rs b/db/db.rs index 6c31ae8..e56c086 100644 --- a/db/db.rs +++ b/db/db.rs @@ -1153,8 +1153,9 @@ impl LockedDatabase { /// Calls `f` with a single `recording_playback` row. /// Note the lock is held for the duration of `f`. /// This uses a LRU cache to reduce the number of retrievals from the database. - pub fn with_recording_playback(&self, id: CompositeId, f: F) -> Result - where F: FnOnce(&RecordingPlayback) -> Result { + pub fn with_recording_playback(&self, id: CompositeId, + f: &mut FnMut(&RecordingPlayback) -> Result) + -> Result { // Check for uncommitted path. let s = self.streams_by_id .get(&id.stream()) diff --git a/db/recording.rs b/db/recording.rs index 882ccf0..c29dd14 100644 --- a/db/recording.rs +++ b/db/recording.rs @@ -394,7 +394,7 @@ impl Segment { // Slow path. Need to iterate through the index. trace!("recording::Segment::new slow path, desired_range_90k={:?}, recording={:#?}", self_.desired_range_90k, recording); - db.with_recording_playback(self_.id, |playback| { + db.with_recording_playback(self_.id, &mut |playback| { let mut begin = Box::new(SampleIndexIterator::new()); let data = &(&playback).video_index; let mut it = SampleIndexIterator::new(); @@ -437,8 +437,9 @@ impl Segment { self_.video_sample_entry_id_and_trailing_zero = recording.video_sample_entry_id | (((it.duration_90k == 0) as i32) << 31); - Ok(self_) - }) + Ok(()) + })?; + Ok(self_) } pub fn video_sample_entry_id(&self) -> i32 { @@ -632,7 +633,7 @@ mod tests { fn get_frames(db: &db::Database, segment: &Segment, f: F) -> Vec where F: Fn(&SampleIndexIterator) -> T { let mut v = Vec::new(); - db.lock().with_recording_playback(segment.id, |playback| { + db.lock().with_recording_playback(segment.id, &mut |playback| { segment.foreach(playback, |it| { v.push(f(it)); Ok(()) }) }).unwrap(); v diff --git a/src/mp4.rs b/src/mp4.rs index 14e7c03..f84c023 100644 --- a/src/mp4.rs +++ b/src/mp4.rs @@ -382,8 +382,8 @@ impl Segment { self.index_once.call_once(|| { let index = unsafe { &mut *self.index.get() }; *index = db.lock() - .with_recording_playback(self.s.id, |playback| self.build_index(playback)) - .map_err(|e| { error!("Unable to build index for segment: {:?}", e); }); + .with_recording_playback(self.s.id, &mut |playback| self.build_index(playback)) + .map_err(|e| { error!("Unable to build index for segment: {:?}", e); }); }); let index: &'a _ = unsafe { &*self.index.get() }; match *index { @@ -627,7 +627,7 @@ impl Slice { } let truns = mp4.0.db.lock() - .with_recording_playback(s.s.id, |playback| s.truns(playback, pos, len))?; + .with_recording_playback(s.s.id, &mut |playback| s.truns(playback, pos, len))?; let truns = ARefs::new(truns); Ok(truns.map(|t| &t[r.start as usize .. r.end as usize])) } @@ -2275,7 +2275,7 @@ mod bench { let rel_range_90k = 0 .. row.duration_90k; super::Segment::new(&db, &row, rel_range_90k, 1).unwrap() }; - db.with_recording_playback(segment.s.id, |playback| { + db.with_recording_playback(segment.s.id, &mut |playback| { let v = segment.build_index(playback).unwrap(); // warm. b.bytes = v.len() as u64; // define the benchmark performance in terms of output bytes. b.iter(|| segment.build_index(playback).unwrap()); diff --git a/src/streamer.rs b/src/streamer.rs index 9a51abf..3242372 100644 --- a/src/streamer.rs +++ b/src/streamer.rs @@ -302,7 +302,7 @@ mod tests { } fn get_frames(db: &db::LockedDatabase, id: CompositeId) -> Vec { - db.with_recording_playback(id, |rec| { + db.with_recording_playback(id, &mut |rec| { let mut it = recording::SampleIndexIterator::new(); let mut frames = Vec::new(); while it.next(&rec.video_index).unwrap() {