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

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

Issue 4229003: Add VideoReader and VideoWriter interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month 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/client/jingle_host_connection.h ('k') | remoting/host/chromoting_host.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "remoting/base/constants.h" 7 #include "remoting/base/constants.h"
8 // TODO(hclam): Remove this header once MessageDispatcher is used. 8 // TODO(hclam): Remove this header once MessageDispatcher is used.
9 #include "remoting/base/multiple_array_input_stream.h" 9 #include "remoting/base/multiple_array_input_stream.h"
10 #include "remoting/client/client_config.h" 10 #include "remoting/client/client_config.h"
11 #include "remoting/client/jingle_host_connection.h" 11 #include "remoting/client/jingle_host_connection.h"
12 #include "remoting/jingle_glue/jingle_thread.h" 12 #include "remoting/jingle_glue/jingle_thread.h"
13 #include "remoting/protocol/jingle_chromotocol_server.h" 13 #include "remoting/protocol/jingle_chromotocol_server.h"
14 #include "remoting/protocol/video_stub.h"
14 #include "remoting/protocol/util.h" 15 #include "remoting/protocol/util.h"
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 JingleHostConnection::JingleHostConnection(ClientContext* context) 19 JingleHostConnection::JingleHostConnection(ClientContext* context)
19 : context_(context), 20 : context_(context),
20 event_callback_(NULL) { 21 event_callback_(NULL) {
21 } 22 }
22 23
23 JingleHostConnection::~JingleHostConnection() { 24 JingleHostConnection::~JingleHostConnection() {
24 } 25 }
25 26
26 void JingleHostConnection::Connect(const ClientConfig& config, 27 void JingleHostConnection::Connect(const ClientConfig& config,
27 HostEventCallback* event_callback) { 28 HostEventCallback* event_callback,
29 VideoStub* video_stub) {
28 event_callback_ = event_callback; 30 event_callback_ = event_callback;
31 video_stub_ = video_stub;
29 32
30 // Initialize |jingle_client_|. 33 // Initialize |jingle_client_|.
31 jingle_client_ = new JingleClient(context_->jingle_thread()); 34 jingle_client_ = new JingleClient(context_->jingle_thread());
32 jingle_client_->Init(config.username, config.auth_token, 35 jingle_client_->Init(config.username, config.auth_token,
33 kChromotingTokenServiceName, this); 36 kChromotingTokenServiceName, this);
34 37
35 // Save jid of the host. The actual connection is created later after 38 // Save jid of the host. The actual connection is created later after
36 // |jingle_client_| is connected. 39 // |jingle_client_| is connected.
37 host_jid_ = config.host_jid; 40 host_jid_ = config.host_jid;
38 } 41 }
39 42
40 void JingleHostConnection::Disconnect() { 43 void JingleHostConnection::Disconnect() {
41 if (MessageLoop::current() != message_loop()) { 44 if (MessageLoop::current() != message_loop()) {
42 message_loop()->PostTask( 45 message_loop()->PostTask(
43 FROM_HERE, NewRunnableMethod(this, 46 FROM_HERE, NewRunnableMethod(this,
44 &JingleHostConnection::Disconnect)); 47 &JingleHostConnection::Disconnect));
45 return; 48 return;
46 } 49 }
47 50
51 control_reader_.Close();
48 event_writer_.Close(); 52 event_writer_.Close();
49 video_reader_.Close(); 53 video_reader_->Close();
50 54
51 if (connection_) { 55 if (connection_) {
52 connection_->Close( 56 connection_->Close(
53 NewRunnableMethod(this, &JingleHostConnection::OnDisconnected)); 57 NewRunnableMethod(this, &JingleHostConnection::OnDisconnected));
54 } else { 58 } else {
55 OnDisconnected(); 59 OnDisconnected();
56 } 60 }
57 } 61 }
58 62
59 void JingleHostConnection::OnVideoMessage( 63 void JingleHostConnection::OnControlMessage(ChromotingHostMessage* msg) {
60 ChromotingHostMessage* msg) {
61 event_callback_->HandleMessage(this, msg); 64 event_callback_->HandleMessage(this, msg);
62 } 65 }
63 66
64 void JingleHostConnection::InitConnection() { 67 void JingleHostConnection::InitConnection() {
65 DCHECK_EQ(message_loop(), MessageLoop::current()); 68 DCHECK_EQ(message_loop(), MessageLoop::current());
66 69
67 // Initialize |chromotocol_server_|. 70 // Initialize |chromotocol_server_|.
68 JingleChromotocolServer* chromotocol_server = 71 JingleChromotocolServer* chromotocol_server =
69 new JingleChromotocolServer(context_->jingle_thread()); 72 new JingleChromotocolServer(context_->jingle_thread());
70 // TODO(ajwong): Make this a command switch when we're more stable. 73 // TODO(ajwong): Make this a command switch when we're more stable.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 case ChromotocolConnection::FAILED: 146 case ChromotocolConnection::FAILED:
144 event_callback_->OnConnectionFailed(this); 147 event_callback_->OnConnectionFailed(this);
145 break; 148 break;
146 149
147 case ChromotocolConnection::CLOSED: 150 case ChromotocolConnection::CLOSED:
148 event_callback_->OnConnectionClosed(this); 151 event_callback_->OnConnectionClosed(this);
149 break; 152 break;
150 153
151 case ChromotocolConnection::CONNECTED: 154 case ChromotocolConnection::CONNECTED:
152 // Initialize reader and writer. 155 // Initialize reader and writer.
156 control_reader_.Init<ChromotingHostMessage>(
157 connection_->control_channel(),
158 NewCallback(this, &JingleHostConnection::OnControlMessage));
153 event_writer_.Init(connection_->event_channel()); 159 event_writer_.Init(connection_->event_channel());
154 video_reader_.Init<ChromotingHostMessage>( 160 video_reader_.reset(VideoReader::Create(connection_->config()));
155 connection_->video_channel(), 161 video_reader_->Init(connection_, video_stub_);
156 NewCallback(this, &JingleHostConnection::OnVideoMessage));
157 event_callback_->OnConnectionOpened(this); 162 event_callback_->OnConnectionOpened(this);
158 break; 163 break;
159 164
160 default: 165 default:
161 // Ignore the other states by default. 166 // Ignore the other states by default.
162 break; 167 break;
163 } 168 }
164 } 169 }
165 170
166 MessageLoop* JingleHostConnection::message_loop() { 171 MessageLoop* JingleHostConnection::message_loop() {
167 return context_->jingle_thread()->message_loop(); 172 return context_->jingle_thread()->message_loop();
168 } 173 }
169 174
170 } // namespace remoting 175 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/jingle_host_connection.h ('k') | remoting/host/chromoting_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698