kopia lustrzana https://gitlab.com/eliggett/wfview
Moved audio to separate thread.
rodzic
89fe648868
commit
6fee18df9a
|
@ -0,0 +1,59 @@
|
||||||
|
#include "rxaudiohandler.h"
|
||||||
|
|
||||||
|
rxAudioHandler::rxAudioHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
rxAudioHandler::~rxAudioHandler()
|
||||||
|
{
|
||||||
|
audio->stop();
|
||||||
|
delete audio;
|
||||||
|
delete buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rxAudioHandler::process()
|
||||||
|
{
|
||||||
|
qDebug() << "rxAudio Handler created.";
|
||||||
|
}
|
||||||
|
|
||||||
|
void rxAudioHandler::setup(const QAudioFormat format, const int bufferSize)
|
||||||
|
{
|
||||||
|
this->format = format;
|
||||||
|
this->bufferSize = bufferSize;
|
||||||
|
buffer = new QBuffer();
|
||||||
|
buffer->open(QIODevice::ReadWrite);
|
||||||
|
audio = new QAudioOutput(format);
|
||||||
|
audio->setBufferSize(bufferSize);
|
||||||
|
buffer->seek(0);
|
||||||
|
audio->start(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void rxAudioHandler::incomingAudio(const QByteArray data, const int size)
|
||||||
|
{
|
||||||
|
buffer->buffer().remove(0,buffer->pos());
|
||||||
|
buffer->seek(buffer->size());
|
||||||
|
|
||||||
|
buffer->write(data.constData(), size);
|
||||||
|
buffer->seek(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rxAudioHandler::changeBufferSize(const int newSize)
|
||||||
|
{
|
||||||
|
// TODO: make a way to change the buffer size.
|
||||||
|
// possibly deleting the buffer and re-creating
|
||||||
|
|
||||||
|
audio->setBufferSize(newSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rxAudioHandler::getBufferSize()
|
||||||
|
{
|
||||||
|
emit sendBufferSize(buffer->size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void rxAudioHandler::getAudioBufferSize()
|
||||||
|
{
|
||||||
|
emit sendAudioBufferSize(audio->bufferSize());
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef RXAUDIOHANDLER_H
|
||||||
|
#define RXAUDIOHANDLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <QtMultimedia/QAudioOutput>
|
||||||
|
#include <QBuffer>
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class rxAudioHandler : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
rxAudioHandler();
|
||||||
|
~rxAudioHandler();
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void process();
|
||||||
|
void setup(const QAudioFormat format, const int bufferSize);
|
||||||
|
|
||||||
|
void incomingAudio(const QByteArray data, const int size);
|
||||||
|
void changeBufferSize(const int newSize);
|
||||||
|
void getBufferSize();
|
||||||
|
void getAudioBufferSize();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void audioMessage(QString message);
|
||||||
|
void sendBufferSize(int newSize);
|
||||||
|
void sendAudioBufferSize(int newSize);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QBuffer* buffer;
|
||||||
|
QAudioOutput* audio;
|
||||||
|
QAudioFormat format;
|
||||||
|
int bufferSize;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RXAUDIOHANDLER_H
|
|
@ -576,12 +576,15 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, int aport)
|
||||||
qDebug() << "----- done with audio info -----";
|
qDebug() << "----- done with audio info -----";
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new QBuffer();
|
rxaudio = new rxAudioHandler();
|
||||||
buffer->open(QIODevice::ReadWrite);
|
rxAudioThread = new QThread(this);
|
||||||
audio = new QAudioOutput(format);
|
|
||||||
audio->setBufferSize(10000); // TODO: add preference, maybe UI too. 20210205: connection was wifi --> cellular --> internet --> rig
|
rxaudio->moveToThread(rxAudioThread);
|
||||||
buffer->seek(0);
|
|
||||||
audio->start(buffer);
|
connect(this,SIGNAL(setupAudio(QAudioFormat,int)), rxaudio, SLOT(setup(QAudioFormat,int)));
|
||||||
|
connect(this, SIGNAL(haveAudioData(QByteArray,int)), rxaudio, SLOT(incomingAudio(QByteArray,int)));
|
||||||
|
|
||||||
|
rxaudio->setup(format, 10000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,6 +599,14 @@ udpAudio::~udpAudio()
|
||||||
{
|
{
|
||||||
delete buffer;
|
delete buffer;
|
||||||
}
|
}
|
||||||
|
if(rxaudio != Q_NULLPTR)
|
||||||
|
{
|
||||||
|
delete rxaudio;
|
||||||
|
}
|
||||||
|
if(rxAudioThread != Q_NULLPTR)
|
||||||
|
{
|
||||||
|
delete rxAudioThread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void udpAudio::DataReceived()
|
void udpAudio::DataReceived()
|
||||||
|
@ -638,15 +649,7 @@ void udpAudio::DataReceived()
|
||||||
|
|
||||||
lastReceivedSeq = gotSeq;
|
lastReceivedSeq = gotSeq;
|
||||||
|
|
||||||
//qDebug() << "Got Audio Sequence: (" << r.length() << ") " << gotSeq;
|
emit haveAudioData(r.mid(24), r.mid(24).length());
|
||||||
// Delete contents of buffer up to existing pos()
|
|
||||||
buffer->buffer().remove(0,buffer->pos());
|
|
||||||
// Seek to end of curent buffer
|
|
||||||
buffer->seek(buffer->size());
|
|
||||||
// Append to end of buffer
|
|
||||||
buffer->write(r.mid(24).constData(), r.mid(24).length());
|
|
||||||
// Seek to start of buffer.
|
|
||||||
buffer->seek(0);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
12
udphandler.h
12
udphandler.h
|
@ -15,10 +15,14 @@
|
||||||
// Needed for audio
|
// Needed for audio
|
||||||
#include <QtMultimedia/QAudioOutput>
|
#include <QtMultimedia/QAudioOutput>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "rxaudiohandler.h"
|
||||||
|
|
||||||
|
|
||||||
// Parent class that contains all common items.
|
// Parent class that contains all common items.
|
||||||
class udpBase : public QObject
|
class udpBase : public QObject
|
||||||
{
|
{
|
||||||
|
@ -118,6 +122,10 @@ public:
|
||||||
udpAudio(QHostAddress local, QHostAddress ip, int aport);
|
udpAudio(QHostAddress local, QHostAddress ip, int aport);
|
||||||
~udpAudio();
|
~udpAudio();
|
||||||
QAudioOutput* audio;
|
QAudioOutput* audio;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void haveAudioData(QByteArray data, int length);
|
||||||
|
void setupAudio(const QAudioFormat format, const int bufferSize);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void DataReceived();
|
void DataReceived();
|
||||||
|
@ -128,6 +136,10 @@ private:
|
||||||
bool sentPacketConnect2 = false;
|
bool sentPacketConnect2 = false;
|
||||||
uint16_t sendAudioSeq = 0;
|
uint16_t sendAudioSeq = 0;
|
||||||
|
|
||||||
|
rxAudioHandler* rxaudio;
|
||||||
|
QThread* rxAudioThread;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,8 @@ SOURCES += main.cpp\
|
||||||
freqmemory.cpp \
|
freqmemory.cpp \
|
||||||
rigidentities.cpp \
|
rigidentities.cpp \
|
||||||
udphandler.cpp \
|
udphandler.cpp \
|
||||||
logcategories.cpp
|
logcategories.cpp \
|
||||||
|
rxaudiohandler.cpp
|
||||||
|
|
||||||
HEADERS += wfmain.h \
|
HEADERS += wfmain.h \
|
||||||
commhandler.h \
|
commhandler.h \
|
||||||
|
@ -88,7 +89,8 @@ HEADERS += wfmain.h \
|
||||||
freqmemory.h \
|
freqmemory.h \
|
||||||
rigidentities.h \
|
rigidentities.h \
|
||||||
udphandler.h \
|
udphandler.h \
|
||||||
logcategories.h
|
logcategories.h \
|
||||||
|
rxaudiohandler.h
|
||||||
|
|
||||||
FORMS += wfmain.ui
|
FORMS += wfmain.ui
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue