mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-27 11:00:31 -04:00 
			
		
		
		
	UDP sink: implemented multicast join. Implements #610
This commit is contained in:
		
							parent
							
								
									77051b87fd
								
							
						
					
					
						commit
						6d65bc74fc
					
				| @ -153,6 +153,8 @@ void UDPSource::applySettings(const UDPSourceSettings& settings, bool force) | ||||
|             << " m_amModFactor: " << settings.m_amModFactor | ||||
|             << " m_udpAddressStr: " << settings.m_udpAddress | ||||
|             << " m_udpPort: " << settings.m_udpPort | ||||
|             << " m_multicastAddress: " << settings.m_multicastAddress | ||||
|             << " m_multicastJoin: " << settings.m_multicastJoin | ||||
|             << " m_channelMute: " << settings.m_channelMute | ||||
|             << " m_gainIn: " << settings.m_gainIn | ||||
|             << " m_gainOut: " << settings.m_gainOut | ||||
| @ -192,6 +194,12 @@ void UDPSource::applySettings(const UDPSourceSettings& settings, bool force) | ||||
|     if ((settings.m_udpPort != m_settings.m_udpPort) || force) { | ||||
|         reverseAPIKeys.append("udpPort"); | ||||
|     } | ||||
|     if ((settings.m_multicastAddress != m_settings.m_multicastAddress) || force) { | ||||
|         reverseAPIKeys.append("multicastAddress"); | ||||
|     } | ||||
|     if ((settings.m_multicastJoin != m_settings.m_multicastJoin) || force) { | ||||
|         reverseAPIKeys.append("multicastJoin"); | ||||
|     } | ||||
|     if ((settings.m_channelMute != m_settings.m_channelMute) || force) { | ||||
|         reverseAPIKeys.append("channelMute"); | ||||
|     } | ||||
|  | ||||
| @ -162,7 +162,7 @@ UDPSourceGUI::UDPSourceGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb | ||||
|     m_channelMarker.setBandwidth(16000); | ||||
|     m_channelMarker.setCenterFrequency(0); | ||||
|     m_channelMarker.setColor(m_settings.m_rgbColor); | ||||
|     m_channelMarker.setTitle("UDP Sample Sink"); | ||||
|     m_channelMarker.setTitle("UDP Sample Source"); | ||||
|     m_channelMarker.setSourceOrSinkStream(false); | ||||
|     m_channelMarker.blockSignals(false); | ||||
|     m_channelMarker.setVisible(true); // activate signal on the last setting only
 | ||||
| @ -257,6 +257,8 @@ void UDPSourceGUI::displaySettings() | ||||
| 
 | ||||
|     ui->localUDPAddress->setText(m_settings.m_udpAddress); | ||||
|     ui->localUDPPort->setText(tr("%1").arg(m_settings.m_udpPort)); | ||||
|     ui->multicastAddress->setText(m_settings.m_multicastAddress); | ||||
|     ui->multicastJoin->setChecked(m_settings.m_multicastJoin); | ||||
| 
 | ||||
|     ui->applyBtn->setEnabled(false); | ||||
|     ui->applyBtn->setStyleSheet("QPushButton { background:rgb(79,79,79); }"); | ||||
| @ -330,6 +332,20 @@ void UDPSourceGUI::on_localUDPPort_editingFinished() | ||||
|     ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }"); | ||||
| } | ||||
| 
 | ||||
| void UDPSourceGUI::on_multicastAddress_editingFinished() | ||||
| { | ||||
|     m_settings.m_multicastAddress = ui->multicastAddress->text(); | ||||
|     ui->applyBtn->setEnabled(true); | ||||
|     ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }"); | ||||
| } | ||||
| 
 | ||||
| void UDPSourceGUI::on_multicastJoin_toggled(bool checked) | ||||
| { | ||||
|     m_settings.m_multicastJoin = checked; | ||||
|     ui->applyBtn->setEnabled(true); | ||||
|     ui->applyBtn->setStyleSheet("QPushButton { background-color : green; }"); | ||||
| } | ||||
| 
 | ||||
