mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 13:00:26 -04:00 
			
		
		
		
	RTP support: fixed RTPSink with a new version of the JRTPlib library
This commit is contained in:
		
							parent
							
								
									de2f47dd85
								
							
						
					
					
						commit
						9f220f182c
					
				| @ -426,6 +426,7 @@ void NFMDemod::applySettings(const NFMDemodSettings& settings, bool force) | ||||
|             << " m_ctcssOn: " << settings.m_ctcssOn | ||||
|             << " m_audioMute: " << settings.m_audioMute | ||||
|             << " m_copyAudioToUDP: " << settings.m_copyAudioToUDP | ||||
|             << " m_copyAudioUseRTP: " << settings.m_copyAudioUseRTP | ||||
|             << " m_udpAddress: " << settings.m_udpAddress | ||||
|             << " m_udpPort: " << settings.m_udpPort | ||||
|             << " force: " << force; | ||||
|  | ||||
| @ -18,9 +18,9 @@ | ||||
| #include "rtpsink.h" | ||||
| #include "dsp/dsptypes.h" | ||||
| #include <algorithm> | ||||
| #include <sys/socket.h> | ||||
| 
 | ||||
| RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType) : | ||||
|     m_payloadType(payloadType), | ||||
|     m_sampleRate(48000), | ||||
|     m_sampleBytes(0), | ||||
|     m_packetSamples(0), | ||||
| @ -28,6 +28,7 @@ RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType) | ||||
|     m_sampleBufferIndex(0), | ||||
|     m_byteBuffer(0), | ||||
|     m_destport(port), | ||||
|     m_rtpTransmitter(&m_rtpMemoryManager), | ||||
|     m_mutex(QMutex::Recursive) | ||||
| { | ||||
| 	// Here we use JRTPLIB in a bit funny way since we do not want the socket to bind because we are only sending
 | ||||
| @ -36,25 +37,21 @@ RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType) | ||||
| 	// By doing this the socket is left unbound but sending RTP packets with the library is still possible. Other functions may
 | ||||
| 	// not work but we don't care
 | ||||
| 
 | ||||
| 	m_rtpsock = socket(PF_INET,SOCK_DGRAM,0); | ||||
| 	m_rtpSessionParams.SetOwnTimestampUnit(1.0 / (double) m_sampleRate); | ||||
|     m_rtpTransmissionParams.SetRTCPMultiplexing(true); // do not allocate another socket for RTCP
 | ||||
| 
 | ||||
| 	if (m_rtpsock < 0) { | ||||
| 		qCritical("RTPSink::RTPSink: cannot allocate socket"); | ||||
| 		m_valid = false; | ||||
| 	} | ||||
|     int status = m_rtpTransmitter.Init(false); | ||||
|     if (status < 0) { | ||||
|         qCritical("RTPSink::RTPSink: cannot initialize transmitter: %s", jrtplib::RTPGetErrorString(status).c_str()); | ||||
|         m_valid = false; | ||||
|     } else { | ||||
|         qDebug("RTPSink::RTPSink: initialized transmitter: %s", jrtplib::RTPGetErrorString(status).c_str()); | ||||
|     } | ||||
| 
 | ||||
|     uint32_t endianTest32 = 1; | ||||
|     uint8_t *ptr = (uint8_t*) &endianTest32; | ||||
|     m_endianReverse = (*ptr == 1); | ||||
| 
 | ||||
|     m_destip = inet_addr(address.toStdString().c_str()); | ||||
|     m_destip = ntohl(m_destip); | ||||
| 
 | ||||
|     m_rtpSessionParams.SetOwnTimestampUnit(1.0 / (double) m_sampleRate); | ||||
|     m_rtpTransmissionParams.SetUseExistingSockets(m_rtpsock, m_rtpsock); | ||||
| 
 | ||||
|     int status = m_rtpSession.Create(m_rtpSessionParams, &m_rtpTransmissionParams); | ||||
|     m_rtpTransmitter.Create(m_rtpSessionParams.GetMaximumPacketSize(), &m_rtpTransmissionParams); | ||||
|     qDebug("RTPSink::RTPSink: created transmitter: %s", jrtplib::RTPGetErrorString(status).c_str()); | ||||
| 
 | ||||
