| 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/video_receiver/video_receiver.h" | 5 #include "media/cast/video_receiver/video_receiver.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // to wait for new packet(s). | 360 // to wait for new packet(s). |
| 361 } | 361 } |
| 362 | 362 |
| 363 base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, | 363 base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, |
| 364 uint32 rtp_timestamp) { | 364 uint32 rtp_timestamp) { |
| 365 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 365 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 366 // Senders time in ms when this frame was captured. | 366 // Senders time in ms when this frame was captured. |
| 367 // Note: the senders clock and our local clock might not be synced. | 367 // Note: the senders clock and our local clock might not be synced. |
| 368 base::TimeTicks rtp_timestamp_in_ticks; | 368 base::TimeTicks rtp_timestamp_in_ticks; |
| 369 | 369 |
| 370 // Compute the time offset_in_ticks based on the incoming_rtp_timestamp_. |
| 370 if (time_offset_.InMilliseconds() == 0) { | 371 if (time_offset_.InMilliseconds() == 0) { |
| 371 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 372 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
| 372 incoming_rtp_timestamp_, | 373 incoming_rtp_timestamp_, |
| 373 &rtp_timestamp_in_ticks)) { | 374 &rtp_timestamp_in_ticks)) { |
| 374 // We have not received any RTCP to sync the stream play it out as soon as | 375 // We have not received any RTCP to sync the stream play it out as soon as |
| 375 // possible. | 376 // possible. |
| 376 return now; | 377 return now; |
| 377 } | 378 } |
| 378 time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; | 379 time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; |
| 379 } else if (time_incoming_packet_updated_) { | 380 } else if (time_incoming_packet_updated_) { |
| 380 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 381 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
| 381 incoming_rtp_timestamp_, | 382 incoming_rtp_timestamp_, |
| 382 &rtp_timestamp_in_ticks)) { | 383 &rtp_timestamp_in_ticks)) { |
| 383 // Time to update the time_offset. | 384 // Time to update the time_offset. |
| 384 base::TimeDelta time_offset = | 385 base::TimeDelta time_offset = |
| 385 time_incoming_packet_ - rtp_timestamp_in_ticks; | 386 time_incoming_packet_ - rtp_timestamp_in_ticks; |
| 386 time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) / | 387 time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) / |
| 387 kTimeOffsetFilter; | 388 kTimeOffsetFilter; |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 // Reset |time_incoming_packet_updated_| to enable a future measurement. | 391 // Reset |time_incoming_packet_updated_| to enable a future measurement. |
| 391 time_incoming_packet_updated_ = false; | 392 time_incoming_packet_updated_ = false; |
| 393 // Compute the actual rtp_timestamp_in_ticks based on the current timestamp. |
| 392 if (!rtcp_->RtpTimestampInSenderTime( | 394 if (!rtcp_->RtpTimestampInSenderTime( |
| 393 kVideoFrequency, rtp_timestamp, &rtp_timestamp_in_ticks)) { | 395 kVideoFrequency, rtp_timestamp, &rtp_timestamp_in_ticks)) { |
| 394 // This can fail if we have not received any RTCP packets in a long time. | 396 // This can fail if we have not received any RTCP packets in a long time. |
| 395 return now; | 397 return now; |
| 396 } | 398 } |
| 397 base::TimeTicks render_time = | 399 base::TimeTicks render_time = |
| 398 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_; | 400 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_; |
| 399 if (last_render_time_ > render_time) | 401 if (last_render_time_ > render_time) |
| 400 render_time = last_render_time_; | 402 render_time = last_render_time_; |
| 401 last_render_time_ = render_time; | 403 last_render_time_ = render_time; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 526 } |
| 525 | 527 |
| 526 void VideoReceiver::SendNextRtcpReport() { | 528 void VideoReceiver::SendNextRtcpReport() { |
| 527 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 529 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 528 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); | 530 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); |
| 529 ScheduleNextRtcpReport(); | 531 ScheduleNextRtcpReport(); |
| 530 } | 532 } |
| 531 | 533 |
| 532 } // namespace cast | 534 } // namespace cast |
| 533 } // namespace media | 535 } // namespace media |
| OLD | NEW |