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

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

Issue 2067673004: Style cleanups in RtpSender. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: fix compilation Created 4 years, 6 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 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 612
613 // Fill data buffer with random data. 613 // Fill data buffer with random data.
614 for (size_t j = 0; j < (padding_length >> 2); ++j) { 614 for (size_t j = 0; j < (padding_length >> 2); ++j) {
615 data[j] = rand(); // NOLINT 615 data[j] = rand(); // NOLINT
616 } 616 }
617 // Set number of padding bytes in the last byte of the packet. 617 // Set number of padding bytes in the last byte of the packet.
618 packet[header_length + padding_length - 1] = 618 packet[header_length + padding_length - 1] =
619 static_cast<uint8_t>(padding_length); 619 static_cast<uint8_t>(padding_length);
620 } 620 }
621 621
622 size_t RTPSender::SendPadData(size_t bytes,
623 bool timestamp_provided,
624 uint32_t timestamp,
625 int64_t capture_time_ms) {
626 return SendPadData(bytes, timestamp_provided, timestamp, capture_time_ms,
627 PacketInfo::kNotAProbe);
628 }
629 622
630 size_t RTPSender::SendPadData(size_t bytes, 623 size_t RTPSender::SendPadData(size_t bytes,
631 bool timestamp_provided,
632 uint32_t timestamp,
633 int64_t capture_time_ms,
634 int probe_cluster_id) { 624 int probe_cluster_id) {
625 uint32_t timestamp = 0;
626 int64_t capture_time_ms = 0;
635 // Always send full padding packets. This is accounted for by the 627 // Always send full padding packets. This is accounted for by the
636 // RtpPacketSender, 628 // RtpPacketSender,
637 // which will make sure we don't send too much padding even if a single packet 629 // which will make sure we don't send too much padding even if a single packet
638 // is larger than requested. 630 // is larger than requested.
639 size_t padding_bytes_in_packet = 631 size_t padding_bytes_in_packet =
640 std::min(MaxDataPayloadLength(), kMaxPaddingLength); 632 std::min(MaxDataPayloadLength(), kMaxPaddingLength);
641 size_t bytes_sent = 0; 633 size_t bytes_sent = 0;
642 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( 634 bool using_transport_seq = rtp_header_extension_map_.IsRegistered(
643 kRtpExtensionTransportSequenceNumber) && 635 kRtpExtensionTransportSequenceNumber) &&
644 transport_sequence_number_allocator_; 636 transport_sequence_number_allocator_;
645 for (; bytes > 0; bytes -= padding_bytes_in_packet) { 637 for (; bytes > 0; bytes -= padding_bytes_in_packet) {
646 if (bytes < padding_bytes_in_packet) 638 if (bytes < padding_bytes_in_packet)
647 bytes = padding_bytes_in_packet; 639 bytes = padding_bytes_in_packet;
648 640
649 uint32_t ssrc; 641 uint32_t ssrc;
650 uint16_t sequence_number; 642 uint16_t sequence_number;
651 int payload_type; 643 int payload_type;
652 bool over_rtx; 644 bool over_rtx;
653 { 645 {
654 rtc::CritScope lock(&send_critsect_); 646 rtc::CritScope lock(&send_critsect_);
655 if (!sending_media_) 647 if (!sending_media_)
656 return bytes_sent; 648 return bytes_sent;
657 if (!timestamp_provided) { 649 timestamp = timestamp_;
658 timestamp = timestamp_; 650 capture_time_ms = capture_time_ms_;
659 capture_time_ms = capture_time_ms_;
660 }
661 if (rtx_ == kRtxOff) { 651 if (rtx_ == kRtxOff) {
662 // Without RTX we can't send padding in the middle of frames. 652 // Without RTX we can't send padding in the middle of frames.
663 if (!last_packet_marker_bit_) 653 if (!last_packet_marker_bit_)
664 return 0; 654 return 0;
665 ssrc = ssrc_; 655 ssrc = ssrc_;
666 sequence_number = sequence_number_; 656 sequence_number = sequence_number_;
667 ++sequence_number_; 657 ++sequence_number_;
668 payload_type = payload_type_; 658 payload_type = payload_type_;
669 over_rtx = false; 659 over_rtx = false;
670 } else { 660 } else {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 return fec_enabled && 1036 return fec_enabled &&
1047 header.payloadType == pt_red && 1037 header.payloadType == pt_red &&
1048 buffer[header.headerLength] == pt_fec; 1038 buffer[header.headerLength] == pt_fec;
1049 } 1039 }
1050 1040
1051 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) { 1041 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) {
1052 if (audio_configured_ || bytes == 0) 1042 if (audio_configured_ || bytes == 0)
1053 return 0; 1043 return 0;
1054 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id); 1044 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id);
1055 if (bytes_sent < bytes) 1045 if (bytes_sent < bytes)
1056 bytes_sent += 1046 bytes_sent += SendPadData(bytes - bytes_sent, probe_cluster_id);
1057 SendPadData(bytes - bytes_sent, false, 0, 0, probe_cluster_id);
1058 return bytes_sent; 1047 return bytes_sent;
1059 } 1048 }
1060 1049
1061 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. 1050 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again.
1062 int32_t RTPSender::SendToNetwork(uint8_t* buffer, 1051 int32_t RTPSender::SendToNetwork(uint8_t* buffer,
1063 size_t payload_length, 1052 size_t payload_length,
1064 size_t rtp_header_length, 1053 size_t rtp_header_length,
1065 int64_t capture_time_ms, 1054 int64_t capture_time_ms,
1066 StorageType storage, 1055 StorageType storage,
1067 RtpPacketSender::Priority priority) { 1056 RtpPacketSender::Priority priority) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 ByteWriter<uint32_t>::WriteBigEndian(ptr, csrcs[i]); 1222 ByteWriter<uint32_t>::WriteBigEndian(ptr, csrcs[i]);
1234 ptr += 4; 1223 ptr += 4;
1235 } 1224 }
1236 header[0] = (header[0] & 0xf0) | csrcs.size(); 1225 header[0] = (header[0] & 0xf0) | csrcs.size();
1237 1226
1238 // Update length of header. 1227 // Update length of header.
1239 rtp_header_length += sizeof(uint32_t) * csrcs.size(); 1228 rtp_header_length += sizeof(uint32_t) * csrcs.size();
1240 } 1229 }
1241 1230
1242 uint16_t len = 1231 uint16_t len =
1243 BuildRTPHeaderExtension(header + rtp_header_length, marker_bit); 1232 BuildRtpHeaderExtension(header + rtp_header_length, marker_bit);
1244 if (len > 0) { 1233 if (len > 0) {
1245 header[0] |= 0x10; // Set extension bit. 1234 header[0] |= 0x10; // Set extension bit.
1246 rtp_header_length += len; 1235 rtp_header_length += len;
1247 } 1236 }
1248 return rtp_header_length; 1237 return rtp_header_length;
1249 } 1238 }
1250 1239
1251 int32_t RTPSender::BuildRTPheader(uint8_t* data_buffer, 1240 int32_t RTPSender::BuildRtpHeader(uint8_t* data_buffer,
1252 int8_t payload_type, 1241 int8_t payload_type,
1253 bool marker_bit, 1242 bool marker_bit,
1254 uint32_t capture_timestamp, 1243 uint32_t capture_timestamp,
1255 int64_t capture_time_ms, 1244 int64_t capture_time_ms) {
1256 bool timestamp_provided,
1257 bool inc_sequence_number) {
1258 assert(payload_type >= 0); 1245 assert(payload_type >= 0);
1259 rtc::CritScope lock(&send_critsect_); 1246 rtc::CritScope lock(&send_critsect_);
1260 1247
1261 if (timestamp_provided) { 1248 timestamp_ = start_timestamp_ + capture_timestamp;
1262 timestamp_ = start_timestamp_ + capture_timestamp;
1263 } else {
1264 // Make a unique time stamp.
1265 // We can't inc by the actual time, since then we increase the risk of back
1266 // timing.
1267 timestamp_++;
1268 }
1269 last_timestamp_time_ms_ = clock_->TimeInMilliseconds(); 1249 last_timestamp_time_ms_ = clock_->TimeInMilliseconds();
1270 uint32_t sequence_number = sequence_number_++; 1250 uint32_t sequence_number = sequence_number_++;
1271 capture_time_ms_ = capture_time_ms; 1251 capture_time_ms_ = capture_time_ms;
1272 last_packet_marker_bit_ = marker_bit; 1252 last_packet_marker_bit_ = marker_bit;
1273 return CreateRtpHeader(data_buffer, payload_type, ssrc_, marker_bit, 1253 return CreateRtpHeader(data_buffer, payload_type, ssrc_, marker_bit,
1274 timestamp_, sequence_number, csrcs_); 1254 timestamp_, sequence_number, csrcs_);
1275 } 1255 }
1276 1256
1277 uint16_t RTPSender::BuildRTPHeaderExtension(uint8_t* data_buffer, 1257 uint16_t RTPSender::BuildRtpHeaderExtension(uint8_t* data_buffer,
1278 bool marker_bit) const { 1258 bool marker_bit) const {
1279 if (rtp_header_extension_map_.Size() <= 0) { 1259 if (rtp_header_extension_map_.Size() <= 0) {
1280 return 0; 1260 return 0;
1281 } 1261 }
1282 // RTP header extension, RFC 3550. 1262 // RTP header extension, RFC 3550.
1283 // 0 1 2 3 1263 // 0 1 2 3
1284 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 1264 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1285 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1265 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1286 // | defined by profile | length | 1266 // | defined by profile | length |
1287 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1267 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 rtc::CritScope lock(&send_critsect_); 1976 rtc::CritScope lock(&send_critsect_);
1997 1977
1998 RtpState state; 1978 RtpState state;
1999 state.sequence_number = sequence_number_rtx_; 1979 state.sequence_number = sequence_number_rtx_;
2000 state.start_timestamp = start_timestamp_; 1980 state.start_timestamp = start_timestamp_;
2001 1981
2002 return state; 1982 return state;
2003 } 1983 }
2004 1984
2005 } // namespace webrtc 1985 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698