Commit ba303861 authored by Thiago Santini's avatar Thiago Santini

Fixes timestamp calculation

Assumes that source provides a monotonic timestamp source;
if not, latency before present is not accounted for.

Previous assumption regarding latency failed since frames were
accumulating in the event loop under heavy load
parent 40b92b96
......@@ -9,6 +9,7 @@ FrameGrabber::FrameGrabber(QString id, int code, QObject *parent) :
code(code),
yuvBuffer(NULL),
yuvBufferSize(0),
timestampOffset(INT_MAX),
timeoutMs(2000)
{
#ifdef TURBOJPEG
......@@ -77,8 +78,13 @@ bool FrameGrabber::present(const QVideoFrame &frame)
*
*/
Timestamp t = gTimer.elapsed();
if ( frame.metaData("latency").isValid() ) // uvcengine supports buffering with predefined maximum latency
t -= frame.metaData("latency").toInt();
QVariant ft = frame.metaData("timestamp");
if (ft.isValid() ) {
if (timestampOffset == INT_MAX) // offset between gTimer and frame timer
timestampOffset = t - ft.toInt();
t = ft.toInt() + timestampOffset;
}
if (!frame.isValid())
return false;
......
......@@ -35,6 +35,7 @@ public slots:
private:
QTimer *watchdog;
int timeoutMs;
int timestampOffset;
#ifdef TURBOJPEG
tjhandle tjh;
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment