protected void ClearDesiredSampleTime(IMFSample pSample) { if (pSample == null) { throw new COMException("ClearDesiredSampleTime", E_Pointer); } IMFDesiredSample pDesired = null; object pUnkSwapChain = null; // We store some custom attributes on the sample, so we need to cache them // and reset them. // // This works around the fact that IMFDesiredSample::Clear() removes all of the // attributes from the sample. int counter; int hr; hr = pSample.GetUINT32(MFSamplePresenter_SampleCounter, out counter); MFError.ThrowExceptionForHR(hr); try { Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); hr = pSample.GetUnknown(MFSamplePresenter_SampleSwapChain, IID_IUnknown, out pUnkSwapChain); MFError.ThrowExceptionForHR(hr); } catch { } pDesired = (IMFDesiredSample)pSample; pDesired.Clear(); hr = pSample.SetUINT32(MFSamplePresenter_SampleCounter, counter); MFError.ThrowExceptionForHR(hr); if (pUnkSwapChain != null) { hr = pSample.SetUnknown(MFSamplePresenter_SampleSwapChain, pUnkSwapChain); MFError.ThrowExceptionForHR(hr); } SafeRelease(pUnkSwapChain); //SafeRelease(pDesired); }
//----------------------------------------------------------------------------- // CreateVideoSamples // // Creates video samples based on a specified media type. // // pFormat: Media type that describes the video format. // videoSampleQueue: List that will contain the video samples. // // Note: For each video sample, the method creates a swap chain with a // single back buffer. The video sample object holds a pointer to the swap // chain's back buffer surface. The mixer renders to this surface, and the // D3DPresentEngine renders the video frame by presenting the swap chain. //----------------------------------------------------------------------------- public void CreateVideoSamples( IMFMediaType pFormat, Queue <IMFSample> videoSampleQueue ) { if (m_hwnd == IntPtr.Zero) { throw new COMException("D3DPresentEngine::CreateVideoSamples", (int)HResult.MF_E_INVALIDREQUEST); } if (pFormat == null) { throw new COMException("D3DPresentEngine::CreateVideoSamples", (int)HResult.MF_E_UNEXPECTED); } HResult hr; D3DPRESENT_PARAMETERS pp; IDirect3DSwapChain9 pSwapChain = null; // Swap chain IMFSample pVideoSample = null; // Sampl lock (this) { ReleaseResources(); try { // Get the swap chain parameters from the media type. GetSwapChainPresentParameters(pFormat, out pp); UpdateDestRect(); // Create the video samples. for (int i = 0; i < PRESENTER_BUFFER_COUNT; i++) { // Create a new swap chain. m_pDevice.CreateAdditionalSwapChain(pp, out pSwapChain); // Create the video sample from the swap chain. CreateD3DSample(pSwapChain, out pVideoSample); // Add it to the list. videoSampleQueue.Enqueue(pVideoSample); // Set the swap chain pointer as a custom attribute on the sample. This keeps // a reference count on the swap chain, so that the swap chain is kept alive // for the duration of the sample's lifetime. hr = pVideoSample.SetUnknown(EVRCustomPresenter.MFSamplePresenter_SampleSwapChain, pSwapChain); MFError.ThrowExceptionForHR(hr); //SafeRelease(pVideoSample); SafeRelease(pSwapChain); pSwapChain = null; } } catch { ReleaseResources(); } finally { SafeRelease(pSwapChain); pSwapChain = null; //SafeRelease(pVideoSample); } } }