From 369ba9089766befa963bae6ace3c98a50a7e2dc6 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Tue, 18 May 2021 09:32:56 +0100 Subject: [PATCH] Allow receive only in udpHandler --- audiohandler.cpp | 2 +- audiohandler.h | 2 +- udphandler.cpp | 35 ++++++++++++++++++++++++++++++----- udphandler.h | 5 ++++- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index 30d31c2..b241502 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -753,7 +753,7 @@ audioHandler::~audioHandler() delete audioInput; } - if (resampler) { + if (resampler != NULL) { speex_resampler_destroy(resampler); } } diff --git a/audiohandler.h b/audiohandler.h index 60b65a8..fb25157 100644 --- a/audiohandler.h +++ b/audiohandler.h @@ -96,7 +96,7 @@ private: QVector audioBuffer; QMapinputBuffer; - SpeexResamplerState* resampler; + SpeexResamplerState* resampler=NULL; unsigned int ratioNum; unsigned int ratioDen; }; diff --git a/udphandler.cpp b/udphandler.cpp index c80949b..304f6b1 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -313,6 +313,12 @@ void udpHandler::dataReceived() } else { civ = new udpCivData(localIP, radioIP, civPort); + + // TX is not supported + if (txSampleRates <2 ) { + txSampleRate = 0; + txCodec = 0; + } audio = new udpAudio(localIP, radioIP, audioPort, rxLatency, txLatency, rxSampleRate, rxCodec, txSampleRate, txCodec, audioOutputPort, audioInputPort,resampleQuality); QObject::connect(civ, SIGNAL(receive(QByteArray)), this, SLOT(receiveFromCivStream(QByteArray))); @@ -360,10 +366,19 @@ void udpHandler::dataReceived() { audioType = in->audio; devName = in->name; + civId = in->civ; + rxSampleRates = in->rxsample; + txSampleRates = in->txsample; //replyId = r.mid(0x42, 16); qInfo(logUdp()) << this->metaObject()->className() << "Received radio capabilities, Name:" << devName << " Audio:" << - audioType; + audioType << "CIV:" << hex << civId; + + if (txSampleRates < 2) + { + // TX not supported + qInfo(logUdp()) << this->metaObject()->className() << "TX audio is disabled"; + } } break; } @@ -399,9 +414,11 @@ void udpHandler::sendRequestStream() p.token = token; memcpy(&p.name, devName.toLocal8Bit().constData(), devName.length()); p.rxenable = 1; - p.txenable = 1; + if (this->txSampleRates > 1) { + p.txenable = 1; + p.txcodec = txCodec; + } p.rxcodec = rxCodec; - p.txcodec = txCodec; memcpy(&p.username, usernameEncoded.constData(), usernameEncoded.length()); p.rxsample = qToBigEndian((quint32)rxSampleRate); p.txsample = qToBigEndian((quint32)txSampleRate); @@ -682,6 +699,10 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint this->rxCodec = rxcodec; this->txCodec = txcodec; + if (txSampleRate == 0) { + enableTx = false; + } + init(); // Perform connection QUdpSocket::connect(udp, &QUdpSocket::readyRead, this, &udpAudio::dataReceived); @@ -721,6 +742,7 @@ udpAudio::udpAudio(QHostAddress local, QHostAddress ip, quint16 audioPort, quint connect(this, SIGNAL(haveSetVolume(unsigned char)), rxaudio, SLOT(setVolume(unsigned char))); connect(rxAudioThread, SIGNAL(finished()), rxaudio, SLOT(deleteLater())); + if (txCodec == 0x01) txIsUlawCodec = true; else if (txCodec == 0x04) @@ -744,7 +766,10 @@ 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, inputPort,resampleQuality); + if (enableTx) { + emit setupTxAudio(txNumSamples, txChannelCount, txSampleRate, txLatency, txIsUlawCodec, true, inputPort, resampleQuality); + } + emit setupRxAudio(rxNumSamples, rxChannelCount, rxSampleRate, txLatency, rxIsUlawCodec, false, outputPort,resampleQuality); watchdogTimer = new QTimer(); @@ -877,7 +902,7 @@ void udpAudio::dataReceived() case (16): // Response to control packet handled in udpBase { control_packet_t in = (control_packet_t)r.constData(); - if (in->type == 0x04) + if (in->type == 0x04 && enableTx) { txAudioTimer->start(TXAUDIO_PERIOD); } diff --git a/udphandler.h b/udphandler.h index c4bd34f..b38e815 100644 --- a/udphandler.h +++ b/udphandler.h @@ -224,6 +224,7 @@ private: QThread* txAudioThread = Q_NULLPTR; QTimer* txAudioTimer=Q_NULLPTR; + bool enableTx = 1; }; @@ -313,7 +314,9 @@ private: QTimer* areYouThereTimer = Q_NULLPTR; bool highBandwidthConnection = false; - + quint8 civId = 0; + quint16 rxSampleRates = 0; + quint16 txSampleRates = 0; }; #endif