69 #define WAIT_BETWEEN_CACHE_REFRESH_MILLIS 30000 70 71 /* maximum number of supported devices, playback+capture */ 72 #define MAX_DS_DEVICES 60 73 74 typedef struct { 75 INT32 mixerIndex; 76 BOOL isSource; 77 /* either LPDIRECTSOUND or LPDIRECTSOUNDCAPTURE */ 78 void* dev; 79 /* how many instances use the dev */ 80 INT32 refCount; 81 GUID guid; 82 } DS_AudioDeviceCache; 83 84 static DS_AudioDeviceCache g_audioDeviceCache[MAX_DS_DEVICES]; 85 static INT32 g_cacheCount = 0; 86 static UINT64 g_lastCacheRefreshTime = 0; 87 static INT32 g_mixerCount = 0; 88 89 BOOL DS_lockCache() { 90 /* dummy implementation for now, Java does locking */ 91 return TRUE; 92 } 93 94 void DS_unlockCache() { 95 /* dummy implementation for now */ 96 } 97 98 static GUID CLSID_DAUDIO_Zero = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 99 100 BOOL isEqualGUID(LPGUID lpGuid1, LPGUID lpGuid2) { 101 if (lpGuid1 == NULL || lpGuid2 == NULL) { 102 if (lpGuid1 == lpGuid2) { 103 return TRUE; 104 } 105 if (lpGuid1 == NULL) { 106 lpGuid1 = (LPGUID) (&CLSID_DAUDIO_Zero); 107 } else { 108 lpGuid2 = (LPGUID) (&CLSID_DAUDIO_Zero); 216 g_audioDeviceCache[cacheIndex].mixerIndex = -1; 217 TRACE0("Removing stale Primary Sound Capture Driver from list.\n"); 218 } 219 } 220 g_mixerCount = rs.currMixerIndex; 221 222 g_lastCacheRefreshTime = (UINT64) timeGetTime(); 223 } 224 DS_unlockCache(); 225 /*TRACE1("DirectSound: %d installed devices\n", g_mixerCount);*/ 226 return g_mixerCount; 227 } 228 229 BOOL CALLBACK DS_GetDescEnum(LPGUID lpGuid, 230 LPCSTR lpstrDescription, 231 LPCSTR lpstrModule, 232 DirectAudioDeviceDescription* desc) { 233 234 INT32 cacheIndex = findCacheItemByGUID(lpGuid, g_audioDeviceCache[desc->deviceID].isSource); 235 if (cacheIndex == desc->deviceID) { 236 strncpy(desc->name, lpstrDescription, DAUDIO_STRING_LENGTH); 237 //strncpy(desc->description, lpstrModule, DAUDIO_STRING_LENGTH); 238 desc->maxSimulLines = -1; 239 /* do not continue enumeration */ 240 return FALSE; 241 } 242 return TRUE; 243 } 244 245 246 INT32 DAUDIO_GetDirectAudioDeviceDescription(INT32 mixerIndex, DirectAudioDeviceDescription* desc) { 247 248 if (!DS_lockCache()) { 249 return FALSE; 250 } 251 252 /* set the deviceID field to the cache index */ 253 desc->deviceID = findCacheItemByMixerIndex(mixerIndex); 254 if (desc->deviceID < 0) { 255 DS_unlockCache(); 256 return FALSE; | 69 #define WAIT_BETWEEN_CACHE_REFRESH_MILLIS 30000 70 71 /* maximum number of supported devices, playback+capture */ 72 #define MAX_DS_DEVICES 60 73 74 typedef struct { 75 INT32 mixerIndex; 76 BOOL isSource; 77 /* either LPDIRECTSOUND or LPDIRECTSOUNDCAPTURE */ 78 void* dev; 79 /* how many instances use the dev */ 80 INT32 refCount; 81 GUID guid; 82 } DS_AudioDeviceCache; 83 84 static DS_AudioDeviceCache g_audioDeviceCache[MAX_DS_DEVICES]; 85 static INT32 g_cacheCount = 0; 86 static UINT64 g_lastCacheRefreshTime = 0; 87 static INT32 g_mixerCount = 0; 88 89 /// FIX BUG JDK-8177951: Convert ANSI encoded string to UTF-8 encoded string 90 LPCSTR ANSIToUTF8(const LPCSTR& lpAnsiStr) 91 { 92 // ANSI -> Unicode 93 DWORD dwAnsiLen = strlen(lpAnsiStr); 94 DWORD dwUnicodeLen = ::MultiByteToWideChar(CP_ACP, 0, lpAnsiStr, -1, NULL, 0); 95 LPWSTR lpUnicodeStr; 96 lpUnicodeStr = new WCHAR[dwUnicodeLen]; 97 memset(lpUnicodeStr, 0, (dwUnicodeLen) * sizeof(WCHAR)); 98 MultiByteToWideChar(CP_ACP, 0, lpAnsiStr, -1, lpUnicodeStr, dwUnicodeLen); 99 100 // Unicode -> UTF8 101 LPSTR lpUTF8Str; 102 DWORD dwUTF8Len; 103 dwUTF8Len = WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, NULL, 0, NULL, NULL); 104 lpUTF8Str = new CHAR[dwUTF8Len]; 105 memset(lpUTF8Str, 0, sizeof(CHAR) * (dwUTF8Len)); 106 WideCharToMultiByte(CP_UTF8, 0, lpUnicodeStr, -1, lpUTF8Str, dwUTF8Len, NULL, NULL); 107 delete lpUnicodeStr; 108 return lpUTF8Str; 109 } 110 111 BOOL DS_lockCache() { 112 /* dummy implementation for now, Java does locking */ 113 return TRUE; 114 } 115 116 void DS_unlockCache() { 117 /* dummy implementation for now */ 118 } 119 120 static GUID CLSID_DAUDIO_Zero = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 121 122 BOOL isEqualGUID(LPGUID lpGuid1, LPGUID lpGuid2) { 123 if (lpGuid1 == NULL || lpGuid2 == NULL) { 124 if (lpGuid1 == lpGuid2) { 125 return TRUE; 126 } 127 if (lpGuid1 == NULL) { 128 lpGuid1 = (LPGUID) (&CLSID_DAUDIO_Zero); 129 } else { 130 lpGuid2 = (LPGUID) (&CLSID_DAUDIO_Zero); 238 g_audioDeviceCache[cacheIndex].mixerIndex = -1; 239 TRACE0("Removing stale Primary Sound Capture Driver from list.\n"); 240 } 241 } 242 g_mixerCount = rs.currMixerIndex; 243 244 g_lastCacheRefreshTime = (UINT64) timeGetTime(); 245 } 246 DS_unlockCache(); 247 /*TRACE1("DirectSound: %d installed devices\n", g_mixerCount);*/ 248 return g_mixerCount; 249 } 250 251 BOOL CALLBACK DS_GetDescEnum(LPGUID lpGuid, 252 LPCSTR lpstrDescription, 253 LPCSTR lpstrModule, 254 DirectAudioDeviceDescription* desc) { 255 256 INT32 cacheIndex = findCacheItemByGUID(lpGuid, g_audioDeviceCache[desc->deviceID].isSource); 257 if (cacheIndex == desc->deviceID) { 258 #ifndef UNICODE 259 LPCSTR utf8EncodedName = ANSIToUTF8(lpstrDescription); 260 strncpy(desc->name, utf8EncodedName, DAUDIO_STRING_LENGTH); 261 delete utf8EncodedName; 262 #else 263 strncpy(desc->name, lpstrDescription, DAUDIO_STRING_LENGTH); 264 #endif 265 //strncpy(desc->description, lpstrModule, DAUDIO_STRING_LENGTH); 266 desc->maxSimulLines = -1; 267 /* do not continue enumeration */ 268 return FALSE; 269 } 270 return TRUE; 271 } 272 273 274 INT32 DAUDIO_GetDirectAudioDeviceDescription(INT32 mixerIndex, DirectAudioDeviceDescription* desc) { 275 276 if (!DS_lockCache()) { 277 return FALSE; 278 } 279 280 /* set the deviceID field to the cache index */ 281 desc->deviceID = findCacheItemByMixerIndex(mixerIndex); 282 if (desc->deviceID < 0) { 283 DS_unlockCache(); 284 return FALSE; |