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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 extended_high_sequence_number, | 78 extended_high_sequence_number, |
79 jitter); | 79 jitter); |
80 } | 80 } |
81 | 81 |
82 private: | 82 private: |
83 RtpReceiver* rtp_receiver_; | 83 RtpReceiver* rtp_receiver_; |
84 }; | 84 }; |
85 | 85 |
86 VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment, | 86 VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment, |
87 const VideoReceiverConfig& video_config, | 87 const VideoReceiverConfig& video_config, |
88 PacedPacketSender* const packet_sender) | 88 transport::PacedPacketSender* const packet_sender) |
89 : cast_environment_(cast_environment), | 89 : cast_environment_(cast_environment), |
90 codec_(video_config.codec), | 90 codec_(video_config.codec), |
91 target_delay_delta_( | 91 target_delay_delta_( |
92 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), | 92 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), |
93 frame_delay_(base::TimeDelta::FromMilliseconds( | 93 frame_delay_(base::TimeDelta::FromMilliseconds( |
94 1000 / video_config.max_frame_rate)), | 94 1000 / video_config.max_frame_rate)), |
95 incoming_payload_callback_(new LocalRtpVideoData(this)), | 95 incoming_payload_callback_(new LocalRtpVideoData(this)), |
96 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), | 96 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), |
97 rtp_receiver_(cast_environment_->Clock(), NULL, &video_config, | 97 rtp_receiver_(cast_environment_->Clock(), NULL, &video_config, |
98 incoming_payload_callback_.get()), | 98 incoming_payload_callback_.get()), |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // to wait for new packet(s). | 333 // to wait for new packet(s). |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, | 337 base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, |
338 uint32 rtp_timestamp) { | 338 uint32 rtp_timestamp) { |
339 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 339 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
340 // Senders time in ms when this frame was captured. | 340 // Senders time in ms when this frame was captured. |
341 // Note: the senders clock and our local clock might not be synced. | 341 // Note: the senders clock and our local clock might not be synced. |
342 base::TimeTicks rtp_timestamp_in_ticks; | 342 base::TimeTicks rtp_timestamp_in_ticks; |
| 343 |
343 if (time_offset_.InMilliseconds() == 0) { | 344 if (time_offset_.InMilliseconds() == 0) { |
344 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 345 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
345 incoming_rtp_timestamp_, | 346 incoming_rtp_timestamp_, |
346 &rtp_timestamp_in_ticks)) { | 347 &rtp_timestamp_in_ticks)) { |
347 // We have not received any RTCP to sync the stream play it out as soon as | 348 // We have not received any RTCP to sync the stream play it out as soon as |
348 // possible. | 349 // possible. |
349 return now; | 350 return now; |
350 } | 351 } |
351 time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; | 352 time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; |
352 } else if (time_incoming_packet_updated_) { | 353 } else if (time_incoming_packet_updated_) { |
353 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 354 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
354 incoming_rtp_timestamp_, | 355 incoming_rtp_timestamp_, |
355 &rtp_timestamp_in_ticks)) { | 356 &rtp_timestamp_in_ticks)) { |
356 // Time to update the time_offset. | 357 // Time to update the time_offset. |
357 base::TimeDelta time_offset = | 358 base::TimeDelta time_offset = |
358 time_incoming_packet_ - rtp_timestamp_in_ticks; | 359 time_incoming_packet_ - rtp_timestamp_in_ticks; |
359 time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) | 360 time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) |
360 / kTimeOffsetFilter; | 361 / kTimeOffsetFilter; |
361 } | 362 } |
362 } | 363 } |
363 // Reset |time_incoming_packet_updated_| to enable a future measurement. | 364 // Reset |time_incoming_packet_updated_| to enable a future measurement. |
364 time_incoming_packet_updated_ = false; | 365 time_incoming_packet_updated_ = false; |
365 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 366 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
366 rtp_timestamp, | 367 rtp_timestamp, |
367 &rtp_timestamp_in_ticks)) { | 368 &rtp_timestamp_in_ticks)) { |
368 // This can fail if we have not received any RTCP packets in a long time. | 369 // This can fail if we have not received any RTCP packets in a long time. |
369 return now; | 370 return now; |
370 } | 371 } |
371 base::TimeTicks render_time = | 372 base::TimeTicks render_time = |
372 (rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_); | 373 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_; |
373 if (last_render_time_ > render_time) | 374 if (last_render_time_ > render_time) |
374 render_time = last_render_time_; | 375 render_time = last_render_time_; |
375 last_render_time_ = render_time; | 376 last_render_time_ = render_time; |
376 return render_time; | 377 return render_time; |
377 } | 378 } |
378 | 379 |
379 void VideoReceiver::IncomingPacket(const uint8* packet, size_t length, | 380 void VideoReceiver::IncomingPacket(const uint8* packet, size_t length, |
380 const base::Closure callback) { | 381 const base::Closure callback) { |
381 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 382 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
382 if (Rtcp::IsRtcpPacket(packet, length)) { | 383 if (Rtcp::IsRtcpPacket(packet, length)) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 464 } |
464 | 465 |
465 void VideoReceiver::SendNextRtcpReport() { | 466 void VideoReceiver::SendNextRtcpReport() { |
466 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 467 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
467 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); | 468 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); |
468 ScheduleNextRtcpReport(); | 469 ScheduleNextRtcpReport(); |
469 } | 470 } |
470 | 471 |
471 } // namespace cast | 472 } // namespace cast |
472 } // namespace media | 473 } // namespace media |
OLD | NEW |