Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender.cc

Issue 2867713003: Remove hardcoded kValueSizeBytes values from variable-length header extensions. (Closed)
Patch Set: Patch 4 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
38 constexpr size_t kMaxPaddingLength = 224; 38 constexpr size_t kMaxPaddingLength = 224;
39 constexpr size_t kMinAudioPaddingLength = 50; 39 constexpr size_t kMinAudioPaddingLength = 50;
40 constexpr int kSendSideDelayWindowMs = 1000; 40 constexpr int kSendSideDelayWindowMs = 1000;
41 constexpr size_t kRtpHeaderLength = 12; 41 constexpr size_t kRtpHeaderLength = 12;
42 constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1. 42 constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1.
43 constexpr uint32_t kTimestampTicksPerMs = 90; 43 constexpr uint32_t kTimestampTicksPerMs = 90;
44 constexpr int kBitrateStatisticsWindowMs = 1000; 44 constexpr int kBitrateStatisticsWindowMs = 1000;
45 45
46 constexpr size_t kMinFlexfecPacketsToStoreForPacing = 50; 46 constexpr size_t kMinFlexfecPacketsToStoreForPacing = 50;
47 47
48 template <typename Extension>
49 constexpr RtpExtensionSize CreateExtensionSize() {
50 return {Extension::kId, Extension::kValueSizeBytes};
51 }
52
53 // Size info for header extensions that might be used in padding or FEC packets.
54 constexpr RtpExtensionSize kExtensionSizes[] = {
55 CreateExtensionSize<AbsoluteSendTime>(),
56 CreateExtensionSize<TransmissionOffset>(),
57 CreateExtensionSize<TransportSequenceNumber>(),
58 CreateExtensionSize<PlayoutDelayLimits>(),
59 };
60
48 const char* FrameTypeToString(FrameType frame_type) { 61 const char* FrameTypeToString(FrameType frame_type) {
49 switch (frame_type) { 62 switch (frame_type) {
50 case kEmptyFrame: 63 case kEmptyFrame:
51 return "empty"; 64 return "empty";
52 case kAudioFrameSpeech: return "audio_speech"; 65 case kAudioFrameSpeech: return "audio_speech";
53 case kAudioFrameCN: return "audio_cn"; 66 case kAudioFrameCN: return "audio_cn";
54 case kVideoFrameKey: return "video_key"; 67 case kVideoFrameKey: return "video_key";
55 case kVideoFrameDelta: return "video_delta"; 68 case kVideoFrameDelta: return "video_delta";
56 } 69 }
57 return ""; 70 return "";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Start documenting what thread we're on in what method so that it's easier 163 // Start documenting what thread we're on in what method so that it's easier
151 // to understand performance attributes and possibly remove locks. 164 // to understand performance attributes and possibly remove locks.
152 while (!payload_type_map_.empty()) { 165 while (!payload_type_map_.empty()) {
153 std::map<int8_t, RtpUtility::Payload*>::iterator it = 166 std::map<int8_t, RtpUtility::Payload*>::iterator it =
154 payload_type_map_.begin(); 167 payload_type_map_.begin();
155 delete it->second; 168 delete it->second;
156 payload_type_map_.erase(it); 169 payload_type_map_.erase(it);
157 } 170 }
158 } 171 }
159 172
173 rtc::ArrayView<const RtpExtensionSize> RTPSender::FecExtensionSizes() {
174 return rtc::ArrayView<const RtpExtensionSize>(kExtensionSizes,
175 sizeof(kExtensionSizes));
danilchap 2017/05/10 13:27:13 sizeof would return size in bytes, but array view
erikvarga1 2017/05/10 15:39:31 Oh right, my bad. Fixed now. I've added a test to
176 }
177
160 uint16_t RTPSender::ActualSendBitrateKbit() const { 178 uint16_t RTPSender::ActualSendBitrateKbit() const {
161 rtc::CritScope cs(&statistics_crit_); 179 rtc::CritScope cs(&statistics_crit_);
162 return static_cast<uint16_t>( 180 return static_cast<uint16_t>(
163 total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0) / 181 total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0) /
164 1000); 182 1000);
165 } 183 }
166 184
167 uint32_t RTPSender::VideoBitrateSent() const { 185 uint32_t RTPSender::VideoBitrateSent() const {
168 if (video_) { 186 if (video_) {
169 return video_->VideoBitrateSent(); 187 return video_->VideoBitrateSent();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 288 }
271 289
272 void RTPSender::SetMaxRtpPacketSize(size_t max_packet_size) { 290 void RTPSender::SetMaxRtpPacketSize(size_t max_packet_size) {
273 // Sanity check. 291 // Sanity check.
274 RTC_DCHECK(max_packet_size >= 100 && max_packet_size <= IP_PACKET_SIZE) 292 RTC_DCHECK(max_packet_size >= 100 && max_packet_size <= IP_PACKET_SIZE)
275 << "Invalid max payload length: " << max_packet_size; 293 << "Invalid max payload length: " << max_packet_size;
276 rtc::CritScope lock(&send_critsect_); 294 rtc::CritScope lock(&send_critsect_);
277 max_packet_size_ = max_packet_size; 295 max_packet_size_ = max_packet_size;
278 } 296 }
279 297
280 size_t RTPSender::MaxPayloadSize() const {
281 if (audio_configured_) {
282 return max_packet_size_ - RtpHeaderLength();
283 } else {
284 return max_packet_size_ - RtpHeaderLength() // RTP overhead.
285 - video_->FecPacketOverhead() // FEC/ULP/RED overhead.
286 - (RtxStatus() ? kRtxHeaderSize : 0); // RTX overhead.
287 }
288 }
289
290 size_t RTPSender::MaxRtpPacketSize() const { 298 size_t RTPSender::MaxRtpPacketSize() const {
291 return max_packet_size_; 299 return max_packet_size_;
292 } 300 }
293 301
294 void RTPSender::SetRtxStatus(int mode) { 302 void RTPSender::SetRtxStatus(int mode) {
295 rtc::CritScope lock(&send_critsect_); 303 rtc::CritScope lock(&send_critsect_);
296 rtx_ = mode; 304 rtx_ = mode;
297 } 305 }
298 306
299 int RTPSender::RtxStatus() const { 307 int RTPSender::RtxStatus() const {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info)) 457 if (!PrepareAndSendPacket(std::move(packet), true, false, pacing_info))
450 break; 458 break;
451 bytes_left -= payload_size; 459 bytes_left -= payload_size;
452 } 460 }
453 return bytes_to_send - bytes_left; 461 return bytes_to_send - bytes_left;
454 } 462 }
455 463
456 size_t RTPSender::SendPadData(size_t bytes, 464 size_t RTPSender::SendPadData(size_t bytes,
457 const PacedPacketInfo& pacing_info) { 465 const PacedPacketInfo& pacing_info) {
458 size_t padding_bytes_in_packet; 466 size_t padding_bytes_in_packet;
467
459 if (audio_configured_) { 468 if (audio_configured_) {
460 // Allow smaller padding packets for audio. 469 // Allow smaller padding packets for audio.
470 size_t max_payload_size = max_packet_size_ - RtpHeaderLength();
461 padding_bytes_in_packet = 471 padding_bytes_in_packet =
462 std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); 472 std::min(std::max(bytes, kMinAudioPaddingLength), max_payload_size);
463 if (padding_bytes_in_packet > kMaxPaddingLength) 473 if (padding_bytes_in_packet > kMaxPaddingLength)
464 padding_bytes_in_packet = kMaxPaddingLength; 474 padding_bytes_in_packet = kMaxPaddingLength;
465 } else { 475 } else {
466 // Always send full padding packets. This is accounted for by the 476 // Always send full padding packets. This is accounted for by the
467 // RtpPacketSender, which will make sure we don't send too much padding even 477 // RtpPacketSender, which will make sure we don't send too much padding even
468 // if a single packet is larger than requested. 478 // if a single packet is larger than requested.
469 // We do this to avoid frequently sending small packets on higher bitrates. 479 // We do this to avoid frequently sending small packets on higher bitrates.
470 padding_bytes_in_packet = std::min(MaxPayloadSize(), kMaxPaddingLength); 480 size_t max_payload_size =
481 max_packet_size_ - RtpHeaderLength() // RTP overhead.
482 - video_->FecPacketOverhead() // FEC/ULP/RED overhead.
483 - (RtxStatus() ? kRtxHeaderSize : 0); // RTX overhead.
484 padding_bytes_in_packet = std::min(max_payload_size, kMaxPaddingLength);
471 } 485 }
472 size_t bytes_sent = 0; 486 size_t bytes_sent = 0;
473 while (bytes_sent < bytes) { 487 while (bytes_sent < bytes) {
474 int64_t now_ms = clock_->TimeInMilliseconds(); 488 int64_t now_ms = clock_->TimeInMilliseconds();
475 uint32_t ssrc; 489 uint32_t ssrc;
476 uint32_t timestamp; 490 uint32_t timestamp;
477 int64_t capture_time_ms; 491 int64_t capture_time_ms;
478 uint16_t sequence_number; 492 uint16_t sequence_number;
479 int payload_type; 493 int payload_type;
480 bool over_rtx; 494 bool over_rtx;
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 968
955 rtc::CritScope lock(&statistics_crit_); 969 rtc::CritScope lock(&statistics_crit_);
956 bitrate_callback_->Notify(total_bitrate_sent_.Rate(now_ms).value_or(0), 970 bitrate_callback_->Notify(total_bitrate_sent_.Rate(now_ms).value_or(0),
957 nack_bitrate_sent_.Rate(now_ms).value_or(0), ssrc); 971 nack_bitrate_sent_.Rate(now_ms).value_or(0), ssrc);
958 } 972 }
959 973
960 size_t RTPSender::RtpHeaderLength() const { 974 size_t RTPSender::RtpHeaderLength() const {
961 rtc::CritScope lock(&send_critsect_); 975 rtc::CritScope lock(&send_critsect_);
962 size_t rtp_header_length = kRtpHeaderLength; 976 size_t rtp_header_length = kRtpHeaderLength;
963 rtp_header_length += sizeof(uint32_t) * csrcs_.size(); 977 rtp_header_length += sizeof(uint32_t) * csrcs_.size();
964 rtp_header_length += rtp_header_extension_map_.GetTotalLengthInBytes(); 978 rtp_header_length +=
979 rtp_header_extension_map_.GetTotalLengthInBytes(kExtensionSizes);
965 return rtp_header_length; 980 return rtp_header_length;
966 } 981 }
967 982
968 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { 983 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
969 rtc::CritScope lock(&send_critsect_); 984 rtc::CritScope lock(&send_critsect_);
970 uint16_t first_allocated_sequence_number = sequence_number_; 985 uint16_t first_allocated_sequence_number = sequence_number_;
971 sequence_number_ += packets_to_send; 986 sequence_number_ += packets_to_send;
972 return first_allocated_sequence_number; 987 return first_allocated_sequence_number;
973 } 988 }
974 989
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { 1272 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) {
1258 return; 1273 return;
1259 } 1274 }
1260 rtp_overhead_bytes_per_packet_ = packet.headers_size(); 1275 rtp_overhead_bytes_per_packet_ = packet.headers_size();
1261 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; 1276 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_;
1262 } 1277 }
1263 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); 1278 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet);
1264 } 1279 }
1265 1280
1266 } // namespace webrtc 1281 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698