OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebM 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 #include <climits> | 10 #include <climits> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 virtual void DecompressedFrameHook(const vpx_image_t &img, | 137 virtual void DecompressedFrameHook(const vpx_image_t &img, |
138 vpx_codec_pts_t pts) { | 138 vpx_codec_pts_t pts) { |
139 frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); | 139 frame_info_list_.push_back(FrameInfo(pts, img.d_w, img.d_h)); |
140 } | 140 } |
141 | 141 |
142 std::vector< FrameInfo > frame_info_list_; | 142 std::vector< FrameInfo > frame_info_list_; |
143 }; | 143 }; |
144 | 144 |
145 TEST_P(ResizeTest, TestExternalResizeWorks) { | 145 TEST_P(ResizeTest, TestExternalResizeWorks) { |
146 ResizingVideoSource video; | 146 ResizingVideoSource video; |
| 147 cfg_.g_lag_in_frames = 0; |
147 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 148 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
148 | 149 |
149 for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); | 150 for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
150 info != frame_info_list_.end(); ++info) { | 151 info != frame_info_list_.end(); ++info) { |
151 const unsigned int frame = static_cast<unsigned>(info->pts); | 152 const unsigned int frame = static_cast<unsigned>(info->pts); |
152 const unsigned int expected_w = ScaleForFrameNumber(frame, kInitialWidth); | 153 const unsigned int expected_w = ScaleForFrameNumber(frame, kInitialWidth); |
153 const unsigned int expected_h = ScaleForFrameNumber(frame, kInitialHeight); | 154 const unsigned int expected_h = ScaleForFrameNumber(frame, kInitialHeight); |
154 | 155 |
155 EXPECT_EQ(expected_w, info->w) | 156 EXPECT_EQ(expected_w, info->w) |
156 << "Frame " << frame << "had unexpected width"; | 157 << "Frame " << frame << " had unexpected width"; |
157 EXPECT_EQ(expected_h, info->h) | 158 EXPECT_EQ(expected_h, info->h) |
158 << "Frame " << frame << "had unexpected height"; | 159 << "Frame " << frame << " had unexpected height"; |
159 } | 160 } |
160 } | 161 } |
161 | 162 |
162 const unsigned int kStepDownFrame = 3; | 163 const unsigned int kStepDownFrame = 3; |
163 const unsigned int kStepUpFrame = 6; | 164 const unsigned int kStepUpFrame = 6; |
164 | 165 |
165 class ResizeInternalTest : public ResizeTest { | 166 class ResizeInternalTest : public ResizeTest { |
166 protected: | 167 protected: |
167 #if WRITE_COMPRESSED_STREAM | 168 #if WRITE_COMPRESSED_STREAM |
168 ResizeInternalTest() | 169 ResizeInternalTest() |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 if (pts >= kStepDownFrame && pts < kStepUpFrame) { | 254 if (pts >= kStepDownFrame && pts < kStepUpFrame) { |
254 ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width"; | 255 ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width"; |
255 ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height"; | 256 ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height"; |
256 } else { | 257 } else { |
257 EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width"; | 258 EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width"; |
258 EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height"; | 259 EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height"; |
259 } | 260 } |
260 } | 261 } |
261 } | 262 } |
262 | 263 |
| 264 vpx_img_fmt_t CspForFrameNumber(int frame) { |
| 265 if (frame < 10) |
| 266 return VPX_IMG_FMT_I420; |
| 267 if (frame < 20) |
| 268 return VPX_IMG_FMT_I444; |
| 269 return VPX_IMG_FMT_I420; |
| 270 } |
| 271 |
| 272 class ResizeCspTest : public ResizeTest { |
| 273 protected: |
| 274 #if WRITE_COMPRESSED_STREAM |
| 275 ResizeCspTest() |
| 276 : ResizeTest(), |
| 277 frame0_psnr_(0.0), |
| 278 outfile_(NULL), |
| 279 out_frames_(0) {} |
| 280 #else |
| 281 ResizeCspTest() : ResizeTest(), frame0_psnr_(0.0) {} |
| 282 #endif |
| 283 |
| 284 virtual ~ResizeCspTest() {} |
| 285 |
| 286 virtual void BeginPassHook(unsigned int /*pass*/) { |
| 287 #if WRITE_COMPRESSED_STREAM |
| 288 outfile_ = fopen("vp91-2-05-cspchape.ivf", "wb"); |
| 289 #endif |
| 290 } |
| 291 |
| 292 virtual void EndPassHook() { |
| 293 #if WRITE_COMPRESSED_STREAM |
| 294 if (outfile_) { |
| 295 if (!fseek(outfile_, 0, SEEK_SET)) |
| 296 write_ivf_file_header(&cfg_, out_frames_, outfile_); |
| 297 fclose(outfile_); |
| 298 outfile_ = NULL; |
| 299 } |
| 300 #endif |
| 301 } |
| 302 |
| 303 virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video, |
| 304 libvpx_test::Encoder *encoder) { |
| 305 if (CspForFrameNumber(video->frame()) != VPX_IMG_FMT_I420 && |
| 306 cfg_.g_profile != 1) { |
| 307 cfg_.g_profile = 1; |
| 308 encoder->Config(&cfg_); |
| 309 } |
| 310 if (CspForFrameNumber(video->frame()) == VPX_IMG_FMT_I420 && |
| 311 cfg_.g_profile != 0) { |
| 312 cfg_.g_profile = 0; |
| 313 encoder->Config(&cfg_); |
| 314 } |
| 315 } |
| 316 |
| 317 virtual void PSNRPktHook(const vpx_codec_cx_pkt_t *pkt) { |
| 318 if (!frame0_psnr_) |
| 319 frame0_psnr_ = pkt->data.psnr.psnr[0]; |
| 320 EXPECT_NEAR(pkt->data.psnr.psnr[0], frame0_psnr_, 2.0); |
| 321 } |
| 322 |
| 323 #if WRITE_COMPRESSED_STREAM |
| 324 virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) { |
| 325 ++out_frames_; |
| 326 |
| 327 // Write initial file header if first frame. |
| 328 if (pkt->data.frame.pts == 0) |
| 329 write_ivf_file_header(&cfg_, 0, outfile_); |
| 330 |
| 331 // Write frame header and data. |
| 332 write_ivf_frame_header(pkt, outfile_); |
| 333 (void)fwrite(pkt->data.frame.buf, 1, pkt->data.frame.sz, outfile_); |
| 334 } |
| 335 #endif |
| 336 |
| 337 double frame0_psnr_; |
| 338 #if WRITE_COMPRESSED_STREAM |
| 339 FILE *outfile_; |
| 340 unsigned int out_frames_; |
| 341 #endif |
| 342 }; |
| 343 |
| 344 class ResizingCspVideoSource : public ::libvpx_test::DummyVideoSource { |
| 345 public: |
| 346 ResizingCspVideoSource() { |
| 347 SetSize(kInitialWidth, kInitialHeight); |
| 348 limit_ = 30; |
| 349 } |
| 350 |
| 351 virtual ~ResizingCspVideoSource() {} |
| 352 |
| 353 protected: |
| 354 virtual void Next() { |
| 355 ++frame_; |
| 356 SetImageFormat(CspForFrameNumber(frame_)); |
| 357 FillFrame(); |
| 358 } |
| 359 }; |
| 360 |
| 361 TEST_P(ResizeCspTest, TestResizeCspWorks) { |
| 362 ResizingCspVideoSource video; |
| 363 cfg_.rc_min_quantizer = cfg_.rc_max_quantizer = 48; |
| 364 cfg_.g_lag_in_frames = 0; |
| 365 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 366 } |
| 367 |
263 VP8_INSTANTIATE_TEST_CASE(ResizeTest, ONE_PASS_TEST_MODES); | 368 VP8_INSTANTIATE_TEST_CASE(ResizeTest, ONE_PASS_TEST_MODES); |
| 369 VP9_INSTANTIATE_TEST_CASE(ResizeTest, |
| 370 ::testing::Values(::libvpx_test::kRealTime)); |
264 VP9_INSTANTIATE_TEST_CASE(ResizeInternalTest, | 371 VP9_INSTANTIATE_TEST_CASE(ResizeInternalTest, |
265 ::testing::Values(::libvpx_test::kOnePassBest)); | 372 ::testing::Values(::libvpx_test::kOnePassBest)); |
| 373 VP9_INSTANTIATE_TEST_CASE(ResizeCspTest, |
| 374 ::testing::Values(::libvpx_test::kRealTime)); |
266 } // namespace | 375 } // namespace |
OLD | NEW |