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.
Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
SampleSinkFifo Class Reference

#include <samplesinkfifo.h>

Inherits QObject.

Signals

void dataReady ()
 

Public Member Functions

 SampleSinkFifo (QObject *parent=nullptr)
 
 SampleSinkFifo (int size, QObject *parent=nullptr)
 
 SampleSinkFifo (const SampleSinkFifo &other)
 
 ~SampleSinkFifo ()
 
bool setSize (int size)
 
uint size () const
 
uint fill ()
 
uint write (const quint8 *data, uint count)
 
uint write (SampleVector::const_iterator begin, SampleVector::const_iterator end)
 
uint read (SampleVector::iterator begin, SampleVector::iterator end)
 
uint readBegin (uint count, SampleVector::iterator *part1Begin, SampleVector::iterator *part1End, SampleVector::iterator *part2Begin, SampleVector::iterator *part2End)
 
uint readCommit (uint count)
 

Private Member Functions

void create (uint s)
 

Private Attributes

QMutex m_mutex
 
QTime m_msgRateTimer
 
int m_suppressed
 
SampleVector m_data
 
uint m_size
 
uint m_fill
 
uint m_head
 
uint m_tail
 

Detailed Description

Definition at line 28 of file samplesinkfifo.h.

Constructor & Destructor Documentation

◆ SampleSinkFifo() [1/3]

SampleSinkFifo::SampleSinkFifo ( QObject *  parent = nullptr)

Definition at line 37 of file samplesinkfifo.cpp.

References m_fill, m_head, m_size, m_suppressed, and m_tail.

37  :
38  QObject(parent),
39  m_data()
40 {
41  m_suppressed = -1;
42  m_size = 0;
43  m_fill = 0;
44  m_head = 0;
45  m_tail = 0;
46 }
SampleVector m_data

◆ SampleSinkFifo() [2/3]

SampleSinkFifo::SampleSinkFifo ( int  size,
QObject *  parent = nullptr 
)

Definition at line 48 of file samplesinkfifo.cpp.

References create(), and m_suppressed.

48  :
49  QObject(parent),
50  m_data()
51 {
52  m_suppressed = -1;
53 
54  create(size);
55 }
SampleVector m_data
uint size() const
void create(uint s)
+ Here is the call graph for this function:

◆ SampleSinkFifo() [3/3]

SampleSinkFifo::SampleSinkFifo ( const SampleSinkFifo other)

Definition at line 57 of file samplesinkfifo.cpp.

References m_data, m_fill, m_head, m_size, m_suppressed, and m_tail.

57  :
58  QObject(other.parent()),
59  m_data(other.m_data)
60 {
61  m_suppressed = -1;
62  m_size = m_data.size();
63  m_fill = 0;
64  m_head = 0;
65  m_tail = 0;
66 }
SampleVector m_data

◆ ~SampleSinkFifo()

SampleSinkFifo::~SampleSinkFifo ( )

Definition at line 68 of file samplesinkfifo.cpp.

References m_mutex, and m_size.

69 {
70  QMutexLocker mutexLocker(&m_mutex);
71 
72  m_size = 0;
73 }

Member Function Documentation

◆ create()

void SampleSinkFifo::create ( uint  s)
private

Definition at line 23 of file samplesinkfifo.cpp.

References m_data, m_fill, m_head, m_size, and m_tail.

Referenced by SampleSinkFifo(), and setSize().

24 {
25  m_size = 0;
26  m_fill = 0;
27  m_head = 0;
28  m_tail = 0;
29 
30  m_data.resize(s);
31  m_size = m_data.size();
32 
33  if(m_size != s)
34  qCritical("SampleSinkFifo: out of memory");
35 }
SampleVector m_data
+ Here is the caller graph for this function:

◆ dataReady

void SampleSinkFifo::dataReady ( )
signal

Referenced by DSPDeviceMIMOEngine::handleSetMIMO(), and write().

+ Here is the caller graph for this function:

◆ fill()

uint SampleSinkFifo::fill ( )
inline

Definition at line 53 of file samplesinkfifo.h.

References fill().

Referenced by fill(), ThreadedBasebandSampleSinkFifo::handleFifoData(), DSPDeviceSourceEngine::work(), DSPDeviceMIMOEngine::work(), DSPDeviceMIMOEngine::workSampleSink(), and ThreadedBasebandSampleSinkFifo::~ThreadedBasebandSampleSinkFifo().

