34 #include <vtkDataSetMapper.h>
35 #include <vtkImageFlip.h>
44 #include <QApplication>
45 #include "boost/function.hpp"
46 #include "boost/bind.hpp"
57 mUnsusedProbeDataVector.clear();
60 connect(mBackend->getToolManager().get(), SIGNAL(activeToolChanged(QString)),
this, SLOT(connectVideoToProbe()));
66 this->waitForClientFinished();
69 void VideoConnection::waitForClientFinished()
85 void VideoConnection::fpsSlot(QString source,
double fpsNumber)
88 emit
fps(source, fpsNumber);
98 return mStreamerInterface;
104 class EventProcessingThread :
public QThread
109 qApp->processEvents();
119 CX_LOG_INFO() <<
"Video client already exists - cannot start";
125 CX_LOG_INFO() <<
"Video thread already exists (in shutdown?) - cannot start";
132 connect(mClient, SIGNAL(imageReceived()),
this, SLOT(imageReceivedSlot()));
133 connect(mClient, SIGNAL(sonixStatusReceived()),
this, SLOT(statusReceivedSlot()));
134 connect(mClient, SIGNAL(
fps(QString,
double)),
this, SLOT(fpsSlot(QString,
double)));
136 mThread =
new EventProcessingThread;
137 mThread->setObjectName(
"org.custusx.core.video.imagereceiver");
138 mClient->moveToThread(mThread);
140 connect(mThread.data(), &QThread::started,
this, &VideoConnection::onConnected);
145 connect(mThread.data(), &QThread::finished,
this, &VideoConnection::onDisconnected);
146 connect(mThread.data(), &QThread::finished, mThread.data(), &QThread::deleteLater);
151 void VideoConnection::imageReceivedSlot()
155 this->updateImage(mClient->getLastImageMessage());
158 void VideoConnection::statusReceivedSlot()
162 this->updateStatus(mClient->getLastSonixStatusMessage());
165 void VideoConnection::stopClient()
172 disconnect(mClient, SIGNAL(imageReceived()),
this, SLOT(imageReceivedSlot()));
173 disconnect(mClient, SIGNAL(sonixStatusReceived()),
this, SLOT(statusReceivedSlot()));
174 disconnect(mClient, SIGNAL(
fps(QString,
double)),
this, SLOT(fpsSlot(QString,
double)));
176 QMetaObject::invokeMethod(mClient,
"shutdown", Qt::QueuedConnection);
187 void VideoConnection::onConnected()
189 this->startAllSources();
193 void VideoConnection::onDisconnected()
200 this->stopAllSources();
202 for (
unsigned i=0; i<mSources.size(); ++i)
205 ToolPtr tool = mBackend->getToolManager()->getFirstProbe();
206 if (tool && tool->getProbe())
207 this->removeSourceFromProbe(tool);
210 mStreamerInterface.reset();
216 void VideoConnection::useUnusedProbeDataSlot()
219 for (std::vector<ProbeDefinitionPtr>::const_iterator citer = mUnsusedProbeDataVector.begin(); citer != mUnsusedProbeDataVector.end(); ++citer)
220 this->updateStatus(*citer);
221 mUnsusedProbeDataVector.clear();
224 void VideoConnection::resetProbe()
226 ToolPtr tool = mBackend->getToolManager()->getFirstProbe();
227 if (!tool || !tool->getProbe())
232 ProbeDefinition data = probe->getProbeData();
233 data.setUseDigitalVideo(
false);
234 probe->setProbeSector(data);
244 ToolPtr tool = mBackend->getToolManager()->getFirstProbe();
245 if (!tool || !tool->getProbe())
248 if (mUnsusedProbeDataVector.empty())
250 mUnsusedProbeDataVector.push_back(msg);
258 ProbeDefinition data = probe->getProbeData();
260 data.setUid(msg->getUid());
261 data.setType(msg->getType());
262 data.setSector(msg->getDepthStart(), msg->getDepthEnd(), msg->getWidth());
263 data.setOrigin_p(msg->getOrigin_p());
264 data.setSize(msg->getSize());
265 data.setSpacing(msg->getSpacing());
266 data.setClipRect_p(msg->getClipRect_p());
267 data.setUseDigitalVideo(
true);
269 probe->setProbeSector(data);
270 probe->setActiveStream(msg->getUid());
273 void VideoConnection::startAllSources()
275 for (
unsigned i=0; i<mSources.size(); ++i)
276 mSources[i]->start();
279 void VideoConnection::stopAllSources()
281 for (
unsigned i=0; i<mSources.size(); ++i)
285 void VideoConnection::removeSourceFromProbe(
ToolPtr tool)
288 for (
unsigned i=0; i<mSources.size(); ++i)
289 probe->removeRTSource(mSources[i]);
292 void VideoConnection::updateImage(
ImagePtr message)
297 for (
unsigned i=0; i<mSources.size(); ++i)
299 if (message && message->getUid() == mSources[i]->getUid())
300 source = mSources[i];
303 bool newSource =
false;
307 source.reset(
new BasicVideoSource());
308 mSources.push_back(source);
313 source->setInput(message);
315 QString info = mClient->hostDescription() +
" - " + QString::number(mFPS,
'f', 1) +
" fps";
316 source->setInfoString(info);
320 this->connectVideoToProbe();
327 std::vector<VideoSourcePtr> retval;
328 std::copy(mSources.begin(), mSources.end(), std::back_inserter(retval));
339 void VideoConnection::connectVideoToProbe()
341 ToolPtr tool = mBackend->getToolManager()->getFirstProbe();
349 for (
unsigned i=0; i<mSources.size(); ++i)
350 probe->setRTSource(mSources[i]);
boost::shared_ptr< BasicVideoSource > BasicVideoSourcePtr
boost::shared_ptr< class Image > ImagePtr
VideoConnection(VideoServiceBackendPtr backend)
void videoSourcesChanged()
std::vector< VideoSourcePtr > getVideoSources()
boost::shared_ptr< class VideoServiceBackend > VideoServiceBackendPtr
boost::shared_ptr< Probe > ProbePtr
Base class for receiving images from a video stream.
virtual bool isConnected() const
vtkSmartPointer< vtkDataSetMapper > vtkDataSetMapperPtr
virtual ~VideoConnection()
vtkSmartPointer< vtkImageFlip > vtkImageFlipPtr
boost::shared_ptr< class StreamerService > StreamerServicePtr
void runDirectLinkClient(StreamerService *service)
Abstract class. Interface to Streamers.
boost::shared_ptr< class ProbeDefinition > ProbeDefinitionPtr
void fps(QString source, int fps)
boost::shared_ptr< class Tool > ToolPtr