Search code examples
c#directshowdirectshow.net

Set filter as clock reference of graph


I have a big graph which has three filters with reference clock. I want to choose push demultiplexer as graph reference clock. My graph plays well in GraphEdit but doesn't play smoothly in my application and I think it's because of reference clock of the graph.

How can I choose a filter as reference clock of my graph?

I have this code but it doesn't work:

IReferenceClock refClock = (IReferenceClock) new SystemClock();
long time;
refClock.GetTime(out time);
IMediaFilter mediaFilter = (IMediaFilter) push_demultiplexer;
mediaFilter.SetSyncSource(refClock);

Solution

  • IReferenceClock refClock = (IReferenceClock) new SystemClock();
    

    The code just does a different thing. This is system clock being set to you don't show what exactly... Instead, you want to take filter's clock and set it as filter graph clock like this:

    IReferenceClock refClock = myFilter as IReferenceClock;
    IMediaFilter mediaFilter = filterGraph as IMediaFilter;
    mediaFilter.SetSyncSource(refClock);