niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 8fe03af | 2012-01-23 14:56:14 +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_MEDIA_OPT_UTIL_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPT_UTIL_H_ |
| 13 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 14 | #include <math.h> |
| 15 | #include <stdlib.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 17 | #include "webrtc/base/exp_filter.h" |
pbos | ba8c15b | 2015-07-14 09:36:34 -0700 | [diff] [blame] | 18 | #include "webrtc/base/scoped_ptr.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame^] | 19 | #include "webrtc/modules/video_coding/internal_defines.h" |
| 20 | #include "webrtc/modules/video_coding/qm_select.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/include/trace.h" |
stefan@webrtc.org | eb91792 | 2013-02-18 14:40:18 +0000 | [diff] [blame] | 22 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 24 | namespace webrtc { |
| 25 | namespace media_optimization { |
| 26 | |
marpan@google.com | 30ecda1 | 2011-09-09 17:15:12 +0000 | [diff] [blame] | 27 | // Number of time periods used for (max) window filter for packet loss |
| 28 | // TODO (marpan): set reasonable window size for filtered packet loss, |
| 29 | // adjustment should be based on logged/real data of loss stats/correlation. |
| 30 | enum { kLossPrHistorySize = 10 }; |
| 31 | |
| 32 | // 1000 ms, total filter length is (kLossPrHistorySize * 1000) ms |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 33 | enum { kLossPrShortFilterWinMs = 1000 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
marpan@webrtc.org | 2dad3fb | 2012-01-09 18:18:36 +0000 | [diff] [blame] | 35 | // The type of filter used on the received packet loss reports. |
| 36 | enum FilterPacketLossMode { |
| 37 | kNoFilter, // No filtering on received loss. |
| 38 | kAvgFilter, // Recursive average filter. |
| 39 | kMaxFilter // Max-window filter, over the time interval of: |
| 40 | // (kLossPrHistorySize * kLossPrShortFilterWinMs) ms. |
| 41 | }; |
| 42 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | // Thresholds for hybrid NACK/FEC |
| 44 | // common to media optimization and the jitter buffer. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 45 | const int64_t kLowRttNackMs = 20; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
| 47 | struct VCMProtectionParameters |
| 48 | { |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 49 | VCMProtectionParameters() : rtt(0), lossPr(0.0f), bitRate(0.0f), |
| 50 | packetsPerFrame(0.0f), packetsPerFrameKey(0.0f), frameRate(0.0f), |
| 51 | keyFrameSize(0.0f), fecRateDelta(0), fecRateKey(0), |
Peter Boström | 9cb1f30 | 2015-04-01 11:39:49 +0200 | [diff] [blame] | 52 | codecWidth(0), codecHeight(0), |
mikhal@webrtc.org | 0e7d9d8 | 2011-12-19 19:04:49 +0000 | [diff] [blame] | 53 | numLayers(1) |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 54 | {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 56 | int64_t rtt; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 57 | float lossPr; |
| 58 | float bitRate; |
| 59 | float packetsPerFrame; |
| 60 | float packetsPerFrameKey; |
| 61 | float frameRate; |
| 62 | float keyFrameSize; |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 63 | uint8_t fecRateDelta; |
| 64 | uint8_t fecRateKey; |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 65 | uint16_t codecWidth; |
| 66 | uint16_t codecHeight; |
mikhal@webrtc.org | 0e7d9d8 | 2011-12-19 19:04:49 +0000 | [diff] [blame] | 67 | int numLayers; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | |
| 71 | /******************************/ |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 72 | /* VCMProtectionMethod class */ |
| 73 | /******************************/ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
| 75 | enum VCMProtectionMethodEnum |
| 76 | { |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 77 | kNack, |
| 78 | kFec, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | kNackFec, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | kNone |
| 81 | }; |
| 82 | |
| 83 | class VCMLossProbabilitySample |
| 84 | { |
| 85 | public: |
| 86 | VCMLossProbabilitySample() : lossPr255(0), timeMs(-1) {}; |
| 87 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 88 | uint8_t lossPr255; |
| 89 | int64_t timeMs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 93 | class VCMProtectionMethod |
| 94 | { |
| 95 | public: |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 96 | VCMProtectionMethod(); |
| 97 | virtual ~VCMProtectionMethod(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
| 99 | // Updates the efficiency of the method using the parameters provided |
| 100 | // |
| 101 | // Input: |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 102 | // - parameters : Parameters used to calculate efficiency |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | // |
| 104 | // Return value : True if this method is recommended in |
| 105 | // the given conditions. |
| 106 | virtual bool UpdateParameters(const VCMProtectionParameters* parameters) = 0; |
| 107 | |
| 108 | // Returns the protection type |
| 109 | // |
| 110 | // Return value : The protection type |
| 111 | enum VCMProtectionMethodEnum Type() const { return _type; } |
| 112 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | // Returns the effective packet loss for ER, required by this protection method |
| 114 | // |
| 115 | // Return value : Required effective packet loss |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 116 | virtual uint8_t RequiredPacketLossER() { return _effectivePacketLoss; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 117 | |
| 118 | // Extracts the FEC protection factor for Key frame, required by this protection method |
| 119 | // |
| 120 | // Return value : Required protectionFactor for Key frame |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 121 | virtual uint8_t RequiredProtectionFactorK() { return _protectionFactorK; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
| 123 | // Extracts the FEC protection factor for Delta frame, required by this protection method |
| 124 | // |
| 125 | // Return value : Required protectionFactor for delta frame |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 126 | virtual uint8_t RequiredProtectionFactorD() { return _protectionFactorD; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | |
marpan@google.com | 59fd0f1 | 2011-07-13 17:19:49 +0000 | [diff] [blame] | 128 | // Extracts whether the FEC Unequal protection (UEP) is used for Key frame. |
| 129 | // |
| 130 | // Return value : Required Unequal protection on/off state. |
mikhal@webrtc.org | 685383d | 2011-08-17 23:19:54 +0000 | [diff] [blame] | 131 | virtual bool RequiredUepProtectionK() { return _useUepProtectionK; } |
marpan@google.com | 59fd0f1 | 2011-07-13 17:19:49 +0000 | [diff] [blame] | 132 | |
| 133 | // Extracts whether the the FEC Unequal protection (UEP) is used for Delta frame. |
| 134 | // |
| 135 | // Return value : Required Unequal protection on/off state. |
mikhal@webrtc.org | 685383d | 2011-08-17 23:19:54 +0000 | [diff] [blame] | 136 | virtual bool RequiredUepProtectionD() { return _useUepProtectionD; } |
marpan@google.com | 59fd0f1 | 2011-07-13 17:19:49 +0000 | [diff] [blame] | 137 | |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 138 | virtual int MaxFramesFec() const { return 1; } |
| 139 | |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 140 | // Updates content metrics |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 141 | void UpdateContentMetrics(const VideoContentMetrics* contentMetrics); |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 142 | |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 143 | protected: |
| 144 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 145 | uint8_t _effectivePacketLoss; |
| 146 | uint8_t _protectionFactorK; |
| 147 | uint8_t _protectionFactorD; |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 148 | // Estimation of residual loss after the FEC |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | float _scaleProtKey; |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 150 | int32_t _maxPayloadSize; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 151 | |
marpan@google.com | 86548c6 | 2011-07-12 17:12:57 +0000 | [diff] [blame] | 152 | VCMQmRobustness* _qmRobustness; |
marpan@google.com | 59fd0f1 | 2011-07-13 17:19:49 +0000 | [diff] [blame] | 153 | bool _useUepProtectionK; |
| 154 | bool _useUepProtectionD; |
marpan@google.com | 191b780 | 2011-08-01 19:59:57 +0000 | [diff] [blame] | 155 | float _corrFecCost; |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 156 | enum VCMProtectionMethodEnum _type; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | class VCMNackMethod : public VCMProtectionMethod |
| 160 | { |
| 161 | public: |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 162 | VCMNackMethod(); |
| 163 | virtual ~VCMNackMethod(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | virtual bool UpdateParameters(const VCMProtectionParameters* parameters); |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 165 | // Get the effective packet loss |
| 166 | bool EffectivePacketLoss(const VCMProtectionParameters* parameter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | class VCMFecMethod : public VCMProtectionMethod |
| 170 | { |
| 171 | public: |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 172 | VCMFecMethod(); |
| 173 | virtual ~VCMFecMethod(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | virtual bool UpdateParameters(const VCMProtectionParameters* parameters); |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 175 | // Get the effective packet loss for ER |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | bool EffectivePacketLoss(const VCMProtectionParameters* parameters); |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 177 | // Get the FEC protection factors |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 178 | bool ProtectionFactor(const VCMProtectionParameters* parameters); |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 179 | // Get the boost for key frame protection |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 180 | uint8_t BoostCodeRateKey(uint8_t packetFrameDelta, |
| 181 | uint8_t packetFrameKey) const; |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 182 | // Convert the rates: defined relative to total# packets or source# packets |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 183 | uint8_t ConvertFECRate(uint8_t codeRate) const; |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 184 | // Get the average effective recovery from FEC: for random loss model |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | float AvgRecoveryFEC(const VCMProtectionParameters* parameters) const; |
mikhal@google.com | 679450f | 2011-08-01 22:14:58 +0000 | [diff] [blame] | 186 | // Update FEC with protectionFactorD |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 187 | void UpdateProtectionFactorD(uint8_t protectionFactorD); |
mikhal@webrtc.org | d0752c3 | 2011-10-19 15:48:30 +0000 | [diff] [blame] | 188 | // Update FEC with protectionFactorK |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 189 | void UpdateProtectionFactorK(uint8_t protectionFactorK); |
mikhal@webrtc.org | 0e7d9d8 | 2011-12-19 19:04:49 +0000 | [diff] [blame] | 190 | // Compute the bits per frame. Account for temporal layers when applicable. |
| 191 | int BitsPerFrame(const VCMProtectionParameters* parameters); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 192 | |
| 193 | protected: |
| 194 | enum { kUpperLimitFramesFec = 6 }; |
marpan@webrtc.org | 88ad06b | 2012-04-20 16:05:24 +0000 | [diff] [blame] | 195 | // Thresholds values for the bytes/frame and round trip time, below which we |
| 196 | // may turn off FEC, depending on |_numLayers| and |_maxFramesFec|. |
| 197 | // Max bytes/frame for VGA, corresponds to ~140k at 25fps. |
| 198 | enum { kMaxBytesPerFrameForFec = 700 }; |
| 199 | // Max bytes/frame for CIF and lower: corresponds to ~80k at 25fps. |
| 200 | enum { kMaxBytesPerFrameForFecLow = 400 }; |
| 201 | // Max bytes/frame for frame size larger than VGA, ~200k at 25fps. |
| 202 | enum { kMaxBytesPerFrameForFecHigh = 1000 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 206 | class VCMNackFecMethod : public VCMFecMethod |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | { |
| 208 | public: |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 209 | VCMNackFecMethod(int64_t lowRttNackThresholdMs, |
| 210 | int64_t highRttNackThresholdMs); |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 211 | virtual ~VCMNackFecMethod(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 212 | virtual bool UpdateParameters(const VCMProtectionParameters* parameters); |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 213 | // Get the effective packet loss for ER |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 214 | bool EffectivePacketLoss(const VCMProtectionParameters* parameters); |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 215 | // Get the protection factors |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | bool ProtectionFactor(const VCMProtectionParameters* parameters); |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 217 | // Get the max number of frames the FEC is allowed to be based on. |
| 218 | int MaxFramesFec() const; |
marpan@webrtc.org | 88ad06b | 2012-04-20 16:05:24 +0000 | [diff] [blame] | 219 | // Turn off the FEC based on low bitrate and other factors. |
| 220 | bool BitRateTooLowForFec(const VCMProtectionParameters* parameters); |
stefan@webrtc.org | 932ab18 | 2011-11-29 11:33:31 +0000 | [diff] [blame] | 221 | private: |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 222 | int ComputeMaxFramesFec(const VCMProtectionParameters* parameters); |
| 223 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 224 | int64_t _lowRttNackMs; |
| 225 | int64_t _highRttNackMs; |
stefan@webrtc.org | c35f5ce | 2012-04-11 07:42:25 +0000 | [diff] [blame] | 226 | int _maxFramesFec; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | class VCMLossProtectionLogic |
| 230 | { |
| 231 | public: |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 232 | VCMLossProtectionLogic(int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 233 | ~VCMLossProtectionLogic(); |
| 234 | |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 235 | // Set the protection method to be used |
| 236 | // |
| 237 | // Input: |
| 238 | // - newMethodType : New requested protection method type. If one |
| 239 | // is already set, it will be deleted and replaced |
pbos@webrtc.org | cade82c | 2015-03-12 10:39:24 +0000 | [diff] [blame] | 240 | void SetMethod(VCMProtectionMethodEnum newMethodType); |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 241 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 242 | // Update the round-trip time |
| 243 | // |
| 244 | // Input: |
| 245 | // - rtt : Round-trip time in seconds. |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 246 | void UpdateRtt(int64_t rtt); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 247 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 248 | // Update the filtered packet loss. |
| 249 | // |
| 250 | // Input: |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 251 | // - packetLossEnc : The reported packet loss filtered |
| 252 | // (max window or average) |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 253 | void UpdateFilteredLossPr(uint8_t packetLossEnc); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | |
| 255 | // Update the current target bit rate. |
| 256 | // |
| 257 | // Input: |
| 258 | // - bitRate : The current target bit rate in kbits/s |
| 259 | void UpdateBitRate(float bitRate); |
| 260 | |
| 261 | // Update the number of packets per frame estimate, for delta frames |
| 262 | // |
| 263 | // Input: |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 264 | // - nPackets : Number of packets in the latest sent frame. |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 265 | void UpdatePacketsPerFrame(float nPackets, int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 266 | |
| 267 | // Update the number of packets per frame estimate, for key frames |
| 268 | // |
| 269 | // Input: |
mikhal@google.com | 022716b | 2011-07-20 23:12:57 +0000 | [diff] [blame] | 270 | // - nPackets : umber of packets in the latest sent frame. |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 271 | void UpdatePacketsPerFrameKey(float nPackets, int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 272 | |
| 273 | // Update the keyFrameSize estimate |
| 274 | // |
| 275 | // Input: |
| 276 | // - keyFrameSize : The size of the latest sent key frame. |
| 277 | void UpdateKeyFrameSize(float keyFrameSize); |
| 278 | |
| 279 | // Update the frame rate |
| 280 | // |
| 281 | // Input: |
| 282 | // - frameRate : The current target frame rate. |
| 283 | void UpdateFrameRate(float frameRate) { _frameRate = frameRate; } |
| 284 | |
| 285 | // Update the frame size |
| 286 | // |
| 287 | // Input: |
| 288 | // - width : The codec frame width. |
| 289 | // - height : The codec frame height. |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 290 | void UpdateFrameSize(uint16_t width, uint16_t height); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 291 | |
mikhal@webrtc.org | 0e7d9d8 | 2011-12-19 19:04:49 +0000 | [diff] [blame] | 292 | // Update the number of active layers |
| 293 | // |
| 294 | // Input: |
| 295 | // - numLayers : Number of layers used. |
| 296 | void UpdateNumLayers(int numLayers); |
| 297 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 298 | // The amount of packet loss to cover for with FEC. |
| 299 | // |
| 300 | // Input: |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 301 | // - fecRateKey : Packet loss to cover for with FEC when |
| 302 | // sending key frames. |
| 303 | // - fecRateDelta : Packet loss to cover for with FEC when |
| 304 | // sending delta frames. |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 305 | void UpdateFECRates(uint8_t fecRateKey, uint8_t fecRateDelta) |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 306 | { _fecRateKey = fecRateKey; |
| 307 | _fecRateDelta = fecRateDelta; } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 308 | |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 309 | // Update the protection methods with the current VCMProtectionParameters |
mikhal@webrtc.org | 06ad81f | 2011-08-23 16:03:59 +0000 | [diff] [blame] | 310 | // and set the requested protection settings. |
mikhal@google.com | b29d940 | 2011-08-01 16:39:20 +0000 | [diff] [blame] | 311 | // Return value : Returns true on update |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 312 | bool UpdateMethod(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 313 | |
| 314 | // Returns the method currently selected. |
| 315 | // |
| 316 | // Return value : The protection method currently selected. |
| 317 | VCMProtectionMethod* SelectedMethod() const; |
| 318 | |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 319 | // Return the protection type of the currently selected method |
| 320 | VCMProtectionMethodEnum SelectedType() const; |
| 321 | |
marpan@webrtc.org | 2dad3fb | 2012-01-09 18:18:36 +0000 | [diff] [blame] | 322 | // Updates the filtered loss for the average and max window packet loss, |
| 323 | // and returns the filtered loss probability in the interval [0, 255]. |
| 324 | // The returned filtered loss value depends on the parameter |filter_mode|. |
| 325 | // The input parameter |lossPr255| is the received packet loss. |
| 326 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | // Return value : The filtered loss probability |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 328 | uint8_t FilteredLoss(int64_t nowMs, FilterPacketLossMode filter_mode, |
| 329 | uint8_t lossPr255); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 330 | |
henrik.lundin@webrtc.org | 7d8c72e | 2011-12-21 15:24:01 +0000 | [diff] [blame] | 331 | void Reset(int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 332 | |
mikhal@webrtc.org | a057a95 | 2011-08-26 21:17:34 +0000 | [diff] [blame] | 333 | void Release(); |
| 334 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 335 | private: |
| 336 | // Sets the available loss protection methods. |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 337 | void UpdateMaxLossHistory(uint8_t lossPr255, int64_t now); |
| 338 | uint8_t MaxFilteredLossPr(int64_t nowMs) const; |
pbos | ba8c15b | 2015-07-14 09:36:34 -0700 | [diff] [blame] | 339 | rtc::scoped_ptr<VCMProtectionMethod> _selectedMethod; |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 340 | VCMProtectionParameters _currentParameters; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 341 | int64_t _rtt; |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 342 | float _lossPr; |
| 343 | float _bitRate; |
| 344 | float _frameRate; |
| 345 | float _keyFrameSize; |
| 346 | uint8_t _fecRateKey; |
| 347 | uint8_t _fecRateDelta; |
| 348 | int64_t _lastPrUpdateT; |
| 349 | int64_t _lastPacketPerFrameUpdateT; |
| 350 | int64_t _lastPacketPerFrameUpdateTKey; |
| 351 | rtc::ExpFilter _lossPr255; |
| 352 | VCMLossProbabilitySample _lossPrHistory[kLossPrHistorySize]; |
| 353 | uint8_t _shortMaxLossPr255; |
| 354 | rtc::ExpFilter _packetsPerFrame; |
| 355 | rtc::ExpFilter _packetsPerFrameKey; |
minyue@webrtc.org | 74aaf29 | 2014-07-16 21:28:26 +0000 | [diff] [blame] | 356 | uint16_t _codecWidth; |
| 357 | uint16_t _codecHeight; |
| 358 | int _numLayers; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 359 | }; |
| 360 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 361 | } // namespace media_optimization |
| 362 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 363 | |
| 364 | #endif // WEBRTC_MODULES_VIDEO_CODING_MEDIA_OPT_UTIL_H_ |