mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	BFM demod: implemented use RTP protocol for audio over UDP
This commit is contained in:
		
							parent
							
								
									5e57c0462f
								
							
						
					
					
						commit
						d946ceffc8
					
				@ -26,6 +26,7 @@
 | 
				
			|||||||
#include <dsp/downchannelizer.h>
 | 
					#include <dsp/downchannelizer.h>
 | 
				
			||||||
#include "dsp/threadedbasebandsamplesink.h"
 | 
					#include "dsp/threadedbasebandsamplesink.h"
 | 
				
			||||||
#include "device/devicesourceapi.h"
 | 
					#include "device/devicesourceapi.h"
 | 
				
			||||||
 | 
					#include "audio/audionetsink.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "rdsparser.h"
 | 
					#include "rdsparser.h"
 | 
				
			||||||
#include "bfmdemod.h"
 | 
					#include "bfmdemod.h"
 | 
				
			||||||
@ -84,7 +85,8 @@ BFMDemod::BFMDemod(DeviceSourceAPI *deviceAPI) :
 | 
				
			|||||||
	m_audioBufferFill = 0;
 | 
						m_audioBufferFill = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DSPEngine::instance()->addAudioSink(&m_audioFifo);
 | 
						DSPEngine::instance()->addAudioSink(&m_audioFifo);
 | 
				
			||||||
    m_udpBufferAudio = new UDPSink<AudioSample>(this, m_udpBlockSize, m_settings.m_udpPort);
 | 
						m_audioNetSink = new AudioNetSink(this, true); // true = stereo
 | 
				
			||||||
 | 
						m_audioNetSink->setDestination(m_settings.m_udpAddress, m_settings.m_udpPort);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_channelizer = new DownChannelizer(this);
 | 
					    m_channelizer = new DownChannelizer(this);
 | 
				
			||||||
    m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
 | 
					    m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
 | 
				
			||||||
@ -103,7 +105,7 @@ BFMDemod::~BFMDemod()
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DSPEngine::instance()->removeAudioSink(&m_audioFifo);
 | 
						DSPEngine::instance()->removeAudioSink(&m_audioFifo);
 | 
				
			||||||
	delete m_udpBufferAudio;
 | 
						delete m_audioNetSink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_deviceAPI->removeChannelAPI(this);
 | 
						m_deviceAPI->removeChannelAPI(this);
 | 
				
			||||||
    m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
 | 
					    m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
 | 
				
			||||||
@ -111,6 +113,11 @@ BFMDemod::~BFMDemod()
 | 
				
			|||||||
    delete m_channelizer;
 | 
					    delete m_channelizer;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool BFMDemod::isAudioNetSinkRTPCapable() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return m_audioNetSink && m_audioNetSink->isRTPCapable();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused)))
 | 
					void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused)))
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Complex ci, cs, cr;
 | 
						Complex ci, cs, cr;
 | 
				
			||||||
@ -236,13 +243,17 @@ 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].l = (qint16)(deemph_l * (1<<12) * m_settings.m_volume);
 | 
				
			||||||
						m_audioBuffer[m_audioBufferFill].r = (qint16)(deemph_r * (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]);
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					else
 | 
										else
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						m_audioBuffer[m_audioBufferFill].l = (qint16)(deemph_l * (1<<12) * m_settings.m_volume);
 | 
											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);
 | 
											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]);
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
@ -252,7 +263,9 @@ void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
 | 
				
			|||||||
					quint16 sample = (qint16)(deemph * (1<<12) * m_settings.m_volume);
 | 
										quint16 sample = (qint16)(deemph * (1<<12) * m_settings.m_volume);
 | 
				
			||||||
					m_audioBuffer[m_audioBufferFill].l = sample;
 | 
										m_audioBuffer[m_audioBufferFill].l = sample;
 | 
				
			||||||
					m_audioBuffer[m_audioBufferFill].r = 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]);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				++m_audioBufferFill;
 | 
									++m_audioBufferFill;
 | 
				
			||||||
