Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

MFXVideoDECODE::DecodeHeader Access violation

Atsushi_S_
Beginner
447 Views

Hello.

I am developing application that decode mpeg2, h.264 video stream with HW.

That's application change BackBuffer of Direct3DDevice dynamically.

So, that's application call IDirect3DDevice9::Reset API.

IDirect3DDevice9::Reset must be called after release all resouce depend on Direct3DDevice.

So, I implement following routine.

< Release>

    1.MFXVideoDECODE::Close

    2.MFXVideoSession::Close

    3.MFXFrameAllocator::Free

< Reset >

   1.IDirect3DDevice9::Reset

   2.IDirect3DDeviceManager9::ResetDevice

< ReCreate >

   1.MFXVideoSession::Init

   2.MFXVideoSession::SetHandle

   3.MFXVideoSession::SetFrameAllocator

   4.MFXVideoDECODE::DecodeHeader

   5.MFXFrameAllocator::Alloc

   6.MFXVideoDECODE::Init

In many case, all routines are fine.

But, sometime  Access violation happen in MFXVideoDECODE::DecodeHeader(ReCreate Routine No.4)

Are those routine right ?

How Can I solve this violation ?

My developing enviroment is

OS:Windows 7 SP1 Professional 32bit

CPU: Intel Core i7 - 3770 CPU @ 3.40 GHz

RAM:4.00GB

Graphics: Intel(R) HD Graphics 4000

Graphics Driver Ver:10.18.10.3621

Media Sdk Ver: Media SDK 2014 R2 for Clients

 

 

0 Kudos
2 Replies
Sravanthi_K_Intel
447 Views

Hello,
For decoding an mpeg2 or h264 stream, the routines you listed are alright.
You mention "application that decode mpeg2, h.264 video stream with HW" -> are you saying you are decoding both mpeg2 and h26 input streams in one session? If so, you will need to reset the session when moving from one format to another. And this step is missing in your routines listed.(Something to note - when debugging the application, make sure the structure "m_mfxBS" in DecodeHeader is populated with the correct meta info). If I am missing something in your question, do let me know.

Having said that, can you please provide some more information on your application code structure (for example, where are the loops) and input streams? In general, it will help us reproduce the issue if you could use as much existing code (from samples or tutorials) and bigbuckbunny as input stream.

Thank you.

0 Kudos
Atsushi_S_
Beginner
447 Views

Hello SRAVANTHI.

I try to reproduce this problem on Video Decoding Sample 5.0.461.91752 of Intel Media Sdk.

I add a funtion which name is ResetDirect3DDevice to pipeline_decode.cpp.

And change CD3D9Device::Reset of d3d_device.cpp.

I attached that's file.

The function is

mfxStatus CDecodingPipeline::ResetDirect3DDevice(void){

 mfxStatus sts = MFX_ERR_NONE;
 sInputParams        Params;
 Params.videoType = MFX_CODEC_AVC; // I try this func with H.264  only
 Params.bUseHWLib = true;
 Params.memType = D3D9_MEMORY;
 Params.mode = MODE_RENDERING;
 Params.nAsyncDepth = 4;
 mfxVersion min_version;
 mfxVersion version;

    // close decoder
    sts = m_pmfxDEC->Close();
    MSDK_IGNORE_MFX_STS(sts, MFX_ERR_NOT_INITIALIZED);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 sts = m_mfxSession.Close();

 MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
    // free allocated frames
    DeleteFrames();
    m_pCurrentFreeSurface = NULL;
    m_pCurrentFreeOutputSurface = NULL;

 sts = m_hwdev->Reset();
 MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 

    // we set version to 1.0 and later we will query actual version of the library which will got leaded
    min_version.Major = 1;
    min_version.Minor = 0;

    // Init session
    if (Params.bUseHWLib)
    {
        // try searching on all display adapters
        mfxIMPL impl = MFX_IMPL_HARDWARE_ANY;

        // if d3d11 surfaces are used ask the library to run acceleration through D3D11
        // feature may be unsupported due to OS or MSDK API version
        if (D3D11_MEMORY == Params.memType)
            impl |= MFX_IMPL_VIA_D3D11;

        sts = m_mfxSession.Init(impl, &min_version);

        // MSDK API version may not support multiple adapters - then try initialize on the default
        if (MFX_ERR_NONE != sts)
            sts = m_mfxSession.Init((impl & !MFX_IMPL_HARDWARE_ANY) | MFX_IMPL_HARDWARE, &min_version);
    }
    else
        sts = m_mfxSession.Init(MFX_IMPL_SOFTWARE, &min_version);

    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 sts = MFXQueryVersion(m_mfxSession , &version); // get real API version of the loaded library
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 mfxHDL hdl = NULL;
    mfxHandleType hdl_t = MFX_HANDLE_D3D9_DEVICE_MANAGER;

 sts = m_hwdev->GetHandle(hdl_t, &hdl);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
    sts = m_mfxSession.SetHandle(hdl_t, hdl);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 sts = m_mfxSession.SetFrameAllocator(m_pMFXAllocator);
 MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    // initialize parameters with values from parsed header
    sts = InitMfxParams(&Params);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    // in case of HW accelerated decode frames must be allocated prior to decoder initialization
    sts = AllocFrames();
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    // init decoder
    sts = m_pmfxDEC->Init(&m_mfxVideoParams);
    if (MFX_WRN_PARTIAL_ACCELERATION == sts)
    {
        msdk_printf(MSDK_STRING("WARNING: partial acceleration\n"));
        MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
    }
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    return MFX_ERR_NONE;

}

And CD3D9Device::Reset is

mfxStatus CD3D9Device::Reset()
{
    HRESULT hr = NO_ERROR;

    D3DPRESENT_PARAMETERS d3dpp=m_D3DPP;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    D3DDISPLAYMODE d3dmodeTemp;
    m_pD3DD9->GetDisplayMode(0, &d3dmodeTemp);

    d3dpp.BackBufferWidth  = d3dmodeTemp.Width;
    d3dpp.BackBufferHeight = d3dmodeTemp.Height;
    //Change START
 d3dpp.Windowed = TRUE;
 d3dpp.SwapEffect =D3DSWAPEFFECT_DISCARD;
 d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
 d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
   //Change END

    // Reset will change the parameters, so use a copy instead.
    D3DPRESENT_PARAMETERS d3dppTmp=d3dpp;
    hr = m_pD3DD9->ResetEx(&d3dppTmp, NULL);
    if (FAILED(hr))
        return MFX_ERR_UNDEFINED_BEHAVIOR;
    m_D3DPP = d3dpp;

    hr = m_pDeviceManager9->ResetDevice(m_pD3DD9, m_resetToken);
    if (FAILED(hr))
        return MFX_ERR_UNDEFINED_BEHAVIOR;

    return MFX_ERR_NONE;
}

And I called ResetDirect3DDevice every thirty m_pmfxDEC->DecodeFrameAsync in CDecodingPipeline::RunDecoding (please refer attached file).

The problem reproduce on "InitMfxParams(&Params)" of this function.

Is this function right ?

Please advice to me.

Thank you.
 

 

0 Kudos
Reply