this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreAudio: Implement most AudioFileComponent dispatchers

+212 -180
+1 -45
src/CoreAudio/AudioToolbox/AUComponent.cpp
··· 21 21 #include <AudioToolbox/AUComponent.h> 22 22 #include <AudioToolbox/AudioOutputUnit.h> 23 23 #include <CoreServices/MacErrors.h> 24 - #include <CoreServices/Components.h> 25 - #include "AudioComponentManager.h" 24 + #include "ComponentDispatch.h" 26 25 27 26 const CFStringRef kAudioComponentRegistrationsChangedNotification = CFSTR("AudioComponentRegistrationsChangedNotification"); 28 27 const CFStringRef kAudioComponentInstanceInvalidationNotification = CFSTR("AudioComponentInstanceInvalidationNotification"); 29 - 30 - template <typename First, typename... Rest> 31 - void assignParams(ComponentParameters* cp, size_t totalArgs, size_t argumentIndex, First arg, Rest... rest) 32 - { 33 - #if __LP64__ 34 - cp->params[argumentIndex] = long(arg); 35 - #else 36 - cp->params[totalArgs - argumentIndex - 1] = long(arg); 37 - #endif 38 - 39 - if constexpr (sizeof...(Rest) > 0) 40 - assignParams(cp, totalArgs, argumentIndex+1, rest...); 41 - } 42 - 43 - template <typename ...Args> 44 - OSStatus dispatchCall(AudioUnit inUnit, SInt16 sel, Args... args) 45 - { 46 - if (AudioComponentManager::isOurInstance(inUnit)) 47 - { 48 - AudioComponentPlugInInterface* iface = AudioComponentManager::instance()->instanceInterface(inUnit); 49 - AudioComponentMethod method = iface->Lookup(sel); 50 - if (method != nullptr) 51 - return method(iface, args...); 52 - else 53 - return badComponentSelector; 54 - } 55 - else 56 - { 57 - ComponentParameters* cp = (ComponentParameters*) alloca(sizeof(ComponentParameters) + sizeof...(Args) * sizeof(long)); 58 - constexpr size_t totalArgs = sizeof...(Args)+1; 59 - 60 - assignParams(cp, totalArgs, 0, inUnit); 61 - 62 - if constexpr (totalArgs > 1) 63 - assignParams(cp, totalArgs, 1, args...); 64 - 65 - cp->paramSize = totalArgs * sizeof(long); 66 - cp->what = sel; 67 - cp->flags = 0; 68 - 69 - return CallComponentDispatch(cp); 70 - } 71 - } 72 28 73 29 OSStatus AudioOutputUnitStart(AudioUnit ci) 74 30 {
+141 -135
src/CoreAudio/AudioToolbox/AudioFileComponent.cpp
··· 17 17 along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 19 20 - #include <AudioToolbix/AudioFileComponent.h> 20 + #include <AudioToolbox/AudioFileComponent.h> 21 21 #include <CoreServices/MacErrors.h> 22 + #include "ComponentDispatch.h" 22 23 23 24 OSStatus 24 25 AudioFileComponentCreateURL ( 25 - AudioFileComponent inComponent, 26 - CFURLRef inFileRef, 27 - const AudioStreamBasicDescription *inFormat, 28 - UInt32 inFlags) 26 + AudioFileComponent inComponent, 27 + CFURLRef inFileRef, 28 + const AudioStreamBasicDescription *inFormat, 29 + UInt32 inFlags) 29 30 { 30 - return unimpErr; 31 + return dispatchCall(inComponent, kAudioFileCreateURLSelect, inFileRef, inFormat, inFlags); 31 32 } 32 33 33 34 OSStatus ··· 37 38 SInt8 inPermissions, 38 39 int inFileDescriptor) 39 40 { 40 - return unimpErr; 41 + return dispatchCall(inComponent, kAudioFileOpenURLSelect, inFileRef, inPermissions, inFileDescriptor); 41 42 } 42 43 43 44 OSStatus 44 45 AudioFileComponentOpenWithCallbacks( 45 - AudioFileComponent inComponent, 46 - void *inClientData, 47 - AudioFile_ReadProc inReadFunc, 48 - AudioFile_WriteProc inWriteFunc, 49 - AudioFile_GetSizeProc inGetSizeFunc, 50 - AudioFile_SetSizeProc inSetSizeFunc) 46 + AudioFileComponent inComponent, 47 + void *inClientData, 48 + AudioFile_ReadProc inReadFunc, 49 + AudioFile_WriteProc inWriteFunc, 50 + AudioFile_GetSizeProc inGetSizeFunc, 51 + AudioFile_SetSizeProc inSetSizeFunc) 51 52 { 52 - return unimpErr; 53 + return dispatchCall(inComponent, kAudioFileOpenWithCallbacksSelect, inClientData, inReadFunc, inWriteFunc, inGetSizeFunc, inSetSizeFunc); 53 54 } 54 55 55 56 OSStatus 56 57 AudioFileComponentInitializeWithCallbacks( 57 - AudioFileComponent inComponent, 58 - void *inClientData, 59 - AudioFile_ReadProc inReadFunc, 60 - AudioFile_WriteProc inWriteFunc, 61 - AudioFile_GetSizeProc inGetSizeFunc, 62 - AudioFile_SetSizeProc inSetSizeFunc, 63 - UInt32 inFileType, 64 - const AudioStreamBasicDescription *inFormat, 65 - UInt32 inFlags) 58 + AudioFileComponent inComponent, 59 + void *inClientData, 60 + AudioFile_ReadProc inReadFunc, 61 + AudioFile_WriteProc inWriteFunc, 62 + AudioFile_GetSizeProc inGetSizeFunc, 63 + AudioFile_SetSizeProc inSetSizeFunc, 64 + UInt32 inFileType, 65 + const AudioStreamBasicDescription *inFormat, 66 + UInt32 inFlags) 66 67 { 67 - return unimpErr; 68 + return dispatchCall(inComponent, kAudioFileInitializeWithCallbacksSelect, inClientData, 69 + inReadFunc, inWriteFunc, inGetSizeFunc, inSetSizeFunc, 70 + inFileType, inFormat, inFlags); 68 71 } 69 72 70 73 OSStatus 71 74 AudioFileComponentCloseFile( 72 - AudioFileComponent inComponent) 75 + AudioFileComponent inComponent) 73 76 { 74 - return unimpErr; 77 + return dispatchCall(inComponent, kAudioFileCloseSelect); 75 78 } 76 79 77 80 78 81 79 82 OSStatus 80 83 AudioFileComponentOptimize( 81 - AudioFileComponent inComponent) 84 + AudioFileComponent inComponent) 82 85 { 83 - return unimpErr; 86 + return dispatchCall(inComponent, kAudioFileOptimizeSelect); 84 87 } 85 88 86 89 OSStatus 87 90 AudioFileComponentReadBytes( 88 - AudioFileComponent inComponent, 89 - Boolean inUseCache, 90 - SInt64 inStartingByte, 91 - UInt32 *ioNumBytes, 92 - void *outBuffer) 91 + AudioFileComponent inComponent, 92 + Boolean inUseCache, 93 + SInt64 inStartingByte, 94 + UInt32 *ioNumBytes, 95 + void *outBuffer) 93 96 { 94 - return unimpErr; 97 + return dispatchCall(inComponent, kAudioFileReadBytesSelect, inUseCache, inStartingByte, ioNumBytes, outBuffer); 95 98 } 96 99 97 100 OSStatus 98 101 AudioFileComponentWriteBytes( 99 - AudioFileComponent inComponent, 100 - Boolean inUseCache, 101 - SInt64 inStartingByte, 102 - UInt32 *ioNumBytes, 103 - const void *inBuffer) 102 + AudioFileComponent inComponent, 103 + Boolean inUseCache, 104 + SInt64 inStartingByte, 105 + UInt32 *ioNumBytes, 106 + const void *inBuffer) 104 107 { 105 - return unimpErr; 108 + return dispatchCall(inComponent, kAudioFileWriteBytesSelect, inUseCache, inStartingByte, ioNumBytes, inBuffer); 106 109 } 107 110 108 111 OSStatus 109 112 AudioFileComponentReadPackets( 110 - AudioFileComponent inComponent, 111 - Boolean inUseCache, 112 - UInt32 *outNumBytes, 113 - AudioStreamPacketDescription * _Nullable outPacketDescriptions, 114 - SInt64 inStartingPacket, 115 - UInt32 *ioNumPackets, 116 - void *outBuffer) 113 + AudioFileComponent inComponent, 114 + Boolean inUseCache, 115 + UInt32 *outNumBytes, 116 + AudioStreamPacketDescription * _Nullable outPacketDescriptions, 117 + SInt64 inStartingPacket, 118 + UInt32 *ioNumPackets, 119 + void *outBuffer) 117 120 { 118 - return unimpErr; 121 + return dispatchCall(inComponent, kAudioFileReadPacketsSelect, inUseCache, outNumBytes, outPacketDescriptions, inStartingPacket, 122 + ioNumPackets, outBuffer); 119 123 } 120 124 121 125 OSStatus 122 126 AudioFileComponentReadPacketData( 123 - AudioFileComponent inComponent, 124 - Boolean inUseCache, 125 - UInt32 *ioNumBytes, 126 - AudioStreamPacketDescription * _Nullable outPacketDescriptions, 127 - SInt64 inStartingPacket, 128 - UInt32 *ioNumPackets, 129 - void *outBuffer) 127 + AudioFileComponent inComponent, 128 + Boolean inUseCache, 129 + UInt32 *ioNumBytes, 130 + AudioStreamPacketDescription * _Nullable outPacketDescriptions, 131 + SInt64 inStartingPacket, 132 + UInt32 *ioNumPackets, 133 + void *outBuffer) 130 134 { 131 135 return unimpErr; 132 136 } 133 137 134 138 OSStatus 135 139 AudioFileComponentWritePackets( 136 - AudioFileComponent inComponent, 137 - Boolean inUseCache, 138 - UInt32 inNumBytes, 139 - const AudioStreamPacketDescription * _Nullable inPacketDescriptions, 140 - SInt64 inStartingPacket, 141 - UInt32 *ioNumPackets, 142 - const void *inBuffer) 140 + AudioFileComponent inComponent, 141 + Boolean inUseCache, 142 + UInt32 inNumBytes, 143 + const AudioStreamPacketDescription * _Nullable inPacketDescriptions, 144 + SInt64 inStartingPacket, 145 + UInt32 *ioNumPackets, 146 + const void *inBuffer) 143 147 { 144 - return unimpErr; 148 + return dispatchCall(inComponent, kAudioFileWritePacketsSelect, inUseCache, inNumBytes, inPacketDescriptions, inStartingPacket, 149 + ioNumPackets, inBuffer); 145 150 } 146 151 147 152 OSStatus 148 153 AudioFileComponentGetPropertyInfo( 149 - AudioFileComponent inComponent, 150 - AudioFileComponentPropertyID inPropertyID, 151 - UInt32 * _Nullable outPropertySize, 152 - UInt32 * _Nullable outWritable) 154 + AudioFileComponent inComponent, 155 + AudioFileComponentPropertyID inPropertyID, 156 + UInt32 * _Nullable outPropertySize, 157 + UInt32 * _Nullable outWritable) 153 158 { 154 - return unimpErr; 159 + return dispatchCall(inComponent, kAudioFileGetPropertyInfoSelect, inPropertyID, outPropertySize, outWritable); 155 160 } 156 161 157 162 OSStatus 158 163 AudioFileComponentGetProperty( 159 - AudioFileComponent inComponent, 160 - AudioFileComponentPropertyID inPropertyID, 161 - UInt32 *ioPropertyDataSize, 162 - void *outPropertyData) 164 + AudioFileComponent inComponent, 165 + AudioFileComponentPropertyID inPropertyID, 166 + UInt32 *ioPropertyDataSize, 167 + void *outPropertyData) 163 168 { 164 - return unimpErr; 169 + return dispatchCall(inComponent, kAudioFileGetPropertySelect, inPropertyID, ioPropertyDataSize, outPropertyData); 165 170 } 166 171 167 172 OSStatus 168 173 AudioFileComponentSetProperty( 169 - AudioFileComponent inComponent, 170 - AudioFileComponentPropertyID inPropertyID, 171 - UInt32 inPropertyDataSize, 172 - const void *inPropertyData) 174 + AudioFileComponent inComponent, 175 + AudioFileComponentPropertyID inPropertyID, 176 + UInt32 inPropertyDataSize, 177 + const void *inPropertyData) 173 178 { 174 - return unimpErr; 179 + return dispatchCall(inComponent, kAudioFileSetPropertySelect, inPropertyID, inPropertyDataSize, inPropertyData); 175 180 } 176 181 177 182 OSStatus 178 183 AudioFileComponentCountUserData( 179 - AudioFileComponent inComponent, 180 - UInt32 inUserDataID, 181 - UInt32 *outNumberItems) 184 + AudioFileComponent inComponent, 185 + UInt32 inUserDataID, 186 + UInt32 *outNumberItems) 182 187 { 183 - return unimpErr; 188 + return dispatchCall(inComponent, kAudioFileCountUserDataSelect, inUserDataID, outNumberItems); 184 189 } 185 190 186 191 OSStatus 187 192 AudioFileComponentGetUserDataSize( 188 - AudioFileComponent inComponent, 189 - UInt32 inUserDataID, 190 - UInt32 inIndex, 191 - UInt32 *outUserDataSize) 193 + AudioFileComponent inComponent, 194 + UInt32 inUserDataID, 195 + UInt32 inIndex, 196 + UInt32 *outUserDataSize) 192 197 { 193 - return unimpErr; 198 + return dispatchCall(inComponent, kAudioFileGetUserDataSizeSelect, inUserDataID, inIndex, outUserDataSize); 194 199 } 195 200 196 201 OSStatus 197 202 AudioFileComponentGetUserData( 198 - AudioFileComponent inComponent, 199 - UInt32 inUserDataID, 200 - UInt32 inIndex, 201 - UInt32 *ioUserDataSize, 202 - void *outUserData) 203 + AudioFileComponent inComponent, 204 + UInt32 inUserDataID, 205 + UInt32 inIndex, 206 + UInt32 *ioUserDataSize, 207 + void *outUserData) 203 208 { 204 - return unimpErr; 209 + return dispatchCall(inComponent, kAudioFileGetUserDataSelect, inUserDataID, inIndex, ioUserDataSize, outUserData); 205 210 } 206 211 207 212 OSStatus 208 213 AudioFileComponentSetUserData( 209 - AudioFileComponent inComponent, 210 - UInt32 inUserDataID, 211 - UInt32 inIndex, 212 - UInt32 inUserDataSize, 213 - const void *inUserData) 214 + AudioFileComponent inComponent, 215 + UInt32 inUserDataID, 216 + UInt32 inIndex, 217 + UInt32 inUserDataSize, 218 + const void *inUserData) 214 219 { 215 - return unimpErr; 220 + return dispatchCall(inComponent, kAudioFileSetUserDataSelect, inUserDataID, inIndex, inUserDataSize, inUserData); 216 221 } 217 222 218 223 OSStatus 219 224 AudioFileComponentRemoveUserData( 220 - AudioFileComponent inComponent, 221 - UInt32 inUserDataID, 222 - UInt32 inIndex) 225 + AudioFileComponent inComponent, 226 + UInt32 inUserDataID, 227 + UInt32 inIndex) 223 228 { 224 - return unimpErr; 229 + return dispatchCall(inComponent, kAudioFileRemoveUserDataSelect, inUserDataID, inIndex); 225 230 } 226 231 227 232 OSStatus 228 233 AudioFileComponentExtensionIsThisFormat( 229 - AudioFileComponent inComponent, 230 - CFStringRef inExtension, 231 - UInt32 *outResult) 234 + AudioFileComponent inComponent, 235 + CFStringRef inExtension, 236 + UInt32 *outResult) 232 237 { 233 - return unimpErr; 238 + return dispatchCall(inComponent, kAudioFileExtensionIsThisFormatSelect, inExtension, outResult); 234 239 } 235 240 236 241 OSStatus 237 242 AudioFileComponentFileDataIsThisFormat( 238 - AudioFileComponent inComponent, 239 - UInt32 inDataByteSize, 240 - const void* inData, 241 - UInt32 *outResult) 243 + AudioFileComponent inComponent, 244 + UInt32 inDataByteSize, 245 + const void* inData, 246 + UInt32 *outResult) 242 247 { 243 - return unimpErr; 248 + return dispatchCall(inComponent, kAudioFileFileDataIsThisFormatSelect, inDataByteSize, inData, outResult); 244 249 } 245 250 246 251 OSStatus 247 252 AudioFileComponentFileIsThisFormat( 248 - AudioFileComponent inComponent, 249 - SInt16 inFileRefNum, 250 - UInt32 *outResult) 253 + AudioFileComponent inComponent, 254 + SInt16 inFileRefNum, 255 + UInt32 *outResult) 251 256 { 252 257 return unimpErr; 253 258 } 254 259 255 260 OSStatus 256 261 AudioFileComponentDataIsThisFormat( 257 - AudioFileComponent inComponent, 258 - void * _Nullable inClientData, 259 - AudioFile_ReadProc _Nullable inReadFunc, 260 - AudioFile_WriteProc _Nullable inWriteFunc, 261 - AudioFile_GetSizeProc _Nullable inGetSizeFunc, 262 - AudioFile_SetSizeProc _Nullable inSetSizeFunc, 263 - UInt32 *outResult) 262 + AudioFileComponent inComponent, 263 + void * _Nullable inClientData, 264 + AudioFile_ReadProc _Nullable inReadFunc, 265 + AudioFile_WriteProc _Nullable inWriteFunc, 266 + AudioFile_GetSizeProc _Nullable inGetSizeFunc, 267 + AudioFile_SetSizeProc _Nullable inSetSizeFunc, 268 + UInt32 *outResult) 264 269 { 265 270 return unimpErr; 266 271 } 267 272 268 273 OSStatus 269 274 AudioFileComponentGetGlobalInfoSize( 270 - AudioFileComponent inComponent, 271 - AudioFileComponentPropertyID inPropertyID, 272 - UInt32 inSpecifierSize, 273 - const void * _Nullable inSpecifier, 274 - UInt32 *outPropertySize) 275 + AudioFileComponent inComponent, 276 + AudioFileComponentPropertyID inPropertyID, 277 + UInt32 inSpecifierSize, 278 + const void * _Nullable inSpecifier, 279 + UInt32 *outPropertySize) 275 280 { 276 - return unimpErr; 281 + return dispatchCall(inComponent, kAudioFileGetGlobalInfoSizeSelect, inPropertyID, inSpecifierSize, inSpecifier, outPropertySize); 277 282 } 278 283 279 284 OSStatus 280 285 AudioFileComponentGetGlobalInfo( 281 - AudioFileComponent inComponent, 282 - AudioFileComponentPropertyID inPropertyID, 283 - UInt32 inSpecifierSize, 284 - const void * _Nullable inSpecifier, 285 - UInt32 *ioPropertyDataSize, 286 - void *outPropertyData) 286 + AudioFileComponent inComponent, 287 + AudioFileComponentPropertyID inPropertyID, 288 + UInt32 inSpecifierSize, 289 + const void * _Nullable inSpecifier, 290 + UInt32 *ioPropertyDataSize, 291 + void *outPropertyData) 287 292 { 288 - return unimpErr; 293 + return dispatchCall(inComponent, kAudioFileGetGlobalInfoSelect, inPropertyID, inSpecifierSize, inSpecifier, 294 + ioPropertyDataSize, outPropertyData); 289 295 } 290 296
+1
src/CoreAudio/AudioToolbox/CMakeLists.txt
··· 19 19 AUGraph.cpp 20 20 AudioComponent.mm 21 21 AudioComponentManager.mm 22 + AudioFileComponent.cpp 22 23 ) 23 24 24 25 add_framework(AudioToolbox
+69
src/CoreAudio/AudioToolbox/ComponentDispatch.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _COMPONENT_DISPATCH_H 21 + #define _COMPONENT_DISPATCH_H 22 + #include "AudioComponentManager.h" 23 + #include <CoreServices/Components.h> 24 + 25 + template <typename First, typename... Rest> 26 + void assignParams(ComponentParameters* cp, size_t totalArgs, size_t argumentIndex, First arg, Rest... rest) 27 + { 28 + #if __LP64__ 29 + cp->params[argumentIndex] = long(arg); 30 + #else 31 + cp->params[totalArgs - argumentIndex - 1] = long(arg); 32 + #endif 33 + 34 + if constexpr (sizeof...(Rest) > 0) 35 + assignParams(cp, totalArgs, argumentIndex+1, rest...); 36 + } 37 + 38 + template <typename ...Args> 39 + OSStatus dispatchCall(AudioComponentInstance inUnit, SInt16 sel, Args... args) 40 + { 41 + if (AudioComponentManager::isOurInstance(inUnit)) 42 + { 43 + AudioComponentPlugInInterface* iface = AudioComponentManager::instance()->instanceInterface(inUnit); 44 + AudioComponentMethod method = iface->Lookup(sel); 45 + if (method != nullptr) 46 + return method(iface, args...); 47 + else 48 + return badComponentSelector; 49 + } 50 + else 51 + { 52 + ComponentParameters* cp = (ComponentParameters*) alloca(sizeof(ComponentParameters) + sizeof...(Args) * sizeof(long)); 53 + constexpr size_t totalArgs = sizeof...(Args)+1; 54 + 55 + assignParams(cp, totalArgs, 0, inUnit); 56 + 57 + if constexpr (totalArgs > 1) 58 + assignParams(cp, totalArgs, 1, args...); 59 + 60 + cp->paramSize = totalArgs * sizeof(long); 61 + cp->what = sel; 62 + cp->flags = 0; 63 + 64 + return CallComponentDispatch(cp); 65 + } 66 + } 67 + 68 + #endif 69 +