34 #if HAVE_SCHED_GETAFFINITY
40 #if HAVE_GETPROCESSAFFINITYMASK
45 #include <sys/param.h>
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <sys/sysctl.h>
90 #define MAX_BUFFERS (34+1)
165 #define MAX_AUTO_THREADS 16
169 int ret, nb_cpus = 1;
170 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
175 ret = sched_getaffinity(0,
sizeof(cpuset), &cpuset);
177 nb_cpus = CPU_COUNT(&cpuset);
179 #elif HAVE_GETPROCESSAFFINITYMASK
180 DWORD_PTR proc_aff, sys_aff;
181 ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff);
183 nb_cpus = av_popcount64(proc_aff);
184 #elif HAVE_SYSCTL && defined(HW_NCPU)
185 int mib[2] = { CTL_HW, HW_NCPU };
186 size_t len =
sizeof(nb_cpus);
188 ret = sysctl(mib, 2, &nb_cpus, &len,
NULL, 0);
191 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
192 nb_cpus = sysconf(_SC_NPROC_ONLN);
193 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
194 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
210 int last_execute = 0;
234 c->
func2(avctx, c->
args, our_job, self_id);
290 c->
rets = &dummy_ret;
323 if (thread_count <= 1) {
347 for (i=0; i<thread_count; i++) {
380 while (p->
state == STATE_INPUT_READY && !fctx->
die)
383 if (fctx->
die)
break;
404 p->
state = STATE_INPUT_READY;
475 #define copy_fields(s, e) memcpy(&dst->s, &src->s, (char*)&dst->e - (char*)&dst->s);
554 if (prev_thread->
state == STATE_SETTING_UP) {
556 while (prev_thread->
state == STATE_SETTING_UP)
571 memcpy(buf, avpkt->
data, avpkt->
size);
574 p->
state = STATE_SETTING_UP;
586 while (p->
state != STATE_SETUP_FINISHED && p->
state != STATE_INPUT_READY) {
588 while (p->
state == STATE_SETTING_UP)
591 if (p->
state == STATE_GET_BUFFER) {
593 p->
state = STATE_SETTING_UP;
607 AVFrame *picture,
int *got_picture_ptr,
645 p = &fctx->
threads[finished++];
647 if (p->
state != STATE_INPUT_READY) {
649 while (p->
state != STATE_INPUT_READY)
684 if (!progress || progress[field] >= n)
return;
702 if (!progress || progress[field] >= n)
return;
710 while (progress[field] < n)
720 if(p->
state == STATE_SETUP_FINISHED){
725 p->
state = STATE_SETUP_FINISHED;
735 for (i = 0; i < thread_count; i++) {
738 if (p->
state != STATE_INPUT_READY) {
740 while (p->
state != STATE_INPUT_READY)
761 for (i = 0; i < thread_count; i++) {
780 for (i = 0; i < thread_count; i++) {
825 if (thread_count <= 1) {
836 for (i = 0; i < thread_count; i++) {
862 err = codec->
init(copy);
934 if (i == MAX_BUFFERS) {
959 volatile int *progress;
970 if (p->
state != STATE_SETTING_UP &&
973 av_log(avctx,
AV_LOG_ERROR,
"get_buffer() cannot be called after ff_thread_finish_setup()\n");
994 p->
state = STATE_GET_BUFFER;
997 while (p->
state != STATE_SETTING_UP)
1039 memset(f->
data, 0,
sizeof(f->
data));
1071 "Application has requested %d threads. Using a thread count greater than %d is not recommended.\n",