65 mStreamerInterface(streamerInterface)
67 this->setObjectName(
"imagereceiver worker");
68 mGeneratingTimeCalibration =
false;
69 mLastReferenceTimestampDiff = 0.0;
70 mLastTimeStamps.reserve(20);
75 if (!this->attemptInitialize())
78 mImageStreamer.reset();
85 bool ImageReceiverThread::attemptInitialize()
88 QDomElement element = xmlFile.
getElement(
"video");
89 mImageStreamer = mStreamerInterface->createStreamer(element);
96 mSender.reset(
new DirectlyLinkedSender());
101 mImageStreamer->startStreaming(mSender);
111 mImageStreamer->stopStreaming();
113 mImageStreamer.reset();
120 void ImageReceiverThread::addImageToQueueSlot()
125 void ImageReceiverThread::addSonixStatusToQueueSlot()
133 this->reportFPS(imgMsg->getUid());
137 bool needToCalibrateMsgTimeStamp = this->imageComesFromSonix(imgMsg);
141 if (needToCalibrateMsgTimeStamp)
144 QMutexLocker sentry(&mImageMutex);
145 mMutexedImageMessageQueue.push_back(imgMsg);
153 QMutexLocker sentry(&mSonixStatusMutex);
154 mMutexedSonixStatusMessageQueue.push_back(msg);
161 QMutexLocker sentry(&mImageMutex);
162 if (mMutexedImageMessageQueue.empty())
164 ImagePtr retval = mMutexedImageMessageQueue.front();
165 mMutexedImageMessageQueue.pop_front();
177 QMutexLocker sentry(&mSonixStatusMutex);
178 if (mMutexedSonixStatusMessageQueue.empty())
181 mMutexedSonixStatusMessageQueue.pop_front();
187 QDateTime timestamp_dt = imgMsg->getAcquisitionTime();
188 double timestamp_ms = timestamp_dt.toMSecsSinceEpoch();
190 if (
similar(mLastReferenceTimestampDiff, 0.0, 0.000001))
191 mLastReferenceTimestampDiff = timestamp_dt.msecsTo(QDateTime::currentDateTime());
194 if(mLastSyncTime.isNull() || ( mLastSyncTime.msecsTo(QDateTime::currentDateTime()) > 2000) )
195 mGeneratingTimeCalibration =
true;
197 if(mGeneratingTimeCalibration)
198 mLastTimeStamps.push_back(timestamp_dt.msecsTo(QDateTime::currentDateTime()));
201 if(mLastTimeStamps.size() >= 20)
203 std::sort(mLastTimeStamps.begin(), mLastTimeStamps.end(),
AbsDoubleLess(mLastReferenceTimestampDiff));
205 mLastTimeStamps.resize(15);
208 for (std::vector<double>::const_iterator citer = mLastTimeStamps.begin(); citer != mLastTimeStamps.end(); ++citer)
212 mLastReferenceTimestampDiff = sumTimes / 15.0;
215 mLastTimeStamps.clear();
216 mLastSyncTime = QDateTime::currentDateTime();
217 mGeneratingTimeCalibration =
false;
219 imgMsg->setAcquisitionTime(QDateTime::fromMSecsSinceEpoch(timestamp_ms + mLastReferenceTimestampDiff));
223 void ImageReceiverThread::reportFPS(QString streamUid)
226 if (!mFPSTimer.count(streamUid))
229 mFPSTimer[streamUid]->reset(timeout);
235 if (logger->intervalPassed())
237 emit
fps(streamUid, logger->getFPS());
238 logger->reset(timeout);
242 bool ImageReceiverThread::imageComesFromSonix(
ImagePtr imgMsg)
244 return imgMsg->getUid().contains(
"Sonix", Qt::CaseInsensitive);
249 if (!mStreamerInterface)
251 return mStreamerInterface->getName();
cxResource_EXPORT ProfilePtr profile()
void fps(QString, double)
boost::shared_ptr< class Image > ImagePtr
QDomElement getElement()
return the current element
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
virtual ImagePtr getLastImageMessage()
AbsDoubleLess(double center)
void sonixStatusReceived()
boost::shared_ptr< class CyclicActionLogger > CyclicActionLoggerPtr
void addSonixStatusToQueue(ProbeDefinitionPtr msg)
add the message to a thread-safe queue
virtual QString hostDescription() const
ImageReceiverThread(StreamerServicePtr streamerInterface, QObject *parent=NULL)
void calibrateTimeStamp(ImagePtr imgMsg)
Calibrate the time stamps of the incoming message based on the computer clock. Calibration is based o...
virtual ProbeDefinitionPtr getLastSonixStatusMessage()
boost::shared_ptr< class StreamerService > StreamerServicePtr
bool operator()(const double &d1, const double &d2)
void addImageToQueue(ImagePtr imgMsg)
boost::shared_ptr< class ProbeDefinition > ProbeDefinitionPtr
Helper class for xml files used to store ssc/cx data.