Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: media/cast/video_receiver/video_receiver.cc

Issue 186043003: Cast: Using a min filter to compute time offset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to review Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/video_receiver/video_receiver.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "media/cast/cast_defines.h" 12 #include "media/cast/cast_defines.h"
13 #include "media/cast/framer/framer.h" 13 #include "media/cast/framer/framer.h"
14 #include "media/cast/rtcp/receiver_rtcp_event_subscriber.h" 14 #include "media/cast/rtcp/receiver_rtcp_event_subscriber.h"
15 #include "media/cast/rtcp/rtcp_sender.h" 15 #include "media/cast/rtcp/rtcp_sender.h"
16 #include "media/cast/video_receiver/video_decoder.h" 16 #include "media/cast/video_receiver/video_decoder.h"
17 17
18 namespace { 18 namespace {
19 19
20 static const int64 kMinSchedulingDelayMs = 1; 20 static const int64 kMinSchedulingDelayMs = 1;
21 static const int64 kMinTimeBetweenOffsetUpdatesMs = 2000; 21 static const int64 kMinTimeBetweenOffsetUpdatesMs = 1000;
22 static const int kTimeOffsetFilter = 8; 22 static const int kTimeOffsetMaxCounter = 10;
23 static const int64_t kMinProcessIntervalMs = 5; 23 static const int64_t kMinProcessIntervalMs = 5;
24 24
25 } // namespace 25 } // namespace
26 26
27 namespace media { 27 namespace media {
28 namespace cast { 28 namespace cast {
29 29
30 // Local implementation of RtpData (defined in rtp_rtcp_defines.h). 30 // Local implementation of RtpData (defined in rtp_rtcp_defines.h).
31 // Used to pass payload data into the video receiver. 31 // Used to pass payload data into the video receiver.
32 class LocalRtpVideoData : public RtpData { 32 class LocalRtpVideoData : public RtpData {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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),
pwestin 2014/03/04 00:10:54 we should initialize time_offset_
mikhal1 2014/03/04 00:28:45 will be initialized by the default const' On 2014/
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 350 }
350 351
351 base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, 352 base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now,
352 uint32 rtp_timestamp) { 353 uint32 rtp_timestamp) {
353 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 354 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
354 // Senders time in ms when this frame was captured. 355 // Senders time in ms when this frame was captured.
355 // Note: the senders clock and our local clock might not be synced. 356 // Note: the senders clock and our local clock might not be synced.
356 base::TimeTicks rtp_timestamp_in_ticks; 357 base::TimeTicks rtp_timestamp_in_ticks;
357 358
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_counter_ == 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_counter_;
pwestin 2014/03/04 00:10:54 This will result in a bad first value; since we ha
mikhal1 2014/03/04 00:28:45 true. fixed. On 2014/03/04 00:10:54, pwestin wrote
368 } else if (time_incoming_packet_updated_) { 369 } else if (time_incoming_packet_updated_) {
369 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, 370 if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency,
370 incoming_rtp_timestamp_, 371 incoming_rtp_timestamp_,
371 &rtp_timestamp_in_ticks)) { 372 &rtp_timestamp_in_ticks)) {
372 // Time to update the time_offset. 373 // Time to update the time_offset.
373 base::TimeDelta time_offset = 374 base::TimeDelta time_offset =
374 time_incoming_packet_ - rtp_timestamp_in_ticks; 375 time_incoming_packet_ - rtp_timestamp_in_ticks;
375 time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) / 376 if (time_offset_counter_ < kTimeOffsetMaxCounter &&
376 kTimeOffsetFilter; 377 time_offset < time_offset_)
pwestin 2014/03/04 00:10:54 we should do if (time_offset_counter_ == 1) tim
mikhal1 2014/03/04 00:28:45 updated. On 2014/03/04 00:10:54, pwestin wrote:
378 time_offset_ = time_offset;
hguihot1 2014/03/04 00:06:40 This will select the minimum value within the firs
mikhal1 2014/03/04 00:28:45 That indeed is the intention, the underlying assum
379 ++time_offset_counter_;
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « media/cast/video_receiver/video_receiver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698