int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,

                  AVPacket *pkt, const AVFrame *frame, int *got_packet)

{

    mfxBitstream bs = { { { 0 } } };



    mfxFrameSurface1 *surf = NULL;

    mfxSyncPoint sync      = NULL;

    int ret;



    if (frame) {

        ret = submit_frame(q, frame, &surf);

        if (ret < 0) {

            av_log(avctx, AV_LOG_ERROR, "Error submitting the frame for encoding.\n");

            return ret;

        }

    }



    ret = ff_alloc_packet(pkt, q->packet_size);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");

        return ret;

    }

    bs.Data      = pkt->data;

    bs.MaxLength = pkt->size;



    do {

        ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, &bs, &sync);

        if (ret == MFX_WRN_DEVICE_BUSY)

            av_usleep(1);

    } while (ret > 0);



    if (ret < 0)

        return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret);



    if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)

        print_interlace_msg(avctx, q);



    if (sync) {

        MFXVideoCORE_SyncOperation(q->session, sync, 60000);



        if (bs.FrameType & MFX_FRAMETYPE_I || bs.FrameType & MFX_FRAMETYPE_xI)

            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;

        else if (bs.FrameType & MFX_FRAMETYPE_P || bs.FrameType & MFX_FRAMETYPE_xP)

            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;

        else if (bs.FrameType & MFX_FRAMETYPE_B || bs.FrameType & MFX_FRAMETYPE_xB)

            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;



        pkt->dts  = av_rescale_q(bs.DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);

        pkt->pts  = av_rescale_q(bs.TimeStamp,       (AVRational){1, 90000}, avctx->time_base);

        pkt->size = bs.DataLength;



        if (bs.FrameType & MFX_FRAMETYPE_IDR ||

            bs.FrameType & MFX_FRAMETYPE_xIDR)

            pkt->flags |= AV_PKT_FLAG_KEY;



        *got_packet = 1;

    }



    return 0;

}

int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q,

                  AVPacket *pkt, const AVFrame *frame, int *got_packet)

{

    mfxBitstream bs = { { { 0 } } };



    mfxFrameSurface1 *surf = NULL;

    mfxSyncPoint sync      = NULL;

    int ret;



    if (frame) {

        ret = submit_frame(q, frame, &surf);

        if (ret < 0) {

            av_log(avctx, AV_LOG_ERROR, "Error submitting the frame for encoding.\n");

            return ret;

        }

    }



    ret = ff_alloc_packet(pkt, q->packet_size);

    if (ret < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");

        return ret;

    }

    bs.Data      = pkt->data;

    bs.MaxLength = pkt->size;



    do {

        ret = MFXVideoENCODE_EncodeFrameAsync(q->session, NULL, surf, &bs, &sync);

        if (ret == MFX_WRN_DEVICE_BUSY)

            av_usleep(1);

    } while (ret > 0);



    if (ret < 0)

        return (ret == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(ret);



    if (ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && frame->interlaced_frame)

        print_interlace_msg(avctx, q);



    if (sync) {

        MFXVideoCORE_SyncOperation(q->session, sync, 60000);



        if (bs.FrameType & MFX_FRAMETYPE_I || bs.FrameType & MFX_FRAMETYPE_xI)

            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;

        else if (bs.FrameType & MFX_FRAMETYPE_P || bs.FrameType & MFX_FRAMETYPE_xP)

            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;

        else if (bs.FrameType & MFX_FRAMETYPE_B || bs.FrameType & MFX_FRAMETYPE_xB)

            avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;



        pkt->dts  = av_rescale_q(bs.DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base);

        pkt->pts  = av_rescale_q(bs.TimeStamp,       (AVRational){1, 90000}, avctx->time_base);

        pkt->size = bs.DataLength;



        if (bs.FrameType & MFX_FRAMETYPE_IDR ||

            bs.FrameType & MFX_FRAMETYPE_xIDR)

            pkt->flags |= AV_PKT_FLAG_KEY;



        *got_packet = 1;

    }



    return 0;

}

        if (ret == MFX_WRN_DEVICE_BUSY)     } while (ret > 0);
int FUNC_0(AVCodecContext *VAR_0, QSVEncContext *VAR_1,

                  AVPacket *VAR_2, const AVFrame *VAR_3, int *VAR_4)

