1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-27 04:34:42 +01:00
libtgvoip/OpusEncoder.h

73 lines
2.0 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_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"
#include "utils.h"
2017-02-02 17:24:40 +01:00
#include <stdint.h>
struct OpusEncoder;
namespace tgvoip{
2018-06-04 21:37:43 +02:00
class OpusEncoder{
2017-02-02 17:24:40 +01:00
public:
TGVOIP_DISALLOW_COPY_AND_ASSIGN(OpusEncoder);
2018-06-04 21:37:43 +02:00
OpusEncoder(MediaStreamItf* source, bool needSecondary);
virtual ~OpusEncoder();
2017-02-02 17:24:40 +01:00
virtual void Start();
virtual void Stop();
void SetBitrate(uint32_t bitrate);
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);
void RunThread();
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);
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;
BlockingQueue<unsigned char*> queue;
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-02-02 17:24:40 +01:00
#endif //LIBTGVOIP_OPUSENCODER_H