int ff_dxva2_commit_buffer(AVCodecContext *avctx,

                           AVDXVAContext *ctx,

                           DECODER_BUFFER_DESC *dsc,

                           unsigned type, const void *data, unsigned size,

                           unsigned mb_count)

{

    void     *dxva_data;

    unsigned dxva_size;

    int      result;

    HRESULT hr;



#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,

                                                 D3D11VA_CONTEXT(ctx)->decoder,

                                                 type,

                                                 &dxva_size, &dxva_data);

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, type,

                                            &dxva_data, &dxva_size);

#endif

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%lx\n",

               type, hr);

        return -1;

    }

    if (size <= dxva_size) {

        memcpy(dxva_data, data, size);



#if CONFIG_D3D11VA

        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

            D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc;

            memset(dsc11, 0, sizeof(*dsc11));

            dsc11->BufferType           = type;

            dsc11->DataSize             = size;

            dsc11->NumMBsInBuffer       = mb_count;

        }

#endif

#if CONFIG_DXVA2

        if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

            DXVA2_DecodeBufferDesc *dsc2 = dsc;

            memset(dsc2, 0, sizeof(*dsc2));

            dsc2->CompressedBufferType = type;

            dsc2->DataSize             = size;

            dsc2->NumMBsInBuffer       = mb_count;

        }

#endif



        result = 0;

    } else {

        av_log(avctx, AV_LOG_ERROR, "Buffer for type %u was too small\n", type);

        result = -1;

    }



#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type);

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type);

#endif

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR,

               "Failed to release buffer type %u: 0x%lx\n",

               type, hr);

        result = -1;

    }

    return result;

}

int ff_dxva2_commit_buffer(AVCodecContext *avctx,

                           AVDXVAContext *ctx,

                           DECODER_BUFFER_DESC *dsc,

                           unsigned type, const void *data, unsigned size,

                           unsigned mb_count)

{

    void     *dxva_data;

    unsigned dxva_size;

    int      result;

    HRESULT hr;



#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context,

                                                 D3D11VA_CONTEXT(ctx)->decoder,

                                                 type,

                                                 &dxva_size, &dxva_data);

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(ctx)->decoder, type,

                                            &dxva_data, &dxva_size);

#endif

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%lx\n",

               type, hr);

        return -1;

    }

    if (size <= dxva_size) {

        memcpy(dxva_data, data, size);



#if CONFIG_D3D11VA

        if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

            D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc;

            memset(dsc11, 0, sizeof(*dsc11));

            dsc11->BufferType           = type;

            dsc11->DataSize             = size;

            dsc11->NumMBsInBuffer       = mb_count;

        }

#endif

#if CONFIG_DXVA2

        if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

            DXVA2_DecodeBufferDesc *dsc2 = dsc;

            memset(dsc2, 0, sizeof(*dsc2));

            dsc2->CompressedBufferType = type;

            dsc2->DataSize             = size;

            dsc2->NumMBsInBuffer       = mb_count;

        }

#endif



        result = 0;

    } else {

        av_log(avctx, AV_LOG_ERROR, "Buffer for type %u was too small\n", type);

        result = -1;

    }



#if CONFIG_D3D11VA

    if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type);

#endif

#if CONFIG_DXVA2

    if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(ctx)->decoder, type);

#endif

    if (FAILED(hr)) {

        av_log(avctx, AV_LOG_ERROR,

               "Failed to release buffer type %u: 0x%lx\n",

               type, hr);

        result = -1;

    }

    return result;

}

    HRESULT hr;
int FUNC_0(AVCodecContext *VAR_0,

                           AVDXVAContext *VAR_1,

                           DECODER_BUFFER_DESC *VAR_2,

                           unsigned VAR_3, const void *VAR_4, unsigned VAR_5,

                           unsigned VAR_6)

