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