LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_streammgr.h
Go to the documentation of this file.
1#pragma once
2#include "lasp_daq.h"
3#include "lasp_siggen.h"
4#include "lasp_thread.h"
5#include <list>
6#include <memory>
7#include <mutex>
8#include <thread>
9
13class StreamMgr;
14class InDataHandler;
15
16
17class SeriesBiquad;
18
27class StreamMgr {
28
32 std::unique_ptr<Daq> _inputStream, _outputStream;
33
34 GlobalThreadPool _pool;
35
41 std::list<InDataHandler *> _inDataHandlers;
42 mutable std::mutex _inDataHandler_mtx;
43
48 std::shared_ptr<Siggen> _siggen;
49 std::mutex _siggen_mtx;
50
54 std::vector<std::unique_ptr<SeriesBiquad>> _inputFilters;
55
56
57 mutable std::recursive_mutex _devices_mtx;
61 DeviceInfoList _devices;
62
63 // Singleton, no public constructor. Can only be obtained using
64 // getInstance();
65 StreamMgr();
66
67 friend class InDataHandler;
68 friend class Siggen;
69
70
71 public:
72
73 ~StreamMgr();
74
75 enum class StreamType : us {
79 input = 1 << 0,
83 output = 1 << 1,
84 };
85
86 StreamMgr(const StreamMgr &) = delete;
87 StreamMgr &operator=(const StreamMgr &) = delete;
88
94 static std::shared_ptr<StreamMgr> getInstance();
95
103 std::scoped_lock lck(_devices_mtx);
105 for(const auto& dev: _devices) {
106 d2.push_back(dev->clone());
107 }
108 return d2;
109 }
110
121 void
122 rescanDAQDevices(bool background = false,
123 std::function<void()> callback = std::function<void()>());
124
130 void startStream(const DaqConfiguration &config);
131
139 bool isStreamRunningOK(const StreamType type) const {
140 return getStreamStatus(type).runningOK();
141 }
142 bool isStreamRunning(const StreamType type) const {
143 switch (type) {
144 case (StreamType::input):
145 return bool(_inputStream);
146 break;
147 case (StreamType::output):
148 return bool(_outputStream);
149 break;
150 }
151 return false;
152 }
153
162
171 const Daq *getDaq(StreamType type) const;
172
178 void stopStream(const StreamType stype);
179
184 void stopAllStreams();
185
194 void setSiggen(std::shared_ptr<Siggen> s);
195
196private:
197 void inCallback(const DaqData &data);
198 void outCallback(DaqData &data);
199
200
209 void addInDataHandler(InDataHandler *handler);
210
216 void removeInDataHandler(InDataHandler &handler);
222 void rescanDAQDevices_impl(std::function<void()> callback);
223
224#if LASP_DEBUG == 1
225 const std::thread::id main_thread_id;
226 void checkRightThread() const;
227#else
228 void checkRightThread() const {}
229#endif
230};
231
Information regarding a stream.
Definition lasp_daq.h:39
bool runningOK() const
Returns true if everything is OK with a certain stream and the stream is running.
Definition lasp_daq.h:82
Configuration of a DAQ device.
Data coming from / going to DAQ. Non-interleaved format, which means data in buffer is ordered by cha...
Base cass for all DAQ (Data Acquisition) interfaces. A DAQ can be a custom device,...
Definition lasp_daq.h:29
Simple wrapper around BS::thread_pool that makes a BS::thread_pool a singleton, such that a thread po...
Definition lasp_thread.h:10
A set of Biquad filters in series.
Signal generation abstract base class. Implementation is required for resetImpl(),...
Definition lasp_siggen.h:23
Stream manager. Used to manage the input and output streams. Implemented as a singleton: only one str...
static std::shared_ptr< StreamMgr > getInstance()
Get access to stream manager instance.
Daq::StreamStatus getStreamStatus(const StreamType type) const
Get the streamstatus object corresponding to a given stream.
DeviceInfoList getDeviceInfo() const
Obtain a list of devices currently available. When the StreamMgr is first created,...
void rescanDAQDevices(bool background=false, std::function< void()> callback=std::function< void()>())
Triggers a background scan of the DAQ devices, which updates the internally stored list of devices....
void startStream(const DaqConfiguration &config)
Start a stream based on given configuration.
const Daq * getDaq(StreamType type) const
Get DAQ pointer for a given stream. Gives a nullptr if stream is not running.
bool isStreamRunning(const StreamType type) const
StreamMgr & operator=(const StreamMgr &)=delete
StreamMgr(const StreamMgr &)=delete
void setSiggen(std::shared_ptr< Siggen > s)
Set active signal generator for output streams. Only one ‘Siggen’ is active at the same time....
void stopAllStreams()
Stop and delete all streams. Also called on destruction of the StreamMgr.
@ output
Output stream.
@ input
Input stream.
void stopStream(const StreamType stype)
Stop stream of given type (input / output/ duplex);.
bool isStreamRunningOK(const StreamType type) const
Check if a certain stream is running. If running with no errors, it returns true. If an error occured...
std::vector< std::unique_ptr< DeviceInfo > > DeviceInfoList
std::scoped_lock< std::mutex > lck
size_t us
We often use boolean values.
Definition lasp_types.h:29