static int submit_packet(PerThreadContext *p, AVPacket *avpkt)

{

    FrameThreadContext *fctx = p->parent;

    PerThreadContext *prev_thread = fctx->prev_thread;

    const AVCodec *codec = p->avctx->codec;



    if (!avpkt->size && !(codec->capabilities & AV_CODEC_CAP_DELAY))

        return 0;



    pthread_mutex_lock(&p->mutex);



    release_delayed_buffers(p);



    if (prev_thread) {

        int err;

        if (prev_thread->state == STATE_SETTING_UP) {

            pthread_mutex_lock(&prev_thread->progress_mutex);

            while (prev_thread->state == STATE_SETTING_UP)

                pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex);

            pthread_mutex_unlock(&prev_thread->progress_mutex);

        }



        err = update_context_from_thread(p->avctx, prev_thread->avctx, 0);

        if (err) {

            pthread_mutex_unlock(&p->mutex);

            return err;

        }

    }



    av_packet_unref(&p->avpkt);

    av_packet_ref(&p->avpkt, avpkt);



    p->state = STATE_SETTING_UP;

    pthread_cond_signal(&p->input_cond);

    pthread_mutex_unlock(&p->mutex);



    /*

     * If the client doesn't have a thread-safe get_buffer(),

     * then decoding threads call back to the main thread,

     * and it calls back to the client here.

     */



    if (!p->avctx->thread_safe_callbacks && (

         p->avctx->get_format != avcodec_default_get_format ||

         p->avctx->get_buffer2 != avcodec_default_get_buffer2)) {

        while (p->state != STATE_SETUP_FINISHED && p->state != STATE_INPUT_READY) {

            int call_done = 1;

            pthread_mutex_lock(&p->progress_mutex);

            while (p->state == STATE_SETTING_UP)

                pthread_cond_wait(&p->progress_cond, &p->progress_mutex);



            switch (p->state) {

            case STATE_GET_BUFFER:

                p->result = ff_get_buffer(p->avctx, p->requested_frame, p->requested_flags);

                break;

            case STATE_GET_FORMAT:

                p->result_format = ff_get_format(p->avctx, p->available_formats);

                break;

            default:

                call_done = 0;

                break;

            }

            if (call_done) {

                p->state  = STATE_SETTING_UP;

                pthread_cond_signal(&p->progress_cond);

            }

            pthread_mutex_unlock(&p->progress_mutex);

        }

    }



    fctx->prev_thread = p;

    fctx->next_decoding++;



    return 0;

}

static int submit_packet(PerThreadContext *p, AVPacket *avpkt)

{

    FrameThreadContext *fctx = p->parent;

    PerThreadContext *prev_thread = fctx->prev_thread;

    const AVCodec *codec = p->avctx->codec;



    if (!avpkt->size && !(codec->capabilities & AV_CODEC_CAP_DELAY))

        return 0;



    pthread_mutex_lock(&p->mutex);



    release_delayed_buffers(p);



    if (prev_thread) {

        int err;

        if (prev_thread->state == STATE_SETTING_UP) {

            pthread_mutex_lock(&prev_thread->progress_mutex);

            while (prev_thread->state == STATE_SETTING_UP)

                pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex);

            pthread_mutex_unlock(&prev_thread->progress_mutex);

        }



        err = update_context_from_thread(p->avctx, prev_thread->avctx, 0);

        if (err) {

            pthread_mutex_unlock(&p->mutex);

            return err;

        }

    }



    av_packet_unref(&p->avpkt);

    av_packet_ref(&p->avpkt, avpkt);



    p->state = STATE_SETTING_UP;

    pthread_cond_signal(&p->input_cond);

    pthread_mutex_unlock(&p->mutex);



    











    if (!p->avctx->thread_safe_callbacks && (

         p->avctx->get_format != avcodec_default_get_format ||

         p->avctx->get_buffer2 != avcodec_default_get_buffer2)) {

        while (p->state != STATE_SETUP_FINISHED && p->state != STATE_INPUT_READY) {

            int call_done = 1;

            pthread_mutex_lock(&p->progress_mutex);

            while (p->state == STATE_SETTING_UP)

                pthread_cond_wait(&p->progress_cond, &p->progress_mutex);



            switch (p->state) {

            case STATE_GET_BUFFER:

                p->result = ff_get_buffer(p->avctx, p->requested_frame, p->requested_flags);

                break;

            case STATE_GET_FORMAT:

                p->result_format = ff_get_format(p->avctx, p->available_formats);

                break;

            default:

                call_done = 0;

                break;

            }

            if (call_done) {

                p->state  = STATE_SETTING_UP;

                pthread_cond_signal(&p->progress_cond);

            }

            pthread_mutex_unlock(&p->progress_mutex);

        }

    }



    fctx->prev_thread = p;

    fctx->next_decoding++;



    return 0;

}

    av_packet_ref(&p->avpkt, avpkt);
static int FUNC_0(PerThreadContext *VAR_0, AVPacket *VAR_1)

