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_OPUSENCODER_H
|
|
|
|
#define LIBTGVOIP_OPUSENCODER_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"
|
2018-11-09 16:44:01 +01:00
|
|
|
#include "utils.h"
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-07-17 18:48:21 +02:00
|
|
|
struct OpusEncoder;
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
namespace tgvoip{
|
2018-06-04 21:37:43 +02:00
|
|
|
class OpusEncoder{
|
2017-02-02 17:24:40 +01:00
|
|
|
public:
|
2018-11-09 16:44:01 +01:00
|
|
|
TGVOIP_DISALLOW_COPY_AND_ASSIGN(OpusEncoder);
|
2018-06-04 21:37:43 +02:00
|
|
|
OpusEncoder(MediaStreamItf* source, bool needSecondary);
|
2017-04-28 13:17:56 +02:00
|
|
|
virtual ~OpusEncoder();
|
2017-02-02 17:24:40 +01:00
|
|
|
virtual void Start();
|
|
|
|
virtual void Stop();
|
|
|
|
void SetBitrate(uint32_t bitrate);
|
2017-04-28 13:17:56 +02:00
|
|
|
void SetEchoCanceller(EchoCanceller* aec);
|
2017-02-02 17:24:40 +01:00
|
|
|
void SetOutputFrameDuration(uint32_t duration);
|
|
|
|
void SetPacketLoss(int percent);
|
2017-03-30 16:06:59 +02:00
|
|
|
int GetPacketLoss();
|
2017-02-02 17:24:40 +01:00
|
|
|
uint32_t GetBitrate();
|
2018-05-15 20:23:46 +02:00
|
|
|
void SetDTX(bool enable);
|
|
|
|
void SetLevelMeter(AudioLevelMeter* levelMeter);
|
2018-06-04 21:37:43 +02:00
|
|
|
void SetCallback(void (*f)(unsigned char*, size_t, unsigned char*, size_t, void*), void* param);
|
|
|
|
void SetSecondaryEncoderEnabled(bool enabled);
|
2018-11-30 13:39:31 +01:00
|
|
|
void SetVadMode(bool vad);
|
2018-12-30 00:24:55 +01:00
|
|
|
void AddAudioEffect(effects::AudioEffect* effect);
|
|
|
|
void RemoveAudioEffect(effects::AudioEffect* effect);
|
2019-02-11 17:01:45 +01:00
|
|
|
int GetComplexity(){
|
|
|
|
return complexity;
|
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
static size_t Callback(unsigned char* data, size_t len, void* param);
|
2018-11-09 16:44:01 +01:00
|
|
|
void RunThread();
|
2018-11-21 19:22:31 +01:00
|
|
|
void Encode(int16_t* data, size_t len);
|
2018-06-04 21:37:43 +02:00
|
|
|
void InvokeCallback(unsigned char* data, size_t length, unsigned char* secondaryData, size_t secondaryLength);
|
2017-04-28 13:17:56 +02:00
|
|
|
MediaStreamItf* source;
|
|
|
|
::OpusEncoder* enc;
|
2018-06-04 21:37:43 +02:00
|
|
|
::OpusEncoder* secondaryEncoder;
|
2017-02-02 17:24:40 +01:00
|
|
|
unsigned char buffer[4096];
|
|
|
|
uint32_t requestedBitrate;
|
|
|
|
uint32_t currentBitrate;
|
2018-05-15 20:23:46 +02:00
|
|
|
Thread* thread;
|
2017-07-03 03:42:49 +02:00
|
|
|
BlockingQueue<unsigned char*> queue;
|
2017-04-28 13:17:56 +02:00
|
|
|
BufferPool bufferPool;
|
|
|
|
EchoCanceller* echoCanceller;
|
2017-02-02 17:24:40 +01:00
|
|
|
int complexity;
|
|
|
|
bool running;
|
|
|
|
uint32_t frameDuration;
|
2017-03-30 16:06:59 +02:00
|
|
|
int packetLossPercent;
|
|
|
|
uint32_t mediumCorrectionBitrate;
|
|
|
|
uint32_t strongCorrectionBitrate;
|
|
|
|
double mediumCorrectionMultiplier;
|
|
|
|
double strongCorrectionMultiplier;
|
2018-05-15 20:23:46 +02:00
|
|
|
AudioLevelMeter* levelMeter;
|
2018-06-04 21:37:43 +02:00
|
|
|
bool secondaryEncoderEnabled;
|
2018-11-30 13:39:31 +01:00
|
|
|
bool vadMode=false;
|
|
|
|
uint32_t vadNoVoiceBitrate;
|
2018-12-30 00:24:55 +01:00
|
|
|
std::vector<effects::AudioEffect*> postProcEffects;
|
2019-02-19 22:48:36 +01:00
|
|
|
int secondaryEnabledBandwidth;
|
|
|
|
int vadModeVoiceBandwidth;
|
|
|
|
int vadModeNoVoiceBandwidth;
|
|
|
|
|
|
|
|
bool wasSecondaryEncoderEnabled=false;
|
2018-06-04 21:37:43 +02:00
|
|
|
|
|
|
|
void (*callback)(unsigned char*, size_t, unsigned char*, size_t, void*);
|
|
|
|
void* callbackParam;
|
2017-02-02 17:24:40 +01:00
|
|
|
};
|
2017-04-28 13:17:56 +02:00
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
#endif //LIBTGVOIP_OPUSENCODER_H
|