OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/v4l2_capture_delegate.h" | 5 #include "media/video/capture/linux/v4l2_capture_delegate.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 #include <sys/fcntl.h> | 8 #include <sys/fcntl.h> |
9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 const int result = munmap(plane.start, plane.length); | 134 const int result = munmap(plane.start, plane.length); |
135 PLOG_IF(ERROR, result < 0) << "Error munmap()ing V4L2 buffer"; | 135 PLOG_IF(ERROR, result < 0) << "Error munmap()ing V4L2 buffer"; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void V4L2CaptureDelegate::BufferTracker::AddMmapedPlane(uint8_t* const start, | 139 void V4L2CaptureDelegate::BufferTracker::AddMmapedPlane(uint8_t* const start, |
140 size_t length) { | 140 size_t length) { |
141 Plane plane; | 141 Plane plane; |
142 plane.start = start; | 142 plane.start = start; |
143 plane.length = length; | 143 plane.length = length; |
| 144 plane.payload_size = 0; |
144 planes_.push_back(plane); | 145 planes_.push_back(plane); |
145 } | 146 } |
146 | 147 |
147 V4L2CaptureDelegate::V4L2CaptureDelegate( | 148 V4L2CaptureDelegate::V4L2CaptureDelegate( |
148 const VideoCaptureDevice::Name& device_name, | 149 const VideoCaptureDevice::Name& device_name, |
149 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | 150 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
150 int power_line_frequency) | 151 int power_line_frequency) |
151 : capture_type_((device_name.capture_api_type() == | 152 : capture_type_((device_name.capture_api_type() == |
152 VideoCaptureDevice::Name::V4L2_SINGLE_PLANE) | 153 VideoCaptureDevice::Name::V4L2_SINGLE_PLANE) |
153 ? V4L2_BUF_TYPE_VIDEO_CAPTURE | 154 ? V4L2_BUF_TYPE_VIDEO_CAPTURE |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // Deenqueue, send and reenqueue a buffer if the driver has filled one in. | 393 // Deenqueue, send and reenqueue a buffer if the driver has filled one in. |
393 if (device_pfd.revents & POLLIN) { | 394 if (device_pfd.revents & POLLIN) { |
394 v4l2_buffer buffer; | 395 v4l2_buffer buffer; |
395 FillV4L2Buffer(&buffer, 0); | 396 FillV4L2Buffer(&buffer, 0); |
396 | 397 |
397 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_DQBUF, &buffer)) < 0) { | 398 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_DQBUF, &buffer)) < 0) { |
398 SetErrorState("Failed to dequeue capture buffer"); | 399 SetErrorState("Failed to dequeue capture buffer"); |
399 return; | 400 return; |
400 } | 401 } |
401 | 402 |
| 403 SetPayloadSize(buffer_tracker_pool_[buffer.index], buffer); |
402 SendBuffer(buffer_tracker_pool_[buffer.index], video_fmt_); | 404 SendBuffer(buffer_tracker_pool_[buffer.index], video_fmt_); |
403 | 405 |
404 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QBUF, &buffer)) < 0) { | 406 if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QBUF, &buffer)) < 0) { |
405 SetErrorState("Failed to enqueue capture buffer"); | 407 SetErrorState("Failed to enqueue capture buffer"); |
406 return; | 408 return; |
407 } | 409 } |
408 } | 410 } |
409 | 411 |
410 v4l2_task_runner_->PostTask( | 412 v4l2_task_runner_->PostTask( |
411 FROM_HERE, base::Bind(&V4L2CaptureDelegate::DoCapture, this)); | 413 FROM_HERE, base::Bind(&V4L2CaptureDelegate::DoCapture, this)); |
412 } | 414 } |
413 | 415 |
414 void V4L2CaptureDelegate::SetErrorState(const std::string& reason) { | 416 void V4L2CaptureDelegate::SetErrorState(const std::string& reason) { |
415 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); | 417 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); |
416 is_capturing_ = false; | 418 is_capturing_ = false; |
417 client_->OnError(reason); | 419 client_->OnError(reason); |
418 } | 420 } |
419 | 421 |
420 } // namespace media | 422 } // namespace media |
OLD | NEW |