CD3D9Device::CD3D9Device() { m_pD3D9 = NULL; m_pD3DD9 = NULL; m_pDeviceManager9 = NULL; MSDK_ZERO_MEMORY(m_D3DPP); m_resetToken = 0; m_nViews = 0; m_pS3DControl = NULL; MSDK_ZERO_MEMORY(m_backBufferDesc); m_pDXVAVPS = NULL; m_pDXVAVP_Left = NULL; m_pDXVAVP_Right = NULL; MSDK_ZERO_MEMORY(m_targetRect); MSDK_ZERO_MEMORY(m_VideoDesc); MSDK_ZERO_MEMORY(m_BltParams); MSDK_ZERO_MEMORY(m_Sample); // Initialize DXVA structures DXVA2_AYUVSample16 color = { 0x8000, // Cr 0x8000, // Cb 0x1000, // Y 0xffff // Alpha }; DXVA2_ExtendedFormat format = { // DestFormat DXVA2_SampleProgressiveFrame, // SampleFormat DXVA2_VideoChromaSubsampling_MPEG2, // VideoChromaSubsampling DXVA_NominalRange_0_255, // NominalRange DXVA2_VideoTransferMatrix_BT709, // VideoTransferMatrix DXVA2_VideoLighting_bright, // VideoLighting DXVA2_VideoPrimaries_BT709, // VideoPrimaries DXVA2_VideoTransFunc_709 // VideoTransferFunction }; // init m_VideoDesc structure MSDK_MEMCPY_VAR(m_VideoDesc.SampleFormat, &format, sizeof(DXVA2_ExtendedFormat)); m_VideoDesc.SampleWidth = 0; m_VideoDesc.SampleHeight = 0; m_VideoDesc.InputSampleFreq.Numerator = 60; m_VideoDesc.InputSampleFreq.Denominator = 1; m_VideoDesc.OutputFrameFreq.Numerator = 60; m_VideoDesc.OutputFrameFreq.Denominator = 1; // init m_BltParams structure MSDK_MEMCPY_VAR(m_BltParams.DestFormat, &format, sizeof(DXVA2_ExtendedFormat)); MSDK_MEMCPY_VAR(m_BltParams.BackgroundColor, &color, sizeof(DXVA2_AYUVSample16)); // init m_Sample structure m_Sample.Start = 0; m_Sample.End = 1; m_Sample.SampleFormat = format; m_Sample.PlanarAlpha.Fraction = 0; m_Sample.PlanarAlpha.Value = 1; m_bIsA2rgb10 = FALSE; }
mfxStatus CRendererPipeline::AllocFrames() { mfxStatus sts = MFX_ERR_NONE; mfxFrameAllocRequest EncRequest; mfxU16 nEncSurfNum = 0; // number of surfaces for encoder MSDK_ZERO_MEMORY(EncRequest); MFXVideoENCODE*pmfxENC = new MFXVideoENCODE(m_mfxSession); mfxVideoParam mfxEncParams; MSDK_ZERO_MEMORY(mfxEncParams); mfxEncParams.mfx.CodecId = MFX_CODEC_AVC; mfxEncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED; mfxEncParams.mfx.TargetKbps = 1024; // in Kbps mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_CBR; mfxEncParams.mfx.NumSlice = 0; ConvertFrameRate(60, &mfxEncParams.mfx.FrameInfo.FrameRateExtN, &mfxEncParams.mfx.FrameInfo.FrameRateExtD); mfxEncParams.mfx.EncodedOrder = 0; // binary flag, 0 signals encoder to take frames in display order mfxEncParams.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY; // frame info parameters mfxEncParams.mfx.FrameInfo.FourCC = (m_bUsedNV12 ? MFX_FOURCC_NV12 : MFX_FOURCC_YV12); mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420; mfxEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE; // set frame size and crops // width must be a multiple of 16 // height must be a multiple of 16 in case of frame picture and a multiple of 32 in case of field picture mfxEncParams.mfx.FrameInfo.Width = (m_nWidth); mfxEncParams.mfx.FrameInfo.Height = (m_nHeight); mfxEncParams.mfx.FrameInfo.CropX = 0; mfxEncParams.mfx.FrameInfo.CropY = 0; mfxEncParams.mfx.FrameInfo.CropW = (m_nWidth); mfxEncParams.mfx.FrameInfo.CropH = (m_nHeight); //mfxEncParams.mfx.GopRefDist = 1; //mfxEncParams.mfx.GopPicSize = m_mfxEncParams.mfx.GopPicSize; mfxEncParams.AsyncDepth = 1; sts = pmfxENC->QueryIOSurf(&mfxEncParams, &EncRequest); MSDK_SAFE_DELETE(pmfxENC); // Calculate the number of surfaces for components. // QueryIOSurf functions tell how many surfaces are required to produce at least 1 output. // To achieve better performance we provide extra surfaces. // 1 extra surface at input allows to get 1 extra output. if (EncRequest.NumFrameSuggested < mfxEncParams.AsyncDepth) return MFX_ERR_MEMORY_ALLOC; // The number of surfaces shared by vpp output and encode input. nEncSurfNum = EncRequest.NumFrameSuggested; // prepare allocation requests EncRequest.NumFrameSuggested = EncRequest.NumFrameMin = nEncSurfNum; MSDK_MEMCPY_VAR(EncRequest.Info, &(mfxEncParams.mfx.FrameInfo), sizeof(mfxFrameInfo)); // alloc frames for encoder sts = m_pMFXAllocator->Alloc(m_pMFXAllocator->pthis, &EncRequest, &m_EncResponse); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); // prepare mfxFrameSurface1 array for encoder m_pEncSurfaces = new mfxFrameSurface1[m_EncResponse.NumFrameActual]; MSDK_CHECK_POINTER(m_pEncSurfaces, MFX_ERR_MEMORY_ALLOC); for (int i = 0; i < m_EncResponse.NumFrameActual; i++) { memset(&(m_pEncSurfaces[i]), 0, sizeof(mfxFrameSurface1)); MSDK_MEMCPY_VAR(m_pEncSurfaces[i].Info, &(mfxEncParams.mfx.FrameInfo), sizeof(mfxFrameInfo)); m_pEncSurfaces[i].Data.MemId = m_EncResponse.mids[i]; } return MFX_ERR_NONE; }