Commit afebe2f7 authored by Andreas Öman's avatar Andreas Öman Committed by Guillaume Poirier

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

Originally committed as revision 10407 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent e146ce52
This diff is collapsed.
......@@ -380,6 +380,35 @@ typedef struct H264Context{
const uint8_t *field_scan8x8_cavlc_q0;
int x264_build;
/**
* @defgroup multithreading Members for slice based multithreading
* @{
*/
struct H264Context *thread_context[MAX_THREADS];
/**
* current slice number, used to initalize slice_num of each thread/context
*/
int current_slice;
/**
* Max number of threads / contexts.
* This is equal to AVCodecContext.thread_count unless
* multithreaded decoding is impossible, in which case it is
* reduced to 1.
*/
int max_contexts;
/**
* 1 if the single thread fallback warning has already been
* displayed, 0 otherwise.
*/
int single_decode_warning;
int last_slice_type;
/** @} */
}H264Context;
#endif /* H264_H */
......@@ -418,7 +418,7 @@ void MPV_decode_defaults(MpegEncContext *s){
*/
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 @@ int MPV_common_init(MpegEncContext *s)
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;
......
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