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

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

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: Code review comments Created 4 years, 2 months 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 "webrtc/common_types.h" 14 #include "webrtc/common_types.h"
15 #include "webrtc/video_frame.h"
16 #include "webrtc/base/sequenced_task_checker.h"
15 #include "webrtc/common_video/include/i420_buffer_pool.h" 17 #include "webrtc/common_video/include/i420_buffer_pool.h"
16 #include "webrtc/modules/video_coding/utility/moving_average.h" 18 #include "webrtc/modules/video_coding/utility/moving_average.h"
17 19
18 namespace webrtc { 20 namespace webrtc {
21
22 // An interface for a class that receives scale up/down requests.
23 class ScalingInterface {
magjed_webrtc 2016/10/07 12:02:54 Put 'observer' somewhere in the name, e.g. Scaling
kthelgason 2016/10/07 13:54:48 Done.
24 public:
25 // Called to signal that we can handle larger frames.
26 virtual void ScaleUp() = 0;
27 // Called to signal that encoder to scale down.
28 virtual void ScaleDown() = 0;
29
30 protected:
31 virtual ~ScalingInterface() {}
32 };
33
34 // QualityScaler runs asynchronously and monitors QP values of encoded frames.
35 // It holds a reference to a ScalingInterface implementation to signal
36 // an intent to scale up or down.
19 class QualityScaler { 37 class QualityScaler {
20 public: 38 public:
21 struct Resolution { 39 struct Resolution {
22 int width; 40 int width;
23 int height; 41 int height;
24 }; 42 };
25 43
26 QualityScaler(); 44 QualityScaler();
27 void Init(VideoCodecType codec_type, 45 virtual ~QualityScaler();
28 int initial_bitrate_kbps, 46 // Init starts the quality scaler periodically checking what the average QP
29 int width, 47 // has been recently.
30 int height, 48 // arguments:
31 int fps); 49 // observer_: an implementation of webrtc::ScalingInterface.
32 void Init(int low_qp_threshold, 50 // codec_type: either H264 or VP8, used to determine default thresholds.
33 int high_qp_threshold, 51 void Init(ScalingInterface* obeserver_, VideoCodecType codec_type);
34 int initial_bitrate_kbps, 52 // If specific thresholds are desired these can be supplied instead of
35 int width, 53 // codec_type_.
36 int height, 54 void Init(ScalingInterface* obeserver_,
37 int fps); 55 int low_qp_threshold,
38 void ReportFramerate(int framerate); 56 int high_qp_threshold);
57 // Stop must be called to stop the periodic task before QualityScaler is
58 // destroyed.
59 void Stop();
60 // Should be called each time the encoder drops a frame
61 void ReportDroppedFrame();
62 // Inform the QualityScaler of the last seen QP.
39 void ReportQP(int qp); 63 void ReportQP(int qp);
40 void ReportDroppedFrame(); 64
41 void OnEncodeFrame(int width, int height); 65 // This method declared virtual to help with testing.
42 Resolution GetScaledResolution() const; 66 virtual int64_t GetTimeoutMs();
43 rtc::scoped_refptr<VideoFrameBuffer> GetScaledBuffer(
44 const rtc::scoped_refptr<VideoFrameBuffer>& frame);
45 int downscale_shift() const { return downscale_shift_; }
46 67
47 private: 68 private:
69 class CheckQPTask;
70 void CheckQP();
48 void ClearSamples(); 71 void ClearSamples();
49 void ScaleUp(); 72 void ReportQPLow();
50 void ScaleDown(); 73 void ReportQPHigh();
51 void UpdateTargetResolution(int width, int height);
52 74
53 I420BufferPool pool_; 75 ScalingInterface* observer_ GUARDED_BY(&task_checker_);
76 CheckQPTask* check_qp_task_ GUARDED_BY(&task_checker_);
77 rtc::SequencedTaskChecker task_checker_;
54 78
55 size_t num_samples_downscale_; 79 bool fast_rampup_ GUARDED_BY(&task_checker_);
56 size_t num_samples_upscale_; 80 int64_t measure_interval_ GUARDED_BY(&task_checker_);
57 bool fast_rampup_; 81 MovingAverage average_qp_ GUARDED_BY(&task_checker_);
58 MovingAverage average_qp_; 82 MovingAverage framedrop_percent_ GUARDED_BY(&task_checker_);
59 MovingAverage framedrop_percent_;
60 83
61 int low_qp_threshold_; 84 int low_qp_threshold_ GUARDED_BY(&task_checker_);
62 int high_qp_threshold_; 85 int high_qp_threshold_ GUARDED_BY(&task_checker_);
63 Resolution target_res_;
64
65 int downscale_shift_;
66 int maximum_shift_;
67 }; 86 };
68 87
69 } // namespace webrtc 88 } // namespace webrtc
70 89
71 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_ 90 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698