{

    mfxBitstream bs = { { { 0 } } };



    mfxFrameSurface1 *surf = NULL;

    mfxSyncPoint sync      = NULL;

    int VAR_5;



    if (VAR_3) {

        VAR_5 = submit_frame(VAR_1, VAR_3, &surf);

        if (VAR_5 < 0) {

            av_log(VAR_0, AV_LOG_ERROR, "Error submitting the VAR_3 for encoding.\n");

            return VAR_5;

        }

    }



    VAR_5 = ff_alloc_packet(VAR_2, VAR_1->packet_size);

    if (VAR_5 < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error allocating the output packet\n");

        return VAR_5;

    }

    bs.Data      = VAR_2->data;

    bs.MaxLength = VAR_2->size;



    do {

        VAR_5 = MFXVideoENCODE_EncodeFrameAsync(VAR_1->session, NULL, surf, &bs, &sync);

        if (VAR_5 == MFX_WRN_DEVICE_BUSY)

            av_usleep(1);

    } while (VAR_5 > 0);



    if (VAR_5 < 0)

        return (VAR_5 == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(VAR_5);



    if (VAR_5 == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && VAR_3->interlaced_frame)

        print_interlace_msg(VAR_0, VAR_1);



    if (sync) {

        MFXVideoCORE_SyncOperation(VAR_1->session, sync, 60000);



        if (bs.FrameType & MFX_FRAMETYPE_I || bs.FrameType & MFX_FRAMETYPE_xI)

            VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_I;

        else if (bs.FrameType & MFX_FRAMETYPE_P || bs.FrameType & MFX_FRAMETYPE_xP)

            VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_P;

        else if (bs.FrameType & MFX_FRAMETYPE_B || bs.FrameType & MFX_FRAMETYPE_xB)

            VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_B;



        VAR_2->dts  = av_rescale_q(bs.DecodeTimeStamp, (AVRational){1, 90000}, VAR_0->time_base);

        VAR_2->pts  = av_rescale_q(bs.TimeStamp,       (AVRational){1, 90000}, VAR_0->time_base);

        VAR_2->size = bs.DataLength;



        if (bs.FrameType & MFX_FRAMETYPE_IDR ||

            bs.FrameType & MFX_FRAMETYPE_xIDR)

            VAR_2->flags |= AV_PKT_FLAG_KEY;



        *VAR_4 = 1;

    }



    return 0;

}

int FUNC_0(AVCodecContext *VAR_0, QSVEncContext *VAR_1,
AVPacket *VAR_2, const AVFrame *VAR_3, int *VAR_4)
{ mfxBitstream bs = { { { 0 } } }; mfxFrameSurface1 *surf = NULL; mfxSyncPoint sync      = NULL; int VAR_5; if (VAR_3) { VAR_5 = submit_frame(VAR_1, VAR_3, &surf); if (VAR_5 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error submitting the VAR_3 for encoding.\n"); return VAR_5; } } VAR_5 = ff_alloc_packet(VAR_2, VAR_1->packet_size); if (VAR_5 < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error allocating the output packet\n"); return VAR_5; } bs.Data      = VAR_2->data; bs.MaxLength = VAR_2->size; do { VAR_5 = MFXVideoENCODE_EncodeFrameAsync(VAR_1->session, NULL, surf, &bs, &sync); if (VAR_5 == MFX_WRN_DEVICE_BUSY)
av_usleep(1); } while (VAR_5 > 0); if (VAR_5 < 0)
return (VAR_5 == MFX_ERR_MORE_DATA) ? 0 : ff_qsv_error(VAR_5); if (VAR_5 == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM && VAR_3->interlaced_frame)
print_interlace_msg(VAR_0, VAR_1); if (sync) { MFXVideoCORE_SyncOperation(VAR_1->session, sync, 60000); if (bs.FrameType & MFX_FRAMETYPE_I || bs.FrameType & MFX_FRAMETYPE_xI)
VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_I; else if (bs.FrameType & MFX_FRAMETYPE_P || bs.FrameType & MFX_FRAMETYPE_xP)
VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_P; else if (bs.FrameType & MFX_FRAMETYPE_B || bs.FrameType & MFX_FRAMETYPE_xB)
VAR_0->coded_frame->pict_type = AV_PICTURE_TYPE_B; VAR_2->dts  = av_rescale_q(bs.DecodeTimeStamp, (AVRational){1, 90000}, VAR_0->time_base); VAR_2->pts  = av_rescale_q(bs.TimeStamp,       (AVRational){1, 90000}, VAR_0->time_base); VAR_2->size = bs.DataLength; if (bs.FrameType & MFX_FRAMETYPE_IDR ||
bs.FrameType & MFX_FRAMETYPE_xIDR)
VAR_2->flags |= AV_PKT_FLAG_KEY; *VAR_4 = 1; } return 0; }