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

Side by Side Diff: remoting/client/chromoting_client.cc

Issue 2384063004: Move audio decoding to protocol layer (Closed)
Patch Set: Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/client/chromoting_client.h" 5 #include "remoting/client/chromoting_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "remoting/base/capabilities.h" 10 #include "remoting/base/capabilities.h"
11 #include "remoting/base/constants.h" 11 #include "remoting/base/constants.h"
12 #include "remoting/client/audio_consumer.h"
13 #include "remoting/client/audio_decode_scheduler.h"
14 #include "remoting/client/client_context.h" 12 #include "remoting/client/client_context.h"
15 #include "remoting/client/client_user_interface.h" 13 #include "remoting/client/client_user_interface.h"
16 #include "remoting/protocol/authenticator.h" 14 #include "remoting/protocol/authenticator.h"
17 #include "remoting/protocol/connection_to_host.h" 15 #include "remoting/protocol/connection_to_host.h"
18 #include "remoting/protocol/host_stub.h" 16 #include "remoting/protocol/host_stub.h"
19 #include "remoting/protocol/ice_connection_to_host.h" 17 #include "remoting/protocol/ice_connection_to_host.h"
20 #include "remoting/protocol/jingle_session_manager.h" 18 #include "remoting/protocol/jingle_session_manager.h"
21 #include "remoting/protocol/negotiating_client_authenticator.h" 19 #include "remoting/protocol/negotiating_client_authenticator.h"
22 #include "remoting/protocol/session_config.h" 20 #include "remoting/protocol/session_config.h"
23 #include "remoting/protocol/transport_context.h" 21 #include "remoting/protocol/transport_context.h"
24 #include "remoting/protocol/video_renderer.h" 22 #include "remoting/protocol/video_renderer.h"
25 #include "remoting/protocol/webrtc_connection_to_host.h" 23 #include "remoting/protocol/webrtc_connection_to_host.h"
26 #include "remoting/signaling/jid_util.h" 24 #include "remoting/signaling/jid_util.h"
27 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 25 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
28 26
29 namespace remoting { 27 namespace remoting {
30 28
31 ChromotingClient::ChromotingClient(ClientContext* client_context, 29 ChromotingClient::ChromotingClient(
32 ClientUserInterface* user_interface, 30 ClientContext* client_context,
33 protocol::VideoRenderer* video_renderer, 31 ClientUserInterface* user_interface,
34 base::WeakPtr<AudioConsumer> audio_consumer) 32 protocol::VideoRenderer* video_renderer,
33 base::WeakPtr<protocol::AudioStub> audio_consumer)
35 : user_interface_(user_interface), video_renderer_(video_renderer) { 34 : user_interface_(user_interface), video_renderer_(video_renderer) {
36 DCHECK(client_context->main_task_runner()->BelongsToCurrentThread()); 35 DCHECK(client_context->main_task_runner()->BelongsToCurrentThread());
37 if (audio_consumer) { 36
38 audio_decode_scheduler_.reset(new AudioDecodeScheduler( 37 audio_decode_task_runner_ = client_context->audio_decode_task_runner();
39 client_context->main_task_runner(), 38 audio_consumer_ = audio_consumer;
40 client_context->audio_decode_task_runner(), audio_consumer));
41 }
42 } 39 }
43 40
44 ChromotingClient::~ChromotingClient() { 41 ChromotingClient::~ChromotingClient() {
45 if (signal_strategy_) 42 if (signal_strategy_)
46 signal_strategy_->RemoveListener(this); 43 signal_strategy_->RemoveListener(this);
47 } 44 }
48 45
49 void ChromotingClient::set_protocol_config( 46 void ChromotingClient::set_protocol_config(
50 std::unique_ptr<protocol::CandidateSessionConfig> config) { 47 std::unique_ptr<protocol::CandidateSessionConfig> config) {
51 protocol_config_ = std::move(config); 48 protocol_config_ = std::move(config);
(...skipping 11 matching lines...) Expand all
63 const std::string& host_jid, 60 const std::string& host_jid,
64 const std::string& capabilities) { 61 const std::string& capabilities) {
65 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
66 DCHECK(!session_manager_); // Start must be called more than once. 63 DCHECK(!session_manager_); // Start must be called more than once.
67 64
68 host_jid_ = NormalizeJid(host_jid); 65 host_jid_ = NormalizeJid(host_jid);
69 local_capabilities_ = capabilities; 66 local_capabilities_ = capabilities;
70 67
71 if (!protocol_config_) 68 if (!protocol_config_)
72 protocol_config_ = protocol::CandidateSessionConfig::CreateDefault(); 69 protocol_config_ = protocol::CandidateSessionConfig::CreateDefault();
73 if (!audio_decode_scheduler_) 70 if (!audio_consumer_)
74 protocol_config_->DisableAudioChannel(); 71 protocol_config_->DisableAudioChannel();
75 72
76 if (!connection_) { 73 if (!connection_) {
77 if (protocol_config_->webrtc_supported()) { 74 if (protocol_config_->webrtc_supported()) {
78 DCHECK(!protocol_config_->ice_supported()); 75 DCHECK(!protocol_config_->ice_supported());
79 #if !defined(ENABLE_WEBRTC_REMOTING_CLIENT) 76 #if !defined(ENABLE_WEBRTC_REMOTING_CLIENT)
80 LOG(FATAL) << "WebRTC is not supported."; 77 LOG(FATAL) << "WebRTC is not supported.";
81 #else 78 #else
82 connection_.reset(new protocol::WebrtcConnectionToHost()); 79 connection_.reset(new protocol::WebrtcConnectionToHost());
83 #endif 80 #endif
84 } else { 81 } else {
85 DCHECK(protocol_config_->ice_supported()); 82 DCHECK(protocol_config_->ice_supported());
86 connection_.reset(new protocol::IceConnectionToHost()); 83 connection_.reset(new protocol::IceConnectionToHost());
87 } 84 }
88 } 85 }
89 connection_->set_client_stub(this); 86 connection_->set_client_stub(this);
90 connection_->set_clipboard_stub(this); 87 connection_->set_clipboard_stub(this);
91 connection_->set_video_renderer(video_renderer_); 88 connection_->set_video_renderer(video_renderer_);
92 connection_->set_audio_stub(audio_decode_scheduler_.get()); 89
90 connection_->InitializeAudio(audio_decode_task_runner_, audio_consumer_);
93 91
94 session_manager_.reset(new protocol::JingleSessionManager(signal_strategy)); 92 session_manager_.reset(new protocol::JingleSessionManager(signal_strategy));
95 session_manager_->set_protocol_config(std::move(protocol_config_)); 93 session_manager_->set_protocol_config(std::move(protocol_config_));
96 94
97 client_auth_config_ = client_auth_config; 95 client_auth_config_ = client_auth_config;
98 transport_context_ = transport_context; 96 transport_context_ = transport_context;
99 97
100 signal_strategy_ = signal_strategy; 98 signal_strategy_ = signal_strategy;
101 signal_strategy_->AddListener(this); 99 signal_strategy_->AddListener(this);
102 100
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 190
193 user_interface_->GetCursorShapeStub()->SetCursorShape(cursor_shape); 191 user_interface_->GetCursorShapeStub()->SetCursorShape(cursor_shape);
194 } 192 }
195 193
196 void ChromotingClient::OnConnectionState( 194 void ChromotingClient::OnConnectionState(
197 protocol::ConnectionToHost::State state, 195 protocol::ConnectionToHost::State state,
198 protocol::ErrorCode error) { 196 protocol::ErrorCode error) {
199 DCHECK(thread_checker_.CalledOnValidThread()); 197 DCHECK(thread_checker_.CalledOnValidThread());
200 VLOG(1) << "ChromotingClient::OnConnectionState(" << state << ")"; 198 VLOG(1) << "ChromotingClient::OnConnectionState(" << state << ")";
201 199
202 if (state == protocol::ConnectionToHost::AUTHENTICATED) { 200 if (state == protocol::ConnectionToHost::CONNECTED) {
203 OnAuthenticated();
204 } else if (state == protocol::ConnectionToHost::CONNECTED) {
205 OnChannelsConnected(); 201 OnChannelsConnected();
206 } 202 }
207 user_interface_->OnConnectionState(state, error); 203 user_interface_->OnConnectionState(state, error);
208 } 204 }
209 205
210 void ChromotingClient::OnConnectionReady(bool ready) { 206 void ChromotingClient::OnConnectionReady(bool ready) {
211 VLOG(1) << "ChromotingClient::OnConnectionReady(" << ready << ")"; 207 VLOG(1) << "ChromotingClient::OnConnectionReady(" << ready << ")";
212 user_interface_->OnConnectionReady(ready); 208 user_interface_->OnConnectionReady(ready);
213 } 209 }
214 210
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void ChromotingClient::StartConnection() { 242 void ChromotingClient::StartConnection() {
247 DCHECK(thread_checker_.CalledOnValidThread()); 243 DCHECK(thread_checker_.CalledOnValidThread());
248 connection_->Connect( 244 connection_->Connect(
249 session_manager_->Connect( 245 session_manager_->Connect(
250 host_jid_, base::MakeUnique<protocol::NegotiatingClientAuthenticator>( 246 host_jid_, base::MakeUnique<protocol::NegotiatingClientAuthenticator>(
251 NormalizeJid(signal_strategy_->GetLocalJid()), 247 NormalizeJid(signal_strategy_->GetLocalJid()),
252 host_jid_, client_auth_config_)), 248 host_jid_, client_auth_config_)),
253 transport_context_, this); 249 transport_context_, this);
254 } 250 }
255 251
256 void ChromotingClient::OnAuthenticated() {
257 DCHECK(thread_checker_.CalledOnValidThread());
258
259 // Initialize the decoder.
260 if (connection_->config().is_audio_enabled())
261 audio_decode_scheduler_->Initialize(connection_->config());
262 }
263
264 void ChromotingClient::OnChannelsConnected() { 252 void ChromotingClient::OnChannelsConnected() {
265 DCHECK(thread_checker_.CalledOnValidThread()); 253 DCHECK(thread_checker_.CalledOnValidThread());
266 254
267 // Negotiate capabilities with the host. 255 // Negotiate capabilities with the host.
268 VLOG(1) << "Client capabilities: " << local_capabilities_; 256 VLOG(1) << "Client capabilities: " << local_capabilities_;
269 257
270 protocol::Capabilities capabilities; 258 protocol::Capabilities capabilities;
271 capabilities.set_capabilities(local_capabilities_); 259 capabilities.set_capabilities(local_capabilities_);
272 connection_->host_stub()->SetCapabilities(capabilities); 260 connection_->host_stub()->SetCapabilities(capabilities);
273 261
274 mouse_input_scaler_.set_input_stub(connection_->input_stub()); 262 mouse_input_scaler_.set_input_stub(connection_->input_stub());
275 } 263 }
276 264
277 } // namespace remoting 265 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698