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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 RTPSender::RTPSender( | 112 RTPSender::RTPSender( |
113 bool audio, | 113 bool audio, |
114 Clock* clock, | 114 Clock* clock, |
115 Transport* transport, | 115 Transport* transport, |
116 RtpAudioFeedback* audio_feedback, | 116 RtpAudioFeedback* audio_feedback, |
117 RtpPacketSender* paced_sender, | 117 RtpPacketSender* paced_sender, |
118 TransportSequenceNumberAllocator* sequence_number_allocator, | 118 TransportSequenceNumberAllocator* sequence_number_allocator, |
119 TransportFeedbackObserver* transport_feedback_observer, | 119 TransportFeedbackObserver* transport_feedback_observer, |
120 BitrateStatisticsObserver* bitrate_callback, | 120 BitrateStatisticsObserver* bitrate_callback, |
121 FrameCountObserver* frame_count_observer, | 121 FrameCountObserver* frame_count_observer, |
122 SendSideDelayObserver* send_side_delay_observer) | 122 SendSideDelayObserver* send_side_delay_observer, |
123 SendPacketObserver* send_packet_observer) | |
123 : clock_(clock), | 124 : clock_(clock), |
124 // TODO(holmer): Remove this conversion when we remove the use of | 125 // TODO(holmer): Remove this conversion when we remove the use of |
125 // TickTime. | 126 // TickTime. |
126 clock_delta_ms_(clock_->TimeInMilliseconds() - | 127 clock_delta_ms_(clock_->TimeInMilliseconds() - |
127 TickTime::MillisecondTimestamp()), | 128 TickTime::MillisecondTimestamp()), |
128 bitrates_(new BitrateAggregator(bitrate_callback)), | 129 bitrates_(new BitrateAggregator(bitrate_callback)), |
129 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()), | 130 total_bitrate_sent_(clock, bitrates_->total_bitrate_observer()), |
130 audio_configured_(audio), | 131 audio_configured_(audio), |
131 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), | 132 audio_(audio ? new RTPSenderAudio(clock, this, audio_feedback) : nullptr), |
132 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), | 133 video_(audio ? nullptr : new RTPSenderVideo(clock, this)), |
(...skipping 17 matching lines...) Expand all Loading... | |
150 // NACK. | 151 // NACK. |
151 nack_byte_count_times_(), | 152 nack_byte_count_times_(), |
152 nack_byte_count_(), | 153 nack_byte_count_(), |
153 nack_bitrate_(clock, bitrates_->retransmit_bitrate_observer()), | 154 nack_bitrate_(clock, bitrates_->retransmit_bitrate_observer()), |
154 packet_history_(clock), | 155 packet_history_(clock), |
155 // Statistics | 156 // Statistics |
156 statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()), | 157 statistics_crit_(CriticalSectionWrapper::CreateCriticalSection()), |
157 rtp_stats_callback_(NULL), | 158 rtp_stats_callback_(NULL), |
158 frame_count_observer_(frame_count_observer), | 159 frame_count_observer_(frame_count_observer), |
159 send_side_delay_observer_(send_side_delay_observer), | 160 send_side_delay_observer_(send_side_delay_observer), |
161 send_packet_observer_(send_packet_observer), | |
160 // RTP variables | 162 // RTP variables |
161 start_timestamp_forced_(false), | 163 start_timestamp_forced_(false), |
162 start_timestamp_(0), | 164 start_timestamp_(0), |
163 ssrc_db_(*SSRCDatabase::GetSSRCDatabase()), | 165 ssrc_db_(*SSRCDatabase::GetSSRCDatabase()), |
164 remote_ssrc_(0), | 166 remote_ssrc_(0), |
165 sequence_number_forced_(false), | 167 sequence_number_forced_(false), |
166 ssrc_forced_(false), | 168 ssrc_forced_(false), |
167 timestamp_(0), | 169 timestamp_(0), |
168 capture_time_ms_(0), | 170 capture_time_ms_(0), |
169 last_timestamp_time_ms_(0), | 171 last_timestamp_time_ms_(0), |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 | 880 |
879 if (!packet_history_.GetPacketAndSetSendTime(sequence_number, | 881 if (!packet_history_.GetPacketAndSetSendTime(sequence_number, |
880 0, | 882 0, |
881 retransmission, | 883 retransmission, |
882 data_buffer, | 884 data_buffer, |
883 &length, | 885 &length, |
884 &stored_time_ms)) { | 886 &stored_time_ms)) { |
885 // Packet cannot be found. Allow sending to continue. | 887 // Packet cannot be found. Allow sending to continue. |
886 return true; | 888 return true; |
887 } | 889 } |
888 if (!retransmission && capture_time_ms > 0) { | 890 |
889 UpdateDelayStatistics(capture_time_ms, clock_->TimeInMilliseconds()); | |
890 } | |
891 int rtx; | 891 int rtx; |
892 { | 892 { |
893 CriticalSectionScoped lock(send_critsect_.get()); | 893 CriticalSectionScoped lock(send_critsect_.get()); |
894 rtx = rtx_; | 894 rtx = rtx_; |
895 } | 895 } |
896 return PrepareAndSendPacket(data_buffer, | 896 return PrepareAndSendPacket(data_buffer, |
897 length, | 897 length, |
898 capture_time_ms, | 898 capture_time_ms, |
899 retransmission && (rtx & kRtxRetransmitted) > 0, | 899 retransmission && (rtx & kRtxRetransmitted) > 0, |
900 retransmission); | 900 retransmission); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 PacketOptions options; | 939 PacketOptions options; |
940 if (using_transport_seq) { | 940 if (using_transport_seq) { |
941 options.packet_id = | 941 options.packet_id = |
942 UpdateTransportSequenceNumber(buffer_to_send_ptr, length, rtp_header); | 942 UpdateTransportSequenceNumber(buffer_to_send_ptr, length, rtp_header); |
943 } | 943 } |
944 | 944 |
945 if (using_transport_seq && transport_feedback_observer_) { | 945 if (using_transport_seq && transport_feedback_observer_) { |
946 transport_feedback_observer_->AddPacket(options.packet_id, length, true); | 946 transport_feedback_observer_->AddPacket(options.packet_id, length, true); |
947 } | 947 } |
948 | 948 |
949 if (!is_retransmit && !send_over_rtx) { | |
950 UpdateDelayStatistics(capture_time_ms, now_ms); | |
951 UpdateOnSendPacket(capture_time_ms, &options.packet_id); | |
952 } | |
953 | |
949 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); | 954 bool ret = SendPacketToNetwork(buffer_to_send_ptr, length, options); |
950 if (ret) { | 955 if (ret) { |
951 CriticalSectionScoped lock(send_critsect_.get()); | 956 CriticalSectionScoped lock(send_critsect_.get()); |
952 media_has_been_sent_ = true; | 957 media_has_been_sent_ = true; |
953 } | 958 } |
954 UpdateRtpStats(buffer_to_send_ptr, length, rtp_header, send_over_rtx, | 959 UpdateRtpStats(buffer_to_send_ptr, length, rtp_header, send_over_rtx, |
955 is_retransmit); | 960 is_retransmit); |
956 return ret; | 961 return ret; |
957 } | 962 } |
958 | 963 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1058 payload_length, false); | 1063 payload_length, false); |
1059 if (last_capture_time_ms_sent_ == 0 || | 1064 if (last_capture_time_ms_sent_ == 0 || |
1060 corrected_time_ms > last_capture_time_ms_sent_) { | 1065 corrected_time_ms > last_capture_time_ms_sent_) { |
1061 last_capture_time_ms_sent_ = corrected_time_ms; | 1066 last_capture_time_ms_sent_ = corrected_time_ms; |
1062 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 1067 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
1063 "PacedSend", corrected_time_ms, | 1068 "PacedSend", corrected_time_ms, |
1064 "capture_time_ms", corrected_time_ms); | 1069 "capture_time_ms", corrected_time_ms); |
1065 } | 1070 } |
1066 return 0; | 1071 return 0; |
1067 } | 1072 } |
1068 if (capture_time_ms > 0) { | 1073 PacketOptions options; |
1069 UpdateDelayStatistics(capture_time_ms, now_ms); | 1074 UpdateDelayStatistics(capture_time_ms, now_ms); |
1070 } | 1075 UpdateOnSendPacket(capture_time_ms, &options.packet_id); |
stefan-webrtc
2015/12/10 08:37:49
I don't think we have to add it here since this pa
åsapersson
2015/12/15 14:28:26
OK, removed from this path.
| |
1071 | 1076 |
1072 size_t length = payload_length + rtp_header_length; | 1077 size_t length = payload_length + rtp_header_length; |
1073 bool sent = SendPacketToNetwork(buffer, length, PacketOptions()); | 1078 bool sent = SendPacketToNetwork(buffer, length, options); |
1074 | 1079 |
1075 // Mark the packet as sent in the history even if send failed. Dropping a | 1080 // Mark the packet as sent in the history even if send failed. Dropping a |
1076 // packet here should be treated as any other packet drop so we should be | 1081 // packet here should be treated as any other packet drop so we should be |
1077 // ready for a retransmission. | 1082 // ready for a retransmission. |
1078 packet_history_.SetSent(rtp_header.sequenceNumber); | 1083 packet_history_.SetSent(rtp_header.sequenceNumber); |
1079 | 1084 |
1080 if (!sent) | 1085 if (!sent) |
1081 return -1; | 1086 return -1; |
1082 | 1087 |
1083 { | 1088 { |
1084 CriticalSectionScoped lock(send_critsect_.get()); | 1089 CriticalSectionScoped lock(send_critsect_.get()); |
1085 media_has_been_sent_ = true; | 1090 media_has_been_sent_ = true; |
1086 } | 1091 } |
1087 UpdateRtpStats(buffer, length, rtp_header, false, false); | 1092 UpdateRtpStats(buffer, length, rtp_header, false, false); |
1088 return 0; | 1093 return 0; |
1089 } | 1094 } |
1090 | 1095 |
1091 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { | 1096 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { |
1092 if (!send_side_delay_observer_) | 1097 if (!send_side_delay_observer_ || capture_time_ms <= 0) |
1093 return; | 1098 return; |
1094 | 1099 |
1095 uint32_t ssrc; | 1100 uint32_t ssrc; |
1096 int avg_delay_ms = 0; | 1101 int avg_delay_ms = 0; |
1097 int max_delay_ms = 0; | 1102 int max_delay_ms = 0; |
1098 { | 1103 { |
1099 CriticalSectionScoped lock(send_critsect_.get()); | 1104 CriticalSectionScoped lock(send_critsect_.get()); |
1100 ssrc = ssrc_; | 1105 ssrc = ssrc_; |
1101 } | 1106 } |
1102 { | 1107 { |
(...skipping 11 matching lines...) Expand all Loading... | |
1114 ++num_delays; | 1119 ++num_delays; |
1115 } | 1120 } |
1116 if (num_delays == 0) | 1121 if (num_delays == 0) |
1117 return; | 1122 return; |
1118 avg_delay_ms = (avg_delay_ms + num_delays / 2) / num_delays; | 1123 avg_delay_ms = (avg_delay_ms + num_delays / 2) / num_delays; |
1119 } | 1124 } |
1120 send_side_delay_observer_->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, | 1125 send_side_delay_observer_->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, |
1121 ssrc); | 1126 ssrc); |
1122 } | 1127 } |
1123 | 1128 |
1129 void RTPSender::UpdateOnSendPacket(int64_t capture_time_ms, int* packet_id) { | |
1130 if (!send_packet_observer_ || !transport_sequence_number_allocator_ || | |
1131 capture_time_ms <= 0) | |
1132 return; | |
1133 | |
1134 uint32_t ssrc; | |
1135 { | |
1136 CriticalSectionScoped lock(send_critsect_.get()); | |
1137 ssrc = ssrc_; | |
stefan-webrtc
2015/12/10 08:37:49
The ssrc is available without locking from the rtp
åsapersson
2015/12/15 14:28:26
Done.
| |
1138 } | |
1139 if (*packet_id == -1) | |
1140 *packet_id = transport_sequence_number_allocator_->AllocateSequenceNumber(); | |
stefan-webrtc
2015/12/10 08:37:49
Can we move this out of this method and call it on
åsapersson
2015/12/15 14:28:26
Done.
| |
1141 | |
1142 send_packet_observer_->OnSendPacket(*packet_id, capture_time_ms, ssrc); | |
stefan-webrtc
2015/12/10 08:37:49
Is it possible to unify this callback with the cal
åsapersson
2015/12/15 14:28:26
I guess it can be done if we do not want to do it
stefan-webrtc
2016/01/18 19:48:25
Why doesn't it work per stream? I don't think I un
| |
1143 } | |
1144 | |
1124 void RTPSender::ProcessBitrate() { | 1145 void RTPSender::ProcessBitrate() { |
1125 CriticalSectionScoped cs(send_critsect_.get()); | 1146 CriticalSectionScoped cs(send_critsect_.get()); |
1126 total_bitrate_sent_.Process(); | 1147 total_bitrate_sent_.Process(); |
1127 nack_bitrate_.Process(); | 1148 nack_bitrate_.Process(); |
1128 if (audio_configured_) { | 1149 if (audio_configured_) { |
1129 return; | 1150 return; |
1130 } | 1151 } |
1131 video_->ProcessBitrate(); | 1152 video_->ProcessBitrate(); |
1132 } | 1153 } |
1133 | 1154 |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1905 CriticalSectionScoped lock(send_critsect_.get()); | 1926 CriticalSectionScoped lock(send_critsect_.get()); |
1906 | 1927 |
1907 RtpState state; | 1928 RtpState state; |
1908 state.sequence_number = sequence_number_rtx_; | 1929 state.sequence_number = sequence_number_rtx_; |
1909 state.start_timestamp = start_timestamp_; | 1930 state.start_timestamp = start_timestamp_; |
1910 | 1931 |
1911 return state; | 1932 return state; |
1912 } | 1933 } |
1913 | 1934 |
1914 } // namespace webrtc | 1935 } // namespace webrtc |
OLD | NEW |