Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Sachin_R_
Beginner
98 Views

Initialize Camera Plugin in custom app

Hi, 

I'm trying to use colour correction filter present in camera plugin. I've been facing issues in initializing MFXVideoVPP object after enabling the Camera plugin.

The sample given in samples ( from github) works fine by default but when I try to use this plugin in my custom app, it never gets initialized. It loads from into the session without errors though. 

Here is the code that I've tried. This is really a hack - not real app code - I just want to see that MFXVideoVPP get initialized at first. The last call - Query fails very neatly saying unsupported params. 

Note: I'm hard-coding input params - all params are picked up from sample_camera example. Let the m_pmfxVPP get initialized at first place.

MFXVideoSession m_mfxSession;
	mfxVideoParam ml_mfxVideoParams;
	CHWDevice *m_hwdev;
	mfxStatus sts;
	MemType memTypeIn = SYSTEM_MEMORY , memTypeOut = D3D9_MEMORY;
	// API version
	mfxVersion version =  {10, MFX_VERSION_MAJOR};
	// try searching on all display adapters
	mfxIMPL impl = MFX_IMPL_HARDWARE_ANY;
	impl |= MFX_IMPL_VIA_D3D9;
	sts = m_mfxSession.Init(impl, &version);

	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	// create VP
	MFXVideoVPP* m_pmfxVPP = new MFXVideoVPP(m_mfxSession);
	MSDK_CHECK_POINTER(m_pmfxVPP, MFX_ERR_MEMORY_ALLOC);

    mfxHDL hdl = NULL;
	//HWDevice
	HWND window = NULL;
	m_hwdev = new CD3D9Device();

	 if (NULL == m_hwdev)
        return MFX_ERR_MEMORY_ALLOC;
    sts = m_hwdev->Init(0, 0, MSDKAdapter::GetNumber(m_mfxSession));
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	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);

	MFXFrameAllocator*      ml_pMFXd3dAllocator;
    mfxAllocatorParams*     ml_pmfxd3dAllocatorParams;
    MFXFrameAllocator*      ml_pMFXsysAllocator, *ml_pMFXAllocatorIn;
    mfxAllocatorParams*     ml_pmfxsysAllocatorParams, *ml_pmfxAllocatorParamsIn;

	MFXFrameAllocator*	ml_pMFXAllocatorOut;
	mfxAllocatorParams* ml_pmfxAllocatorParamsOut;


	ml_pMFXd3dAllocator = new D3DFrameAllocator;
	MSDK_CHECK_POINTER(ml_pMFXd3dAllocator, MFX_ERR_MEMORY_ALLOC);

	D3DAllocatorParams *pd3dAllocParams = new D3DAllocatorParams;
	MSDK_CHECK_POINTER(pd3dAllocParams, MFX_ERR_MEMORY_ALLOC);
	pd3dAllocParams->pManager = reinterpret_cast<IDirect3DDeviceManager9 *>(hdl);

	ml_pmfxd3dAllocatorParams = pd3dAllocParams;

	ml_pMFXAllocatorOut = ml_pMFXd3dAllocator;
	ml_pmfxAllocatorParamsOut = ml_pmfxd3dAllocatorParams;
	sts = m_mfxSession.SetFrameAllocator(ml_pMFXd3dAllocator);
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	// create system memory allocator
	ml_pMFXsysAllocator = new CamSysMemFrameAllocator;
	MSDK_CHECK_POINTER(ml_pMFXsysAllocator, MFX_ERR_MEMORY_ALLOC);

	CamSysMemAllocatorParams *pCamSysAllocParams = new CamSysMemAllocatorParams;
	MSDK_CHECK_POINTER(pCamSysAllocParams, MFX_ERR_MEMORY_ALLOC);
	pCamSysAllocParams->alignment = CAM_SYSMEM_ALIGNMENT;
	ml_pmfxsysAllocatorParams = pCamSysAllocParams;

	ml_pMFXAllocatorIn = ml_pMFXsysAllocator;
	ml_pmfxAllocatorParamsIn = ml_pmfxsysAllocatorParams;

	  // initialize memory allocator(s)
    sts = ml_pMFXAllocatorIn->Init(ml_pmfxAllocatorParamsIn);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	//Library plugin UID
	static const mfxU8 CAMERA_PIPE_UID[]  = {0x54, 0x54, 0x26, 0x16, 0x24, 0x33, 0x41, 0xe6, 0x93, 0xae, 0x89, 0x99, 0x42, 0xce, 0x73, 0x55};
	 mfxPluginUID        m_UID_Camera;
   
    sts = ml_pMFXAllocatorOut->Init(ml_pmfxAllocatorParamsOut);
   
	{
        MSDK_MEMCPY(m_UID_Camera.Data, CAMERA_PIPE_UID, 16);
        sts = MFXVideoUSER_Load(m_mfxSession, &m_UID_Camera, 1);
        MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
    }

	//mfx init
	ml_mfxVideoParams.vpp.In.CropX = 0;
	ml_mfxVideoParams.vpp.In.CropY = 0;
	ml_mfxVideoParams.vpp.In.Width  = (mfxU16)1920;
	ml_mfxVideoParams.vpp.In.Height = (mfxU16)1080;
	    // Width and height values must be aligned in order to arhive maximum paerfromance
    ml_mfxVideoParams.vpp.In.Width  = align_32(ml_mfxVideoParams.vpp.In.Width);
    ml_mfxVideoParams.vpp.In.Height = align(ml_mfxVideoParams.vpp.In.Height);

	ml_mfxVideoParams.vpp.In.CropW = (mfxU16)1920;
    ml_mfxVideoParams.vpp.In.CropH = (mfxU16)1080;

    // Add additional CropX,CropY if any
    ml_mfxVideoParams.vpp.In.CropX += align((mfxU16)0);
    ml_mfxVideoParams.vpp.In.CropY += (mfxU16)0;
    ml_mfxVideoParams.vpp.In.FourCC = 1429614930;
    //Only R16 input supported now, should use chroma format monochrome
    ml_mfxVideoParams.vpp.In.ChromaFormat = MFX_CHROMAFORMAT_MONOCHROME;

    ml_mfxVideoParams.vpp.In.BitDepthLuma = (mfxU16)10;

    // CropW of the output frame must be the same as CropW of the input. Resize is not supported
    // The same for CropH
    ml_mfxVideoParams.vpp.Out.CropW = (mfxU16)1920;
    ml_mfxVideoParams.vpp.Out.CropH = (mfxU16)1080;

    ml_mfxVideoParams.vpp.Out.Width  = align_32((mfxU16)1920);
    ml_mfxVideoParams.vpp.Out.Height = align((mfxU16)1080);
    ml_mfxVideoParams.vpp.Out.CropX  = align((mfxU16)0);
    ml_mfxVideoParams.vpp.Out.CropY  = (mfxU16)0;
    ml_mfxVideoParams.vpp.Out.FourCC = 876758866;
    //Only ARGB onput supported now, should use chroma format 444
    ml_mfxVideoParams.vpp.Out.ChromaFormat = MFX_CHROMAFORMAT_YUV444;

    ml_mfxVideoParams.vpp.Out.BitDepthLuma = 8; //pParams->frameInfo[VPP_OUT].FourCC == MFX_FOURCC_ARGB16 ? m_mfxVideoParams.vpp.In.BitDepthLuma : 8;

    ConvertFrameRate(24, &ml_mfxVideoParams.vpp.In.FrameRateExtN, &ml_mfxVideoParams.vpp.In.FrameRateExtD);
    ConvertFrameRate(24, &ml_mfxVideoParams.vpp.Out.FrameRateExtN, &ml_mfxVideoParams.vpp.Out.FrameRateExtD);

    // specify memory type
    ml_mfxVideoParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
	ml_mfxVideoParams.IOPattern |= MFX_IOPATTERN_OUT_VIDEO_MEMORY;

   
   ml_mfxVideoParams.AsyncDepth = 4;//(mfxU16)pParams->asyncDepth;

   mfxExtCamGammaCorrection      ml_GammaCorrection;
   ml_GammaCorrection.Mode =2;
   ml_GammaCorrection.NumPoints = 64;
   MSDK_ZERO_MEMORY(ml_GammaCorrection);
   ml_GammaCorrection.Header.BufferId = MFX_EXTBUF_CAM_GAMMA_CORRECTION;
   ml_GammaCorrection.Header.BufferSz = sizeof(ml_GammaCorrection);

   //mfxU16 gamma_point[64];
   //mfxU16 gamma_corrected[64];
   mfxU16 gamma_point[64] =
   {
	   0,  94, 104, 114, 124, 134, 144, 154, 159, 164, 169, 174, 179, 184, 194, 199,
	   204, 209, 214, 219, 224, 230, 236, 246, 256, 266, 276, 286, 296, 306, 316, 326,
	   336, 346, 356, 366, 376, 386, 396, 406, 416, 426, 436, 446, 456, 466, 476, 486,
	   496, 516, 526, 536, 546, 556, 566, 576, 586, 596, 606, 616, 626, 636, 646, 1023
   };

   mfxU16 gamma_correct[64] =
   {
	   4,   4,  20,  37,  56,  75,  96, 117, 128, 140, 150, 161, 171, 180, 198, 207,
	   216, 224, 232, 240, 249, 258, 268, 283, 298, 310, 329, 344, 359, 374, 389, 404,
	   420, 435, 451, 466, 482, 498, 515, 531, 548, 565, 582, 599, 617, 635, 653, 671,
	   690, 729, 749, 769, 790, 811, 832, 854, 876, 899, 922, 945, 969, 994, 1019,1019
   };
   MSDK_MEMCPY(ml_GammaCorrection.GammaPoint, gamma_point, ml_GammaCorrection.NumPoints*sizeof(mfxU16));
   MSDK_MEMCPY(ml_GammaCorrection.GammaCorrected, gamma_correct, ml_GammaCorrection.NumPoints*sizeof(mfxU16));

   std::vector<mfxExtBuffer *> ml_ExtBuffers;
   ml_ExtBuffers.push_back((mfxExtBuffer *)&ml_GammaCorrection);

   mfxExtCamPipeControl ml_PipeControl;
    MSDK_ZERO_MEMORY(ml_PipeControl);
    ml_PipeControl.Header.BufferId = MFX_EXTBUF_CAM_PIPECONTROL;
    ml_PipeControl.Header.BufferSz = sizeof(ml_PipeControl);
    ml_PipeControl.RawFormat = (mfxU16)0;
    ml_ExtBuffers.push_back((mfxExtBuffer *)&ml_PipeControl);

	
    ml_mfxVideoParams.ExtParam = reinterpret_cast<mfxExtBuffer**>(&ml_ExtBuffers[0]);
    ml_mfxVideoParams.NumExtParam = static_cast<mfxU16>(ml_ExtBuffers.size());

	//Init End

	//Query
	sts = m_pmfxVPP->Query(&ml_mfxVideoParams, &ml_mfxVideoParams);
    MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
    MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

 

0 Kudos
3 Replies
Anna_B_Intel
Employee
98 Views

Hi Sachin,

What exact error message returns Query: MFX_ERR_INVALID_VIDEO_PARAM or MFX_ERR_INVALID_VIDEO_PARAM?

Best wishes,

Anna

Sachin_R_
Beginner
98 Views

Hi Anna,

I get MFX_ERR_UNSUPPORTED for Query call. If i go ahead and perform Init() then I get MFX_ERR_INVALID_VIDEO_PARAM.

Thanks,

Sachin

Anna_B_Intel
Employee
98 Views

Make sure that you set correct input parameters (ml_mfxVideoParams.vpp.In.Width and ml_mfxVideoParams.vpp.In.Height) it should be the same with parameters of input video.

Best wishes,

Anna

Reply