diff mpegvideo.c @ 5642:d2598034f2a9 libavcodec

Add slice-based parallel H.264 decoding Patch by Andreas ªÓman % andreas A olebyn P nu % NB: depends on having a thread library activated at config time, and on having a source encoded with multiple slices Original threads: date: May 18, 2007 11:00 PM subject: [FFmpeg-devel] Parallelized h264 proof-of-concept date: Jun 15, 2007 10:10 PM subject: [FFmpeg-devel] [PATCH] h264 parallelized, (was: Parallelized h264 proof-of-concept) date: Jun 25, 2007 7:02 PM subject: Re: [FFmpeg-devel] [PATCH] h264 parallelized
author gpoirier
date Wed, 05 Sep 2007 16:18:15 +0000
parents 0e4860e1beb6
children 1766e8863911
line wrap: on
line diff
--- a/mpegvideo.c	Wed Sep 05 11:05:33 2007 +0000
+++ b/mpegvideo.c	Wed Sep 05 16:18:15 2007 +0000
@@ -418,7 +418,7 @@
  */
 int MPV_common_init(MpegEncContext *s)
 {
-    int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
+    int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads;
 
     s->mb_height = (s->height + 15) / 16;
 
@@ -587,12 +587,16 @@
     s->context_initialized = 1;
 
     s->thread_context[0]= s;
-    for(i=1; i<s->avctx->thread_count; i++){
+    /* h264 does thread context setup itself, but it needs context[0]
+     * to be fully initialized for the error resilience code */
+    threads = s->codec_id == CODEC_ID_H264 ? 1 : s->avctx->thread_count;
+
+    for(i=1; i<threads; i++){
         s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
         memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
     }
 
-    for(i=0; i<s->avctx->thread_count; i++){
+    for(i=0; i<threads; i++){
         if(init_duplicate_context(s->thread_context[i], s) < 0)
            goto fail;
         s->thread_context[i]->start_mb_y= (s->mb_height*(i  ) + s->avctx->thread_count/2) / s->avctx->thread_count;