1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 13:21:50 -05:00

BFM demod: implement RTP over UDP for audio copy

This commit is contained in:
f4exb 2018-03-10 07:03:11 +01:00
parent 7bf9252039
commit dc9cb0463f
9 changed files with 73 additions and 12 deletions

View File

@ -21,6 +21,7 @@
#include <complex.h>
#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<AudioSample>(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<QThread*>(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<QString&>(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;

View File

@ -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<AudioSample> *m_udpBufferAudio;
AudioNetSink *m_audioNetSink;
static const int m_udpBlockSize;

View File

@ -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);
}

View File

@ -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);

View File

@ -321,6 +321,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="useRTP">
<property name="toolTip">
<string>Use RTP protocol for audio copy to UDP</string>
</property>
<property name="text">
<string>R</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -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();

View File

@ -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;

View File

@ -31,7 +31,6 @@
#include "dsp/phasediscri.h"
#include "audio/audiofifo.h"
#include "util/message.h"
#include "util/udpsink.h"
#include "wfmdemodsettings.h"

View File

@ -387,7 +387,7 @@
<item>
<widget class="QCheckBox" name="useRTP">
<property name="toolTip">
<string>Kiki koko kuku cacaboudin</string>
<string>Use RTP protocol for audio copy to UDP</string>
</property>
<property name="text">
<string>R</string>