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
25 #include "wine/port.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
46 /***********************************************************************
47 * acmDriverAddA (MSACM32.@)
49 MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule,
50 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
53 WCHAR * driverW = NULL;
54 LPARAM lParamW = lParam;
56 TRACE("(%p, %p, %08lx, %08lx, %08lx)\n",
57 phadid, hinstModule, lParam, dwPriority, fdwAdd);
60 WARN("invalid parameter\n");
61 return MMSYSERR_INVALPARAM;
64 /* Check if any unknown flags */
66 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
67 ACM_DRIVERADDF_GLOBAL)) {
68 WARN("invalid flag\n");
69 return MMSYSERR_INVALFLAG;
72 /* Check if any incompatible flags */
73 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
74 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) {
75 WARN("invalid flag\n");
76 return MMSYSERR_INVALFLAG;
79 /* A->W translation of name */
80 if ((fdwAdd & ACM_DRIVERADDF_TYPEMASK) == ACM_DRIVERADDF_NAME) {
83 if (lParam == 0) return MMSYSERR_INVALPARAM;
84 len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
85 driverW = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
86 if (!driverW) return MMSYSERR_NOMEM;
87 MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam, -1, driverW, len);
88 lParamW = (LPARAM)driverW;
91 resultW = acmDriverAddW(phadid, hinstModule, lParamW, dwPriority, fdwAdd);
92 HeapFree(MSACM_hHeap, 0, driverW);
96 /***********************************************************************
97 * acmDriverAddW (MSACM32.@)
100 MMRESULT WINAPI acmDriverAddW(PHACMDRIVERID phadid, HINSTANCE hinstModule,
101 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
103 TRACE("(%p, %p, %08lx, %08lx, %08lx)\n",
104 phadid, hinstModule, lParam, dwPriority, fdwAdd);
107 WARN("invalid parameter\n");
108 return MMSYSERR_INVALPARAM;
111 /* Check if any unknown flags */
113 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
114 ACM_DRIVERADDF_GLOBAL)) {
115 WARN("invalid flag\n");
116 return MMSYSERR_INVALFLAG;
119 /* Check if any incompatible flags */
120 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
121 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) {
122 WARN("invalid flag\n");
123 return MMSYSERR_INVALFLAG;
126 switch (fdwAdd & ACM_DRIVERADDF_TYPEMASK) {
127 case ACM_DRIVERADDF_NAME:
130 lParam name of value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32
131 dwPriority (unused, set to 0)
133 *phadid = (HACMDRIVERID) MSACM_RegisterDriverFromRegistry((LPCWSTR)lParam);
135 ERR("Unable to register driver via ACM_DRIVERADDF_NAME\n");
136 return MMSYSERR_INVALPARAM;
139 case ACM_DRIVERADDF_FUNCTION:
141 hInstModule Handle of module which contains driver entry proc
142 lParam Driver function address
143 dwPriority (unused, set to 0)
145 fdwAdd &= ~ACM_DRIVERADDF_TYPEMASK;
148 FIXME("(%p, %p, %ld, %ld, %ld): ACM_DRIVERADDF_FUNCTION: stub\n", phadid, hinstModule, lParam, dwPriority, fdwAdd);
149 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
150 return MMSYSERR_ERROR;
151 case ACM_DRIVERADDF_NOTIFYHWND:
154 lParam Handle of notification window
155 dwPriority Window message to send for notification broadcasts
158 FIXME("(%p, %p, %ld, %ld, %ld): ACM_DRIVERADDF_NOTIFYHWND: stub\n", phadid, hinstModule, lParam, dwPriority, fdwAdd);
159 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
160 return MMSYSERR_ERROR;
162 ERR("invalid flag value 0x%08lx for fdwAdd\n", fdwAdd & ACM_DRIVERADDF_TYPEMASK);
163 return MMSYSERR_INVALFLAG;
166 MSACM_BroadcastNotification();
167 return MMSYSERR_NOERROR;
170 /***********************************************************************
171 * acmDriverClose (MSACM32.@)
173 MMRESULT WINAPI acmDriverClose(HACMDRIVER had, DWORD fdwClose)
176 PWINE_ACMDRIVERID padid;
177 PWINE_ACMDRIVER* tpad;
179 TRACE("(%p, %08lx)\n", had, fdwClose);
182 WARN("invalid flag\n");
183 return MMSYSERR_INVALFLAG;
186 pad = MSACM_GetDriver(had);
188 WARN("invalid handle\n");
189 return MMSYSERR_INVALHANDLE;
192 padid = pad->obj.pACMDriverID;
194 /* remove driver from list */
195 for (tpad = &(padid->pACMDriverList); *tpad; tpad = &((*tpad)->pNextACMDriver)) {
197 *tpad = (*tpad)->pNextACMDriver;
202 /* close driver if it has been opened */
203 if (pad->hDrvr && !padid->hInstModule)
204 CloseDriver(pad->hDrvr, 0, 0);
206 HeapFree(MSACM_hHeap, 0, pad);
208 return MMSYSERR_NOERROR;
211 /***********************************************************************
212 * acmDriverDetailsA (MSACM32.@)
214 MMRESULT WINAPI acmDriverDetailsA(HACMDRIVERID hadid, PACMDRIVERDETAILSA padd, DWORD fdwDetails)
217 ACMDRIVERDETAILSW addw;
219 TRACE("(%p, %p, %08lx)\n", hadid, padd, fdwDetails);
222 WARN("invalid parameter\n");
223 return MMSYSERR_INVALPARAM;
226 if (padd->cbStruct < 4) {
227 WARN("invalid parameter\n");
228 return MMSYSERR_INVALPARAM;
231 addw.cbStruct = sizeof(addw);
232 mmr = acmDriverDetailsW(hadid, &addw, fdwDetails);
234 ACMDRIVERDETAILSA padda;
236 padda.fccType = addw.fccType;
237 padda.fccComp = addw.fccComp;
238 padda.wMid = addw.wMid;
239 padda.wPid = addw.wPid;
240 padda.vdwACM = addw.vdwACM;
241 padda.vdwDriver = addw.vdwDriver;
242 padda.fdwSupport = addw.fdwSupport;
243 padda.cFormatTags = addw.cFormatTags;
244 padda.cFilterTags = addw.cFilterTags;
245 padda.hicon = addw.hicon;
246 WideCharToMultiByte( CP_ACP, 0, addw.szShortName, -1, padda.szShortName,
247 sizeof(padda.szShortName), NULL, NULL );
248 WideCharToMultiByte( CP_ACP, 0, addw.szLongName, -1, padda.szLongName,
249 sizeof(padda.szLongName), NULL, NULL );
250 WideCharToMultiByte( CP_ACP, 0, addw.szCopyright, -1, padda.szCopyright,
251 sizeof(padda.szCopyright), NULL, NULL );
252 WideCharToMultiByte( CP_ACP, 0, addw.szLicensing, -1, padda.szLicensing,
253 sizeof(padda.szLicensing), NULL, NULL );
254 WideCharToMultiByte( CP_ACP, 0, addw.szFeatures, -1, padda.szFeatures,
255 sizeof(padda.szFeatures), NULL, NULL );
256 padda.cbStruct = min(padd->cbStruct, sizeof(*padd));
257 memcpy(padd, &padda, padda.cbStruct);
262 /***********************************************************************
263 * acmDriverDetailsW (MSACM32.@)
265 MMRESULT WINAPI acmDriverDetailsW(HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails)
270 TRACE("(%p, %p, %08lx)\n", hadid, padd, fdwDetails);
273 WARN("invalid parameter\n");
274 return MMSYSERR_INVALPARAM;
277 if (padd->cbStruct < 4) {
278 WARN("invalid parameter\n");
279 return MMSYSERR_INVALPARAM;
283 WARN("invalid flag\n");
284 return MMSYSERR_INVALFLAG;
287 mmr = acmDriverOpen(&acmDrvr, hadid, 0);
288 if (mmr == MMSYSERR_NOERROR) {
289 ACMDRIVERDETAILSW paddw;
290 paddw.cbStruct = sizeof(paddw);
291 mmr = (MMRESULT)MSACM_Message(acmDrvr, ACMDM_DRIVER_DETAILS, (LPARAM)&paddw, 0);
293 acmDriverClose(acmDrvr, 0);
294 paddw.cbStruct = min(padd->cbStruct, sizeof(*padd));
295 memcpy(padd, &paddw, paddw.cbStruct);
301 /***********************************************************************
302 * acmDriverEnum (MSACM32.@)
304 MMRESULT WINAPI acmDriverEnum(ACMDRIVERENUMCB fnCallback, DWORD dwInstance, DWORD fdwEnum)
306 PWINE_ACMDRIVERID padid;
309 TRACE("(%p, %08lx, %08lx)\n", fnCallback, dwInstance, fdwEnum);
312 WARN("invalid parameter\n");
313 return MMSYSERR_INVALPARAM;
316 if (fdwEnum & ~(ACM_DRIVERENUMF_NOLOCAL|ACM_DRIVERENUMF_DISABLED)) {
317 WARN("invalid flag\n");
318 return MMSYSERR_INVALFLAG;
321 for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
322 fdwSupport = padid->fdwSupport;
324 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
325 if (fdwEnum & ACM_DRIVERENUMF_DISABLED)
326 fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
330 if (!(*fnCallback)((HACMDRIVERID)padid, dwInstance, fdwSupport))
334 return MMSYSERR_NOERROR;
337 /***********************************************************************
338 * acmDriverID (MSACM32.@)
340 MMRESULT WINAPI acmDriverID(HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID)
344 TRACE("(%p, %p, %08lx)\n", hao, phadid, fdwDriverID);
347 WARN("invalid flag\n");
348 return MMSYSERR_INVALFLAG;
351 pao = MSACM_GetObj(hao, WINE_ACMOBJ_DONTCARE);
353 WARN("invalid handle\n");
354 return MMSYSERR_INVALHANDLE;
358 WARN("invalid parameter\n");
359 return MMSYSERR_INVALPARAM;
362 *phadid = (HACMDRIVERID) pao->pACMDriverID;
364 return MMSYSERR_NOERROR;
367 /***********************************************************************
368 * acmDriverMessage (MSACM32.@)
371 LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
373 TRACE("(%p, %04x, %08lx, %08lx\n", had, uMsg, lParam1, lParam2);
375 if ((uMsg >= ACMDM_USER && uMsg < ACMDM_RESERVED_LOW) ||
376 uMsg == ACMDM_DRIVER_ABOUT ||
377 uMsg == DRV_QUERYCONFIGURE ||
378 uMsg == DRV_CONFIGURE)
379 return MSACM_Message(had, uMsg, lParam1, lParam2);
381 WARN("invalid parameter\n");
382 return MMSYSERR_INVALPARAM;
385 /***********************************************************************
386 * acmDriverOpen (MSACM32.@)
388 MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen)
390 PWINE_ACMDRIVERID padid;
391 PWINE_ACMDRIVER pad = NULL;
394 TRACE("(%p, %p, %08lu)\n", phad, hadid, fdwOpen);
397 WARN("invalid parameter\n");
398 return MMSYSERR_INVALPARAM;
402 WARN("invalid flag\n");
403 return MMSYSERR_INVALFLAG;
406 padid = MSACM_GetDriverID(hadid);
408 WARN("invalid handle\n");
409 return MMSYSERR_INVALHANDLE;
412 pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
415 return MMSYSERR_NOMEM;
418 pad->obj.dwType = WINE_ACMOBJ_DRIVER;
419 pad->obj.pACMDriverID = padid;
421 if (!(pad->hDrvr = (HDRVR)padid->hInstModule))
423 ACMDRVOPENDESCW adod;
426 /* this is not an externally added driver... need to actually load it */
427 if (!padid->pszDriverAlias)
429 ret = MMSYSERR_ERROR;
433 adod.cbStruct = sizeof(adod);
434 adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
435 adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
436 adod.dwVersion = acmGetVersion();
437 adod.dwFlags = fdwOpen;
439 len = strlen("Drivers32") + 1;
440 adod.pszSectionName = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
441 MultiByteToWideChar(CP_ACP, 0, "Drivers32", -1, (LPWSTR)adod.pszSectionName, len);
442 adod.pszAliasName = padid->pszDriverAlias;
445 pad->hDrvr = OpenDriver(padid->pszDriverAlias, NULL, (DWORD)&adod);
447 HeapFree(MSACM_hHeap, 0, (LPWSTR)adod.pszSectionName);
455 /* insert new pad at beg of list */
456 pad->pNextACMDriver = padid->pACMDriverList;
457 padid->pACMDriverList = pad;
459 /* FIXME: Create a WINE_ACMDRIVER32 */
460 *phad = (HACMDRIVER)pad;
461 TRACE("'%s' => %p\n", debugstr_w(padid->pszDriverAlias), pad);
463 return MMSYSERR_NOERROR;
465 WARN("failed: ret = %08x\n", ret);
466 if (pad && !pad->hDrvr)
467 HeapFree(MSACM_hHeap, 0, pad);
471 /***********************************************************************
472 * acmDriverPriority (MSACM32.@)
474 MMRESULT WINAPI acmDriverPriority(HACMDRIVERID hadid, DWORD dwPriority, DWORD fdwPriority)
477 TRACE("(%p, %08lx, %08lx)\n", hadid, dwPriority, fdwPriority);
479 /* Check for unknown flags */
481 ~(ACM_DRIVERPRIORITYF_ENABLE|ACM_DRIVERPRIORITYF_DISABLE|
482 ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END)) {
483 WARN("invalid flag\n");
484 return MMSYSERR_INVALFLAG;
487 /* Check for incompatible flags */
488 if ((fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) &&
489 (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE)) {
490 WARN("invalid flag\n");
491 return MMSYSERR_INVALFLAG;
494 /* Check for incompatible flags */
495 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) &&
496 (fdwPriority & ACM_DRIVERPRIORITYF_END)) {
497 WARN("invalid flag\n");
498 return MMSYSERR_INVALFLAG;
501 /* According to MSDN, ACM_DRIVERPRIORITYF_BEGIN and ACM_DRIVERPRIORITYF_END
502 may only appear by themselves, and in addition, hadid and dwPriority must
504 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) ||
505 (fdwPriority & ACM_DRIVERPRIORITYF_END)) {
506 if (fdwPriority & ~(ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END)) {
507 WARN("ACM_DRIVERPRIORITYF_[BEGIN|END] cannot be used with any other flags\n");
508 return MMSYSERR_INVALPARAM;
511 WARN("priority invalid with ACM_DRIVERPRIORITYF_[BEGIN|END]\n");
512 return MMSYSERR_INVALPARAM;
515 WARN("non-null hadid invalid with ACM_DRIVERPRIORITYF_[BEGIN|END]\n");
516 return MMSYSERR_INVALPARAM;
518 /* FIXME: MSDN wording suggests that deferred notification should be
519 implemented as a system-wide lock held by a calling task, and that
520 re-enabling notifications should broadcast them across all processes.
521 This implementation uses a simple DWORD counter. One consequence of the
522 current implementation is that applications will never see
523 MMSYSERR_ALLOCATED as a return error.
525 if (fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) {
526 MSACM_DisableNotifications();
527 } else if (fdwPriority & ACM_DRIVERPRIORITYF_END) {
528 MSACM_EnableNotifications();
530 return MMSYSERR_NOERROR;
532 PWINE_ACMDRIVERID padid;
533 BOOL bPerformBroadcast = FALSE;
535 /* Fetch driver ID */
536 padid = MSACM_GetDriverID(hadid);
538 WARN("invalid handle\n");
539 return MMSYSERR_INVALHANDLE;
542 /* Check whether driver ID is appropriate for requested op */
544 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL) {
545 return MMSYSERR_NOTSUPPORTED;
547 if (dwPriority != 1 && dwPriority != -1) {
548 FIXME("unexpected priority %ld, using sign only\n", dwPriority);
549 if (dwPriority < 0) dwPriority = -1;
550 if (dwPriority > 0) dwPriority = 1;
553 if (dwPriority == 1 && (padid->pPrevACMDriverID == NULL ||
554 (padid->pPrevACMDriverID->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL))) {
555 /* do nothing - driver is first of list, or first after last
557 } else if (dwPriority == -1 && padid->pNextACMDriverID == NULL) {
558 /* do nothing - driver is last of list */
560 MSACM_RePositionDriver(padid, dwPriority);
561 bPerformBroadcast = TRUE;
565 /* Check whether driver ID should be enabled or disabled */
566 if (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE) {
567 if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
568 padid->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
569 bPerformBroadcast = TRUE;
571 } else if (fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) {
572 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
573 padid->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
574 bPerformBroadcast = TRUE;
578 /* Perform broadcast of changes */
579 if (bPerformBroadcast) {
580 MSACM_WriteCurrentPriorities();
581 MSACM_BroadcastNotification();
583 return MMSYSERR_NOERROR;
587 /***********************************************************************
588 * acmDriverRemove (MSACM32.@)
590 MMRESULT WINAPI acmDriverRemove(HACMDRIVERID hadid, DWORD fdwRemove)
592 PWINE_ACMDRIVERID padid;
594 TRACE("(%p, %08lx)\n", hadid, fdwRemove);
596 padid = MSACM_GetDriverID(hadid);
598 WARN("invalid handle\n");
599 return MMSYSERR_INVALHANDLE;
603 WARN("invalid flag\n");
604 return MMSYSERR_INVALFLAG;
607 MSACM_UnregisterDriver(padid);
608 MSACM_BroadcastNotification();
610 return MMSYSERR_NOERROR;