shithub: libvpx

Download patch

ref: 318ca07657507e464556ffb909c28856eb6e1d13
parent: e7db593a464d522ad22dadefaa80027cb19615f1
author: Yunqing Wang <yunqingwang@google.com>
date: Mon Feb 13 07:29:31 EST 2017

The bitstream bit match test in multi-threaded encoder

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

--- a/test/vp9_ethread_test.cc
+++ b/test/vp9_ethread_test.cc
@@ -190,6 +190,7 @@
         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 @@
         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 @@
   int threads_;
   ::libvpx_test::TestMode encoding_mode_;
   int set_cpu_used_;
+  int new_mt_mode_;
   std::vector<std::string> md5_;
 };
 
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -260,6 +260,7 @@
   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) {
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -52,6 +52,7 @@
   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 @@
   0,                     // render width
   0,                     // render height
   1,                     // new_mt
+  0,                     // ethread_bit_match
 };
 
 struct vpx_codec_alg_priv {
@@ -248,6 +250,7 @@
         "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 @@
   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 @@
   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 @@
   { 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 },
--- a/vpx/vp8cx.h
+++ b/vpx/vp8cx.h
@@ -555,6 +555,15 @@
   */
   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
@@ -848,6 +857,9 @@
 
 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