jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.4KB

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