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

59 lines
1.8 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_AUDIOUNITIO_H
#define LIBTGVOIP_AUDIOUNITIO_H
#include <AudioUnit/AudioUnit.h>
2017-03-30 16:06:59 +02:00
#include "../../threading.h"
2017-02-02 17:24:40 +01:00
namespace tgvoip{ namespace audio{
class AudioInputAudioUnit;
class AudioOutputAudioUnit;
2017-02-02 17:24:40 +01:00
class AudioUnitIO{
2017-02-02 17:24:40 +01:00
public:
AudioUnitIO();
~AudioUnitIO();
2017-02-02 17:24:40 +01:00
void Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels);
void AttachInput(AudioInputAudioUnit* i);
void AttachOutput(AudioOutputAudioUnit* o);
2017-02-02 17:24:40 +01:00
void DetachInput();
void DetachOutput();
void EnableInput(bool enabled);
void EnableOutput(bool enabled);
static AudioUnitIO* Get();
2017-02-02 17:24:40 +01:00
static void Release();
2017-03-30 16:06:59 +02:00
static void* StartFakeIOThread(void* arg);
static void AudioSessionAcquired();
2017-02-02 17:24:40 +01:00
private:
static OSStatus BufferCallback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData);
void BufferCallback(AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 bus, UInt32 numFrames, AudioBufferList* ioData);
2017-03-30 16:06:59 +02:00
void RunFakeIOThread();
void Init();
void ActuallyConfigure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels);
void ProcessAudioSessionAcquired();
2017-02-02 17:24:40 +01:00
AudioComponentInstance unit;
AudioInputAudioUnit* input;
AudioOutputAudioUnit* output;
2017-02-02 17:24:40 +01:00
AudioBufferList inBufferList;
bool configured;
bool inputEnabled;
bool outputEnabled;
2017-03-30 16:06:59 +02:00
bool runFakeIO;
uint32_t cfgSampleRate;
uint32_t cfgBitsPerSample;
uint32_t cfgChannels;
tgvoip_thread_t fakeIOThread;
2017-02-02 17:24:40 +01:00
static int refCount;
static AudioUnitIO* sharedInstance;
2017-03-30 16:06:59 +02:00
static bool haveAudioSession;
2017-02-02 17:24:40 +01:00
};
}}
2017-02-02 17:24:40 +01:00
#endif /* LIBTGVOIP_AUDIOUNITIO_H */