Skip to content

Commit 46feae2

Browse files
authored
don't panic if camera frames have early timestamp (#759)
1 parent c2844c7 commit 46feae2

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

crates/media/src/sources/camera.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use flume::{Receiver, Sender};
22
use std::time::{Instant, SystemTime};
3-
use tracing::{error, info};
3+
use tracing::{error, info, warn};
44

55
use crate::{
66
data::{FFVideo, VideoInfo},
@@ -32,16 +32,20 @@ impl CameraSource {
3232

3333
fn process_frame(&self, camera_frame: RawCameraFrame) -> Result<(), MediaError> {
3434
let RawCameraFrame { frame, captured_at } = camera_frame;
35-
if let Err(_) = self.output.send((
36-
frame,
37-
captured_at
38-
.duration_since(self.start_time)
39-
.unwrap()
40-
.as_secs_f64(),
41-
)) {
42-
return Err(MediaError::Any(
43-
"Pipeline is unreachable! Stopping capture".into(),
44-
));
35+
match captured_at.duration_since(self.start_time) {
36+
Ok(time) => {
37+
if let Err(_) = self.output.send((frame, time.as_secs_f64())) {
38+
return Err(MediaError::Any(
39+
"Pipeline is unreachable! Stopping capture".into(),
40+
));
41+
}
42+
}
43+
Err(error) => {
44+
warn!(
45+
"Camera frame captured {} millis before start time",
46+
error.duration().as_millis()
47+
);
48+
}
4549
}
4650

4751
Ok(())

0 commit comments

Comments
 (0)