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

Side by Side Diff: remoting/protocol/connection_to_host.cc

Issue 10532211: Added piping for sending audio packets from host to client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unittests Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/connection_to_host.h ('k') | remoting/protocol/content_description.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/protocol/connection_to_host.h" 5 #include "remoting/protocol/connection_to_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "remoting/base/constants.h" 10 #include "remoting/base/constants.h"
11 #include "remoting/jingle_glue/javascript_signal_strategy.h" 11 #include "remoting/jingle_glue/javascript_signal_strategy.h"
12 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 12 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
13 #include "remoting/protocol/audio_reader.h"
14 #include "remoting/protocol/audio_stub.h"
13 #include "remoting/protocol/auth_util.h" 15 #include "remoting/protocol/auth_util.h"
14 #include "remoting/protocol/authenticator.h" 16 #include "remoting/protocol/authenticator.h"
15 #include "remoting/protocol/client_control_dispatcher.h" 17 #include "remoting/protocol/client_control_dispatcher.h"
16 #include "remoting/protocol/client_event_dispatcher.h" 18 #include "remoting/protocol/client_event_dispatcher.h"
17 #include "remoting/protocol/client_stub.h" 19 #include "remoting/protocol/client_stub.h"
18 #include "remoting/protocol/clipboard_stub.h" 20 #include "remoting/protocol/clipboard_stub.h"
19 #include "remoting/protocol/errors.h" 21 #include "remoting/protocol/errors.h"
20 #include "remoting/protocol/jingle_session_manager.h" 22 #include "remoting/protocol/jingle_session_manager.h"
21 #include "remoting/protocol/transport.h" 23 #include "remoting/protocol/transport.h"
22 #include "remoting/protocol/video_reader.h" 24 #include "remoting/protocol/video_reader.h"
23 #include "remoting/protocol/video_stub.h" 25 #include "remoting/protocol/video_stub.h"
24 #include "remoting/protocol/util.h" 26 #include "remoting/protocol/util.h"
25 27
26 namespace remoting { 28 namespace remoting {
27 namespace protocol { 29 namespace protocol {
28 30
29 ConnectionToHost::ConnectionToHost( 31 ConnectionToHost::ConnectionToHost(
30 bool allow_nat_traversal) 32 bool allow_nat_traversal)
31 : allow_nat_traversal_(allow_nat_traversal), 33 : allow_nat_traversal_(allow_nat_traversal),
32 event_callback_(NULL), 34 event_callback_(NULL),
33 client_stub_(NULL), 35 client_stub_(NULL),
34 clipboard_stub_(NULL), 36 clipboard_stub_(NULL),
35 video_stub_(NULL), 37 video_stub_(NULL),
38 audio_stub_(NULL),
36 state_(CONNECTING), 39 state_(CONNECTING),
37 error_(OK) { 40 error_(OK) {
38 } 41 }
39 42
40 ConnectionToHost::~ConnectionToHost() { 43 ConnectionToHost::~ConnectionToHost() {
41 } 44 }
42 45
43 ClipboardStub* ConnectionToHost::clipboard_stub() { 46 ClipboardStub* ConnectionToHost::clipboard_stub() {
44 return &clipboard_forwarder_; 47 return &clipboard_forwarder_;
45 } 48 }
46 49
47 HostStub* ConnectionToHost::host_stub() { 50 HostStub* ConnectionToHost::host_stub() {
48 // TODO(wez): Add a HostFilter class, equivalent to input filter. 51 // TODO(wez): Add a HostFilter class, equivalent to input filter.
49 return control_dispatcher_.get(); 52 return control_dispatcher_.get();
50 } 53 }
51 54
52 InputStub* ConnectionToHost::input_stub() { 55 InputStub* ConnectionToHost::input_stub() {
53 return &event_forwarder_; 56 return &event_forwarder_;
54 } 57 }
55 58
56 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, 59 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy,
57 const std::string& local_jid, 60 const std::string& local_jid,
58 const std::string& host_jid, 61 const std::string& host_jid,
59 const std::string& host_public_key, 62 const std::string& host_public_key,
60 scoped_ptr<TransportFactory> transport_factory, 63 scoped_ptr<TransportFactory> transport_factory,
61 scoped_ptr<Authenticator> authenticator, 64 scoped_ptr<Authenticator> authenticator,
62 HostEventCallback* event_callback, 65 HostEventCallback* event_callback,
63 ClientStub* client_stub, 66 ClientStub* client_stub,
64 ClipboardStub* clipboard_stub, 67 ClipboardStub* clipboard_stub,
65 VideoStub* video_stub) { 68 VideoStub* video_stub,
69 AudioStub* audio_stub) {
66 event_callback_ = event_callback; 70 event_callback_ = event_callback;
67 client_stub_ = client_stub; 71 client_stub_ = client_stub;
68 clipboard_stub_ = clipboard_stub; 72 clipboard_stub_ = clipboard_stub;
69 video_stub_ = video_stub; 73 video_stub_ = video_stub;
74 audio_stub_ = audio_stub;
70 authenticator_ = authenticator.Pass(); 75 authenticator_ = authenticator.Pass();
71 76
72 // Save jid of the host. The actual connection is created later after 77 // Save jid of the host. The actual connection is created later after
73 // |signal_strategy_| is connected. 78 // |signal_strategy_| is connected.
74 host_jid_ = host_jid; 79 host_jid_ = host_jid;
75 host_public_key_ = host_public_key; 80 host_public_key_ = host_public_key;
76 81
77 JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(local_jid); 82 JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(local_jid);
78 strategy->AttachXmppProxy(xmpp_proxy); 83 strategy->AttachXmppProxy(xmpp_proxy);
79 signal_strategy_.reset(strategy); 84 signal_strategy_.reset(strategy);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 case Session::CONNECTING: 160 case Session::CONNECTING:
156 case Session::CONNECTED: 161 case Session::CONNECTED:
157 // Don't care about these events. 162 // Don't care about these events.
158 break; 163 break;
159 164
160 case Session::AUTHENTICATED: 165 case Session::AUTHENTICATED:
161 video_reader_ = VideoReader::Create(session_->config()); 166 video_reader_ = VideoReader::Create(session_->config());
162 video_reader_->Init(session_.get(), video_stub_, base::Bind( 167 video_reader_->Init(session_.get(), video_stub_, base::Bind(
163 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); 168 &ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
164 169
170 audio_reader_ = AudioReader::Create(session_->config());
171 if (audio_reader_.get()) {
172 audio_reader_->Init(session_.get(), audio_stub_, base::Bind(
173 &ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
174 }
175
165 control_dispatcher_.reset(new ClientControlDispatcher()); 176 control_dispatcher_.reset(new ClientControlDispatcher());
166 control_dispatcher_->Init(session_.get(), base::Bind( 177 control_dispatcher_->Init(session_.get(), base::Bind(
167 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); 178 &ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
168 control_dispatcher_->set_client_stub(client_stub_); 179 control_dispatcher_->set_client_stub(client_stub_);
169 control_dispatcher_->set_clipboard_stub(clipboard_stub_); 180 control_dispatcher_->set_clipboard_stub(clipboard_stub_);
170 181
171 event_dispatcher_.reset(new ClientEventDispatcher()); 182 event_dispatcher_.reset(new ClientEventDispatcher());
172 event_dispatcher_->Init(session_.get(), base::Bind( 183 event_dispatcher_->Init(session_.get(), base::Bind(
173 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); 184 &ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
174 break; 185 break;
(...skipping 26 matching lines...) Expand all
201 if (!successful) { 212 if (!successful) {
202 LOG(ERROR) << "Failed to connect video channel"; 213 LOG(ERROR) << "Failed to connect video channel";
203 CloseOnError(CHANNEL_CONNECTION_ERROR); 214 CloseOnError(CHANNEL_CONNECTION_ERROR);
204 return; 215 return;
205 } 216 }
206 217
207 NotifyIfChannelsReady(); 218 NotifyIfChannelsReady();
208 } 219 }
209 220
210 void ConnectionToHost::NotifyIfChannelsReady() { 221 void ConnectionToHost::NotifyIfChannelsReady() {
211 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && 222 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected())
212 event_dispatcher_.get() && event_dispatcher_->is_connected() && 223 return;
213 video_reader_.get() && video_reader_->is_connected() && 224 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected())
214 state_ == CONNECTING) { 225 return;
215 // Start forwarding clipboard and input events. 226 if (!video_reader_.get() || !video_reader_->is_connected())
216 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); 227 return;
217 event_forwarder_.set_input_stub(event_dispatcher_.get()); 228 if ((!audio_reader_.get() || !audio_reader_->is_connected()) &&
218 SetState(CONNECTED, OK); 229 session_->config().is_audio_enabled()) {
230 return;
219 } 231 }
232 if (state_ != CONNECTING)
233 return;
234
235 // Start forwarding clipboard and input events.
236 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get());
237 event_forwarder_.set_input_stub(event_dispatcher_.get());
238 SetState(CONNECTED, OK);
220 } 239 }
221 240
222 void ConnectionToHost::CloseOnError(ErrorCode error) { 241 void ConnectionToHost::CloseOnError(ErrorCode error) {
223 CloseChannels(); 242 CloseChannels();
224 SetState(FAILED, error); 243 SetState(FAILED, error);
225 } 244 }
226 245
227 void ConnectionToHost::CloseChannels() { 246 void ConnectionToHost::CloseChannels() {
228 control_dispatcher_.reset(); 247 control_dispatcher_.reset();
229 event_dispatcher_.reset(); 248 event_dispatcher_.reset();
230 clipboard_forwarder_.set_clipboard_stub(NULL); 249 clipboard_forwarder_.set_clipboard_stub(NULL);
231 event_forwarder_.set_input_stub(NULL); 250 event_forwarder_.set_input_stub(NULL);
232 video_reader_.reset(); 251 video_reader_.reset();
252 audio_reader_.reset();
233 } 253 }
234 254
235 void ConnectionToHost::SetState(State state, ErrorCode error) { 255 void ConnectionToHost::SetState(State state, ErrorCode error) {
236 DCHECK(CalledOnValidThread()); 256 DCHECK(CalledOnValidThread());
237 // |error| should be specified only when |state| is set to FAILED. 257 // |error| should be specified only when |state| is set to FAILED.
238 DCHECK(state == FAILED || error == OK); 258 DCHECK(state == FAILED || error == OK);
239 259
240 if (state != state_) { 260 if (state != state_) {
241 state_ = state; 261 state_ = state;
242 error_ = error; 262 error_ = error;
243 event_callback_->OnConnectionState(state_, error_); 263 event_callback_->OnConnectionState(state_, error_);
244 } 264 }
245 } 265 }
246 266
247 } // namespace protocol 267 } // namespace protocol
248 } // namespace remoting 268 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_to_host.h ('k') | remoting/protocol/content_description.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698