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" |
| 11 #include "media/cast/net/pacing/paced_sender.h" |
| 12 #include "media/cast/net/rtcp/rtcp_builder.h" |
11 #include "media/cast/net/rtcp/rtcp_defines.h" | 13 #include "media/cast/net/rtcp/rtcp_defines.h" |
12 #include "media/cast/net/rtcp/rtcp_sender.h" | |
13 #include "media/cast/net/rtcp/rtcp_utility.h" | 14 #include "media/cast/net/rtcp/rtcp_utility.h" |
14 | 15 |
15 using base::TimeDelta; | 16 using base::TimeDelta; |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 namespace cast { | 19 namespace cast { |
19 | 20 |
20 static const int32 kMaxRttMs = 10000; // 10 seconds. | 21 static const int32 kMaxRttMs = 10000; // 10 seconds. |
21 // Reject packets that are older than 0.5 seconds older than | 22 // Reject packets that are older than 0.5 seconds older than |
22 // the newest packet we've seen so far. This protect internal | 23 // the newest packet we've seen so far. This protect internal |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const RtcpRttCallback& rtt_callback, | 58 const RtcpRttCallback& rtt_callback, |
58 const RtcpLogMessageCallback& log_callback, | 59 const RtcpLogMessageCallback& log_callback, |
59 base::TickClock* clock, | 60 base::TickClock* clock, |
60 PacedPacketSender* packet_sender, | 61 PacedPacketSender* packet_sender, |
61 uint32 local_ssrc, | 62 uint32 local_ssrc, |
62 uint32 remote_ssrc) | 63 uint32 remote_ssrc) |
63 : cast_callback_(cast_callback), | 64 : cast_callback_(cast_callback), |
64 rtt_callback_(rtt_callback), | 65 rtt_callback_(rtt_callback), |
65 log_callback_(log_callback), | 66 log_callback_(log_callback), |
66 clock_(clock), | 67 clock_(clock), |
67 rtcp_sender_(new RtcpSender(packet_sender, local_ssrc)), | 68 rtcp_builder_(local_ssrc), |
| 69 packet_sender_(packet_sender), |
68 local_ssrc_(local_ssrc), | 70 local_ssrc_(local_ssrc), |
69 remote_ssrc_(remote_ssrc), | 71 remote_ssrc_(remote_ssrc), |
70 last_report_truncated_ntp_(0), | 72 last_report_truncated_ntp_(0), |
71 local_clock_ahead_by_(ClockDriftSmoother::GetDefaultTimeConstant()), | 73 local_clock_ahead_by_(ClockDriftSmoother::GetDefaultTimeConstant()), |
72 lip_sync_rtp_timestamp_(0), | 74 lip_sync_rtp_timestamp_(0), |
73 lip_sync_ntp_timestamp_(0), | 75 lip_sync_ntp_timestamp_(0), |
74 min_rtt_(TimeDelta::FromMilliseconds(kMaxRttMs)), | 76 min_rtt_(TimeDelta::FromMilliseconds(kMaxRttMs)), |
75 number_of_rtt_in_avg_(0) { | 77 number_of_rtt_in_avg_(0) { |
76 } | 78 } |
77 | 79 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 uint32 delay_fraction = 0; | 223 uint32 delay_fraction = 0; |
222 base::TimeDelta delta = now - time_last_report_received_; | 224 base::TimeDelta delta = now - time_last_report_received_; |
223 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 225 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
224 &delay_fraction); | 226 &delay_fraction); |
225 report_block.delay_since_last_sr = | 227 report_block.delay_since_last_sr = |
226 ConvertToNtpDiff(delay_seconds, delay_fraction); | 228 ConvertToNtpDiff(delay_seconds, delay_fraction); |
227 } else { | 229 } else { |
228 report_block.delay_since_last_sr = 0; | 230 report_block.delay_since_last_sr = 0; |
229 } | 231 } |
230 } | 232 } |
231 rtcp_sender_->SendRtcpFromRtpReceiver( | 233 packet_sender_->SendRtcpPacket( |
232 rtp_receiver_statistics ? &report_block : NULL, | 234 local_ssrc_, |
233 &rrtr, | 235 rtcp_builder_.BuildRtcpFromReceiver( |
234 cast_message, | 236 rtp_receiver_statistics ? &report_block : NULL, |
235 rtcp_events, | 237 &rrtr, |
236 target_delay); | 238 cast_message, |
| 239 rtcp_events, |
| 240 target_delay)); |
237 } | 241 } |
238 | 242 |
239 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, | 243 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, |
240 uint32 current_time_as_rtp_timestamp, | 244 uint32 current_time_as_rtp_timestamp, |
241 uint32 send_packet_count, | 245 uint32 send_packet_count, |
242 size_t send_octet_count) { | 246 size_t send_octet_count) { |
243 uint32 current_ntp_seconds = 0; | 247 uint32 current_ntp_seconds = 0; |
244 uint32 current_ntp_fractions = 0; | 248 uint32 current_ntp_fractions = 0; |
245 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, | 249 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, |
246 ¤t_ntp_fractions); | 250 ¤t_ntp_fractions); |
247 SaveLastSentNtpTime(current_time, current_ntp_seconds, | 251 SaveLastSentNtpTime(current_time, current_ntp_seconds, |
248 current_ntp_fractions); | 252 current_ntp_fractions); |
249 | 253 |
250 RtcpSenderInfo sender_info; | 254 RtcpSenderInfo sender_info; |
251 sender_info.ntp_seconds = current_ntp_seconds; | 255 sender_info.ntp_seconds = current_ntp_seconds; |
252 sender_info.ntp_fraction = current_ntp_fractions; | 256 sender_info.ntp_fraction = current_ntp_fractions; |
253 sender_info.rtp_timestamp = current_time_as_rtp_timestamp; | 257 sender_info.rtp_timestamp = current_time_as_rtp_timestamp; |
254 sender_info.send_packet_count = send_packet_count; | 258 sender_info.send_packet_count = send_packet_count; |
255 sender_info.send_octet_count = send_octet_count; | 259 sender_info.send_octet_count = send_octet_count; |
256 | 260 |
257 rtcp_sender_->SendRtcpFromRtpSender(sender_info); | 261 packet_sender_->SendRtcpPacket( |
| 262 local_ssrc_, |
| 263 rtcp_builder_.BuildRtcpFromSender(sender_info)); |
258 } | 264 } |
259 | 265 |
260 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) { | 266 void Rtcp::OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction) { |
261 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); | 267 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); |
262 | 268 |
263 const base::TimeTicks now = clock_->NowTicks(); | 269 const base::TimeTicks now = clock_->NowTicks(); |
264 time_last_report_received_ = now; | 270 time_last_report_received_ = now; |
265 | 271 |
266 // TODO(miu): This clock offset calculation does not account for packet | 272 // TODO(miu): This clock offset calculation does not account for packet |
267 // transit time over the network. End2EndTest.EvilNetwork confirms that this | 273 // transit time over the network. End2EndTest.EvilNetwork confirms that this |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 405 } |
400 | 406 |
401 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { | 407 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { |
402 if (log_callback_.is_null()) | 408 if (log_callback_.is_null()) |
403 return; | 409 return; |
404 log_callback_.Run(receiver_log); | 410 log_callback_.Run(receiver_log); |
405 } | 411 } |
406 | 412 |
407 } // namespace cast | 413 } // namespace cast |
408 } // namespace media | 414 } // namespace media |
OLD | NEW |