Index: mpcommon.h =================================================================== --- mpcommon.h (版本 23698) +++ mpcommon.h (工作副本) @@ -5,3 +5,4 @@ extern sub_data *subdata; extern subtitle *vo_sub_last; void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset); +unsigned get_num_processors(void); Index: mpcommon.c =================================================================== --- mpcommon.c (版本 23698) +++ mpcommon.c (工作副本) @@ -1,4 +1,18 @@ #include + +#if defined(WIN32) +#include +#elif defined(SYS_LINUX) +#include +#elif defined(SYS_BEOS) +#include +#elif defined(SYS_MACOSX) +#include +#include +#elif defined(sun) +#include +#endif + #include "stream/stream.h" #include "libmpdemux/demuxer.h" #include "libmpdemux/stheader.h" @@ -138,3 +152,37 @@ } current_module=NULL; } + +static unsigned popcnt(unsigned n) +{ + unsigned ret, i; + for (ret = 0, i = 0; i < sizeof(n) * 8; i++) + ret += (n >> i) & 1; + return ret; +} + +unsigned get_num_processors(void) +{ + unsigned ret = 1; +#if defined(WIN32) + DWORD proc, sys; + if (GetProcessAffinityMask(GetCurrentProcess(), &proc, &sys)) + ret = popcnt(proc); +#elif defined(SYS_LINUX) + cpu_set_t aff; + if (sched_getaffinity(0, sizeof(aff), &aff) != -1) + ret = popcnt(aff); +#elif defined(SYS_BEOS) + system_info info; + get_system_info(&info); + ret = info.cpu_count; +#elif defined(SYS_MACOSX) + size_t len = sizeof(ret); + if (sysctlbyname("hw.ncpu", &ret, &len, NULL, 0)) + ret = 1; +#elif defined(sun) + ret = sysconf(_SC_NPROCESSORS_CONF); +#endif + return ret; +} + Index: libmpcodecs/vd_ffmpeg.c =================================================================== --- libmpcodecs/vd_ffmpeg.c (版本 23698) +++ libmpcodecs/vd_ffmpeg.c (工作副本) @@ -88,7 +89,7 @@ static char *lavc_param_skip_loop_filter_str = NULL; static char *lavc_param_skip_idct_str = NULL; static char *lavc_param_skip_frame_str = NULL; -static int lavc_param_threads=1; +static int lavc_param_threads=0; static int lavc_param_bitexact=0; m_option_t lavc_decode_opts_conf[]={ @@ -109,7 +110,7 @@ {"skiploopfilter", &lavc_param_skip_loop_filter_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"skipidct", &lavc_param_skip_idct_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"skipframe", &lavc_param_skip_frame_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL}, + {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 0, 8, NULL}, {"bitexact", &lavc_param_bitexact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL}, {NULL, NULL, 0, 0, 0, 0, NULL} }; @@ -402,6 +403,8 @@ if(sh->bih) avctx->bits_per_sample= sh->bih->biBitCount; + if(lavc_param_threads == 0) + lavc_param_threads = get_num_processors(); if(lavc_param_threads > 1) avcodec_thread_init(avctx, lavc_param_threads); /* open it */ Index: libmpcodecs/ve_lavc.c =================================================================== --- libmpcodecs/ve_lavc.c (版本 23698) +++ libmpcodecs/ve_lavc.c (工作副本) @@ -141,7 +141,7 @@ static int lavc_param_nssew= 8; static int lavc_param_closed_gop = 0; static int lavc_param_dc_precision = 8; -static int lavc_param_threads= 1; +static int lavc_param_threads= 0; static int lavc_param_turbo = 0; static int lavc_param_brd_scale = 0; static int lavc_param_bidir_refine = 0; @@ -285,7 +285,7 @@ {"top", &lavc_param_top, CONF_TYPE_INT, CONF_RANGE, -1, 1, NULL}, {"qns", &lavc_param_qns, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL}, {"nssew", &lavc_param_nssew, CONF_TYPE_INT, CONF_RANGE, 0, 1000000, NULL}, - {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL}, + {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 0, 8, NULL}, {"turbo", &lavc_param_turbo, CONF_TYPE_FLAG, 0, 0, 1, NULL}, {"brd_scale", &lavc_param_brd_scale, CONF_TYPE_INT, CONF_RANGE, 0, 10, NULL}, {"bidir_refine", &lavc_param_bidir_refine, CONF_TYPE_INT, CONF_RANGE, 0, 4, NULL}, @@ -663,6 +663,8 @@ vf->priv->pic->quality = (int)(FF_QP2LAMBDA * lavc_param_vqscale + 0.5); } + if(lavc_param_threads == 0) + lavc_param_threads = get_num_processors(); if(lavc_param_threads > 1) avcodec_thread_init(lavc_venc_context, lavc_param_threads); Index: DOCS/man/en/mplayer.1 =================================================================== --- DOCS/man/en/mplayer.1 (版本 23698) +++ DOCS/man/en/mplayer.1 (工作副本) @@ -4246,8 +4246,8 @@ Skips decoding of frames completely. Big speedup, but jerky motion and sometimes bad artifacts (see skiploopfilter for available skip values). -.IPs "threads=<1\-8> (MPEG-1/2 only)" -number of threads to use for decoding (default: 1) +.IPs "threads=<0\-8> (MPEG-1/2 only)" +number of threads to use for decoding, 0 for autodetect (default) .IPs vismv= Visualize motion vectors. .RSss @@ -7242,8 +7242,8 @@ Do not use this option unless you know exactly what you are doing. . .TP -.B threads=<1\-8> -Maximum number of threads to use (default: 1). +.B threads=<0\-8> +Maximum number of threads to use, 0 for autodetect (default). May have a slight negative effect on motion estimation. .RE .