Index: media/remoting/shared_session.cc |
diff --git a/media/remoting/remoting_source_impl.cc b/media/remoting/shared_session.cc |
similarity index 53% |
rename from media/remoting/remoting_source_impl.cc |
rename to media/remoting/shared_session.cc |
index 136d758d94fc558a1add4ca51baa1323661f153c..d2c54a2da2b77b659c142dcec707ac96d76701a6 100644 |
--- a/media/remoting/remoting_source_impl.cc |
+++ b/media/remoting/shared_session.cc |
@@ -2,25 +2,25 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "media/remoting/remoting_source_impl.h" |
+#include "media/remoting/shared_session.h" |
#include "base/bind.h" |
#include "base/logging.h" |
-#include "media/remoting/rpc/proto_utils.h" |
+#include "media/remoting/proto_utils.h" |
namespace media { |
+namespace remoting { |
-RemotingSourceImpl::RemotingSourceImpl( |
- mojom::RemotingSourceRequest source_request, |
- mojom::RemoterPtr remoter) |
- : rpc_broker_(base::Bind(&RemotingSourceImpl::SendMessageToSink, |
+SharedSession::SharedSession(mojom::RemotingSourceRequest source_request, |
+ mojom::RemoterPtr remoter) |
+ : rpc_broker_(base::Bind(&SharedSession::SendMessageToSink, |
base::Unretained(this))), |
binding_(this, std::move(source_request)), |
remoter_(std::move(remoter)) { |
DCHECK(remoter_); |
} |
-RemotingSourceImpl::~RemotingSourceImpl() { |
+SharedSession::~SharedSession() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
if (!clients_.empty()) { |
@@ -29,7 +29,7 @@ RemotingSourceImpl::~RemotingSourceImpl() { |
} |
} |
-void RemotingSourceImpl::OnSinkAvailable( |
+void SharedSession::OnSinkAvailable( |
mojom::RemotingSinkCapabilities capabilities) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -38,80 +38,76 @@ void RemotingSourceImpl::OnSinkAvailable( |
return; |
} |
sink_capabilities_ = capabilities; |
- if (state_ == RemotingSessionState::SESSION_UNAVAILABLE) |
- UpdateAndNotifyState(RemotingSessionState::SESSION_CAN_START); |
+ if (state_ == SESSION_UNAVAILABLE) |
+ UpdateAndNotifyState(SESSION_CAN_START); |
} |
-void RemotingSourceImpl::OnSinkGone() { |
+void SharedSession::OnSinkGone() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
sink_capabilities_ = mojom::RemotingSinkCapabilities::NONE; |
- if (state_ == RemotingSessionState::SESSION_PERMANENTLY_STOPPED) |
+ if (state_ == SESSION_PERMANENTLY_STOPPED) |
return; |
- if (state_ == RemotingSessionState::SESSION_CAN_START) { |
- UpdateAndNotifyState(RemotingSessionState::SESSION_UNAVAILABLE); |
+ if (state_ == SESSION_CAN_START) { |
+ UpdateAndNotifyState(SESSION_UNAVAILABLE); |
return; |
} |
- if (state_ == RemotingSessionState::SESSION_STARTED || |
- state_ == RemotingSessionState::SESSION_STARTING) { |
+ if (state_ == SESSION_STARTED || state_ == SESSION_STARTING) { |
VLOG(1) << "Sink is gone in a remoting session."; |
// Remoting is being stopped by Remoter. |
- UpdateAndNotifyState(RemotingSessionState::SESSION_STOPPING); |
+ UpdateAndNotifyState(SESSION_STOPPING); |
} |
} |
-void RemotingSourceImpl::OnStarted() { |
+void SharedSession::OnStarted() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
VLOG(1) << "Remoting started successively."; |
- if (clients_.empty() || |
- state_ == RemotingSessionState::SESSION_PERMANENTLY_STOPPED || |
- state_ == RemotingSessionState::SESSION_STOPPING) { |
+ if (clients_.empty() || state_ == SESSION_PERMANENTLY_STOPPED || |
+ state_ == SESSION_STOPPING) { |
for (Client* client : clients_) |
client->OnStarted(false); |
return; |
} |
for (Client* client : clients_) |
client->OnStarted(true); |
- state_ = RemotingSessionState::SESSION_STARTED; |
+ state_ = SESSION_STARTED; |
} |
-void RemotingSourceImpl::OnStartFailed(mojom::RemotingStartFailReason reason) { |
+void SharedSession::OnStartFailed(mojom::RemotingStartFailReason reason) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
VLOG(1) << "Failed to start remoting:" << reason; |
for (Client* client : clients_) |
client->OnStarted(false); |
- if (state_ == RemotingSessionState::SESSION_PERMANENTLY_STOPPED) |
+ if (state_ == SESSION_PERMANENTLY_STOPPED) |
return; |
- state_ = RemotingSessionState::SESSION_UNAVAILABLE; |
+ state_ = SESSION_UNAVAILABLE; |
} |
-void RemotingSourceImpl::OnStopped(mojom::RemotingStopReason reason) { |
+void SharedSession::OnStopped(mojom::RemotingStopReason reason) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
VLOG(1) << "Remoting stopped: " << reason; |
- if (state_ == RemotingSessionState::SESSION_PERMANENTLY_STOPPED) |
+ if (state_ == SESSION_PERMANENTLY_STOPPED) |
return; |
- RemotingSessionState state = RemotingSessionState::SESSION_UNAVAILABLE; |
- UpdateAndNotifyState(state); |
+ UpdateAndNotifyState(SESSION_UNAVAILABLE); |
} |
-void RemotingSourceImpl::OnMessageFromSink( |
- const std::vector<uint8_t>& message) { |
+void SharedSession::OnMessageFromSink(const std::vector<uint8_t>& message) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- std::unique_ptr<remoting::pb::RpcMessage> rpc(new remoting::pb::RpcMessage()); |
+ std::unique_ptr<pb::RpcMessage> rpc(new pb::RpcMessage()); |
if (!rpc->ParseFromArray(message.data(), message.size())) { |
- LOG(ERROR) << "corrupted Rpc message"; |
+ VLOG(1) << "corrupted Rpc message"; |
Shutdown(); |
return; |
} |
rpc_broker_.ProcessMessageFromRemote(std::move(rpc)); |
} |
-void RemotingSourceImpl::UpdateAndNotifyState(RemotingSessionState state) { |
+void SharedSession::UpdateAndNotifyState(SessionState state) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
if (state_ == state) |
@@ -121,13 +117,13 @@ void RemotingSourceImpl::UpdateAndNotifyState(RemotingSessionState state) { |
client->OnSessionStateChanged(); |
} |
-void RemotingSourceImpl::StartRemoting(Client* client) { |
+void SharedSession::StartRemoting(Client* client) { |
DCHECK(std::find(clients_.begin(), clients_.end(), client) != clients_.end()); |
switch (state_) { |
case SESSION_CAN_START: |
remoter_->Start(); |
- UpdateAndNotifyState(RemotingSessionState::SESSION_STARTING); |
+ UpdateAndNotifyState(SESSION_STARTING); |
break; |
case SESSION_STARTING: |
break; |
@@ -142,50 +138,48 @@ void RemotingSourceImpl::StartRemoting(Client* client) { |
} |
} |
-void RemotingSourceImpl::StopRemoting(Client* client) { |
+void SharedSession::StopRemoting(Client* client) { |
DCHECK(std::find(clients_.begin(), clients_.end(), client) != clients_.end()); |
- VLOG(1) << "RemotingSourceImpl::StopRemoting: " << state_; |
+ VLOG(1) << "SharedSession::StopRemoting: " << state_; |
- if (state_ != RemotingSessionState::SESSION_STARTING && |
- state_ != RemotingSessionState::SESSION_STARTED) |
+ if (state_ != SESSION_STARTING && state_ != SESSION_STARTED) |
return; |
remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); |
- UpdateAndNotifyState(RemotingSessionState::SESSION_STOPPING); |
+ UpdateAndNotifyState(SESSION_STOPPING); |
} |
-void RemotingSourceImpl::AddClient(Client* client) { |
+void SharedSession::AddClient(Client* client) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(std::find(clients_.begin(), clients_.end(), client) == clients_.end()); |
clients_.push_back(client); |
} |
-void RemotingSourceImpl::RemoveClient(Client* client) { |
+void SharedSession::RemoveClient(Client* client) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
auto it = std::find(clients_.begin(), clients_.end(), client); |
DCHECK(it != clients_.end()); |
clients_.erase(it); |
- if (clients_.empty() && (state_ == RemotingSessionState::SESSION_STARTED || |
- state_ == RemotingSessionState::SESSION_STARTING)) { |
+ if (clients_.empty() && |
+ (state_ == SESSION_STARTED || state_ == SESSION_STARTING)) { |
remoter_->Stop(mojom::RemotingStopReason::SOURCE_GONE); |
- state_ = RemotingSessionState::SESSION_STOPPING; |
+ state_ = SESSION_STOPPING; |
} |
} |
-void RemotingSourceImpl::Shutdown() { |
+void SharedSession::Shutdown() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- if (state_ == RemotingSessionState::SESSION_STARTED || |
- state_ == RemotingSessionState::SESSION_STARTING) |
+ if (state_ == SESSION_STARTED || state_ == SESSION_STARTING) |
remoter_->Stop(mojom::RemotingStopReason::UNEXPECTED_FAILURE); |
- UpdateAndNotifyState(RemotingSessionState::SESSION_PERMANENTLY_STOPPED); |
+ UpdateAndNotifyState(SESSION_PERMANENTLY_STOPPED); |
} |
-void RemotingSourceImpl::StartDataPipe( |
+void SharedSession::StartDataPipe( |
std::unique_ptr<mojo::DataPipe> audio_data_pipe, |
std::unique_ptr<mojo::DataPipe> video_data_pipe, |
const DataPipeStartCallback& done_callback) { |
@@ -195,7 +189,7 @@ void RemotingSourceImpl::StartDataPipe( |
bool audio = audio_data_pipe != nullptr; |
bool video = video_data_pipe != nullptr; |
if (!audio && !video) { |
- LOG(ERROR) << "No audio and video to establish data pipe"; |
+ LOG(ERROR) << "No audio nor video to establish data pipe"; |
done_callback.Run(mojom::RemotingDataStreamSenderPtrInfo(), |
mojom::RemotingDataStreamSenderPtrInfo(), |
mojo::ScopedDataPipeProducerHandle(), |
@@ -204,15 +198,14 @@ void RemotingSourceImpl::StartDataPipe( |
} |
mojom::RemotingDataStreamSenderPtr audio_stream_sender; |
mojom::RemotingDataStreamSenderPtr video_stream_sender; |
- remoter_->StartDataStreams( |
- audio ? std::move(audio_data_pipe->consumer_handle) |
- : mojo::ScopedDataPipeConsumerHandle(), |
- video ? std::move(video_data_pipe->consumer_handle) |
- : mojo::ScopedDataPipeConsumerHandle(), |
- audio ? mojo::MakeRequest(&audio_stream_sender) |
- : media::mojom::RemotingDataStreamSenderRequest(), |
- video ? mojo::MakeRequest(&video_stream_sender) |
- : media::mojom::RemotingDataStreamSenderRequest()); |
+ remoter_->StartDataStreams(audio ? std::move(audio_data_pipe->consumer_handle) |
+ : mojo::ScopedDataPipeConsumerHandle(), |
+ video ? std::move(video_data_pipe->consumer_handle) |
+ : mojo::ScopedDataPipeConsumerHandle(), |
+ audio ? mojo::MakeRequest(&audio_stream_sender) |
+ : mojom::RemotingDataStreamSenderRequest(), |
+ video ? mojo::MakeRequest(&video_stream_sender) |
+ : mojom::RemotingDataStreamSenderRequest()); |
done_callback.Run(audio_stream_sender.PassInterface(), |
video_stream_sender.PassInterface(), |
audio ? std::move(audio_data_pipe->producer_handle) |
@@ -221,16 +214,11 @@ void RemotingSourceImpl::StartDataPipe( |
: mojo::ScopedDataPipeProducerHandle()); |
} |
-remoting::RpcBroker* RemotingSourceImpl::GetRpcBroker() const { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- // TODO(xjz): Fix the const-correctness. |
- return const_cast<remoting::RpcBroker*>(&rpc_broker_); |
-} |
- |
-void RemotingSourceImpl::SendMessageToSink( |
+void SharedSession::SendMessageToSink( |
std::unique_ptr<std::vector<uint8_t>> message) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
remoter_->SendMessageToSink(*message); |
} |
+} // namespace remoting |
} // namespace media |