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

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

Issue 1327933003: Enable probing with repeated payload packets by default. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing yet another flake in libjingle tests. Created 5 years, 3 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false)) 562 if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false))
563 break; 563 break;
564 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); 564 RtpUtility::RtpHeaderParser rtp_parser(buffer, length);
565 RTPHeader rtp_header; 565 RTPHeader rtp_header;
566 rtp_parser.Parse(rtp_header); 566 rtp_parser.Parse(rtp_header);
567 bytes_left -= static_cast<int>(length - rtp_header.headerLength); 567 bytes_left -= static_cast<int>(length - rtp_header.headerLength);
568 } 568 }
569 return bytes_to_send - bytes_left; 569 return bytes_to_send - bytes_left;
570 } 570 }
571 571
572 size_t RTPSender::BuildPaddingPacket(uint8_t* packet, size_t header_length) { 572 void RTPSender::BuildPaddingPacket(uint8_t* packet,
573 size_t padding_bytes_in_packet = kMaxPaddingLength; 573 size_t header_length,
574 size_t padding_length) {
574 packet[0] |= 0x20; // Set padding bit. 575 packet[0] |= 0x20; // Set padding bit.
575 int32_t *data = 576 int32_t *data =
576 reinterpret_cast<int32_t *>(&(packet[header_length])); 577 reinterpret_cast<int32_t *>(&(packet[header_length]));
577 578
578 // Fill data buffer with random data. 579 // Fill data buffer with random data.
579 for (size_t j = 0; j < (padding_bytes_in_packet >> 2); ++j) { 580 for (size_t j = 0; j < (padding_length >> 2); ++j) {
580 data[j] = rand(); // NOLINT 581 data[j] = rand(); // NOLINT
581 } 582 }
582 // Set number of padding bytes in the last byte of the packet. 583 // Set number of padding bytes in the last byte of the packet.
583 packet[header_length + padding_bytes_in_packet - 1] = 584 packet[header_length + padding_length - 1] =
584 static_cast<uint8_t>(padding_bytes_in_packet); 585 static_cast<uint8_t>(padding_length);
585 return padding_bytes_in_packet;
586 } 586 }
587 587
588 size_t RTPSender::TrySendPadData(size_t bytes) { 588 size_t RTPSender::SendPadData(size_t bytes,
589 int64_t capture_time_ms; 589 bool timestamp_provided,
590 uint32_t timestamp; 590 uint32_t timestamp,
591 { 591 int64_t capture_time_ms) {
592 CriticalSectionScoped cs(send_critsect_.get()); 592 // Always send full padding packets. This is accounted for by the PacedSender,
593 timestamp = timestamp_; 593 // which will make sure we don't send too much padding even if a single packet
594 capture_time_ms = capture_time_ms_; 594 // is larger than requested.
595 if (last_timestamp_time_ms_ > 0) { 595 size_t padding_bytes_in_packet =
596 timestamp += 596 std::min(MaxDataPayloadLength(), kMaxPaddingLength);
597 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90;
598 capture_time_ms +=
599 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_);
600 }
601 }
602 return SendPadData(timestamp, capture_time_ms, bytes);
603 }
604
605 size_t RTPSender::SendPadData(uint32_t timestamp,
606 int64_t capture_time_ms,
607 size_t bytes) {
608 size_t padding_bytes_in_packet = 0;
609 size_t bytes_sent = 0; 597 size_t bytes_sent = 0;
610 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( 598 bool using_transport_seq = rtp_header_extension_map_.IsRegistered(
611 kRtpExtensionTransportSequenceNumber) && 599 kRtpExtensionTransportSequenceNumber) &&
612 packet_router_; 600 packet_router_;
613 for (; bytes > 0; bytes -= padding_bytes_in_packet) { 601 for (; bytes > 0; bytes -= padding_bytes_in_packet) {
614 // Always send full padding packets. 602 if (bytes < padding_bytes_in_packet)
615 if (bytes < kMaxPaddingLength) 603 bytes = padding_bytes_in_packet;
616 bytes = kMaxPaddingLength;
617 604
618 uint32_t ssrc; 605 uint32_t ssrc;
619 uint16_t sequence_number; 606 uint16_t sequence_number;
620 int payload_type; 607 int payload_type;
621 bool over_rtx; 608 bool over_rtx;
622 { 609 {
623 CriticalSectionScoped cs(send_critsect_.get()); 610 CriticalSectionScoped cs(send_critsect_.get());
624 // Only send padding packets following the last packet of a frame, 611 if (!timestamp_provided) {
625 // indicated by the marker bit. 612 timestamp = timestamp_;
613 capture_time_ms = capture_time_ms_;
614 }
626 if (rtx_ == kRtxOff) { 615 if (rtx_ == kRtxOff) {
627 // Without RTX we can't send padding in the middle of frames. 616 // Without RTX we can't send padding in the middle of frames.
628 if (!last_packet_marker_bit_) 617 if (!last_packet_marker_bit_)
629 return 0; 618 return 0;
630 ssrc = ssrc_; 619 ssrc = ssrc_;
631 sequence_number = sequence_number_; 620 sequence_number = sequence_number_;
632 ++sequence_number_; 621 ++sequence_number_;
633 payload_type = payload_type_; 622 payload_type = payload_type_;
634 over_rtx = false; 623 over_rtx = false;
635 } else { 624 } else {
636 // Without abs-send-time a media packet must be sent before padding so 625 // Without abs-send-time a media packet must be sent before padding so
637 // that the timestamps used for estimation are correct. 626 // that the timestamps used for estimation are correct.
638 if (!media_has_been_sent_ && !rtp_header_extension_map_.IsRegistered( 627 if (!media_has_been_sent_ && !rtp_header_extension_map_.IsRegistered(
639 kRtpExtensionAbsoluteSendTime)) 628 kRtpExtensionAbsoluteSendTime))
640 return 0; 629 return 0;
630 // Only change change the timestamp of padding packets sent over RTX.
631 // Padding only packets over RTP has to be sent as part of a media
632 // frame (and therefore the same timestamp).
633 if (last_timestamp_time_ms_ > 0) {
634 timestamp +=
635 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90;
636 capture_time_ms +=
637 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_);
638 }
641 ssrc = ssrc_rtx_; 639 ssrc = ssrc_rtx_;
642 sequence_number = sequence_number_rtx_; 640 sequence_number = sequence_number_rtx_;
643 ++sequence_number_rtx_; 641 ++sequence_number_rtx_;
644 payload_type = rtx_payload_type_; 642 payload_type = rtx_payload_type_;
645 over_rtx = true; 643 over_rtx = true;
646 } 644 }
647 } 645 }
648 646
649 uint8_t padding_packet[IP_PACKET_SIZE]; 647 uint8_t padding_packet[IP_PACKET_SIZE];
650 size_t header_length = 648 size_t header_length =
651 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, 649 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp,
652 sequence_number, std::vector<uint32_t>()); 650 sequence_number, std::vector<uint32_t>());
653 assert(header_length != static_cast<size_t>(-1)); 651 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet);
654 padding_bytes_in_packet = BuildPaddingPacket(padding_packet, header_length);
655 assert(padding_bytes_in_packet <= bytes);
656 size_t length = padding_bytes_in_packet + header_length; 652 size_t length = padding_bytes_in_packet + header_length;
657 int64_t now_ms = clock_->TimeInMilliseconds(); 653 int64_t now_ms = clock_->TimeInMilliseconds();
658 654
659 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); 655 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length);
660 RTPHeader rtp_header; 656 RTPHeader rtp_header;
661 rtp_parser.Parse(rtp_header); 657 rtp_parser.Parse(rtp_header);
662 658
663 if (capture_time_ms > 0) { 659 if (capture_time_ms > 0) {
664 UpdateTransmissionTimeOffset( 660 UpdateTransmissionTimeOffset(
665 padding_packet, length, rtp_header, now_ms - capture_time_ms); 661 padding_packet, length, rtp_header, now_ms - capture_time_ms);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 size_t RTPSender::TimeToSendPadding(size_t bytes) { 991 size_t RTPSender::TimeToSendPadding(size_t bytes) {
996 if (bytes == 0) 992 if (bytes == 0)
997 return 0; 993 return 0;
998 { 994 {
999 CriticalSectionScoped cs(send_critsect_.get()); 995 CriticalSectionScoped cs(send_critsect_.get());
1000 if (!sending_media_) 996 if (!sending_media_)
1001 return 0; 997 return 0;
1002 } 998 }
1003 size_t bytes_sent = TrySendRedundantPayloads(bytes); 999 size_t bytes_sent = TrySendRedundantPayloads(bytes);
1004 if (bytes_sent < bytes) 1000 if (bytes_sent < bytes)
1005 bytes_sent += TrySendPadData(bytes - bytes_sent); 1001 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0);
1006 return bytes_sent; 1002 return bytes_sent;
1007 } 1003 }
1008 1004
1009 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. 1005 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again.
1010 int32_t RTPSender::SendToNetwork( 1006 int32_t RTPSender::SendToNetwork(
1011 uint8_t *buffer, size_t payload_length, size_t rtp_header_length, 1007 uint8_t *buffer, size_t payload_length, size_t rtp_header_length,
1012 int64_t capture_time_ms, StorageType storage, 1008 int64_t capture_time_ms, StorageType storage,
1013 PacedSender::Priority priority) { 1009 PacedSender::Priority priority) {
1014 RtpUtility::RtpHeaderParser rtp_parser(buffer, 1010 RtpUtility::RtpHeaderParser rtp_parser(buffer,
1015 payload_length + rtp_header_length); 1011 payload_length + rtp_header_length);
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 CriticalSectionScoped lock(send_critsect_.get()); 1898 CriticalSectionScoped lock(send_critsect_.get());
1903 1899
1904 RtpState state; 1900 RtpState state;
1905 state.sequence_number = sequence_number_rtx_; 1901 state.sequence_number = sequence_number_rtx_;
1906 state.start_timestamp = start_timestamp_; 1902 state.start_timestamp = start_timestamp_;
1907 1903
1908 return state; 1904 return state;
1909 } 1905 }
1910 1906
1911 } // namespace webrtc 1907 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_sender.h ('k') | webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698