OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/rtcp/rtcp.h" | 5 #include "media/cast/rtcp/rtcp.h" |
6 | 6 |
7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "media/cast/cast_config.h" | 9 #include "media/cast/cast_config.h" |
10 #include "media/cast/cast_defines.h" | 10 #include "media/cast/cast_defines.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 const ReceiverRtcpEventSubscriber* event_subscriber) { | 234 const ReceiverRtcpEventSubscriber* event_subscriber) { |
235 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 235 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
236 uint32 packet_type_flags = 0; | 236 uint32 packet_type_flags = 0; |
237 | 237 |
238 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 238 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
239 transport::RtcpReportBlock report_block; | 239 transport::RtcpReportBlock report_block; |
240 RtcpReceiverReferenceTimeReport rrtr; | 240 RtcpReceiverReferenceTimeReport rrtr; |
241 | 241 |
242 // Attach our NTP to all RTCP packets; with this information a "smart" sender | 242 // Attach our NTP to all RTCP packets; with this information a "smart" sender |
243 // can make decisions based on how old the RTCP message is. | 243 // can make decisions based on how old the RTCP message is. |
244 packet_type_flags |= RtcpSender::kRtcpRrtr; | 244 packet_type_flags |= transport::kRtcpRrtr; |
245 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); | 245 ConvertTimeTicksToNtp(now, &rrtr.ntp_seconds, &rrtr.ntp_fraction); |
246 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); | 246 SaveLastSentNtpTime(now, rrtr.ntp_seconds, rrtr.ntp_fraction); |
247 | 247 |
248 if (cast_message) { | 248 if (cast_message) { |
249 packet_type_flags |= RtcpSender::kRtcpCast; | 249 packet_type_flags |= transport::kRtcpCast; |
250 } | 250 } |
251 if (event_subscriber) { | 251 if (event_subscriber) { |
252 packet_type_flags |= RtcpSender::kRtcpReceiverLog; | 252 packet_type_flags |= transport::kRtcpReceiverLog; |
253 } | 253 } |
254 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) { | 254 if (rtcp_mode_ == kRtcpCompound || now >= next_time_to_send_rtcp_) { |
255 packet_type_flags |= RtcpSender::kRtcpRr; | 255 packet_type_flags |= transport::kRtcpRr; |
256 | 256 |
257 report_block.remote_ssrc = 0; // Not needed to set send side. | 257 report_block.remote_ssrc = 0; // Not needed to set send side. |
258 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. | 258 report_block.media_ssrc = remote_ssrc_; // SSRC of the RTP packet sender. |
259 if (rtp_receiver_statistics_) { | 259 if (rtp_receiver_statistics_) { |
260 rtp_receiver_statistics_->GetStatistics( | 260 rtp_receiver_statistics_->GetStatistics( |
261 &report_block.fraction_lost, &report_block.cumulative_lost, | 261 &report_block.fraction_lost, &report_block.cumulative_lost, |
262 &report_block.extended_high_sequence_number, &report_block.jitter); | 262 &report_block.extended_high_sequence_number, &report_block.jitter); |
263 cast_environment_->Logging()->InsertGenericEvent(now, kJitterMs, | 263 cast_environment_->Logging()->InsertGenericEvent(now, kJitterMs, |
264 report_block.jitter); | 264 report_block.jitter); |
265 cast_environment_->Logging()->InsertGenericEvent( | 265 cast_environment_->Logging()->InsertGenericEvent( |
266 now, kPacketLoss, report_block.fraction_lost); | 266 now, kPacketLoss, report_block.fraction_lost); |
267 } | 267 } |
268 | 268 |
269 report_block.last_sr = last_report_received_; | 269 report_block.last_sr = last_report_received_; |
270 if (!time_last_report_received_.is_null()) { | 270 if (!time_last_report_received_.is_null()) { |
271 uint32 delay_seconds = 0; | 271 uint32 delay_seconds = 0; |
272 uint32 delay_fraction = 0; | 272 uint32 delay_fraction = 0; |
273 base::TimeDelta delta = now - time_last_report_received_; | 273 base::TimeDelta delta = now - time_last_report_received_; |
274 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 274 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
275 &delay_fraction); | 275 &delay_fraction); |
276 report_block.delay_since_last_sr = | 276 report_block.delay_since_last_sr = |
277 ConvertToNtpDiff(delay_seconds, delay_fraction); | 277 ConvertToNtpDiff(delay_seconds, delay_fraction); |
278 } else { | 278 } else { |
279 report_block.delay_since_last_sr = 0; | 279 report_block.delay_since_last_sr = 0; |
280 } | 280 } |
281 UpdateNextTimeToSendRtcp(); | 281 UpdateNextTimeToSendRtcp(); |
282 } | 282 } |
283 rtcp_sender_->SendRtcpFromRtpReceiver( | 283 rtcp_sender_->SendRtcpFromRtpReceiver( |
284 packet_type_flags, &report_block, &rrtr, cast_message, event_subscriber); | 284 packet_type_flags, &report_block, &rrtr, cast_message, event_subscriber, |
285 target_delay_ms_); | |
285 } | 286 } |
286 | 287 |
287 void Rtcp::SendRtcpFromRtpSender( | 288 void Rtcp::SendRtcpFromRtpSender( |
288 const transport::RtcpSenderLogMessage& sender_log_message) { | 289 const transport::RtcpSenderLogMessage& sender_log_message) { |
289 DCHECK(transport_sender_); | 290 DCHECK(transport_sender_); |
290 uint32 packet_type_flags = RtcpSender::kRtcpSr; | 291 uint32 packet_type_flags = transport::kRtcpSr; |
291 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 292 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
292 | 293 |
293 if (sender_log_message.size()) { | 294 if (sender_log_message.size()) { |
294 packet_type_flags |= RtcpSender::kRtcpSenderLog; | 295 packet_type_flags |= transport::kRtcpSenderLog; |
295 } | 296 } |
296 | 297 |
297 transport::RtcpSenderInfo sender_info; | 298 transport::RtcpSenderInfo sender_info; |
298 if (rtp_sender_statistics_) { | 299 if (rtp_sender_statistics_) { |
299 rtp_sender_statistics_->GetStatistics(now, &sender_info); | 300 rtp_sender_statistics_->GetStatistics(now, &sender_info); |
300 } else { | 301 } else { |
301 memset(&sender_info, 0, sizeof(sender_info)); | 302 memset(&sender_info, 0, sizeof(sender_info)); |
302 } | 303 } |
303 SaveLastSentNtpTime(now, sender_info.ntp_seconds, sender_info.ntp_fraction); | 304 SaveLastSentNtpTime(now, sender_info.ntp_seconds, sender_info.ntp_fraction); |
304 | 305 |
305 transport::RtcpDlrrReportBlock dlrr; | 306 transport::RtcpDlrrReportBlock dlrr; |
306 if (!time_last_report_received_.is_null()) { | 307 if (!time_last_report_received_.is_null()) { |
307 packet_type_flags |= RtcpSender::kRtcpDlrr; | 308 packet_type_flags |= transport::kRtcpDlrr; |
308 dlrr.last_rr = last_report_received_; | 309 dlrr.last_rr = last_report_received_; |
309 uint32 delay_seconds = 0; | 310 uint32 delay_seconds = 0; |
310 uint32 delay_fraction = 0; | 311 uint32 delay_fraction = 0; |
311 base::TimeDelta delta = now - time_last_report_received_; | 312 base::TimeDelta delta = now - time_last_report_received_; |
312 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, | 313 ConvertTimeToFractions(delta.InMicroseconds(), &delay_seconds, |
313 &delay_fraction); | 314 &delay_fraction); |
314 | 315 |
315 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction); | 316 dlrr.delay_since_last_rr = ConvertToNtpDiff(delay_seconds, delay_fraction); |
316 } | 317 } |
317 | 318 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 *rtp_timestamp_in_ticks = ConvertNtpToTimeTicks(last_received_ntp_seconds_, | 386 *rtp_timestamp_in_ticks = ConvertNtpToTimeTicks(last_received_ntp_seconds_, |
386 last_received_ntp_fraction_) + | 387 last_received_ntp_fraction_) + |
387 base::TimeDelta::FromMilliseconds(rtp_time_diff_ms); | 388 base::TimeDelta::FromMilliseconds(rtp_time_diff_ms); |
388 return true; | 389 return true; |
389 } | 390 } |
390 | 391 |
391 void Rtcp::SetCastReceiverEventHistorySize(size_t size) { | 392 void Rtcp::SetCastReceiverEventHistorySize(size_t size) { |
392 rtcp_receiver_->SetCastReceiverEventHistorySize(size); | 393 rtcp_receiver_->SetCastReceiverEventHistorySize(size); |
393 } | 394 } |
394 | 395 |
396 void Rtcp::SetTargetDelay(base::TimeDelta target_delay) { | |
397 target_delay_ms_ = static_cast<uint16>(target_delay.InMilliseconds()); | |
pwestin(chromium)
2014/03/11 22:07:55
Sanity check for large and negative values
mikhal1
2014/03/12 18:01:59
Done.
| |
398 } | |
399 | |
395 void Rtcp::OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, | 400 void Rtcp::OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, |
396 uint32 last_report, | 401 uint32 last_report, |
397 uint32 delay_since_last_report) { | 402 uint32 delay_since_last_report) { |
398 RtcpSendTimeMap::iterator it = last_reports_sent_map_.find(last_report); | 403 RtcpSendTimeMap::iterator it = last_reports_sent_map_.find(last_report); |
399 if (it == last_reports_sent_map_.end()) { | 404 if (it == last_reports_sent_map_.end()) { |
400 return; // Feedback on another report. | 405 return; // Feedback on another report. |
401 } | 406 } |
402 | 407 |
403 base::TimeDelta sender_delay = | 408 base::TimeDelta sender_delay = |
404 cast_environment_->Clock()->NowTicks() - it->second; | 409 cast_environment_->Clock()->NowTicks() - it->second; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 int random = base::RandInt(0, 999); | 494 int random = base::RandInt(0, 999); |
490 base::TimeDelta time_to_next = | 495 base::TimeDelta time_to_next = |
491 (rtcp_interval_ / 2) + (rtcp_interval_ * random / 1000); | 496 (rtcp_interval_ / 2) + (rtcp_interval_ * random / 1000); |
492 | 497 |
493 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 498 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
494 next_time_to_send_rtcp_ = now + time_to_next; | 499 next_time_to_send_rtcp_ = now + time_to_next; |
495 } | 500 } |
496 | 501 |
497 } // namespace cast | 502 } // namespace cast |
498 } // namespace media | 503 } // namespace media |
OLD | NEW |