From d22b5ecd056cdc71e93f28a361af2e640687c906 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 30 Mar 2018 01:19:02 +0200 Subject: [PATCH] Fixed RTP stereo --- sdrbase/audio/audionetsink.cpp | 3 +-- sdrbase/util/rtpsink.cpp | 33 +++++++++++++++++++++++++++++++++ sdrbase/util/rtpsink.h | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/sdrbase/audio/audionetsink.cpp b/sdrbase/audio/audionetsink.cpp index 8cde5dda6..5b7afd47d 100644 --- a/sdrbase/audio/audionetsink.cpp +++ b/sdrbase/audio/audionetsink.cpp @@ -148,8 +148,7 @@ void AudioNetSink::write(qint16 lSample, qint16 rSample) } else if (m_type == SinkRTP) { - m_rtpBufferAudio->write((uint8_t *) &lSample); - m_rtpBufferAudio->write((uint8_t *) &rSample); + m_rtpBufferAudio->write((uint8_t *) &lSample, (uint8_t *) &rSample); } } diff --git a/sdrbase/util/rtpsink.cpp b/sdrbase/util/rtpsink.cpp index b298d1146..71ea98cbf 100644 --- a/sdrbase/util/rtpsink.cpp +++ b/sdrbase/util/rtpsink.cpp @@ -212,6 +212,39 @@ void RTPSink::write(const uint8_t *sampleByte) } } +void RTPSink::write(const uint8_t *sampleByteL, const uint8_t *sampleByteR) +{ + QMutexLocker locker(&m_mutex); + + if (m_sampleBufferIndex < m_packetSamples) + { + writeNetBuf(&m_byteBuffer[m_sampleBufferIndex*m_sampleBytes], + sampleByteL, + elemLength(m_payloadType), + m_sampleBytes, + m_endianReverse); + writeNetBuf(&m_byteBuffer[m_sampleBufferIndex*m_sampleBytes + elemLength(m_payloadType)], + sampleByteR, + elemLength(m_payloadType), + m_sampleBytes, + m_endianReverse); + m_sampleBufferIndex++; + } + else + { + int status = m_rtpSession.SendPacket((const void *) m_byteBuffer, (std::size_t) m_bufferSize); + + if (status < 0) { + qCritical("RTPSink::write: cannot write packet: %s", qrtplib::RTPGetErrorString(status).c_str()); + } + + writeNetBuf(&m_byteBuffer[0], sampleByteL, elemLength(m_payloadType), m_sampleBytes, m_endianReverse); + writeNetBuf(&m_byteBuffer[2], sampleByteR, elemLength(m_payloadType), m_sampleBytes, m_endianReverse); + m_sampleBufferIndex = 1; + } + +} + void RTPSink::write(const uint8_t *samples, int nbSamples) { int samplesIndex = 0; diff --git a/sdrbase/util/rtpsink.h b/sdrbase/util/rtpsink.h index cdfb66093..424dca772 100644 --- a/sdrbase/util/rtpsink.h +++ b/sdrbase/util/rtpsink.h @@ -55,6 +55,7 @@ public: void addDestination(const QString& address, uint16_t port); void write(const uint8_t *sampleByte); + void write(const uint8_t *sampleByteL, const uint8_t *sampleByteR); void write(const uint8_t *sampleByte, int nbSamples); protected: