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

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

Issue 8036005: Add a flag in StopCapture to allow event handler to choose event notification. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: add missing file Created 9 years, 2 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 "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/synchronization/waitable_event.h"
8 #include "content/common/child_process.h" 9 #include "content/common/child_process.h"
9 #include "content/common/media/video_capture_messages.h" 10 #include "content/common/media/video_capture_messages.h"
10 11
11 VideoCaptureImpl::DIBBuffer::DIBBuffer( 12 VideoCaptureImpl::DIBBuffer::DIBBuffer(
12 base::SharedMemory* d, media::VideoCapture::VideoFrameBuffer* ptr) 13 base::SharedMemory* d, media::VideoCapture::VideoFrameBuffer* ptr)
13 : dib(d), 14 : dib(d),
14 mapped_memory(ptr) {} 15 mapped_memory(ptr) {}
15 16
16 VideoCaptureImpl::DIBBuffer::~DIBBuffer() { 17 VideoCaptureImpl::DIBBuffer::~DIBBuffer() {
17 delete dib; 18 delete dib;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void VideoCaptureImpl::StartCapture( 88 void VideoCaptureImpl::StartCapture(
88 media::VideoCapture::EventHandler* handler, 89 media::VideoCapture::EventHandler* handler,
89 const VideoCaptureCapability& capability) { 90 const VideoCaptureCapability& capability) {
90 DCHECK_EQ(capability.raw_type, media::VideoFrame::I420); 91 DCHECK_EQ(capability.raw_type, media::VideoFrame::I420);
91 92
92 ml_proxy_->PostTask(FROM_HERE, 93 ml_proxy_->PostTask(FROM_HERE,
93 NewRunnableMethod(this, &VideoCaptureImpl::DoStartCapture, handler, 94 NewRunnableMethod(this, &VideoCaptureImpl::DoStartCapture, handler,
94 capability)); 95 capability));
95 } 96 }
96 97
97 void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler) { 98 void VideoCaptureImpl::StopCapture(media::VideoCapture::EventHandler* handler,
98 ml_proxy_->PostTask(FROM_HERE, 99 bool need_notification) {
99 NewRunnableMethod(this, &VideoCaptureImpl::DoStopCapture, handler)); 100 if (need_notification) {
101 ml_proxy_->PostTask(FROM_HERE,
102 NewRunnableMethod(this, &VideoCaptureImpl::DoStopCapture, handler,
103 static_cast<base::WaitableEvent*>(NULL)));
104 } else {
105 base::WaitableEvent completion(false, false);
106 ml_proxy_->PostTask(FROM_HERE,
107 NewRunnableMethod(this, &VideoCaptureImpl::DoStopCapture, handler,
108 &completion));
109 completion.Wait();
110 }
100 } 111 }
101 112
102 void VideoCaptureImpl::FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) { 113 void VideoCaptureImpl::FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) {
103 ml_proxy_->PostTask(FROM_HERE, 114 ml_proxy_->PostTask(FROM_HERE,
104 NewRunnableMethod(this, &VideoCaptureImpl::DoFeedBuffer, buffer)); 115 NewRunnableMethod(this, &VideoCaptureImpl::DoFeedBuffer, buffer));
105 } 116 }
106 117
107 void VideoCaptureImpl::OnBufferCreated( 118 void VideoCaptureImpl::OnBufferCreated(
108 base::SharedMemoryHandle handle, 119 base::SharedMemoryHandle handle,
109 int length, int buffer_id) { 120 int length, int buffer_id) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 current_params_.width = capability.width; 217 current_params_.width = capability.width;
207 current_params_.height = capability.height; 218 current_params_.height = capability.height;
208 current_params_.frame_per_second = capability.max_fps; 219 current_params_.frame_per_second = capability.max_fps;
209 DLOG(INFO) << "StartCapture: resolution (" 220 DLOG(INFO) << "StartCapture: resolution ("
210 << current_params_.width << ", " << current_params_.height << ")"; 221 << current_params_.width << ", " << current_params_.height << ")";
211 222
212 StartCaptureInternal(); 223 StartCaptureInternal();
213 } 224 }
214 225
215 void VideoCaptureImpl::DoStopCapture( 226 void VideoCaptureImpl::DoStopCapture(
216 media::VideoCapture::EventHandler* handler) { 227 media::VideoCapture::EventHandler* handler,
228 base::WaitableEvent* completion) {
217 DCHECK(ml_proxy_->BelongsToCurrentThread()); 229 DCHECK(ml_proxy_->BelongsToCurrentThread());
218 230
219 ClientInfo::iterator it = pending_clients_.find(handler); 231 ClientInfo::iterator it = pending_clients_.find(handler);
220 if (it != pending_clients_.end()) { 232 if (it != pending_clients_.end()) {
221 handler->OnStopped(this);
222 pending_clients_.erase(it); 233 pending_clients_.erase(it);
234 if (!completion)
235 handler->OnStopped(this);
236 else
237 completion->Signal();
223 return; 238 return;
224 } 239 }
225 240
226 if (clients_.find(handler) == clients_.end()) 241 if (clients_.find(handler) == clients_.end())
227 return; 242 return;
228 243
229 handler->OnStopped(this); 244 if (!completion)
245 handler->OnStopped(this);
246 else
247 completion->Signal();
230 clients_.erase(handler); 248 clients_.erase(handler);
231 master_clients_.remove(handler); 249 master_clients_.remove(handler);
232 250
233 // Still have at least one master client. 251 // Still have at least one master client.
234 if (master_clients_.size() > 0) 252 if (master_clients_.size() > 0)
235 return; 253 return;
236 254
237 // TODO(wjia): Is it really needed to handle resolution change for non-master 255 // TODO(wjia): Is it really needed to handle resolution change for non-master
238 // clients, except no client case? 256 // clients, except no client case?
239 if (clients_.size() > 0) { 257 if (clients_.size() > 0) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 464 }
447 465
448 void VideoCaptureImpl::Send(IPC::Message* message) { 466 void VideoCaptureImpl::Send(IPC::Message* message) {
449 base::MessageLoopProxy* io_message_loop_proxy = 467 base::MessageLoopProxy* io_message_loop_proxy =
450 ChildProcess::current()->io_message_loop_proxy(); 468 ChildProcess::current()->io_message_loop_proxy();
451 469
452 io_message_loop_proxy->PostTask(FROM_HERE, 470 io_message_loop_proxy->PostTask(FROM_HERE,
453 NewRunnableMethod(message_filter_.get(), 471 NewRunnableMethod(message_filter_.get(),
454 &VideoCaptureMessageFilter::Send, message)); 472 &VideoCaptureMessageFilter::Send, message));
455 } 473 }
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_module_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698