2018-09-01 00:59:09 +02: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_AUDIO_IO_CALLBACK
|
|
|
|
#define LIBTGVOIP_AUDIO_IO_CALLBACK
|
|
|
|
|
|
|
|
#include <functional>
|
2020-01-24 20:26:34 +01:00
|
|
|
#include <memory>
|
2018-09-01 00:59:09 +02:00
|
|
|
|
2020-01-24 20:26:34 +01:00
|
|
|
#include "AudioIO.h"
|
2020-01-22 12:43:51 +01:00
|
|
|
#include "../tools/threading.h"
|
2018-09-01 00:59:09 +02:00
|
|
|
|
2020-01-22 12:43:51 +01:00
|
|
|
namespace tgvoip
|
|
|
|
{
|
|
|
|
namespace audio
|
|
|
|
{
|
|
|
|
class AudioInputCallback : public AudioInput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AudioInputCallback();
|
|
|
|
virtual ~AudioInputCallback();
|
|
|
|
virtual void Start() override;
|
|
|
|
virtual void Stop() override;
|
|
|
|
void SetDataCallback(std::function<void(int16_t *, size_t)> c);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void RunThread();
|
|
|
|
bool running = false;
|
|
|
|
bool recording = false;
|
|
|
|
Thread *thread;
|
|
|
|
std::function<void(int16_t *, size_t)> dataCallback;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioOutputCallback : public AudioOutput
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AudioOutputCallback();
|
|
|
|
virtual ~AudioOutputCallback();
|
|
|
|
virtual void Start() override;
|
|
|
|
virtual void Stop() override;
|
|
|
|
virtual bool IsPlaying() override;
|
|
|
|
void SetDataCallback(std::function<void(int16_t *, size_t)> c);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void RunThread();
|
|
|
|
bool running = false;
|
|
|
|
bool playing = false;
|
|
|
|
Thread *thread;
|
|
|
|
std::function<void(int16_t *, size_t)> dataCallback;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioIOCallback : public AudioIO
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AudioIOCallback();
|
|
|
|
virtual ~AudioIOCallback();
|
2020-01-24 20:26:34 +01:00
|
|
|
virtual std::shared_ptr<AudioInput> GetInput() override;
|
|
|
|
virtual std::shared_ptr<AudioOutput> GetOutput() override;
|
2020-01-22 12:43:51 +01:00
|
|
|
|
|
|
|
private:
|
2020-01-24 20:26:34 +01:00
|
|
|
std::shared_ptr<AudioInputCallback> input;
|
|
|
|
std::shared_ptr<AudioOutputCallback> output;
|
2020-01-22 12:43:51 +01:00
|
|
|
};
|
|
|
|
} // namespace audio
|
|
|
|
} // namespace tgvoip
|
2018-09-01 00:59:09 +02:00
|
|
|
|
|
|
|
#endif /* LIBTGVOIP_AUDIO_IO_CALLBACK */
|