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