Allow selection of audio input and output devices for UDP Audio

audioplugins
Phil Taylor 2021-03-01 20:31:05 +00:00
rodzic 91a60bf918
commit a254a937ff
6 zmienionych plików z 50 dodań i 39 usunięć

Wyświetl plik

@ -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) { if (isInitialized) {
return false; return false;
@ -772,12 +772,29 @@ bool audioHandler::init(const quint8 bits, const quint8 channels, const quint16
this->radioSampleRate = samplerate; this->radioSampleRate = samplerate;
this->chunkSize = this->radioSampleBits * 120; this->chunkSize = this->radioSampleBits * 120;
qDebug(logAudio()) << "Got audio port name: " << port;
if (isInput) if (isInput) {
isInitialized = setDevice(QAudioDeviceInfo::defaultInputDevice()); const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
else for (const QAudioDeviceInfo& deviceInfo : deviceInfos) {
isInitialized = setDevice(QAudioDeviceInfo::defaultOutputDevice()); 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; return isInitialized;
} }

Wyświetl plik

@ -54,7 +54,7 @@ public:
void getNextAudioChunk(QByteArray &data); void getNextAudioChunk(QByteArray &data);
bool isChunkAvailable(); bool isChunkAvailable();
public slots: 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 incomingAudio(const audioPacket data);
void changeLatency(const quint16 newSize); void changeLatency(const quint16 newSize);

Wyświetl plik

@ -5,17 +5,22 @@
#include "logcategories.h" #include "logcategories.h"
udpHandler::udpHandler(udpPreferences prefs) : 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->port = this->controlPort;
this->username = prefs.username; this->username = prefs.username;
this->password = prefs.password; 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 << 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; " rx codec: " << rxCodec << " tx sample rate: " << txSampleRate << " tx codec: " << txCodec;
@ -298,12 +303,11 @@ void udpHandler::dataReceived()
} }
else { else {
civ = new udpCivData(localIP, radioIP, civPort); 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(civ, SIGNAL(receive(QByteArray)), this, SLOT(receiveFromCivStream(QByteArray)));
QObject::connect(audio, SIGNAL(haveAudioData(audioPacket)), this, SLOT(receiveAudioData(audioPacket))); 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; streamOpened = true;
@ -640,7 +644,7 @@ void udpCivData::dataReceived()
// Audio stream // 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"; qDebug(logUdp()) << "Starting udpAudio";
this->localIP = local; this->localIP = local;
@ -683,7 +687,7 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint
rxaudio->moveToThread(rxAudioThread); 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>(); qRegisterMetaType<audioPacket>();
connect(this, SIGNAL(haveAudioData(audioPacket)), rxaudio, SLOT(incomingAudio(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); 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())); connect(txAudioThread, SIGNAL(finished()), txaudio, SLOT(deleteLater()));
rxAudioThread->start(); rxAudioThread->start();
@ -715,8 +719,8 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint
connect(pingTimer, &QTimer::timeout, this, &udpBase::sendPing); connect(pingTimer, &QTimer::timeout, this, &udpBase::sendPing);
pingTimer->start(PING_PERIOD); // send ping packets every 100ms pingTimer->start(PING_PERIOD); // send ping packets every 100ms
emit setupTxAudio(txNumSamples, txChannelCount, txSampleRate, txLatency, txIsUlawCodec, true); emit setupTxAudio(txNumSamples, txChannelCount, txSampleRate, txLatency, txIsUlawCodec, true, inputPort);
emit setupRxAudio(rxNumSamples, rxChannelCount, rxSampleRate, txLatency, rxIsUlawCodec, false); emit setupRxAudio(rxNumSamples, rxChannelCount, rxSampleRate, txLatency, rxIsUlawCodec, false, outputPort);
watchdogTimer = new QTimer(); watchdogTimer = new QTimer();
connect(watchdogTimer, &QTimer::timeout, this, &udpAudio::watchdog); connect(watchdogTimer, &QTimer::timeout, this, &udpAudio::watchdog);

Wyświetl plik

@ -164,14 +164,14 @@ class udpAudio : public udpBase
Q_OBJECT Q_OBJECT
public: 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(); ~udpAudio();
signals: signals:
void haveAudioData(audioPacket data); 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 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); 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); void haveChangeLatency(quint16 value);
@ -272,6 +272,9 @@ private:
quint8 rxCodec; quint8 rxCodec;
quint8 txCodec; quint8 txCodec;
QString audioInputPort;
QString audioOutputPort;
quint16 reauthInterval = 60000; quint16 reauthInterval = 60000;
QString devName; QString devName;
QString compName; QString compName;
@ -290,6 +293,7 @@ private:
QTimer* areYouThereTimer = Q_NULLPTR; QTimer* areYouThereTimer = Q_NULLPTR;
bool highBandwidthConnection = false; bool highBandwidthConnection = false;
}; };
Q_DECLARE_METATYPE(struct audioPacket) Q_DECLARE_METATYPE(struct audioPacket)

Wyświetl plik

@ -2876,16 +2876,6 @@ void wfmain::on_controlPortTxt_textChanged(QString text)
udpPrefs.controlLANPort = text.toUInt(); 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) void wfmain::on_usernameTxt_textChanged(QString text)
{ {
udpPrefs.username = text; udpPrefs.username = text;

Wyświetl plik

@ -311,10 +311,6 @@ private slots:
void on_controlPortTxt_textChanged(QString text); 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_usernameTxt_textChanged(QString text);
void on_passwordTxt_textChanged(QString text); void on_passwordTxt_textChanged(QString text);