Commit 4d97006e authored by Thiago Santini's avatar Thiago Santini

Fixes timer offset estimation and updates uvcengine/libuvc

libuvc: 69e45682220ff93abc6d675acfaa8fc6de8f5fca

uvcengine: fce1f275eb53cc87725f7232944813bc36da75cf
parent 0267349b
......@@ -9,7 +9,7 @@ FrameGrabber::FrameGrabber(QString id, int code, QObject *parent) :
code(code),
yuvBuffer(NULL),
yuvBufferSize(0),
timestampOffset(INT_MAX),
timestampOffset(0),
timeoutMs(2e3)
{
#ifdef TURBOJPEG
......@@ -87,8 +87,12 @@ bool FrameGrabber::present(const QVideoFrame &frame)
QVariant ft = frame.metaData("timestamp");
if (ft.isValid() ) {
if (timestampOffset == INT_MAX) // offset between gTimer and frame timer
timestampOffset = t - ft.toInt();
if ( timestampOffsetEstimators.size() < 30) {
// Use median of first N frames to estimate the offset
timestampOffsetEstimators.emplace_back( t - ft.toInt() );
std::sort(timestampOffsetEstimators.begin(), timestampOffsetEstimators.end());
timestampOffset = timestampOffsetEstimators[ 0.5*(timestampOffsetEstimators.size()-1) ];
}
t = ft.toInt() + timestampOffset;
}
......
......@@ -35,7 +35,8 @@ public slots:
private:
QTimer *watchdog;
int timeoutMs;
int timestampOffset;
Timestamp timestampOffset;
std::vector<Timestamp> timestampOffsetEstimators;
#ifdef TURBOJPEG
tjhandle tjh;
#endif
......
......@@ -41,7 +41,7 @@ unsigned int PerformanceMonitor::enrol(const QString &id, const QString &stage)
return idx;
}
bool PerformanceMonitor::shouldDrop(const unsigned int &idx, const unsigned int &delay, const unsigned int &maxDelay)
bool PerformanceMonitor::shouldDrop(const unsigned int &idx, const int &delay, const int &maxDelay)
{
if (delay > maxDelay) {
droppedFrameCount[idx]++;
......
......@@ -12,7 +12,7 @@ public:
std::vector<unsigned long int> droppedFrameCount;
unsigned int enrol(const QString &id, const QString &stage);
bool shouldDrop(const unsigned int &idx, const unsigned int &delay, const unsigned int &maxDelay=50);
bool shouldDrop(const unsigned int &idx, const int &delay, const int &maxDelay=50);
void account(const unsigned int &idx);
QString getEnrolled(const unsigned int &idx) { return idx < enrolled.size() ? enrolled[idx] : QString(); }
unsigned int enrolledCount() { return (unsigned int) enrolled.size(); }
......
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