diff options
-rw-r--r-- | pjmedia/include/pjmedia/config.h | 10 | ||||
-rw-r--r-- | pjmedia/src/pjmedia/pasound.c | 36 |
2 files changed, 45 insertions, 1 deletions
diff --git a/pjmedia/include/pjmedia/config.h b/pjmedia/include/pjmedia/config.h index 0b7f542a..a0c0ee5d 100644 --- a/pjmedia/include/pjmedia/config.h +++ b/pjmedia/include/pjmedia/config.h @@ -73,6 +73,16 @@ /** + * Specify whether we prefer to use DirectSound on Windows. + * + * Say yes! + */ +#ifndef PJMEDIA_PREFER_DIRECT_SOUND +# define PJMEDIA_PREFER_DIRECT_SOUND 1 +#endif + + +/** * Specify number of sound buffers. Larger number is better for sound * stability and to accomodate sound devices that are unable to send frames * in timely manner, however it would probably cause more audio delay (and diff --git a/pjmedia/src/pjmedia/pasound.c b/pjmedia/src/pjmedia/pasound.c index a2ec6276..1a5e819c 100644 --- a/pjmedia/src/pjmedia/pasound.c +++ b/pjmedia/src/pjmedia/pasound.c @@ -265,6 +265,23 @@ static int pa_get_default_input_dev(int channel_count) { int i, count; + /* Special for Windows - try to use the DirectSound implementation + * first since it provides better latency. + */ +#if PJMEDIA_PREFER_DIRECT_SOUND + if (Pa_HostApiTypeIdToHostApiIndex(paDirectSound) >= 0) { + const PaHostApiInfo *pHI; + int index = Pa_HostApiTypeIdToHostApiIndex(paDirectSound); + pHI = Pa_GetHostApiInfo(index); + if (pHI) { + const PaDeviceInfo *paDevInfo = NULL; + paDevInfo = Pa_GetDeviceInfo(pHI->defaultInputDevice); + if (paDevInfo && paDevInfo->maxInputChannels >= channel_count) + return pHI->defaultInputDevice; + } + } +#endif + /* Enumerate the host api's for the default devices, and return * the device with suitable channels. */ @@ -304,6 +321,23 @@ static int pa_get_default_output_dev(int channel_count) { int i, count; + /* Special for Windows - try to use the DirectSound implementation + * first since it provides better latency. + */ +#if PJMEDIA_PREFER_DIRECT_SOUND + if (Pa_HostApiTypeIdToHostApiIndex(paDirectSound) >= 0) { + const PaHostApiInfo *pHI; + int index = Pa_HostApiTypeIdToHostApiIndex(paDirectSound); + pHI = Pa_GetHostApiInfo(index); + if (pHI) { + const PaDeviceInfo *paDevInfo = NULL; + paDevInfo = Pa_GetDeviceInfo(pHI->defaultOutputDevice); + if (paDevInfo && paDevInfo->maxOutputChannels >= channel_count) + return pHI->defaultOutputDevice; + } + } +#endif + /* Enumerate the host api's for the default devices, and return * the device with suitable channels. */ @@ -334,7 +368,7 @@ static int pa_get_default_output_dev(int channel_count) if (paDevInfo->maxOutputChannels >= channel_count) return i; } - + return -1; } |