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_video_device.h" | 9 #include "content/common/gpu/media/generic_v4l2_video_device.h" |
10 #if defined(ARCH_CPU_ARMEL) | 10 #if defined(ARCH_CPU_ARMEL) |
11 #include "content/common/gpu/media/tegra_v4l2_video_device.h" | 11 #include "content/common/gpu/media/tegra_v4l2_video_device.h" |
12 #endif | 12 #endif |
13 | 13 |
14 // TODO(posciak): remove this once V4L2 headers are updated. | 14 // TODO(posciak): remove this once V4L2 headers are updated. |
15 #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') | 15 #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') |
16 #define V4L2_PIX_FMT_H264_SLICE v4l2_fourcc('S', '2', '6', '4') | |
17 #define V4L2_PIX_FMT_VP8_FRAME v4l2_fourcc('V', 'P', '8', 'F') | |
18 | 16 |
19 namespace content { | 17 namespace content { |
20 | 18 |
21 V4L2Device::~V4L2Device() { | 19 V4L2Device::~V4L2Device() {} |
| 20 |
| 21 // static |
| 22 scoped_ptr<V4L2Device> V4L2Device::Create(Type type) { |
| 23 DVLOG(3) << __PRETTY_FUNCTION__; |
| 24 |
| 25 scoped_ptr<GenericV4L2Device> generic_device(new GenericV4L2Device(type)); |
| 26 if (generic_device->Initialize()) |
| 27 return generic_device.Pass(); |
| 28 |
| 29 #if defined(ARCH_CPU_ARMEL) |
| 30 scoped_ptr<TegraV4L2Device> tegra_device(new TegraV4L2Device(type)); |
| 31 if (tegra_device->Initialize()) |
| 32 return tegra_device.Pass(); |
| 33 #endif |
| 34 |
| 35 LOG(ERROR) << "Failed to create V4L2Device"; |
| 36 return scoped_ptr<V4L2Device>(); |
22 } | 37 } |
23 | 38 |
24 // static | 39 // static |
25 scoped_refptr<V4L2Device> V4L2Device::Create(Type type) { | |
26 DVLOG(3) << __PRETTY_FUNCTION__; | |
27 | |
28 scoped_refptr<GenericV4L2Device> generic_device(new GenericV4L2Device(type)); | |
29 if (generic_device->Initialize()) | |
30 return generic_device; | |
31 | |
32 #if defined(ARCH_CPU_ARMEL) | |
33 scoped_refptr<TegraV4L2Device> tegra_device(new TegraV4L2Device(type)); | |
34 if (tegra_device->Initialize()) | |
35 return tegra_device; | |
36 #endif | |
37 | |
38 LOG(ERROR) << "Failed to create V4L2Device"; | |
39 return scoped_refptr<V4L2Device>(); | |
40 } | |
41 | |
42 // static | |
43 media::VideoFrame::Format V4L2Device::V4L2PixFmtToVideoFrameFormat( | 40 media::VideoFrame::Format V4L2Device::V4L2PixFmtToVideoFrameFormat( |
44 uint32 pix_fmt) { | 41 uint32 pix_fmt) { |
45 switch (pix_fmt) { | 42 switch (pix_fmt) { |
46 case V4L2_PIX_FMT_NV12: | 43 case V4L2_PIX_FMT_NV12: |
47 case V4L2_PIX_FMT_NV12M: | 44 case V4L2_PIX_FMT_NV12M: |
48 return media::VideoFrame::NV12; | 45 return media::VideoFrame::NV12; |
49 | 46 |
50 case V4L2_PIX_FMT_YUV420: | 47 case V4L2_PIX_FMT_YUV420: |
51 case V4L2_PIX_FMT_YUV420M: | 48 case V4L2_PIX_FMT_YUV420M: |
52 return media::VideoFrame::I420; | 49 return media::VideoFrame::I420; |
(...skipping 18 matching lines...) Expand all Loading... |
71 return V4L2_PIX_FMT_YUV420M; | 68 return V4L2_PIX_FMT_YUV420M; |
72 | 69 |
73 default: | 70 default: |
74 LOG(FATAL) << "Add more cases as needed"; | 71 LOG(FATAL) << "Add more cases as needed"; |
75 return 0; | 72 return 0; |
76 } | 73 } |
77 } | 74 } |
78 | 75 |
79 // static | 76 // static |
80 uint32 V4L2Device::VideoCodecProfileToV4L2PixFmt( | 77 uint32 V4L2Device::VideoCodecProfileToV4L2PixFmt( |
81 media::VideoCodecProfile profile, | 78 media::VideoCodecProfile profile) { |
82 bool slice_based) { | |
83 if (profile >= media::H264PROFILE_MIN && | 79 if (profile >= media::H264PROFILE_MIN && |
84 profile <= media::H264PROFILE_MAX) { | 80 profile <= media::H264PROFILE_MAX) { |
85 if (slice_based) | 81 return V4L2_PIX_FMT_H264; |
86 return V4L2_PIX_FMT_H264_SLICE; | |
87 else | |
88 return V4L2_PIX_FMT_H264; | |
89 } else if (profile >= media::VP8PROFILE_MIN && | 82 } else if (profile >= media::VP8PROFILE_MIN && |
90 profile <= media::VP8PROFILE_MAX) { | 83 profile <= media::VP8PROFILE_MAX) { |
91 if (slice_based) | 84 return V4L2_PIX_FMT_VP8; |
92 return V4L2_PIX_FMT_VP8_FRAME; | |
93 else | |
94 return V4L2_PIX_FMT_VP8; | |
95 } else if (profile >= media::VP9PROFILE_MIN && | 85 } else if (profile >= media::VP9PROFILE_MIN && |
96 profile <= media::VP9PROFILE_MAX) { | 86 profile <= media::VP9PROFILE_MAX) { |
97 return V4L2_PIX_FMT_VP9; | 87 return V4L2_PIX_FMT_VP9; |
98 } else { | 88 } else { |
99 LOG(FATAL) << "Add more cases as needed"; | 89 LOG(FATAL) << "Add more cases as needed"; |
100 return 0; | 90 return 0; |
101 } | 91 } |
102 } | 92 } |
103 | 93 |
104 // static | 94 // static |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Sanity checks. Calculated coded size has to contain given visible size | 186 // Sanity checks. Calculated coded size has to contain given visible size |
197 // and fulfill buffer byte size requirements. | 187 // and fulfill buffer byte size requirements. |
198 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); | 188 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); |
199 DCHECK_LE(sizeimage, | 189 DCHECK_LE(sizeimage, |
200 media::VideoFrame::AllocationSize(frame_format, coded_size)); | 190 media::VideoFrame::AllocationSize(frame_format, coded_size)); |
201 | 191 |
202 return coded_size; | 192 return coded_size; |
203 } | 193 } |
204 | 194 |
205 } // namespace content | 195 } // namespace content |
OLD | NEW |