| 6 |
| 7 | #ifndef LIBTGVOIP_OPUSDECODER_H |
| 8 | #define LIBTGVOIP_OPUSDECODER_H |
| 9 |
| 10 |
| 11 | #include "MediaStreamItf.h" |
| 12 | #include "threading.h" |
| 13 | #include "BlockingQueue.h" |
| 14 | #include "Buffers.h" |
| 15 | #include "EchoCanceller.h" |
| 16 | #include "JitterBuffer.h" |
| 17 | #include "utils.h" |
| 18 | #include <stdio.h> |
| 19 | #include <vector> |
| 20 | #include <memory> |
| 21 |
| 22 | struct OpusDecoder; |
| 23 |
| 24 | namespace tgvoip{ |
| 25 | class OpusDecoder { |
| 26 | public: |
| 27 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(OpusDecoder); |
| 28 | virtual void Start(); |
| 29 |
| 30 | virtual void Stop(); |
| 31 |
| 32 | OpusDecoder(const std::shared_ptr<MediaStreamItf>& dst, bool isAsync, bool needEC); |
| 33 | OpusDecoder(const std::unique_ptr<MediaStreamItf>& dst, bool isAsync, bool needEC); |
| 34 | OpusDecoder(MediaStreamItf* dst, bool isAsync, bool needEC); |
| 35 | virtual ~OpusDecoder(); |
| 36 | size_t HandleCallback(unsigned char* data, size_t len); |
| 37 | void SetEchoCanceller(EchoCanceller* canceller); |
| 38 | void SetFrameDuration(uint32_t duration); |
| 39 | void SetJitterBuffer(std::shared_ptr<JitterBuffer> jitterBuffer); |
| 40 | void SetDTX(bool enable); |
| 41 | void SetLevelMeter(AudioLevelMeter* levelMeter); |
| 42 | void AddAudioEffect(effects::AudioEffect* effect); |
| 43 | void RemoveAudioEffect(effects::AudioEffect* effect); |
| 44 |
| 45 | private: |
| 46 | void Initialize(bool isAsync, bool needEC); |
| 47 | static size_t Callback(unsigned char* data, size_t len, void* param); |
| 48 | void RunThread(); |
| 49 | int DecodeNextFrame(); |
| 50 | ::OpusDecoder* dec; |
| 51 | ::OpusDecoder* ecDec; |
| 52 | BlockingQueue<unsigned char*>* decodedQueue; |
| 53 | BufferPool* bufferPool; |
| 54 | unsigned char* buffer; |
| 55 | unsigned char* lastDecoded; |
| 56 | unsigned char* processedBuffer; |
| 57 | size_t outputBufferSize; |
| 58 | bool running; |
| 59 | Thread* thread; |
| 60 | Semaphore* semaphore; |
| 61 | uint32_t frameDuration; |
| 62 | EchoCanceller* echoCanceller; |
| 63 | std::shared_ptr<JitterBuffer> jitterBuffer; |
| 64 | AudioLevelMeter* levelMeter; |
| 65 | int consecutiveLostPackets; |
| 66 | bool enableDTX; |
| 67 | size_t silentPacketCount; |
| 68 | std::vector<effects::AudioEffect*> postProcEffects; |
| 69 | bool async; |
| 70 | unsigned char nextBuffer[8192]; |
| 71 | unsigned char decodeBuffer[8192]; |
| 72 | size_t nextLen; |
| 73 | unsigned int packetsPerFrame; |
| 74 | ptrdiff_t remainingDataLen; |
| 75 | bool prevWasEC; |
| 76 | int16_t prevLastSample; |
| 77 | }; |
| 78 | } |
| 79 |
| 80 | #endif //LIBTGVOIP_OPUSDECODER_H |
| 81 |