static void frame_thread_free(AVCodecContext *avctx, int thread_count)

{

    FrameThreadContext *fctx = avctx->thread_opaque;

    AVCodec *codec = avctx->codec;

    int i;



    park_frame_worker_threads(fctx, thread_count);



    if (fctx->prev_thread && fctx->prev_thread != fctx->threads)

        update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0);



    fctx->die = 1;



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

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



        pthread_mutex_lock(&p->mutex);

        pthread_cond_signal(&p->input_cond);

        pthread_mutex_unlock(&p->mutex);



        pthread_join(p->thread, NULL);



        if (codec->close)

            codec->close(p->avctx);



        avctx->codec = NULL;



        release_delayed_buffers(p);

    }



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

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



        avcodec_default_free_buffers(p->avctx);



        pthread_mutex_destroy(&p->mutex);

        pthread_mutex_destroy(&p->progress_mutex);

        pthread_cond_destroy(&p->input_cond);

        pthread_cond_destroy(&p->progress_cond);

        pthread_cond_destroy(&p->output_cond);

        av_freep(&p->avpkt.data);



        if (i)

            av_freep(&p->avctx->priv_data);



        av_freep(&p->avctx);

    }



    av_freep(&fctx->threads);

    pthread_mutex_destroy(&fctx->buffer_mutex);

    av_freep(&avctx->thread_opaque);

    avctx->has_b_frames -= avctx->thread_count - 1;

}

static void frame_thread_free(AVCodecContext *avctx, int thread_count)

{

    FrameThreadContext *fctx = avctx->thread_opaque;

    AVCodec *codec = avctx->codec;

    int i;



    park_frame_worker_threads(fctx, thread_count);



    if (fctx->prev_thread && fctx->prev_thread != fctx->threads)

        update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0);



    fctx->die = 1;



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

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



        pthread_mutex_lock(&p->mutex);

        pthread_cond_signal(&p->input_cond);

        pthread_mutex_unlock(&p->mutex);



        pthread_join(p->thread, NULL);



        if (codec->close)

            codec->close(p->avctx);



        avctx->codec = NULL;



        release_delayed_buffers(p);

    }



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

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



        avcodec_default_free_buffers(p->avctx);



        pthread_mutex_destroy(&p->mutex);

        pthread_mutex_destroy(&p->progress_mutex);

        pthread_cond_destroy(&p->input_cond);

        pthread_cond_destroy(&p->progress_cond);

        pthread_cond_destroy(&p->output_cond);

        av_freep(&p->avpkt.data);



        if (i)

            av_freep(&p->avctx->priv_data);



        av_freep(&p->avctx);

    }



    av_freep(&fctx->threads);

    pthread_mutex_destroy(&fctx->buffer_mutex);

    av_freep(&avctx->thread_opaque);

    avctx->has_b_frames -= avctx->thread_count - 1;

}

    avctx->has_b_frames -= avctx->thread_count - 1;
static void FUNC_0(AVCodecContext *VAR_0, int VAR_1)

{

    FrameThreadContext *fctx = VAR_0->thread_opaque;

    AVCodec *codec = VAR_0->codec;

    int VAR_2;



    park_frame_worker_threads(fctx, VAR_1);



    if (fctx->prev_thread && fctx->prev_thread != fctx->threads)

        update_context_from_thread(fctx->threads->VAR_0, fctx->prev_thread->VAR_0, 0);



    fctx->die = 1;



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

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



        pthread_mutex_lock(&p->mutex);

        pthread_cond_signal(&p->input_cond);

        pthread_mutex_unlock(&p->mutex);



        pthread_join(p->thread, NULL);



        if (codec->close)

            codec->close(p->VAR_0);



        VAR_0->codec = NULL;



        release_delayed_buffers(p);

    }



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

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



        avcodec_default_free_buffers(p->VAR_0);



        pthread_mutex_destroy(&p->mutex);

        pthread_mutex_destroy(&p->progress_mutex);

        pthread_cond_destroy(&p->input_cond);

        pthread_cond_destroy(&p->progress_cond);

        pthread_cond_destroy(&p->output_cond);

        av_freep(&p->avpkt.data);



        if (VAR_2)

            av_freep(&p->VAR_0->priv_data);



        av_freep(&p->VAR_0);

    }



    av_freep(&fctx->threads);

    pthread_mutex_destroy(&fctx->buffer_mutex);

    av_freep(&VAR_0->thread_opaque);

    VAR_0->has_b_frames -= VAR_0->VAR_1 - 1;

}

static void FUNC_0(AVCodecContext *VAR_0, int VAR_1)
{ FrameThreadContext *fctx = VAR_0->thread_opaque; AVCodec *codec = VAR_0->codec; int VAR_2; park_frame_worker_threads(fctx, VAR_1); if (fctx->prev_thread && fctx->prev_thread != fctx->threads)
update_context_from_thread(fctx->threads->VAR_0, fctx->prev_thread->VAR_0, 0); fctx->die = 1; for (VAR_2 = 0; VAR_2 < VAR_1; VAR_2++) { PerThreadContext *p = &fctx->threads[VAR_2]; pthread_mutex_lock(&p->mutex); pthread_cond_signal(&p->input_cond); pthread_mutex_unlock(&p->mutex); pthread_join(p->thread, NULL); if (codec->close)
codec->close(p->VAR_0); VAR_0->codec = NULL; release_delayed_buffers(p); } for (VAR_2 = 0; VAR_2 < VAR_1; VAR_2++) { PerThreadContext *p = &fctx->threads[VAR_2]; avcodec_default_free_buffers(p->VAR_0); pthread_mutex_destroy(&p->mutex); pthread_mutex_destroy(&p->progress_mutex); pthread_cond_destroy(&p->input_cond); pthread_cond_destroy(&p->progress_cond); pthread_cond_destroy(&p->output_cond); av_freep(&p->avpkt.data); if (VAR_2)
av_freep(&p->VAR_0->priv_data); av_freep(&p->VAR_0); } av_freep(&fctx->threads); pthread_mutex_destroy(&fctx->buffer_mutex); av_freep(&VAR_0->thread_opaque); VAR_0->has_b_frames -= VAR_0->VAR_1 - 1; }