Commit 709bbe84 authored by MONSEIGNE Thibaut's avatar MONSEIGNE Thibaut

Fix: Signal concatenation

Fix crash with no stimulation in signal
benefited to fix the coding rules
parent b9876aef
......@@ -6,7 +6,7 @@
#include <openvibe/ov_all.h>
#include <toolkit/ovtk_all.h>
#include <stdio.h>
#include <cstdio>
#include <vector>
#include <list>
// The unique identifiers for the box and its descriptor.
......@@ -33,10 +33,10 @@ namespace OpenViBEPlugins
bool initialize() override;
bool uninitialize() override;
bool processClock(OpenViBE::CMessageClock& rMessageClock) override;
bool processClock(OpenViBE::CMessageClock& messageClock) override;
uint64_t getClockFrequency() override { return 8LL << 32; }
bool processInput(uint32_t inputIndex) override;
bool processInput(uint32_t index) override;
bool process() override;
......@@ -45,68 +45,68 @@ namespace OpenViBEPlugins
protected:
virtual bool concate();
bool m_bConcatenationFinished;
bool m_bResynchroDone;
uint64_t m_ui64TimeOut;
bool m_finished = false;
bool m_resynchroDone = false;
uint64_t m_timeOut = 0;
bool m_bHeaderSent;
uint32_t m_ui32HeaderReceivedCount;
uint32_t m_ui32EndReceivedCount;
bool m_bStimHeaderSent;
bool m_bEndSent;
bool m_bStatsPrinted;
bool m_headerSent = false;
uint32_t m_headerReceivedCount = 0;
uint32_t m_endReceivedCount = 0;
bool m_stimHeaderSent = false;
bool m_endSent = false;
bool m_statsPrinted = false;
std::vector<uint64_t> m_vEndOfFileStimulations;
std::vector<bool> m_vEndOfFileReached;
std::vector<uint64_t> m_eofStimulations;
std::vector<bool> m_eofReached;
struct Chunk
struct SChunk
{
OpenViBE::IMemoryBuffer* m_pMemoryBuffer;
uint64_t m_ui64StartTime;
uint64_t m_ui64EndTime;
OpenViBE::IMemoryBuffer* m_Buffer;
uint64_t m_StartTime;
uint64_t m_EndTime;
};
struct StimulationChunk
struct SStimulationChunk
{
OpenViBE::IStimulationSet* m_pStimulationSet;
uint64_t m_ui64StartTime;
uint64_t m_ui64EndTime;
OpenViBE::IStimulationSet* m_StimulationSet;
uint64_t m_StartTime;
uint64_t m_EndTime;
};
uint64_t l_ui64stimChunkLength;
uint64_t m_stimChunkLength = 0;
// File end times
std::vector<uint64_t> m_vFileEndTimes;
std::vector<uint64_t> m_fileEndTimes;
// The signal buffers, one per file
std::vector<std::vector<Chunk>> m_vSignalChunkBuffers;
std::vector<std::vector<SChunk>> m_signalChunkBuffers;
std::vector<std::vector<StimulationChunk>> m_vStimulationChunkBuffers;
std::vector<std::vector<SStimulationChunk>> m_stimulationChunkBuffers;
// The stimulations are stored in one stimulation set per file. The chunk are reconstructed.
std::vector<OpenViBE::IStimulationSet *> m_vStimulationSets;
std::vector<OpenViBE::IStimulationSet *> m_stimulationSets;
//The decoders, (1 signal/1 stim) per file
std::vector<OpenViBEToolkit::TStimulationDecoder<CBoxAlgorithmSignalConcatenation> *> m_vStimulationDecoders;
std::vector<OpenViBEToolkit::TSignalDecoder<CBoxAlgorithmSignalConcatenation> *> m_vSignalDecoders;
std::vector<OpenViBEToolkit::TStimulationDecoder<CBoxAlgorithmSignalConcatenation> *> m_stimulationDecoders;
std::vector<OpenViBEToolkit::TSignalDecoder<CBoxAlgorithmSignalConcatenation> *> m_signalDecoders;
// the encoders : signal, stim and trigger encoder.
OpenViBEToolkit::TSignalEncoder<CBoxAlgorithmSignalConcatenation> m_oSignalEncoder;
OpenViBEToolkit::TStimulationEncoder<CBoxAlgorithmSignalConcatenation> m_oStimulationEncoder;
OpenViBEToolkit::TStimulationEncoder<CBoxAlgorithmSignalConcatenation> m_oTriggerEncoder;
OpenViBEToolkit::TSignalEncoder<CBoxAlgorithmSignalConcatenation> m_signalEncoder;
OpenViBEToolkit::TStimulationEncoder<CBoxAlgorithmSignalConcatenation> m_stimulationEncoder;
OpenViBEToolkit::TStimulationEncoder<CBoxAlgorithmSignalConcatenation> m_triggerEncoder;
uint64_t m_ui64TriggerDate;
uint64_t m_ui64LastChunkStartTime;
uint64_t m_ui64LastChunkEndTime;
uint64_t m_triggerDate = 0;
uint64_t m_lastChunkStartTime = 0;
uint64_t m_lastChunkEndTime = 0;
struct ConcatenationState
struct SConcatenationState
{
uint32_t ui32CurrentFileIndex;
uint32_t ui32CurrentChunkIndex;
uint32_t ui32CurrentStimulationIndex;
uint32_t m_CurrentFileIndex;
uint32_t m_CurrentChunkIndex;
uint32_t m_CurrentStimulationIndex;
};
ConcatenationState m_sState;
SConcatenationState m_state;
};
......@@ -116,45 +116,31 @@ namespace OpenViBEPlugins
{
public:
bool check(OpenViBE::Kernel::IBox& rBox)
bool check(OpenViBE::Kernel::IBox& rBox) const
{
char l_sName[1024];
uint32_t i;
for (i = 0; i < rBox.getInputCount() >> 1; i++)
for (uint32_t i = 0; i < rBox.getInputCount() >> 1; i++)
{
sprintf(l_sName, "Input signal %u", i + 1);
rBox.setInputName(i * 2, l_sName);
rBox.setInputName(i * 2, ("Input signal " + std::to_string(i + 1)).c_str());
rBox.setInputType(i * 2, OV_TypeId_Signal);
sprintf(l_sName, "Input stimulations %u", i + 1);
rBox.setInputName(i * 2 + 1, l_sName);
rBox.setInputName(i * 2 + 1, ("Input stimulations " + std::to_string(i + 1)).c_str());
rBox.setInputType(i * 2 + 1, OV_TypeId_Stimulations);
sprintf(l_sName, "End-of-file stimulation for input %u", i + 1);
rBox.setSettingName(i + 1, l_sName);
rBox.setSettingName(i + 1, ("End-of-file stimulation for input " + std::to_string(i + 1)).c_str());
}
return true;
}
bool onInputRemoved(OpenViBE::Kernel::IBox& rBox, const uint32_t ui32Index) override
bool onInputRemoved(OpenViBE::Kernel::IBox& rBox, const uint32_t index) override
{
if (ui32Index & 1)//odd index
{
rBox.removeInput(ui32Index - 1);
}
else //even index
{
rBox.removeInput(ui32Index);
}
rBox.removeSetting(ui32Index >> 1);
if (index & 1) { rBox.removeInput(index - 1); } // odd index
else { rBox.removeInput(index); } // even index
rBox.removeSetting(index >> 1);
return this->check(rBox);
}
bool onInputAdded(OpenViBE::Kernel::IBox& rBox, const uint32_t ui32Index) override
bool onInputAdded(OpenViBE::Kernel::IBox& rBox, const uint32_t /*index*/) override
{
rBox.addInput("", OV_TypeId_Stimulations);
rBox.addSetting("",OV_TypeId_Stimulation, "OVTK_StimulationId_ExperimentStop");
......@@ -220,7 +206,7 @@ namespace OpenViBEPlugins
_IsDerivedFromClass_Final_(OpenViBE::Plugins::IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_SignalConcatenationDesc);
};
};
};
} // namespace FileIO
} // namespace OpenViBEPlugins
#endif // __OpenViBEPlugins_BoxAlgorithm_SignalConcatenation_H__
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