2017-02-02 19:24:40 +03:00
|
|
|
//
|
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBTGVOIP_OPUSDECODER_H
|
|
|
|
#define LIBTGVOIP_OPUSDECODER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "MediaStreamItf.h"
|
|
|
|
#include "opus.h"
|
|
|
|
#include "threading.h"
|
|
|
|
#include "BlockingQueue.h"
|
|
|
|
#include "BufferPool.h"
|
|
|
|
#include "EchoCanceller.h"
|
|
|
|
#include "JitterBuffer.h"
|
|
|
|
#include <stdio.h>
|
2017-09-07 08:39:33 +03:00
|
|
|
#include <vector>
|
2017-02-02 19:24:40 +03:00
|
|
|
|
2017-04-28 14:17:56 +03:00
|
|
|
namespace tgvoip{
|
|
|
|
class OpusDecoder {
|
2017-02-02 19:24:40 +03:00
|
|
|
public:
|
|
|
|
virtual void Start();
|
|
|
|
|
|
|
|
virtual void Stop();
|
|
|
|
|
2018-05-15 21:23:46 +03:00
|
|
|
OpusDecoder(MediaStreamItf* dst, bool isAsync);
|
2017-04-28 14:17:56 +03:00
|
|
|
virtual ~OpusDecoder();
|
2018-05-15 21:23:46 +03:00
|
|
|
size_t HandleCallback(unsigned char* data, size_t len);
|
2017-04-28 14:17:56 +03:00
|
|
|
void SetEchoCanceller(EchoCanceller* canceller);
|
2017-02-02 19:24:40 +03:00
|
|
|
void SetFrameDuration(uint32_t duration);
|
2017-04-28 14:17:56 +03:00
|
|
|
void SetJitterBuffer(JitterBuffer* jitterBuffer);
|
2018-05-15 21:23:46 +03:00
|
|
|
void SetDTX(bool enable);
|
|
|
|
void SetLevelMeter(AudioLevelMeter* levelMeter);
|
2017-09-07 08:39:33 +03:00
|
|
|
void AddAudioEffect(AudioEffect* effect);
|
|
|
|
void RemoveAudioEffect(AudioEffect* effect);
|
2017-02-02 19:24:40 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
static size_t Callback(unsigned char* data, size_t len, void* param);
|
2018-05-15 21:23:46 +03:00
|
|
|
void RunThread(void* param);
|
|
|
|
int DecodeNextFrame();
|
2017-04-28 14:17:56 +03:00
|
|
|
::OpusDecoder* dec;
|
2017-07-03 04:42:49 +03:00
|
|
|
BlockingQueue<unsigned char*>* decodedQueue;
|
2017-04-28 14:17:56 +03:00
|
|
|
BufferPool* bufferPool;
|
2017-02-02 19:24:40 +03:00
|
|
|
unsigned char* buffer;
|
|
|
|
unsigned char* lastDecoded;
|
2018-05-15 21:23:46 +03:00
|
|
|
unsigned char* processedBuffer;
|
2017-02-02 19:24:40 +03:00
|
|
|
size_t outputBufferSize;
|
|
|
|
bool running;
|
2018-05-15 21:23:46 +03:00
|
|
|
Thread* thread;
|
|
|
|
Semaphore* semaphore;
|
2017-02-02 19:24:40 +03:00
|
|
|
uint32_t frameDuration;
|
2017-04-28 14:17:56 +03:00
|
|
|
EchoCanceller* echoCanceller;
|
|
|
|
JitterBuffer* jitterBuffer;
|
2018-05-15 21:23:46 +03:00
|
|
|
AudioLevelMeter* levelMeter;
|
|
|
|
int consecutiveLostPackets;
|
|
|
|
bool enableDTX;
|
|
|
|
size_t silentPacketCount;
|
2017-09-07 08:39:33 +03:00
|
|
|
std::vector<AudioEffect*> postProcEffects;
|
2018-05-15 21:23:46 +03:00
|
|
|
bool async;
|
|
|
|
unsigned char nextBuffer[8192];
|
|
|
|
unsigned char decodeBuffer[8192];
|
|
|
|
bool first;
|
|
|
|
size_t nextLen;
|
|
|
|
unsigned int packetsPerFrame;
|
2018-05-24 19:42:28 +03:00
|
|
|
ptrdiff_t remainingDataLen;
|
2017-02-02 19:24:40 +03:00
|
|
|
};
|
2017-04-28 14:17:56 +03:00
|
|
|
}
|
2017-02-02 19:24:40 +03:00
|
|
|
|
|
|
|
#endif //LIBTGVOIP_OPUSDECODER_H
|