1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-03 10:07:45 +01:00
libtgvoip/OpusEncoder.h

83 lines
2.3 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>
#include <atomic>
2017-02-02 17:24:40 +01:00
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);
void SetCallback(std::function <void(unsigned char*, size_t, unsigned char*, size_t)> callback);
2018-06-04 21:37:43 +02:00
void SetSecondaryEncoderEnabled(bool enabled);
2018-11-30 13:39:31 +01:00
void SetVadMode(bool vad);
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);
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];
std::atomic<uint32_t> requestedBitrate;
2017-02-02 17:24:40 +01:00
uint32_t currentBitrate;
2018-05-15 20:23:46 +02:00
Thread* thread;
BlockingQueue<Buffer> queue;
BufferPool<960*2, 10> bufferPool;
EchoCanceller* echoCanceller;
std::atomic<int> complexity;
std::atomic<bool> running;
2017-02-02 17:24:40 +01:00
uint32_t frameDuration;
2017-03-30 16:06:59 +02:00
int packetLossPercent;
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;
std::vector<effects::AudioEffect*> postProcEffects;
int secondaryEnabledBandwidth;
int vadModeVoiceBandwidth;
int vadModeNoVoiceBandwidth;
bool wasSecondaryEncoderEnabled=false;
2018-06-04 21:37:43 +02:00
std::function <void(unsigned char*, size_t, unsigned char*, size_t)> callback;
2017-02-02 17:24:40 +01:00
};
}
2017-02-02 17:24:40 +01:00
#endif //LIBTGVOIP_OPUSENCODER_H