OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/media/cast_remoting_sender.h" | 5 #include "chrome/browser/media/cast_remoting_sender.h" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <map> | 8 #include <map> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
14 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/stl_util.h" |
15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
16 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
17 #include "media/base/bind_to_current_loop.h" | 19 #include "media/base/bind_to_current_loop.h" |
18 #include "media/cast/constants.h" | 20 #include "media/cast/constants.h" |
19 | 21 |
| 22 using content::BrowserThread; |
| 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 // Global map for looking-up CastRemotingSender instances by their | 26 // Global map for looking-up CastRemotingSender instances by their |
23 // |remoting_stream_id_|. | 27 // |rtp_stream_id|. |
24 using CastRemotingSenderMap = std::map<int32_t, cast::CastRemotingSender*>; | 28 using CastRemotingSenderMap = std::map<int32_t, cast::CastRemotingSender*>; |
25 base::LazyInstance<CastRemotingSenderMap>::Leaky g_sender_map = | 29 base::LazyInstance<CastRemotingSenderMap>::Leaky g_sender_map = |
26 LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
27 | 31 |
28 constexpr base::TimeDelta kMinSchedulingDelay = | 32 constexpr base::TimeDelta kMinSchedulingDelay = |
29 base::TimeDelta::FromMilliseconds(1); | 33 base::TimeDelta::FromMilliseconds(1); |
30 constexpr base::TimeDelta kMaxAckDelay = base::TimeDelta::FromMilliseconds(800); | 34 constexpr base::TimeDelta kMaxAckDelay = base::TimeDelta::FromMilliseconds(800); |
31 constexpr base::TimeDelta kMinAckDelay = base::TimeDelta::FromMilliseconds(400); | |
32 constexpr base::TimeDelta kReceiverProcessTime = | 35 constexpr base::TimeDelta kReceiverProcessTime = |
33 base::TimeDelta::FromMilliseconds(250); | 36 base::TimeDelta::FromMilliseconds(250); |
34 | 37 |
35 } // namespace | 38 } // namespace |
36 | 39 |
37 namespace cast { | 40 namespace cast { |
38 | 41 |
39 class CastRemotingSender::RemotingRtcpClient final | 42 class CastRemotingSender::RemotingRtcpClient final |
40 : public media::cast::RtcpObserver { | 43 : public media::cast::RtcpObserver { |
41 public: | 44 public: |
(...skipping 23 matching lines...) Expand all Loading... |
65 DISALLOW_COPY_AND_ASSIGN(RemotingRtcpClient); | 68 DISALLOW_COPY_AND_ASSIGN(RemotingRtcpClient); |
66 }; | 69 }; |
67 | 70 |
68 // Convenience macro used in logging statements throughout this file. | 71 // Convenience macro used in logging statements throughout this file. |
69 #define SENDER_SSRC (is_audio_ ? "AUDIO[" : "VIDEO[") << ssrc_ << "] " | 72 #define SENDER_SSRC (is_audio_ ? "AUDIO[" : "VIDEO[") << ssrc_ << "] " |
70 | 73 |
71 CastRemotingSender::CastRemotingSender( | 74 CastRemotingSender::CastRemotingSender( |
72 scoped_refptr<media::cast::CastEnvironment> cast_environment, | 75 scoped_refptr<media::cast::CastEnvironment> cast_environment, |
73 media::cast::CastTransport* transport, | 76 media::cast::CastTransport* transport, |
74 const media::cast::CastTransportRtpConfig& config) | 77 const media::cast::CastTransportRtpConfig& config) |
75 : remoting_stream_id_(config.rtp_stream_id), | 78 : rtp_stream_id_(config.rtp_stream_id), |
76 cast_environment_(std::move(cast_environment)), | 79 cast_environment_(std::move(cast_environment)), |
77 transport_(transport), | 80 transport_(transport), |
78 ssrc_(config.ssrc), | 81 ssrc_(config.ssrc), |
79 is_audio_(config.rtp_payload_type == | 82 is_audio_(config.rtp_payload_type == |
80 media::cast::RtpPayloadType::REMOTE_AUDIO), | 83 media::cast::RtpPayloadType::REMOTE_AUDIO), |
| 84 binding_(this), |
81 max_ack_delay_(kMaxAckDelay), | 85 max_ack_delay_(kMaxAckDelay), |
82 last_sent_frame_id_(media::cast::FrameId::first() - 1), | 86 last_sent_frame_id_(media::cast::FrameId::first() - 1), |
83 latest_acked_frame_id_(media::cast::FrameId::first() - 1), | 87 latest_acked_frame_id_(media::cast::FrameId::first() - 1), |
84 duplicate_ack_counter_(0), | 88 duplicate_ack_counter_(0), |
85 last_frame_was_canceled_(false), | 89 input_queue_discards_remaining_(0), |
| 90 flow_restart_pending_(true), |
86 weak_factory_(this) { | 91 weak_factory_(this) { |
| 92 // Confirm this constructor is running on the IO BrowserThread and the |
| 93 // CastEnvironment::MAIN thread is the same thread. |
| 94 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
87 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); | 95 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
88 | 96 |
89 CastRemotingSender*& pointer_in_map = g_sender_map.Get()[remoting_stream_id_]; | 97 CastRemotingSender*& pointer_in_map = g_sender_map.Get()[rtp_stream_id_]; |
90 DCHECK(!pointer_in_map); | 98 DCHECK(!pointer_in_map); |
91 pointer_in_map = this; | 99 pointer_in_map = this; |
| 100 |
92 transport_->InitializeStream( | 101 transport_->InitializeStream( |
93 config, base::MakeUnique<RemotingRtcpClient>(weak_factory_.GetWeakPtr())); | 102 config, base::MakeUnique<RemotingRtcpClient>(weak_factory_.GetWeakPtr())); |
94 } | 103 } |
95 | 104 |
96 CastRemotingSender::~CastRemotingSender() { | 105 CastRemotingSender::~CastRemotingSender() { |
97 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); | 106 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 107 g_sender_map.Pointer()->erase(rtp_stream_id_); |
| 108 } |
98 | 109 |
99 g_sender_map.Pointer()->erase(remoting_stream_id_); | 110 // static |
| 111 void CastRemotingSender::FindAndBind( |
| 112 int32_t rtp_stream_id, |
| 113 mojo::ScopedDataPipeConsumerHandle pipe, |
| 114 media::mojom::RemotingDataStreamSenderRequest request, |
| 115 const base::Closure& error_callback) { |
| 116 // CastRemotingSender lives entirely on the IO thread, so trampoline if |
| 117 // necessary. |
| 118 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 119 BrowserThread::PostTask( |
| 120 BrowserThread::IO, FROM_HERE, |
| 121 base::Bind(&CastRemotingSender::FindAndBind, rtp_stream_id, |
| 122 base::Passed(&pipe), base::Passed(&request), |
| 123 // Using media::BindToCurrentLoop() so the |error_callback| |
| 124 // is trampolined back to the original thread. |
| 125 media::BindToCurrentLoop(error_callback))); |
| 126 return; |
| 127 } |
| 128 |
| 129 DCHECK(!error_callback.is_null()); |
| 130 |
| 131 // Look-up the CastRemotingSender instance by its |rtp_stream_id|. |
| 132 const auto it = g_sender_map.Pointer()->find(rtp_stream_id); |
| 133 if (it == g_sender_map.Pointer()->end()) { |
| 134 DLOG(ERROR) << "Cannot find CastRemotingSender instance by ID: " |
| 135 << rtp_stream_id; |
| 136 error_callback.Run(); |
| 137 return; |
| 138 } |
| 139 CastRemotingSender* const sender = it->second; |
| 140 |
| 141 // Confirm that the CastRemotingSender isn't already bound to a message pipe. |
| 142 if (sender->binding_.is_bound()) { |
| 143 DLOG(ERROR) << "Attempt to bind to CastRemotingSender a second time (id=" |
| 144 << rtp_stream_id << ")!"; |
| 145 error_callback.Run(); |
| 146 return; |
| 147 } |
| 148 |
| 149 DCHECK(sender->error_callback_.is_null()); |
| 150 sender->error_callback_ = error_callback; |
| 151 |
| 152 sender->pipe_ = std::move(pipe); |
| 153 sender->pipe_watcher_.Start( |
| 154 sender->pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, |
| 155 base::Bind(&CastRemotingSender::ProcessInputQueue, |
| 156 base::Unretained(sender))); |
| 157 sender->binding_.Bind(std::move(request)); |
| 158 sender->binding_.set_connection_error_handler(sender->error_callback_); |
100 } | 159 } |
101 | 160 |
102 void CastRemotingSender::OnReceivedRtt(base::TimeDelta round_trip_time) { | 161 void CastRemotingSender::OnReceivedRtt(base::TimeDelta round_trip_time) { |
103 DCHECK_GT(round_trip_time, base::TimeDelta()); | 162 DCHECK_GT(round_trip_time, base::TimeDelta()); |
104 current_round_trip_time_ = round_trip_time; | 163 current_round_trip_time_ = round_trip_time; |
105 max_ack_delay_ = 2 * current_round_trip_time_ + kReceiverProcessTime; | 164 max_ack_delay_ = 2 * std::max(current_round_trip_time_, base::TimeDelta()) + |
106 max_ack_delay_ = | 165 kReceiverProcessTime; |
107 std::max(std::min(max_ack_delay_, kMaxAckDelay), kMinAckDelay); | 166 max_ack_delay_ = std::min(max_ack_delay_, kMaxAckDelay); |
108 } | 167 } |
109 | 168 |
110 void CastRemotingSender::ResendCheck() { | 169 void CastRemotingSender::ResendCheck() { |
111 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); | 170 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
112 | 171 |
113 DCHECK(!last_send_time_.is_null()); | 172 DCHECK(!last_send_time_.is_null()); |
114 const base::TimeDelta time_since_last_send = | 173 const base::TimeDelta time_since_last_send = |
115 cast_environment_->Clock()->NowTicks() - last_send_time_; | 174 cast_environment_->Clock()->NowTicks() - last_send_time_; |
116 if (time_since_last_send > max_ack_delay_) { | 175 if (time_since_last_send > max_ack_delay_) { |
117 if (latest_acked_frame_id_ == last_sent_frame_id_) { | 176 if (latest_acked_frame_id_ == last_sent_frame_id_) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 frames_to_cancel.push_back(latest_acked_frame_id_); | 295 frames_to_cancel.push_back(latest_acked_frame_id_); |
237 // This is a good place to match the trace for frame ids | 296 // This is a good place to match the trace for frame ids |
238 // since this ensures we not only track frame ids that are | 297 // since this ensures we not only track frame ids that are |
239 // implicitly ACKed, but also handles duplicate ACKs | 298 // implicitly ACKed, but also handles duplicate ACKs |
240 TRACE_EVENT_ASYNC_END1( | 299 TRACE_EVENT_ASYNC_END1( |
241 "cast.stream", is_audio_ ? "Audio Transport" : "Video Transport", | 300 "cast.stream", is_audio_ ? "Audio Transport" : "Video Transport", |
242 latest_acked_frame_id_.lower_32_bits(), "RTT_usecs", | 301 latest_acked_frame_id_.lower_32_bits(), "RTT_usecs", |
243 current_round_trip_time_.InMicroseconds()); | 302 current_round_trip_time_.InMicroseconds()); |
244 } while (latest_acked_frame_id_ < cast_feedback.ack_frame_id); | 303 } while (latest_acked_frame_id_ < cast_feedback.ack_frame_id); |
245 transport_->CancelSendingFrames(ssrc_, frames_to_cancel); | 304 transport_->CancelSendingFrames(ssrc_, frames_to_cancel); |
| 305 |
| 306 // One or more frames were canceled. This may allow pending input operations |
| 307 // to complete. |
| 308 ProcessInputQueue(MOJO_RESULT_OK); |
246 } | 309 } |
247 } | 310 } |
248 | 311 |
| 312 void CastRemotingSender::ConsumeDataChunk(uint32_t offset, uint32_t size, |
| 313 uint32_t total_payload_size) { |
| 314 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
| 315 input_queue_.push( |
| 316 base::Bind(&CastRemotingSender::TryConsumeDataChunk, |
| 317 base::Unretained(this), offset, size, total_payload_size)); |
| 318 ProcessInputQueue(MOJO_RESULT_OK); |
| 319 } |
| 320 |
249 void CastRemotingSender::SendFrame() { | 321 void CastRemotingSender::SendFrame() { |
250 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); | 322 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
| 323 input_queue_.push( |
| 324 base::Bind(&CastRemotingSender::TrySendFrame, base::Unretained(this))); |
| 325 ProcessInputQueue(MOJO_RESULT_OK); |
| 326 } |
251 | 327 |
| 328 void CastRemotingSender::ProcessInputQueue(MojoResult result) { |
| 329 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
| 330 while (!input_queue_.empty()) { |
| 331 if (!input_queue_.front().Run(input_queue_discards_remaining_ > 0)) |
| 332 break; // Operation must be retried later. Stop processing queue. |
| 333 input_queue_.pop(); |
| 334 if (input_queue_discards_remaining_ > 0) |
| 335 --input_queue_discards_remaining_; |
| 336 } |
| 337 } |
| 338 |
| 339 bool CastRemotingSender::TryConsumeDataChunk(uint32_t offset, uint32_t size, |
| 340 uint32_t total_payload_size, |
| 341 bool discard_data) { |
| 342 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
| 343 |
| 344 do { |
| 345 if (!pipe_.is_valid()) { |
| 346 VLOG(1) << SENDER_SSRC << "Data pipe handle no longer valid."; |
| 347 break; |
| 348 } |
| 349 |
| 350 if (offset + size > total_payload_size) { |
| 351 LOG(ERROR) |
| 352 << SENDER_SSRC << "BUG: offset + size > total_payload_size (" |
| 353 << offset << " + " << size << " > " << total_payload_size << ')'; |
| 354 break; |
| 355 } |
| 356 |
| 357 // If the data is to be discarded, do a data pipe read with the DISCARD flag |
| 358 // set. |
| 359 if (discard_data) { |
| 360 const MojoResult result = mojo::ReadDataRaw( |
| 361 pipe_.get(), nullptr, &size, |
| 362 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| 363 if (result == MOJO_RESULT_OK) |
| 364 return true; // Successfully discarded data. |
| 365 if (result == MOJO_RESULT_OUT_OF_RANGE) |
| 366 return false; // Retry later. |
| 367 LOG(ERROR) << SENDER_SSRC |
| 368 << "Unexpected result when discarding from data pipe (" |
| 369 << result << ')'; |
| 370 break; |
| 371 } |
| 372 |
| 373 // If |total_payload_size| has changed, resize the data string. If it has |
| 374 // not changed, the following statement will be a no-op. |
| 375 next_frame_data_.resize(total_payload_size); |
| 376 |
| 377 const MojoResult result = mojo::ReadDataRaw( |
| 378 pipe_.get(), base::string_as_array(&next_frame_data_) + offset, &size, |
| 379 MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| 380 if (result == MOJO_RESULT_OK) |
| 381 return true; // Successfully consumed data. |
| 382 if (result == MOJO_RESULT_OUT_OF_RANGE) |
| 383 return false; // Retry later. |
| 384 LOG(ERROR) |
| 385 << SENDER_SSRC << "Read from data pipe failed (" << result << ')'; |
| 386 } while (false); |
| 387 |
| 388 // If this point is reached, there was a fatal error. Shut things down and run |
| 389 // the error callback. |
| 390 pipe_watcher_.Cancel(); |
| 391 pipe_.reset(); |
| 392 binding_.Close(); |
| 393 error_callback_.Run(); |
| 394 return true; |
| 395 } |
| 396 |
| 397 bool CastRemotingSender::TrySendFrame(bool discard_data) { |
| 398 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
| 399 |
| 400 // If the frame's data is to be discarded, just return immediately. |
| 401 if (discard_data) |
| 402 return true; |
| 403 |
| 404 // If there would be too many frames in-flight, do not proceed. |
252 if (NumberOfFramesInFlight() >= media::cast::kMaxUnackedFrames) { | 405 if (NumberOfFramesInFlight() >= media::cast::kMaxUnackedFrames) { |
253 // TODO(xjz): Delay the sending of this frame and stop reading the next | 406 VLOG(1) << SENDER_SSRC |
254 // frame data. | 407 << "Cannot send frame now because too many frames are in flight."; |
255 return; | 408 return false; |
256 } | 409 } |
257 | 410 |
258 VLOG(2) << SENDER_SSRC | 411 VLOG(2) << SENDER_SSRC |
259 << "About to send another frame: last_sent=" << last_sent_frame_id_ | 412 << "About to send another frame: last_sent=" << last_sent_frame_id_ |
260 << ", latest_acked=" << latest_acked_frame_id_; | 413 << ", latest_acked=" << latest_acked_frame_id_; |
261 | 414 |
262 const media::cast::FrameId frame_id = last_sent_frame_id_ + 1; | 415 const media::cast::FrameId frame_id = last_sent_frame_id_ + 1; |
263 const bool is_first_frame_to_be_sent = last_send_time_.is_null(); | 416 const bool is_first_frame_to_be_sent = last_send_time_.is_null(); |
264 | 417 |
265 base::TimeTicks last_frame_reference_time = last_send_time_; | 418 base::TimeTicks last_frame_reference_time = last_send_time_; |
266 last_send_time_ = cast_environment_->Clock()->NowTicks(); | 419 last_send_time_ = cast_environment_->Clock()->NowTicks(); |
267 last_sent_frame_id_ = frame_id; | 420 last_sent_frame_id_ = frame_id; |
268 // If this is the first frame about to be sent, fake the value of | 421 // If this is the first frame about to be sent, fake the value of |
269 // |latest_acked_frame_id_| to indicate the receiver starts out all caught up. | 422 // |latest_acked_frame_id_| to indicate the receiver starts out all caught up. |
270 // Also, schedule the periodic frame re-send checks. | 423 // Also, schedule the periodic frame re-send checks. |
271 if (is_first_frame_to_be_sent) | 424 if (is_first_frame_to_be_sent) |
272 ScheduleNextResendCheck(); | 425 ScheduleNextResendCheck(); |
273 | 426 |
274 DVLOG(3) << "Sending remoting frame, id = " << frame_id; | 427 DVLOG(3) << "Sending remoting frame, id = " << frame_id; |
275 | 428 |
276 media::cast::EncodedFrame remoting_frame; | 429 media::cast::EncodedFrame remoting_frame; |
277 remoting_frame.frame_id = frame_id; | 430 remoting_frame.frame_id = frame_id; |
278 remoting_frame.dependency = | 431 if (flow_restart_pending_) { |
279 (is_first_frame_to_be_sent || last_frame_was_canceled_) | 432 remoting_frame.dependency = media::cast::EncodedFrame::KEY; |
280 ? media::cast::EncodedFrame::KEY | 433 flow_restart_pending_ = false; |
281 : media::cast::EncodedFrame::DEPENDENT; | 434 } else { |
| 435 DCHECK(!is_first_frame_to_be_sent); |
| 436 remoting_frame.dependency = media::cast::EncodedFrame::DEPENDENT; |
| 437 } |
282 remoting_frame.referenced_frame_id = | 438 remoting_frame.referenced_frame_id = |
283 remoting_frame.dependency == media::cast::EncodedFrame::KEY | 439 remoting_frame.dependency == media::cast::EncodedFrame::KEY |
284 ? frame_id | 440 ? frame_id |
285 : frame_id - 1; | 441 : frame_id - 1; |
286 remoting_frame.reference_time = last_send_time_; | 442 remoting_frame.reference_time = last_send_time_; |
287 media::cast::RtpTimeTicks last_frame_rtp_timestamp; | 443 media::cast::RtpTimeTicks last_frame_rtp_timestamp; |
288 if (is_first_frame_to_be_sent) { | 444 if (is_first_frame_to_be_sent) { |
289 last_frame_reference_time = remoting_frame.reference_time; | 445 last_frame_reference_time = remoting_frame.reference_time; |
290 last_frame_rtp_timestamp = | 446 last_frame_rtp_timestamp = |
291 media::cast::RtpTimeTicks() - media::cast::RtpTimeDelta::FromTicks(1); | 447 media::cast::RtpTimeTicks() - media::cast::RtpTimeDelta::FromTicks(1); |
(...skipping 18 matching lines...) Expand all Loading... |
310 remoting_event->media_type = | 466 remoting_event->media_type = |
311 is_audio_ ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT; | 467 is_audio_ ? media::cast::AUDIO_EVENT : media::cast::VIDEO_EVENT; |
312 remoting_event->rtp_timestamp = remoting_frame.rtp_timestamp; | 468 remoting_event->rtp_timestamp = remoting_frame.rtp_timestamp; |
313 remoting_event->frame_id = frame_id; | 469 remoting_event->frame_id = frame_id; |
314 remoting_event->size = remoting_frame.data.length(); | 470 remoting_event->size = remoting_frame.data.length(); |
315 remoting_event->key_frame = | 471 remoting_event->key_frame = |
316 remoting_frame.dependency == media::cast::EncodedFrame::KEY; | 472 remoting_frame.dependency == media::cast::EncodedFrame::KEY; |
317 cast_environment_->logger()->DispatchFrameEvent(std::move(remoting_event)); | 473 cast_environment_->logger()->DispatchFrameEvent(std::move(remoting_event)); |
318 | 474 |
319 RecordLatestFrameTimestamps(frame_id, remoting_frame.rtp_timestamp); | 475 RecordLatestFrameTimestamps(frame_id, remoting_frame.rtp_timestamp); |
320 last_frame_was_canceled_ = false; | |
321 | 476 |
322 transport_->InsertFrame(ssrc_, remoting_frame); | 477 transport_->InsertFrame(ssrc_, remoting_frame); |
| 478 |
| 479 return true; |
323 } | 480 } |
324 | 481 |
325 void CastRemotingSender::CancelFramesInFlight() { | 482 void CastRemotingSender::CancelInFlightData() { |
326 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); | 483 DCHECK(cast_environment_->CurrentlyOn(media::cast::CastEnvironment::MAIN)); |
327 | 484 |
328 base::STLClearObject(&next_frame_data_); | 485 base::STLClearObject(&next_frame_data_); |
329 | 486 |
| 487 // TODO(miu): The following code is something we want to do as an |
| 488 // optimization. However, as-is, it's not quite correct. We can only cancel |
| 489 // frames where no packets have actually hit the network yet. Said another |
| 490 // way, we can only cancel frames the receiver has definitely not seen any |
| 491 // part of (including kickstarting!). http://crbug.com/647423 |
| 492 #if 0 |
330 if (latest_acked_frame_id_ < last_sent_frame_id_) { | 493 if (latest_acked_frame_id_ < last_sent_frame_id_) { |
331 std::vector<media::cast::FrameId> frames_to_cancel; | 494 std::vector<media::cast::FrameId> frames_to_cancel; |
332 do { | 495 do { |
333 ++latest_acked_frame_id_; | 496 ++latest_acked_frame_id_; |
334 frames_to_cancel.push_back(latest_acked_frame_id_); | 497 frames_to_cancel.push_back(latest_acked_frame_id_); |
335 } while (latest_acked_frame_id_ < last_sent_frame_id_); | 498 } while (latest_acked_frame_id_ < last_sent_frame_id_); |
336 transport_->CancelSendingFrames(ssrc_, frames_to_cancel); | 499 transport_->CancelSendingFrames(ssrc_, frames_to_cancel); |
337 } | 500 } |
| 501 #endif |
338 | 502 |
339 last_frame_was_canceled_ = true; | 503 // Flag that all pending input operations should discard data. |
| 504 input_queue_discards_remaining_ = input_queue_.size(); |
| 505 |
| 506 flow_restart_pending_ = true; |
| 507 VLOG(1) << SENDER_SSRC |
| 508 << "Now restarting because in-flight data was just canceled."; |
340 } | 509 } |
341 | 510 |
342 } // namespace cast | 511 } // namespace cast |
OLD | NEW |