static void CommitDecommitTest(void) { IMemAllocator* pMemAllocator; HRESULT hr; hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (LPVOID*)&pMemAllocator); ok(hr==S_OK, "Unable to create memory allocator %x\n", hr); if (hr == S_OK) { ALLOCATOR_PROPERTIES RequestedProps; ALLOCATOR_PROPERTIES ActualProps; IMediaSample *sample = NULL, *sample2 = NULL; RequestedProps.cBuffers = 2; RequestedProps.cbBuffer = 65536; RequestedProps.cbAlign = 1; RequestedProps.cbPrefix = 0; hr = IMemAllocator_SetProperties(pMemAllocator, &RequestedProps, &ActualProps); ok(hr==S_OK, "SetProperties returned: %x\n", hr); hr = IMemAllocator_Commit(pMemAllocator); ok(hr==S_OK, "Commit returned: %x\n", hr); hr = IMemAllocator_Commit(pMemAllocator); ok(hr==S_OK, "Commit returned: %x\n", hr); hr = IMemAllocator_GetBuffer(pMemAllocator, &sample, NULL, NULL, 0); ok(hr==S_OK, "Could not get a buffer: %x\n", hr); hr = IMemAllocator_Decommit(pMemAllocator); ok(hr==S_OK, "Decommit returned: %x\n", hr); hr = IMemAllocator_Decommit(pMemAllocator); ok(hr==S_OK, "Cecommit returned: %x\n", hr); /* Decommit and recommit while holding a sample */ if (sample) { hr = IMemAllocator_Commit(pMemAllocator); ok(hr==S_OK, "Commit returned: %x\n", hr); hr = IMemAllocator_GetBuffer(pMemAllocator, &sample2, NULL, NULL, 0); ok(hr==S_OK, "Could not get a buffer: %x\n", hr); IUnknown_Release(sample); if (sample2) IUnknown_Release(sample2); hr = IMemAllocator_Decommit(pMemAllocator); ok(hr==S_OK, "Cecommit returned: %x\n", hr); } IMemAllocator_Release(pMemAllocator); } }
HRESULT qcap_driver_stop(Capture *capBox, FILTER_STATE *state) { TRACE("%p -> (%p)\n", capBox, state); if (*state == State_Stopped) return S_OK; EnterCriticalSection(&capBox->CritSect); if (capBox->thread) { if (*state == State_Paused) ResumeThread(capBox->thread); capBox->stopped = 1; capBox->thread = 0; if (capBox->iscommitted) { IMemInputPin *pMem = NULL; IMemAllocator * pAlloc = NULL; IPin *pConnect = NULL; HRESULT hr; capBox->iscommitted = 0; hr = IPin_ConnectedTo(capBox->pOut, &pConnect); if (SUCCEEDED(hr)) hr = IPin_QueryInterface(pConnect, &IID_IMemInputPin, (void **) &pMem); if (SUCCEEDED(hr)) hr = IMemInputPin_GetAllocator(pMem, &pAlloc); if (SUCCEEDED(hr)) hr = IMemAllocator_Decommit(pAlloc); if (pAlloc) IMemAllocator_Release(pAlloc); if (pMem) IMemInputPin_Release(pMem); if (pConnect) IPin_Release(pConnect); if (hr != S_OK && hr != VFW_E_NOT_COMMITTED) WARN("Decommitting allocator: %x\n", hr); } V4l_Unprepare(capBox); } *state = State_Stopped; LeaveCriticalSection(&capBox->CritSect); return S_OK; }
/* IMemInputPin */ static HRESULT WINAPI SampleGrabber_IMemInputPin_NotifyAllocator(IMemInputPin *iface, IMemAllocator *allocator, BOOL readOnly) { SG_Impl *This = impl_from_IMemInputPin(iface); TRACE("(%p)->(%p, %u) allocator = %p\n", This, allocator, readOnly, This->allocator); if (This->allocator == allocator) return S_OK; if (This->allocator) IMemAllocator_Release(This->allocator); This->allocator = allocator; if (allocator) IMemAllocator_AddRef(allocator); return S_OK; }
static ULONG WINAPI QTOutPin_Release(IPin *iface) { QTOutPin *This = impl_QTOutPin_from_IPin(iface); ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount); TRACE("(%p)->() Release from %d\n", iface, refCount + 1); if (!refCount) { DeleteMediaType(This->pmt); FreeMediaType(&This->pin.pin.mtCurrent); if (This->pin.pAllocator) IMemAllocator_Release(This->pin.pAllocator); CoTaskMemFree(This); return 0; } return refCount; }
static ULONG WINAPI QTInPin_Release(IPin *iface) { QTInPin *This = impl_from_IPin(iface); ULONG refCount = InterlockedDecrement(&This->pin.refCount); TRACE("(%p)->() Release from %d\n", iface, refCount + 1); if (!refCount) { FreeMediaType(&This->pin.mtCurrent); if (This->pAlloc) IMemAllocator_Release(This->pAlloc); This->pAlloc = NULL; This->pin.IPin_iface.lpVtbl = NULL; return 0; } else return refCount; }
/* Cleanup at end of life */ static void SampleGrabber_cleanup(SG_Impl *This) { TRACE("(%p)\n", This); if (This->filter.filterInfo.pGraph) WARN("(%p) still joined to filter graph %p\n", This, This->filter.filterInfo.pGraph); if (This->allocator) IMemAllocator_Release(This->allocator); if (This->memOutput) IMemInputPin_Release(This->memOutput); if (This->grabberIface) ISampleGrabberCB_Release(This->grabberIface); if (This->mtype.pbFormat) CoTaskMemFree(This->mtype.pbFormat); if (This->bufferData) CoTaskMemFree(This->bufferData); if(This->seekthru_unk) IUnknown_Release(This->seekthru_unk); }
/* Cleanup at end of life */ static void SampleGrabber_cleanup(SG_Impl *This) { TRACE("(%p)\n", This); if (This->info.pGraph) WARN("(%p) still joined to filter graph %p\n", This, This->info.pGraph); if (This->allocator) IMemAllocator_Release(This->allocator); if (This->refClock) IReferenceClock_Release(This->refClock); if (This->memOutput) IMemInputPin_Release(This->memOutput); if (This->grabberIface) ISampleGrabberCB_Release(This->grabberIface); if (This->mtype.pbFormat) CoTaskMemFree(This->mtype.pbFormat); if (This->bufferData) CoTaskMemFree(This->bufferData); if(This->seekthru_unk) IUnknown_Release(This->seekthru_unk); This->critSect.DebugInfo->Spare[0] = 0; DeleteCriticalSection(&This->critSect); }
HRESULT qcap_driver_run(Capture *capBox, FILTER_STATE *state) { HANDLE thread; HRESULT hr; TRACE("%p -> (%p)\n", capBox, state); if (*state == State_Running) return S_OK; EnterCriticalSection(&capBox->CritSect); capBox->stopped = 0; if (*state == State_Stopped) { *state = State_Running; if (!capBox->iscommitted++) { IMemAllocator * pAlloc = NULL; ALLOCATOR_PROPERTIES ap, actual; OutputPin *out; ap.cBuffers = 3; if (!capBox->swresize) ap.cbBuffer = capBox->width * capBox->height; else ap.cbBuffer = capBox->outputwidth * capBox->outputheight; ap.cbBuffer = (ap.cbBuffer * capBox->bitDepth) / 8; ap.cbAlign = 1; ap.cbPrefix = 0; out = (OutputPin *)capBox->pOut; hr = IMemInputPin_GetAllocator(out->pMemInputPin, &pAlloc); if (SUCCEEDED(hr)) hr = IMemAllocator_SetProperties(pAlloc, &ap, &actual); if (SUCCEEDED(hr)) hr = IMemAllocator_Commit(pAlloc); if (pAlloc) IMemAllocator_Release(pAlloc); TRACE("Committing allocator: %x\n", hr); } thread = CreateThread(NULL, 0, ReadThread, capBox, 0, NULL); if (thread) { capBox->thread = thread; SetThreadPriority(thread, THREAD_PRIORITY_LOWEST); LeaveCriticalSection(&capBox->CritSect); return S_OK; } ERR("Creating thread failed.. %u\n", GetLastError()); LeaveCriticalSection(&capBox->CritSect); return E_FAIL; } ResumeThread(capBox->thread); *state = State_Running; LeaveCriticalSection(&capBox->CritSect); return S_OK; }
static HRESULT WINAPI QTInPin_ReceiveConnection(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt) { HRESULT hr = S_OK; ALLOCATOR_PROPERTIES props; QTInPin *This = impl_from_IPin(iface); TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt); EnterCriticalSection(This->pin.pCritSec); This->pReader = NULL; if (This->pin.pConnectedTo) hr = VFW_E_ALREADY_CONNECTED; else if (IPin_QueryAccept(iface, pmt) != S_OK) hr = VFW_E_TYPE_NOT_ACCEPTED; else { PIN_DIRECTION pindirReceive; IPin_QueryDirection(pReceivePin, &pindirReceive); if (pindirReceive != PINDIR_OUTPUT) hr = VFW_E_INVALID_DIRECTION; } if (FAILED(hr)) { LeaveCriticalSection(This->pin.pCritSec); return hr; } hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader); if (FAILED(hr)) { LeaveCriticalSection(This->pin.pCritSec); TRACE("Input source is not an AsyncReader\n"); return hr; } LeaveCriticalSection(This->pin.pCritSec); EnterCriticalSection(&impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->filter.csFilter); hr = QT_Process_Movie(impl_from_IBaseFilter(This->pin.pinInfo.pFilter)); if (FAILED(hr)) { LeaveCriticalSection(&impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->filter.csFilter); TRACE("Unable to process movie\n"); return hr; } This->pAlloc = NULL; props.cBuffers = 8; props.cbAlign = 1; props.cbBuffer = impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->outputSize + props.cbAlign; props.cbPrefix = 0; hr = IAsyncReader_RequestAllocator(This->pReader, NULL, &props, &This->pAlloc); if (SUCCEEDED(hr)) { CopyMediaType(&This->pin.mtCurrent, pmt); This->pin.pConnectedTo = pReceivePin; IPin_AddRef(pReceivePin); hr = IMemAllocator_Commit(This->pAlloc); } else { QT_RemoveOutputPins(impl_from_IBaseFilter(This->pin.pinInfo.pFilter)); if (This->pReader) IAsyncReader_Release(This->pReader); This->pReader = NULL; if (This->pAlloc) IMemAllocator_Release(This->pAlloc); This->pAlloc = NULL; } TRACE("Size: %i\n", props.cbBuffer); LeaveCriticalSection(&impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->filter.csFilter); return hr; }