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 <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 media::cast::RtpPayloadType::REMOTE_AUDIO), | 85 media::cast::RtpPayloadType::REMOTE_AUDIO), |
86 logging_flush_interval_(logging_flush_interval), | 86 logging_flush_interval_(logging_flush_interval), |
87 frame_event_cb_(cb), | 87 frame_event_cb_(cb), |
88 clock_(new base::DefaultTickClock()), | 88 clock_(new base::DefaultTickClock()), |
89 binding_(this), | 89 binding_(this), |
90 max_ack_delay_(kMaxAckDelay), | 90 max_ack_delay_(kMaxAckDelay), |
91 last_sent_frame_id_(media::cast::FrameId::first() - 1), | 91 last_sent_frame_id_(media::cast::FrameId::first() - 1), |
92 latest_acked_frame_id_(media::cast::FrameId::first() - 1), | 92 latest_acked_frame_id_(media::cast::FrameId::first() - 1), |
93 duplicate_ack_counter_(0), | 93 duplicate_ack_counter_(0), |
94 input_queue_discards_remaining_(0), | 94 input_queue_discards_remaining_(0), |
95 pipe_watcher_(FROM_HERE), | 95 pipe_watcher_(FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::MANUAL), |
96 flow_restart_pending_(true), | 96 flow_restart_pending_(true), |
97 weak_factory_(this) { | 97 weak_factory_(this) { |
98 // Confirm this constructor is running on the IO BrowserThread. | 98 // Confirm this constructor is running on the IO BrowserThread. |
99 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 99 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
100 | 100 |
101 CastRemotingSender*& pointer_in_map = g_sender_map.Get()[rtp_stream_id_]; | 101 CastRemotingSender*& pointer_in_map = g_sender_map.Get()[rtp_stream_id_]; |
102 DCHECK(!pointer_in_map); | 102 DCHECK(!pointer_in_map); |
103 pointer_in_map = this; | 103 pointer_in_map = this; |
104 | 104 |
105 transport_->InitializeStream( | 105 transport_->InitializeStream( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 DLOG(ERROR) << "Attempt to bind to CastRemotingSender a second time (id=" | 157 DLOG(ERROR) << "Attempt to bind to CastRemotingSender a second time (id=" |
158 << rtp_stream_id << ")!"; | 158 << rtp_stream_id << ")!"; |
159 error_callback.Run(); | 159 error_callback.Run(); |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 DCHECK(sender->error_callback_.is_null()); | 163 DCHECK(sender->error_callback_.is_null()); |
164 sender->error_callback_ = error_callback; | 164 sender->error_callback_ = error_callback; |
165 | 165 |
166 sender->pipe_ = std::move(pipe); | 166 sender->pipe_ = std::move(pipe); |
167 sender->pipe_watcher_.Start( | 167 sender->pipe_watcher_.Watch(sender->pipe_.get(), |
168 sender->pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, | 168 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, |
169 base::Bind(&CastRemotingSender::ProcessInputQueue, | 169 base::Bind(&CastRemotingSender::ProcessInputQueue, |
170 base::Unretained(sender))); | 170 base::Unretained(sender))); |
| 171 sender->pipe_watcher_.ArmOrNotify(); |
171 sender->binding_.Bind(std::move(request)); | 172 sender->binding_.Bind(std::move(request)); |
172 sender->binding_.set_connection_error_handler(sender->error_callback_); | 173 sender->binding_.set_connection_error_handler(sender->error_callback_); |
173 } | 174 } |
174 | 175 |
175 void CastRemotingSender::OnReceivedRtt(base::TimeDelta round_trip_time) { | 176 void CastRemotingSender::OnReceivedRtt(base::TimeDelta round_trip_time) { |
176 DCHECK_GT(round_trip_time, base::TimeDelta()); | 177 DCHECK_GT(round_trip_time, base::TimeDelta()); |
177 current_round_trip_time_ = round_trip_time; | 178 current_round_trip_time_ = round_trip_time; |
178 max_ack_delay_ = 2 * std::max(current_round_trip_time_, base::TimeDelta()) + | 179 max_ack_delay_ = 2 * std::max(current_round_trip_time_, base::TimeDelta()) + |
179 kReceiverProcessTime; | 180 kReceiverProcessTime; |
180 max_ack_delay_ = std::min(max_ack_delay_, kMaxAckDelay); | 181 max_ack_delay_ = std::min(max_ack_delay_, kMaxAckDelay); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 372 } |
372 | 373 |
373 // If the data is to be discarded, do a data pipe read with the DISCARD flag | 374 // If the data is to be discarded, do a data pipe read with the DISCARD flag |
374 // set. | 375 // set. |
375 if (discard_data) { | 376 if (discard_data) { |
376 const MojoResult result = mojo::ReadDataRaw( | 377 const MojoResult result = mojo::ReadDataRaw( |
377 pipe_.get(), nullptr, &size, | 378 pipe_.get(), nullptr, &size, |
378 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE); | 379 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
379 if (result == MOJO_RESULT_OK) | 380 if (result == MOJO_RESULT_OK) |
380 return true; // Successfully discarded data. | 381 return true; // Successfully discarded data. |
381 if (result == MOJO_RESULT_OUT_OF_RANGE) | 382 if (result == MOJO_RESULT_OUT_OF_RANGE) { |
| 383 pipe_watcher_.ArmOrNotify(); |
382 return false; // Retry later. | 384 return false; // Retry later. |
| 385 } |
383 LOG(ERROR) << SENDER_SSRC | 386 LOG(ERROR) << SENDER_SSRC |
384 << "Unexpected result when discarding from data pipe (" | 387 << "Unexpected result when discarding from data pipe (" |
385 << result << ')'; | 388 << result << ')'; |
386 break; | 389 break; |
387 } | 390 } |
388 | 391 |
389 // If |total_payload_size| has changed, resize the data string. If it has | 392 // If |total_payload_size| has changed, resize the data string. If it has |
390 // not changed, the following statement will be a no-op. | 393 // not changed, the following statement will be a no-op. |
391 next_frame_data_.resize(total_payload_size); | 394 next_frame_data_.resize(total_payload_size); |
392 | 395 |
393 const MojoResult result = mojo::ReadDataRaw( | 396 const MojoResult result = mojo::ReadDataRaw( |
394 pipe_.get(), base::string_as_array(&next_frame_data_) + offset, &size, | 397 pipe_.get(), base::string_as_array(&next_frame_data_) + offset, &size, |
395 MOJO_READ_DATA_FLAG_ALL_OR_NONE); | 398 MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
396 if (result == MOJO_RESULT_OK) | 399 if (result == MOJO_RESULT_OK) |
397 return true; // Successfully consumed data. | 400 return true; // Successfully consumed data. |
398 if (result == MOJO_RESULT_OUT_OF_RANGE) | 401 if (result == MOJO_RESULT_OUT_OF_RANGE) { |
| 402 pipe_watcher_.ArmOrNotify(); |
399 return false; // Retry later. | 403 return false; // Retry later. |
| 404 } |
400 LOG(ERROR) | 405 LOG(ERROR) |
401 << SENDER_SSRC << "Read from data pipe failed (" << result << ')'; | 406 << SENDER_SSRC << "Read from data pipe failed (" << result << ')'; |
402 } while (false); | 407 } while (false); |
403 | 408 |
404 // If this point is reached, there was a fatal error. Shut things down and run | 409 // If this point is reached, there was a fatal error. Shut things down and run |
405 // the error callback. | 410 // the error callback. |
406 pipe_watcher_.Cancel(); | 411 pipe_watcher_.Cancel(); |
407 pipe_.reset(); | 412 pipe_.reset(); |
408 binding_.Close(); | 413 binding_.Close(); |
409 error_callback_.Run(); | 414 error_callback_.Run(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 frame_event_cb_.Run(frame_events); | 540 frame_event_cb_.Run(frame_events); |
536 } | 541 } |
537 | 542 |
538 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 543 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
539 FROM_HERE, base::Bind(&CastRemotingSender::SendFrameEvents, | 544 FROM_HERE, base::Bind(&CastRemotingSender::SendFrameEvents, |
540 weak_factory_.GetWeakPtr()), | 545 weak_factory_.GetWeakPtr()), |
541 logging_flush_interval_); | 546 logging_flush_interval_); |
542 } | 547 } |
543 | 548 |
544 } // namespace cast | 549 } // namespace cast |
OLD | NEW |