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.
threadedbasebandsamplesink.cpp
Go to the documentation of this file.
2 
3 #include <QThread>
4 #include <QDebug>
5 #include "dsp/dspcommands.h"
6 #include "util/message.h"
7 
9  m_sampleSink(sampleSink)
10 {
11  connect(&m_sampleFifo, SIGNAL(dataReady()), this, SLOT(handleFifoData()));
12  m_sampleFifo.setSize(size);
13 }
14 
16 {
18 }
19 
20 void ThreadedBasebandSampleSinkFifo::writeToFifo(SampleVector::const_iterator& begin, SampleVector::const_iterator& end)
21 {
22  m_sampleFifo.write(begin, end);
23 }
24 
25 void ThreadedBasebandSampleSinkFifo::handleFifoData() // FIXME: Fixed? Move it to the new threadable sink class
26 {
27  bool positiveOnly = false;
28 
29  while ((m_sampleFifo.fill() > 0) && (m_sampleSink->getInputMessageQueue()->size() == 0))
30  {
31  SampleVector::iterator part1begin;
32  SampleVector::iterator part1end;
33  SampleVector::iterator part2begin;
34  SampleVector::iterator part2end;
35 
36  std::size_t count = m_sampleFifo.readBegin(m_sampleFifo.fill(), &part1begin, &part1end, &part2begin, &part2end);
37 
38  // first part of FIFO data
39 
40  if (count > 0)
41  {
42  // handle data
43  if(m_sampleSink != NULL)
44  {
45  m_sampleSink->feed(part1begin, part1end, positiveOnly);
46  }
47 
48  m_sampleFifo.readCommit(part1end - part1begin);
49  }
50 
51  // second part of FIFO data (used when block wraps around)
52 
53  if(part2begin != part2end)
54  {
55  // handle data
56  if(m_sampleSink != NULL)
57  {
58  m_sampleSink->feed(part2begin, part2end, positiveOnly);
59  }
60 
61  m_sampleFifo.readCommit(part2end - part2begin);
62  }
63  }
64 }
65 
67  m_basebandSampleSink(sampleSink)
68 {
69  QString name = "ThreadedBasebandSampleSink(" + m_basebandSampleSink->objectName() + ")";
70  setObjectName(name);
71 
72  qDebug() << "ThreadedBasebandSampleSink::ThreadedBasebandSampleSink: " << name;
73 
74  m_thread = new QThread(parent);
76  //moveToThread(m_thread); // FIXME: Fixed? the intermediate FIFO should be handled within the sink. Define a new type of sink that is compatible with threading
77  m_basebandSampleSink->moveToThread(m_thread);
81  delete msg;
82  //m_sampleFifo.moveToThread(m_thread);
83  //connect(&m_sampleFifo, SIGNAL(dataReady()), this, SLOT(handleData()));
84  //m_sampleFifo.setSize(262144);
85 
86  qDebug() << "ThreadedBasebandSampleSink::ThreadedBasebandSampleSink: thread: " << thread() << " m_thread: " << m_thread;
87 }
88 
90 {
91  if (m_thread->isRunning()) {
92  stop();
93  }
94 
95  delete m_threadedBasebandSampleSinkFifo; // Valgrind memcheck
96  delete m_thread;
97 }
98 
100 {
101  qDebug() << "ThreadedBasebandSampleSink::start";
102  m_thread->start();
104 }
105 
107 {
108  qDebug() << "ThreadedBasebandSampleSink::stop";
110  m_thread->exit();
111  m_thread->wait();
112 }
113 
114 void ThreadedBasebandSampleSink::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
115 {
116  (void) positiveOnly;
117  //m_sampleSink->feed(begin, end, positiveOnly);
118  //m_sampleFifo.write(begin, end);
120 }
121 
123 {
124  return m_basebandSampleSink->handleMessage(cmd);
125 }
126 
128 {
129  return m_basebandSampleSink->objectName();
130 }
QThread * m_thread
The thead object.
int size()
Returns queue size.
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
bool handleSinkMessage(const Message &cmd)
Send message to sink synchronously.
uint write(const quint8 *data, uint count)
void start()
this thread start()
ThreadedBasebandSampleSinkFifo * m_threadedBasebandSampleSinkFifo
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)=0
ThreadedBasebandSampleSinkFifo(BasebandSampleSink *sampleSink, std::size_t size=1<< 18)
uint readCommit(uint count)
ThreadedBasebandSampleSink(BasebandSampleSink *sampleSink, QObject *parent=0)
bool setSize(int size)
BasebandSampleSink * m_basebandSampleSink
virtual void start()=0
virtual bool handleMessage(const Message &cmd)=0
Processing of a message. Returns true if message has actually been processed.
void writeToFifo(SampleVector::const_iterator &begin, SampleVector::const_iterator &end)
void stop()
this thread exit() and wait()
static MsgThreadedSink * create(const QThread *thread)
virtual void stop()=0
uint readBegin(uint count, SampleVector::iterator *part1Begin, SampleVector::iterator *part1End, SampleVector::iterator *part2Begin, SampleVector::iterator *part2End)
void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
Feed sink with samples.