[PATCH 4/5] quartz/parser: Share source pin and filter reference counts.

Zebediah Figura z.figura12 at gmail.com
Sun Jun 16 19:35:02 CDT 2019


Uniquely, native quartz doesn't do this. But it doesn't make much sense to
follow native quartz in this case, and it leads to simpler code on our part.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/quartz/parser.c | 49 +++++++++++++++++---------------------------
 1 file changed, 19 insertions(+), 30 deletions(-)

diff --git a/dlls/quartz/parser.c b/dlls/quartz/parser.c
index 7e705ccb7f5..5743a53fd2e 100644
--- a/dlls/quartz/parser.c
+++ b/dlls/quartz/parser.c
@@ -383,26 +383,27 @@ HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PR
     return hr;
 }
 
-static HRESULT WINAPI break_connection(IPin *iface)
+static void free_source_pin(IPin *iface)
 {
     Parser_OutputPin *pin = unsafe_impl_Parser_OutputPin_from_IPin(iface);
-    HRESULT hr;
 
-    if (!pin->pin.pin.pConnectedTo || !pin->pin.pMemInputPin)
-        hr = VFW_E_NOT_CONNECTED;
-    else
+    if (pin->pin.pin.pConnectedTo)
     {
-        hr = IPin_Disconnect(pin->pin.pin.pConnectedTo);
+        IPin_Disconnect(pin->pin.pin.pConnectedTo);
         IPin_Disconnect(iface);
     }
 
-    return hr;
+    FreeMediaType(pin->pmt);
+    CoTaskMemFree(pin->pmt);
+    FreeMediaType(&pin->pin.pin.mtCurrent);
+    if (pin->pin.pAllocator)
+        IMemAllocator_Release(pin->pin.pAllocator);
+    CoTaskMemFree(pin);
 }
 
 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
 {
     /* NOTE: should be in critical section when calling this function */
-    HRESULT hr;
     ULONG i;
     IPin ** ppOldPins = This->ppPins;
 
@@ -413,11 +414,7 @@ static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
     memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
 
     for (i = 0; i < This->cStreams; i++)
-    {
-        hr = break_connection(ppOldPins[i + 1]);
-        TRACE("Disconnect: %08x\n", hr);
-        IPin_Release(ppOldPins[i + 1]);
-    }
+        free_source_pin(ppOldPins[i + 1]);
 
     BaseFilterImpl_IncrementPinVersion(&This->filter);
     This->cStreams = 0;
@@ -567,24 +564,16 @@ static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid,
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
+static ULONG WINAPI Parser_OutputPin_AddRef(IPin *iface)
 {
-    Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
-    ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
-    
-    TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
+    Parser_OutputPin *pin = unsafe_impl_Parser_OutputPin_from_IPin(iface);
+    return IBaseFilter_AddRef(pin->pin.pin.pinInfo.pFilter);
+}
 
-    if (!refCount)
-    {
-        FreeMediaType(This->pmt);
-        CoTaskMemFree(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 Parser_OutputPin_Release(IPin * iface)
+{
+    Parser_OutputPin *pin = unsafe_impl_Parser_OutputPin_from_IPin(iface);
+    return IBaseFilter_Release(pin->pin.pin.pinInfo.pFilter);
 }
 
 static HRESULT WINAPI Parser_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
@@ -612,7 +601,7 @@ static HRESULT WINAPI Parser_OutputPin_CheckMediaType(BasePin *pin, const AM_MED
 static const IPinVtbl Parser_OutputPin_Vtbl = 
 {
     Parser_OutputPin_QueryInterface,
-    BasePinImpl_AddRef,
+    Parser_OutputPin_AddRef,
     Parser_OutputPin_Release,
     Parser_OutputPin_Connect,
     BaseOutputPinImpl_ReceiveConnection,
-- 
2.21.0




More information about the wine-devel mailing list