00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackCoreAudioDriver__
00021 #define __JackCoreAudioDriver__
00022
00023 #include <AudioToolbox/AudioConverter.h>
00024 #include <CoreAudio/CoreAudio.h>
00025 #include <AudioUnit/AudioUnit.h>
00026 #include "JackAudioDriver.h"
00027 #include "JackTime.h"
00028
00029 #include <vector>
00030
00031 using namespace std;
00032
00033 namespace Jack
00034 {
00035
00036 #define kVersion 102
00037
00038 typedef UInt8 CAAudioHardwareDeviceSectionID;
00039 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
00040 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
00041 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
00042 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
00043
00044 #define WAIT_COUNTER 60
00045
00052 class JackCoreAudioDriver : public JackAudioDriver
00053 {
00054
00055 private:
00056
00057 AudioUnit fAUHAL;
00058
00059 AudioBufferList* fJackInputData;
00060 AudioBufferList* fDriverOutputData;
00061
00062 AudioDeviceID fDeviceID;
00063 AudioObjectID fPluginID;
00064
00065 AudioUnitRenderActionFlags* fActionFags;
00066 AudioTimeStamp* fCurrentTime;
00067
00068 bool fState;
00069 bool fHogged;
00070
00071 char fCaptureUID[256];
00072 char fPlaybackUID[256];
00073
00074 float fIOUsage;
00075 float fComputationGrain;
00076 bool fClockDriftCompensate;
00077
00078
00079
00080
00081
00082
00083
00084 static OSStatus Render(void *inRefCon,
00085 AudioUnitRenderActionFlags *ioActionFlags,
00086 const AudioTimeStamp *inTimeStamp,
00087 UInt32 inBusNumber,
00088 UInt32 inNumberFrames,
00089 AudioBufferList *ioData);
00090
00091 static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
00092 UInt32 inChannel,
00093 Boolean isInput,
00094 AudioDevicePropertyID inPropertyID,
00095 void* inClientData);
00096
00097 static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
00098 UInt32 inChannel,
00099 Boolean isInput,
00100 AudioDevicePropertyID inPropertyID,
00101 void* inClientData);
00102
00103 OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
00104 OSStatus GetDefaultDevice(AudioDeviceID* id);
00105 OSStatus GetDefaultInputDevice(AudioDeviceID* id);
00106 OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
00107 OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
00108 OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
00109
00110
00111 OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice);
00112 OSStatus CreateAggregateDeviceAux(vector<AudioDeviceID> captureDeviceID, vector<AudioDeviceID> playbackDeviceID, jack_nframes_t samplerate, AudioDeviceID* outAggregateDevice);
00113 OSStatus DestroyAggregateDevice();
00114 bool IsAggregateDevice(AudioDeviceID device);
00115
00116 int SetupDevices(const char* capture_driver_uid,
00117 const char* playback_driver_uid,
00118 char* capture_driver_name,
00119 char* playback_driver_name,
00120 jack_nframes_t samplerate);
00121
00122 int SetupChannels(bool capturing,
00123 bool playing,
00124 int& inchannels,
00125 int& outchannels,
00126 int& in_nChannels,
00127 int& out_nChannels,
00128 bool strict);
00129
00130 int SetupBuffers(int inchannels);
00131 void DisposeBuffers();
00132
00133 int SetupBufferSize(jack_nframes_t buffer_size);
00134 int SetupSampleRate(jack_nframes_t samplerate);
00135 int SetupSampleRateAux(AudioDeviceID inDevice, jack_nframes_t samplerate);
00136
00137 int OpenAUHAL(bool capturing,
00138 bool playing,
00139 int inchannels,
00140 int outchannels,
00141 int in_nChannels,
00142 int out_nChannels,
00143 jack_nframes_t nframes,
00144 jack_nframes_t samplerate);
00145 void CloseAUHAL();
00146
00147 int AddListeners();
00148 void RemoveListeners();
00149
00150 bool TakeHogAux(AudioDeviceID deviceID, bool isInput);
00151 bool TakeHog();
00152
00153 public:
00154
00155 JackCoreAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
00156 virtual ~JackCoreAudioDriver();
00157
00158 int Open(jack_nframes_t buffer_size,
00159 jack_nframes_t samplerate,
00160 bool capturing,
00161 bool playing,
00162 int chan_in,
00163 int chan_out,
00164 bool monitor,
00165 const char* capture_driver_name,
00166 const char* playback_driver_name,
00167 jack_nframes_t capture_latency,
00168 jack_nframes_t playback_latency,
00169 int async_output_latency,
00170 int computation_grain,
00171 bool hogged,
00172 bool clock_drift);
00173 int Close();
00174
00175 int Attach();
00176
00177 int Start();
00178 int Stop();
00179
00180 int Read();
00181 int Write();
00182
00183
00184 bool IsFixedBufferSize()
00185 {
00186 return false;
00187 }
00188
00189 int SetBufferSize(jack_nframes_t buffer_size);
00190 };
00191
00192 }
00193
00194 #endif