@ -419,6 +432,7 @@ void BFMDemod::applySettings(const BFMDemodSettings& settings, bool force)
 | 
				
			|||||||
            << " m_showPilot: " << settings.m_showPilot
 | 
					            << " m_showPilot: " << settings.m_showPilot
 | 
				
			||||||
            << " m_rdsActive: " << settings.m_rdsActive
 | 
					            << " m_rdsActive: " << settings.m_rdsActive
 | 
				
			||||||
            << " m_copyAudioToUDP: " << settings.m_copyAudioToUDP
 | 
					            << " m_copyAudioToUDP: " << settings.m_copyAudioToUDP
 | 
				
			||||||
 | 
								<< " m_copyAudioUseRTP" << settings.m_copyAudioUseRTP
 | 
				
			||||||
            << " m_udpAddress: " << settings.m_udpAddress
 | 
					            << " m_udpAddress: " << settings.m_udpAddress
 | 
				
			||||||
            << " m_udpPort: " << settings.m_udpPort
 | 
					            << " m_udpPort: " << settings.m_udpPort
 | 
				
			||||||
            << " force: " << force;
 | 
					            << " force: " << force;
 | 
				
			||||||
@ -483,8 +497,27 @@ void BFMDemod::applySettings(const BFMDemodSettings& settings, bool force)
 | 
				
			|||||||
    if ((settings.m_udpAddress != m_settings.m_udpAddress)
 | 
					    if ((settings.m_udpAddress != m_settings.m_udpAddress)
 | 
				
			||||||
        || (settings.m_udpPort != m_settings.m_udpPort) || force)
 | 
					        || (settings.m_udpPort != m_settings.m_udpPort) || force)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        m_udpBufferAudio->setAddress(const_cast<QString&>(settings.m_udpAddress));
 | 
					    	m_audioNetSink->setDestination(settings.m_udpAddress, settings.m_udpPort);
 | 
				
			||||||
        m_udpBufferAudio->setPort(settings.m_udpPort);
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ((settings.m_copyAudioUseRTP != m_settings.m_copyAudioUseRTP) || force)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (settings.m_copyAudioUseRTP)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (m_audioNetSink->selectType(AudioNetSink::SinkRTP)) {
 | 
				
			||||||
 | 
					                qDebug("BFMDemod::applySettings: set audio sink to RTP mode");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                qWarning("BFMDemod::applySettings: RTP support for audio sink not available. Fall back too UDP");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (m_audioNetSink->selectType(AudioNetSink::SinkUDP)) {
 | 
				
			||||||
 | 
					                qDebug("BFMDemod::applySettings: set audio sink to UDP mode");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                qWarning("BFMDemod::applySettings: failed to set audio sink to UDP mode");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_settings = settings;
 | 
					    m_settings = settings;
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,6 @@
 | 
				
			|||||||
#include "dsp/phasediscri.h"
 | 
					#include "dsp/phasediscri.h"
 | 
				
			||||||
#include "audio/audiofifo.h"
 | 
					#include "audio/audiofifo.h"
 | 
				
			||||||
#include "util/message.h"
 | 
					#include "util/message.h"
 | 
				
			||||||
#include "util/udpsink.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "rdsparser.h"
 | 
					#include "rdsparser.h"
 | 
				
			||||||
#include "rdsdecoder.h"
 | 
					#include "rdsdecoder.h"
 | 
				
			||||||
@ -43,6 +42,7 @@
 | 
				
			|||||||
class DeviceSourceAPI;
 | 
					class DeviceSourceAPI;
 | 
				
			||||||
class ThreadedBasebandSampleSink;
 | 
					class ThreadedBasebandSampleSink;
 | 
				
			||||||
class DownChannelizer;
 | 
					class DownChannelizer;
 | 
				
			||||||
 | 
					class AudioNetSink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BFMDemod : public BasebandSampleSink, public ChannelSinkAPI {
 | 
					class BFMDemod : public BasebandSampleSink, public ChannelSinkAPI {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
@ -153,6 +153,7 @@ public:
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    RDSParser& getRDSParser() { return m_rdsParser; }
 | 
					    RDSParser& getRDSParser() { return m_rdsParser; }
 | 
				
			||||||
 | 
					    bool isAudioNetSinkRTPCapable() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static const QString m_channelIdURI;
 | 
					    static const QString m_channelIdURI;
 | 
				
			||||||
    static const QString m_channelId;
 | 
					    static const QString m_channelId;
 | 
				
			||||||
@ -221,7 +222,7 @@ private:
 | 
				
			|||||||
	static const int default_excursion = 750000; // +/- 75 kHz
 | 
						static const int default_excursion = 750000; // +/- 75 kHz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PhaseDiscriminators m_phaseDiscri;
 | 
						PhaseDiscriminators m_phaseDiscri;
 | 
				
			||||||
    UDPSink<AudioSample> *m_udpBufferAudio;
 | 
					    AudioNetSink *m_audioNetSink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static const int m_udpBlockSize;
 | 
					    static const int m_udpBlockSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -207,6 +207,12 @@ void BFMDemodGUI::on_copyAudioToUDP_toggled(bool copy)
 | 
				
			|||||||
    applySettings();
 | 
					    applySettings();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void BFMDemodGUI::on_useRTP_toggled(bool checked)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    m_settings.m_copyAudioUseRTP = checked;
 | 
				
			||||||
 | 
					    applySettings();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BFMDemodGUI::on_showPilot_clicked()
 | 
					void BFMDemodGUI::on_showPilot_clicked()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_settings.m_showPilot = ui->showPilot->isChecked();
 | 
					    m_settings.m_showPilot = ui->showPilot->isChecked();
 | 
				
			||||||
@ -383,6 +389,7 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban
 | 
				
			|||||||
	ui->g00AltFrequenciesBox->setEnabled(false);
 | 
						ui->g00AltFrequenciesBox->setEnabled(false);
 | 
				
			||||||
	ui->g14MappedFrequencies->setEnabled(false);
 | 
						ui->g14MappedFrequencies->setEnabled(false);
 | 
				
			||||||
	ui->g14AltFrequencies->setEnabled(false);
 | 
						ui->g14AltFrequencies->setEnabled(false);
 | 
				
			||||||
 | 
						ui->useRTP->setEnabled(m_bfmDemod->isAudioNetSinkRTPCapable());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rdsUpdateFixedFields();
 | 
						rdsUpdateFixedFields();
 | 
				
			||||||
	rdsUpdate(true);
 | 
						rdsUpdate(true);
 | 
				
			||||||
@ -456,6 +463,10 @@ void BFMDemodGUI::displaySettings()
 | 
				
			|||||||
    ui->rds->setChecked(m_settings.m_rdsActive);
 | 
					    ui->rds->setChecked(m_settings.m_rdsActive);
 | 
				
			||||||
    ui->copyAudioToUDP->setChecked(m_settings.m_copyAudioToUDP);
 | 
					    ui->copyAudioToUDP->setChecked(m_settings.m_copyAudioToUDP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (m_bfmDemod->isAudioNetSinkRTPCapable()) {
 | 
				
			||||||
 | 
					        ui->useRTP->setChecked(m_settings.m_copyAudioUseRTP);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    blockApplySettings(false);
 | 
					    blockApplySettings(false);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -109,6 +109,7 @@ private slots:
 | 
				
			|||||||
	void on_showPilot_clicked();
 | 
						void on_showPilot_clicked();
 | 
				
			||||||
	void on_rds_clicked();
 | 
						void on_rds_clicked();
 | 
				
			||||||
	void on_copyAudioToUDP_toggled(bool copy);
 | 
						void on_copyAudioToUDP_toggled(bool copy);
 | 
				
			||||||
 | 
					    void on_useRTP_toggled(bool checked);
 | 
				
			||||||
	void on_g14ProgServiceNames_currentIndexChanged(int index);
 | 
						void on_g14ProgServiceNames_currentIndexChanged(int index);
 | 
				
			||||||
	void on_clearData_clicked(bool checked);
 | 
						void on_clearData_clicked(bool checked);
 | 
				
			||||||
	void on_g00AltFrequenciesBox_activated(int index);
 | 
						void on_g00AltFrequenciesBox_activated(int index);
 | 
				
			||||||
 | 
				
			|||||||
@ -321,6 +321,19 @@
 | 
				
			|||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
 | 
					      <item>
 | 
				
			||||||
 | 
					       <widget class="QToolButton" name="useRTP">
 | 
				
			||||||
 | 
					        <property name="toolTip">
 | 
				
			||||||
 | 
					         <string>Use RTP protocol for copy audio to UDP</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="text">
 | 
				
			||||||
 | 
					         <string>R</string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="checkable">
 | 
				
			||||||
 | 
					         <bool>true</bool>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
 | 
					       </widget>
 | 
				
			||||||
 | 
					      </item>
 | 
				
			||||||
     </layout>
 | 
					     </layout>
 | 
				
			||||||
    </item>
 | 
					    </item>
 | 
				
			||||||
    <item>
 | 
					    <item>
 | 
				
			||||||
 | 
				
			|||||||
@ -47,6 +47,7 @@ void BFMDemodSettings::resetToDefaults()
 | 
				
			|||||||
    m_showPilot = false;
 | 
					    m_showPilot = false;
 | 
				
			||||||
    m_rdsActive = false;
 | 
					    m_rdsActive = false;
 | 
				
			||||||
    m_copyAudioToUDP = false;
 | 
					    m_copyAudioToUDP = false;
 | 
				
			||||||
 | 
					    m_copyAudioUseRTP = false;
 | 
				
			||||||
    m_udpAddress = "127.0.0.1";
 | 
					    m_udpAddress = "127.0.0.1";
 | 
				
			||||||
    m_udpPort = 9999;
 | 
					    m_udpPort = 9999;
 | 
				
			||||||
    m_rgbColor = QColor(80, 120, 228).rgb();
 | 
					    m_rgbColor = QColor(80, 120, 228).rgb();
 | 
				
			||||||
@ -75,6 +76,7 @@ QByteArray BFMDemodSettings::serialize() const
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s.writeString(12, m_title);
 | 
					    s.writeString(12, m_title);
 | 
				
			||||||
 | 
					    s.writeBool(13, m_copyAudioUseRTP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return s.final();
 | 
					    return s.final();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -123,6 +125,7 @@ bool BFMDemodSettings::deserialize(const QByteArray& data)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        d.readString(12, &m_title, "Broadcast FM Demod");
 | 
					        d.readString(12, &m_title, "Broadcast FM Demod");
 | 
				
			||||||
 | 
					        d.readBool(13, &m_copyAudioUseRTP, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,7 @@ struct BFMDemodSettings
 | 
				
			|||||||
    bool m_showPilot;
 | 
					    bool m_showPilot;
 | 
				
			||||||
    bool m_rdsActive;
 | 
					    bool m_rdsActive;
 | 
				
			||||||
    bool m_copyAudioToUDP;
 | 
					    bool m_copyAudioToUDP;
 | 
				
			||||||
 | 
					    bool m_copyAudioUseRTP;
 | 
				
			||||||
    QString m_udpAddress;
 | 
					    QString m_udpAddress;
 | 
				
			||||||
    quint16 m_udpPort;
 | 
					    quint16 m_udpPort;
 | 
				
			||||||
    quint32 m_rgbColor;
 | 
					    quint32 m_rgbColor;
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const PluginDescriptor BFMPlugin::m_pluginDescriptor = {
 | 
					const PluginDescriptor BFMPlugin::m_pluginDescriptor = {
 | 
				
			||||||
	QString("Broadcast FM Demodulator"),
 | 
						QString("Broadcast FM Demodulator"),
 | 
				
			||||||
	QString("3.10.1"),
 | 
						QString("3.12.0"),
 | 
				
			||||||
	QString("(c) Edouard Griffiths, F4EXB"),
 | 
						QString("(c) Edouard Griffiths, F4EXB"),
 | 
				
			||||||
	QString("https://github.com/f4exb/sdrangel"),
 | 
						QString("https://github.com/f4exb/sdrangel"),
 | 
				
			||||||
	true,
 | 
						true,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user