Fix bad license header style from CRLF to LF.
Bug: webrtc:13227 Change-Id: I39a83c7ba7ad69ee7dbbd53758d45d0b3c3b5b12 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/233884 Commit-Queue: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Philip Eliasson <philipel@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35189}
This commit is contained in:
parent
339965f93c
commit
2ab7d5b961
@ -1,150 +1,150 @@
|
||||
/*
|
||||
* Copyright 2021 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 "modules/video_coding/utility/bandwidth_quality_scaler.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/video/video_adaptation_reason.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/bandwidth_quality_scaler_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/exp_filter.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
#include "rtc_base/weak_ptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kDefaultMaxWindowSizeMs = 5000;
|
||||
constexpr float kHigherMaxBitrateTolerationFactor = 0.95;
|
||||
constexpr float kLowerMinBitrateTolerationFactor = 0.8;
|
||||
constexpr int kDefaultBitrateStateUpdateIntervalSeconds = 5;
|
||||
} // namespace
|
||||
|
||||
BandwidthQualityScaler::BandwidthQualityScaler(
|
||||
BandwidthQualityScalerUsageHandlerInterface* handler)
|
||||
: kBitrateStateUpdateInterval(TimeDelta::Seconds(
|
||||
BandwidthQualityScalerSettings::ParseFromFieldTrials()
|
||||
.BitrateStateUpdateInterval()
|
||||
.value_or(kDefaultBitrateStateUpdateIntervalSeconds))),
|
||||
handler_(handler),
|
||||
encoded_bitrate_(kDefaultMaxWindowSizeMs, RateStatistics::kBpsScale),
|
||||
weak_ptr_factory_(this) {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
RTC_DCHECK(handler_ != nullptr);
|
||||
|
||||
StartCheckForBitrate();
|
||||
}
|
||||
|
||||
BandwidthQualityScaler::~BandwidthQualityScaler() {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
}
|
||||
|
||||
void BandwidthQualityScaler::StartCheckForBitrate() {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
TaskQueueBase::Current()->PostDelayedTask(
|
||||
ToQueuedTask([this_weak_ptr = weak_ptr_factory_.GetWeakPtr(), this] {
|
||||
if (!this_weak_ptr) {
|
||||
// The caller BandwidthQualityScaler has been deleted.
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
switch (CheckBitrate()) {
|
||||
case BandwidthQualityScaler::CheckBitrateResult::kHighBitRate: {
|
||||
handler_->OnReportUsageBandwidthHigh();
|
||||
last_frame_size_pixels_.reset();
|
||||
break;
|
||||
}
|
||||
case BandwidthQualityScaler::CheckBitrateResult::kLowBitRate: {
|
||||
handler_->OnReportUsageBandwidthLow();
|
||||
last_frame_size_pixels_.reset();
|
||||
break;
|
||||
}
|
||||
case BandwidthQualityScaler::CheckBitrateResult::kNormalBitrate: {
|
||||
break;
|
||||
}
|
||||
case BandwidthQualityScaler::CheckBitrateResult::
|
||||
kInsufficientSamples: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
StartCheckForBitrate();
|
||||
}),
|
||||
kBitrateStateUpdateInterval.ms());
|
||||
}
|
||||
|
||||
void BandwidthQualityScaler::ReportEncodeInfo(int frame_size_bytes,
|
||||
int64_t time_sent_in_ms,
|
||||
uint32_t encoded_width,
|
||||
uint32_t encoded_height) {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
last_time_sent_in_ms_ = time_sent_in_ms;
|
||||
last_frame_size_pixels_ = encoded_width * encoded_height;
|
||||
encoded_bitrate_.Update(frame_size_bytes, time_sent_in_ms);
|
||||
}
|
||||
|
||||
void BandwidthQualityScaler::SetResolutionBitrateLimits(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits) {
|
||||
if (resolution_bitrate_limits.empty()) {
|
||||
resolution_bitrate_limits_ = EncoderInfoSettings::
|
||||
GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted();
|
||||
} else {
|
||||
resolution_bitrate_limits_ = resolution_bitrate_limits;
|
||||
}
|
||||
}
|
||||
|
||||
BandwidthQualityScaler::CheckBitrateResult
|
||||
BandwidthQualityScaler::CheckBitrate() {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
if (!last_frame_size_pixels_.has_value() ||
|
||||
!last_time_sent_in_ms_.has_value()) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kInsufficientSamples;
|
||||
}
|
||||
|
||||
absl::optional<int64_t> current_bitrate_bps =
|
||||
encoded_bitrate_.Rate(last_time_sent_in_ms_.value());
|
||||
if (!current_bitrate_bps.has_value()) {
|
||||
// We can't get a valid bitrate due to not enough data points.
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kInsufficientSamples;
|
||||
}
|
||||
absl::optional<VideoEncoder::ResolutionBitrateLimits> suitable_bitrate_limit =
|
||||
EncoderInfoSettings::
|
||||
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||
last_frame_size_pixels_, resolution_bitrate_limits_);
|
||||
|
||||
if (!suitable_bitrate_limit.has_value()) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kInsufficientSamples;
|
||||
}
|
||||
|
||||
// Multiply by toleration factor to solve the frequent adaptation due to
|
||||
// critical value.
|
||||
if (current_bitrate_bps > suitable_bitrate_limit->max_bitrate_bps *
|
||||
kHigherMaxBitrateTolerationFactor) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kLowBitRate;
|
||||
} else if (current_bitrate_bps <
|
||||
suitable_bitrate_limit->min_start_bitrate_bps *
|
||||
kLowerMinBitrateTolerationFactor) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kHighBitRate;
|
||||
}
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kNormalBitrate;
|
||||
}
|
||||
|
||||
BandwidthQualityScalerUsageHandlerInterface::
|
||||
~BandwidthQualityScalerUsageHandlerInterface() {}
|
||||
} // namespace webrtc
|
||||
/*
|
||||
* Copyright (c) 2021 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 "modules/video_coding/utility/bandwidth_quality_scaler.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/video/video_adaptation_reason.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/bandwidth_quality_scaler_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/exp_filter.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
#include "rtc_base/weak_ptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int kDefaultMaxWindowSizeMs = 5000;
|
||||
constexpr float kHigherMaxBitrateTolerationFactor = 0.95;
|
||||
constexpr float kLowerMinBitrateTolerationFactor = 0.8;
|
||||
constexpr int kDefaultBitrateStateUpdateIntervalSeconds = 5;
|
||||
} // namespace
|
||||
|
||||
BandwidthQualityScaler::BandwidthQualityScaler(
|
||||
BandwidthQualityScalerUsageHandlerInterface* handler)
|
||||
: kBitrateStateUpdateInterval(TimeDelta::Seconds(
|
||||
BandwidthQualityScalerSettings::ParseFromFieldTrials()
|
||||
.BitrateStateUpdateInterval()
|
||||
.value_or(kDefaultBitrateStateUpdateIntervalSeconds))),
|
||||
handler_(handler),
|
||||
encoded_bitrate_(kDefaultMaxWindowSizeMs, RateStatistics::kBpsScale),
|
||||
weak_ptr_factory_(this) {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
RTC_DCHECK(handler_ != nullptr);
|
||||
|
||||
StartCheckForBitrate();
|
||||
}
|
||||
|
||||
BandwidthQualityScaler::~BandwidthQualityScaler() {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
}
|
||||
|
||||
void BandwidthQualityScaler::StartCheckForBitrate() {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
TaskQueueBase::Current()->PostDelayedTask(
|
||||
ToQueuedTask([this_weak_ptr = weak_ptr_factory_.GetWeakPtr(), this] {
|
||||
if (!this_weak_ptr) {
|
||||
// The caller BandwidthQualityScaler has been deleted.
|
||||
return;
|
||||
}
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
switch (CheckBitrate()) {
|
||||
case BandwidthQualityScaler::CheckBitrateResult::kHighBitRate: {
|
||||
handler_->OnReportUsageBandwidthHigh();
|
||||
last_frame_size_pixels_.reset();
|
||||
break;
|
||||
}
|
||||
case BandwidthQualityScaler::CheckBitrateResult::kLowBitRate: {
|
||||
handler_->OnReportUsageBandwidthLow();
|
||||
last_frame_size_pixels_.reset();
|
||||
break;
|
||||
}
|
||||
case BandwidthQualityScaler::CheckBitrateResult::kNormalBitrate: {
|
||||
break;
|
||||
}
|
||||
case BandwidthQualityScaler::CheckBitrateResult::
|
||||
kInsufficientSamples: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
StartCheckForBitrate();
|
||||
}),
|
||||
kBitrateStateUpdateInterval.ms());
|
||||
}
|
||||
|
||||
void BandwidthQualityScaler::ReportEncodeInfo(int frame_size_bytes,
|
||||
int64_t time_sent_in_ms,
|
||||
uint32_t encoded_width,
|
||||
uint32_t encoded_height) {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
last_time_sent_in_ms_ = time_sent_in_ms;
|
||||
last_frame_size_pixels_ = encoded_width * encoded_height;
|
||||
encoded_bitrate_.Update(frame_size_bytes, time_sent_in_ms);
|
||||
}
|
||||
|
||||
void BandwidthQualityScaler::SetResolutionBitrateLimits(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits) {
|
||||
if (resolution_bitrate_limits.empty()) {
|
||||
resolution_bitrate_limits_ = EncoderInfoSettings::
|
||||
GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted();
|
||||
} else {
|
||||
resolution_bitrate_limits_ = resolution_bitrate_limits;
|
||||
}
|
||||
}
|
||||
|
||||
BandwidthQualityScaler::CheckBitrateResult
|
||||
BandwidthQualityScaler::CheckBitrate() {
|
||||
RTC_DCHECK_RUN_ON(&task_checker_);
|
||||
if (!last_frame_size_pixels_.has_value() ||
|
||||
!last_time_sent_in_ms_.has_value()) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kInsufficientSamples;
|
||||
}
|
||||
|
||||
absl::optional<int64_t> current_bitrate_bps =
|
||||
encoded_bitrate_.Rate(last_time_sent_in_ms_.value());
|
||||
if (!current_bitrate_bps.has_value()) {
|
||||
// We can't get a valid bitrate due to not enough data points.
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kInsufficientSamples;
|
||||
}
|
||||
absl::optional<VideoEncoder::ResolutionBitrateLimits> suitable_bitrate_limit =
|
||||
EncoderInfoSettings::
|
||||
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||
last_frame_size_pixels_, resolution_bitrate_limits_);
|
||||
|
||||
if (!suitable_bitrate_limit.has_value()) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kInsufficientSamples;
|
||||
}
|
||||
|
||||
// Multiply by toleration factor to solve the frequent adaptation due to
|
||||
// critical value.
|
||||
if (current_bitrate_bps > suitable_bitrate_limit->max_bitrate_bps *
|
||||
kHigherMaxBitrateTolerationFactor) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kLowBitRate;
|
||||
} else if (current_bitrate_bps <
|
||||
suitable_bitrate_limit->min_start_bitrate_bps *
|
||||
kLowerMinBitrateTolerationFactor) {
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kHighBitRate;
|
||||
}
|
||||
return BandwidthQualityScaler::CheckBitrateResult::kNormalBitrate;
|
||||
}
|
||||
|
||||
BandwidthQualityScalerUsageHandlerInterface::
|
||||
~BandwidthQualityScalerUsageHandlerInterface() {}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -1,95 +1,95 @@
|
||||
/*
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_VIDEO_CODING_UTILITY_BANDWIDTH_QUALITY_SCALER_H_
|
||||
#define MODULES_VIDEO_CODING_UTILITY_BANDWIDTH_QUALITY_SCALER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/sequence_checker.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "rtc_base/experiments/encoder_info_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/exp_filter.h"
|
||||
#include "rtc_base/rate_statistics.h"
|
||||
#include "rtc_base/ref_count.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/system/no_unique_address.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/weak_ptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class BandwidthQualityScalerUsageHandlerInterface {
|
||||
public:
|
||||
virtual ~BandwidthQualityScalerUsageHandlerInterface();
|
||||
|
||||
virtual void OnReportUsageBandwidthHigh() = 0;
|
||||
virtual void OnReportUsageBandwidthLow() = 0;
|
||||
};
|
||||
|
||||
// BandwidthQualityScaler runs asynchronously and monitors bandwidth values of
|
||||
// encoded frames. It holds a reference to a
|
||||
// BandwidthQualityScalerUsageHandlerInterface implementation to signal an
|
||||
// overuse or underuse of bandwidth (which indicate a desire to scale the video
|
||||
// stream down or up).
|
||||
class BandwidthQualityScaler {
|
||||
public:
|
||||
explicit BandwidthQualityScaler(
|
||||
BandwidthQualityScalerUsageHandlerInterface* handler);
|
||||
virtual ~BandwidthQualityScaler();
|
||||
|
||||
void ReportEncodeInfo(int frame_size_bytes,
|
||||
int64_t time_sent_in_ms,
|
||||
uint32_t encoded_width,
|
||||
uint32_t encoded_height);
|
||||
|
||||
// We prioritise to using the |resolution_bitrate_limits| provided by the
|
||||
// current decoder. If not provided, we will use the default data by
|
||||
// GetDefaultResolutionBitrateLimits().
|
||||
void SetResolutionBitrateLimits(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits);
|
||||
|
||||
const TimeDelta kBitrateStateUpdateInterval;
|
||||
|
||||
private:
|
||||
enum class CheckBitrateResult {
|
||||
kInsufficientSamples,
|
||||
kNormalBitrate,
|
||||
kHighBitRate,
|
||||
kLowBitRate,
|
||||
};
|
||||
|
||||
// We will periodically check encode bitrate, this function will make
|
||||
// resolution up or down decisions and report the decision to the adapter.
|
||||
void StartCheckForBitrate();
|
||||
CheckBitrateResult CheckBitrate();
|
||||
|
||||
RTC_NO_UNIQUE_ADDRESS SequenceChecker task_checker_;
|
||||
BandwidthQualityScalerUsageHandlerInterface* const handler_
|
||||
RTC_GUARDED_BY(&task_checker_);
|
||||
|
||||
absl::optional<int64_t> last_time_sent_in_ms_ RTC_GUARDED_BY(&task_checker_);
|
||||
RateStatistics encoded_bitrate_ RTC_GUARDED_BY(&task_checker_);
|
||||
absl::optional<int> last_frame_size_pixels_ RTC_GUARDED_BY(&task_checker_);
|
||||
rtc::WeakPtrFactory<BandwidthQualityScaler> weak_ptr_factory_;
|
||||
|
||||
std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_VIDEO_CODING_UTILITY_BANDWIDTH_QUALITY_SCALER_H_
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_VIDEO_CODING_UTILITY_BANDWIDTH_QUALITY_SCALER_H_
|
||||
#define MODULES_VIDEO_CODING_UTILITY_BANDWIDTH_QUALITY_SCALER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/sequence_checker.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "rtc_base/experiments/encoder_info_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/exp_filter.h"
|
||||
#include "rtc_base/rate_statistics.h"
|
||||
#include "rtc_base/ref_count.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/system/no_unique_address.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "rtc_base/weak_ptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class BandwidthQualityScalerUsageHandlerInterface {
|
||||
public:
|
||||
virtual ~BandwidthQualityScalerUsageHandlerInterface();
|
||||
|
||||
virtual void OnReportUsageBandwidthHigh() = 0;
|
||||
virtual void OnReportUsageBandwidthLow() = 0;
|
||||
};
|
||||
|
||||
// BandwidthQualityScaler runs asynchronously and monitors bandwidth values of
|
||||
// encoded frames. It holds a reference to a
|
||||
// BandwidthQualityScalerUsageHandlerInterface implementation to signal an
|
||||
// overuse or underuse of bandwidth (which indicate a desire to scale the video
|
||||
// stream down or up).
|
||||
class BandwidthQualityScaler {
|
||||
public:
|
||||
explicit BandwidthQualityScaler(
|
||||
BandwidthQualityScalerUsageHandlerInterface* handler);
|
||||
virtual ~BandwidthQualityScaler();
|
||||
|
||||
void ReportEncodeInfo(int frame_size_bytes,
|
||||
int64_t time_sent_in_ms,
|
||||
uint32_t encoded_width,
|
||||
uint32_t encoded_height);
|
||||
|
||||
// We prioritise to using the |resolution_bitrate_limits| provided by the
|
||||
// current decoder. If not provided, we will use the default data by
|
||||
// GetDefaultResolutionBitrateLimits().
|
||||
void SetResolutionBitrateLimits(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits);
|
||||
|
||||
const TimeDelta kBitrateStateUpdateInterval;
|
||||
|
||||
private:
|
||||
enum class CheckBitrateResult {
|
||||
kInsufficientSamples,
|
||||
kNormalBitrate,
|
||||
kHighBitRate,
|
||||
kLowBitRate,
|
||||
};
|
||||
|
||||
// We will periodically check encode bitrate, this function will make
|
||||
// resolution up or down decisions and report the decision to the adapter.
|
||||
void StartCheckForBitrate();
|
||||
CheckBitrateResult CheckBitrate();
|
||||
|
||||
RTC_NO_UNIQUE_ADDRESS SequenceChecker task_checker_;
|
||||
BandwidthQualityScalerUsageHandlerInterface* const handler_
|
||||
RTC_GUARDED_BY(&task_checker_);
|
||||
|
||||
absl::optional<int64_t> last_time_sent_in_ms_ RTC_GUARDED_BY(&task_checker_);
|
||||
RateStatistics encoded_bitrate_ RTC_GUARDED_BY(&task_checker_);
|
||||
absl::optional<int> last_frame_size_pixels_ RTC_GUARDED_BY(&task_checker_);
|
||||
rtc::WeakPtrFactory<BandwidthQualityScaler> weak_ptr_factory_;
|
||||
|
||||
std::vector<VideoEncoder::ResolutionBitrateLimits> resolution_bitrate_limits_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_VIDEO_CODING_UTILITY_BANDWIDTH_QUALITY_SCALER_H_
|
||||
|
||||
@ -1,279 +1,279 @@
|
||||
/*
|
||||
* Copyright 2021 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 "modules/video_coding/utility/bandwidth_quality_scaler.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/experiments/encoder_info_settings.h"
|
||||
#include "rtc_base/task_queue_for_test.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
#include "test/field_trial.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
constexpr int kFramerateFps = 30;
|
||||
constexpr int kDefaultBitrateStateUpdateIntervalSeconds = 5;
|
||||
constexpr int kDefaultEncodeDeltaTimeMs = 33; // 1/30(s) => 33(ms)
|
||||
|
||||
} // namespace
|
||||
|
||||
class FakeBandwidthQualityScalerHandler
|
||||
: public BandwidthQualityScalerUsageHandlerInterface {
|
||||
public:
|
||||
~FakeBandwidthQualityScalerHandler() override = default;
|
||||
void OnReportUsageBandwidthHigh() override {
|
||||
adapt_down_event_count_++;
|
||||
event_.Set();
|
||||
}
|
||||
|
||||
void OnReportUsageBandwidthLow() override {
|
||||
adapt_up_event_count_++;
|
||||
event_.Set();
|
||||
}
|
||||
|
||||
rtc::Event event_;
|
||||
int adapt_up_event_count_ = 0;
|
||||
int adapt_down_event_count_ = 0;
|
||||
};
|
||||
|
||||
class BandwidthQualityScalerUnderTest : public BandwidthQualityScaler {
|
||||
public:
|
||||
explicit BandwidthQualityScalerUnderTest(
|
||||
BandwidthQualityScalerUsageHandlerInterface* handler)
|
||||
: BandwidthQualityScaler(handler) {}
|
||||
|
||||
int GetBitrateStateUpdateIntervalMs() {
|
||||
return this->kBitrateStateUpdateInterval.ms() + 200;
|
||||
}
|
||||
};
|
||||
|
||||
class BandwidthQualityScalerTest
|
||||
: public ::testing::Test,
|
||||
public ::testing::WithParamInterface<std::string> {
|
||||
protected:
|
||||
enum ScaleDirection {
|
||||
kKeepScaleNormalBandwidth,
|
||||
kKeepScaleAboveMaxBandwidth,
|
||||
kKeepScaleUnderMinBandwidth,
|
||||
};
|
||||
|
||||
enum FrameType {
|
||||
kKeyFrame,
|
||||
kNormalFrame,
|
||||
kNormalFrame_Overuse,
|
||||
kNormalFrame_Underuse,
|
||||
};
|
||||
struct FrameConfig {
|
||||
FrameConfig(int frame_num,
|
||||
FrameType frame_type,
|
||||
int actual_width,
|
||||
int actual_height)
|
||||
: frame_num(frame_num),
|
||||
frame_type(frame_type),
|
||||
actual_width(actual_width),
|
||||
actual_height(actual_height) {}
|
||||
|
||||
int frame_num;
|
||||
FrameType frame_type;
|
||||
int actual_width;
|
||||
int actual_height;
|
||||
};
|
||||
|
||||
BandwidthQualityScalerTest()
|
||||
: scoped_field_trial_(GetParam()),
|
||||
task_queue_("BandwidthQualityScalerTestQueue"),
|
||||
handler_(std::make_unique<FakeBandwidthQualityScalerHandler>()) {
|
||||
task_queue_.SendTask(
|
||||
[this] {
|
||||
bandwidth_quality_scaler_ =
|
||||
std::unique_ptr<BandwidthQualityScalerUnderTest>(
|
||||
new BandwidthQualityScalerUnderTest(handler_.get()));
|
||||
bandwidth_quality_scaler_->SetResolutionBitrateLimits(
|
||||
EncoderInfoSettings::
|
||||
GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted());
|
||||
// Only for testing. Set first_timestamp_ in RateStatistics to 0.
|
||||
bandwidth_quality_scaler_->ReportEncodeInfo(0, 0, 0, 0);
|
||||
},
|
||||
RTC_FROM_HERE);
|
||||
}
|
||||
|
||||
~BandwidthQualityScalerTest() {
|
||||
task_queue_.SendTask([this] { bandwidth_quality_scaler_ = nullptr; },
|
||||
RTC_FROM_HERE);
|
||||
}
|
||||
|
||||
int GetFrameSizeBytes(
|
||||
const FrameConfig& config,
|
||||
const VideoEncoder::ResolutionBitrateLimits& bitrate_limits) {
|
||||
int scale = 8 * kFramerateFps;
|
||||
switch (config.frame_type) {
|
||||
case FrameType::kKeyFrame: {
|
||||
// 4 is experimental value. Based on the test, the number of bytes of
|
||||
// the key frame is about four times of the normal frame
|
||||
return bitrate_limits.max_bitrate_bps * 4 / scale;
|
||||
}
|
||||
case FrameType::kNormalFrame_Overuse: {
|
||||
return bitrate_limits.max_bitrate_bps * 3 / 2 / scale;
|
||||
}
|
||||
case FrameType::kNormalFrame_Underuse: {
|
||||
return bitrate_limits.min_start_bitrate_bps * 3 / 4 / scale;
|
||||
}
|
||||
case FrameType::kNormalFrame: {
|
||||
return (bitrate_limits.max_bitrate_bps +
|
||||
bitrate_limits.min_start_bitrate_bps) /
|
||||
2 / scale;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
absl::optional<VideoEncoder::ResolutionBitrateLimits>
|
||||
GetDefaultSuitableBitrateLimit(int frame_size_pixels) {
|
||||
return EncoderInfoSettings::
|
||||
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||
frame_size_pixels,
|
||||
EncoderInfoSettings::
|
||||
GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted());
|
||||
}
|
||||
|
||||
void TriggerBandwidthQualityScalerTest(
|
||||
const std::vector<FrameConfig>& frame_configs) {
|
||||
task_queue_.SendTask(
|
||||
[frame_configs, this] {
|
||||
RTC_CHECK(!frame_configs.empty());
|
||||
|
||||
int total_frame_nums = 0;
|
||||
for (const FrameConfig& frame_config : frame_configs) {
|
||||
total_frame_nums += frame_config.frame_num;
|
||||
}
|
||||
|
||||
EXPECT_EQ(kFramerateFps * kDefaultBitrateStateUpdateIntervalSeconds,
|
||||
total_frame_nums);
|
||||
|
||||
uint32_t time_send_to_scaler_ms_ = rtc::TimeMillis();
|
||||
for (size_t i = 0; i < frame_configs.size(); ++i) {
|
||||
const FrameConfig& config = frame_configs[i];
|
||||
absl::optional<VideoEncoder::ResolutionBitrateLimits>
|
||||
suitable_bitrate = GetDefaultSuitableBitrateLimit(
|
||||
config.actual_width * config.actual_height);
|
||||
EXPECT_TRUE(suitable_bitrate);
|
||||
for (int j = 0; j <= config.frame_num; ++j) {
|
||||
time_send_to_scaler_ms_ += kDefaultEncodeDeltaTimeMs;
|
||||
int frame_size_bytes =
|
||||
GetFrameSizeBytes(config, suitable_bitrate.value());
|
||||
RTC_CHECK(frame_size_bytes > 0);
|
||||
bandwidth_quality_scaler_->ReportEncodeInfo(
|
||||
frame_size_bytes, time_send_to_scaler_ms_,
|
||||
config.actual_width, config.actual_height);
|
||||
}
|
||||
}
|
||||
},
|
||||
RTC_FROM_HERE);
|
||||
}
|
||||
|
||||
test::ScopedFieldTrials scoped_field_trial_;
|
||||
TaskQueueForTest task_queue_;
|
||||
std::unique_ptr<BandwidthQualityScalerUnderTest> bandwidth_quality_scaler_;
|
||||
std::unique_ptr<FakeBandwidthQualityScalerHandler> handler_;
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FieldTrials,
|
||||
BandwidthQualityScalerTest,
|
||||
::testing::Values("WebRTC-Video-BandwidthQualityScalerSettings/"
|
||||
"bitrate_state_update_interval_s_:1/",
|
||||
"WebRTC-Video-BandwidthQualityScalerSettings/"
|
||||
"bitrate_state_update_interval_s_:2/"));
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, AllNormalFrame_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(150, FrameType::kNormalFrame, 640, 360)};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 654253, so it falls in the range
|
||||
// without any operation(up/down).
|
||||
EXPECT_FALSE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(0, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, AllNoramlFrame_AboveMaxBandwidth_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(150, FrameType::kNormalFrame_Overuse, 640, 360)};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 1208000 > 800000 * 0.95, so it
|
||||
// triggers adapt_up_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(1, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, AllNormalFrame_Underuse_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(150, FrameType::kNormalFrame_Underuse, 640, 360)};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 377379 < 500000 * 0.8, so it
|
||||
// triggers adapt_down_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(1, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(0, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, FixedFrameTypeTest1_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(5, FrameType::kNormalFrame_Underuse, 640, 360),
|
||||
FrameConfig(110, FrameType::kNormalFrame, 640, 360),
|
||||
FrameConfig(20, FrameType::kNormalFrame_Overuse, 640, 360),
|
||||
FrameConfig(15, FrameType::kKeyFrame, 640, 360),
|
||||
};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it
|
||||
// triggers adapt_up_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(1, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, FixedFrameTypeTest2_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(10, FrameType::kNormalFrame_Underuse, 640, 360),
|
||||
FrameConfig(50, FrameType::kNormalFrame, 640, 360),
|
||||
FrameConfig(5, FrameType::kKeyFrame, 640, 360),
|
||||
FrameConfig(85, FrameType::kNormalFrame_Overuse, 640, 360),
|
||||
};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it
|
||||
// triggers adapt_up_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(1, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
/*
|
||||
* Copyright (c) 2021 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 "modules/video_coding/utility/bandwidth_quality_scaler.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/experiments/encoder_info_settings.h"
|
||||
#include "rtc_base/task_queue_for_test.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
#include "test/field_trial.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
constexpr int kFramerateFps = 30;
|
||||
constexpr int kDefaultBitrateStateUpdateIntervalSeconds = 5;
|
||||
constexpr int kDefaultEncodeDeltaTimeMs = 33; // 1/30(s) => 33(ms)
|
||||
|
||||
} // namespace
|
||||
|
||||
class FakeBandwidthQualityScalerHandler
|
||||
: public BandwidthQualityScalerUsageHandlerInterface {
|
||||
public:
|
||||
~FakeBandwidthQualityScalerHandler() override = default;
|
||||
void OnReportUsageBandwidthHigh() override {
|
||||
adapt_down_event_count_++;
|
||||
event_.Set();
|
||||
}
|
||||
|
||||
void OnReportUsageBandwidthLow() override {
|
||||
adapt_up_event_count_++;
|
||||
event_.Set();
|
||||
}
|
||||
|
||||
rtc::Event event_;
|
||||
int adapt_up_event_count_ = 0;
|
||||
int adapt_down_event_count_ = 0;
|
||||
};
|
||||
|
||||
class BandwidthQualityScalerUnderTest : public BandwidthQualityScaler {
|
||||
public:
|
||||
explicit BandwidthQualityScalerUnderTest(
|
||||
BandwidthQualityScalerUsageHandlerInterface* handler)
|
||||
: BandwidthQualityScaler(handler) {}
|
||||
|
||||
int GetBitrateStateUpdateIntervalMs() {
|
||||
return this->kBitrateStateUpdateInterval.ms() + 200;
|
||||
}
|
||||
};
|
||||
|
||||
class BandwidthQualityScalerTest
|
||||
: public ::testing::Test,
|
||||
public ::testing::WithParamInterface<std::string> {
|
||||
protected:
|
||||
enum ScaleDirection {
|
||||
kKeepScaleNormalBandwidth,
|
||||
kKeepScaleAboveMaxBandwidth,
|
||||
kKeepScaleUnderMinBandwidth,
|
||||
};
|
||||
|
||||
enum FrameType {
|
||||
kKeyFrame,
|
||||
kNormalFrame,
|
||||
kNormalFrame_Overuse,
|
||||
kNormalFrame_Underuse,
|
||||
};
|
||||
struct FrameConfig {
|
||||
FrameConfig(int frame_num,
|
||||
FrameType frame_type,
|
||||
int actual_width,
|
||||
int actual_height)
|
||||
: frame_num(frame_num),
|
||||
frame_type(frame_type),
|
||||
actual_width(actual_width),
|
||||
actual_height(actual_height) {}
|
||||
|
||||
int frame_num;
|
||||
FrameType frame_type;
|
||||
int actual_width;
|
||||
int actual_height;
|
||||
};
|
||||
|
||||
BandwidthQualityScalerTest()
|
||||
: scoped_field_trial_(GetParam()),
|
||||
task_queue_("BandwidthQualityScalerTestQueue"),
|
||||
handler_(std::make_unique<FakeBandwidthQualityScalerHandler>()) {
|
||||
task_queue_.SendTask(
|
||||
[this] {
|
||||
bandwidth_quality_scaler_ =
|
||||
std::unique_ptr<BandwidthQualityScalerUnderTest>(
|
||||
new BandwidthQualityScalerUnderTest(handler_.get()));
|
||||
bandwidth_quality_scaler_->SetResolutionBitrateLimits(
|
||||
EncoderInfoSettings::
|
||||
GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted());
|
||||
// Only for testing. Set first_timestamp_ in RateStatistics to 0.
|
||||
bandwidth_quality_scaler_->ReportEncodeInfo(0, 0, 0, 0);
|
||||
},
|
||||
RTC_FROM_HERE);
|
||||
}
|
||||
|
||||
~BandwidthQualityScalerTest() {
|
||||
task_queue_.SendTask([this] { bandwidth_quality_scaler_ = nullptr; },
|
||||
RTC_FROM_HERE);
|
||||
}
|
||||
|
||||
int GetFrameSizeBytes(
|
||||
const FrameConfig& config,
|
||||
const VideoEncoder::ResolutionBitrateLimits& bitrate_limits) {
|
||||
int scale = 8 * kFramerateFps;
|
||||
switch (config.frame_type) {
|
||||
case FrameType::kKeyFrame: {
|
||||
// 4 is experimental value. Based on the test, the number of bytes of
|
||||
// the key frame is about four times of the normal frame
|
||||
return bitrate_limits.max_bitrate_bps * 4 / scale;
|
||||
}
|
||||
case FrameType::kNormalFrame_Overuse: {
|
||||
return bitrate_limits.max_bitrate_bps * 3 / 2 / scale;
|
||||
}
|
||||
case FrameType::kNormalFrame_Underuse: {
|
||||
return bitrate_limits.min_start_bitrate_bps * 3 / 4 / scale;
|
||||
}
|
||||
case FrameType::kNormalFrame: {
|
||||
return (bitrate_limits.max_bitrate_bps +
|
||||
bitrate_limits.min_start_bitrate_bps) /
|
||||
2 / scale;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
absl::optional<VideoEncoder::ResolutionBitrateLimits>
|
||||
GetDefaultSuitableBitrateLimit(int frame_size_pixels) {
|
||||
return EncoderInfoSettings::
|
||||
GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted(
|
||||
frame_size_pixels,
|
||||
EncoderInfoSettings::
|
||||
GetDefaultSinglecastBitrateLimitsWhenQpIsUntrusted());
|
||||
}
|
||||
|
||||
void TriggerBandwidthQualityScalerTest(
|
||||
const std::vector<FrameConfig>& frame_configs) {
|
||||
task_queue_.SendTask(
|
||||
[frame_configs, this] {
|
||||
RTC_CHECK(!frame_configs.empty());
|
||||
|
||||
int total_frame_nums = 0;
|
||||
for (const FrameConfig& frame_config : frame_configs) {
|
||||
total_frame_nums += frame_config.frame_num;
|
||||
}
|
||||
|
||||
EXPECT_EQ(kFramerateFps * kDefaultBitrateStateUpdateIntervalSeconds,
|
||||
total_frame_nums);
|
||||
|
||||
uint32_t time_send_to_scaler_ms_ = rtc::TimeMillis();
|
||||
for (size_t i = 0; i < frame_configs.size(); ++i) {
|
||||
const FrameConfig& config = frame_configs[i];
|
||||
absl::optional<VideoEncoder::ResolutionBitrateLimits>
|
||||
suitable_bitrate = GetDefaultSuitableBitrateLimit(
|
||||
config.actual_width * config.actual_height);
|
||||
EXPECT_TRUE(suitable_bitrate);
|
||||
for (int j = 0; j <= config.frame_num; ++j) {
|
||||
time_send_to_scaler_ms_ += kDefaultEncodeDeltaTimeMs;
|
||||
int frame_size_bytes =
|
||||
GetFrameSizeBytes(config, suitable_bitrate.value());
|
||||
RTC_CHECK(frame_size_bytes > 0);
|
||||
bandwidth_quality_scaler_->ReportEncodeInfo(
|
||||
frame_size_bytes, time_send_to_scaler_ms_,
|
||||
config.actual_width, config.actual_height);
|
||||
}
|
||||
}
|
||||
},
|
||||
RTC_FROM_HERE);
|
||||
}
|
||||
|
||||
test::ScopedFieldTrials scoped_field_trial_;
|
||||
TaskQueueForTest task_queue_;
|
||||
std::unique_ptr<BandwidthQualityScalerUnderTest> bandwidth_quality_scaler_;
|
||||
std::unique_ptr<FakeBandwidthQualityScalerHandler> handler_;
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
FieldTrials,
|
||||
BandwidthQualityScalerTest,
|
||||
::testing::Values("WebRTC-Video-BandwidthQualityScalerSettings/"
|
||||
"bitrate_state_update_interval_s_:1/",
|
||||
"WebRTC-Video-BandwidthQualityScalerSettings/"
|
||||
"bitrate_state_update_interval_s_:2/"));
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, AllNormalFrame_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(150, FrameType::kNormalFrame, 640, 360)};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 654253, so it falls in the range
|
||||
// without any operation(up/down).
|
||||
EXPECT_FALSE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(0, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, AllNoramlFrame_AboveMaxBandwidth_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(150, FrameType::kNormalFrame_Overuse, 640, 360)};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 1208000 > 800000 * 0.95, so it
|
||||
// triggers adapt_up_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(1, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, AllNormalFrame_Underuse_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(150, FrameType::kNormalFrame_Underuse, 640, 360)};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 377379 < 500000 * 0.8, so it
|
||||
// triggers adapt_down_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(1, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(0, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, FixedFrameTypeTest1_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(5, FrameType::kNormalFrame_Underuse, 640, 360),
|
||||
FrameConfig(110, FrameType::kNormalFrame, 640, 360),
|
||||
FrameConfig(20, FrameType::kNormalFrame_Overuse, 640, 360),
|
||||
FrameConfig(15, FrameType::kKeyFrame, 640, 360),
|
||||
};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it
|
||||
// triggers adapt_up_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(1, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
TEST_P(BandwidthQualityScalerTest, FixedFrameTypeTest2_640x360) {
|
||||
const std::vector<FrameConfig> frame_configs{
|
||||
FrameConfig(10, FrameType::kNormalFrame_Underuse, 640, 360),
|
||||
FrameConfig(50, FrameType::kNormalFrame, 640, 360),
|
||||
FrameConfig(5, FrameType::kKeyFrame, 640, 360),
|
||||
FrameConfig(85, FrameType::kNormalFrame_Overuse, 640, 360),
|
||||
};
|
||||
TriggerBandwidthQualityScalerTest(frame_configs);
|
||||
|
||||
// When resolution is 640*360, experimental working bitrate range is
|
||||
// [500000,800000] bps. Encoded bitrate is 1059462 > 800000 * 0.95, so it
|
||||
// triggers adapt_up_event_count_.
|
||||
EXPECT_TRUE(handler_->event_.Wait(
|
||||
bandwidth_quality_scaler_->GetBitrateStateUpdateIntervalMs()));
|
||||
EXPECT_EQ(0, handler_->adapt_down_event_count_);
|
||||
EXPECT_EQ(1, handler_->adapt_up_event_count_);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -1,85 +1,85 @@
|
||||
/*
|
||||
* Copyright 2021 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/bandwidth_quality_scaler_resource.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/balanced_degradation_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// static
|
||||
rtc::scoped_refptr<BandwidthQualityScalerResource>
|
||||
BandwidthQualityScalerResource::Create() {
|
||||
return rtc::make_ref_counted<BandwidthQualityScalerResource>();
|
||||
}
|
||||
|
||||
BandwidthQualityScalerResource::BandwidthQualityScalerResource()
|
||||
: VideoStreamEncoderResource("BandwidthQualityScalerResource"),
|
||||
bandwidth_quality_scaler_(nullptr) {}
|
||||
|
||||
BandwidthQualityScalerResource::~BandwidthQualityScalerResource() {
|
||||
RTC_DCHECK(!bandwidth_quality_scaler_);
|
||||
}
|
||||
|
||||
bool BandwidthQualityScalerResource::is_started() const {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
return bandwidth_quality_scaler_.get();
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::StartCheckForOveruse(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits) {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
RTC_DCHECK(!is_started());
|
||||
bandwidth_quality_scaler_ = std::make_unique<BandwidthQualityScaler>(this);
|
||||
|
||||
// If the configuration parameters more than one, we should define and
|
||||
// declare the function BandwidthQualityScaler::Initialize() and call it.
|
||||
bandwidth_quality_scaler_->SetResolutionBitrateLimits(
|
||||
resolution_bitrate_limits);
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::StopCheckForOveruse() {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
RTC_DCHECK(is_started());
|
||||
// Ensure we have no pending callbacks. This makes it safe to destroy the
|
||||
// BandwidthQualityScaler and even task queues with tasks in-flight.
|
||||
bandwidth_quality_scaler_.reset();
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::OnReportUsageBandwidthHigh() {
|
||||
OnResourceUsageStateMeasured(ResourceUsageState::kOveruse);
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::OnReportUsageBandwidthLow() {
|
||||
OnResourceUsageStateMeasured(ResourceUsageState::kUnderuse);
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::OnEncodeCompleted(
|
||||
const EncodedImage& encoded_image,
|
||||
int64_t time_sent_in_us,
|
||||
int64_t encoded_image_size_bytes) {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
|
||||
if (bandwidth_quality_scaler_) {
|
||||
bandwidth_quality_scaler_->ReportEncodeInfo(
|
||||
encoded_image_size_bytes, time_sent_in_us / 1000,
|
||||
encoded_image._encodedWidth, encoded_image._encodedHeight);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
/*
|
||||
* Copyright (c) 2021 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/bandwidth_quality_scaler_resource.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/balanced_degradation_settings.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// static
|
||||
rtc::scoped_refptr<BandwidthQualityScalerResource>
|
||||
BandwidthQualityScalerResource::Create() {
|
||||
return rtc::make_ref_counted<BandwidthQualityScalerResource>();
|
||||
}
|
||||
|
||||
BandwidthQualityScalerResource::BandwidthQualityScalerResource()
|
||||
: VideoStreamEncoderResource("BandwidthQualityScalerResource"),
|
||||
bandwidth_quality_scaler_(nullptr) {}
|
||||
|
||||
BandwidthQualityScalerResource::~BandwidthQualityScalerResource() {
|
||||
RTC_DCHECK(!bandwidth_quality_scaler_);
|
||||
}
|
||||
|
||||
bool BandwidthQualityScalerResource::is_started() const {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
return bandwidth_quality_scaler_.get();
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::StartCheckForOveruse(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits) {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
RTC_DCHECK(!is_started());
|
||||
bandwidth_quality_scaler_ = std::make_unique<BandwidthQualityScaler>(this);
|
||||
|
||||
// If the configuration parameters more than one, we should define and
|
||||
// declare the function BandwidthQualityScaler::Initialize() and call it.
|
||||
bandwidth_quality_scaler_->SetResolutionBitrateLimits(
|
||||
resolution_bitrate_limits);
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::StopCheckForOveruse() {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
RTC_DCHECK(is_started());
|
||||
// Ensure we have no pending callbacks. This makes it safe to destroy the
|
||||
// BandwidthQualityScaler and even task queues with tasks in-flight.
|
||||
bandwidth_quality_scaler_.reset();
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::OnReportUsageBandwidthHigh() {
|
||||
OnResourceUsageStateMeasured(ResourceUsageState::kOveruse);
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::OnReportUsageBandwidthLow() {
|
||||
OnResourceUsageStateMeasured(ResourceUsageState::kUnderuse);
|
||||
}
|
||||
|
||||
void BandwidthQualityScalerResource::OnEncodeCompleted(
|
||||
const EncodedImage& encoded_image,
|
||||
int64_t time_sent_in_us,
|
||||
int64_t encoded_image_size_bytes) {
|
||||
RTC_DCHECK_RUN_ON(encoder_queue());
|
||||
|
||||
if (bandwidth_quality_scaler_) {
|
||||
bandwidth_quality_scaler_->ReportEncodeInfo(
|
||||
encoded_image_size_bytes, time_sent_in_us / 1000,
|
||||
encoded_image._encodedWidth, encoded_image._encodedHeight);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -1,64 +1,64 @@
|
||||
/*
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_
|
||||
#define VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/video/video_adaptation_reason.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "call/adaptation/degradation_preference_provider.h"
|
||||
#include "call/adaptation/resource_adaptation_processor_interface.h"
|
||||
#include "modules/video_coding/utility/bandwidth_quality_scaler.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "video/adaptation/video_stream_encoder_resource.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Handles interaction with the BandwidthQualityScaler.
|
||||
class BandwidthQualityScalerResource
|
||||
: public VideoStreamEncoderResource,
|
||||
public BandwidthQualityScalerUsageHandlerInterface {
|
||||
public:
|
||||
static rtc::scoped_refptr<BandwidthQualityScalerResource> Create();
|
||||
|
||||
BandwidthQualityScalerResource();
|
||||
~BandwidthQualityScalerResource() override;
|
||||
|
||||
bool is_started() const;
|
||||
|
||||
void OnEncodeCompleted(const EncodedImage& encoded_image,
|
||||
int64_t time_sent_in_us,
|
||||
int64_t encoded_image_size_bytes);
|
||||
|
||||
void StartCheckForOveruse(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits);
|
||||
void StopCheckForOveruse();
|
||||
|
||||
// BandwidthScalerQpUsageHandlerInterface implementation.
|
||||
void OnReportUsageBandwidthHigh() override;
|
||||
void OnReportUsageBandwidthLow() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<BandwidthQualityScaler> bandwidth_quality_scaler_
|
||||
RTC_GUARDED_BY(encoder_queue());
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_
|
||||
#define VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
#include "api/video/video_adaptation_reason.h"
|
||||
#include "api/video_codecs/video_encoder.h"
|
||||
#include "call/adaptation/degradation_preference_provider.h"
|
||||
#include "call/adaptation/resource_adaptation_processor_interface.h"
|
||||
#include "modules/video_coding/utility/bandwidth_quality_scaler.h"
|
||||
#include "rtc_base/ref_counted_object.h"
|
||||
#include "rtc_base/task_queue.h"
|
||||
#include "video/adaptation/video_stream_encoder_resource.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Handles interaction with the BandwidthQualityScaler.
|
||||
class BandwidthQualityScalerResource
|
||||
: public VideoStreamEncoderResource,
|
||||
public BandwidthQualityScalerUsageHandlerInterface {
|
||||
public:
|
||||
static rtc::scoped_refptr<BandwidthQualityScalerResource> Create();
|
||||
|
||||
BandwidthQualityScalerResource();
|
||||
~BandwidthQualityScalerResource() override;
|
||||
|
||||
bool is_started() const;
|
||||
|
||||
void OnEncodeCompleted(const EncodedImage& encoded_image,
|
||||
int64_t time_sent_in_us,
|
||||
int64_t encoded_image_size_bytes);
|
||||
|
||||
void StartCheckForOveruse(
|
||||
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
|
||||
resolution_bitrate_limits);
|
||||
void StopCheckForOveruse();
|
||||
|
||||
// BandwidthScalerQpUsageHandlerInterface implementation.
|
||||
void OnReportUsageBandwidthHigh() override;
|
||||
void OnReportUsageBandwidthLow() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<BandwidthQualityScaler> bandwidth_quality_scaler_
|
||||
RTC_GUARDED_BY(encoder_queue());
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user