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) {