static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src,

                           int flags)

{

    IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->data[3];

    DXVA2Mapping      *map;

    D3DSURFACE_DESC    surfaceDesc;

    D3DLOCKED_RECT     LockedRect;

    HRESULT            hr;

    int i, err, nb_planes;

    int lock_flags = 0;



    nb_planes = av_pix_fmt_count_planes(dst->format);



    hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);

    if (FAILED(hr)) {

        av_log(ctx, AV_LOG_ERROR, "Error getting a surface description\n");

        return AVERROR_UNKNOWN;

    }



    if (!(flags & AV_HWFRAME_MAP_WRITE))

        lock_flags |= D3DLOCK_READONLY;

    if (flags & AV_HWFRAME_MAP_OVERWRITE)

        lock_flags |= D3DLOCK_DISCARD;



    hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, lock_flags);

    if (FAILED(hr)) {

        av_log(ctx, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");

        return AVERROR_UNKNOWN;

    }



    map = av_mallocz(sizeof(*map));

    if (!map)

        goto fail;



    err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,

                                dxva2_unmap_frame, map);

    if (err < 0) {

        av_freep(&map);

        goto fail;

    }



    for (i = 0; i < nb_planes; i++)

        dst->linesize[i] = LockedRect.Pitch;



    av_image_fill_pointers(dst->data, dst->format, surfaceDesc.Height,

                           (uint8_t*)LockedRect.pBits, dst->linesize);



    if (dst->format == AV_PIX_FMT_PAL8)

        dst->data[1] = (uint8_t*)map->palette_dummy;



    return 0;

fail:

    IDirect3DSurface9_UnlockRect(surface);

    return err;

}

static int dxva2_map_frame(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src,

                           int flags)

{

    IDirect3DSurface9 *surface = (IDirect3DSurface9*)src->data[3];

    DXVA2Mapping      *map;

    D3DSURFACE_DESC    surfaceDesc;

    D3DLOCKED_RECT     LockedRect;

    HRESULT            hr;

    int i, err, nb_planes;

    int lock_flags = 0;



    nb_planes = av_pix_fmt_count_planes(dst->format);



    hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);

    if (FAILED(hr)) {

        av_log(ctx, AV_LOG_ERROR, "Error getting a surface description\n");

        return AVERROR_UNKNOWN;

    }



    if (!(flags & AV_HWFRAME_MAP_WRITE))

        lock_flags |= D3DLOCK_READONLY;

    if (flags & AV_HWFRAME_MAP_OVERWRITE)

        lock_flags |= D3DLOCK_DISCARD;



    hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, lock_flags);

    if (FAILED(hr)) {

        av_log(ctx, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");

        return AVERROR_UNKNOWN;

    }



    map = av_mallocz(sizeof(*map));

    if (!map)

        goto fail;



    err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src,

                                dxva2_unmap_frame, map);

    if (err < 0) {

        av_freep(&map);

        goto fail;

    }



    for (i = 0; i < nb_planes; i++)

        dst->linesize[i] = LockedRect.Pitch;



    av_image_fill_pointers(dst->data, dst->format, surfaceDesc.Height,

                           (uint8_t*)LockedRect.pBits, dst->linesize);



    if (dst->format == AV_PIX_FMT_PAL8)

        dst->data[1] = (uint8_t*)map->palette_dummy;



    return 0;

fail:

    IDirect3DSurface9_UnlockRect(surface);

    return err;

}

    if (!map)
static int FUNC_0(AVHWFramesContext *VAR_0, AVFrame *VAR_1, const AVFrame *VAR_2,

                           int VAR_3)

{

    IDirect3DSurface9 *surface = (IDirect3DSurface9*)VAR_2->data[3];

    DXVA2Mapping      *map;

    D3DSURFACE_DESC    surfaceDesc;

    D3DLOCKED_RECT     LockedRect;

    HRESULT            hr;

    int VAR_4, VAR_5, VAR_6;

    int VAR_7 = 0;



    VAR_6 = av_pix_fmt_count_planes(VAR_1->format);



    hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc);

    if (FAILED(hr)) {

        av_log(VAR_0, AV_LOG_ERROR, "Error getting a surface description\n");

        return AVERROR_UNKNOWN;

    }



    if (!(VAR_3 & AV_HWFRAME_MAP_WRITE))

        VAR_7 |= D3DLOCK_READONLY;

    if (VAR_3 & AV_HWFRAME_MAP_OVERWRITE)

        VAR_7 |= D3DLOCK_DISCARD;



    hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, VAR_7);

    if (FAILED(hr)) {

        av_log(VAR_0, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");

        return AVERROR_UNKNOWN;

    }



    map = av_mallocz(sizeof(*map));

    if (!map)

        goto fail;



    VAR_5 = ff_hwframe_map_create(VAR_2->hw_frames_ctx, VAR_1, VAR_2,

                                dxva2_unmap_frame, map);

    if (VAR_5 < 0) {

        av_freep(&map);

        goto fail;

    }



    for (VAR_4 = 0; VAR_4 < VAR_6; VAR_4++)

        VAR_1->linesize[VAR_4] = LockedRect.Pitch;



    av_image_fill_pointers(VAR_1->data, VAR_1->format, surfaceDesc.Height,

                           (uint8_t*)LockedRect.pBits, VAR_1->linesize);



    if (VAR_1->format == AV_PIX_FMT_PAL8)

        VAR_1->data[1] = (uint8_t*)map->palette_dummy;



    return 0;

fail:

    IDirect3DSurface9_UnlockRect(surface);

    return VAR_5;

}

static int FUNC_0(AVHWFramesContext *VAR_0, AVFrame *VAR_1, const AVFrame *VAR_2,
int VAR_3)
{ IDirect3DSurface9 *surface = (IDirect3DSurface9*)VAR_2->data[3]; DXVA2Mapping      *map; D3DSURFACE_DESC    surfaceDesc; D3DLOCKED_RECT     LockedRect; HRESULT            hr; int VAR_4, VAR_5, VAR_6; int VAR_7 = 0; VAR_6 = av_pix_fmt_count_planes(VAR_1->format); hr = IDirect3DSurface9_GetDesc(surface, &surfaceDesc); if (FAILED(hr)) { av_log(VAR_0, AV_LOG_ERROR, "Error getting a surface description\n"); return AVERROR_UNKNOWN; } if (!(VAR_3 & AV_HWFRAME_MAP_WRITE))
VAR_7 |= D3DLOCK_READONLY; if (VAR_3 & AV_HWFRAME_MAP_OVERWRITE)
VAR_7 |= D3DLOCK_DISCARD; hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, VAR_7); if (FAILED(hr)) { av_log(VAR_0, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n"); return AVERROR_UNKNOWN; } map = av_mallocz(sizeof(*map)); if (!map)
goto fail; VAR_5 = ff_hwframe_map_create(VAR_2->hw_frames_ctx, VAR_1, VAR_2,
dxva2_unmap_frame, map); if (VAR_5 < 0) { av_freep(&map); goto fail; } for (VAR_4 = 0; VAR_4 < VAR_6; VAR_4++) VAR_1->linesize[VAR_4] = LockedRect.Pitch; av_image_fill_pointers(VAR_1->data, VAR_1->format, surfaceDesc.Height,
(uint8_t*)LockedRect.pBits, VAR_1->linesize); if (VAR_1->format == AV_PIX_FMT_PAL8)
VAR_1->data[1] = (uint8_t*)map->palette_dummy; return 0; fail:
IDirect3DSurface9_UnlockRect(surface); return VAR_5; }