| void UDPSourceGUI::on_sampleRate_textEdited(const QString& arg1) | ||||
| { | ||||
|     (void) arg1; | ||||
|  | ||||
| @ -94,6 +94,8 @@ private slots: | ||||
|     void on_sampleFormat_currentIndexChanged(int index); | ||||
|     void on_localUDPAddress_editingFinished(); | ||||
|     void on_localUDPPort_editingFinished(); | ||||
|     void on_multicastAddress_editingFinished(); | ||||
|     void on_multicastJoin_toggled(bool checked); | ||||
|     void on_sampleRate_textEdited(const QString& arg1); | ||||
|     void on_rfBandwidth_textEdited(const QString& arg1); | ||||
|     void on_fmDeviation_textEdited(const QString& arg1); | ||||
|  | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -49,6 +49,8 @@ void UDPSourceSettings::resetToDefaults() | ||||
|     m_squelchEnabled = true; | ||||
|     m_udpAddress = "127.0.0.1"; | ||||
|     m_udpPort = 9998; | ||||
|     m_multicastAddress = "224.0.0.1"; | ||||
|     m_multicastJoin = false; | ||||
|     m_rgbColor = QColor(225, 25, 99).rgb(); | ||||
|     m_title = "UDP Sample Source"; | ||||
|     m_streamIndex = 0; | ||||
| @ -75,6 +77,8 @@ QByteArray UDPSourceSettings::serialize() const | ||||
|         s.writeBlob(7, m_spectrumGUI->serialize()); | ||||
|     } | ||||
| 
 | ||||
|     s.writeString(8, m_multicastAddress); | ||||
|     s.writeBool(9, m_multicastJoin); | ||||
|     s.writeS32(10, roundf(m_gainOut * 10.0)); | ||||
|     s.writeS32(11, m_fmDeviation); | ||||
|     s.writeReal(12, m_amModFactor); | ||||
| @ -139,6 +143,8 @@ bool UDPSourceSettings::deserialize(const QByteArray& data) | ||||
|             m_spectrumGUI->deserialize(bytetmp); | ||||
|         } | ||||
| 
 | ||||
|         d.readString(8, &m_multicastAddress, "224.0.0.1"); | ||||
|         d.readBool(9, &m_multicastJoin, false); | ||||
|         d.readS32(10, &s32tmp, 10); | ||||
|         m_gainOut = s32tmp / 10.0; | ||||
| 
 | ||||
| @ -167,7 +173,7 @@ bool UDPSourceSettings::deserialize(const QByteArray& data) | ||||
|             m_udpPort = 9998; | ||||
|         } | ||||
| 
 | ||||
|         d.readString(20, &m_title, "UDP Sample Sink"); | ||||
|         d.readString(20, &m_title, "UDP Sample Source"); | ||||
| 
 | ||||
|         d.readBool(21, &m_useReverseAPI, false); | ||||
|         d.readString(22, &m_reverseAPIAddress, "127.0.0.1"); | ||||
|  | ||||
| @ -56,6 +56,8 @@ struct UDPSourceSettings | ||||
| 
 | ||||
|     QString m_udpAddress; | ||||
|     uint16_t m_udpPort; | ||||
|     QString m_multicastAddress; | ||||
|     bool m_multicastJoin; | ||||
| 
 | ||||
|     QString m_title; | ||||
|     int m_streamIndex; | ||||
|  | ||||
| @ -338,6 +338,8 @@ void UDPSourceSource::applySettings(const UDPSourceSettings& settings, bool forc | ||||
|             << " m_amModFactor: " << settings.m_amModFactor | ||||
|             << " m_udpAddressStr: " << settings.m_udpAddress | ||||
|             << " m_udpPort: " << settings.m_udpPort | ||||
|             << " m_multicastAddress: " << settings.m_multicastAddress | ||||
|             << " m_multicastJoin: " << settings.m_multicastJoin | ||||
|             << " m_channelMute: " << settings.m_channelMute | ||||
|             << " m_gainIn: " << settings.m_gainIn | ||||
|             << " m_gainOut: " << settings.m_gainOut | ||||
| @ -385,9 +387,11 @@ void UDPSourceSource::applySettings(const UDPSourceSettings& settings, bool forc | ||||
|     } | ||||
| 
 | ||||
|     if ((settings.m_udpAddress != m_settings.m_udpAddress) || | ||||
|         (settings.m_udpPort != m_settings.m_udpPort) || force) | ||||
|         (settings.m_udpPort != m_settings.m_udpPort) || | ||||
|         (settings.m_multicastAddress != m_settings.m_multicastAddress) || | ||||
|         (settings.m_multicastJoin != m_settings.m_multicastJoin) || force) | ||||
|     { | ||||
|         m_udpHandler.configureUDPLink(settings.m_udpAddress, settings.m_udpPort); | ||||
|         m_udpHandler.configureUDPLink(settings.m_udpAddress, settings.m_udpPort, settings.m_multicastAddress, settings.m_multicastJoin); | ||||
|     } | ||||
| 
 | ||||
