static int frame_thread_init(AVCodecContext *avctx)

{

    int thread_count = avctx->thread_count;

    AVCodec *codec = avctx->codec;

    AVCodecContext *src = avctx;

    FrameThreadContext *fctx;

    int i, err = 0;



    if (thread_count <= 1) {

        avctx->active_thread_type = 0;

        return 0;

    }



    avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));



    fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);

    pthread_mutex_init(&fctx->buffer_mutex, NULL);

    fctx->delaying = 1;



    for (i = 0; i < thread_count; i++) {

        AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));

        PerThreadContext *p  = &fctx->threads[i];



        pthread_mutex_init(&p->mutex, NULL);

        pthread_mutex_init(&p->progress_mutex, NULL);

        pthread_cond_init(&p->input_cond, NULL);

        pthread_cond_init(&p->progress_cond, NULL);

        pthread_cond_init(&p->output_cond, NULL);



        p->parent = fctx;

        p->avctx  = copy;



        if (!copy) {

            err = AVERROR(ENOMEM);

            goto error;

        }



        *copy = *src;

        copy->thread_opaque = p;

        copy->pkt = &p->avpkt;



        if (!i) {

            src = copy;



            if (codec->init)

                err = codec->init(copy);



            update_context_from_thread(avctx, copy, 1);

        } else {

            copy->priv_data = av_malloc(codec->priv_data_size);

            if (!copy->priv_data) {

                err = AVERROR(ENOMEM);

                goto error;

            }

            memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);

            copy->internal = av_malloc(sizeof(AVCodecInternal));

            if (!copy->internal) {

                err = AVERROR(ENOMEM);

                goto error;

            }

            *(copy->internal) = *(src->internal);

            copy->internal->is_copy = 1;



            if (codec->init_thread_copy)

                err = codec->init_thread_copy(copy);

        }



        if (err) goto error;



        pthread_create(&p->thread, NULL, frame_worker_thread, p);

    }



    return 0;



error:

    frame_thread_free(avctx, i+1);



    return err;

}

static int frame_thread_init(AVCodecContext *avctx)

{

    int thread_count = avctx->thread_count;

    AVCodec *codec = avctx->codec;

    AVCodecContext *src = avctx;

    FrameThreadContext *fctx;

    int i, err = 0;



    if (thread_count <= 1) {

        avctx->active_thread_type = 0;

        return 0;

    }



    avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));



    fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);

    pthread_mutex_init(&fctx->buffer_mutex, NULL);

    fctx->delaying = 1;



    for (i = 0; i < thread_count; i++) {

        AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));

        PerThreadContext *p  = &fctx->threads[i];



        pthread_mutex_init(&p->mutex, NULL);

        pthread_mutex_init(&p->progress_mutex, NULL);

        pthread_cond_init(&p->input_cond, NULL);

        pthread_cond_init(&p->progress_cond, NULL);

        pthread_cond_init(&p->output_cond, NULL);



        p->parent = fctx;

        p->avctx  = copy;



        if (!copy) {

            err = AVERROR(ENOMEM);

            goto error;

        }



        *copy = *src;

        copy->thread_opaque = p;

        copy->pkt = &p->avpkt;



        if (!i) {

            src = copy;



            if (codec->init)

                err = codec->init(copy);



            update_context_from_thread(avctx, copy, 1);

        } else {

            copy->priv_data = av_malloc(codec->priv_data_size);

            if (!copy->priv_data) {

                err = AVERROR(ENOMEM);

                goto error;

            }

            memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);

            copy->internal = av_malloc(sizeof(AVCodecInternal));

            if (!copy->internal) {

                err = AVERROR(ENOMEM);

                goto error;

            }

            *(copy->internal) = *(src->internal);

            copy->internal->is_copy = 1;



            if (codec->init_thread_copy)

                err = codec->init_thread_copy(copy);

        }



        if (err) goto error;



        pthread_create(&p->thread, NULL, frame_worker_thread, p);

    }



    return 0;



error:

    frame_thread_free(avctx, i+1);



    return err;

}

        pthread_create(&p->thread, NULL, frame_worker_thread, p);
static int FUNC_0(AVCodecContext *VAR_0)

