Chromium Code Reviews| Index: media/gpu/v4l2_image_processor.cc |
| diff --git a/media/gpu/v4l2_image_processor.cc b/media/gpu/v4l2_image_processor.cc |
| index c169255b101795713deb5b6f13a54b8bd0a06f26..3c9e9efd432050f81914d178c3a9187b00baca1b 100644 |
| --- a/media/gpu/v4l2_image_processor.cc |
| +++ b/media/gpu/v4l2_image_processor.cc |
| @@ -57,6 +57,7 @@ V4L2ImageProcessor::V4L2ImageProcessor(const scoped_refptr<V4L2Device>& device) |
| : input_format_(PIXEL_FORMAT_UNKNOWN), |
| output_format_(PIXEL_FORMAT_UNKNOWN), |
| input_memory_type_(V4L2_MEMORY_USERPTR), |
| + output_memory_type_(V4L2_MEMORY_MMAP), |
| input_format_fourcc_(0), |
| output_format_fourcc_(0), |
| input_planes_count_(0), |
| @@ -100,6 +101,7 @@ void V4L2ImageProcessor::NotifyErrorOnChildThread( |
| bool V4L2ImageProcessor::Initialize(VideoPixelFormat input_format, |
| VideoPixelFormat output_format, |
| v4l2_memory input_memory_type, |
| + v4l2_memory output_memory_type, |
| gfx::Size input_visible_size, |
| gfx::Size input_allocated_size, |
| gfx::Size output_visible_size, |
| @@ -110,6 +112,8 @@ bool V4L2ImageProcessor::Initialize(VideoPixelFormat input_format, |
| DCHECK_GT(num_buffers, 0); |
| DCHECK(input_memory_type == V4L2_MEMORY_USERPTR || |
| input_memory_type == V4L2_MEMORY_DMABUF); |
| + DCHECK(output_memory_type == V4L2_MEMORY_MMAP || |
| + output_memory_type == V4L2_MEMORY_DMABUF); |
| error_cb_ = error_cb; |
| input_format_ = input_format; |
| @@ -125,6 +129,7 @@ bool V4L2ImageProcessor::Initialize(VideoPixelFormat input_format, |
| } |
| input_memory_type_ = input_memory_type; |
| + output_memory_type_ = output_memory_type; |
| input_visible_size_ = input_visible_size; |
| input_allocated_size_ = input_allocated_size; |
| output_visible_size_ = output_visible_size; |
| @@ -220,12 +225,19 @@ bool V4L2ImageProcessor::TryOutputFormat(uint32_t pixelformat, |
| void V4L2ImageProcessor::Process(const scoped_refptr<VideoFrame>& frame, |
| int output_buffer_index, |
| + std::vector<base::ScopedFD> output_dmabuf_fds, |
| const FrameReadyCB& cb) { |
| DVLOG(3) << __func__ << ": ts=" << frame->timestamp().InMilliseconds(); |
| + if (output_memory_type_ == V4L2_MEMORY_DMABUF) { |
| + DCHECK_EQ(output_planes_count_, output_dmabuf_fds.size()); |
|
Pawel Osciak
2016/09/14 04:17:29
Sorry, I meant an if instead of DCHECK. The doc re
wuchengli
2016/09/14 05:17:27
I see. I added a boolean return value to indicate
|
| + } else { |
| + DCHECK_EQ(0u, output_dmabuf_fds.size()); |
| + } |
| std::unique_ptr<JobRecord> job_record(new JobRecord()); |
| job_record->frame = frame; |
| job_record->output_buffer_index = output_buffer_index; |
| + job_record->output_dmabuf_fds = std::move(output_dmabuf_fds); |
| job_record->ready_cb = cb; |
| device_thread_.task_runner()->PostTask( |
| @@ -237,6 +249,8 @@ void V4L2ImageProcessor::ProcessTask(std::unique_ptr<JobRecord> job_record) { |
| int index = job_record->output_buffer_index; |
| DVLOG(3) << __func__ << ": Reusing output buffer, index=" << index; |
| DCHECK(device_thread_.task_runner()->BelongsToCurrentThread()); |
| + output_buffer_map_[index].dmabuf_fds = |
| + std::move(job_record->output_dmabuf_fds); |
| EnqueueOutput(index); |
| input_queue_.push(make_linked_ptr(job_record.release())); |
| @@ -375,7 +389,7 @@ bool V4L2ImageProcessor::CreateOutputBuffers() { |
| memset(&reqbufs, 0, sizeof(reqbufs)); |
| reqbufs.count = num_buffers_; |
| reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| - reqbufs.memory = V4L2_MEMORY_MMAP; |
| + reqbufs.memory = output_memory_type_; |
| IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_REQBUFS, &reqbufs); |
| if (static_cast<int>(reqbufs.count) != num_buffers_) { |
| LOG(ERROR) << "Failed to allocate output buffers. reqbufs.count=" |
| @@ -412,7 +426,7 @@ void V4L2ImageProcessor::DestroyOutputBuffers() { |
| memset(&reqbufs, 0, sizeof(reqbufs)); |
| reqbufs.count = 0; |
| reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| - reqbufs.memory = V4L2_MEMORY_MMAP; |
| + reqbufs.memory = output_memory_type_; |
| IOCTL_OR_LOG_ERROR(VIDIOC_REQBUFS, &reqbufs); |
| output_buffer_map_.clear(); |
| @@ -547,7 +561,7 @@ void V4L2ImageProcessor::Dequeue() { |
| memset(&dqbuf, 0, sizeof(dqbuf)); |
| memset(&planes, 0, sizeof(planes)); |
| dqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| - dqbuf.memory = V4L2_MEMORY_MMAP; |
| + dqbuf.memory = output_memory_type_; |
| dqbuf.m.planes = planes; |
| dqbuf.length = output_planes_count_; |
| if (device_->Ioctl(VIDIOC_DQBUF, &dqbuf) != 0) { |
| @@ -562,6 +576,7 @@ void V4L2ImageProcessor::Dequeue() { |
| OutputRecord& output_record = output_buffer_map_[dqbuf.index]; |
| DCHECK(output_record.at_device); |
| output_record.at_device = false; |
| + output_record.dmabuf_fds.clear(); |
| output_buffer_queued_count_--; |
| // Jobs are always processed in FIFO order. |
| @@ -634,7 +649,11 @@ bool V4L2ImageProcessor::EnqueueOutputRecord(int index) { |
| memset(qbuf_planes, 0, sizeof(qbuf_planes)); |
| qbuf.index = index; |
| qbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| - qbuf.memory = V4L2_MEMORY_MMAP; |
| + qbuf.memory = output_memory_type_; |
| + if (output_memory_type_ == V4L2_MEMORY_DMABUF) { |
| + for (size_t i = 0; i < output_record.dmabuf_fds.size(); ++i) |
| + qbuf_planes[i].m.fd = output_record.dmabuf_fds[i].get(); |
| + } |
| qbuf.m.planes = qbuf_planes; |
| qbuf.length = output_planes_count_; |
| IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_QBUF, &qbuf); |