OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/big_endian.h" |
6 | 6 #include "base/time/tick_clock.h" |
7 #include <limits> | |
8 | |
9 #include "base/time/time.h" | |
10 #include "media/cast/cast_environment.h" | |
11 #include "media/cast/constants.h" | |
12 #include "media/cast/net/cast_transport_config.h" | |
13 #include "media/cast/net/cast_transport_defines.h" | |
14 #include "media/cast/net/pacing/paced_sender.h" | 7 #include "media/cast/net/pacing/paced_sender.h" |
| 8 #include "media/cast/net/rtcp/receiver_rtcp_session.h" |
15 #include "media/cast/net/rtcp/rtcp_builder.h" | 9 #include "media/cast/net/rtcp/rtcp_builder.h" |
16 #include "media/cast/net/rtcp/rtcp_defines.h" | 10 #include "media/cast/net/rtcp/rtcp_defines.h" |
17 #include "media/cast/net/rtcp/rtcp_utility.h" | 11 #include "media/cast/net/rtcp/rtcp_utility.h" |
18 | 12 |
19 using base::TimeDelta; | |
20 | |
21 namespace media { | 13 namespace media { |
22 namespace cast { | 14 namespace cast { |
23 | 15 |
24 namespace { | 16 namespace { |
25 | 17 |
26 enum { | |
27 kStatsHistoryWindowMs = 10000, // 10 seconds. | |
28 | |
29 // Reject packets that are older than 0.5 seconds older than | |
30 // the newest packet we've seen so far. This protects internal | |
31 // states from crazy routers. (Based on RRTR) | |
32 kOutOfOrderMaxAgeMs = 500, | |
33 | |
34 // Minimum number of bytes required to make a valid RTCP packet. | |
35 kMinLengthOfRtcp = 8, | |
36 }; | |
37 | |
38 // Create a NTP diff from seconds and fractions of seconds; delay_fraction is | 18 // Create a NTP diff from seconds and fractions of seconds; delay_fraction is |
39 // fractions of a second where 0x80000000 is half a second. | 19 // fractions of a second where 0x80000000 is half a second. |
40 uint32_t ConvertToNtpDiff(uint32_t delay_seconds, uint32_t delay_fraction) { | 20 uint32_t ConvertToNtpDiff(uint32_t delay_seconds, uint32_t delay_fraction) { |
41 return ((delay_seconds & 0x0000FFFF) << 16) + | 21 return ((delay_seconds & 0x0000FFFF) << 16) + |
42 ((delay_fraction & 0xFFFF0000) >> 16); | 22 ((delay_fraction & 0xFFFF0000) >> 16); |
43 } | 23 } |
44 | 24 |
45 // Parse a NTP diff value into a base::TimeDelta. | |
46 base::TimeDelta ConvertFromNtpDiff(uint32_t ntp_delay) { | |
47 int64_t delay_us = | |
48 (ntp_delay & 0x0000ffff) * base::Time::kMicrosecondsPerSecond; | |
49 delay_us >>= 16; | |
50 delay_us += | |
51 ((ntp_delay & 0xffff0000) >> 16) * base::Time::kMicrosecondsPerSecond; | |
52 return base::TimeDelta::FromMicroseconds(delay_us); | |
53 } | |
54 | |
55 // A receiver frame event is identified by frame RTP timestamp, event timestamp | |
56 // and event type. | |
57 // A receiver packet event is identified by all of the above plus packet id. | |
58 // The key format is as follows: | |
59 // First uint64_t: | |
60 // bits 0-11: zeroes (unused). | |
61 // bits 12-15: event type ID. | |
62 // bits 16-31: packet ID if packet event, 0 otherwise. | |
63 // bits 32-63: RTP timestamp. | |
64 // Second uint64_t: | |
65 // bits 0-63: event TimeTicks internal value. | |
66 std::pair<uint64_t, uint64_t> GetReceiverEventKey( | |
67 RtpTimeTicks frame_rtp_timestamp, | |
68 const base::TimeTicks& event_timestamp, | |
69 uint8_t event_type, | |
70 uint16_t packet_id_or_zero) { | |
71 uint64_t value1 = event_type; | |
72 value1 <<= 16; | |
73 value1 |= packet_id_or_zero; | |
74 value1 <<= 32; | |
75 value1 |= frame_rtp_timestamp.lower_32_bits(); | |
76 return std::make_pair( | |
77 value1, static_cast<uint64_t>(event_timestamp.ToInternalValue())); | |
78 } | |
79 | |
80 } // namespace | 25 } // namespace |
81 | 26 |
82 Rtcp::Rtcp(const RtcpCastMessageCallback& cast_callback, | 27 ReceiverRtcpSession::ReceiverRtcpSession(base::TickClock* clock, |
83 const RtcpRttCallback& rtt_callback, | 28 PacedPacketSender* packet_sender, |
84 const RtcpLogMessageCallback& log_callback, | 29 uint32_t local_ssrc, |
85 base::TickClock* clock, | 30 uint32_t remote_ssrc) |
86 PacedPacketSender* packet_sender, | 31 : clock_(clock), |
87 uint32_t local_ssrc, | |
88 uint32_t remote_ssrc) | |
89 : cast_callback_(cast_callback), | |
90 rtt_callback_(rtt_callback), | |
91 log_callback_(log_callback), | |
92 clock_(clock), | |
93 rtcp_builder_(local_ssrc), | |
94 packet_sender_(packet_sender), | 32 packet_sender_(packet_sender), |
95 local_ssrc_(local_ssrc), | 33 local_ssrc_(local_ssrc), |
96 remote_ssrc_(remote_ssrc), | 34 remote_ssrc_(remote_ssrc), |
97 parser_(local_ssrc_, remote_ssrc_), | |
98 last_report_truncated_ntp_(0), | 35 last_report_truncated_ntp_(0), |
99 local_clock_ahead_by_(ClockDriftSmoother::GetDefaultTimeConstant()), | 36 local_clock_ahead_by_(ClockDriftSmoother::GetDefaultTimeConstant()), |
100 lip_sync_ntp_timestamp_(0), | 37 lip_sync_ntp_timestamp_(0), |
101 largest_seen_timestamp_(base::TimeTicks::FromInternalValue( | 38 parser_(local_ssrc, remote_ssrc) {} |
102 std::numeric_limits<int64_t>::min())), | |
103 ack_frame_id_wrap_helper_(kFirstFrameId - 1) {} | |
104 | 39 |
105 Rtcp::~Rtcp() {} | 40 ReceiverRtcpSession::~ReceiverRtcpSession() {} |
106 | 41 |
107 bool Rtcp::IsRtcpPacket(const uint8_t* packet, size_t length) { | 42 bool ReceiverRtcpSession::IncomingRtcpPacket(const uint8_t* data, |
108 if (length < kMinLengthOfRtcp) { | 43 size_t length) { |
109 LOG(ERROR) << "Invalid RTCP packet received."; | |
110 return false; | |
111 } | |
112 | |
113 uint8_t packet_type = packet[1]; | |
114 return packet_type >= kPacketTypeLow && packet_type <= kPacketTypeHigh; | |
115 } | |
116 | |
117 uint32_t Rtcp::GetSsrcOfSender(const uint8_t* rtcp_buffer, size_t length) { | |
118 if (length < kMinLengthOfRtcp) | |
119 return 0; | |
120 uint32_t ssrc_of_sender; | |
121 base::BigEndianReader big_endian_reader( | |
122 reinterpret_cast<const char*>(rtcp_buffer), length); | |
123 big_endian_reader.Skip(4); // Skip header. | |
124 big_endian_reader.ReadU32(&ssrc_of_sender); | |
125 return ssrc_of_sender; | |
126 } | |
127 | |
128 bool Rtcp::IncomingRtcpPacket(const uint8_t* data, size_t length) { | |
129 // Check if this is a valid RTCP packet. | 44 // Check if this is a valid RTCP packet. |
130 if (!IsRtcpPacket(data, length)) { | 45 if (!IsRtcpPacket(data, length)) { |
131 VLOG(1) << "Rtcp@" << this << "::IncomingRtcpPacket() -- " | 46 VLOG(1) << "Rtcp@" << this << "::IncomingRtcpPacket() -- " |
132 << "Received an invalid (non-RTCP?) packet."; | 47 << "Received an invalid (non-RTCP?) packet."; |
133 return false; | 48 return false; |
134 } | 49 } |
135 | 50 |
136 // Check if this packet is to us. | 51 // Check if this packet is to us. |
137 uint32_t ssrc_of_sender = GetSsrcOfSender(data, length); | 52 uint32_t ssrc_of_sender = GetSsrcOfSender(data, length); |
138 if (ssrc_of_sender != remote_ssrc_) { | 53 if (ssrc_of_sender != remote_ssrc_) { |
139 return false; | 54 return false; |
140 } | 55 } |
141 | 56 |
142 // Parse this packet. | 57 // Parse this packet. |
143 base::BigEndianReader reader(reinterpret_cast<const char*>(data), length); | 58 base::BigEndianReader reader(reinterpret_cast<const char*>(data), length); |
144 if (parser_.Parse(&reader)) { | 59 if (parser_.Parse(&reader)) { |
145 if (parser_.has_receiver_reference_time_report()) { | |
146 base::TimeTicks t = ConvertNtpToTimeTicks( | |
147 parser_.receiver_reference_time_report().ntp_seconds, | |
148 parser_.receiver_reference_time_report().ntp_fraction); | |
149 if (t > largest_seen_timestamp_) { | |
150 largest_seen_timestamp_ = t; | |
151 } else if ((largest_seen_timestamp_ - t).InMilliseconds() > | |
152 kOutOfOrderMaxAgeMs) { | |
153 // Reject packet, it is too old. | |
154 VLOG(1) << "Rejecting RTCP packet as it is too old (" | |
155 << (largest_seen_timestamp_ - t).InMilliseconds() | |
156 << " ms)"; | |
157 return true; | |
158 } | |
159 | |
160 OnReceivedNtp(parser_.receiver_reference_time_report().ntp_seconds, | |
161 parser_.receiver_reference_time_report().ntp_fraction); | |
162 } | |
163 if (parser_.has_sender_report()) { | 60 if (parser_.has_sender_report()) { |
164 OnReceivedNtp(parser_.sender_report().ntp_seconds, | 61 OnReceivedNtp(parser_.sender_report().ntp_seconds, |
165 parser_.sender_report().ntp_fraction); | 62 parser_.sender_report().ntp_fraction); |
166 OnReceivedLipSyncInfo(parser_.sender_report().rtp_timestamp, | 63 OnReceivedLipSyncInfo(parser_.sender_report().rtp_timestamp, |
167 parser_.sender_report().ntp_seconds, | 64 parser_.sender_report().ntp_seconds, |
168 parser_.sender_report().ntp_fraction); | 65 parser_.sender_report().ntp_fraction); |
169 } | 66 } |
170 if (parser_.has_receiver_log()) { | |
171 if (DedupeReceiverLog(parser_.mutable_receiver_log())) { | |
172 OnReceivedReceiverLog(parser_.receiver_log()); | |
173 } | |
174 } | |
175 if (parser_.has_last_report()) { | |
176 OnReceivedDelaySinceLastReport(parser_.last_report(), | |
177 parser_.delay_since_last_report()); | |
178 } | |
179 if (parser_.has_cast_message()) { | |
180 parser_.mutable_cast_message()->ack_frame_id = | |
181 ack_frame_id_wrap_helper_.MapTo32bitsFrameId( | |
182 parser_.mutable_cast_message()->ack_frame_id); | |
183 OnReceivedCastFeedback(parser_.cast_message()); | |
184 } | |
185 } | 67 } |
186 return true; | 68 return true; |
187 } | 69 } |
188 | 70 |
189 bool Rtcp::DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log) { | 71 void ReceiverRtcpSession::OnReceivedNtp(uint32_t ntp_seconds, |
190 RtcpReceiverLogMessage::iterator i = receiver_log->begin(); | 72 uint32_t ntp_fraction) { |
191 while (i != receiver_log->end()) { | 73 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); |
192 RtcpReceiverEventLogMessages* messages = &i->event_log_messages_; | |
193 RtcpReceiverEventLogMessages::iterator j = messages->begin(); | |
194 while (j != messages->end()) { | |
195 ReceiverEventKey key = GetReceiverEventKey(i->rtp_timestamp_, | |
196 j->event_timestamp, | |
197 j->type, | |
198 j->packet_id); | |
199 RtcpReceiverEventLogMessages::iterator tmp = j; | |
200 ++j; | |
201 if (receiver_event_key_set_.insert(key).second) { | |
202 receiver_event_key_queue_.push(key); | |
203 if (receiver_event_key_queue_.size() > kReceiverRtcpEventHistorySize) { | |
204 receiver_event_key_set_.erase(receiver_event_key_queue_.front()); | |
205 receiver_event_key_queue_.pop(); | |
206 } | |
207 } else { | |
208 messages->erase(tmp); | |
209 } | |
210 } | |
211 | 74 |
212 RtcpReceiverLogMessage::iterator tmp = i; | 75 const base::TimeTicks now = clock_->NowTicks(); |
213 ++i; | 76 time_last_report_received_ = now; |
214 if (messages->empty()) { | 77 |
215 receiver_log->erase(tmp); | 78 // TODO(miu): This clock offset calculation does not account for packet |
216 } | 79 // transit time over the network. End2EndTest.EvilNetwork confirms that this |
| 80 // contributes a very significant source of error here. Determine whether |
| 81 // RTT should be factored-in, and how that changes the rest of the |
| 82 // calculation. |
| 83 const base::TimeDelta measured_offset = |
| 84 now - ConvertNtpToTimeTicks(ntp_seconds, ntp_fraction); |
| 85 local_clock_ahead_by_.Update(now, measured_offset); |
| 86 if (measured_offset < local_clock_ahead_by_.Current()) { |
| 87 // Logically, the minimum offset between the clocks has to be the correct |
| 88 // one. For example, the time it took to transmit the current report may |
| 89 // have been lower than usual, and so some of the error introduced by the |
| 90 // transmission time can be eliminated. |
| 91 local_clock_ahead_by_.Reset(now, measured_offset); |
217 } | 92 } |
218 return !receiver_log->empty(); | 93 VLOG(1) << "Local clock is ahead of the remote clock by: " |
| 94 << "measured=" << measured_offset.InMicroseconds() << " usec, " |
| 95 << "filtered=" << local_clock_ahead_by_.Current().InMicroseconds() |
| 96 << " usec."; |
219 } | 97 } |
220 | 98 |
221 RtcpTimeData Rtcp::ConvertToNTPAndSave(base::TimeTicks now) { | 99 void ReceiverRtcpSession::SendRtcpReport( |
222 RtcpTimeData ret; | |
223 ret.timestamp = now; | |
224 | |
225 // Attach our NTP to all RTCP packets; with this information a "smart" sender | |
226 // can make decisions based on how old the RTCP message is. | |
227 ConvertTimeTicksToNtp(now, &ret.ntp_seconds, &ret.ntp_fraction); | |
228 SaveLastSentNtpTime(now, ret.ntp_seconds, ret.ntp_fraction); | |
229 return ret; | |
230 } | |
231 | |
232 void Rtcp::SendRtcpFromRtpReceiver( | |
233 RtcpTimeData time_data, | 100 RtcpTimeData time_data, |
234 const RtcpCastMessage* cast_message, | 101 const RtcpCastMessage* cast_message, |
235 base::TimeDelta target_delay, | 102 base::TimeDelta target_delay, |
236 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, | 103 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
237 const RtpReceiverStatistics* rtp_receiver_statistics) const { | 104 const RtpReceiverStatistics* rtp_receiver_statistics) const { |
238 RtcpReportBlock report_block; | 105 RtcpReportBlock report_block; |
239 RtcpReceiverReferenceTimeReport rrtr; | 106 RtcpReceiverReferenceTimeReport rrtr; |
240 rrtr.ntp_seconds = time_data.ntp_seconds; | 107 rrtr.ntp_seconds = time_data.ntp_seconds; |
241 rrtr.ntp_fraction = time_data.ntp_fraction; | 108 rrtr.ntp_fraction = time_data.ntp_fraction; |
242 | 109 |
(...skipping 13 matching lines...) Expand all Loading... |
256 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 123 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
257 &delay_fraction); | 124 &delay_fraction); |
258 report_block.delay_since_last_sr = | 125 report_block.delay_since_last_sr = |
259 ConvertToNtpDiff(delay_seconds, delay_fraction); | 126 ConvertToNtpDiff(delay_seconds, delay_fraction); |
260 } else { | 127 } else { |
261 report_block.delay_since_last_sr = 0; | 128 report_block.delay_since_last_sr = 0; |
262 } | 129 } |
263 } | 130 } |
264 RtcpBuilder rtcp_builder(local_ssrc_); | 131 RtcpBuilder rtcp_builder(local_ssrc_); |
265 packet_sender_->SendRtcpPacket( | 132 packet_sender_->SendRtcpPacket( |
266 local_ssrc_, | 133 local_ssrc_, rtcp_builder.BuildRtcpFromReceiver( |
267 rtcp_builder.BuildRtcpFromReceiver( | 134 rtp_receiver_statistics ? &report_block : NULL, &rrtr, |
268 rtp_receiver_statistics ? &report_block : NULL, | 135 cast_message, rtcp_events, target_delay)); |
269 &rrtr, | |
270 cast_message, | |
271 rtcp_events, | |
272 target_delay)); | |
273 } | 136 } |
274 | 137 |
275 void Rtcp::SendRtcpFromRtpSender(base::TimeTicks current_time, | 138 void ReceiverRtcpSession::OnReceivedLipSyncInfo(RtpTimeTicks rtp_timestamp, |
276 RtpTimeTicks current_time_as_rtp_timestamp, | 139 uint32_t ntp_seconds, |
277 uint32_t send_packet_count, | 140 uint32_t ntp_fraction) { |
278 size_t send_octet_count) { | |
279 uint32_t current_ntp_seconds = 0; | |
280 uint32_t current_ntp_fractions = 0; | |
281 ConvertTimeTicksToNtp(current_time, ¤t_ntp_seconds, | |
282 ¤t_ntp_fractions); | |
283 SaveLastSentNtpTime(current_time, current_ntp_seconds, | |
284 current_ntp_fractions); | |
285 | |
286 RtcpSenderInfo sender_info; | |
287 sender_info.ntp_seconds = current_ntp_seconds; | |
288 sender_info.ntp_fraction = current_ntp_fractions; | |
289 sender_info.rtp_timestamp = current_time_as_rtp_timestamp; | |
290 sender_info.send_packet_count = send_packet_count; | |
291 sender_info.send_octet_count = send_octet_count; | |
292 | |
293 packet_sender_->SendRtcpPacket( | |
294 local_ssrc_, | |
295 rtcp_builder_.BuildRtcpFromSender(sender_info)); | |
296 } | |
297 | |
298 void Rtcp::OnReceivedNtp(uint32_t ntp_seconds, uint32_t ntp_fraction) { | |
299 last_report_truncated_ntp_ = ConvertToNtpDiff(ntp_seconds, ntp_fraction); | |
300 | |
301 const base::TimeTicks now = clock_->NowTicks(); | |
302 time_last_report_received_ = now; | |
303 | |
304 // TODO(miu): This clock offset calculation does not account for packet | |
305 // transit time over the network. End2EndTest.EvilNetwork confirms that this | |
306 // contributes a very significant source of error here. Determine whether | |
307 // RTT should be factored-in, and how that changes the rest of the | |
308 // calculation. | |
309 const base::TimeDelta measured_offset = | |
310 now - ConvertNtpToTimeTicks(ntp_seconds, ntp_fraction); | |
311 local_clock_ahead_by_.Update(now, measured_offset); | |
312 if (measured_offset < local_clock_ahead_by_.Current()) { | |
313 // Logically, the minimum offset between the clocks has to be the correct | |
314 // one. For example, the time it took to transmit the current report may | |
315 // have been lower than usual, and so some of the error introduced by the | |
316 // transmission time can be eliminated. | |
317 local_clock_ahead_by_.Reset(now, measured_offset); | |
318 } | |
319 VLOG(1) << "Local clock is ahead of the remote clock by: " | |
320 << "measured=" << measured_offset.InMicroseconds() << " usec, " | |
321 << "filtered=" << local_clock_ahead_by_.Current().InMicroseconds() | |
322 << " usec."; | |
323 } | |
324 | |
325 void Rtcp::OnReceivedLipSyncInfo(RtpTimeTicks rtp_timestamp, | |
326 uint32_t ntp_seconds, | |
327 uint32_t ntp_fraction) { | |
328 if (ntp_seconds == 0) { | 141 if (ntp_seconds == 0) { |
329 NOTREACHED(); | 142 NOTREACHED(); |
330 return; | 143 return; |
331 } | 144 } |
332 lip_sync_rtp_timestamp_ = rtp_timestamp; | 145 lip_sync_rtp_timestamp_ = rtp_timestamp; |
333 lip_sync_ntp_timestamp_ = | 146 lip_sync_ntp_timestamp_ = |
334 (static_cast<uint64_t>(ntp_seconds) << 32) | ntp_fraction; | 147 (static_cast<uint64_t>(ntp_seconds) << 32) | ntp_fraction; |
335 } | 148 } |
336 | 149 |
337 bool Rtcp::GetLatestLipSyncTimes(RtpTimeTicks* rtp_timestamp, | 150 bool ReceiverRtcpSession::GetLatestLipSyncTimes( |
338 base::TimeTicks* reference_time) const { | 151 RtpTimeTicks* rtp_timestamp, |
| 152 base::TimeTicks* reference_time) const { |
339 if (!lip_sync_ntp_timestamp_) | 153 if (!lip_sync_ntp_timestamp_) |
340 return false; | 154 return false; |
341 | 155 |
342 const base::TimeTicks local_reference_time = | 156 const base::TimeTicks local_reference_time = |
343 ConvertNtpToTimeTicks( | 157 ConvertNtpToTimeTicks( |
344 static_cast<uint32_t>(lip_sync_ntp_timestamp_ >> 32), | 158 static_cast<uint32_t>(lip_sync_ntp_timestamp_ >> 32), |
345 static_cast<uint32_t>(lip_sync_ntp_timestamp_)) + | 159 static_cast<uint32_t>(lip_sync_ntp_timestamp_)) + |
346 local_clock_ahead_by_.Current(); | 160 local_clock_ahead_by_.Current(); |
347 | 161 |
348 // Sanity-check: Getting regular lip sync updates? | 162 // Sanity-check: Getting regular lip sync updates? |
349 DCHECK((clock_->NowTicks() - local_reference_time) < | 163 DCHECK((clock_->NowTicks() - local_reference_time) < |
350 base::TimeDelta::FromMinutes(1)); | 164 base::TimeDelta::FromMinutes(1)); |
351 | 165 |
352 *rtp_timestamp = lip_sync_rtp_timestamp_; | 166 *rtp_timestamp = lip_sync_rtp_timestamp_; |
353 *reference_time = local_reference_time; | 167 *reference_time = local_reference_time; |
354 return true; | 168 return true; |
355 } | 169 } |
356 | 170 |
357 void Rtcp::OnReceivedDelaySinceLastReport(uint32_t last_report, | |
358 uint32_t delay_since_last_report) { | |
359 RtcpSendTimeMap::iterator it = last_reports_sent_map_.find(last_report); | |
360 if (it == last_reports_sent_map_.end()) { | |
361 return; // Feedback on another report. | |
362 } | |
363 | |
364 const base::TimeDelta sender_delay = clock_->NowTicks() - it->second; | |
365 const base::TimeDelta receiver_delay = | |
366 ConvertFromNtpDiff(delay_since_last_report); | |
367 current_round_trip_time_ = sender_delay - receiver_delay; | |
368 // If the round trip time was computed as less than 1 ms, assume clock | |
369 // imprecision by one or both peers caused a bad value to be calculated. | |
370 // While plenty of networks do easily achieve less than 1 ms round trip time, | |
371 // such a level of precision cannot be measured with our approach; and 1 ms is | |
372 // good enough to represent "under 1 ms" for our use cases. | |
373 current_round_trip_time_ = | |
374 std::max(current_round_trip_time_, base::TimeDelta::FromMilliseconds(1)); | |
375 | |
376 if (!rtt_callback_.is_null()) | |
377 rtt_callback_.Run(current_round_trip_time_); | |
378 } | |
379 | |
380 void Rtcp::OnReceivedCastFeedback(const RtcpCastMessage& cast_message) { | |
381 if (cast_callback_.is_null()) | |
382 return; | |
383 cast_callback_.Run(cast_message); | |
384 } | |
385 | |
386 void Rtcp::SaveLastSentNtpTime(const base::TimeTicks& now, | |
387 uint32_t last_ntp_seconds, | |
388 uint32_t last_ntp_fraction) { | |
389 // Make sure |now| is always greater than the last element in | |
390 // |last_reports_sent_queue_|. | |
391 if (!last_reports_sent_queue_.empty()) { | |
392 DCHECK(now >= last_reports_sent_queue_.back().second); | |
393 } | |
394 | |
395 uint32_t last_report = ConvertToNtpDiff(last_ntp_seconds, last_ntp_fraction); | |
396 last_reports_sent_map_[last_report] = now; | |
397 last_reports_sent_queue_.push(std::make_pair(last_report, now)); | |
398 | |
399 const base::TimeTicks timeout = | |
400 now - TimeDelta::FromMilliseconds(kStatsHistoryWindowMs); | |
401 | |
402 // Cleanup old statistics older than |timeout|. | |
403 while (!last_reports_sent_queue_.empty()) { | |
404 RtcpSendTimePair oldest_report = last_reports_sent_queue_.front(); | |
405 if (oldest_report.second < timeout) { | |
406 last_reports_sent_map_.erase(oldest_report.first); | |
407 last_reports_sent_queue_.pop(); | |
408 } else { | |
409 break; | |
410 } | |
411 } | |
412 } | |
413 | |
414 void Rtcp::OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log) { | |
415 if (log_callback_.is_null()) | |
416 return; | |
417 log_callback_.Run(receiver_log); | |
418 } | |
419 | |
420 } // namespace cast | 171 } // namespace cast |
421 } // namespace media | 172 } // namespace media |
OLD | NEW |