Chromium Code Reviews| 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 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 | 94 |
| 95 ProducerFec::ProducerFec() | 95 ProducerFec::ProducerFec() |
| 96 : fec_(ForwardErrorCorrection::CreateUlpfec()), | 96 : fec_(ForwardErrorCorrection::CreateUlpfec()), |
| 97 num_protected_frames_(0), | 97 num_protected_frames_(0), |
| 98 num_important_packets_(0), | 98 num_important_packets_(0), |
| 99 min_num_media_packets_(1) { | 99 min_num_media_packets_(1) { |
| 100 memset(¶ms_, 0, sizeof(params_)); | 100 memset(¶ms_, 0, sizeof(params_)); |
| 101 memset(&new_params_, 0, sizeof(new_params_)); | 101 memset(&new_params_, 0, sizeof(new_params_)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 ProducerFec::~ProducerFec() { | 104 ProducerFec::~ProducerFec() = default; |
| 105 DeleteMediaPackets(); | |
| 106 } | |
| 107 | 105 |
| 108 std::unique_ptr<RedPacket> ProducerFec::BuildRedPacket( | 106 std::unique_ptr<RedPacket> ProducerFec::BuildRedPacket( |
| 109 const uint8_t* data_buffer, | 107 const uint8_t* data_buffer, |
| 110 size_t payload_length, | 108 size_t payload_length, |
| 111 size_t rtp_header_length, | 109 size_t rtp_header_length, |
| 112 int red_payload_type) { | 110 int red_payload_type) { |
| 113 std::unique_ptr<RedPacket> red_packet(new RedPacket( | 111 std::unique_ptr<RedPacket> red_packet(new RedPacket( |
| 114 payload_length + kRedForFecHeaderLength + rtp_header_length)); | 112 payload_length + kRedForFecHeaderLength + rtp_header_length)); |
| 115 int payload_type = data_buffer[1] & 0x7f; | 113 int payload_type = data_buffer[1] & 0x7f; |
| 116 red_packet->CreateHeader(data_buffer, rtp_header_length, red_payload_type, | 114 red_packet->CreateHeader(data_buffer, rtp_header_length, red_payload_type, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // it is currently always disabled. | 171 // it is currently always disabled. |
| 174 // | 172 // |
| 175 // Since unequal protection is disabled, the value of | 173 // Since unequal protection is disabled, the value of |
| 176 // |num_important_packets_| has no importance when calling GenerateFec(). | 174 // |num_important_packets_| has no importance when calling GenerateFec(). |
| 177 constexpr bool kUseUnequalProtection = false; | 175 constexpr bool kUseUnequalProtection = false; |
| 178 int ret = fec_->EncodeFec(media_packets_, params_.fec_rate, | 176 int ret = fec_->EncodeFec(media_packets_, params_.fec_rate, |
| 179 num_important_packets_, kUseUnequalProtection, | 177 num_important_packets_, kUseUnequalProtection, |
| 180 params_.fec_mask_type, &generated_fec_packets_); | 178 params_.fec_mask_type, &generated_fec_packets_); |
| 181 if (generated_fec_packets_.empty()) { | 179 if (generated_fec_packets_.empty()) { |
| 182 num_protected_frames_ = 0; | 180 num_protected_frames_ = 0; |
| 183 DeleteMediaPackets(); | 181 media_packets_.clear(); |
| 184 } | 182 } |
| 185 return ret; | 183 return ret; |
| 186 } | 184 } |
| 187 return 0; | 185 return 0; |
| 188 } | 186 } |
| 189 | 187 |
| 190 bool ProducerFec::ExcessOverheadBelowMax() const { | 188 bool ProducerFec::ExcessOverheadBelowMax() const { |
| 191 return ((Overhead() - params_.fec_rate) < kMaxExcessOverhead); | 189 return ((Overhead() - params_.fec_rate) < kMaxExcessOverhead); |
| 192 } | 190 } |
| 193 | 191 |
| 194 bool ProducerFec::MinimumMediaPacketsReached() const { | 192 bool ProducerFec::MinimumMediaPacketsReached() const { |
| 195 float average_num_packets_per_frame = | 193 float average_num_packets_per_frame = |
| 196 static_cast<float>(media_packets_.size()) / num_protected_frames_; | 194 static_cast<float>(media_packets_.size()) / num_protected_frames_; |
| 197 int num_media_packets = static_cast<int>(media_packets_.size()); | 195 int num_media_packets = static_cast<int>(media_packets_.size()); |
| 198 if (average_num_packets_per_frame < kMinMediaPacketsAdaptationThreshold) { | 196 if (average_num_packets_per_frame < kMinMediaPacketsAdaptationThreshold) { |
| 199 return num_media_packets >= min_num_media_packets_; | 197 return num_media_packets >= min_num_media_packets_; |
| 200 } else { | 198 } else { |
| 201 // For larger rates (more packets/frame), increase the threshold. | 199 // For larger rates (more packets/frame), increase the threshold. |
| 202 // TODO(brandtr): Investigate what impact this adaptation has. | 200 // TODO(brandtr): Investigate what impact this adaptation has. |
| 203 return num_media_packets >= min_num_media_packets_ + 1; | 201 return num_media_packets >= min_num_media_packets_ + 1; |
| 204 } | 202 } |
| 205 } | 203 } |
| 206 | 204 |
| 207 bool ProducerFec::FecAvailable() const { | |
| 208 return !generated_fec_packets_.empty(); | |
| 209 } | |
| 210 | |
| 211 size_t ProducerFec::NumAvailableFecPackets() const { | 205 size_t ProducerFec::NumAvailableFecPackets() const { |
| 212 return generated_fec_packets_.size(); | 206 return generated_fec_packets_.size(); |
|
stefan-webrtc
2016/09/05 14:50:20
Since generated_fec_packets_ is a list, this metho
stefan-webrtc
2016/09/05 14:52:36
Or actually since it's only tests, I'm ok with doi
brandtr
2016/09/05 14:58:38
NumAvailableFecPackets() is used by RTPSenderVideo
brandtr
2016/09/26 14:09:27
Sorry for the flip-flopping here, but I decided to
| |
| 213 } | 207 } |
| 214 | 208 |
| 215 size_t ProducerFec::MaxPacketOverhead() const { | 209 size_t ProducerFec::MaxPacketOverhead() const { |
| 216 return fec_->MaxPacketOverhead(); | 210 return fec_->MaxPacketOverhead(); |
| 217 } | 211 } |
| 218 | 212 |
| 219 std::vector<std::unique_ptr<RedPacket>> ProducerFec::GetFecPacketsAsRed( | 213 std::vector<std::unique_ptr<RedPacket>> ProducerFec::GetFecPacketsAsRed( |
| 220 int red_payload_type, | 214 int red_payload_type, |
| 221 int ulpfec_payload_type, | 215 int ulpfec_payload_type, |
| 222 uint16_t first_seq_num, | 216 uint16_t first_seq_num, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 234 std::unique_ptr<RedPacket> red_packet(new RedPacket( | 228 std::unique_ptr<RedPacket> red_packet(new RedPacket( |
| 235 fec_packet->length + kRedForFecHeaderLength + rtp_header_length)); | 229 fec_packet->length + kRedForFecHeaderLength + rtp_header_length)); |
| 236 red_packet->CreateHeader(last_media_packet->data, rtp_header_length, | 230 red_packet->CreateHeader(last_media_packet->data, rtp_header_length, |
| 237 red_payload_type, ulpfec_payload_type); | 231 red_payload_type, ulpfec_payload_type); |
| 238 red_packet->SetSeqNum(seq_num++); | 232 red_packet->SetSeqNum(seq_num++); |
| 239 red_packet->ClearMarkerBit(); | 233 red_packet->ClearMarkerBit(); |
| 240 red_packet->AssignPayload(fec_packet->data, fec_packet->length); | 234 red_packet->AssignPayload(fec_packet->data, fec_packet->length); |
| 241 red_packets.push_back(std::move(red_packet)); | 235 red_packets.push_back(std::move(red_packet)); |
| 242 } | 236 } |
| 243 // Reset state. | 237 // Reset state. |
| 244 DeleteMediaPackets(); | 238 media_packets_.clear(); |
| 245 generated_fec_packets_.clear(); | 239 generated_fec_packets_.clear(); |
| 246 num_protected_frames_ = 0; | 240 num_protected_frames_ = 0; |
| 247 return red_packets; | 241 return red_packets; |
| 248 } | 242 } |
| 249 | 243 |
| 250 int ProducerFec::Overhead() const { | 244 int ProducerFec::Overhead() const { |
| 251 // Overhead is defined as relative to the number of media packets, and not | |
| 252 // relative to total number of packets. This definition is inherited from the | |
| 253 // protection factor produced by video_coding module and how the FEC | |
| 254 // generation is implemented. | |
| 255 RTC_DCHECK(!media_packets_.empty()); | 245 RTC_DCHECK(!media_packets_.empty()); |
| 256 int num_fec_packets = | 246 int num_fec_packets = |
| 257 fec_->NumFecPackets(media_packets_.size(), params_.fec_rate); | 247 fec_->NumFecPackets(media_packets_.size(), params_.fec_rate); |
| 258 // Return the overhead in Q8. | 248 // Return the overhead in Q8. |
| 259 return (num_fec_packets << 8) / media_packets_.size(); | 249 return (num_fec_packets << 8) / media_packets_.size(); |
| 260 } | 250 } |
| 261 | 251 |
| 262 void ProducerFec::DeleteMediaPackets() { | |
| 263 media_packets_.clear(); | |
| 264 } | |
| 265 | |
| 266 } // namespace webrtc | 252 } // namespace webrtc |
| OLD | NEW |