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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 size_t length = bytes_left; | 572 size_t length = bytes_left; |
573 int64_t capture_time_ms; | 573 int64_t capture_time_ms; |
574 if (!packet_history_.GetBestFittingPacket(buffer, &length, | 574 if (!packet_history_.GetBestFittingPacket(buffer, &length, |
575 &capture_time_ms)) { | 575 &capture_time_ms)) { |
576 break; | 576 break; |
577 } | 577 } |
578 if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false)) | 578 if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false)) |
579 break; | 579 break; |
580 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); | 580 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); |
581 RTPHeader rtp_header; | 581 RTPHeader rtp_header; |
582 rtp_parser.Parse(rtp_header); | 582 rtp_parser.Parse(&rtp_header); |
583 bytes_left -= static_cast<int>(length - rtp_header.headerLength); | 583 bytes_left -= static_cast<int>(length - rtp_header.headerLength); |
584 } | 584 } |
585 return bytes_to_send - bytes_left; | 585 return bytes_to_send - bytes_left; |
586 } | 586 } |
587 | 587 |
588 void RTPSender::BuildPaddingPacket(uint8_t* packet, | 588 void RTPSender::BuildPaddingPacket(uint8_t* packet, |
589 size_t header_length, | 589 size_t header_length, |
590 size_t padding_length) { | 590 size_t padding_length) { |
591 packet[0] |= 0x20; // Set padding bit. | 591 packet[0] |= 0x20; // Set padding bit. |
592 int32_t *data = | 592 int32_t* data = reinterpret_cast<int32_t*>(&(packet[header_length])); |
593 reinterpret_cast<int32_t *>(&(packet[header_length])); | |
594 | 593 |
595 // Fill data buffer with random data. | 594 // Fill data buffer with random data. |
596 for (size_t j = 0; j < (padding_length >> 2); ++j) { | 595 for (size_t j = 0; j < (padding_length >> 2); ++j) { |
597 data[j] = rand(); // NOLINT | 596 data[j] = rand(); // NOLINT |
598 } | 597 } |
599 // Set number of padding bytes in the last byte of the packet. | 598 // Set number of padding bytes in the last byte of the packet. |
600 packet[header_length + padding_length - 1] = | 599 packet[header_length + padding_length - 1] = |
601 static_cast<uint8_t>(padding_length); | 600 static_cast<uint8_t>(padding_length); |
602 } | 601 } |
603 | 602 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 uint8_t padding_packet[IP_PACKET_SIZE]; | 663 uint8_t padding_packet[IP_PACKET_SIZE]; |
665 size_t header_length = | 664 size_t header_length = |
666 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, | 665 CreateRtpHeader(padding_packet, payload_type, ssrc, false, timestamp, |
667 sequence_number, std::vector<uint32_t>()); | 666 sequence_number, std::vector<uint32_t>()); |
668 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet); | 667 BuildPaddingPacket(padding_packet, header_length, padding_bytes_in_packet); |
669 size_t length = padding_bytes_in_packet + header_length; | 668 size_t length = padding_bytes_in_packet + header_length; |
670 int64_t now_ms = clock_->TimeInMilliseconds(); | 669 int64_t now_ms = clock_->TimeInMilliseconds(); |
671 | 670 |
672 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); | 671 RtpUtility::RtpHeaderParser rtp_parser(padding_packet, length); |
673 RTPHeader rtp_header; | 672 RTPHeader rtp_header; |
674 rtp_parser.Parse(rtp_header); | 673 rtp_parser.Parse(&rtp_header); |
675 | 674 |
676 if (capture_time_ms > 0) { | 675 if (capture_time_ms > 0) { |
677 UpdateTransmissionTimeOffset( | 676 UpdateTransmissionTimeOffset( |
678 padding_packet, length, rtp_header, now_ms - capture_time_ms); | 677 padding_packet, length, rtp_header, now_ms - capture_time_ms); |
679 } | 678 } |
680 | 679 |
681 UpdateAbsoluteSendTime(padding_packet, length, rtp_header, now_ms); | 680 UpdateAbsoluteSendTime(padding_packet, length, rtp_header, now_ms); |
682 | 681 |
683 PacketOptions options; | 682 PacketOptions options; |
684 if (using_transport_seq) { | 683 if (using_transport_seq) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 if (!packet_history_.GetPacketAndSetSendTime(packet_id, min_resend_time, true, | 715 if (!packet_history_.GetPacketAndSetSendTime(packet_id, min_resend_time, true, |
717 data_buffer, &length, | 716 data_buffer, &length, |
718 &capture_time_ms)) { | 717 &capture_time_ms)) { |
719 // Packet not found. | 718 // Packet not found. |
720 return 0; | 719 return 0; |
721 } | 720 } |
722 | 721 |
723 if (paced_sender_) { | 722 if (paced_sender_) { |
724 RtpUtility::RtpHeaderParser rtp_parser(data_buffer, length); | 723 RtpUtility::RtpHeaderParser rtp_parser(data_buffer, length); |
725 RTPHeader header; | 724 RTPHeader header; |
726 if (!rtp_parser.Parse(header)) { | 725 if (!rtp_parser.Parse(&header)) { |
727 assert(false); | 726 assert(false); |
728 return -1; | 727 return -1; |
729 } | 728 } |
730 // Convert from TickTime to Clock since capture_time_ms is based on | 729 // Convert from TickTime to Clock since capture_time_ms is based on |
731 // TickTime. | 730 // TickTime. |
732 int64_t corrected_capture_tims_ms = capture_time_ms + clock_delta_ms_; | 731 int64_t corrected_capture_tims_ms = capture_time_ms + clock_delta_ms_; |
733 paced_sender_->InsertPacket( | 732 paced_sender_->InsertPacket( |
734 RtpPacketSender::kNormalPriority, header.ssrc, header.sequenceNumber, | 733 RtpPacketSender::kNormalPriority, header.ssrc, header.sequenceNumber, |
735 corrected_capture_tims_ms, length - header.headerLength, true); | 734 corrected_capture_tims_ms, length - header.headerLength, true); |
736 | 735 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 capture_time_ms, | 901 capture_time_ms, |
903 retransmission && (rtx & kRtxRetransmitted) > 0, | 902 retransmission && (rtx & kRtxRetransmitted) > 0, |
904 retransmission); | 903 retransmission); |
905 } | 904 } |
906 | 905 |
907 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, | 906 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, |
908 size_t length, | 907 size_t length, |
909 int64_t capture_time_ms, | 908 int64_t capture_time_ms, |
910 bool send_over_rtx, | 909 bool send_over_rtx, |
911 bool is_retransmit) { | 910 bool is_retransmit) { |
912 uint8_t *buffer_to_send_ptr = buffer; | 911 uint8_t* buffer_to_send_ptr = buffer; |
913 | 912 |
914 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); | 913 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); |
915 RTPHeader rtp_header; | 914 RTPHeader rtp_header; |
916 rtp_parser.Parse(rtp_header); | 915 rtp_parser.Parse(&rtp_header); |
917 if (!is_retransmit && rtp_header.markerBit) { | 916 if (!is_retransmit && rtp_header.markerBit) { |
918 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", | 917 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", |
919 capture_time_ms); | 918 capture_time_ms); |
920 } | 919 } |
921 | 920 |
922 TRACE_EVENT_INSTANT2( | 921 TRACE_EVENT_INSTANT2( |
923 TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PrepareAndSendPacket", | 922 TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PrepareAndSendPacket", |
924 "timestamp", rtp_header.timestamp, "seqnum", rtp_header.sequenceNumber); | 923 "timestamp", rtp_header.timestamp, "seqnum", rtp_header.sequenceNumber); |
925 | 924 |
926 uint8_t data_buffer_rtx[IP_PACKET_SIZE]; | 925 uint8_t data_buffer_rtx[IP_PACKET_SIZE]; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. | 1024 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. |
1026 int32_t RTPSender::SendToNetwork(uint8_t* buffer, | 1025 int32_t RTPSender::SendToNetwork(uint8_t* buffer, |
1027 size_t payload_length, | 1026 size_t payload_length, |
1028 size_t rtp_header_length, | 1027 size_t rtp_header_length, |
1029 int64_t capture_time_ms, | 1028 int64_t capture_time_ms, |
1030 StorageType storage, | 1029 StorageType storage, |
1031 RtpPacketSender::Priority priority) { | 1030 RtpPacketSender::Priority priority) { |
1032 RtpUtility::RtpHeaderParser rtp_parser(buffer, | 1031 RtpUtility::RtpHeaderParser rtp_parser(buffer, |
1033 payload_length + rtp_header_length); | 1032 payload_length + rtp_header_length); |
1034 RTPHeader rtp_header; | 1033 RTPHeader rtp_header; |
1035 rtp_parser.Parse(rtp_header); | 1034 rtp_parser.Parse(&rtp_header); |
1036 | 1035 |
1037 int64_t now_ms = clock_->TimeInMilliseconds(); | 1036 int64_t now_ms = clock_->TimeInMilliseconds(); |
1038 | 1037 |
1039 // |capture_time_ms| <= 0 is considered invalid. | 1038 // |capture_time_ms| <= 0 is considered invalid. |
1040 // TODO(holmer): This should be changed all over Video Engine so that negative | 1039 // TODO(holmer): This should be changed all over Video Engine so that negative |
1041 // time is consider invalid, while 0 is considered a valid time. | 1040 // time is consider invalid, while 0 is considered a valid time. |
1042 if (capture_time_ms > 0) { | 1041 if (capture_time_ms > 0) { |
1043 UpdateTransmissionTimeOffset(buffer, payload_length + rtp_header_length, | 1042 UpdateTransmissionTimeOffset(buffer, payload_length + rtp_header_length, |
1044 rtp_header, now_ms - capture_time_ms); | 1043 rtp_header, now_ms - capture_time_ms); |
1045 } | 1044 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 header[1] = static_cast<uint8_t>(payload_type); | 1167 header[1] = static_cast<uint8_t>(payload_type); |
1169 if (marker_bit) { | 1168 if (marker_bit) { |
1170 header[1] |= kRtpMarkerBitMask; // Marker bit is set. | 1169 header[1] |= kRtpMarkerBitMask; // Marker bit is set. |
1171 } | 1170 } |
1172 ByteWriter<uint16_t>::WriteBigEndian(header + 2, sequence_number); | 1171 ByteWriter<uint16_t>::WriteBigEndian(header + 2, sequence_number); |
1173 ByteWriter<uint32_t>::WriteBigEndian(header + 4, timestamp); | 1172 ByteWriter<uint32_t>::WriteBigEndian(header + 4, timestamp); |
1174 ByteWriter<uint32_t>::WriteBigEndian(header + 8, ssrc); | 1173 ByteWriter<uint32_t>::WriteBigEndian(header + 8, ssrc); |
1175 int32_t rtp_header_length = kRtpHeaderLength; | 1174 int32_t rtp_header_length = kRtpHeaderLength; |
1176 | 1175 |
1177 if (csrcs.size() > 0) { | 1176 if (csrcs.size() > 0) { |
1178 uint8_t *ptr = &header[rtp_header_length]; | 1177 uint8_t* ptr = &header[rtp_header_length]; |
1179 for (size_t i = 0; i < csrcs.size(); ++i) { | 1178 for (size_t i = 0; i < csrcs.size(); ++i) { |
1180 ByteWriter<uint32_t>::WriteBigEndian(ptr, csrcs[i]); | 1179 ByteWriter<uint32_t>::WriteBigEndian(ptr, csrcs[i]); |
1181 ptr += 4; | 1180 ptr += 4; |
1182 } | 1181 } |
1183 header[0] = (header[0] & 0xf0) | csrcs.size(); | 1182 header[0] = (header[0] & 0xf0) | csrcs.size(); |
1184 | 1183 |
1185 // Update length of header. | 1184 // Update length of header. |
1186 rtp_header_length += sizeof(uint32_t) * csrcs.size(); | 1185 rtp_header_length += sizeof(uint32_t) * csrcs.size(); |
1187 } | 1186 } |
1188 | 1187 |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 | 1819 |
1821 void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length, | 1820 void RTPSender::BuildRtxPacket(uint8_t* buffer, size_t* length, |
1822 uint8_t* buffer_rtx) { | 1821 uint8_t* buffer_rtx) { |
1823 CriticalSectionScoped cs(send_critsect_.get()); | 1822 CriticalSectionScoped cs(send_critsect_.get()); |
1824 uint8_t* data_buffer_rtx = buffer_rtx; | 1823 uint8_t* data_buffer_rtx = buffer_rtx; |
1825 // Add RTX header. | 1824 // Add RTX header. |
1826 RtpUtility::RtpHeaderParser rtp_parser( | 1825 RtpUtility::RtpHeaderParser rtp_parser( |
1827 reinterpret_cast<const uint8_t*>(buffer), *length); | 1826 reinterpret_cast<const uint8_t*>(buffer), *length); |
1828 | 1827 |
1829 RTPHeader rtp_header; | 1828 RTPHeader rtp_header; |
1830 rtp_parser.Parse(rtp_header); | 1829 rtp_parser.Parse(&rtp_header); |
1831 | 1830 |
1832 // Add original RTP header. | 1831 // Add original RTP header. |
1833 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); | 1832 memcpy(data_buffer_rtx, buffer, rtp_header.headerLength); |
1834 | 1833 |
1835 // Replace payload type, if a specific type is set for RTX. | 1834 // Replace payload type, if a specific type is set for RTX. |
1836 if (rtx_payload_type_ != -1) { | 1835 if (rtx_payload_type_ != -1) { |
1837 data_buffer_rtx[1] = static_cast<uint8_t>(rtx_payload_type_); | 1836 data_buffer_rtx[1] = static_cast<uint8_t>(rtx_payload_type_); |
1838 if (rtp_header.markerBit) | 1837 if (rtp_header.markerBit) |
1839 data_buffer_rtx[1] |= kRtpMarkerBitMask; | 1838 data_buffer_rtx[1] |= kRtpMarkerBitMask; |
1840 } | 1839 } |
1841 | 1840 |
1842 // Replace sequence number. | 1841 // Replace sequence number. |
1843 uint8_t *ptr = data_buffer_rtx + 2; | 1842 uint8_t* ptr = data_buffer_rtx + 2; |
1844 ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++); | 1843 ByteWriter<uint16_t>::WriteBigEndian(ptr, sequence_number_rtx_++); |
1845 | 1844 |
1846 // Replace SSRC. | 1845 // Replace SSRC. |
1847 ptr += 6; | 1846 ptr += 6; |
1848 ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_); | 1847 ByteWriter<uint32_t>::WriteBigEndian(ptr, ssrc_rtx_); |
1849 | 1848 |
1850 // Add OSN (original sequence number). | 1849 // Add OSN (original sequence number). |
1851 ptr = data_buffer_rtx + rtp_header.headerLength; | 1850 ptr = data_buffer_rtx + rtp_header.headerLength; |
1852 ByteWriter<uint16_t>::WriteBigEndian(ptr, rtp_header.sequenceNumber); | 1851 ByteWriter<uint16_t>::WriteBigEndian(ptr, rtp_header.sequenceNumber); |
1853 ptr += 2; | 1852 ptr += 2; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1907 CriticalSectionScoped lock(send_critsect_.get()); | 1906 CriticalSectionScoped lock(send_critsect_.get()); |
1908 | 1907 |
1909 RtpState state; | 1908 RtpState state; |
1910 state.sequence_number = sequence_number_rtx_; | 1909 state.sequence_number = sequence_number_rtx_; |
1911 state.start_timestamp = start_timestamp_; | 1910 state.start_timestamp = start_timestamp_; |
1912 | 1911 |
1913 return state; | 1912 return state; |
1914 } | 1913 } |
1915 | 1914 |
1916 } // namespace webrtc | 1915 } // namespace webrtc |
OLD | NEW |