Commit e41b3529 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

quartz/filtergraph: Clean up CheckCircularConnection().

Use clearer variable names, and simplify the error handling. Signed-off-by: 's avatarZebediah Figura <zfigura@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent ae9d64ed
...@@ -771,65 +771,66 @@ static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface, ...@@ -771,65 +771,66 @@ static HRESULT WINAPI FilterGraph2_FindFilterByName(IFilterGraph2 *iface,
return VFW_E_NOT_FOUND; return VFW_E_NOT_FOUND;
} }
/* Don't allow a circular connection to form, return VFW_E_CIRCULAR_GRAPH if this would be the case. static HRESULT check_cyclic_connection(IPin *source, IPin *sink)
* 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)
{ {
IPin *upstream_source, *upstream_sink;
PIN_INFO source_info, sink_info;
IEnumPins *enumpins;
HRESULT hr; HRESULT hr;
PIN_INFO info_out, info_in;
hr = IPin_QueryPinInfo(out, &info_out); hr = IPin_QueryPinInfo(sink, &sink_info);
if (FAILED(hr)) if (FAILED(hr))
{
ERR("Failed to query pin, hr %#x.\n", hr);
return hr; return hr;
}
IBaseFilter_Release(sink_info.pFilter);
hr = IPin_QueryPinInfo(in, &info_in); hr = IPin_QueryPinInfo(source, &source_info);
if (SUCCEEDED(hr))
IBaseFilter_Release(info_in.pFilter);
if (FAILED(hr)) if (FAILED(hr))
goto out; {
ERR("Failed to query pin, hr %#x.\n", hr);
return hr;
}
if (info_out.pFilter == info_in.pFilter) if (sink_info.pFilter == source_info.pFilter)
hr = VFW_E_CIRCULAR_GRAPH;
else
{ {
IEnumPins *enumpins; WARN("Cyclic connection detected; returning VFW_E_CIRCULAR_GRAPH.\n");
IPin *test; IBaseFilter_Release(source_info.pFilter);
return VFW_E_CIRCULAR_GRAPH;
}
hr = IBaseFilter_EnumPins(info_out.pFilter, &enumpins); hr = IBaseFilter_EnumPins(source_info.pFilter, &enumpins);
if (FAILED(hr)) if (FAILED(hr))
goto out; {
ERR("Failed to enumerate pins, hr %#x.\n", hr);
IBaseFilter_Release(source_info.pFilter);
return hr;
}
IEnumPins_Reset(enumpins); while ((hr = IEnumPins_Next(enumpins, 1, &upstream_sink, NULL)) == S_OK)
while ((hr = IEnumPins_Next(enumpins, 1, &test, NULL)) == S_OK)
{ {
PIN_DIRECTION dir = PINDIR_OUTPUT; PIN_DIRECTION dir = PINDIR_OUTPUT;
IPin_QueryDirection(test, &dir);
if (dir == PINDIR_INPUT) IPin_QueryDirection(upstream_sink, &dir);
{ if (dir == PINDIR_INPUT && IPin_ConnectedTo(upstream_sink, &upstream_source) == S_OK)
IPin *victim = NULL;
IPin_ConnectedTo(test, &victim);
if (victim)
{ {
hr = CheckCircularConnection(This, victim, in); hr = check_cyclic_connection(upstream_source, sink);
IPin_Release(victim); IPin_Release(upstream_source);
if (FAILED(hr)) if (FAILED(hr))
{ {
IPin_Release(test); IPin_Release(upstream_sink);
break; IEnumPins_Release(enumpins);
} IBaseFilter_Release(source_info.pFilter);
return hr;
} }
} }
IPin_Release(test); IPin_Release(upstream_sink);
} }
IEnumPins_Release(enumpins); IEnumPins_Release(enumpins);
}
out: IBaseFilter_Release(source_info.pFilter);
IBaseFilter_Release(info_out.pFilter); return S_OK;
if (FAILED(hr))
ERR("Checking filtergraph returned %08x, something's not right!\n", hr);
return hr;
} }
static struct filter *find_sorted_filter(struct filter_graph *graph, IBaseFilter *iface) 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 ...@@ -855,7 +856,7 @@ static void sort_filter_recurse(struct filter_graph *graph, struct filter *filte
TRACE("Sorting filter %p.\n", filter->filter); 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); assert(!filter->sorting);
filter->sorting = TRUE; filter->sorting = TRUE;
...@@ -935,13 +936,13 @@ static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppi ...@@ -935,13 +936,13 @@ static HRESULT WINAPI FilterGraph2_ConnectDirect(IFilterGraph2 *iface, IPin *ppi
{ {
if (dir == PINDIR_INPUT) if (dir == PINDIR_INPUT)
{ {
hr = CheckCircularConnection(This, ppinOut, ppinIn); hr = check_cyclic_connection(ppinOut, ppinIn);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = IPin_Connect(ppinOut, ppinIn, pmt); hr = IPin_Connect(ppinOut, ppinIn, pmt);
} }
else else
{ {
hr = CheckCircularConnection(This, ppinIn, ppinOut); hr = check_cyclic_connection(ppinIn, ppinOut);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = IPin_Connect(ppinIn, ppinOut, pmt); hr = IPin_Connect(ppinIn, ppinOut, pmt);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment