From 1a265888639c88ba8aee78ee2b3f27d74a0da960 Mon Sep 17 00:00:00 2001 From: "mikhal@webrtc.org" Date: Fri, 21 Sep 2012 15:37:06 +0000 Subject: [PATCH] Adding a 64 bit alignment calcualtion to LibYuv. BUG= Review URL: https://webrtc-codereview.appspot.com/823006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2800 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/common_video/libyuv/include/webrtc_libyuv.h | 16 +++++++++++----- src/common_video/libyuv/libyuv_unittest.cc | 12 ++++++++++++ src/common_video/libyuv/webrtc_libyuv.cc | 4 ++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/common_video/libyuv/include/webrtc_libyuv.h b/src/common_video/libyuv/include/webrtc_libyuv.h index 87fbdb180c..68c3aa5ab9 100644 --- a/src/common_video/libyuv/include/webrtc_libyuv.h +++ b/src/common_video/libyuv/include/webrtc_libyuv.h @@ -56,13 +56,19 @@ enum VideoRotationMode { kRotate270 = 270, }; +// Align value to 64 bits. +// Input: +// - value : Input value to be aligned. +// Return value: An aligned to 64 bit form of the input value. +int AlignTo64Bit(int value); + // Calculate the required buffer size. // Input: -// - type - The type of the designated video frame. -// - width - frame width in pixels. -// - height - frame height in pixels. -// Return value: The required size in bytes to accommodate the specified -// video frame or -1 in case of an error . +// - type :The type of the designated video frame. +// - width :frame width in pixels. +// - height :frame height in pixels. +// Return value: :The required size in bytes to accommodate the specified +// video frame or -1 in case of an error . int CalcBufferSize(VideoType type, int width, int height); // Convert To I420 diff --git a/src/common_video/libyuv/libyuv_unittest.cc b/src/common_video/libyuv/libyuv_unittest.cc index 3e58314152..343d494396 100644 --- a/src/common_video/libyuv/libyuv_unittest.cc +++ b/src/common_video/libyuv/libyuv_unittest.cc @@ -301,4 +301,16 @@ TEST_F(TestLibYuv, DISABLED_MirrorTest) { delete [] test_frame2; } +TEST_F(TestLibYuv, alignment) { + int value = 640; + int aligned_value = (value + 63) & ~63; + EXPECT_EQ(AlignTo64Bit(value), aligned_value); + value = 600; + aligned_value = (value + 63) & ~63; + EXPECT_EQ(AlignTo64Bit(value), aligned_value); + value = 0; + aligned_value = (value + 63) & ~63; + EXPECT_EQ(AlignTo64Bit(value), aligned_value); +} + } // namespace diff --git a/src/common_video/libyuv/webrtc_libyuv.cc b/src/common_video/libyuv/webrtc_libyuv.cc index 9c370f77ae..eed647637f 100644 --- a/src/common_video/libyuv/webrtc_libyuv.cc +++ b/src/common_video/libyuv/webrtc_libyuv.cc @@ -52,6 +52,10 @@ VideoType RawVideoTypeToCommonVideoVideoType(RawVideoType type) { return kUnknown; } +int AlignTo64Bit(int value) { + return ((value + 63) & ~63); +} + int CalcBufferSize(VideoType type, int width, int height) { int buffer_size = 0; switch (type) {