OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/net/rtcp/rtcp.h" | 5 #include "media/cast/net/rtcp/rtcp.h" |
6 | 6 |
7 #include "media/cast/cast_config.h" | 7 #include "media/cast/cast_config.h" |
8 #include "media/cast/cast_defines.h" | 8 #include "media/cast/cast_defines.h" |
9 #include "media/cast/cast_environment.h" | 9 #include "media/cast/cast_environment.h" |
10 #include "media/cast/net/cast_transport_defines.h" | 10 #include "media/cast/net/cast_transport_defines.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 190 } |
191 } | 191 } |
192 return !receiver_log->empty(); | 192 return !receiver_log->empty(); |
193 } | 193 } |
194 | 194 |
195 void Rtcp::SendRtcpFromRtpReceiver( | 195 void Rtcp::SendRtcpFromRtpReceiver( |
196 const RtcpCastMessage* cast_message, | 196 const RtcpCastMessage* cast_message, |
197 base::TimeDelta target_delay, | 197 base::TimeDelta target_delay, |
198 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events, | 198 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events, |
199 RtpReceiverStatistics* rtp_receiver_statistics) { | 199 RtpReceiverStatistics* rtp_receiver_statistics) { |
200 uint32 packet_type_flags = 0; | |
201 | |
202 base::TimeTicks now = clock_->NowTicks(); | 200 base::TimeTicks now = clock_->NowTicks(); |
203 RtcpReportBlock report_block; | 201 RtcpReportBlock report_block; |
204 RtcpReceiverReferenceTimeReport rrtr; | 202 RtcpReceiverReferenceTimeReport rrtr; |
205 | 203 |
206 // Attach our NTP to all RTCP packets; with this information a "smart" sender | 204 // Attach our NTP to all RTCP packets; with this information a "smart" sender |
207 // can make decisions based on how old the RTCP message is. | 205 // can make decisions based on how old the RTCP message is. |
208 packet_type_flags |= kRtcpRrtr; | |
209 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); | 206 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); |
210 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); | 207 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); |
211 | 208 |
212 if (cast_message) { | |
213 packet_type_flags |= kRtcpCast; | |
214 } | |
215 if (rtcp_events) { | |
216 packet_type_flags |= kRtcpReceiverLog; | |
217 } | |
218 // If RTCP is in compound mode then we always send a RR. | |
219 if (rtp_receiver_statistics) { | 209 if (rtp_receiver_statistics) { |
220 packet_type_flags |= kRtcpRr; | |
221 | |
222 report_block.remote_ssrc = 0; // Not needed to set send side. | 210 report_block.remote_ssrc = 0; // Not needed to set send side. |
223 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. | 211 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. |
224 if (rtp_receiver_statistics) { | 212 if (rtp_receiver_statistics) { |
225 rtp_receiver_statistics->GetStatistics( | 213 rtp_receiver_statistics->GetStatistics( |
226 &report_block.fraction_lost, &report_block.cumulative_lost, | 214 &report_block.fraction_lost, &report_block.cumulative_lost, |
227 &report_block.extended_high_sequence_number, &report_block.jitter); | 215 &report_block.extended_high_sequence_number, &report_block.jitter); |
228 } | 216 } |
229 | 217 |
230 report_block.last_sr = last_report_truncated_ntp_; | 218 report_block.last_sr = last_report_truncated_ntp_; |
231 if (!time_last_report_received_.is_null()) { | 219 if (!time_last_report_received_.is_null()) { |
232 uint32 delay_seconds = 0; | 220 uint32 delay_seconds = 0; |
233 uint32 delay_fraction = 0; | 221 uint32 delay_fraction = 0; |
234 base::TimeDelta delta = now - time_last_report_received_; | 222 base::TimeDelta delta = now - time_last_report_received_; |
235 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 223 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
236 &delay_fraction); | 224 &delay_fraction); |
237 report_block.delay_since_last_sr = | 225 report_block.delay_since_last_sr = |
238 ConvertToNtpDiff(delay_seconds, delay_fraction); | 226 ConvertToNtpDiff(delay_seconds, delay_fraction); |
239 } else { | 227 } else { |
240 report_block.delay_since_last_sr = 0; | 228 report_block.delay_since_last_sr = 0; |
241 } | 229 } |
242 } | 230 } |
243 rtcp_sender_->SendRtcpFromRtpReceiver(packet_type_flags, | 231 rtcp_sender_->SendRtcpFromRtpReceiver( |
244 &report_block, | 232 rtp_receiver_statistics ? &report_block : NULL, |
245 &rrtr, | 233 &rrtr, |
246 cast_message, | 234 cast_message, |
247 rtcp_events, | 235 rtcp_events, |
248 target_delay); | 236 target_delay); |
249 } | 237 } |
250 | 238 |
251 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, | 239 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, |
252 uint32 current_time_as_rtp_timestamp, | 240 uint32 current_time_as_rtp_timestamp, |
253 uint32 send_packet_count, | 241 uint32 send_packet_count, |
254 size_t send_octet_count) { | 242 size_t send_octet_count) { |
255 uint32 packet_type_flags = kRtcpSr; | |
256 uint32 current_ntp_seconds = 0; | 243 uint32 current_ntp_seconds = 0; |
257 uint32 current_ntp_fractions = 0; | 244 uint32 current_ntp_fractions = 0; |
258 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, | 245 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, |
259 ¤t_ntp_fractions); | 246 ¤t_ntp_fractions); |
260 SaveLastSentNtpTime(current_time, current_ntp_seconds, | 247 SaveLastSentNtpTime(current_time, current_ntp_seconds, |
261 current_ntp_fractions); | 248 current_ntp_fractions); |
262 | 249 |
263 RtcpDlrrReportBlock dlrr; | |
264 if (!time_last_report_received_.is_null()) { | |
265 packet_type_flags |= kRtcpDlrr; | |
266 dlrr.last_rr = last_report_truncated_ntp_; | |
267 uint32 delay_seconds = 0; | |
268 uint32 delay_fraction = 0; | |
269 base::TimeDelta delta = current_time - time_last_report_received_; | |
270 // TODO(hclam): DLRR is not used by any receiver. Consider removing | |
271 // it. There is one race condition in the computation of the time for | |
272 // DLRR: current time is submitted to this method while | |
273 // |time_last_report_received_| is updated just before that. This can | |
274 // happen if current time is not submitted synchronously. | |
275 if (delta < base::TimeDelta()) | |
276 delta = base::TimeDelta(); | |
277 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | |
278 &delay_fraction); | |
279 | |
280 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction); | |
281 } | |
282 | |
283 RtcpSenderInfo sender_info; | 250 RtcpSenderInfo sender_info; |
284 sender_info.ntp_seconds = current_ntp_seconds; | 251 sender_info.ntp_seconds = current_ntp_seconds; |
285 sender_info.ntp_fraction = current_ntp_fractions; | 252 sender_info.ntp_fraction = current_ntp_fractions; |
286 sender_info.rtp_timestamp = current_time_as_rtp_timestamp; | 253 sender_info.rtp_timestamp = current_time_as_rtp_timestamp; |
287 sender_info.send_packet_count = send_packet_count; | 254 sender_info.send_packet_count = send_packet_count; |
288 sender_info.send_octet_count = send_octet_count; | 255 sender_info.send_octet_count = send_octet_count; |
289 | 256 |
290 rtcp_sender_->SendRtcpFromRtpSender(packet_type_flags, sender_info, dlrr); | 257 rtcp_sender_->SendRtcpFromRtpSender(sender_info); |
291 } | 258 } |
292 | 259 |
293 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) { | 260 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) { |
294 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); | 261 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); |
295 | 262 |
296 const base::TimeTicks now = clock_->NowTicks(); | 263 const base::TimeTicks now = clock_->NowTicks(); |
297 time_last_report_received_ = now; | 264 time_last_report_received_ = now; |
298 | 265 |
299 // TODO(miu): This clock offset calculation does not account for packet | 266 // TODO(miu): This clock offset calculation does not account for packet |
300 // transit time over the network. End2EndTest.EvilNetwork confirms that this | 267 // transit time over the network. End2EndTest.EvilNetwork confirms that this |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 399 } |
433 | 400 |
434 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { | 401 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { |
435 if (log_callback_.is_null()) | 402 if (log_callback_.is_null()) |
436 return; | 403 return; |
437 log_callback_.Run(receiver_log); | 404 log_callback_.Run(receiver_log); |
438 } | 405 } |
439 | 406 |
440 } // namespace cast | 407 } // namespace cast |
441 } // namespace media | 408 } // namespace media |
OLD | NEW |