2018-01-28 19:59:03 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-19 00:43:20 -05:00
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// Copyright (C) 2015-2016, 2018-2019 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
2018-01-28 19:59:03 -05:00
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2018-01-28 19:59:03 -05:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef SDRBASE_AUDIO_AUDIONETSINK_H_
|
|
|
|
#define SDRBASE_AUDIO_AUDIONETSINK_H_
|
|
|
|
|
|
|
|
#include "dsp/dsptypes.h"
|
2019-02-14 11:21:14 -05:00
|
|
|
#include "audiofilter.h"
|
2019-02-13 01:53:38 -05:00
|
|
|
#include "audiocompressor.h"
|
2019-02-16 21:40:11 -05:00
|
|
|
#include "audiog722.h"
|
2019-02-18 12:29:37 -05:00
|
|
|
#include "audioopus.h"
|
2018-03-20 08:49:21 -04:00
|
|
|
#include "export.h"
|
2018-01-28 23:19:59 -05:00
|
|
|
|
2018-03-06 19:15:59 -05:00
|
|
|
#include <QObject>
|
2018-03-07 18:16:24 -05:00
|
|
|
#include <QHostAddress>
|
|
|
|
#include <stdint.h>
|
2018-03-06 19:15:59 -05:00
|
|
|
|
2018-03-07 18:16:24 -05:00
|
|
|
class QUdpSocket;
|
2018-01-30 18:40:54 -05:00
|
|
|
class RTPSink;
|
2018-03-05 20:23:47 -05:00
|
|
|
class QThread;
|
2018-01-28 19:59:03 -05:00
|
|
|
|
2018-03-03 14:23:38 -05:00
|
|
|
class SDRBASE_API AudioNetSink {
|
2018-01-28 19:59:03 -05:00
|
|
|
public:
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SinkUDP,
|
|
|
|
SinkRTP
|
|
|
|
} SinkType;
|
|
|
|
|
2019-02-13 01:53:38 -05:00
|
|
|
typedef enum
|
|
|
|
{
|
2019-02-13 04:34:36 -05:00
|
|
|
CodecL16, //!< Linear 16 bit samples (no formatting)
|
|
|
|
CodecL8, //!< Linear 8 bit samples
|
|
|
|
CodecPCMA, //!< PCM A-law 8 bit samples
|
2019-02-16 21:40:11 -05:00
|
|
|
CodecPCMU, //!< PCM Mu-law 8 bit samples
|
2019-02-17 20:30:43 -05:00
|
|
|
CodecG722, //!< G722 compressed 8 bit samples 16kS/s in 8kS/s out
|
|
|
|
CodecOpus //!< Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates
|
2019-02-13 01:53:38 -05:00
|
|
|
} Codec;
|
|
|
|
|
2018-03-27 03:04:10 -04:00
|
|
|
AudioNetSink(QObject *parent); //!< without RTP
|
|
|
|
AudioNetSink(QObject *parent, int sampleRate, bool stereo); //!< with RTP
|
2018-01-28 19:59:03 -05:00
|
|
|
~AudioNetSink();
|
|
|
|
|
|
|
|
void setDestination(const QString& address, uint16_t port);
|
|
|
|
void addDestination(const QString& address, uint16_t port);
|
|
|
|
void deleteDestination(const QString& address, uint16_t port);
|
2019-02-13 01:53:38 -05:00
|
|
|
void setParameters(Codec codec, bool stereo, int sampleRate);
|
2019-02-14 11:21:14 -05:00
|
|
|
void setDecimation(uint32_t decimation);
|
2018-01-28 19:59:03 -05:00
|
|
|
|
|
|
|
void write(qint16 sample);
|
2018-03-26 16:58:17 -04:00
|
|
|
void write(qint16 lSample, qint16 rSample);
|
2018-01-28 19:59:03 -05:00
|
|
|
|
2018-03-07 18:16:24 -05:00
|
|
|
bool isRTPCapable() const;
|
2018-01-28 19:59:03 -05:00
|
|
|
bool selectType(SinkType type);
|
|
|
|
|
2018-03-05 20:23:47 -05:00
|
|
|
void moveToThread(QThread *thread);
|
|
|
|
|
2018-01-28 19:59:03 -05:00
|
|
|
static const int m_udpBlockSize;
|
2019-02-17 07:32:17 -05:00
|
|
|
static const int m_dataBlockSize = 65536; // room for G722 conversion (64000 = 12800*5 largest to date)
|
|
|
|
static const int m_g722BlockSize = 12800; // number of resulting G722 bytes (80*20ms frames)
|
2019-02-18 01:57:03 -05:00
|
|
|
static const int m_opusBlockSize = 960*2; // provision for 20ms of 2 int16 channels at 48 kS/s
|
2019-02-18 12:29:37 -05:00
|
|
|
static const int m_opusOutputSize = 160; // output frame: 20ms of 8 bit data @ 64 kbits/s = 160 bytes
|
2018-01-28 19:59:03 -05:00
|
|
|
|
|
|
|
protected:
|
2019-02-18 12:29:37 -05:00
|
|
|
void setNewCodecData(); // actions to take when changes affecting codec dependent data occurs
|
|
|
|
void setDecimationFilters(); // set decimation filters limits depending on effective sample rate and codec
|
2019-02-17 07:32:17 -05:00
|
|
|
|
2018-01-28 19:59:03 -05:00
|
|
|
SinkType m_type;
|
2019-02-13 01:53:38 -05:00
|
|
|
Codec m_codec;
|
2018-03-07 18:16:24 -05:00
|
|
|
QUdpSocket *m_udpSocket;
|
2018-01-30 18:40:54 -05:00
|
|
|
RTPSink *m_rtpBufferAudio;
|
2019-02-13 01:53:38 -05:00
|
|
|
AudioCompressor m_audioCompressor;
|
2019-02-16 21:40:11 -05:00
|
|
|
AudioG722 m_g722;
|
2019-02-18 12:29:37 -05:00
|
|
|
AudioOpus m_opus;
|
2023-12-09 06:52:56 -05:00
|
|
|
AudioFilter m_audioFilterR;
|
|
|
|
AudioFilter m_audioFilterL;
|
2019-02-16 19:32:32 -05:00
|
|
|
int m_sampleRate;
|
2019-02-18 12:29:37 -05:00
|
|
|
bool m_stereo;
|
2019-02-14 11:21:14 -05:00
|
|
|
uint32_t m_decimation;
|
|
|
|
uint32_t m_decimationCount;
|
2019-02-16 21:40:11 -05:00
|
|
|
char m_data[m_dataBlockSize];
|
2019-02-18 12:29:37 -05:00
|
|
|
int16_t m_opusIn[m_opusBlockSize];
|
|
|
|
int m_codecInputSize; // codec input block size - for codecs with actual encoding (Opus only for now)
|
|
|
|
int m_codecInputIndex; // codec input block fill index
|
|
|
|
int m_codecRatio; // codec compression ratio
|
2018-03-07 18:16:24 -05:00
|
|
|
unsigned int m_bufferIndex;
|
|
|
|
QHostAddress m_address;
|
|
|
|
unsigned int m_port;
|
2018-01-28 19:59:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* SDRBASE_AUDIO_AUDIONETSINK_H_ */
|