| 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 int probe_cluster_id) { |
| 593 // Always send full padding packets. This is accounted for by the | 596 // Always send full padding packets. This is accounted for by the |
| 594 // RtpPacketSender, | 597 // RtpPacketSender, |
| 595 // which will make sure we don't send too much padding even if a single packet | 598 // which will make sure we don't send too much padding even if a single packet |
| 596 // is larger than requested. | 599 // is larger than requested. |
| 597 size_t padding_bytes_in_packet = | 600 size_t padding_bytes_in_packet = |
| 598 std::min(MaxDataPayloadLength(), kMaxPaddingLength); | 601 std::min(MaxDataPayloadLength(), kMaxPaddingLength); |
| 599 size_t bytes_sent = 0; | 602 size_t bytes_sent = 0; |
| 600 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( | 603 bool using_transport_seq = rtp_header_extension_map_.IsRegistered( |
| 601 kRtpExtensionTransportSequenceNumber) && | 604 kRtpExtensionTransportSequenceNumber) && |
| 602 transport_sequence_number_allocator_; | 605 transport_sequence_number_allocator_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 } | 673 } |
| 671 | 674 |
| 672 UpdateAbsoluteSendTime(padding_packet, length, rtp_header, now_ms); | 675 UpdateAbsoluteSendTime(padding_packet, length, rtp_header, now_ms); |
| 673 | 676 |
| 674 PacketOptions options; | 677 PacketOptions options; |
| 675 if (AllocateTransportSequenceNumber(&options.packet_id)) { | 678 if (AllocateTransportSequenceNumber(&options.packet_id)) { |
| 676 if (UpdateTransportSequenceNumber(options.packet_id, padding_packet, | 679 if (UpdateTransportSequenceNumber(options.packet_id, padding_packet, |
| 677 length, rtp_header)) { | 680 length, rtp_header)) { |
| 678 if (transport_feedback_observer_) | 681 if (transport_feedback_observer_) |
| 679 transport_feedback_observer_->AddPacket(options.packet_id, length, | 682 transport_feedback_observer_->AddPacket(options.packet_id, length, |
| 680 true); | 683 true, probe_cluster_id); |
| 681 } | 684 } |
| 682 } | 685 } |
| 683 | 686 |
| 684 if (!SendPacketToNetwork(padding_packet, length, options)) | 687 if (!SendPacketToNetwork(padding_packet, length, options)) |
| 685 break; | 688 break; |
| 686 | 689 |
| 687 bytes_sent += padding_bytes_in_packet; | 690 bytes_sent += padding_bytes_in_packet; |
| 688 UpdateRtpStats(padding_packet, length, rtp_header, over_rtx, false); | 691 UpdateRtpStats(padding_packet, length, rtp_header, over_rtx, false); |
| 689 } | 692 } |
| 690 | 693 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 corrected_capture_tims_ms, length - header.headerLength, true); | 729 corrected_capture_tims_ms, length - header.headerLength, true); |
| 727 | 730 |
| 728 return length; | 731 return length; |
| 729 } | 732 } |
| 730 int rtx = kRtxOff; | 733 int rtx = kRtxOff; |
| 731 { | 734 { |
| 732 rtc::CritScope lock(&send_critsect_); | 735 rtc::CritScope lock(&send_critsect_); |
| 733 rtx = rtx_; | 736 rtx = rtx_; |
| 734 } | 737 } |
| 735 if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms, | 738 if (!PrepareAndSendPacket(data_buffer, length, capture_time_ms, |
| 736 (rtx & kRtxRetransmitted) > 0, true)) { | 739 (rtx & kRtxRetransmitted) > 0, true, |
| 740 PacketInfo::kNotAProbe)) { |
| 737 return -1; | 741 return -1; |
| 738 } | 742 } |
| 739 return static_cast<int32_t>(length); | 743 return static_cast<int32_t>(length); |
| 740 } | 744 } |
| 741 | 745 |
| 742 bool RTPSender::SendPacketToNetwork(const uint8_t* packet, | 746 bool RTPSender::SendPacketToNetwork(const uint8_t* packet, |
| 743 size_t size, | 747 size_t size, |
| 744 const PacketOptions& options) { | 748 const PacketOptions& options) { |
| 745 int bytes_sent = -1; | 749 int bytes_sent = -1; |
| 746 if (transport_) { | 750 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]; | 866 nack_byte_count_[i + 1] = nack_byte_count_[i]; |
| 863 nack_byte_count_times_[i + 1] = nack_byte_count_times_[i]; | 867 nack_byte_count_times_[i + 1] = nack_byte_count_times_[i]; |
| 864 } | 868 } |
| 865 nack_byte_count_[0] = bytes; | 869 nack_byte_count_[0] = bytes; |
| 866 nack_byte_count_times_[0] = now; | 870 nack_byte_count_times_[0] = now; |
| 867 } | 871 } |
| 868 | 872 |
| 869 // Called from pacer when we can send the packet. | 873 // Called from pacer when we can send the packet. |
| 870 bool RTPSender::TimeToSendPacket(uint16_t sequence_number, | 874 bool RTPSender::TimeToSendPacket(uint16_t sequence_number, |
| 871 int64_t capture_time_ms, | 875 int64_t capture_time_ms, |
| 872 bool retransmission) { | 876 bool retransmission, |
| 877 int probe_cluster_id) { |
| 873 size_t length = IP_PACKET_SIZE; | 878 size_t length = IP_PACKET_SIZE; |
| 874 uint8_t data_buffer[IP_PACKET_SIZE]; | 879 uint8_t data_buffer[IP_PACKET_SIZE]; |
| 875 int64_t stored_time_ms; | 880 int64_t stored_time_ms; |
| 876 | 881 |
| 877 if (!packet_history_.GetPacketAndSetSendTime(sequence_number, | 882 if (!packet_history_.GetPacketAndSetSendTime(sequence_number, |
| 878 0, | 883 0, |
| 879 retransmission, | 884 retransmission, |
| 880 data_buffer, | 885 data_buffer, |
| 881 &length, | 886 &length, |
| 882 &stored_time_ms)) { | 887 &stored_time_ms)) { |
| 883 // Packet cannot be found. Allow sending to continue. | 888 // Packet cannot be found. Allow sending to continue. |
| 884 return true; | 889 return true; |
| 885 } | 890 } |
| 886 | 891 |
| 887 int rtx; | 892 int rtx; |
| 888 { | 893 { |
| 889 rtc::CritScope lock(&send_critsect_); | 894 rtc::CritScope lock(&send_critsect_); |
| 890 rtx = rtx_; | 895 rtx = rtx_; |
| 891 } | 896 } |
| 892 return PrepareAndSendPacket(data_buffer, | 897 return PrepareAndSendPacket(data_buffer, length, capture_time_ms, |
| 893 length, | |
| 894 capture_time_ms, | |
| 895 retransmission && (rtx & kRtxRetransmitted) > 0, | 898 retransmission && (rtx & kRtxRetransmitted) > 0, |
| 896 retransmission); | 899 retransmission, probe_cluster_id); |
| 897 } | 900 } |
| 898 | 901 |
| 899 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, | 902 bool RTPSender::PrepareAndSendPacket(uint8_t* buffer, |
| 900 size_t length, | 903 size_t length, |
| 901 int64_t capture_time_ms, | 904 int64_t capture_time_ms, |
| 902 bool send_over_rtx, | 905 bool send_over_rtx, |
| 903 bool is_retransmit) { | 906 bool is_retransmit, |
| 907 int probe_cluster_id) { |
| 904 uint8_t* buffer_to_send_ptr = buffer; | 908 uint8_t* buffer_to_send_ptr = buffer; |
| 905 | 909 |
| 906 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); | 910 RtpUtility::RtpHeaderParser rtp_parser(buffer, length); |
| 907 RTPHeader rtp_header; | 911 RTPHeader rtp_header; |
| 908 rtp_parser.Parse(&rtp_header); | 912 rtp_parser.Parse(&rtp_header); |
| 909 if (!is_retransmit && rtp_header.markerBit) { | 913 if (!is_retransmit && rtp_header.markerBit) { |
| 910 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", | 914 TRACE_EVENT_ASYNC_END0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PacedSend", |
| 911 capture_time_ms); | 915 capture_time_ms); |
| 912 } | 916 } |
| 913 | 917 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 925 int64_t diff_ms = now_ms - capture_time_ms; | 929 int64_t diff_ms = now_ms - capture_time_ms; |
| 926 UpdateTransmissionTimeOffset(buffer_to_send_ptr, length, rtp_header, | 930 UpdateTransmissionTimeOffset(buffer_to_send_ptr, length, rtp_header, |
| 927 diff_ms); | 931 diff_ms); |
| 928 UpdateAbsoluteSendTime(buffer_to_send_ptr, length, rtp_header, now_ms); | 932 UpdateAbsoluteSendTime(buffer_to_send_ptr, length, rtp_header, now_ms); |
| 929 | 933 |
| 930 PacketOptions options; | 934 PacketOptions options; |
| 931 if (AllocateTransportSequenceNumber(&options.packet_id)) { | 935 if (AllocateTransportSequenceNumber(&options.packet_id)) { |
| 932 if (UpdateTransportSequenceNumber(options.packet_id, buffer_to_send_ptr, | 936 if (UpdateTransportSequenceNumber(options.packet_id, buffer_to_send_ptr, |
| 933 length, rtp_header)) { | 937 length, rtp_header)) { |
| 934 if (transport_feedback_observer_) | 938 if (transport_feedback_observer_) |
| 935 transport_feedback_observer_->AddPacket(options.packet_id, length, | 939 transport_feedback_observer_->AddPacket(options.packet_id, length, true, |
| 936 true); | 940 probe_cluster_id); |
| 937 } | 941 } |
| 938 } | 942 } |
| 939 | 943 |
| 940 if (!is_retransmit && !send_over_rtx) { | 944 if (!is_retransmit && !send_over_rtx) { |
| 941 UpdateDelayStatistics(capture_time_ms, now_ms); | 945 UpdateDelayStatistics(capture_time_ms, now_ms); |
| 942 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); | 946 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); |
| 943 } | 947 } |
| 944 | 948 |
| 945 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); | 949 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); |
| 946 if (ret) { | 950 if (ret) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 } | 997 } |
| 994 bool fec_enabled; | 998 bool fec_enabled; |
| 995 uint8_t pt_red; | 999 uint8_t pt_red; |
| 996 uint8_t pt_fec; | 1000 uint8_t pt_fec; |
| 997 video_->GenericFECStatus(&fec_enabled, &pt_red, &pt_fec); | 1001 video_->GenericFECStatus(&fec_enabled, &pt_red, &pt_fec); |
| 998 return fec_enabled && | 1002 return fec_enabled && |
| 999 header.payloadType == pt_red && | 1003 header.payloadType == pt_red && |
| 1000 buffer[header.headerLength] == pt_fec; | 1004 buffer[header.headerLength] == pt_fec; |
| 1001 } | 1005 } |
| 1002 | 1006 |
| 1003 size_t RTPSender::TimeToSendPadding(size_t bytes) { | 1007 size_t RTPSender::TimeToSendPadding(size_t bytes, int probe_cluster_id) { |
| 1004 if (audio_configured_ || bytes == 0) | 1008 if (audio_configured_ || bytes == 0) |
| 1005 return 0; | 1009 return 0; |
| 1006 size_t bytes_sent = TrySendRedundantPayloads(bytes); | 1010 size_t bytes_sent = TrySendRedundantPayloads(bytes, probe_cluster_id); |
| 1007 if (bytes_sent < bytes) | 1011 if (bytes_sent < bytes) |
| 1008 bytes_sent += SendPadData(bytes - bytes_sent, false, 0, 0); | 1012 bytes_sent += |
| 1013 SendPadData(bytes - bytes_sent, false, 0, 0, probe_cluster_id); |
| 1009 return bytes_sent; | 1014 return bytes_sent; |
| 1010 } | 1015 } |
| 1011 | 1016 |
| 1012 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. | 1017 // TODO(pwestin): send in the RtpHeaderParser to avoid parsing it again. |
| 1013 int32_t RTPSender::SendToNetwork(uint8_t* buffer, | 1018 int32_t RTPSender::SendToNetwork(uint8_t* buffer, |
| 1014 size_t payload_length, | 1019 size_t payload_length, |
| 1015 size_t rtp_header_length, | 1020 size_t rtp_header_length, |
| 1016 int64_t capture_time_ms, | 1021 int64_t capture_time_ms, |
| 1017 StorageType storage, | 1022 StorageType storage, |
| 1018 RtpPacketSender::Priority priority) { | 1023 RtpPacketSender::Priority priority) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 "capture_time_ms", corrected_time_ms); | 1060 "capture_time_ms", corrected_time_ms); |
| 1056 } | 1061 } |
| 1057 return 0; | 1062 return 0; |
| 1058 } | 1063 } |
| 1059 | 1064 |
| 1060 PacketOptions options; | 1065 PacketOptions options; |
| 1061 if (AllocateTransportSequenceNumber(&options.packet_id)) { | 1066 if (AllocateTransportSequenceNumber(&options.packet_id)) { |
| 1062 if (UpdateTransportSequenceNumber(options.packet_id, buffer, length, | 1067 if (UpdateTransportSequenceNumber(options.packet_id, buffer, length, |
| 1063 rtp_header)) { | 1068 rtp_header)) { |
| 1064 if (transport_feedback_observer_) | 1069 if (transport_feedback_observer_) |
| 1065 transport_feedback_observer_->AddPacket(options.packet_id, length, | 1070 transport_feedback_observer_->AddPacket(options.packet_id, length, true, |
| 1066 true); | 1071 PacketInfo::kNotAProbe); |
| 1067 } | 1072 } |
| 1068 } | 1073 } |
| 1069 UpdateDelayStatistics(capture_time_ms, now_ms); | 1074 UpdateDelayStatistics(capture_time_ms, now_ms); |
| 1070 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); | 1075 UpdateOnSendPacket(options.packet_id, capture_time_ms, rtp_header.ssrc); |
| 1071 | 1076 |
| 1072 bool sent = SendPacketToNetwork(buffer, length, options); | 1077 bool sent = SendPacketToNetwork(buffer, length, options); |
| 1073 | 1078 |
| 1074 // Mark the packet as sent in the history even if send failed. Dropping a | 1079 // 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 | 1080 // packet here should be treated as any other packet drop so we should be |
| 1076 // ready for a retransmission. | 1081 // ready for a retransmission. |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 rtc::CritScope lock(&send_critsect_); | 1916 rtc::CritScope lock(&send_critsect_); |
| 1912 | 1917 |
| 1913 RtpState state; | 1918 RtpState state; |
| 1914 state.sequence_number = sequence_number_rtx_; | 1919 state.sequence_number = sequence_number_rtx_; |
| 1915 state.start_timestamp = start_timestamp_; | 1920 state.start_timestamp = start_timestamp_; |
| 1916 | 1921 |
| 1917 return state; | 1922 return state; |
| 1918 } | 1923 } |
| 1919 | 1924 |
| 1920 } // namespace webrtc | 1925 } // namespace webrtc |
| OLD | NEW |