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.
fileinput.h
Go to the documentation of this file.
1 // Copyright (C) 2015-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_FILEINPUT_H
19 #define INCLUDE_FILEINPUT_H
20 
21 #include <ctime>
22 #include <iostream>
23 #include <fstream>
24 
25 #include <QString>
26 #include <QByteArray>
27 #include <QTimer>
28 #include <QNetworkRequest>
29 
30 #include "dsp/devicesamplesource.h"
31 #include "fileinputsettings.h"
32 
33 class QNetworkAccessManager;
34 class QNetworkReply;
35 class FileInputThread;
36 class DeviceAPI;
37 
38 class FileInput : public DeviceSampleSource {
39  Q_OBJECT
40 public:
41  class MsgConfigureFileInput : public Message {
43 
44  public:
45  const FileInputSettings& getSettings() const { return m_settings; }
46  bool getForce() const { return m_force; }
47 
48  static MsgConfigureFileInput* create(const FileInputSettings& settings, bool force)
49  {
50  return new MsgConfigureFileInput(settings, force);
51  }
52 
53  private:
55  bool m_force;
56 
57  MsgConfigureFileInput(const FileInputSettings& settings, bool force) :
58  Message(),
59  m_settings(settings),
60  m_force(force)
61  { }
62  };
63 
66 
67  public:
68  const QString& getFileName() const { return m_fileName; }
69 
70  static MsgConfigureFileSourceName* create(const QString& fileName)
71  {
72  return new MsgConfigureFileSourceName(fileName);
73  }
74 
75  private:
76  QString m_fileName;
77 
78  MsgConfigureFileSourceName(const QString& fileName) :
79  Message(),
80  m_fileName(fileName)
81  { }
82  };
83 
86 
87  public:
88  bool isWorking() const { return m_working; }
89 
90  static MsgConfigureFileInputWork* create(bool working)
91  {
92  return new MsgConfigureFileInputWork(working);
93  }
94 
95  private:
96  bool m_working;
97 
98  MsgConfigureFileInputWork(bool working) :
99  Message(),
100  m_working(working)
101  { }
102  };
103 
106 
107  public:
108 
110  {
112  }
113 
114  private:
115 
117  Message()
118  { }
119  };
120 
123 
124  public:
125  int getMillis() const { return m_seekMillis; }
126 
127  static MsgConfigureFileSourceSeek* create(int seekMillis)
128  {
129  return new MsgConfigureFileSourceSeek(seekMillis);
130  }
131 
132  protected:
134 
135  MsgConfigureFileSourceSeek(int seekMillis) :
136  Message(),
137  m_seekMillis(seekMillis)
138  { }
139  };
140 
143 
144  public:
145  bool getAcquisition() const { return m_acquisition; }
146 
147  static MsgReportFileSourceAcquisition* create(bool acquisition)
148  {
149  return new MsgReportFileSourceAcquisition(acquisition);
150  }
151 
152  protected:
154 
155  MsgReportFileSourceAcquisition(bool acquisition) :
156  Message(),
157  m_acquisition(acquisition)
158  { }
159  };
160 
161  class MsgStartStop : public Message {
163 
164  public:
165  bool getStartStop() const { return m_startStop; }
166 
167  static MsgStartStop* create(bool startStop) {
168  return new MsgStartStop(startStop);
169  }
170 
171  protected:
173 
174  MsgStartStop(bool startStop) :
175  Message(),
176  m_startStop(startStop)
177  { }
178  };
179 
180  class MsgPlayPause : public Message {
182 
183  public:
184  bool getPlayPause() const { return m_playPause; }
185 
186  static MsgPlayPause* create(bool playPause) {
187  return new MsgPlayPause(playPause);
188  }
189 
190  protected:
192 
193  MsgPlayPause(bool playPause) :
194  Message(),
195  m_playPause(playPause)
196  { }
197  };
198 
201 
202  public:
203  int getSampleRate() const { return m_sampleRate; }
204  quint32 getSampleSize() const { return m_sampleSize; }
205  quint64 getCenterFrequency() const { return m_centerFrequency; }
206  quint64 getStartingTimeStamp() const { return m_startingTimeStamp; }
207  quint64 getRecordLength() const { return m_recordLength; }
208 
209  static MsgReportFileInputStreamData* create(int sampleRate,
210  quint32 sampleSize,
211  quint64 centerFrequency,
212  quint64 startingTimeStamp,
213  quint64 recordLength)
214  {
215  return new MsgReportFileInputStreamData(sampleRate, sampleSize, centerFrequency, startingTimeStamp, recordLength);
216  }
217 
218  protected:
220  quint32 m_sampleSize;
223  quint64 m_recordLength;
224 
226  quint32 sampleSize,
227  quint64 centerFrequency,
228  quint64 startingTimeStamp,
229  quint64 recordLength) :
230  Message(),
231  m_sampleRate(sampleRate),
232  m_sampleSize(sampleSize),
233  m_centerFrequency(centerFrequency),
234  m_startingTimeStamp(startingTimeStamp),
235  m_recordLength(recordLength)
236  { }
237  };
238 
241 
242  public:
243  quint64 getSamplesCount() const { return m_samplesCount; }
244 
245  static MsgReportFileInputStreamTiming* create(quint64 samplesCount)
246  {
247  return new MsgReportFileInputStreamTiming(samplesCount);
248  }
249 
250  protected:
251  quint64 m_samplesCount;
252 
253  MsgReportFileInputStreamTiming(quint64 samplesCount) :
254  Message(),
255  m_samplesCount(samplesCount)
256  { }
257  };
258 
259  class MsgReportHeaderCRC : public Message {
261 
262  public:
263  bool isOK() const { return m_ok; }
264 
265  static MsgReportHeaderCRC* create(bool ok) {
266  return new MsgReportHeaderCRC(ok);
267  }
268 
269  protected:
270  bool m_ok;
271 
273  Message(),
274  m_ok(ok)
275  { }
276  };
277 
278  FileInput(DeviceAPI *deviceAPI);
279  virtual ~FileInput();
280  virtual void destroy();
281 
282  virtual void init();
283  virtual bool start();
284  virtual void stop();
285 
286  virtual QByteArray serialize() const;
287  virtual bool deserialize(const QByteArray& data);
288 
289  virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; }
290  virtual const QString& getDeviceDescription() const;
291  virtual int getSampleRate() const;
292  virtual void setSampleRate(int sampleRate) { (void) sampleRate; }
293  virtual quint64 getCenterFrequency() const;
294  virtual void setCenterFrequency(qint64 centerFrequency);
295  quint64 getStartingTimeStamp() const;
296 
297  virtual bool handleMessage(const Message& message);
298 
299  virtual int webapiSettingsGet(
301  QString& errorMessage);
302 
303  virtual int webapiSettingsPutPatch(
304  bool force,
305  const QStringList& deviceSettingsKeys,
306  SWGSDRangel::SWGDeviceSettings& response, // query + response
307  QString& errorMessage);
308 
309  virtual int webapiRunGet(
310  SWGSDRangel::SWGDeviceState& response,
311  QString& errorMessage);
312 
313  virtual int webapiRun(
314  bool run,
315  SWGSDRangel::SWGDeviceState& response,
316  QString& errorMessage);
317 
318  virtual int webapiReportGet(
320  QString& errorMessage);
321 
322  private:
324  QMutex m_mutex;
326  std::ifstream m_ifstream;
329  QString m_fileName;
331  quint32 m_sampleSize;
333  quint64 m_recordLength;
336  QNetworkAccessManager *m_networkManager;
337  QNetworkRequest m_networkRequest;
338 
339  void openFileStream();
340  void seekFileStream(int seekMillis);
341  bool applySettings(const FileInputSettings& settings, bool force = false);
344  void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileInputSettings& settings, bool force);
345  void webapiReverseSendStartStop(bool start);
346 
347 private slots:
348  void networkManagerFinished(QNetworkReply *reply);
349 };
350 
351 #endif // INCLUDE_FILESOURCEINPUT_H
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const FileInputSettings &settings)
Definition: fileinput.cpp:543
FileInput(DeviceAPI *deviceAPI)
Definition: fileinput.cpp:52
virtual bool handleMessage(const Message &message)
Definition: fileinput.cpp:295
MsgReportFileSourceAcquisition(bool acquisition)
Definition: fileinput.h:155
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: fileinput.cpp:275
MsgConfigureFileSourceSeek(int seekMillis)
Definition: fileinput.h:135
MsgReportFileInputStreamTiming(quint64 samplesCount)
Definition: fileinput.h:253
virtual bool deserialize(const QByteArray &data)
Definition: fileinput.cpp:238
QString m_deviceDescription
Definition: fileinput.h:328
std::ifstream m_ifstream
Definition: fileinput.h:326
DeviceAPI * m_deviceAPI
Definition: fileinput.h:323
virtual quint64 getCenterFrequency() const
Center frequency exposed by the source.
Definition: fileinput.cpp:270
static MsgConfigureFileInputStreamTiming * create()
Definition: fileinput.h:109
MsgReportFileInputStreamData(int sampleRate, quint32 sampleSize, quint64 centerFrequency, quint64 startingTimeStamp, quint64 recordLength)
Definition: fileinput.h:225
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: fileinput.cpp:513
virtual void setSampleRate(int sampleRate)
For when the source sample rate is set externally.
Definition: fileinput.h:292
MsgPlayPause(bool playPause)
Definition: fileinput.h:193
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport &response)
Definition: fileinput.cpp:561
QTimer m_masterTimer
Definition: fileinput.h:335
void openFileStream()
Definition: fileinput.cpp:88
virtual bool start()
Definition: fileinput.cpp:176
const QString & getFileName() const
Definition: fileinput.h:68
static MsgConfigureFileInputWork * create(bool working)
Definition: fileinput.h:90
static MsgReportFileInputStreamTiming * create(quint64 samplesCount)
Definition: fileinput.h:245
void webapiReverseSendStartStop(bool start)
Definition: fileinput.cpp:636
quint64 m_startingTimeStamp
Definition: fileinput.h:334
FileInputSettings m_settings
Definition: fileinput.h:54
virtual void destroy()
Definition: fileinput.cpp:83
static MsgConfigureFileInput * create(const FileInputSettings &settings, bool force)
Definition: fileinput.h:48
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
virtual ~FileInput()
Definition: fileinput.cpp:74
MsgConfigureFileSourceName(const QString &fileName)
Definition: fileinput.h:78
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
Definition: fileinput.cpp:504
static MsgConfigureFileSourceName * create(const QString &fileName)
Definition: fileinput.h:70
static MsgPlayPause * create(bool playPause)
Definition: fileinput.h:186
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
virtual void stop()
Definition: fileinput.cpp:213
virtual const QString & getDeviceDescription() const
Definition: fileinput.cpp:260
virtual int getSampleRate() const
Sample rate exposed by the source.
Definition: fileinput.cpp:265
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: fileinput.cpp:449
const FileInputSettings & getSettings() const
Definition: fileinput.h:45
static MsgReportHeaderCRC * create(bool ok)
Definition: fileinput.h:265
bool getStartStop() const
Definition: fileinput.h:165
int m_sampleRate
Definition: fileinput.h:330
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
Definition: fileinput.cpp:460
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
Definition: fileinput.cpp:170
FileInputSettings m_settings
Definition: fileinput.h:325
virtual QByteArray serialize() const
Definition: fileinput.cpp:233
MsgConfigureFileInput(const FileInputSettings &settings, bool force)
Definition: fileinput.h:57
QMutex m_mutex
Definition: fileinput.h:324
virtual int webapiReportGet(SWGSDRangel::SWGDeviceReport &response, QString &errorMessage)
Definition: fileinput.cpp:532
FileInputThread * m_fileInputThread
Definition: fileinput.h:327
QNetworkRequest m_networkRequest
Definition: fileinput.h:337
void seekFileStream(int seekMillis)
Definition: fileinput.cpp:156
MsgStartStop(bool startStop)
Definition: fileinput.h:174
quint64 m_centerFrequency
Definition: fileinput.h:332
quint64 getStartingTimeStamp() const
Definition: fileinput.cpp:290
quint64 m_recordLength
record length in seconds computed from file size
Definition: fileinput.h:333
static MsgConfigureFileSourceSeek * create(int seekMillis)
Definition: fileinput.h:127
quint32 m_sampleSize
Definition: fileinput.h:331
void networkManagerFinished(QNetworkReply *reply)
Definition: fileinput.cpp:664
static MsgReportFileSourceAcquisition * create(bool acquisition)
Definition: fileinput.h:147
bool getPlayPause() const
Definition: fileinput.h:184
static MsgReportFileInputStreamData * create(int sampleRate, quint32 sampleSize, quint64 centerFrequency, quint64 startingTimeStamp, quint64 recordLength)
Definition: fileinput.h:209
QString m_fileName
Definition: fileinput.h:329
virtual void setMessageQueueToGUI(MessageQueue *queue)
Definition: fileinput.h:289
int m_seekMillis
millis of seek position from the beginning 0..1000
Definition: fileinput.h:133
bool applySettings(const FileInputSettings &settings, bool force=false)
Definition: fileinput.cpp:406
static MsgStartStop * create(bool startStop)
Definition: fileinput.h:167
QNetworkAccessManager * m_networkManager
Definition: fileinput.h:336
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const FileInputSettings &settings, bool force)
Definition: fileinput.cpp:597