{

    FrameThreadContext *fctx = VAR_0->parent;

    PerThreadContext *prev_thread = fctx->prev_thread;

    const AVCodec *VAR_2 = VAR_0->avctx->VAR_2;



    if (!VAR_1->size && !(VAR_2->capabilities & AV_CODEC_CAP_DELAY))

        return 0;



    pthread_mutex_lock(&VAR_0->mutex);



    release_delayed_buffers(VAR_0);



    if (prev_thread) {

        int VAR_3;

        if (prev_thread->state == STATE_SETTING_UP) {

            pthread_mutex_lock(&prev_thread->progress_mutex);

            while (prev_thread->state == STATE_SETTING_UP)

                pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex);

            pthread_mutex_unlock(&prev_thread->progress_mutex);

        }



        VAR_3 = update_context_from_thread(VAR_0->avctx, prev_thread->avctx, 0);

        if (VAR_3) {

            pthread_mutex_unlock(&VAR_0->mutex);

            return VAR_3;

        }

    }



    av_packet_unref(&VAR_0->VAR_1);

    av_packet_ref(&VAR_0->VAR_1, VAR_1);



    VAR_0->state = STATE_SETTING_UP;

    pthread_cond_signal(&VAR_0->input_cond);

    pthread_mutex_unlock(&VAR_0->mutex);



    











    if (!VAR_0->avctx->thread_safe_callbacks && (

         VAR_0->avctx->get_format != avcodec_default_get_format ||

         VAR_0->avctx->get_buffer2 != avcodec_default_get_buffer2)) {

        while (VAR_0->state != STATE_SETUP_FINISHED && VAR_0->state != STATE_INPUT_READY) {

            int VAR_4 = 1;

            pthread_mutex_lock(&VAR_0->progress_mutex);

            while (VAR_0->state == STATE_SETTING_UP)

                pthread_cond_wait(&VAR_0->progress_cond, &VAR_0->progress_mutex);



            switch (VAR_0->state) {

            case STATE_GET_BUFFER:

                VAR_0->result = ff_get_buffer(VAR_0->avctx, VAR_0->requested_frame, VAR_0->requested_flags);

                break;

            case STATE_GET_FORMAT:

                VAR_0->result_format = ff_get_format(VAR_0->avctx, VAR_0->available_formats);

                break;

            default:

                VAR_4 = 0;

                break;

            }

            if (VAR_4) {

                VAR_0->state  = STATE_SETTING_UP;

                pthread_cond_signal(&VAR_0->progress_cond);

            }

            pthread_mutex_unlock(&VAR_0->progress_mutex);

        }

    }



    fctx->prev_thread = VAR_0;

    fctx->next_decoding++;



    return 0;

}

static int FUNC_0(PerThreadContext *VAR_0, AVPacket *VAR_1)
{ FrameThreadContext *fctx = VAR_0->parent; PerThreadContext *prev_thread = fctx->prev_thread; const AVCodec *VAR_2 = VAR_0->avctx->VAR_2; if (!VAR_1->size && !(VAR_2->capabilities & AV_CODEC_CAP_DELAY))
return 0; pthread_mutex_lock(&VAR_0->mutex); release_delayed_buffers(VAR_0); if (prev_thread) { int VAR_3; if (prev_thread->state == STATE_SETTING_UP) { pthread_mutex_lock(&prev_thread->progress_mutex); while (prev_thread->state == STATE_SETTING_UP)
pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex); pthread_mutex_unlock(&prev_thread->progress_mutex); } VAR_3 = update_context_from_thread(VAR_0->avctx, prev_thread->avctx, 0); if (VAR_3) { pthread_mutex_unlock(&VAR_0->mutex); return VAR_3; } } av_packet_unref(&VAR_0->VAR_1); av_packet_ref(&VAR_0->VAR_1, VAR_1); VAR_0->state = STATE_SETTING_UP; pthread_cond_signal(&VAR_0->input_cond); pthread_mutex_unlock(&VAR_0->mutex); if (!VAR_0->avctx->thread_safe_callbacks && (
VAR_0->avctx->get_format != avcodec_default_get_format ||
VAR_0->avctx->get_buffer2 != avcodec_default_get_buffer2)) { while (VAR_0->state != STATE_SETUP_FINISHED && VAR_0->state != STATE_INPUT_READY) { int VAR_4 = 1; pthread_mutex_lock(&VAR_0->progress_mutex); while (VAR_0->state == STATE_SETTING_UP)
pthread_cond_wait(&VAR_0->progress_cond, &VAR_0->progress_mutex); switch (VAR_0->state) { case STATE_GET_BUFFER:
VAR_0->result = ff_get_buffer(VAR_0->avctx, VAR_0->requested_frame, VAR_0->requested_flags); break; case STATE_GET_FORMAT:
VAR_0->result_format = ff_get_format(VAR_0->avctx, VAR_0->available_formats); break; default:
VAR_4 = 0; break; } if (VAR_4) { VAR_0->state  = STATE_SETTING_UP; pthread_cond_signal(&VAR_0->progress_cond); } pthread_mutex_unlock(&VAR_0->progress_mutex); } } fctx->prev_thread = VAR_0; fctx->next_decoding++; return 0; }