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

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

Issue 4476003: Add VideoPacket struct for video packets. Refactor Decode interface to use it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged 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/chromoting_client.h ('k') | remoting/client/rectangle_update_decoder.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 "remoting/client/chromoting_client.h" 5 #include "remoting/client/chromoting_client.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "remoting/base/tracer.h" 8 #include "remoting/base/tracer.h"
9 #include "remoting/client/chromoting_view.h" 9 #include "remoting/client/chromoting_view.h"
10 #include "remoting/client/client_context.h" 10 #include "remoting/client/client_context.h"
11 #include "remoting/client/input_handler.h" 11 #include "remoting/client/input_handler.h"
12 #include "remoting/client/rectangle_update_decoder.h" 12 #include "remoting/client/rectangle_update_decoder.h"
13 #include "remoting/proto/internal.pb.h" 13 #include "remoting/proto/internal.pb.h"
14 #include "remoting/protocol/connection_to_host.h" 14 #include "remoting/protocol/connection_to_host.h"
15 #include "remoting/protocol/session_config.h"
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 ChromotingClient::ChromotingClient(const ClientConfig& config, 19 ChromotingClient::ChromotingClient(const ClientConfig& config,
19 ClientContext* context, 20 ClientContext* context,
20 protocol::ConnectionToHost* connection, 21 protocol::ConnectionToHost* connection,
21 ChromotingView* view, 22 ChromotingView* view,
22 RectangleUpdateDecoder* rectangle_decoder, 23 RectangleUpdateDecoder* rectangle_decoder,
23 InputHandler* input_handler, 24 InputHandler* input_handler,
24 CancelableTask* client_done) 25 CancelableTask* client_done)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 message_loop()->PostTask( 88 message_loop()->PostTask(
88 FROM_HERE, 89 FROM_HERE,
89 NewRunnableMethod(this, &ChromotingClient::SetViewport, 90 NewRunnableMethod(this, &ChromotingClient::SetViewport,
90 x, y, width, height)); 91 x, y, width, height));
91 return; 92 return;
92 } 93 }
93 94
94 view_->SetViewport(x, y, width, height); 95 view_->SetViewport(x, y, width, height);
95 } 96 }
96 97
97 void ChromotingClient::HandleMessage(protocol::ConnectionToHost* conn,
98 ChromotingHostMessage* msg) {
99 if (message_loop() != MessageLoop::current()) {
100 message_loop()->PostTask(
101 FROM_HERE,
102 NewRunnableMethod(this, &ChromotingClient::HandleMessage,
103 conn, msg));
104 return;
105 }
106
107 // TODO(ajwong): Consider creating a macro similar to the IPC message
108 // mappings. Also reconsider the lifetime of the message object.
109 if (msg->has_init_client()) {
110 ScopedTracer tracer("Handle Init Client");
111 InitClient(msg->init_client());
112 delete msg;
113 } else {
114 NOTREACHED() << "Unknown message received";
115 }
116 }
117
118 void ChromotingClient::ProcessVideoPacket(const VideoPacket* packet, 98 void ChromotingClient::ProcessVideoPacket(const VideoPacket* packet,
119 Task* done) { 99 Task* done) {
120 if (message_loop() != MessageLoop::current()) { 100 if (message_loop() != MessageLoop::current()) {
121 message_loop()->PostTask( 101 message_loop()->PostTask(
122 FROM_HERE, 102 FROM_HERE,
123 NewRunnableMethod(this, &ChromotingClient::ProcessVideoPacket, 103 NewRunnableMethod(this, &ChromotingClient::ProcessVideoPacket,
124 packet, done)); 104 packet, done));
125 return; 105 return;
126 } 106 }
127 107
128 received_packets_.push_back(QueuedVideoPacket(packet, done)); 108 received_packets_.push_back(QueuedVideoPacket(packet, done));
129 if (!packet_being_processed_) 109 if (!packet_being_processed_)
130 DispatchPacket(); 110 DispatchPacket();
131 } 111 }
132 112
133 void ChromotingClient::DispatchPacket() { 113 void ChromotingClient::DispatchPacket() {
134 DCHECK_EQ(message_loop(), MessageLoop::current()); 114 DCHECK_EQ(message_loop(), MessageLoop::current());
135 CHECK(!packet_being_processed_); 115 CHECK(!packet_being_processed_);
136 116
137 if (received_packets_.empty()) { 117 if (received_packets_.empty()) {
138 // Nothing to do! 118 // Nothing to do!
139 return; 119 return;
140 } 120 }
141 121
142 const VideoPacket* packet = received_packets_.front().packet; 122 const VideoPacket* packet = received_packets_.front().packet;
143 packet_being_processed_ = true; 123 packet_being_processed_ = true;
144 124
145 ScopedTracer tracer("Handle video packet"); 125 ScopedTracer tracer("Handle video packet");
146 rectangle_decoder_->DecodePacket( 126 rectangle_decoder_->DecodePacket(
147 *packet, NewTracedMethod(this, &ChromotingClient::OnPacketDone)); 127 packet, NewTracedMethod(this, &ChromotingClient::OnPacketDone));
148 } 128 }
149 129
150 void ChromotingClient::OnConnectionOpened(protocol::ConnectionToHost* conn) { 130 void ChromotingClient::OnConnectionOpened(protocol::ConnectionToHost* conn) {
151 VLOG(1) << "ChromotingClient::OnConnectionOpened"; 131 VLOG(1) << "ChromotingClient::OnConnectionOpened";
152 SetConnectionState(CONNECTED); 132 SetConnectionState(CONNECTED);
133 Initialize();
153 } 134 }
154 135
155 void ChromotingClient::OnConnectionClosed(protocol::ConnectionToHost* conn) { 136 void ChromotingClient::OnConnectionClosed(protocol::ConnectionToHost* conn) {
156 VLOG(1) << "ChromotingClient::OnConnectionClosed"; 137 VLOG(1) << "ChromotingClient::OnConnectionClosed";
157 SetConnectionState(DISCONNECTED); 138 SetConnectionState(DISCONNECTED);
158 } 139 }
159 140
160 void ChromotingClient::OnConnectionFailed(protocol::ConnectionToHost* conn) { 141 void ChromotingClient::OnConnectionFailed(protocol::ConnectionToHost* conn) {
161 VLOG(1) << "ChromotingClient::OnConnectionFailed"; 142 VLOG(1) << "ChromotingClient::OnConnectionFailed";
162 SetConnectionState(FAILED); 143 SetConnectionState(FAILED);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 175
195 received_packets_.front().done->Run(); 176 received_packets_.front().done->Run();
196 delete received_packets_.front().done; 177 delete received_packets_.front().done;
197 received_packets_.pop_front(); 178 received_packets_.pop_front();
198 179
199 packet_being_processed_ = false; 180 packet_being_processed_ = false;
200 181
201 DispatchPacket(); 182 DispatchPacket();
202 } 183 }
203 184
204 void ChromotingClient::InitClient(const InitClientMessage& init_client) { 185 void ChromotingClient::Initialize() {
205 DCHECK_EQ(message_loop(), MessageLoop::current()); 186 if (message_loop() != MessageLoop::current()) {
206 TraceContext::tracer()->PrintString("Init received"); 187 message_loop()->PostTask(
188 FROM_HERE,
189 NewTracedMethod(this, &ChromotingClient::Initialize));
190 return;
191 }
192
193 TraceContext::tracer()->PrintString("Initializing client.");
194
195 const protocol::SessionConfig* config = connection_->config();
207 196
208 // Resize the window. 197 // Resize the window.
209 int width = init_client.width(); 198 int width = config->initial_resolution().width;
210 int height = init_client.height(); 199 int height = config->initial_resolution().height;
211 VLOG(1) << "Init client received geometry: " << width << "x" << height; 200 VLOG(1) << "Initial screen geometry: " << width << "x" << height;
212 201
213 // TODO(ajwong): What to do here? Does the decoder actually need to request 202 // TODO(ajwong): What to do here? Does the decoder actually need to request
214 // the right frame size? This is mainly an optimization right? 203 // the right frame size? This is mainly an optimization right?
215 // rectangle_decoder_->SetOutputFrameSize(width, height); 204 // rectangle_decoder_->SetOutputFrameSize(width, height);
216 view_->SetViewport(0, 0, width, height); 205 view_->SetViewport(0, 0, width, height);
217 206
207 // Initialize the decoder.
208 rectangle_decoder_->Initialize(config);
209
218 // Schedule the input handler to process the event queue. 210 // Schedule the input handler to process the event queue.
219 input_handler_->Initialize(); 211 input_handler_->Initialize();
220 } 212 }
221 213
222 } // namespace remoting 214 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/chromoting_client.h ('k') | remoting/client/rectangle_update_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698