1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_ 12 #define VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_ 13 14 #include <memory> 15 #include <queue> 16 #include <string> 17 #include <vector> 18 19 #include "absl/types/optional.h" 20 #include "api/scoped_refptr.h" 21 #include "api/video/video_adaptation_reason.h" 22 #include "api/video_codecs/video_encoder.h" 23 #include "call/adaptation/degradation_preference_provider.h" 24 #include "call/adaptation/resource_adaptation_processor_interface.h" 25 #include "modules/video_coding/utility/bandwidth_quality_scaler.h" 26 #include "video/adaptation/video_stream_encoder_resource.h" 27 28 namespace webrtc { 29 30 // Handles interaction with the BandwidthQualityScaler. 31 class BandwidthQualityScalerResource 32 : public VideoStreamEncoderResource, 33 public BandwidthQualityScalerUsageHandlerInterface { 34 public: 35 static rtc::scoped_refptr<BandwidthQualityScalerResource> Create(); 36 37 BandwidthQualityScalerResource(); 38 ~BandwidthQualityScalerResource() override; 39 40 bool is_started() const; 41 42 void OnEncodeCompleted(const EncodedImage& encoded_image, 43 int64_t time_sent_in_us, 44 int64_t encoded_image_size_bytes); 45 46 void StartCheckForOveruse( 47 const std::vector<VideoEncoder::ResolutionBitrateLimits>& 48 resolution_bitrate_limits); 49 void StopCheckForOveruse(); 50 51 // BandwidthScalerQpUsageHandlerInterface implementation. 52 void OnReportUsageBandwidthHigh() override; 53 void OnReportUsageBandwidthLow() override; 54 55 private: 56 std::unique_ptr<BandwidthQualityScaler> bandwidth_quality_scaler_ 57 RTC_GUARDED_BY(encoder_queue()); 58 }; 59 60 } // namespace webrtc 61 62 #endif // VIDEO_ADAPTATION_BANDWIDTH_QUALITY_SCALER_RESOURCE_H_ 63