From: Zebediah Figura Subject: [PATCH 3/5] quartz/filtergraph: Don't use QueryInternalConnections() to find output pins in FilterGraph2_Connect(). Message-Id: <1537457780-22798-3-git-send-email-z.figura12@gmail.com> Date: Thu, 20 Sep 2018 10:36:18 -0500 In-Reply-To: <1537457780-22798-1-git-send-email-z.figura12@gmail.com> References: <1537457780-22798-1-git-send-email-z.figura12@gmail.com> The tests need the following patch in order to pass. Signed-off-by: Zebediah Figura --- dlls/quartz/filtergraph.c | 102 +++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/dlls/quartz/filtergraph.c b/dlls/quartz/filtergraph.c index 1fa6476..6fe5b80 100644 --- a/dlls/quartz/filtergraph.c +++ b/dlls/quartz/filtergraph.c @@ -1070,6 +1070,55 @@ static HRESULT GetInternalConnections(IBaseFilter* pfilter, IPin* pinputpin, IPi return S_OK; } +/* Attempt to connect one of the output pins on filter to sink. Helper for + * FilterGraph2_Connect(). */ +static HRESULT connect_output_pin(IFilterGraphImpl *graph, IBaseFilter *filter, IPin *sink) +{ + IEnumPins *enumpins; + PIN_DIRECTION dir; + HRESULT hr; + WCHAR *id; + IPin *pin; + + hr = IBaseFilter_EnumPins(filter, &enumpins); + if (FAILED(hr)) + return hr; + + while (IEnumPins_Next(enumpins, 1, &pin, NULL) == S_OK) + { + IPin_QueryDirection(pin, &dir); + if (dir == PINDIR_OUTPUT) + { + hr = IPin_QueryId(pin, &id); + if (FAILED(hr)) + { + IPin_Release(pin); + IEnumPins_Release(enumpins); + return hr; + } + + if (id[0] == '~') + { + TRACE("Skipping non-rendered pin %s.\n", debugstr_w(id)); + IPin_Release(pin); + IEnumPins_Release(enumpins); + return E_FAIL; + } + + if (SUCCEEDED(IFilterGraph2_Connect(&graph->IFilterGraph2_iface, pin, sink))) + { + IPin_Release(pin); + IEnumPins_Release(enumpins); + return S_OK; + } + } + IPin_Release(pin); + } + + IEnumPins_Release(enumpins); + return VFW_E_CANNOT_CONNECT; +} + /*** IGraphBuilder methods ***/ static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IPin *ppinIn) { @@ -1081,13 +1130,11 @@ static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, IEnumPins* penumpins; IEnumMoniker* pEnumMoniker; GUID tab[2]; - ULONG nb = 0; IMoniker* pMoniker; ULONG pin; PIN_INFO PinInfo; CLSID FilterCLSID; PIN_DIRECTION dir; - unsigned int i = 0; IFilterMapper2 *pFilterMapper2 = NULL; TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn); @@ -1196,11 +1243,10 @@ static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, } hr = VFW_E_CANNOT_RENDER; - while(IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, &nb) == S_OK) + while (IEnumMoniker_Next(pEnumMoniker, 1, &pMoniker, NULL) == S_OK) { VARIANT var; GUID clsid; - IPin** ppins = NULL; IPin* ppinfilter = NULL; IBaseFilter* pfilter = NULL; IAMGraphBuilderCallback *callback = NULL; @@ -1297,52 +1343,10 @@ static HRESULT WINAPI FilterGraph2_Connect(IFilterGraph2 *iface, IPin *ppinOut, } TRACE("Successfully connected to filter, follow chain...\n"); - /* Render all output pins of the filter by calling IFilterGraph2_Connect on each of them */ - hr = GetInternalConnections(pfilter, ppinfilter, &ppins, &nb); - - if (SUCCEEDED(hr)) { - if (nb == 0) { - IPin_Disconnect(ppinfilter); - IPin_Disconnect(ppinOut); - goto error; - } - TRACE("pins to consider: %d\n", nb); - for(i = 0; i < nb; i++) - { - LPWSTR pinname = NULL; - - TRACE("Processing pin %u\n", i); - - hr = IPin_QueryId(ppins[i], &pinname); - if (SUCCEEDED(hr)) - { - if (pinname[0] == '~') - { - TRACE("Pinname=%s, skipping\n", debugstr_w(pinname)); - hr = E_FAIL; - } - else - hr = IFilterGraph2_Connect(iface, ppins[i], ppinIn); - CoTaskMemFree(pinname); - } - - if (FAILED(hr)) { - TRACE("Cannot connect pin %p (%x)\n", ppinfilter, hr); - } - IPin_Release(ppins[i]); - if (SUCCEEDED(hr)) break; - } - while (++i < nb) IPin_Release(ppins[i]); - CoTaskMemFree(ppins); + if (SUCCEEDED(hr = connect_output_pin(This, pfilter, ppinIn))) + { IPin_Release(ppinfilter); IBaseFilter_Release(pfilter); - if (FAILED(hr)) - { - IPin_Disconnect(ppinfilter); - IPin_Disconnect(ppinOut); - IFilterGraph2_RemoveFilter(iface, pfilter); - continue; - } break; } @@ -1353,8 +1357,6 @@ error: IFilterGraph2_RemoveFilter(iface, pfilter); IBaseFilter_Release(pfilter); } - while (++i < nb) IPin_Release(ppins[i]); - CoTaskMemFree(ppins); } IEnumMoniker_Release(pEnumMoniker); -- 2.7.4