| 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> | |
| 6 #include <linux/videodev2.h> | 5 #include <linux/videodev2.h> |
| 7 | 6 |
| 8 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 9 #include "content/common/gpu/media/generic_v4l2_video_device.h" | 8 #include "content/common/gpu/media/generic_v4l2_video_device.h" |
| 10 #include "content/common/gpu/media/tegra_v4l2_video_device.h" | 9 #include "content/common/gpu/media/tegra_v4l2_video_device.h" |
| 11 | 10 |
| 12 // TODO(posciak): remove this once V4L2 headers are updated. | |
| 13 #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') | |
| 14 | |
| 15 namespace content { | 11 namespace content { |
| 16 | 12 |
| 17 V4L2Device::~V4L2Device() {} | 13 V4L2Device::~V4L2Device() {} |
| 18 | 14 |
| 19 // static | 15 // static |
| 20 scoped_ptr<V4L2Device> V4L2Device::Create(Type type) { | 16 scoped_ptr<V4L2Device> V4L2Device::Create(Type type) { |
| 21 DVLOG(3) << __PRETTY_FUNCTION__; | 17 DVLOG(3) << __PRETTY_FUNCTION__; |
| 22 | 18 |
| 23 scoped_ptr<GenericV4L2Device> generic_device(new GenericV4L2Device(type)); | 19 scoped_ptr<GenericV4L2Device> generic_device(new GenericV4L2Device(type)); |
| 24 if (generic_device->Initialize()) | 20 if (generic_device->Initialize()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 uint32 pix_fmt) { | 33 uint32 pix_fmt) { |
| 38 switch (pix_fmt) { | 34 switch (pix_fmt) { |
| 39 case V4L2_PIX_FMT_NV12: | 35 case V4L2_PIX_FMT_NV12: |
| 40 case V4L2_PIX_FMT_NV12M: | 36 case V4L2_PIX_FMT_NV12M: |
| 41 return media::VideoFrame::NV12; | 37 return media::VideoFrame::NV12; |
| 42 | 38 |
| 43 case V4L2_PIX_FMT_YUV420: | 39 case V4L2_PIX_FMT_YUV420: |
| 44 case V4L2_PIX_FMT_YUV420M: | 40 case V4L2_PIX_FMT_YUV420M: |
| 45 return media::VideoFrame::I420; | 41 return media::VideoFrame::I420; |
| 46 | 42 |
| 47 case V4L2_PIX_FMT_RGB32: | |
| 48 return media::VideoFrame::ARGB; | |
| 49 | |
| 50 default: | 43 default: |
| 51 LOG(FATAL) << "Add more cases as needed"; | 44 LOG(FATAL) << "Add more cases as needed"; |
| 52 return media::VideoFrame::UNKNOWN; | 45 return media::VideoFrame::UNKNOWN; |
| 53 } | 46 } |
| 54 } | 47 } |
| 55 | 48 |
| 56 // static | 49 // static |
| 57 uint32 V4L2Device::VideoFrameFormatToV4L2PixFmt( | 50 uint32 V4L2Device::VideoFrameFormatToV4L2PixFmt( |
| 58 media::VideoFrame::Format format) { | 51 media::VideoFrame::Format format) { |
| 59 switch (format) { | 52 switch (format) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 | 64 |
| 72 // static | 65 // static |
| 73 uint32 V4L2Device::VideoCodecProfileToV4L2PixFmt( | 66 uint32 V4L2Device::VideoCodecProfileToV4L2PixFmt( |
| 74 media::VideoCodecProfile profile) { | 67 media::VideoCodecProfile profile) { |
| 75 if (profile >= media::H264PROFILE_MIN && | 68 if (profile >= media::H264PROFILE_MIN && |
| 76 profile <= media::H264PROFILE_MAX) { | 69 profile <= media::H264PROFILE_MAX) { |
| 77 return V4L2_PIX_FMT_H264; | 70 return V4L2_PIX_FMT_H264; |
| 78 } else if (profile >= media::VP8PROFILE_MIN && | 71 } else if (profile >= media::VP8PROFILE_MIN && |
| 79 profile <= media::VP8PROFILE_MAX) { | 72 profile <= media::VP8PROFILE_MAX) { |
| 80 return V4L2_PIX_FMT_VP8; | 73 return V4L2_PIX_FMT_VP8; |
| 81 } else if (profile >= media::VP9PROFILE_MIN && | |
| 82 profile <= media::VP9PROFILE_MAX) { | |
| 83 return V4L2_PIX_FMT_VP9; | |
| 84 } else { | 74 } else { |
| 85 LOG(FATAL) << "Add more cases as needed"; | 75 LOG(FATAL) << "Add more cases as needed"; |
| 86 return 0; | 76 return 0; |
| 87 } | 77 } |
| 88 } | 78 } |
| 89 | 79 |
| 90 // static | 80 // static |
| 91 uint32_t V4L2Device::V4L2PixFmtToDrmFormat(uint32_t format) { | |
| 92 switch (format) { | |
| 93 case V4L2_PIX_FMT_NV12: | |
| 94 case V4L2_PIX_FMT_NV12M: | |
| 95 return DRM_FORMAT_NV12; | |
| 96 | |
| 97 case V4L2_PIX_FMT_YUV420: | |
| 98 case V4L2_PIX_FMT_YUV420M: | |
| 99 return DRM_FORMAT_YUV420; | |
| 100 | |
| 101 case V4L2_PIX_FMT_RGB32: | |
| 102 return DRM_FORMAT_ARGB8888; | |
| 103 | |
| 104 default: | |
| 105 LOG(FATAL) << "Add more cases as needed"; | |
| 106 return 0; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 // static | |
| 111 gfx::Size V4L2Device::CodedSizeFromV4L2Format(struct v4l2_format format) { | 81 gfx::Size V4L2Device::CodedSizeFromV4L2Format(struct v4l2_format format) { |
| 112 gfx::Size coded_size; | 82 gfx::Size coded_size; |
| 113 gfx::Size visible_size; | 83 gfx::Size visible_size; |
| 114 media::VideoFrame::Format frame_format = media::VideoFrame::UNKNOWN; | 84 media::VideoFrame::Format frame_format = media::VideoFrame::UNKNOWN; |
| 115 size_t bytesperline = 0; | 85 size_t bytesperline = 0; |
| 116 // Total bytes in the frame. | 86 // Total bytes in the frame. |
| 117 size_t sizeimage = 0; | 87 size_t sizeimage = 0; |
| 118 | 88 |
| 119 if (V4L2_TYPE_IS_MULTIPLANAR(format.type)) { | 89 if (V4L2_TYPE_IS_MULTIPLANAR(format.type)) { |
| 120 DCHECK_GT(format.fmt.pix_mp.num_planes, 0); | 90 DCHECK_GT(format.fmt.pix_mp.num_planes, 0); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Sanity checks. Calculated coded size has to contain given visible size | 152 // Sanity checks. Calculated coded size has to contain given visible size |
| 183 // and fulfill buffer byte size requirements. | 153 // and fulfill buffer byte size requirements. |
| 184 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); | 154 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); |
| 185 DCHECK_LE(sizeimage, | 155 DCHECK_LE(sizeimage, |
| 186 media::VideoFrame::AllocationSize(frame_format, coded_size)); | 156 media::VideoFrame::AllocationSize(frame_format, coded_size)); |
| 187 | 157 |
| 188 return coded_size; | 158 return coded_size; |
| 189 } | 159 } |
| 190 | 160 |
| 191 } // namespace content | 161 } // namespace content |
| OLD | NEW |