kopia lustrzana https://gitlab.com/eliggett/wfview
Allow selection of audio input and output devices for UDP Audio
rodzic
91a60bf918
commit
a254a937ff
|
@ -752,7 +752,7 @@ audioHandler::~audioHandler()
|
|||
}
|
||||
}
|
||||
|
||||
bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool ulaw, const bool isinput)
|
||||
bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool ulaw, const bool isinput, QString port)
|
||||
{
|
||||
if (isInitialized) {
|
||||
return false;
|
||||
|
@ -772,12 +772,29 @@ bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16
|
|||
this->radioSampleRate = samplerate;
|
||||
this->chunkSize = this->radioSampleBits * 120;
|
||||
|
||||
qDebug(logAudio()) << "Got audio port name: " << port;
|
||||
|
||||
if (isInput)
|
||||
isInitialized = setDevice(QAudioDeviceInfo::defaultInputDevice());
|
||||
else
|
||||
isInitialized = setDevice(QAudioDeviceInfo::defaultOutputDevice());
|
||||
|
||||
if (isInput) {
|
||||
const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
for (const QAudioDeviceInfo& deviceInfo : deviceInfos) {
|
||||
if (deviceInfo.deviceName() == port) {
|
||||
qDebug(logAudio()) << "Input Audio Device name: " << deviceInfo.deviceName();
|
||||
isInitialized = setDevice(deviceInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
for (const QAudioDeviceInfo& deviceInfo : deviceInfos) {
|
||||
if (deviceInfo.deviceName() == port) {
|
||||
qDebug(logAudio()) << "Output Audio Device name: " << deviceInfo.deviceName();
|
||||
isInitialized = setDevice(deviceInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isInitialized;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
void getNextAudioChunk(QByteArray &data);
|
||||
bool isChunkAvailable();
|
||||
public slots:
|
||||
bool init(const quint8 bits, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isulaw, const bool isinput);
|
||||
bool init(const quint8 bits, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isulaw, const bool isinput, QString port);
|
||||
void incomingAudio(const audioPacket data);
|
||||
void changeLatency(const quint16 newSize);
|
||||
|
||||
|
|
|
@ -5,17 +5,22 @@
|
|||
#include "logcategories.h"
|
||||
|
||||
udpHandler::udpHandler(udpPreferences prefs) :
|
||||
controlPort(prefs.controlLANPort)
|
||||
controlPort(prefs.controlLANPort),
|
||||
civPort(0),
|
||||
audioPort(0),
|
||||
rxSampleRate(prefs.audioRXSampleRate),
|
||||
txSampleRate(prefs.audioRXSampleRate),
|
||||
rxLatency(prefs.audioRXLatency),
|
||||
txLatency(prefs.audioTXLatency),
|
||||
rxCodec(prefs.audioRXCodec),
|
||||
txCodec(prefs.audioTXCodec),
|
||||
audioInputPort(prefs.audioInput),
|
||||
audioOutputPort(prefs.audioOutput)
|
||||
{
|
||||
|
||||
this->port = this->controlPort;
|
||||
this->username = prefs.username;
|
||||
this->password = prefs.password;
|
||||
this->rxLatency = prefs.audioRXLatency;
|
||||
this->txLatency = prefs.audioTXLatency;
|
||||
this->rxSampleRate = prefs.audioRXSampleRate;
|
||||
this->txSampleRate = prefs.audioTXSampleRate;
|
||||
this->rxCodec = prefs.audioRXCodec;
|
||||
this->txCodec = prefs.audioTXCodec;
|
||||
|
||||
qDebug(logUdp()) << "Starting udpHandler user:" << username << " rx latency:" << rxLatency << " tx latency:" << txLatency << " rx sample rate: " << rxSampleRate <<
|
||||
" rx codec: " << rxCodec << " tx sample rate: " << txSampleRate << " tx codec: " << txCodec;
|
||||
|
@ -298,12 +303,11 @@ void udpHandler::dataReceived()
|
|||
}
|
||||
else {
|
||||
civ = new udpCivData(localIP, radioIP, civPort);
|
||||
audio = new udpAudio(localIP, radioIP, audioPort, rxLatency, txLatency, rxSampleRate, rxCodec, txSampleRate, txCodec);
|
||||
audio = new udpAudio(localIP, radioIP, audioPort, rxLatency, txLatency, rxSampleRate, rxCodec, txSampleRate, txCodec, audioOutputPort, audioInputPort);
|
||||
|
||||
QObject::connect(civ, SIGNAL(receive(QByteArray)), this, SLOT(receiveFromCivStream(QByteArray)));
|
||||
QObject::connect(audio, SIGNAL(haveAudioData(audioPacket)), this, SLOT(receiveAudioData(audioPacket)));
|
||||
QObject::connect(this, SIGNAL(haveChangeLatency(quint16)), audio, SLOT(changeLatency(quint16)));
|
||||
|
||||
QObject::connect(this, SIGNAL(haveChangeLatency(quint16)), audio, SLOT(changeLatency(quint16)));
|
||||
|
||||
streamOpened = true;
|
||||
|
||||
|
@ -640,7 +644,7 @@ void udpCivData::dataReceived()
|
|||
|
||||
|
||||
// Audio stream
|
||||
udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint16 rxlatency, quint16 txlatency, quint16 rxsample, quint8 rxcodec, quint16 txsample, quint8 txcodec)
|
||||
udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint16 rxlatency, quint16 txlatency, quint16 rxsample, quint8 rxcodec, quint16 txsample, quint8 txcodec, QString outputPort, QString inputPort)
|
||||
{
|
||||
qDebug(logUdp()) << "Starting udpAudio";
|
||||
this->localIP = local;
|
||||
|
@ -683,7 +687,7 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint
|
|||
|
||||
rxaudio->moveToThread(rxAudioThread);
|
||||
|
||||
connect(this, SIGNAL(setupRxAudio(quint8, quint8, quint16, quint16, bool, bool)), rxaudio, SLOT(init(quint8, quint8, quint16, quint16, bool, bool)));
|
||||
connect(this, SIGNAL(setupRxAudio(quint8, quint8, quint16, quint16, bool, bool, QString)), rxaudio, SLOT(init(quint8, quint8, quint16, quint16, bool, bool,QString)));
|
||||
|
||||
qRegisterMetaType<audioPacket>();
|
||||
connect(this, SIGNAL(haveAudioData(audioPacket)), rxaudio, SLOT(incomingAudio(audioPacket)));
|
||||
|
@ -702,7 +706,7 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint
|
|||
|
||||
txaudio->moveToThread(txAudioThread);
|
||||
|
||||
connect(this, SIGNAL(setupTxAudio(quint8, quint8, quint16, quint16, bool, bool)), txaudio, SLOT(init(quint8, quint8, quint16, quint16, bool, bool)));
|
||||
connect(this, SIGNAL(setupTxAudio(quint8, quint8, quint16, quint16, bool, bool,QString)), txaudio, SLOT(init(quint8, quint8, quint16, quint16, bool, bool,QString)));
|
||||
connect(txAudioThread, SIGNAL(finished()), txaudio, SLOT(deleteLater()));
|
||||
|
||||
rxAudioThread->start();
|
||||
|
@ -715,8 +719,8 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint
|
|||
connect(pingTimer, &QTimer::timeout, this, &udpBase::sendPing);
|
||||
pingTimer->start(PING_PERIOD); // send ping packets every 100ms
|
||||
|
||||
emit setupTxAudio(txNumSamples, txChannelCount, txSampleRate, txLatency, txIsUlawCodec, true);
|
||||
emit setupRxAudio(rxNumSamples, rxChannelCount, rxSampleRate, txLatency, rxIsUlawCodec, false);
|
||||
emit setupTxAudio(txNumSamples, txChannelCount, txSampleRate, txLatency, txIsUlawCodec, true, inputPort);
|
||||
emit setupRxAudio(rxNumSamples, rxChannelCount, rxSampleRate, txLatency, rxIsUlawCodec, false, outputPort);
|
||||
|
||||
watchdogTimer = new QTimer();
|
||||
connect(watchdogTimer, &QTimer::timeout, this, &udpAudio::watchdog);
|
||||
|
|
10
udphandler.h
10
udphandler.h
|
@ -164,14 +164,14 @@ class udpAudio : public udpBase
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
udpAudio(QHostAddress local, QHostAddress ip, quint16 aport, quint16 rxlatency, quint16 txlatency, quint16 rxsample, quint8 rxcodec, quint16 txsample, quint8 txcodec);
|
||||
udpAudio(QHostAddress local, QHostAddress ip, quint16 aport, quint16 rxlatency, quint16 txlatency, quint16 rxsample, quint8 rxcodec, quint16 txsample, quint8 txcodec, QString outputPort, QString inputPort);
|
||||
~udpAudio();
|
||||
|
||||
signals:
|
||||
void haveAudioData(audioPacket data);
|
||||
|
||||
void setupTxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput);
|
||||
void setupRxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput);
|
||||
void setupTxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput, QString port);
|
||||
void setupRxAudio(const quint8 samples, const quint8 channels, const quint16 samplerate, const quint16 latency, const bool isUlaw, const bool isInput, QString port);
|
||||
|
||||
void haveChangeLatency(quint16 value);
|
||||
|
||||
|
@ -272,6 +272,9 @@ private:
|
|||
quint8 rxCodec;
|
||||
quint8 txCodec;
|
||||
|
||||
QString audioInputPort;
|
||||
QString audioOutputPort;
|
||||
|
||||
quint16 reauthInterval = 60000;
|
||||
QString devName;
|
||||
QString compName;
|
||||
|
@ -290,6 +293,7 @@ private:
|
|||
QTimer* areYouThereTimer = Q_NULLPTR;
|
||||
|
||||
bool highBandwidthConnection = false;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(struct audioPacket)
|
||||
|
|
10
wfmain.cpp
10
wfmain.cpp
|
@ -2876,16 +2876,6 @@ void wfmain::on_controlPortTxt_textChanged(QString text)
|
|||
udpPrefs.controlLANPort = text.toUInt();
|
||||
}
|
||||
|
||||
void wfmain::on_serialPortTxt_textChanged(QString text)
|
||||
{
|
||||
udpPrefs.serialLANPort = text.toUInt();
|
||||
}
|
||||
|
||||
void wfmain::on_audioPortTxt_textChanged(QString text)
|
||||
{
|
||||
udpPrefs.audioLANPort = text.toUInt();
|
||||
}
|
||||
|
||||
void wfmain::on_usernameTxt_textChanged(QString text)
|
||||
{
|
||||
udpPrefs.username = text;
|
||||
|
|
4
wfmain.h
4
wfmain.h
|
@ -311,10 +311,6 @@ private slots:
|
|||
|
||||
void on_controlPortTxt_textChanged(QString text);
|
||||
|
||||
void on_serialPortTxt_textChanged(QString text);
|
||||
|
||||
void on_audioPortTxt_textChanged(QString text);
|
||||
|
||||
void on_usernameTxt_textChanged(QString text);
|
||||
|
||||
void on_passwordTxt_textChanged(QString text);
|
||||
|
|
Ładowanie…
Reference in New Issue