1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1998 Patrik Stridvall
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
43 /**********************************************************************/
45 HANDLE MSACM_hHeap = NULL;
46 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
47 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
49 static DWORD MSACM_suspendBroadcastCount = 0;
50 static BOOL MSACM_pendingBroadcast = FALSE;
51 static PWINE_ACMNOTIFYWND MSACM_pFirstACMNotifyWnd = NULL;
52 static PWINE_ACMNOTIFYWND MSACM_pLastACMNotifyWnd = NULL;
54 static void MSACM_ReorderDriversByPriority(void);
56 /***********************************************************************
57 * MSACM_RegisterDriverFromRegistry()
59 PWINE_ACMDRIVERID MSACM_RegisterDriverFromRegistry(LPCWSTR pszRegEntry)
61 static const WCHAR msacmW[] = {'M','S','A','C','M','.'};
62 static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\',
63 'M','i','c','r','o','s','o','f','t','\\',
64 'W','i','n','d','o','w','s',' ','N','T','\\',
65 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
66 'D','r','i','v','e','r','s','3','2','\0'};
70 PWINE_ACMDRIVERID padid = NULL;
72 /* The requested registry entry must have the format msacm.XXXXX in order to
73 be recognized in any future sessions of msacm
75 if (0 == strncmpiW(buf, msacmW, sizeof(msacmW)/sizeof(WCHAR))) {
76 lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey);
77 if (lRet != ERROR_SUCCESS) {
78 WARN("unable to open registry key - 0x%08lx\n", lRet);
81 lRet = RegQueryValueExW(hKey, pszRegEntry, NULL, NULL, (LPBYTE)buf, &bufLen);
82 if (lRet != ERROR_SUCCESS) {
83 WARN("unable to query requested subkey %s - 0x%08lx\n", debugstr_w(pszRegEntry), lRet);
85 MSACM_RegisterDriver(pszRegEntry, buf, 0);
94 /***********************************************************************
97 static void MSACM_DumpCache(PWINE_ACMDRIVERID padid)
101 TRACE("cFilterTags=%lu cFormatTags=%lu fdwSupport=%08lx\n",
102 padid->cFilterTags, padid->cFormatTags, padid->fdwSupport);
103 for (i = 0; i < padid->cache->cFormatTags; i++) {
104 TRACE("\tdwFormatTag=%lu cbwfx=%lu\n",
105 padid->aFormatTag[i].dwFormatTag, padid->aFormatTag[i].cbwfx);
110 /***********************************************************************
111 * MSACM_FindFormatTagInCache [internal]
113 * Returns TRUE is the format tag fmtTag is present in the cache.
114 * If so, idx is set to its index.
116 BOOL MSACM_FindFormatTagInCache(WINE_ACMDRIVERID* padid, DWORD fmtTag, LPDWORD idx)
120 for (i = 0; i < padid->cFormatTags; i++) {
121 if (padid->aFormatTag[i].dwFormatTag == fmtTag) {
129 /***********************************************************************
132 static BOOL MSACM_FillCache(PWINE_ACMDRIVERID padid)
136 ACMDRIVERDETAILSW add;
137 ACMFORMATTAGDETAILSW aftd;
139 if (acmDriverOpen(&had, (HACMDRIVERID)padid, 0) != 0)
142 padid->aFormatTag = NULL;
143 add.cbStruct = sizeof(add);
144 if (MSACM_Message(had, ACMDM_DRIVER_DETAILS, (LPARAM)&add, 0))
147 if (add.cFormatTags > 0) {
148 padid->aFormatTag = HeapAlloc(MSACM_hHeap, HEAP_ZERO_MEMORY,
149 add.cFormatTags * sizeof(padid->aFormatTag[0]));
150 if (!padid->aFormatTag) goto errCleanUp;
153 padid->cFormatTags = add.cFormatTags;
154 padid->cFilterTags = add.cFilterTags;
155 padid->fdwSupport = add.fdwSupport;
157 aftd.cbStruct = sizeof(aftd);
159 for (ntag = 0; ntag < add.cFormatTags; ntag++) {
160 aftd.dwFormatTagIndex = ntag;
161 if (MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)&aftd, ACM_FORMATTAGDETAILSF_INDEX)) {
162 TRACE("IIOs (%s)\n", debugstr_w(padid->pszDriverAlias));
165 padid->aFormatTag[ntag].dwFormatTag = aftd.dwFormatTag;
166 padid->aFormatTag[ntag].cbwfx = aftd.cbFormatSize;
169 acmDriverClose(had, 0);
174 if (had) acmDriverClose(had, 0);
175 HeapFree(MSACM_hHeap, 0, padid->aFormatTag);
176 padid->aFormatTag = NULL;
180 /***********************************************************************
181 * MSACM_GetRegistryKey
183 static LPWSTR MSACM_GetRegistryKey(const WINE_ACMDRIVERID* padid)
185 static const WCHAR baseKey[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
186 'A','u','d','i','o','C','o','m','p','r','e','s','s','i','o','n','M','a','n','a','g','e','r','\\',
187 'D','r','i','v','e','r','C','a','c','h','e','\\','\0'};
191 if (!padid->pszDriverAlias) {
192 ERR("No alias needed for registry entry\n");
195 len = strlenW(baseKey);
196 ret = HeapAlloc(MSACM_hHeap, 0, (len + strlenW(padid->pszDriverAlias) + 1) * sizeof(WCHAR));
197 if (!ret) return NULL;
199 strcpyW(ret, baseKey);
200 strcpyW(ret + len, padid->pszDriverAlias);
201 CharLowerW(ret + len);
205 /***********************************************************************
208 static BOOL MSACM_ReadCache(PWINE_ACMDRIVERID padid)
210 LPWSTR key = MSACM_GetRegistryKey(padid);
214 if (!key) return FALSE;
216 padid->aFormatTag = NULL;
218 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, key, &hKey))
221 size = sizeof(padid->cFormatTags);
222 if (RegQueryValueExA(hKey, "cFormatTags", 0, &type, (void*)&padid->cFormatTags, &size))
224 size = sizeof(padid->cFilterTags);
225 if (RegQueryValueExA(hKey, "cFilterTags", 0, &type, (void*)&padid->cFilterTags, &size))
227 size = sizeof(padid->fdwSupport);
228 if (RegQueryValueExA(hKey, "fdwSupport", 0, &type, (void*)&padid->fdwSupport, &size))
231 if (padid->cFormatTags > 0) {
232 size = padid->cFormatTags * sizeof(padid->aFormatTag[0]);
233 padid->aFormatTag = HeapAlloc(MSACM_hHeap, HEAP_ZERO_MEMORY, size);
234 if (!padid->aFormatTag) goto errCleanUp;
235 if (RegQueryValueExA(hKey, "aFormatTagCache", 0, &type, (void*)padid->aFormatTag, &size))
238 HeapFree(MSACM_hHeap, 0, key);
242 HeapFree(MSACM_hHeap, 0, key);
243 HeapFree(MSACM_hHeap, 0, padid->aFormatTag);
244 padid->aFormatTag = NULL;
249 /***********************************************************************
252 static BOOL MSACM_WriteCache(PWINE_ACMDRIVERID padid)
254 LPWSTR key = MSACM_GetRegistryKey(padid);
257 if (!key) return FALSE;
259 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, key, &hKey))
262 if (RegSetValueExA(hKey, "cFormatTags", 0, REG_DWORD, (void*)&padid->cFormatTags, sizeof(DWORD)))
264 if (RegSetValueExA(hKey, "cFilterTags", 0, REG_DWORD, (void*)&padid->cFilterTags, sizeof(DWORD)))
266 if (RegSetValueExA(hKey, "fdwSupport", 0, REG_DWORD, (void*)&padid->fdwSupport, sizeof(DWORD)))
268 if (RegSetValueExA(hKey, "aFormatTagCache", 0, REG_BINARY,
269 (void*)padid->aFormatTag,
270 padid->cFormatTags * sizeof(padid->aFormatTag[0])))
272 HeapFree(MSACM_hHeap, 0, key);
276 HeapFree(MSACM_hHeap, 0, key);
280 /***********************************************************************
281 * MSACM_RegisterDriver()
283 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPCWSTR pszDriverAlias, LPCWSTR pszFileName,
284 HINSTANCE hinstModule)
286 PWINE_ACMDRIVERID padid;
288 TRACE("(%s, %s, %p)\n",
289 debugstr_w(pszDriverAlias), debugstr_w(pszFileName), hinstModule);
291 padid = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
292 padid->obj.dwType = WINE_ACMOBJ_DRIVERID;
293 padid->obj.pACMDriverID = padid;
294 padid->pszDriverAlias = NULL;
297 padid->pszDriverAlias = HeapAlloc( MSACM_hHeap, 0, (strlenW(pszDriverAlias)+1) * sizeof(WCHAR) );
298 strcpyW( padid->pszDriverAlias, pszDriverAlias );
300 padid->pszFileName = NULL;
303 padid->pszFileName = HeapAlloc( MSACM_hHeap, 0, (strlenW(pszFileName)+1) * sizeof(WCHAR) );
304 strcpyW( padid->pszFileName, pszFileName );
306 padid->hInstModule = hinstModule;
308 padid->pACMDriverList = NULL;
309 padid->pNextACMDriverID = NULL;
310 padid->pPrevACMDriverID = MSACM_pLastACMDriverID;
311 if (MSACM_pLastACMDriverID)
312 MSACM_pLastACMDriverID->pNextACMDriverID = padid;
313 MSACM_pLastACMDriverID = padid;
314 if (!MSACM_pFirstACMDriverID)
315 MSACM_pFirstACMDriverID = padid;
316 /* disable the driver if we cannot load the cache */
317 if (!MSACM_ReadCache(padid) && !MSACM_FillCache(padid)) {
318 WARN("Couldn't load cache for ACM driver (%s)\n", debugstr_w(pszFileName));
319 MSACM_UnregisterDriver(padid);
325 /***********************************************************************
326 * MSACM_RegisterAllDrivers()
328 void MSACM_RegisterAllDrivers(void)
330 static const WCHAR msacm32[] = {'m','s','a','c','m','3','2','.','d','l','l','\0'};
331 static const WCHAR msacmW[] = {'M','S','A','C','M','.'};
332 static const WCHAR drv32[] = {'d','r','i','v','e','r','s','3','2','\0'};
333 static const WCHAR sys[] = {'s','y','s','t','e','m','.','i','n','i','\0'};
334 static const WCHAR drvkey[] = {'S','o','f','t','w','a','r','e','\\',
335 'M','i','c','r','o','s','o','f','t','\\',
336 'W','i','n','d','o','w','s',' ','N','T','\\',
337 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
338 'D','r','i','v','e','r','s','3','2','\0'};
339 DWORD i, cnt = 0, bufLen, lRet;
340 WCHAR buf[2048], *name, *s;
344 /* FIXME: What if the user edits system.ini while the program is running?
345 * Does Windows handle that? */
346 if (MSACM_pFirstACMDriverID) return;
348 lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, drvkey, 0, KEY_QUERY_VALUE, &hKey);
349 if (lRet == ERROR_SUCCESS) {
350 RegQueryInfoKeyW( hKey, 0, 0, 0, &cnt, 0, 0, 0, 0, 0, 0, 0);
351 for (i = 0; i < cnt; i++) {
352 bufLen = sizeof(buf) / sizeof(buf[0]);
353 lRet = RegEnumKeyExW(hKey, i, buf, &bufLen, 0, 0, 0, &lastWrite);
354 if (lRet != ERROR_SUCCESS) continue;
355 if (strncmpiW(buf, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue;
356 if (!(name = strchrW(buf, '='))) continue;
358 MSACM_RegisterDriver(buf, name + 1, 0);
363 if (GetPrivateProfileSectionW(drv32, buf, sizeof(buf)/sizeof(buf[0]), sys))
365 for(s = buf; *s; s += strlenW(s) + 1)
367 if (strncmpiW(s, msacmW, sizeof(msacmW)/sizeof(msacmW[0]))) continue;
368 if (!(name = strchrW(s, '='))) continue;
370 MSACM_RegisterDriver(s, name + 1, 0);
374 MSACM_ReorderDriversByPriority();
375 MSACM_RegisterDriver(msacm32, msacm32, 0);
378 /***********************************************************************
379 * MSACM_RegisterNotificationWindow()
381 PWINE_ACMNOTIFYWND MSACM_RegisterNotificationWindow(HWND hNotifyWnd, DWORD dwNotifyMsg)
383 PWINE_ACMNOTIFYWND panwnd;
385 TRACE("(%p,0x%08lx)\n", hNotifyWnd, dwNotifyMsg);
387 panwnd = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMNOTIFYWND));
388 panwnd->obj.dwType = WINE_ACMOBJ_NOTIFYWND;
389 panwnd->obj.pACMDriverID = 0;
390 panwnd->hNotifyWnd = hNotifyWnd;
391 panwnd->dwNotifyMsg = dwNotifyMsg;
392 panwnd->fdwSupport = 0;
394 panwnd->pNextACMNotifyWnd = NULL;
395 panwnd->pPrevACMNotifyWnd = MSACM_pLastACMNotifyWnd;
396 if (MSACM_pLastACMNotifyWnd)
397 MSACM_pLastACMNotifyWnd->pNextACMNotifyWnd = panwnd;
398 MSACM_pLastACMNotifyWnd = panwnd;
399 if (!MSACM_pFirstACMNotifyWnd)
400 MSACM_pFirstACMNotifyWnd = panwnd;
405 /***********************************************************************
406 * MSACM_BroadcastNotification()
408 void MSACM_BroadcastNotification(void)
410 if (MSACM_suspendBroadcastCount <= 0) {
411 PWINE_ACMNOTIFYWND panwnd;
413 for (panwnd = MSACM_pFirstACMNotifyWnd; panwnd; panwnd = panwnd->pNextACMNotifyWnd)
414 if (!(panwnd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED))
415 SendMessageW(panwnd->hNotifyWnd, panwnd->dwNotifyMsg, 0, 0);
417 MSACM_pendingBroadcast = TRUE;
421 /***********************************************************************
422 * MSACM_DisableNotifications()
424 void MSACM_DisableNotifications(void)
426 MSACM_suspendBroadcastCount++;
429 /***********************************************************************
430 * MSACM_EnableNotifications()
432 void MSACM_EnableNotifications(void)
434 if (MSACM_suspendBroadcastCount > 0) {
435 MSACM_suspendBroadcastCount--;
436 if (MSACM_suspendBroadcastCount == 0 && MSACM_pendingBroadcast) {
437 MSACM_pendingBroadcast = FALSE;
438 MSACM_BroadcastNotification();
443 /***********************************************************************
444 * MSACM_UnRegisterNotificationWindow()
446 PWINE_ACMNOTIFYWND MSACM_UnRegisterNotificationWindow(PWINE_ACMNOTIFYWND panwnd)
448 PWINE_ACMNOTIFYWND p;
450 for (p = MSACM_pFirstACMNotifyWnd; p; p = p->pNextACMNotifyWnd) {
452 PWINE_ACMNOTIFYWND pNext = p->pNextACMNotifyWnd;
454 if (p->pPrevACMNotifyWnd) p->pPrevACMNotifyWnd->pNextACMNotifyWnd = p->pNextACMNotifyWnd;
455 if (p->pNextACMNotifyWnd) p->pNextACMNotifyWnd->pPrevACMNotifyWnd = p->pPrevACMNotifyWnd;
456 if (MSACM_pFirstACMNotifyWnd == p) MSACM_pFirstACMNotifyWnd = p->pNextACMNotifyWnd;
457 if (MSACM_pLastACMNotifyWnd == p) MSACM_pLastACMNotifyWnd = p->pPrevACMNotifyWnd;
458 HeapFree(MSACM_hHeap, 0, p);
466 /***********************************************************************
467 * MSACM_RePositionDriver()
469 void MSACM_RePositionDriver(PWINE_ACMDRIVERID padid, DWORD dwPriority)
471 PWINE_ACMDRIVERID pTargetPosition = NULL;
473 /* Remove selected driver from linked list */
474 if (MSACM_pFirstACMDriverID == padid) {
475 MSACM_pFirstACMDriverID = padid->pNextACMDriverID;
477 if (MSACM_pLastACMDriverID == padid) {
478 MSACM_pLastACMDriverID = padid->pPrevACMDriverID;
480 if (padid->pPrevACMDriverID != NULL) {
481 padid->pPrevACMDriverID->pNextACMDriverID = padid->pNextACMDriverID;
483 if (padid->pNextACMDriverID != NULL) {
484 padid->pNextACMDriverID->pPrevACMDriverID = padid->pPrevACMDriverID;
487 /* Look up position where selected driver should be */
488 if (dwPriority == 1) {
489 pTargetPosition = padid->pPrevACMDriverID;
490 while (pTargetPosition->pPrevACMDriverID != NULL &&
491 !(pTargetPosition->pPrevACMDriverID->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL)) {
492 pTargetPosition = pTargetPosition->pPrevACMDriverID;
494 } else if (dwPriority == -1) {
495 pTargetPosition = padid->pNextACMDriverID;
496 while (pTargetPosition->pNextACMDriverID != NULL) {
497 pTargetPosition = pTargetPosition->pNextACMDriverID;
501 /* Place selected driver in selected position */
502 padid->pPrevACMDriverID = pTargetPosition->pPrevACMDriverID;
503 padid->pNextACMDriverID = pTargetPosition;
504 if (padid->pPrevACMDriverID != NULL) {
505 padid->pPrevACMDriverID->pNextACMDriverID = padid;
507 MSACM_pFirstACMDriverID = padid;
509 if (padid->pNextACMDriverID != NULL) {
510 padid->pNextACMDriverID->pPrevACMDriverID = padid;
512 MSACM_pLastACMDriverID = padid;
516 /***********************************************************************
517 * MSACM_ReorderDriversByPriority()
518 * Reorders all drivers based on the priority list indicated by the registry key:
519 * HKCU\\Software\\Microsoft\\Multimedia\\Audio Compression Manager\\Priority v4.00
521 static void MSACM_ReorderDriversByPriority(void)
523 PWINE_ACMDRIVERID padid;
524 unsigned int iNumDrivers;
525 PWINE_ACMDRIVERID * driverList = NULL;
526 HKEY hPriorityKey = NULL;
530 /* Count drivers && alloc corresponding memory for list */
532 for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) iNumDrivers++;
536 static const WCHAR basePriorityKey[] = {
537 'S','o','f','t','w','a','r','e','\\',
538 'M','i','c','r','o','s','o','f','t','\\',
539 'M','u','l','t','i','m','e','d','i','a','\\',
540 'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
541 'P','r','i','o','r','i','t','y',' ','v','4','.','0','0','\0'
547 driverList = HeapAlloc(MSACM_hHeap, 0, iNumDrivers * sizeof(PWINE_ACMDRIVERID));
550 ERR("out of memory\n");
554 lError = RegOpenKeyW(HKEY_CURRENT_USER, basePriorityKey, &hPriorityKey);
555 if (lError != ERROR_SUCCESS) {
556 TRACE("RegOpenKeyW failed, possibly key does not exist yet\n");
561 /* Copy drivers into list to simplify linked list modification */
562 for (i = 0, padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID, i++)
564 driverList[i] = padid;
567 /* Query each of the priorities in turn. Alias key is in lowercase.
568 The general form of the priority record is the following:
569 "PriorityN" --> "1, msacm.driveralias"
570 where N is an integer, and the value is a string of the driver
571 alias, prefixed by "1, " for an enabled driver, or "0, " for a
574 for (i = 0; i < iNumDrivers; i++)
576 static const WCHAR priorityTmpl[] = {'P','r','i','o','r','i','t','y','%','l','d','\0'};
578 unsigned int iTargetPosition;
579 unsigned int iCurrentPosition;
581 static const WCHAR sPrefix[] = {'m','s','a','c','m','.','\0'};
583 /* Build expected entry name */
584 snprintfW(szSubKey, 17, priorityTmpl, i + 1);
585 lBufferLength = sizeof(szBuffer);
586 lError = RegQueryValueExW(hPriorityKey, szSubKey, NULL, NULL, (LPBYTE)szBuffer, (LPDWORD)&lBufferLength);
587 if (lError != ERROR_SUCCESS) continue;
589 /* Recovered driver alias should be at this position */
592 /* Locate driver alias in driver list */
593 pAlias = strstrW(szBuffer, sPrefix);
594 if (pAlias == NULL) continue;
596 for (iCurrentPosition = 0; iCurrentPosition < iNumDrivers; iCurrentPosition++) {
597 if (strcmpiW(driverList[iCurrentPosition]->pszDriverAlias, pAlias) == 0)
600 if (iCurrentPosition < iNumDrivers && iTargetPosition != iCurrentPosition) {
601 padid = driverList[iTargetPosition];
602 driverList[iTargetPosition] = driverList[iCurrentPosition];
603 driverList[iCurrentPosition] = padid;
605 /* Locate enabled status */
606 if (szBuffer[0] == '1') {
607 driverList[iTargetPosition]->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
608 } else if (szBuffer[0] == '0') {
609 driverList[iTargetPosition]->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
614 /* Re-assign pointers so that linked list traverses the ordered array */
615 for (i = 0; i < iNumDrivers; i++) {
616 driverList[i]->pPrevACMDriverID = (i > 0) ? driverList[i - 1] : NULL;
617 driverList[i]->pNextACMDriverID = (i < iNumDrivers - 1) ? driverList[i + 1] : NULL;
619 MSACM_pFirstACMDriverID = driverList[0];
620 MSACM_pLastACMDriverID = driverList[iNumDrivers - 1];
624 if (hPriorityKey != NULL) RegCloseKey(hPriorityKey);
625 if (driverList != NULL) HeapFree(MSACM_hHeap, 0, driverList);
628 /***********************************************************************
629 * MSACM_WriteCurrentPriorities()
630 * Writes out current order of driver priorities to registry key:
631 * HKCU\\Software\\Microsoft\\Multimedia\\Audio Compression Manager\\Priority v4.00
633 void MSACM_WriteCurrentPriorities(void)
637 static const WCHAR basePriorityKey[] = {
638 'S','o','f','t','w','a','r','e','\\',
639 'M','i','c','r','o','s','o','f','t','\\',
640 'M','u','l','t','i','m','e','d','i','a','\\',
641 'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
642 'P','r','i','o','r','i','t','y',' ','v','4','.','0','0','\0'
644 PWINE_ACMDRIVERID padid;
645 DWORD dwPriorityCounter;
646 static const WCHAR priorityTmpl[] = {'P','r','i','o','r','i','t','y','%','l','d','\0'};
647 static const WCHAR valueTmpl[] = {'%','c',',',' ','%','s','\0'};
648 static const WCHAR converterAlias[] = {'I','n','t','e','r','n','a','l',' ','P','C','M',' ','C','o','n','v','e','r','t','e','r','\0'};
652 /* Delete ACM priority key and create it anew */
653 lError = RegDeleteKeyW(HKEY_CURRENT_USER, basePriorityKey);
654 if (lError != ERROR_SUCCESS && lError != ERROR_FILE_NOT_FOUND) {
655 ERR("unable to remove current key %s (0x%08lx) - priority changes won't persist past application end.\n",
656 debugstr_w(basePriorityKey), lError);
659 lError = RegCreateKeyW(HKEY_CURRENT_USER, basePriorityKey, &hPriorityKey);
660 if (lError != ERROR_SUCCESS) {
661 ERR("unable to create key %s (0x%08lx) - priority changes won't persist past application end.\n",
662 debugstr_w(basePriorityKey), lError);
666 /* Write current list of priorities */
667 for (dwPriorityCounter = 0, padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
668 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL) continue;
669 if (padid->pszDriverAlias == NULL) continue; /* internal PCM converter is last */
671 /* Build required value name */
673 snprintfW(szSubKey, 17, priorityTmpl, dwPriorityCounter);
675 /* Value has a 1 in front for enabled drivers and 0 for disabled drivers */
676 snprintfW(szBuffer, 256, valueTmpl, (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) ? '0' : '1', padid->pszDriverAlias);
679 lError = RegSetValueExW(hPriorityKey, szSubKey, 0, REG_SZ, (BYTE *)szBuffer, (strlenW(szBuffer) + 1) * sizeof(WCHAR));
680 if (lError != ERROR_SUCCESS) {
681 ERR("unable to write value for %s under key %s (0x%08lx)\n",
682 debugstr_w(padid->pszDriverAlias), debugstr_w(basePriorityKey), lError);
686 /* Build required value name */
688 snprintfW(szSubKey, 17, priorityTmpl, dwPriorityCounter);
690 /* Value has a 1 in front for enabled drivers and 0 for disabled drivers */
691 snprintfW(szBuffer, 256, valueTmpl, '1', converterAlias);
693 lError = RegSetValueExW(hPriorityKey, szSubKey, 0, REG_SZ, (BYTE *)szBuffer, (strlenW(szBuffer) + 1) * sizeof(WCHAR));
694 if (lError != ERROR_SUCCESS) {
695 ERR("unable to write value for %s under key %s (0x%08lx)\n",
696 debugstr_w(converterAlias), debugstr_w(basePriorityKey), lError);
698 RegCloseKey(hPriorityKey);
701 /***********************************************************************
702 * MSACM_UnregisterDriver()
704 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
706 PWINE_ACMDRIVERID pNextACMDriverID;
708 while (p->pACMDriverList)
709 acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
711 HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
712 HeapFree(MSACM_hHeap, 0, p->pszFileName);
713 HeapFree(MSACM_hHeap, 0, p->aFormatTag);
715 if (p == MSACM_pFirstACMDriverID)
716 MSACM_pFirstACMDriverID = p->pNextACMDriverID;
717 if (p == MSACM_pLastACMDriverID)
718 MSACM_pLastACMDriverID = p->pPrevACMDriverID;
720 if (p->pPrevACMDriverID)
721 p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
722 if (p->pNextACMDriverID)
723 p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
725 pNextACMDriverID = p->pNextACMDriverID;
727 HeapFree(MSACM_hHeap, 0, p);
729 return pNextACMDriverID;
732 /***********************************************************************
733 * MSACM_UnregisterAllDrivers()
735 void MSACM_UnregisterAllDrivers(void)
737 PWINE_ACMNOTIFYWND panwnd = MSACM_pFirstACMNotifyWnd;
738 PWINE_ACMDRIVERID p = MSACM_pFirstACMDriverID;
742 p = MSACM_UnregisterDriver(p);
746 panwnd = MSACM_UnRegisterNotificationWindow(panwnd);
750 /***********************************************************************
753 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj, DWORD type)
755 PWINE_ACMOBJ pao = (PWINE_ACMOBJ)hObj;
757 if (pao == NULL || IsBadReadPtr(pao, sizeof(WINE_ACMOBJ)) ||
758 ((type != WINE_ACMOBJ_DONTCARE) && (type != pao->dwType)))
763 /***********************************************************************
764 * MSACM_GetDriverID()
766 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
768 return (PWINE_ACMDRIVERID)MSACM_GetObj((HACMOBJ)hDriverID, WINE_ACMOBJ_DRIVERID);
771 /***********************************************************************
774 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
776 return (PWINE_ACMDRIVER)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_DRIVER);
779 /***********************************************************************
780 * MSACM_GetNotifyWnd()
782 PWINE_ACMNOTIFYWND MSACM_GetNotifyWnd(HACMDRIVERID hDriver)
784 return (PWINE_ACMNOTIFYWND)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_NOTIFYWND);
788 /***********************************************************************
791 MMRESULT MSACM_Message(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
793 PWINE_ACMDRIVER pad = MSACM_GetDriver(had);
795 return pad ? SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2) : MMSYSERR_INVALHANDLE;