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

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

Issue 7058055: create one video capture message filter per renderer process (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: from code review Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/common/child_process.h" 7 #include "content/common/child_process.h"
8 #include "content/common/video_capture_messages.h" 8 #include "content/common/video_capture_messages.h"
9 9
10 VideoCaptureImpl::DIBBuffer::DIBBuffer( 10 VideoCaptureImpl::DIBBuffer::DIBBuffer(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 io_message_loop_proxy->PostTask(FROM_HERE, 61 io_message_loop_proxy->PostTask(FROM_HERE,
62 NewRunnableMethod(this, &VideoCaptureImpl::AddDelegateOnIOThread)); 62 NewRunnableMethod(this, &VideoCaptureImpl::AddDelegateOnIOThread));
63 return; 63 return;
64 } 64 }
65 65
66 AddDelegateOnIOThread(); 66 AddDelegateOnIOThread();
67 } 67 }
68 68
69 void VideoCaptureImpl::DeInit(Task* task) { 69 void VideoCaptureImpl::DeInit(Task* task) {
70 if (state_ == kStarted) 70 if (state_ == kStarted)
71 message_filter_->Send(new VideoCaptureHostMsg_Stop(0, device_id_)); 71 Send(new VideoCaptureHostMsg_Stop(0, device_id_));
72 72
73 base::MessageLoopProxy* io_message_loop_proxy = 73 base::MessageLoopProxy* io_message_loop_proxy =
74 ChildProcess::current()->io_message_loop_proxy(); 74 ChildProcess::current()->io_message_loop_proxy();
75 75
76 if (!io_message_loop_proxy->BelongsToCurrentThread()) { 76 if (!io_message_loop_proxy->BelongsToCurrentThread()) {
77 io_message_loop_proxy->PostTask(FROM_HERE, 77 io_message_loop_proxy->PostTask(FROM_HERE,
78 NewRunnableMethod(this, &VideoCaptureImpl::RemoveDelegateOnIOThread, 78 NewRunnableMethod(this, &VideoCaptureImpl::RemoveDelegateOnIOThread,
79 task)); 79 task));
80 return; 80 return;
81 } 81 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 void VideoCaptureImpl::OnBufferReceived(TransportDIB::Handle handle, 222 void VideoCaptureImpl::OnBufferReceived(TransportDIB::Handle handle,
223 base::Time timestamp) { 223 base::Time timestamp) {
224 if (!ml_proxy_->BelongsToCurrentThread()) { 224 if (!ml_proxy_->BelongsToCurrentThread()) {
225 ml_proxy_->PostTask(FROM_HERE, 225 ml_proxy_->PostTask(FROM_HERE,
226 NewRunnableMethod(this, &VideoCaptureImpl::OnBufferReceived, 226 NewRunnableMethod(this, &VideoCaptureImpl::OnBufferReceived,
227 handle, timestamp)); 227 handle, timestamp));
228 return; 228 return;
229 } 229 }
230 230
231 if (state_ != kStarted) { 231 if (state_ != kStarted) {
232 message_filter_->Send( 232 Send(new VideoCaptureHostMsg_BufferReady(0, device_id_, handle));
233 new VideoCaptureHostMsg_BufferReady(0, device_id_, handle));
234 return; 233 return;
235 } 234 }
236 235
237 media::VideoCapture::VideoFrameBuffer* buffer; 236 media::VideoCapture::VideoFrameBuffer* buffer;
238 CachedDIB::iterator it; 237 CachedDIB::iterator it;
239 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { 238 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) {
240 if ((*it)->dib->handle() == handle) 239 if ((*it)->dib->handle() == handle)
241 break; 240 break;
242 } 241 }
243 if (it == cached_dibs_.end()) { 242 if (it == cached_dibs_.end()) {
244 TransportDIB* dib = TransportDIB::Map(handle); 243 TransportDIB* dib = TransportDIB::Map(handle);
245 buffer = new VideoFrameBuffer(); 244 buffer = new VideoFrameBuffer();
246 buffer->memory_pointer = dib->memory(); 245 buffer->memory_pointer = dib->memory();
247 buffer->buffer_size = dib->size(); 246 buffer->buffer_size = dib->size();
248 buffer->width = width_; 247 buffer->width = width_;
249 buffer->height = height_; 248 buffer->height = height_;
250 249
251 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer); 250 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer);
252 cached_dibs_.push_back(dib_buffer); 251 cached_dibs_.push_back(dib_buffer);
253 } else { 252 } else {
254 buffer = (*it)->mapped_memory; 253 buffer = (*it)->mapped_memory;
255 } 254 }
256 255
257 // TODO(wjia): handle buffer sharing with downstream modules. 256 // TODO(wjia): handle buffer sharing with downstream modules.
258 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { 257 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) {
259 it->first->OnBufferReady(this, buffer); 258 it->first->OnBufferReady(this, buffer);
260 } 259 }
261 260
262 message_filter_->Send( 261 Send(new VideoCaptureHostMsg_BufferReady(0, device_id_, handle));
263 new VideoCaptureHostMsg_BufferReady(0, device_id_, handle));
264 } 262 }
265 263
266 void VideoCaptureImpl::OnStateChanged( 264 void VideoCaptureImpl::OnStateChanged(
267 const media::VideoCapture::State& state) { 265 const media::VideoCapture::State& state) {
268 if (!ml_proxy_->BelongsToCurrentThread()) { 266 if (!ml_proxy_->BelongsToCurrentThread()) {
269 ml_proxy_->PostTask(FROM_HERE, 267 ml_proxy_->PostTask(FROM_HERE,
270 NewRunnableMethod(this, &VideoCaptureImpl::OnStateChanged, state)); 268 NewRunnableMethod(this, &VideoCaptureImpl::OnStateChanged, state));
271 return; 269 return;
272 } 270 }
273 271
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 333
336 void VideoCaptureImpl::StopDevice() { 334 void VideoCaptureImpl::StopDevice() {
337 if (!ml_proxy_->BelongsToCurrentThread()) { 335 if (!ml_proxy_->BelongsToCurrentThread()) {
338 ml_proxy_->PostTask(FROM_HERE, 336 ml_proxy_->PostTask(FROM_HERE,
339 NewRunnableMethod(this, &VideoCaptureImpl::StopDevice)); 337 NewRunnableMethod(this, &VideoCaptureImpl::StopDevice));
340 return; 338 return;
341 } 339 }
342 340
343 if (state_ == kStarted) { 341 if (state_ == kStarted) {
344 state_ = kStopping; 342 state_ = kStopping;
345 message_filter_->Send(new VideoCaptureHostMsg_Stop(0, device_id_)); 343 Send(new VideoCaptureHostMsg_Stop(0, device_id_));
346 width_ = height_ = 0; 344 width_ = height_ = 0;
347 } 345 }
348 } 346 }
349 347
350 void VideoCaptureImpl::RestartCapture() { 348 void VideoCaptureImpl::RestartCapture() {
351 DCHECK(ml_proxy_->BelongsToCurrentThread()); 349 DCHECK(ml_proxy_->BelongsToCurrentThread());
352 DCHECK_EQ(state_, kStopped); 350 DCHECK_EQ(state_, kStopped);
353 351
354 width_ = new_width_; 352 width_ = new_width_;
355 height_ = new_height_; 353 height_ = new_height_;
356 new_width_ = 0; 354 new_width_ = 0;
357 new_height_ = 0; 355 new_height_ = 0;
358 356
359 DLOG(INFO) << "RestartCapture, " << width_ << ", " << height_; 357 DLOG(INFO) << "RestartCapture, " << width_ << ", " << height_;
360 StartCaptureInternal(); 358 StartCaptureInternal();
361 } 359 }
362 360
363 void VideoCaptureImpl::StartCaptureInternal() { 361 void VideoCaptureImpl::StartCaptureInternal() {
364 DCHECK(ml_proxy_->BelongsToCurrentThread()); 362 DCHECK(ml_proxy_->BelongsToCurrentThread());
365 DCHECK(device_id_); 363 DCHECK(device_id_);
366 364
367 media::VideoCaptureParams params; 365 media::VideoCaptureParams params;
368 params.width = width_; 366 params.width = width_;
369 params.height = height_; 367 params.height = height_;
370 params.session_id = session_id_; 368 params.session_id = session_id_;
371 369
372 message_filter_->Send(new VideoCaptureHostMsg_Start(0, device_id_, params)); 370 Send(new VideoCaptureHostMsg_Start(0, device_id_, params));
373 state_ = kStarted; 371 state_ = kStarted;
374 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { 372 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) {
375 it->first->OnStarted(this); 373 it->first->OnStarted(this);
376 } 374 }
377 } 375 }
378 376
379 void VideoCaptureImpl::AddDelegateOnIOThread() { 377 void VideoCaptureImpl::AddDelegateOnIOThread() {
380 message_filter_->AddDelegate(this); 378 message_filter_->AddDelegate(this);
381 } 379 }
382 380
383 void VideoCaptureImpl::RemoveDelegateOnIOThread(Task* task) { 381 void VideoCaptureImpl::RemoveDelegateOnIOThread(Task* task) {
384 base::ScopedTaskRunner task_runner(task); 382 base::ScopedTaskRunner task_runner(task);
385 message_filter_->RemoveDelegate(this); 383 message_filter_->RemoveDelegate(this);
386 } 384 }
385
386 void VideoCaptureImpl::Send(IPC::Message* message) {
387 base::MessageLoopProxy* io_message_loop_proxy =
388 ChildProcess::current()->io_message_loop_proxy();
389
390 io_message_loop_proxy->PostTask(FROM_HERE,
391 NewRunnableMethod(message_filter_.get(),
392 &VideoCaptureMessageFilter::Send, message));
393 }
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698