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) |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 190 |
191 // Sanity checks. Calculated coded size has to contain given visible size | 191 // Sanity checks. Calculated coded size has to contain given visible size |
192 // and fulfill buffer byte size requirements. | 192 // and fulfill buffer byte size requirements. |
193 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); | 193 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); |
194 DCHECK_LE(sizeimage, | 194 DCHECK_LE(sizeimage, |
195 media::VideoFrame::AllocationSize(frame_format, coded_size)); | 195 media::VideoFrame::AllocationSize(frame_format, coded_size)); |
196 | 196 |
197 return coded_size; | 197 return coded_size; |
198 } | 198 } |
199 | 199 |
200 gfx::Size V4L2Device::GetMaxSupportedResolution(uint32_t pixelformat) { | |
201 gfx::Size max_resolution; | |
202 v4l2_frmsizeenum frame_size; | |
203 memset(&frame_size, 0, sizeof(frame_size)); | |
204 frame_size.pixel_format = pixelformat; | |
205 for (; Ioctl(VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0; ++frame_size.index) { | |
206 if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE && | |
207 frame_size.discrete.width >= | |
208 base::checked_cast<uint32_t>(max_resolution.width()) && | |
209 frame_size.discrete.height >= | |
210 base::checked_cast<uint32_t>(max_resolution.height())) { | |
211 max_resolution.SetSize(frame_size.discrete.width, | |
212 frame_size.discrete.height); | |
213 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE || | |
214 frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) { | |
215 max_resolution.SetSize(frame_size.stepwise.max_width, | |
216 frame_size.stepwise.max_height); | |
217 break; | |
218 } | |
219 } | |
220 if (max_resolution.IsEmpty()) { | |
221 LOG(ERROR) << "GetMaxSupportedResolution failed for fourcc " << std::hex | |
222 << pixelformat << ", fall back to 1088p"; | |
wuchengli
2015/04/23 07:11:44
1088p is not a common usage. To avoid confusion, s
henryhsu
2015/04/23 08:21:54
Done.
| |
223 max_resolution.SetSize(1920, 1088); | |
224 } | |
225 return max_resolution; | |
226 } | |
227 | |
228 media::VideoDecodeAccelerator::SupportedProfiles | |
229 V4L2Device::GetSupportedDecodeProfiles(std::vector<uint32_t> fourcc_formats) { | |
wuchengli
2015/04/23 07:11:44
Let's move "const Type type_;" from GenericV4L2Dev
henryhsu
2015/04/23 08:21:53
Done.
| |
230 media::VideoDecodeAccelerator::SupportedProfiles profiles; | |
231 media::VideoDecodeAccelerator::SupportedProfile profile; | |
232 profile.min_resolution.SetSize(16, 16); | |
233 v4l2_fmtdesc fmtdesc; | |
234 memset(&fmtdesc, 0, sizeof(fmtdesc)); | |
235 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
236 | |
237 for (; Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { | |
238 if (std::find(fourcc_formats.begin(), fourcc_formats.end(), | |
239 fmtdesc.pixelformat) == fourcc_formats.end()) | |
240 continue; | |
241 profile.max_resolution = GetMaxSupportedResolution(fmtdesc.pixelformat); | |
242 switch (fmtdesc.pixelformat) { | |
243 case V4L2_PIX_FMT_H264: | |
244 case V4L2_PIX_FMT_H264_SLICE: | |
245 for (uint32 media_profile = media::H264PROFILE_MIN; | |
246 media_profile <= media::H264PROFILE_MAX; ++media_profile) { | |
247 profile.profile = | |
248 static_cast<media::VideoCodecProfile>(media_profile); | |
249 profiles.push_back(profile); | |
250 } | |
251 break; | |
252 case V4L2_PIX_FMT_VP8: | |
253 case V4L2_PIX_FMT_VP8_FRAME: | |
254 profile.profile = media::VP8PROFILE_ANY; | |
255 profiles.push_back(profile); | |
256 break; | |
257 case V4L2_PIX_FMT_VP9: | |
258 profile.profile = media::VP9PROFILE_ANY; | |
259 profiles.push_back(profile); | |
260 break; | |
261 } | |
262 } | |
263 return profiles; | |
264 } | |
265 | |
200 } // namespace content | 266 } // namespace content |
OLD | NEW |