mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 17:58:43 -05:00
RTP support: fixed RTPSink (1)
This commit is contained in:
parent
9a3832a14f
commit
ec262caa33
@ -18,6 +18,7 @@
|
|||||||
#include "rtpsink.h"
|
#include "rtpsink.h"
|
||||||
#include "dsp/dsptypes.h"
|
#include "dsp/dsptypes.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType) :
|
RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType) :
|
||||||
m_sampleRate(48000),
|
m_sampleRate(48000),
|
||||||
@ -29,6 +30,19 @@ RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType)
|
|||||||
m_destport(port),
|
m_destport(port),
|
||||||
m_mutex(QMutex::Recursive)
|
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
|
||||||
|
// data to a remote party and we don't want to waste a port on the local machine for each possible connection that may not be used.
|
||||||
|
// Therefore we create a socket and assign it through the SetUseExistingSockets method of the RTPUDPv4TransmissionParams object
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
if (m_rtpsock < 0) {
|
||||||
|
qCritical("RTPSink::RTPSink: cannot allocate socket");
|
||||||
|
m_valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t endianTest32 = 1;
|
uint32_t endianTest32 = 1;
|
||||||
uint8_t *ptr = (uint8_t*) &endianTest32;
|
uint8_t *ptr = (uint8_t*) &endianTest32;
|
||||||
m_endianReverse = (*ptr == 1);
|
m_endianReverse = (*ptr == 1);
|
||||||
@ -37,25 +51,31 @@ RTPSink::RTPSink(const QString& address, uint16_t port, PayloadType payloadType)
|
|||||||
m_destip = ntohl(m_destip);
|
m_destip = ntohl(m_destip);
|
||||||
|
|
||||||
m_rtpSessionParams.SetOwnTimestampUnit(1.0 / (double) m_sampleRate);
|
m_rtpSessionParams.SetOwnTimestampUnit(1.0 / (double) m_sampleRate);
|
||||||
int status = m_rtpSession.Create(m_rtpSessionParams);
|
m_rtpTransmissionParams.SetUseExistingSockets(m_rtpsock, m_rtpsock);
|
||||||
|
|
||||||
|
int status = m_rtpSession.Create(m_rtpSessionParams, &m_rtpTransmissionParams);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
qCritical("RTPSink::RTPSink: cannot create session: %s", jrtplib::RTPGetErrorString(status).c_str());
|
qCritical("RTPSink::RTPSink: cannot create session: %s", jrtplib::RTPGetErrorString(status).c_str());
|
||||||
|
m_valid = false;
|
||||||
} else {
|
} else {
|
||||||
qDebug("RTPSink::RTPSink: created session: %s", jrtplib::RTPGetErrorString(status).c_str());
|
qDebug("RTPSink::RTPSink: created session: %s", jrtplib::RTPGetErrorString(status).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
setPayloadType(payloadType);
|
setPayloadType(payloadType);
|
||||||
|
m_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RTPSink::~RTPSink()
|
RTPSink::~RTPSink()
|
||||||
{
|
{
|
||||||
jrtplib::RTPTime delay = jrtplib::RTPTime(10.0);
|
jrtplib::RTPTime delay = jrtplib::RTPTime(10.0);
|
||||||
m_rtpSession.BYEDestroy(delay, "Time's up", 9);
|
m_rtpSession.sDestroy(delay, "Time's up", 9);
|
||||||
|
|
||||||
if (m_byteBuffer) {
|
if (m_byteBuffer) {
|
||||||
delete[] m_byteBuffer;
|
delete[] m_byteBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(m_rtpsock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTPSink::setPayloadType(PayloadType payloadType)
|
void RTPSink::setPayloadType(PayloadType payloadType)
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
RTPSink(const QString& address, uint16_t port, PayloadType payloadType = PayloadL16Mono);
|
RTPSink(const QString& address, uint16_t port, PayloadType payloadType = PayloadL16Mono);
|
||||||
~RTPSink();
|
~RTPSink();
|
||||||
|
|
||||||
|
bool isValid() const { return m_valid; }
|
||||||
void setPayloadType(PayloadType payloadType);
|
void setPayloadType(PayloadType payloadType);
|
||||||
|
|
||||||
void setDestination(const QString& address, uint16_t port);
|
void setDestination(const QString& address, uint16_t port);
|
||||||
@ -56,6 +57,8 @@ protected:
|
|||||||
static void writeNetBuf(uint8_t *dest, const uint8_t *src, unsigned int elemLen, unsigned int bytesLen, bool endianReverse);
|
static void writeNetBuf(uint8_t *dest, const uint8_t *src, unsigned int elemLen, unsigned int bytesLen, bool endianReverse);
|
||||||
static unsigned int elemLength(PayloadType payloadType);
|
static unsigned int elemLength(PayloadType payloadType);
|
||||||
|
|
||||||
|
int m_rtpsock;
|
||||||
|
bool m_valid;
|
||||||
PayloadType m_payloadType;
|
PayloadType m_payloadType;
|
||||||
int m_sampleRate;
|
int m_sampleRate;
|
||||||
int m_sampleBytes;
|
int m_sampleBytes;
|
||||||
|
Loading…
Reference in New Issue
Block a user