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

Side by Side Diff: media/gpu/v4l2_image_processor.cc

Issue 2398883002: Add support for multiple V4L2 video devices of the same type. (Closed)
Patch Set: Fixes for image processor. Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <linux/videodev2.h> 7 #include <linux/videodev2.h>
8 #include <poll.h> 8 #include <poll.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/eventfd.h> 10 #include <sys/eventfd.h>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return false; 128 return false;
129 } 129 }
130 130
131 input_memory_type_ = input_memory_type; 131 input_memory_type_ = input_memory_type;
132 output_memory_type_ = output_memory_type; 132 output_memory_type_ = output_memory_type;
133 input_visible_size_ = input_visible_size; 133 input_visible_size_ = input_visible_size;
134 input_allocated_size_ = input_allocated_size; 134 input_allocated_size_ = input_allocated_size;
135 output_visible_size_ = output_visible_size; 135 output_visible_size_ = output_visible_size;
136 output_allocated_size_ = output_allocated_size; 136 output_allocated_size_ = output_allocated_size;
137 137
138 if (!device_->Open(input_format_fourcc_)) {
139 LOG(ERROR) << "Failed to open device for input format: "
140 << VideoPixelFormatToString(input_format)
141 << " fourcc: " << std::hex << input_format_fourcc_;
142 return false;
143 }
144
138 // Capabilities check. 145 // Capabilities check.
139 struct v4l2_capability caps; 146 struct v4l2_capability caps;
140 memset(&caps, 0, sizeof(caps)); 147 memset(&caps, 0, sizeof(caps));
141 const __u32 kCapsRequired = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING; 148 const __u32 kCapsRequired = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING;
142 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_QUERYCAP, &caps); 149 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_QUERYCAP, &caps);
143 if ((caps.capabilities & kCapsRequired) != kCapsRequired) { 150 if ((caps.capabilities & kCapsRequired) != kCapsRequired) {
144 LOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP: " 151 LOG(ERROR) << "Initialize(): ioctl() failed: VIDIOC_QUERYCAP: "
145 << "caps check failed: 0x" << std::hex << caps.capabilities; 152 << "caps check failed: 0x" << std::hex << caps.capabilities;
146 return false; 153 return false;
147 } 154 }
(...skipping 26 matching lines...) Expand all
174 181
175 std::vector<base::ScopedFD> V4L2ImageProcessor::GetDmabufsForOutputBuffer( 182 std::vector<base::ScopedFD> V4L2ImageProcessor::GetDmabufsForOutputBuffer(
176 int output_buffer_index) { 183 int output_buffer_index) {
177 DCHECK_GE(output_buffer_index, 0); 184 DCHECK_GE(output_buffer_index, 0);
178 DCHECK_LT(output_buffer_index, num_buffers_); 185 DCHECK_LT(output_buffer_index, num_buffers_);
179 return device_->GetDmabufsForV4L2Buffer(output_buffer_index, 186 return device_->GetDmabufsForV4L2Buffer(output_buffer_index,
180 output_planes_count_, 187 output_planes_count_,
181 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); 188 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
182 } 189 }
183 190
191 // static
184 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedInputFormats() { 192 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedInputFormats() {
185 std::vector<uint32_t> input_formats; 193 scoped_refptr<V4L2Device> device =
186 v4l2_fmtdesc fmtdesc; 194 V4L2Device::Create(V4L2Device::Type::kImageProcessor);
187 memset(&fmtdesc, 0, sizeof(fmtdesc)); 195 if (!device)
188 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 196 return std::vector<uint32_t>();
189 for (; device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { 197
190 input_formats.push_back(fmtdesc.pixelformat); 198 return device->GetSupportedImageProcessorPixelformats(
191 } 199 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
192 return input_formats;
193 } 200 }
194 201
202 // static
195 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedOutputFormats() { 203 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedOutputFormats() {
196 std::vector<uint32_t> output_formats; 204 scoped_refptr<V4L2Device> device =
197 v4l2_fmtdesc fmtdesc; 205 V4L2Device::Create(V4L2Device::Type::kImageProcessor);
198 memset(&fmtdesc, 0, sizeof(fmtdesc)); 206 if (!device)
199 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 207 return std::vector<uint32_t>();
200 for (; device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { 208
201 output_formats.push_back(fmtdesc.pixelformat); 209 return device->GetSupportedImageProcessorPixelformats(
202 } 210 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
203 return output_formats;
204 } 211 }
205 212
206 bool V4L2ImageProcessor::TryOutputFormat(uint32_t pixelformat, 213 // static
214 bool V4L2ImageProcessor::TryOutputFormat(uint32_t input_pixelformat,
215 uint32_t output_pixelformat,
207 gfx::Size* size, 216 gfx::Size* size,
208 size_t* num_planes) { 217 size_t* num_planes) {
209 DVLOG(1) << __func__ << ": size=" << size->ToString(); 218 DVLOG(1) << __func__ << ": size=" << size->ToString();
219 scoped_refptr<V4L2Device> device =
220 V4L2Device::Create(V4L2Device::Type::kImageProcessor);
221 if (!device)
222 return false;
223
224 if (!device->Open(input_pixelformat))
225 return false;
226
210 struct v4l2_format format; 227 struct v4l2_format format;
211 memset(&format, 0, sizeof(format)); 228 memset(&format, 0, sizeof(format));
212 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 229 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
213 format.fmt.pix_mp.width = size->width(); 230 format.fmt.pix_mp.width = size->width();
214 format.fmt.pix_mp.height = size->height(); 231 format.fmt.pix_mp.height = size->height();
215 format.fmt.pix_mp.pixelformat = pixelformat; 232 format.fmt.pix_mp.pixelformat = output_pixelformat;
216 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_TRY_FMT, &format); 233 if (device->Ioctl(VIDIOC_TRY_FMT, &format) != 0)
234 return false;
217 235
218 *num_planes = format.fmt.pix_mp.num_planes; 236 *num_planes = format.fmt.pix_mp.num_planes;
219 *size = V4L2Device::CodedSizeFromV4L2Format(format); 237 *size = V4L2Device::CodedSizeFromV4L2Format(format);
220 DVLOG(1) << __func__ << ": adjusted output coded size=" << size->ToString() 238 DVLOG(1) << __func__ << ": adjusted output coded size=" << size->ToString()
221 << ", num_planes=" << *num_planes; 239 << ", num_planes=" << *num_planes;
222 return true; 240 return true;
223 } 241 }
224 242
225 bool V4L2ImageProcessor::Process(const scoped_refptr<VideoFrame>& frame, 243 bool V4L2ImageProcessor::Process(const scoped_refptr<VideoFrame>& frame,
226 int output_buffer_index, 244 int output_buffer_index,
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 output_buffer_queued_count_ = 0; 773 output_buffer_queued_count_ = 0;
756 } 774 }
757 775
758 void V4L2ImageProcessor::FrameReady(const FrameReadyCB& cb, 776 void V4L2ImageProcessor::FrameReady(const FrameReadyCB& cb,
759 int output_buffer_index) { 777 int output_buffer_index) {
760 DCHECK(child_task_runner_->BelongsToCurrentThread()); 778 DCHECK(child_task_runner_->BelongsToCurrentThread());
761 cb.Run(output_buffer_index); 779 cb.Run(output_buffer_index);
762 } 780 }
763 781
764 } // namespace media 782 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698