Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sender/frame_sender.h" | 5 #include "media/cast/sender/frame_sender.h" |
| 6 | 6 |
| 7 namespace media { | 7 namespace media { |
| 8 namespace cast { | 8 namespace cast { |
| 9 namespace { | 9 namespace { |
| 10 const int kMinSchedulingDelayMs = 1; | 10 const int kMinSchedulingDelayMs = 1; |
| 11 } // namespace | 11 } // namespace |
| 12 | 12 |
| 13 FrameSender::FrameSender(scoped_refptr<CastEnvironment> cast_environment, | 13 FrameSender::FrameSender(scoped_refptr<CastEnvironment> cast_environment, |
| 14 CastTransportSender* const transport_sender, | 14 CastTransportSender* const transport_sender, |
| 15 base::TimeDelta rtcp_interval, | 15 base::TimeDelta rtcp_interval, |
| 16 int rtp_timebase, | 16 int rtp_timebase, |
| 17 uint32 ssrc, | 17 uint32 ssrc, |
| 18 double max_frame_rate, | 18 double max_frame_rate, |
| 19 base::TimeDelta playout_delay) | 19 base::TimeDelta playout_delay) |
| 20 : cast_environment_(cast_environment), | 20 : cast_environment_(cast_environment), |
| 21 transport_sender_(transport_sender), | 21 transport_sender_(transport_sender), |
| 22 ssrc_(ssrc), | 22 ssrc_(ssrc), |
| 23 rtt_available_(false), | 23 rtt_available_(false), |
| 24 rtcp_interval_(rtcp_interval), | 24 rtcp_interval_(rtcp_interval), |
| 25 max_frame_rate_(max_frame_rate), | 25 max_frame_rate_(max_frame_rate), |
| 26 frames_in_encoder_(0), | |
| 26 num_aggressive_rtcp_reports_sent_(0), | 27 num_aggressive_rtcp_reports_sent_(0), |
| 27 last_sent_frame_id_(0), | 28 last_sent_frame_id_(0), |
| 28 latest_acked_frame_id_(0), | 29 latest_acked_frame_id_(0), |
| 29 duplicate_ack_counter_(0), | 30 duplicate_ack_counter_(0), |
| 30 rtp_timebase_(rtp_timebase), | 31 rtp_timebase_(rtp_timebase), |
| 31 weak_factory_(this) { | 32 weak_factory_(this) { |
| 32 DCHECK_GT(rtp_timebase_, 0); | 33 DCHECK_GT(rtp_timebase_, 0); |
| 33 SetTargetPlayoutDelay(playout_delay); | 34 SetTargetPlayoutDelay(playout_delay); |
| 34 send_target_playout_delay_ = false; | 35 send_target_playout_delay_ = false; |
| 35 memset(frame_rtp_timestamps_, 0, sizeof(frame_rtp_timestamps_)); | 36 memset(frame_rtp_timestamps_, 0, sizeof(frame_rtp_timestamps_)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 152 } |
| 152 | 153 |
| 153 base::TimeTicks FrameSender::GetRecordedReferenceTime(uint32 frame_id) const { | 154 base::TimeTicks FrameSender::GetRecordedReferenceTime(uint32 frame_id) const { |
| 154 return frame_reference_times_[frame_id % arraysize(frame_reference_times_)]; | 155 return frame_reference_times_[frame_id % arraysize(frame_reference_times_)]; |
| 155 } | 156 } |
| 156 | 157 |
| 157 RtpTimestamp FrameSender::GetRecordedRtpTimestamp(uint32 frame_id) const { | 158 RtpTimestamp FrameSender::GetRecordedRtpTimestamp(uint32 frame_id) const { |
| 158 return frame_rtp_timestamps_[frame_id % arraysize(frame_rtp_timestamps_)]; | 159 return frame_rtp_timestamps_[frame_id % arraysize(frame_rtp_timestamps_)]; |
| 159 } | 160 } |
| 160 | 161 |
| 162 bool FrameSender::ShouldDropNextFrame(base::TimeTicks capture_time) const { | |
| 163 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | |
| 164 int frames_in_flight = 0; | |
| 165 base::TimeDelta duration_in_flight; | |
| 166 if (!last_send_time_.is_null()) { | |
| 167 frames_in_flight = | |
| 168 static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_); | |
| 169 if (frames_in_flight > 0) { | |
| 170 const uint32 oldest_unacked_frame_id = latest_acked_frame_id_ + 1; | |
| 171 duration_in_flight = | |
| 172 capture_time - GetRecordedReferenceTime(oldest_unacked_frame_id); | |
| 173 } | |
| 174 } | |
| 175 frames_in_flight += frames_in_encoder_; | |
| 176 VLOG(2) << frames_in_flight | |
| 177 << " frames in flight; last sent: " << last_sent_frame_id_ | |
| 178 << "; latest acked: " << latest_acked_frame_id_ | |
| 179 << "; frames in encoder: " << frames_in_encoder_ | |
| 180 << "; duration in flight: " | |
| 181 << duration_in_flight.InMicroseconds() << " usec (" | |
| 182 << (target_playout_delay_ > base::TimeDelta() ? | |
| 183 100 * duration_in_flight / target_playout_delay_ : | |
| 184 kint64max) << "%)"; | |
| 185 return frames_in_flight >= max_unacked_frames_ || | |
| 186 duration_in_flight >= target_playout_delay_; | |
|
Alpha Left Google
2014/09/05 20:02:07
What's the reason of choosing "duration_in_flight
miu
2014/09/05 20:40:27
You can ignore this:
1. hubbe@ has already moved
| |
| 187 } | |
| 188 | |
| 161 } // namespace cast | 189 } // namespace cast |
| 162 } // namespace media | 190 } // namespace media |
| OLD | NEW |