Skip to content

Commit

Permalink
Fix video spinner sometimes showing at the end of videos (#7622)
Browse files Browse the repository at this point in the history
### What
* Closes #7570

I'm starting to lean more towards @Wumpf view that we should try to
unify the native and web decoders to reduce code duplication… I think
I'll tackle that next.

### 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)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7622?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/7622?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!
* [x] If have noted any breaking changes to the log API in
`CHANGELOG.md` and the migration guide

- [PR Build Summary](https://build.rerun.io/pr/7622)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
emilk authored Oct 7, 2024
1 parent baebd02 commit c230971
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/viewer/re_renderer/src/video/decoder/native_av1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl VideoDecoder for Av1VideoDecoder {
return Err(DecodingError::NegativeTimestamp);
}
let presentation_timestamp = Time::from_secs(presentation_timestamp_s, self.data.timescale);
let presentation_timestamp = presentation_timestamp.min(self.data.duration); // Don't seek past the end of the video.

let Some(requested_segment_idx) = latest_at_idx(
&self.data.segments,
Expand Down
9 changes: 3 additions & 6 deletions crates/viewer/re_renderer/src/video/decoder/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ impl WebVideoDecoder {
return Err(DecodingError::NegativeTimestamp);
}
let presentation_timestamp = Time::from_secs(presentation_timestamp_s, self.data.timescale);
let presentation_timestamp = presentation_timestamp.min(self.data.duration); // Don't seek past the end of the video.

self.enqueue_requested_segments(presentation_timestamp)?;
self.try_present_frame(presentation_timestamp)
}
Expand Down Expand Up @@ -304,8 +306,6 @@ impl WebVideoDecoder {

let mut decoder_output = self.decoder_output.lock();

let timescale = self.data.timescale;

let frames = &mut decoder_output.frames;

let Some(frame_idx) = latest_at_idx(
Expand Down Expand Up @@ -346,13 +346,10 @@ impl WebVideoDecoder {
let frame_idx = 0;
let frame = &frames[frame_idx];

let frame_timestamp_ms = frame.composition_timestamp.into_millis(timescale);
let frame_duration_ms = frame.duration.into_millis(timescale);

// This handles the case when we have a buffered frame that's older than the requested timestamp.
// We don't want to show this frame to the user, because it's not actually the one they requested,
// so instead return the last decoded frame.
if presentation_timestamp.into_millis(timescale) - frame_timestamp_ms > frame_duration_ms {
if presentation_timestamp - frame.composition_timestamp > frame.duration {
return Ok(VideoFrameTexture::Pending(self.texture.clone()));
}

Expand Down

0 comments on commit c230971

Please sign in to comment.