Chromium Code Reviews| 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 std::vector<uint32_t>& pixelformats) { | |
| 234 CHECK_EQ(type_, kDecoder); | |
|
wuchengli
2015/04/24 02:45:40
s/CHECK/DCHECK/. We should not crash the entire GP
| |
| 235 media::VideoDecodeAccelerator::SupportedProfiles profiles; | |
| 236 media::VideoDecodeAccelerator::SupportedProfile profile; | |
| 237 profile.min_resolution.SetSize(16, 16); | |
| 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.begin(), pixelformats.end(), | |
| 244 fmtdesc.pixelformat) == pixelformats.end()) | |
| 245 continue; | |
| 246 profile.max_resolution = GetMaxSupportedResolution(fmtdesc.pixelformat); | |
| 247 switch (fmtdesc.pixelformat) { | |
| 248 case V4L2_PIX_FMT_H264: | |
| 249 case V4L2_PIX_FMT_H264_SLICE: | |
| 250 for (uint32 media_profile = media::H264PROFILE_MIN; | |
| 251 media_profile <= media::H264PROFILE_MAX; ++media_profile) { | |
| 252 profile.profile = | |
| 253 static_cast<media::VideoCodecProfile>(media_profile); | |
| 254 profiles.push_back(profile); | |
| 255 } | |
| 256 break; | |
| 257 case V4L2_PIX_FMT_VP8: | |
| 258 case V4L2_PIX_FMT_VP8_FRAME: | |
| 259 profile.profile = media::VP8PROFILE_ANY; | |
| 260 profiles.push_back(profile); | |
| 261 break; | |
| 262 case V4L2_PIX_FMT_VP9: | |
| 263 profile.profile = media::VP9PROFILE_ANY; | |
| 264 profiles.push_back(profile); | |
| 265 break; | |
| 266 } | |
| 267 } | |
| 268 return profiles; | |
| 269 } | |
| 270 | |
| 200 } // namespace content | 271 } // namespace content |
| OLD | NEW |