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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 size_t RTPSender::BuildPaddingPacket(uint8_t* packet, |
573 size_t padding_bytes_in_packet = kMaxPaddingLength; | 573 size_t header_length, |
574 size_t max_padding_length) { | |
mflodman
2015/09/08 12:33:51
This could be named only padding_length, since we'
stefan-webrtc
2015/09/08 13:17:34
Done.
| |
575 size_t padding_bytes_in_packet = max_padding_length; | |
mflodman
2015/09/08 12:33:51
No need for this variable.
stefan-webrtc
2015/09/08 13:17:34
Done.
| |
574 packet[0] |= 0x20; // Set padding bit. | 576 packet[0] |= 0x20; // Set padding bit. |
575 int32_t *data = | 577 int32_t *data = |
576 reinterpret_cast<int32_t *>(&(packet[header_length])); | 578 reinterpret_cast<int32_t *>(&(packet[header_length])); |
577 | 579 |
578 // Fill data buffer with random data. | 580 // Fill data buffer with random data. |
579 for (size_t j = 0; j < (padding_bytes_in_packet >> 2); ++j) { | 581 for (size_t j = 0; j < (padding_bytes_in_packet >> 2); ++j) { |
580 data[j] = rand(); // NOLINT | 582 data[j] = rand(); // NOLINT |
581 } | 583 } |
582 // Set number of padding bytes in the last byte of the packet. | 584 // Set number of padding bytes in the last byte of the packet. |
583 packet[header_length + padding_bytes_in_packet - 1] = | 585 packet[header_length + padding_bytes_in_packet - 1] = |
584 static_cast<uint8_t>(padding_bytes_in_packet); | 586 static_cast<uint8_t>(padding_bytes_in_packet); |
585 return padding_bytes_in_packet; | 587 return padding_bytes_in_packet; |
mflodman
2015/09/08 12:33:51
And no need to return the length here, it will alw
stefan-webrtc
2015/09/08 13:17:34
Done.
| |
586 } | 588 } |
587 | 589 |
588 size_t RTPSender::TrySendPadData(size_t bytes) { | 590 size_t RTPSender::TrySendPadData(size_t bytes) { |
589 int64_t capture_time_ms; | 591 int64_t capture_time_ms; |
590 uint32_t timestamp; | 592 uint32_t timestamp; |
591 { | 593 { |
592 CriticalSectionScoped cs(send_critsect_.get()); | 594 CriticalSectionScoped cs(send_critsect_.get()); |
593 timestamp = timestamp_; | 595 timestamp = timestamp_; |
594 capture_time_ms = capture_time_ms_; | 596 capture_time_ms = capture_time_ms_; |
595 if (last_timestamp_time_ms_ > 0) { | 597 if (rtx_ != kRtxOff && last_timestamp_time_ms_ > 0) { |
596 timestamp += | 598 timestamp += |
597 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90; | 599 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90; |
598 capture_time_ms += | 600 capture_time_ms += |
599 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_); | 601 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_); |
600 } | 602 } |
601 } | 603 } |
602 return SendPadData(timestamp, capture_time_ms, bytes); | 604 return SendPadData(timestamp, capture_time_ms, bytes); |
603 } | 605 } |
604 | 606 |
605 size_t RTPSender::SendPadData(uint32_t timestamp, | 607 size_t RTPSender::SendPadData(uint32_t timestamp, |
606 int64_t capture_time_ms, | 608 int64_t capture_time_ms, |
607 size_t bytes) { | 609 size_t bytes) { |
608 size_t padding_bytes_in_packet = 0; | 610 size_t padding_bytes_in_packet = 0; |
mflodman
2015/09/08 12:33:51
Won't this always be = std::min(MaxDataPayloadLeng
stefan-webrtc
2015/09/08 13:17:34
Done.
| |
609 size_t bytes_sent = 0; | 611 size_t bytes_sent = 0; |
610 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( | 612 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( |
611 kRtpExtensionTransportSequenceNumber) && | 613 kRtpExtensionTransportSequenceNumber) && |
612 packet_router_; | 614 packet_router_; |
613 for (; bytes > 0; bytes -= padding_bytes_in_packet) { | 615 for (; bytes > 0; bytes -= padding_bytes_in_packet) { |
614 // Always send full padding packets. | 616 // Always send full padding packets. |
mflodman
2015/09/08 12:33:51
Can you extend this comment to indicate this is ta
stefan-webrtc
2015/09/08 13:17:35
Done.
| |
615 if (bytes < kMaxPaddingLength) | 617 size_t max_padding_length = |
616 bytes = kMaxPaddingLength; | 618 std::min(MaxDataPayloadLength(), kMaxPaddingLength); |
619 if (bytes < max_padding_length) | |
620 bytes = max_padding_length; | |
617 | 621 |
618 uint32_t ssrc; | 622 uint32_t ssrc; |
619 uint16_t sequence_number; | 623 uint16_t sequence_number; |
620 int payload_type; | 624 int payload_type; |
621 bool over_rtx; | 625 bool over_rtx; |
622 { | 626 { |
623 CriticalSectionScoped cs(send_critsect_.get()); | 627 CriticalSectionScoped cs(send_critsect_.get()); |
624 // Only send padding packets following the last packet of a frame, | 628 // Only send padding packets following the last packet of a frame, |
625 // indicated by the marker bit. | 629 // indicated by the marker bit. |
626 if (rtx_ == kRtxOff) { | 630 if (rtx_ == kRtxOff) { |
(...skipping 17 matching lines...) Expand all Loading... | |
644 payload_type = rtx_payload_type_; | 648 payload_type = rtx_payload_type_; |
645 over_rtx = true; | 649 over_rtx = true; |
646 } | 650 } |
647 } | 651 } |
648 | 652 |
649 uint8_t padding_packet[IP_PACKET_SIZE]; | 653 uint8_t padding_packet[IP_PACKET_SIZE]; |
650 size_t header_length = | 654 size_t header_length = |
651 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, | 655 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, |
652 sequence_number, std::vector<uint32_t>()); | 656 sequence_number, std::vector<uint32_t>()); |
653 assert(header_length != static_cast<size_t>(-1)); | 657 assert(header_length != static_cast<size_t>(-1)); |
654 padding_bytes_in_packet = BuildPaddingPacket(padding_packet, header_length); | 658 padding_bytes_in_packet = |
659 BuildPaddingPacket(padding_packet, header_length, max_padding_length); | |
655 assert(padding_bytes_in_packet <= bytes); | 660 assert(padding_bytes_in_packet <= bytes); |
656 size_t length = padding_bytes_in_packet + header_length; | 661 size_t length = padding_bytes_in_packet + header_length; |
657 int64_t now_ms = clock_->TimeInMilliseconds(); | 662 int64_t now_ms = clock_->TimeInMilliseconds(); |
658 | 663 |
659 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); | 664 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); |
660 RTPHeader rtp_header; | 665 RTPHeader rtp_header; |
661 rtp_parser.Parse(rtp_header); | 666 rtp_parser.Parse(rtp_header); |
662 | 667 |
663 if (capture_time_ms > 0) { | 668 if (capture_time_ms > 0) { |
664 UpdateTransmissionTimeOffset( | 669 UpdateTransmissionTimeOffset( |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1898 CriticalSectionScoped lock(send_critsect_.get()); | 1903 CriticalSectionScoped lock(send_critsect_.get()); |
1899 | 1904 |
1900 RtpState state; | 1905 RtpState state; |
1901 state.sequence_number = sequence_number_rtx_; | 1906 state.sequence_number = sequence_number_rtx_; |
1902 state.start_timestamp = start_timestamp_; | 1907 state.start_timestamp = start_timestamp_; |
1903 | 1908 |
1904 return state; | 1909 return state; |
1905 } | 1910 } |
1906 | 1911 |
1907 } // namespace webrtc | 1912 } // namespace webrtc |
OLD | NEW |