Hog mode in JackCoreAudioDriver (in progress).
[jack2.git] / macosx / coreaudio / JackCoreAudioDriver.h
blobd3dcfa21d99175908dd2eb7625fb8b22d5d14b8a
1 /*
2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __JackCoreAudioDriver__
21 #define __JackCoreAudioDriver__
23 #include <AudioToolbox/AudioConverter.h>
24 #include <CoreAudio/CoreAudio.h>
25 #include <AudioUnit/AudioUnit.h>
26 #include "JackAudioDriver.h"
27 #include "JackTime.h"
29 namespace Jack
32 #define kVersion 102
34 typedef UInt8 CAAudioHardwareDeviceSectionID;
35 #define kAudioDeviceSectionInput ((CAAudioHardwareDeviceSectionID)0x01)
36 #define kAudioDeviceSectionOutput ((CAAudioHardwareDeviceSectionID)0x00)
37 #define kAudioDeviceSectionGlobal ((CAAudioHardwareDeviceSectionID)0x00)
38 #define kAudioDeviceSectionWildcard ((CAAudioHardwareDeviceSectionID)0xFF)
40 /*!
41 \brief The CoreAudio driver.
43 \todo hardware monitoring
46 class JackCoreAudioDriver : public JackAudioDriver
49 private:
51 AudioUnit fAUHAL;
53 AudioBufferList* fJackInputData;
54 AudioBufferList* fDriverOutputData;
56 AudioDeviceID fDeviceID; // Used "duplex" device
57 AudioObjectID fPluginID; // Used for aggregate device
59 AudioUnitRenderActionFlags* fActionFags;
60 AudioTimeStamp* fCurrentTime;
62 bool fState;
64 // Initial state
65 bool fCapturing;
66 bool fPlaying;
68 int fInChannels;
69 int fOutChannels;
71 char fCaptureUID[256];
72 char fPlaybackUID[256];
74 bool fMonitor;
75 float fIOUsage;
76 float fComputationGrain;
78 /*
79 #ifdef MAC_OS_X_VERSION_10_5
80 AudioDeviceIOProcID fMesureCallbackID;
81 #endif
84 static OSStatus Render(void *inRefCon,
85 AudioUnitRenderActionFlags *ioActionFlags,
86 const AudioTimeStamp *inTimeStamp,
87 UInt32 inBusNumber,
88 UInt32 inNumberFrames,
89 AudioBufferList *ioData);
91 static OSStatus MeasureCallback(AudioDeviceID inDevice,
92 const AudioTimeStamp* inNow,
93 const AudioBufferList* inInputData,
94 const AudioTimeStamp* inInputTime,
95 AudioBufferList* outOutputData,
96 const AudioTimeStamp* inOutputTime,
97 void* inClientData);
99 static OSStatus DeviceNotificationCallback(AudioDeviceID inDevice,
100 UInt32 inChannel,
101 Boolean isInput,
102 AudioDevicePropertyID inPropertyID,
103 void* inClientData);
105 static OSStatus SRNotificationCallback(AudioDeviceID inDevice,
106 UInt32 inChannel,
107 Boolean isInput,
108 AudioDevicePropertyID inPropertyID,
109 void* inClientData);
111 OSStatus GetDeviceIDFromUID(const char* UID, AudioDeviceID* id);
112 OSStatus GetDefaultDevice(AudioDeviceID* id);
113 OSStatus GetDefaultInputDevice(AudioDeviceID* id);
114 OSStatus GetDefaultOutputDevice(AudioDeviceID* id);
115 OSStatus GetDeviceNameFromID(AudioDeviceID id, char* name);
116 OSStatus GetTotalChannels(AudioDeviceID device, int& channelCount, bool isInput);
118 // Setup
119 OSStatus CreateAggregateDevice(AudioDeviceID captureDeviceID, AudioDeviceID playbackDeviceID, AudioDeviceID* outAggregateDevice);
120 OSStatus DestroyAggregateDevice();
122 int SetupDevices(const char* capture_driver_uid,
123 const char* playback_driver_uid,
124 char* capture_driver_name,
125 char* playback_driver_name);
127 int SetupChannels(bool capturing,
128 bool playing,
129 int& inchannels,
130 int& outchannels,
131 int& in_nChannels,
132 int& out_nChannels,
133 bool strict);
135 int SetupBuffers(int inchannels);
136 void DisposeBuffers();
138 int SetupBufferSizeAndSampleRate(jack_nframes_t buffer_size, jack_nframes_t samplerate);
140 int OpenAUHAL(bool capturing,
141 bool playing,
142 int inchannels,
143 int outchannels,
144 int in_nChannels,
145 int out_nChannels,
146 jack_nframes_t nframes,
147 jack_nframes_t samplerate,
148 bool strict);
149 void CloseAUHAL();
151 int AddListeners();
152 void RemoveListeners();
154 bool TakeHog(AudioDeviceID deviceID, bool isInput);
156 public:
158 JackCoreAudioDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
159 virtual ~JackCoreAudioDriver();
161 int Open(jack_nframes_t buffer_size,
162 jack_nframes_t samplerate,
163 bool capturing,
164 bool playing,
165 int chan_in,
166 int chan_out,
167 bool monitor,
168 const char* capture_driver_name,
169 const char* playback_driver_name,
170 jack_nframes_t capture_latency,
171 jack_nframes_t playback_latency,
172 int async_output_latency,
173 int computation_grain);
174 int Close();
176 int Attach();
178 int Start();
179 int Stop();
181 int Read();
182 int Write();
184 // BufferSize can be changed
185 bool IsFixedBufferSize()
187 return false;
190 int SetBufferSize(jack_nframes_t buffer_size);
193 } // end of namespace
195 #endif