]> granicus.if.org Git - libvpx/commitdiff
vp8 dec: Add flag to bring up threads. m72-3626
authorJerome Jiang <jianj@google.com>
Tue, 8 Jan 2019 18:51:54 +0000 (10:51 -0800)
committerJerome Jiang <jianj@google.com>
Fri, 18 Jan 2019 18:20:13 +0000 (10:20 -0800)
Instead of creating a new decoder instance when restarting all threads
after they were shut down, re-create threads on the new flag.

BUG=webm:1577

Change-Id: I6272ecaa1b586afdaa5ed8d6eab80aff8f5eb673
(cherry picked from commit 7be8d2df6c1c224a96b75d8f2ed66df7cbd0bb48)

test/invalid_file_test.cc
vp8/decoder/decodeframe.c
vp8/decoder/onyxd_if.c
vp8/decoder/onyxd_int.h
vp8/vp8_dx_iface.c

index a92612af4d9052682145889a7c00cae1c6edb95b..8eed05eb494ad822bf057c7ed2673f91845403e8 100644 (file)
@@ -123,9 +123,9 @@ TEST_P(InvalidFileTest, ReturnCode) { RunTest(); }
 
 #if CONFIG_VP8_DECODER
 const DecodeParam kVP8InvalidFileTests[] = {
-  { 1, "invalid-bug-1443-v2.ivf" },
+  { 1, "invalid-bug-1443.ivf" },
   { 1, "invalid-token-partition.ivf" },
-  { 1, "invalid-vp80-00-comprehensive-s17661_r01-05_b6-.v2.ivf" },
+  { 1, "invalid-vp80-00-comprehensive-s17661_r01-05_b6-.ivf" },
 };
 
 VP8_INSTANTIATE_TEST_CASE(InvalidFileTest,
index 617abf77c46ee479ba8218ec89db32fcda9d86c7..650d1d0408d9395a2df50ad903be430a2940d942 100644 (file)
@@ -1222,6 +1222,7 @@ int vp8_decode_frame(VP8D_COMP *pbi) {
     unsigned int thread;
     if (vp8mt_decode_mb_rows(pbi, xd)) {
       vp8_decoder_remove_threads(pbi);
+      pbi->restart_threads = 1;
       vpx_internal_error(&pbi->common.error, VPX_CODEC_CORRUPT_FRAME, NULL);
     }
     vp8_yv12_extend_frame_borders(yv12_fb_new);
index e7e1cfc94996b46a002d94901c6b31ec6c2f466e..c6fb51d0cb50bf4c3641ce62f11d3761a78d32d2 100644 (file)
@@ -16,6 +16,7 @@
 #include "onyxd_int.h"
 #include "vpx_mem/vpx_mem.h"
 #include "vp8/common/alloccommon.h"
+#include "vp8/common/common.h"
 #include "vp8/common/loopfilter.h"
 #include "vp8/common/swapyv12buffer.h"
 #include "vp8/common/threading.h"
@@ -428,7 +429,6 @@ int vp8dx_references_buffer(VP8_COMMON *oci, int ref_frame) {
 }
 
 int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf) {
-  if (fb->pbi[0]) remove_decompressor(fb->pbi[0]);
   /* decoder instance for single thread mode */
   fb->pbi[0] = create_decompressor(oxcf);
   if (!fb->pbi[0]) return VPX_CODEC_ERROR;
@@ -436,7 +436,7 @@ int vp8_create_decoder_instances(struct frame_buffers *fb, VP8D_CONFIG *oxcf) {
 #if CONFIG_MULTITHREAD
   if (setjmp(fb->pbi[0]->common.error.jmp)) {
     vp8_remove_decoder_instances(fb);
-    memset(fb->pbi, 0, sizeof(fb->pbi));
+    vp8_zero(fb->pbi);
     vpx_clear_system_state();
     return VPX_CODEC_ERROR;
   }
index 5e1687d1a681da934c5f96219c3d24db9e1fe2b0..75286e430717413c472ad3f143fadefde8504dce 100644 (file)
@@ -118,6 +118,12 @@ typedef struct VP8D_COMP {
 
   vpx_decrypt_cb decrypt_cb;
   void *decrypt_state;
+#if CONFIG_MULTITHREAD
+  // Restart threads on next frame if set to 1.
+  // This is set when error happens in multithreaded decoding and all threads
+  // are shut down.
+  int restart_threads;
+#endif
 } VP8D_COMP;
 
 void vp8cx_init_de_quantizer(VP8D_COMP *pbi);
index a72d805052448bcf63350acbe598cbead6c42287..7db77195b24b1d7894c3630100e9504bd906be30 100644 (file)
@@ -45,6 +45,12 @@ struct vpx_codec_alg_priv {
   vpx_codec_dec_cfg_t cfg;
   vp8_stream_info_t si;
   int decoder_init;
+#if CONFIG_MULTITHREAD
+  // Restart threads on next frame if set to 1.
+  // This is set when error happens in multithreaded decoding and all threads
+  // are shut down.
+  int restart_threads;
+#endif
   int postproc_cfg_set;
   vp8_postproc_cfg_t postproc_cfg;
   vpx_decrypt_cb decrypt_cb;
@@ -268,7 +274,7 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
                                   const uint8_t *data, unsigned int data_sz,
                                   void *user_priv, long deadline) {
   volatile vpx_codec_err_t res;
-  unsigned int resolution_change = 0;
+  volatile unsigned int resolution_change = 0;
   unsigned int w, h;
 
   if (!ctx->fragments.enabled && (data == NULL && data_sz == 0)) {
@@ -298,6 +304,27 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
 
   if ((ctx->si.h != h) || (ctx->si.w != w)) resolution_change = 1;
 
+#if CONFIG_MULTITHREAD
+  if (!res && ctx->restart_threads) {
+    struct frame_buffers *fb = &ctx->yv12_frame_buffers;
+    VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0];
+    VP8_COMMON *const pc = &pbi->common;
+    if (setjmp(pbi->common.error.jmp)) {
+      vp8_remove_decoder_instances(fb);
+      vp8_zero(fb->pbi);
+      vpx_clear_system_state();
+      return VPX_CODEC_ERROR;
+    }
+    pbi->common.error.setjmp = 1;
+    pbi->max_threads = ctx->cfg.threads;
+    vp8_decoder_create_threads(pbi);
+    if (vpx_atomic_load_acquire(&pbi->b_multithreaded_rd)) {
+      vp8mt_alloc_temp_buffers(pbi, pc->Width, pc->mb_rows);
+    }
+    ctx->restart_threads = 0;
+    pbi->common.error.setjmp = 0;
+  }
+#endif
   /* Initialize the decoder instance on the first frame*/
   if (!res && !ctx->decoder_init) {
     VP8D_CONFIG oxcf;
@@ -439,9 +466,13 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
         pc->fb_idx_ref_cnt[pc->new_fb_idx]--;
       }
       pc->error.setjmp = 0;
-      ctx->si.w = 0;
-      ctx->si.h = 0;
-      ctx->decoder_init = 0;
+#if CONFIG_MULTITHREAD
+      if (pbi->restart_threads) {
+        ctx->si.w = 0;
+        ctx->si.h = 0;
+        ctx->restart_threads = 1;
+      }
+#endif
       res = update_error_state(ctx, &pbi->common.error);
       return res;
     }
@@ -450,7 +481,9 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
 
     /* update the pbi fragment data */
     pbi->fragments = ctx->fragments;
-
+#if CONFIG_MULTITHREAD
+    pbi->restart_threads = 0;
+#endif
     ctx->user_priv = user_priv;
     if (vp8dx_receive_compressed_data(pbi, data_sz, data, deadline)) {
       res = update_error_state(ctx, &pbi->common.error);