MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ff_slice_thread_init

Function ff_slice_thread_init

libavcodec/pthread_slice.c:112–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112av_cold int ff_slice_thread_init(AVCodecContext *avctx)
113{
114 SliceThreadContext *c;
115 int thread_count = avctx->thread_count;
116 void (*mainfunc)(void *);
117
118 if (!thread_count) {
119 int nb_cpus = av_cpu_count();
120 if (avctx->height)
121 nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);
122 // use number of cores + 1 as thread count if there is more than one
123 if (nb_cpus > 1)
124 thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
125 else
126 thread_count = avctx->thread_count = 1;
127 }
128
129 if (thread_count <= 1) {
130 avctx->active_thread_type = 0;
131 return 0;
132 }
133
134 avctx->internal->thread_ctx = c = av_mallocz(sizeof(*c));
135 if (!c)
136 return AVERROR(ENOMEM);
137 mainfunc = ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SLICE_THREAD_HAS_MF ? &main_function : NULL;
138 thread_count = avpriv_slicethread_create(&c->thread, avctx, worker_func,
139 mainfunc, thread_count);
140 if (thread_count <= 1) {
141 ff_slice_thread_free(avctx);
142 avctx->thread_count = 1;
143 avctx->active_thread_type = 0;
144 return thread_count < 0 ? thread_count : 0;
145 }
146 avctx->thread_count = thread_count;
147
148 avctx->execute = thread_execute;
149 avctx->execute2 = thread_execute2;
150 return 0;
151}

Callers 1

ff_thread_initFunction · 0.85

Calls 5

av_cpu_countFunction · 0.85
ffcodecFunction · 0.85
ff_slice_thread_freeFunction · 0.85
av_malloczFunction · 0.50

Tested by

no test coverage detected