1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-26 20:24:38 +01:00
libtgvoip/OpusDecoder.h

82 lines
2.3 KiB
C
Raw Permalink Normal View History

2017-02-02 17:24:40 +01: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 "threading.h"
#include "BlockingQueue.h"
2018-06-04 21:37:43 +02:00
#include "Buffers.h"
2017-02-02 17:24:40 +01:00
#include "EchoCanceller.h"
#include "JitterBuffer.h"
#include "utils.h"
2017-02-02 17:24:40 +01:00
#include <stdio.h>
#include <vector>
2018-06-04 21:37:43 +02:00
#include <memory>
#include <atomic>
2017-02-02 17:24:40 +01:00
struct OpusDecoder;
namespace tgvoip{
class OpusDecoder {
2017-02-02 17:24:40 +01:00
public:
TGVOIP_DISALLOW_COPY_AND_ASSIGN(OpusDecoder);
2017-02-02 17:24:40 +01:00
virtual void Start();
virtual void Stop();
2018-06-04 21:37:43 +02:00
OpusDecoder(const std::shared_ptr<MediaStreamItf>& dst, bool isAsync, bool needEC);
OpusDecoder(const std::unique_ptr<MediaStreamItf>& dst, bool isAsync, bool needEC);
OpusDecoder(MediaStreamItf* dst, bool isAsync, bool needEC);
virtual ~OpusDecoder();
2018-05-15 20:23:46 +02:00
size_t HandleCallback(unsigned char* data, size_t len);
void SetEchoCanceller(EchoCanceller* canceller);
2017-02-02 17:24:40 +01:00
void SetFrameDuration(uint32_t duration);
2018-06-04 21:37:43 +02:00
void SetJitterBuffer(std::shared_ptr<JitterBuffer> jitterBuffer);
2018-05-15 20:23:46 +02:00
void SetDTX(bool enable);
void SetLevelMeter(AudioLevelMeter* levelMeter);
void AddAudioEffect(effects::AudioEffect* effect);
void RemoveAudioEffect(effects::AudioEffect* effect);
2017-02-02 17:24:40 +01:00
private:
2018-06-04 21:37:43 +02:00
void Initialize(bool isAsync, bool needEC);
2017-02-02 17:24:40 +01:00
static size_t Callback(unsigned char* data, size_t len, void* param);
void RunThread();
2018-05-15 20:23:46 +02:00
int DecodeNextFrame();
::OpusDecoder* dec;
2018-06-04 21:37:43 +02:00
::OpusDecoder* ecDec;
BlockingQueue<Buffer>* decodedQueue;
BufferPool<960*2, 32> bufferPool;
2017-02-02 17:24:40 +01:00
unsigned char* buffer;
unsigned char* lastDecoded;
unsigned char* processedBuffer;
2017-02-02 17:24:40 +01:00
size_t outputBufferSize;
std::atomic<bool> running;
2018-05-15 20:23:46 +02:00
Thread* thread;
Semaphore* semaphore;
2017-02-02 17:24:40 +01:00
uint32_t frameDuration;
EchoCanceller* echoCanceller;
2018-06-04 21:37:43 +02:00
std::shared_ptr<JitterBuffer> jitterBuffer;
2018-05-15 20:23:46 +02:00
AudioLevelMeter* levelMeter;
int consecutiveLostPackets;
bool enableDTX;
size_t silentPacketCount;
std::vector<effects::AudioEffect*> postProcEffects;
std::atomic<bool> async;
alignas(2) unsigned char nextBuffer[8192];
alignas(2) unsigned char decodeBuffer[8192];
2018-05-15 20:23:46 +02:00
size_t nextLen;
unsigned int packetsPerFrame;
2018-05-24 18:42:28 +02:00
ptrdiff_t remainingDataLen;
2018-06-04 21:37:43 +02:00
bool prevWasEC;
int16_t prevLastSample;
2017-02-02 17:24:40 +01:00
};
}
2017-02-02 17:24:40 +01:00
#endif //LIBTGVOIP_OPUSDECODER_H