OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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_MEDIA_OPTIMIZATION_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "webrtc/modules/include/module_common_types.h" | 17 #include "webrtc/modules/include/module_common_types.h" |
18 #include "webrtc/modules/video_coding/include/video_coding.h" | 18 #include "webrtc/modules/video_coding/include/video_coding.h" |
19 #include "webrtc/modules/video_coding/media_opt_util.h" | 19 #include "webrtc/modules/video_coding/media_opt_util.h" |
20 #include "webrtc/modules/video_coding/qm_select.h" | |
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 20 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 | 23 |
25 // Forward declarations. | 24 // Forward declarations. |
26 class Clock; | 25 class Clock; |
27 class FrameDropper; | 26 class FrameDropper; |
28 class VCMContentMetricsProcessing; | 27 class VCMContentMetricsProcessing; |
29 | 28 |
30 namespace media_optimization { | 29 namespace media_optimization { |
(...skipping 21 matching lines...) Expand all Loading... |
52 // Inputs: target bitrate - the encoder target bitrate in bits/s. | 51 // Inputs: target bitrate - the encoder target bitrate in bits/s. |
53 // fraction_lost - packet loss rate in % in the network. | 52 // fraction_lost - packet loss rate in % in the network. |
54 // round_trip_time_ms - round trip time in milliseconds. | 53 // round_trip_time_ms - round trip time in milliseconds. |
55 // min_bit_rate - the bit rate of the end-point with lowest rate. | 54 // min_bit_rate - the bit rate of the end-point with lowest rate. |
56 // max_bit_rate - the bit rate of the end-point with highest rate. | 55 // max_bit_rate - the bit rate of the end-point with highest rate. |
57 // TODO(andresp): Find if the callbacks can be triggered only after releasing | 56 // TODO(andresp): Find if the callbacks can be triggered only after releasing |
58 // an internal critical section. | 57 // an internal critical section. |
59 uint32_t SetTargetRates(uint32_t target_bitrate, | 58 uint32_t SetTargetRates(uint32_t target_bitrate, |
60 uint8_t fraction_lost, | 59 uint8_t fraction_lost, |
61 int64_t round_trip_time_ms, | 60 int64_t round_trip_time_ms, |
62 VCMProtectionCallback* protection_callback, | 61 VCMProtectionCallback* protection_callback); |
63 VCMQMSettingsCallback* qmsettings_callback); | |
64 | 62 |
65 void SetProtectionMethod(VCMProtectionMethodEnum method); | 63 void SetProtectionMethod(VCMProtectionMethodEnum method); |
66 void EnableQM(bool enable); | |
67 void EnableFrameDropper(bool enable); | 64 void EnableFrameDropper(bool enable); |
68 | 65 |
69 // Lets the sender suspend video when the rate drops below | 66 // Lets the sender suspend video when the rate drops below |
70 // |threshold_bps|, and turns back on when the rate goes back up above | 67 // |threshold_bps|, and turns back on when the rate goes back up above |
71 // |threshold_bps| + |window_bps|. | 68 // |threshold_bps| + |window_bps|. |
72 void SuspendBelowMinBitrate(int threshold_bps, int window_bps); | 69 void SuspendBelowMinBitrate(int threshold_bps, int window_bps); |
73 bool IsVideoSuspended() const; | 70 bool IsVideoSuspended() const; |
74 | 71 |
75 bool DropFrame(); | 72 bool DropFrame(); |
76 | 73 |
77 void UpdateContentData(const VideoContentMetrics* content_metrics); | |
78 | |
79 // Informs Media Optimization of encoded output. | 74 // Informs Media Optimization of encoded output. |
80 int32_t UpdateWithEncodedData(const EncodedImage& encoded_image); | 75 int32_t UpdateWithEncodedData(const EncodedImage& encoded_image); |
81 | 76 |
82 // InputFrameRate 0 = no frame rate estimate available. | 77 // InputFrameRate 0 = no frame rate estimate available. |
83 uint32_t InputFrameRate(); | 78 uint32_t InputFrameRate(); |
84 uint32_t SentFrameRate(); | 79 uint32_t SentFrameRate(); |
85 uint32_t SentBitRate(); | 80 uint32_t SentBitRate(); |
86 | 81 |
87 private: | 82 private: |
88 enum { kFrameCountHistorySize = 90 }; | 83 enum { kFrameCountHistorySize = 90 }; |
89 enum { kFrameHistoryWinMs = 2000 }; | 84 enum { kFrameHistoryWinMs = 2000 }; |
90 enum { kBitrateAverageWinMs = 1000 }; | 85 enum { kBitrateAverageWinMs = 1000 }; |
91 | 86 |
92 struct EncodedFrameSample; | 87 struct EncodedFrameSample; |
93 typedef std::list<EncodedFrameSample> FrameSampleList; | 88 typedef std::list<EncodedFrameSample> FrameSampleList; |
94 | 89 |
95 void UpdateIncomingFrameRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 90 void UpdateIncomingFrameRate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
96 void PurgeOldFrameSamples(int64_t now_ms) | 91 void PurgeOldFrameSamples(int64_t now_ms) |
97 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 92 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
98 void UpdateSentBitrate(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 93 void UpdateSentBitrate(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
99 void UpdateSentFramerate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 94 void UpdateSentFramerate() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
100 | 95 |
101 // Computes new Quality Mode. | |
102 int32_t SelectQuality(VCMQMSettingsCallback* qmsettings_callback) | |
103 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
104 | |
105 // Verifies if QM settings differ from default, i.e. if an update is required. | |
106 // Computes actual values, as will be sent to the encoder. | |
107 bool QMUpdate(VCMResolutionScale* qm, | |
108 VCMQMSettingsCallback* qmsettings_callback) | |
109 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
110 | |
111 // Checks if we should make a QM change. Return true if yes, false otherwise. | |
112 bool CheckStatusForQMchange() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
113 | |
114 void ProcessIncomingFrameRate(int64_t now) | 96 void ProcessIncomingFrameRate(int64_t now) |
115 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 97 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
116 | 98 |
117 // Checks conditions for suspending the video. The method compares | 99 // Checks conditions for suspending the video. The method compares |
118 // |video_target_bitrate_| with the threshold values for suspension, and | 100 // |video_target_bitrate_| with the threshold values for suspension, and |
119 // changes the state of |video_suspended_| accordingly. | 101 // changes the state of |video_suspended_| accordingly. |
120 void CheckSuspendConditions() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 102 void CheckSuspendConditions() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
121 | 103 |
122 void SetEncodingDataInternal(VideoCodecType send_codec_type, | 104 void SetEncodingDataInternal(VideoCodecType send_codec_type, |
123 int32_t max_bit_rate, | 105 int32_t max_bit_rate, |
(...skipping 21 matching lines...) Expand all Loading... |
145 std::unique_ptr<FrameDropper> frame_dropper_ GUARDED_BY(crit_sect_); | 127 std::unique_ptr<FrameDropper> frame_dropper_ GUARDED_BY(crit_sect_); |
146 std::unique_ptr<VCMLossProtectionLogic> loss_prot_logic_ | 128 std::unique_ptr<VCMLossProtectionLogic> loss_prot_logic_ |
147 GUARDED_BY(crit_sect_); | 129 GUARDED_BY(crit_sect_); |
148 uint8_t fraction_lost_ GUARDED_BY(crit_sect_); | 130 uint8_t fraction_lost_ GUARDED_BY(crit_sect_); |
149 uint32_t send_statistics_[4] GUARDED_BY(crit_sect_); | 131 uint32_t send_statistics_[4] GUARDED_BY(crit_sect_); |
150 uint32_t send_statistics_zero_encode_ GUARDED_BY(crit_sect_); | 132 uint32_t send_statistics_zero_encode_ GUARDED_BY(crit_sect_); |
151 int32_t max_payload_size_ GUARDED_BY(crit_sect_); | 133 int32_t max_payload_size_ GUARDED_BY(crit_sect_); |
152 int video_target_bitrate_ GUARDED_BY(crit_sect_); | 134 int video_target_bitrate_ GUARDED_BY(crit_sect_); |
153 float incoming_frame_rate_ GUARDED_BY(crit_sect_); | 135 float incoming_frame_rate_ GUARDED_BY(crit_sect_); |
154 int64_t incoming_frame_times_[kFrameCountHistorySize] GUARDED_BY(crit_sect_); | 136 int64_t incoming_frame_times_[kFrameCountHistorySize] GUARDED_BY(crit_sect_); |
155 bool enable_qm_ GUARDED_BY(crit_sect_); | |
156 std::list<EncodedFrameSample> encoded_frame_samples_ GUARDED_BY(crit_sect_); | 137 std::list<EncodedFrameSample> encoded_frame_samples_ GUARDED_BY(crit_sect_); |
157 uint32_t avg_sent_bit_rate_bps_ GUARDED_BY(crit_sect_); | 138 uint32_t avg_sent_bit_rate_bps_ GUARDED_BY(crit_sect_); |
158 uint32_t avg_sent_framerate_ GUARDED_BY(crit_sect_); | 139 uint32_t avg_sent_framerate_ GUARDED_BY(crit_sect_); |
159 uint32_t key_frame_cnt_ GUARDED_BY(crit_sect_); | 140 uint32_t key_frame_cnt_ GUARDED_BY(crit_sect_); |
160 uint32_t delta_frame_cnt_ GUARDED_BY(crit_sect_); | 141 uint32_t delta_frame_cnt_ GUARDED_BY(crit_sect_); |
161 std::unique_ptr<VCMContentMetricsProcessing> content_ GUARDED_BY(crit_sect_); | |
162 std::unique_ptr<VCMQmResolution> qm_resolution_ GUARDED_BY(crit_sect_); | |
163 int64_t last_qm_update_time_ GUARDED_BY(crit_sect_); | |
164 int64_t last_change_time_ GUARDED_BY(crit_sect_); // Content/user triggered. | |
165 int num_layers_ GUARDED_BY(crit_sect_); | 142 int num_layers_ GUARDED_BY(crit_sect_); |
166 bool suspension_enabled_ GUARDED_BY(crit_sect_); | 143 bool suspension_enabled_ GUARDED_BY(crit_sect_); |
167 bool video_suspended_ GUARDED_BY(crit_sect_); | 144 bool video_suspended_ GUARDED_BY(crit_sect_); |
168 int suspension_threshold_bps_ GUARDED_BY(crit_sect_); | 145 int suspension_threshold_bps_ GUARDED_BY(crit_sect_); |
169 int suspension_window_bps_ GUARDED_BY(crit_sect_); | 146 int suspension_window_bps_ GUARDED_BY(crit_sect_); |
170 }; | 147 }; |
171 } // namespace media_optimization | 148 } // namespace media_optimization |
172 } // namespace webrtc | 149 } // namespace webrtc |
173 | 150 |
174 #endif // WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ | 151 #endif // WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_ |
OLD | NEW |