annotate src/portaudio_20140130/include/pa_win_wasapi.h @ 83:ae30d91d2ffe

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