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

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

Issue 343523005: Cast: Avoid retransmit if we sent the same packet recently (less than RTT) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bugfix Created 6 years, 6 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
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/audio_sender/audio_sender.h" 5 #include "media/cast/audio_sender/audio_sender.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "media/cast/audio_sender/audio_encoder.h" 10 #include "media/cast/audio_sender/audio_encoder.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // TODO(miu): The values "2" and "3" should be derived from configuration. 245 // TODO(miu): The values "2" and "3" should be derived from configuration.
246 if (duplicate_ack_counter_ >= 2 && duplicate_ack_counter_ % 3 == 2) { 246 if (duplicate_ack_counter_ >= 2 && duplicate_ack_counter_ % 3 == 2) {
247 VLOG(1) << "Received duplicate ACK for frame " << latest_acked_frame_id_; 247 VLOG(1) << "Received duplicate ACK for frame " << latest_acked_frame_id_;
248 ResendForKickstart(); 248 ResendForKickstart();
249 } 249 }
250 } else { 250 } else {
251 // Only count duplicated ACKs if there is no NACK request in between. 251 // Only count duplicated ACKs if there is no NACK request in between.
252 // This is to avoid aggresive resend. 252 // This is to avoid aggresive resend.
253 duplicate_ack_counter_ = 0; 253 duplicate_ack_counter_ = 0;
254 254
255 base::TimeDelta rtt;
256 base::TimeDelta avg_rtt;
257 base::TimeDelta min_rtt;
258 base::TimeDelta max_rtt;
259 rtcp_.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt);
260
255 // A NACK is also used to cancel pending re-transmissions. 261 // A NACK is also used to cancel pending re-transmissions.
256 transport_sender_->ResendPackets( 262 transport_sender_->ResendPackets(
257 true, cast_feedback.missing_frames_and_packets_, true); 263 true, cast_feedback.missing_frames_and_packets_, false, min_rtt);
258 } 264 }
259 265
260 const base::TimeTicks now = cast_environment_->Clock()->NowTicks(); 266 const base::TimeTicks now = cast_environment_->Clock()->NowTicks();
261 267
262 const RtpTimestamp rtp_timestamp = 268 const RtpTimestamp rtp_timestamp =
263 frame_id_to_rtp_timestamp_[cast_feedback.ack_frame_id_ & 0xff]; 269 frame_id_to_rtp_timestamp_[cast_feedback.ack_frame_id_ & 0xff];
264 cast_environment_->Logging()->InsertFrameEvent(now, 270 cast_environment_->Logging()->InsertFrameEvent(now,
265 FRAME_ACK_RECEIVED, 271 FRAME_ACK_RECEIVED,
266 AUDIO_EVENT, 272 AUDIO_EVENT,
267 rtp_timestamp, 273 rtp_timestamp,
268 cast_feedback.ack_frame_id_); 274 cast_feedback.ack_frame_id_);
269 275
270 const bool is_acked_out_of_order = 276 const bool is_acked_out_of_order =
271 static_cast<int32>(cast_feedback.ack_frame_id_ - 277 static_cast<int32>(cast_feedback.ack_frame_id_ -
272 latest_acked_frame_id_) < 0; 278 latest_acked_frame_id_) < 0;
273 VLOG(2) << "Received ACK" << (is_acked_out_of_order ? " out-of-order" : "") 279 VLOG(2) << "Received ACK" << (is_acked_out_of_order ? " out-of-order" : "")
274 << " for frame " << cast_feedback.ack_frame_id_; 280 << " for frame " << cast_feedback.ack_frame_id_;
275 if (!is_acked_out_of_order) { 281 if (!is_acked_out_of_order) {
276 // Cancel resends of acked frames. 282 // Cancel resends of acked frames.
277 MissingFramesAndPacketsMap missing_frames_and_packets; 283 MissingFramesAndPacketsMap missing_frames_and_packets;
278 PacketIdSet missing; 284 PacketIdSet missing;
279 while (latest_acked_frame_id_ != cast_feedback.ack_frame_id_) { 285 while (latest_acked_frame_id_ != cast_feedback.ack_frame_id_) {
280 latest_acked_frame_id_++; 286 latest_acked_frame_id_++;
281 missing_frames_and_packets[latest_acked_frame_id_] = missing; 287 missing_frames_and_packets[latest_acked_frame_id_] = missing;
282 } 288 }
283 transport_sender_->ResendPackets(true, missing_frames_and_packets, true); 289 transport_sender_->ResendPackets(
290 true, missing_frames_and_packets, true, base::TimeDelta());
284 latest_acked_frame_id_ = cast_feedback.ack_frame_id_; 291 latest_acked_frame_id_ = cast_feedback.ack_frame_id_;
285 } 292 }
286 } 293 }
287 294
288 bool AudioSender::AreTooManyFramesInFlight() const { 295 bool AudioSender::AreTooManyFramesInFlight() const {
289 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 296 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
290 int frames_in_flight = 0; 297 int frames_in_flight = 0;
291 if (!last_send_time_.is_null()) { 298 if (!last_send_time_.is_null()) {
292 frames_in_flight += 299 frames_in_flight +=
293 static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_); 300 static_cast<int32>(last_sent_frame_id_ - latest_acked_frame_id_);
(...skipping 12 matching lines...) Expand all
306 // Send the first packet of the last encoded frame to kick start 313 // Send the first packet of the last encoded frame to kick start
307 // retransmission. This gives enough information to the receiver what 314 // retransmission. This gives enough information to the receiver what
308 // packets and frames are missing. 315 // packets and frames are missing.
309 MissingFramesAndPacketsMap missing_frames_and_packets; 316 MissingFramesAndPacketsMap missing_frames_and_packets;
310 PacketIdSet missing; 317 PacketIdSet missing;
311 missing.insert(kRtcpCastLastPacket); 318 missing.insert(kRtcpCastLastPacket);
312 missing_frames_and_packets.insert( 319 missing_frames_and_packets.insert(
313 std::make_pair(last_sent_frame_id_, missing)); 320 std::make_pair(last_sent_frame_id_, missing));
314 last_send_time_ = cast_environment_->Clock()->NowTicks(); 321 last_send_time_ = cast_environment_->Clock()->NowTicks();
315 322
323 base::TimeDelta rtt;
324 base::TimeDelta avg_rtt;
325 base::TimeDelta min_rtt;
326 base::TimeDelta max_rtt;
327 rtcp_.Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt);
328
316 // Sending this extra packet is to kick-start the session. There is 329 // Sending this extra packet is to kick-start the session. There is
317 // no need to optimize re-transmission for this case. 330 // no need to optimize re-transmission for this case.
318 transport_sender_->ResendPackets(true, missing_frames_and_packets, 331 transport_sender_->ResendPackets(
319 false); 332 true, missing_frames_and_packets, false, min_rtt);
320 } 333 }
321 334
322 } // namespace cast 335 } // namespace cast
323 } // namespace media 336 } // namespace media
OLDNEW
« no previous file with comments | « chrome/renderer/media/cast_transport_sender_ipc.cc ('k') | media/cast/logging/logging_defines.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698