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