[QUARTZ] Some stuff to start the graph (take 2)

Robert Shearman rob at codeweavers.com
Wed Dec 29 05:45:30 CST 2004


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



More information about the wine-devel mailing list