OLD | NEW |
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 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const int size_uv_; | 90 const int size_uv_; |
91 const size_t frame_length_; | 91 const size_t frame_length_; |
92 }; | 92 }; |
93 | 93 |
94 TestLibYuv::TestLibYuv() | 94 TestLibYuv::TestLibYuv() |
95 : source_file_(NULL), | 95 : source_file_(NULL), |
96 orig_frame_(), | 96 orig_frame_(), |
97 width_(352), | 97 width_(352), |
98 height_(288), | 98 height_(288), |
99 size_y_(width_ * height_), | 99 size_y_(width_ * height_), |
100 size_uv_(((width_ + 1 ) / 2) * ((height_ + 1) / 2)), | 100 size_uv_(((width_ + 1) / 2) * ((height_ + 1) / 2)), |
101 frame_length_(CalcBufferSize(kI420, 352, 288)) { | 101 frame_length_(CalcBufferSize(kI420, 352, 288)) { |
102 orig_buffer_.reset(new uint8_t[frame_length_]); | 102 orig_buffer_.reset(new uint8_t[frame_length_]); |
103 } | 103 } |
104 | 104 |
105 void TestLibYuv::SetUp() { | 105 void TestLibYuv::SetUp() { |
106 const std::string input_file_name = webrtc::test::ProjectRootPath() + | 106 const std::string input_file_name = webrtc::test::ProjectRootPath() + |
107 "resources/foreman_cif.yuv"; | 107 "resources/foreman_cif.yuv"; |
108 source_file_ = fopen(input_file_name.c_str(), "rb"); | 108 source_file_ = fopen(input_file_name.c_str(), "rb"); |
109 ASSERT_TRUE(source_file_ != NULL) << "Cannot read file: "<< | 109 ASSERT_TRUE(source_file_ != NULL) << "Cannot read file: "<< |
110 input_file_name << "\n"; | 110 input_file_name << "\n"; |
(...skipping 24 matching lines...) Expand all Loading... |
135 // Reading YUV frame - testing on the first frame of the foreman sequence | 135 // Reading YUV frame - testing on the first frame of the foreman sequence |
136 int j = 0; | 136 int j = 0; |
137 std::string output_file_name = webrtc::test::OutputPath() + | 137 std::string output_file_name = webrtc::test::OutputPath() + |
138 "LibYuvTest_conversion.yuv"; | 138 "LibYuvTest_conversion.yuv"; |
139 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 139 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
140 ASSERT_TRUE(output_file != NULL); | 140 ASSERT_TRUE(output_file != NULL); |
141 | 141 |
142 double psnr = 0.0; | 142 double psnr = 0.0; |
143 | 143 |
144 VideoFrame res_i420_frame; | 144 VideoFrame res_i420_frame; |
145 EXPECT_EQ(0,res_i420_frame.CreateEmptyFrame(width_, height_, width_, | 145 EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, width_, |
146 (width_ + 1) / 2, | 146 (width_ + 1) / 2, |
147 (width_ + 1) / 2)); | 147 (width_ + 1) / 2)); |
148 printf("\nConvert #%d I420 <-> I420 \n", j); | 148 printf("\nConvert #%d I420 <-> I420 \n", j); |
149 rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); | 149 rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); |
150 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, | 150 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, |
151 out_i420_buffer.get())); | 151 out_i420_buffer.get())); |
152 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, | 152 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, |
153 height_, 0, kVideoRotation_0, &res_i420_frame)); | 153 height_, 0, kVideoRotation_0, &res_i420_frame)); |
154 | 154 |
155 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 155 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { |
156 return; | 156 return; |
157 } | 157 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 "LibYuvTest_conversion.yuv"; | 274 "LibYuvTest_conversion.yuv"; |
275 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 275 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
276 ASSERT_TRUE(output_file != NULL); | 276 ASSERT_TRUE(output_file != NULL); |
277 | 277 |
278 double psnr = 0.0; | 278 double psnr = 0.0; |
279 | 279 |
280 VideoFrame res_i420_frame; | 280 VideoFrame res_i420_frame; |
281 int stride_y = 0; | 281 int stride_y = 0; |
282 int stride_uv = 0; | 282 int stride_uv = 0; |
283 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); | 283 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); |
284 EXPECT_EQ(0,res_i420_frame.CreateEmptyFrame(width_, height_, | 284 EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, |
285 stride_y, stride_uv, stride_uv)); | 285 stride_y, stride_uv, stride_uv)); |
286 rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); | 286 rtc::scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); |
287 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, | 287 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, |
288 out_i420_buffer.get())); | 288 out_i420_buffer.get())); |
289 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, | 289 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, |
290 height_, 0, kVideoRotation_0, &res_i420_frame)); | 290 height_, 0, kVideoRotation_0, &res_i420_frame)); |
291 | 291 |
292 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 292 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { |
293 return; | 293 return; |
294 } | 294 } |
295 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 295 psnr = I420PSNR(&orig_frame_, &res_i420_frame); |
296 EXPECT_EQ(48.0, psnr); | 296 EXPECT_EQ(48.0, psnr); |
297 } | 297 } |
298 | 298 |
299 | 299 |
300 TEST_F(TestLibYuv, RotateTest) { | 300 TEST_F(TestLibYuv, RotateTest) { |
301 // Use ConvertToI420 for multiple roatations - see that nothing breaks, all | 301 // Use ConvertToI420 for multiple roatations - see that nothing breaks, all |
302 // memory is properly allocated and end result is equal to the starting point. | 302 // memory is properly allocated and end result is equal to the starting point. |
303 VideoFrame rotated_res_i420_frame; | 303 VideoFrame rotated_res_i420_frame; |
304 int rotated_width = height_; | 304 int rotated_width = height_; |
305 int rotated_height = width_; | 305 int rotated_height = width_; |
306 int stride_y ; | 306 int stride_y; |
307 int stride_uv; | 307 int stride_uv; |
308 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); | 308 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); |
309 EXPECT_EQ(0,rotated_res_i420_frame.CreateEmptyFrame(rotated_width, | 309 EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(rotated_width, |
310 rotated_height, | 310 rotated_height, |
311 stride_y, | 311 stride_y, |
312 stride_uv, | 312 stride_uv, |
313 stride_uv)); | 313 stride_uv)); |
314 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, | 314 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, |
315 0, kVideoRotation_90, &rotated_res_i420_frame)); | 315 0, kVideoRotation_90, &rotated_res_i420_frame)); |
316 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, | 316 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, |
317 0, kVideoRotation_270, &rotated_res_i420_frame)); | 317 0, kVideoRotation_270, &rotated_res_i420_frame)); |
318 EXPECT_EQ(0,rotated_res_i420_frame.CreateEmptyFrame(width_, height_, | 318 EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(width_, height_, |
319 width_, (width_ + 1) / 2, | 319 width_, (width_ + 1) / 2, |
320 (width_ + 1) / 2)); | 320 (width_ + 1) / 2)); |
321 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, | 321 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, |
322 0, kVideoRotation_180, &rotated_res_i420_frame)); | 322 0, kVideoRotation_180, &rotated_res_i420_frame)); |
323 } | 323 } |
324 | 324 |
325 TEST_F(TestLibYuv, alignment) { | 325 TEST_F(TestLibYuv, alignment) { |
326 int value = 0x3FF; // 1023 | 326 int value = 0x3FF; // 1023 |
327 EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero. | 327 EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero. |
328 EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero. | 328 EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero. |
329 EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero. | 329 EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero. |
330 } | 330 } |
331 | 331 |
332 TEST_F(TestLibYuv, StrideAlignment) { | 332 TEST_F(TestLibYuv, StrideAlignment) { |
333 int stride_y = 0; | 333 int stride_y = 0; |
334 int stride_uv = 0; | 334 int stride_uv = 0; |
335 int width = 52; | 335 int width = 52; |
336 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 336 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
337 EXPECT_EQ(64, stride_y); | 337 EXPECT_EQ(64, stride_y); |
338 EXPECT_EQ(32, stride_uv); | 338 EXPECT_EQ(32, stride_uv); |
339 width = 128; | 339 width = 128; |
340 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 340 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
341 EXPECT_EQ(128, stride_y); | 341 EXPECT_EQ(128, stride_y); |
342 EXPECT_EQ(64, stride_uv); | 342 EXPECT_EQ(64, stride_uv); |
343 width = 127; | 343 width = 127; |
344 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 344 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
345 EXPECT_EQ(128, stride_y); | 345 EXPECT_EQ(128, stride_y); |
346 EXPECT_EQ(64, stride_uv); | 346 EXPECT_EQ(64, stride_uv); |
347 } | 347 } |
348 | 348 |
349 } // namespace | 349 } // namespace webrtc |
OLD | NEW |