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