Hi, 

I'm currently using the DirectShow plugin to play two videos through 
DirectShow, which works fine and as intended. I require both of these videos to 
play completely in sync with one another, but as they play along they go out of 
sync. I have tried comparing the current frame of each video and if different 
seek them both to the same frame, but that, for obvious reasons, causes the 
videos to stutter.
I did a bit of research into this on the web and came across a post detailing 
several steps to synchronise two DirectShow graphs, the details are below:

    * Pick one graph as the master.
    * Make sure the master has a clock. This is normally done when going 
active, but you can force it to happen earlier by calling SetDefaultSyncSource 
on the graph.
    * Query the graphs for IMediaFilter, get the clock from the master graph 
using GetSyncSource and pass it to the other graphs using SetSyncSource.
    * Pause all the graphs.
    * Wait until GetState returns S_OK (the pause is complete).
    * Get the time from the graph and add 10ms or so.
    * Call IMediaFilter::Run on all graphs, passing this time (now + 10ms) as 
the parameter.


Now to implement this I put an exported function into the DirectShow plugin 
which lets me access the _renderer, using this I have implemented the above 
steps as such:

DirectShowImageStream* s1 = dynamic_cast<DirectShowImageStream*>(imagestream1);
DirectShowImageStream* s2 = dynamic_cast<DirectShowImageStream*>(imagestream2);

IReferenceClock* pClock = 0;

s1->getRenderer()->_graphBuilder->SetDefaultSyncSource(); 
s1->getRenderer()->_mediaFilter->GetSyncSource( &pClock );              
s2->getRenderer()->_mediaFilter->SetSyncSource( pClock );

s1->getRenderer()->_mediaFilter->Pause();               
s2->getRenderer()->_mediaFilter->Pause();

        //while( (s1->getRenderer()->GetState(1000, State_Paused) && 
s2->getRenderer()->GetState(1000,State_Paused)) != S_OK )
        //{             
        //}     

Sleep(1000);    

REFERENCE_TIME time = 0;  

pClock->GetTime(&time);         

s1->getRenderer()->_mediaFilter->Run( time + 100 );     
s2->getRenderer()->_mediaFilter->Run( time + 100 );

As you may notice the wait for the state is commented out as I cant seem to 
find the correct enum for the second GetState parameter, I have add a 
Sleep(1000) to try to compensate.
Using the above code both streams still play out of sync with one another, have 
tested with the same video in both graphs and they do not align, I was hoping 
maybe the author of the DirectShow plugin could advise me as to why this is the 
case? I am new to DirectShow coding so any help anyone can give will be greatly 
appreciated.

The video is encoded in HD using h264 and uses ffdshow codec when playing. 

Thanks Nathan

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=24440#24440





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to