mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-12-06 07:42:29 -05:00
pass prev duration and runs through API layer
Builds on f3ddbfe, for #32 and #59.
This commit is contained in:
9
db/db.rs
9
db/db.rs
@@ -156,7 +156,7 @@ pub struct VideoSampleEntryToInsert {
|
||||
}
|
||||
|
||||
/// A row used in `list_recordings_by_time` and `list_recordings_by_id`.
|
||||
#[derive(Debug)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct ListRecordingsRow {
|
||||
pub start: recording::Time,
|
||||
pub video_sample_entry_id: i32,
|
||||
@@ -171,6 +171,11 @@ pub struct ListRecordingsRow {
|
||||
pub run_offset: i32,
|
||||
pub open_id: u32,
|
||||
pub flags: i32,
|
||||
|
||||
/// This is populated by `list_recordings_by_id` but not `list_recordings_by_time`.
|
||||
/// (It's not included in the `recording_cover` index, so adding it to
|
||||
/// `list_recordings_by_time` would be inefficient.)
|
||||
pub prev_duration_and_runs: Option<(recording::Duration, i32)>,
|
||||
}
|
||||
|
||||
/// A row used in `list_aggregated_recordings`.
|
||||
@@ -261,6 +266,7 @@ impl RecordingToInsert {
|
||||
run_offset: self.run_offset,
|
||||
open_id,
|
||||
flags: self.flags | RecordingFlags::Uncommitted as i32,
|
||||
prev_duration_and_runs: Some((self.prev_duration, self.prev_runs)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1078,7 +1084,6 @@ impl LockedDatabase {
|
||||
s.cum_duration += dur;
|
||||
s.cum_runs += if l.run_offset == 0 { 1 } else { 0 };
|
||||
let end = l.start + dur;
|
||||
info!("range={:?}", l.start .. end);
|
||||
s.add_recording(l.start .. end, l.sample_file_bytes);
|
||||
}
|
||||
s.synced_recordings = 0;
|
||||
|
||||
14
db/raw.rs
14
db/raw.rs
@@ -73,7 +73,9 @@ const LIST_RECORDINGS_BY_ID_SQL: &'static str = r#"
|
||||
recording.video_samples,
|
||||
recording.video_sync_samples,
|
||||
recording.video_sample_entry_id,
|
||||
recording.open_id
|
||||
recording.open_id,
|
||||
recording.prev_duration_90k,
|
||||
recording.prev_runs
|
||||
from
|
||||
recording
|
||||
where
|
||||
@@ -130,7 +132,7 @@ pub(crate) fn list_recordings_by_time(
|
||||
":start_time_90k": desired_time.start.0,
|
||||
":end_time_90k": desired_time.end.0,
|
||||
})?;
|
||||
list_recordings_inner(rows, f)
|
||||
list_recordings_inner(rows, false, f)
|
||||
}
|
||||
|
||||
/// Lists the specified recordings in ascending order by id.
|
||||
@@ -142,10 +144,10 @@ pub(crate) fn list_recordings_by_id(
|
||||
":start": CompositeId::new(stream_id, desired_ids.start).0,
|
||||
":end": CompositeId::new(stream_id, desired_ids.end).0,
|
||||
})?;
|
||||
list_recordings_inner(rows, f)
|
||||
list_recordings_inner(rows, true, f)
|
||||
}
|
||||
|
||||
fn list_recordings_inner(mut rows: rusqlite::Rows,
|
||||
fn list_recordings_inner(mut rows: rusqlite::Rows, include_prev: bool,
|
||||
f: &mut dyn FnMut(db::ListRecordingsRow) -> Result<(), Error>)
|
||||
-> Result<(), Error> {
|
||||
while let Some(row) = rows.next()? {
|
||||
@@ -160,6 +162,10 @@ fn list_recordings_inner(mut rows: rusqlite::Rows,
|
||||
video_sync_samples: row.get(7)?,
|
||||
video_sample_entry_id: row.get(8)?,
|
||||
open_id: row.get(9)?,
|
||||
prev_duration_and_runs: match include_prev {
|
||||
false => None,
|
||||
true => Some((recording::Duration(row.get(10)?), row.get(11)?)),
|
||||
},
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user