Split StimulusProducer=>StimulusBuffer+StimulusProducer
We're getting ready for the last mile of the StimulusBuffer API and the proto-completion of the LivoxGen1 StimBuffApi.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#ifndef _STIMULUS_BUFFER_H
|
||||
#define _STIMULUS_BUFFER_H
|
||||
|
||||
#include <config.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <user/spMcRingBuffer.h>
|
||||
#include "stimulusFrame.h"
|
||||
|
||||
namespace smo {
|
||||
namespace stim_buff {
|
||||
|
||||
// Forward declaration
|
||||
class StimulusProducer;
|
||||
|
||||
/**
|
||||
* StimulusBuffer manages a collection of stimulus frames and ring buffer.
|
||||
*
|
||||
* This buffer holds the actual frame storage and ring buffer for stimulus
|
||||
* data. It maintains a reference to the StimulusProducer that it owns.
|
||||
*/
|
||||
class StimulusBuffer
|
||||
{
|
||||
public:
|
||||
explicit StimulusBuffer(
|
||||
std::shared_ptr<StimulusProducer> &producer,
|
||||
int histbuffMs,
|
||||
const SpMcRingBuffer::InputEngineConstraints& ringBufferConstraints)
|
||||
: producer(producer),
|
||||
histbuffMs(histbuffMs),
|
||||
frames_(static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS)),
|
||||
ringBufferConstraints(ringBufferConstraints),
|
||||
ringBuffer(
|
||||
static_cast<size_t>(histbuffMs / CONFIG_STIMBUFF_FRAME_PERIOD_MS),
|
||||
ringBufferConstraints)
|
||||
{}
|
||||
|
||||
~StimulusBuffer() = default;
|
||||
|
||||
// Non-copyable, movable
|
||||
StimulusBuffer(const StimulusBuffer&) = delete;
|
||||
StimulusBuffer& operator=(const StimulusBuffer&) = delete;
|
||||
StimulusBuffer(StimulusBuffer&&) = default;
|
||||
StimulusBuffer& operator=(StimulusBuffer&&) = default;
|
||||
|
||||
public:
|
||||
std::shared_ptr<StimulusProducer> producer;
|
||||
std::vector<StimulusFrame> frames_;
|
||||
|
||||
protected:
|
||||
int histbuffMs;
|
||||
SpMcRingBuffer::InputEngineConstraints ringBufferConstraints;
|
||||
SpMcRingBuffer ringBuffer;
|
||||
};
|
||||
|
||||
} // namespace stim_buff
|
||||
} // namespace smo
|
||||
|
||||
#endif // _STIMULUS_BUFFER_H
|
||||
@@ -14,8 +14,6 @@
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <spinLock.h>
|
||||
#include <user/spMcRingBuffer.h>
|
||||
#include "stimulusFrame.h"
|
||||
#include "deviceAttachmentSpec.h"
|
||||
|
||||
namespace smo {
|
||||
@@ -33,29 +31,12 @@ namespace stim_buff {
|
||||
*/
|
||||
class StimulusProducer
|
||||
{
|
||||
public:
|
||||
class PcloudFormatDesc
|
||||
{
|
||||
public:
|
||||
enum class Format
|
||||
{
|
||||
XYZ,
|
||||
XYZI,
|
||||
};
|
||||
|
||||
public:
|
||||
Format format;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit StimulusProducer(
|
||||
const std::shared_ptr<device::DeviceAttachmentSpec>
|
||||
&deviceAttachmentSpec,
|
||||
size_t nSlots,
|
||||
const SpMcRingBuffer::InputEngineConstraints& ringBufferConstraints,
|
||||
boost::asio::io_service& ioService_)
|
||||
: deviceAttachmentSpec(deviceAttachmentSpec),
|
||||
ringBuffer(nSlots, ringBufferConstraints),
|
||||
ioService(ioService_),
|
||||
shouldContinue(false), timer(ioService),
|
||||
nDeferrals(0)
|
||||
@@ -86,6 +67,8 @@ public:
|
||||
{ frameAssemblyRateLimiter.release(); }
|
||||
|
||||
protected:
|
||||
SpinLock frameAssemblyRateLimiter;
|
||||
|
||||
// Virtual functions for derived classes to override
|
||||
virtual int getStopDelayMs() const
|
||||
{
|
||||
@@ -99,11 +82,6 @@ private:
|
||||
|
||||
public:
|
||||
std::shared_ptr<device::DeviceAttachmentSpec> deviceAttachmentSpec;
|
||||
std::vector<StimulusFrame> frames_;
|
||||
|
||||
protected:
|
||||
SpinLock frameAssemblyRateLimiter;
|
||||
SpMcRingBuffer ringBuffer;
|
||||
|
||||
private:
|
||||
boost::asio::io_service& ioService;
|
||||
|
||||
Reference in New Issue
Block a user