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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 frame_delay_(base::TimeDelta::FromMilliseconds( | 100 frame_delay_(base::TimeDelta::FromMilliseconds( |
101 1000 / video_config.max_frame_rate)), | 101 1000 / video_config.max_frame_rate)), |
102 incoming_payload_callback_(new LocalRtpVideoData(this)), | 102 incoming_payload_callback_(new LocalRtpVideoData(this)), |
103 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), | 103 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), |
104 rtp_receiver_(cast_environment_->Clock(), | 104 rtp_receiver_(cast_environment_->Clock(), |
105 NULL, | 105 NULL, |
106 &video_config, | 106 &video_config, |
107 incoming_payload_callback_.get()), | 107 incoming_payload_callback_.get()), |
108 rtp_video_receiver_statistics_( | 108 rtp_video_receiver_statistics_( |
109 new LocalRtpReceiverStatistics(&rtp_receiver_)), | 109 new LocalRtpReceiverStatistics(&rtp_receiver_)), |
110 time_offset_counter_(0), | |
110 decryptor_(), | 111 decryptor_(), |
111 time_incoming_packet_updated_(false), | 112 time_incoming_packet_updated_(false), |
112 incoming_rtp_timestamp_(0), | 113 incoming_rtp_timestamp_(0), |
113 weak_factory_(this) { | 114 weak_factory_(this) { |
114 int max_unacked_frames = | 115 int max_unacked_frames = |
115 video_config.rtp_max_delay_ms * video_config.max_frame_rate / 1000; | 116 video_config.rtp_max_delay_ms * video_config.max_frame_rate / 1000; |
116 DCHECK(max_unacked_frames) << "Invalid argument"; | 117 DCHECK(max_unacked_frames) << "Invalid argument"; |
117 | 118 |
118 decryptor_.Initialize(video_config.aes_key, video_config.aes_iv_mask); | 119 decryptor_.Initialize(video_config.aes_key, video_config.aes_iv_mask); |
119 framer_.reset(new Framer(cast_environment->Clock(), | 120 framer_.reset(new Framer(cast_environment->Clock(), |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 // Compute the time offset_in_ticks based on the incoming_rtp_timestamp_. | 359 // Compute the time offset_in_ticks based on the incoming_rtp_timestamp_. |
359 if (time_offset_.InMilliseconds() == 0) { | 360 if (time_offset_.InMilliseconds() == 0) { |
360 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 361 if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
361 incoming_rtp_timestamp_, | 362 incoming_rtp_timestamp_, |
362 &rtp_timestamp_in_ticks)) { | 363 &rtp_timestamp_in_ticks)) { |
363 // We have not received any RTCP to sync the stream play it out as soon as | 364 // We have not received any RTCP to sync the stream play it out as soon as |
364 // possible. | 365 // possible. |
365 return now; | 366 return now; |
366 } | 367 } |
367 time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; | 368 time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; |
369 ++time_offset_counter_; | |
368 } else if (time_incoming_packet_updated_) { | 370 } else if (time_incoming_packet_updated_) { |
369 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, | 371 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, |
370 incoming_rtp_timestamp_, | 372 incoming_rtp_timestamp_, |
371 &rtp_timestamp_in_ticks)) { | 373 &rtp_timestamp_in_ticks)) { |
372 // Time to update the time_offset. | 374 // Time to update the time_offset. |
373 base::TimeDelta time_offset = | 375 base::TimeDelta time_offset = |
374 time_incoming_packet_ - rtp_timestamp_in_ticks; | 376 time_incoming_packet_ - rtp_timestamp_in_ticks; |
375 time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) / | 377 if (time_offset_counter_ < 10 && time_offset < time_offset_) |
376 kTimeOffsetFilter; | 378 time_offset_ = time_offset; |
379 ++time_offset_counter_; | |
hguihot1
2014/03/03 23:20:59
The previous filter was basically doing:
time_off
mikhal1
2014/03/03 23:33:23
That is indeed part of the problem, which can be d
pwestin
2014/03/03 23:35:47
Mikhal based on the date we have seen in testing I
mikhal1
2014/03/04 00:02:37
True, just thought of it as I was responding to hg
| |
377 } | 380 } |
378 } | 381 } |
379 // Reset |time_incoming_packet_updated_| to enable a future measurement. | 382 // Reset |time_incoming_packet_updated_| to enable a future measurement. |
380 time_incoming_packet_updated_ = false; | 383 time_incoming_packet_updated_ = false; |
381 // Compute the actual rtp_timestamp_in_ticks based on the current timestamp. | 384 // Compute the actual rtp_timestamp_in_ticks based on the current timestamp. |
382 if (!rtcp_->RtpTimestampInSenderTime( | 385 if (!rtcp_->RtpTimestampInSenderTime( |
383 kVideoFrequency, rtp_timestamp, &rtp_timestamp_in_ticks)) { | 386 kVideoFrequency, rtp_timestamp, &rtp_timestamp_in_ticks)) { |
384 // This can fail if we have not received any RTCP packets in a long time. | 387 // This can fail if we have not received any RTCP packets in a long time. |
385 return now; | 388 return now; |
386 } | 389 } |
(...skipping 15 matching lines...) Expand all Loading... | |
402 } | 405 } |
403 | 406 |
404 void VideoReceiver::IncomingParsedRtpPacket(const uint8* payload_data, | 407 void VideoReceiver::IncomingParsedRtpPacket(const uint8* payload_data, |
405 size_t payload_size, | 408 size_t payload_size, |
406 const RtpCastHeader& rtp_header) { | 409 const RtpCastHeader& rtp_header) { |
407 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 410 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
408 | 411 |
409 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 412 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
410 if (time_incoming_packet_.is_null() || | 413 if (time_incoming_packet_.is_null() || |
411 now - time_incoming_packet_ > | 414 now - time_incoming_packet_ > |
412 base::TimeDelta::FromMilliseconds(kMinTimeBetweenOffsetUpdatesMs)) { | 415 base::TimeDelta::FromMilliseconds(kMinTimeBetweenOffsetUpdatesMs)) { |
pwestin
2014/03/03 23:35:47
kMinTimeBetweenOffsetUpdatesMs should be decreased
mikhal1
2014/03/04 00:02:37
Done.
| |
413 if (time_incoming_packet_.is_null()) | 416 if (time_incoming_packet_.is_null()) |
414 InitializeTimers(); | 417 InitializeTimers(); |
415 incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; | 418 incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; |
416 time_incoming_packet_ = now; | 419 time_incoming_packet_ = now; |
417 time_incoming_packet_updated_ = true; | 420 time_incoming_packet_updated_ = true; |
418 } | 421 } |
419 | 422 |
420 frame_id_to_rtp_timestamp_[rtp_header.frame_id & 0xff] = | 423 frame_id_to_rtp_timestamp_[rtp_header.frame_id & 0xff] = |
421 rtp_header.webrtc.header.timestamp; | 424 rtp_header.webrtc.header.timestamp; |
422 cast_environment_->Logging()->InsertPacketEvent( | 425 cast_environment_->Logging()->InsertPacketEvent( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 } | 518 } |
516 | 519 |
517 void VideoReceiver::SendNextRtcpReport() { | 520 void VideoReceiver::SendNextRtcpReport() { |
518 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 521 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
519 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); | 522 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); |
520 ScheduleNextRtcpReport(); | 523 ScheduleNextRtcpReport(); |
521 } | 524 } |
522 | 525 |
523 } // namespace cast | 526 } // namespace cast |
524 } // namespace media | 527 } // namespace media |
OLD | NEW |