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

Side by Side Diff: media/video/capture/linux/video_capture_device_linux.cc

Issue 8304017: enable video capture to support sharing across multiple renderer processes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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
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 "media/video/capture/linux/video_capture_device_linux.h" 5 #include "media/video/capture/linux/video_capture_device_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/videodev2.h> 9 #include <linux/videodev2.h>
10 #include <sys/ioctl.h> 10 #include <sys/ioctl.h>
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 } 134 }
135 135
136 void VideoCaptureDeviceLinux::Allocate(int width, 136 void VideoCaptureDeviceLinux::Allocate(int width,
137 int height, 137 int height,
138 int frame_rate, 138 int frame_rate,
139 EventHandler* observer) { 139 EventHandler* observer) {
140 if (v4l2_thread_.IsRunning()) { 140 if (v4l2_thread_.IsRunning()) {
141 return; // Wrong state. 141 return; // Wrong state.
142 } 142 }
143 v4l2_thread_.Start(); 143 v4l2_thread_.Start();
perkj_chrome 2011/10/27 07:27:32 This is what make manager->Start synchronouse.
144 v4l2_thread_.message_loop()->PostTask( 144 v4l2_thread_.message_loop()->PostTask(
145 FROM_HERE, 145 FROM_HERE,
146 base::Bind(&VideoCaptureDeviceLinux::OnAllocate, base::Unretained(this), 146 base::Bind(&VideoCaptureDeviceLinux::OnAllocate, base::Unretained(this),
147 width, height, frame_rate, observer)); 147 width, height, frame_rate, observer));
148 } 148 }
149 149
150 void VideoCaptureDeviceLinux::Start() { 150 void VideoCaptureDeviceLinux::Start() {
151 if (!v4l2_thread_.IsRunning()) { 151 if (!v4l2_thread_.IsRunning()) {
152 return; // Wrong state. 152 return; // Wrong state.
153 } 153 }
(...skipping 12 matching lines...) Expand all
166 } 166 }
167 167
168 void VideoCaptureDeviceLinux::DeAllocate() { 168 void VideoCaptureDeviceLinux::DeAllocate() {
169 if (!v4l2_thread_.IsRunning()) { 169 if (!v4l2_thread_.IsRunning()) {
170 return; // Wrong state. 170 return; // Wrong state.
171 } 171 }
172 v4l2_thread_.message_loop()->PostTask( 172 v4l2_thread_.message_loop()->PostTask(
173 FROM_HERE, 173 FROM_HERE,
174 base::Bind(&VideoCaptureDeviceLinux::OnDeAllocate, 174 base::Bind(&VideoCaptureDeviceLinux::OnDeAllocate,
175 base::Unretained(this))); 175 base::Unretained(this)));
176 v4l2_thread_.Stop(); 176 v4l2_thread_.Stop();
perkj_chrome 2011/10/27 07:27:32 manager->Stop syncronouse.
177 177
178 // Make sure no buffers are still allocated. 178 // Make sure no buffers are still allocated.
179 // This can happen (theoretically) if an error occurs when trying to stop 179 // This can happen (theoretically) if an error occurs when trying to stop
180 // the camera. 180 // the camera.
181 DeAllocateVideoBuffers(); 181 DeAllocateVideoBuffers();
182 } 182 }
183 183
184 const VideoCaptureDevice::Name& VideoCaptureDeviceLinux::device_name() { 184 const VideoCaptureDevice::Name& VideoCaptureDeviceLinux::device_name() {
185 return device_name_; 185 return device_name_;
186 } 186 }
187 187
188 void VideoCaptureDeviceLinux::OnAllocate(int width, 188 void VideoCaptureDeviceLinux::OnAllocate(int width,
189 int height, 189 int height,
190 int frame_rate, 190 int frame_rate,
191 EventHandler* observer) { 191 EventHandler* observer) {
192 DCHECK_EQ(v4l2_thread_.message_loop(), MessageLoop::current()); 192 DCHECK_EQ(v4l2_thread_.message_loop(), MessageLoop::current());
193 193
194 observer_ = observer; 194 observer_ = observer;
195 observer_->OnDeviceState(true);
195 196
196 if ((device_fd_ = open(device_name_.unique_id.c_str(), O_RDONLY)) < 0) { 197 if ((device_fd_ = open(device_name_.unique_id.c_str(), O_RDONLY)) < 0) {
197 SetErrorState("Failed to open V4L2 device driver."); 198 SetErrorState("Failed to open V4L2 device driver.");
198 return; 199 return;
199 } 200 }
200 201
201 // Test if this is a V4L2 device. 202 // Test if this is a V4L2 device.
202 v4l2_capability cap; 203 v4l2_capability cap;
203 if (!((ioctl(device_fd_, VIDIOC_QUERYCAP, &cap) == 0) && 204 if (!((ioctl(device_fd_, VIDIOC_QUERYCAP, &cap) == 0) &&
204 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))) { 205 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 r_buffer.memory = V4L2_MEMORY_MMAP; 436 r_buffer.memory = V4L2_MEMORY_MMAP;
436 r_buffer.count = 0; 437 r_buffer.count = 0;
437 438
438 if (ioctl(device_fd_, VIDIOC_REQBUFS, &r_buffer) < 0) { 439 if (ioctl(device_fd_, VIDIOC_REQBUFS, &r_buffer) < 0) {
439 SetErrorState("Failed to reset buf."); 440 SetErrorState("Failed to reset buf.");
440 } 441 }
441 442
442 delete [] buffer_pool_; 443 delete [] buffer_pool_;
443 buffer_pool_ = NULL; 444 buffer_pool_ = NULL;
444 buffer_pool_size_ = 0; 445 buffer_pool_size_ = 0;
446 observer_->OnDeviceState(false);
445 } 447 }
446 448
447 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { 449 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) {
448 DLOG(ERROR) << reason; 450 DLOG(ERROR) << reason;
449 state_ = kError; 451 state_ = kError;
450 observer_->OnError(); 452 observer_->OnError();
451 } 453 }
452 454
453 } // namespace media 455 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698