[FFmpeg-soc] [PATCH 9/9] Enable multithreading for Mimic.

Alexander Strange astrange at ithinksw.com
Thu May 29 05:59:28 CEST 2008


---
  libavcodec/mimic.c |   39 +++++++++++++++++++++++++++++++--------
  1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c
index 530692a..6a9e536 100644
--- a/libavcodec/mimic.c
+++ b/libavcodec/mimic.c
@@ -27,6 +27,7 @@
  #include "bitstream.h"
  #include "bytestream.h"
  #include "dsputil.h"
+#include "thread.h"

  #define MIMIC_HEADER_SIZE   20

@@ -124,6 +125,21 @@ static av_cold int  
mimic_decode_init(AVCodecContext *avctx)
      return 0;
  }

+static int mimic_decode_update_context(AVCodecContext *avctx,  
AVCodecContext *avctx_from)
+{
+    MimicContext *ctx = avctx->priv_data, *src = avctx_from->priv_data;
+
+    ctx->cur_index = src->next_cur_index;
+    ctx->prev_index = src->next_prev_index;
+
+    memcpy(ctx->buf_ptrs, src->buf_ptrs, sizeof(src->buf_ptrs));
+    memcpy(ctx->flipped_ptrs, src->flipped_ptrs, sizeof(src- 
 >flipped_ptrs));
+
+    memset(&ctx->buf_ptrs[ctx->cur_index], 0, sizeof(AVFrame));
+
+    return 0;
+}
+
  const static int8_t vlcdec_lookup[9][64] = {
      {    0, },
      {   -1,   1, },
@@ -208,7 +224,7 @@ static int vlc_decode_block(MimicContext *ctx, int  
num_coeffs, int qscale)
  static int decode(MimicContext *ctx, int quality, int num_coeffs,
                    int is_iframe)
  {
-    int y, x, plane;
+    int y, x, plane, cur_row = 0;

      for(plane = 0; plane < 3; plane++) {
          const int is_chroma = !!plane;
@@ -239,6 +255,7 @@ static int decode(MimicContext *ctx, int quality,  
int num_coeffs,
                          int index = (ctx->cur_index+backref)&15;
                          uint8_t *p = ctx->flipped_ptrs[index].data[0];

+                        ff_await_decode_progress(&ctx- 
 >buf_ptrs[index], cur_row);
                          if(p) {
                              p += src -
                                  ctx->flipped_ptrs[ctx- 
 >prev_index].data[plane];
@@ -249,6 +266,7 @@ static int decode(MimicContext *ctx, int quality,  
int num_coeffs,
                          }
                      }
                  } else {
+                    ff_await_decode_progress(&ctx->buf_ptrs[ctx- 
 >prev_index], cur_row);
                      ctx->dsp.put_pixels_tab[1][0](dst, src, stride,  
8);
                  }
                  src += 8;
@@ -256,6 +274,8 @@ static int decode(MimicContext *ctx, int quality,  
int num_coeffs,
              }
              src += (stride - ctx->num_hblocks[plane])<<3;
              dst += (stride - ctx->num_hblocks[plane])<<3;
+
+            ff_report_decode_progress(&ctx->buf_ptrs[ctx->cur_index],  
cur_row++);
          }
      }

@@ -327,7 +347,7 @@ static int mimic_decode_frame(AVCodecContext  
*avctx, void *data,
      }

      ctx->buf_ptrs[ctx->cur_index].reference = 1;
-    if(avctx->get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) {
+    if(ff_mt_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) {
          av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
          return -1;
      }
@@ -339,6 +359,8 @@ static int mimic_decode_frame(AVCodecContext  
*avctx, void *data,
      prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index],
                    (AVPicture*) &ctx->buf_ptrs[ctx->cur_index]);

+    ff_report_predecode_done(avctx);
+
      ctx->swap_buf = av_fast_realloc(ctx->swap_buf, &ctx- 
 >swap_buf_size,
                                   swap_buf_size +  
FF_INPUT_BUFFER_PADDING_SIZE);
      if(!ctx->swap_buf)
@@ -350,7 +372,7 @@ static int mimic_decode_frame(AVCodecContext  
*avctx, void *data,
      init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3);

      if(!decode(ctx, quality, num_coeffs, !is_pframe)) {
-        avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
+        ff_mt_release_buffer(&ctx->buf_ptrs[ctx->cur_index]);
          return -1;
      }

@@ -363,7 +385,7 @@ static int mimic_decode_frame(AVCodecContext  
*avctx, void *data,

      /* Only release frames that aren't used for backreferences  
anymore */
      if(ctx->buf_ptrs[ctx->cur_index].data[0])
-        avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
+        ff_mt_release_buffer(&ctx->buf_ptrs[ctx->cur_index]);

      return buf_size;
  }
@@ -375,9 +397,9 @@ static av_cold int mimic_decode_end(AVCodecContext  
*avctx)

      av_free(ctx->swap_buf);
      for(i = 0; i < 16; i++)
-        if(ctx->buf_ptrs[i].data[0])
-            avctx->release_buffer(avctx, &ctx->buf_ptrs[i]);
-    free_vlc(&ctx->vlc);
+        if(ctx->buf_ptrs[i].data[0] && avctx == ctx->buf_ptrs[i].avctx)
+            ff_mt_release_buffer(&ctx->buf_ptrs[i]);
+    if (!avctx->is_copy) free_vlc(&ctx->vlc);

      return 0;
  }
@@ -391,6 +413,7 @@ AVCodec mimic_decoder = {
      NULL,
      mimic_decode_end,
      mimic_decode_frame,
-    CODEC_CAP_DR1,
+    CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
      .long_name = "Mimic",
+    .update_context = mimic_decode_update_context
  };
-- 
1.5.5.1





More information about the FFmpeg-soc mailing list