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 18 matching lines...) Expand all Loading... | |
| 29 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_audio.h" |
| 30 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" |
| 31 #include "webrtc/modules/rtp_rtcp/source/time_util.h" | 31 #include "webrtc/modules/rtp_rtcp/source/time_util.h" |
| 32 #include "webrtc/system_wrappers/include/field_trial.h" | 32 #include "webrtc/system_wrappers/include/field_trial.h" |
| 33 | 33 |
| 34 namespace webrtc { | 34 namespace webrtc { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. | 37 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. |
| 38 constexpr size_t kMaxPaddingLength = 224; | 38 constexpr size_t kMaxPaddingLength = 224; |
| 39 constexpr size_t kMinAudioPaddingLength = 50; | |
| 39 constexpr int kSendSideDelayWindowMs = 1000; | 40 constexpr int kSendSideDelayWindowMs = 1000; |
| 40 constexpr size_t kRtpHeaderLength = 12; | 41 constexpr size_t kRtpHeaderLength = 12; |
| 41 constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1. | 42 constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1. |
| 42 constexpr uint32_t kTimestampTicksPerMs = 90; | 43 constexpr uint32_t kTimestampTicksPerMs = 90; |
| 43 constexpr int kBitrateStatisticsWindowMs = 1000; | 44 constexpr int kBitrateStatisticsWindowMs = 1000; |
| 44 | 45 |
| 45 constexpr size_t kMinFlexfecPacketsToStoreForPacing = 50; | 46 constexpr size_t kMinFlexfecPacketsToStoreForPacing = 50; |
| 46 | 47 |
| 47 const char* FrameTypeToString(FrameType frame_type) { | 48 const char* FrameTypeToString(FrameType frame_type) { |
| 48 switch (frame_type) { | 49 switch (frame_type) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 case kRtpExtensionTransportSequenceNumber: | 209 case kRtpExtensionTransportSequenceNumber: |
| 209 return rtp_header_extension_map_.Register(type, id); | 210 return rtp_header_extension_map_.Register(type, id); |
| 210 case kRtpExtensionNone: | 211 case kRtpExtensionNone: |
| 211 case kRtpExtensionNumberOfExtensions: | 212 case kRtpExtensionNumberOfExtensions: |
| 212 LOG(LS_ERROR) << "Invalid RTP extension type for registration"; | 213 LOG(LS_ERROR) << "Invalid RTP extension type for registration"; |
| 213 return -1; | 214 return -1; |
| 214 } | 215 } |
| 215 return -1; | 216 return -1; |
| 216 } | 217 } |
| 217 | 218 |
| 218 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) { | 219 bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) const { |
| 219 rtc::CritScope lock(&send_critsect_); | 220 rtc::CritScope lock(&send_critsect_); |
| 220 return rtp_header_extension_map_.IsRegistered(type); | 221 return rtp_header_extension_map_.IsRegistered(type); |
| 221 } | 222 } |
| 222 | 223 |
| 223 int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { | 224 int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { |
| 224 rtc::CritScope lock(&send_critsect_); | 225 rtc::CritScope lock(&send_critsect_); |
| 225 return rtp_header_extension_map_.Deregister(type); | 226 return rtp_header_extension_map_.Deregister(type); |
| 226 } | 227 } |
| 227 | 228 |
| 228 int32_t RTPSender::RegisterPayload( | 229 int32_t RTPSender::RegisterPayload( |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 break; | 475 break; |
| 475 size_t payload_size = packet->payload_size(); | 476 size_t payload_size = packet->payload_size(); |
| 476 if (!PrepareAndSendPacket(std::move(packet), true, false, probe_cluster_id)) | 477 if (!PrepareAndSendPacket(std::move(packet), true, false, probe_cluster_id)) |
| 477 break; | 478 break; |
| 478 bytes_left -= payload_size; | 479 bytes_left -= payload_size; |
| 479 } | 480 } |
| 480 return bytes_to_send - bytes_left; | 481 return bytes_to_send - bytes_left; |
| 481 } | 482 } |
| 482 | 483 |
| 483 size_t RTPSender::SendPadData(size_t bytes, int probe_cluster_id) { | 484 size_t RTPSender::SendPadData(size_t bytes, int probe_cluster_id) { |
| 484 // Always send full padding packets. This is accounted for by the | 485 size_t padding_bytes_in_packet; |
| 485 // RtpPacketSender, which will make sure we don't send too much padding even | 486 if (audio_configured_) { |
| 486 // if a single packet is larger than requested. | 487 // Allow smaller padding packets for audio. |
| 487 size_t padding_bytes_in_packet = | 488 padding_bytes_in_packet = |
| 488 std::min(MaxPayloadSize(), kMaxPaddingLength); | 489 std::max(std::min(bytes, MaxPayloadSize()), kMinAudioPaddingLength); |
|
terelius
2017/02/03 14:26:14
Note this order of operation allows sending paddin
stefan-webrtc
2017/02/03 14:39:25
Thanks, that's not the intent.
| |
| 490 if (padding_bytes_in_packet > kMaxPaddingLength) | |
| 491 padding_bytes_in_packet = kMaxPaddingLength; | |
| 492 } else { | |
| 493 // Always send full padding packets. This is accounted for by the | |
| 494 // RtpPacketSender, which will make sure we don't send too much padding even | |
| 495 // if a single packet is larger than requested. | |
| 496 // We do this to avoid frequently sending small packets on higher bitrates. | |
| 497 padding_bytes_in_packet = std::min(MaxPayloadSize(), kMaxPaddingLength); | |
| 498 } | |
| 489 size_t bytes_sent = 0; | 499 size_t bytes_sent = 0; |
| 490 while (bytes_sent < bytes) { | 500 while (bytes_sent < bytes) { |
| 491 int64_t now_ms = clock_->TimeInMilliseconds(); | 501 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 492 uint32_t ssrc; | 502 uint32_t ssrc; |
| 493 uint32_t timestamp; | 503 uint32_t timestamp; |
| 494 int64_t capture_time_ms; | 504 int64_t capture_time_ms; |
| 495 uint16_t sequence_number; | 505 uint16_t sequence_number; |
| 496 int payload_type; | 506 int payload_type; |
| 497 bool over_rtx; | 507 bool over_rtx; |
| 498 { | 508 { |
| 499 rtc::CritScope lock(&send_critsect_); | 509 rtc::CritScope lock(&send_critsect_); |
| 500 if (!sending_media_) | 510 if (!sending_media_) |
| 501 break; | 511 break; |
| 502 timestamp = last_rtp_timestamp_; | 512 timestamp = last_rtp_timestamp_; |
| 503 capture_time_ms = capture_time_ms_; | 513 capture_time_ms = capture_time_ms_; |
| 504 if (rtx_ == kRtxOff) { | 514 if (rtx_ == kRtxOff) { |
| 515 if (payload_type_ == -1) | |
| 516 break; | |
| 505 // 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. |
| 506 if (!last_packet_marker_bit_) | 518 // For audio marker bits doesn't mark the end of a frame and frames |
|
terelius
2017/02/03 14:26:14
What does the marker bit mean for audio? Though un
stefan-webrtc
2017/02/03 14:39:25
It has no clear meaning, but one possible interpre
terelius
2017/02/03 14:42:19
Acknowledged.
| |
| 519 // are usually a single packet, so for now we don't apply this rule | |
| 520 // for audio. | |
| 521 if (!audio_configured_ && !last_packet_marker_bit_) { | |
| 507 break; | 522 break; |
| 523 } | |
| 508 ssrc = ssrc_; | 524 ssrc = ssrc_; |
| 509 sequence_number = sequence_number_; | 525 sequence_number = sequence_number_; |
| 510 ++sequence_number_; | 526 ++sequence_number_; |
| 511 payload_type = payload_type_; | 527 payload_type = payload_type_; |
| 512 over_rtx = false; | 528 over_rtx = false; |
| 513 } else { | 529 } else { |
| 514 // Without abs-send-time or transport sequence number a media packet | 530 // Without abs-send-time or transport sequence number a media packet |
| 515 // must be sent before padding so that the timestamps used for | 531 // must be sent before padding so that the timestamps used for |
| 516 // estimation are correct. | 532 // estimation are correct. |
| 517 if (!media_has_been_sent_ && | 533 if (!media_has_been_sent_ && |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 | 805 |
| 790 // RED+ULPFEC. | 806 // RED+ULPFEC. |
| 791 int pt_red; | 807 int pt_red; |
| 792 int pt_fec; | 808 int pt_fec; |
| 793 video_->GetUlpfecConfig(&pt_red, &pt_fec); | 809 video_->GetUlpfecConfig(&pt_red, &pt_fec); |
| 794 return static_cast<int>(packet.PayloadType()) == pt_red && | 810 return static_cast<int>(packet.PayloadType()) == pt_red && |
| 795 static_cast<int>(packet.payload()[0]) == pt_fec; | 811 static_cast<int>(packet.payload()[0]) == pt_fec; |
| 796 } | 812 } |
| 797 | 813 |
| 798 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) { | 814 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) { |
| 799 if (audio_configured_ || bytes == 0) | 815 if (bytes == 0) |
| 800 return 0; | 816 return 0; |
| 801 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id); | 817 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id); |
| 802 if (bytes_sent < bytes) | 818 if (bytes_sent < bytes) |
| 803 bytes_sent += SendPadData(bytes - bytes_sent, probe_cluster_id); | 819 bytes_sent += SendPadData(bytes - bytes_sent, probe_cluster_id); |
| 804 return bytes_sent; | 820 return bytes_sent; |
| 805 } | 821 } |
| 806 | 822 |
| 807 bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, | 823 bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet, |
| 808 StorageType storage, | 824 StorageType storage, |
| 809 RtpPacketSender::Priority priority) { | 825 RtpPacketSender::Priority priority) { |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1278 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { | 1294 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { |
| 1279 return; | 1295 return; |
| 1280 } | 1296 } |
| 1281 rtp_overhead_bytes_per_packet_ = packet.headers_size(); | 1297 rtp_overhead_bytes_per_packet_ = packet.headers_size(); |
| 1282 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; | 1298 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; |
| 1283 } | 1299 } |
| 1284 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); | 1300 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); |
| 1285 } | 1301 } |
| 1286 | 1302 |
| 1287 } // namespace webrtc | 1303 } // namespace webrtc |
| OLD | NEW |