From dc9cb0463faa04b022f991a6f0ec76057a59491c Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 10 Mar 2018 07:03:11 +0100 Subject: [PATCH] BFM demod: implement RTP over UDP for audio copy --- plugins/channelrx/demodbfm/bfmdemod.cpp | 50 ++++++++++++++++--- plugins/channelrx/demodbfm/bfmdemod.h | 5 +- plugins/channelrx/demodbfm/bfmdemodgui.cpp | 14 ++++++ plugins/channelrx/demodbfm/bfmdemodgui.h | 1 + plugins/channelrx/demodbfm/bfmdemodgui.ui | 10 ++++ .../channelrx/demodbfm/bfmdemodsettings.cpp | 1 + plugins/channelrx/demodbfm/bfmdemodsettings.h | 1 + plugins/channelrx/demodwfm/wfmdemod.h | 1 - plugins/channelrx/demodwfm/wfmdemodgui.ui | 2 +- 9 files changed, 73 insertions(+), 12 deletions(-) diff --git a/plugins/channelrx/demodbfm/bfmdemod.cpp b/plugins/channelrx/demodbfm/bfmdemod.cpp index 7ce345792..8bf7c5b7a 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.cpp +++ b/plugins/channelrx/demodbfm/bfmdemod.cpp @@ -21,6 +21,7 @@ #include #include "audio/audiooutput.h" +#include "audio/audionetsink.h" #include "dsp/dspengine.h" #include "dsp/downchannelizer.h" #include "dsp/threadedbasebandsamplesink.h" @@ -84,7 +85,9 @@ BFMDemod::BFMDemod(DeviceSourceAPI *deviceAPI) : m_audioBufferFill = 0; DSPEngine::instance()->addAudioSink(&m_audioFifo); - m_udpBufferAudio = new UDPSink(this, m_udpBlockSize, m_settings.m_udpPort); + m_audioNetSink = new AudioNetSink(0); // parent thread allocated dynamically + m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort); + m_audioNetSink->setStereo(true); m_channelizer = new DownChannelizer(this); m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); @@ -103,7 +106,7 @@ BFMDemod::~BFMDemod() } DSPEngine::instance()->removeAudioSink(&m_audioFifo); - delete m_udpBufferAudio; + delete m_audioNetSink; m_deviceAPI->removeChannelAPI(this); m_deviceAPI->removeThreadedSink(m_threadedChannelizer); @@ -235,8 +238,10 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto m_audioBuffer[m_audioBufferFill].l = (qint16)(deemph_l * (1<<12) * m_settings.m_volume); m_audioBuffer[m_audioBufferFill].r = (qint16)(deemph_r * (1<<12) * m_settings.m_volume); - if (m_settings.m_copyAudioToUDP) { - m_udpBufferAudio->write(m_audioBuffer[m_audioBufferFill]); + if (m_settings.m_copyAudioToUDP) + { + m_audioNetSink->write(m_audioBuffer[m_audioBufferFill].l); + m_audioNetSink->write(m_audioBuffer[m_audioBufferFill].r); } } else @@ -247,8 +252,10 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto m_audioBuffer[m_audioBufferFill].l = sample; m_audioBuffer[m_audioBufferFill].r = sample; - if (m_settings.m_copyAudioToUDP) { - m_udpBufferAudio->write(m_audioBuffer[m_audioBufferFill]); + if (m_settings.m_copyAudioToUDP) + { + m_audioNetSink->write(m_audioBuffer[m_audioBufferFill].l); + m_audioNetSink->write(m_audioBuffer[m_audioBufferFill].r); } } @@ -347,6 +354,14 @@ bool BFMDemod::handleMessage(const Message& cmd) return true; } + else if (BasebandSampleSink::MsgThreadedSink::match(cmd)) + { + BasebandSampleSink::MsgThreadedSink& cfg = (BasebandSampleSink::MsgThreadedSink&) cmd; + const QThread *thread = cfg.getThread(); + qDebug("BFMDemod::handleMessage: BasebandSampleSink::MsgThreadedSink: %p", thread); + m_audioNetSink->moveToThread(const_cast(thread)); // use the thread for udp sinks + return true; + } else if (DSPSignalNotification::match(cmd)) { return true; @@ -484,8 +499,27 @@ void BFMDemod::applySettings(const BFMDemodSettings& settings, bool force) if ((settings.m_udpAddress != m_settings.m_udpAddress) || (settings.m_udpPort != m_settings.m_udpPort) || force) { - m_udpBufferAudio->setAddress(const_cast(settings.m_udpAddress)); - m_udpBufferAudio->setPort(settings.m_udpPort); + m_audioNetSink->setDestination(settings.m_udpAddress, settings.m_udpPort); + } + + if ((settings.m_copyAudioUseRTP != m_settings.m_copyAudioUseRTP) || force) + { + if (settings.m_copyAudioUseRTP) + { + if (m_audioNetSink->selectType(AudioNetSink::SinkRTP)) { + qDebug("WFMDemod::applySettings: set audio sink to RTP mode"); + } else { + qWarning("WFMDemod::applySettings: RTP support for audio sink not available. Fall back too UDP"); + } + } + else + { + if (m_audioNetSink->selectType(AudioNetSink::SinkUDP)) { + qDebug("WFMDemod::applySettings: set audio sink to UDP mode"); + } else { + qWarning("WFMDemod::applySettings: failed to set audio sink to UDP mode"); + } + } } m_settings = settings; diff --git a/plugins/channelrx/demodbfm/bfmdemod.h b/plugins/channelrx/demodbfm/bfmdemod.h index cf0a7ee33..41a8bffb7 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.h +++ b/plugins/channelrx/demodbfm/bfmdemod.h @@ -33,7 +33,6 @@ #include "dsp/phasediscri.h" #include "audio/audiofifo.h" #include "util/message.h" -#include "util/udpsink.h" #include "rdsparser.h" #include "rdsdecoder.h" @@ -43,6 +42,7 @@ class DeviceSourceAPI; class ThreadedBasebandSampleSink; class DownChannelizer; +class AudioNetSink; class BFMDemod : public BasebandSampleSink, public ChannelSinkAPI { public: @@ -152,6 +152,7 @@ public: m_magsqCount = 0; } + bool isAudioNetSinkRTPCapable() const { return false; } RDSParser& getRDSParser() { return m_rdsParser; } static const QString m_channelIdURI; @@ -221,7 +222,7 @@ private: static const int default_excursion = 750000; // +/- 75 kHz PhaseDiscriminators m_phaseDiscri; - UDPSink *m_udpBufferAudio; + AudioNetSink *m_audioNetSink; static const int m_udpBlockSize; diff --git a/plugins/channelrx/demodbfm/bfmdemodgui.cpp b/plugins/channelrx/demodbfm/bfmdemodgui.cpp index ff1ebcd0b..f33253382 100644 --- a/plugins/channelrx/demodbfm/bfmdemodgui.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodgui.cpp @@ -207,6 +207,12 @@ void BFMDemodGUI::on_copyAudioToUDP_toggled(bool copy) applySettings(); } +void BFMDemodGUI::on_useRTP_toggled(bool checked) +{ + m_settings.m_copyAudioUseRTP = checked; + applySettings(); +} + void BFMDemodGUI::on_showPilot_clicked() { m_settings.m_showPilot = ui->showPilot->isChecked(); @@ -375,6 +381,10 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban m_deviceUISet->addChannelMarker(&m_channelMarker); m_deviceUISet->addRollupWidget(this); + if (!m_bfmDemod->isAudioNetSinkRTPCapable()) { + ui->useRTP->hide(); + } + connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor())); @@ -456,6 +466,10 @@ void BFMDemodGUI::displaySettings() ui->rds->setChecked(m_settings.m_rdsActive); ui->copyAudioToUDP->setChecked(m_settings.m_copyAudioToUDP); + if (m_bfmDemod->isAudioNetSinkRTPCapable()) { + ui->useRTP->setChecked(m_settings.m_copyAudioUseRTP); + } + blockApplySettings(false); } diff --git a/plugins/channelrx/demodbfm/bfmdemodgui.h b/plugins/channelrx/demodbfm/bfmdemodgui.h index a008bb22b..629a50ee0 100644 --- a/plugins/channelrx/demodbfm/bfmdemodgui.h +++ b/plugins/channelrx/demodbfm/bfmdemodgui.h @@ -109,6 +109,7 @@ private slots: void on_showPilot_clicked(); void on_rds_clicked(); void on_copyAudioToUDP_toggled(bool copy); + void on_useRTP_toggled(bool checked); void on_g14ProgServiceNames_currentIndexChanged(int index); void on_clearData_clicked(bool checked); void on_g00AltFrequenciesBox_activated(int index); diff --git a/plugins/channelrx/demodbfm/bfmdemodgui.ui b/plugins/channelrx/demodbfm/bfmdemodgui.ui index 7894e4185..d76e8c2b3 100644 --- a/plugins/channelrx/demodbfm/bfmdemodgui.ui +++ b/plugins/channelrx/demodbfm/bfmdemodgui.ui @@ -321,6 +321,16 @@ + + + + Use RTP protocol for audio copy to UDP + + + R + + + diff --git a/plugins/channelrx/demodbfm/bfmdemodsettings.cpp b/plugins/channelrx/demodbfm/bfmdemodsettings.cpp index 1c6d1cd13..c7c273d5e 100644 --- a/plugins/channelrx/demodbfm/bfmdemodsettings.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodsettings.cpp @@ -47,6 +47,7 @@ void BFMDemodSettings::resetToDefaults() m_showPilot = false; m_rdsActive = false; m_copyAudioToUDP = false; + m_copyAudioUseRTP = false; m_udpAddress = "127.0.0.1"; m_udpPort = 9999; m_rgbColor = QColor(80, 120, 228).rgb(); diff --git a/plugins/channelrx/demodbfm/bfmdemodsettings.h b/plugins/channelrx/demodbfm/bfmdemodsettings.h index b79f6e114..38e1678f9 100644 --- a/plugins/channelrx/demodbfm/bfmdemodsettings.h +++ b/plugins/channelrx/demodbfm/bfmdemodsettings.h @@ -34,6 +34,7 @@ struct BFMDemodSettings bool m_showPilot; bool m_rdsActive; bool m_copyAudioToUDP; + bool m_copyAudioUseRTP; QString m_udpAddress; quint16 m_udpPort; quint32 m_rgbColor; diff --git a/plugins/channelrx/demodwfm/wfmdemod.h b/plugins/channelrx/demodwfm/wfmdemod.h index e87dc3904..4a17378b1 100644 --- a/plugins/channelrx/demodwfm/wfmdemod.h +++ b/plugins/channelrx/demodwfm/wfmdemod.h @@ -31,7 +31,6 @@ #include "dsp/phasediscri.h" #include "audio/audiofifo.h" #include "util/message.h" -#include "util/udpsink.h" #include "wfmdemodsettings.h" diff --git a/plugins/channelrx/demodwfm/wfmdemodgui.ui b/plugins/channelrx/demodwfm/wfmdemodgui.ui index ca63b9d3b..05ffd6164 100644 --- a/plugins/channelrx/demodwfm/wfmdemodgui.ui +++ b/plugins/channelrx/demodwfm/wfmdemodgui.ui @@ -387,7 +387,7 @@ - Kiki koko kuku cacaboudin + Use RTP protocol for audio copy to UDP R