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