vp9_encoder_parms_get_to_decoder.cc 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

11 12
#include "third_party/googletest/src/include/gtest/gtest.h"

13 14
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
15
#include "test/util.h"
16
#include "test/y4m_video_source.h"
17
#include "vp9/vp9_dx_iface.h"
18 19 20 21 22 23 24 25 26 27 28 29 30 31

namespace {

const int kCpuUsed = 2;

struct EncodePerfTestVideo {
  const char *name;
  uint32_t width;
  uint32_t height;
  uint32_t bitrate;
  int frames;
};

const EncodePerfTestVideo kVP9EncodePerfTestVectors[] = {
32
  {"niklas_1280_720_30.y4m", 1280, 720, 600, 10},
33 34 35 36 37 38 39 40
};

struct EncodeParameters {
  int32_t tile_rows;
  int32_t tile_cols;
  int32_t lossless;
  int32_t error_resilient;
  int32_t frame_parallel;
41
  vpx_color_range_t color_range;
42
  vpx_color_space_t cs;
43
  int render_size[2];
44 45 46 47
  // TODO(JBB): quantizers / bitrate
};

const EncodeParameters kVP9EncodeParameterSet[] = {
48 49 50 51
  {0, 0, 0, 1, 0, VPX_CR_STUDIO_RANGE, VPX_CS_BT_601},
  {0, 0, 0, 0, 0, VPX_CR_FULL_RANGE, VPX_CS_BT_709},
  {0, 0, 1, 0, 0, VPX_CR_FULL_RANGE, VPX_CS_BT_2020},
  {0, 2, 0, 0, 1, VPX_CR_STUDIO_RANGE, VPX_CS_UNKNOWN, { 640, 480 }},
52
  // TODO(JBB): Test profiles (requires more work).
53 54
};

55
class VpxEncoderParmsGetToDecoder
56
    : public ::libvpx_test::EncoderTest,
57
      public ::libvpx_test::CodecTestWith2Params<EncodeParameters,
58 59
                                                 EncodePerfTestVideo> {
 protected:
60
  VpxEncoderParmsGetToDecoder()
61
      : EncoderTest(GET_PARAM(0)), encode_parms(GET_PARAM(1)) {}
62

63
  virtual ~VpxEncoderParmsGetToDecoder() {}
64 65 66 67 68 69 70 71 72 73 74 75 76 77

  virtual void SetUp() {
    InitializeConfig();
    SetMode(::libvpx_test::kTwoPassGood);
    cfg_.g_lag_in_frames = 25;
    cfg_.g_error_resilient = encode_parms.error_resilient;
    dec_cfg_.threads = 4;
    test_video_ = GET_PARAM(2);
    cfg_.rc_target_bitrate = test_video_.bitrate;
  }

  virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
                                  ::libvpx_test::Encoder *encoder) {
    if (video->frame() == 1) {
78
      encoder->Control(VP9E_SET_COLOR_SPACE, encode_parms.cs);
79
      encoder->Control(VP9E_SET_COLOR_RANGE, encode_parms.color_range);
80 81 82 83 84 85 86 87 88 89
      encoder->Control(VP9E_SET_LOSSLESS, encode_parms.lossless);
      encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING,
                       encode_parms.frame_parallel);
      encoder->Control(VP9E_SET_TILE_ROWS, encode_parms.tile_rows);
      encoder->Control(VP9E_SET_TILE_COLUMNS, encode_parms.tile_cols);
      encoder->Control(VP8E_SET_CPUUSED, kCpuUsed);
      encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
      encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
      encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
      encoder->Control(VP8E_SET_ARNR_TYPE, 3);
90 91
      if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0)
        encoder->Control(VP9E_SET_RENDER_SIZE, encode_parms.render_size);
92 93 94 95
    }
  }

  virtual bool HandleDecodeResult(const vpx_codec_err_t res_dec,
96
                                  const libvpx_test::VideoSource &video,
97
                                  libvpx_test::Decoder *decoder) {
98 99
    vpx_codec_ctx_t *const vp9_decoder = decoder->GetDecoder();
    vpx_codec_alg_priv_t *const priv =
100
        reinterpret_cast<vpx_codec_alg_priv_t *>(vp9_decoder->priv);
James Zern's avatar
James Zern committed
101 102 103
    FrameWorkerData *const worker_data =
        reinterpret_cast<FrameWorkerData *>(priv->frame_workers[0].data1);
    VP9_COMMON *const common = &worker_data->pbi->common;
104 105

    if (encode_parms.lossless) {
106 107 108 109 110
      EXPECT_EQ(0, common->base_qindex);
      EXPECT_EQ(0, common->y_dc_delta_q);
      EXPECT_EQ(0, common->uv_dc_delta_q);
      EXPECT_EQ(0, common->uv_ac_delta_q);
      EXPECT_EQ(ONLY_4X4, common->tx_mode);
111
    }
112
    EXPECT_EQ(encode_parms.error_resilient, common->error_resilient_mode);
113
    if (encode_parms.error_resilient) {
114 115
      EXPECT_EQ(1, common->frame_parallel_decoding_mode);
      EXPECT_EQ(0, common->use_prev_frame_mvs);
116
    } else {
117 118
      EXPECT_EQ(encode_parms.frame_parallel,
                common->frame_parallel_decoding_mode);
119
    }
120
    EXPECT_EQ(encode_parms.color_range, common->color_range);
121
    EXPECT_EQ(encode_parms.cs, common->color_space);
122 123 124 125
    if (encode_parms.render_size[0] > 0 && encode_parms.render_size[1] > 0) {
      EXPECT_EQ(encode_parms.render_size[0], common->render_width);
      EXPECT_EQ(encode_parms.render_size[1], common->render_height);
    }
126 127
    EXPECT_EQ(encode_parms.tile_cols, common->log2_tile_cols);
    EXPECT_EQ(encode_parms.tile_rows, common->log2_tile_rows);
128 129 130 131 132 133 134 135 136 137 138

    EXPECT_EQ(VPX_CODEC_OK, res_dec) << decoder->DecodeError();
    return VPX_CODEC_OK == res_dec;
  }

  EncodePerfTestVideo test_video_;

 private:
  EncodeParameters encode_parms;
};

James Zern's avatar
James Zern committed
139
TEST_P(VpxEncoderParmsGetToDecoder, BitstreamParms) {
140 141
  init_flags_ = VPX_CODEC_USE_PSNR;

142 143 144
  libvpx_test::VideoSource *const video =
      new libvpx_test::Y4mVideoSource(test_video_.name, 0, test_video_.frames);
  ASSERT_TRUE(video != NULL);
145 146

  ASSERT_NO_FATAL_FAILURE(RunLoop(video));
147
  delete video;
148 149
}

150 151 152
VP9_INSTANTIATE_TEST_CASE(VpxEncoderParmsGetToDecoder,
                          ::testing::ValuesIn(kVP9EncodeParameterSet),
                          ::testing::ValuesIn(kVP9EncodePerfTestVectors));
153
}  // namespace