vp9_encoder_parms_get_to_decoder.cc 5.4 KB

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