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

Side by Side Diff: content/renderer/media/video_capture_impl.cc

Issue 120893002: Eliminate video capture thread in renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git cl upload Created 6 years, 11 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
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 "content/renderer/media/video_capture_impl.h" 5 #include "content/renderer/media/video_capture_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/child/child_process.h" 9 #include "content/child/child_process.h"
10 #include "content/common/media/video_capture_messages.h" 10 #include "content/common/media/video_capture_messages.h"
(...skipping 24 matching lines...) Expand all
35 bool VideoCaptureImpl::CaptureStarted() { 35 bool VideoCaptureImpl::CaptureStarted() {
36 return state_ == VIDEO_CAPTURE_STATE_STARTED; 36 return state_ == VIDEO_CAPTURE_STATE_STARTED;
37 } 37 }
38 38
39 int VideoCaptureImpl::CaptureFrameRate() { 39 int VideoCaptureImpl::CaptureFrameRate() {
40 return last_frame_format_.frame_rate; 40 return last_frame_format_.frame_rate;
41 } 41 }
42 42
43 VideoCaptureImpl::VideoCaptureImpl( 43 VideoCaptureImpl::VideoCaptureImpl(
44 const media::VideoCaptureSessionId session_id, 44 const media::VideoCaptureSessionId session_id,
45 base::MessageLoopProxy* capture_message_loop_proxy,
46 VideoCaptureMessageFilter* filter) 45 VideoCaptureMessageFilter* filter)
47 : VideoCapture(), 46 : VideoCapture(),
48 message_filter_(filter), 47 message_filter_(filter),
49 capture_message_loop_proxy_(capture_message_loop_proxy),
50 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()), 48 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()),
51 device_id_(0), 49 device_id_(0),
52 session_id_(session_id), 50 session_id_(session_id),
53 suspended_(false), 51 suspended_(false),
54 state_(VIDEO_CAPTURE_STATE_STOPPED), 52 state_(VIDEO_CAPTURE_STATE_STOPPED),
55 weak_this_factory_(this) { 53 weak_this_factory_(this) {
56 DCHECK(filter); 54 DCHECK(filter);
57 } 55 }
58 56
59 VideoCaptureImpl::~VideoCaptureImpl() {} 57 VideoCaptureImpl::~VideoCaptureImpl() {}
60 58
61 void VideoCaptureImpl::Init() { 59 void VideoCaptureImpl::Init() {
Ami GONE FROM CHROMIUM 2014/01/08 01:43:58 Why? What's the benefit? (the cost is increased o
Alpha Left Google 2014/01/08 22:30:50 That's not that case. Init, DeInit are called from
62 if (!io_message_loop_proxy_->BelongsToCurrentThread()) { 60 io_message_loop_proxy_->PostTask(FROM_HERE,
63 io_message_loop_proxy_->PostTask(FROM_HERE, 61 base::Bind(&VideoCaptureImpl::InitOnIOThread,
64 base::Bind(&VideoCaptureImpl::AddDelegateOnIOThread, 62 base::Unretained(this)));
65 base::Unretained(this)));
66 } else {
67 AddDelegateOnIOThread();
68 }
69 } 63 }
70 64
71 void VideoCaptureImpl::DeInit(base::Closure task) { 65 void VideoCaptureImpl::DeInit(base::Closure done_cb) {
72 capture_message_loop_proxy_->PostTask(FROM_HERE, 66 io_message_loop_proxy_->PostTask(FROM_HERE,
73 base::Bind(&VideoCaptureImpl::DoDeInitOnCaptureThread, 67 base::Bind(&VideoCaptureImpl::DeInitOnIOThread,
74 base::Unretained(this), task)); 68 base::Unretained(this),
69 done_cb));
70 }
71
72 void VideoCaptureImpl::SuspendCapture(bool suspend) {
73 io_message_loop_proxy_->PostTask(FROM_HERE,
74 base::Bind(&VideoCaptureImpl::SuspendCaptureOnIOThread,
75 base::Unretained(this),
76 suspend));
75 } 77 }
76 78
77 void VideoCaptureImpl::StartCapture( 79 void VideoCaptureImpl::StartCapture(
78 media::VideoCapture::EventHandler* handler, 80 media::VideoCapture::EventHandler* handler,
79 const media::VideoCaptureParams& params) { 81 const media::VideoCaptureParams& params) {
80 capture_message_loop_proxy_->PostTask(FROM_HERE, 82 io_message_loop_proxy_->PostTask(FROM_HERE,
81 base::Bind(&VideoCaptureImpl::DoStartCaptureOnCaptureThread, 83 base::Bind(&VideoCaptureImpl::StartCaptureOnIOThread,
82 base::Unretained(this), handler, params)); 84 base::Unretained(this), handler, params));
83 } 85 }
84 86
85 void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) { 87 void VideoCaptureImpl::StopCapture(
86 capture_message_loop_proxy_->PostTask(FROM_HERE, 88 media::VideoCapture::EventHandler* handler) {
87 base::Bind(&VideoCaptureImpl::DoStopCaptureOnCaptureThread, 89 io_message_loop_proxy_->PostTask(FROM_HERE,
90 base::Bind(&VideoCaptureImpl::StopCaptureOnIOThread,
88 base::Unretained(this), handler)); 91 base::Unretained(this), handler));
89 } 92 }
90 93
91 void VideoCaptureImpl::OnBufferCreated( 94 void VideoCaptureImpl::InitOnIOThread() {
92 base::SharedMemoryHandle handle, 95 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
93 int length, int buffer_id) { 96 message_filter_->AddDelegate(this);
94 capture_message_loop_proxy_->PostTask(FROM_HERE,
95 base::Bind(&VideoCaptureImpl::DoBufferCreatedOnCaptureThread,
96 base::Unretained(this), handle, length, buffer_id));
97 } 97 }
98 98
99 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) { 99 void VideoCaptureImpl::DeInitOnIOThread(base::Closure done_cb) {
100 capture_message_loop_proxy_->PostTask(FROM_HERE, 100 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
101 base::Bind(&VideoCaptureImpl::DoBufferDestroyedOnCaptureThread, 101 if (state_ == VIDEO_CAPTURE_STATE_STARTED)
102 base::Unretained(this), buffer_id)); 102 Send(new VideoCaptureHostMsg_Stop(device_id_));
103 message_filter_->RemoveDelegate(this);
104 done_cb.Run();
103 } 105 }
104 106
105 void VideoCaptureImpl::OnBufferReceived( 107 void VideoCaptureImpl::SuspendCaptureOnIOThread(bool suspend) {
106 int buffer_id, 108 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
107 base::Time timestamp, 109 suspended_ = suspend;
108 const media::VideoCaptureFormat& format) {
109 capture_message_loop_proxy_->PostTask(FROM_HERE,
110 base::Bind(&VideoCaptureImpl::DoBufferReceivedOnCaptureThread,
111 base::Unretained(this), buffer_id, timestamp, format));
112 } 110 }
113 111
114 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { 112 void VideoCaptureImpl::StartCaptureOnIOThread(
115 capture_message_loop_proxy_->PostTask(FROM_HERE,
116 base::Bind(&VideoCaptureImpl::DoStateChangedOnCaptureThread,
117 base::Unretained(this), state));
118 }
119
120 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) {
121 capture_message_loop_proxy_->PostTask(FROM_HERE,
122 base::Bind(&VideoCaptureImpl::DoDelegateAddedOnCaptureThread,
123 base::Unretained(this), device_id));
124 }
125
126 void VideoCaptureImpl::SuspendCapture(bool suspend) {
127 capture_message_loop_proxy_->PostTask(FROM_HERE,
128 base::Bind(&VideoCaptureImpl::DoSuspendCaptureOnCaptureThread,
129 base::Unretained(this), suspend));
130 }
131
132 void VideoCaptureImpl::DoDeInitOnCaptureThread(base::Closure task) {
133 if (state_ == VIDEO_CAPTURE_STATE_STARTED)
134 Send(new VideoCaptureHostMsg_Stop(device_id_));
135
136 io_message_loop_proxy_->PostTask(FROM_HERE,
137 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread,
138 base::Unretained(this), task));
139 }
140
141 void VideoCaptureImpl::DoStartCaptureOnCaptureThread(
142 media::VideoCapture::EventHandler* handler, 113 media::VideoCapture::EventHandler* handler,
143 const media::VideoCaptureParams& params) { 114 const media::VideoCaptureParams& params) {
144 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 115 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
145
146 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { 116 if (state_ == VIDEO_CAPTURE_STATE_ERROR) {
147 handler->OnError(this, 1); 117 handler->OnError(this, 1);
148 handler->OnRemoved(this); 118 handler->OnRemoved(this);
149 } else if ((clients_pending_on_filter_.find(handler) != 119 } else if ((clients_pending_on_filter_.find(handler) !=
150 clients_pending_on_filter_.end()) || 120 clients_pending_on_filter_.end()) ||
151 (clients_pending_on_restart_.find(handler) != 121 (clients_pending_on_restart_.find(handler) !=
152 clients_pending_on_restart_.end()) || 122 clients_pending_on_restart_.end()) ||
153 clients_.find(handler) != clients_.end() ) { 123 clients_.find(handler) != clients_.end() ) {
154 // This client has started. 124 // This client has started.
155 } else if (!device_id_) { 125 } else if (!device_id_) {
(...skipping 20 matching lines...) Expand all
176 media::limits::kMaxFramesPerSecond; 146 media::limits::kMaxFramesPerSecond;
177 } 147 }
178 DVLOG(1) << "StartCapture: starting with first resolution " 148 DVLOG(1) << "StartCapture: starting with first resolution "
179 << params_.requested_format.frame_size.ToString(); 149 << params_.requested_format.frame_size.ToString();
180 150
181 StartCaptureInternal(); 151 StartCaptureInternal();
182 } 152 }
183 } 153 }
184 } 154 }
185 155
186 void VideoCaptureImpl::DoStopCaptureOnCaptureThread( 156 void VideoCaptureImpl::StopCaptureOnIOThread(
187 media::VideoCapture::EventHandler* handler) { 157 media::VideoCapture::EventHandler* handler) {
188 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 158 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
189 159
190 // A handler can be in only one client list. 160 // A handler can be in only one client list.
191 // If this handler is in any client list, we can just remove it from 161 // If this handler is in any client list, we can just remove it from
192 // that client list and don't have to run the other following RemoveClient(). 162 // that client list and don't have to run the other following RemoveClient().
193 RemoveClient(handler, &clients_pending_on_filter_) || 163 RemoveClient(handler, &clients_pending_on_filter_) ||
194 RemoveClient(handler, &clients_pending_on_restart_) || 164 RemoveClient(handler, &clients_pending_on_restart_) ||
195 RemoveClient(handler, &clients_); 165 RemoveClient(handler, &clients_);
196 166
197 if (clients_.empty()) { 167 if (clients_.empty()) {
198 DVLOG(1) << "StopCapture: No more client, stopping ..."; 168 DVLOG(1) << "StopCapture: No more client, stopping ...";
199 StopDevice(); 169 StopDevice();
200 client_buffers_.clear(); 170 client_buffers_.clear();
201 weak_this_factory_.InvalidateWeakPtrs(); 171 weak_this_factory_.InvalidateWeakPtrs();
202 } 172 }
203 } 173 }
204 174
205 void VideoCaptureImpl::DoBufferCreatedOnCaptureThread( 175 void VideoCaptureImpl::OnBufferCreated(
206 base::SharedMemoryHandle handle, 176 base::SharedMemoryHandle handle,
207 int length, int buffer_id) { 177 int length, int buffer_id) {
208 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 178 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
209 179
210 // In case client calls StopCapture before the arrival of created buffer, 180 // In case client calls StopCapture before the arrival of created buffer,
211 // just close this buffer and return. 181 // just close this buffer and return.
212 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { 182 if (state_ != VIDEO_CAPTURE_STATE_STARTED) {
213 base::SharedMemory::CloseHandle(handle); 183 base::SharedMemory::CloseHandle(handle);
214 return; 184 return;
215 } 185 }
216 186
217 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false)); 187 scoped_ptr<base::SharedMemory> shm(new base::SharedMemory(handle, false));
218 if (!shm->Map(length)) { 188 if (!shm->Map(length)) {
219 DLOG(ERROR) << "DoBufferCreatedOnCaptureThread: Map() failed."; 189 DLOG(ERROR) << "OnBufferCreated: Map failed.";
220 return; 190 return;
221 } 191 }
222 192
223 bool inserted = 193 bool inserted =
224 client_buffers_.insert(std::make_pair( 194 client_buffers_.insert(std::make_pair(
225 buffer_id, 195 buffer_id,
226 new ClientBuffer(shm.Pass(), 196 new ClientBuffer(shm.Pass(),
227 length))).second; 197 length))).second;
228 DCHECK(inserted); 198 DCHECK(inserted);
229 } 199 }
230 200
231 void VideoCaptureImpl::DoBufferDestroyedOnCaptureThread(int buffer_id) { 201 void VideoCaptureImpl::OnBufferDestroyed(int buffer_id) {
232 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 202 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
233 203
234 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 204 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
235 if (iter == client_buffers_.end()) 205 if (iter == client_buffers_.end())
236 return; 206 return;
237 207
238 DCHECK(!iter->second || iter->second->HasOneRef()) 208 DCHECK(!iter->second || iter->second->HasOneRef())
239 << "Instructed to delete buffer we are still using."; 209 << "Instructed to delete buffer we are still using.";
240 client_buffers_.erase(iter); 210 client_buffers_.erase(iter);
241 } 211 }
242 212
243 void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( 213 void VideoCaptureImpl::OnBufferReceived(
244 int buffer_id, 214 int buffer_id,
245 base::Time timestamp, 215 base::Time timestamp,
246 const media::VideoCaptureFormat& format) { 216 const media::VideoCaptureFormat& format) {
247 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 217 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
248 218
249 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { 219 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) {
250 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 220 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id));
251 return; 221 return;
252 } 222 }
253 223
254 last_frame_format_ = format; 224 last_frame_format_ = format;
255 225
256 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id); 226 ClientBufferMap::iterator iter = client_buffers_.find(buffer_id);
257 DCHECK(iter != client_buffers_.end()); 227 DCHECK(iter != client_buffers_.end());
258 scoped_refptr<ClientBuffer> buffer = iter->second; 228 scoped_refptr<ClientBuffer> buffer = iter->second;
259 scoped_refptr<media::VideoFrame> frame = 229 scoped_refptr<media::VideoFrame> frame =
260 media::VideoFrame::WrapExternalPackedMemory( 230 media::VideoFrame::WrapExternalPackedMemory(
261 media::VideoFrame::I420, 231 media::VideoFrame::I420,
262 last_frame_format_.frame_size, 232 last_frame_format_.frame_size,
263 gfx::Rect(last_frame_format_.frame_size), 233 gfx::Rect(last_frame_format_.frame_size),
264 last_frame_format_.frame_size, 234 last_frame_format_.frame_size,
265 reinterpret_cast<uint8*>(buffer->buffer->memory()), 235 reinterpret_cast<uint8*>(buffer->buffer->memory()),
266 buffer->buffer_size, 236 buffer->buffer_size,
267 buffer->buffer->handle(), 237 buffer->buffer->handle(),
268 // TODO(sheu): convert VideoCaptureMessageFilter::Delegate to use 238 // TODO(sheu): convert VideoCaptureMessageFilter::Delegate to use
269 // base::TimeTicks instead of base::Time. http://crbug.com/249215 239 // base::TimeTicks instead of base::Time. http://crbug.com/249215
270 timestamp - base::Time::UnixEpoch(), 240 timestamp - base::Time::UnixEpoch(),
271 media::BindToLoop( 241 media::BindToLoop(
272 capture_message_loop_proxy_, 242 io_message_loop_proxy_,
273 base::Bind( 243 base::Bind(
274 &VideoCaptureImpl::DoClientBufferFinishedOnCaptureThread, 244 &VideoCaptureImpl::OnClientBufferFinished,
275 weak_this_factory_.GetWeakPtr(), 245 weak_this_factory_.GetWeakPtr(),
276 buffer_id, 246 buffer_id,
277 buffer))); 247 buffer)));
278 248
279 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) 249 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it)
280 it->first->OnFrameReady(this, frame); 250 it->first->OnFrameReady(this, frame);
281 } 251 }
282 252
283 void VideoCaptureImpl::DoClientBufferFinishedOnCaptureThread( 253 void VideoCaptureImpl::OnClientBufferFinished(
284 int buffer_id, 254 int buffer_id,
285 const scoped_refptr<ClientBuffer>& buffer) { 255 const scoped_refptr<ClientBuffer>& buffer) {
286 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 256 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
287 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); 257 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id));
288 } 258 }
289 259
290 void VideoCaptureImpl::DoStateChangedOnCaptureThread(VideoCaptureState state) { 260 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) {
291 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 261 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
292 262
293 switch (state) { 263 switch (state) {
294 case VIDEO_CAPTURE_STATE_STARTED: 264 case VIDEO_CAPTURE_STATE_STARTED:
295 break; 265 break;
296 case VIDEO_CAPTURE_STATE_STOPPED: 266 case VIDEO_CAPTURE_STATE_STOPPED:
297 state_ = VIDEO_CAPTURE_STATE_STOPPED; 267 state_ = VIDEO_CAPTURE_STATE_STOPPED;
298 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_; 268 DVLOG(1) << "OnStateChanged: stopped!, device_id = " << device_id_;
299 client_buffers_.clear(); 269 client_buffers_.clear();
300 weak_this_factory_.InvalidateWeakPtrs(); 270 weak_this_factory_.InvalidateWeakPtrs();
301 if (!clients_.empty() || !clients_pending_on_restart_.empty()) 271 if (!clients_.empty() || !clients_pending_on_restart_.empty())
(...skipping 23 matching lines...) Expand all
325 it->first->OnRemoved(this); 295 it->first->OnRemoved(this);
326 } 296 }
327 clients_.clear(); 297 clients_.clear();
328 state_ = VIDEO_CAPTURE_STATE_ENDED; 298 state_ = VIDEO_CAPTURE_STATE_ENDED;
329 break; 299 break;
330 default: 300 default:
331 break; 301 break;
332 } 302 }
333 } 303 }
334 304
335 void VideoCaptureImpl::DoDelegateAddedOnCaptureThread(int32 device_id) { 305 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) {
336 DVLOG(1) << "DoDelegateAdded: device_id " << device_id; 306 DVLOG(1) << "OnDelegateAdded: device_id " << device_id;
337 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 307 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
338 308
339 device_id_ = device_id; 309 device_id_ = device_id;
340 for (ClientInfo::iterator it = clients_pending_on_filter_.begin(); 310 for (ClientInfo::iterator it = clients_pending_on_filter_.begin();
341 it != clients_pending_on_filter_.end(); ) { 311 it != clients_pending_on_filter_.end(); ) {
342 media::VideoCapture::EventHandler* handler = it->first; 312 media::VideoCapture::EventHandler* handler = it->first;
343 const media::VideoCaptureParams params = it->second; 313 const media::VideoCaptureParams params = it->second;
344 clients_pending_on_filter_.erase(it++); 314 clients_pending_on_filter_.erase(it++);
345 StartCapture(handler, params); 315 StartCapture(handler, params);
346 } 316 }
347 } 317 }
348 318
349 void VideoCaptureImpl::DoSuspendCaptureOnCaptureThread(bool suspend) {
350 DVLOG(1) << "DoSuspendCapture: suspend " << (suspend ? "yes" : "no");
351 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread());
352
353 suspended_ = suspend;
354 }
355
356 void VideoCaptureImpl::StopDevice() { 319 void VideoCaptureImpl::StopDevice() {
357 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 320 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
358 321
359 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 322 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
360 state_ = VIDEO_CAPTURE_STATE_STOPPING; 323 state_ = VIDEO_CAPTURE_STATE_STOPPING;
361 Send(new VideoCaptureHostMsg_Stop(device_id_)); 324 Send(new VideoCaptureHostMsg_Stop(device_id_));
362 params_.requested_format.frame_size.SetSize(0, 0); 325 params_.requested_format.frame_size.SetSize(0, 0);
363 } 326 }
364 } 327 }
365 328
366 void VideoCaptureImpl::RestartCapture() { 329 void VideoCaptureImpl::RestartCapture() {
367 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 330 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
368 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED); 331 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED);
369 332
370 int width = 0; 333 int width = 0;
371 int height = 0; 334 int height = 0;
372 for (ClientInfo::iterator it = clients_.begin(); 335 for (ClientInfo::iterator it = clients_.begin();
373 it != clients_.end(); ++it) { 336 it != clients_.end(); ++it) {
374 width = std::max(width, it->second.requested_format.frame_size.width()); 337 width = std::max(width, it->second.requested_format.frame_size.width());
375 height = std::max(height, it->second.requested_format.frame_size.height()); 338 height = std::max(height, it->second.requested_format.frame_size.height());
376 } 339 }
377 for (ClientInfo::iterator it = clients_pending_on_restart_.begin(); 340 for (ClientInfo::iterator it = clients_pending_on_restart_.begin();
378 it != clients_pending_on_restart_.end(); ) { 341 it != clients_pending_on_restart_.end(); ) {
379 width = std::max(width, it->second.requested_format.frame_size.width()); 342 width = std::max(width, it->second.requested_format.frame_size.width());
380 height = std::max(height, it->second.requested_format.frame_size.height()); 343 height = std::max(height, it->second.requested_format.frame_size.height());
381 clients_[it->first] = it->second; 344 clients_[it->first] = it->second;
382 clients_pending_on_restart_.erase(it++); 345 clients_pending_on_restart_.erase(it++);
383 } 346 }
384 params_.requested_format.frame_size.SetSize(width, height); 347 params_.requested_format.frame_size.SetSize(width, height);
385 DVLOG(1) << "RestartCapture, " 348 DVLOG(1) << "RestartCapture, "
386 << params_.requested_format.frame_size.ToString(); 349 << params_.requested_format.frame_size.ToString();
387 StartCaptureInternal(); 350 StartCaptureInternal();
388 } 351 }
389 352
390 void VideoCaptureImpl::StartCaptureInternal() { 353 void VideoCaptureImpl::StartCaptureInternal() {
391 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 354 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
392 DCHECK(device_id_); 355 DCHECK(device_id_);
393 356
394 Send(new VideoCaptureHostMsg_Start(device_id_, session_id_, params_)); 357 Send(new VideoCaptureHostMsg_Start(device_id_, session_id_, params_));
395 state_ = VIDEO_CAPTURE_STATE_STARTED; 358 state_ = VIDEO_CAPTURE_STATE_STARTED;
396 } 359 }
397 360
398 void VideoCaptureImpl::AddDelegateOnIOThread() {
399 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
400 message_filter_->AddDelegate(this);
401 }
402
403 void VideoCaptureImpl::RemoveDelegateOnIOThread(base::Closure task) {
404 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
405 message_filter_->RemoveDelegate(this);
406 capture_message_loop_proxy_->PostTask(FROM_HERE, task);
407 }
408
409 void VideoCaptureImpl::Send(IPC::Message* message) { 361 void VideoCaptureImpl::Send(IPC::Message* message) {
410 io_message_loop_proxy_->PostTask(FROM_HERE, 362 io_message_loop_proxy_->PostTask(FROM_HERE,
411 base::Bind(base::IgnoreResult(&VideoCaptureMessageFilter::Send), 363 base::Bind(base::IgnoreResult(&VideoCaptureMessageFilter::Send),
412 message_filter_.get(), message)); 364 message_filter_.get(), message));
413 } 365 }
414 366
415 bool VideoCaptureImpl::RemoveClient( 367 bool VideoCaptureImpl::RemoveClient(
416 media::VideoCapture::EventHandler* handler, 368 media::VideoCapture::EventHandler* handler,
417 ClientInfo* clients) { 369 ClientInfo* clients) {
418 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); 370 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
419 bool found = false; 371 bool found = false;
420 372
421 ClientInfo::iterator it = clients->find(handler); 373 ClientInfo::iterator it = clients->find(handler);
422 if (it != clients->end()) { 374 if (it != clients->end()) {
423 handler->OnStopped(this); 375 handler->OnStopped(this);
424 handler->OnRemoved(this); 376 handler->OnRemoved(this);
425 clients->erase(it); 377 clients->erase(it);
426 found = true; 378 found = true;
427 } 379 }
428 return found; 380 return found;
429 } 381 }
430 382
431 } // namespace content 383 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698