int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)

{

    int opaque_alloc = 0;

    int ret;



    q->param.IOPattern  = MFX_IOPATTERN_IN_SYSTEM_MEMORY;

    q->param.AsyncDepth = q->async_depth;



    q->async_fifo = av_fifo_alloc((1 + q->async_depth) *

                                  (sizeof(AVPacket) + sizeof(mfxSyncPoint) + sizeof(mfxBitstream*)));

    if (!q->async_fifo)

        return AVERROR(ENOMEM);



    if (avctx->hwaccel_context) {

        AVQSVContext *qsv = avctx->hwaccel_context;



        q->session         = qsv->session;

        q->param.IOPattern = qsv->iopattern;



        opaque_alloc = qsv->opaque_alloc;

    }



    if (!q->session) {

        ret = ff_qsv_init_internal_session(avctx, &q->internal_session,

                                           q->load_plugins);

        if (ret < 0)

            return ret;



        q->session = q->internal_session;

    }



    ret = init_video_param(avctx, q);

    if (ret < 0)

        return ret;



    ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error querying the encoding parameters\n");

        return ff_qsv_error(ret);

    }



    if (opaque_alloc) {

        ret = qsv_init_opaque_alloc(avctx, q);

        if (ret < 0)

            return ret;

    }



    if (avctx->hwaccel_context) {

        AVQSVContext *qsv = avctx->hwaccel_context;

        int i, j;



        q->extparam = av_mallocz_array(qsv->nb_ext_buffers + q->nb_extparam_internal,

                                       sizeof(*q->extparam));

        if (!q->extparam)

            return AVERROR(ENOMEM);



        q->param.ExtParam = q->extparam;

        for (i = 0; i < qsv->nb_ext_buffers; i++)

            q->param.ExtParam[i] = qsv->ext_buffers[i];

        q->param.NumExtParam = qsv->nb_ext_buffers;



        for (i = 0; i < q->nb_extparam_internal; i++) {

            for (j = 0; j < qsv->nb_ext_buffers; j++) {

                if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]->BufferId)

                    break;

            }

            if (j < qsv->nb_ext_buffers)

                continue;



            q->param.ExtParam[q->param.NumExtParam++] = q->extparam_internal[i];

        }

    } else {

        q->param.ExtParam    = q->extparam_internal;

        q->param.NumExtParam = q->nb_extparam_internal;

    }



    ret = MFXVideoENCODE_Init(q->session, &q->param);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n");

        return ff_qsv_error(ret);

    }



    ret = qsv_retrieve_enc_params(avctx, q);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error retrieving encoding parameters.\n");

        return ret;

    }



    q->avctx = avctx;



    return 0;

}

int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)

{

    int opaque_alloc = 0;

    int ret;



    q->param.IOPattern  = MFX_IOPATTERN_IN_SYSTEM_MEMORY;

    q->param.AsyncDepth = q->async_depth;



    q->async_fifo = av_fifo_alloc((1 + q->async_depth) *

                                  (sizeof(AVPacket) + sizeof(mfxSyncPoint) + sizeof(mfxBitstream*)));

    if (!q->async_fifo)

        return AVERROR(ENOMEM);



    if (avctx->hwaccel_context) {

        AVQSVContext *qsv = avctx->hwaccel_context;



        q->session         = qsv->session;

        q->param.IOPattern = qsv->iopattern;



        opaque_alloc = qsv->opaque_alloc;

    }



    if (!q->session) {

        ret = ff_qsv_init_internal_session(avctx, &q->internal_session,

                                           q->load_plugins);

        if (ret < 0)

            return ret;



        q->session = q->internal_session;

    }



    ret = init_video_param(avctx, q);

    if (ret < 0)

        return ret;



    ret = MFXVideoENCODE_QueryIOSurf(q->session, &q->param, &q->req);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error querying the encoding parameters\n");

        return ff_qsv_error(ret);

    }



    if (opaque_alloc) {

        ret = qsv_init_opaque_alloc(avctx, q);

        if (ret < 0)

            return ret;

    }



    if (avctx->hwaccel_context) {

        AVQSVContext *qsv = avctx->hwaccel_context;

        int i, j;



        q->extparam = av_mallocz_array(qsv->nb_ext_buffers + q->nb_extparam_internal,

                                       sizeof(*q->extparam));

        if (!q->extparam)

            return AVERROR(ENOMEM);



        q->param.ExtParam = q->extparam;

        for (i = 0; i < qsv->nb_ext_buffers; i++)

            q->param.ExtParam[i] = qsv->ext_buffers[i];

        q->param.NumExtParam = qsv->nb_ext_buffers;



        for (i = 0; i < q->nb_extparam_internal; i++) {

            for (j = 0; j < qsv->nb_ext_buffers; j++) {

                if (qsv->ext_buffers[j]->BufferId == q->extparam_internal[i]->BufferId)

                    break;

            }

            if (j < qsv->nb_ext_buffers)

                continue;



            q->param.ExtParam[q->param.NumExtParam++] = q->extparam_internal[i];

        }

    } else {

        q->param.ExtParam    = q->extparam_internal;

        q->param.NumExtParam = q->nb_extparam_internal;

    }



    ret = MFXVideoENCODE_Init(q->session, &q->param);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error initializing the encoder\n");

        return ff_qsv_error(ret);

    }



    ret = qsv_retrieve_enc_params(avctx, q);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error retrieving encoding parameters.\n");

        return ret;

    }



    q->avctx = avctx;



    return 0;

}

