tile_independence_test.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <cstdio>
  11. #include <cstdlib>
  12. #include <string>
  13. #include "third_party/googletest/src/include/gtest/gtest.h"
  14. #include "test/codec_factory.h"
  15. #include "test/encode_test_driver.h"
  16. #include "test/i420_video_source.h"
  17. #include "test/util.h"
  18. #include "test/md5_helper.h"
  19. #include "vpx_mem/vpx_mem.h"
  20. namespace {
  21. class TileIndependenceTest : public ::libvpx_test::EncoderTest,
  22. public ::libvpx_test::CodecTestWithParam<int> {
  23. protected:
  24. TileIndependenceTest()
  25. : EncoderTest(GET_PARAM(0)), md5_fw_order_(), md5_inv_order_(),
  26. n_tiles_(GET_PARAM(1)) {
  27. init_flags_ = VPX_CODEC_USE_PSNR;
  28. vpx_codec_dec_cfg_t cfg = vpx_codec_dec_cfg_t();
  29. cfg.w = 704;
  30. cfg.h = 144;
  31. cfg.threads = 1;
  32. fw_dec_ = codec_->CreateDecoder(cfg, 0);
  33. inv_dec_ = codec_->CreateDecoder(cfg, 0);
  34. inv_dec_->Control(VP9_INVERT_TILE_DECODE_ORDER, 1);
  35. }
  36. virtual ~TileIndependenceTest() {
  37. delete fw_dec_;
  38. delete inv_dec_;
  39. }
  40. virtual void SetUp() {
  41. InitializeConfig();
  42. SetMode(libvpx_test::kTwoPassGood);
  43. }
  44. virtual void PreEncodeFrameHook(libvpx_test::VideoSource *video,
  45. libvpx_test::Encoder *encoder) {
  46. if (video->frame() == 0) {
  47. encoder->Control(VP9E_SET_TILE_COLUMNS, n_tiles_);
  48. }
  49. }
  50. void UpdateMD5(::libvpx_test::Decoder *dec, const vpx_codec_cx_pkt_t *pkt,
  51. ::libvpx_test::MD5 *md5) {
  52. const vpx_codec_err_t res = dec->DecodeFrame(
  53. reinterpret_cast<uint8_t *>(pkt->data.frame.buf), pkt->data.frame.sz);
  54. if (res != VPX_CODEC_OK) {
  55. abort_ = true;
  56. ASSERT_EQ(VPX_CODEC_OK, res);
  57. }
  58. const vpx_image_t *img = dec->GetDxData().Next();
  59. md5->Add(img);
  60. }
  61. virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
  62. UpdateMD5(fw_dec_, pkt, &md5_fw_order_);
  63. UpdateMD5(inv_dec_, pkt, &md5_inv_order_);
  64. }
  65. ::libvpx_test::MD5 md5_fw_order_, md5_inv_order_;
  66. ::libvpx_test::Decoder *fw_dec_, *inv_dec_;
  67. private:
  68. int n_tiles_;
  69. };
  70. // run an encode with 2 or 4 tiles, and do the decode both in normal and
  71. // inverted tile ordering. Ensure that the MD5 of the output in both cases
  72. // is identical. If so, tiles are considered independent and the test passes.
  73. TEST_P(TileIndependenceTest, MD5Match) {
  74. const vpx_rational timebase = { 33333333, 1000000000 };
  75. cfg_.g_timebase = timebase;
  76. cfg_.rc_target_bitrate = 500;
  77. cfg_.g_lag_in_frames = 25;
  78. cfg_.rc_end_usage = VPX_VBR;
  79. libvpx_test::I420VideoSource video("hantro_collage_w352h288.yuv", 704, 144,
  80. timebase.den, timebase.num, 0, 30);
  81. ASSERT_NO_FATAL_FAILURE(RunLoop(&video));
  82. const char *md5_fw_str = md5_fw_order_.Get();
  83. const char *md5_inv_str = md5_inv_order_.Get();
  84. // could use ASSERT_EQ(!memcmp(.., .., 16) here, but this gives nicer
  85. // output if it fails. Not sure if it's helpful since it's really just
  86. // a MD5...
  87. ASSERT_STREQ(md5_fw_str, md5_inv_str);
  88. }
  89. VP9_INSTANTIATE_TEST_CASE(TileIndependenceTest, ::testing::Range(0, 2, 1));
  90. } // namespace