The bitstream bit match test in multi-threaded encoder
authorYunqing Wang <yunqingwang@google.com>
Mon, 13 Feb 2017 20:29:31 +0000 (12:29 -0800)
committerYunqing Wang <yunqingwang@google.com>
Mon, 13 Feb 2017 21:02:26 +0000 (13:02 -0800)
While the new-mt mode is enabled(namely, allowing to use row-based
multi-threading in encoder), several speed features that adaptively
adjust encoding parameters during encoding would cause mismatch
between single-thread encoded bitstream and multi-thread encoded
bitstream. This patch provides a set_control API to disable these
features, so that the bit match bitstream is obtained in the unit
test.

Change-Id: Ie9868bafdfe196296d1dd29e0dca517f6a9a4d60

test/vp9_ethread_test.cc
vp9/encoder/vp9_encoder.h
vp9/vp9_cx_iface.c
vpx/vp8cx.h

index 21e34d6..2f34cc2 100644 (file)
@@ -190,6 +190,7 @@ class VPxEncoderThreadTest
         encoding_mode_(GET_PARAM(1)), set_cpu_used_(GET_PARAM(2)) {
     init_flags_ = VPX_CODEC_USE_PSNR;
     md5_.clear();
+    new_mt_mode_ = 1;
   }
   virtual ~VPxEncoderThreadTest() {}
 
@@ -227,6 +228,11 @@ class VPxEncoderThreadTest
         encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
         encoder->Control(VP8E_SET_ARNR_TYPE, 3);
         encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 0);
+
+        // While new_mt = 1(namely, using row-based multi-threading), several
+        // speed features that would adaptively adjust encoding parameters have
+        // to be disabled to guarantee the bit match of the resulted bitstream.
+        if (new_mt_mode_) encoder->Control(VP9E_ENABLE_THREAD_BIT_MATCH, 1);
       } else {
         encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 0);
         encoder->Control(VP9E_SET_AQ_MODE, 3);
@@ -258,6 +264,7 @@ class VPxEncoderThreadTest
   int threads_;
   ::libvpx_test::TestMode encoding_mode_;
   int set_cpu_used_;
+  int new_mt_mode_;
   std::vector<std::string> md5_;
 };
 
index 1a70cb4..65f3f86 100644 (file)
@@ -260,6 +260,7 @@ typedef struct VP9EncoderConfig {
   VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
 
   int new_mt;
+  unsigned int ethread_bit_match;
 } VP9EncoderConfig;
 
 static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
index c239ca6..4811890 100644 (file)
@@ -52,6 +52,7 @@ struct vp9_extracfg {
   int render_width;
   int render_height;
   unsigned int new_mt;
+  unsigned int ethread_bit_match;
 };
 
 static struct vp9_extracfg default_extra_cfg = {
@@ -84,6 +85,7 @@ static struct vp9_extracfg default_extra_cfg = {
   0,                     // render width
   0,                     // render height
   1,                     // new_mt
+  0,                     // ethread_bit_match
 };
 
 struct vpx_codec_alg_priv {
@@ -248,6 +250,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
         "or kf_max_dist instead.");
 
   RANGE_CHECK(extra_cfg, new_mt, 0, 1);
+  RANGE_CHECK(extra_cfg, ethread_bit_match, 0, 1);
   RANGE_CHECK(extra_cfg, enable_auto_alt_ref, 0, 2);
   RANGE_CHECK(extra_cfg, cpu_used, -8, 8);
   RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6);
@@ -558,6 +561,7 @@ static vpx_codec_err_t set_encoder_config(
   oxcf->target_level = extra_cfg->target_level;
 
   oxcf->new_mt = extra_cfg->new_mt;
+  oxcf->ethread_bit_match = extra_cfg->ethread_bit_match;
 
   for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
 #if CONFIG_SPATIAL_SVC
@@ -854,6 +858,13 @@ static vpx_codec_err_t ctrl_set_new_mt(vpx_codec_alg_priv_t *ctx,
   return update_extra_cfg(ctx, &extra_cfg);
 }
 
+static vpx_codec_err_t ctrl_set_ethread_bit_match(vpx_codec_alg_priv_t *ctx,
+                                                  va_list args) {
+  struct vp9_extracfg extra_cfg = ctx->extra_cfg;
+  extra_cfg.ethread_bit_match = CAST(VP9E_ENABLE_THREAD_BIT_MATCH, args);
+  return update_extra_cfg(ctx, &extra_cfg);
+}
+
 static vpx_codec_err_t ctrl_get_level(vpx_codec_alg_priv_t *ctx, va_list args) {
   int *const arg = va_arg(args, int *);
   if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
@@ -1607,6 +1618,7 @@ static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
   { VP9E_SET_RENDER_SIZE, ctrl_set_render_size },
   { VP9E_SET_TARGET_LEVEL, ctrl_set_target_level },
   { VP9E_SET_NEW_MT, ctrl_set_new_mt },
+  { VP9E_ENABLE_THREAD_BIT_MATCH, ctrl_set_ethread_bit_match },
 
   // Getters
   { VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer },
index a04d7dd..923734c 100644 (file)
@@ -555,6 +555,15 @@ enum vp8e_enc_control_id {
   */
   VP9E_SET_NEW_MT,
 
+  /*!\brief Codec control function to enable the bit match result in multi-
+   * threaded encoder unit tests.
+   *
+   * 0 : off, 1 : on
+   *
+   * Supported in codecs: VP9
+   */
+  VP9E_ENABLE_THREAD_BIT_MATCH,
+
   /*!\brief Codec control function to get bitstream level.
    *
    * Supported in codecs: VP9
@@ -849,6 +858,9 @@ VPX_CTRL_USE_TYPE(VP9E_SET_TARGET_LEVEL, unsigned int)
 VPX_CTRL_USE_TYPE(VP9E_SET_NEW_MT, unsigned int)
 #define VPX_CTRL_VP9E_SET_NEW_MT
 
+VPX_CTRL_USE_TYPE(VP9E_ENABLE_THREAD_BIT_MATCH, unsigned int)
+#define VPX_CTRL_VP9E_ENABLE_THREAD_BIT_MATCH
+
 VPX_CTRL_USE_TYPE(VP9E_GET_LEVEL, int *)
 #define VPX_CTRL_VP9E_GET_LEVEL