Index: media/cast/sender/video_sender.cc |
diff --git a/media/cast/sender/video_sender.cc b/media/cast/sender/video_sender.cc |
index f0e3a1440c6c32dc3d59cc7344ee49cf68c6d330..5b095ce4a8b9a9ce36649b803149f6664c63a02f 100644 |
--- a/media/cast/sender/video_sender.cc |
+++ b/media/cast/sender/video_sender.cc |
@@ -126,7 +126,7 @@ void VideoSender::InsertRawVideoFrame( |
"timestamp", capture_time.ToInternalValue(), |
"rtp_timestamp", rtp_timestamp); |
- if (AreTooManyFramesInFlight()) { |
+ if (ShouldDropNextFrame(capture_time)) { |
VLOG(1) << "Dropping frame due to too many frames currently in-flight."; |
return; |
} |
@@ -174,6 +174,8 @@ void VideoSender::SendEncodedVideoFrame( |
// Also, schedule the periodic frame re-send checks. |
if (is_first_frame_to_be_sent) { |
latest_acked_frame_id_ = frame_id - 1; |
+ frame_id_to_rtp_timestamp_[latest_acked_frame_id_ & 0xff] = |
+ encoded_frame->rtp_timestamp; |
ScheduleNextResendCheck(); |
} |
@@ -338,18 +340,34 @@ void VideoSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) { |
} |
} |
-bool VideoSender::AreTooManyFramesInFlight() const { |
+bool VideoSender::ShouldDropNextFrame(base::TimeTicks capture_time) const { |
DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
- int frames_in_flight = frames_in_encoder_; |
+ int frames_in_flight = 0; |
+ int32 rtp_duration_in_flight = 0; |
if (!last_send_time_.is_null()) { |
- frames_in_flight += |
+ frames_in_flight = |
static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_); |
+ uint32 estimated_rtp_timestamp; |
+ if (frames_in_flight > 0 && |
+ rtp_timestamp_helper_.EstimateRtpTimestamp(capture_time, |
+ &estimated_rtp_timestamp)) { |
+ const uint32 oldest_unacked_frame_id = latest_acked_frame_id_ + 1; |
+ rtp_duration_in_flight = static_cast<int32>( |
+ estimated_rtp_timestamp - |
+ frame_id_to_rtp_timestamp_[oldest_unacked_frame_id & 0xff]); |
+ } |
} |
+ frames_in_flight += frames_in_encoder_; |
VLOG(2) << frames_in_flight |
<< " frames in flight; last sent: " << last_sent_frame_id_ |
- << " latest acked: " << latest_acked_frame_id_ |
- << " frames in encoder: " << frames_in_encoder_; |
- return frames_in_flight >= max_unacked_frames_; |
+ << "; latest acked: " << latest_acked_frame_id_ |
+ << "; frames in encoder: " << frames_in_encoder_ |
+ << "; duration in flight: " |
+ << (max_unacked_rtp_delta_ > 0 ? |
+ 100 * rtp_duration_in_flight / max_unacked_rtp_delta_ : |
+ kint32max) << "%"; |
+ return frames_in_flight >= max_unacked_frames_ || |
+ rtp_duration_in_flight >= max_unacked_rtp_delta_; |
} |
void VideoSender::ResendForKickstart() { |