MFXVideoDECODE_Init因MFX_ERR_MEMORY_ALLOC

时间:2017-10-26 07:45:17

标签: c++ decode intel intel-media-sdk

我正在尝试使用intel-media-sdk解码器来播放h.264视频。这是我的初始化解码器的代码:

mfxStatus decoder::initDecoder(HWND window, mfxBitstream *Header) {
    mfxStatus sts = MFX_ERR_NONE;
    mfxVersion ver = { { 0, 1 } };
    mfxVideoParam mfxVideoParams;
    mfxFrameAllocator mfxAllocator;
    mfxFrameAllocResponse mfxResponse;

    sts = m_mfxSession.Init(MFX_IMPL_AUTO_ANY, &ver); //sts = MFX_ERR_NONE

    if (sts == MFX_ERR_NONE) {
        sts = m_mfxSession.SetHandle(MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9, 
            m_renderer.initD3d(GetIntelDeviceAdapterNum(), window)); //sts = MFX_ERR_NONE
        if (sts == MFX_ERR_NONE) {
            mfxAllocator.pthis = m_mfxSession;
            sts = m_mfxSession.SetFrameAllocator(&mfxAllocator); //sts = MFX_ERR_NONE
            if (sts == MFX_ERR_NONE) {
                MFXVideoDECODE mfxDEC(m_mfxSession);
                m_mfxVideoDecode = mfxDEC;
                memset(&mfxVideoParams, 0, sizeof(mfxVideoParams));
                mfxVideoParams.mfx.CodecId = MFX_CODEC_AVC;
                mfxVideoParams.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;

                sts = m_mfxVideoDecode.DecodeHeader(Header, &mfxVideoParams); //sts = MFX_ERR_NONE
                if (sts == MFX_ERR_NONE) {
                    memset(&m_mfxRequest, 0, sizeof(m_mfxRequest));
                    sts = m_mfxVideoDecode.QueryIOSurf(&mfxVideoParams, &m_mfxRequest); //sts = MFX_ERR_NONE
                    if (sts == MFX_ERR_NONE) {
                        sts = m_renderer.allocSurfaces(mfxAllocator.pthis, &m_mfxRequest, &mfxResponse);
                        if (sts == MFX_ERR_NONE) {
                            m_pmfxSurfaces = new mfxFrameSurface1 *[m_mfxRequest.NumFrameSuggested];
                            for (int i = 0; i < m_mfxRequest.NumFrameSuggested; i++) {
                                m_pmfxSurfaces[i] = new mfxFrameSurface1;
                                memset(m_pmfxSurfaces[i], 0, sizeof(mfxFrameSurface1));
                                memcpy(&(m_pmfxSurfaces[i]->Info), &(mfxVideoParams.mfx.FrameInfo), sizeof(mfxFrameInfo));
                                // MID (memory id) represents one video NV12 surface
                                m_pmfxSurfaces[i]->Data.MemId = mfxResponse.mids[i];
                            };
                            sts = m_mfxVideoDecode.Init(&mfxVideoParams); //sts = MFX_ERR_MEMORY_ALLOC
                        }
                    }
                }
            }
        }
    }

    return sts;
}

因为你可以看到MFXVideoDECODE::Init(mfxVideoParam*)(内部调用MFXVideoDECODE_Init)返回MFX_ERR_MEMORY_ALLOC,这里奇怪的是this document它说这个函数没有这个回复值。

以下是有关mfxVideoParams的一些调试信息:

  

AllocId = 0,AsyncDepth = 0,IOPattern = 16,mfx.CodecId = 541283905,   mfx.CodecProfile = 77,mfx.CodecLevel = 30,vpp.In.FourCC = 842094158,   vpp.In.Width = 864,vpp.In.Height = 480,vpp.In.CropW = 854,   vpp.In.CropH = 480,vpp.In.BufferSize = 31458144,vpp.In.AspectRatioW   = 1,vpp.In.AspectRatioH = 1,vpp.In.PicStruct = 1,vpp.In.ChromaFormat = 1

以下是标题中的一些成员数据定义,用于此处:

MFXVideoSession m_mfxSession;
MFXVideoDECODE m_mfxVideoDecode;
mfxFrameAllocRequest m_mfxRequest;
mfxFrameSurface1** m_pmfxSurfaces;

以下是有关我当前工作设备的一些信息,可能与此问题有关:

  • 操作系统:Windows 8.1
  • 处理器:Intel(R)Core(TM)i5-3470 CPU @ 3.20GHZ
  • 系统类型:64位操作系统,基于x64的处理器
  • 已安装的内存(RAM):8.00 GB

最后重现完全相同的情况我从this site下载了名为big_buck_bunny_1080p_h264.mov的视频,然后用ffmpeg将其解压缩到h264并在我的程序中使用它。

1 个答案:

答案 0 :(得分:2)

您需要使用适当的函数初始化mfxFrameAlocator回调函数(Alloc,Free,GetHDL,...)。 例如:

//static member
mfxStatus decoder::gethdl(mfxHDL pthis, mfxMemId mid, mfxHDL* handle)
{
    pthis; // To avoid warning for this unused parameter

    if (handle == 0) return MFX_ERR_INVALID_HANDLE;

    *handle = mid;
    return MFX_ERR_NONE;
}



mfxStatus decoder::initDecoder(HWND window, mfxBitstream *Header) {

    //blah blah
    mfxAllocator.pthis = m_mfxSession;
    mfxAllocator.GetHDL = gethdl;
    //define for these too
    //mfxAllocator.Alloc = alloc;
    //mfxAllocator.Free = free;
    //mfxAllocator.Lock = lock;
    //mfxAllocator.Unlock = unlock;

    //rest of your code
}