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_sender/video_sender.h" | 5 #include "media/cast/video_sender/video_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 VLOG(1) << "Received duplicate ACK for frame " << latest_acked_frame_id_; | 314 VLOG(1) << "Received duplicate ACK for frame " << latest_acked_frame_id_; |
315 ResendForKickstart(); | 315 ResendForKickstart(); |
316 } | 316 } |
317 } else { | 317 } else { |
318 // Only count duplicated ACKs if there is no NACK request in between. | 318 // Only count duplicated ACKs if there is no NACK request in between. |
319 // This is to avoid aggresive resend. | 319 // This is to avoid aggresive resend. |
320 duplicate_ack_counter_ = 0; | 320 duplicate_ack_counter_ = 0; |
321 | 321 |
322 // A NACK is also used to cancel pending re-transmissions. | 322 // A NACK is also used to cancel pending re-transmissions. |
323 transport_sender_->ResendPackets( | 323 transport_sender_->ResendPackets( |
324 false, cast_feedback.missing_frames_and_packets_, true); | 324 false, cast_feedback.missing_frames_and_packets_, true, rtt); |
325 } | 325 } |
326 | 326 |
327 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 327 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
328 congestion_control_.AckFrame(cast_feedback.ack_frame_id_, now); | 328 congestion_control_.AckFrame(cast_feedback.ack_frame_id_, now); |
329 | 329 |
330 RtpTimestamp rtp_timestamp = | 330 RtpTimestamp rtp_timestamp = |
331 frame_id_to_rtp_timestamp_[cast_feedback.ack_frame_id_ & 0xff]; | 331 frame_id_to_rtp_timestamp_[cast_feedback.ack_frame_id_ & 0xff]; |
332 cast_environment_->Logging()->InsertFrameEvent(now, | 332 cast_environment_->Logging()->InsertFrameEvent(now, |
333 FRAME_ACK_RECEIVED, | 333 FRAME_ACK_RECEIVED, |
334 VIDEO_EVENT, | 334 VIDEO_EVENT, |
335 rtp_timestamp, | 335 rtp_timestamp, |
336 cast_feedback.ack_frame_id_); | 336 cast_feedback.ack_frame_id_); |
337 | 337 |
338 const bool is_acked_out_of_order = | 338 const bool is_acked_out_of_order = |
339 static_cast<int32>(cast_feedback.ack_frame_id_ - | 339 static_cast<int32>(cast_feedback.ack_frame_id_ - |
340 latest_acked_frame_id_) < 0; | 340 latest_acked_frame_id_) < 0; |
341 VLOG(2) << "Received ACK" << (is_acked_out_of_order ? " out-of-order" : "") | 341 VLOG(2) << "Received ACK" << (is_acked_out_of_order ? " out-of-order" : "") |
342 << " for frame " << cast_feedback.ack_frame_id_; | 342 << " for frame " << cast_feedback.ack_frame_id_; |
343 if (!is_acked_out_of_order) { | 343 if (!is_acked_out_of_order) { |
344 // Cancel resends of acked frames. | 344 // Cancel resends of acked frames. |
345 MissingFramesAndPacketsMap missing_frames_and_packets; | 345 MissingFramesAndPacketsMap missing_frames_and_packets; |
346 PacketIdSet missing; | 346 PacketIdSet missing; |
347 while (latest_acked_frame_id_ != cast_feedback.ack_frame_id_) { | 347 while (latest_acked_frame_id_ != cast_feedback.ack_frame_id_) { |
348 latest_acked_frame_id_++; | 348 latest_acked_frame_id_++; |
349 missing_frames_and_packets[latest_acked_frame_id_] = missing; | 349 missing_frames_and_packets[latest_acked_frame_id_] = missing; |
350 } | 350 } |
351 transport_sender_->ResendPackets(false, missing_frames_and_packets, true); | 351 transport_sender_->ResendPackets( |
| 352 false, missing_frames_and_packets, true, rtt); |
352 latest_acked_frame_id_ = cast_feedback.ack_frame_id_; | 353 latest_acked_frame_id_ = cast_feedback.ack_frame_id_; |
353 } | 354 } |
354 } | 355 } |
355 | 356 |
356 bool VideoSender::AreTooManyFramesInFlight() const { | 357 bool VideoSender::AreTooManyFramesInFlight() const { |
357 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 358 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
358 int frames_in_flight = frames_in_encoder_; | 359 int frames_in_flight = frames_in_encoder_; |
359 if (!last_send_time_.is_null()) { | 360 if (!last_send_time_.is_null()) { |
360 frames_in_flight += | 361 frames_in_flight += |
361 static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_); | 362 static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_); |
(...skipping 13 matching lines...) Expand all Loading... |
375 // Send the first packet of the last encoded frame to kick start | 376 // Send the first packet of the last encoded frame to kick start |
376 // retransmission. This gives enough information to the receiver what | 377 // retransmission. This gives enough information to the receiver what |
377 // packets and frames are missing. | 378 // packets and frames are missing. |
378 MissingFramesAndPacketsMap missing_frames_and_packets; | 379 MissingFramesAndPacketsMap missing_frames_and_packets; |
379 PacketIdSet missing; | 380 PacketIdSet missing; |
380 missing.insert(kRtcpCastLastPacket); | 381 missing.insert(kRtcpCastLastPacket); |
381 missing_frames_and_packets.insert( | 382 missing_frames_and_packets.insert( |
382 std::make_pair(last_sent_frame_id_, missing)); | 383 std::make_pair(last_sent_frame_id_, missing)); |
383 last_send_time_ = cast_environment_->Clock()->NowTicks(); | 384 last_send_time_ = cast_environment_->Clock()->NowTicks(); |
384 | 385 |
| 386 base::TimeDelta rtt; |
| 387 base::TimeDelta avg_rtt; |
| 388 base::TimeDelta min_rtt; |
| 389 base::TimeDelta max_rtt; |
| 390 rtcp_.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt); |
| 391 |
385 // Sending this extra packet is to kick-start the session. There is | 392 // Sending this extra packet is to kick-start the session. There is |
386 // no need to optimize re-transmission for this case. | 393 // no need to optimize re-transmission for this case. |
387 transport_sender_->ResendPackets(false, missing_frames_and_packets, | 394 transport_sender_->ResendPackets(false, missing_frames_and_packets, |
388 false); | 395 false, avg_rtt); |
389 } | 396 } |
390 | 397 |
391 } // namespace cast | 398 } // namespace cast |
392 } // namespace media | 399 } // namespace media |
OLD | NEW |