From 925fec376bbd9d50600c65cab1d7a6d9720cea6a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 12 Nov 2024 15:23:58 +0100 Subject: [PATCH] Improve `FrameInfo` handling (#8099) ### What Added `is_sync` and make sure `FrameInfo` is either valid or `None`. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) --- crates/store/re_video/src/decode/av1.rs | 3 +- .../re_video/src/decode/ffmpeg_h264/ffmpeg.rs | 7 ++ crates/store/re_video/src/decode/mod.rs | 28 +++--- crates/store/re_video/src/decode/webcodecs.rs | 3 +- crates/store/re_video/src/demux/mod.rs | 5 +- crates/utils/re_log/src/setup.rs | 3 +- crates/viewer/re_data_ui/src/video.rs | 51 ++++++---- .../re_renderer/src/video/chunk_decoder.rs | 15 +-- crates/viewer/re_renderer/src/video/mod.rs | 11 +-- crates/viewer/re_renderer/src/video/player.rs | 98 +++++++++---------- .../re_ui/src/list_item/property_content.rs | 11 ++- 11 files changed, 130 insertions(+), 105 deletions(-) diff --git a/crates/store/re_video/src/decode/av1.rs b/crates/store/re_video/src/decode/av1.rs index c28215ae0f95..7d2f852adeb7 100644 --- a/crates/store/re_video/src/decode/av1.rs +++ b/crates/store/re_video/src/decode/av1.rs @@ -253,9 +253,10 @@ fn create_frame(debug_name: &str, picture: &dav1d::Picture) -> Result { format, }, info: FrameInfo { + is_sync: None, // TODO(emilk) presentation_timestamp: Time(picture.timestamp().unwrap_or(0)), duration: Time(picture.duration()), - ..Default::default() + latest_decode_timestamp: None, }, }) } diff --git a/crates/store/re_video/src/decode/ffmpeg_h264/ffmpeg.rs b/crates/store/re_video/src/decode/ffmpeg_h264/ffmpeg.rs index 9829e05df12d..cd8218234e42 100644 --- a/crates/store/re_video/src/decode/ffmpeg_h264/ffmpeg.rs +++ b/crates/store/re_video/src/decode/ffmpeg_h264/ffmpeg.rs @@ -93,6 +93,11 @@ impl From for crate::decode::Error { /// ffmpeg does not tell us the timestamp/duration of a given frame, so we need to remember it. #[derive(Clone)] struct FfmpegFrameInfo { + /// The start of a new [`crate::demux::GroupOfPictures`]? + /// + /// This probably means this is a _keyframe_, and that and entire frame + /// can be decoded from only this one sample (though I'm not 100% sure). + is_sync: bool, presentation_timestamp: Time, duration: Time, decode_timestamp: Time, @@ -575,6 +580,7 @@ fn read_ffmpeg_output( format: pixel_format.clone(), }, info: FrameInfo { + is_sync: Some(frame_info.is_sync), presentation_timestamp: frame_info.presentation_timestamp, duration: frame_info.duration, latest_decode_timestamp: Some(frame_info.decode_timestamp), @@ -690,6 +696,7 @@ impl AsyncDecoder for FfmpegCliH264Decoder { // We send the information about this chunk first. // Chunks are defined to always yield a single frame. let frame_info = FfmpegFrameInfo { + is_sync: chunk.is_sync, presentation_timestamp: chunk.presentation_timestamp, decode_timestamp: chunk.decode_timestamp, duration: chunk.duration, diff --git a/crates/store/re_video/src/decode/mod.rs b/crates/store/re_video/src/decode/mod.rs index e4a46805a929..83f5055ec07b 100644 --- a/crates/store/re_video/src/decode/mod.rs +++ b/crates/store/re_video/src/decode/mod.rs @@ -215,6 +215,9 @@ pub fn new_decoder( /// For details on how to interpret the data, see [`crate::Sample`]. pub struct Chunk { /// The start of a new [`crate::demux::GroupOfPictures`]? + /// + /// This probably means this is a _keyframe_, and that and entire frame + /// can be decoded from only this one sample (though I'm not 100% sure). pub is_sync: bool, pub data: Vec, @@ -250,17 +253,18 @@ pub type FrameContent = webcodecs::WebVideoFrame; /// Meta information about a decoded video frame, as reported by the decoder. #[derive(Debug, Clone)] pub struct FrameInfo { - /// The presentation timestamp of the frame. + /// The start of a new [`crate::demux::GroupOfPictures`]? /// - /// Decoders are required to report this. - /// A timestamp of [`Time::MAX`] indicates that the frame is invalid or not yet available. + /// This probably means this is a _keyframe_, and that and entire frame + /// can be decoded from only this one sample (though I'm not 100% sure). + /// + /// None indicates that the information is not available. + pub is_sync: Option, + + /// The presentation timestamp of the frame. pub presentation_timestamp: Time, /// How long the frame is valid. - /// - /// Decoders are required to report this. - /// A duration of [`Time::MAX`] indicates that the frame is invalid or not yet available. - // Implementation note: unlike with presentation timestamp we may be able fine with making this optional. pub duration: Time, /// The decode timestamp of the last chunk that was needed to decode this frame. @@ -269,16 +273,6 @@ pub struct FrameInfo { pub latest_decode_timestamp: Option