Christian Costa wrote:
Hi,
This time with more thread safety.
Looking better, but one more change needed. In addition, most of the code in filtergraph.c isn't thread safe. Thread safety is particularly important in DirectShow where threads are heavily used. Debugging random crashes is not fun.
...
/*** IMediaControl methods ***/ static HRESULT WINAPI Mediacontrol_Run(IMediaControl *iface) { ICOM_THIS_MULTI(IFilterGraphImpl, IMediaControl_vtbl, iface);
- int i;
- IBaseFilter* pfilter;
- IEnumPins* pEnum;
- HRESULT hr;
- IPin* pPin;
- LONG dummy;
- PIN_DIRECTION dir;
- TRACE("(%p/%p)->(): stub !!!\n", This, iface);
- TRACE("(%p/%p)->()\n", This, iface);
- if (This->state == State_Running)
return S_OK;
This should be inside the critical section, being careful, of course, not to return without calling LeaveCriticalSection.
EnterCriticalSection(&This->cs);
/* Explorer the graph from source filters to renderers, determine renderers number and
* run filters from renderers to source filters */
This->nRenderers = 0; ResetEvent(This->hEventCompletion);
for(i = 0; i < This->nFilters; i++)
{
BOOL source = TRUE;
pfilter = This->ppFiltersInGraph[i];
hr = IBaseFilter_EnumPins(pfilter, &pEnum);
if (hr != S_OK)
{
ERR("Enum pins failed %lx\n", hr);
continue;
}
/* Check if it is a source filter */
while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
{
IPin_QueryDirection(pPin, &dir);
if (dir == PINDIR_INPUT)
{
source = FALSE;
break;
}
}
if (source == TRUE)
{
TRACE("Found a source filter\n");
IEnumPins_Reset(pEnum);
while(IEnumPins_Next(pEnum, 1, &pPin, &dummy) == S_OK)
{
/* Explore the graph downstream from this pin */
ExploreGraph(This, pPin, 0);
}
IBaseFilter_Run(pfilter, 0);
}
IEnumPins_Release(pEnum);
}
This->state = State_Running;
LeaveCriticalSection(&This->cs);
return S_FALSE;
}
Rob
Robert Shearman wrote:
Christian Costa wrote:
Hi,
This time with more thread safety.
Looking better, but one more change needed. In addition, most of the code in filtergraph.c isn't thread safe.
I agree. I will look at this after I finish what I'm currently working on.
Thread safety is particularly important in DirectShow where threads are heavily used. Debugging random crashes is not fun.
Bye, Christian