This CL breaks up the CheckQp() operation into several steps managed by the inner helper class CheckQpTask, making responding to high or low QP an asynchronous operation. Why? Reconfiguring the stream in response to QP overuse will in the future be handled on a separate task queue. See Call-Level Adaptation Processing for more details: https://docs.google.com/document/d/1ZyC26yOCknrrcYa839ZWLxD6o6Gig5A3lVTh4E41074/edit?usp=sharing Instead of "bool AdaptDown()" when high QP is reported, synchronously returning true or false depending on the result of adaptation, this CL introduces void QualityScalerQpUsageHandlerInterface::OnReportQpUsageHigh( rtc::scoped_refptr<QualityScalerQpUsageHandlerCallback>); Where QualityScalerQpUsageHandlerCallback::OnQpUsageHandled( bool clear_qp_samples); Instructs the QualityScaler whether to clear samples before checking QP the next time or to increase the frequency of checking (corresponding to AdaptDown's return value prior to this CL). QualityScaler no longer using AdaptationObserverInterface, this class is renamed and moved to overuse_frame_detector.h. The dependency between CheckQpTasks is made explicit with CheckQpTask::Result and variables like observed_enough_frames_, adapt_called_ and adapt_failed_ are moved there and given more descriptive names. Bug: webrtc:11521 Change-Id: I7faf795aeee5ded18ce75eb1617f88226e337228 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173760 Reviewed-by: Evan Shrubsole <eshr@google.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31140}
84 lines
2.7 KiB
C++
84 lines
2.7 KiB
C++
/*
|
|
* Copyright 2020 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/adaptation/encode_usage_resource.h"
|
|
|
|
#include <limits>
|
|
#include <utility>
|
|
|
|
#include "api/video/video_adaptation_reason.h"
|
|
#include "rtc_base/checks.h"
|
|
|
|
namespace webrtc {
|
|
|
|
EncodeUsageResource::EncodeUsageResource(
|
|
std::unique_ptr<OveruseFrameDetector> overuse_detector)
|
|
: overuse_detector_(std::move(overuse_detector)),
|
|
is_started_(false),
|
|
target_frame_rate_(absl::nullopt) {
|
|
RTC_DCHECK(overuse_detector_);
|
|
}
|
|
|
|
void EncodeUsageResource::StartCheckForOveruse(CpuOveruseOptions options) {
|
|
RTC_DCHECK(!is_started_);
|
|
overuse_detector_->StartCheckForOveruse(TaskQueueBase::Current(),
|
|
std::move(options), this);
|
|
is_started_ = true;
|
|
overuse_detector_->OnTargetFramerateUpdated(TargetFrameRateAsInt());
|
|
}
|
|
|
|
void EncodeUsageResource::StopCheckForOveruse() {
|
|
overuse_detector_->StopCheckForOveruse();
|
|
is_started_ = false;
|
|
}
|
|
|
|
void EncodeUsageResource::SetTargetFrameRate(
|
|
absl::optional<double> target_frame_rate) {
|
|
if (target_frame_rate == target_frame_rate_)
|
|
return;
|
|
target_frame_rate_ = target_frame_rate;
|
|
if (is_started_)
|
|
overuse_detector_->OnTargetFramerateUpdated(TargetFrameRateAsInt());
|
|
}
|
|
|
|
void EncodeUsageResource::OnEncodeStarted(const VideoFrame& cropped_frame,
|
|
int64_t time_when_first_seen_us) {
|
|
// TODO(hbos): Rename FrameCaptured() to something more appropriate (e.g.
|
|
// "OnEncodeStarted"?) or revise usage.
|
|
overuse_detector_->FrameCaptured(cropped_frame, time_when_first_seen_us);
|
|
}
|
|
|
|
void EncodeUsageResource::OnEncodeCompleted(
|
|
uint32_t timestamp,
|
|
int64_t time_sent_in_us,
|
|
int64_t capture_time_us,
|
|
absl::optional<int> encode_duration_us) {
|
|
// TODO(hbos): Rename FrameSent() to something more appropriate (e.g.
|
|
// "OnEncodeCompleted"?).
|
|
overuse_detector_->FrameSent(timestamp, time_sent_in_us, capture_time_us,
|
|
encode_duration_us);
|
|
}
|
|
|
|
void EncodeUsageResource::AdaptUp() {
|
|
OnResourceUsageStateMeasured(ResourceUsageState::kUnderuse);
|
|
}
|
|
|
|
void EncodeUsageResource::AdaptDown() {
|
|
OnResourceUsageStateMeasured(ResourceUsageState::kOveruse);
|
|
}
|
|
|
|
int EncodeUsageResource::TargetFrameRateAsInt() {
|
|
return target_frame_rate_.has_value()
|
|
? static_cast<int>(target_frame_rate_.value())
|
|
: std::numeric_limits<int>::max();
|
|
}
|
|
|
|
} // namespace webrtc
|