static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags)

{

    PerThreadContext *p = avctx->internal->thread_ctx;

    int err;



    f->owner = avctx;



    ff_init_buffer_info(avctx, f->f);



    if (!(avctx->active_thread_type & FF_THREAD_FRAME))

        return ff_get_buffer(avctx, f->f, flags);



    if (atomic_load(&p->state) != STATE_SETTING_UP &&

        (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n");

        return -1;

    }



    if (avctx->internal->allocate_progress) {

        atomic_int *progress;

        f->progress = av_buffer_alloc(2 * sizeof(*progress));

        if (!f->progress) {

            return AVERROR(ENOMEM);

        }

        progress = (atomic_int*)f->progress->data;



        atomic_init(&progress[0], -1);

        atomic_init(&progress[1], -1);

    }



    pthread_mutex_lock(&p->parent->buffer_mutex);

    if (avctx->thread_safe_callbacks ||

        avctx->get_buffer2 == avcodec_default_get_buffer2) {

        err = ff_get_buffer(avctx, f->f, flags);

    } else {

        pthread_mutex_lock(&p->progress_mutex);

        p->requested_frame = f->f;

        p->requested_flags = flags;

        atomic_store_explicit(&p->state, STATE_GET_BUFFER, memory_order_release);

        pthread_cond_broadcast(&p->progress_cond);



        while (atomic_load(&p->state) != STATE_SETTING_UP)

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



        err = p->result;



        pthread_mutex_unlock(&p->progress_mutex);



    }

    if (!THREAD_SAFE_CALLBACKS(avctx) && !avctx->codec->update_thread_context)

        ff_thread_finish_setup(avctx);

    if (err)

        av_buffer_unref(&f->progress);



    pthread_mutex_unlock(&p->parent->buffer_mutex);



    return err;

}

static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags)

