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 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" | 11 #include "webrtc/modules/rtp_rtcp/source/producer_fec.h" |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/base/basictypes.h" | 16 #include "webrtc/base/basictypes.h" |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
19 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 19 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
20 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 20 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 constexpr size_t kRedForFecHeaderLength = 1; | 24 constexpr size_t kRedForFecHeaderLength = 1; |
25 | 25 |
26 // This controls the maximum amount of excess overhead (actual - target) | 26 // This controls the maximum amount of excess overhead (actual - target) |
27 // allowed in order to trigger GenerateFec(), before |params_.max_fec_frames| | 27 // allowed in order to trigger EncodeFec(), before |params_.max_fec_frames| |
28 // is reached. Overhead here is defined as relative to number of media packets. | 28 // is reached. Overhead here is defined as relative to number of media packets. |
29 constexpr int kMaxExcessOverhead = 50; // Q8. | 29 constexpr int kMaxExcessOverhead = 50; // Q8. |
30 | 30 |
31 // This is the minimum number of media packets required (above some protection | 31 // This is the minimum number of media packets required (above some protection |
32 // level) in order to trigger GenerateFec(), before |params_.max_fec_frames| is | 32 // level) in order to trigger EncodeFec(), before |params_.max_fec_frames| is |
33 // reached. | 33 // reached. |
34 constexpr size_t kMinMediaPackets = 4; | 34 constexpr size_t kMinMediaPackets = 4; |
35 | 35 |
36 // Threshold on the received FEC protection level, above which we enforce at | 36 // Threshold on the received FEC protection level, above which we enforce at |
37 // least |kMinMediaPackets| packets for the FEC code. Below this | 37 // least |kMinMediaPackets| packets for the FEC code. Below this |
38 // threshold |kMinMediaPackets| is set to default value of 1. | 38 // threshold |kMinMediaPackets| is set to default value of 1. |
39 // | 39 // |
40 // The range is between 0 and 255, where 255 corresponds to 100% overhead | 40 // The range is between 0 and 255, where 255 corresponds to 100% overhead |
41 // (relative to the number of protected media packets). | 41 // (relative to the number of protected media packets). |
42 constexpr uint8_t kHighProtectionThreshold = 80; | 42 constexpr uint8_t kHighProtectionThreshold = 80; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 (num_protected_frames_ == params_.max_fec_frames || | 168 (num_protected_frames_ == params_.max_fec_frames || |
169 (ExcessOverheadBelowMax() && MinimumMediaPacketsReached()))) { | 169 (ExcessOverheadBelowMax() && MinimumMediaPacketsReached()))) { |
170 RTC_DCHECK_LE(num_important_packets_, | 170 RTC_DCHECK_LE(num_important_packets_, |
171 static_cast<int>(ForwardErrorCorrection::kMaxMediaPackets)); | 171 static_cast<int>(ForwardErrorCorrection::kMaxMediaPackets)); |
172 // TODO(pbos): Consider whether unequal protection should be enabled or not, | 172 // TODO(pbos): Consider whether unequal protection should be enabled or not, |
173 // it is currently always disabled. | 173 // it is currently always disabled. |
174 // | 174 // |
175 // Since unequal protection is disabled, the value of | 175 // Since unequal protection is disabled, the value of |
176 // |num_important_packets_| has no importance when calling GenerateFec(). | 176 // |num_important_packets_| has no importance when calling GenerateFec(). |
177 constexpr bool kUseUnequalProtection = false; | 177 constexpr bool kUseUnequalProtection = false; |
178 int ret = fec_.GenerateFec(media_packets_, params_.fec_rate, | 178 int ret = fec_.EncodeFec(media_packets_, params_.fec_rate, |
179 num_important_packets_, kUseUnequalProtection, | 179 num_important_packets_, kUseUnequalProtection, |
180 params_.fec_mask_type, &generated_fec_packets_); | 180 params_.fec_mask_type, &generated_fec_packets_); |
181 if (generated_fec_packets_.empty()) { | 181 if (generated_fec_packets_.empty()) { |
182 num_protected_frames_ = 0; | 182 num_protected_frames_ = 0; |
183 DeleteMediaPackets(); | 183 DeleteMediaPackets(); |
184 } | 184 } |
185 return ret; | 185 return ret; |
186 } | 186 } |
187 return 0; | 187 return 0; |
188 } | 188 } |
189 | 189 |
190 bool ProducerFec::ExcessOverheadBelowMax() const { | 190 bool ProducerFec::ExcessOverheadBelowMax() const { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 fec_.NumFecPackets(media_packets_.size(), params_.fec_rate); | 260 fec_.NumFecPackets(media_packets_.size(), params_.fec_rate); |
261 // Return the overhead in Q8. | 261 // Return the overhead in Q8. |
262 return (num_fec_packets << 8) / media_packets_.size(); | 262 return (num_fec_packets << 8) / media_packets_.size(); |
263 } | 263 } |
264 | 264 |
265 void ProducerFec::DeleteMediaPackets() { | 265 void ProducerFec::DeleteMediaPackets() { |
266 media_packets_.clear(); | 266 media_packets_.clear(); |
267 } | 267 } |
268 | 268 |
269 } // namespace webrtc | 269 } // namespace webrtc |
OLD | NEW |