comparison 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
comparison
equal deleted inserted replaced
5641:1e93e637fa21 5642:d2598034f2a9
416 * init common structure for both encoder and decoder. 416 * init common structure for both encoder and decoder.
417 * this assumes that some variables like width/height are already set 417 * this assumes that some variables like width/height are already set
418 */ 418 */
419 int MPV_common_init(MpegEncContext *s) 419 int MPV_common_init(MpegEncContext *s)
420 { 420 {
421 int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; 421 int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads;
422 422
423 s->mb_height = (s->height + 15) / 16; 423 s->mb_height = (s->height + 15) / 16;
424 424
425 if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){ 425 if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){
426 av_log(s->avctx, AV_LOG_ERROR, "too many threads\n"); 426 av_log(s->avctx, AV_LOG_ERROR, "too many threads\n");
585 } 585 }
586 586
587 s->context_initialized = 1; 587 s->context_initialized = 1;
588 588
589 s->thread_context[0]= s; 589 s->thread_context[0]= s;
590 for(i=1; i<s->avctx->thread_count; i++){ 590 /* h264 does thread context setup itself, but it needs context[0]
591 * to be fully initialized for the error resilience code */
592 threads = s->codec_id == CODEC_ID_H264 ? 1 : s->avctx->thread_count;
593
594 for(i=1; i<threads; i++){
591 s->thread_context[i]= av_malloc(sizeof(MpegEncContext)); 595 s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
592 memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); 596 memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
593 } 597 }
594 598
595 for(i=0; i<s->avctx->thread_count; i++){ 599 for(i=0; i<threads; i++){
596 if(init_duplicate_context(s->thread_context[i], s) < 0) 600 if(init_duplicate_context(s->thread_context[i], s) < 0)
597 goto fail; 601 goto fail;
598 s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; 602 s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count;
599 s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; 603 s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count;
600 } 604 }