HRESULT D3DPresentEngine::createVideoSamples(IMFMediaType *format, QList<IMFSample*> &videoSampleQueue) { if (!format) return MF_E_UNEXPECTED; HRESULT hr = S_OK; D3DPRESENT_PARAMETERS pp; IDirect3DSwapChain9 *swapChain = NULL; IMFSample *videoSample = NULL; QMutexLocker locker(&m_mutex); releaseResources(); // Get the swap chain parameters from the media type. hr = getSwapChainPresentParameters(format, &pp); if (FAILED(hr)) goto done; // Create the video samples. for (int i = 0; i < PRESENTER_BUFFER_COUNT; i++) { // Create a new swap chain. hr = m_device->CreateAdditionalSwapChain(&pp, &swapChain); if (FAILED(hr)) goto done; // Create the video sample from the swap chain. hr = createD3DSample(swapChain, &videoSample); if (FAILED(hr)) goto done; // Add it to the list. videoSample->AddRef(); videoSampleQueue.append(videoSample); // 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 = videoSample->SetUnknown(MFSamplePresenter_SampleSwapChain, swapChain); if (FAILED(hr)) goto done; qt_wmf_safeRelease(&videoSample); qt_wmf_safeRelease(&swapChain); } done: if (FAILED(hr)) releaseResources(); qt_wmf_safeRelease(&swapChain); qt_wmf_safeRelease(&videoSample); return hr; }