SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
dspdevicesinkengine.h
Go to the documentation of this file.
1 // Copyright (C) 2016 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef SDRBASE_DSP_DSPDEVICESINKENGINE_H_
20 #define SDRBASE_DSP_DSPDEVICESINKENGINE_H_
21 
22 #include <QThread>
23 #include <QTimer>
24 #include <QMutex>
25 #include <QWaitCondition>
26 #include <stdint.h>
27 #include <list>
28 #include <map>
29 #include "dsp/dsptypes.h"
30 #include "dsp/fftwindow.h"
31 #include "util/messagequeue.h"
32 #include "util/syncmessenger.h"
33 #include "export.h"
34 
35 class DeviceSampleSink;
38 class BasebandSampleSink;
39 
40 class SDRBASE_API DSPDeviceSinkEngine : public QThread {
41  Q_OBJECT
42 
43 public:
44  enum State {
49  StError
50  };
51 
52  DSPDeviceSinkEngine(uint32_t uid, QObject* parent = NULL);
54 
55  uint32_t getUID() const { return m_uid; }
56 
57  MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; }
58 
59  void start();
60  void stop();
61 
62  bool initGeneration();
63  bool startGeneration();
64  void stopGeneration();
65 
66  void setSink(DeviceSampleSink* sink);
67  DeviceSampleSink *getSink() { return m_deviceSampleSink; }
68  void setSinkSequence(int sequence);
69 
70  void addThreadedSource(ThreadedBasebandSampleSource* source);
71  void removeThreadedSource(ThreadedBasebandSampleSource* source);
72 
73  void addSpectrumSink(BasebandSampleSink* spectrumSink);
74  void removeSpectrumSink(BasebandSampleSink* spectrumSink);
75 
76  State state() const { return m_state; }
77 
78  QString errorMessage();
79  QString sinkDeviceDescription();
80 
81 private:
83 
84  MessageQueue m_inputMessageQueue; //<! Input message queue. Post here.
86 
88 
89  QString m_errorMessage;
91 
94 
95  typedef std::list<BasebandSampleSource*> BasebandSampleSources;
96  BasebandSampleSources m_basebandSampleSources;
97 
98  typedef std::list<ThreadedBasebandSampleSource*> ThreadedBasebandSampleSources;
99  ThreadedBasebandSampleSources m_threadedBasebandSampleSources;
100 
101  typedef std::map<BasebandSampleSource*, SampleVector::iterator> BasebandSampleSourcesIteratorMap;
102  typedef std::pair<BasebandSampleSource*, SampleVector::iterator> BasebandSampleSourcesIteratorMapKV;
103  BasebandSampleSourcesIteratorMap m_basebandSampleSourcesIteratorMap;
104 
105  typedef std::map<ThreadedBasebandSampleSource*, SampleVector::iterator> ThreadedBasebandSampleSourcesIteratorMap;
106  typedef std::pair<ThreadedBasebandSampleSource*, SampleVector::iterator> ThreadedBasebandSampleSourcesIteratorMapKV;
107  ThreadedBasebandSampleSourcesIteratorMap m_threadedBasebandSampleSourcesIteratorMap;
108 
110 
114 
115  void run();
116  void work(int nbWriteSamples);
117 
118  State gotoIdle();
119  State gotoInit();
120  State gotoRunning();
121  State gotoError(const QString& errorMsg);
122 
123  void handleSetSink(DeviceSampleSink* sink);
124  void checkNumberOfBasebandSources();
125 
126 private slots:
127  void handleData(int nbSamples);
128  void handleInputMessages();
129  void handleSynchronousMessages();
130  void handleForwardToSpectrumSink(int nbSamples);
131 };
132 
133 
134 
135 
136 
137 #endif /* SDRBASE_DSP_DSPDEVICESINKENGINE_H_ */
DeviceSampleSink * getSink()
engine is before initialization
engine is ready to run
State state() const
Return DSP engine current state.
DeviceSampleSink * m_deviceSampleSink
BasebandSampleSink * m_spectrumSink
std::pair< BasebandSampleSource *, SampleVector::iterator > BasebandSampleSourcesIteratorMapKV
BasebandSampleSourcesIteratorMap m_basebandSampleSourcesIteratorMap
unsigned int uint32_t
Definition: rtptypes_win.h:46
ThreadedBasebandSampleSourcesIteratorMap m_threadedBasebandSampleSourcesIteratorMap
std::map< BasebandSampleSource *, SampleVector::iterator > BasebandSampleSourcesIteratorMap
std::list< ThreadedBasebandSampleSource * > ThreadedBasebandSampleSources
BasebandSampleSources m_basebandSampleSources
baseband sample sources within main thread (usually file input)
SyncMessenger m_syncMessenger
Used to process messages synchronously with the thread.
uint32_t getUID() const
MessageQueue m_inputMessageQueue
MessageQueue * getInputMessageQueue()
uint32_t m_uid
unique ID
uint32_t m_multipleSourcesDivisionFactor
std::map< ThreadedBasebandSampleSource *, SampleVector::iterator > ThreadedBasebandSampleSourcesIteratorMap
std::pair< ThreadedBasebandSampleSource *, SampleVector::iterator > ThreadedBasebandSampleSourcesIteratorMapKV
std::list< BasebandSampleSource * > BasebandSampleSources
#define SDRBASE_API
Definition: export.h:40
ThreadedBasebandSampleSources m_threadedBasebandSampleSources
baseband sample sources on their own threads (usually channels)