a4f89f5fb5231ca365b965763dbd5fb9f32935a3
[reactos.git] / reactos / dll / win32 / msacm32 / driver.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4 * MSACM32 library
5 *
6 * Copyright 1998 Patrik Stridvall
7 * 1999 Eric Pouech
8 *
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.
13 *
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.
18 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24 #define WIN32_NO_STATUS
25
26 #include <config.h>
27 //#include "wine/port.h"
28
29 //#include <stdarg.h>
30 //#include <stdio.h>
31
32 #include <windef.h>
33 //#include "winbase.h"
34 #include <wingdi.h>
35 //#include "winuser.h"
36 //#include "winnls.h"
37 //#include "mmsystem.h"
38 //#include "mmreg.h"
39 //#include "msacm.h"
40 #include <msacmdrv.h>
41 #include "wineacm.h"
42 #include <wine/debug.h>
43 #include <wine/unicode.h>
44
45 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
46
47 /***********************************************************************
48 * acmDriverAddA (MSACM32.@)
49 */
50 MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule,
51 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
52 {
53 MMRESULT resultW;
54 WCHAR * driverW = NULL;
55 LPARAM lParamW = lParam;
56
57 TRACE("(%p, %p, %08lx, %08x, %08x)\n",
58 phadid, hinstModule, lParam, dwPriority, fdwAdd);
59
60 if (!phadid) {
61 WARN("invalid parameter\n");
62 return MMSYSERR_INVALPARAM;
63 }
64
65 /* Check if any unknown flags */
66 if (fdwAdd &
67 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
68 ACM_DRIVERADDF_GLOBAL)) {
69 WARN("invalid flag\n");
70 return MMSYSERR_INVALFLAG;
71 }
72
73 /* Check if any incompatible flags */
74 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
75 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) {
76 WARN("invalid flag\n");
77 return MMSYSERR_INVALFLAG;
78 }
79
80 /* A->W translation of name */
81 if ((fdwAdd & ACM_DRIVERADDF_TYPEMASK) == ACM_DRIVERADDF_NAME) {
82 INT len;
83
84 if (lParam == 0) return MMSYSERR_INVALPARAM;
85 len = MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
86 driverW = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
87 if (!driverW) return MMSYSERR_NOMEM;
88 MultiByteToWideChar(CP_ACP, 0, (LPSTR)lParam, -1, driverW, len);
89 lParamW = (LPARAM)driverW;
90 }
91
92 resultW = acmDriverAddW(phadid, hinstModule, lParamW, dwPriority, fdwAdd);
93 HeapFree(MSACM_hHeap, 0, driverW);
94 return resultW;
95 }
96
97 /***********************************************************************
98 * acmDriverAddW (MSACM32.@)
99 *
100 */
101 MMRESULT WINAPI acmDriverAddW(PHACMDRIVERID phadid, HINSTANCE hinstModule,
102 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
103 {
104 PWINE_ACMLOCALDRIVER pLocalDrv = NULL;
105
106 TRACE("(%p, %p, %08lx, %08x, %08x)\n",
107 phadid, hinstModule, lParam, dwPriority, fdwAdd);
108
109 if (!phadid) {
110 WARN("invalid parameter\n");
111 return MMSYSERR_INVALPARAM;
112 }
113
114 /* Check if any unknown flags */
115 if (fdwAdd &
116 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
117 ACM_DRIVERADDF_GLOBAL)) {
118 WARN("invalid flag\n");
119 return MMSYSERR_INVALFLAG;
120 }
121
122 /* Check if any incompatible flags */
123 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) &&
124 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) {
125 WARN("invalid flag\n");
126 return MMSYSERR_INVALFLAG;
127 }
128
129 switch (fdwAdd & ACM_DRIVERADDF_TYPEMASK) {
130 case ACM_DRIVERADDF_NAME:
131 /*
132 hInstModule (unused)
133 lParam name of value in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32
134 dwPriority (unused, set to 0)
135 */
136 *phadid = (HACMDRIVERID) MSACM_RegisterDriverFromRegistry((LPCWSTR)lParam);
137 if (!*phadid) {
138 ERR("Unable to register driver via ACM_DRIVERADDF_NAME\n");
139 return MMSYSERR_INVALPARAM;
140 }
141 break;
142 case ACM_DRIVERADDF_FUNCTION:
143 /*
144 hInstModule Handle of module which contains driver entry proc
145 lParam Driver function address
146 dwPriority (unused, set to 0)
147 */
148 fdwAdd &= ~ACM_DRIVERADDF_TYPEMASK;
149 /* FIXME: fdwAdd ignored */
150 /* Application-supplied acmDriverProc's are placed at the top of the priority unless
151 fdwAdd indicates ACM_DRIVERADDF_GLOBAL
152 */
153 pLocalDrv = MSACM_RegisterLocalDriver(hinstModule, (DRIVERPROC)lParam);
154 *phadid = pLocalDrv ? (HACMDRIVERID) MSACM_RegisterDriver(NULL, NULL, pLocalDrv) : NULL;
155 if (!*phadid) {
156 ERR("Unable to register driver via ACM_DRIVERADDF_FUNCTION\n");
157 return MMSYSERR_INVALPARAM;
158 }
159 break;
160 case ACM_DRIVERADDF_NOTIFYHWND:
161 /*
162 hInstModule (unused)
163 lParam Handle of notification window
164 dwPriority Window message to send for notification broadcasts
165 */
166 *phadid = (HACMDRIVERID) MSACM_RegisterNotificationWindow((HWND)lParam, dwPriority);
167 if (!*phadid) {
168 ERR("Unable to register driver via ACM_DRIVERADDF_NOTIFYHWND\n");
169 return MMSYSERR_INVALPARAM;
170 }
171 break;
172 default:
173 ERR("invalid flag value 0x%08x for fdwAdd\n", fdwAdd & ACM_DRIVERADDF_TYPEMASK);
174 return MMSYSERR_INVALFLAG;
175 }
176
177 MSACM_BroadcastNotification();
178 return MMSYSERR_NOERROR;
179 }
180
181 /***********************************************************************
182 * acmDriverClose (MSACM32.@)
183 */
184 MMRESULT WINAPI acmDriverClose(HACMDRIVER had, DWORD fdwClose)
185 {
186 PWINE_ACMDRIVER pad;
187 PWINE_ACMDRIVERID padid;
188 PWINE_ACMDRIVER* tpad;
189
190 TRACE("(%p, %08x)\n", had, fdwClose);
191
192 if (fdwClose) {
193 WARN("invalid flag\n");
194 return MMSYSERR_INVALFLAG;
195 }
196
197 pad = MSACM_GetDriver(had);
198 if (!pad) {
199 WARN("invalid handle\n");
200 return MMSYSERR_INVALHANDLE;
201 }
202
203 padid = pad->obj.pACMDriverID;
204
205 /* remove driver from list */
206 for (tpad = &(padid->pACMDriverList); *tpad; tpad = &((*tpad)->pNextACMDriver)) {
207 if (*tpad == pad) {
208 *tpad = (*tpad)->pNextACMDriver;
209 break;
210 }
211 }
212
213 /* close driver if it has been opened */
214 if (pad->hDrvr && !pad->pLocalDrvrInst)
215 CloseDriver(pad->hDrvr, 0, 0);
216 else if (pad->pLocalDrvrInst)
217 MSACM_CloseLocalDriver(pad->pLocalDrvrInst);
218
219 pad->obj.dwType = 0;
220 HeapFree(MSACM_hHeap, 0, pad);
221
222 return MMSYSERR_NOERROR;
223 }
224
225 /***********************************************************************
226 * acmDriverDetailsA (MSACM32.@)
227 */
228 MMRESULT WINAPI acmDriverDetailsA(HACMDRIVERID hadid, PACMDRIVERDETAILSA padd, DWORD fdwDetails)
229 {
230 MMRESULT mmr;
231 ACMDRIVERDETAILSW addw;
232
233 TRACE("(%p, %p, %08x)\n", hadid, padd, fdwDetails);
234
235 if (!padd) {
236 WARN("invalid parameter\n");
237 return MMSYSERR_INVALPARAM;
238 }
239
240 if (padd->cbStruct < 4) {
241 WARN("invalid parameter\n");
242 return MMSYSERR_INVALPARAM;
243 }
244
245 addw.cbStruct = sizeof(addw);
246 mmr = acmDriverDetailsW(hadid, &addw, fdwDetails);
247 if (mmr == 0) {
248 ACMDRIVERDETAILSA padda;
249
250 padda.fccType = addw.fccType;
251 padda.fccComp = addw.fccComp;
252 padda.wMid = addw.wMid;
253 padda.wPid = addw.wPid;
254 padda.vdwACM = addw.vdwACM;
255 padda.vdwDriver = addw.vdwDriver;
256 padda.fdwSupport = addw.fdwSupport;
257 padda.cFormatTags = addw.cFormatTags;
258 padda.cFilterTags = addw.cFilterTags;
259 padda.hicon = addw.hicon;
260 WideCharToMultiByte( CP_ACP, 0, addw.szShortName, -1, padda.szShortName,
261 sizeof(padda.szShortName), NULL, NULL );
262 WideCharToMultiByte( CP_ACP, 0, addw.szLongName, -1, padda.szLongName,
263 sizeof(padda.szLongName), NULL, NULL );
264 WideCharToMultiByte( CP_ACP, 0, addw.szCopyright, -1, padda.szCopyright,
265 sizeof(padda.szCopyright), NULL, NULL );
266 WideCharToMultiByte( CP_ACP, 0, addw.szLicensing, -1, padda.szLicensing,
267 sizeof(padda.szLicensing), NULL, NULL );
268 WideCharToMultiByte( CP_ACP, 0, addw.szFeatures, -1, padda.szFeatures,
269 sizeof(padda.szFeatures), NULL, NULL );
270 padda.cbStruct = min(padd->cbStruct, sizeof(*padd));
271 memcpy(padd, &padda, padda.cbStruct);
272 }
273 return mmr;
274 }
275
276 /***********************************************************************
277 * acmDriverDetailsW (MSACM32.@)
278 */
279 MMRESULT WINAPI acmDriverDetailsW(HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails)
280 {
281 HACMDRIVER acmDrvr;
282 MMRESULT mmr;
283
284 TRACE("(%p, %p, %08x)\n", hadid, padd, fdwDetails);
285
286 if (!padd) {
287 WARN("invalid parameter\n");
288 return MMSYSERR_INVALPARAM;
289 }
290
291 if (padd->cbStruct < 4) {
292 WARN("invalid parameter\n");
293 return MMSYSERR_INVALPARAM;
294 }
295
296 if (fdwDetails) {
297 WARN("invalid flag\n");
298 return MMSYSERR_INVALFLAG;
299 }
300
301 mmr = acmDriverOpen(&acmDrvr, hadid, 0);
302 if (mmr == MMSYSERR_NOERROR) {
303 ACMDRIVERDETAILSW paddw;
304 paddw.cbStruct = sizeof(paddw);
305 mmr = MSACM_Message(acmDrvr, ACMDM_DRIVER_DETAILS, (LPARAM)&paddw, 0);
306
307 acmDriverClose(acmDrvr, 0);
308 paddw.cbStruct = min(padd->cbStruct, sizeof(*padd));
309 memcpy(padd, &paddw, paddw.cbStruct);
310 }
311 else if (mmr == MMSYSERR_NODRIVER)
312 return MMSYSERR_NOTSUPPORTED;
313
314 return mmr;
315 }
316
317 /***********************************************************************
318 * acmDriverEnum (MSACM32.@)
319 */
320 MMRESULT WINAPI acmDriverEnum(ACMDRIVERENUMCB fnCallback, DWORD_PTR dwInstance,
321 DWORD fdwEnum)
322 {
323 PWINE_ACMDRIVERID padid;
324 DWORD fdwSupport;
325
326 TRACE("(%p, %08lx, %08x)\n", fnCallback, dwInstance, fdwEnum);
327
328 if (!fnCallback) {
329 WARN("invalid parameter\n");
330 return MMSYSERR_INVALPARAM;
331 }
332
333 if (fdwEnum & ~(ACM_DRIVERENUMF_NOLOCAL|ACM_DRIVERENUMF_DISABLED)) {
334 WARN("invalid flag\n");
335 return MMSYSERR_INVALFLAG;
336 }
337
338 for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
339 fdwSupport = padid->fdwSupport;
340
341 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
342 if (fdwEnum & ACM_DRIVERENUMF_DISABLED)
343 fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
344 else
345 continue;
346 }
347 if (!(*fnCallback)((HACMDRIVERID)padid, dwInstance, fdwSupport))
348 break;
349 }
350
351 return MMSYSERR_NOERROR;
352 }
353
354 /***********************************************************************
355 * acmDriverID (MSACM32.@)
356 */
357 MMRESULT WINAPI acmDriverID(HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID)
358 {
359 PWINE_ACMOBJ pao;
360
361 TRACE("(%p, %p, %08x)\n", hao, phadid, fdwDriverID);
362
363 if (fdwDriverID) {
364 WARN("invalid flag\n");
365 return MMSYSERR_INVALFLAG;
366 }
367
368 pao = MSACM_GetObj(hao, WINE_ACMOBJ_DONTCARE);
369 if (!pao) {
370 WARN("invalid handle\n");
371 return MMSYSERR_INVALHANDLE;
372 }
373
374 if (!phadid) {
375 WARN("invalid parameter\n");
376 return MMSYSERR_INVALPARAM;
377 }
378
379 *phadid = (HACMDRIVERID) pao->pACMDriverID;
380
381 return MMSYSERR_NOERROR;
382 }
383
384 /***********************************************************************
385 * acmDriverMessage (MSACM32.@)
386 *
387 * Note: MSDN documentation (July 2001) is incomplete. This function
388 * accepts sending messages to an HACMDRIVERID in addition to the
389 * documented HACMDRIVER. In fact, for DRV_QUERYCONFIGURE and DRV_CONFIGURE,
390 * this might actually be the required mode of operation.
391 *
392 * Note: For DRV_CONFIGURE, msacm supplies its own DRVCONFIGINFO structure
393 * when the application fails to supply one. Some native drivers depend on
394 * this and refuse to display unless a valid DRVCONFIGINFO structure is
395 * built and supplied.
396 */
397 LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
398 {
399 TRACE("(%p, %04x, %08lx, %08lx\n", had, uMsg, lParam1, lParam2);
400
401 if ((uMsg >= ACMDM_USER && uMsg < ACMDM_RESERVED_LOW) ||
402 uMsg == ACMDM_DRIVER_ABOUT ||
403 uMsg == DRV_QUERYCONFIGURE ||
404 uMsg == DRV_CONFIGURE)
405 {
406 PWINE_ACMDRIVERID padid;
407 LRESULT lResult;
408 LPDRVCONFIGINFO pConfigInfo = NULL;
409 LPWSTR section_name = NULL;
410 LPWSTR alias_name = NULL;
411
412 /* Check whether handle is an HACMDRIVERID */
413 padid = MSACM_GetDriverID((HACMDRIVERID)had);
414
415 /* If the message is DRV_CONFIGURE, and the application provides no
416 DRVCONFIGINFO structure, msacm must supply its own.
417 */
418 if (uMsg == DRV_CONFIGURE && lParam2 == 0) {
419 LPWSTR pAlias;
420
421 /* Get the alias from the HACMDRIVERID */
422 if (padid) {
423 pAlias = padid->pszDriverAlias;
424 if (pAlias == NULL) {
425 WARN("DRV_CONFIGURE: no alias for this driver, cannot self-supply alias\n");
426 }
427 } else {
428 FIXME("DRV_CONFIGURE: reverse lookup HACMDRIVER -> HACMDRIVERID not implemented\n");
429 pAlias = NULL;
430 }
431
432 if (pAlias != NULL) {
433 /* DRVCONFIGINFO is only 12 bytes long, but native msacm
434 * reports a 16-byte structure to codecs, so allocate 16 bytes,
435 * just to be on the safe side.
436 */
437 const unsigned int iStructSize = 16;
438 pConfigInfo = HeapAlloc(MSACM_hHeap, 0, iStructSize);
439 if (!pConfigInfo) {
440 ERR("OOM while supplying DRVCONFIGINFO for DRV_CONFIGURE, using NULL\n");
441 } else {
442 static const WCHAR drivers32[] = {'D','r','i','v','e','r','s','3','2','\0'};
443
444 pConfigInfo->dwDCISize = iStructSize;
445
446 section_name = HeapAlloc(MSACM_hHeap, 0, (strlenW(drivers32) + 1) * sizeof(WCHAR));
447 if (section_name) strcpyW(section_name, drivers32);
448 pConfigInfo->lpszDCISectionName = section_name;
449 alias_name = HeapAlloc(MSACM_hHeap, 0, (strlenW(pAlias) + 1) * sizeof(WCHAR));
450 if (alias_name) strcpyW(alias_name, pAlias);
451 pConfigInfo->lpszDCIAliasName = alias_name;
452
453 if (pConfigInfo->lpszDCISectionName == NULL || pConfigInfo->lpszDCIAliasName == NULL) {
454 HeapFree(MSACM_hHeap, 0, alias_name);
455 HeapFree(MSACM_hHeap, 0, section_name);
456 HeapFree(MSACM_hHeap, 0, pConfigInfo);
457 pConfigInfo = NULL;
458 ERR("OOM while supplying DRVCONFIGINFO for DRV_CONFIGURE, using NULL\n");
459 }
460 }
461 }
462
463 lParam2 = (LPARAM)pConfigInfo;
464 }
465
466 if (padid) {
467 /* Handle is really an HACMDRIVERID, must have an open session to get an HACMDRIVER */
468 if (padid->pACMDriverList != NULL) {
469 lResult = MSACM_Message((HACMDRIVER)padid->pACMDriverList, uMsg, lParam1, lParam2);
470 } else {
471 MMRESULT mmr = acmDriverOpen(&had, (HACMDRIVERID)padid, 0);
472 if (mmr != MMSYSERR_NOERROR) {
473 lResult = MMSYSERR_INVALPARAM;
474 } else {
475 lResult = acmDriverMessage(had, uMsg, lParam1, lParam2);
476 acmDriverClose(had, 0);
477 }
478 }
479 } else {
480 lResult = MSACM_Message(had, uMsg, lParam1, lParam2);
481 }
482 if (pConfigInfo) {
483 HeapFree(MSACM_hHeap, 0, alias_name);
484 HeapFree(MSACM_hHeap, 0, section_name);
485 HeapFree(MSACM_hHeap, 0, pConfigInfo);
486 }
487 return lResult;
488 }
489 WARN("invalid parameter\n");
490 return MMSYSERR_INVALPARAM;
491 }
492
493 /***********************************************************************
494 * acmDriverOpen (MSACM32.@)
495 */
496 MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen)
497 {
498 PWINE_ACMDRIVERID padid;
499 PWINE_ACMDRIVER pad = NULL;
500 MMRESULT ret;
501
502 TRACE("(%p, %p, %08u)\n", phad, hadid, fdwOpen);
503
504 if (!phad) {
505 WARN("invalid parameter\n");
506 return MMSYSERR_INVALPARAM;
507 }
508
509 if (fdwOpen) {
510 WARN("invalid flag\n");
511 return MMSYSERR_INVALFLAG;
512 }
513
514 padid = MSACM_GetDriverID(hadid);
515 if (!padid) {
516 WARN("invalid handle\n");
517 return MMSYSERR_INVALHANDLE;
518 }
519
520 pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
521 if (!pad) {
522 WARN("no memory\n");
523 return MMSYSERR_NOMEM;
524 }
525
526 pad->obj.dwType = WINE_ACMOBJ_DRIVER;
527 pad->obj.pACMDriverID = padid;
528 pad->hDrvr = 0;
529 pad->pLocalDrvrInst = NULL;
530
531 if (padid->pLocalDriver == NULL)
532 {
533 ACMDRVOPENDESCW adod;
534 int len;
535 LPWSTR section_name;
536
537 /* this is not an externally added driver... need to actually load it */
538 if (!padid->pszDriverAlias)
539 {
540 ret = MMSYSERR_ERROR;
541 goto gotError;
542 }
543
544 adod.cbStruct = sizeof(adod);
545 adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
546 adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
547 adod.dwVersion = acmGetVersion();
548 adod.dwFlags = fdwOpen;
549 adod.dwError = 0;
550 len = strlen("Drivers32") + 1;
551 section_name = HeapAlloc(MSACM_hHeap, 0, len * sizeof(WCHAR));
552 MultiByteToWideChar(CP_ACP, 0, "Drivers32", -1, section_name, len);
553 adod.pszSectionName = section_name;
554 adod.pszAliasName = padid->pszDriverAlias;
555 adod.dnDevNode = 0;
556
557 pad->hDrvr = OpenDriver(padid->pszDriverAlias, NULL, (DWORD_PTR)&adod);
558
559 HeapFree(MSACM_hHeap, 0, section_name);
560 if (!pad->hDrvr)
561 {
562 ret = adod.dwError;
563 if (ret == MMSYSERR_NOERROR)
564 ret = MMSYSERR_NODRIVER;
565 goto gotError;
566 }
567 }
568 else
569 {
570 ACMDRVOPENDESCW adod;
571
572 pad->hDrvr = NULL;
573
574 adod.cbStruct = sizeof(adod);
575 adod.fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
576 adod.fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
577 adod.dwVersion = acmGetVersion();
578 adod.dwFlags = fdwOpen;
579 adod.dwError = 0;
580 adod.pszSectionName = NULL;
581 adod.pszAliasName = NULL;
582 adod.dnDevNode = 0;
583
584 pad->pLocalDrvrInst = MSACM_OpenLocalDriver(padid->pLocalDriver, (DWORD_PTR)&adod);
585 if (!pad->pLocalDrvrInst)
586 {
587 ret = adod.dwError;
588 if (ret == MMSYSERR_NOERROR)
589 ret = MMSYSERR_NODRIVER;
590 goto gotError;
591 }
592 }
593
594 /* insert new pad at beg of list */
595 pad->pNextACMDriver = padid->pACMDriverList;
596 padid->pACMDriverList = pad;
597
598 /* FIXME: Create a WINE_ACMDRIVER32 */
599 *phad = (HACMDRIVER)pad;
600 TRACE("%s => %p\n", debugstr_w(padid->pszDriverAlias), pad);
601
602 return MMSYSERR_NOERROR;
603 gotError:
604 WARN("failed: ret = %08x\n", ret);
605 if (pad && !pad->hDrvr)
606 HeapFree(MSACM_hHeap, 0, pad);
607 return ret;
608 }
609
610 /***********************************************************************
611 * acmDriverPriority (MSACM32.@)
612 */
613 MMRESULT WINAPI acmDriverPriority(HACMDRIVERID hadid, DWORD dwPriority, DWORD fdwPriority)
614 {
615
616 TRACE("(%p, %08x, %08x)\n", hadid, dwPriority, fdwPriority);
617
618 /* Check for unknown flags */
619 if (fdwPriority &
620 ~(ACM_DRIVERPRIORITYF_ENABLE|ACM_DRIVERPRIORITYF_DISABLE|
621 ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END)) {
622 WARN("invalid flag\n");
623 return MMSYSERR_INVALFLAG;
624 }
625
626 /* Check for incompatible flags */
627 if ((fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) &&
628 (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE)) {
629 WARN("invalid flag\n");
630 return MMSYSERR_INVALFLAG;
631 }
632
633 /* Check for incompatible flags */
634 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) &&
635 (fdwPriority & ACM_DRIVERPRIORITYF_END)) {
636 WARN("invalid flag\n");
637 return MMSYSERR_INVALFLAG;
638 }
639
640 /* According to MSDN, ACM_DRIVERPRIORITYF_BEGIN and ACM_DRIVERPRIORITYF_END
641 may only appear by themselves, and in addition, hadid and dwPriority must
642 both be zero */
643 if ((fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) ||
644 (fdwPriority & ACM_DRIVERPRIORITYF_END)) {
645 if (fdwPriority & ~(ACM_DRIVERPRIORITYF_BEGIN|ACM_DRIVERPRIORITYF_END)) {
646 WARN("ACM_DRIVERPRIORITYF_[BEGIN|END] cannot be used with any other flags\n");
647 return MMSYSERR_INVALPARAM;
648 }
649 if (dwPriority) {
650 WARN("priority invalid with ACM_DRIVERPRIORITYF_[BEGIN|END]\n");
651 return MMSYSERR_INVALPARAM;
652 }
653 if (hadid) {
654 WARN("non-null hadid invalid with ACM_DRIVERPRIORITYF_[BEGIN|END]\n");
655 return MMSYSERR_INVALPARAM;
656 }
657 /* FIXME: MSDN wording suggests that deferred notification should be
658 implemented as a system-wide lock held by a calling task, and that
659 re-enabling notifications should broadcast them across all processes.
660 This implementation uses a simple DWORD counter. One consequence of the
661 current implementation is that applications will never see
662 MMSYSERR_ALLOCATED as a return error.
663 */
664 if (fdwPriority & ACM_DRIVERPRIORITYF_BEGIN) {
665 MSACM_DisableNotifications();
666 } else if (fdwPriority & ACM_DRIVERPRIORITYF_END) {
667 MSACM_EnableNotifications();
668 }
669 return MMSYSERR_NOERROR;
670 } else {
671 PWINE_ACMDRIVERID padid;
672 PWINE_ACMNOTIFYWND panwnd;
673 BOOL bPerformBroadcast = FALSE;
674
675 /* Fetch driver ID */
676 padid = MSACM_GetDriverID(hadid);
677 panwnd = MSACM_GetNotifyWnd(hadid);
678 if (!padid && !panwnd) {
679 WARN("invalid handle\n");
680 return MMSYSERR_INVALHANDLE;
681 }
682
683 if (padid) {
684 /* Check whether driver ID is appropriate for requested op */
685 if (dwPriority) {
686 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL) {
687 return MMSYSERR_NOTSUPPORTED;
688 }
689 if (dwPriority != 1 && dwPriority != (DWORD)-1) {
690 FIXME("unexpected priority %d, using sign only\n", dwPriority);
691 if ((signed)dwPriority < 0) dwPriority = (DWORD)-1;
692 if (dwPriority > 0) dwPriority = 1;
693 }
694
695 if (dwPriority == 1 && (padid->pPrevACMDriverID == NULL ||
696 (padid->pPrevACMDriverID->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL))) {
697 /* do nothing - driver is first of list, or first after last
698 local driver */
699 } else if (dwPriority == (DWORD)-1 && padid->pNextACMDriverID == NULL) {
700 /* do nothing - driver is last of list */
701 } else {
702 MSACM_RePositionDriver(padid, dwPriority);
703 bPerformBroadcast = TRUE;
704 }
705 }
706
707 /* Check whether driver ID should be enabled or disabled */
708 if (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE) {
709 if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
710 padid->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
711 bPerformBroadcast = TRUE;
712 }
713 } else if (fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) {
714 if (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
715 padid->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
716 bPerformBroadcast = TRUE;
717 }
718 }
719 }
720
721 if (panwnd) {
722 if (dwPriority) {
723 return MMSYSERR_NOTSUPPORTED;
724 }
725
726 /* Check whether notify window should be enabled or disabled */
727 if (fdwPriority & ACM_DRIVERPRIORITYF_DISABLE) {
728 if (!(panwnd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
729 panwnd->fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
730 bPerformBroadcast = TRUE;
731 }
732 } else if (fdwPriority & ACM_DRIVERPRIORITYF_ENABLE) {
733 if (panwnd->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) {
734 panwnd->fdwSupport &= ~ACMDRIVERDETAILS_SUPPORTF_DISABLED;
735 bPerformBroadcast = TRUE;
736 }
737 }
738 }
739
740 /* Perform broadcast of changes */
741 if (bPerformBroadcast) {
742 MSACM_WriteCurrentPriorities();
743 MSACM_BroadcastNotification();
744 }
745 return MMSYSERR_NOERROR;
746 }
747 }
748
749 /***********************************************************************
750 * acmDriverRemove (MSACM32.@)
751 */
752 MMRESULT WINAPI acmDriverRemove(HACMDRIVERID hadid, DWORD fdwRemove)
753 {
754 PWINE_ACMDRIVERID padid;
755 PWINE_ACMNOTIFYWND panwnd;
756
757 TRACE("(%p, %08x)\n", hadid, fdwRemove);
758
759 padid = MSACM_GetDriverID(hadid);
760 panwnd = MSACM_GetNotifyWnd(hadid);
761 if (!padid && !panwnd) {
762 WARN("invalid handle\n");
763 return MMSYSERR_INVALHANDLE;
764 }
765
766 if (fdwRemove) {
767 WARN("invalid flag\n");
768 return MMSYSERR_INVALFLAG;
769 }
770
771 if (padid) MSACM_UnregisterDriver(padid);
772 if (panwnd) MSACM_UnRegisterNotificationWindow(panwnd);
773 MSACM_BroadcastNotification();
774
775 return MMSYSERR_NOERROR;
776 }