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.
fileinputthread.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_FILEINPUTTHREAD_H
19 #define INCLUDE_FILEINPUTTHREAD_H
20 
21 #include <QThread>
22 #include <QMutex>
23 #include <QWaitCondition>
24 #include <QTimer>
25 #include <QElapsedTimer>
26 #include <iostream>
27 #include <fstream>
28 #include <cstdlib>
29 
30 #include "dsp/inthalfbandfilter.h"
31 #include "util/message.h"
32 
33 #define FILESOURCE_THROTTLE_MS 50
34 
35 class SampleSinkFifo;
36 class MessageQueue;
37 
38 class FileInputThread : public QThread {
39  Q_OBJECT
40 
41 public:
42  class MsgReportEOF : public Message {
44 
45  public:
46  static MsgReportEOF* create() {
47  return new MsgReportEOF();
48  }
49 
50  private:
52  Message()
53  { }
54  };
55 
56  FileInputThread(std::ifstream *samplesStream,
57  SampleSinkFifo* sampleFifo,
58  const QTimer& timer,
59  MessageQueue *fileInputMessageQueue,
60  QObject* parent = NULL);
62 
63  void startWork();
64  void stopWork();
65  void setSampleRateAndSize(int samplerate, quint32 samplesize);
66  void setBuffers(std::size_t chunksize);
67  bool isRunning() const { return m_running; }
68  quint64 getSamplesCount() const { return m_samplesCount; }
69  void setSamplesCount(quint64 samplesCount) { m_samplesCount = samplesCount; }
70 
71 private:
73  QWaitCondition m_startWaiter;
74  volatile bool m_running;
75 
76  std::ifstream* m_ifstream;
77  quint8 *m_fileBuf;
78  quint8 *m_convertBuf;
79  std::size_t m_bufsize;
80  qint64 m_chunksize;
82  quint64 m_samplesCount;
83  const QTimer& m_timer;
85 
87  quint64 m_samplesize;
88  quint64 m_samplebytes;
89  qint64 m_throttlems;
90  QElapsedTimer m_elapsedTimer;
92 
93  void run();
94  //void decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len);
95  void writeToSampleFifo(const quint8* buf, qint32 nbBytes);
96 
97 private slots:
98  void tick();
99 };
100 
101 #endif // INCLUDE_FILEINPUTTHREAD_H
std::size_t m_bufsize
volatile bool m_running
QWaitCondition m_startWaiter
quint64 m_samplesize
File effective sample size in bits (I or Q). Ex: 16, 24.
void writeToSampleFifo(const quint8 *buf, qint32 nbBytes)
quint64 getSamplesCount() const
quint8 * m_convertBuf
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
const QTimer & m_timer
quint64 m_samplebytes
Number of bytes used to store a I or Q sample. Ex: 2. 4.
std::ifstream * m_ifstream
MessageQueue * m_fileInputMessageQueue
quint64 m_samplesCount
SampleSinkFifo * m_sampleFifo
bool isRunning() const
void setSampleRateAndSize(int samplerate, quint32 samplesize)
void setBuffers(std::size_t chunksize)
static MsgReportEOF * create()
QElapsedTimer m_elapsedTimer
FileInputThread(std::ifstream *samplesStream, SampleSinkFifo *sampleFifo, const QTimer &timer, MessageQueue *fileInputMessageQueue, QObject *parent=NULL)
void setSamplesCount(quint64 samplesCount)
int m_samplerate
File I/Q stream original sample rate.