Commit 0bd0ca2c authored by mikhal@chromium.org's avatar mikhal@chromium.org

Cast: Using a min filter to compute time offset

Modifying the time offset filter to take to minimum of the first 10 values. 
Once ten offset values were seen, the value will be constant for the entire session. 
This may be justified by the fact we are seeking the offset between sender and
 receiver without accounting the network jitter.

Review URL: https://codereview.chromium.org/186043003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255166 0039d316-1c4b-4281-b951-d872f2087c98
parent 028053d4
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
namespace { namespace {
static const int64 kMinSchedulingDelayMs = 1; static const int64 kMinSchedulingDelayMs = 1;
static const int64 kMinTimeBetweenOffsetUpdatesMs = 2000; static const int64 kMinTimeBetweenOffsetUpdatesMs = 1000;
static const int kTimeOffsetFilter = 8; static const int kTimeOffsetMaxCounter = 10;
static const int64_t kMinProcessIntervalMs = 5; static const int64_t kMinProcessIntervalMs = 5;
} // namespace } // namespace
...@@ -107,6 +107,7 @@ VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment, ...@@ -107,6 +107,7 @@ VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment,
incoming_payload_callback_.get()), incoming_payload_callback_.get()),
rtp_video_receiver_statistics_( rtp_video_receiver_statistics_(
new LocalRtpReceiverStatistics(&rtp_receiver_)), new LocalRtpReceiverStatistics(&rtp_receiver_)),
time_offset_counter_(0),
decryptor_(), decryptor_(),
time_incoming_packet_updated_(false), time_incoming_packet_updated_(false),
incoming_rtp_timestamp_(0), incoming_rtp_timestamp_(0),
...@@ -356,7 +357,7 @@ base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, ...@@ -356,7 +357,7 @@ base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now,
base::TimeTicks rtp_timestamp_in_ticks; base::TimeTicks rtp_timestamp_in_ticks;
// Compute the time offset_in_ticks based on the incoming_rtp_timestamp_. // Compute the time offset_in_ticks based on the incoming_rtp_timestamp_.
if (time_offset_.InMilliseconds() == 0) { if (time_offset_counter_ == 0) {
if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency, if (!rtcp_->RtpTimestampInSenderTime(kVideoFrequency,
incoming_rtp_timestamp_, incoming_rtp_timestamp_,
&rtp_timestamp_in_ticks)) { &rtp_timestamp_in_ticks)) {
...@@ -364,7 +365,8 @@ base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, ...@@ -364,7 +365,8 @@ base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now,
// possible. // possible.
return now; return now;
} }
time_offset_ = time_incoming_packet_ - rtp_timestamp_in_ticks; ++time_offset_counter_;
return now;
} else if (time_incoming_packet_updated_) { } else if (time_incoming_packet_updated_) {
if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency, if (rtcp_->RtpTimestampInSenderTime(kVideoFrequency,
incoming_rtp_timestamp_, incoming_rtp_timestamp_,
...@@ -372,8 +374,16 @@ base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now, ...@@ -372,8 +374,16 @@ base::TimeTicks VideoReceiver::GetRenderTime(base::TimeTicks now,
// Time to update the time_offset. // Time to update the time_offset.
base::TimeDelta time_offset = base::TimeDelta time_offset =
time_incoming_packet_ - rtp_timestamp_in_ticks; time_incoming_packet_ - rtp_timestamp_in_ticks;
time_offset_ = ((kTimeOffsetFilter - 1) * time_offset_ + time_offset) / // Taking the minimum of the first kTimeOffsetMaxCounter values. We are
kTimeOffsetFilter; // assuming that we are looking for the minimum offset, which will occur
// when network conditions are the best. This should occur at least once
// within the first kTimeOffsetMaxCounter samples. Any drift should be
// very slow, and negligible for this use case.
if (time_offset_counter_ == 1)
time_offset_ = time_offset;
else if (time_offset_counter_ < kTimeOffsetMaxCounter)
time_offset_ = std::min(time_offset_, time_offset);
++time_offset_counter_;
} }
} }
// Reset |time_incoming_packet_updated_| to enable a future measurement. // Reset |time_incoming_packet_updated_| to enable a future measurement.
......
...@@ -115,6 +115,7 @@ class VideoReceiver : public base::NonThreadSafe, ...@@ -115,6 +115,7 @@ class VideoReceiver : public base::NonThreadSafe,
scoped_ptr<Rtcp> rtcp_; scoped_ptr<Rtcp> rtcp_;
scoped_ptr<RtpReceiverStatistics> rtp_video_receiver_statistics_; scoped_ptr<RtpReceiverStatistics> rtp_video_receiver_statistics_;
base::TimeDelta time_offset_; // Sender-receiver offset estimation. base::TimeDelta time_offset_; // Sender-receiver offset estimation.
int time_offset_counter_;
transport::TransportEncryptionHandler decryptor_; transport::TransportEncryptionHandler decryptor_;
std::list<VideoFrameEncodedCallback> queued_encoded_callbacks_; std::list<VideoFrameEncodedCallback> queued_encoded_callbacks_;
bool time_incoming_packet_updated_; bool time_incoming_packet_updated_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment