Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); | |
|
perkj_chrome
2011/10/17 08:39:43
What is the purpose of this? Is it possible to avo
wjia(left Chromium)
2011/10/21 00:56:13
I am trying to handle the case where observer_ (i.
perkj_chrome
2011/10/21 14:54:00
We had previously solved this in another way.
Also
wjia(left Chromium)
2011/10/21 23:54:16
Could you clarify it's VideoCapture::StopCapture o
| |
| 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 Loading... | |
| 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 |
| OLD | NEW |