{

    void     *VAR_7;

    unsigned VAR_8;

    int      VAR_9;

    HRESULT hr;



#if CONFIG_D3D11VA

    if (VAR_0->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(VAR_1)->video_context,

                                                 D3D11VA_CONTEXT(VAR_1)->decoder,

                                                 VAR_3,

                                                 &VAR_8, &VAR_7);

#endif

#if CONFIG_DXVA2

    if (VAR_0->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(VAR_1)->decoder, VAR_3,

                                            &VAR_7, &VAR_8);

#endif

    if (FAILED(hr)) {

        av_log(VAR_0, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%lx\n",

               VAR_3, hr);

        return -1;

    }

    if (VAR_5 <= VAR_8) {

        memcpy(VAR_7, VAR_4, VAR_5);



#if CONFIG_D3D11VA

        if (VAR_0->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {

            D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = VAR_2;

            memset(dsc11, 0, sizeof(*dsc11));

            dsc11->BufferType           = VAR_3;

            dsc11->DataSize             = VAR_5;

            dsc11->NumMBsInBuffer       = VAR_6;

        }

#endif

#if CONFIG_DXVA2

        if (VAR_0->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {

            DXVA2_DecodeBufferDesc *dsc2 = VAR_2;

            memset(dsc2, 0, sizeof(*dsc2));

            dsc2->CompressedBufferType = VAR_3;

            dsc2->DataSize             = VAR_5;

            dsc2->NumMBsInBuffer       = VAR_6;

        }

#endif



        VAR_9 = 0;

    } else {

        av_log(VAR_0, AV_LOG_ERROR, "Buffer for VAR_3 %u was too small\n", VAR_3);

        VAR_9 = -1;

    }



#if CONFIG_D3D11VA

    if (VAR_0->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)

        hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(VAR_1)->video_context, D3D11VA_CONTEXT(VAR_1)->decoder, VAR_3);

#endif

#if CONFIG_DXVA2

    if (VAR_0->pix_fmt == AV_PIX_FMT_DXVA2_VLD)

        hr = IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(VAR_1)->decoder, VAR_3);

#endif

    if (FAILED(hr)) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Failed to release buffer VAR_3 %u: 0x%lx\n",

               VAR_3, hr);

        VAR_9 = -1;

    }

    return VAR_9;

}

int FUNC_0(AVCodecContext *VAR_0,
AVDXVAContext *VAR_1,
DECODER_BUFFER_DESC *VAR_2,
unsigned VAR_3, const void *VAR_4, unsigned VAR_5,
unsigned VAR_6)
{ void     *VAR_7; unsigned VAR_8; int      VAR_9; HRESULT hr; #if CONFIG_D3D11VA
if (VAR_0->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(VAR_1)->video_context,
D3D11VA_CONTEXT(VAR_1)->decoder,
VAR_3,
&VAR_8, &VAR_7); #endif
#if CONFIG_DXVA2
if (VAR_0->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
hr = IDirectXVideoDecoder_GetBuffer(DXVA2_CONTEXT(VAR_1)->decoder, VAR_3,
&VAR_7, &VAR_8); #endif
if (FAILED(hr)) { av_log(VAR_0, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%lx\n",
VAR_3, hr); return -1; } if (VAR_5 <= VAR_8) { memcpy(VAR_7, VAR_4, VAR_5); #if CONFIG_D3D11VA
if (VAR_0->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = VAR_2; memset(dsc11, 0, sizeof(*dsc11)); dsc11->BufferType           = VAR_3; dsc11->DataSize             = VAR_5; dsc11->NumMBsInBuffer       = VAR_6; } #endif
#if CONFIG_DXVA2
if (VAR_0->pix_fmt == AV_PIX_FMT_DXVA2_VLD) { DXVA2_DecodeBufferDesc *dsc2 = VAR_2; memset(dsc2, 0, sizeof(*dsc2)); dsc2->CompressedBufferType = VAR_3; dsc2->DataSize             = VAR_5; dsc2->NumMBsInBuffer       = VAR_6; } #endif
VAR_9 = 0; } else { av_log(VAR_0, AV_LOG_ERROR, "Buffer for VAR_3 %u was too small\n", VAR_3); VAR_9 = -1; } #if CONFIG_D3D11VA
if (VAR_0->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(VAR_1)->video_context, D3D11VA_CONTEXT(VAR_1)->decoder, VAR_3); #endif
#if CONFIG_DXVA2
if (VAR_0->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
hr = IDirectXVideoDecoder_ReleaseBuffer(DXVA2_CONTEXT(VAR_1)->decoder, VAR_3); #endif
if (FAILED(hr)) { av_log(VAR_0, AV_LOG_ERROR,
"Failed to release buffer VAR_3 %u: 0x%lx\n",
VAR_3, hr); VAR_9 = -1; } return VAR_9; }