Zebediah Figura : quartz/filtergraph: Clean up CheckCircularConnection().

Alexandre Julliard julliard at winehq.org
Thu Feb 3 16:06:56 CST 2022


Module: wine
Branch: master
Commit: e41b3529e394d53ffac0e8ac1e88749d8d942329
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e41b3529e394d53ffac0e8ac1e88749d8d942329

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Wed Feb  2 22:58:09 2022 -0600

quartz/filtergraph: Clean up CheckCircularConnection().

Use clearer variable names, and simplify the error handling.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/quartz/filtergraph.c | 91 ++++++++++++++++++++++++-----------------------
 1 file changed, 46 insertions(+), 45 deletions(-)

diff --git a/dlls/quartz/filtergraph.c b/dlls/quartz/filtergraph.c
index 74f1adcb665..0dccf2b7fb4 100644
--- a/dlls/quartz/filtergraph.c
+++ b/dlls/quartz/filtergraph.c
@@ -771,65 +771,66 @@ static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
     return VFW_E_NOT_FOUND;
 }
 
-/* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case.
- * A circular connection will be formed if from the filter of the output pin, the input pin can be reached
- */
-static HRESULT CheckCircularConnection(struct filter_graph *This, IPin *out, IPin *in)
+static HRESULT check_cyclic_connection(IPin *source, IPin *sink)
 {
+    IPin *upstream_source, *upstream_sink;
+    PIN_INFO source_info, sink_info;
+    IEnumPins *enumpins;
     HRESULT hr;
-    PIN_INFO info_out, info_in;
 
-    hr = IPin_QueryPinInfo(out, &info_out);
+    hr = IPin_QueryPinInfo(sink, &sink_info);
     if (FAILED(hr))
+    {
+        ERR("Failed to query pin, hr %#x.\n", hr);
         return hr;
+    }
+    IBaseFilter_Release(sink_info.pFilter);
 
-    hr = IPin_QueryPinInfo(in, &info_in);
-    if (SUCCEEDED(hr))
-        IBaseFilter_Release(info_in.pFilter);
+    hr = IPin_QueryPinInfo(source, &source_info);
     if (FAILED(hr))
-        goto out;
+    {
+        ERR("Failed to query pin, hr %#x.\n", hr);
+        return hr;
+    }
 
-    if (info_out.pFilter == info_in.pFilter)
-        hr = VFW_E_CIRCULAR_GRAPH;
-    else
+    if (sink_info.pFilter == source_info.pFilter)
     {
-        IEnumPins *enumpins;
-        IPin *test;
+        WARN("Cyclic connection detected; returning VFW_E_CIRCULAR_GRAPH.\n");
+        IBaseFilter_Release(source_info.pFilter);
+        return VFW_E_CIRCULAR_GRAPH;
+    }
 
-        hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins);
-        if (FAILED(hr))
-            goto out;
+    hr = IBaseFilter_EnumPins(source_info.pFilter, &enumpins);
+    if (FAILED(hr))
+    {
+        ERR("Failed to enumerate pins, hr %#x.\n", hr);
+        IBaseFilter_Release(source_info.pFilter);
+        return hr;
+    }
+
+    while ((hr = IEnumPins_Next(enumpins, 1, &upstream_sink, NULL)) == S_OK)
+    {
+        PIN_DIRECTION dir = PINDIR_OUTPUT;
 
-        IEnumPins_Reset(enumpins);
-        while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
+        IPin_QueryDirection(upstream_sink, &dir);
+        if (dir == PINDIR_INPUT && IPin_ConnectedTo(upstream_sink, &upstream_source) == S_OK)
         {
-            PIN_DIRECTION dir = PINDIR_OUTPUT;
-            IPin_QueryDirection(test, &dir);
-            if (dir == PINDIR_INPUT)
+            hr = check_cyclic_connection(upstream_source, sink);
+            IPin_Release(upstream_source);
+            if (FAILED(hr))
             {
-                IPin *victim = NULL;
-                IPin_ConnectedTo(test, &victim);
-                if (victim)
-                {
-                    hr = CheckCircularConnection(This, victim, in);
-                    IPin_Release(victim);
-                    if (FAILED(hr))
-                    {
-                        IPin_Release(test);
-                        break;
-                    }
-                }
+                IPin_Release(upstream_sink);
+                IEnumPins_Release(enumpins);
+                IBaseFilter_Release(source_info.pFilter);
+                return hr;
             }
-            IPin_Release(test);
         }
-        IEnumPins_Release(enumpins);
+        IPin_Release(upstream_sink);
     }
+    IEnumPins_Release(enumpins);
 
-out:
-    IBaseFilter_Release(info_out.pFilter);
-    if (FAILED(hr))
-        ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
-    return hr;
+    IBaseFilter_Release(source_info.pFilter);
+    return S_OK;
 }
 
 static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface)
@@ -855,7 +856,7 @@ static void sort_filter_recurse(struct filter_graph *graph, struct filter *filte
 
     TRACE("Sorting filter %p.\n", filter->filter);
 
-    /* Cyclic connections should be caught by CheckCircularConnection(). */
+    /* Cyclic connections should be caught by check_cyclic_connection(). */
     assert(!filter->sorting);
 
     filter->sorting = TRUE;
@@ -935,13 +936,13 @@ static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppi
     {
         if (dir == PINDIR_INPUT)
         {
-            hr = CheckCircularConnection(This, ppinOut, ppinIn);
+            hr = check_cyclic_connection(ppinOut, ppinIn);
             if (SUCCEEDED(hr))
                 hr = IPin_Connect(ppinOut, ppinIn, pmt);
         }
         else
         {
-            hr = CheckCircularConnection(This, ppinIn, ppinOut);
+            hr = check_cyclic_connection(ppinIn, ppinOut);
             if (SUCCEEDED(hr))
                 hr = IPin_Connect(ppinIn, ppinOut, pmt);
         }




More information about the wine-cvs mailing list