xref: /reactos/dll/win32/msacm32/msacm32_main.c (revision 98e8827a)
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 #include <stdarg.h>
25 
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wine/debug.h"
29 #include "mmsystem.h"
30 #define NOBITMAP
31 #include "mmreg.h"
32 #include "msacm.h"
33 #include "msacmdrv.h"
34 #include "wineacm.h"
35 
36 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
37 
38 /**********************************************************************/
39 
40 HINSTANCE	MSACM_hInstance32 = 0;
41 
42 /***********************************************************************
43  *           DllMain (MSACM32.init)
44  */
45 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
46 {
47     TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, lpvReserved);
48 
49     switch (fdwReason) {
50     case DLL_PROCESS_ATTACH:
51         DisableThreadLibraryCalls(hInstDLL);
52         MSACM_hHeap = HeapCreate(0, 0x10000, 0);
53         MSACM_hInstance32 = hInstDLL;
54         MSACM_RegisterAllDrivers();
55 	break;
56     case DLL_PROCESS_DETACH:
57         MSACM_UnregisterAllDrivers();
58         if (lpvReserved) break;
59         HeapDestroy(MSACM_hHeap);
60 	break;
61     default:
62 	break;
63     }
64     return TRUE;
65 }
66 
67 /***********************************************************************
68  *           XRegThunkEntry (MSACM32.1)
69  * FIXME
70  *   No documentation found.
71  */
72 
73 /***********************************************************************
74  *           acmGetVersion (MSACM32.@)
75  */
76 DWORD WINAPI acmGetVersion(void)
77 {
78     OSVERSIONINFOA version;
79 
80     version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
81     if (!GetVersionExA( &version ))
82 	return 0x04030000;
83 
84     switch (version.dwPlatformId) {
85     case VER_PLATFORM_WIN32_NT:
86 	return 0x04000565; /* 4.0.1381 */
87     case VER_PLATFORM_WIN32s:
88 	return 0x02010000; /* 2.1 */
89     default:
90         FIXME("%x not supported\n", version.dwPlatformId);
91         /* fall through */
92     case VER_PLATFORM_WIN32_WINDOWS:
93 	return 0x04030000; /* 4.3.0 */
94     }
95 }
96 
97 /***********************************************************************
98  *           acmMessage32 (MSACM32.35)
99  * FIXME
100  *   No documentation found.
101  */
102 
103 /***********************************************************************
104  *           acmMetrics (MSACM32.@)
105  */
106 MMRESULT WINAPI acmMetrics(HACMOBJ hao, UINT uMetric, LPVOID pMetric)
107 {
108     PWINE_ACMOBJ 	pao = MSACM_GetObj(hao, WINE_ACMOBJ_DONTCARE);
109     BOOL 		bLocal = TRUE;
110     PWINE_ACMDRIVERID	padid;
111     DWORD		val = 0;
112     unsigned int	i;
113     MMRESULT		mmr = MMSYSERR_NOERROR;
114 
115     TRACE("(%p, %d, %p);\n", hao, uMetric, pMetric);
116 
117 #define CheckLocal(padid) (!bLocal || ((padid)->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_LOCAL))
118 
119     switch (uMetric) {
120     case ACM_METRIC_COUNT_DRIVERS:
121 	bLocal = FALSE;
122 	/* fall through */
123     case ACM_METRIC_COUNT_LOCAL_DRIVERS:
124 	if (hao) return MMSYSERR_INVALHANDLE;
125         if (!pMetric) return MMSYSERR_INVALPARAM;
126 	for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID)
127 	    if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && CheckLocal(padid))
128 		val++;
129 	*(LPDWORD)pMetric = val;
130 	break;
131 
132     case ACM_METRIC_COUNT_CODECS:
133 	bLocal = FALSE;
134 	/* fall through */
135     case ACM_METRIC_COUNT_LOCAL_CODECS:
136 	if (hao) return MMSYSERR_INVALHANDLE;
137         if (!pMetric) return MMSYSERR_INVALPARAM;
138 	for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID)
139 	    if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) &&
140 		(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CODEC) &&
141 		CheckLocal(padid))
142 		val++;
143 	*(LPDWORD)pMetric = val;
144 	break;
145 
146     case ACM_METRIC_COUNT_CONVERTERS:
147 	bLocal = FALSE;
148 	/* fall through */
149     case ACM_METRIC_COUNT_LOCAL_CONVERTERS:
150 	if (hao) return MMSYSERR_INVALHANDLE;
151         if (!pMetric) return MMSYSERR_INVALPARAM;
152 	for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID)
153 	    if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) &&
154 		 (padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CONVERTER) &&
155 		CheckLocal(padid))
156 		val++;
157 	*(LPDWORD)pMetric = val;
158 	break;
159 
160     case ACM_METRIC_COUNT_FILTERS:
161 	bLocal = FALSE;
162 	/* fall through */
163     case ACM_METRIC_COUNT_LOCAL_FILTERS:
164 	if (hao) return MMSYSERR_INVALHANDLE;
165         if (!pMetric) return MMSYSERR_INVALPARAM;
166 	for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID)
167 	    if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) &&
168 		(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_FILTER) &&
169 		CheckLocal(padid))
170 		val++;
171 	*(LPDWORD)pMetric = val;
172 	break;
173 
174     case ACM_METRIC_COUNT_DISABLED:
175 	bLocal = FALSE;
176 	/* fall through */
177     case ACM_METRIC_COUNT_LOCAL_DISABLED:
178 	if (hao) return MMSYSERR_INVALHANDLE;
179         if (!pMetric) return MMSYSERR_INVALPARAM;
180 	for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID)
181 	    if ((padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && CheckLocal(padid))
182 		val++;
183 	*(LPDWORD)pMetric = val;
184 	break;
185 
186     case ACM_METRIC_MAX_SIZE_FORMAT:
187 	if (hao == NULL) {
188 	    for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
189 		if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
190 		    for (i = 0; i < padid->cFormatTags; i++) {
191 			if (val < padid->aFormatTag[i].cbwfx)
192 			    val = padid->aFormatTag[i].cbwfx;
193 		    }
194 		}
195 	    }
196 	} else if (pao != NULL) {
197 	    switch (pao->dwType) {
198 	    case WINE_ACMOBJ_DRIVER:
199 	    case WINE_ACMOBJ_DRIVERID:
200 		padid = pao->pACMDriverID;
201 		break;
202 	    default:
203 		return MMSYSERR_INVALHANDLE;
204 	    }
205 	    if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED)) {
206 		for (i = 0; i < padid->cFormatTags; i++) {
207 		    if (val < padid->aFormatTag[i].cbwfx)
208 			val = padid->aFormatTag[i].cbwfx;
209 		}
210 	    }
211 	} else {
212 	    return MMSYSERR_INVALHANDLE;
213 	}
214         if (!pMetric) return MMSYSERR_INVALPARAM;
215 	*(LPDWORD)pMetric = val;
216         break;
217 
218     case ACM_METRIC_COUNT_HARDWARE:
219         if (hao) return MMSYSERR_INVALHANDLE;
220         if (!pMetric) return MMSYSERR_INVALPARAM;
221         *(LPDWORD)pMetric = 0;
222         FIXME("ACM_METRIC_COUNT_HARDWARE not implemented\n");
223         break;
224 
225     case ACM_METRIC_DRIVER_PRIORITY:
226         /* Return current list position of driver */
227         if (!hao) return MMSYSERR_INVALHANDLE;
228         mmr = MMSYSERR_INVALHANDLE;
229         for (i = 1, padid = MSACM_pFirstACMDriverID; padid; i++, padid = padid->pNextACMDriverID) {
230             if (padid == (PWINE_ACMDRIVERID)hao) {
231                 if (pMetric) {
232                     *(LPDWORD)pMetric = i;
233                     mmr = MMSYSERR_NOERROR;
234                 } else {
235                     mmr = MMSYSERR_INVALPARAM;
236                 }
237                 break;
238             }
239         }
240         break;
241 
242     case ACM_METRIC_DRIVER_SUPPORT:
243         /* Return fdwSupport for driver */
244         if (!hao) return MMSYSERR_INVALHANDLE;
245         mmr = MMSYSERR_INVALHANDLE;
246         for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) {
247             if (padid == (PWINE_ACMDRIVERID)hao) {
248                 if (pMetric) {
249                     *(LPDWORD)pMetric = padid->fdwSupport;
250                     mmr = MMSYSERR_NOERROR;
251                 } else {
252                     mmr = MMSYSERR_INVALPARAM;
253                 }
254                 break;
255             }
256         }
257         break;
258 
259     case ACM_METRIC_HARDWARE_WAVE_INPUT:
260     case ACM_METRIC_HARDWARE_WAVE_OUTPUT:
261     case ACM_METRIC_MAX_SIZE_FILTER:
262     default:
263 	FIXME("(%p, %d, %p): stub\n", hao, uMetric, pMetric);
264 	mmr = MMSYSERR_NOTSUPPORTED;
265     }
266     return mmr;
267 }
268