From 6a9c85944427e3c4355bce67d7f677ec69527bff Mon Sep 17 00:00:00 2001 From: Alexander Strange Date: Thu, 2 Jun 2011 10:15:58 -0700 Subject: H264/MPEG frame-level multi-threading. Signed-off-by: Ronald S. Bultje --- libavcodec/mpegvideo_enc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'libavcodec/mpegvideo_enc.c') diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index a212149189..237ea64790 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -36,6 +36,7 @@ #include "mjpegenc.h" #include "msmpeg4.h" #include "faandct.h" +#include "thread.h" #include "aandcttab.h" #include "flv.h" #include "mpeg4video.h" @@ -1225,9 +1226,9 @@ int MPV_encode_picture(AVCodecContext *avctx, { MpegEncContext *s = avctx->priv_data; AVFrame *pic_arg = data; - int i, stuffing_count; + int i, stuffing_count, context_count = avctx->active_thread_type&FF_THREAD_SLICE ? avctx->thread_count : 1; - for(i=0; ithread_count; i++){ + for(i=0; ithread_context[i]->start_mb_y; int end_y= s->thread_context[i]-> end_mb_y; int h= s->mb_height; @@ -1291,7 +1292,7 @@ vbv_retry: s->last_non_b_time= s->time - s->pp_time; } // av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); - for(i=0; ithread_count; i++){ + for(i=0; ithread_context[i]->pb; init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); } @@ -2758,6 +2759,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) { int i; int bits; + int context_count = (s->avctx->active_thread_type & FF_THREAD_SLICE) ? s->avctx->thread_count : 1; s->picture_number = picture_number; @@ -2797,7 +2799,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) } s->mb_intra=0; //for the rate distortion & bit compare functions - for(i=1; iavctx->thread_count; i++){ + for(i=1; ithread_context[i], s); } @@ -2810,11 +2812,11 @@ static int encode_picture(MpegEncContext *s, int picture_number) s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; if(s->pict_type != AV_PICTURE_TYPE_B && s->avctx->me_threshold==0){ if((s->avctx->pre_me && s->last_non_b_pict_type==AV_PICTURE_TYPE_I) || s->avctx->pre_me==2){ - s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } } - s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); }else /* if(s->pict_type == AV_PICTURE_TYPE_I) */{ /* I-Frame */ for(i=0; imb_stride*s->mb_height; i++) @@ -2822,10 +2824,10 @@ static int encode_picture(MpegEncContext *s, int picture_number) if(!s->fixed_qscale){ /* finding spatial complexity for I-frame rate control */ - s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); } } - for(i=1; iavctx->thread_count; i++){ + for(i=1; ithread_context[i]); } s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; @@ -2961,11 +2963,11 @@ static int encode_picture(MpegEncContext *s, int picture_number) bits= put_bits_count(&s->pb); s->header_bits= bits - s->last_bits; - for(i=1; iavctx->thread_count; i++){ + for(i=1; ithread_context[i], s); } - s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); - for(i=1; iavctx->thread_count; i++){ + s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + for(i=1; ithread_context[i]); } emms_c(); -- cgit v1.2.3