webrtc_m130/video/frame_decode_timing.cc
Evan Shrubsole f7a1937e70 Add FrameBufferProxy test for low-latency renderer
Ensures that frames are decoded instantly when in low-latency render
mode. This also tests the max queue size behaviour. Adds a new test
suite for FrameBufferProxy that sets the appropriate field trials.

* Fixes FrameDecodeTiming to never use negative wait times for decode
timestamps.

R=kron@webrtc.org

Change-Id: I06cbec52e1e866e21aa964b24c4fd0163c26961b
Bug: webrtc:13658
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251601
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Johannes Kron <kron@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35999}
2022-02-15 08:30:51 +00:00

58 lines
2.3 KiB
C++

/*
* 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,
bool too_many_frames_queued) {
const Timestamp now = clock_->CurrentTime();
Timestamp render_time = Timestamp::Millis(
timing_->RenderTimeMs(next_temporal_unit_rtp, now.ms()));
TimeDelta max_wait = TimeDelta::Millis(timing_->MaxWaitingTime(
render_time.ms(), now.ms(), 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.ms()
<< " with delay " << max_wait.ms() << "ms";
return absl::nullopt;
}
RTC_DLOG(LS_VERBOSE) << "Selected frame with rtp " << next_temporal_unit_rtp
<< " render time " << render_time.ms()
<< " with a max wait of " << max_wait.ms() << "ms";
Timestamp latest_decode_time = now + std::max(max_wait, TimeDelta::Zero());
return FrameSchedule{.latest_decode_time = latest_decode_time,
.render_time = render_time};
}
} // namespace webrtc