vp9_encoder_parms_get_to_decoder.cc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2014 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 "third_party/googletest/src/include/gtest/gtest.h"
  11. #include "test/codec_factory.h"
  12. #include "test/encode_test_driver.h"
  13. #include "test/util.h"
  14. #include "test/y4m_video_source.h"
  15. #include "vp9/vp9_dx_iface.h"
  16. namespace {
  17. const int kCpuUsed = 2;
  18. struct EncodePerfTestVideo {
  19. const char *name;
  20. uint32_t width;
  21. uint32_t height;
  22. uint32_t bitrate;
  23. int frames;
  24. };
  25. const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
  26. { "niklas_1280_720_30.y4m", 1280, 720, 600, 10 },
  27. };
  28. struct EncodeParameters {
  29. int32_t tile_rows;
  30. int32_t tile_cols;
  31. int32_t lossless;
  32. int32_t error_resilient;
  33. int32_t frame_parallel;
  34. vpx_color_range_t color_range;
  35. vpx_color_space_t cs;
  36. int render_size[2];
  37. // TODO(JBB): quantizers / bitrate
  38. };
  39. const EncodeParameters kVP9EncodeParameterSet[] = {
  40. { 0, 0, 0, 1, 0, VPX_CR_STUDIO_RANGE, VPX_CS_BT_601, { 0, 0 } },
  41. { 0, 0, 0, 0, 0, VPX_CR_FULL_RANGE, VPX_CS_BT_709, { 0, 0 } },
  42. { 0, 0, 1, 0, 0, VPX_CR_FULL_RANGE, VPX_CS_BT_2020, { 0, 0 } },
  43. { 0, 2, 0, 0, 1, VPX_CR_STUDIO_RANGE, VPX_CS_UNKNOWN, { 640, 480 } },
  44. // TODO(JBB): Test profiles (requires more work).
  45. };
  46. class VpxEncoderParmsGetToDecoder
  47. : public ::libvpx_test::EncoderTest,
  48. public ::libvpx_test::CodecTestWith2Params<EncodeParameters,
  49. EncodePerfTestVideo> {
  50. protected:
  51. VpxEncoderParmsGetToDecoder()
  52. : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {}
  53. virtual ~VpxEncoderParmsGetToDecoder() {}
  54. virtual void SetUp() {
  55. InitializeConfig();
  56. SetMode(::libvpx_test::kTwoPassGood);
  57. cfg_.g_lag_in_frames = 25;
  58. cfg_.g_error_resilient = encode_parms.error_resilient;
  59. dec_cfg_.threads = 4;
  60. test_video_ = GET_PARAM(2);
  61. cfg_.rc_target_bitrate = test_video_.bitrate;
  62. }
  63. virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
  64. ::libvpx_test::Encoder *encoder) {
  65. if (video->frame() == 1) {
  66. encoder->Control(VP9E_SET_COLOR_SPACE, encode_parms.cs);
  67. encoder->Control(VP9E_SET_COLOR_RANGE, encode_parms.color_range);
  68. encoder->Control(VP9E_SET_LOSSLESS, encode_parms.lossless);
  69. encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING,
  70. encode_parms.frame_parallel);
  71. encoder->Control(VP9E_SET_TILE_ROWS, encode_parms.tile_rows);
  72. encoder->Control(VP9E_SET_TILE_COLUMNS, encode_parms.tile_cols);
  73. encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
  74. encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
  75. encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
  76. encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
  77. encoder->Control(VP8E_SET_ARNR_TYPE, 3);
  78. if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) {
  79. encoder->Control(VP9E_SET_RENDER_SIZE, encode_parms.render_size);
  80. }
  81. }
  82. }
  83. virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
  84. const libvpx_test::VideoSource & /*video*/,
  85. libvpx_test::Decoder *decoder) {
  86. vpx_codec_ctx_t *const vp9_decoder = decoder->GetDecoder();
  87. vpx_codec_alg_priv_t *const priv =
  88. reinterpret_cast<vpx_codec_alg_priv_t *>(vp9_decoder->priv);
  89. VP9_COMMON *const common = &priv->pbi->common;
  90. if (encode_parms.lossless) {
  91. EXPECT_EQ(0, common->base_qindex);
  92. EXPECT_EQ(0, common->y_dc_delta_q);
  93. EXPECT_EQ(0, common->uv_dc_delta_q);
  94. EXPECT_EQ(0, common->uv_ac_delta_q);
  95. EXPECT_EQ(ONLY_4X4, common->tx_mode);
  96. }
  97. EXPECT_EQ(encode_parms.error_resilient, common->error_resilient_mode);
  98. if (encode_parms.error_resilient) {
  99. EXPECT_EQ(1, common->frame_parallel_decoding_mode);
  100. EXPECT_EQ(0, common->use_prev_frame_mvs);
  101. } else {
  102. EXPECT_EQ(encode_parms.frame_parallel,
  103. common->frame_parallel_decoding_mode);
  104. }
  105. EXPECT_EQ(encode_parms.color_range, common->color_range);
  106. EXPECT_EQ(encode_parms.cs, common->color_space);
  107. if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) {
  108. EXPECT_EQ(encode_parms.render_size[0], common->render_width);
  109. EXPECT_EQ(encode_parms.render_size[1], common->render_height);
  110. }
  111. EXPECT_EQ(encode_parms.tile_cols, common->log2_tile_cols);
  112. EXPECT_EQ(encode_parms.tile_rows, common->log2_tile_rows);
  113. EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
  114. return VPX_CODEC_OK == res_dec;
  115. }
  116. EncodePerfTestVideo test_video_;
  117. private:
  118. EncodeParameters encode_parms;
  119. };
  120. TEST_P(VpxEncoderParmsGetToDecoder, BitstreamParms) {
  121. init_flags_ = VPX_CODEC_USE_PSNR;
  122. testing::internal::scoped_ptr<libvpx_test::VideoSource> video(
  123. new libvpx_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames));
  124. ASSERT_TRUE(video.get() != NULL);
  125. ASSERT_NO_FATAL_FAILURE(RunLoop(video.get()));
  126. }
  127. VP9_INSTANTIATE_TEST_CASE(VpxEncoderParmsGetToDecoder,
  128. ::testing::ValuesIn(kVP9EncodeParameterSet),
  129. ::testing::ValuesIn(kVP9EncodePerfTestVectors));
  130. } // namespace