{

    PerThreadContext *p = avctx->internal->thread_ctx;

    int err;



    f->owner = avctx;



    ff_init_buffer_info(avctx, f->f);



    if (!(avctx->active_thread_type & FF_THREAD_FRAME))

        return ff_get_buffer(avctx, f->f, flags);



    if (atomic_load(&p->state) != STATE_SETTING_UP &&

        (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n");

        return -1;

    }



    if (avctx->internal->allocate_progress) {

        atomic_int *progress;

        f->progress = av_buffer_alloc(2 * sizeof(*progress));

        if (!f->progress) {

            return AVERROR(ENOMEM);

        }

        progress = (atomic_int*)f->progress->data;



        atomic_init(&progress[0], -1);

        atomic_init(&progress[1], -1);

    }



    pthread_mutex_lock(&p->parent->buffer_mutex);

    if (avctx->thread_safe_callbacks ||

        avctx->get_buffer2 == avcodec_default_get_buffer2) {

        err = ff_get_buffer(avctx, f->f, flags);

    } else {

        pthread_mutex_lock(&p->progress_mutex);

        p->requested_frame = f->f;

        p->requested_flags = flags;

        atomic_store_explicit(&p->state, STATE_GET_BUFFER, memory_order_release);

        pthread_cond_broadcast(&p->progress_cond);



        while (atomic_load(&p->state) != STATE_SETTING_UP)

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



        err = p->result;



        pthread_mutex_unlock(&p->progress_mutex);



    }

    if (!THREAD_SAFE_CALLBACKS(avctx) && !avctx->codec->update_thread_context)

        ff_thread_finish_setup(avctx);

    if (err)

        av_buffer_unref(&f->progress);



    pthread_mutex_unlock(&p->parent->buffer_mutex);



    return err;

}

    f->owner = avctx;     f->owner = avctx;
static int FUNC_0(AVCodecContext *VAR_0, ThreadFrame *VAR_1, int VAR_2)

{

    PerThreadContext *p = VAR_0->internal->thread_ctx;

    int VAR_3;



    VAR_1->owner = VAR_0;



    ff_init_buffer_info(VAR_0, VAR_1->VAR_1);



    if (!(VAR_0->active_thread_type & FF_THREAD_FRAME))

        return ff_get_buffer(VAR_0, VAR_1->VAR_1, VAR_2);



    if (atomic_load(&p->state) != STATE_SETTING_UP &&

        (VAR_0->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(VAR_0))) {

        av_log(VAR_0, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n");

        return -1;

    }



    if (VAR_0->internal->allocate_progress) {

        atomic_int *progress;

        VAR_1->progress = av_buffer_alloc(2 * sizeof(*progress));

        if (!VAR_1->progress) {

            return AVERROR(ENOMEM);

        }

        progress = (atomic_int*)VAR_1->progress->data;



        atomic_init(&progress[0], -1);

        atomic_init(&progress[1], -1);

    }



    pthread_mutex_lock(&p->parent->buffer_mutex);

    if (VAR_0->thread_safe_callbacks ||

        VAR_0->get_buffer2 == avcodec_default_get_buffer2) {

        VAR_3 = ff_get_buffer(VAR_0, VAR_1->VAR_1, VAR_2);

    } else {

        pthread_mutex_lock(&p->progress_mutex);

        p->requested_frame = VAR_1->VAR_1;

        p->requested_flags = VAR_2;

        atomic_store_explicit(&p->state, STATE_GET_BUFFER, memory_order_release);

        pthread_cond_broadcast(&p->progress_cond);



        while (atomic_load(&p->state) != STATE_SETTING_UP)

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



        VAR_3 = p->result;



        pthread_mutex_unlock(&p->progress_mutex);



    }

    if (!THREAD_SAFE_CALLBACKS(VAR_0) && !VAR_0->codec->update_thread_context)

        ff_thread_finish_setup(VAR_0);

    if (VAR_3)

        av_buffer_unref(&VAR_1->progress);



    pthread_mutex_unlock(&p->parent->buffer_mutex);



    return VAR_3;

}

static int FUNC_0(AVCodecContext *VAR_0, ThreadFrame *VAR_1, int VAR_2)
{ PerThreadContext *p = VAR_0->internal->thread_ctx; int VAR_3; VAR_1->owner = VAR_0; ff_init_buffer_info(VAR_0, VAR_1->VAR_1); if (!(VAR_0->active_thread_type & FF_THREAD_FRAME))
return ff_get_buffer(VAR_0, VAR_1->VAR_1, VAR_2); if (atomic_load(&p->state) != STATE_SETTING_UP &&
(VAR_0->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(VAR_0))) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n"); return -1; } if (VAR_0->internal->allocate_progress) { atomic_int *progress; VAR_1->progress = av_buffer_alloc(2 * sizeof(*progress)); if (!VAR_1->progress) { return AVERROR(ENOMEM); } progress = (atomic_int*)VAR_1->progress->data; atomic_init(&progress[0], -1); atomic_init(&progress[1], -1); } pthread_mutex_lock(&p->parent->buffer_mutex); if (VAR_0->thread_safe_callbacks ||
VAR_0->get_buffer2 == avcodec_default_get_buffer2) { VAR_3 = ff_get_buffer(VAR_0, VAR_1->VAR_1, VAR_2); } else { pthread_mutex_lock(&p->progress_mutex); p->requested_frame = VAR_1->VAR_1; p->requested_flags = VAR_2; atomic_store_explicit(&p->state, STATE_GET_BUFFER, memory_order_release); pthread_cond_broadcast(&p->progress_cond); while (atomic_load(&p->state) != STATE_SETTING_UP)
pthread_cond_wait(&p->progress_cond, &p->progress_mutex); VAR_3 = p->result; pthread_mutex_unlock(&p->progress_mutex); } if (!THREAD_SAFE_CALLBACKS(VAR_0) && !VAR_0->codec->update_thread_context)
ff_thread_finish_setup(VAR_0); if (VAR_3)
av_buffer_unref(&VAR_1->progress); pthread_mutex_unlock(&p->parent->buffer_mutex); return VAR_3; }