Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dxva2 decode error #1256

Closed
fogin opened this issue Apr 12, 2024 · 2 comments
Closed

dxva2 decode error #1256

fogin opened this issue Apr 12, 2024 · 2 comments

Comments

@fogin
Copy link

fogin commented Apr 12, 2024

ERROR - A hardware frames or device context is required for hardware accelerated decoding.
ERROR - Failed setup for format dxva2_vld: hwaccel initialisation returned error.

when i use dxva2renderer, report this error

@cgutman
Copy link
Member

cgutman commented Apr 13, 2024

I need your full Moonlight log file to investigate.

@fogin
Copy link
Author

fogin commented Apr 15, 2024

I used the dxva2.cpp file alone as part of my renderer, and the error disappeared after I added the following code to the end of the initialize function:
{
m_HwDeviceContext = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_DXVA2);
if (!m_HwDeviceContext) {
ALOGE("Failed to allocate D3D11VA device context");
return false;
}

    AVHWDeviceContext* deviceContext = (AVHWDeviceContext*)m_HwDeviceContext->data;
    AVDXVA2DeviceContext* dxva2DevCtx = (AVDXVA2DeviceContext*)deviceContext->hwctx;

    // AVHWDeviceContext takes ownership of these objects
    UINT reset_token = 0;
    HRESULT hr = DXVA2CreateDirect3DDeviceManager9(&reset_token, &dxva2DevCtx->devmgr);
    if (FAILED(hr))
        return false;

    hr = dxva2DevCtx->devmgr->ResetDevice(m_Device, reset_token);
    if (FAILED(hr))
        return false;

    int err = av_hwdevice_ctx_init(m_HwDeviceContext);
    if (err < 0) {
        ALOGE("Failed to initialize D3D11VA device context: %d",
            err);
        return false;
    }
}

{
    m_HwFramesContext = av_hwframe_ctx_alloc(m_HwDeviceContext);
    if (!m_HwFramesContext) {
        ALOGE("Failed to allocate D3D11VA frame context");
        return false;
    }

    AVHWFramesContext* framesContext = (AVHWFramesContext*)m_HwFramesContext->data;

    // We require NV12 or P010 textures for our shader
    framesContext->format = AV_PIX_FMT_DXVA2_VLD;
    framesContext->sw_format = AV_PIX_FMT_NV12;

    framesContext->width = FFALIGN(params->width, 128);
    framesContext->height = FFALIGN(params->height, 128);
    /* 1 base work surface */
    int num_surfaces = 20;

    /* add surfaces based on number of possible refs */
    framesContext->initial_pool_size = num_surfaces;
    int err = av_hwframe_ctx_init(m_HwFramesContext);
    if (err < 0) {
        ALOGE("Failed to initialize D3D11VA frame context: %d", err);
        return false;
    }
}

@cgutman cgutman closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants