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> |
| 14 #include <utility> |
| 15 |
13 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
14 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 17 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
16 | 19 |
17 namespace webrtc { | 20 namespace webrtc { |
18 | 21 |
19 enum { kREDForFECHeaderLength = 1 }; | 22 enum { kREDForFECHeaderLength = 1 }; |
20 // This controls the maximum amount of excess overhead (actual - target) | 23 // This controls the maximum amount of excess overhead (actual - target) |
21 // allowed in order to trigger GenerateFec(), before |params_.max_fec_frames| | 24 // 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. | 25 // is reached. Overhead here is defined as relative to number of media packets. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 size_t payload_length, | 135 size_t payload_length, |
133 size_t rtp_header_length) { | 136 size_t rtp_header_length) { |
134 assert(fec_packets_.empty()); | 137 assert(fec_packets_.empty()); |
135 if (media_packets_fec_.empty()) { | 138 if (media_packets_fec_.empty()) { |
136 params_ = new_params_; | 139 params_ = new_params_; |
137 } | 140 } |
138 bool complete_frame = false; | 141 bool complete_frame = false; |
139 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; | 142 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; |
140 if (media_packets_fec_.size() < ForwardErrorCorrection::kMaxMediaPackets) { | 143 if (media_packets_fec_.size() < ForwardErrorCorrection::kMaxMediaPackets) { |
141 // Generic FEC can only protect up to kMaxMediaPackets packets. | 144 // Generic FEC can only protect up to kMaxMediaPackets packets. |
142 ForwardErrorCorrection::Packet* packet = | 145 std::unique_ptr<ForwardErrorCorrection::Packet> packet( |
143 new ForwardErrorCorrection::Packet(); | 146 new ForwardErrorCorrection::Packet()); |
144 packet->length = payload_length + rtp_header_length; | 147 packet->length = payload_length + rtp_header_length; |
145 memcpy(packet->data, data_buffer, packet->length); | 148 memcpy(packet->data, data_buffer, packet->length); |
146 media_packets_fec_.push_back(packet); | 149 media_packets_fec_.push_back(std::move(packet)); |
147 } | 150 } |
148 if (marker_bit) { | 151 if (marker_bit) { |
149 ++num_frames_; | 152 ++num_frames_; |
150 complete_frame = true; | 153 complete_frame = true; |
151 } | 154 } |
152 // Produce FEC over at most |params_.max_fec_frames| frames, or as soon as: | 155 // Produce FEC over at most |params_.max_fec_frames| frames, or as soon as: |
153 // (1) the excess overhead (actual overhead - requested/target overhead) is | 156 // (1) the excess overhead (actual overhead - requested/target overhead) is |
154 // less than |kMaxExcessOverhead|, and | 157 // less than |kMaxExcessOverhead|, and |
155 // (2) at least |minimum_media_packets_fec_| media packets is reached. | 158 // (2) at least |minimum_media_packets_fec_| media packets is reached. |
156 if (complete_frame && | 159 if (complete_frame && |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 size_t rtp_header_length) { | 215 size_t rtp_header_length) { |
213 std::vector<RedPacket*> fec_packets; | 216 std::vector<RedPacket*> fec_packets; |
214 fec_packets.reserve(fec_packets_.size()); | 217 fec_packets.reserve(fec_packets_.size()); |
215 uint16_t sequence_number = first_seq_num; | 218 uint16_t sequence_number = first_seq_num; |
216 while (!fec_packets_.empty()) { | 219 while (!fec_packets_.empty()) { |
217 // Build FEC packet. The FEC packets in |fec_packets_| doesn't | 220 // Build FEC packet. The FEC packets in |fec_packets_| doesn't |
218 // have RTP headers, so we're reusing the header from the last | 221 // have RTP headers, so we're reusing the header from the last |
219 // media packet. | 222 // media packet. |
220 ForwardErrorCorrection::Packet* packet_to_send = fec_packets_.front(); | 223 ForwardErrorCorrection::Packet* packet_to_send = fec_packets_.front(); |
221 ForwardErrorCorrection::Packet* last_media_packet = | 224 ForwardErrorCorrection::Packet* last_media_packet = |
222 media_packets_fec_.back(); | 225 media_packets_fec_.back().get(); |
223 | 226 |
224 RedPacket* red_packet = new RedPacket( | 227 RedPacket* red_packet = new RedPacket( |
225 packet_to_send->length + kREDForFECHeaderLength + rtp_header_length); | 228 packet_to_send->length + kREDForFECHeaderLength + rtp_header_length); |
226 red_packet->CreateHeader(last_media_packet->data, rtp_header_length, | 229 red_packet->CreateHeader(last_media_packet->data, rtp_header_length, |
227 red_pl_type, fec_pl_type); | 230 red_pl_type, fec_pl_type); |
228 red_packet->SetSeqNum(sequence_number++); | 231 red_packet->SetSeqNum(sequence_number++); |
229 red_packet->ClearMarkerBit(); | 232 red_packet->ClearMarkerBit(); |
230 red_packet->AssignPayload(packet_to_send->data, packet_to_send->length); | 233 red_packet->AssignPayload(packet_to_send->data, packet_to_send->length); |
231 | 234 |
232 fec_packets.push_back(red_packet); | 235 fec_packets.push_back(red_packet); |
(...skipping 11 matching lines...) Expand all Loading... |
244 // protection factor produced by video_coding module and how the FEC | 247 // protection factor produced by video_coding module and how the FEC |
245 // generation is implemented. | 248 // generation is implemented. |
246 assert(!media_packets_fec_.empty()); | 249 assert(!media_packets_fec_.empty()); |
247 int num_fec_packets = fec_->GetNumberOfFecPackets(media_packets_fec_.size(), | 250 int num_fec_packets = fec_->GetNumberOfFecPackets(media_packets_fec_.size(), |
248 params_.fec_rate); | 251 params_.fec_rate); |
249 // Return the overhead in Q8. | 252 // Return the overhead in Q8. |
250 return (num_fec_packets << 8) / media_packets_fec_.size(); | 253 return (num_fec_packets << 8) / media_packets_fec_.size(); |
251 } | 254 } |
252 | 255 |
253 void ProducerFec::DeletePackets() { | 256 void ProducerFec::DeletePackets() { |
254 while (!media_packets_fec_.empty()) { | 257 media_packets_fec_.clear(); |
255 delete media_packets_fec_.front(); | |
256 media_packets_fec_.pop_front(); | |
257 } | |
258 assert(media_packets_fec_.empty()); | |
259 } | 258 } |
260 | 259 |
261 } // namespace webrtc | 260 } // namespace webrtc |
OLD | NEW |