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.
localsink.h
Go to the documentation of this file.
1 // Copyright (C) 2019 Edouard Griffiths, F4EXB. //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #ifndef INCLUDE_LOCALSINK_H_
19 #define INCLUDE_LOCALSINK_H_
20 
21 #include <QObject>
22 #include <QMutex>
23 #include <QNetworkRequest>
24 
25 #include "dsp/basebandsamplesink.h"
26 #include "channel/channelapi.h"
27 #include "localsinksettings.h"
28 
29 class DeviceAPI;
30 class DeviceSampleSource;
32 class DownChannelizer;
33 class LocalSinkThread;
34 class QNetworkAccessManager;
35 class QNetworkReply;
36 
37 class LocalSink : public BasebandSampleSink, public ChannelAPI {
38  Q_OBJECT
39 public:
40  class MsgConfigureLocalSink : public Message {
42 
43  public:
44  const LocalSinkSettings& getSettings() const { return m_settings; }
45  bool getForce() const { return m_force; }
46 
47  static MsgConfigureLocalSink* create(const LocalSinkSettings& settings, bool force)
48  {
49  return new MsgConfigureLocalSink(settings, force);
50  }
51 
52  private:
54  bool m_force;
55 
56  MsgConfigureLocalSink(const LocalSinkSettings& settings, bool force) :
57  Message(),
58  m_settings(settings),
59  m_force(force)
60  { }
61  };
62 
65 
66  public:
67  static MsgSampleRateNotification* create(int sampleRate) {
68  return new MsgSampleRateNotification(sampleRate);
69  }
70 
71  int getSampleRate() const { return m_sampleRate; }
72 
73  private:
74 
75  MsgSampleRateNotification(int sampleRate) :
76  Message(),
77  m_sampleRate(sampleRate)
78  { }
79 
81  };
82 
85 
86  public:
87  int getLog2Decim() const { return m_log2Decim; }
88  int getFilterChainHash() const { return m_filterChainHash; }
89 
90  static MsgConfigureChannelizer* create(unsigned int log2Decim, unsigned int filterChainHash) {
91  return new MsgConfigureChannelizer(log2Decim, filterChainHash);
92  }
93 
94  private:
95  unsigned int m_log2Decim;
96  unsigned int m_filterChainHash;
97 
98  MsgConfigureChannelizer(unsigned int log2Decim, unsigned int filterChainHash) :
99  Message(),
100  m_log2Decim(log2Decim),
101  m_filterChainHash(filterChainHash)
102  { }
103  };
104 
105  LocalSink(DeviceAPI *deviceAPI);
106  virtual ~LocalSink();
107  virtual void destroy() { delete this; }
108 
109  virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
110  virtual void start();
111  virtual void stop();
112  virtual bool handleMessage(const Message& cmd);
113 
114  virtual void getIdentifier(QString& id) { id = objectName(); }
115  virtual void getTitle(QString& title) { title = "Local Sink"; }
116  virtual qint64 getCenterFrequency() const { return m_frequencyOffset; }
117 
118  virtual QByteArray serialize() const;
119  virtual bool deserialize(const QByteArray& data);
120 
121  virtual int getNbSinkStreams() const { return 1; }
122  virtual int getNbSourceStreams() const { return 0; }
123 
124  virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
125  {
126  (void) streamIndex;
127  (void) sinkElseSource;
128  return m_frequencyOffset;
129  }
130 
131  virtual int webapiSettingsGet(
133  QString& errorMessage);
134 
135  virtual int webapiSettingsPutPatch(
136  bool force,
137  const QStringList& channelSettingsKeys,
139  QString& errorMessage);
140 
142  void setCenterFrequency(uint64_t centerFrequency) { m_centerFrequency = centerFrequency; }
143 
145  void setSampleRate(uint32_t sampleRate) { m_sampleRate = sampleRate; }
146 
147  void setChannelizer(unsigned int log2Decim, unsigned int filterChainHash);
148  void getLocalDevices(std::vector<uint32_t>& indexes);
149 
150  static const QString m_channelIdURI;
151  static const QString m_channelId;
152 
153 signals:
154  void samplesAvailable(const quint8* data, uint count);
155 
156 private:
160  bool m_running;
161 
164 
169 
170  QNetworkAccessManager *m_networkManager;
171  QNetworkRequest m_networkRequest;
172 
173  void applySettings(const LocalSinkSettings& settings, bool force = false);
179  void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const LocalSinkSettings& settings, bool force);
180 
181 private slots:
182  void networkManagerFinished(QNetworkReply *reply);
183 };
184 
185 #endif /* INCLUDE_LOCALSINK_H_ */
int64_t m_frequencyOffset
Definition: localsink.h:166
void networkManagerFinished(QNetworkReply *reply)
Definition: localsink.cpp:488
MsgConfigureChannelizer(unsigned int log2Decim, unsigned int filterChainHash)
Definition: localsink.h:98
uint64_t m_centerFrequency
Definition: localsink.h:165
virtual qint64 getCenterFrequency() const
Applies to a default stream.
Definition: localsink.h:116
DeviceSampleSource * getLocalDevice(uint32_t index)
Definition: localsink.cpp:239
virtual QByteArray serialize() const
Definition: localsink.cpp:200
uint32_t m_sampleRate
Definition: localsink.h:167
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: localsink.cpp:350
const LocalSinkSettings & getSettings() const
Definition: localsink.h:44
DownChannelizer * m_channelizer
Definition: localsink.h:159
uint32_t m_deviceSampleRate
Definition: localsink.h:168
bool m_running
Definition: localsink.h:160
MsgConfigureLocalSink(const LocalSinkSettings &settings, bool force)
Definition: localsink.h:56
virtual int getNbSinkStreams() const
Definition: localsink.h:121
virtual void destroy()
Definition: localsink.h:107
void setCenterFrequency(uint64_t centerFrequency)
Definition: localsink.h:142
__int64 int64_t
Definition: rtptypes_win.h:47
void samplesAvailable(const quint8 *data, uint count)
MsgSampleRateNotification(int sampleRate)
Definition: localsink.h:75
virtual bool deserialize(const QByteArray &data)
Definition: localsink.cpp:205
unsigned int uint32_t
Definition: rtptypes_win.h:46
ThreadedBasebandSampleSink * m_threadedChannelizer
Definition: localsink.h:158
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const LocalSinkSettings &settings)
Definition: localsink.cpp:415
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Definition: localsink.cpp:339
void setSampleRate(uint32_t sampleRate)
Definition: localsink.h:145
void applySettings(const LocalSinkSettings &settings, bool force=false)
Definition: localsink.cpp:282
LocalSink(DeviceAPI *deviceAPI)
Definition: localsink.cpp:48
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual ~LocalSink()
Definition: localsink.cpp:69
static MsgSampleRateNotification * create(int sampleRate)
Definition: localsink.h:67
QNetworkRequest m_networkRequest
Definition: localsink.h:171
LocalSinkSettings m_settings
Definition: localsink.h:53
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
Definition: localsink.cpp:124
void propagateSampleRateAndFrequency(uint32_t index)
Definition: localsink.cpp:271
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const LocalSinkSettings &settings, bool force)
Definition: localsink.cpp:441
static MsgConfigureLocalSink * create(const LocalSinkSettings &settings, bool force)
Definition: localsink.h:47
virtual void start()
Definition: localsink.cpp:85
virtual void stop()
Definition: localsink.cpp:110
virtual int getNbSourceStreams() const
Definition: localsink.h:122
static const QString m_channelId
Definition: localsink.h:151
virtual void getTitle(QString &title)
Definition: localsink.h:115
DeviceAPI * m_deviceAPI
Definition: localsink.h:157
static MsgConfigureChannelizer * create(unsigned int log2Decim, unsigned int filterChainHash)
Definition: localsink.h:90
LocalSinkSettings m_settings
Definition: localsink.h:162
LocalSinkThread * m_sinkThread
Definition: localsink.h:163
virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const
Definition: localsink.h:124
static const QString m_channelIdURI
Definition: localsink.h:150
void validateFilterChainHash(LocalSinkSettings &settings)
Definition: localsink.cpp:322
QNetworkAccessManager * m_networkManager
Definition: localsink.h:170
void getLocalDevices(std::vector< uint32_t > &indexes)
Definition: localsink.cpp:223
void calculateFrequencyOffset()
Definition: localsink.cpp:333
virtual void getIdentifier(QString &id)
Definition: localsink.h:114
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool po)
Definition: localsink.cpp:79
void setChannelizer(unsigned int log2Decim, unsigned int filterChainHash)
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48