annotate src/portaudio_20161030_catalina_patch/include/pa_win_wasapi.h @ 81:7029a4916348

Merge build update
author Chris Cannam
date Thu, 31 Oct 2019 13:36:58 +0000
parents 4edcd14160a5
children
rev   line source
Chris@55 1 #ifndef PA_WIN_WASAPI_H
Chris@55 2 #define PA_WIN_WASAPI_H
Chris@55 3 /*
Chris@55 4 * $Id: $
Chris@55 5 * PortAudio Portable Real-Time Audio Library
Chris@55 6 * DirectSound specific extensions
Chris@55 7 *
Chris@55 8 * Copyright (c) 1999-2007 Ross Bencina and Phil Burk
Chris@55 9 *
Chris@55 10 * Permission is hereby granted, free of charge, to any person obtaining
Chris@55 11 * a copy of this software and associated documentation files
Chris@55 12 * (the "Software"), to deal in the Software without restriction,
Chris@55 13 * including without limitation the rights to use, copy, modify, merge,
Chris@55 14 * publish, distribute, sublicense, and/or sell copies of the Software,
Chris@55 15 * and to permit persons to whom the Software is furnished to do so,
Chris@55 16 * subject to the following conditions:
Chris@55 17 *
Chris@55 18 * The above copyright notice and this permission notice shall be
Chris@55 19 * included in all copies or substantial portions of the Software.
Chris@55 20 *
Chris@55 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@55 22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@55 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Chris@55 24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
Chris@55 25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@55 26 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@55 27 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@55 28 */
Chris@55 29
Chris@55 30 /*
Chris@55 31 * The text above constitutes the entire PortAudio license; however,
Chris@55 32 * the PortAudio community also makes the following non-binding requests:
Chris@55 33 *
Chris@55 34 * Any person wishing to distribute modifications to the Software is
Chris@55 35 * requested to send the modifications to the original developer so that
Chris@55 36 * they can be incorporated into the canonical version. It is also
Chris@55 37 * requested that these non-binding requests be included along with the
Chris@55 38 * license above.
Chris@55 39 */
Chris@55 40
Chris@55 41 /** @file
Chris@55 42 @ingroup public_header
Chris@55 43 @brief WASAPI-specific PortAudio API extension header file.
Chris@55 44 */
Chris@55 45
Chris@55 46 #include "portaudio.h"
Chris@55 47 #include "pa_win_waveformat.h"
Chris@55 48
Chris@55 49 #ifdef __cplusplus
Chris@55 50 extern "C"
Chris@55 51 {
Chris@55 52 #endif /* __cplusplus */
Chris@55 53
Chris@55 54
Chris@55 55 /* Setup flags */
Chris@55 56 typedef enum PaWasapiFlags
Chris@55 57 {
Chris@55 58 /* puts WASAPI into exclusive mode */
Chris@55 59 paWinWasapiExclusive = (1 << 0),
Chris@55 60
Chris@55 61 /* allows to skip internal PA processing completely */
Chris@55 62 paWinWasapiRedirectHostProcessor = (1 << 1),
Chris@55 63
Chris@55 64 /* assigns custom channel mask */
Chris@55 65 paWinWasapiUseChannelMask = (1 << 2),
Chris@55 66
Chris@55 67 /* selects non-Event driven method of data read/write
Chris@55 68 Note: WASAPI Event driven core is capable of 2ms latency!!!, but Polling
Chris@55 69 method can only provide 15-20ms latency. */
Chris@55 70 paWinWasapiPolling = (1 << 3),
Chris@55 71
Chris@55 72 /* forces custom thread priority setting, must be used if PaWasapiStreamInfo::threadPriority
Chris@55 73 is set to a custom value */
Chris@55 74 paWinWasapiThreadPriority = (1 << 4)
Chris@55 75 }
Chris@55 76 PaWasapiFlags;
Chris@55 77 #define paWinWasapiExclusive (paWinWasapiExclusive)
Chris@55 78 #define paWinWasapiRedirectHostProcessor (paWinWasapiRedirectHostProcessor)
Chris@55 79 #define paWinWasapiUseChannelMask (paWinWasapiUseChannelMask)
Chris@55 80 #define paWinWasapiPolling (paWinWasapiPolling)
Chris@55 81 #define paWinWasapiThreadPriority (paWinWasapiThreadPriority)
Chris@55 82
Chris@55 83
Chris@55 84 /* Host processor. Allows to skip internal PA processing completely.
Chris@55 85 You must set paWinWasapiRedirectHostProcessor flag to PaWasapiStreamInfo::flags member
Chris@55 86 in order to have host processor redirected to your callback.
Chris@55 87 Use with caution! inputFrames and outputFrames depend solely on final device setup.
Chris@55 88 To query maximal values of inputFrames/outputFrames use PaWasapi_GetFramesPerHostBuffer.
Chris@55 89 */
Chris@55 90 typedef void (*PaWasapiHostProcessorCallback) (void *inputBuffer, long inputFrames,
Chris@55 91 void *outputBuffer, long outputFrames,
Chris@55 92 void *userData);
Chris@55 93
Chris@55 94 /* Device role. */
Chris@55 95 typedef enum PaWasapiDeviceRole
Chris@55 96 {
Chris@55 97 eRoleRemoteNetworkDevice = 0,
Chris@55 98 eRoleSpeakers,
Chris@55 99 eRoleLineLevel,
Chris@55 100 eRoleHeadphones,
Chris@55 101 eRoleMicrophone,
Chris@55 102 eRoleHeadset,
Chris@55 103 eRoleHandset,
Chris@55 104 eRoleUnknownDigitalPassthrough,
Chris@55 105 eRoleSPDIF,
Chris@55 106 eRoleHDMI,
Chris@55 107 eRoleUnknownFormFactor
Chris@55 108 }
Chris@55 109 PaWasapiDeviceRole;
Chris@55 110
Chris@55 111
Chris@55 112 /* Jack connection type. */
Chris@55 113 typedef enum PaWasapiJackConnectionType
Chris@55 114 {
Chris@55 115 eJackConnTypeUnknown,
Chris@55 116 eJackConnType3Point5mm,
Chris@55 117 eJackConnTypeQuarter,
Chris@55 118 eJackConnTypeAtapiInternal,
Chris@55 119 eJackConnTypeRCA,
Chris@55 120 eJackConnTypeOptical,
Chris@55 121 eJackConnTypeOtherDigital,
Chris@55 122 eJackConnTypeOtherAnalog,
Chris@55 123 eJackConnTypeMultichannelAnalogDIN,
Chris@55 124 eJackConnTypeXlrProfessional,
Chris@55 125 eJackConnTypeRJ11Modem,
Chris@55 126 eJackConnTypeCombination
Chris@55 127 }
Chris@55 128 PaWasapiJackConnectionType;
Chris@55 129
Chris@55 130
Chris@55 131 /* Jack geometric location. */
Chris@55 132 typedef enum PaWasapiJackGeoLocation
Chris@55 133 {
Chris@55 134 eJackGeoLocUnk = 0,
Chris@55 135 eJackGeoLocRear = 0x1, /* matches EPcxGeoLocation::eGeoLocRear */
Chris@55 136 eJackGeoLocFront,
Chris@55 137 eJackGeoLocLeft,
Chris@55 138 eJackGeoLocRight,
Chris@55 139 eJackGeoLocTop,
Chris@55 140 eJackGeoLocBottom,
Chris@55 141 eJackGeoLocRearPanel,
Chris@55 142 eJackGeoLocRiser,
Chris@55 143 eJackGeoLocInsideMobileLid,
Chris@55 144 eJackGeoLocDrivebay,
Chris@55 145 eJackGeoLocHDMI,
Chris@55 146 eJackGeoLocOutsideMobileLid,
Chris@55 147 eJackGeoLocATAPI,
Chris@55 148 eJackGeoLocReserved5,
Chris@55 149 eJackGeoLocReserved6,
Chris@55 150 }
Chris@55 151 PaWasapiJackGeoLocation;
Chris@55 152
Chris@55 153
Chris@55 154 /* Jack general location. */
Chris@55 155 typedef enum PaWasapiJackGenLocation
Chris@55 156 {
Chris@55 157 eJackGenLocPrimaryBox = 0,
Chris@55 158 eJackGenLocInternal,
Chris@55 159 eJackGenLocSeparate,
Chris@55 160 eJackGenLocOther
Chris@55 161 }
Chris@55 162 PaWasapiJackGenLocation;
Chris@55 163
Chris@55 164
Chris@55 165 /* Jack's type of port. */
Chris@55 166 typedef enum PaWasapiJackPortConnection
Chris@55 167 {
Chris@55 168 eJackPortConnJack = 0,
Chris@55 169 eJackPortConnIntegratedDevice,
Chris@55 170 eJackPortConnBothIntegratedAndJack,
Chris@55 171 eJackPortConnUnknown
Chris@55 172 }
Chris@55 173 PaWasapiJackPortConnection;
Chris@55 174
Chris@55 175
Chris@55 176 /* Thread priority. */
Chris@55 177 typedef enum PaWasapiThreadPriority
Chris@55 178 {
Chris@55 179 eThreadPriorityNone = 0,
Chris@55 180 eThreadPriorityAudio, //!< Default for Shared mode.
Chris@55 181 eThreadPriorityCapture,
Chris@55 182 eThreadPriorityDistribution,
Chris@55 183 eThreadPriorityGames,
Chris@55 184 eThreadPriorityPlayback,
Chris@55 185 eThreadPriorityProAudio, //!< Default for Exclusive mode.
Chris@55 186 eThreadPriorityWindowManager
Chris@55 187 }
Chris@55 188 PaWasapiThreadPriority;
Chris@55 189
Chris@55 190
Chris@55 191 /* Stream descriptor. */
Chris@55 192 typedef struct PaWasapiJackDescription
Chris@55 193 {
Chris@55 194 unsigned long channelMapping;
Chris@55 195 unsigned long color; /* derived from macro: #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) */
Chris@55 196 PaWasapiJackConnectionType connectionType;
Chris@55 197 PaWasapiJackGeoLocation geoLocation;
Chris@55 198 PaWasapiJackGenLocation genLocation;
Chris@55 199 PaWasapiJackPortConnection portConnection;
Chris@55 200 unsigned int isConnected;
Chris@55 201 }
Chris@55 202 PaWasapiJackDescription;
Chris@55 203
Chris@55 204
Chris@55 205 /** Stream category.
Chris@55 206 Note:
Chris@55 207 - values are equal to WASAPI AUDIO_STREAM_CATEGORY enum
Chris@55 208 - supported since Windows 8.0, noop on earler versions
Chris@55 209 - values 1,2 are deprecated on Windows 10 and not included into enumeration
Chris@55 210
Chris@55 211 @version Available as of 19.6.0
Chris@55 212 */
Chris@55 213 typedef enum PaWasapiStreamCategory
Chris@55 214 {
Chris@55 215 eAudioCategoryOther = 0,
Chris@55 216 eAudioCategoryCommunications = 3,
Chris@55 217 eAudioCategoryAlerts = 4,
Chris@55 218 eAudioCategorySoundEffects = 5,
Chris@55 219 eAudioCategoryGameEffects = 6,
Chris@55 220 eAudioCategoryGameMedia = 7,
Chris@55 221 eAudioCategoryGameChat = 8,
Chris@55 222 eAudioCategorySpeech = 9,
Chris@55 223 eAudioCategoryMovie = 10,
Chris@55 224 eAudioCategoryMedia = 11
Chris@55 225 }
Chris@55 226 PaWasapiStreamCategory;
Chris@55 227
Chris@55 228
Chris@55 229 /** Stream option.
Chris@55 230 Note:
Chris@55 231 - values are equal to WASAPI AUDCLNT_STREAMOPTIONS enum
Chris@55 232 - supported since Windows 8.1, noop on earler versions
Chris@55 233
Chris@55 234 @version Available as of 19.6.0
Chris@55 235 */
Chris@55 236 typedef enum PaWasapiStreamOption
Chris@55 237 {
Chris@55 238 eStreamOptionNone = 0, //!< default
Chris@55 239 eStreamOptionRaw = 1, //!< bypass WASAPI Audio Engine DSP effects, supported since Windows 8.1
Chris@55 240 eStreamOptionMatchFormat = 2 //!< force WASAPI Audio Engine into a stream format, supported since Windows 10
Chris@55 241 }
Chris@55 242 PaWasapiStreamOption;
Chris@55 243
Chris@55 244
Chris@55 245 /* Stream descriptor. */
Chris@55 246 typedef struct PaWasapiStreamInfo
Chris@55 247 {
Chris@55 248 unsigned long size; /**< sizeof(PaWasapiStreamInfo) */
Chris@55 249 PaHostApiTypeId hostApiType; /**< paWASAPI */
Chris@55 250 unsigned long version; /**< 1 */
Chris@55 251
Chris@55 252 unsigned long flags; /**< collection of PaWasapiFlags */
Chris@55 253
Chris@55 254 /** Support for WAVEFORMATEXTENSIBLE channel masks. If flags contains
Chris@55 255 paWinWasapiUseChannelMask this allows you to specify which speakers
Chris@55 256 to address in a multichannel stream. Constants for channelMask
Chris@55 257 are specified in pa_win_waveformat.h. Will be used only if
Chris@55 258 paWinWasapiUseChannelMask flag is specified.
Chris@55 259 */
Chris@55 260 PaWinWaveFormatChannelMask channelMask;
Chris@55 261
Chris@55 262 /** Delivers raw data to callback obtained from GetBuffer() methods skipping
Chris@55 263 internal PortAudio processing inventory completely. userData parameter will
Chris@55 264 be the same that was passed to Pa_OpenStream method. Will be used only if
Chris@55 265 paWinWasapiRedirectHostProcessor flag is specified.
Chris@55 266 */
Chris@55 267 PaWasapiHostProcessorCallback hostProcessorOutput;
Chris@55 268 PaWasapiHostProcessorCallback hostProcessorInput;
Chris@55 269
Chris@55 270 /** Specifies thread priority explicitly. Will be used only if paWinWasapiThreadPriority flag
Chris@55 271 is specified.
Chris@55 272
Chris@55 273 Please note, if Input/Output streams are opened simultaniously (Full-Duplex mode)
Chris@55 274 you shall specify same value for threadPriority or othervise one of the values will be used
Chris@55 275 to setup thread priority.
Chris@55 276 */
Chris@55 277 PaWasapiThreadPriority threadPriority;
Chris@55 278
Chris@55 279 /** Stream category.
Chris@55 280 @see PaWasapiStreamCategory
Chris@55 281 @version Available as of 19.6.0
Chris@55 282 */
Chris@55 283 PaWasapiStreamCategory streamCategory;
Chris@55 284
Chris@55 285 /** Stream option.
Chris@55 286 @see PaWasapiStreamOption
Chris@55 287 @version Available as of 19.6.0
Chris@55 288 */
Chris@55 289 PaWasapiStreamOption streamOption;
Chris@55 290 }
Chris@55 291 PaWasapiStreamInfo;
Chris@55 292
Chris@55 293
Chris@55 294 /** Returns default sound format for device. Format is represented by PaWinWaveFormat or
Chris@55 295 WAVEFORMATEXTENSIBLE structure.
Chris@55 296
Chris@55 297 @param pFormat Pointer to PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure.
Chris@55 298 @param nFormatSize Size of PaWinWaveFormat or WAVEFORMATEXTENSIBLE structure in bytes.
Chris@55 299 @param nDevice Device index.
Chris@55 300
Chris@55 301 @return Non-negative value indicating the number of bytes copied into format decriptor
Chris@55 302 or, a PaErrorCode (which are always negative) if PortAudio is not initialized
Chris@55 303 or an error is encountered.
Chris@55 304 */
Chris@55 305 int PaWasapi_GetDeviceDefaultFormat( void *pFormat, unsigned int nFormatSize, PaDeviceIndex nDevice );
Chris@55 306
Chris@55 307
Chris@55 308 /** Returns device role (PaWasapiDeviceRole enum).
Chris@55 309
Chris@55 310 @param nDevice device index.
Chris@55 311
Chris@55 312 @return Non-negative value indicating device role or, a PaErrorCode (which are always negative)
Chris@55 313 if PortAudio is not initialized or an error is encountered.
Chris@55 314 */
Chris@55 315 int/*PaWasapiDeviceRole*/ PaWasapi_GetDeviceRole( PaDeviceIndex nDevice );
Chris@55 316
Chris@55 317
Chris@55 318 /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
Chris@55 319 which makes calls to Pa_WriteStream/Pa_ReadStream.
Chris@55 320
Chris@55 321 @param hTask Handle to pointer to priority task. Must be used with PaWasapi_RevertThreadPriority
Chris@55 322 method to revert thread priority to initial state.
Chris@55 323
Chris@55 324 @param nPriorityClass Id of thread priority of PaWasapiThreadPriority type. Specifying
Chris@55 325 eThreadPriorityNone does nothing.
Chris@55 326
Chris@55 327 @return Error code indicating success or failure.
Chris@55 328 @see PaWasapi_RevertThreadPriority
Chris@55 329 */
Chris@55 330 PaError PaWasapi_ThreadPriorityBoost( void **hTask, PaWasapiThreadPriority nPriorityClass );
Chris@55 331
Chris@55 332
Chris@55 333 /** Boost thread priority of calling thread (MMCSS). Use it for Blocking Interface only for thread
Chris@55 334 which makes calls to Pa_WriteStream/Pa_ReadStream.
Chris@55 335
Chris@55 336 @param hTask Task handle obtained by PaWasapi_BoostThreadPriority method.
Chris@55 337 @return Error code indicating success or failure.
Chris@55 338 @see PaWasapi_BoostThreadPriority
Chris@55 339 */
Chris@55 340 PaError PaWasapi_ThreadPriorityRevert( void *hTask );
Chris@55 341
Chris@55 342
Chris@55 343 /** Get number of frames per host buffer. This is maximal value of frames of WASAPI buffer which
Chris@55 344 can be locked for operations. Use this method as helper to findout maximal values of
Chris@55 345 inputFrames/outputFrames of PaWasapiHostProcessorCallback.
Chris@55 346
Chris@55 347 @param pStream Pointer to PaStream to query.
Chris@55 348 @param nInput Pointer to variable to receive number of input frames. Can be NULL.
Chris@55 349 @param nOutput Pointer to variable to receive number of output frames. Can be NULL.
Chris@55 350 @return Error code indicating success or failure.
Chris@55 351 @see PaWasapiHostProcessorCallback
Chris@55 352 */
Chris@55 353 PaError PaWasapi_GetFramesPerHostBuffer( PaStream *pStream, unsigned int *nInput, unsigned int *nOutput );
Chris@55 354
Chris@55 355
Chris@55 356 /** Get number of jacks associated with a WASAPI device. Use this method to determine if
Chris@55 357 there are any jacks associated with the provided WASAPI device. Not all audio devices
Chris@55 358 will support this capability. This is valid for both input and output devices.
Chris@55 359 @param nDevice device index.
Chris@55 360 @param jcount Number of jacks is returned in this variable
Chris@55 361 @return Error code indicating success or failure
Chris@55 362 @see PaWasapi_GetJackDescription
Chris@55 363 */
Chris@55 364 PaError PaWasapi_GetJackCount(PaDeviceIndex nDevice, int *jcount);
Chris@55 365
Chris@55 366
Chris@55 367 /** Get the jack description associated with a WASAPI device and jack number
Chris@55 368 Before this function is called, use PaWasapi_GetJackCount to determine the
Chris@55 369 number of jacks associated with device. If jcount is greater than zero, then
Chris@55 370 each jack from 0 to jcount can be queried with this function to get the jack
Chris@55 371 description.
Chris@55 372 @param nDevice device index.
Chris@55 373 @param jindex Which jack to return information
Chris@55 374 @param KSJACK_DESCRIPTION This structure filled in on success.
Chris@55 375 @return Error code indicating success or failure
Chris@55 376 @see PaWasapi_GetJackCount
Chris@55 377 */
Chris@55 378 PaError PaWasapi_GetJackDescription(PaDeviceIndex nDevice, int jindex, PaWasapiJackDescription *pJackDescription);
Chris@55 379
Chris@55 380
Chris@55 381 /*
Chris@55 382 IMPORTANT:
Chris@55 383
Chris@55 384 WASAPI is implemented for Callback and Blocking interfaces. It supports Shared and Exclusive
Chris@55 385 share modes.
Chris@55 386
Chris@55 387 Exclusive Mode:
Chris@55 388
Chris@55 389 Exclusive mode allows to deliver audio data directly to hardware bypassing
Chris@55 390 software mixing.
Chris@55 391 Exclusive mode is specified by 'paWinWasapiExclusive' flag.
Chris@55 392
Chris@55 393 Callback Interface:
Chris@55 394
Chris@55 395 Provides best audio quality with low latency. Callback interface is implemented in
Chris@55 396 two versions:
Chris@55 397
Chris@55 398 1) Event-Driven:
Chris@55 399 This is the most powerful WASAPI implementation which provides glitch-free
Chris@55 400 audio at around 3ms latency in Exclusive mode. Lowest possible latency for this mode is
Chris@55 401 3 ms for HD Audio class audio chips. For the Shared mode latency can not be
Chris@55 402 lower than 20 ms.
Chris@55 403
Chris@55 404 2) Poll-Driven:
Chris@55 405 Polling is another 2-nd method to operate with WASAPI. It is less efficient than Event-Driven
Chris@55 406 and provides latency at around 10-13ms. Polling must be used to overcome a system bug
Chris@55 407 under Windows Vista x64 when application is WOW64(32-bit) and Event-Driven method simply
Chris@55 408 times out (event handle is never signalled on buffer completion). Please note, such WOW64 bug
Chris@55 409 does not exist in Vista x86 or Windows 7.
Chris@55 410 Polling can be setup by speciying 'paWinWasapiPolling' flag. Our WASAPI implementation detects
Chris@55 411 WOW64 bug and sets 'paWinWasapiPolling' automatically.
Chris@55 412
Chris@55 413 Thread priority:
Chris@55 414
Chris@55 415 Normally thread priority is set automatically and does not require modification. Although
Chris@55 416 if user wants some tweaking thread priority can be modified by setting 'paWinWasapiThreadPriority'
Chris@55 417 flag and specifying 'PaWasapiStreamInfo::threadPriority' with value from PaWasapiThreadPriority
Chris@55 418 enum.
Chris@55 419
Chris@55 420 Blocking Interface:
Chris@55 421
Chris@55 422 Blocking interface is implemented but due to above described Poll-Driven method can not
Chris@55 423 deliver lowest possible latency. Specifying too low latency in Shared mode will result in
Chris@55 424 distorted audio although Exclusive mode adds stability.
Chris@55 425
Chris@55 426 Pa_IsFormatSupported:
Chris@55 427
Chris@55 428 To check format with correct Share Mode (Exclusive/Shared) you must supply
Chris@55 429 PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
Chris@55 430 PaStreamParameters::hostApiSpecificStreamInfo structure.
Chris@55 431
Chris@55 432 Pa_OpenStream:
Chris@55 433
Chris@55 434 To set desired Share Mode (Exclusive/Shared) you must supply
Chris@55 435 PaWasapiStreamInfo with flags paWinWasapiExclusive set through member of
Chris@55 436 PaStreamParameters::hostApiSpecificStreamInfo structure.
Chris@55 437 */
Chris@55 438
Chris@55 439 #ifdef __cplusplus
Chris@55 440 }
Chris@55 441 #endif /* __cplusplus */
Chris@55 442
Chris@55 443 #endif /* PA_WIN_WASAPI_H */