{

    int VAR_1 = VAR_0->VAR_1;

    AVCodec *codec = VAR_0->codec;

    AVCodecContext *src = VAR_0;

    FrameThreadContext *fctx;

    int VAR_2, VAR_3 = 0;



    if (VAR_1 <= 1) {

        VAR_0->active_thread_type = 0;

        return 0;

    }



    VAR_0->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));



    fctx->threads = av_mallocz(sizeof(PerThreadContext) * VAR_1);

    pthread_mutex_init(&fctx->buffer_mutex, NULL);

    fctx->delaying = 1;



    for (VAR_2 = 0; VAR_2 < VAR_1; VAR_2++) {

        AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));

        PerThreadContext *p  = &fctx->threads[VAR_2];



        pthread_mutex_init(&p->mutex, NULL);

        pthread_mutex_init(&p->progress_mutex, NULL);

        pthread_cond_init(&p->input_cond, NULL);

        pthread_cond_init(&p->progress_cond, NULL);

        pthread_cond_init(&p->output_cond, NULL);



        p->parent = fctx;

        p->VAR_0  = copy;



        if (!copy) {

            VAR_3 = AVERROR(ENOMEM);

            goto error;

        }



        *copy = *src;

        copy->thread_opaque = p;

        copy->pkt = &p->avpkt;



        if (!VAR_2) {

            src = copy;



            if (codec->init)

                VAR_3 = codec->init(copy);



            update_context_from_thread(VAR_0, copy, 1);

        } else {

            copy->priv_data = av_malloc(codec->priv_data_size);

            if (!copy->priv_data) {

                VAR_3 = AVERROR(ENOMEM);

                goto error;

            }

            memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);

            copy->internal = av_malloc(sizeof(AVCodecInternal));

            if (!copy->internal) {

                VAR_3 = AVERROR(ENOMEM);

                goto error;

            }

            *(copy->internal) = *(src->internal);

            copy->internal->is_copy = 1;



            if (codec->init_thread_copy)

                VAR_3 = codec->init_thread_copy(copy);

        }



        if (VAR_3) goto error;



        pthread_create(&p->thread, NULL, frame_worker_thread, p);

    }



    return 0;



error:

    frame_thread_free(VAR_0, VAR_2+1);



    return VAR_3;

}

static int FUNC_0(AVCodecContext *VAR_0)
{ int VAR_1 = VAR_0->VAR_1; AVCodec *codec = VAR_0->codec; AVCodecContext *src = VAR_0; FrameThreadContext *fctx; int VAR_2, VAR_3 = 0; if (VAR_1 <= 1) { VAR_0->active_thread_type = 0; return 0; } VAR_0->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext)); fctx->threads = av_mallocz(sizeof(PerThreadContext) * VAR_1); pthread_mutex_init(&fctx->buffer_mutex, NULL); fctx->delaying = 1; for (VAR_2 = 0; VAR_2 < VAR_1; VAR_2++) { AVCodecContext *copy = av_malloc(sizeof(AVCodecContext)); PerThreadContext *p  = &fctx->threads[VAR_2]; pthread_mutex_init(&p->mutex, NULL); pthread_mutex_init(&p->progress_mutex, NULL); pthread_cond_init(&p->input_cond, NULL); pthread_cond_init(&p->progress_cond, NULL); pthread_cond_init(&p->output_cond, NULL); p->parent = fctx; p->VAR_0  = copy; if (!copy) { VAR_3 = AVERROR(ENOMEM); goto error; } *copy = *src; copy->thread_opaque = p; copy->pkt = &p->avpkt; if (!VAR_2) { src = copy; if (codec->init)
VAR_3 = codec->init(copy); update_context_from_thread(VAR_0, copy, 1); } else { copy->priv_data = av_malloc(codec->priv_data_size); if (!copy->priv_data) { VAR_3 = AVERROR(ENOMEM); goto error; } memcpy(copy->priv_data, src->priv_data, codec->priv_data_size); copy->internal = av_malloc(sizeof(AVCodecInternal)); if (!copy->internal) { VAR_3 = AVERROR(ENOMEM); goto error; } *(copy->internal) = *(src->internal); copy->internal->is_copy = 1; if (codec->init_thread_copy)
VAR_3 = codec->init_thread_copy(copy); } if (VAR_3) goto error; pthread_create(&p->thread, NULL, frame_worker_thread, p); } return 0; error:
frame_thread_free(VAR_0, VAR_2+1); return VAR_3; }