1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-04 18:47:48 +01:00
libtgvoip/OpusDecoder.h

81 lines
2.2 KiB
C
Raw 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>
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<unsigned char*>* decodedQueue;
BufferPool* bufferPool;
2017-02-02 17:24:40 +01:00
unsigned char* buffer;
unsigned char* lastDecoded;
2018-05-15 20:23:46 +02:00
unsigned char* processedBuffer;
2017-02-02 17:24:40 +01:00
size_t outputBufferSize;
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;
2018-05-15 20:23:46 +02:00
bool async;
unsigned char nextBuffer[8192];
unsigned char decodeBuffer[8192];
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