niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 WEBRTC_MODULES_VIDEO_CODING_QM_SELECT_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_QM_SELECT_H_ |
| 13 | |
pbos@webrtc.org | a440732 | 2013-07-16 12:32:05 +0000 | [diff] [blame] | 14 | #include "webrtc/common_types.h" |
| 15 | #include "webrtc/typedefs.h" |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 16 | |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 17 | /******************************************************/ |
| 18 | /* Quality Modes: Resolution and Robustness settings */ |
| 19 | /******************************************************/ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | struct VideoContentMetrics; |
| 23 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 24 | struct VCMResolutionScale { |
| 25 | VCMResolutionScale() |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 26 | : codec_width(640), |
| 27 | codec_height(480), |
| 28 | frame_rate(30.0f), |
| 29 | spatial_width_fact(1.0f), |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 30 | spatial_height_fact(1.0f), |
| 31 | temporal_fact(1.0f), |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 32 | change_resolution_spatial(false), |
| 33 | change_resolution_temporal(false) { |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 34 | } |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 35 | uint16_t codec_width; |
| 36 | uint16_t codec_height; |
| 37 | float frame_rate; |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 38 | float spatial_width_fact; |
| 39 | float spatial_height_fact; |
| 40 | float temporal_fact; |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 41 | bool change_resolution_spatial; |
| 42 | bool change_resolution_temporal; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 45 | enum ImageType { |
| 46 | kQCIF = 0, // 176x144 |
| 47 | kHCIF, // 264x216 = half(~3/4x3/4) CIF. |
| 48 | kQVGA, // 320x240 = quarter VGA. |
| 49 | kCIF, // 352x288 |
| 50 | kHVGA, // 480x360 = half(~3/4x3/4) VGA. |
| 51 | kVGA, // 640x480 |
| 52 | kQFULLHD, // 960x540 = quarter FULLHD, and half(~3/4x3/4) WHD. |
| 53 | kWHD, // 1280x720 |
| 54 | kFULLHD, // 1920x1080 |
| 55 | kNumImageTypes |
| 56 | }; |
| 57 | |
| 58 | const uint32_t kSizeOfImageType[kNumImageTypes] = |
| 59 | { 25344, 57024, 76800, 101376, 172800, 307200, 518400, 921600, 2073600 }; |
| 60 | |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 61 | enum FrameRateLevelClass { |
| 62 | kFrameRateLow, |
| 63 | kFrameRateMiddle1, |
| 64 | kFrameRateMiddle2, |
| 65 | kFrameRateHigh |
| 66 | }; |
| 67 | |
| 68 | enum ContentLevelClass { |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 69 | kLow, |
| 70 | kHigh, |
| 71 | kDefault |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 74 | struct VCMContFeature { |
| 75 | VCMContFeature() |
| 76 | : value(0.0f), |
| 77 | level(kDefault) { |
| 78 | } |
| 79 | void Reset() { |
| 80 | value = 0.0f; |
| 81 | level = kDefault; |
| 82 | } |
| 83 | float value; |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 84 | ContentLevelClass level; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 85 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 87 | enum UpDownAction { |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 88 | kUpResolution, |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 89 | kDownResolution |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 90 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 92 | enum SpatialAction { |
| 93 | kNoChangeSpatial, |
| 94 | kOneHalfSpatialUniform, // 3/4 x 3/4: 9/6 ~1/2 pixel reduction. |
| 95 | kOneQuarterSpatialUniform, // 1/2 x 1/2: 1/4 pixel reduction. |
| 96 | kNumModesSpatial |
| 97 | }; |
| 98 | |
| 99 | enum TemporalAction { |
| 100 | kNoChangeTemporal, |
| 101 | kTwoThirdsTemporal, // 2/3 frame rate reduction |
| 102 | kOneHalfTemporal, // 1/2 frame rate reduction |
| 103 | kNumModesTemporal |
| 104 | }; |
| 105 | |
| 106 | struct ResolutionAction { |
| 107 | ResolutionAction() |
| 108 | : spatial(kNoChangeSpatial), |
| 109 | temporal(kNoChangeTemporal) { |
| 110 | } |
| 111 | SpatialAction spatial; |
| 112 | TemporalAction temporal; |
| 113 | }; |
| 114 | |
| 115 | // Down-sampling factors for spatial (width and height), and temporal. |
| 116 | const float kFactorWidthSpatial[kNumModesSpatial] = |
| 117 | { 1.0f, 4.0f / 3.0f, 2.0f }; |
| 118 | |
| 119 | const float kFactorHeightSpatial[kNumModesSpatial] = |
| 120 | { 1.0f, 4.0f / 3.0f, 2.0f }; |
| 121 | |
| 122 | const float kFactorTemporal[kNumModesTemporal] = |
| 123 | { 1.0f, 1.5f, 2.0f }; |
| 124 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 125 | enum EncoderState { |
| 126 | kStableEncoding, // Low rate mis-match, stable buffer levels. |
| 127 | kStressedEncoding, // Significant over-shooting of target rate, |
| 128 | // Buffer under-flow, etc. |
| 129 | kEasyEncoding // Significant under-shooting of target rate. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 132 | // QmMethod class: main class for resolution and robustness settings |
| 133 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 134 | class VCMQmMethod { |
| 135 | public: |
| 136 | VCMQmMethod(); |
| 137 | virtual ~VCMQmMethod(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 139 | // Reset values |
| 140 | void ResetQM(); |
| 141 | virtual void Reset() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 143 | // Compute content class. |
| 144 | uint8_t ComputeContentClass(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 146 | // Update with the content metrics. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 147 | void UpdateContent(const VideoContentMetrics* content_metrics); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 149 | // Compute spatial texture magnitude and level. |
| 150 | // Spatial texture is a spatial prediction error measure. |
| 151 | void ComputeSpatial(); |
marpan@webrtc.org | bd5648f | 2012-02-17 23:16:58 +0000 | [diff] [blame] | 152 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 153 | // Compute motion magnitude and level for NFD metric. |
| 154 | // NFD is normalized frame difference (normalized by spatial variance). |
| 155 | void ComputeMotionNFD(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 157 | // Get the imageType (CIF, VGA, HD, etc) for the system width/height. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 158 | ImageType GetImageType(uint16_t width, uint16_t height); |
| 159 | |
| 160 | // Return the closest image type. |
| 161 | ImageType FindClosestImageType(uint16_t width, uint16_t height); |
marpan@webrtc.org | bd5648f | 2012-02-17 23:16:58 +0000 | [diff] [blame] | 162 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 163 | // Get the frame rate level. |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 164 | FrameRateLevelClass FrameRateLevel(float frame_rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 165 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 166 | protected: |
| 167 | // Content Data. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 168 | const VideoContentMetrics* content_metrics_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 169 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 170 | // Encoder frame sizes and native frame sizes. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 171 | uint16_t width_; |
| 172 | uint16_t height_; |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 173 | float user_frame_rate_; |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 174 | uint16_t native_width_; |
| 175 | uint16_t native_height_; |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 176 | float native_frame_rate_; |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 177 | float aspect_ratio_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 178 | // Image type and frame rate leve, for the current encoder resolution. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 179 | ImageType image_type_; |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 180 | FrameRateLevelClass framerate_level_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 181 | // Content class data. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 182 | VCMContFeature motion_; |
| 183 | VCMContFeature spatial_; |
| 184 | uint8_t content_class_; |
| 185 | bool init_; |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | // Resolution settings class |
| 189 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 190 | class VCMQmResolution : public VCMQmMethod { |
| 191 | public: |
| 192 | VCMQmResolution(); |
| 193 | virtual ~VCMQmResolution(); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 194 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 195 | // Reset all quantities. |
| 196 | virtual void Reset(); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 197 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 198 | // Reset rate quantities and counters after every SelectResolution() call. |
| 199 | void ResetRates(); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 200 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 201 | // Reset down-sampling state. |
| 202 | void ResetDownSamplingState(); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 203 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 204 | // Get the encoder state. |
| 205 | EncoderState GetEncoderState(); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 206 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 207 | // Initialize after SetEncodingData in media_opt. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 208 | int Initialize(float bitrate, |
| 209 | float user_framerate, |
| 210 | uint16_t width, |
| 211 | uint16_t height, |
| 212 | int num_layers); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 213 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 214 | // Update the encoder frame size. |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 215 | void UpdateCodecParameters(float frame_rate, uint16_t width, uint16_t height); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 216 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 217 | // Update with actual bit rate (size of the latest encoded frame) |
| 218 | // and frame type, after every encoded frame. |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 219 | void UpdateEncodedSize(size_t encoded_size); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 220 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 221 | // Update with new target bitrate, actual encoder sent rate, frame_rate, |
| 222 | // loss rate: every ~1 sec from SetTargetRates in media_opt. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 223 | void UpdateRates(float target_bitrate, |
| 224 | float encoder_sent_rate, |
| 225 | float incoming_framerate, |
| 226 | uint8_t packet_loss); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 227 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 228 | // Extract ST (spatio-temporal) resolution action. |
| 229 | // Inputs: qm: Reference to the quality modes pointer. |
| 230 | // Output: the spatial and/or temporal scale change. |
| 231 | int SelectResolution(VCMResolutionScale** qm); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 233 | private: |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 234 | // Set the default resolution action. |
| 235 | void SetDefaultAction(); |
| 236 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 237 | // Compute rates for the selection of down-sampling action. |
| 238 | void ComputeRatesForSelection(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 240 | // Compute the encoder state. |
| 241 | void ComputeEncoderState(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 243 | // Return true if the action is to go back up in resolution. |
| 244 | bool GoingUpResolution(); |
| 245 | |
| 246 | // Return true if the action is to go down in resolution. |
| 247 | bool GoingDownResolution(); |
| 248 | |
| 249 | // Check the condition for going up in resolution by the scale factors: |
| 250 | // |facWidth|, |facHeight|, |facTemp|. |
| 251 | // |scaleFac| is a scale factor for the transition rate. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 252 | bool ConditionForGoingUp(float fac_width, |
| 253 | float fac_height, |
| 254 | float fac_temp, |
| 255 | float scale_fac); |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 256 | |
| 257 | // Get the bitrate threshold for the resolution action. |
| 258 | // The case |facWidth|=|facHeight|=|facTemp|==1 is for down-sampling action. |
| 259 | // |scaleFac| is a scale factor for the transition rate. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 260 | float GetTransitionRate(float fac_width, |
| 261 | float fac_height, |
| 262 | float fac_temp, |
| 263 | float scale_fac); |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 264 | |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 265 | // Update the down-sampling state. |
| 266 | void UpdateDownsamplingState(UpDownAction up_down); |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 267 | |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 268 | // Update the codec frame size and frame rate. |
| 269 | void UpdateCodecResolution(); |
| 270 | |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 271 | // Return a state based on average target rate relative transition rate. |
| 272 | uint8_t RateClass(float transition_rate); |
| 273 | |
| 274 | // Adjust the action selected from the table. |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 275 | void AdjustAction(); |
| 276 | |
marpan@webrtc.org | e22d81c | 2012-03-20 18:21:53 +0000 | [diff] [blame] | 277 | // Covert 2 stages of 3/4 (=9/16) spatial decimation to 1/2. |
| 278 | void ConvertSpatialFractionalToWhole(); |
| 279 | |
marpan@webrtc.org | c5b392e | 2012-06-29 21:44:55 +0000 | [diff] [blame] | 280 | // Returns true if the new frame sizes, under the selected spatial action, |
| 281 | // are of even size. |
| 282 | bool EvenFrameSize(); |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 283 | |
| 284 | // Insert latest down-sampling action into the history list. |
| 285 | void InsertLatestDownAction(); |
| 286 | |
| 287 | // Remove the last (first element) down-sampling action from the list. |
| 288 | void RemoveLastDownAction(); |
| 289 | |
| 290 | // Check constraints on the amount of down-sampling allowed. |
| 291 | void ConstrainAmountOfDownSampling(); |
| 292 | |
| 293 | // For going up in resolution: pick spatial or temporal action, |
| 294 | // if both actions were separately selected. |
| 295 | void PickSpatialOrTemporal(); |
| 296 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 297 | // Select the directional (1x2 or 2x1) spatial down-sampling action. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 298 | void SelectSpatialDirectionMode(float transition_rate); |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 299 | |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 300 | enum { kDownActionHistorySize = 10}; |
| 301 | |
| 302 | VCMResolutionScale* qm_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 303 | // Encoder rate control parameters. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 304 | float target_bitrate_; |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 305 | float incoming_framerate_; |
| 306 | float per_frame_bandwidth_; |
| 307 | float buffer_level_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 308 | |
| 309 | // Data accumulated every ~1sec from MediaOpt. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 310 | float sum_target_rate_; |
| 311 | float sum_incoming_framerate_; |
| 312 | float sum_rate_MM_; |
| 313 | float sum_rate_MM_sgn_; |
| 314 | float sum_packet_loss_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 315 | // Counters. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 316 | uint32_t frame_cnt_; |
| 317 | uint32_t frame_cnt_delta_; |
| 318 | uint32_t update_rate_cnt_; |
| 319 | uint32_t low_buffer_cnt_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 320 | |
| 321 | // Resolution state parameters. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 322 | float state_dec_factor_spatial_; |
| 323 | float state_dec_factor_temporal_; |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 324 | |
| 325 | // Quantities used for selection. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 326 | float avg_target_rate_; |
| 327 | float avg_incoming_framerate_; |
| 328 | float avg_ratio_buffer_low_; |
| 329 | float avg_rate_mismatch_; |
| 330 | float avg_rate_mismatch_sgn_; |
| 331 | float avg_packet_loss_; |
| 332 | EncoderState encoder_state_; |
| 333 | ResolutionAction action_; |
| 334 | // Short history of the down-sampling actions from the Initialize() state. |
| 335 | // This is needed for going up in resolution. Since the total amount of |
| 336 | // down-sampling actions are constrained, the length of the list need not be |
| 337 | // large: i.e., (4/3) ^{kDownActionHistorySize} <= kMaxDownSample. |
| 338 | ResolutionAction down_action_history_[kDownActionHistorySize]; |
| 339 | int num_layers_; |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 340 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 341 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 342 | // Robustness settings class. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 343 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 344 | class VCMQmRobustness : public VCMQmMethod { |
| 345 | public: |
| 346 | VCMQmRobustness(); |
| 347 | ~VCMQmRobustness(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 348 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 349 | virtual void Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 350 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 351 | // Adjust FEC rate based on content: every ~1 sec from SetTargetRates. |
| 352 | // Returns an adjustment factor. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 353 | float AdjustFecFactor(uint8_t code_rate_delta, |
| 354 | float total_rate, |
| 355 | float framerate, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 356 | int64_t rtt_time, |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 357 | uint8_t packet_loss); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 358 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 359 | // Set the UEP protection on/off. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 360 | bool SetUepProtection(uint8_t code_rate_delta, |
| 361 | float total_rate, |
| 362 | uint8_t packet_loss, |
| 363 | bool frame_type); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 364 | |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 365 | private: |
| 366 | // Previous state of network parameters. |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 367 | float prev_total_rate_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 368 | int64_t prev_rtt_time_; |
marpan@webrtc.org | accf607 | 2012-03-07 17:16:10 +0000 | [diff] [blame] | 369 | uint8_t prev_packet_loss_; |
| 370 | uint8_t prev_code_rate_delta_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | }; |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 372 | } // namespace webrtc |
marpan@webrtc.org | 9d76b4e | 2012-02-28 23:39:31 +0000 | [diff] [blame] | 373 | #endif // WEBRTC_MODULES_VIDEO_CODING_QM_SELECT_H_ |