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 <linux/videodev2.h> | 5 #include <linux/videodev2.h> |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
| 8 #include "content/common/gpu/media/exynos_v4l2_video_device.h" | 8 #include "content/common/gpu/media/exynos_v4l2_video_device.h" |
| 9 #include "content/common/gpu/media/tegra_v4l2_video_device.h" | 9 #include "content/common/gpu/media/tegra_v4l2_video_device.h" |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } else { | 74 } else { |
| 75 LOG(FATAL) << "Add more cases as needed"; | 75 LOG(FATAL) << "Add more cases as needed"; |
| 76 return 0; | 76 return 0; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 // static | 80 // static |
| 81 gfx::Size V4L2Device::CodedSizeFromV4L2Format(struct v4l2_format format) { | 81 gfx::Size V4L2Device::CodedSizeFromV4L2Format(struct v4l2_format format) { |
| 82 gfx::Size coded_size; | 82 gfx::Size coded_size; |
| 83 gfx::Size visible_size; | 83 gfx::Size visible_size; |
| 84 media::VideoFrame::Format frame_format = media::VideoFrame::UNKNOWN; | 84 media::VideoFrame::Format frame_format = media::VideoFrame::UNKNOWN; |
|
scherkus (not reviewing)
2014/08/20 17:13:53
are we using actual VideoFrames in V4L2 code?
it
wuchengli
2014/08/21 01:03:57
V4L2 code use actual VideoFrames like v4l2_image_p
scherkus (not reviewing)
2014/08/21 21:37:54
Thanks for the pointers.
I'm a little wary of mak
| |
| 85 int bytesperline = 0; | 85 int bytesperline = 0; |
| 86 int sizeimage = 0; | 86 int sizeimage = 0; |
| 87 | 87 |
| 88 if (V4L2_TYPE_IS_MULTIPLANAR(format.type) && | 88 if (V4L2_TYPE_IS_MULTIPLANAR(format.type) && |
| 89 format.fmt.pix_mp.num_planes > 0) { | 89 format.fmt.pix_mp.num_planes > 0) { |
| 90 bytesperline = | 90 bytesperline = |
| 91 base::checked_cast<int>(format.fmt.pix_mp.plane_fmt[0].bytesperline); | 91 base::checked_cast<int>(format.fmt.pix_mp.plane_fmt[0].bytesperline); |
| 92 sizeimage = | 92 sizeimage = |
| 93 base::checked_cast<int>(format.fmt.pix_mp.plane_fmt[0].sizeimage); | 93 base::checked_cast<int>(format.fmt.pix_mp.plane_fmt[0].sizeimage); |
| 94 visible_size.SetSize(base::checked_cast<int>(format.fmt.pix_mp.width), | 94 visible_size.SetSize(base::checked_cast<int>(format.fmt.pix_mp.width), |
| 95 base::checked_cast<int>(format.fmt.pix_mp.height)); | 95 base::checked_cast<int>(format.fmt.pix_mp.height)); |
| 96 frame_format = | 96 frame_format = |
| 97 V4L2Device::V4L2PixFmtToVideoFrameFormat(format.fmt.pix_mp.pixelformat); | 97 V4L2Device::V4L2PixFmtToVideoFrameFormat(format.fmt.pix_mp.pixelformat); |
| 98 } else { | 98 } else { |
| 99 bytesperline = base::checked_cast<int>(format.fmt.pix.bytesperline); | 99 bytesperline = base::checked_cast<int>(format.fmt.pix.bytesperline); |
| 100 sizeimage = base::checked_cast<int>(format.fmt.pix.sizeimage); | 100 sizeimage = base::checked_cast<int>(format.fmt.pix.sizeimage); |
| 101 visible_size.SetSize(base::checked_cast<int>(format.fmt.pix.width), | 101 visible_size.SetSize(base::checked_cast<int>(format.fmt.pix.width), |
| 102 base::checked_cast<int>(format.fmt.pix.height)); | 102 base::checked_cast<int>(format.fmt.pix.height)); |
| 103 frame_format = | 103 frame_format = |
| 104 V4L2Device::V4L2PixFmtToVideoFrameFormat(format.fmt.pix.pixelformat); | 104 V4L2Device::V4L2PixFmtToVideoFrameFormat(format.fmt.pix.pixelformat); |
| 105 } | 105 } |
| 106 | 106 |
| 107 int horiz_bpp = | 107 int horiz_bpp = |
| 108 media::VideoFrame::PlaneHorizontalBitsPerPixel(frame_format, 0); | 108 media::VideoFrame::PlaneHorizontalBitsPerPixel(frame_format, 0); |
| 109 DVLOG(3) << __func__ << ": bytesperline=" << bytesperline | |
| 110 << ", sizeimage=" << sizeimage | |
| 111 << ", visible_size=" << visible_size.ToString() << ", frame_format=" | |
| 112 << media::VideoFrame::FormatToString(frame_format) | |
| 113 << ", horiz_bpp=" << horiz_bpp; | |
| 109 if (sizeimage == 0 || bytesperline == 0 || horiz_bpp == 0 || | 114 if (sizeimage == 0 || bytesperline == 0 || horiz_bpp == 0 || |
| 110 (bytesperline * 8) % horiz_bpp != 0) { | 115 (bytesperline * 8) % horiz_bpp != 0) { |
| 111 DLOG(ERROR) << "Invalid format provided"; | 116 DLOG(ERROR) << "Invalid format provided"; |
| 112 return coded_size; | 117 return coded_size; |
| 113 } | 118 } |
| 114 | 119 |
| 115 // Round up sizeimage to full bytesperlines. sizeimage does not have to be | 120 // Round up sizeimage to full bytesperlines. sizeimage does not have to be |
| 116 // a multiple of bytesperline, as in V4L2 terms it's just a byte size of | 121 // a multiple of bytesperline, as in V4L2 terms it's just a byte size of |
| 117 // the buffer, unrelated to its payload. | 122 // the buffer, unrelated to its payload. |
| 118 sizeimage = ((sizeimage + bytesperline - 1) / bytesperline) * bytesperline; | 123 sizeimage = ((sizeimage + bytesperline - 1) / bytesperline) * bytesperline; |
| 119 | 124 |
| 120 coded_size.SetSize(bytesperline * 8 / horiz_bpp, sizeimage / bytesperline); | 125 coded_size.SetSize(bytesperline * 8 / horiz_bpp, sizeimage / bytesperline); |
| 126 DVLOG(3) << "coded_size=" << coded_size.ToString(); | |
| 121 | 127 |
| 122 // Sanity checks. Calculated coded size has to contain given visible size | 128 // Sanity checks. Calculated coded size has to contain given visible size |
| 123 // and fulfill buffer byte size requirements for each plane. | 129 // and fulfill buffer byte size requirements for each plane. |
| 124 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); | 130 DCHECK(gfx::Rect(coded_size).Contains(gfx::Rect(visible_size))); |
| 125 | 131 |
| 126 if (V4L2_TYPE_IS_MULTIPLANAR(format.type)) { | 132 if (V4L2_TYPE_IS_MULTIPLANAR(format.type)) { |
| 127 for (size_t i = 0; i < format.fmt.pix_mp.num_planes; ++i) { | 133 for (size_t i = 0; i < format.fmt.pix_mp.num_planes; ++i) { |
| 128 DCHECK_LE( | 134 DCHECK_EQ(format.fmt.pix_mp.plane_fmt[i].bytesperline, |
| 129 format.fmt.pix_mp.plane_fmt[i].sizeimage, | 135 base::checked_cast<__u32>(media::VideoFrame::RowBytes( |
| 130 media::VideoFrame::PlaneAllocationSize(frame_format, i, coded_size)); | 136 i, frame_format, coded_size.width()))); |
| 131 DCHECK_LE(format.fmt.pix_mp.plane_fmt[i].bytesperline, | |
| 132 base::checked_cast<__u32>(coded_size.width())); | |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 | 139 |
| 136 return coded_size; | 140 return coded_size; |
| 137 } | 141 } |
| 138 | 142 |
| 139 } // namespace content | 143 } // namespace content |
| OLD | NEW |