Chromium Code Reviews| 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 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 if (rtx_ != kRtxOff && last_timestamp_time_ms_ > 0) { | |
|
mflodman
2015/09/15 11:48:51
I'd like a comment explaining this.
stefan-webrtc
2015/09/15 12:01:57
Done. I also moved lines 614-619 down to the RTX
| |
| 615 timestamp += | |
| 616 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_) * 90; | |
| 617 capture_time_ms += | |
| 618 (clock_->TimeInMilliseconds() - last_timestamp_time_ms_); | |
| 619 } | |
| 620 } | |
| 626 if (rtx_ == kRtxOff) { | 621 if (rtx_ == kRtxOff) { |
| 627 // Without RTX we can't send padding in the middle of frames. | 622 // Without RTX we can't send padding in the middle of frames. |
| 628 if (!last_packet_marker_bit_) | 623 if (!last_packet_marker_bit_) |
| 629 return 0; | 624 return 0; |
| 630 ssrc = ssrc_; | 625 ssrc = ssrc_; |
| 631 sequence_number = sequence_number_; | 626 sequence_number = sequence_number_; |
| 632 ++sequence_number_; | 627 ++sequence_number_; |
| 633 payload_type = payload_type_; | 628 payload_type = payload_type_; |
| 634 over_rtx = false; | 629 over_rtx = false; |
| 635 } else { | 630 } else { |
| 636 // Without abs-send-time a media packet must be sent before padding so | 631 // Without abs-send-time a media packet must be sent before padding so |
| 637 // that the timestamps used for estimation are correct. | 632 // that the timestamps used for estimation are correct. |
| 638 if (!media_has_been_sent_ && !rtp_header_extension_map_.IsRegistered( | 633 if (!media_has_been_sent_ && !rtp_header_extension_map_.IsRegistered( |
| 639 kRtpExtensionAbsoluteSendTime)) | 634 kRtpExtensionAbsoluteSendTime)) |
| 640 return 0; | 635 return 0; |
| 641 ssrc = ssrc_rtx_; | 636 ssrc = ssrc_rtx_; |
| 642 sequence_number = sequence_number_rtx_; | 637 sequence_number = sequence_number_rtx_; |
| 643 ++sequence_number_rtx_; | 638 ++sequence_number_rtx_; |
| 644 payload_type = rtx_payload_type_; | 639 payload_type = rtx_payload_type_; |
| 645 over_rtx = true; | 640 over_rtx = true; |
| 646 } | 641 } |
| 647 } | 642 } |
| 648 | 643 |
| 649 uint8_t padding_packet[IP_PACKET_SIZE]; | 644 uint8_t padding_packet[IP_PACKET_SIZE]; |
| 650 size_t header_length = | 645 size_t header_length = |
| 651 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, | 646 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, |
| 652 sequence_number, std::vector<uint32_t>()); | 647 sequence_number, std::vector<uint32_t>()); |
| 653 assert(header_length != static_cast<size_t>(-1)); | 648 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; | 649 size_t length = padding_bytes_in_packet + header_length; |
| 657 int64_t now_ms = clock_->TimeInMilliseconds(); | 650 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 658 | 651 |
| 659 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); | 652 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); |
| 660 RTPHeader rtp_header; | 653 RTPHeader rtp_header; |
| 661 rtp_parser.Parse(rtp_header); | 654 rtp_parser.Parse(rtp_header); |
| 662 | 655 |
| 663 if (capture_time_ms > 0) { | 656 if (capture_time_ms > 0) { |
| 664 UpdateTransmissionTimeOffset( | 657 UpdateTransmissionTimeOffset( |
| 665 padding_packet, length, rtp_header, now_ms - capture_time_ms); | 658 padding_packet, length, rtp_header, now_ms - capture_time_ms); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 990 size_t RTPSender::TimeToSendPadding(size_t bytes) { | 983 size_t RTPSender::TimeToSendPadding(size_t bytes) { |
| 991 if (bytes == 0) | 984 if (bytes == 0) |
| 992 return 0; | 985 return 0; |
| 993 { | 986 { |
| 994 CriticalSectionScoped cs(send_critsect_.get()); | 987 CriticalSectionScoped cs(send_critsect_.get()); |
| 995 if (!sending_media_) | 988 if (!sending_media_) |
| 996 return 0; | 989 return 0; |
| 997 } | 990 } |
| 998 size_t bytes_sent = TrySendRedundantPayloads(bytes); | 991 size_t bytes_sent = TrySendRedundantPayloads(bytes); |
| 999 if (bytes_sent < bytes) | 992 if (bytes_sent < bytes) |
| 1000 bytes_sent += TrySendPadData(bytes - bytes_sent); | 993 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0); |
| 1001 return bytes_sent; | 994 return bytes_sent; |
| 1002 } | 995 } |
| 1003 | 996 |
| 1004 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. | 997 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. |
| 1005 int32_t RTPSender::SendToNetwork( | 998 int32_t RTPSender::SendToNetwork( |
| 1006 uint8_t *buffer, size_t payload_length, size_t rtp_header_length, | 999 uint8_t *buffer, size_t payload_length, size_t rtp_header_length, |
| 1007 int64_t capture_time_ms, StorageType storage, | 1000 int64_t capture_time_ms, StorageType storage, |
| 1008 PacedSender::Priority priority) { | 1001 PacedSender::Priority priority) { |
| 1009 RtpUtility::RtpHeaderParser rtp_parser(buffer, | 1002 RtpUtility::RtpHeaderParser rtp_parser(buffer, |
| 1010 payload_length + rtp_header_length); | 1003 payload_length + rtp_header_length); |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1898 CriticalSectionScoped lock(send_critsect_.get()); | 1891 CriticalSectionScoped lock(send_critsect_.get()); |
| 1899 | 1892 |
| 1900 RtpState state; | 1893 RtpState state; |
| 1901 state.sequence_number = sequence_number_rtx_; | 1894 state.sequence_number = sequence_number_rtx_; |
| 1902 state.start_timestamp = start_timestamp_; | 1895 state.start_timestamp = start_timestamp_; |
| 1903 | 1896 |
| 1904 return state; | 1897 return state; |
| 1905 } | 1898 } |
| 1906 | 1899 |
| 1907 } // namespace webrtc | 1900 } // namespace webrtc |
| OLD | NEW |