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

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 1 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 // Size info for header extensions that might be used in padding or FEC packets.
49 constexpr RtpExtensionSize kExtensionSizes[] = {
50 CreateExtensionSize<AbsoluteSendTime>(),
51 CreateExtensionSize<TransmissionOffset>(),
52 CreateExtensionSize<TransportSequenceNumber>(),
53 CreateExtensionSize<PlayoutDelayLimits>(),
54 };
55
48 const char* FrameTypeToString(FrameType frame_type) { 56 const char* FrameTypeToString(FrameType frame_type) {
49 switch (frame_type) { 57 switch (frame_type) {
50 case kEmptyFrame: 58 case kEmptyFrame:
51 return "empty"; 59 return "empty";
52 case kAudioFrameSpeech: return "audio_speech"; 60 case kAudioFrameSpeech: return "audio_speech";
53 case kAudioFrameCN: return "audio_cn"; 61 case kAudioFrameCN: return "audio_cn";
54 case kVideoFrameKey: return "video_key"; 62 case kVideoFrameKey: return "video_key";
55 case kVideoFrameDelta: return "video_delta"; 63 case kVideoFrameDelta: return "video_delta";
56 } 64 }
57 return ""; 65 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 158 // Start documenting what thread we're on in what method so that it's easier
151 // to understand performance attributes and possibly remove locks. 159 // to understand performance attributes and possibly remove locks.
152 while (!payload_type_map_.empty()) { 160 while (!payload_type_map_.empty()) {
153 std::map<int8_t, RtpUtility::Payload*>::iterator it = 161 std::map<int8_t, RtpUtility::Payload*>::iterator it =
154 payload_type_map_.begin(); 162 payload_type_map_.begin();
155 delete it->second; 163 delete it->second;
156 payload_type_map_.erase(it); 164 payload_type_map_.erase(it);
157 } 165 }
158 } 166 }
159 167
168 rtc::ArrayView<const RtpExtensionSize> RTPSender::FecExtensionSizes() {
169 return kExtensionSizes;
170 }
171
160 uint16_t RTPSender::ActualSendBitrateKbit() const { 172 uint16_t RTPSender::ActualSendBitrateKbit() const {
161 rtc::CritScope cs(&statistics_crit_); 173 rtc::CritScope cs(&statistics_crit_);
162 return static_cast<uint16_t>( 174 return static_cast<uint16_t>(
163 total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0) / 175 total_bitrate_sent_.Rate(clock_->TimeInMilliseconds()).value_or(0) /
164 1000); 176 1000);
165 } 177 }
166 178
167 uint32_t RTPSender::VideoBitrateSent() const { 179 uint32_t RTPSender::VideoBitrateSent() const {
168 if (video_) { 180 if (video_) {
169 return video_->VideoBitrateSent(); 181 return video_->VideoBitrateSent();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 282 }
271 283
272 void RTPSender::SetMaxRtpPacketSize(size_t max_packet_size) { 284 void RTPSender::SetMaxRtpPacketSize(size_t max_packet_size) {
273 // Sanity check. 285 // Sanity check.
274 RTC_DCHECK(max_packet_size >= 100 && max_packet_size <= IP_PACKET_SIZE) 286 RTC_DCHECK(max_packet_size >= 100 && max_packet_size <= IP_PACKET_SIZE)
275 << "Invalid max payload length: " << max_packet_size; 287 << "Invalid max payload length: " << max_packet_size;
276 rtc::CritScope lock(&send_critsect_); 288 rtc::CritScope lock(&send_critsect_);
277 max_packet_size_ = max_packet_size; 289 max_packet_size_ = max_packet_size;
278 } 290 }
279 291
280 size_t RTPSender::MaxPayloadSize() const { 292 size_t RTPSender::MaxPayloadSize(
danilchap 2017/05/09 12:33:49 if you agree to remove MaxPayloadSize from rtp_rtc
erikvarga1 2017/05/09 13:30:30 Done.
293 rtc::ArrayView<const RtpExtensionSize> extension_sizes) const {
281 if (audio_configured_) { 294 if (audio_configured_) {
282 return max_packet_size_ - RtpHeaderLength(); 295 return max_packet_size_ - RtpHeaderLength(extension_sizes);
283 } else { 296 } else {
284 return max_packet_size_ - RtpHeaderLength() // RTP overhead. 297 return max_packet_size_ - RtpHeaderLength(extension_sizes) // RTP overhead.
285 - video_->FecPacketOverhead() // FEC/ULP/RED overhead. 298 - video_->FecPacketOverhead() // FEC/ULP/RED overhead.
286 - (RtxStatus() ? kRtxHeaderSize : 0); // RTX overhead. 299 - (RtxStatus() ? kRtxHeaderSize : 0); // RTX overhead.
287 } 300 }
288 } 301 }
289 302
290 size_t RTPSender::MaxRtpPacketSize() const { 303 size_t RTPSender::MaxRtpPacketSize() const {
291 return max_packet_size_; 304 return max_packet_size_;
292 } 305 }
293 306
294 void RTPSender::SetRtxStatus(int mode) { 307 void RTPSender::SetRtxStatus(int mode) {
295 rtc::CritScope lock(&send_critsect_); 308 rtc::CritScope lock(&send_critsect_);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 465 }
453 return bytes_to_send - bytes_left; 466 return bytes_to_send - bytes_left;
454 } 467 }
455 468
456 size_t RTPSender::SendPadData(size_t bytes, 469 size_t RTPSender::SendPadData(size_t bytes,
457 const PacedPacketInfo& pacing_info) { 470 const PacedPacketInfo& pacing_info) {
458 size_t padding_bytes_in_packet; 471 size_t padding_bytes_in_packet;
459 if (audio_configured_) { 472 if (audio_configured_) {
460 // Allow smaller padding packets for audio. 473 // Allow smaller padding packets for audio.
461 padding_bytes_in_packet = 474 padding_bytes_in_packet =
462 std::min(std::max(bytes, kMinAudioPaddingLength), MaxPayloadSize()); 475 std::min(std::max(bytes, kMinAudioPaddingLength),
476 MaxPayloadSize(kExtensionSizes));
463 if (padding_bytes_in_packet > kMaxPaddingLength) 477 if (padding_bytes_in_packet > kMaxPaddingLength)
464 padding_bytes_in_packet = kMaxPaddingLength; 478 padding_bytes_in_packet = kMaxPaddingLength;
465 } else { 479 } else {
466 // Always send full padding packets. This is accounted for by the 480 // 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 481 // RtpPacketSender, which will make sure we don't send too much padding even
468 // if a single packet is larger than requested. 482 // if a single packet is larger than requested.
469 // We do this to avoid frequently sending small packets on higher bitrates. 483 // We do this to avoid frequently sending small packets on higher bitrates.
470 padding_bytes_in_packet = std::min(MaxPayloadSize(), kMaxPaddingLength); 484 padding_bytes_in_packet = std::min(MaxPayloadSize(kExtensionSizes),
485 kMaxPaddingLength);
471 } 486 }
472 size_t bytes_sent = 0; 487 size_t bytes_sent = 0;
473 while (bytes_sent < bytes) { 488 while (bytes_sent < bytes) {
474 int64_t now_ms = clock_->TimeInMilliseconds(); 489 int64_t now_ms = clock_->TimeInMilliseconds();
475 uint32_t ssrc; 490 uint32_t ssrc;
476 uint32_t timestamp; 491 uint32_t timestamp;
477 int64_t capture_time_ms; 492 int64_t capture_time_ms;
478 uint16_t sequence_number; 493 uint16_t sequence_number;
479 int payload_type; 494 int payload_type;
480 bool over_rtx; 495 bool over_rtx;
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 if (!ssrc_) 965 if (!ssrc_)
951 return; 966 return;
952 ssrc = *ssrc_; 967 ssrc = *ssrc_;
953 } 968 }
954 969
955 rtc::CritScope lock(&statistics_crit_); 970 rtc::CritScope lock(&statistics_crit_);
956 bitrate_callback_->Notify(total_bitrate_sent_.Rate(now_ms).value_or(0), 971 bitrate_callback_->Notify(total_bitrate_sent_.Rate(now_ms).value_or(0),
957 nack_bitrate_sent_.Rate(now_ms).value_or(0), ssrc); 972 nack_bitrate_sent_.Rate(now_ms).value_or(0), ssrc);
958 } 973 }
959 974
960 size_t RTPSender::RtpHeaderLength() const { 975 size_t RTPSender::RtpHeaderLength(
976 rtc::ArrayView<const RtpExtensionSize> extension_sizes) const {
961 rtc::CritScope lock(&send_critsect_); 977 rtc::CritScope lock(&send_critsect_);
962 size_t rtp_header_length = kRtpHeaderLength; 978 size_t rtp_header_length = kRtpHeaderLength;
963 rtp_header_length += sizeof(uint32_t) * csrcs_.size(); 979 rtp_header_length += sizeof(uint32_t) * csrcs_.size();
964 rtp_header_length += rtp_header_extension_map_.GetTotalLengthInBytes(); 980 rtp_header_length +=
981 rtp_header_extension_map_.GetTotalLengthInBytes(extension_sizes);
965 return rtp_header_length; 982 return rtp_header_length;
966 } 983 }
967 984
968 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) { 985 uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
969 rtc::CritScope lock(&send_critsect_); 986 rtc::CritScope lock(&send_critsect_);
970 uint16_t first_allocated_sequence_number = sequence_number_; 987 uint16_t first_allocated_sequence_number = sequence_number_;
971 sequence_number_ += packets_to_send; 988 sequence_number_ += packets_to_send;
972 return first_allocated_sequence_number; 989 return first_allocated_sequence_number;
973 } 990 }
974 991
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) { 1274 if (rtp_overhead_bytes_per_packet_ == packet.headers_size()) {
1258 return; 1275 return;
1259 } 1276 }
1260 rtp_overhead_bytes_per_packet_ = packet.headers_size(); 1277 rtp_overhead_bytes_per_packet_ = packet.headers_size();
1261 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_; 1278 overhead_bytes_per_packet = rtp_overhead_bytes_per_packet_;
1262 } 1279 }
1263 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet); 1280 overhead_observer_->OnOverheadChanged(overhead_bytes_per_packet);
1264 } 1281 }
1265 1282
1266 } // namespace webrtc 1283 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698