[QUARTZ] Fixes for filtergraph and transform filter

Christian Costa titan.costa at wanadoo.fr
Sun Aug 21 10:36:01 CDT 2005


Hi,

Changelog:
Properly allocate/release memory when adding filters to the filtergraph.
When connecting pin, discard filter which is the same as the upstream one.
Remove wrong extra IBaseFilter_Release.
Improve traces by showing filters owing pins we want to connect or render.
Properly initialize output pin of transform filter.

Christian Costa   titan.costa at wanadoo.fr

-------------- next part --------------
Index: dlls/quartz/filtergraph.c
===================================================================
RCS file: /home/wine/wine/dlls/quartz/filtergraph.c,v
retrieving revision 1.33
diff -u -r1.33 filtergraph.c
--- dlls/quartz/filtergraph.c	17 Aug 2005 09:52:15 -0000	1.33
+++ dlls/quartz/filtergraph.c	21 Aug 2005 14:13:19 -0000
@@ -352,13 +352,16 @@
 
     if (This->nFilters + 1 > This->filterCapacity)
     {
-        int newCapacity = 2*This->filterCapacity;
+        int newCapacity = This->filterCapacity ? 2 * This->filterCapacity : 1;
         IBaseFilter ** ppNewFilters = CoTaskMemAlloc(newCapacity * sizeof(IBaseFilter*));
         LPWSTR * pNewNames = CoTaskMemAlloc(newCapacity * sizeof(LPWSTR));
         memcpy(ppNewFilters, This->ppFiltersInGraph, This->nFilters * sizeof(IBaseFilter*));
         memcpy(pNewNames, This->pFilterNames, This->nFilters * sizeof(LPWSTR));
-        CoTaskMemFree(This->ppFiltersInGraph);
-        CoTaskMemFree(This->pFilterNames);
+        if (!This->filterCapacity)
+        {
+            CoTaskMemFree(This->ppFiltersInGraph);
+            CoTaskMemFree(This->pFilterNames);
+        }
         This->ppFiltersInGraph = ppNewFilters;
         This->pFilterNames = pNewNames;
         This->filterCapacity = newCapacity;
@@ -461,6 +464,25 @@
 
     /* FIXME: check pins are in graph */
 
+    if (TRACE_ON(quartz))
+    {
+        PIN_INFO PinInfo;
+
+        hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
+        if (FAILED(hr))
+            return hr;
+
+        TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
+        IBaseFilter_Release(PinInfo.pFilter);
+
+        hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
+        if (FAILED(hr))
+            return hr;
+
+        TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
+        IBaseFilter_Release(PinInfo.pFilter);
+    }
+
     hr = IPin_QueryDirection(ppinIn, &dir);
     if (SUCCEEDED(hr))
     {
@@ -623,9 +645,28 @@
     ULONG nb;
     IMoniker* pMoniker;
     ULONG pin;
+    PIN_INFO PinInfo;
+    CLSID FilterCLSID;
 
     TRACE("(%p/%p)->(%p, %p)\n", This, iface, ppinOut, ppinIn);
 
+    if (TRACE_ON(quartz))
+    {
+	hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
+        if (FAILED(hr))
+            return hr;
+
+        TRACE("Filter owning first pin => %p\n", PinInfo.pFilter);
+        IBaseFilter_Release(PinInfo.pFilter);
+
+        hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
+        if (FAILED(hr))
+            return hr;
+
+        TRACE("Filter owning second pin => %p\n", PinInfo.pFilter);
+        IBaseFilter_Release(PinInfo.pFilter);
+    }
+
     /* Try direct connection first */
     hr = IPin_Connect(ppinOut, ppinIn, NULL);
     if (SUCCEEDED(hr)) {
@@ -633,6 +674,16 @@
     }
     TRACE("Direct connection failed, trying to insert other filters\n");
 
+    hr = IPin_QueryPinInfo(ppinIn, &PinInfo);
+    if (FAILED(hr))
+       return hr;
+
+    hr = IBaseFilter_GetClassID(PinInfo.pFilter, &FilterCLSID);
+    if (FAILED(hr))
+       return hr;
+
+    IBaseFilter_Release(PinInfo.pFilter);
+
     /* Find the appropriate transform filter than can transform the minor media type of output pin of the upstream 
      * filter to the minor mediatype of input pin of the renderer */
     hr = IPin_EnumMediaTypes(ppinOut, &penummt);
@@ -674,14 +725,19 @@
         hr = GetFilterInfo(pMoniker, &clsid, &var);
         IMoniker_Release(pMoniker);
         if (FAILED(hr)) {
-           ERR("Unable to retrieve filter info (%lx)\n", hr);
-           goto error;
+            ERR("Unable to retrieve filter info (%lx)\n", hr);
+            goto error;
+        }
+
+        if (IsEqualGUID(&clsid, &FilterCLSID)) {
+            /* Skip filter (same as the one the output pin belongs to) */
+            goto error;
         }
 
         hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&pfilter);
         if (FAILED(hr)) {
-           ERR("Unable to create filter (%lx), trying next one\n", hr);
-           goto error;
+            ERR("Unable to create filter (%lx), trying next one\n", hr);
+            goto error;
         }
 
         hr = IGraphBuilder_AddFilter(iface, pfilter, NULL);
@@ -767,6 +823,18 @@
 
     TRACE("(%p/%p)->(%p)\n", This, iface, ppinOut);
 
+    if (TRACE_ON(quartz))
+    {
+        PIN_INFO PinInfo;
+
+        hr = IPin_QueryPinInfo(ppinOut, &PinInfo);
+        if (FAILED(hr))
+            return hr;
+
+        TRACE("Filter owning pin => %p\n", PinInfo.pFilter);
+        IBaseFilter_Release(PinInfo.pFilter);
+    }
+
     hr = IPin_EnumMediaTypes(ppinOut, &penummt);
     if (FAILED(hr)) {
         ERR("EnumMediaTypes (%lx)\n", hr);
@@ -819,7 +887,6 @@
             hr = IGraphBuilder_AddFilter(iface, pfilter, NULL);
             if (FAILED(hr)) {
                 ERR("Unable to add filter (%lx)\n", hr);
-                IBaseFilter_Release(pfilter);
                 pfilter = NULL;
                 goto error;
             }
@@ -1295,7 +1362,7 @@
         }
         if (source == TRUE)
         {
-            TRACE("Found a source filter\n");
+            TRACE("Found a source filter %p\n", pfilter);
             IEnumPins_Reset(pEnum);
             while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
             {
@@ -1364,7 +1431,7 @@
     *pfs = This->state;
 
     LeaveCriticalSection(&This->cs);
-    
+
     return S_OK;
 }
 
Index: dlls/quartz/transform.c
===================================================================
RCS file: /home/wine/wine/dlls/quartz/transform.c,v
retrieving revision 1.6
diff -u -r1.6 transform.c
--- dlls/quartz/transform.c	20 Jun 2005 18:39:40 -0000	1.6
+++ dlls/quartz/transform.c	21 Aug 2005 14:13:21 -0000
@@ -201,7 +201,7 @@
     piOutput.pFilter = (IBaseFilter *)pTransformFilter;
     lstrcpynW(piOutput.achName, wcsOutputPinName, sizeof(piOutput.achName) / sizeof(piOutput.achName[0]));
 
-    hr = TransformFilter_InputPin_Construct(&piInput, TransformFilter_Sample, (LPVOID)pTransformFilter, TransformFilter_Input_QueryAccept, &pTransformFilter->csFilter, &pTransformFilter->ppPins[0]);
+    hr = TransformFilter_InputPin_Construct(&piInput, TransformFilter_Sample, pTransformFilter, TransformFilter_Input_QueryAccept, &pTransformFilter->csFilter, &pTransformFilter->ppPins[0]);
 
     if (SUCCEEDED(hr))
     {
@@ -211,7 +211,7 @@
         props.cbBuffer = 0; /* Will be updated at connection time */
         props.cBuffers = 2;
 
-        hr = TransformFilter_OutputPin_Construct(&piOutput, &props, NULL, TransformFilter_Output_QueryAccept, &pTransformFilter->csFilter, &pTransformFilter->ppPins[1]);
+        hr = TransformFilter_OutputPin_Construct(&piOutput, &props, pTransformFilter, TransformFilter_Output_QueryAccept, &pTransformFilter->csFilter, &pTransformFilter->ppPins[1]);
 
 	if (FAILED(hr))
 	    ERR("Cannot create output pin (%lx)\n", hr);


More information about the wine-patches mailing list