1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

Copy audio to UDP/RTP: Opus implementation (5)

This commit is contained in:
f4exb 2019-02-19 02:07:26 +01:00
parent 0aaab42f95
commit bd48a2feb5
5 changed files with 16 additions and 4 deletions

View File

@ -175,6 +175,8 @@ void AudioNetSink::setNewCodecData()
<< " Fs: " << m_sampleRate/m_decimation
<< " stereo: " << m_stereo;
m_opus.setEncoder(m_sampleRate/m_decimation, m_stereo ? 2 : 1);
m_codecInputIndex = 0;
m_bufferIndex = 0;
}
setDecimationFilters();

View File

@ -20,12 +20,14 @@
#include "opus/opus.h"
#include <QDebug>
#include <QMutexLocker>
#include "audioopus.h"
AudioOpus::AudioOpus() :
m_encoderState(0),
m_encoderOK(false)
m_encoderOK(false),
m_mutex(QMutex::Recursive)
{
qDebug("AudioOpus::AudioOpus: libopus version %s", opus_get_version_string());
}
@ -41,6 +43,7 @@ void AudioOpus::setEncoder(int32_t fs, int nChannels)
{
int error;
bool newInstance = true;
QMutexLocker mutexLocker(&m_mutex);
if (m_encoderState)
{
@ -85,6 +88,8 @@ void AudioOpus::setEncoder(int32_t fs, int nChannels)
int AudioOpus::encode(int frameSize, int16_t *in, uint8_t *out)
{
QMutexLocker mutexLocker(&m_mutex);
int nbBytes = opus_encode(m_encoderState, in, frameSize, out, m_maxPacketSize);
if (nbBytes < 0)

View File

@ -19,6 +19,7 @@
#define SDRBASE_AUDIO_AUDIOOPUS_H_
#include <stdint.h>
#include <QMutex>
#include "export.h"
class OpusEncoder;
@ -38,6 +39,7 @@ public:
private:
OpusEncoder *m_encoderState;
bool m_encoderOK;
QMutex m_mutex;
};
#endif /* SDRBASE_AUDIO_AUDIOOPUS_H_ */

View File

@ -129,12 +129,13 @@ m=audio 9998 RTP/AVP 9
a=rtpmap:9 G722/8000/1
```
For Opus mono:
For Opus mono or stereo:
```
c=IN IP4 192.168.0.34
m=audio 9998 RTP/AVP 101
a=rtpmap:101 opus/48000/1
m=audio 9998 RTP/AVP 96
a=rtpmap:96 opus/48000/2
a=fmtp:96 cbr=1
```
&#9758; Note that on Android clients VLC has trouble working with the RTP stream (choppy audio, hanging unexpectedly...) therefore [MX player](https://play.google.com/store/apps/details?id=com.mxtech.videoplayer.ad&hl=en) is recommended.

View File

@ -317,6 +317,8 @@ void AudioDialogX::updateOutputSDPString()
break;
case AudioOutput::UDPCodecOpus:
format = "opus";
nChannels = 2; // always 2 even for mono
effectiveSampleRate = 48000; // always 48000 regardless of input rate
break;
case AudioOutput::UDPCodecL16:
default: