diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /third_party/libwebrtc/video/frame_decode_timing.cc | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/video/frame_decode_timing.cc')
-rw-r--r-- | third_party/libwebrtc/video/frame_decode_timing.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/third_party/libwebrtc/video/frame_decode_timing.cc b/third_party/libwebrtc/video/frame_decode_timing.cc new file mode 100644 index 0000000000..58ecd41c9e --- /dev/null +++ b/third_party/libwebrtc/video/frame_decode_timing.cc @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "video/frame_decode_timing.h" + +#include <algorithm> + +#include "absl/types/optional.h" +#include "api/units/time_delta.h" +#include "rtc_base/logging.h" + +namespace webrtc { + +FrameDecodeTiming::FrameDecodeTiming(Clock* clock, + webrtc::VCMTiming const* timing) + : clock_(clock), timing_(timing) { + RTC_DCHECK(clock_); + RTC_DCHECK(timing_); +} + +absl::optional<FrameDecodeTiming::FrameSchedule> +FrameDecodeTiming::OnFrameBufferUpdated(uint32_t next_temporal_unit_rtp, + uint32_t last_temporal_unit_rtp, + TimeDelta max_wait_for_frame, + bool too_many_frames_queued) { + RTC_DCHECK_GE(max_wait_for_frame, TimeDelta::Zero()); + const Timestamp now = clock_->CurrentTime(); + Timestamp render_time = timing_->RenderTime(next_temporal_unit_rtp, now); + TimeDelta max_wait = + timing_->MaxWaitingTime(render_time, now, too_many_frames_queued); + + // If the delay is not too far in the past, or this is the last decodable + // frame then it is the best frame to be decoded. Otherwise, fast-forward + // to the next frame in the buffer. + if (max_wait <= -kMaxAllowedFrameDelay && + next_temporal_unit_rtp != last_temporal_unit_rtp) { + RTC_DLOG(LS_VERBOSE) << "Fast-forwarded frame " << next_temporal_unit_rtp + << " render time " << render_time << " with delay " + << max_wait; + return absl::nullopt; + } + + max_wait.Clamp(TimeDelta::Zero(), max_wait_for_frame); + RTC_DLOG(LS_VERBOSE) << "Selected frame with rtp " << next_temporal_unit_rtp + << " render time " << render_time + << " with a max wait of " << max_wait_for_frame + << " clamped to " << max_wait; + Timestamp latest_decode_time = now + max_wait; + return FrameSchedule{.latest_decode_time = latest_decode_time, + .render_time = render_time}; +} + +} // namespace webrtc |