PDA

View Full Version : How to get accurate time stamps for each frame?



Julianz
December 8, 2011, 01:31:29
We are using the DFG/USB-lt converter with a 30 Hz camera and reading in the frames using the v3.2 Imaging Control software in C++. We would like to know the timing of each frame as it arrives to a fair degree of accuracy (at least 1 ms say). I am able to measure the time as each frames arrives in the frameReady() event handler using the Windows high performance time counter. However, there appears to be significant variability in the differences between frame times - typically the differences hover around 33 ms as one might expect but occasionally we get some that are about about 45 ms, some even longer. I know Windows is most likely to blame for this as it is not a real-time OS. We have done our best to remove other background processes that might cause things to be interrupted or delayed but I am wondering whether you have a hardware based time stamp that we can access that would be unaffected by such delays. I looked at the structure you mentioned in another thread:

typedef struct
{
REFERENCE_TIME SampleStart;
REFERENCE_TIME SampleEnd;
DWORD FrameNumber;
tFrameDesc FrameType; // Type of the frame
} tsMediaSampleDesc;

I was hoping that the SampleStart would be the kind of thing that we are looking for. However, these times stamps seem to be afflicted with almost the same amount of jitter as the time stamps I am generating. Do you have anything that stamps the time of the frame data as it comes in?

Thanks

Stefan Geissler
December 8, 2011, 08:20:15
Hi Julian,

The SampleStart are created by the driver, when it is informed about a new frame being delivered. That means, the USB board driver informs the DFG/USB2-lt driver about this frame. This is the best you can get.

You are right, the delays are created by Windows and DirectShow.

Julianz
December 8, 2011, 21:40:03
Many thanks Stefan for your prompt answer. That's disappointing news. Is this the same for all of your hardware including the digital cameras? Is it not possible for the hardware in the camera or at the front end of the frame grabber, for example, to provide an accurate time stamp that would be passed on to the driver?

Julianz
December 9, 2011, 01:48:57
Some more related questions that might help me get round the time stamp issue. In tsMediaSampleDesc I can retrieve the frame number. If for some reason a frame is skipped will the FrameNumber field show the gap? So if I get frames 1, 2, 4, and 5 will I see it in those numbers or will it just count down 1,2,3,4 in the FrameNumber field?

Also if I set a buffer array of 10 frame buffers say, how do I know in frameReady() whether there is more than one buffer sitting there waiting to be processed? How do I access them in the right order?

Stefan Geissler
December 9, 2011, 09:37:12
Regarding time spans:
The analogue cameras do not send time stamps through composite or Y/C as far as I know. (I case they do, this will be ignored by the digitizer of the DFG/USB2-lt).

Regarding frame number:
The DFG/USB2-lt is sending images all the time. If you miss a frameReady call, because the last frameReady call did not return in time, then the frame number sequence will have a gap. How to handle this is shown in the C++ "Callback" sample.


Also if I set a buffer array of 10 frame buffers say, how do I know in frameReady() whether there is more than one buffer sitting there waiting to be processed? How do I access them in the right order?

You do not now by parameters. But you may pass a reference of your FrameHandlerSink to the CListener class and use its method getLastAcqMemBuffer() to query the last acquried memory buffer. You can compare its data (e.g. samplestarttime) with the one passed to the frameReady Call. If the differ, then you may are outdated in frameReady.

However, if your frameReady does not last longer than the frame rate's time intervall allows, this wont happen.