Commit 228b8b98 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

quartz: Simplify FilterGraph2_AddFilter().

parent 7daf0304
......@@ -184,7 +184,9 @@ typedef struct _IFilterGraphImpl {
LONG ref;
IUnknown *punkFilterMapper2;
struct list filters;
LONG nameIndex;
unsigned int name_index;
IReferenceClock *refClock;
IBaseFilter *refClockProvider;
EventsQueue evqueue;
......@@ -554,74 +556,68 @@ static IBaseFilter *find_filter_by_name(IFilterGraphImpl *graph, const WCHAR *na
}
/*** IFilterGraph methods ***/
static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface, IBaseFilter *pFilter,
LPCWSTR pName)
static HRESULT WINAPI FilterGraph2_AddFilter(IFilterGraph2 *iface,
IBaseFilter *filter, const WCHAR *name)
{
IFilterGraphImpl *This = impl_from_IFilterGraph2(iface);
IFilterGraphImpl *graph = impl_from_IFilterGraph2(iface);
BOOL duplicate_name = FALSE;
struct filter *entry;
unsigned int i;
HRESULT hr;
int j;
WCHAR* wszFilterName = NULL;
BOOL duplicate_name = FALSE;
TRACE("(%p/%p)->(%p, %s (%p))\n", This, iface, pFilter, debugstr_w(pName), pName);
TRACE("graph %p, filter %p, name %s.\n", graph, filter, debugstr_w(name));
if (!pFilter)
if (!filter)
return E_POINTER;
wszFilterName = CoTaskMemAlloc( (pName ? lstrlenW(pName) + 6 : 5) * sizeof(WCHAR) );
if (!(entry = heap_alloc(sizeof(*entry))))
return E_OUTOFMEMORY;
if (pName && find_filter_by_name(This, pName))
if (!(entry->name = CoTaskMemAlloc((name ? wcslen(name) + 6 : 5) * sizeof(WCHAR))))
{
heap_free(entry);
return E_OUTOFMEMORY;
}
if (name && find_filter_by_name(graph, name))
duplicate_name = TRUE;
/* If no name given or name already existing, generate one */
if (!pName || duplicate_name)
if (!name || duplicate_name)
{
static const WCHAR wszFmt1[] = {'%','s',' ','%','0','4','d',0};
static const WCHAR wszFmt2[] = {'%','0','4','d',0};
for (j = 0; j < 10000 ; j++)
{
/* Create name */
if (pName)
swprintf(wszFilterName, pName ? lstrlenW(pName) + 6 : 5, wszFmt1, pName, This->nameIndex);
else
swprintf(wszFilterName, pName ? lstrlenW(pName) + 6 : 5, wszFmt2, This->nameIndex);
TRACE("Generated name %s\n", debugstr_w(wszFilterName));
for (i = 0; i < 10000 ; ++i)
{
if (name)
swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%s %04u", name, graph->name_index);
else
swprintf(entry->name, name ? wcslen(name) + 6 : 5, L"%04u", graph->name_index);
if (This->nameIndex++ == 10000)
This->nameIndex = 1;
graph->name_index = (graph->name_index + 1) % 10000;
if (!find_filter_by_name(This, wszFilterName))
if (!find_filter_by_name(graph, entry->name))
break;
}
/* Unable to find a suitable name */
if (j == 10000)
{
CoTaskMemFree(wszFilterName);
return VFW_E_DUPLICATE_NAME;
}
}
if (i == 10000)
{
CoTaskMemFree(entry->name);
heap_free(entry);
return VFW_E_DUPLICATE_NAME;
}
}
else
memcpy(wszFilterName, pName, (lstrlenW(pName) + 1) * sizeof(WCHAR));
wcscpy(entry->name, name);
hr = IBaseFilter_JoinFilterGraph(pFilter, (IFilterGraph *)&This->IFilterGraph2_iface, wszFilterName);
if (FAILED(hr))
if (FAILED(hr = IBaseFilter_JoinFilterGraph(filter,
(IFilterGraph *)&graph->IFilterGraph2_iface, entry->name)))
{
CoTaskMemFree(wszFilterName);
CoTaskMemFree(entry->name);
heap_free(entry);
return hr;
}
if (!(entry = heap_alloc(sizeof(*entry))))
{
CoTaskMemFree(wszFilterName);
return E_OUTOFMEMORY;
}
IBaseFilter_AddRef(entry->filter = pFilter);
entry->name = wszFilterName;
list_add_head(&This->filters, &entry->entry);
This->version++;
IBaseFilter_AddRef(entry->filter = filter);
list_add_head(&graph->filters, &entry->entry);
++graph->version;
return duplicate_name ? VFW_S_DUPLICATE_NAME : hr;
}
......@@ -5706,7 +5702,7 @@ static HRESULT filter_graph_common_create(IUnknown *outer, void **out, BOOL thre
fimpl->IGraphVersion_iface.lpVtbl = &IGraphVersion_VTable;
fimpl->ref = 1;
list_init(&fimpl->filters);
fimpl->nameIndex = 1;
fimpl->name_index = 1;
fimpl->refClock = NULL;
fimpl->hEventCompletion = CreateEventW(0, TRUE, FALSE, 0);
fimpl->HandleEcComplete = TRUE;
......
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