xref: /aosp_15_r20/external/webrtc/video/adaptation/quality_scaler_resource.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2020 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_QUALITY_SCALER_RESOURCE_H_
12 #define VIDEO_ADAPTATION_QUALITY_SCALER_RESOURCE_H_
13 
14 #include <memory>
15 #include <queue>
16 #include <string>
17 
18 #include "absl/types/optional.h"
19 #include "api/scoped_refptr.h"
20 #include "api/video/video_adaptation_reason.h"
21 #include "api/video_codecs/video_encoder.h"
22 #include "call/adaptation/degradation_preference_provider.h"
23 #include "call/adaptation/resource_adaptation_processor_interface.h"
24 #include "modules/video_coding/utility/quality_scaler.h"
25 #include "video/adaptation/video_stream_encoder_resource.h"
26 
27 namespace webrtc {
28 
29 // Handles interaction with the QualityScaler.
30 class QualityScalerResource : public VideoStreamEncoderResource,
31                               public QualityScalerQpUsageHandlerInterface {
32  public:
33   static rtc::scoped_refptr<QualityScalerResource> Create();
34 
35   QualityScalerResource();
36   ~QualityScalerResource() override;
37 
38   bool is_started() const;
39 
40   void StartCheckForOveruse(VideoEncoder::QpThresholds qp_thresholds);
41   void StopCheckForOveruse();
42   void SetQpThresholds(VideoEncoder::QpThresholds qp_thresholds);
43   bool QpFastFilterLow();
44   void OnEncodeCompleted(const EncodedImage& encoded_image,
45                          int64_t time_sent_in_us);
46   void OnFrameDropped(EncodedImageCallback::DropReason reason);
47 
48   // QualityScalerQpUsageHandlerInterface implementation.
49   void OnReportQpUsageHigh() override;
50   void OnReportQpUsageLow() override;
51 
52  private:
53   std::unique_ptr<QualityScaler> quality_scaler_
54       RTC_GUARDED_BY(encoder_queue());
55 };
56 
57 }  // namespace webrtc
58 
59 #endif  // VIDEO_ADAPTATION_QUALITY_SCALER_RESOURCE_H_
60