Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: webrtc/modules/video_coding/utility/quality_scaler.h

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: Fix flaky test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ 12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
13 13
14 #include <utility>
15
14 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
15 #include "webrtc/common_video/include/i420_buffer_pool.h" 17 #include "webrtc/base/optional.h"
18 #include "webrtc/base/sequenced_task_checker.h"
16 #include "webrtc/modules/video_coding/utility/moving_average.h" 19 #include "webrtc/modules/video_coding/utility/moving_average.h"
17 20
18 namespace webrtc { 21 namespace webrtc {
22
23 // An interface for a class that receives scale up/down requests.
24 class ScalingObserverInterface {
25 public:
26 enum ScaleReason { kQuality, kCpu };
27 static const size_t kScaleReasonSize = 2;
28 // Called to signal that we can handle larger frames.
29 virtual void ScaleUp(ScaleReason reason) = 0;
30 // Called to signal that encoder to scale down.
31 virtual void ScaleDown(ScaleReason reason) = 0;
32
33 protected:
34 virtual ~ScalingObserverInterface() {}
35 };
36
37 // QualityScaler runs asynchronously and monitors QP values of encoded frames.
38 // It holds a reference to a ScalingObserverInterface implementation to signal
39 // an intent to scale up or down.
19 class QualityScaler { 40 class QualityScaler {
20 public: 41 public:
21 struct Resolution { 42 struct QPThresholds {
22 int width; 43 QPThresholds(int l, int h) : low(l), high(h) {}
23 int height; 44 QPThresholds() : low(-1), high(-1) {}
45 int low;
46 int high;
47 };
48 struct Settings {
49 Settings(bool on, int low, int high)
50 : enabled(on),
51 thresholds(rtc::Optional<QPThresholds>(QPThresholds(low, high))) {}
52 explicit Settings(bool on) : enabled(on) {}
53 const bool enabled;
54 const rtc::Optional<QPThresholds> thresholds;
24 }; 55 };
25 56
26 QualityScaler(); 57 // Construct a QualityScaler with a given |observer|.
27 void Init(VideoCodecType codec_type, 58 // This starts the quality scaler periodically checking what the average QP
28 int initial_bitrate_kbps, 59 // has been recently.
29 int width, 60 QualityScaler(ScalingObserverInterface* observer, VideoCodecType codec_type);
30 int height, 61 // If specific thresholds are desired these can be supplied as |thresholds|.
31 int fps); 62 QualityScaler(ScalingObserverInterface* observer, QPThresholds thresholds);
32 void Init(int low_qp_threshold, 63 virtual ~QualityScaler();
33 int high_qp_threshold, 64 // Should be called each time the encoder drops a frame
34 int initial_bitrate_kbps, 65 void ReportDroppedFrame() const;
magjed_webrtc 2016/11/10 13:07:00 I don't think this function or ReportQP should be
kthelgason 2016/11/10 15:38:27 Acknowledged.
35 int width, 66 // Inform the QualityScaler of the last seen QP.
36 int height, 67 void ReportQP(int qp) const;
37 int fps); 68
38 void ReportFramerate(int framerate); 69 // This method declared virtual to help with testing.
magjed_webrtc 2016/11/10 13:07:00 It's not virtual anymore and not used for testing,
kthelgason 2016/11/10 15:38:27 Done.
39 void ReportQP(int qp); 70 int64_t GetSamplingPeriodMs() const;
40 void ReportDroppedFrame(); 71
41 void OnEncodeFrame(int width, int height); 72 // The following members declared protected for testing purposes
42 Resolution GetScaledResolution() const; 73 protected:
43 rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer( 74 QualityScaler(ScalingObserverInterface* observer,
44 const rtc::scoped_refptr<VideoFrameBuffer>& frame); 75 QPThresholds thresholds,
45 int downscale_shift() const { return downscale_shift_; } 76 int64_t sampling_period);
46 77
47 private: 78 private:
79 class CheckQPTask;
80 void CheckQP();
48 void ClearSamples(); 81 void ClearSamples();
49 void ScaleUp(); 82 void ReportQPLow();
50 void ScaleDown(); 83 void ReportQPHigh();
51 void UpdateTargetResolution(int width, int height);
52 84
53 I420BufferPool pool_; 85 CheckQPTask* check_qp_task_ GUARDED_BY(&task_checker_);
86 ScalingObserverInterface* const observer_ GUARDED_BY(&task_checker_);
87 rtc::SequencedTaskChecker task_checker_;
54 88
55 size_t num_samples_downscale_; 89 int64_t sampling_period_ms_;
56 size_t num_samples_upscale_; 90 bool fast_rampup_ GUARDED_BY(&task_checker_);
57 bool fast_rampup_; 91 mutable MovingAverage average_qp_ GUARDED_BY(&task_checker_);
magjed_webrtc 2016/11/10 13:07:00 I don't think these should be mutable unless you h
kthelgason 2016/11/10 15:38:27 I made these mutable and the report{QP, DroppedFra
58 MovingAverage average_qp_; 92 mutable MovingAverage framedrop_percent_ GUARDED_BY(&task_checker_);
59 MovingAverage framedrop_percent_;
60 93
61 int low_qp_threshold_; 94 QPThresholds thresholds_ GUARDED_BY(&task_checker_);
62 int high_qp_threshold_;
63 Resolution target_res_;
64
65 int downscale_shift_;
66 int maximum_shift_;
67 }; 95 };
68
69 } // namespace webrtc 96 } // namespace webrtc
70 97
71 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ 98 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698