int FUNC_0(AVCodecContext *VAR_0, QSVEncContext *VAR_1)

{

    int VAR_2 = 0;

    int VAR_3;



    VAR_1->param.IOPattern  = MFX_IOPATTERN_IN_SYSTEM_MEMORY;

    VAR_1->param.AsyncDepth = VAR_1->async_depth;



    VAR_1->async_fifo = av_fifo_alloc((1 + VAR_1->async_depth) *

                                  (sizeof(AVPacket) + sizeof(mfxSyncPoint) + sizeof(mfxBitstream*)));

    if (!VAR_1->async_fifo)

        return AVERROR(ENOMEM);



    if (VAR_0->hwaccel_context) {

        AVQSVContext *qsv = VAR_0->hwaccel_context;



        VAR_1->session         = qsv->session;

        VAR_1->param.IOPattern = qsv->iopattern;



        VAR_2 = qsv->VAR_2;

    }



    if (!VAR_1->session) {

        VAR_3 = ff_qsv_init_internal_session(VAR_0, &VAR_1->internal_session,

                                           VAR_1->load_plugins);

        if (VAR_3 < 0)

            return VAR_3;



        VAR_1->session = VAR_1->internal_session;

    }



    VAR_3 = init_video_param(VAR_0, VAR_1);

    if (VAR_3 < 0)

        return VAR_3;



    VAR_3 = MFXVideoENCODE_QueryIOSurf(VAR_1->session, &VAR_1->param, &VAR_1->req);

    if (VAR_3 < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error querying the encoding parameters\n");

        return ff_qsv_error(VAR_3);

    }



    if (VAR_2) {

        VAR_3 = qsv_init_opaque_alloc(VAR_0, VAR_1);

        if (VAR_3 < 0)

            return VAR_3;

    }



    if (VAR_0->hwaccel_context) {

        AVQSVContext *qsv = VAR_0->hwaccel_context;

        int VAR_4, VAR_5;



        VAR_1->extparam = av_mallocz_array(qsv->nb_ext_buffers + VAR_1->nb_extparam_internal,

                                       sizeof(*VAR_1->extparam));

        if (!VAR_1->extparam)

            return AVERROR(ENOMEM);



        VAR_1->param.ExtParam = VAR_1->extparam;

        for (VAR_4 = 0; VAR_4 < qsv->nb_ext_buffers; VAR_4++)

            VAR_1->param.ExtParam[VAR_4] = qsv->ext_buffers[VAR_4];

        VAR_1->param.NumExtParam = qsv->nb_ext_buffers;



        for (VAR_4 = 0; VAR_4 < VAR_1->nb_extparam_internal; VAR_4++) {

            for (VAR_5 = 0; VAR_5 < qsv->nb_ext_buffers; VAR_5++) {

                if (qsv->ext_buffers[VAR_5]->BufferId == VAR_1->extparam_internal[VAR_4]->BufferId)

                    break;

            }

            if (VAR_5 < qsv->nb_ext_buffers)

                continue;



            VAR_1->param.ExtParam[VAR_1->param.NumExtParam++] = VAR_1->extparam_internal[VAR_4];

        }

    } else {

        VAR_1->param.ExtParam    = VAR_1->extparam_internal;

        VAR_1->param.NumExtParam = VAR_1->nb_extparam_internal;

    }



    VAR_3 = MFXVideoENCODE_Init(VAR_1->session, &VAR_1->param);

    if (VAR_3 < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error initializing the encoder\n");

        return ff_qsv_error(VAR_3);

    }



    VAR_3 = qsv_retrieve_enc_params(VAR_0, VAR_1);

    if (VAR_3 < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error retrieving encoding parameters.\n");

        return VAR_3;

    }



    VAR_1->VAR_0 = VAR_0;



    return 0;

}

