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 <libdrm/drm_fourcc.h> | 5 #include <libdrm/drm_fourcc.h> |
6 #include <linux/videodev2.h> | 6 #include <linux/videodev2.h> |
7 | 7 |
8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
9 #include "content/common/gpu/media/generic_v4l2_device.h" | 9 #include "content/common/gpu/media/generic_v4l2_device.h" |
10 #if defined(ARCH_CPU_ARMEL) | 10 #if defined(ARCH_CPU_ARMEL) |
11 #include "content/common/gpu/media/tegra_v4l2_device.h" | 11 #include "content/common/gpu/media/tegra_v4l2_device.h" |
12 #endif | 12 #endif |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 V4L2Device::V4L2Device(Type type) : type_(type) { | |
17 } | |
18 | |
16 V4L2Device::~V4L2Device() { | 19 V4L2Device::~V4L2Device() { |
17 } | 20 } |
18 | 21 |
19 // static | 22 // static |
20 scoped_refptr<V4L2Device> V4L2Device::Create(Type type) { | 23 scoped_refptr<V4L2Device> V4L2Device::Create(Type type) { |
21 DVLOG(3) << __PRETTY_FUNCTION__; | 24 DVLOG(3) << __PRETTY_FUNCTION__; |
22 | 25 |
23 scoped_refptr<GenericV4L2Device> generic_device(new GenericV4L2Device(type)); | 26 scoped_refptr<GenericV4L2Device> generic_device(new GenericV4L2Device(type)); |
24 if (generic_device->Initialize()) | 27 if (generic_device->Initialize()) |
25 return generic_device; | 28 return generic_device; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 193 |
191 // Sanity checks. Calculated coded size has to contain given visible size | 194 // Sanity checks. Calculated coded size has to contain given visible size |
192 // and fulfill buffer byte size requirements. | 195 // and fulfill buffer byte size requirements. |
193 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); | 196 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); |
194 DCHECK_LE(sizeimage, | 197 DCHECK_LE(sizeimage, |
195 media::VideoFrame::AllocationSize(frame_format, coded_size)); | 198 media::VideoFrame::AllocationSize(frame_format, coded_size)); |
196 | 199 |
197 return coded_size; | 200 return coded_size; |
198 } | 201 } |
199 | 202 |
203 gfx::Size V4L2Device::GetMaxSupportedResolution(uint32_t pixelformat) { | |
204 gfx::Size max_resolution; | |
205 v4l2_frmsizeenum frame_size; | |
206 memset(&frame_size, 0, sizeof(frame_size)); | |
207 frame_size.pixel_format = pixelformat; | |
208 for (; Ioctl(VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0; ++frame_size.index) { | |
209 if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE && | |
210 frame_size.discrete.width >= | |
211 base::checked_cast<uint32_t>(max_resolution.width()) && | |
212 frame_size.discrete.height >= | |
213 base::checked_cast<uint32_t>(max_resolution.height())) { | |
214 max_resolution.SetSize(frame_size.discrete.width, | |
215 frame_size.discrete.height); | |
216 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE || | |
217 frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) { | |
218 max_resolution.SetSize(frame_size.stepwise.max_width, | |
219 frame_size.stepwise.max_height); | |
220 break; | |
221 } | |
222 } | |
223 if (max_resolution.IsEmpty()) { | |
224 LOG(ERROR) << "GetMaxSupportedResolution failed for fourcc " << std::hex | |
225 << pixelformat << ", fall back to 1920x1088."; | |
226 max_resolution.SetSize(1920, 1088); | |
227 } | |
228 return max_resolution; | |
229 } | |
230 | |
231 media::VideoDecodeAccelerator::SupportedProfiles | |
232 V4L2Device::GetSupportedDecodeProfiles( | |
233 const uint32_t num_formats, const uint32_t pixelformats[]) { | |
234 DCHECK_EQ(type_, kDecoder); | |
235 media::VideoDecodeAccelerator::SupportedProfiles profiles; | |
236 media::VideoDecodeAccelerator::SupportedProfile profile; | |
237 profile.min_resolution.SetSize(16, 16); | |
Pawel Osciak
2015/04/27 05:36:15
Framesize API also supports minimum resolution, th
henryhsu
2015/04/27 07:23:51
Done.
| |
238 v4l2_fmtdesc fmtdesc; | |
239 memset(&fmtdesc, 0, sizeof(fmtdesc)); | |
240 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
241 | |
242 for (; Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { | |
243 if (std::find(pixelformats, pixelformats + num_formats, | |
244 fmtdesc.pixelformat) == pixelformats + num_formats) | |
245 continue; | |
246 profile.max_resolution = GetMaxSupportedResolution(fmtdesc.pixelformat); | |
247 uint32_t min_profile, max_profile; | |
Pawel Osciak
2015/04/27 05:36:15
s/uint32_t/int/
henryhsu
2015/04/27 07:23:51
Done.
| |
248 switch (fmtdesc.pixelformat) { | |
249 case V4L2_PIX_FMT_H264: | |
250 case V4L2_PIX_FMT_H264_SLICE: | |
251 min_profile = media::H264PROFILE_MIN; | |
252 max_profile = media::H264PROFILE_MAX; | |
253 break; | |
254 case V4L2_PIX_FMT_VP8: | |
255 case V4L2_PIX_FMT_VP8_FRAME: | |
256 min_profile = media::VP8PROFILE_MIN; | |
257 max_profile = media::VP8PROFILE_MAX; | |
258 break; | |
259 case V4L2_PIX_FMT_VP9: | |
260 min_profile = media::VP9PROFILE_MIN; | |
261 max_profile = media::VP9PROFILE_MAX; | |
262 break; | |
263 default: | |
264 NOTREACHED() << "Unhandled pixelformat " << std::hex | |
265 << fmtdesc.pixelformat; | |
266 break; | |
Pawel Osciak
2015/04/27 05:36:14
NOTREACHED is not a fatal failure in Release, so y
henryhsu
2015/04/27 07:23:51
Done.
| |
267 } | |
268 for (uint32_t media_profile = min_profile; media_profile <= max_profile; | |
Pawel Osciak
2015/04/27 05:36:14
s/uint32_t/int/
henryhsu
2015/04/27 07:23:51
Done.
| |
269 ++media_profile) { | |
270 profile.profile = | |
271 static_cast<media::VideoCodecProfile>(media_profile); | |
272 profiles.push_back(profile); | |
273 } | |
274 } | |
275 return profiles; | |
276 } | |
277 | |
200 } // namespace content | 278 } // namespace content |
OLD | NEW |