| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 void TestLibYuv::SetUp() { | 105 void TestLibYuv::SetUp() { |
| 106 const std::string input_file_name = webrtc::test::ResourcePath("foreman_cif", | 106 const std::string input_file_name = webrtc::test::ResourcePath("foreman_cif", |
| 107 "yuv"); | 107 "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"; |
| 111 | 111 |
| 112 EXPECT_EQ(frame_length_, | 112 EXPECT_EQ(frame_length_, |
| 113 fread(orig_buffer_.get(), 1, frame_length_, source_file_)); | 113 fread(orig_buffer_.get(), 1, frame_length_, source_file_)); |
| 114 orig_frame_.CreateFrame(orig_buffer_.get(), | 114 EXPECT_EQ(0, orig_frame_.CreateFrame(orig_buffer_.get(), |
| 115 orig_buffer_.get() + size_y_, | 115 orig_buffer_.get() + size_y_, |
| 116 orig_buffer_.get() + | 116 orig_buffer_.get() + |
| 117 size_y_ + size_uv_, | 117 size_y_ + size_uv_, |
| 118 width_, height_, | 118 width_, height_, |
| 119 width_, (width_ + 1) / 2, | 119 width_, (width_ + 1) / 2, |
| 120 (width_ + 1) / 2, | 120 (width_ + 1) / 2)); |
| 121 kVideoRotation_0); | |
| 122 } | 121 } |
| 123 | 122 |
| 124 void TestLibYuv::TearDown() { | 123 void TestLibYuv::TearDown() { |
| 125 if (source_file_ != NULL) { | 124 if (source_file_ != NULL) { |
| 126 ASSERT_EQ(0, fclose(source_file_)); | 125 ASSERT_EQ(0, fclose(source_file_)); |
| 127 } | 126 } |
| 128 source_file_ = NULL; | 127 source_file_ = NULL; |
| 129 } | 128 } |
| 130 | 129 |
| 131 TEST_F(TestLibYuv, ConvertSanityTest) { | 130 TEST_F(TestLibYuv, ConvertSanityTest) { |
| 132 // TODO(mikhal) | 131 // TODO(mikhal) |
| 133 } | 132 } |
| 134 | 133 |
| 135 TEST_F(TestLibYuv, ConvertTest) { | 134 TEST_F(TestLibYuv, ConvertTest) { |
| 136 // 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 |
| 137 int j = 0; | 136 int j = 0; |
| 138 std::string output_file_name = webrtc::test::OutputPath() + | 137 std::string output_file_name = webrtc::test::OutputPath() + |
| 139 "LibYuvTest_conversion.yuv"; | 138 "LibYuvTest_conversion.yuv"; |
| 140 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 139 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
| 141 ASSERT_TRUE(output_file != NULL); | 140 ASSERT_TRUE(output_file != NULL); |
| 142 | 141 |
| 143 double psnr = 0.0; | 142 double psnr = 0.0; |
| 144 | 143 |
| 145 VideoFrame res_i420_frame; | 144 VideoFrame res_i420_frame; |
| 146 res_i420_frame.CreateEmptyFrame(width_, height_, width_, | 145 EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, width_, |
| 147 (width_ + 1) / 2, | 146 (width_ + 1) / 2, |
| 148 (width_ + 1) / 2); | 147 (width_ + 1) / 2)); |
| 149 printf("\nConvert #%d I420 <-> I420 \n", j); | 148 printf("\nConvert #%d I420 <-> I420 \n", j); |
| 150 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_]); |
| 151 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, | 150 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, |
| 152 out_i420_buffer.get())); | 151 out_i420_buffer.get())); |
| 153 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_, |
| 154 height_, 0, kVideoRotation_0, &res_i420_frame)); | 153 height_, 0, kVideoRotation_0, &res_i420_frame)); |
| 155 | 154 |
| 156 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 155 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { |
| 157 return; | 156 return; |
| 158 } | 157 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 195 |
| 197 printf("\nConvert #%d I420 <-> YV12\n", j); | 196 printf("\nConvert #%d I420 <-> YV12\n", j); |
| 198 rtc::scoped_ptr<uint8_t[]> outYV120Buffer(new uint8_t[frame_length_]); | 197 rtc::scoped_ptr<uint8_t[]> outYV120Buffer(new uint8_t[frame_length_]); |
| 199 rtc::scoped_ptr<uint8_t[]> res_i420_buffer(new uint8_t[frame_length_]); | 198 rtc::scoped_ptr<uint8_t[]> res_i420_buffer(new uint8_t[frame_length_]); |
| 200 VideoFrame yv12_frame; | 199 VideoFrame yv12_frame; |
| 201 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYV12, 0, outYV120Buffer.get())); | 200 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYV12, 0, outYV120Buffer.get())); |
| 202 yv12_frame.CreateFrame(outYV120Buffer.get(), | 201 yv12_frame.CreateFrame(outYV120Buffer.get(), |
| 203 outYV120Buffer.get() + size_y_, | 202 outYV120Buffer.get() + size_y_, |
| 204 outYV120Buffer.get() + size_y_ + size_uv_, | 203 outYV120Buffer.get() + size_y_ + size_uv_, |
| 205 width_, height_, | 204 width_, height_, |
| 206 width_, (width_ + 1) / 2, (width_ + 1) / 2, | 205 width_, (width_ + 1) / 2, (width_ + 1) / 2); |
| 207 kVideoRotation_0); | |
| 208 EXPECT_EQ(0, ConvertFromYV12(yv12_frame, kI420, 0, res_i420_buffer.get())); | 206 EXPECT_EQ(0, ConvertFromYV12(yv12_frame, kI420, 0, res_i420_buffer.get())); |
| 209 if (fwrite(res_i420_buffer.get(), 1, frame_length_, output_file) != | 207 if (fwrite(res_i420_buffer.get(), 1, frame_length_, output_file) != |
| 210 frame_length_) { | 208 frame_length_) { |
| 211 return; | 209 return; |
| 212 } | 210 } |
| 213 | 211 |
| 214 ConvertToI420(kI420, res_i420_buffer.get(), 0, 0, width_, height_, 0, | 212 ConvertToI420(kI420, res_i420_buffer.get(), 0, 0, width_, height_, 0, |
| 215 kVideoRotation_0, &res_i420_frame); | 213 kVideoRotation_0, &res_i420_frame); |
| 216 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 214 psnr = I420PSNR(&orig_frame_, &res_i420_frame); |
| 217 EXPECT_EQ(48.0, psnr); | 215 EXPECT_EQ(48.0, psnr); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 "LibYuvTest_conversion.yuv"; | 274 "LibYuvTest_conversion.yuv"; |
| 277 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 275 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
| 278 ASSERT_TRUE(output_file != NULL); | 276 ASSERT_TRUE(output_file != NULL); |
| 279 | 277 |
| 280 double psnr = 0.0; | 278 double psnr = 0.0; |
| 281 | 279 |
| 282 VideoFrame res_i420_frame; | 280 VideoFrame res_i420_frame; |
| 283 int stride_y = 0; | 281 int stride_y = 0; |
| 284 int stride_uv = 0; | 282 int stride_uv = 0; |
| 285 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); | 283 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); |
| 286 res_i420_frame.CreateEmptyFrame(width_, height_, | 284 EXPECT_EQ(0, res_i420_frame.CreateEmptyFrame(width_, height_, |
| 287 stride_y, stride_uv, stride_uv); | 285 stride_y, stride_uv, stride_uv)); |
| 288 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_]); |
| 289 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, | 287 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, |
| 290 out_i420_buffer.get())); | 288 out_i420_buffer.get())); |
| 291 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_, |
| 292 height_, 0, kVideoRotation_0, &res_i420_frame)); | 290 height_, 0, kVideoRotation_0, &res_i420_frame)); |
| 293 | 291 |
| 294 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 292 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { |
| 295 return; | 293 return; |
| 296 } | 294 } |
| 297 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 295 psnr = I420PSNR(&orig_frame_, &res_i420_frame); |
| 298 EXPECT_EQ(48.0, psnr); | 296 EXPECT_EQ(48.0, psnr); |
| 299 } | 297 } |
| 300 | 298 |
| 301 | 299 |
| 302 TEST_F(TestLibYuv, RotateTest) { | 300 TEST_F(TestLibYuv, RotateTest) { |
| 303 // Use ConvertToI420 for multiple roatations - see that nothing breaks, all | 301 // Use ConvertToI420 for multiple roatations - see that nothing breaks, all |
| 304 // 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. |
| 305 VideoFrame rotated_res_i420_frame; | 303 VideoFrame rotated_res_i420_frame; |
| 306 int rotated_width = height_; | 304 int rotated_width = height_; |
| 307 int rotated_height = width_; | 305 int rotated_height = width_; |
| 308 int stride_y; | 306 int stride_y; |
| 309 int stride_uv; | 307 int stride_uv; |
| 310 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); | 308 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); |
| 311 rotated_res_i420_frame.CreateEmptyFrame(rotated_width, | 309 EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(rotated_width, |
| 312 rotated_height, | 310 rotated_height, |
| 313 stride_y, | 311 stride_y, |
| 314 stride_uv, | 312 stride_uv, |
| 315 stride_uv); | 313 stride_uv)); |
| 316 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_, |
| 317 0, kVideoRotation_90, &rotated_res_i420_frame)); | 315 0, kVideoRotation_90, &rotated_res_i420_frame)); |
| 318 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_, |
| 319 0, kVideoRotation_270, &rotated_res_i420_frame)); | 317 0, kVideoRotation_270, &rotated_res_i420_frame)); |
| 320 rotated_res_i420_frame.CreateEmptyFrame(width_, height_, | 318 EXPECT_EQ(0, rotated_res_i420_frame.CreateEmptyFrame(width_, height_, |
| 321 width_, (width_ + 1) / 2, | 319 width_, (width_ + 1) / 2, |
| 322 (width_ + 1) / 2); | 320 (width_ + 1) / 2)); |
| 323 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_, |
| 324 0, kVideoRotation_180, &rotated_res_i420_frame)); | 322 0, kVideoRotation_180, &rotated_res_i420_frame)); |
| 325 } | 323 } |
| 326 | 324 |
| 327 TEST_F(TestLibYuv, alignment) { | 325 TEST_F(TestLibYuv, alignment) { |
| 328 int value = 0x3FF; // 1023 | 326 int value = 0x3FF; // 1023 |
| 329 EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero. | 327 EXPECT_EQ(0x400, AlignInt(value, 128)); // Low 7 bits are zero. |
| 330 EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero. | 328 EXPECT_EQ(0x400, AlignInt(value, 64)); // Low 6 bits are zero. |
| 331 EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero. | 329 EXPECT_EQ(0x400, AlignInt(value, 32)); // Low 5 bits are zero. |
| 332 } | 330 } |
| 333 | 331 |
| 334 TEST_F(TestLibYuv, StrideAlignment) { | 332 TEST_F(TestLibYuv, StrideAlignment) { |
| 335 int stride_y = 0; | 333 int stride_y = 0; |
| 336 int stride_uv = 0; | 334 int stride_uv = 0; |
| 337 int width = 52; | 335 int width = 52; |
| 338 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 336 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
| 339 EXPECT_EQ(64, stride_y); | 337 EXPECT_EQ(64, stride_y); |
| 340 EXPECT_EQ(32, stride_uv); | 338 EXPECT_EQ(32, stride_uv); |
| 341 width = 128; | 339 width = 128; |
| 342 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 340 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
| 343 EXPECT_EQ(128, stride_y); | 341 EXPECT_EQ(128, stride_y); |
| 344 EXPECT_EQ(64, stride_uv); | 342 EXPECT_EQ(64, stride_uv); |
| 345 width = 127; | 343 width = 127; |
| 346 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 344 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
| 347 EXPECT_EQ(128, stride_y); | 345 EXPECT_EQ(128, stride_y); |
| 348 EXPECT_EQ(64, stride_uv); | 346 EXPECT_EQ(64, stride_uv); |
| 349 } | 347 } |
| 350 | 348 |
| 351 } // namespace webrtc | 349 } // namespace webrtc |
| OLD | NEW |