| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2018 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01: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 17:21:14 +01:00
										 |  |  | #include "audiofilter.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-13 07:53:38 +01:00
										 |  |  | #include "audiocompressor.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  | #include "audiog722.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01:00
										 |  |  | #include "audioopus.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2018-01-29 05:19:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-07 01:15:59 +01:00
										 |  |  | #include <QObject>
 | 
					
						
							| 
									
										
										
										
											2018-03-08 00:16:24 +01:00
										 |  |  | #include <QHostAddress>
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							| 
									
										
										
										
											2018-03-07 01:15:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-08 00:16:24 +01:00
										 |  |  | class QUdpSocket; | 
					
						
							| 
									
										
										
										
											2018-01-31 00:40:54 +01:00
										 |  |  | class RTPSink; | 
					
						
							| 
									
										
										
										
											2018-03-06 02:23:47 +01:00
										 |  |  | class QThread; | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class SDRBASE_API AudioNetSink { | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | public: | 
					
						
							|  |  |  |     typedef enum | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         SinkUDP, | 
					
						
							|  |  |  |         SinkRTP | 
					
						
							|  |  |  |     } SinkType; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-13 07:53:38 +01:00
										 |  |  |     typedef enum | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-02-13 10:34:36 +01:00
										 |  |  |         CodecL16,  //!< Linear 16 bit samples (no formatting)
 | 
					
						
							|  |  |  |         CodecL8,   //!< Linear 8 bit samples
 | 
					
						
							|  |  |  |         CodecPCMA, //!< PCM A-law 8 bit samples
 | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  |         CodecPCMU, //!< PCM Mu-law 8 bit samples
 | 
					
						
							| 
									
										
										
										
											2019-02-18 02:30:43 +01: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 07:53:38 +01:00
										 |  |  |     } Codec; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 09:04:10 +02:00
										 |  |  |     AudioNetSink(QObject *parent); //!< without RTP
 | 
					
						
							|  |  |  |     AudioNetSink(QObject *parent, int sampleRate, bool stereo); //!< with RTP
 | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01: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 07:53:38 +01:00
										 |  |  |     void setParameters(Codec codec, bool stereo, int sampleRate); | 
					
						
							| 
									
										
										
										
											2019-02-14 17:21:14 +01:00
										 |  |  |     void setDecimation(uint32_t decimation); | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void write(qint16 sample); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:58:17 +02:00
										 |  |  |     void write(qint16 lSample, qint16 rSample); | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-08 00:16:24 +01:00
										 |  |  |     bool isRTPCapable() const; | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  |     bool selectType(SinkType type); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 02:23:47 +01:00
										 |  |  |     void moveToThread(QThread *thread); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  |     static const int m_udpBlockSize; | 
					
						
							| 
									
										
										
										
											2019-02-17 13:32:17 +01: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 07:57:03 +01:00
										 |  |  |     static const int m_opusBlockSize = 960*2; // provision for 20ms of 2 int16 channels at 48 kS/s
 | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01:00
										 |  |  |     static const int m_opusOutputSize = 160;  // output frame: 20ms of 8 bit data @ 64 kbits/s = 160 bytes
 | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01: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 13:32:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  |     SinkType m_type; | 
					
						
							| 
									
										
										
										
											2019-02-13 07:53:38 +01:00
										 |  |  |     Codec m_codec; | 
					
						
							| 
									
										
										
										
											2018-03-08 00:16:24 +01:00
										 |  |  |     QUdpSocket *m_udpSocket; | 
					
						
							| 
									
										
										
										
											2018-01-31 00:40:54 +01:00
										 |  |  |     RTPSink *m_rtpBufferAudio; | 
					
						
							| 
									
										
										
										
											2019-02-13 07:53:38 +01:00
										 |  |  |     AudioCompressor m_audioCompressor; | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  |     AudioG722 m_g722; | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01:00
										 |  |  |     AudioOpus m_opus; | 
					
						
							| 
									
										
										
										
											2019-02-14 17:21:14 +01:00
										 |  |  |     AudioFilter m_audioFilter; | 
					
						
							| 
									
										
										
										
											2019-02-17 01:32:32 +01:00
										 |  |  |     int m_sampleRate; | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01:00
										 |  |  |     bool m_stereo; | 
					
						
							| 
									
										
										
										
											2019-02-14 17:21:14 +01:00
										 |  |  |     uint32_t m_decimation; | 
					
						
							|  |  |  |     uint32_t m_decimationCount; | 
					
						
							| 
									
										
										
										
											2019-02-17 03:40:11 +01:00
										 |  |  |     char m_data[m_dataBlockSize]; | 
					
						
							| 
									
										
										
										
											2019-02-18 18:29:37 +01: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-08 00:16:24 +01:00
										 |  |  |     unsigned int m_bufferIndex; | 
					
						
							|  |  |  |     QHostAddress m_address; | 
					
						
							|  |  |  |     unsigned int m_port; | 
					
						
							| 
									
										
										
										
											2018-01-29 01:59:03 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* SDRBASE_AUDIO_AUDIONETSINK_H_ */
 |