Chromium Code Reviews

Side by Side Diff: webrtc/modules/rtp_rtcp/source/producer_fec.cc

Issue 2080553003: Style updates for ForwardErrorCorrection and related classes (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 "webrtc/modules/rtp_rtcp/source/byte_io.h" 13 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
14 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" 14 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h"
15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 enum { kREDForFECHeaderLength = 1 }; 19 enum { kREDForFECHeaderLength = 1 };
20 // This controls the maximum amount of excess overhead (actual - target) 20 // This controls the maximum amount of excess overhead (actual - target)
21 // allowed in order to trigger GenerateFEC(), before |params_.max_fec_frames| 21 // allowed in order to trigger GenerateFec(), before |params_.max_fec_frames|
22 // is reached. Overhead here is defined as relative to number of media packets. 22 // is reached. Overhead here is defined as relative to number of media packets.
23 enum { kMaxExcessOverhead = 50 }; // Q8. 23 enum { kMaxExcessOverhead = 50 }; // Q8.
24 // This is the minimum number of media packets required (above some protection 24 // This is the minimum number of media packets required (above some protection
25 // level) in order to trigger GenerateFEC(), before |params_.max_fec_frames| is 25 // level) in order to trigger GenerateFec(), before |params_.max_fec_frames| is
26 // reached. 26 // reached.
27 enum { kMinimumMediaPackets = 4 }; 27 enum { kMinimumMediaPackets = 4 };
28 // Threshold on the received FEC protection level, above which we enforce at 28 // Threshold on the received FEC protection level, above which we enforce at
29 // least |kMinimumMediaPackets| packets for the FEC code. Below this 29 // least |kMinimumMediaPackets| packets for the FEC code. Below this
30 // threshold |kMinimumMediaPackets| is set to default value of 1. 30 // threshold |kMinimumMediaPackets| is set to default value of 1.
31 enum { kHighProtectionThreshold = 80 }; // Corresponds to ~30 overhead, range 31 enum { kHighProtectionThreshold = 80 }; // Corresponds to ~30 overhead, range
32 // is 0 to 255, where 255 corresponds to 100% overhead (relative to number of 32 // is 0 to 255, where 255 corresponds to 100% overhead (relative to number of
33 // media packets). 33 // media packets).
34 34
35 RedPacket::RedPacket(size_t length) 35 RedPacket::RedPacket(size_t length)
(...skipping 96 matching lines...)
132 size_t payload_length, 132 size_t payload_length,
133 size_t rtp_header_length) { 133 size_t rtp_header_length) {
134 assert(fec_packets_.empty()); 134 assert(fec_packets_.empty());
135 if (media_packets_fec_.empty()) { 135 if (media_packets_fec_.empty()) {
136 params_ = new_params_; 136 params_ = new_params_;
137 } 137 }
138 bool complete_frame = false; 138 bool complete_frame = false;
139 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; 139 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false;
140 if (media_packets_fec_.size() < ForwardErrorCorrection::kMaxMediaPackets) { 140 if (media_packets_fec_.size() < ForwardErrorCorrection::kMaxMediaPackets) {
141 // Generic FEC can only protect up to kMaxMediaPackets packets. 141 // Generic FEC can only protect up to kMaxMediaPackets packets.
142 ForwardErrorCorrection::Packet* packet = new ForwardErrorCorrection::Packet; 142 ForwardErrorCorrection::Packet* packet =
143 new ForwardErrorCorrection::Packet();
143 packet->length = payload_length + rtp_header_length; 144 packet->length = payload_length + rtp_header_length;
144 memcpy(packet->data, data_buffer, packet->length); 145 memcpy(packet->data, data_buffer, packet->length);
145 media_packets_fec_.push_back(packet); 146 media_packets_fec_.push_back(packet);
146 } 147 }
147 if (marker_bit) { 148 if (marker_bit) {
148 ++num_frames_; 149 ++num_frames_;
149 complete_frame = true; 150 complete_frame = true;
150 } 151 }
151 // Produce FEC over at most |params_.max_fec_frames| frames, or as soon as: 152 // Produce FEC over at most |params_.max_fec_frames| frames, or as soon as:
152 // (1) the excess overhead (actual overhead - requested/target overhead) is 153 // (1) the excess overhead (actual overhead - requested/target overhead) is
153 // less than |kMaxExcessOverhead|, and 154 // less than |kMaxExcessOverhead|, and
154 // (2) at least |minimum_media_packets_fec_| media packets is reached. 155 // (2) at least |minimum_media_packets_fec_| media packets is reached.
155 if (complete_frame && 156 if (complete_frame &&
156 (num_frames_ == params_.max_fec_frames || 157 (num_frames_ == params_.max_fec_frames ||
157 (ExcessOverheadBelowMax() && MinimumMediaPacketsReached()))) { 158 (ExcessOverheadBelowMax() && MinimumMediaPacketsReached()))) {
158 assert(num_first_partition_ <= 159 assert(num_first_partition_ <=
159 static_cast<int>(ForwardErrorCorrection::kMaxMediaPackets)); 160 static_cast<int>(ForwardErrorCorrection::kMaxMediaPackets));
160 // TODO(pbos): Consider whether unequal protection should be enabled or not, 161 // TODO(pbos): Consider whether unequal protection should be enabled or not,
161 // it is currently always disabled. 162 // it is currently always disabled.
162 int ret = fec_->GenerateFEC(media_packets_fec_, params_.fec_rate, 163 int ret = fec_->GenerateFec(media_packets_fec_, params_.fec_rate,
163 num_first_partition_, false, 164 num_first_partition_, false,
164 params_.fec_mask_type, &fec_packets_); 165 params_.fec_mask_type, &fec_packets_);
165 if (fec_packets_.empty()) { 166 if (fec_packets_.empty()) {
166 num_frames_ = 0; 167 num_frames_ = 0;
167 DeletePackets(); 168 DeletePackets();
168 } 169 }
169 return ret; 170 return ret;
170 } 171 }
171 return 0; 172 return 0;
172 } 173 }
(...skipping 78 matching lines...)
251 252
252 void ProducerFec::DeletePackets() { 253 void ProducerFec::DeletePackets() {
253 while (!media_packets_fec_.empty()) { 254 while (!media_packets_fec_.empty()) {
254 delete media_packets_fec_.front(); 255 delete media_packets_fec_.front();
255 media_packets_fec_.pop_front(); 256 media_packets_fec_.pop_front();
256 } 257 }
257 assert(media_packets_fec_.empty()); 258 assert(media_packets_fec_.empty());
258 } 259 }
259 260
260 } // namespace webrtc 261 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/producer_fec.h ('k') | webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine