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

Side by Side Diff: chrome/browser/media/cast_remoting_sender.cc

Issue 2750373002: Revert of Mojo: Armed Watchers (Closed)
Patch Set: Created 3 years, 9 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 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
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, mojo::SimpleWatcher::ArmingPolicy::MANUAL), 95 pipe_watcher_(FROM_HERE),
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
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_.Watch(sender->pipe_.get(), 167 sender->pipe_watcher_.Start(
168 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE, 168 sender->pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE,
169 base::Bind(&CastRemotingSender::ProcessInputQueue, 169 base::Bind(&CastRemotingSender::ProcessInputQueue,
170 base::Unretained(sender))); 170 base::Unretained(sender)));
171 sender->pipe_watcher_.ArmOrNotify();
172 sender->binding_.Bind(std::move(request)); 171 sender->binding_.Bind(std::move(request));
173 sender->binding_.set_connection_error_handler(sender->error_callback_); 172 sender->binding_.set_connection_error_handler(sender->error_callback_);
174 } 173 }
175 174
176 void CastRemotingSender::OnReceivedRtt(base::TimeDelta round_trip_time) { 175 void CastRemotingSender::OnReceivedRtt(base::TimeDelta round_trip_time) {
177 DCHECK_GT(round_trip_time, base::TimeDelta()); 176 DCHECK_GT(round_trip_time, base::TimeDelta());
178 current_round_trip_time_ = round_trip_time; 177 current_round_trip_time_ = round_trip_time;
179 max_ack_delay_ = 2 * std::max(current_round_trip_time_, base::TimeDelta()) + 178 max_ack_delay_ = 2 * std::max(current_round_trip_time_, base::TimeDelta()) +
180 kReceiverProcessTime; 179 kReceiverProcessTime;
181 max_ack_delay_ = std::min(max_ack_delay_, kMaxAckDelay); 180 max_ack_delay_ = std::min(max_ack_delay_, kMaxAckDelay);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 371 }
373 372
374 // If the data is to be discarded, do a data pipe read with the DISCARD flag 373 // If the data is to be discarded, do a data pipe read with the DISCARD flag
375 // set. 374 // set.
376 if (discard_data) { 375 if (discard_data) {
377 const MojoResult result = mojo::ReadDataRaw( 376 const MojoResult result = mojo::ReadDataRaw(
378 pipe_.get(), nullptr, &size, 377 pipe_.get(), nullptr, &size,
379 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE); 378 MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE);
380 if (result == MOJO_RESULT_OK) 379 if (result == MOJO_RESULT_OK)
381 return true; // Successfully discarded data. 380 return true; // Successfully discarded data.
382 if (result == MOJO_RESULT_OUT_OF_RANGE) { 381 if (result == MOJO_RESULT_OUT_OF_RANGE)
383 pipe_watcher_.ArmOrNotify();
384 return false; // Retry later. 382 return false; // Retry later.
385 }
386 LOG(ERROR) << SENDER_SSRC 383 LOG(ERROR) << SENDER_SSRC
387 << "Unexpected result when discarding from data pipe (" 384 << "Unexpected result when discarding from data pipe ("
388 << result << ')'; 385 << result << ')';
389 break; 386 break;
390 } 387 }
391 388
392 // If |total_payload_size| has changed, resize the data string. If it has 389 // If |total_payload_size| has changed, resize the data string. If it has
393 // not changed, the following statement will be a no-op. 390 // not changed, the following statement will be a no-op.
394 next_frame_data_.resize(total_payload_size); 391 next_frame_data_.resize(total_payload_size);
395 392
396 const MojoResult result = mojo::ReadDataRaw( 393 const MojoResult result = mojo::ReadDataRaw(
397 pipe_.get(), base::string_as_array(&next_frame_data_) + offset, &size, 394 pipe_.get(), base::string_as_array(&next_frame_data_) + offset, &size,
398 MOJO_READ_DATA_FLAG_ALL_OR_NONE); 395 MOJO_READ_DATA_FLAG_ALL_OR_NONE);
399 if (result == MOJO_RESULT_OK) 396 if (result == MOJO_RESULT_OK)
400 return true; // Successfully consumed data. 397 return true; // Successfully consumed data.
401 if (result == MOJO_RESULT_OUT_OF_RANGE) { 398 if (result == MOJO_RESULT_OUT_OF_RANGE)
402 pipe_watcher_.ArmOrNotify();
403 return false; // Retry later. 399 return false; // Retry later.
404 }
405 LOG(ERROR) 400 LOG(ERROR)
406 << SENDER_SSRC << "Read from data pipe failed (" << result << ')'; 401 << SENDER_SSRC << "Read from data pipe failed (" << result << ')';
407 } while (false); 402 } while (false);
408 403
409 // If this point is reached, there was a fatal error. Shut things down and run 404 // If this point is reached, there was a fatal error. Shut things down and run
410 // the error callback. 405 // the error callback.
411 pipe_watcher_.Cancel(); 406 pipe_watcher_.Cancel();
412 pipe_.reset(); 407 pipe_.reset();
413 binding_.Close(); 408 binding_.Close();
414 error_callback_.Run(); 409 error_callback_.Run();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 frame_event_cb_.Run(frame_events); 535 frame_event_cb_.Run(frame_events);
541 } 536 }
542 537
543 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 538 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
544 FROM_HERE, base::Bind(&CastRemotingSender::SendFrameEvents, 539 FROM_HERE, base::Bind(&CastRemotingSender::SendFrameEvents,
545 weak_factory_.GetWeakPtr()), 540 weak_factory_.GetWeakPtr()),
546 logging_flush_interval_); 541 logging_flush_interval_);
547 } 542 }
548 543
549 } // namespace cast 544 } // namespace cast
OLDNEW
« no previous file with comments | « chrome/browser/media/cast_remoting_sender.h ('k') | content/browser/loader/mojo_async_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698