1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-11-27 04:34:42 +01:00
libtgvoip/OpusEncoder.h
Grishka 5380aaba0d 2.2
- Refactored audio I/O to allow sharing a common context between input and output, for those OSes that require this
- Rewritten periodic operation handling to use a "run loop" thingy instead of an ugly loop formerly known as tick thread
- Fixed a bunch of compiler warnings (closes #13)
- Added automake so you no longer need to use the GYP file for standalone builds (closes #43)
2018-07-17 19:48:21 +03:00

71 lines
2.0 KiB
C++

//
// 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 "EchoCanceller.h"
#include <stdint.h>
struct OpusEncoder;
namespace tgvoip{
class OpusEncoder{
public:
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);
private:
static size_t Callback(unsigned char* data, size_t len, void* param);
void RunThread(void* arg);
void Encode(unsigned char* 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;
uint32_t mediumCorrectionBitrate;
uint32_t strongCorrectionBitrate;
double mediumCorrectionMultiplier;
double strongCorrectionMultiplier;
AudioLevelMeter* levelMeter;
bool secondaryEncoderEnabled;
void (*callback)(unsigned char*, size_t, unsigned char*, size_t, void*);
void* callbackParam;
};
}
#endif //LIBTGVOIP_OPUSENCODER_H