|     status = m_rtpSession.Create(m_rtpSessionParams, &m_rtpTransmitter); | ||||
|     if (status < 0) { | ||||
|         qCritical("RTPSink::RTPSink: cannot create session: %s", jrtplib::RTPGetErrorString(status).c_str()); | ||||
|         m_valid = false; | ||||
| @ -64,6 +61,14 @@ RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType) | ||||
| 
 | ||||
|     setPayloadType(payloadType); | ||||
|     m_valid = true; | ||||
| 
 | ||||
|     uint32_t endianTest32 = 1; | ||||
|     uint8_t *ptr = (uint8_t*) &endianTest32; | ||||
|     m_endianReverse = (*ptr == 1); | ||||
| 
 | ||||
|     m_destip = inet_addr(address.toStdString().c_str()); | ||||
|     m_destip = ntohl(m_destip); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| RTPSink::~RTPSink() | ||||
|  | ||||
| @ -20,16 +20,47 @@ | ||||
| 
 | ||||
| #include <QString> | ||||
| #include <QMutex> | ||||
| #include <QDebug> | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| // jrtplib includes
 | ||||
| #include "rtpsession.h" | ||||
| #include "rtpudpv4transmitter.h" | ||||
| #include "rtpudpv4transmitternobind.h" | ||||
| #include "rtpipv4address.h" | ||||
| #include "rtpsessionparams.h" | ||||
| #include "rtperrors.h" | ||||
| #include "rtplibraryversion.h" | ||||
| 
 | ||||
| class RTPSinkMemoryManager : public jrtplib::RTPMemoryManager | ||||
| { | ||||
| public: | ||||
|     RTPSinkMemoryManager() | ||||
|     { | ||||
|         alloccount = 0; | ||||
|         freecount = 0; | ||||
|     } | ||||
|     ~RTPSinkMemoryManager() | ||||
|     { | ||||
|         qDebug() << "RTPSinkMemoryManager::~RTPSinkMemoryManager: alloc: " << alloccount << " free: " << freecount; | ||||
|     } | ||||
|     void *AllocateBuffer(size_t numbytes, int memtype) | ||||
|     { | ||||
|         void *buf = malloc(numbytes); | ||||
|         qDebug() << "RTPSinkMemoryManager::AllocateBuffer: Allocated " << numbytes << " bytes at location " << buf << " (memtype = " << memtype << ")"; | ||||
|         alloccount++; | ||||
|         return buf; | ||||
|     } | ||||
| 
 | ||||
|     void FreeBuffer(void *p) | ||||
|     { | ||||
|         qDebug() << "RTPSinkMemoryManager::FreeBuffer: Freeing block " << p; | ||||
|         freecount++; | ||||
|         free(p); | ||||
|     } | ||||
| private: | ||||
|     int alloccount,freecount; | ||||
| }; | ||||
| 
 | ||||
| class RTPSink | ||||
| { | ||||
| public: | ||||
| @ -57,7 +88,6 @@ protected: | ||||
|     static void writeNetBuf(uint8_t *dest, const uint8_t *src, unsigned int elemLen, unsigned int bytesLen, bool endianReverse); | ||||
|     static unsigned int elemLength(PayloadType payloadType); | ||||
| 
 | ||||
|     int m_rtpsock; | ||||
|     bool m_valid; | ||||
|     PayloadType m_payloadType; | ||||
|     int m_sampleRate; | ||||
| @ -70,7 +100,9 @@ protected: | ||||
|     uint16_t m_destport; | ||||
|     jrtplib::RTPSession m_rtpSession; | ||||
|     jrtplib::RTPSessionParams m_rtpSessionParams; | ||||
|     jrtplib::RTPUDPv4TransmissionParams m_rtpTransmissionParams; | ||||
|     jrtplib::RTPUDPv4TransmissionNoBindParams m_rtpTransmissionParams; | ||||
|     jrtplib::RTPUDPv4TransmitterNoBind m_rtpTransmitter; | ||||
|     RTPSinkMemoryManager m_rtpMemoryManager; | ||||
|     bool m_endianReverse; | ||||
|     QMutex m_mutex; | ||||
| }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user