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 "opus.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 <stdint.h>
|
|
|
|
|
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-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);
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
static size_t Callback(unsigned char* data, size_t len, void* param);
|
2018-05-15 20:23:46 +02:00
|
|
|
void RunThread(void* arg);
|
2017-02-02 17:24:40 +01:00
|
|
|
void Encode(unsigned char* 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;
|
|
|
|
|
|
|
|
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
|