1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-11 16:49:52 +01:00
libtgvoip/controller/media/MediaStreamItf.h

96 lines
2.1 KiB
C
Raw Normal View History

2020-01-22 12:43:51 +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_MEDIASTREAMINPUT_H
#define LIBTGVOIP_MEDIASTREAMINPUT_H
#include <string.h>
#include <vector>
#include <memory>
#include <stdint.h>
#include "tools/threading.h"
#include "tools/BlockingQueue.h"
#include "tools/Buffers.h"
namespace tgvoip
{
class EchoCanceller;
class MediaStreamItf
{
public:
virtual void Start() = 0;
virtual void Stop() = 0;
void SetCallback(size_t (*f)(unsigned char *, size_t, void *), void *param);
//protected:
size_t InvokeCallback(unsigned char *data, size_t length);
private:
size_t (*callback)(unsigned char *, size_t, void *) = NULL;
void *callbackParam;
2020-03-10 19:36:27 +01:00
Mutex callbackMutex;
2020-01-22 12:43:51 +01:00
};
class AudioMixer : public MediaStreamItf
{
public:
AudioMixer();
virtual ~AudioMixer();
void SetOutput(MediaStreamItf *output);
virtual void Start();
virtual void Stop();
void AddInput(std::shared_ptr<MediaStreamItf> input);
void RemoveInput(std::shared_ptr<MediaStreamItf> input);
void SetInputVolume(std::shared_ptr<MediaStreamItf> input, float volumeDB);
void SetEchoCanceller(EchoCanceller *aec);
private:
void RunThread();
struct MixerInput
{
std::shared_ptr<MediaStreamItf> source;
float multiplier;
};
Mutex inputsMutex;
void DoCallback(unsigned char *data, size_t length);
static size_t OutputCallback(unsigned char *data, size_t length, void *arg);
std::vector<MixerInput> inputs;
Thread *thread;
BufferPool<960 * 2, 16> bufferPool;
BlockingQueue<Buffer> processedQueue;
Semaphore semaphore;
EchoCanceller *echoCanceller;
bool running;
};
class CallbackWrapper : public MediaStreamItf
{
public:
CallbackWrapper(){};
virtual ~CallbackWrapper(){};
virtual void Start(){};
virtual void Stop(){};
};
class AudioLevelMeter
{
public:
AudioLevelMeter();
float GetLevel();
void Update(int16_t *samples, size_t count);
private:
int16_t absMax;
int16_t count;
int8_t currentLevel;
int16_t currentLevelFullRange;
};
}; // namespace tgvoip
#endif //LIBTGVOIP_MEDIASTREAMINPUT_H