summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-09-28 13:12:15 +0000
committerBenny Prijono <bennylp@teluu.com>2007-09-28 13:12:15 +0000
commit59ec12f02f622b889aa42d725db79592b4040fd2 (patch)
tree7ad9519001cabc371a78c99c79c87ea8d7bd3db9
parentb584e87dd4000183820bf6a4c90f3061d524fe8b (diff)
Ticket #384: Prefer to use Direct Sound as the sound device backend on Windows
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1456 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/include/pjmedia/config.h10
-rw-r--r--pjmedia/src/pjmedia/pasound.c36
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;
}