| 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; | |
| 148 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); | 147 ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); |
| 149 | 148 |
| 150 for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); | 149 for (std::vector<FrameInfo>::const_iterator info = frame_info_list_.begin(); |
| 151 info != frame_info_list_.end(); ++info) { | 150 info != frame_info_list_.end(); ++info) { |
| 152 const unsigned int frame = static_cast<unsigned>(info->pts); | 151 const unsigned int frame = static_cast<unsigned>(info->pts); |
| 153 const unsigned int expected_w = ScaleForFrameNumber(frame, kInitialWidth); | 152 const unsigned int expected_w = ScaleForFrameNumber(frame, kInitialWidth); |
| 154 const unsigned int expected_h = ScaleForFrameNumber(frame, kInitialHeight); | 153 const unsigned int expected_h = ScaleForFrameNumber(frame, kInitialHeight); |
| 155 | 154 |
| 156 EXPECT_EQ(expected_w, info->w) | 155 EXPECT_EQ(expected_w, info->w) |
| 157 << "Frame " << frame << " had unexpected width"; | 156 << "Frame " << frame << "had unexpected width"; |
| 158 EXPECT_EQ(expected_h, info->h) | 157 EXPECT_EQ(expected_h, info->h) |
| 159 << "Frame " << frame << " had unexpected height"; | 158 << "Frame " << frame << "had unexpected height"; |
| 160 } | 159 } |
| 161 } | 160 } |
| 162 | 161 |
| 163 const unsigned int kStepDownFrame = 3; | 162 const unsigned int kStepDownFrame = 3; |
| 164 const unsigned int kStepUpFrame = 6; | 163 const unsigned int kStepUpFrame = 6; |
| 165 | 164 |
| 166 class ResizeInternalTest : public ResizeTest { | 165 class ResizeInternalTest : public ResizeTest { |
| 167 protected: | 166 protected: |
| 168 #if WRITE_COMPRESSED_STREAM | 167 #if WRITE_COMPRESSED_STREAM |
| 169 ResizeInternalTest() | 168 ResizeInternalTest() |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 if (pts >= kStepDownFrame && pts < kStepUpFrame) { | 253 if (pts >= kStepDownFrame && pts < kStepUpFrame) { |
| 255 ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width"; | 254 ASSERT_EQ(282U, info->w) << "Frame " << pts << " had unexpected width"; |
| 256 ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height"; | 255 ASSERT_EQ(173U, info->h) << "Frame " << pts << " had unexpected height"; |
| 257 } else { | 256 } else { |
| 258 EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width"; | 257 EXPECT_EQ(352U, info->w) << "Frame " << pts << " had unexpected width"; |
| 259 EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height"; | 258 EXPECT_EQ(288U, info->h) << "Frame " << pts << " had unexpected height"; |
| 260 } | 259 } |
| 261 } | 260 } |
| 262 } | 261 } |
| 263 | 262 |
| 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 | |
| 368 VP8_INSTANTIATE_TEST_CASE(ResizeTest, ONE_PASS_TEST_MODES); | 263 VP8_INSTANTIATE_TEST_CASE(ResizeTest, ONE_PASS_TEST_MODES); |
| 369 VP9_INSTANTIATE_TEST_CASE(ResizeTest, | |
| 370 ::testing::Values(::libvpx_test::kRealTime)); | |
| 371 VP9_INSTANTIATE_TEST_CASE(ResizeInternalTest, | 264 VP9_INSTANTIATE_TEST_CASE(ResizeInternalTest, |
| 372 ::testing::Values(::libvpx_test::kOnePassBest)); | 265 ::testing::Values(::libvpx_test::kOnePassBest)); |
| 373 VP9_INSTANTIATE_TEST_CASE(ResizeCspTest, | |
| 374 ::testing::Values(::libvpx_test::kRealTime)); | |
| 375 } // namespace | 266 } // namespace |
| OLD | NEW |