99 lines
2.3 KiB
C++
99 lines
2.3 KiB
C++
#ifndef STAGINGBUFFER_H
|
|
#define STAGINGBUFFER_H
|
|
|
|
#include <memory>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <atomic>
|
|
|
|
namespace smo {
|
|
namespace stim_buff {
|
|
|
|
/**
|
|
* StagingBuffer manages a large buffer to guide io_uring in assembling some
|
|
* number of Livox Avia pcloud UDP dgrams into a single stim frame.
|
|
*
|
|
* The buffer operates in a cycle:
|
|
* 1. io_uring assembles UDP dgrams into the buffer until it's full
|
|
* 2. Buffer is handed off to the stimbuff layer to be appended to the stimbuff.
|
|
* 3. When the stimbuff layer has appended the current assembled frame, the
|
|
* assembly buffer is reset and cycle repeats.
|
|
*/
|
|
class StagingBuffer
|
|
{
|
|
public:
|
|
class InputEngineConstraints
|
|
{
|
|
public:
|
|
InputEngineConstraints();
|
|
~InputEngineConstraints();
|
|
};
|
|
|
|
class OutputEngineConstraints
|
|
{
|
|
public:
|
|
OutputEngineConstraints();
|
|
~OutputEngineConstraints();
|
|
};
|
|
|
|
public:
|
|
/** EXPLANATION:
|
|
* We use the input and output engine constraints to determine the total
|
|
* amount of memory required internally to assemble a single frame with
|
|
* the given number of points per frame.
|
|
*/
|
|
explicit StagingBuffer(
|
|
const InputEngineConstraints& inputEngineConstraints,
|
|
const OutputEngineConstraints& outputEngineConstraints,
|
|
size_t nPointsPerFrame);
|
|
~StagingBuffer();
|
|
|
|
// Non-copyable, movable
|
|
StagingBuffer(const StagingBuffer&) = delete;
|
|
StagingBuffer& operator=(const StagingBuffer&) = delete;
|
|
StagingBuffer(StagingBuffer&&) = default;
|
|
StagingBuffer& operator=(StagingBuffer&&) = default;
|
|
|
|
public:
|
|
// operator IoUringQueueDescriptor() const;
|
|
// operator OpenClSharedBufferDescriptor() const;
|
|
|
|
bool isAssembling() const { return isAssembling_; }
|
|
void startAssembly();
|
|
void stopAssembly();
|
|
|
|
private:
|
|
// Buffer data
|
|
std::unique_ptr<uint8_t[]> buffer_;
|
|
size_t bufferSize_;
|
|
|
|
// Current state
|
|
std::atomic<size_t> currentSize_;
|
|
std::atomic<bool> isAssembling_;
|
|
};
|
|
|
|
class IoUringConstraints
|
|
: public StagingBuffer::InputEngineConstraints
|
|
{
|
|
public:
|
|
IoUringConstraints()
|
|
: StagingBuffer::InputEngineConstraints()
|
|
{}
|
|
~IoUringConstraints() = default;
|
|
};
|
|
|
|
class OpenClConstraints
|
|
: public StagingBuffer::OutputEngineConstraints
|
|
{
|
|
public:
|
|
OpenClConstraints()
|
|
: StagingBuffer::OutputEngineConstraints()
|
|
{}
|
|
~OpenClConstraints() = default;
|
|
};
|
|
|
|
} // namespace stim_buff
|
|
} // namespace smo
|
|
|
|
#endif // STAGINGBUFFER_H
|