Box code snippet : how to send a stimulation

  • NB: Document updated for OpenViBE 1.1.0 (08.Oct.2015).

What ?

We want to send a specific stimulation on a box output, using a stimulation encoder, when a specific condition is met.

References

Code

We assume:

  • m_oStimulationEncoder is a Stimulation encoder from the codec toolkit
  • m_ui64StimulationToSend is the code of the stimulation you need to send
  • l_bCondition is a boolean indicating if the condition we are monitoring is met or not
  • The stimulation output is at index 0 in the box and the encoder is initialized to this.
  • l_ui64LastChunkStartTime and l_ui64LastChunkEndTime are taken from the last input chunk processed by the box, just when the condition is met. If there is no input to synchronize with, we can get the player time as end time and previous player time as start time (i.e. the time range of between 2 calls.
  • Note that the OpenViBE stimulation stream is supposed to be dense: the chunk is sent even if there is no stimulation. This way the downstream boxes can be aware of a stimulation missing.

In the process() function of your box:

IStimulationSet* l_pStimulationSet = m_oStimulationEncoder.getInputStimulationSet();
l_pStimulationSet->clear(); // to be sure that the stimulation set in the codec is empty

if(l_bCondition)
{
    // we get the current time of the player
    const uint64 l_ui64StimulationDate = this->getPlayerContext().getCurrentTime();

    // appending the stimulation (duration = 0)
    l_pStimulation->appendStimulation(m_ui64StimulationToSend, l_ui64StimulationDate, 0);
}

// encoding the stimulation
m_oStimulationEncoder.encodeBuffer();
this->getDynamicBoxContext().markOutputAsReadyToSend(0,l_ui64LastChunkStartTime,
    l_ui64LastChunkEndtime);

This entry was posted in Code snippet and tagged . Bookmark the permalink.