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.
localsinkthread.cpp
Go to the documentation of this file.
1 // Copyright (C) 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 #include "dsp/samplesinkfifo.h"
19 
20 #include "localsinkthread.h"
21 
23 
24 LocalSinkThread::LocalSinkThread(QObject* parent) :
25  QThread(parent),
26  m_running(false),
27  m_sampleFifo(0)
28 {
29  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
30 }
31 
33 {
34  qDebug("LocalSinkThread::~LocalSinkThread");
35 }
36 
38 {
39  MsgStartStop *msg = MsgStartStop::create(start);
41 }
42 
44 {
45  qDebug("LocalSinkThread::startWork");
46  m_startWaitMutex.lock();
47  start();
48  while(!m_running)
49  m_startWaiter.wait(&m_startWaitMutex, 100);
50  m_startWaitMutex.unlock();
51 }
52 
54 {
55  qDebug("LocalSinkThread::stopWork");
56  m_running = false;
57  wait();
58 }
59 
61 {
62  qDebug("LocalSinkThread::run: begin");
63  m_running = true;
64  m_startWaiter.wakeAll();
65 
66  while (m_running)
67  {
68  sleep(1); // Do nothing as everything is in the data handler (dequeuer)
69  }
70 
71  m_running = false;
72  qDebug("LocalSinkThread::run: end");
73 }
74 
75 void LocalSinkThread::processSamples(const quint8* data, uint count)
76 {
77  if (m_sampleFifo) {
78  m_sampleFifo->write(data, count);
79  }
80 }
81 
83 {
84  Message* message;
85 
86  while ((message = m_inputMessageQueue.pop()) != 0)
87  {
88  if (MsgStartStop::match(*message))
89  {
90  MsgStartStop* notif = (MsgStartStop*) message;
91  qDebug("LocalSinkThread::handleInputMessages: MsgStartStop: %s", notif->getStartStop() ? "start" : "stop");
92 
93  if (notif->getStartStop()) {
94  startWork();
95  } else {
96  stopWork();
97  }
98 
99  delete message;
100  }
101  }
102 }
void processSamples(const quint8 *data, uint count)
Message * pop()
Pop message from queue.
void push(Message *message, bool emitSignal=true)
Push message onto queue.
SampleSinkFifo * m_sampleFifo
uint write(const quint8 *data, uint count)
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
Definition: message.h:52
QWaitCondition m_startWaiter
void startStop(bool start)
static MsgStartStop * create(bool startStop)
MessageQueue m_inputMessageQueue
static bool match(const Message *message)
Definition: message.cpp:45
volatile bool m_running