OLD | NEW |
---|---|
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 Loading... | |
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(V4L2Device::Type::kImageProcessor, input_format_fourcc_)) { | |
139 LOG(ERROR) << "Failed to open device for input format: " | |
140 << VideoPixelFormatToString(input_format) | |
141 << " fourcc: " << std::hex << input_format_fourcc_; | |
kcwu
2016/10/07 11:19:05
0x
Pawel Osciak
2016/10/11 06:13:46
Done.
| |
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 Loading... | |
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 |
184 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedInputFormats() { | 191 // static |
185 std::vector<uint32_t> input_formats; | 192 bool V4L2ImageProcessor::IsSupported() { |
186 v4l2_fmtdesc fmtdesc; | 193 scoped_refptr<V4L2Device> device = V4L2Device::Create(); |
187 memset(&fmtdesc, 0, sizeof(fmtdesc)); | 194 if (!device) |
188 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 195 return false; |
189 for (; device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { | 196 |
190 input_formats.push_back(fmtdesc.pixelformat); | 197 return device->IsImageProcessingSupported(); |
191 } | |
192 return input_formats; | |
193 } | 198 } |
194 | 199 |
195 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedOutputFormats() { | 200 // static |
196 std::vector<uint32_t> output_formats; | 201 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedInputFormats() { |
197 v4l2_fmtdesc fmtdesc; | 202 scoped_refptr<V4L2Device> device = V4L2Device::Create(); |
198 memset(&fmtdesc, 0, sizeof(fmtdesc)); | 203 if (!device) |
199 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 204 return std::vector<uint32_t>(); |
200 for (; device_->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { | 205 |
201 output_formats.push_back(fmtdesc.pixelformat); | 206 return device->GetSupportedImageProcessorPixelformats( |
202 } | 207 V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); |
203 return output_formats; | |
204 } | 208 } |
205 | 209 |
206 bool V4L2ImageProcessor::TryOutputFormat(uint32_t pixelformat, | 210 // static |
211 std::vector<uint32_t> V4L2ImageProcessor::GetSupportedOutputFormats() { | |
212 scoped_refptr<V4L2Device> device = V4L2Device::Create(); | |
213 if (!device) | |
214 return std::vector<uint32_t>(); | |
215 | |
216 return device->GetSupportedImageProcessorPixelformats( | |
217 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); | |
218 } | |
219 | |
220 // static | |
221 bool V4L2ImageProcessor::TryOutputFormat(uint32_t input_pixelformat, | |
222 uint32_t output_pixelformat, | |
207 gfx::Size* size, | 223 gfx::Size* size, |
208 size_t* num_planes) { | 224 size_t* num_planes) { |
209 DVLOG(1) << __func__ << ": size=" << size->ToString(); | 225 DVLOG(1) << __func__ << ": size=" << size->ToString(); |
226 scoped_refptr<V4L2Device> device = V4L2Device::Create(); | |
227 if (!device || | |
228 !device->Open(V4L2Device::Type::kImageProcessor, input_pixelformat)) | |
229 return false; | |
230 | |
210 struct v4l2_format format; | 231 struct v4l2_format format; |
211 memset(&format, 0, sizeof(format)); | 232 memset(&format, 0, sizeof(format)); |
212 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | 233 format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
213 format.fmt.pix_mp.width = size->width(); | 234 format.fmt.pix_mp.width = size->width(); |
214 format.fmt.pix_mp.height = size->height(); | 235 format.fmt.pix_mp.height = size->height(); |
215 format.fmt.pix_mp.pixelformat = pixelformat; | 236 format.fmt.pix_mp.pixelformat = output_pixelformat; |
216 IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_TRY_FMT, &format); | 237 if (device->Ioctl(VIDIOC_TRY_FMT, &format) != 0) |
238 return false; | |
217 | 239 |
218 *num_planes = format.fmt.pix_mp.num_planes; | 240 *num_planes = format.fmt.pix_mp.num_planes; |
219 *size = V4L2Device::CodedSizeFromV4L2Format(format); | 241 *size = V4L2Device::CodedSizeFromV4L2Format(format); |
220 DVLOG(1) << __func__ << ": adjusted output coded size=" << size->ToString() | 242 DVLOG(1) << __func__ << ": adjusted output coded size=" << size->ToString() |
221 << ", num_planes=" << *num_planes; | 243 << ", num_planes=" << *num_planes; |
222 return true; | 244 return true; |
223 } | 245 } |
224 | 246 |
225 bool V4L2ImageProcessor::Process(const scoped_refptr<VideoFrame>& frame, | 247 bool V4L2ImageProcessor::Process(const scoped_refptr<VideoFrame>& frame, |
226 int output_buffer_index, | 248 int output_buffer_index, |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 output_buffer_queued_count_ = 0; | 777 output_buffer_queued_count_ = 0; |
756 } | 778 } |
757 | 779 |
758 void V4L2ImageProcessor::FrameReady(const FrameReadyCB& cb, | 780 void V4L2ImageProcessor::FrameReady(const FrameReadyCB& cb, |
759 int output_buffer_index) { | 781 int output_buffer_index) { |
760 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 782 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
761 cb.Run(output_buffer_index); | 783 cb.Run(output_buffer_index); |
762 } | 784 } |
763 | 785 |
764 } // namespace media | 786 } // namespace media |
OLD | NEW |