#include "video/adaptation/video_stream_encoder_resource_manager.h"
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <utility>
#include "absl/algorithm/container.h"
#include "absl/base/macros.h"
#include "api/adaptation/resource.h"
#include "api/field_trials_view.h"
#include "api/sequence_checker.h"
#include "api/task_queue/task_queue_base.h"
#include "api/video/video_adaptation_reason.h"
#include "api/video/video_source_interface.h"
#include "call/adaptation/video_source_restrictions.h"
#include "modules/video_coding/svc/scalability_mode_util.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
#include "video/adaptation/quality_scaler_resource.h"
namespace webrtc {
const int kDefaultInputPixelsWidth = …;
const int kDefaultInputPixelsHeight = …;
namespace {
constexpr const char* kPixelLimitResourceFieldTrialName = …;
bool IsResolutionScalingEnabled(DegradationPreference degradation_preference) { … }
bool IsFramerateScalingEnabled(DegradationPreference degradation_preference) { … }
std::string ToString(VideoAdaptationReason reason) { … }
std::vector<bool> GetActiveLayersFlags(const VideoCodec& codec) { … }
bool EqualFlags(const std::vector<bool>& a, const std::vector<bool>& b) { … }
}
class VideoStreamEncoderResourceManager::InitialFrameDropper { … };
VideoStreamEncoderResourceManager::VideoStreamEncoderResourceManager(
VideoStreamInputStateProvider* input_state_provider,
VideoStreamEncoderObserver* encoder_stats_observer,
Clock* clock,
bool experiment_cpu_load_estimator,
std::unique_ptr<OveruseFrameDetector> overuse_detector,
DegradationPreferenceProvider* degradation_preference_provider,
const FieldTrialsView& field_trials)
: … { … }
VideoStreamEncoderResourceManager::~VideoStreamEncoderResourceManager() =
default;
void VideoStreamEncoderResourceManager::Initialize(
TaskQueueBase* encoder_queue) { … }
void VideoStreamEncoderResourceManager::SetAdaptationProcessor(
ResourceAdaptationProcessorInterface* adaptation_processor,
VideoStreamAdapter* stream_adapter) { … }
void VideoStreamEncoderResourceManager::SetDegradationPreferences(
DegradationPreference degradation_preference) { … }
DegradationPreference
VideoStreamEncoderResourceManager::degradation_preference() const { … }
void VideoStreamEncoderResourceManager::ConfigureEncodeUsageResource() { … }
void VideoStreamEncoderResourceManager::MaybeInitializePixelLimitResource() { … }
void VideoStreamEncoderResourceManager::StopManagedResources() { … }
void VideoStreamEncoderResourceManager::AddResource(
rtc::scoped_refptr<Resource> resource,
VideoAdaptationReason reason) { … }
void VideoStreamEncoderResourceManager::RemoveResource(
rtc::scoped_refptr<Resource> resource) { … }
std::vector<AdaptationConstraint*>
VideoStreamEncoderResourceManager::AdaptationConstraints() const { … }
void VideoStreamEncoderResourceManager::SetEncoderSettings(
EncoderSettings encoder_settings) { … }
void VideoStreamEncoderResourceManager::SetStartBitrate(
DataRate start_bitrate) { … }
void VideoStreamEncoderResourceManager::SetTargetBitrate(
DataRate target_bitrate) { … }
void VideoStreamEncoderResourceManager::SetEncoderRates(
const VideoEncoder::RateControlParameters& encoder_rates) { … }
void VideoStreamEncoderResourceManager::OnFrameDroppedDueToSize() { … }
void VideoStreamEncoderResourceManager::OnEncodeStarted(
const VideoFrame& cropped_frame,
int64_t time_when_first_seen_us) { … }
void VideoStreamEncoderResourceManager::OnEncodeCompleted(
const EncodedImage& encoded_image,
int64_t time_sent_in_us,
absl::optional<int> encode_duration_us,
DataSize frame_size) { … }
void VideoStreamEncoderResourceManager::OnFrameDropped(
EncodedImageCallback::DropReason reason) { … }
bool VideoStreamEncoderResourceManager::DropInitialFrames() const { … }
absl::optional<uint32_t>
VideoStreamEncoderResourceManager::SingleActiveStreamPixels() const { … }
absl::optional<uint32_t>
VideoStreamEncoderResourceManager::UseBandwidthAllocationBps() const { … }
void VideoStreamEncoderResourceManager::OnMaybeEncodeFrame() { … }
void VideoStreamEncoderResourceManager::UpdateQualityScalerSettings(
absl::optional<VideoEncoder::QpThresholds> qp_thresholds) { … }
void VideoStreamEncoderResourceManager::UpdateBandwidthQualityScalerSettings(
bool bandwidth_quality_scaling_allowed,
const std::vector<VideoEncoder::ResolutionBitrateLimits>&
resolution_bitrate_limits) { … }
void VideoStreamEncoderResourceManager::ConfigureQualityScaler(
const VideoEncoder::EncoderInfo& encoder_info) { … }
void VideoStreamEncoderResourceManager::ConfigureBandwidthQualityScaler(
const VideoEncoder::EncoderInfo& encoder_info) { … }
VideoAdaptationReason VideoStreamEncoderResourceManager::GetReasonFromResource(
rtc::scoped_refptr<Resource> resource) const { … }
CpuOveruseOptions VideoStreamEncoderResourceManager::GetCpuOveruseOptions()
const { … }
int VideoStreamEncoderResourceManager::LastFrameSizeOrDefault() const { … }
void VideoStreamEncoderResourceManager::OnVideoSourceRestrictionsUpdated(
VideoSourceRestrictions restrictions,
const VideoAdaptationCounters& adaptation_counters,
rtc::scoped_refptr<Resource> reason,
const VideoSourceRestrictions& unfiltered_restrictions) { … }
void VideoStreamEncoderResourceManager::OnResourceLimitationChanged(
rtc::scoped_refptr<Resource> resource,
const std::map<rtc::scoped_refptr<Resource>, VideoAdaptationCounters>&
resource_limitations) { … }
void VideoStreamEncoderResourceManager::MaybeUpdateTargetFrameRate() { … }
void VideoStreamEncoderResourceManager::UpdateStatsAdaptationSettings() const { … }
std::string VideoStreamEncoderResourceManager::ActiveCountsToString(
const std::map<VideoAdaptationReason, VideoAdaptationCounters>&
active_counts) { … }
bool VideoStreamEncoderResourceManager::IsSimulcastOrMultipleSpatialLayers(
const VideoEncoderConfig& encoder_config,
const VideoCodec& video_codec) { … }
}