diff -uNrp c/common/common.c b/common/common.c --- c/common/common.c 2008-09-25 17:44:51 +0300 +++ b/common/common.c 2008-09-25 17:45:50 +0300 @@ -44,6 +44,8 @@ void x264_param_default( x264_param_t /* CPU autodetect */ param->cpu = x264_cpu_detect(); param->i_threads = 1; + param->i_threads_boost = 0; + param->i_thread_input_boost = 0; param->b_deterministic = 1; /* Video properties */ @@ -267,6 +269,14 @@ int x264_param_parse( x264_param_t *p, c else p->i_threads = atoi(value); } + OPT("threads-boost") + { + p->i_threads_boost = atoi(value); + } + OPT("thread-input-boost") + { + p->i_thread_input_boost = atoi(value); + } OPT("thread-queue") { if( !strcmp(value, "auto") ) diff -uNrp c/encoder/encoder.c b/encoder/encoder.c --- c/encoder/encoder.c 2008-09-25 17:44:51 +0300 +++ b/encoder/encoder.c 2008-09-25 17:46:09 +0300 @@ -385,6 +385,8 @@ static int x264_validate_parameters( x26 return -1; } + h->param.i_threads_boost = x264_clip3( h->param.i_threads_boost, -2, 2 ); + h->param.i_thread_input_boost = x264_clip3( h->param.i_thread_input_boost, -2, 2 ); if( h->param.i_threads == 0 ) h->param.i_threads = x264_cpu_num_processors() * 3/2; h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_THREAD_MAX ); @@ -833,8 +835,15 @@ x264_t *x264_encoder_open ( x264_param if( h->param.i_threads > 1 ) { + pthread_attr_t t_attr; + struct sched_param prio; + prio.sched_priority = h->param.i_threads_boost; + + pthread_attr_init(&t_attr); + pthread_attr_setschedparam(&t_attr, &prio); + for( i = 0; i < h->param.i_threads; i++ ) - x264_pthread_create( &h->thread_handle[i], NULL, (void*)x264_slices_write_thread, h ); + x264_pthread_create( &h->thread_handle[i], &t_attr, (void*)x264_slices_write_thread, h ); } return h; diff -uNrp c/muxers.c b/muxers.c --- c/muxers.c 2008-09-25 17:44:26 +0300 +++ b/muxers.c 2008-09-25 17:46:53 +0300 @@ -429,6 +429,7 @@ typedef struct { int frame_total; int in_progress; struct thread_input_arg_t *next_args; + int priority; } thread_input_t; typedef struct thread_input_arg_t { @@ -442,6 +443,7 @@ int open_file_thread( char *psz_filename { thread_input_t *h = malloc(sizeof(thread_input_t)); x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height ); + h->priority = p_param->i_thread_input_boost; h->p_read_frame = p_read_frame; h->p_close_infile = p_close_infile; h->p_handle = *p_handle; @@ -494,7 +496,14 @@ int read_frame_thread( x264_picture_t *p h->next_frame = h->next_args->i_frame = i_frame+1; h->next_args->pic = &h->pic; - x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args ); + + pthread_attr_t t_attr; + struct sched_param prio; + prio.sched_priority = h->priority; + pthread_attr_init(&t_attr); + pthread_attr_setschedparam(&t_attr, &prio); + + x264_pthread_create( &h->tid, &t_attr, (void*)read_frame_thread_int, h->next_args ); h->in_progress = 1; } else diff -uNrp c/x264.c b/x264.c --- c/x264.c 2008-09-25 17:44:51 +0300 +++ b/x264.c 2008-09-25 17:47:30 +0300 @@ -326,8 +326,17 @@ static void Help( x264_param_t *defaults H0( " --no-psnr Disable PSNR computation\n" ); H0( " --no-ssim Disable SSIM computation\n" ); H0( " --threads Parallel encoding\n" ); + H1( " --threads-boost Tune priority for encoding threads [%d]\n" + " -2: LOWEST\n" + " -1: BELOW_NORMAL\n" + " 0: NORMAL\n" + " 1: ABOVE_NORMAL\n" + " 2: HIGHEST\n", + defaults->i_threads_boost ); H1( " --thread-queue Number of delay frames for thread sync\n" ); H0( " --thread-input Run Avisynth in its own thread\n" ); + H1( " --thread-input-boost Tune priority for input thread (Values as in 'threads-boost') [%d]\n", + defaults->i_thread_input_boost ); H1( " --non-deterministic Slightly improve quality of SMP, at the cost of repeatability\n" ); H1( " --asm Override CPU detection\n" ); H1( " --no-asm Disable all CPU optimizations\n" ); @@ -454,6 +463,8 @@ static int Parse( int argc, char **argv { "zones", required_argument, NULL, 0 }, { "qpfile", required_argument, NULL, OPT_QPFILE }, { "threads", required_argument, NULL, 0 }, + { "threads-boost", required_argument, NULL, 0 }, + { "thread-input-boost", required_argument, NULL, 0 }, { "thread-queue", required_argument, NULL, 0 }, { "thread-input", no_argument, NULL, OPT_THREAD_INPUT }, { "non-deterministic", no_argument, NULL, 0 }, diff -uNrp c/x264.h b/x264.h --- c/x264.h 2008-09-25 17:44:51 +0300 +++ b/x264.h 2008-09-25 17:47:43 +0300 @@ -151,6 +151,8 @@ typedef struct x264_param_t /* CPU flags */ unsigned int cpu; int i_threads; /* encode multiple frames in parallel */ + int i_threads_boost; /* priority of encoding threads */ + int i_thread_input_boost; /* priority of input thread */ int i_thread_queue; /* number of frames to prepare in advance (>= i_threads) */ int b_deterministic; /* whether to allow non-deterministic optimizations when threaded */