Search code examples
delphifilterdirectshow

How to convert between "double" timestamp from DirectShow sample grabber and FillBuffer REFERENCE_TIME?


The IMediaSample SetTime() function expects two REFERENCE_TIME parameters. REFERENCE_TIME is defined as type "LongLong" in Delphi 6, the programming language I am using for my DirectShow application. However, the first parameter of the Callback method that the DirectShow sample grabber filter uses to pass the sample time of a new media sample is cast as double. How do I convert between these two values so I can compare the sample time's between media sample's I receive from the sample grabber filter and the REFERENCE_TIME values that I generate in my push source filter's FillBuffer() method?

Also, would the sample time that is provided by the Sample Grabber filter in the callback method be considered the Start time of a media sample, or the End time?


Solution

  • Simple part: double is in seconds, and REFERENCE_TIME is in 100 ns units. Hence the conversion is simple: multiple or divide by 1E+7.

    Not so simple one: you capture some time in grabber in one filter graph, and you time stamp data in your filter in another graph. Both graphs have time stamps to indicate streaming/presentation time, which is relative to graph "run time". That is, when media sample is passed between graphs, there might also a time stamp offset involved.

    As for end time, with video media samples, sample stop time may be omitted or set equal to start time; with audio stop time is normally something you can compute by adding start time to time of payload data the buffer holds.

    Bonus reading on MSDN: Time and Clocks in DirectShow