13 #include <vtkDataSetMapper.h>
14 #include <vtkImageFlip.h>
23 #include <QApplication>
24 #include "boost/function.hpp"
25 #include "boost/bind.hpp"
36 mUnusedProbeDefinitionVector.clear();
39 connect(mBackend->tracking().get(), SIGNAL(activeToolChanged(QString)),
this, SLOT(connectVideoToProbe()));
45 this->waitForClientFinished();
48 void VideoConnection::waitForClientFinished()
64 void VideoConnection::fpsSlot(QString source,
double fpsNumber)
67 emit
fps(source, fpsNumber);
77 return mStreamerInterface;
83 class EventProcessingThread :
public QThread
88 qApp->processEvents();
98 CX_LOG_INFO() <<
"Video client already exists - cannot start";
104 CX_LOG_INFO() <<
"Video thread already exists (in shutdown?) - cannot start";
108 mStreamerInterface = service;
115 mThread =
new EventProcessingThread;
116 mThread->setObjectName(
"org.custusx.core.video.imagereceiver");
117 mClient->moveToThread(mThread);
119 connect(mThread.data(), &QThread::started,
this, &VideoConnection::onConnected);
124 connect(mThread.data(), &QThread::finished,
this, &VideoConnection::onDisconnected);
125 connect(mThread.data(), &QThread::finished, mThread.data(), &QThread::deleteLater);
130 void VideoConnection::imageReceivedSlot()
134 this->updateImage(mClient->getLastImageMessage());
137 void VideoConnection::statusReceivedSlot()
141 this->updateStatus(mClient->getLastSonixStatusMessage());
144 void VideoConnection::stopClient()
155 QMetaObject::invokeMethod(mClient,
"shutdown", Qt::QueuedConnection);
166 void VideoConnection::onConnected()
168 this->startAllSources();
172 void VideoConnection::onDisconnected()
179 this->stopAllSources();
181 for (
unsigned i=0; i<mSources.size(); ++i)
184 ToolPtr tool = mBackend->tracking()->getFirstProbe();
185 if (tool && tool->getProbe())
186 this->removeSourceFromProbe(tool);
189 mStreamerInterface.reset();
195 void VideoConnection::useUnusedProbeDefinitionSlot()
199 std::vector<ProbeDefinitionPtr> unusedProbeDefinitionVector = mUnusedProbeDefinitionVector;
200 mUnusedProbeDefinitionVector.clear();
202 for (
unsigned i = 0; i < unusedProbeDefinitionVector.size(); ++i)
203 this->updateStatus(unusedProbeDefinitionVector[i]);
206 void VideoConnection::resetProbe()
208 ToolPtr tool = mBackend->tracking()->getFirstProbe();
209 if (!tool || !tool->getProbe())
214 ProbeDefinition data = probe->getProbeDefinition();
215 data.setUseDigitalVideo(
false);
216 probe->setProbeDefinition(data);
226 ToolPtr tool = mBackend->tracking()->getFirstProbe();
227 if (!tool || !tool->getProbe())
230 if (mUnusedProbeDefinitionVector.empty())
232 mUnusedProbeDefinitionVector.push_back(msg);
240 ProbeDefinition data = probe->getProbeDefinition();
242 data.setUid(msg->getUid());
243 data.setType(msg->getType());
244 data.setSector(msg->getDepthStart(), msg->getDepthEnd(), msg->getWidth());
245 data.setOrigin_p(msg->getOrigin_p());
246 data.setSize(msg->getSize());
247 data.setSpacing(msg->getSpacing());
248 data.setClipRect_p(msg->getClipRect_p());
249 data.setUseDigitalVideo(
true);
251 probe->setProbeDefinition(data);
252 probe->setActiveStream(msg->getUid());
255 void VideoConnection::startAllSources()
257 for (
unsigned i=0; i<mSources.size(); ++i)
258 mSources[i]->start();
261 void VideoConnection::stopAllSources()
263 for (
unsigned i=0; i<mSources.size(); ++i)
267 void VideoConnection::removeSourceFromProbe(
ToolPtr tool)
270 for (
unsigned i=0; i<mSources.size(); ++i)
271 probe->removeRTSource(mSources[i]);
274 void VideoConnection::updateImage(
ImagePtr message)
279 for (
unsigned i=0; i<mSources.size(); ++i)
281 if (message && message->getUid() == mSources[i]->getUid())
282 source = mSources[i];
285 bool newSource =
false;
289 source.reset(
new BasicVideoSource());
290 mSources.push_back(source);
295 source->setInput(message);
297 QString info = mClient->hostDescription() +
" - " + QString::number(mFPS,
'f', 1) +
" fps";
298 source->setInfoString(info);
302 this->connectVideoToProbe();
309 std::vector<VideoSourcePtr> retval;
310 std::copy(mSources.begin(), mSources.end(), std::back_inserter(retval));
321 void VideoConnection::connectVideoToProbe()
323 ToolPtr tool = mBackend->tracking()->getFirstProbe();
331 for (
unsigned i=0; i<mSources.size(); ++i)
332 probe->setRTSource(mSources[i]);