|     if ((settings.m_channelMute != m_settings.m_channelMute) || force) | ||||
|  | ||||
| @ -29,9 +29,11 @@ UDPSourceUDPHandler::UDPSourceUDPHandler() : | ||||
|     m_dataSocket(nullptr), | ||||
|     m_dataAddress(QHostAddress::LocalHost), | ||||
|     m_remoteAddress(QHostAddress::LocalHost), | ||||
|     m_multicastAddress(QStringLiteral("224.0.0.1")), | ||||
|     m_dataPort(9999), | ||||
|     m_remotePort(0), | ||||
|     m_dataConnected(false), | ||||
|     m_multicast(false), | ||||
|     m_udpDumpIndex(0), | ||||
|     m_nbUDPFrames(m_minNbUDPFrames), | ||||
|     m_nbAllocatedUDPFrames(m_minNbUDPFrames), | ||||
| @ -50,6 +52,7 @@ UDPSourceUDPHandler::UDPSourceUDPHandler() : | ||||
| 
 | ||||
| UDPSourceUDPHandler::~UDPSourceUDPHandler() | ||||
| { | ||||
|     stop(); | ||||
|     delete[] m_udpBuf; | ||||
| } | ||||
| 
 | ||||
| @ -65,9 +68,19 @@ void UDPSourceUDPHandler::start() | ||||
|     if (!m_dataConnected) | ||||
|     { | ||||
| 
 | ||||
|         if (m_dataSocket->bind(m_dataAddress, m_dataPort)) | ||||
|         if (m_dataSocket->bind(m_multicast ? QHostAddress::AnyIPv4 : m_dataAddress, m_dataPort, QUdpSocket::ShareAddress)) | ||||
|         { | ||||
|             qDebug("UDPSourceUDPHandler::start: bind data socket to %s:%d", m_dataAddress.toString().toStdString().c_str(),  m_dataPort); | ||||
| 
 | ||||
|             if (m_multicast) | ||||
|             { | ||||
|                 if (m_dataSocket->joinMulticastGroup(m_multicastAddress)) { | ||||
|                     qDebug("UDPSourceUDPHandler::start: joined multicast group %s", qPrintable(m_multicastAddress.toString())); | ||||
|                 } else { | ||||
|                     qDebug("UDPSourceUDPHandler::start: failed joining multicast group %s", qPrintable(m_multicastAddress.toString())); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             connect(m_dataSocket, SIGNAL(readyRead()), this, SLOT(dataReadyRead())); // , Qt::QueuedConnection gets stuck since Qt 5.8.0
 | ||||
|             m_dataConnected = true; | ||||
|         } | ||||
| @ -92,7 +105,7 @@ void UDPSourceUDPHandler::stop() | ||||
|     if (m_dataSocket) | ||||
|     { | ||||
|         delete m_dataSocket; | ||||
|         m_dataSocket = 0; | ||||
|         m_dataSocket = nullptr; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -224,15 +237,20 @@ void UDPSourceUDPHandler::advanceReadPointer(int nbBytes) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void UDPSourceUDPHandler::configureUDPLink(const QString& address, quint16 port) | ||||
| void UDPSourceUDPHandler::configureUDPLink(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin) | ||||
| { | ||||
|     Message* msg = MsgUDPAddressAndPort::create(address, port); | ||||
|     Message* msg = MsgUDPAddressAndPort::create(address, port, multicastAddress, multicastJoin); | ||||
|     m_inputMessageQueue.push(msg); | ||||
| } | ||||
| 
 | ||||
| void UDPSourceUDPHandler::applyUDPLink(const QString& address, quint16 port) | ||||
| void UDPSourceUDPHandler::applyUDPLink(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin) | ||||
| { | ||||
|     qDebug("UDPSourceUDPHandler::configureUDPLink: %s:%d", address.toStdString().c_str(), port); | ||||
|     qDebug() << "UDPSourceUDPHandler::configureUDPLink: " | ||||
|         << " address: " << address | ||||
|         << " port: " << port | ||||
|         << " multicastAddress: " << multicastAddress | ||||
|         << " multicastJoin: " << multicastJoin; | ||||
| 
 | ||||
|     bool addressOK = m_dataAddress.setAddress(address); | ||||
| 
 | ||||
|     if (!addressOK) | ||||
| @ -241,6 +259,15 @@ void UDPSourceUDPHandler::applyUDPLink(const QString& address, quint16 port) | ||||
|         m_dataAddress = QHostAddress::LocalHost; | ||||
|     } | ||||
| 
 | ||||
|     m_multicast = multicastJoin; | ||||
|     addressOK = m_multicastAddress.setAddress(multicastAddress); | ||||
| 
 | ||||
|     if (!addressOK) | ||||
|     { | ||||
|         qWarning("UDPSourceUDPHandler::configureUDPLink: invalid multicast address %s. disabling multicast.", address.toStdString().c_str()); | ||||
|         m_multicast = false; | ||||
|     } | ||||
| 
 | ||||
|     stop(); | ||||
|     m_dataPort = port; | ||||
|     resetReadIndex(); | ||||
| @ -291,7 +318,7 @@ bool UDPSourceUDPHandler::handleMessage(const Message& cmd) | ||||
|     if (UDPSourceUDPHandler::MsgUDPAddressAndPort::match(cmd)) | ||||
|     { | ||||
|         UDPSourceUDPHandler::MsgUDPAddressAndPort& notif = (UDPSourceUDPHandler::MsgUDPAddressAndPort&) cmd; | ||||
|         applyUDPLink(notif.getAddress(), notif.getPort()); | ||||
|         applyUDPLink(notif.getAddress(), notif.getPort(), notif.getMulticastAddress(), notif.getMulticastJoin()); | ||||
|         return true; | ||||
|     } | ||||
|     else | ||||
|  | ||||
| @ -37,7 +37,8 @@ public: | ||||
| 
 | ||||
|     void start(); | ||||
|     void stop(); | ||||
|     void configureUDPLink(const QString& address, quint16 port); | ||||
|     void configureUDPLink(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin); | ||||
|     void configureMulticastAddress(const QString& address); | ||||
|     void resetReadIndex(); | ||||
|     void resizeBuffer(float sampleRate); | ||||
| 
 | ||||
| @ -71,20 +72,26 @@ private: | ||||
|     public: | ||||
|         const QString& getAddress() const { return m_address; } | ||||
|         quint16 getPort() const { return m_port; } | ||||
|         const QString& getMulticastAddress() const { return m_multicastAddress; } | ||||
|         bool getMulticastJoin() const { return m_multicastJoin; } | ||||
| 
 | ||||
|         static MsgUDPAddressAndPort* create(QString address, quint16 port) | ||||
|         static MsgUDPAddressAndPort* create(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin) | ||||
|         { | ||||
|             return new MsgUDPAddressAndPort(address, port); | ||||
|             return new MsgUDPAddressAndPort(address, port, multicastAddress, multicastJoin); | ||||
|         } | ||||
| 
 | ||||
|     private: | ||||
|         QString m_address; | ||||
|         quint16 m_port; | ||||
|         QString m_multicastAddress; | ||||
|         bool m_multicastJoin; | ||||
| 
 | ||||
|         MsgUDPAddressAndPort(QString address, quint16 port) : | ||||
|         MsgUDPAddressAndPort(const QString& address, quint16 port, const QString& multicastAddress, bool multicastJoin) : | ||||
|             Message(), | ||||
|             m_address(address), | ||||
|             m_port(port) | ||||
|             m_port(port), | ||||
|             m_multicastAddress(multicastAddress), | ||||
|             m_multicastJoin(multicastJoin) | ||||
|         { } | ||||
|     }; | ||||
| 
 | ||||
| @ -92,15 +99,17 @@ private: | ||||
| 
 | ||||
|     void moveData(char *blk); | ||||
|     void advanceReadPointer(int nbBytes); | ||||
|     void applyUDPLink(const QString& address, quint16 port); | ||||
|     void applyUDPLink(const QString& address, quint16 port, const QString& multicastAddress, bool muticastJoin); | ||||
|     bool handleMessage(const Message& message); | ||||
| 
 | ||||
|     QUdpSocket *m_dataSocket; | ||||
|     QHostAddress m_dataAddress; | ||||
|     QHostAddress m_remoteAddress; | ||||
|     QHostAddress m_multicastAddress; | ||||
|     quint16 m_dataPort; | ||||
|     quint16 m_remotePort; | ||||
|     bool m_dataConnected; | ||||
|     bool m_multicast; | ||||
|     udpBlk_t *m_udpBuf; | ||||
|     char m_udpDump[m_udpBlockSize + 8192]; // UDP block size + largest possible block
 | ||||
|     int m_udpDumpIndex; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user