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 29 matching lines...) Expand all Loading... |
40 FILE* source_file_; | 40 FILE* source_file_; |
41 std::unique_ptr<VideoFrame> orig_frame_; | 41 std::unique_ptr<VideoFrame> orig_frame_; |
42 const int width_; | 42 const int width_; |
43 const int height_; | 43 const int height_; |
44 const int size_y_; | 44 const int size_y_; |
45 const int size_uv_; | 45 const int size_uv_; |
46 const size_t frame_length_; | 46 const size_t frame_length_; |
47 }; | 47 }; |
48 | 48 |
49 TestLibYuv::TestLibYuv() | 49 TestLibYuv::TestLibYuv() |
50 : source_file_(NULL), | 50 : source_file_(nullptr), |
51 orig_frame_(), | 51 orig_frame_(), |
52 width_(352), | 52 width_(352), |
53 height_(288), | 53 height_(288), |
54 size_y_(width_ * height_), | 54 size_y_(width_ * height_), |
55 size_uv_(((width_ + 1) / 2) * ((height_ + 1) / 2)), | 55 size_uv_(((width_ + 1) / 2) * ((height_ + 1) / 2)), |
56 frame_length_(CalcBufferSize(kI420, 352, 288)) {} | 56 frame_length_(CalcBufferSize(kI420, 352, 288)) {} |
57 | 57 |
58 void TestLibYuv::SetUp() { | 58 void TestLibYuv::SetUp() { |
59 const std::string input_file_name = webrtc::test::ResourcePath("foreman_cif", | 59 const std::string input_file_name = webrtc::test::ResourcePath("foreman_cif", |
60 "yuv"); | 60 "yuv"); |
61 source_file_ = fopen(input_file_name.c_str(), "rb"); | 61 source_file_ = fopen(input_file_name.c_str(), "rb"); |
62 ASSERT_TRUE(source_file_ != NULL) << "Cannot read file: "<< | 62 ASSERT_TRUE(source_file_ != nullptr) |
63 input_file_name << "\n"; | 63 << "Cannot read file: " << input_file_name << "\n"; |
64 | 64 |
65 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 65 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
66 test::ReadI420Buffer(width_, height_, source_file_)); | 66 test::ReadI420Buffer(width_, height_, source_file_)); |
67 | 67 |
68 orig_frame_.reset(new VideoFrame(buffer, kVideoRotation_0, 0)); | 68 orig_frame_.reset(new VideoFrame(buffer, kVideoRotation_0, 0)); |
69 } | 69 } |
70 | 70 |
71 void TestLibYuv::TearDown() { | 71 void TestLibYuv::TearDown() { |
72 if (source_file_ != NULL) { | 72 if (source_file_ != nullptr) { |
73 ASSERT_EQ(0, fclose(source_file_)); | 73 ASSERT_EQ(0, fclose(source_file_)); |
74 } | 74 } |
75 source_file_ = NULL; | 75 source_file_ = nullptr; |
76 } | 76 } |
77 | 77 |
78 TEST_F(TestLibYuv, ConvertSanityTest) { | 78 TEST_F(TestLibYuv, ConvertSanityTest) { |
79 // TODO(mikhal) | 79 // TODO(mikhal) |
80 } | 80 } |
81 | 81 |
82 TEST_F(TestLibYuv, ConvertTest) { | 82 TEST_F(TestLibYuv, ConvertTest) { |
83 // Reading YUV frame - testing on the first frame of the foreman sequence | 83 // Reading YUV frame - testing on the first frame of the foreman sequence |
84 int j = 0; | 84 int j = 0; |
85 std::string output_file_name = webrtc::test::OutputPath() + | 85 std::string output_file_name = webrtc::test::OutputPath() + |
86 "LibYuvTest_conversion.yuv"; | 86 "LibYuvTest_conversion.yuv"; |
87 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 87 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
88 ASSERT_TRUE(output_file != NULL); | 88 ASSERT_TRUE(output_file != nullptr); |
89 | 89 |
90 double psnr = 0.0; | 90 double psnr = 0.0; |
91 | 91 |
92 rtc::scoped_refptr<I420Buffer> res_i420_buffer = I420Buffer::Create( | 92 rtc::scoped_refptr<I420Buffer> res_i420_buffer = I420Buffer::Create( |
93 width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2); | 93 width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2); |
94 | 94 |
95 printf("\nConvert #%d I420 <-> I420 \n", j); | 95 printf("\nConvert #%d I420 <-> I420 \n", j); |
96 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); | 96 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); |
97 EXPECT_EQ(0, ConvertFromI420(*orig_frame_, kI420, 0, out_i420_buffer.get())); | 97 EXPECT_EQ(0, ConvertFromI420(*orig_frame_, kI420, 0, out_i420_buffer.get())); |
98 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, | 98 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 EXPECT_GT(ceil(psnr), 42); | 197 EXPECT_GT(ceil(psnr), 42); |
198 | 198 |
199 ASSERT_EQ(0, fclose(output_file)); | 199 ASSERT_EQ(0, fclose(output_file)); |
200 } | 200 } |
201 | 201 |
202 TEST_F(TestLibYuv, ConvertAlignedFrame) { | 202 TEST_F(TestLibYuv, ConvertAlignedFrame) { |
203 // Reading YUV frame - testing on the first frame of the foreman sequence | 203 // Reading YUV frame - testing on the first frame of the foreman sequence |
204 std::string output_file_name = webrtc::test::OutputPath() + | 204 std::string output_file_name = webrtc::test::OutputPath() + |
205 "LibYuvTest_conversion.yuv"; | 205 "LibYuvTest_conversion.yuv"; |
206 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 206 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
207 ASSERT_TRUE(output_file != NULL); | 207 ASSERT_TRUE(output_file != nullptr); |
208 | 208 |
209 double psnr = 0.0; | 209 double psnr = 0.0; |
210 | 210 |
211 int stride_y = 0; | 211 int stride_y = 0; |
212 int stride_uv = 0; | 212 int stride_uv = 0; |
213 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); | 213 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); |
214 | 214 |
215 rtc::scoped_refptr<I420Buffer> res_i420_buffer = | 215 rtc::scoped_refptr<I420Buffer> res_i420_buffer = |
216 I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv); | 216 I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv); |
217 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); | 217 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 2, 2); | 299 2, 2); |
300 | 300 |
301 EXPECT_THAT(dst_y, ::testing::ElementsAre( | 301 EXPECT_THAT(dst_y, ::testing::ElementsAre( |
302 Average(0, 1, 4, 5), Average(2, 3, 6, 7), | 302 Average(0, 1, 4, 5), Average(2, 3, 6, 7), |
303 Average(8, 9, 12, 13), Average(10, 11, 14, 15))); | 303 Average(8, 9, 12, 13), Average(10, 11, 14, 15))); |
304 EXPECT_THAT(dst_uv, | 304 EXPECT_THAT(dst_uv, |
305 ::testing::ElementsAre(Average(0, 2, 4, 6), Average(1, 3, 5, 7))); | 305 ::testing::ElementsAre(Average(0, 2, 4, 6), Average(1, 3, 5, 7))); |
306 } | 306 } |
307 | 307 |
308 } // namespace webrtc | 308 } // namespace webrtc |
OLD | NEW |