53 { QMutexLocker mutexLocker(&m_mutex); uint fill = m_fill; return fill; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

uint SampleSinkFifo::read ( SampleVector::iterator  begin,
SampleVector::iterator  end 
)

Definition at line 167 of file samplesinkfifo.cpp.

References m_data, m_fill, m_head, m_mutex, m_size, and MIN.

168 {
169  QMutexLocker mutexLocker(&m_mutex);
170  uint count = end - begin;
171  uint total;
172  uint remaining;
173  uint len;
174 
175  total = MIN(count, m_fill);
176  if(total < count)
177  qCritical("SampleSinkFifo: underflow - missing %u samples", count - total);
178 
179  remaining = total;
180  while(remaining > 0) {
181  len = MIN(remaining, m_size - m_head);
182  std::copy(m_data.begin() + m_head, m_data.begin() + m_head + len, begin);
183  m_head += len;
184  m_head %= m_size;
185  m_fill -= len;
186  begin += len;
187  remaining -= len;
188  }
189 
190  return total;
191 }
SampleVector m_data
#define MIN(x, y)

◆ readBegin()

uint SampleSinkFifo::readBegin ( uint  count,
SampleVector::iterator *  part1Begin,
SampleVector::iterator *  part1End,
SampleVector::iterator *  part2Begin,
SampleVector::iterator *  part2End 
)

Definition at line 193 of file samplesinkfifo.cpp.

References m_data, m_fill, m_head, m_mutex, m_size, and MIN.

Referenced by ThreadedBasebandSampleSinkFifo::handleFifoData(), DSPDeviceSourceEngine::work(), DSPDeviceMIMOEngine::work(), and DSPDeviceMIMOEngine::workSampleSink().

196 {
197  QMutexLocker mutexLocker(&m_mutex);
198  uint total;
199  uint remaining;
200  uint len;
201  uint head = m_head;
202 
203  total = MIN(count, m_fill);
204  if(total < count)
205  qCritical("SampleSinkFifo: underflow - missing %u samples", count - total);
206 
207  remaining = total;
208  if(remaining > 0) {
209  len = MIN(remaining, m_size - head);
210  *part1Begin = m_data.begin() + head;
211  *part1End = m_data.begin() + head + len;
212  head += len;
213  head %= m_size;
214  remaining -= len;
215  } else {
216  *part1Begin = m_data.end();
217  *part1End = m_data.end();
218  }
219  if(remaining > 0) {
220  len = MIN(remaining, m_size - head);
221  *part2Begin = m_data.begin() + head;
222  *part2End = m_data.begin() + head + len;
223  } else {
224  *part2Begin = m_data.end();
225  *part2End = m_data.end();
226  }
227 
228  return total;
229 }
SampleVector m_data
#define MIN(x, y)
+ Here is the caller graph for this function:

◆ readCommit()

uint SampleSinkFifo::readCommit ( uint  count)

Definition at line 231 of file samplesinkfifo.cpp.

References m_fill, m_head, m_mutex, and m_size.

Referenced by ThreadedBasebandSampleSinkFifo::handleFifoData(), DSPDeviceSourceEngine::work(), DSPDeviceMIMOEngine::work(), DSPDeviceMIMOEngine::workSampleSink(), and ThreadedBasebandSampleSinkFifo::~ThreadedBasebandSampleSinkFifo().

232 {
233  QMutexLocker mutexLocker(&m_mutex);
234 
235  if(count > m_fill) {
236  qCritical("SampleSinkFifo: cannot commit more than available samples");
237  count = m_fill;
238  }
239  m_head = (m_head + count) % m_size;
240  m_fill -= count;
241 
242  return count;
243 }
+ Here is the caller graph for this function:

◆ setSize()

bool SampleSinkFifo::setSize ( int  size)

◆ size()

uint SampleSinkFifo::size ( ) const
inline

Definition at line 52 of file samplesinkfifo.h.

52 { return m_size; }

◆ write() [1/2]

uint SampleSinkFifo::write ( const quint8 *  data,
uint  count 
)

Definition at line 82 of file samplesinkfifo.cpp.

References dataReady(), m_data, m_fill, m_msgRateTimer, m_mutex, m_size, m_suppressed, m_tail, and MIN.

Referenced by Bladerf1InputThread::callback(), RTLSDRThread::callback(), SDRPlayThread::callback(), AirspyHFThread::callback(), PerseusThread::callback(), HackRFInputThread::callback(), AirspyThread::callback(), LimeSDRInputThread::callback(), TestMIThread::callback(), TestSourceThread::callback(), XTRXInputThread::callbackSI(), BladeRF2InputThread::callbackSI(), SoapySDRInputThread::callbackSI12(), SoapySDRInputThread::callbackSI16(), SoapySDRInputThread::callbackSI8(), SoapySDRInputThread::callbackSIF(), PlutoSDRInputThread::convert(), KiwiSDRWorker::onBinaryMessageReceived(), LocalSinkThread::processSamples(), RemoteInputUDPHandler::tick(), FCDProThread::work(), FCDProPlusThread::work(), ThreadedBasebandSampleSinkFifo::writeToFifo(), and FileInputThread::writeToSampleFifo().

83 {
84  QMutexLocker mutexLocker(&m_mutex);
85  uint total;
86  uint remaining;
87  uint len;
88  const Sample* begin = (const Sample*)data;
89  count /= sizeof(Sample);
90 
91  total = MIN(count, m_size - m_fill);
92  if(total < count) {
93  if(m_suppressed < 0) {
94  m_suppressed = 0;
95  m_msgRateTimer.start();
96  qCritical("SampleSinkFifo: overflow - dropping %u samples", count - total);
97  } else {
98  if(m_msgRateTimer.elapsed() > 2500) {
99  qCritical("SampleSinkFifo: %u messages dropped", m_suppressed);
100  qCritical("SampleSinkFifo: overflow - dropping %u samples", count - total);
101  m_suppressed = -1;
102  } else {
103  m_suppressed++;
104  }
105  }
106  }
107 
108  remaining = total;
109  while(remaining > 0) {
110  len = MIN(remaining, m_size - m_tail);
111  std::copy(begin, begin + len, m_data.begin() + m_tail);
112  m_tail += len;
113  m_tail %= m_size;
114  m_fill += len;
115  begin += len;
116  remaining -= len;
117  }
118 
119  if(m_fill > 0)
120  emit dataReady();
121 
122  return total;
123 }
SampleVector m_data
#define MIN(x, y)
+ Here is the caller graph for this function:

◆ write() [2/2]

uint SampleSinkFifo::write ( SampleVector::const_iterator  begin,
SampleVector::const_iterator  end 
)

Definition at line 125 of file samplesinkfifo.cpp.

References dataReady(), m_data, m_fill, m_msgRateTimer, m_mutex, m_size, m_suppressed, m_tail, and MIN.

126 {
127  QMutexLocker mutexLocker(&m_mutex);
128  uint count = end - begin;
129  uint total;
130  uint remaining;
131  uint len;
132 
133  total = MIN(count, m_size - m_fill);
134  if(total < count) {
135  if(m_suppressed < 0) {
136  m_suppressed = 0;
137  m_msgRateTimer.start();
138  qCritical("SampleSinkFifo: overflow - dropping %u samples", count - total);
139  } else {
140  if(m_msgRateTimer.elapsed() > 2500) {
141  qCritical("SampleSinkFifo: %u messages dropped", m_suppressed);
142  qCritical("SampleSinkFifo: overflow - dropping %u samples", count - total);
143  m_suppressed = -1;
144  } else {
145  m_suppressed++;
146  }
147  }
148  }
149 
150  remaining = total;
151  while(remaining > 0) {
152  len = MIN(remaining, m_size - m_tail);
153  std::copy(begin, begin + len, m_data.begin() + m_tail);
154  m_tail += len;
155  m_tail %= m_size;
156  m_fill += len;
157  begin += len;
158  remaining -= len;
159  }
160 
161  if(m_fill > 0)
162  emit dataReady();
163 
164  return total;
165 }
SampleVector m_data
#define MIN(x, y)

Member Data Documentation

◆ m_data

SampleVector SampleSinkFifo::m_data
private

Definition at line 36 of file samplesinkfifo.h.

Referenced by create(), read(), readBegin(), SampleSinkFifo(), setSize(), and write().

◆ m_fill

uint SampleSinkFifo::m_fill
private

Definition at line 39 of file samplesinkfifo.h.

Referenced by create(), read(), readBegin(), readCommit(), SampleSinkFifo(), and write().

◆ m_head

uint SampleSinkFifo::m_head
private

Definition at line 40 of file samplesinkfifo.h.

Referenced by create(), read(), readBegin(), readCommit(), and SampleSinkFifo().

◆ m_msgRateTimer

QTime SampleSinkFifo::m_msgRateTimer
private

Definition at line 33 of file samplesinkfifo.h.

Referenced by write().

◆ m_mutex

QMutex SampleSinkFifo::m_mutex
private

Definition at line 32 of file samplesinkfifo.h.

Referenced by read(), readBegin(), readCommit(), write(), and ~SampleSinkFifo().

◆ m_size

uint SampleSinkFifo::m_size
private

◆ m_suppressed

int SampleSinkFifo::m_suppressed
private

Definition at line 34 of file samplesinkfifo.h.

Referenced by SampleSinkFifo(), and write().

◆ m_tail

uint SampleSinkFifo::m_tail
private

Definition at line 41 of file samplesinkfifo.h.

Referenced by create(), SampleSinkFifo(), and write().


The documentation for this class was generated from the following files: