Commit c62c07d3 authored by Michael Niedermayer's avatar Michael Niedermayer

multithreaded mpeg2 decoding

Originally committed as revision 2810 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent c0a2c42f
...@@ -2256,6 +2256,11 @@ static void opt_input_file(const char *filename) ...@@ -2256,6 +2256,11 @@ static void opt_input_file(const char *filename)
/* update the current parameters so that they match the one of the input stream */ /* update the current parameters so that they match the one of the input stream */
for(i=0;i<ic->nb_streams;i++) { for(i=0;i<ic->nb_streams;i++) {
AVCodecContext *enc = &ic->streams[i]->codec; AVCodecContext *enc = &ic->streams[i]->codec;
#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
#endif
enc->thread_count= thread_count;
switch(enc->codec_type) { switch(enc->codec_type) {
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
//fprintf(stderr, "\nInput Audio channels: %d", enc->channels); //fprintf(stderr, "\nInput Audio channels: %d", enc->channels);
......
...@@ -168,6 +168,7 @@ static int64_t start_time = AV_NOPTS_VALUE; ...@@ -168,6 +168,7 @@ static int64_t start_time = AV_NOPTS_VALUE;
static int debug = 0; static int debug = 0;
static int debug_mv = 0; static int debug_mv = 0;
static int step = 0; static int step = 0;
static int thread_count = 1;
/* current context */ /* current context */
static int is_full_screen; static int is_full_screen;
...@@ -1169,6 +1170,12 @@ static int stream_component_open(VideoState *is, int stream_index) ...@@ -1169,6 +1170,12 @@ static int stream_component_open(VideoState *is, int stream_index)
if (!codec || if (!codec ||
avcodec_open(enc, codec) < 0) avcodec_open(enc, codec) < 0)
return -1; return -1;
enc->debug = debug;
#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
#endif
enc->thread_count= thread_count;
switch(enc->codec_type) { switch(enc->codec_type) {
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
is->audio_stream = stream_index; is->audio_stream = stream_index;
...@@ -1197,7 +1204,6 @@ static int stream_component_open(VideoState *is, int stream_index) ...@@ -1197,7 +1204,6 @@ static int stream_component_open(VideoState *is, int stream_index)
packet_queue_init(&is->videoq); packet_queue_init(&is->videoq);
is->video_tid = SDL_CreateThread(video_thread, is); is->video_tid = SDL_CreateThread(video_thread, is);
enc->debug = debug;
enc->debug_mv = debug_mv; enc->debug_mv = debug_mv;
break; break;
default: default:
...@@ -1794,6 +1800,14 @@ static void opt_vismv(const char *arg) ...@@ -1794,6 +1800,14 @@ static void opt_vismv(const char *arg)
debug_mv = atoi(arg); debug_mv = atoi(arg);
} }
static void opt_thread_count(const char *arg)
{
thread_count= atoi(arg);
#if !defined(HAVE_PTHREADS) && !defined(HAVE_W32THREADS)
fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
#endif
}
const OptionDef options[] = { const OptionDef options[] = {
{ "h", 0, {(void*)show_help}, "show help" }, { "h", 0, {(void*)show_help}, "show help" },
{ "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" }, { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" },
...@@ -1814,7 +1828,8 @@ const OptionDef options[] = { ...@@ -1814,7 +1828,8 @@ const OptionDef options[] = {
#ifdef CONFIG_NETWORK #ifdef CONFIG_NETWORK
{ "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" }, { "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" },
#endif #endif
{ "sync", HAS_ARG | OPT_EXPERT, {(void*)&opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" }, { "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" },
{ "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
{ NULL, }, { NULL, },
}; };
......
...@@ -652,7 +652,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en ...@@ -652,7 +652,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en
s->error_status_table[start_xy] |= VP_START; s->error_status_table[start_xy] |= VP_START;
if(start_xy > 0){ if(start_xy > 0 && s->avctx->thread_count <= 1){
int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ]; int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
prev_status &= ~ VP_START; prev_status &= ~ VP_START;
......
This diff is collapsed.
...@@ -468,13 +468,17 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){ ...@@ -468,13 +468,17 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){
#undef COPY #undef COPY
} }
static void update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){
MpegEncContext bak; MpegEncContext bak;
int i;
//FIXME copy only needed parts //FIXME copy only needed parts
//START_TIMER //START_TIMER
backup_duplicate_context(&bak, dst); backup_duplicate_context(&bak, dst);
memcpy(dst, src, sizeof(MpegEncContext)); memcpy(dst, src, sizeof(MpegEncContext));
backup_duplicate_context(dst, &bak); backup_duplicate_context(dst, &bak);
for(i=0;i<12;i++){
dst->pblocks[i] = (short *)(&dst->block[i]);
}
//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads //STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads
} }
...@@ -4632,7 +4636,7 @@ static void encode_picture(MpegEncContext *s, int picture_number) ...@@ -4632,7 +4636,7 @@ static void encode_picture(MpegEncContext *s, int picture_number)
s->mb_intra=0; //for the rate distoration & bit compare functions s->mb_intra=0; //for the rate distoration & bit compare functions
for(i=1; i<s->avctx->thread_count; i++){ for(i=1; i<s->avctx->thread_count; i++){
update_duplicate_context(s->thread_context[i], s); ff_update_duplicate_context(s->thread_context[i], s);
} }
/* Estimate motion for every MB */ /* Estimate motion for every MB */
......
...@@ -736,6 +736,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict); ...@@ -736,6 +736,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix); void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix);
int ff_find_unused_picture(MpegEncContext *s, int shared); int ff_find_unused_picture(MpegEncContext *s, int shared);
void ff_denoise_dct(MpegEncContext *s, DCTELEM *block); void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
void ff_er_frame_start(MpegEncContext *s); void ff_er_frame_start(MpegEncContext *s);
void ff_er_frame_end(MpegEncContext *s); void ff_er_frame_end(MpegEncContext *s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment