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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 TEST_F(TestLibYuv, ConvertTest) { | 88 TEST_F(TestLibYuv, ConvertTest) { |
89 // Reading YUV frame - testing on the first frame of the foreman sequence | 89 // Reading YUV frame - testing on the first frame of the foreman sequence |
90 int j = 0; | 90 int j = 0; |
91 std::string output_file_name = webrtc::test::OutputPath() + | 91 std::string output_file_name = webrtc::test::OutputPath() + |
92 "LibYuvTest_conversion.yuv"; | 92 "LibYuvTest_conversion.yuv"; |
93 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 93 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
94 ASSERT_TRUE(output_file != NULL); | 94 ASSERT_TRUE(output_file != NULL); |
95 | 95 |
96 double psnr = 0.0; | 96 double psnr = 0.0; |
97 | 97 |
98 VideoFrame res_i420_frame; | 98 rtc::scoped_refptr<I420Buffer> res_i420_buffer = I420Buffer::Create( |
99 res_i420_frame.CreateEmptyFrame(width_, height_, width_, | 99 width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2); |
100 (width_ + 1) / 2, | 100 |
101 (width_ + 1) / 2); | |
102 printf("\nConvert #%d I420 <-> I420 \n", j); | 101 printf("\nConvert #%d I420 <-> I420 \n", j); |
103 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); | 102 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); |
104 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, | 103 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, out_i420_buffer.get())); |
105 out_i420_buffer.get())); | |
106 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, | 104 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, |
107 height_, 0, kVideoRotation_0, &res_i420_frame)); | 105 height_, 0, kVideoRotation_0, |
| 106 res_i420_buffer.get())); |
108 | 107 |
109 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 108 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
110 return; | 109 return; |
111 } | 110 } |
112 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 111 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
113 EXPECT_EQ(48.0, psnr); | 112 EXPECT_EQ(48.0, psnr); |
114 j++; | 113 j++; |
115 | 114 |
116 printf("\nConvert #%d I420 <-> RGB24\n", j); | 115 printf("\nConvert #%d I420 <-> RGB24\n", j); |
117 std::unique_ptr<uint8_t[]> res_rgb_buffer2(new uint8_t[width_ * height_ * 3]); | 116 std::unique_ptr<uint8_t[]> res_rgb_buffer2(new uint8_t[width_ * height_ * 3]); |
118 // Align the stride values for the output frame. | 117 // Align the stride values for the output frame. |
119 int stride_y = 0; | 118 int stride_y = 0; |
120 int stride_uv = 0; | 119 int stride_uv = 0; |
121 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); | 120 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); |
122 res_i420_frame.CreateEmptyFrame(width_, height_, stride_y, | 121 res_i420_buffer = |
123 stride_uv, stride_uv); | 122 I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv); |
124 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB24, 0, res_rgb_buffer2.get())); | 123 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB24, 0, res_rgb_buffer2.get())); |
125 | 124 |
126 EXPECT_EQ(0, ConvertToI420(kRGB24, res_rgb_buffer2.get(), 0, 0, width_, | 125 EXPECT_EQ(0, ConvertToI420(kRGB24, res_rgb_buffer2.get(), 0, 0, width_, |
127 height_, 0, kVideoRotation_0, &res_i420_frame)); | 126 height_, 0, kVideoRotation_0, |
| 127 res_i420_buffer.get())); |
128 | 128 |
129 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 129 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
130 return; | 130 return; |
131 } | 131 } |
132 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 132 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
133 | 133 |
134 // Optimization Speed- quality trade-off => 45 dB only (platform dependant). | 134 // Optimization Speed- quality trade-off => 45 dB only (platform dependant). |
135 EXPECT_GT(ceil(psnr), 44); | 135 EXPECT_GT(ceil(psnr), 44); |
136 j++; | 136 j++; |
137 | 137 |
138 printf("\nConvert #%d I420 <-> UYVY\n", j); | 138 printf("\nConvert #%d I420 <-> UYVY\n", j); |
139 std::unique_ptr<uint8_t[]> out_uyvy_buffer(new uint8_t[width_ * height_ * 2]); | 139 std::unique_ptr<uint8_t[]> out_uyvy_buffer(new uint8_t[width_ * height_ * 2]); |
140 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())); |
141 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_, |
142 height_, 0, kVideoRotation_0, &res_i420_frame)); | 142 height_, 0, kVideoRotation_0, |
143 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 143 res_i420_buffer.get())); |
| 144 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
144 EXPECT_EQ(48.0, psnr); | 145 EXPECT_EQ(48.0, psnr); |
145 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 146 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
146 return; | 147 return; |
147 } | 148 } |
148 j++; | 149 j++; |
149 | 150 |
150 printf("\nConvert #%d I420 <-> YUY2\n", j); | 151 printf("\nConvert #%d I420 <-> YUY2\n", j); |
151 std::unique_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]); | 152 std::unique_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]); |
152 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get())); | 153 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get())); |
153 | 154 |
154 EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_, | 155 EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_, |
155 height_, 0, kVideoRotation_0, &res_i420_frame)); | 156 height_, 0, |
| 157 kVideoRotation_0, res_i420_buffer.get())); |
156 | 158 |
157 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 159 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
158 return; | 160 return; |
159 } | 161 } |
160 | 162 |
161 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 163 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
162 EXPECT_EQ(48.0, psnr); | 164 EXPECT_EQ(48.0, psnr); |
| 165 |
163 printf("\nConvert #%d I420 <-> RGB565\n", j); | 166 printf("\nConvert #%d I420 <-> RGB565\n", j); |
164 std::unique_ptr<uint8_t[]> out_rgb565_buffer( | 167 std::unique_ptr<uint8_t[]> out_rgb565_buffer( |
165 new uint8_t[width_ * height_ * 2]); | 168 new uint8_t[width_ * height_ * 2]); |
166 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB565, 0, | 169 EXPECT_EQ(0, |
167 out_rgb565_buffer.get())); | 170 ConvertFromI420(orig_frame_, kRGB565, 0, out_rgb565_buffer.get())); |
168 | 171 |
169 EXPECT_EQ(0, ConvertToI420(kRGB565, out_rgb565_buffer.get(), 0, 0, width_, | 172 EXPECT_EQ(0, ConvertToI420(kRGB565, out_rgb565_buffer.get(), 0, 0, width_, |
170 height_, 0, kVideoRotation_0, &res_i420_frame)); | 173 height_, 0, |
171 | 174 kVideoRotation_0, res_i420_buffer.get())); |
172 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 175 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
173 return; | 176 return; |
174 } | 177 } |
175 j++; | 178 j++; |
176 | 179 |
177 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 180 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
178 // TODO(leozwang) Investigate the right psnr should be set for I420ToRGB565, | 181 // TODO(leozwang) Investigate the right psnr should be set for I420ToRGB565, |
179 // Another example is I420ToRGB24, the psnr is 44 | 182 // Another example is I420ToRGB24, the psnr is 44 |
180 // TODO(mikhal): Add psnr for RGB565, 1555, 4444, convert to ARGB. | 183 // TODO(mikhal): Add psnr for RGB565, 1555, 4444, convert to ARGB. |
181 EXPECT_GT(ceil(psnr), 40); | 184 EXPECT_GT(ceil(psnr), 40); |
182 | 185 |
183 printf("\nConvert #%d I420 <-> ARGB8888\n", j); | 186 printf("\nConvert #%d I420 <-> ARGB8888\n", j); |
184 std::unique_ptr<uint8_t[]> out_argb8888_buffer( | 187 std::unique_ptr<uint8_t[]> out_argb8888_buffer( |
185 new uint8_t[width_ * height_ * 4]); | 188 new uint8_t[width_ * height_ * 4]); |
186 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kARGB, 0, | 189 EXPECT_EQ(0, |
187 out_argb8888_buffer.get())); | 190 ConvertFromI420(orig_frame_, kARGB, 0, out_argb8888_buffer.get())); |
188 | 191 |
189 EXPECT_EQ(0, ConvertToI420(kARGB, out_argb8888_buffer.get(), 0, 0, width_, | 192 EXPECT_EQ(0, ConvertToI420(kARGB, out_argb8888_buffer.get(), 0, 0, width_, |
190 height_, 0, kVideoRotation_0, &res_i420_frame)); | 193 height_, 0, kVideoRotation_0, |
| 194 res_i420_buffer.get())); |
191 | 195 |
192 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 196 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
193 return; | 197 return; |
194 } | 198 } |
195 | 199 |
196 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 200 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
197 // TODO(leozwang) Investigate the right psnr should be set for I420ToARGB8888, | 201 // TODO(leozwang) Investigate the right psnr should be set for |
| 202 // I420ToARGB8888, |
198 EXPECT_GT(ceil(psnr), 42); | 203 EXPECT_GT(ceil(psnr), 42); |
199 | 204 |
200 ASSERT_EQ(0, fclose(output_file)); | 205 ASSERT_EQ(0, fclose(output_file)); |
201 } | 206 } |
202 | 207 |
203 TEST_F(TestLibYuv, ConvertAlignedFrame) { | 208 TEST_F(TestLibYuv, ConvertAlignedFrame) { |
204 // Reading YUV frame - testing on the first frame of the foreman sequence | 209 // Reading YUV frame - testing on the first frame of the foreman sequence |
205 std::string output_file_name = webrtc::test::OutputPath() + | 210 std::string output_file_name = webrtc::test::OutputPath() + |
206 "LibYuvTest_conversion.yuv"; | 211 "LibYuvTest_conversion.yuv"; |
207 FILE* output_file = fopen(output_file_name.c_str(), "wb"); | 212 FILE* output_file = fopen(output_file_name.c_str(), "wb"); |
208 ASSERT_TRUE(output_file != NULL); | 213 ASSERT_TRUE(output_file != NULL); |
209 | 214 |
210 double psnr = 0.0; | 215 double psnr = 0.0; |
211 | 216 |
212 VideoFrame res_i420_frame; | |
213 int stride_y = 0; | 217 int stride_y = 0; |
214 int stride_uv = 0; | 218 int stride_uv = 0; |
215 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); | 219 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); |
216 res_i420_frame.CreateEmptyFrame(width_, height_, | 220 |
217 stride_y, stride_uv, stride_uv); | 221 rtc::scoped_refptr<I420Buffer> res_i420_buffer = |
| 222 I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv); |
218 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); | 223 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); |
219 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, | 224 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, |
220 out_i420_buffer.get())); | 225 out_i420_buffer.get())); |
221 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, | 226 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, |
222 height_, 0, kVideoRotation_0, &res_i420_frame)); | 227 height_, 0, kVideoRotation_0, |
| 228 res_i420_buffer.get())); |
223 | 229 |
224 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { | 230 if (PrintVideoFrame(*res_i420_buffer, output_file) < 0) { |
225 return; | 231 return; |
226 } | 232 } |
227 psnr = I420PSNR(&orig_frame_, &res_i420_frame); | 233 psnr = I420PSNR(*orig_frame_.video_frame_buffer(), *res_i420_buffer); |
228 EXPECT_EQ(48.0, psnr); | 234 EXPECT_EQ(48.0, psnr); |
229 } | 235 } |
230 | 236 |
231 | 237 |
232 TEST_F(TestLibYuv, RotateTest) { | 238 TEST_F(TestLibYuv, RotateTest) { |
233 // Use ConvertToI420 for multiple roatations - see that nothing breaks, all | 239 // Use ConvertToI420 for multiple rotations - see that nothing breaks, all |
234 // memory is properly allocated and end result is equal to the starting point. | 240 // memory is properly allocated and end result is equal to the starting point. |
235 VideoFrame rotated_res_i420_frame; | |
236 int rotated_width = height_; | 241 int rotated_width = height_; |
237 int rotated_height = width_; | 242 int rotated_height = width_; |
238 int stride_y; | 243 int stride_y; |
239 int stride_uv; | 244 int stride_uv; |
240 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); | 245 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); |
241 rotated_res_i420_frame.CreateEmptyFrame(rotated_width, | 246 rtc::scoped_refptr<I420Buffer> rotated_res_i420_buffer = I420Buffer::Create( |
242 rotated_height, | 247 rotated_width, rotated_height, stride_y, stride_uv, stride_uv); |
243 stride_y, | |
244 stride_uv, | |
245 stride_uv); | |
246 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_, |
247 0, kVideoRotation_90, &rotated_res_i420_frame)); | 249 0, kVideoRotation_90, |
| 250 rotated_res_i420_buffer.get())); |
248 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, | 251 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, |
249 0, kVideoRotation_270, &rotated_res_i420_frame)); | 252 0, kVideoRotation_270, |
250 rotated_res_i420_frame.CreateEmptyFrame(width_, height_, | 253 rotated_res_i420_buffer.get())); |
251 width_, (width_ + 1) / 2, | 254 rotated_res_i420_buffer = I420Buffer::Create( |
252 (width_ + 1) / 2); | 255 width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2); |
253 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, | 256 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, |
254 0, kVideoRotation_180, &rotated_res_i420_frame)); | 257 0, kVideoRotation_180, |
| 258 rotated_res_i420_buffer.get())); |
255 } | 259 } |
256 | 260 |
257 } // namespace webrtc | 261 } // namespace webrtc |
OLD | NEW |