int ff_slice_thread_init(AVCodecContext *avctx)

{

    int i;

    SliceThreadContext *c;

    int thread_count = avctx->thread_count;



#if HAVE_W32THREADS

    w32thread_init();

#endif



    // We cannot do this in the encoder init as the threads are created before

    if (av_codec_is_encoder(avctx->codec) &&

        avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO &&

        avctx->height > 2800)

        thread_count = avctx->thread_count = 1;



    if (!thread_count) {

        int nb_cpus = av_cpu_count();

        if  (avctx->height)

            nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);

        // use number of cores + 1 as thread count if there is more than one

        if (nb_cpus > 1)

            thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);

        else

            thread_count = avctx->thread_count = 1;

    }



    if (thread_count <= 1) {

        avctx->active_thread_type = 0;

        return 0;

    }



    c = av_mallocz(sizeof(SliceThreadContext));

    if (!c)

        return -1;



    c->workers = av_mallocz_array(thread_count, sizeof(pthread_t));

    if (!c->workers) {

        av_free(c);

        return -1;

    }



    avctx->internal->thread_ctx = c;

    c->current_job = 0;

    c->job_count = 0;

    c->job_size = 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);

           ff_thread_free(avctx);

           return -1;

        }

    }



    thread_park_workers(c, thread_count);



    avctx->execute = thread_execute;

    avctx->execute2 = thread_execute2;

    return 0;

}

int ff_slice_thread_init(AVCodecContext *avctx)

{

    int i;

    SliceThreadContext *c;

    int thread_count = avctx->thread_count;



#if HAVE_W32THREADS

    w32thread_init();

#endif



    

    if (av_codec_is_encoder(avctx->codec) &&

        avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO &&

        avctx->height > 2800)

        thread_count = avctx->thread_count = 1;



    if (!thread_count) {

        int nb_cpus = av_cpu_count();

        if  (avctx->height)

            nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16);

        

        if (nb_cpus > 1)

            thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);

        else

            thread_count = avctx->thread_count = 1;

    }



    if (thread_count <= 1) {

        avctx->active_thread_type = 0;

        return 0;

    }



    c = av_mallocz(sizeof(SliceThreadContext));

    if (!c)

        return -1;



    c->workers = av_mallocz_array(thread_count, sizeof(pthread_t));

    if (!c->workers) {

        av_free(c);

        return -1;

    }



    avctx->internal->thread_ctx = c;

    c->current_job = 0;

    c->job_count = 0;

    c->job_size = 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);

           ff_thread_free(avctx);

           return -1;

        }

    }



    thread_park_workers(c, thread_count);



    avctx->execute = thread_execute;

    avctx->execute2 = thread_execute2;

    return 0;

}

    int thread_count = avctx->thread_count;     pthread_mutex_lock(&c->current_job_lock);     pthread_mutex_lock(&c->current_job_lock);     pthread_mutex_lock(&c->current_job_lock);     int i;     c = av_mallocz(sizeof(SliceThreadContext));     if (!c)         return -1;     c->workers = av_mallocz_array(thread_count, sizeof(pthread_t));     if (!c->workers) {         av_free(c);         return -1;     avctx->internal->thread_ctx = c;     c->current_job = 0;     c->job_count = 0;     c->job_size = 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);            ff_thread_free(avctx);            return -1;     thread_park_workers(c, thread_count);
int FUNC_0(AVCodecContext *VAR_0)

{

    int VAR_1;

    SliceThreadContext *c;

    int VAR_2 = VAR_0->VAR_2;



#if HAVE_W32THREADS

    w32thread_init();

#endif



    

    if (av_codec_is_encoder(VAR_0->codec) &&

        VAR_0->codec_id == AV_CODEC_ID_MPEG1VIDEO &&

        VAR_0->height > 2800)

        VAR_2 = VAR_0->VAR_2 = 1;



    if (!VAR_2) {

        int VAR_3 = av_cpu_count();

        if  (VAR_0->height)

            VAR_3 = FFMIN(VAR_3, (VAR_0->height+15)/16);

        

        if (VAR_3 > 1)

            VAR_2 = VAR_0->VAR_2 = FFMIN(VAR_3 + 1, MAX_AUTO_THREADS);

        else

            VAR_2 = VAR_0->VAR_2 = 1;

    }



    if (VAR_2 <= 1) {

        VAR_0->active_thread_type = 0;

        return 0;

    }



    c = av_mallocz(sizeof(SliceThreadContext));

    if (!c)

        return -1;



    c->workers = av_mallocz_array(VAR_2, sizeof(pthread_t));

    if (!c->workers) {

        av_free(c);

        return -1;

    }



    VAR_0->internal->thread_ctx = c;

    c->current_job = 0;

    c->job_count = 0;

    c->job_size = 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 (VAR_1=0; VAR_1<VAR_2; VAR_1++) {

        if(pthread_create(&c->workers[VAR_1], NULL, worker, VAR_0)) {

           VAR_0->VAR_2 = VAR_1;

           pthread_mutex_unlock(&c->current_job_lock);

           ff_thread_free(VAR_0);

           return -1;

        }

    }



    thread_park_workers(c, VAR_2);



    VAR_0->execute = thread_execute;

    VAR_0->execute2 = thread_execute2;

    return 0;

}

int FUNC_0(AVCodecContext *VAR_0)
{ int VAR_1; SliceThreadContext *c; int VAR_2 = VAR_0->VAR_2; #if HAVE_W32THREADS
w32thread_init(); #endif
if (av_codec_is_encoder(VAR_0->codec) &&
VAR_0->codec_id == AV_CODEC_ID_MPEG1VIDEO &&
VAR_0->height > 2800)
VAR_2 = VAR_0->VAR_2 = 1; if (!VAR_2) { int VAR_3 = av_cpu_count(); if  (VAR_0->height)
VAR_3 = FFMIN(VAR_3, (VAR_0->height+15)/16); if (VAR_3 > 1)
VAR_2 = VAR_0->VAR_2 = FFMIN(VAR_3 + 1, MAX_AUTO_THREADS); else
VAR_2 = VAR_0->VAR_2 = 1; } if (VAR_2 <= 1) { VAR_0->active_thread_type = 0; return 0; } c = av_mallocz(sizeof(SliceThreadContext)); if (!c)
return -1; c->workers = av_mallocz_array(VAR_2, sizeof(pthread_t)); if (!c->workers) { av_free(c); return -1; } VAR_0->internal->thread_ctx = c; c->current_job = 0; c->job_count = 0; c->job_size = 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 (VAR_1=0; VAR_1<VAR_2; VAR_1++) { if(pthread_create(&c->workers[VAR_1], NULL, worker, VAR_0)) { VAR_0->VAR_2 = VAR_1; pthread_mutex_unlock(&c->current_job_lock); ff_thread_free(VAR_0); return -1; } } thread_park_workers(c, VAR_2); VAR_0->execute = thread_execute; VAR_0->execute2 = thread_execute2; return 0; }