int FUNC_0(AVCodecContext *VAR_0, QSVEncContext *VAR_1)
{ int VAR_2 = 0; int VAR_3; VAR_1->param.IOPattern  = MFX_IOPATTERN_IN_SYSTEM_MEMORY; VAR_1->param.AsyncDepth = VAR_1->async_depth; VAR_1->async_fifo = av_fifo_alloc((1 + VAR_1->async_depth) *
(sizeof(AVPacket) + sizeof(mfxSyncPoint) + sizeof(mfxBitstream*))); if (!VAR_1->async_fifo)
return AVERROR(ENOMEM); if (VAR_0->hwaccel_context) { AVQSVContext *qsv = VAR_0->hwaccel_context; VAR_1->session         = qsv->session; VAR_1->param.IOPattern = qsv->iopattern; VAR_2 = qsv->VAR_2; } if (!VAR_1->session) { VAR_3 = ff_qsv_init_internal_session(VAR_0, &VAR_1->internal_session,
VAR_1->load_plugins); if (VAR_3 < 0)
return VAR_3; VAR_1->session = VAR_1->internal_session; } VAR_3 = init_video_param(VAR_0, VAR_1); if (VAR_3 < 0)
return VAR_3; VAR_3 = MFXVideoENCODE_QueryIOSurf(VAR_1->session, &VAR_1->param, &VAR_1->req); if (VAR_3 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error querying the encoding parameters\n"); return ff_qsv_error(VAR_3); } if (VAR_2) { VAR_3 = qsv_init_opaque_alloc(VAR_0, VAR_1); if (VAR_3 < 0)
return VAR_3; } if (VAR_0->hwaccel_context) { AVQSVContext *qsv = VAR_0->hwaccel_context; int VAR_4, VAR_5; VAR_1->extparam = av_mallocz_array(qsv->nb_ext_buffers + VAR_1->nb_extparam_internal,
sizeof(*VAR_1->extparam)); if (!VAR_1->extparam)
return AVERROR(ENOMEM); VAR_1->param.ExtParam = VAR_1->extparam; for (VAR_4 = 0; VAR_4 < qsv->nb_ext_buffers; VAR_4++) VAR_1->param.ExtParam[VAR_4] = qsv->ext_buffers[VAR_4]; VAR_1->param.NumExtParam = qsv->nb_ext_buffers; for (VAR_4 = 0; VAR_4 < VAR_1->nb_extparam_internal; VAR_4++) { for (VAR_5 = 0; VAR_5 < qsv->nb_ext_buffers; VAR_5++) { if (qsv->ext_buffers[VAR_5]->BufferId == VAR_1->extparam_internal[VAR_4]->BufferId)
break; } if (VAR_5 < qsv->nb_ext_buffers)
continue; VAR_1->param.ExtParam[VAR_1->param.NumExtParam++] = VAR_1->extparam_internal[VAR_4]; } } else { VAR_1->param.ExtParam    = VAR_1->extparam_internal; VAR_1->param.NumExtParam = VAR_1->nb_extparam_internal; } VAR_3 = MFXVideoENCODE_Init(VAR_1->session, &VAR_1->param); if (VAR_3 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error initializing the encoder\n"); return ff_qsv_error(VAR_3); } VAR_3 = qsv_retrieve_enc_params(VAR_0, VAR_1); if (VAR_3 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error retrieving encoding parameters.\n"); return VAR_3; } VAR_1->VAR_0 = VAR_0; return 0; }