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

Function avcodec_thread_init

libavcodec/pthread.c:143–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
144{
145 int i;
146 ThreadContext *c;
147
148 avctx->thread_count = thread_count;
149
150 if (thread_count <= 1)
151 return 0;
152
153 c = av_mallocz(sizeof(ThreadContext));
154 if (!c)
155 return -1;
156
157 c->workers = av_mallocz(sizeof(pthread_t)*thread_count);
158 if (!c->workers) {
159 av_free(c);
160 return -1;
161 }
162
163 avctx->thread_opaque = c;
164 c->current_job = 0;
165 c->job_count = 0;
166 c->job_size = 0;
167 c->done = 0;
168 pthread_cond_init(&c->current_job_cond, NULL);
169 pthread_cond_init(&c->last_job_cond, NULL);
170 pthread_mutex_init(&c->current_job_lock, NULL);
171 pthread_mutex_lock(&c->current_job_lock);
172 for (i=0; i<thread_count; i++) {
173 if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
174 avctx->thread_count = i;
175 pthread_mutex_unlock(&c->current_job_lock);
176 avcodec_thread_free(avctx);
177 return -1;
178 }
179 }
180
181 avcodec_thread_park_workers(c, thread_count);
182
183 avctx->execute = avcodec_thread_execute;
184 avctx->execute2 = avcodec_thread_execute2;
185 return 0;
186}

Callers

nothing calls this directly

Calls 4

av_malloczFunction · 0.85
av_freeFunction · 0.85
avcodec_thread_freeFunction · 0.70

Tested by

no test coverage detected