| 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 <linux/videodev2.h> | 6 #include <linux/videodev2.h> |
| 6 | 7 |
| 7 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 8 #include "content/common/gpu/media/generic_v4l2_video_device.h" | 9 #include "content/common/gpu/media/generic_v4l2_video_device.h" |
| 9 #include "content/common/gpu/media/tegra_v4l2_video_device.h" | 10 #include "content/common/gpu/media/tegra_v4l2_video_device.h" |
| 10 | 11 |
| 11 namespace content { | 12 namespace content { |
| 12 | 13 |
| 13 V4L2Device::~V4L2Device() {} | 14 V4L2Device::~V4L2Device() {} |
| 14 | 15 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 33 uint32 pix_fmt) { | 34 uint32 pix_fmt) { |
| 34 switch (pix_fmt) { | 35 switch (pix_fmt) { |
| 35 case V4L2_PIX_FMT_NV12: | 36 case V4L2_PIX_FMT_NV12: |
| 36 case V4L2_PIX_FMT_NV12M: | 37 case V4L2_PIX_FMT_NV12M: |
| 37 return media::VideoFrame::NV12; | 38 return media::VideoFrame::NV12; |
| 38 | 39 |
| 39 case V4L2_PIX_FMT_YUV420: | 40 case V4L2_PIX_FMT_YUV420: |
| 40 case V4L2_PIX_FMT_YUV420M: | 41 case V4L2_PIX_FMT_YUV420M: |
| 41 return media::VideoFrame::I420; | 42 return media::VideoFrame::I420; |
| 42 | 43 |
| 44 case V4L2_PIX_FMT_RGB32: |
| 45 return media::VideoFrame::ARGB; |
| 46 |
| 43 default: | 47 default: |
| 44 LOG(FATAL) << "Add more cases as needed"; | 48 LOG(FATAL) << "Add more cases as needed"; |
| 45 return media::VideoFrame::UNKNOWN; | 49 return media::VideoFrame::UNKNOWN; |
| 46 } | 50 } |
| 47 } | 51 } |
| 48 | 52 |
| 49 // static | 53 // static |
| 50 uint32 V4L2Device::VideoFrameFormatToV4L2PixFmt( | 54 uint32 V4L2Device::VideoFrameFormatToV4L2PixFmt( |
| 51 media::VideoFrame::Format format) { | 55 media::VideoFrame::Format format) { |
| 52 switch (format) { | 56 switch (format) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 71 } else if (profile >= media::VP8PROFILE_MIN && | 75 } else if (profile >= media::VP8PROFILE_MIN && |
| 72 profile <= media::VP8PROFILE_MAX) { | 76 profile <= media::VP8PROFILE_MAX) { |
| 73 return V4L2_PIX_FMT_VP8; | 77 return V4L2_PIX_FMT_VP8; |
| 74 } else { | 78 } else { |
| 75 LOG(FATAL) << "Add more cases as needed"; | 79 LOG(FATAL) << "Add more cases as needed"; |
| 76 return 0; | 80 return 0; |
| 77 } | 81 } |
| 78 } | 82 } |
| 79 | 83 |
| 80 // static | 84 // static |
| 85 uint32_t V4L2Device::V4L2PixFmtToDrmFormat(uint32_t format) { |
| 86 switch (format) { |
| 87 case V4L2_PIX_FMT_NV12: |
| 88 case V4L2_PIX_FMT_NV12M: |
| 89 return DRM_FORMAT_NV12; |
| 90 |
| 91 case V4L2_PIX_FMT_YUV420: |
| 92 case V4L2_PIX_FMT_YUV420M: |
| 93 return DRM_FORMAT_YUV420; |
| 94 |
| 95 case V4L2_PIX_FMT_RGB32: |
| 96 return DRM_FORMAT_ARGB8888; |
| 97 |
| 98 default: |
| 99 LOG(FATAL) << "Add more cases as needed"; |
| 100 return 0; |
| 101 } |
| 102 } |
| 103 |
| 104 // static |
| 81 gfx::Size V4L2Device::CodedSizeFromV4L2Format(struct v4l2_format format) { | 105 gfx::Size V4L2Device::CodedSizeFromV4L2Format(struct v4l2_format format) { |
| 82 gfx::Size coded_size; | 106 gfx::Size coded_size; |
| 83 gfx::Size visible_size; | 107 gfx::Size visible_size; |
| 84 media::VideoFrame::Format frame_format = media::VideoFrame::UNKNOWN; | 108 media::VideoFrame::Format frame_format = media::VideoFrame::UNKNOWN; |
| 85 size_t bytesperline = 0; | 109 size_t bytesperline = 0; |
| 86 // Total bytes in the frame. | 110 // Total bytes in the frame. |
| 87 size_t sizeimage = 0; | 111 size_t sizeimage = 0; |
| 88 | 112 |
| 89 if (V4L2_TYPE_IS_MULTIPLANAR(format.type)) { | 113 if (V4L2_TYPE_IS_MULTIPLANAR(format.type)) { |
| 90 DCHECK_GT(format.fmt.pix_mp.num_planes, 0); | 114 DCHECK_GT(format.fmt.pix_mp.num_planes, 0); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Sanity checks. Calculated coded size has to contain given visible size | 176 // Sanity checks. Calculated coded size has to contain given visible size |
| 153 // and fulfill buffer byte size requirements. | 177 // and fulfill buffer byte size requirements. |
| 154 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); | 178 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); |
| 155 DCHECK_LE(sizeimage, | 179 DCHECK_LE(sizeimage, |
| 156 media::VideoFrame::AllocationSize(frame_format, coded_size)); | 180 media::VideoFrame::AllocationSize(frame_format, coded_size)); |
| 157 | 181 |
| 158 return coded_size; | 182 return coded_size; |
| 159 } | 183 } |
| 160 | 184 |
| 161 } // namespace content | 185 } // namespace content |
| OLD | NEW |