1
0
mirror of https://github.com/danog/libtgvoip.git synced 2025-01-22 21:11:36 +01:00
libtgvoip/OpusDecoder.h

72 lines
1.8 KiB
C
Raw Normal View History

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>
#include <vector>
2017-02-02 19:24:40 +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);
virtual ~OpusDecoder();
2018-05-15 21:23:46 +03:00
size_t HandleCallback(unsigned char* data, size_t len);
void SetEchoCanceller(EchoCanceller* canceller);
2017-02-02 19:24:40 +03:00
void SetFrameDuration(uint32_t duration);
void SetJitterBuffer(JitterBuffer* jitterBuffer);
2018-05-15 21:23:46 +03:00
void SetDTX(bool enable);
void SetLevelMeter(AudioLevelMeter* levelMeter);
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();
::OpusDecoder* dec;
BlockingQueue<unsigned char*>* decodedQueue;
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;
EchoCanceller* echoCanceller;
JitterBuffer* jitterBuffer;
2018-05-15 21:23:46 +03:00
AudioLevelMeter* levelMeter;
int consecutiveLostPackets;
bool enableDTX;
size_t silentPacketCount;
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-02-02 19:24:40 +03:00
#endif //LIBTGVOIP_OPUSDECODER_H