OLD | NEW |
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/host/session_manager.h" | 5 #include "remoting/host/screen_recorder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "remoting/base/capture_data.h" | 12 #include "remoting/base/capture_data.h" |
13 #include "remoting/base/tracer.h" | 13 #include "remoting/base/tracer.h" |
14 #include "remoting/proto/control.pb.h" | 14 #include "remoting/proto/control.pb.h" |
15 #include "remoting/proto/video.pb.h" | 15 #include "remoting/proto/video.pb.h" |
(...skipping 15 matching lines...) Expand all Loading... |
31 base::TimeDelta::FromSeconds(1); | 31 base::TimeDelta::FromSeconds(1); |
32 | 32 |
33 // We divide the pending update stream number by this value to determine the | 33 // We divide the pending update stream number by this value to determine the |
34 // rate divider. | 34 // rate divider. |
35 static const int kSlowDownFactor = 10; | 35 static const int kSlowDownFactor = 10; |
36 | 36 |
37 // A list of dividers used to divide the max rate to determine the current | 37 // A list of dividers used to divide the max rate to determine the current |
38 // capture rate. | 38 // capture rate. |
39 static const int kRateDividers[] = {1, 2, 4, 8, 16}; | 39 static const int kRateDividers[] = {1, 2, 4, 8, 16}; |
40 | 40 |
41 SessionManager::SessionManager( | 41 ScreenRecorder::ScreenRecorder( |
42 MessageLoop* capture_loop, | 42 MessageLoop* capture_loop, |
43 MessageLoop* encode_loop, | 43 MessageLoop* encode_loop, |
44 MessageLoop* network_loop, | 44 MessageLoop* network_loop, |
45 Capturer* capturer, | 45 Capturer* capturer, |
46 Encoder* encoder) | 46 Encoder* encoder) |
47 : capture_loop_(capture_loop), | 47 : capture_loop_(capture_loop), |
48 encode_loop_(encode_loop), | 48 encode_loop_(encode_loop), |
49 network_loop_(network_loop), | 49 network_loop_(network_loop), |
50 capturer_(capturer), | 50 capturer_(capturer), |
51 encoder_(encoder), | 51 encoder_(encoder), |
52 rate_(kDefaultCaptureRate), | 52 rate_(kDefaultCaptureRate), |
53 started_(false), | 53 started_(false), |
54 recordings_(0), | 54 recordings_(0), |
55 max_rate_(kDefaultCaptureRate), | 55 max_rate_(kDefaultCaptureRate), |
56 rate_control_started_(false) { | 56 rate_control_started_(false) { |
57 DCHECK(capture_loop_); | 57 DCHECK(capture_loop_); |
58 DCHECK(encode_loop_); | 58 DCHECK(encode_loop_); |
59 DCHECK(network_loop_); | 59 DCHECK(network_loop_); |
60 } | 60 } |
61 | 61 |
62 SessionManager::~SessionManager() { | 62 ScreenRecorder::~ScreenRecorder() { |
63 connections_.clear(); | 63 connections_.clear(); |
64 } | 64 } |
65 | 65 |
66 // Public methods -------------------------------------------------------------- | 66 // Public methods -------------------------------------------------------------- |
67 | 67 |
68 void SessionManager::Start() { | 68 void ScreenRecorder::Start() { |
69 capture_loop_->PostTask( | 69 capture_loop_->PostTask( |
70 FROM_HERE, NewTracedMethod(this, &SessionManager::DoStart)); | 70 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoStart)); |
71 } | 71 } |
72 | 72 |
73 void SessionManager::Pause() { | 73 void ScreenRecorder::Pause() { |
74 capture_loop_->PostTask( | 74 capture_loop_->PostTask( |
75 FROM_HERE, NewTracedMethod(this, &SessionManager::DoPause)); | 75 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoPause)); |
76 } | 76 } |
77 | 77 |
78 void SessionManager::SetMaxRate(double rate) { | 78 void ScreenRecorder::SetMaxRate(double rate) { |
79 capture_loop_->PostTask( | 79 capture_loop_->PostTask( |
80 FROM_HERE, NewTracedMethod(this, &SessionManager::DoSetMaxRate, rate)); | 80 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoSetMaxRate, rate)); |
81 } | 81 } |
82 | 82 |
83 void SessionManager::AddConnection( | 83 void ScreenRecorder::AddConnection( |
84 scoped_refptr<ConnectionToClient> connection) { | 84 scoped_refptr<ConnectionToClient> connection) { |
85 // Gets the init information for the connection. | 85 // Gets the init information for the connection. |
86 capture_loop_->PostTask( | 86 capture_loop_->PostTask( |
87 FROM_HERE, | 87 FROM_HERE, |
88 NewTracedMethod(this, &SessionManager::DoGetInitInfo, connection)); | 88 NewTracedMethod(this, &ScreenRecorder::DoGetInitInfo, connection)); |
89 } | 89 } |
90 | 90 |
91 void SessionManager::RemoveConnection( | 91 void ScreenRecorder::RemoveConnection( |
92 scoped_refptr<ConnectionToClient> connection) { | 92 scoped_refptr<ConnectionToClient> connection) { |
93 network_loop_->PostTask( | 93 network_loop_->PostTask( |
94 FROM_HERE, | 94 FROM_HERE, |
95 NewTracedMethod(this, &SessionManager::DoRemoveClient, connection)); | 95 NewTracedMethod(this, &ScreenRecorder::DoRemoveClient, connection)); |
96 } | 96 } |
97 | 97 |
98 void SessionManager::RemoveAllConnections() { | 98 void ScreenRecorder::RemoveAllConnections() { |
99 network_loop_->PostTask( | 99 network_loop_->PostTask( |
100 FROM_HERE, | 100 FROM_HERE, |
101 NewTracedMethod(this, &SessionManager::DoRemoveAllClients)); | 101 NewTracedMethod(this, &ScreenRecorder::DoRemoveAllClients)); |
102 } | 102 } |
103 | 103 |
104 // Private accessors ----------------------------------------------------------- | 104 // Private accessors ----------------------------------------------------------- |
105 | 105 |
106 Capturer* SessionManager::capturer() { | 106 Capturer* ScreenRecorder::capturer() { |
107 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 107 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
108 return capturer_.get(); | 108 return capturer_.get(); |
109 } | 109 } |
110 | 110 |
111 Encoder* SessionManager::encoder() { | 111 Encoder* ScreenRecorder::encoder() { |
112 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 112 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
113 return encoder_.get(); | 113 return encoder_.get(); |
114 } | 114 } |
115 | 115 |
116 // Capturer thread ------------------------------------------------------------- | 116 // Capturer thread ------------------------------------------------------------- |
117 | 117 |
118 void SessionManager::DoStart() { | 118 void ScreenRecorder::DoStart() { |
119 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 119 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
120 | 120 |
121 if (started_) { | 121 if (started_) { |
122 NOTREACHED() << "Record session already started."; | 122 NOTREACHED() << "Record session already started."; |
123 return; | 123 return; |
124 } | 124 } |
125 | 125 |
126 started_ = true; | 126 started_ = true; |
127 DoCapture(); | 127 DoCapture(); |
128 | 128 |
129 // Starts the rate regulation. | 129 // Starts the rate regulation. |
130 network_loop_->PostTask( | 130 network_loop_->PostTask( |
131 FROM_HERE, | 131 FROM_HERE, |
132 NewTracedMethod(this, &SessionManager::DoStartRateControl)); | 132 NewTracedMethod(this, &ScreenRecorder::DoStartRateControl)); |
133 } | 133 } |
134 | 134 |
135 void SessionManager::DoPause() { | 135 void ScreenRecorder::DoPause() { |
136 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 136 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
137 | 137 |
138 if (!started_) { | 138 if (!started_) { |
139 NOTREACHED() << "Record session not started."; | 139 NOTREACHED() << "Record session not started."; |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 started_ = false; | 143 started_ = false; |
144 | 144 |
145 // Pause the rate regulation. | 145 // Pause the rate regulation. |
146 network_loop_->PostTask( | 146 network_loop_->PostTask( |
147 FROM_HERE, | 147 FROM_HERE, |
148 NewTracedMethod(this, &SessionManager::DoPauseRateControl)); | 148 NewTracedMethod(this, &ScreenRecorder::DoPauseRateControl)); |
149 } | 149 } |
150 | 150 |
151 void SessionManager::DoSetRate(double rate) { | 151 void ScreenRecorder::DoSetRate(double rate) { |
152 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 152 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
153 if (rate == rate_) | 153 if (rate == rate_) |
154 return; | 154 return; |
155 | 155 |
156 // Change the current capture rate. | 156 // Change the current capture rate. |
157 rate_ = rate; | 157 rate_ = rate; |
158 | 158 |
159 // If we have already started then schedule the next capture with the new | 159 // If we have already started then schedule the next capture with the new |
160 // rate. | 160 // rate. |
161 if (started_) | 161 if (started_) |
162 ScheduleNextCapture(); | 162 ScheduleNextCapture(); |
163 } | 163 } |
164 | 164 |
165 void SessionManager::DoSetMaxRate(double max_rate) { | 165 void ScreenRecorder::DoSetMaxRate(double max_rate) { |
166 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 166 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
167 | 167 |
168 // TODO(hclam): Should also check for small epsilon. | 168 // TODO(hclam): Should also check for small epsilon. |
169 if (max_rate != 0) { | 169 if (max_rate != 0) { |
170 max_rate_ = max_rate; | 170 max_rate_ = max_rate; |
171 DoSetRate(max_rate); | 171 DoSetRate(max_rate); |
172 } else { | 172 } else { |
173 NOTREACHED() << "Rate is too small."; | 173 NOTREACHED() << "Rate is too small."; |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 void SessionManager::ScheduleNextCapture() { | 177 void ScreenRecorder::ScheduleNextCapture() { |
178 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 178 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
179 | 179 |
180 ScopedTracer tracer("capture"); | 180 ScopedTracer tracer("capture"); |
181 | 181 |
182 TraceContext::tracer()->PrintString("Capture Scheduled"); | 182 TraceContext::tracer()->PrintString("Capture Scheduled"); |
183 | 183 |
184 if (rate_ == 0) | 184 if (rate_ == 0) |
185 return; | 185 return; |
186 | 186 |
187 base::TimeDelta interval = base::TimeDelta::FromMilliseconds( | 187 base::TimeDelta interval = base::TimeDelta::FromMilliseconds( |
188 static_cast<int>(base::Time::kMillisecondsPerSecond / rate_)); | 188 static_cast<int>(base::Time::kMillisecondsPerSecond / rate_)); |
189 capture_loop_->PostDelayedTask( | 189 capture_loop_->PostDelayedTask( |
190 FROM_HERE, | 190 FROM_HERE, |
191 NewTracedMethod(this, &SessionManager::DoCapture), | 191 NewTracedMethod(this, &ScreenRecorder::DoCapture), |
192 interval.InMilliseconds()); | 192 interval.InMilliseconds()); |
193 } | 193 } |
194 | 194 |
195 void SessionManager::DoCapture() { | 195 void ScreenRecorder::DoCapture() { |
196 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 196 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
197 // Make sure we have at most two oustanding recordings. We can simply return | 197 // Make sure we have at most two oustanding recordings. We can simply return |
198 // if we can't make a capture now, the next capture will be started by the | 198 // if we can't make a capture now, the next capture will be started by the |
199 // end of an encode operation. | 199 // end of an encode operation. |
200 if (recordings_ >= 2 || !started_) { | 200 if (recordings_ >= 2 || !started_) { |
201 return; | 201 return; |
202 } | 202 } |
203 TraceContext::tracer()->PrintString("Capture Started"); | 203 TraceContext::tracer()->PrintString("Capture Started"); |
204 | 204 |
205 base::Time now = base::Time::Now(); | 205 base::Time now = base::Time::Now(); |
(...skipping 11 matching lines...) Expand all Loading... |
217 last_capture_time_ = now; | 217 last_capture_time_ = now; |
218 ++recordings_; | 218 ++recordings_; |
219 | 219 |
220 // Before we actually do a capture, schedule the next one. | 220 // Before we actually do a capture, schedule the next one. |
221 ScheduleNextCapture(); | 221 ScheduleNextCapture(); |
222 | 222 |
223 // And finally perform one capture. | 223 // And finally perform one capture. |
224 DCHECK(capturer()); | 224 DCHECK(capturer()); |
225 | 225 |
226 capturer()->CaptureInvalidRects( | 226 capturer()->CaptureInvalidRects( |
227 NewCallback(this, &SessionManager::CaptureDoneCallback)); | 227 NewCallback(this, &ScreenRecorder::CaptureDoneCallback)); |
228 } | 228 } |
229 | 229 |
230 void SessionManager::CaptureDoneCallback( | 230 void ScreenRecorder::CaptureDoneCallback( |
231 scoped_refptr<CaptureData> capture_data) { | 231 scoped_refptr<CaptureData> capture_data) { |
232 // TODO(hclam): There is a bug if the capturer doesn't produce any dirty | 232 // TODO(hclam): There is a bug if the capturer doesn't produce any dirty |
233 // rects. | 233 // rects. |
234 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 234 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
235 TraceContext::tracer()->PrintString("Capture Done"); | 235 TraceContext::tracer()->PrintString("Capture Done"); |
236 encode_loop_->PostTask( | 236 encode_loop_->PostTask( |
237 FROM_HERE, | 237 FROM_HERE, |
238 NewTracedMethod(this, &SessionManager::DoEncode, capture_data)); | 238 NewTracedMethod(this, &ScreenRecorder::DoEncode, capture_data)); |
239 } | 239 } |
240 | 240 |
241 void SessionManager::DoFinishEncode() { | 241 void ScreenRecorder::DoFinishEncode() { |
242 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 242 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
243 | 243 |
244 // Decrement the number of recording in process since we have completed | 244 // Decrement the number of recording in process since we have completed |
245 // one cycle. | 245 // one cycle. |
246 --recordings_; | 246 --recordings_; |
247 | 247 |
248 // Try to do a capture again. Note that the following method may do nothing | 248 // Try to do a capture again. Note that the following method may do nothing |
249 // if it is too early to perform a capture. | 249 // if it is too early to perform a capture. |
250 if (rate_ > 0) | 250 if (rate_ > 0) |
251 DoCapture(); | 251 DoCapture(); |
252 } | 252 } |
253 | 253 |
254 void SessionManager::DoGetInitInfo( | 254 void ScreenRecorder::DoGetInitInfo( |
255 scoped_refptr<ConnectionToClient> connection) { | 255 scoped_refptr<ConnectionToClient> connection) { |
256 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 256 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
257 | 257 |
258 ScopedTracer tracer("init"); | 258 ScopedTracer tracer("init"); |
259 | 259 |
260 // Add the client to the list so it can receive update stream. | 260 // Add the client to the list so it can receive update stream. |
261 network_loop_->PostTask( | 261 network_loop_->PostTask( |
262 FROM_HERE, | 262 FROM_HERE, |
263 NewTracedMethod(this, &SessionManager::DoAddClient, connection)); | 263 NewTracedMethod(this, &ScreenRecorder::DoAddClient, connection)); |
264 } | 264 } |
265 | 265 |
266 // Network thread -------------------------------------------------------------- | 266 // Network thread -------------------------------------------------------------- |
267 | 267 |
268 void SessionManager::DoStartRateControl() { | 268 void ScreenRecorder::DoStartRateControl() { |
269 DCHECK_EQ(network_loop_, MessageLoop::current()); | 269 DCHECK_EQ(network_loop_, MessageLoop::current()); |
270 | 270 |
271 if (rate_control_started_) { | 271 if (rate_control_started_) { |
272 NOTREACHED() << "Rate regulation already started"; | 272 NOTREACHED() << "Rate regulation already started"; |
273 return; | 273 return; |
274 } | 274 } |
275 rate_control_started_ = true; | 275 rate_control_started_ = true; |
276 ScheduleNextRateControl(); | 276 ScheduleNextRateControl(); |
277 } | 277 } |
278 | 278 |
279 void SessionManager::DoPauseRateControl() { | 279 void ScreenRecorder::DoPauseRateControl() { |
280 DCHECK_EQ(network_loop_, MessageLoop::current()); | 280 DCHECK_EQ(network_loop_, MessageLoop::current()); |
281 | 281 |
282 if (!rate_control_started_) { | 282 if (!rate_control_started_) { |
283 NOTREACHED() << "Rate regulation not started"; | 283 NOTREACHED() << "Rate regulation not started"; |
284 return; | 284 return; |
285 } | 285 } |
286 rate_control_started_ = false; | 286 rate_control_started_ = false; |
287 } | 287 } |
288 | 288 |
289 void SessionManager::ScheduleNextRateControl() { | 289 void ScreenRecorder::ScheduleNextRateControl() { |
290 ScopedTracer tracer("Rate Control"); | 290 ScopedTracer tracer("Rate Control"); |
291 network_loop_->PostDelayedTask( | 291 network_loop_->PostDelayedTask( |
292 FROM_HERE, | 292 FROM_HERE, |
293 NewTracedMethod(this, &SessionManager::DoRateControl), | 293 NewTracedMethod(this, &ScreenRecorder::DoRateControl), |
294 kRateControlInterval.InMilliseconds()); | 294 kRateControlInterval.InMilliseconds()); |
295 } | 295 } |
296 | 296 |
297 void SessionManager::DoRateControl() { | 297 void ScreenRecorder::DoRateControl() { |
298 DCHECK_EQ(network_loop_, MessageLoop::current()); | 298 DCHECK_EQ(network_loop_, MessageLoop::current()); |
299 | 299 |
300 // If we have been paused then shutdown the rate regulation loop. | 300 // If we have been paused then shutdown the rate regulation loop. |
301 if (!rate_control_started_) | 301 if (!rate_control_started_) |
302 return; | 302 return; |
303 | 303 |
304 int max_pending_update_streams = 0; | 304 int max_pending_update_streams = 0; |
305 for (size_t i = 0; i < connections_.size(); ++i) { | 305 for (size_t i = 0; i < connections_.size(); ++i) { |
306 max_pending_update_streams = | 306 max_pending_update_streams = |
307 std::max(max_pending_update_streams, | 307 std::max(max_pending_update_streams, |
(...skipping 10 matching lines...) Expand all Loading... |
318 new_rate = 0; | 318 new_rate = 0; |
319 } else { | 319 } else { |
320 // Slow down the capture rate using the divider. | 320 // Slow down the capture rate using the divider. |
321 new_rate = max_rate_ / kRateDividers[slow_down]; | 321 new_rate = max_rate_ / kRateDividers[slow_down]; |
322 } | 322 } |
323 DCHECK_NE(new_rate, -1.0); | 323 DCHECK_NE(new_rate, -1.0); |
324 | 324 |
325 // Then set the rate. | 325 // Then set the rate. |
326 capture_loop_->PostTask( | 326 capture_loop_->PostTask( |
327 FROM_HERE, | 327 FROM_HERE, |
328 NewTracedMethod(this, &SessionManager::DoSetRate, new_rate)); | 328 NewTracedMethod(this, &ScreenRecorder::DoSetRate, new_rate)); |
329 ScheduleNextRateControl(); | 329 ScheduleNextRateControl(); |
330 } | 330 } |
331 | 331 |
332 void SessionManager::DoSendVideoPacket(VideoPacket* packet) { | 332 void ScreenRecorder::DoSendVideoPacket(VideoPacket* packet) { |
333 DCHECK_EQ(network_loop_, MessageLoop::current()); | 333 DCHECK_EQ(network_loop_, MessageLoop::current()); |
334 | 334 |
335 TraceContext::tracer()->PrintString("DoSendUpdate"); | 335 TraceContext::tracer()->PrintString("DoSendUpdate"); |
336 | 336 |
337 for (ConnectionToClientList::const_iterator i = connections_.begin(); | 337 for (ConnectionToClientList::const_iterator i = connections_.begin(); |
338 i < connections_.end(); ++i) { | 338 i < connections_.end(); ++i) { |
339 (*i)->SendVideoPacket(*packet); | 339 (*i)->SendVideoPacket(*packet); |
340 } | 340 } |
341 delete packet; | 341 delete packet; |
342 | 342 |
343 TraceContext::tracer()->PrintString("DoSendUpdate done"); | 343 TraceContext::tracer()->PrintString("DoSendUpdate done"); |
344 } | 344 } |
345 | 345 |
346 void SessionManager::DoAddClient(scoped_refptr<ConnectionToClient> connection) { | 346 void ScreenRecorder::DoAddClient(scoped_refptr<ConnectionToClient> connection) { |
347 DCHECK_EQ(network_loop_, MessageLoop::current()); | 347 DCHECK_EQ(network_loop_, MessageLoop::current()); |
348 | 348 |
349 // TODO(hclam): Force a full frame for next encode. | 349 // TODO(hclam): Force a full frame for next encode. |
350 connections_.push_back(connection); | 350 connections_.push_back(connection); |
351 } | 351 } |
352 | 352 |
353 void SessionManager::DoRemoveClient( | 353 void ScreenRecorder::DoRemoveClient( |
354 scoped_refptr<ConnectionToClient> connection) { | 354 scoped_refptr<ConnectionToClient> connection) { |
355 DCHECK_EQ(network_loop_, MessageLoop::current()); | 355 DCHECK_EQ(network_loop_, MessageLoop::current()); |
356 | 356 |
357 // TODO(hclam): Is it correct to do to a scoped_refptr? | 357 // TODO(hclam): Is it correct to do to a scoped_refptr? |
358 ConnectionToClientList::iterator it | 358 ConnectionToClientList::iterator it |
359 = std::find(connections_.begin(), connections_.end(), connection); | 359 = std::find(connections_.begin(), connections_.end(), connection); |
360 if (it != connections_.end()) { | 360 if (it != connections_.end()) { |
361 connections_.erase(it); | 361 connections_.erase(it); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 void SessionManager::DoRemoveAllClients() { | 365 void ScreenRecorder::DoRemoveAllClients() { |
366 DCHECK_EQ(network_loop_, MessageLoop::current()); | 366 DCHECK_EQ(network_loop_, MessageLoop::current()); |
367 | 367 |
368 // Clear the list of connections. | 368 // Clear the list of connections. |
369 connections_.clear(); | 369 connections_.clear(); |
370 } | 370 } |
371 | 371 |
372 // Encoder thread -------------------------------------------------------------- | 372 // Encoder thread -------------------------------------------------------------- |
373 | 373 |
374 void SessionManager::DoEncode( | 374 void ScreenRecorder::DoEncode( |
375 scoped_refptr<CaptureData> capture_data) { | 375 scoped_refptr<CaptureData> capture_data) { |
376 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 376 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
377 TraceContext::tracer()->PrintString("DoEncode called"); | 377 TraceContext::tracer()->PrintString("DoEncode called"); |
378 | 378 |
379 // Early out if there's nothing to encode. | 379 // Early out if there's nothing to encode. |
380 if (!capture_data->dirty_rects().size()) { | 380 if (!capture_data->dirty_rects().size()) { |
381 capture_loop_->PostTask( | 381 capture_loop_->PostTask( |
382 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); | 382 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoFinishEncode)); |
383 return; | 383 return; |
384 } | 384 } |
385 | 385 |
386 // TODO(hclam): Enable |force_refresh| if a new connection was | 386 // TODO(hclam): Enable |force_refresh| if a new connection was |
387 // added. | 387 // added. |
388 TraceContext::tracer()->PrintString("Encode start"); | 388 TraceContext::tracer()->PrintString("Encode start"); |
389 encoder_->Encode(capture_data, false, | 389 encoder_->Encode(capture_data, false, |
390 NewCallback(this, &SessionManager::EncodeDataAvailableTask)); | 390 NewCallback(this, &ScreenRecorder::EncodeDataAvailableTask)); |
391 TraceContext::tracer()->PrintString("Encode Done"); | 391 TraceContext::tracer()->PrintString("Encode Done"); |
392 } | 392 } |
393 | 393 |
394 void SessionManager::EncodeDataAvailableTask(VideoPacket* packet) { | 394 void ScreenRecorder::EncodeDataAvailableTask(VideoPacket* packet) { |
395 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 395 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
396 | 396 |
397 bool last = (packet->flags() & VideoPacket::LAST_PACKET) != 0; | 397 bool last = (packet->flags() & VideoPacket::LAST_PACKET) != 0; |
398 | 398 |
399 // Before a new encode task starts, notify connected clients a new update | 399 // Before a new encode task starts, notify connected clients a new update |
400 // stream is coming. | 400 // stream is coming. |
401 // Notify this will keep a reference to the DataBuffer in the | 401 // Notify this will keep a reference to the DataBuffer in the |
402 // task. The ownership will eventually pass to the ConnectionToClients. | 402 // task. The ownership will eventually pass to the ConnectionToClients. |
403 network_loop_->PostTask( | 403 network_loop_->PostTask( |
404 FROM_HERE, | 404 FROM_HERE, |
405 NewTracedMethod(this, &SessionManager::DoSendVideoPacket, packet)); | 405 NewTracedMethod(this, &ScreenRecorder::DoSendVideoPacket, packet)); |
406 | 406 |
407 if (last) { | 407 if (last) { |
408 capture_loop_->PostTask( | 408 capture_loop_->PostTask( |
409 FROM_HERE, NewTracedMethod(this, &SessionManager::DoFinishEncode)); | 409 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoFinishEncode)); |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
413 } // namespace remoting | 413 } // namespace remoting |
OLD | NEW |