Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: webrtc/common_video/libyuv/libyuv_unittest.cc

Issue 2021843002: Delete unused code in webrtc_libyuv.cc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Copy Calc16ByteAlignedStride. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <math.h> 11 #include <math.h>
12 #include <string.h> 12 #include <string.h>
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
18 #include "webrtc/test/testsupport/fileutils.h" 18 #include "webrtc/test/testsupport/fileutils.h"
19 #include "webrtc/video_frame.h" 19 #include "webrtc/video_frame.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 22
23 namespace {
24 void Calc16ByteAlignedStride(int width, int* stride_y, int* stride_uv) {
25 *stride_y = 16 * ((width + 15) / 16);
26 *stride_uv = 16 * ((width + 31) / 32);
27 }
28
29 } // Anonymous namespace
30
23 class TestLibYuv : public ::testing::Test { 31 class TestLibYuv : public ::testing::Test {
24 protected: 32 protected:
25 TestLibYuv(); 33 TestLibYuv();
26 virtual void SetUp(); 34 virtual void SetUp();
27 virtual void TearDown(); 35 virtual void TearDown();
28 36
29 FILE* source_file_; 37 FILE* source_file_;
30 VideoFrame orig_frame_; 38 VideoFrame orig_frame_;
31 std::unique_ptr<uint8_t[]> orig_buffer_; 39 std::unique_ptr<uint8_t[]> orig_buffer_;
32 const int width_; 40 const int width_;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get())); 140 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get()));
133 EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_, 141 EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_,
134 height_, 0, kVideoRotation_0, &res_i420_frame)); 142 height_, 0, kVideoRotation_0, &res_i420_frame));
135 psnr = I420PSNR(&orig_frame_, &res_i420_frame); 143 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
136 EXPECT_EQ(48.0, psnr); 144 EXPECT_EQ(48.0, psnr);
137 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { 145 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
138 return; 146 return;
139 } 147 }
140 j++; 148 j++;
141 149
142 printf("\nConvert #%d I420 <-> YV12\n", j);
143 std::unique_ptr<uint8_t[]> outYV120Buffer(new uint8_t[frame_length_]);
144 std::unique_ptr<uint8_t[]> res_i420_buffer(new uint8_t[frame_length_]);
145 VideoFrame yv12_frame;
146 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYV12, 0, outYV120Buffer.get()));
147 yv12_frame.CreateFrame(outYV120Buffer.get(),
148 outYV120Buffer.get() + size_y_,
149 outYV120Buffer.get() + size_y_ + size_uv_,
150 width_, height_,
151 width_, (width_ + 1) / 2, (width_ + 1) / 2,
152 kVideoRotation_0);
153 EXPECT_EQ(0, ConvertFromYV12(yv12_frame, kI420, 0, res_i420_buffer.get()));
154 if (fwrite(res_i420_buffer.get(), 1, frame_length_, output_file) !=
155 frame_length_) {
156 return;
157 }
158
159 ConvertToI420(kI420, res_i420_buffer.get(), 0, 0, width_, height_, 0,
160 kVideoRotation_0, &res_i420_frame);
161 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
162 EXPECT_EQ(48.0, psnr);
163 j++;
164
165 printf("\nConvert #%d I420 <-> YUY2\n", j); 150 printf("\nConvert #%d I420 <-> YUY2\n", j);
166 std::unique_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]); 151 std::unique_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]);
167 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get())); 152 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get()));
168 153
169 EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_, 154 EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_,
170 height_, 0, kVideoRotation_0, &res_i420_frame)); 155 height_, 0, kVideoRotation_0, &res_i420_frame));
171 156
172 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { 157 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
173 return; 158 return;
174 } 159 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 0, kVideoRotation_90, &rotated_res_i420_frame)); 247 0, kVideoRotation_90, &rotated_res_i420_frame));
263 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 248 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
264 0, kVideoRotation_270, &rotated_res_i420_frame)); 249 0, kVideoRotation_270, &rotated_res_i420_frame));
265 rotated_res_i420_frame.CreateEmptyFrame(width_, height_, 250 rotated_res_i420_frame.CreateEmptyFrame(width_, height_,
266 width_, (width_ + 1) / 2, 251 width_, (width_ + 1) / 2,
267 (width_ + 1) / 2); 252 (width_ + 1) / 2);
268 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 253 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
269 0, kVideoRotation_180, &rotated_res_i420_frame)); 254 0, kVideoRotation_180, &rotated_res_i420_frame));
270 } 255 }
271 256
272 TEST_F(TestLibYuv, alignment) {
273 int value = 0x3FF; // 1023
274 EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero.
275 EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero.
276 EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero.
277 }
278
279 TEST_F(TestLibYuv, StrideAlignment) {
280 int stride_y = 0;
281 int stride_uv = 0;
282 int width = 52;
283 Calc16ByteAlignedStride(width, &stride_y, &stride_uv);
284 EXPECT_EQ(64, stride_y);
285 EXPECT_EQ(32, stride_uv);
286 width = 128;
287 Calc16ByteAlignedStride(width, &stride_y, &stride_uv);
288 EXPECT_EQ(128, stride_y);
289 EXPECT_EQ(64, stride_uv);
290 width = 127;
291 Calc16ByteAlignedStride(width, &stride_y, &stride_uv);
292 EXPECT_EQ(128, stride_y);
293 EXPECT_EQ(64, stride_uv);
294 }
295
296 } // namespace webrtc 257 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/libyuv/include/webrtc_libyuv.h ('k') | webrtc/common_video/libyuv/webrtc_libyuv.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698