| 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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } else if (frame_type == kVideoFrameDelta) { | 536 } else if (frame_type == kVideoFrameDelta) { |
| 537 ++frame_counts_.delta_frames; | 537 ++frame_counts_.delta_frames; |
| 538 } | 538 } |
| 539 if (frame_count_observer_) { | 539 if (frame_count_observer_) { |
| 540 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); | 540 frame_count_observer_->FrameCountUpdated(frame_counts_, ssrc); |
| 541 } | 541 } |
| 542 | 542 |
| 543 return ret_val; | 543 return ret_val; |
| 544 } | 544 } |
| 545 | 545 |
| 546 size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send) { | 546 size_t RTPSender::TrySendRedundantPayloads(size_t bytes_to_send, |
| 547 int probe_cluster_id) { |
| 547 { | 548 { |
| 548 rtc::CritScope lock(&send_critsect_); | 549 rtc::CritScope lock(&send_critsect_); |
| 549 if (!sending_media_) | 550 if (!sending_media_) |
| 550 return 0; | 551 return 0; |
| 551 if ((rtx_ & kRtxRedundantPayloads) == 0) | 552 if ((rtx_ & kRtxRedundantPayloads) == 0) |
| 552 return 0; | 553 return 0; |
| 553 } | 554 } |
| 554 | 555 |
| 555 uint8_t buffer[IP_PACKET_SIZE]; | 556 uint8_t buffer[IP_PACKET_SIZE]; |
| 556 int bytes_left = static_cast<int>(bytes_to_send); | 557 int bytes_left = static_cast<int>(bytes_to_send); |
| 557 while (bytes_left > 0) { | 558 while (bytes_left > 0) { |
| 558 size_t length = bytes_left; | 559 size_t length = bytes_left; |
| 559 int64_t capture_time_ms; | 560 int64_t capture_time_ms; |
| 560 if (!packet_history_.GetBestFittingPacket(buffer, &length, | 561 if (!packet_history_.GetBestFittingPacket(buffer, &length, |
| 561 &capture_time_ms)) { | 562 &capture_time_ms)) { |
| 562 break; | 563 break; |
| 563 } | 564 } |
| 564 if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false)) | 565 if (!PrepareAndSendPacket(buffer, length, capture_time_ms, true, false, |
| 566 probe_cluster_id)) |
| 565 break; | 567 break; |
| 566 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); | 568 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); |
| 567 RTPHeader rtp_header; | 569 RTPHeader rtp_header; |
| 568 rtp_parser.Parse(&rtp_header); | 570 rtp_parser.Parse(&rtp_header); |
| 569 bytes_left -= static_cast<int>(length - rtp_header.headerLength); | 571 bytes_left -= static_cast<int>(length - rtp_header.headerLength); |
| 570 } | 572 } |
| 571 return bytes_to_send - bytes_left; | 573 return bytes_to_send - bytes_left; |
| 572 } | 574 } |
| 573 | 575 |
| 574 void RTPSender::BuildPaddingPacket(uint8_t* packet, | 576 void RTPSender::BuildPaddingPacket(uint8_t* packet, |
| 575 size_t header_length, | 577 size_t header_length, |
| 576 size_t padding_length) { | 578 size_t padding_length) { |
| 577 packet[0] |= 0x20; // Set padding bit. | 579 packet[0] |= 0x20; // Set padding bit. |
| 578 int32_t* data = reinterpret_cast<int32_t*>(&(packet[header_length])); | 580 int32_t* data = reinterpret_cast<int32_t*>(&(packet[header_length])); |
| 579 | 581 |
| 580 // Fill data buffer with random data. | 582 // Fill data buffer with random data. |
| 581 for (size_t j = 0; j < (padding_length >> 2); ++j) { | 583 for (size_t j = 0; j < (padding_length >> 2); ++j) { |
| 582 data[j] = rand(); // NOLINT | 584 data[j] = rand(); // NOLINT |
| 583 } | 585 } |
| 584 // Set number of padding bytes in the last byte of the packet. | 586 // Set number of padding bytes in the last byte of the packet. |
| 585 packet[header_length + padding_length - 1] = | 587 packet[header_length + padding_length - 1] = |
| 586 static_cast<uint8_t>(padding_length); | 588 static_cast<uint8_t>(padding_length); |
| 587 } | 589 } |
| 588 | 590 |
| 589 size_t RTPSender::SendPadData(size_t bytes, | 591 size_t RTPSender::SendPadData(size_t bytes, |
| 590 bool timestamp_provided, | 592 bool timestamp_provided, |
| 591 uint32_t timestamp, | 593 uint32_t timestamp, |
| 592 int64_t capture_time_ms) { | 594 int64_t capture_time_ms) { |
| 595 return SendPadData(bytes, timestamp_provided, timestamp, capture_time_ms, |
| 596 PacketInfo::kNotAProbe); |
| 597 } |
| 598 |
| 599 size_t RTPSender::SendPadData(size_t bytes, |
| 600 bool timestamp_provided, |
| 601 uint32_t timestamp, |
| 602 int64_t capture_time_ms, |
| 603 int probe_cluster_id) { |
| 593 // Always send full padding packets. This is accounted for by the | 604 // Always send full padding packets. This is accounted for by the |
| 594 // RtpPacketSender, | 605 // RtpPacketSender, |
| 595 // which will make sure we don't send too much padding even if a single packet | 606 // which will make sure we don't send too much padding even if a single packet |
| 596 // is larger than requested. | 607 // is larger than requested. |
| 597 size_t padding_bytes_in_packet = | 608 size_t padding_bytes_in_packet = |
| 598 std::min(MaxDataPayloadLength(), kMaxPaddingLength); | 609 std::min(MaxDataPayloadLength(), kMaxPaddingLength); |
| 599 size_t bytes_sent = 0; | 610 size_t bytes_sent = 0; |
| 600 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( | 611 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( |
| 601 kRtpExtensionTransportSequenceNumber) && | 612 kRtpExtensionTransportSequenceNumber) && |
| 602 transport_sequence_number_allocator_; | 613 transport_sequence_number_allocator_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 } | 681 } |
| 671 | 682 |
| 672 UpdateAbsoluteSendTime(padding_packet, length, rtp_header, now_ms); | 683 UpdateAbsoluteSendTime(padding_packet, length, rtp_header, now_ms); |
| 673 | 684 |
| 674 PacketOptions options; | 685 PacketOptions options; |
| 675 if (AllocateTransportSequenceNumber(&options.packet_id)) { | 686 if (AllocateTransportSequenceNumber(&options.packet_id)) { |
| 676 if (UpdateTransportSequenceNumber(options.packet_id, padding_packet, | 687 if (UpdateTransportSequenceNumber(options.packet_id, padding_packet, |
| 677 length, rtp_header)) { | 688 length, rtp_header)) { |
| 678 if (transport_feedback_observer_) | 689 if (transport_feedback_observer_) |
| 679 transport_feedback_observer_->AddPacket(options.packet_id, length, | 690 transport_feedback_observer_->AddPacket(options.packet_id, length, |
| 680 true); | 691 true, probe_cluster_id); |
| 681 } | 692 } |
| 682 } | 693 } |
| 683 | 694 |
| 684 if (!SendPacketToNetwork(padding_packet, length, options)) | 695 if (!SendPacketToNetwork(padding_packet, length, options)) |
| 685 break; | 696 break; |
| 686 | 697 |
| 687 bytes_sent += padding_bytes_in_packet; | 698 bytes_sent += padding_bytes_in_packet; |
| 688 UpdateRtpStats(padding_packet, length, rtp_header, over_rtx, false); | 699 UpdateRtpStats(padding_packet, length, rtp_header, over_rtx, false); |
| 689 } | 700 } |
| 690 | 701 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 corrected_capture_tims_ms, length - header.headerLength, true); | 737 corrected_capture_tims_ms, length - header.headerLength, true); |
| 727 | 738 |
| 728 return length; | 739 return length; |
| 729 } | 740 } |
| 730 int rtx = kRtxOff; | 741 int rtx = kRtxOff; |
| 731 { | 742 { |
| 732 rtc::CritScope lock(&send_critsect_); | 743 rtc::CritScope lock(&send_critsect_); |
| 733 rtx = rtx_; | 744 rtx = rtx_; |
| 734 } | 745 } |
| 735 if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms, | 746 if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms, |
| 736 (rtx & kRtxRetransmitted) > 0, true)) { | 747 (rtx & kRtxRetransmitted) > 0, true, |
| 748 PacketInfo::kNotAProbe)) { |
| 737 return -1; | 749 return -1; |
| 738 } | 750 } |
| 739 return static_cast<int32_t>(length); | 751 return static_cast<int32_t>(length); |
| 740 } | 752 } |
| 741 | 753 |
| 742 bool RTPSender::SendPacketToNetwork(const uint8_t* packet, | 754 bool RTPSender::SendPacketToNetwork(const uint8_t* packet, |
| 743 size_t size, | 755 size_t size, |
| 744 const PacketOptions& options) { | 756 const PacketOptions& options) { |
| 745 int bytes_sent = -1; | 757 int bytes_sent = -1; |
| 746 if (transport_) { | 758 if (transport_) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 nack_byte_count_[i + 1] = nack_byte_count_[i]; | 874 nack_byte_count_[i + 1] = nack_byte_count_[i]; |
| 863 nack_byte_count_times_[i + 1] = nack_byte_count_times_[i]; | 875 nack_byte_count_times_[i + 1] = nack_byte_count_times_[i]; |
| 864 } | 876 } |
| 865 nack_byte_count_[0] = bytes; | 877 nack_byte_count_[0] = bytes; |
| 866 nack_byte_count_times_[0] = now; | 878 nack_byte_count_times_[0] = now; |
| 867 } | 879 } |
| 868 | 880 |
| 869 // Called from pacer when we can send the packet. | 881 // Called from pacer when we can send the packet. |
| 870 bool RTPSender::TimeToSendPacket(uint16_t sequence_number, | 882 bool RTPSender::TimeToSendPacket(uint16_t sequence_number, |
| 871 int64_t capture_time_ms, | 883 int64_t capture_time_ms, |
| 872 bool retransmission) { | 884 bool retransmission, |
| 885 int probe_cluster_id) { |
| 873 size_t length = IP_PACKET_SIZE; | 886 size_t length = IP_PACKET_SIZE; |
| 874 uint8_t data_buffer[IP_PACKET_SIZE]; | 887 uint8_t data_buffer[IP_PACKET_SIZE]; |
| 875 int64_t stored_time_ms; | 888 int64_t stored_time_ms; |
| 876 | 889 |
| 877 if (!packet_history_.GetPacketAndSetSendTime(sequence_number, | 890 if (!packet_history_.GetPacketAndSetSendTime(sequence_number, |
| 878 0, | 891 0, |
| 879 retransmission, | 892 retransmission, |
| 880 data_buffer, | 893 data_buffer, |
| 881 &length, | 894 &length, |
| 882 &stored_time_ms)) { | 895 &stored_time_ms)) { |
| 883 // Packet cannot be found. Allow sending to continue. | 896 // Packet cannot be found. Allow sending to continue. |
| 884 return true; | 897 return true; |
| 885 } | 898 } |
| 886 | 899 |
| 887 int rtx; | 900 int rtx; |
| 888 { | 901 { |
| 889 rtc::CritScope lock(&send_critsect_); | 902 rtc::CritScope lock(&send_critsect_); |
| 890 rtx = rtx_; | 903 rtx = rtx_; |
| 891 } | 904 } |
| 892 return PrepareAndSendPacket(data_buffer, | 905 return PrepareAndSendPacket(data_buffer, length, capture_time_ms, |
| 893 length, | |
| 894 capture_time_ms, | |
| 895 retransmission && (rtx & kRtxRetransmitted) > 0, | 906 retransmission && (rtx & kRtxRetransmitted) > 0, |
| 896 retransmission); | 907 retransmission, probe_cluster_id); |
| 897 } | 908 } |
| 898 | 909 |
| 899 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, | 910 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, |
| 900 size_t length, | 911 size_t length, |
| 901 int64_t capture_time_ms, | 912 int64_t capture_time_ms, |
| 902 bool send_over_rtx, | 913 bool send_over_rtx, |
| 903 bool is_retransmit) { | 914 bool is_retransmit, |
| 915 int probe_cluster_id) { |
| 904 uint8_t* buffer_to_send_ptr = buffer; | 916 uint8_t* buffer_to_send_ptr = buffer; |
| 905 | 917 |
| 906 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); | 918 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); |
| 907 RTPHeader rtp_header; | 919 RTPHeader rtp_header; |
| 908 rtp_parser.Parse(&rtp_header); | 920 rtp_parser.Parse(&rtp_header); |
| 909 if (!is_retransmit && rtp_header.markerBit) { | 921 if (!is_retransmit && rtp_header.markerBit) { |
| 910 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", | 922 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", |
| 911 capture_time_ms); | 923 capture_time_ms); |
| 912 } | 924 } |
| 913 | 925 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 925 int64_t diff_ms = now_ms - capture_time_ms; | 937 int64_t diff_ms = now_ms - capture_time_ms; |
| 926 UpdateTransmissionTimeOffset(buffer_to_send_ptr, length, rtp_header, | 938 UpdateTransmissionTimeOffset(buffer_to_send_ptr, length, rtp_header, |
| 927 diff_ms); | 939 diff_ms); |
| 928 UpdateAbsoluteSendTime(buffer_to_send_ptr, length, rtp_header, now_ms); | 940 UpdateAbsoluteSendTime(buffer_to_send_ptr, length, rtp_header, now_ms); |
| 929 | 941 |
| 930 PacketOptions options; | 942 PacketOptions options; |
| 931 if (AllocateTransportSequenceNumber(&options.packet_id)) { | 943 if (AllocateTransportSequenceNumber(&options.packet_id)) { |
| 932 if (UpdateTransportSequenceNumber(options.packet_id, buffer_to_send_ptr, | 944 if (UpdateTransportSequenceNumber(options.packet_id, buffer_to_send_ptr, |
| 933 length, rtp_header)) { | 945 length, rtp_header)) { |
| 934 if (transport_feedback_observer_) | 946 if (transport_feedback_observer_) |
| 935 transport_feedback_observer_->AddPacket(options.packet_id, length, | 947 transport_feedback_observer_->AddPacket(options.packet_id, length, true, |
| 936 true); | 948 probe_cluster_id); |
| 937 } | 949 } |
| 938 } | 950 } |
| 939 | 951 |
| 940 if (!is_retransmit && !send_over_rtx) { | 952 if (!is_retransmit && !send_over_rtx) { |
| 941 UpdateDelayStatistics(capture_time_ms, now_ms); | 953 UpdateDelayStatistics(capture_time_ms, now_ms); |
| 942 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); | 954 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); |
| 943 } | 955 } |
| 944 | 956 |
| 945 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); | 957 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); |
| 946 if (ret) { | 958 if (ret) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 } | 1005 } |
| 994 bool fec_enabled; | 1006 bool fec_enabled; |
| 995 uint8_t pt_red; | 1007 uint8_t pt_red; |
| 996 uint8_t pt_fec; | 1008 uint8_t pt_fec; |
| 997 video_->GenericFECStatus(&fec_enabled, &pt_red, &pt_fec); | 1009 video_->GenericFECStatus(&fec_enabled, &pt_red, &pt_fec); |
| 998 return fec_enabled && | 1010 return fec_enabled && |
| 999 header.payloadType == pt_red && | 1011 header.payloadType == pt_red && |
| 1000 buffer[header.headerLength] == pt_fec; | 1012 buffer[header.headerLength] == pt_fec; |
| 1001 } | 1013 } |
| 1002 | 1014 |
| 1003 size_t RTPSender::TimeToSendPadding(size_t bytes) { | 1015 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) { |
| 1004 if (audio_configured_ || bytes == 0) | 1016 if (audio_configured_ || bytes == 0) |
| 1005 return 0; | 1017 return 0; |
| 1006 size_t bytes_sent = TrySendRedundantPayloads(bytes); | 1018 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id); |
| 1007 if (bytes_sent < bytes) | 1019 if (bytes_sent < bytes) |
| 1008 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0); | 1020 bytes_sent += |
| 1021 SendPadData(bytes - bytes_sent, false, 0, 0, probe_cluster_id); |
| 1009 return bytes_sent; | 1022 return bytes_sent; |
| 1010 } | 1023 } |
| 1011 | 1024 |
| 1012 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. | 1025 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. |
| 1013 int32_t RTPSender::SendToNetwork(uint8_t* buffer, | 1026 int32_t RTPSender::SendToNetwork(uint8_t* buffer, |
| 1014 size_t payload_length, | 1027 size_t payload_length, |
| 1015 size_t rtp_header_length, | 1028 size_t rtp_header_length, |
| 1016 int64_t capture_time_ms, | 1029 int64_t capture_time_ms, |
| 1017 StorageType storage, | 1030 StorageType storage, |
| 1018 RtpPacketSender::Priority priority) { | 1031 RtpPacketSender::Priority priority) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 "capture_time_ms", corrected_time_ms); | 1068 "capture_time_ms", corrected_time_ms); |
| 1056 } | 1069 } |
| 1057 return 0; | 1070 return 0; |
| 1058 } | 1071 } |
| 1059 | 1072 |
| 1060 PacketOptions options; | 1073 PacketOptions options; |
| 1061 if (AllocateTransportSequenceNumber(&options.packet_id)) { | 1074 if (AllocateTransportSequenceNumber(&options.packet_id)) { |
| 1062 if (UpdateTransportSequenceNumber(options.packet_id, buffer, length, | 1075 if (UpdateTransportSequenceNumber(options.packet_id, buffer, length, |
| 1063 rtp_header)) { | 1076 rtp_header)) { |
| 1064 if (transport_feedback_observer_) | 1077 if (transport_feedback_observer_) |
| 1065 transport_feedback_observer_->AddPacket(options.packet_id, length, | 1078 transport_feedback_observer_->AddPacket(options.packet_id, length, true, |
| 1066 true); | 1079 PacketInfo::kNotAProbe); |
| 1067 } | 1080 } |
| 1068 } | 1081 } |
| 1069 UpdateDelayStatistics(capture_time_ms, now_ms); | 1082 UpdateDelayStatistics(capture_time_ms, now_ms); |
| 1070 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); | 1083 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); |
| 1071 | 1084 |
| 1072 bool sent = SendPacketToNetwork(buffer, length, options); | 1085 bool sent = SendPacketToNetwork(buffer, length, options); |
| 1073 | 1086 |
| 1074 // Mark the packet as sent in the history even if send failed. Dropping a | 1087 // Mark the packet as sent in the history even if send failed. Dropping a |
| 1075 // packet here should be treated as any other packet drop so we should be | 1088 // packet here should be treated as any other packet drop so we should be |
| 1076 // ready for a retransmission. | 1089 // ready for a retransmission. |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 rtc::CritScope lock(&send_critsect_); | 1924 rtc::CritScope lock(&send_critsect_); |
| 1912 | 1925 |
| 1913 RtpState state; | 1926 RtpState state; |
| 1914 state.sequence_number = sequence_number_rtx_; | 1927 state.sequence_number = sequence_number_rtx_; |
| 1915 state.start_timestamp = start_timestamp_; | 1928 state.start_timestamp = start_timestamp_; |
| 1916 | 1929 |
| 1917 return state; | 1930 return state; |
| 1918 } | 1931 } |
| 1919 | 1932 |
| 1920 } // namespace webrtc | 1933 } // namespace webrtc |
| OLD | NEW |