forked from telegramdesktop/libtgvoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpusEncoder.h
executable file
·88 lines (75 loc) · 2.33 KB
/
OpusEncoder.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
79
80
81
82
83
84
85
86
87
88
//
// 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_OPUSENCODER_H
#define LIBTGVOIP_OPUSENCODER_H
#include "MediaStreamItf.h"
#include "threading.h"
#include "BlockingQueue.h"
#include "Buffers.h"
#include "utils.h"
#include <stdint.h>
struct OpusEncoder;
namespace tgvoip{
class EchoCanceller;
namespace effects {
class AudioEffect;
} // namespace effects
class OpusEncoder{
public:
TGVOIP_DISALLOW_COPY_AND_ASSIGN(OpusEncoder);
OpusEncoder(MediaStreamItf* source, bool needSecondary);
virtual ~OpusEncoder();
virtual void Start();
virtual void Stop();
void SetBitrate(uint32_t bitrate);
void SetEchoCanceller(EchoCanceller* aec);
void SetOutputFrameDuration(uint32_t duration);
void SetPacketLoss(int percent);
int GetPacketLoss();
uint32_t GetBitrate();
void SetDTX(bool enable);
void SetLevelMeter(AudioLevelMeter* levelMeter);
void SetCallback(void (*f)(unsigned char*, size_t, unsigned char*, size_t, void*), void* param);
void SetSecondaryEncoderEnabled(bool enabled);
void SetVadMode(bool vad);
void AddAudioEffect(effects::AudioEffect* effect);
void RemoveAudioEffect(effects::AudioEffect* effect);
int GetComplexity(){
return complexity;
}
private:
static size_t Callback(unsigned char* data, size_t len, void* param);
void RunThread();
void Encode(int16_t* data, size_t len);
void InvokeCallback(unsigned char* data, size_t length, unsigned char* secondaryData, size_t secondaryLength);
MediaStreamItf* source;
::OpusEncoder* enc;
::OpusEncoder* secondaryEncoder;
unsigned char buffer[4096];
uint32_t requestedBitrate;
uint32_t currentBitrate;
Thread* thread;
BlockingQueue<unsigned char*> queue;
BufferPool bufferPool;
EchoCanceller* echoCanceller;
int complexity;
bool running;
uint32_t frameDuration;
int packetLossPercent;
AudioLevelMeter* levelMeter;
bool secondaryEncoderEnabled;
bool vadMode=false;
uint32_t vadNoVoiceBitrate;
std::vector<effects::AudioEffect*> postProcEffects;
int secondaryEnabledBandwidth;
int vadModeVoiceBandwidth;
int vadModeNoVoiceBandwidth;
bool wasSecondaryEncoderEnabled=false;
void (*callback)(unsigned char*, size_t, unsigned char*, size_t, void*);
void* callbackParam;
};
}
#endif //LIBTGVOIP_OPUSENCODER_H