| 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_packet_to_send.h" |
| 20 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 constexpr size_t kRedForFecHeaderLength = 1; | 25 constexpr size_t kRedForFecHeaderLength = 1; |
| 25 | 26 |
| 26 // This controls the maximum amount of excess overhead (actual - target) | 27 // This controls the maximum amount of excess overhead (actual - target) |
| 27 // allowed in order to trigger GenerateFec(), before |params_.max_fec_frames| | 28 // allowed in order to trigger GenerateFec(), before |params_.max_fec_frames| |
| 28 // is reached. Overhead here is defined as relative to number of media packets. | 29 // is reached. Overhead here is defined as relative to number of media packets. |
| 29 constexpr int kMaxExcessOverhead = 50; // Q8. | 30 constexpr int kMaxExcessOverhead = 50; // Q8. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // produced. | 138 // produced. |
| 138 new_params_ = *params; | 139 new_params_ = *params; |
| 139 num_important_packets_ = num_important_packets; | 140 num_important_packets_ = num_important_packets; |
| 140 if (params->fec_rate > kHighProtectionThreshold) { | 141 if (params->fec_rate > kHighProtectionThreshold) { |
| 141 min_num_media_packets_ = kMinMediaPackets; | 142 min_num_media_packets_ = kMinMediaPackets; |
| 142 } else { | 143 } else { |
| 143 min_num_media_packets_ = 1; | 144 min_num_media_packets_ = 1; |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 148 void ProducerFec::BuildRedPacket(int red_pl_type, |
| 149 const RtpPacketToSend& media_packet, |
| 150 RtpPacketToSend* red_packet) { |
| 151 RTC_DCHECK_GE(red_packet->capacity(), |
| 152 media_packet.size() + kRedForFecHeaderLength); |
| 153 red_packet->CopyHeaderFrom(media_packet); |
| 154 red_packet->SetPayloadType(red_pl_type); |
| 155 uint8_t* red_payload = red_packet->AllocatePayload( |
| 156 kRedForFecHeaderLength + media_packet.payload_size()); |
| 157 red_payload[0] = media_packet.PayloadType(); |
| 158 memcpy(&red_payload[kRedForFecHeaderLength], media_packet.payload(), |
| 159 media_packet.payload_size()); |
| 160 } |
| 161 |
| 147 int ProducerFec::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, | 162 int ProducerFec::AddRtpPacketAndGenerateFec(const uint8_t* data_buffer, |
| 148 size_t payload_length, | 163 size_t payload_length, |
| 149 size_t rtp_header_length) { | 164 size_t rtp_header_length) { |
| 150 RTC_DCHECK(generated_fec_packets_.empty()); | 165 RTC_DCHECK(generated_fec_packets_.empty()); |
| 151 if (media_packets_.empty()) { | 166 if (media_packets_.empty()) { |
| 152 params_ = new_params_; | 167 params_ = new_params_; |
| 153 } | 168 } |
| 154 bool complete_frame = false; | 169 bool complete_frame = false; |
| 155 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; | 170 const bool marker_bit = (data_buffer[1] & kRtpMarkerBitMask) ? true : false; |
| 156 if (media_packets_.size() < ForwardErrorCorrection::kMaxMediaPackets) { | 171 if (media_packets_.size() < ForwardErrorCorrection::kMaxMediaPackets) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 fec_->GetNumberOfFecPackets(media_packets_.size(), params_.fec_rate); | 276 fec_->GetNumberOfFecPackets(media_packets_.size(), params_.fec_rate); |
| 262 // Return the overhead in Q8. | 277 // Return the overhead in Q8. |
| 263 return (num_fec_packets << 8) / media_packets_.size(); | 278 return (num_fec_packets << 8) / media_packets_.size(); |
| 264 } | 279 } |
| 265 | 280 |
| 266 void ProducerFec::DeleteMediaPackets() { | 281 void ProducerFec::DeleteMediaPackets() { |
| 267 media_packets_.clear(); | 282 media_packets_.clear(); |
| 268 } | 283 } |
| 269 | 284 |
| 270 } // namespace webrtc | 285 } // namespace webrtc |
| OLD | NEW |