| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 fec_bitrate_.Update(fec_packet->length(), clock_->TimeInMilliseconds()); | 163 fec_bitrate_.Update(fec_packet->length(), clock_->TimeInMilliseconds()); |
| 164 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 164 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 165 "Video::PacketFec", "timestamp", rtp_timestamp, | 165 "Video::PacketFec", "timestamp", rtp_timestamp, |
| 166 "seqnum", fec_sequence_number); | 166 "seqnum", fec_sequence_number); |
| 167 } else { | 167 } else { |
| 168 LOG(LS_WARNING) << "Failed to send FEC packet " << fec_sequence_number; | 168 LOG(LS_WARNING) << "Failed to send FEC packet " << fec_sequence_number; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 void RTPSenderVideo::SetUlpfecConfig(bool enabled, | 173 void RTPSenderVideo::SetUlpfecConfig(int red_payload_type, |
| 174 int red_payload_type, | |
| 175 int ulpfec_payload_type) { | 174 int ulpfec_payload_type) { |
| 176 RTC_DCHECK(!enabled || red_payload_type > 0); | 175 // Sanity check. Per the definition of UlpfecConfig (see config.h), |
| 176 // a payload type of -1 means that the corresponding feature is |
| 177 // turned off. |
| 178 RTC_DCHECK_GE(red_payload_type, -1); |
| 177 RTC_DCHECK_LE(red_payload_type, 127); | 179 RTC_DCHECK_LE(red_payload_type, 127); |
| 180 RTC_DCHECK_GE(ulpfec_payload_type, -1); |
| 178 RTC_DCHECK_LE(ulpfec_payload_type, 127); | 181 RTC_DCHECK_LE(ulpfec_payload_type, 127); |
| 179 | 182 |
| 180 rtc::CritScope cs(&crit_); | 183 rtc::CritScope cs(&crit_); |
| 181 fec_enabled_ = enabled; | |
| 182 red_payload_type_ = red_payload_type; | 184 red_payload_type_ = red_payload_type; |
| 185 red_enabled_ = (red_payload_type_ != -1); |
| 183 fec_payload_type_ = ulpfec_payload_type; | 186 fec_payload_type_ = ulpfec_payload_type; |
| 187 fec_enabled_ = (fec_payload_type_ != -1); |
| 188 |
| 189 // TODO(brandtr): Remove when the RED/RTX workaround is removed. |
| 190 RTC_DCHECK(red_enabled_ || !fec_enabled_); |
| 184 | 191 |
| 185 // Reset FEC rates. | 192 // Reset FEC rates. |
| 186 delta_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom}; | 193 delta_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom}; |
| 187 key_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom}; | 194 key_fec_params_ = FecProtectionParams{0, 1, kFecMaskRandom}; |
| 188 } | 195 } |
| 189 | 196 |
| 190 void RTPSenderVideo::UlpfecConfig(bool* enabled, | 197 void RTPSenderVideo::UlpfecConfig(int* red_payload_type, |
| 191 int* red_payload_type, | |
| 192 int* ulpfec_payload_type) const { | 198 int* ulpfec_payload_type) const { |
| 193 rtc::CritScope cs(&crit_); | 199 rtc::CritScope cs(&crit_); |
| 194 *enabled = fec_enabled_; | |
| 195 *red_payload_type = red_payload_type_; | 200 *red_payload_type = red_payload_type_; |
| 196 *ulpfec_payload_type = fec_payload_type_; | 201 *ulpfec_payload_type = fec_payload_type_; |
| 197 } | 202 } |
| 198 | 203 |
| 199 size_t RTPSenderVideo::FecPacketOverhead() const { | 204 size_t RTPSenderVideo::FecPacketOverhead() const { |
| 200 rtc::CritScope cs(&crit_); | 205 rtc::CritScope cs(&crit_); |
| 201 size_t overhead = 0; | 206 size_t overhead = 0; |
| 202 if (red_payload_type_ != -1) { | 207 if (red_enabled_) { |
| 203 // Overhead is FEC headers plus RED for FEC header plus anything in RTP | 208 // Overhead is FEC headers plus RED for FEC header plus anything in RTP |
| 204 // header beyond the 12 bytes base header (CSRC list, extensions...) | 209 // header beyond the 12 bytes base header (CSRC list, extensions...) |
| 205 // This reason for the header extensions to be included here is that | 210 // This reason for the header extensions to be included here is that |
| 206 // from an FEC viewpoint, they are part of the payload to be protected. | 211 // from an FEC viewpoint, they are part of the payload to be protected. |
| 207 // (The base RTP header is already protected by the FEC header.) | 212 // (The base RTP header is already protected by the FEC header.) |
| 208 return producer_fec_.MaxPacketOverhead() + kRedForFecHeaderLength + | 213 return producer_fec_.MaxPacketOverhead() + kRedForFecHeaderLength + |
| 209 (rtp_sender_->RtpHeaderLength() - kRtpHeaderSize); | 214 (rtp_sender_->RtpHeaderLength() - kRtpHeaderSize); |
| 210 } | 215 } |
| 211 if (fec_enabled_) | 216 if (fec_enabled_) |
| 212 overhead += producer_fec_.MaxPacketOverhead(); | 217 overhead += producer_fec_.MaxPacketOverhead(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 (rtp_sender_->RtxStatus() ? kRtxHeaderSize : 0); | 270 (rtp_sender_->RtxStatus() ? kRtxHeaderSize : 0); |
| 266 RTC_DCHECK_LE(packet_capacity, rtp_header->capacity()); | 271 RTC_DCHECK_LE(packet_capacity, rtp_header->capacity()); |
| 267 RTC_DCHECK_GT(packet_capacity, rtp_header->headers_size()); | 272 RTC_DCHECK_GT(packet_capacity, rtp_header->headers_size()); |
| 268 size_t max_data_payload_length = packet_capacity - rtp_header->headers_size(); | 273 size_t max_data_payload_length = packet_capacity - rtp_header->headers_size(); |
| 269 | 274 |
| 270 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( | 275 std::unique_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( |
| 271 video_type, max_data_payload_length, | 276 video_type, max_data_payload_length, |
| 272 video_header ? &(video_header->codecHeader) : nullptr, frame_type)); | 277 video_header ? &(video_header->codecHeader) : nullptr, frame_type)); |
| 273 | 278 |
| 274 StorageType storage; | 279 StorageType storage; |
| 275 int red_payload_type; | 280 bool red_enabled; |
| 276 bool first_frame = first_frame_sent_(); | 281 bool first_frame = first_frame_sent_(); |
| 277 { | 282 { |
| 278 rtc::CritScope cs(&crit_); | 283 rtc::CritScope cs(&crit_); |
| 279 FecProtectionParams* fec_params = | 284 FecProtectionParams* fec_params = |
| 280 frame_type == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_; | 285 frame_type == kVideoFrameKey ? &key_fec_params_ : &delta_fec_params_; |
| 281 producer_fec_.SetFecParameters(fec_params); | 286 producer_fec_.SetFecParameters(fec_params); |
| 282 storage = packetizer->GetStorageType(retransmission_settings_); | 287 storage = packetizer->GetStorageType(retransmission_settings_); |
| 283 red_payload_type = red_payload_type_; | 288 red_enabled = red_enabled_; |
| 284 } | 289 } |
| 285 | 290 |
| 286 // TODO(changbin): we currently don't support to configure the codec to | 291 // TODO(changbin): we currently don't support to configure the codec to |
| 287 // output multiple partitions for VP8. Should remove below check after the | 292 // output multiple partitions for VP8. Should remove below check after the |
| 288 // issue is fixed. | 293 // issue is fixed. |
| 289 const RTPFragmentationHeader* frag = | 294 const RTPFragmentationHeader* frag = |
| 290 (video_type == kRtpVideoVp8) ? NULL : fragmentation; | 295 (video_type == kRtpVideoVp8) ? NULL : fragmentation; |
| 291 | 296 |
| 292 packetizer->SetPayloadData(payload_data, payload_size, frag); | 297 packetizer->SetPayloadData(payload_data, payload_size, frag); |
| 293 | 298 |
| 294 bool first = true; | 299 bool first = true; |
| 295 bool last = false; | 300 bool last = false; |
| 296 while (!last) { | 301 while (!last) { |
| 297 std::unique_ptr<RtpPacketToSend> packet(new RtpPacketToSend(*rtp_header)); | 302 std::unique_ptr<RtpPacketToSend> packet(new RtpPacketToSend(*rtp_header)); |
| 298 uint8_t* payload = packet->AllocatePayload(max_data_payload_length); | 303 uint8_t* payload = packet->AllocatePayload(max_data_payload_length); |
| 299 RTC_DCHECK(payload); | 304 RTC_DCHECK(payload); |
| 300 | 305 |
| 301 size_t payload_bytes_in_packet = 0; | 306 size_t payload_bytes_in_packet = 0; |
| 302 if (!packetizer->NextPacket(payload, &payload_bytes_in_packet, &last)) | 307 if (!packetizer->NextPacket(payload, &payload_bytes_in_packet, &last)) |
| 303 return false; | 308 return false; |
| 304 | 309 |
| 305 packet->SetPayloadSize(payload_bytes_in_packet); | 310 packet->SetPayloadSize(payload_bytes_in_packet); |
| 306 packet->SetMarker(last); | 311 packet->SetMarker(last); |
| 307 if (!rtp_sender_->AssignSequenceNumber(packet.get())) | 312 if (!rtp_sender_->AssignSequenceNumber(packet.get())) |
| 308 return false; | 313 return false; |
| 309 | 314 |
| 310 if (red_payload_type != -1) { | 315 if (red_enabled) { |
| 311 SendVideoPacketAsRed(std::move(packet), storage, | 316 SendVideoPacketAsRed(std::move(packet), storage, |
| 312 packetizer->GetProtectionType() == kProtectedPacket); | 317 packetizer->GetProtectionType() == kProtectedPacket); |
| 313 } else { | 318 } else { |
| 314 SendVideoPacket(std::move(packet), storage); | 319 SendVideoPacket(std::move(packet), storage); |
| 315 } | 320 } |
| 316 | 321 |
| 317 if (first_frame) { | 322 if (first_frame) { |
| 318 if (first) { | 323 if (first) { |
| 319 LOG(LS_INFO) | 324 LOG(LS_INFO) |
| 320 << "Sent first RTP packet of the first video frame (pre-pacer)"; | 325 << "Sent first RTP packet of the first video frame (pre-pacer)"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 346 rtc::CritScope cs(&crit_); | 351 rtc::CritScope cs(&crit_); |
| 347 return retransmission_settings_; | 352 return retransmission_settings_; |
| 348 } | 353 } |
| 349 | 354 |
| 350 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { | 355 void RTPSenderVideo::SetSelectiveRetransmissions(uint8_t settings) { |
| 351 rtc::CritScope cs(&crit_); | 356 rtc::CritScope cs(&crit_); |
| 352 retransmission_settings_ = settings; | 357 retransmission_settings_ = settings; |
| 353 } | 358 } |
| 354 | 359 |
| 355 } // namespace webrtc | 360 } // namespace webrtc |
| OLD | NEW |