From ebf3b1fc4bb4e3d50691a6feb1a7729795fa7195 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 27 Mar 2018 09:04:10 +0200 Subject: [PATCH] RTP fixes --- plugins/channelrx/demodam/amdemod.cpp | 2 +- plugins/channelrx/demodbfm/bfmdemod.h | 1 - plugins/channelrx/demodnfm/nfmdemod.cpp | 2 +- plugins/channelrx/demodssb/ssbdemod.cpp | 6 ++++-- plugins/channelrx/demodwfm/wfmdemod.cpp | 2 +- sdrbase/audio/audionetsink.cpp | 14 ++++++++++---- sdrbase/audio/audionetsink.h | 3 ++- sdrbase/audio/audiooutput.cpp | 2 +- sdrbase/util/rtpsink.cpp | 25 +++++++++++++------------ sdrbase/util/rtpsink.h | 2 +- 10 files changed, 34 insertions(+), 25 deletions(-) diff --git a/plugins/channelrx/demodam/amdemod.cpp b/plugins/channelrx/demodam/amdemod.cpp index bb62ff584..e0562dbdf 100644 --- a/plugins/channelrx/demodam/amdemod.cpp +++ b/plugins/channelrx/demodam/amdemod.cpp @@ -65,7 +65,7 @@ AMDemod::AMDemod(DeviceSourceAPI *deviceAPI) : DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo, getInputMessageQueue()); m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate(); - m_audioNetSink = new AudioNetSink(0, false, false); // parent thread allocated dynamically + m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically - no RTP m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort); applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true); diff --git a/plugins/channelrx/demodbfm/bfmdemod.h b/plugins/channelrx/demodbfm/bfmdemod.h index 90813e197..81426d871 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.h +++ b/plugins/channelrx/demodbfm/bfmdemod.h @@ -42,7 +42,6 @@ class DeviceSourceAPI; class ThreadedBasebandSampleSink; class DownChannelizer; -class AudioNetSink; class BFMDemod : public BasebandSampleSink, public ChannelSinkAPI { public: diff --git a/plugins/channelrx/demodnfm/nfmdemod.cpp b/plugins/channelrx/demodnfm/nfmdemod.cpp index b78a20522..7759ea7e7 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -81,7 +81,7 @@ NFMDemod::NFMDemod(DeviceSourceAPI *devieAPI) : m_afSquelch.setCoefficients(24, 600, 48000.0, 200, 0); // 0.5ms test period, 300ms average span, 48kS/s SR, 100ms attack, no decay DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo, getInputMessageQueue()); - m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically + m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically - no RTP m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort); applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true); diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index a460a9a99..dd6e362ba 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -66,7 +66,9 @@ SSBDemod::SSBDemod(DeviceSourceAPI *deviceAPI) : m_spanLog2 = 3; m_inputSampleRate = 48000; m_inputFrequencyOffset = 0; - m_audioSampleRate = DSPEngine::instance()->getDefaultAudioSampleRate(); + + DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo, getInputMessageQueue()); + m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate(); m_audioBuffer.resize(1<<14); m_audioBufferFill = 0; @@ -86,7 +88,7 @@ SSBDemod::SSBDemod(DeviceSourceAPI *deviceAPI) : DSBFilter = new fftfilt((2.0f * m_Bandwidth) / m_audioSampleRate, 2 * ssbFftLen); DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo, getInputMessageQueue()); - m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically + m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically - no RTP m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort); applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true); diff --git a/plugins/channelrx/demodwfm/wfmdemod.cpp b/plugins/channelrx/demodwfm/wfmdemod.cpp index 2c722598e..a8544b605 100644 --- a/plugins/channelrx/demodwfm/wfmdemod.cpp +++ b/plugins/channelrx/demodwfm/wfmdemod.cpp @@ -60,7 +60,7 @@ WFMDemod::WFMDemod(DeviceSourceAPI* deviceAPI) : m_audioBufferFill = 0; DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo, getInputMessageQueue()); - m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically + m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically - no RTP m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort); applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true); diff --git a/sdrbase/audio/audionetsink.cpp b/sdrbase/audio/audionetsink.cpp index 43e40ec0a..8cde5dda6 100644 --- a/sdrbase/audio/audionetsink.cpp +++ b/sdrbase/audio/audionetsink.cpp @@ -23,17 +23,23 @@ const int AudioNetSink::m_udpBlockSize = 512; -AudioNetSink::AudioNetSink(QObject *parent, bool stereo, bool useRTP) : +AudioNetSink::AudioNetSink(QObject *parent) : m_type(SinkUDP), m_rtpBufferAudio(0), m_bufferIndex(0), m_port(9998) { m_udpSocket = new QUdpSocket(parent); +} - if (useRTP) { - m_rtpBufferAudio = new RTPSink(m_udpSocket, stereo); - } +AudioNetSink::AudioNetSink(QObject *parent, int sampleRate, bool stereo) : + m_type(SinkUDP), + m_rtpBufferAudio(0), + m_bufferIndex(0), + m_port(9998) +{ + m_udpSocket = new QUdpSocket(parent); + m_rtpBufferAudio = new RTPSink(m_udpSocket, sampleRate, stereo); } AudioNetSink::~AudioNetSink() diff --git a/sdrbase/audio/audionetsink.h b/sdrbase/audio/audionetsink.h index 600c68672..38c237e15 100644 --- a/sdrbase/audio/audionetsink.h +++ b/sdrbase/audio/audionetsink.h @@ -37,7 +37,8 @@ public: SinkRTP } SinkType; - AudioNetSink(QObject *parent, bool stereo = false, bool useRTP = true); + AudioNetSink(QObject *parent); //!< without RTP + AudioNetSink(QObject *parent, int sampleRate, bool stereo); //!< with RTP ~AudioNetSink(); void setDestination(const QString& address, uint16_t port); diff --git a/sdrbase/audio/audiooutput.cpp b/sdrbase/audio/audiooutput.cpp index bf905e6ff..2899f8a95 100644 --- a/sdrbase/audio/audiooutput.cpp +++ b/sdrbase/audio/audiooutput.cpp @@ -111,7 +111,7 @@ bool AudioOutput::start(int device, int rate) } m_audioOutput = new QAudioOutput(devInfo, m_audioFormat); - m_audioNetSink = new AudioNetSink(0); + m_audioNetSink = new AudioNetSink(0, m_audioFormat.sampleRate(), false); QIODevice::open(QIODevice::ReadOnly); diff --git a/sdrbase/util/rtpsink.cpp b/sdrbase/util/rtpsink.cpp index f87ac3cb2..7747a7400 100644 --- a/sdrbase/util/rtpsink.cpp +++ b/sdrbase/util/rtpsink.cpp @@ -19,9 +19,9 @@ #include "dsp/dsptypes.h" #include -RTPSink::RTPSink(QUdpSocket *udpSocket, bool stereo) : +RTPSink::RTPSink(QUdpSocket *udpSocket, int sampleRate, bool stereo) : m_payloadType(stereo ? RTPSink::PayloadL16Stereo : RTPSink::PayloadL16Mono), - m_sampleRate(48000), + m_sampleRate(sampleRate), m_sampleBytes(0), m_packetSamples(0), m_bufferSize(0), @@ -76,7 +76,7 @@ void RTPSink::setPayloadInformation(PayloadType payloadType, int sampleRate) uint32_t timestampinc; QMutexLocker locker(&m_mutex); - qDebug("RTPSink::setPayloadType: %d sampleRate: %d", payloadType, sampleRate); + qDebug("RTPSink::setPayloadInformation: %d sampleRate: %d", payloadType, sampleRate); switch (payloadType) { @@ -107,9 +107,9 @@ void RTPSink::setPayloadInformation(PayloadType payloadType, int sampleRate) int status = m_rtpSession.SetTimestampUnit(1.0 / (double) m_sampleRate); if (status < 0) { - qCritical("RTPSink::setPayloadType: cannot set timestamp unit: %s", qrtplib::RTPGetErrorString(status).c_str()); + qCritical("RTPSink::setPayloadInformation: cannot set timestamp unit: %s", qrtplib::RTPGetErrorString(status).c_str()); } else { - qDebug("RTPSink::setPayloadType: timestamp unit set to %f: %s", + qDebug("RTPSink::setPayloadInformation: timestamp unit set to %f: %s", 1.0 / (double) m_sampleRate, qrtplib::RTPGetErrorString(status).c_str()); } @@ -117,25 +117,26 @@ void RTPSink::setPayloadInformation(PayloadType payloadType, int sampleRate) status = m_rtpSession.SetDefaultMark(false); if (status < 0) { - qCritical("RTPSink::setPayloadType: cannot set default mark: %s", qrtplib::RTPGetErrorString(status).c_str()); + qCritical("RTPSink::setPayloadInformation: cannot set default mark: %s", qrtplib::RTPGetErrorString(status).c_str()); } else { - qDebug("RTPSink::setPayloadType: set default mark to false: %s", qrtplib::RTPGetErrorString(status).c_str()); + qDebug("RTPSink::setPayloadInformation: set default mark to false: %s", qrtplib::RTPGetErrorString(status).c_str()); } status = m_rtpSession.SetDefaultTimestampIncrement(timestampinc); if (status < 0) { - qCritical("RTPSink::setPayloadType: cannot set default timestamp increment: %s", qrtplib::RTPGetErrorString(status).c_str()); + qCritical("RTPSink::setPayloadInformation: cannot set default timestamp increment: %s", qrtplib::RTPGetErrorString(status).c_str()); } else { - qDebug("RTPSink::setPayloadType: set default timestamp increment to %d: %s", timestampinc, qrtplib::RTPGetErrorString(status).c_str()); + qDebug("RTPSink::setPayloadInformation: set default timestamp increment to %d: %s", timestampinc, qrtplib::RTPGetErrorString(status).c_str()); } - status = m_rtpSession.SetMaximumPacketSize(m_bufferSize+40); + int maximumPacketSize = std::max(m_bufferSize+40, RTP_MINPACKETSIZE); + status = m_rtpSession.SetMaximumPacketSize(maximumPacketSize); if (status < 0) { - qCritical("RTPSink::setPayloadType: cannot set maximum packet size: %s", qrtplib::RTPGetErrorString(status).c_str()); + qCritical("RTPSink::setPayloadInformation: cannot set maximum packet size: %s", qrtplib::RTPGetErrorString(status).c_str()); } else { - qDebug("RTPSink::setPayloadType: set maximum packet size to %d bytes: %s", m_bufferSize+40, qrtplib::RTPGetErrorString(status).c_str()); + qDebug("RTPSink::setPayloadInformation: set maximum packet size to %d bytes: %s", maximumPacketSize, qrtplib::RTPGetErrorString(status).c_str()); } } diff --git a/sdrbase/util/rtpsink.h b/sdrbase/util/rtpsink.h index 43fb4e0d0..cdfb66093 100644 --- a/sdrbase/util/rtpsink.h +++ b/sdrbase/util/rtpsink.h @@ -44,7 +44,7 @@ public: PayloadL16Stereo, } PayloadType; - RTPSink(QUdpSocket *udpSocket, bool stereo); + RTPSink(QUdpSocket *udpSocket, int sampleRate, bool stereo); ~RTPSink(); bool isValid() const { return m_valid; }