static void rungraph(void) { HRESULT hr; IMediaControl* pmc; IMediaEvent* pme; HANDLE hEvent; hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaControl, (LPVOID*)&pmc); ok(hr==S_OK, "Cannot get IMediaControl interface returned: %lx\n", hr); hr = IMediaControl_Run(pmc); ok(hr==S_FALSE, "Cannot run the graph returned: %lx\n", hr); hr = IGraphBuilder_QueryInterface(pgraph, &IID_IMediaEvent, (LPVOID*)&pme); ok(hr==S_OK, "Cannot get IMediaEvent interface returned: %lx\n", hr); hr = IMediaEvent_GetEventHandle(pme, (OAEVENT*)&hEvent); ok(hr==S_OK, "Cannot get event handle returned: %lx\n", hr); /* WaitForSingleObject(hEvent, INFINITE); */ Sleep(20000); hr = IMediaControl_Release(pme); ok(hr==2, "Releasing mediaevent returned: %lx\n", hr); hr = IMediaControl_Stop(pmc); ok(hr==S_OK, "Cannot stop the graph returned: %lx\n", hr); hr = IMediaControl_Release(pmc); ok(hr==1, "Releasing mediacontrol returned: %lx\n", hr); }
static ULONG WINAPI IAMMultiMediaStreamImpl_Release(IAMMultiMediaStream* iface) { IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface); ULONG ref = InterlockedDecrement(&This->ref); ULONG i; TRACE("(%p/%p)\n", iface, This); if (!ref) { for(i = 0; i < This->nbStreams; i++) IMediaStream_Release(This->pStreams[i]); if (This->ipin) IPin_Release(This->ipin); if (This->media_stream_filter) IBaseFilter_Release(This->media_stream_filter); if (This->media_seeking) IMediaSeeking_Release(This->media_seeking); if (This->media_control) IMediaControl_Release(This->media_control); if (This->pFilterGraph) IGraphBuilder_Release(This->pFilterGraph); HeapFree(GetProcessHeap(), 0, This); } return ref; }
/*************************************************************************** * MCIQTZ_mciClose [internal] */ static DWORD MCIQTZ_mciClose(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms) { WINE_MCIQTZ* wma; TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpParms); wma = MCIQTZ_mciGetOpenDev(wDevID); if (!wma) return MCIERR_INVALID_DEVICE_ID; MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL); if (wma->opened) { IVideoWindow_Release(wma->vidwin); IBasicVideo_Release(wma->vidbasic); IMediaSeeking_Release(wma->seek); IMediaEvent_Release(wma->mevent); IGraphBuilder_Release(wma->pgraph); IMediaControl_Release(wma->pmctrl); if (wma->uninit) CoUninitialize(); wma->opened = FALSE; } return 0; }
/*** IAMMultiMediaStream methods ***/ static HRESULT WINAPI IAMMultiMediaStreamImpl_Initialize(IAMMultiMediaStream* iface, STREAM_TYPE StreamType, DWORD dwFlags, IGraphBuilder* pFilterGraph) { IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface); HRESULT hr = S_OK; const WCHAR filternameW[] = {'M','e','d','i','a','S','t','r','e','a','m','F','i','l','t','e','r',0}; TRACE("(%p/%p)->(%x,%x,%p)\n", This, iface, (DWORD)StreamType, dwFlags, pFilterGraph); if (pFilterGraph) { This->pFilterGraph = pFilterGraph; IGraphBuilder_AddRef(This->pFilterGraph); } else { hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&This->pFilterGraph); } if (SUCCEEDED(hr)) { This->StreamType = StreamType; hr = IGraphBuilder_QueryInterface(This->pFilterGraph, &IID_IMediaSeeking, (void**)&This->media_seeking); if (SUCCEEDED(hr)) IGraphBuilder_QueryInterface(This->pFilterGraph, &IID_IMediaControl, (void**)&This->media_control); if (SUCCEEDED(hr)) hr = CoCreateInstance(&CLSID_MediaStreamFilter, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&This->media_stream_filter); if (SUCCEEDED(hr)) IGraphBuilder_AddFilter(This->pFilterGraph, This->media_stream_filter, filternameW); if (SUCCEEDED(hr)) { IMediaEventEx* media_event = NULL; hr = IGraphBuilder_QueryInterface(This->pFilterGraph, &IID_IMediaEventEx, (void**)&media_event); if (SUCCEEDED(hr)) hr = IMediaEventEx_GetEventHandle(media_event, &This->event); if (SUCCEEDED(hr)) hr = IMediaEventEx_SetNotifyFlags(media_event, AM_MEDIAEVENT_NONOTIFY); if (media_event) IMediaEventEx_Release(media_event); } } if (FAILED(hr)) { if (This->media_stream_filter) IBaseFilter_Release(This->media_stream_filter); This->media_stream_filter = NULL; if (This->media_seeking) IMediaSeeking_Release(This->media_seeking); This->media_seeking = NULL; if (This->media_control) IMediaControl_Release(This->media_control); This->media_control = NULL; if (This->pFilterGraph) IGraphBuilder_Release(This->pFilterGraph); This->pFilterGraph = NULL; } return hr; }
static int dshow_read_close(AVFormatContext *s) { struct dshow_ctx *ctx = s->priv_data; AVPacketList *pktl; if (ctx->control) { IMediaControl_Stop(ctx->control); IMediaControl_Release(ctx->control); } if (ctx->media_event) IMediaEvent_Release(ctx->media_event); if (ctx->graph) { IEnumFilters *fenum; int r; r = IGraphBuilder_EnumFilters(ctx->graph, &fenum); if (r == S_OK) { IBaseFilter *f; IEnumFilters_Reset(fenum); while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK) { if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK) IEnumFilters_Reset(fenum); /* When a filter is removed, * the list must be reset. */ IBaseFilter_Release(f); } IEnumFilters_Release(fenum); } IGraphBuilder_Release(ctx->graph); } if (ctx->capture_pin[VideoDevice]) libAVPin_Release(ctx->capture_pin[VideoDevice]); if (ctx->capture_pin[AudioDevice]) libAVPin_Release(ctx->capture_pin[AudioDevice]); if (ctx->capture_filter[VideoDevice]) libAVFilter_Release(ctx->capture_filter[VideoDevice]); if (ctx->capture_filter[AudioDevice]) libAVFilter_Release(ctx->capture_filter[AudioDevice]); if (ctx->device_pin[VideoDevice]) IPin_Release(ctx->device_pin[VideoDevice]); if (ctx->device_pin[AudioDevice]) IPin_Release(ctx->device_pin[AudioDevice]); if (ctx->device_filter[VideoDevice]) IBaseFilter_Release(ctx->device_filter[VideoDevice]); if (ctx->device_filter[AudioDevice]) IBaseFilter_Release(ctx->device_filter[AudioDevice]); if (ctx->device_name[0]) av_freep(&ctx->device_name[0]); if (ctx->device_name[1]) av_freep(&ctx->device_name[1]); if(ctx->mutex) CloseHandle(ctx->mutex); if(ctx->event[0]) CloseHandle(ctx->event[0]); if(ctx->event[1]) CloseHandle(ctx->event[1]); pktl = ctx->pktl; while (pktl) { AVPacketList *next = pktl->next; av_packet_unref(&pktl->pkt); av_free(pktl); pktl = next; } CoUninitialize(); return 0; }
/*************************************************************************** * MCIQTZ_mciOpen [internal] */ static DWORD MCIQTZ_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_DGV_OPEN_PARMSW lpOpenParms) { WINE_MCIQTZ* wma; HRESULT hr; DWORD style = 0; RECT rc = { 0, 0, 0, 0 }; TRACE("(%04x, %08X, %p)\n", wDevID, dwFlags, lpOpenParms); if (!lpOpenParms) return MCIERR_NULL_PARAMETER_BLOCK; wma = MCIQTZ_mciGetOpenDev(wDevID); if (!wma) return MCIERR_INVALID_DEVICE_ID; MCIQTZ_mciStop(wDevID, MCI_WAIT, NULL); hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); wma->uninit = SUCCEEDED(hr); hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (LPVOID*)&wma->pgraph); if (FAILED(hr)) { TRACE("Cannot create filtergraph (hr = %x)\n", hr); goto err; } hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaControl, (LPVOID*)&wma->pmctrl); if (FAILED(hr)) { TRACE("Cannot get IMediaControl interface (hr = %x)\n", hr); goto err; } hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaSeeking, (void**)&wma->seek); if (FAILED(hr)) { TRACE("Cannot get IMediaSeeking interface (hr = %x)\n", hr); goto err; } hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IMediaEvent, (void**)&wma->mevent); if (FAILED(hr)) { TRACE("Cannot get IMediaEvent interface (hr = %x)\n", hr); goto err; } hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IVideoWindow, (void**)&wma->vidwin); if (FAILED(hr)) { TRACE("Cannot get IVideoWindow interface (hr = %x)\n", hr); goto err; } hr = IGraphBuilder_QueryInterface(wma->pgraph, &IID_IBasicVideo, (void**)&wma->vidbasic); if (FAILED(hr)) { TRACE("Cannot get IBasicVideo interface (hr = %x)\n", hr); goto err; } if (!(dwFlags & MCI_OPEN_ELEMENT) || (dwFlags & MCI_OPEN_ELEMENT_ID)) { TRACE("Wrong dwFlags %x\n", dwFlags); goto err; } if (!lpOpenParms->lpstrElementName || !lpOpenParms->lpstrElementName[0]) { TRACE("Invalid filename specified\n"); goto err; } TRACE("Open file %s\n", debugstr_w(lpOpenParms->lpstrElementName)); hr = IGraphBuilder_RenderFile(wma->pgraph, lpOpenParms->lpstrElementName, NULL); if (FAILED(hr)) { TRACE("Cannot render file (hr = %x)\n", hr); goto err; } IVideoWindow_put_AutoShow(wma->vidwin, OAFALSE); IVideoWindow_put_Visible(wma->vidwin, OAFALSE); if (dwFlags & MCI_DGV_OPEN_WS) style = lpOpenParms->dwStyle; if (dwFlags & MCI_DGV_OPEN_PARENT) { IVideoWindow_put_MessageDrain(wma->vidwin, (OAHWND)lpOpenParms->hWndParent); IVideoWindow_put_WindowState(wma->vidwin, SW_HIDE); IVideoWindow_put_WindowStyle(wma->vidwin, style|WS_CHILD); IVideoWindow_put_Owner(wma->vidwin, (OAHWND)lpOpenParms->hWndParent); GetClientRect(lpOpenParms->hWndParent, &rc); IVideoWindow_SetWindowPosition(wma->vidwin, rc.left, rc.top, rc.right - rc.top, rc.bottom - rc.top); wma->parent = (HWND)lpOpenParms->hWndParent; } else if (style) IVideoWindow_put_WindowStyle(wma->vidwin, style); IBasicVideo_GetVideoSize(wma->vidbasic, &rc.right, &rc.bottom); wma->opened = TRUE; if (dwFlags & MCI_NOTIFY) mciDriverNotify(HWND_32(LOWORD(lpOpenParms->dwCallback)), wDevID, MCI_NOTIFY_SUCCESSFUL); return 0; err: if (wma->vidbasic) IBasicVideo_Release(wma->vidbasic); wma->vidbasic = NULL; if (wma->seek) IMediaSeeking_Release(wma->seek); wma->seek = NULL; if (wma->vidwin) IVideoWindow_Release(wma->vidwin); wma->vidwin = NULL; if (wma->pgraph) IGraphBuilder_Release(wma->pgraph); wma->pgraph = NULL; if (wma->mevent) IMediaEvent_Release(wma->mevent); wma->mevent = NULL; if (wma->pmctrl) IMediaControl_Release(wma->pmctrl); wma->pmctrl = NULL; if (wma->uninit) CoUninitialize(); wma->uninit = 0; return MCIERR_INTERNAL; }