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.
remotedatareadqueue.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB. //
3 // //
4 // Remote sink channel (Rx) data blocks to read queue //
5 // //
6 // SDRangel can serve as a remote SDR front end that handles the interface //
7 // with a physical device and sends or receives the I/Q samples stream via UDP //
8 // to or from another SDRangel instance or any program implementing the same //
9 // protocol. The remote SDRangel is controlled via its Web REST API. //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation as version 3 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License V3 for more details. //
20 // //
21 // You should have received a copy of the GNU General Public License //
22 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
24 
27 
29 
31  m_dataBlock(0),
32  m_maxSize(MinimumMaxSize),
33  m_blockIndex(1),
34  m_sampleIndex(0),
35  m_sampleCount(0),
36  m_full(false)
37 {}
38 
40 {
41  RemoteDataBlock* data;
42 
43  while ((data = pop()) != 0)
44  {
45  qDebug("RemoteDataReadQueue::~RemoteDataReadQueue: data block was still in queue");
46  delete data;
47  }
48 }
49 
51 {
52  if (length() >= m_maxSize)
53  {
54  qWarning("RemoteDataReadQueue::push: queue is full");
55  m_full = true; // stop filling the queue
56  RemoteDataBlock *data = m_dataReadQueue.takeLast();
57  delete data;
58  }
59 
60  if (m_full) {
61  m_full = (length() > m_maxSize/2); // do not fill queue again before queue is half size
62  }
63 
64  if (!m_full) {
65  m_dataReadQueue.append(dataBlock);
66  }
67 }
68 
70 {
71  if (m_dataReadQueue.isEmpty())
72  {
73  return 0;
74  }
75  else
76  {
77  m_blockIndex = 1;
78  m_sampleIndex = 0;
79 
80  return m_dataReadQueue.takeFirst();
81  }
82 }
83 
85 {
86  if (size != m_maxSize) {
88  }
89 }
90 
91 void RemoteDataReadQueue::readSample(Sample& s, bool scaleForTx)
92 {
93  // depletion/repletion state
94  if (m_dataBlock == 0)
95  {
96  if (length() >= m_maxSize/2)
97  {
98  qDebug("RemoteDataReadQueue::readSample: initial pop new block: queue size: %u", length());
99  m_blockIndex = 1;
100  m_dataBlock = m_dataReadQueue.takeFirst();
102  m_sampleIndex++;
103  m_sampleCount++;
104  }
105  else
106  {
107  s = Sample{0, 0};
108  }
109 
110  return;
111  }
112 
114  uint32_t samplesPerBlock = RemoteNbBytesPerBlock / sampleSize;
115 
116  if (m_sampleIndex < samplesPerBlock)
117  {
119  m_sampleIndex++;
120  m_sampleCount++;
121  }
122  else
123  {
124  m_sampleIndex = 0;
125  m_blockIndex++;
126 
127  if (m_blockIndex < RemoteNbOrginalBlocks)
128  {
130  m_sampleIndex++;
131  m_sampleCount++;
132  }
133  else
134  {
135  delete m_dataBlock;
136  m_dataBlock = 0;
137 
138  if (length() == 0) {
139  qWarning("RemoteDataReadQueue::readSample: try to pop new block but queue is empty");
140  }
141 
142  if (length() > 0)
143  {
144  //qDebug("RemoteDataReadQueue::readSample: pop new block: queue size: %u", length());
145  m_blockIndex = 1;
146  m_dataBlock = m_dataReadQueue.takeFirst();
148  m_sampleIndex++;
149  m_sampleCount++;
150  }
151  else
152  {
153  s = Sample{0, 0};
154  }
155  }
156  }
157 }
158 
159 
160 
uint32_t size() const
Returns queue size (max length)
RemoteSuperBlock * m_superBlocks
uint32_t m_sampleCount
use a counter capped below 2^31 as it is going to be converted to an int in the web interface ...
void readSample(Sample &s, bool scaleForTx=false)
Read sample from queue possibly scaling to Tx size.
unsigned int uint32_t
Definition: rtptypes_win.h:46
bool m_full
full condition was hit
void setSize(uint32_t size)
Sets the queue size (max length)
uint8_t m_sampleBytes
number of bytes per sample (2 or 4) for this block
uint32_t length() const
Returns queue length.
RemoteHeader m_header
RemoteDataBlock * m_dataBlock
void convertDataToSample(Sample &s, uint32_t blockIndex, uint32_t sampleIndex, bool scaleForTx)
RemoteDataBlock * pop()
Pop block from the queue.
void push(RemoteDataBlock *dataBlock)
push block on the queue
QQueue< RemoteDataBlock * > m_dataReadQueue
static const uint32_t MinimumMaxSize