Commit 4ff21e64 authored by Jussi Lindgren's avatar Jussi Lindgren

Plugins: Fixed Timeout box not sending a continuous stimulus stream

Side-effect: The chunk containing the timeout stimulus no longer
encodes the time data was last received in the timestamp of the chunk.
parent 96421f29
......@@ -9,13 +9,15 @@ using namespace OpenViBEPlugins::Stimulation;
boolean CBoxAlgorithmTimeout::initialize(void)
{
m_bTimeoutReached = false;
m_ui32TimeoutState = 0;
m_oStimulationEncoder.initialize(*this,0);
m_ui64Timeout = static_cast<uint64>(FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0)) << 32;
m_ui64StimulationToSend = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
m_ui64LastTimePolled = 0;
m_ui64PreviousTime = 0;
return true;
}
......@@ -32,17 +34,12 @@ boolean CBoxAlgorithmTimeout::uninitialize(void)
boolean CBoxAlgorithmTimeout::processClock(IMessageClock& rMessageClock)
{
if (m_bTimeoutReached)
{
return true;
}
// if there was nothing received on the input for a period of time we raise the
// timeout flag and let the box send a stimulation
if (getPlayerContext().getCurrentTime() > m_ui64LastTimePolled + m_ui64Timeout)
if (m_ui32TimeoutState == 0 && getPlayerContext().getCurrentTime() > m_ui64LastTimePolled + m_ui64Timeout)
{
getLogManager() << LogLevel_Info << "Timeout reached" << "\n";
m_bTimeoutReached = true;
m_ui32TimeoutState = 1;
}
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
......@@ -72,20 +69,24 @@ boolean CBoxAlgorithmTimeout::processInput(uint32 ui32InputIndex)
boolean CBoxAlgorithmTimeout::process(void)
{
// If the timeout is reached we send the stimulation on the output 0
if (m_bTimeoutReached)
{
IStimulationSet* l_pStimulationSet = m_oStimulationEncoder.getInputStimulationSet();
l_pStimulationSet->clear();
uint64 l_ui64StimulationDate = this->getPlayerContext().getCurrentTime();
IStimulationSet* l_pStimulationSet = m_oStimulationEncoder.getInputStimulationSet();
l_pStimulationSet->clear();
l_pStimulationSet->appendStimulation(m_ui64StimulationToSend, l_ui64StimulationDate, 0);
const uint64 l_ui64StimulationDate = this->getPlayerContext().getCurrentTime();
// encoding the stimulation
m_oStimulationEncoder.encodeBuffer();
this->getDynamicBoxContext().markOutputAsReadyToSend(0, m_ui64LastTimePolled, l_ui64StimulationDate);
// If the timeout is reached we send the stimulation on the output 0
if (m_ui32TimeoutState == 1)
{
l_pStimulationSet->appendStimulation(m_ui64StimulationToSend, l_ui64StimulationDate, 0);
m_ui32TimeoutState = 2;
}
// we need to send an empty chunk even if there's no stim
m_oStimulationEncoder.encodeBuffer();
this->getDynamicBoxContext().markOutputAsReadyToSend(0, m_ui64PreviousTime, l_ui64StimulationDate);
m_ui64PreviousTime = l_ui64StimulationDate;
return true;
}
......@@ -41,9 +41,10 @@ namespace OpenViBEPlugins
OpenViBEToolkit::TStimulationEncoder < CBoxAlgorithmTimeout > m_oStimulationEncoder;
private:
OpenViBE::boolean m_bTimeoutReached;
OpenViBE::uint32 m_ui32TimeoutState; // 0 == no timeout, 1 == timeout, 2 == timeout sent
OpenViBE::uint64 m_ui64Timeout;
OpenViBE::uint64 m_ui64LastTimePolled;
OpenViBE::uint64 m_ui64PreviousTime;
OpenViBE::uint64 m_ui64StimulationToSend;
};
......@@ -67,7 +68,7 @@ namespace OpenViBEPlugins
virtual OpenViBE::CString getShortDescription(void) const { return OpenViBE::CString("Sends a stimulation after a period of time without receiving signal"); }
virtual OpenViBE::CString getDetailedDescription(void) const { return OpenViBE::CString("Sends a stimulation after a period of time without receiving signal. Useful for stopping scenarios after hardware disconnection."); }
virtual OpenViBE::CString getCategory(void) const { return OpenViBE::CString("Stimulation"); }
virtual OpenViBE::CString getVersion(void) const { return OpenViBE::CString("1.0"); }
virtual OpenViBE::CString getVersion(void) const { return OpenViBE::CString("1.1"); }
virtual OpenViBE::CString getStockItemName(void) const { return OpenViBE::CString("gtk-disconnect"); }
virtual OpenViBE::CIdentifier getCreatedClass(void) const { return OVP_ClassId_BoxAlgorithm_Timeout; }
......
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