summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo_enc.c
diff options
context:
space:
mode:
authorAlexander Strange <astrange@ithinksw.com>2011-06-02 10:15:58 -0700
committerRonald S. Bultje <rsbultje@gmail.com>2011-06-02 10:16:20 -0700
commit6a9c85944427e3c4355bce67d7f677ec69527bff (patch)
treedf4bb83f820a5c0295485ca8b7751c4063d5165f /libavcodec/mpegvideo_enc.c
parent53be7b23e9d7074d1aeee77407b008411d034e9e (diff)
H264/MPEG frame-level multi-threading.
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r--libavcodec/mpegvideo_enc.c24
1 files changed, 13 insertions, 11 deletions
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; i<avctx->thread_count; i++){
+ for(i=0; i<context_count; i++){
int start_y= s->thread_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; i<avctx->thread_count; i++){
+ for(i=0; i<context_count; i++){
PutBitContext *pb= &s->thread_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; i<s->avctx->thread_count; i++){
+ for(i=1; i<context_count; i++){
ff_update_duplicate_context(s->thread_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; i<s->mb_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; i<s->avctx->thread_count; i++){
+ for(i=1; i<context_count; i++){
merge_context_after_me(s, s->thread_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; i<s->avctx->thread_count; i++){
+ for(i=1; i<context_count; i++){
update_duplicate_context_after_me(s->thread_context[i], s);
}
- s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*));
- for(i=1; i<s->avctx->thread_count; i++){
+ s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
+ for(i=1; i<context_count; i++){
merge_context_after_encode(s, s->thread_context[i]);
}
emms_c();