- int i;
- ThreadContext *c;
-
- c = av_mallocz(sizeof(ThreadContext));
- if (!c)
- return -1;
-
- c->workers = av_mallocz(sizeof(pthread_t)*thread_count);
- if (!c->workers) {
- av_free(c);
- return -1;
- }
-
- avctx->thread_opaque = c;
- avctx->thread_count = thread_count;
- c->current_job = 0;
- c->job_count = 0;
- c->done = 0;
- pthread_cond_init(&c->current_job_cond, NULL);
- pthread_cond_init(&c->last_job_cond, NULL);
- pthread_mutex_init(&c->current_job_lock, NULL);
- pthread_mutex_lock(&c->current_job_lock);
- for (i=0; i<thread_count; i++) {
- if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
- avctx->thread_count = i;
- pthread_mutex_unlock(&c->current_job_lock);
- avcodec_thread_free(avctx);
- return -1;
- }
- }
-
- avcodec_thread_park_workers(c, thread_count);
-
- avctx->execute = avcodec_thread_execute;
- return 0;
+ if (avctx->active_thread_type&FF_THREAD_FRAME)
+ ff_frame_thread_free(avctx, avctx->thread_count);
+ else
+ ff_slice_thread_free(avctx);