Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(804)

Side by Side Diff: webrtc/common_video/libyuv/libyuv_unittest.cc

Issue 2278883002: Move MutableDataY{,U,V} methods to I420Buffer only. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update android capture and decoder code. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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); 101 printf("\nConvert #%d I420 <-> I420 \n", j);
102 printf("\nConvert #%d I420 <-> I420 \n", j); 102 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
103 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); 103 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, out_i420_buffer.get()));
104 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, 104 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_,
105 out_i420_buffer.get())); 105 height_, 0, kVideoRotation_0, res_i420_buffer));
106 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_,
107 height_, 0, kVideoRotation_0, &res_i420_frame));
108 106
109 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { 107 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
110 return; 108 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
109 return;
110 }
111 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
magjed_webrtc 2016/08/25 11:12:56 Can you use VideoFrameBuffers as input here instea
nisse-webrtc 2016/08/25 11:31:35 I think the problem is the PrintVideoFrame method.
112 EXPECT_EQ(48.0, psnr);
113 j++;
111 } 114 }
112 psnr = I420PSNR(&orig_frame_, &res_i420_frame); 115 {
magjed_webrtc 2016/08/25 11:12:56 The diff is kind of broken and becomes unnecessari
113 EXPECT_EQ(48.0, psnr); 116 printf("\nConvert #%d I420 <-> RGB24\n", j);
114 j++; 117 std::unique_ptr<uint8_t[]> res_rgb_buffer2(
118 new uint8_t[width_ * height_ * 3]);
119 // Align the stride values for the output frame.
120 int stride_y = 0;
121 int stride_uv = 0;
122 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
123 res_i420_buffer =
124 I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv);
125 EXPECT_EQ(0,
126 ConvertFromI420(orig_frame_, kRGB24, 0, res_rgb_buffer2.get()));
115 127
116 printf("\nConvert #%d I420 <-> RGB24\n", j); 128 EXPECT_EQ(0, ConvertToI420(kRGB24, res_rgb_buffer2.get(), 0, 0, width_,
117 std::unique_ptr<uint8_t[]> res_rgb_buffer2(new uint8_t[width_ * height_ * 3]); 129 height_, 0, kVideoRotation_0, res_i420_buffer));
118 // Align the stride values for the output frame.
119 int stride_y = 0;
120 int stride_uv = 0;
121 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
122 res_i420_frame.CreateEmptyFrame(width_, height_, stride_y,
123 stride_uv, stride_uv);
124 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB24, 0, res_rgb_buffer2.get()));
125 130
126 EXPECT_EQ(0, ConvertToI420(kRGB24, res_rgb_buffer2.get(), 0, 0, width_, 131 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
127 height_, 0, kVideoRotation_0, &res_i420_frame)); 132 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
133 return;
134 }
135 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
128 136
129 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { 137 // Optimization Speed- quality trade-off => 45 dB only (platform dependant).
130 return; 138 EXPECT_GT(ceil(psnr), 44);
139 j++;
131 } 140 }
132 psnr = I420PSNR(&orig_frame_, &res_i420_frame); 141 {
142 printf("\nConvert #%d I420 <-> UYVY\n", j);
143 std::unique_ptr<uint8_t[]> out_uyvy_buffer(
144 new uint8_t[width_ * height_ * 2]);
145 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get()));
146 EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_,
147 height_, 0, kVideoRotation_0, res_i420_buffer));
148 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
149 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
150 EXPECT_EQ(48.0, psnr);
151 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
152 return;
153 }
154 j++;
155 }
156 {
157 printf("\nConvert #%d I420 <-> YUY2\n", j);
158 std::unique_ptr<uint8_t[]> out_yuy2_buffer(
159 new uint8_t[width_ * height_ * 2]);
160 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get()));
133 161
134 // Optimization Speed- quality trade-off => 45 dB only (platform dependant). 162 EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_,
135 EXPECT_GT(ceil(psnr), 44); 163 height_, 0, kVideoRotation_0, res_i420_buffer));
136 j++;
137 164
138 printf("\nConvert #%d I420 <-> UYVY\n", j); 165 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
139 std::unique_ptr<uint8_t[]> out_uyvy_buffer(new uint8_t[width_ * height_ * 2]); 166 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
140 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get())); 167 return;
141 EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_, 168 }
142 height_, 0, kVideoRotation_0, &res_i420_frame)); 169
143 psnr = I420PSNR(&orig_frame_, &res_i420_frame); 170 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
144 EXPECT_EQ(48.0, psnr); 171 EXPECT_EQ(48.0, psnr);
145 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
146 return;
147 } 172 }
148 j++; 173 {
174 printf("\nConvert #%d I420 <-> RGB565\n", j);
175 std::unique_ptr<uint8_t[]> out_rgb565_buffer(
176 new uint8_t[width_ * height_ * 2]);
177 EXPECT_EQ(
178 0, ConvertFromI420(orig_frame_, kRGB565, 0, out_rgb565_buffer.get()));
149 179
150 printf("\nConvert #%d I420 <-> YUY2\n", j); 180 EXPECT_EQ(0, ConvertToI420(kRGB565, out_rgb565_buffer.get(), 0, 0, width_,
151 std::unique_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]); 181 height_, 0, kVideoRotation_0, res_i420_buffer));
152 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get())); 182 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
183 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
184 return;
185 }
186 j++;
153 187
154 EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_, 188 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
155 height_, 0, kVideoRotation_0, &res_i420_frame)); 189 // TODO(leozwang) Investigate the right psnr should be set for I420ToRGB565,
190 // Another example is I420ToRGB24, the psnr is 44
191 // TODO(mikhal): Add psnr for RGB565, 1555, 4444, convert to ARGB.
192 EXPECT_GT(ceil(psnr), 40);
193 }
194 {
195 printf("\nConvert #%d I420 <-> ARGB8888\n", j);
196 std::unique_ptr<uint8_t[]> out_argb8888_buffer(
197 new uint8_t[width_ * height_ * 4]);
198 EXPECT_EQ(
199 0, ConvertFromI420(orig_frame_, kARGB, 0, out_argb8888_buffer.get()));
156 200
157 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { 201 EXPECT_EQ(0, ConvertToI420(kARGB, out_argb8888_buffer.get(), 0, 0, width_,
158 return; 202 height_, 0, kVideoRotation_0, res_i420_buffer));
203
204 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
205 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
206 return;
207 }
208
209 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
210 // TODO(leozwang) Investigate the right psnr should be set for
211 // I420ToARGB8888,
212 EXPECT_GT(ceil(psnr), 42);
159 } 213 }
160
161 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
162 EXPECT_EQ(48.0, psnr);
163 printf("\nConvert #%d I420 <-> RGB565\n", j);
164 std::unique_ptr<uint8_t[]> out_rgb565_buffer(
165 new uint8_t[width_ * height_ * 2]);
166 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB565, 0,
167 out_rgb565_buffer.get()));
168
169 EXPECT_EQ(0, ConvertToI420(kRGB565, out_rgb565_buffer.get(), 0, 0, width_,
170 height_, 0, kVideoRotation_0, &res_i420_frame));
171
172 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
173 return;
174 }
175 j++;
176
177 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
178 // TODO(leozwang) Investigate the right psnr should be set for I420ToRGB565,
179 // Another example is I420ToRGB24, the psnr is 44
180 // TODO(mikhal): Add psnr for RGB565, 1555, 4444, convert to ARGB.
181 EXPECT_GT(ceil(psnr), 40);
182
183 printf("\nConvert #%d I420 <-> ARGB8888\n", j);
184 std::unique_ptr<uint8_t[]> out_argb8888_buffer(
185 new uint8_t[width_ * height_ * 4]);
186 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kARGB, 0,
187 out_argb8888_buffer.get()));
188
189 EXPECT_EQ(0, ConvertToI420(kARGB, out_argb8888_buffer.get(), 0, 0, width_,
190 height_, 0, kVideoRotation_0, &res_i420_frame));
191
192 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
193 return;
194 }
195
196 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
197 // TODO(leozwang) Investigate the right psnr should be set for I420ToARGB8888,
198 EXPECT_GT(ceil(psnr), 42);
199
200 ASSERT_EQ(0, fclose(output_file)); 214 ASSERT_EQ(0, fclose(output_file));
201 } 215 }
202 216
203 TEST_F(TestLibYuv, ConvertAlignedFrame) { 217 TEST_F(TestLibYuv, ConvertAlignedFrame) {
204 // Reading YUV frame - testing on the first frame of the foreman sequence 218 // Reading YUV frame - testing on the first frame of the foreman sequence
205 std::string output_file_name = webrtc::test::OutputPath() + 219 std::string output_file_name = webrtc::test::OutputPath() +
206 "LibYuvTest_conversion.yuv"; 220 "LibYuvTest_conversion.yuv";
207 FILE* output_file = fopen(output_file_name.c_str(), "wb"); 221 FILE* output_file = fopen(output_file_name.c_str(), "wb");
208 ASSERT_TRUE(output_file != NULL); 222 ASSERT_TRUE(output_file != NULL);
209 223
210 double psnr = 0.0; 224 double psnr = 0.0;
211 225
212 VideoFrame res_i420_frame;
213 int stride_y = 0; 226 int stride_y = 0;
214 int stride_uv = 0; 227 int stride_uv = 0;
215 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); 228 Calc16ByteAlignedStride(width_, &stride_y, &stride_uv);
216 res_i420_frame.CreateEmptyFrame(width_, height_, 229
217 stride_y, stride_uv, stride_uv); 230 rtc::scoped_refptr<I420Buffer> res_i420_buffer =
231 I420Buffer::Create(width_, height_, stride_y, stride_uv, stride_uv);
218 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); 232 std::unique_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]);
219 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, 233 EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0,
220 out_i420_buffer.get())); 234 out_i420_buffer.get()));
221 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_, 235 EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, width_,
222 height_, 0, kVideoRotation_0, &res_i420_frame)); 236 height_, 0, kVideoRotation_0, res_i420_buffer));
223 237
238 VideoFrame res_i420_frame(res_i420_buffer, 0, 0, webrtc::kVideoRotation_0);
224 if (PrintVideoFrame(res_i420_frame, output_file) < 0) { 239 if (PrintVideoFrame(res_i420_frame, output_file) < 0) {
magjed_webrtc 2016/08/25 11:12:56 It would be nice if you can make functions like Pr
225 return; 240 return;
226 } 241 }
227 psnr = I420PSNR(&orig_frame_, &res_i420_frame); 242 psnr = I420PSNR(&orig_frame_, &res_i420_frame);
228 EXPECT_EQ(48.0, psnr); 243 EXPECT_EQ(48.0, psnr);
229 } 244 }
230 245
231 246
232 TEST_F(TestLibYuv, RotateTest) { 247 TEST_F(TestLibYuv, RotateTest) {
233 // Use ConvertToI420 for multiple roatations - see that nothing breaks, all 248 // Use ConvertToI420 for multiple rotations - see that nothing breaks, all
234 // memory is properly allocated and end result is equal to the starting point. 249 // memory is properly allocated and end result is equal to the starting point.
235 VideoFrame rotated_res_i420_frame;
236 int rotated_width = height_; 250 int rotated_width = height_;
237 int rotated_height = width_; 251 int rotated_height = width_;
238 int stride_y; 252 int stride_y;
239 int stride_uv; 253 int stride_uv;
240 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv); 254 Calc16ByteAlignedStride(rotated_width, &stride_y, &stride_uv);
241 rotated_res_i420_frame.CreateEmptyFrame(rotated_width, 255 rtc::scoped_refptr<I420Buffer> rotated_res_i420_buffer = I420Buffer::Create(
242 rotated_height, 256 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_, 257 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
247 0, kVideoRotation_90, &rotated_res_i420_frame)); 258 0, kVideoRotation_90, rotated_res_i420_buffer));
248 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 259 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
249 0, kVideoRotation_270, &rotated_res_i420_frame)); 260 0, kVideoRotation_270, rotated_res_i420_buffer));
250 rotated_res_i420_frame.CreateEmptyFrame(width_, height_, 261 rotated_res_i420_buffer = I420Buffer::Create(
251 width_, (width_ + 1) / 2, 262 width_, height_, width_, (width_ + 1) / 2, (width_ + 1) / 2);
252 (width_ + 1) / 2);
253 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_, 263 EXPECT_EQ(0, ConvertToI420(kI420, orig_buffer_.get(), 0, 0, width_, height_,
254 0, kVideoRotation_180, &rotated_res_i420_frame)); 264 0, kVideoRotation_180, rotated_res_i420_buffer));
255 } 265 }
256 266
257 } // namespace webrtc 267 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698