1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2020 The WebRTC Project Authors. All rights reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef VIDEO_ADAPTATION_QUALITY_SCALER_RESOURCE_H_ 12*d9f75844SAndroid Build Coastguard Worker #define VIDEO_ADAPTATION_QUALITY_SCALER_RESOURCE_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include <memory> 15*d9f75844SAndroid Build Coastguard Worker #include <queue> 16*d9f75844SAndroid Build Coastguard Worker #include <string> 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h" 19*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h" 20*d9f75844SAndroid Build Coastguard Worker #include "api/video/video_adaptation_reason.h" 21*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/video_encoder.h" 22*d9f75844SAndroid Build Coastguard Worker #include "call/adaptation/degradation_preference_provider.h" 23*d9f75844SAndroid Build Coastguard Worker #include "call/adaptation/resource_adaptation_processor_interface.h" 24*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/utility/quality_scaler.h" 25*d9f75844SAndroid Build Coastguard Worker #include "video/adaptation/video_stream_encoder_resource.h" 26*d9f75844SAndroid Build Coastguard Worker 27*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 28*d9f75844SAndroid Build Coastguard Worker 29*d9f75844SAndroid Build Coastguard Worker // Handles interaction with the QualityScaler. 30*d9f75844SAndroid Build Coastguard Worker class QualityScalerResource : public VideoStreamEncoderResource, 31*d9f75844SAndroid Build Coastguard Worker public QualityScalerQpUsageHandlerInterface { 32*d9f75844SAndroid Build Coastguard Worker public: 33*d9f75844SAndroid Build Coastguard Worker static rtc::scoped_refptr<QualityScalerResource> Create(); 34*d9f75844SAndroid Build Coastguard Worker 35*d9f75844SAndroid Build Coastguard Worker QualityScalerResource(); 36*d9f75844SAndroid Build Coastguard Worker ~QualityScalerResource() override; 37*d9f75844SAndroid Build Coastguard Worker 38*d9f75844SAndroid Build Coastguard Worker bool is_started() const; 39*d9f75844SAndroid Build Coastguard Worker 40*d9f75844SAndroid Build Coastguard Worker void StartCheckForOveruse(VideoEncoder::QpThresholds qp_thresholds); 41*d9f75844SAndroid Build Coastguard Worker void StopCheckForOveruse(); 42*d9f75844SAndroid Build Coastguard Worker void SetQpThresholds(VideoEncoder::QpThresholds qp_thresholds); 43*d9f75844SAndroid Build Coastguard Worker bool QpFastFilterLow(); 44*d9f75844SAndroid Build Coastguard Worker void OnEncodeCompleted(const EncodedImage& encoded_image, 45*d9f75844SAndroid Build Coastguard Worker int64_t time_sent_in_us); 46*d9f75844SAndroid Build Coastguard Worker void OnFrameDropped(EncodedImageCallback::DropReason reason); 47*d9f75844SAndroid Build Coastguard Worker 48*d9f75844SAndroid Build Coastguard Worker // QualityScalerQpUsageHandlerInterface implementation. 49*d9f75844SAndroid Build Coastguard Worker void OnReportQpUsageHigh() override; 50*d9f75844SAndroid Build Coastguard Worker void OnReportQpUsageLow() override; 51*d9f75844SAndroid Build Coastguard Worker 52*d9f75844SAndroid Build Coastguard Worker private: 53*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<QualityScaler> quality_scaler_ 54*d9f75844SAndroid Build Coastguard Worker RTC_GUARDED_BY(encoder_queue()); 55*d9f75844SAndroid Build Coastguard Worker }; 56*d9f75844SAndroid Build Coastguard Worker 57*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 58*d9f75844SAndroid Build Coastguard Worker 59*d9f75844SAndroid Build Coastguard Worker #endif // VIDEO_ADAPTATION_QUALITY_SCALER_RESOURCE_H_ 60