Question

Thanks to Roman R's answer to my previous question I now have an asynchronous filter wrapping a 3rd party decoder library.

The encoded input samples are coming from a network source. At present I am not adding timestamps to the decoded frames so the framerate is rather jerky as it is dependent on the time the data packets are received.

When the library decodes a full frame it also provides a UTC timestamp of the time the frame was captured according to the clock on the source encoder.

The question is: how can I related this to the stream time and create a sensible value for the SetTime function? I've played around with it but what ever values I put in just seem to lock up the filter graph at the CBaseOutputPin::Deliver function.

Was it helpful?

Solution

The easiest time stamping is as follows. You time stamp your first media sample with a zero (see adjustment note in next paragraph) and the following will be stamped with a difference against it. That is, you start streaming and you obtain first sample from your network source, you remember this time UTC0 and attach zero to the DirectShow media sample. Following frames 1, 2 ... N with UTC times UTC1... UTCN and will be converted to DirectShow time UTCN - UTC0. You might need an additional conversion to proper units, as DirectShow will need 100 ns units and your network source might be giving you something like 1/90000 s.

Since your source is perhaps a live source, and your first frame might be obtained not exactly at graph run time, you might be adjusting resulting media sample time stamp using a difference between current filter graph's IReferenceClock::GetTime and time received as argument to IBaseFilter::Run call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top