| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 rtp_stats_callback_(nullptr), | 104 rtp_stats_callback_(nullptr), |
| 105 total_bitrate_sent_(kBitrateStatisticsWindowMs, | 105 total_bitrate_sent_(kBitrateStatisticsWindowMs, |
| 106 RateStatistics::kBpsScale), | 106 RateStatistics::kBpsScale), |
| 107 nack_bitrate_sent_(kBitrateStatisticsWindowMs, RateStatistics::kBpsScale), | 107 nack_bitrate_sent_(kBitrateStatisticsWindowMs, RateStatistics::kBpsScale), |
| 108 frame_count_observer_(frame_count_observer), | 108 frame_count_observer_(frame_count_observer), |
| 109 send_side_delay_observer_(send_side_delay_observer), | 109 send_side_delay_observer_(send_side_delay_observer), |
| 110 event_log_(event_log), | 110 event_log_(event_log), |
| 111 send_packet_observer_(send_packet_observer), | 111 send_packet_observer_(send_packet_observer), |
| 112 bitrate_callback_(bitrate_callback), | 112 bitrate_callback_(bitrate_callback), |
| 113 // RTP variables | 113 // RTP variables |
| 114 ssrc_db_(SSRCDatabase::GetSSRCDatabase()), |
| 114 remote_ssrc_(0), | 115 remote_ssrc_(0), |
| 115 sequence_number_forced_(false), | 116 sequence_number_forced_(false), |
| 117 ssrc_forced_(false), |
| 116 last_rtp_timestamp_(0), | 118 last_rtp_timestamp_(0), |
| 117 capture_time_ms_(0), | 119 capture_time_ms_(0), |
| 118 last_timestamp_time_ms_(0), | 120 last_timestamp_time_ms_(0), |
| 119 media_has_been_sent_(false), | 121 media_has_been_sent_(false), |
| 120 last_packet_marker_bit_(false), | 122 last_packet_marker_bit_(false), |
| 121 csrcs_(), | 123 csrcs_(), |
| 122 rtx_(kRtxOff), | 124 rtx_(kRtxOff), |
| 123 rtp_overhead_bytes_per_packet_(0), | 125 rtp_overhead_bytes_per_packet_(0), |
| 124 retransmission_rate_limiter_(retransmission_rate_limiter), | 126 retransmission_rate_limiter_(retransmission_rate_limiter), |
| 125 overhead_observer_(overhead_observer), | 127 overhead_observer_(overhead_observer), |
| 126 send_side_bwe_with_overhead_( | 128 send_side_bwe_with_overhead_( |
| 127 webrtc::field_trial::FindFullName( | 129 webrtc::field_trial::FindFullName( |
| 128 "WebRTC-SendSideBwe-WithOverhead") == "Enabled") { | 130 "WebRTC-SendSideBwe-WithOverhead") == "Enabled") { |
| 131 ssrc_ = ssrc_db_->CreateSSRC(); |
| 132 RTC_DCHECK(ssrc_ != 0); |
| 133 ssrc_rtx_ = ssrc_db_->CreateSSRC(); |
| 134 RTC_DCHECK(ssrc_rtx_ != 0); |
| 135 |
| 129 // This random initialization is not intended to be cryptographic strong. | 136 // This random initialization is not intended to be cryptographic strong. |
| 130 timestamp_offset_ = random_.Rand<uint32_t>(); | 137 timestamp_offset_ = random_.Rand<uint32_t>(); |
| 131 // Random start, 16 bits. Can't be 0. | 138 // Random start, 16 bits. Can't be 0. |
| 132 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 139 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 133 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 140 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 134 | 141 |
| 135 // Store FlexFEC packets in the packet history data structure, so they can | 142 // Store FlexFEC packets in the packet history data structure, so they can |
| 136 // be found when paced. | 143 // be found when paced. |
| 137 if (flexfec_sender) { | 144 if (flexfec_sender) { |
| 138 flexfec_packet_history_.SetStorePacketsStatus( | 145 flexfec_packet_history_.SetStorePacketsStatus( |
| 139 true, kMinFlexfecPacketsToStoreForPacing); | 146 true, kMinFlexfecPacketsToStoreForPacing); |
| 140 } | 147 } |
| 141 } | 148 } |
| 142 | 149 |
| 143 RTPSender::~RTPSender() { | 150 RTPSender::~RTPSender() { |
| 144 // TODO(tommi): Use a thread checker to ensure the object is created and | 151 // TODO(tommi): Use a thread checker to ensure the object is created and |
| 145 // deleted on the same thread. At the moment this isn't possible due to | 152 // deleted on the same thread. At the moment this isn't possible due to |
| 146 // voe::ChannelOwner in voice engine. To reproduce, run: | 153 // voe::ChannelOwner in voice engine. To reproduce, run: |
| 147 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus | 154 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus |
| 148 | 155 |
| 149 // TODO(tommi,holmer): We don't grab locks in the dtor before accessing member | 156 // TODO(tommi,holmer): We don't grab locks in the dtor before accessing member |
| 150 // variables but we grab them in all other methods. (what's the design?) | 157 // variables but we grab them in all other methods. (what's the design?) |
| 151 // Start documenting what thread we're on in what method so that it's easier | 158 // Start documenting what thread we're on in what method so that it's easier |
| 152 // to understand performance attributes and possibly remove locks. | 159 // to understand performance attributes and possibly remove locks. |
| 160 if (remote_ssrc_ != 0) { |
| 161 ssrc_db_->ReturnSSRC(remote_ssrc_); |
| 162 } |
| 163 ssrc_db_->ReturnSSRC(ssrc_); |
| 164 |
| 165 SSRCDatabase::ReturnSSRCDatabase(); |
| 153 while (!payload_type_map_.empty()) { | 166 while (!payload_type_map_.empty()) { |
| 154 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 167 std::map<int8_t, RtpUtility::Payload*>::iterator it = |
| 155 payload_type_map_.begin(); | 168 payload_type_map_.begin(); |
| 156 delete it->second; | 169 delete it->second; |
| 157 payload_type_map_.erase(it); | 170 payload_type_map_.erase(it); |
| 158 } | 171 } |
| 159 } | 172 } |
| 160 | 173 |
| 161 uint16_t RTPSender::ActualSendBitrateKbit() const { | 174 uint16_t RTPSender::ActualSendBitrateKbit() const { |
| 162 rtc::CritScope cs(&statistics_crit_); | 175 rtc::CritScope cs(&statistics_crit_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 190 switch (type) { | 203 switch (type) { |
| 191 case kRtpExtensionVideoRotation: | 204 case kRtpExtensionVideoRotation: |
| 192 case kRtpExtensionPlayoutDelay: | 205 case kRtpExtensionPlayoutDelay: |
| 193 case kRtpExtensionTransmissionTimeOffset: | 206 case kRtpExtensionTransmissionTimeOffset: |
| 194 case kRtpExtensionAbsoluteSendTime: | 207 case kRtpExtensionAbsoluteSendTime: |
| 195 case kRtpExtensionAudioLevel: | 208 case kRtpExtensionAudioLevel: |
| 196 case kRtpExtensionTransportSequenceNumber: | 209 case kRtpExtensionTransportSequenceNumber: |
| 197 return rtp_header_extension_map_.Register(type, id); | 210 return rtp_header_extension_map_.Register(type, id); |
| 198 case kRtpExtensionNone: | 211 case kRtpExtensionNone: |
| 199 case kRtpExtensionNumberOfExtensions: | 212 case kRtpExtensionNumberOfExtensions: |
| 200 LOG(LS_ERROR) << "Invalid RTP extension type for registration."; | 213 LOG(LS_ERROR) << "Invalid RTP extension type for registration"; |
| 201 return -1; | 214 return -1; |
| 202 } | 215 } |
| 203 return -1; | 216 return -1; |
| 204 } | 217 } |
| 205 | 218 |
| 206 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) const { | 219 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) const { |
| 207 rtc::CritScope lock(&send_critsect_); | 220 rtc::CritScope lock(&send_critsect_); |
| 208 return rtp_header_extension_map_.IsRegistered(type); | 221 return rtp_header_extension_map_.IsRegistered(type); |
| 209 } | 222 } |
| 210 | 223 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 rtx_ = mode; | 327 rtx_ = mode; |
| 315 } | 328 } |
| 316 | 329 |
| 317 int RTPSender::RtxStatus() const { | 330 int RTPSender::RtxStatus() const { |
| 318 rtc::CritScope lock(&send_critsect_); | 331 rtc::CritScope lock(&send_critsect_); |
| 319 return rtx_; | 332 return rtx_; |
| 320 } | 333 } |
| 321 | 334 |
| 322 void RTPSender::SetRtxSsrc(uint32_t ssrc) { | 335 void RTPSender::SetRtxSsrc(uint32_t ssrc) { |
| 323 rtc::CritScope lock(&send_critsect_); | 336 rtc::CritScope lock(&send_critsect_); |
| 324 ssrc_rtx_.emplace(ssrc); | 337 ssrc_rtx_ = ssrc; |
| 325 } | 338 } |
| 326 | 339 |
| 327 uint32_t RTPSender::RtxSsrc() const { | 340 uint32_t RTPSender::RtxSsrc() const { |
| 328 rtc::CritScope lock(&send_critsect_); | 341 rtc::CritScope lock(&send_critsect_); |
| 329 RTC_DCHECK(ssrc_rtx_); | 342 return ssrc_rtx_; |
| 330 return *ssrc_rtx_; | |
| 331 } | 343 } |
| 332 | 344 |
| 333 void RTPSender::SetRtxPayloadType(int payload_type, | 345 void RTPSender::SetRtxPayloadType(int payload_type, |
| 334 int associated_payload_type) { | 346 int associated_payload_type) { |
| 335 rtc::CritScope lock(&send_critsect_); | 347 rtc::CritScope lock(&send_critsect_); |
| 336 RTC_DCHECK_LE(payload_type, 127); | 348 RTC_DCHECK_LE(payload_type, 127); |
| 337 RTC_DCHECK_LE(associated_payload_type, 127); | 349 RTC_DCHECK_LE(associated_payload_type, 127); |
| 338 if (payload_type < 0) { | 350 if (payload_type < 0) { |
| 339 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type << "."; | 351 LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type; |
| 340 return; | 352 return; |
| 341 } | 353 } |
| 342 | 354 |
| 343 rtx_payload_type_map_[associated_payload_type] = payload_type; | 355 rtx_payload_type_map_[associated_payload_type] = payload_type; |
| 344 } | 356 } |
| 345 | 357 |
| 346 int32_t RTPSender::CheckPayloadType(int8_t payload_type, | 358 int32_t RTPSender::CheckPayloadType(int8_t payload_type, |
| 347 RtpVideoCodecTypes* video_type) { | 359 RtpVideoCodecTypes* video_type) { |
| 348 rtc::CritScope lock(&send_critsect_); | 360 rtc::CritScope lock(&send_critsect_); |
| 349 | 361 |
| 350 if (payload_type < 0) { | 362 if (payload_type < 0) { |
| 351 LOG(LS_ERROR) << "Invalid payload_type " << payload_type << "."; | 363 LOG(LS_ERROR) << "Invalid payload_type " << payload_type; |
| 352 return -1; | 364 return -1; |
| 353 } | 365 } |
| 354 if (payload_type_ == payload_type) { | 366 if (payload_type_ == payload_type) { |
| 355 if (!audio_configured_) { | 367 if (!audio_configured_) { |
| 356 *video_type = video_->VideoCodecType(); | 368 *video_type = video_->VideoCodecType(); |
| 357 } | 369 } |
| 358 return 0; | 370 return 0; |
| 359 } | 371 } |
| 360 std::map<int8_t, RtpUtility::Payload*>::iterator it = | 372 std::map<int8_t, RtpUtility::Payload*>::iterator it = |
| 361 payload_type_map_.find(payload_type); | 373 payload_type_map_.find(payload_type); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 382 size_t payload_size, | 394 size_t payload_size, |
| 383 const RTPFragmentationHeader* fragmentation, | 395 const RTPFragmentationHeader* fragmentation, |
| 384 const RTPVideoHeader* rtp_header, | 396 const RTPVideoHeader* rtp_header, |
| 385 uint32_t* transport_frame_id_out) { | 397 uint32_t* transport_frame_id_out) { |
| 386 uint32_t ssrc; | 398 uint32_t ssrc; |
| 387 uint16_t sequence_number; | 399 uint16_t sequence_number; |
| 388 uint32_t rtp_timestamp; | 400 uint32_t rtp_timestamp; |
| 389 { | 401 { |
| 390 // Drop this packet if we're not sending media packets. | 402 // Drop this packet if we're not sending media packets. |
| 391 rtc::CritScope lock(&send_critsect_); | 403 rtc::CritScope lock(&send_critsect_); |
| 392 RTC_DCHECK(ssrc_); | 404 ssrc = ssrc_; |
| 393 | |
| 394 ssrc = *ssrc_; | |
| 395 sequence_number = sequence_number_; | 405 sequence_number = sequence_number_; |
| 396 rtp_timestamp = timestamp_offset_ + capture_timestamp; | 406 rtp_timestamp = timestamp_offset_ + capture_timestamp; |
| 397 if (transport_frame_id_out) | 407 if (transport_frame_id_out) |
| 398 *transport_frame_id_out = rtp_timestamp; | 408 *transport_frame_id_out = rtp_timestamp; |
| 399 if (!sending_media_) | 409 if (!sending_media_) |
| 400 return true; | 410 return true; |
| 401 } | 411 } |
| 402 RtpVideoCodecTypes video_type = kRtpVideoGeneric; | 412 RtpVideoCodecTypes video_type = kRtpVideoGeneric; |
| 403 if (CheckPayloadType(payload_type, &video_type) != 0) { | 413 if (CheckPayloadType(payload_type, &video_type) != 0) { |
| 404 LOG(LS_ERROR) << "Don't send data with unknown payload type: " | 414 LOG(LS_ERROR) << "Don't send data with unknown payload type: " |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 if (rtx_ == kRtxOff) { | 514 if (rtx_ == kRtxOff) { |
| 505 if (payload_type_ == -1) | 515 if (payload_type_ == -1) |
| 506 break; | 516 break; |
| 507 // Without RTX we can't send padding in the middle of frames. | 517 // Without RTX we can't send padding in the middle of frames. |
| 508 // For audio marker bits doesn't mark the end of a frame and frames | 518 // For audio marker bits doesn't mark the end of a frame and frames |
| 509 // are usually a single packet, so for now we don't apply this rule | 519 // are usually a single packet, so for now we don't apply this rule |
| 510 // for audio. | 520 // for audio. |
| 511 if (!audio_configured_ && !last_packet_marker_bit_) { | 521 if (!audio_configured_ && !last_packet_marker_bit_) { |
| 512 break; | 522 break; |
| 513 } | 523 } |
| 514 if (!ssrc_) { | 524 ssrc = ssrc_; |
| 515 LOG(LS_ERROR) << "SSRC unset."; | |
| 516 return 0; | |
| 517 } | |
| 518 | |
| 519 RTC_DCHECK(ssrc_); | |
| 520 ssrc = *ssrc_; | |
| 521 | |
| 522 sequence_number = sequence_number_; | 525 sequence_number = sequence_number_; |
| 523 ++sequence_number_; | 526 ++sequence_number_; |
| 524 payload_type = payload_type_; | 527 payload_type = payload_type_; |
| 525 over_rtx = false; | 528 over_rtx = false; |
| 526 } else { | 529 } else { |
| 527 // Without abs-send-time or transport sequence number a media packet | 530 // Without abs-send-time or transport sequence number a media packet |
| 528 // must be sent before padding so that the timestamps used for | 531 // must be sent before padding so that the timestamps used for |
| 529 // estimation are correct. | 532 // estimation are correct. |
| 530 if (!media_has_been_sent_ && | 533 if (!media_has_been_sent_ && |
| 531 !(rtp_header_extension_map_.IsRegistered(AbsoluteSendTime::kId) || | 534 !(rtp_header_extension_map_.IsRegistered(AbsoluteSendTime::kId) || |
| 532 (rtp_header_extension_map_.IsRegistered( | 535 (rtp_header_extension_map_.IsRegistered( |
| 533 TransportSequenceNumber::kId) && | 536 TransportSequenceNumber::kId) && |
| 534 transport_sequence_number_allocator_))) { | 537 transport_sequence_number_allocator_))) { |
| 535 break; | 538 break; |
| 536 } | 539 } |
| 537 // Only change change the timestamp of padding packets sent over RTX. | 540 // Only change change the timestamp of padding packets sent over RTX. |
| 538 // Padding only packets over RTP has to be sent as part of a media | 541 // Padding only packets over RTP has to be sent as part of a media |
| 539 // frame (and therefore the same timestamp). | 542 // frame (and therefore the same timestamp). |
| 540 if (last_timestamp_time_ms_ > 0) { | 543 if (last_timestamp_time_ms_ > 0) { |
| 541 timestamp += | 544 timestamp += |
| 542 (now_ms - last_timestamp_time_ms_) * kTimestampTicksPerMs; | 545 (now_ms - last_timestamp_time_ms_) * kTimestampTicksPerMs; |
| 543 capture_time_ms += (now_ms - last_timestamp_time_ms_); | 546 capture_time_ms += (now_ms - last_timestamp_time_ms_); |
| 544 } | 547 } |
| 545 if (!ssrc_rtx_) { | 548 ssrc = ssrc_rtx_; |
| 546 LOG(LS_ERROR) << "RTX SSRC unset."; | |
| 547 return 0; | |
| 548 } | |
| 549 RTC_DCHECK(ssrc_rtx_); | |
| 550 ssrc = *ssrc_rtx_; | |
| 551 sequence_number = sequence_number_rtx_; | 549 sequence_number = sequence_number_rtx_; |
| 552 ++sequence_number_rtx_; | 550 ++sequence_number_rtx_; |
| 553 payload_type = rtx_payload_type_map_.begin()->second; | 551 payload_type = rtx_payload_type_map_.begin()->second; |
| 554 over_rtx = true; | 552 over_rtx = true; |
| 555 } | 553 } |
| 556 } | 554 } |
| 557 | 555 |
| 558 RtpPacketToSend padding_packet(&rtp_header_extension_map_); | 556 RtpPacketToSend padding_packet(&rtp_header_extension_map_); |
| 559 padding_packet.SetPayloadType(payload_type); | 557 padding_packet.SetPayloadType(payload_type); |
| 560 padding_packet.SetMarker(false); | 558 padding_packet.SetMarker(false); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 if (event_log_ && bytes_sent > 0) { | 638 if (event_log_ && bytes_sent > 0) { |
| 641 event_log_->LogRtpHeader(kOutgoingPacket, MediaType::ANY, packet.data(), | 639 event_log_->LogRtpHeader(kOutgoingPacket, MediaType::ANY, packet.data(), |
| 642 packet.size()); | 640 packet.size()); |
| 643 } | 641 } |
| 644 } | 642 } |
| 645 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 643 TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 646 "RTPSender::SendPacketToNetwork", "size", packet.size(), | 644 "RTPSender::SendPacketToNetwork", "size", packet.size(), |
| 647 "sent", bytes_sent); | 645 "sent", bytes_sent); |
| 648 // TODO(pwestin): Add a separate bitrate for sent bitrate after pacer. | 646 // TODO(pwestin): Add a separate bitrate for sent bitrate after pacer. |
| 649 if (bytes_sent <= 0) { | 647 if (bytes_sent <= 0) { |
| 650 LOG(LS_WARNING) << "Transport failed to send packet."; | 648 LOG(LS_WARNING) << "Transport failed to send packet"; |
| 651 return false; | 649 return false; |
| 652 } | 650 } |
| 653 return true; | 651 return true; |
| 654 } | 652 } |
| 655 | 653 |
| 656 int RTPSender::SelectiveRetransmissions() const { | 654 int RTPSender::SelectiveRetransmissions() const { |
| 657 if (!video_) | 655 if (!video_) |
| 658 return -1; | 656 return -1; |
| 659 return video_->SelectiveRetransmissions(); | 657 return video_->SelectiveRetransmissions(); |
| 660 } | 658 } |
| 661 | 659 |
| 662 int RTPSender::SetSelectiveRetransmissions(uint8_t settings) { | 660 int RTPSender::SetSelectiveRetransmissions(uint8_t settings) { |
| 663 if (!video_) | 661 if (!video_) |
| 664 return -1; | 662 return -1; |
| 665 video_->SetSelectiveRetransmissions(settings); | 663 video_->SetSelectiveRetransmissions(settings); |
| 666 return 0; | 664 return 0; |
| 667 } | 665 } |
| 668 | 666 |
| 669 void RTPSender::OnReceivedNack( | 667 void RTPSender::OnReceivedNack( |
| 670 const std::vector<uint16_t>& nack_sequence_numbers, | 668 const std::vector<uint16_t>& nack_sequence_numbers, |
| 671 int64_t avg_rtt) { | 669 int64_t avg_rtt) { |
| 672 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 670 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| 673 "RTPSender::OnReceivedNACK", "num_seqnum", | 671 "RTPSender::OnReceivedNACK", "num_seqnum", |
| 674 nack_sequence_numbers.size(), "avg_rtt", avg_rtt); | 672 nack_sequence_numbers.size(), "avg_rtt", avg_rtt); |
| 675 for (uint16_t seq_no : nack_sequence_numbers) { | 673 for (uint16_t seq_no : nack_sequence_numbers) { |
| 676 const int32_t bytes_sent = ReSendPacket(seq_no, 5 + avg_rtt); | 674 const int32_t bytes_sent = ReSendPacket(seq_no, 5 + avg_rtt); |
| 677 if (bytes_sent < 0) { | 675 if (bytes_sent < 0) { |
| 678 // Failed to send one Sequence number. Give up the rest in this nack. | 676 // Failed to send one Sequence number. Give up the rest in this nack. |
| 679 LOG(LS_WARNING) << "Failed resending RTP packet " << seq_no | 677 LOG(LS_WARNING) << "Failed resending RTP packet " << seq_no |
| 680 << ", Discard rest of packets."; | 678 << ", Discard rest of packets"; |
| 681 break; | 679 break; |
| 682 } | 680 } |
| 683 } | 681 } |
| 684 } | 682 } |
| 685 | 683 |
| 686 void RTPSender::OnReceivedRtcpReportBlocks( | 684 void RTPSender::OnReceivedRtcpReportBlocks( |
| 687 const ReportBlockList& report_blocks) { | 685 const ReportBlockList& report_blocks) { |
| 688 playout_delay_oracle_.OnReceivedRtcpReportBlocks(report_blocks); | 686 playout_delay_oracle_.OnReceivedRtcpReportBlocks(report_blocks); |
| 689 } | 687 } |
| 690 | 688 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 | 912 |
| 915 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { | 913 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { |
| 916 if (!send_side_delay_observer_ || capture_time_ms <= 0) | 914 if (!send_side_delay_observer_ || capture_time_ms <= 0) |
| 917 return; | 915 return; |
| 918 | 916 |
| 919 uint32_t ssrc; | 917 uint32_t ssrc; |
| 920 int avg_delay_ms = 0; | 918 int avg_delay_ms = 0; |
| 921 int max_delay_ms = 0; | 919 int max_delay_ms = 0; |
| 922 { | 920 { |
| 923 rtc::CritScope lock(&send_critsect_); | 921 rtc::CritScope lock(&send_critsect_); |
| 924 if (!ssrc_) | 922 ssrc = ssrc_; |
| 925 return; | |
| 926 ssrc = *ssrc_; | |
| 927 } | 923 } |
| 928 { | 924 { |
| 929 rtc::CritScope cs(&statistics_crit_); | 925 rtc::CritScope cs(&statistics_crit_); |
| 930 // TODO(holmer): Compute this iteratively instead. | 926 // TODO(holmer): Compute this iteratively instead. |
| 931 send_delays_[now_ms] = now_ms - capture_time_ms; | 927 send_delays_[now_ms] = now_ms - capture_time_ms; |
| 932 send_delays_.erase(send_delays_.begin(), | 928 send_delays_.erase(send_delays_.begin(), |
| 933 send_delays_.lower_bound(now_ms - | 929 send_delays_.lower_bound(now_ms - |
| 934 kSendSideDelayWindowMs)); | 930 kSendSideDelayWindowMs)); |
| 935 int num_delays = 0; | 931 int num_delays = 0; |
| 936 for (auto it = send_delays_.upper_bound(now_ms - kSendSideDelayWindowMs); | 932 for (auto it = send_delays_.upper_bound(now_ms - kSendSideDelayWindowMs); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 956 send_packet_observer_->OnSendPacket(packet_id, capture_time_ms, ssrc); | 952 send_packet_observer_->OnSendPacket(packet_id, capture_time_ms, ssrc); |
| 957 } | 953 } |
| 958 | 954 |
| 959 void RTPSender::ProcessBitrate() { | 955 void RTPSender::ProcessBitrate() { |
| 960 if (!bitrate_callback_) | 956 if (!bitrate_callback_) |
| 961 return; | 957 return; |
| 962 int64_t now_ms = clock_->TimeInMilliseconds(); | 958 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 963 uint32_t ssrc; | 959 uint32_t ssrc; |
| 964 { | 960 { |
| 965 rtc::CritScope lock(&send_critsect_); | 961 rtc::CritScope lock(&send_critsect_); |
| 966 if (!ssrc_) | 962 ssrc = ssrc_; |
| 967 return; | |
| 968 ssrc = *ssrc_; | |
| 969 } | 963 } |
| 970 | 964 |
| 971 rtc::CritScope lock(&statistics_crit_); | 965 rtc::CritScope lock(&statistics_crit_); |
| 972 bitrate_callback_->Notify(total_bitrate_sent_.Rate(now_ms).value_or(0), | 966 bitrate_callback_->Notify(total_bitrate_sent_.Rate(now_ms).value_or(0), |
| 973 nack_bitrate_sent_.Rate(now_ms).value_or(0), ssrc); | 967 nack_bitrate_sent_.Rate(now_ms).value_or(0), ssrc); |
| 974 } | 968 } |
| 975 | 969 |
| 976 size_t RTPSender::RtpHeaderLength() const { | 970 size_t RTPSender::RtpHeaderLength() const { |
| 977 rtc::CritScope lock(&send_critsect_); | 971 rtc::CritScope lock(&send_critsect_); |
| 978 size_t rtp_header_length = kRtpHeaderLength; | 972 size_t rtp_header_length = kRtpHeaderLength; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 992 StreamDataCounters* rtx_stats) const { | 986 StreamDataCounters* rtx_stats) const { |
| 993 rtc::CritScope lock(&statistics_crit_); | 987 rtc::CritScope lock(&statistics_crit_); |
| 994 *rtp_stats = rtp_stats_; | 988 *rtp_stats = rtp_stats_; |
| 995 *rtx_stats = rtx_rtp_stats_; | 989 *rtx_stats = rtx_rtp_stats_; |
| 996 } | 990 } |
| 997 | 991 |
| 998 std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const { | 992 std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const { |
| 999 rtc::CritScope lock(&send_critsect_); | 993 rtc::CritScope lock(&send_critsect_); |
| 1000 std::unique_ptr<RtpPacketToSend> packet( | 994 std::unique_ptr<RtpPacketToSend> packet( |
| 1001 new RtpPacketToSend(&rtp_header_extension_map_, max_packet_size_)); | 995 new RtpPacketToSend(&rtp_header_extension_map_, max_packet_size_)); |
| 1002 RTC_DCHECK(ssrc_); | 996 packet->SetSsrc(ssrc_); |
| 1003 packet->SetSsrc(*ssrc_); | |
| 1004 packet->SetCsrcs(csrcs_); | 997 packet->SetCsrcs(csrcs_); |
| 1005 // Reserve extensions, if registered, RtpSender set in SendToNetwork. | 998 // Reserve extensions, if registered, RtpSender set in SendToNetwork. |
| 1006 packet->ReserveExtension<AbsoluteSendTime>(); | 999 packet->ReserveExtension<AbsoluteSendTime>(); |
| 1007 packet->ReserveExtension<TransmissionOffset>(); | 1000 packet->ReserveExtension<TransmissionOffset>(); |
| 1008 packet->ReserveExtension<TransportSequenceNumber>(); | 1001 packet->ReserveExtension<TransportSequenceNumber>(); |
| 1009 if (playout_delay_oracle_.send_playout_delay()) { | 1002 if (playout_delay_oracle_.send_playout_delay()) { |
| 1010 packet->SetExtension<PlayoutDelayLimits>( | 1003 packet->SetExtension<PlayoutDelayLimits>( |
| 1011 playout_delay_oracle_.playout_delay()); | 1004 playout_delay_oracle_.playout_delay()); |
| 1012 } | 1005 } |
| 1013 return packet; | 1006 return packet; |
| 1014 } | 1007 } |
| 1015 | 1008 |
| 1016 bool RTPSender::AssignSequenceNumber(RtpPacketToSend* packet) { | 1009 bool RTPSender::AssignSequenceNumber(RtpPacketToSend* packet) { |
| 1017 rtc::CritScope lock(&send_critsect_); | 1010 rtc::CritScope lock(&send_critsect_); |
| 1018 if (!sending_media_) | 1011 if (!sending_media_) |
| 1019 return false; | 1012 return false; |
| 1020 RTC_DCHECK(packet->Ssrc() == ssrc_); | 1013 RTC_DCHECK_EQ(packet->Ssrc(), ssrc_); |
| 1021 packet->SetSequenceNumber(sequence_number_++); | 1014 packet->SetSequenceNumber(sequence_number_++); |
| 1022 | 1015 |
| 1023 // Remember marker bit to determine if padding can be inserted with | 1016 // Remember marker bit to determine if padding can be inserted with |
| 1024 // sequence number following |packet|. | 1017 // sequence number following |packet|. |
| 1025 last_packet_marker_bit_ = packet->Marker(); | 1018 last_packet_marker_bit_ = packet->Marker(); |
| 1026 // Save timestamps to generate timestamp field and extensions for the padding. | 1019 // Save timestamps to generate timestamp field and extensions for the padding. |
| 1027 last_rtp_timestamp_ = packet->Timestamp(); | 1020 last_rtp_timestamp_ = packet->Timestamp(); |
| 1028 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); | 1021 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); |
| 1029 capture_time_ms_ = packet->capture_time_ms(); | 1022 capture_time_ms_ = packet->capture_time_ms(); |
| 1030 return true; | 1023 return true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1042 return false; | 1035 return false; |
| 1043 | 1036 |
| 1044 *packet_id = transport_sequence_number_allocator_->AllocateSequenceNumber(); | 1037 *packet_id = transport_sequence_number_allocator_->AllocateSequenceNumber(); |
| 1045 | 1038 |
| 1046 if (!packet->SetExtension<TransportSequenceNumber>(*packet_id)) | 1039 if (!packet->SetExtension<TransportSequenceNumber>(*packet_id)) |
| 1047 return false; | 1040 return false; |
| 1048 | 1041 |
| 1049 return true; | 1042 return true; |
| 1050 } | 1043 } |
| 1051 | 1044 |
| 1045 void RTPSender::SetSendingStatus(bool enabled) { |
| 1046 if (!enabled) { |
| 1047 rtc::CritScope lock(&send_critsect_); |
| 1048 if (!ssrc_forced_) { |
| 1049 // Generate a new SSRC. |
| 1050 ssrc_db_->ReturnSSRC(ssrc_); |
| 1051 ssrc_ = ssrc_db_->CreateSSRC(); |
| 1052 RTC_DCHECK(ssrc_ != 0); |
| 1053 } |
| 1054 // Don't initialize seq number if SSRC passed externally. |
| 1055 if (!sequence_number_forced_ && !ssrc_forced_) { |
| 1056 // Generate a new sequence number. |
| 1057 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 1058 } |
| 1059 } |
| 1060 } |
| 1061 |
| 1052 void RTPSender::SetSendingMediaStatus(bool enabled) { | 1062 void RTPSender::SetSendingMediaStatus(bool enabled) { |
| 1053 rtc::CritScope lock(&send_critsect_); | 1063 rtc::CritScope lock(&send_critsect_); |
| 1054 sending_media_ = enabled; | 1064 sending_media_ = enabled; |
| 1055 } | 1065 } |
| 1056 | 1066 |
| 1057 bool RTPSender::SendingMedia() const { | 1067 bool RTPSender::SendingMedia() const { |
| 1058 rtc::CritScope lock(&send_critsect_); | 1068 rtc::CritScope lock(&send_critsect_); |
| 1059 return sending_media_; | 1069 return sending_media_; |
| 1060 } | 1070 } |
| 1061 | 1071 |
| 1062 void RTPSender::SetTimestampOffset(uint32_t timestamp) { | 1072 void RTPSender::SetTimestampOffset(uint32_t timestamp) { |
| 1063 rtc::CritScope lock(&send_critsect_); | 1073 rtc::CritScope lock(&send_critsect_); |
| 1064 timestamp_offset_ = timestamp; | 1074 timestamp_offset_ = timestamp; |
| 1065 } | 1075 } |
| 1066 | 1076 |
| 1067 uint32_t RTPSender::TimestampOffset() const { | 1077 uint32_t RTPSender::TimestampOffset() const { |
| 1068 rtc::CritScope lock(&send_critsect_); | 1078 rtc::CritScope lock(&send_critsect_); |
| 1069 return timestamp_offset_; | 1079 return timestamp_offset_; |
| 1070 } | 1080 } |
| 1071 | 1081 |
| 1082 uint32_t RTPSender::GenerateNewSSRC() { |
| 1083 // If configured via API, return 0. |
| 1084 rtc::CritScope lock(&send_critsect_); |
| 1085 |
| 1086 if (ssrc_forced_) { |
| 1087 return 0; |
| 1088 } |
| 1089 ssrc_ = ssrc_db_->CreateSSRC(); |
| 1090 RTC_DCHECK(ssrc_ != 0); |
| 1091 return ssrc_; |
| 1092 } |
| 1093 |
| 1072 void RTPSender::SetSSRC(uint32_t ssrc) { | 1094 void RTPSender::SetSSRC(uint32_t ssrc) { |
| 1073 // This is configured via the API. | 1095 // This is configured via the API. |
| 1074 rtc::CritScope lock(&send_critsect_); | 1096 rtc::CritScope lock(&send_critsect_); |
| 1075 | 1097 |
| 1076 if (ssrc_ == ssrc) { | 1098 if (ssrc_ == ssrc && ssrc_forced_) { |
| 1077 return; // Since it's same ssrc, don't reset anything. | 1099 return; // Since it's same ssrc, don't reset anything. |
| 1078 } | 1100 } |
| 1079 ssrc_.emplace(ssrc); | 1101 ssrc_forced_ = true; |
| 1102 ssrc_db_->ReturnSSRC(ssrc_); |
| 1103 ssrc_db_->RegisterSSRC(ssrc); |
| 1104 ssrc_ = ssrc; |
| 1080 if (!sequence_number_forced_) { | 1105 if (!sequence_number_forced_) { |
| 1081 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 1106 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
| 1082 } | 1107 } |
| 1083 } | 1108 } |
| 1084 | 1109 |
| 1085 uint32_t RTPSender::SSRC() const { | 1110 uint32_t RTPSender::SSRC() const { |
| 1086 rtc::CritScope lock(&send_critsect_); | 1111 rtc::CritScope lock(&send_critsect_); |
| 1087 RTC_DCHECK(ssrc_); | 1112 return ssrc_; |
| 1088 return *ssrc_; | |
| 1089 } | 1113 } |
| 1090 | 1114 |
| 1091 rtc::Optional<uint32_t> RTPSender::FlexfecSsrc() const { | 1115 rtc::Optional<uint32_t> RTPSender::FlexfecSsrc() const { |
| 1092 if (video_) { | 1116 if (video_) { |
| 1093 return video_->FlexfecSsrc(); | 1117 return video_->FlexfecSsrc(); |
| 1094 } | 1118 } |
| 1095 return rtc::Optional<uint32_t>(); | 1119 return rtc::Optional<uint32_t>(); |
| 1096 } | 1120 } |
| 1097 | 1121 |
| 1098 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 1122 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 // when transport interface would be updated to take buffer class. | 1182 // when transport interface would be updated to take buffer class. |
| 1159 std::unique_ptr<RtpPacketToSend> rtx_packet(new RtpPacketToSend( | 1183 std::unique_ptr<RtpPacketToSend> rtx_packet(new RtpPacketToSend( |
| 1160 &rtp_header_extension_map_, packet.size() + kRtxHeaderSize)); | 1184 &rtp_header_extension_map_, packet.size() + kRtxHeaderSize)); |
| 1161 // Add original RTP header. | 1185 // Add original RTP header. |
| 1162 rtx_packet->CopyHeaderFrom(packet); | 1186 rtx_packet->CopyHeaderFrom(packet); |
| 1163 { | 1187 { |
| 1164 rtc::CritScope lock(&send_critsect_); | 1188 rtc::CritScope lock(&send_critsect_); |
| 1165 if (!sending_media_) | 1189 if (!sending_media_) |
| 1166 return nullptr; | 1190 return nullptr; |
| 1167 | 1191 |
| 1168 RTC_DCHECK(ssrc_rtx_); | |
| 1169 | |
| 1170 // Replace payload type. | 1192 // Replace payload type. |
| 1171 auto kv = rtx_payload_type_map_.find(packet.PayloadType()); | 1193 auto kv = rtx_payload_type_map_.find(packet.PayloadType()); |
| 1172 if (kv == rtx_payload_type_map_.end()) | 1194 if (kv == rtx_payload_type_map_.end()) |
| 1173 return nullptr; | 1195 return nullptr; |
| 1174 rtx_packet->SetPayloadType(kv->second); | 1196 rtx_packet->SetPayloadType(kv->second); |
| 1175 | 1197 |
| 1176 // Replace sequence number. | 1198 // Replace sequence number. |
| 1177 rtx_packet->SetSequenceNumber(sequence_number_rtx_++); | 1199 rtx_packet->SetSequenceNumber(sequence_number_rtx_++); |
| 1178 | 1200 |
| 1179 // Replace SSRC. | 1201 // Replace SSRC. |
| 1180 rtx_packet->SetSsrc(*ssrc_rtx_); | 1202 rtx_packet->SetSsrc(ssrc_rtx_); |
| 1181 } | 1203 } |
| 1182 | 1204 |
| 1183 uint8_t* rtx_payload = | 1205 uint8_t* rtx_payload = |
| 1184 rtx_packet->AllocatePayload(packet.payload_size() + kRtxHeaderSize); | 1206 rtx_packet->AllocatePayload(packet.payload_size() + kRtxHeaderSize); |
| 1185 RTC_DCHECK(rtx_payload); | 1207 RTC_DCHECK(rtx_payload); |
| 1186 // Add OSN (original sequence number). | 1208 // Add OSN (original sequence number). |
| 1187 ByteWriter<uint16_t>::WriteBigEndian(rtx_payload, packet.SequenceNumber()); | 1209 ByteWriter<uint16_t>::WriteBigEndian(rtx_payload, packet.SequenceNumber()); |
| 1188 | 1210 |
| 1189 // Add original payload data. | 1211 // Add original payload data. |
| 1190 auto payload = packet.payload(); | 1212 auto payload = packet.payload(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { | 1294 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { |
| 1273 return; | 1295 return; |
| 1274 } | 1296 } |
| 1275 rtp_overhead_bytes_per_packet_ = packet.headers_size(); | 1297 rtp_overhead_bytes_per_packet_ = packet.headers_size(); |
| 1276 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; | 1298 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; |
| 1277 } | 1299 } |
| 1278 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); | 1300 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); |
| 1279 } | 1301 } |
| 1280 | 1302 |
| 1281 } // namespace webrtc | 1303 } // namespace webrtc |
| OLD | NEW |