ddraw: Set dwMaxVertexCount to 2048.
[wine.git] / dlls / msacm32 / tests / msacm.c
blob5980ac7864095d8cd5ec953580672fde75c510c4
1 /*
2 * Unit tests for msacm functions
4 * Copyright (c) 2004 Robert Reif
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <math.h>
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "mmsystem.h"
31 #define NOBITMAP
32 #include "mmreg.h"
33 #include "msacm.h"
34 #include "msacmdrv.h"
36 static BOOL CALLBACK FormatTagEnumProc(HACMDRIVERID hadid,
37 PACMFORMATTAGDETAILSA paftd,
38 DWORD_PTR dwInstance,
39 DWORD fdwSupport)
41 MMRESULT rc;
42 HACMDRIVER had;
44 if (winetest_interactive)
45 trace(" Format 0x%04lx: %s\n", paftd->dwFormatTag, paftd->szFormatTag);
47 rc = acmDriverOpen(&had, hadid, 0);
48 ok(rc == MMSYSERR_NOERROR || rc == MMSYSERR_NODRIVER,
49 "acmDriverOpen(): rc = %08x, should be %08x\n",
50 rc, MMSYSERR_NOERROR);
52 if (rc == MMSYSERR_NOERROR)
54 ACMFORMATDETAILSA fd = {0};
55 WAVEFORMATEX *pwfx, dst;
56 ACMFORMATTAGDETAILSA aftd_pcm = {0};
57 DWORD dwSize, dwSizeMax;
58 DWORD i;
60 fd.cbStruct = sizeof(fd);
61 if (paftd->cbFormatSize < sizeof(WAVEFORMATEX))
62 pwfx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WAVEFORMATEX));
63 else
64 pwfx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, paftd->cbFormatSize);
65 fd.pwfx = pwfx;
66 fd.cbwfx = paftd->cbFormatSize;
67 fd.dwFormatTag = paftd->dwFormatTag;
69 /* try bad pwfx */
70 fd.pwfx = NULL;
71 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_FORMAT);
72 ok(rc == MMSYSERR_INVALPARAM,
73 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
74 rc, MMSYSERR_INVALPARAM);
75 fd.pwfx = pwfx;
77 /* try bad wFormatTag */
78 fd.pwfx->wFormatTag = WAVE_FORMAT_UNKNOWN;
79 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_FORMAT);
80 ok(rc == MMSYSERR_INVALPARAM,
81 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
82 rc, MMSYSERR_INVALPARAM);
83 fd.pwfx->wFormatTag = paftd->dwFormatTag;
85 /* try bad fdwSupport */
86 fd.fdwSupport = 0xdeadbeef;
87 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_FORMAT);
88 ok(rc == MMSYSERR_INVALPARAM,
89 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
90 rc, MMSYSERR_INVALPARAM);
91 fd.fdwSupport = 0;
93 /* try bad pwfx structure size */
94 fd.cbwfx = sizeof(PCMWAVEFORMAT)-1;
95 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_FORMAT);
96 ok(rc == MMSYSERR_INVALPARAM,
97 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
98 rc, MMSYSERR_INVALPARAM);
99 fd.cbwfx = paftd->cbFormatSize;
101 /* test bad parameters (all zero) */
102 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_FORMAT);
103 ok(rc == ACMERR_NOTPOSSIBLE,
104 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
105 rc, ACMERR_NOTPOSSIBLE);
107 /* test acmFormatSuggest */
109 /* if we don't specify a format, we must give at least the driver's maximum size for any format */
110 acmMetrics((HACMOBJ)had, ACM_METRIC_MAX_SIZE_FORMAT, &dwSize);
111 rc = acmFormatSuggest(had, pwfx, &dst, dwSize-1, 0);
112 ok(rc == MMSYSERR_INVALPARAM,
113 "acmFormatSuggest(): rc = %08x, should be %08x\n",
114 rc, MMSYSERR_INVALPARAM);
116 rc = acmFormatSuggest(had, pwfx, &dst, dwSize, 0);
117 ok(rc == ACMERR_NOTPOSSIBLE,
118 "acmFormatSuggest(): rc = %08x, should be %08x\n",
119 rc, ACMERR_NOTPOSSIBLE);
121 /* if we do specify a format, we must give at least the driver's maximum size for that format */
122 aftd_pcm.cbStruct = sizeof(aftd_pcm);
123 aftd_pcm.dwFormatTag = WAVE_FORMAT_PCM;
124 rc = acmFormatTagDetailsA(had, &aftd_pcm, ACM_FORMATTAGDETAILSF_LARGESTSIZE);
125 ok(rc == MMSYSERR_NOERROR, "returned %08x\n", rc);
127 dst.wFormatTag = WAVE_FORMAT_PCM;
128 rc = acmFormatSuggest(had, pwfx, &dst, aftd_pcm.cbFormatSize-1, ACM_FORMATSUGGESTF_WFORMATTAG);
129 ok(rc == MMSYSERR_INVALPARAM,
130 "acmFormatSuggest(): rc = %08x, should be %08x\n",
131 rc, MMSYSERR_INVALPARAM);
133 rc = acmFormatSuggest(had, pwfx, &dst, aftd_pcm.cbFormatSize, ACM_FORMATSUGGESTF_WFORMATTAG);
134 ok(rc == ACMERR_NOTPOSSIBLE,
135 "acmFormatSuggest(): rc = %08x, should be %08x\n",
136 rc, ACMERR_NOTPOSSIBLE);
138 /* test nonexistent format */
139 dst.wFormatTag = 0xbeef;
140 rc = acmFormatSuggest(had, pwfx, &dst, 0, ACM_FORMATSUGGESTF_WFORMATTAG);
141 ok(rc == ACMERR_NOTPOSSIBLE || rc == MMSYSERR_INVALPARAM,
142 "acmFormatSuggest(): rc = %08x, should be %08x\n",
143 rc, ACMERR_NOTPOSSIBLE);
145 /* if the driver is NULL, we must give at least the maximum size for any driver */
146 acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT, &dwSizeMax);
147 rc = acmFormatSuggest(NULL, pwfx, &dst, dwSizeMax-1, 0);
148 ok(rc == MMSYSERR_INVALPARAM,
149 "acmFormatSuggest(): rc = %08x, should be %08x\n",
150 rc, MMSYSERR_INVALPARAM);
152 if (paftd->dwFormatTag != WAVE_FORMAT_PCM)
154 rc = acmFormatSuggest(NULL, pwfx, &dst, dwSizeMax, 0);
155 ok(rc == ACMERR_NOTPOSSIBLE,
156 "acmFormatSuggest(): rc = %08x, should be %08x\n",
157 rc, ACMERR_NOTPOSSIBLE);
160 /* if we specify a dst format, we must give the maximum size for that format */
161 dst.wFormatTag = WAVE_FORMAT_PCM;
162 rc = acmFormatSuggest(NULL, pwfx, &dst, aftd_pcm.cbFormatSize-1, ACM_FORMATSUGGESTF_WFORMATTAG);
163 ok(rc == MMSYSERR_INVALPARAM || broken (rc == ACMERR_NOTPOSSIBLE), /* WinXP */
164 "acmFormatSuggest(): rc = %08x, should be %08x\n",
165 rc, MMSYSERR_INVALPARAM);
167 rc = acmFormatSuggest(NULL, pwfx, &dst, aftd_pcm.cbFormatSize, ACM_FORMATSUGGESTF_WFORMATTAG);
168 ok(rc == ACMERR_NOTPOSSIBLE,
169 "acmFormatSuggest(): rc = %08x, should be %08x\n",
170 rc, ACMERR_NOTPOSSIBLE);
172 dst.wFormatTag = paftd->dwFormatTag;
173 rc = acmFormatSuggest(NULL, pwfx, &dst, paftd->cbFormatSize-1, ACM_FORMATSUGGESTF_WFORMATTAG);
174 ok(rc == MMSYSERR_INVALPARAM || broken (rc == ACMERR_NOTPOSSIBLE), /* WinXP */
175 "acmFormatSuggest(): rc = %08x, should be %08x\n",
176 rc, MMSYSERR_INVALPARAM);
178 rc = acmFormatSuggest(NULL, pwfx, &dst, paftd->cbFormatSize, ACM_FORMATSUGGESTF_WFORMATTAG);
179 ok(rc == ACMERR_NOTPOSSIBLE,
180 "acmFormatSuggest(): rc = %08x, should be %08x\n",
181 rc, ACMERR_NOTPOSSIBLE);
183 /* test nonexistent format */
184 dst.wFormatTag = 0xbeef;
185 rc = acmFormatSuggest(NULL, pwfx, &dst, 0, ACM_FORMATSUGGESTF_WFORMATTAG);
186 ok(rc == ACMERR_NOTPOSSIBLE || rc == MMSYSERR_INVALPARAM,
187 "acmFormatSuggest(): rc = %08x, should be %08x\n",
188 rc, ACMERR_NOTPOSSIBLE);
190 /* test index */
191 for (i = 0; i < paftd->cStandardFormats; i++)
193 fd.dwFormatIndex = i;
195 fd.fdwSupport = 0;
196 fd.cbwfx = paftd->cbFormatSize;
197 fd.pwfx->cbSize = 0xbeef;
198 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_INDEX);
199 ok(rc == MMSYSERR_NOERROR,
200 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
201 rc, MMSYSERR_NOERROR);
203 /* Windows will write cbSize (and other data) even if the
204 * given cbwfx is not large enough */
205 fd.fdwSupport = 0;
206 fd.cbwfx = sizeof(PCMWAVEFORMAT);
207 fd.pwfx->cbSize = 0xbeef;
208 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_INDEX);
209 todo_wine_if(rc != MMSYSERR_NOERROR) /* remove when fixed */
210 ok(rc == MMSYSERR_NOERROR,
211 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
212 rc, MMSYSERR_NOERROR);
213 if (paftd->dwFormatTag != WAVE_FORMAT_PCM)
214 todo_wine_if(fd.pwfx->cbSize != paftd->cbFormatSize - sizeof(WAVEFORMATEX)) /* remove when fixed */
215 ok(fd.pwfx->cbSize == paftd->cbFormatSize - sizeof(WAVEFORMATEX),
216 "got %d\n", fd.pwfx->cbSize);
219 /* one more */
220 fd.dwFormatIndex = paftd->cStandardFormats;
221 fd.fdwSupport = 0;
222 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_INDEX);
223 ok(rc == MMSYSERR_INVALPARAM,
224 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
225 rc, MMSYSERR_INVALPARAM);
227 HeapFree(GetProcessHeap(), 0, pwfx);
229 return TRUE;
232 static BOOL CALLBACK FormatEnumProc(HACMDRIVERID hadid,
233 LPACMFORMATDETAILSA pafd,
234 DWORD_PTR dwInstance,
235 DWORD fd)
237 MMRESULT rc;
238 HACMDRIVER had;
239 WAVEFORMATEX *dst, *dstMax;
240 DWORD dwSize, dwSizeMax;
241 DWORD fdwSupport;
243 acmMetrics((HACMOBJ)hadid, ACM_METRIC_DRIVER_SUPPORT, &fdwSupport);
245 if (winetest_interactive)
246 trace(" 0x%04lx, %s\n", pafd->dwFormatTag, pafd->szFormat);
248 acmDriverOpen(&had, hadid, 0);
249 dwSize = pafd->cbwfx;
250 dst = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
252 /* test acmFormatSuggest with valid src format */
253 if (pafd->dwFormatTag == WAVE_FORMAT_PCM)
255 rc = acmFormatSuggest(had, pafd->pwfx, dst, dwSize, 0);
256 /* this fails on some decode-only drivers */
257 ok(rc == MMSYSERR_NOERROR || rc == ACMERR_NOTPOSSIBLE,
258 "acmFormatSuggest(): rc = %08x, should be %08x\n",
259 rc, MMSYSERR_NOERROR);
260 if (rc == MMSYSERR_NOERROR)
262 if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CODEC) /* supports different conversions */
263 ok(dst->wFormatTag != WAVE_FORMAT_PCM, "expected different format\n");
264 else
265 ok(dst->wFormatTag == WAVE_FORMAT_PCM,
266 "expected %d, got %d\n", WAVE_FORMAT_PCM, dst->wFormatTag);
269 else
271 rc = acmFormatSuggest(had, pafd->pwfx, dst, dwSize, 0);
272 ok(rc == MMSYSERR_NOERROR,
273 "acmFormatSuggest(): rc = %08x, should be %08x\n",
274 rc, MMSYSERR_NOERROR);
275 ok(dst->wFormatTag == WAVE_FORMAT_PCM,
276 "expected %d, got %d\n", WAVE_FORMAT_PCM, dst->wFormatTag);
277 ok(dst->nChannels == pafd->pwfx->nChannels,
278 "expected %d, got %d\n", pafd->pwfx->nChannels, dst->nChannels);
279 if (pafd->dwFormatTag != 0x42) /* codec 0x0042 returns a different sample rate */
280 ok(dst->nSamplesPerSec == pafd->pwfx->nSamplesPerSec,
281 "expected %ld, got %ld\n", pafd->pwfx->nSamplesPerSec, dst->nSamplesPerSec);
282 ok(dst->wBitsPerSample == 16,
283 "expected %d, got %d\n", 16, dst->wBitsPerSample);
284 ok(dst->nBlockAlign == 2*pafd->pwfx->nChannels,
285 "expected %d, got %d\n", 2*pafd->pwfx->nChannels, dst->nBlockAlign);
287 /* test with NULL driver */
288 acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT, &dwSizeMax);
289 dstMax = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSizeMax);
290 rc = acmFormatSuggest(NULL, pafd->pwfx, dstMax, dwSizeMax, 0);
291 ok(rc == MMSYSERR_NOERROR,
292 "acmFormatSuggest(): rc = %08x, should be %08x\n",
293 rc, MMSYSERR_NOERROR);
295 HeapFree(GetProcessHeap(), 0, dstMax);
298 ZeroMemory(dst, dwSize);
299 dst->wFormatTag = pafd->pwfx->wFormatTag;
300 rc = acmFormatSuggest(had, pafd->pwfx, dst, dwSize, ACM_FORMATSUGGESTF_WFORMATTAG);
301 if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CONVERTER) /* supports same conversions */
302 ok(rc == MMSYSERR_NOERROR,
303 "acmFormatSuggest(): rc = %08x, should be %08x\n",
304 rc, MMSYSERR_NOERROR);
305 else
306 todo_wine_if(rc != ACMERR_NOTPOSSIBLE)
307 ok(rc == ACMERR_NOTPOSSIBLE,
308 "acmFormatSuggest(): rc = %08x, should be %08x\n",
309 rc, ACMERR_NOTPOSSIBLE);
311 HeapFree(GetProcessHeap(), 0, dst);
312 acmDriverClose(had, 0);
314 return TRUE;
317 static BOOL CALLBACK DriverEnumProc(HACMDRIVERID hadid,
318 DWORD_PTR dwInstance,
319 DWORD fdwSupport)
321 MMRESULT rc;
322 ACMDRIVERDETAILSA dd;
323 HACMDRIVER had;
325 DWORD dwDriverPriority;
326 DWORD dwDriverSupport;
328 if (winetest_interactive) {
329 trace("id: %p\n", hadid);
330 trace(" Supports:\n");
331 if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_ASYNC)
332 trace(" async conversions\n");
333 if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CODEC)
334 trace(" different format conversions\n");
335 if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CONVERTER)
336 trace(" same format conversions\n");
337 if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_FILTER)
338 trace(" filtering\n");
341 /* try an invalid pointer */
342 rc = acmDriverDetailsA(hadid, 0, 0);
343 ok(rc == MMSYSERR_INVALPARAM,
344 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
345 rc, MMSYSERR_INVALPARAM);
347 /* try an invalid structure size */
348 ZeroMemory(&dd, sizeof(dd));
349 rc = acmDriverDetailsA(hadid, &dd, 0);
350 ok(rc == MMSYSERR_INVALPARAM,
351 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
352 rc, MMSYSERR_INVALPARAM);
354 /* MSDN says this should fail but it doesn't in practice */
355 dd.cbStruct = 4;
356 rc = acmDriverDetailsA(hadid, &dd, 0);
357 ok(rc == MMSYSERR_NOERROR || rc == MMSYSERR_NOTSUPPORTED,
358 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
359 rc, MMSYSERR_NOERROR);
361 /* try an invalid handle */
362 dd.cbStruct = sizeof(dd);
363 rc = acmDriverDetailsA((HACMDRIVERID)1, &dd, 0);
364 ok(rc == MMSYSERR_INVALHANDLE,
365 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
366 rc, MMSYSERR_INVALHANDLE);
368 /* try an invalid handle and pointer */
369 rc = acmDriverDetailsA((HACMDRIVERID)1, 0, 0);
370 ok(rc == MMSYSERR_INVALPARAM,
371 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
372 rc, MMSYSERR_INVALPARAM);
374 /* try invalid details */
375 rc = acmDriverDetailsA(hadid, &dd, -1);
376 ok(rc == MMSYSERR_INVALFLAG,
377 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
378 rc, MMSYSERR_INVALFLAG);
380 /* try valid parameters */
381 rc = acmDriverDetailsA(hadid, &dd, 0);
382 ok(rc == MMSYSERR_NOERROR || rc == MMSYSERR_NOTSUPPORTED,
383 "acmDriverDetailsA(): rc = %08x, should be %08x\n",
384 rc, MMSYSERR_NOERROR);
386 /* cbStruct should contain size of returned data (at most sizeof(dd))
387 TODO: should it be *exactly* sizeof(dd), as tested here?
389 if (rc == MMSYSERR_NOERROR) {
390 static const struct {
391 const char *shortname;
392 WORD mid;
393 WORD pid;
394 WORD pid_alt;
395 } *iter, expected_ids[] = {
396 { "Microsoft IMA ADPCM", MM_MICROSOFT, MM_MSFT_ACM_IMAADPCM },
397 { "MS-ADPCM", MM_MICROSOFT, MM_MSFT_ACM_MSADPCM },
398 { "Microsoft CCITT G.711", MM_MICROSOFT, MM_MSFT_ACM_G711},
399 { "MPEG Layer-3 Codec", MM_FRAUNHOFER_IIS, MM_FHGIIS_MPEGLAYER3_DECODE, MM_FHGIIS_MPEGLAYER3_PROFESSIONAL },
400 { "MS-PCM", MM_MICROSOFT, MM_MSFT_ACM_PCM },
401 { 0 }
404 ok(dd.cbStruct == sizeof(dd),
405 "acmDriverDetailsA(): cbStruct = %08lx\n", dd.cbStruct);
407 for (iter = expected_ids; iter->shortname; ++iter) {
408 if (!strcmp(iter->shortname, dd.szShortName)) {
409 /* try alternative product id on mismatch */
410 if (iter->pid_alt && iter->pid != dd.wPid)
411 ok(iter->mid == dd.wMid && iter->pid_alt == dd.wPid,
412 "Got wrong manufacturer (0x%x vs 0x%x) or product (0x%x vs 0x%x)\n",
413 dd.wMid, iter->mid,
414 dd.wPid, iter->pid_alt);
415 else
416 ok(iter->mid == dd.wMid && iter->pid == dd.wPid,
417 "Got wrong manufacturer (0x%x vs 0x%x) or product (0x%x vs 0x%x)\n",
418 dd.wMid, iter->mid,
419 dd.wPid, iter->pid);
424 if (rc == MMSYSERR_NOERROR && winetest_interactive) {
425 trace(" Short name: %s\n", dd.szShortName);
426 trace(" Long name: %s\n", dd.szLongName);
427 trace(" Copyright: %s\n", dd.szCopyright);
428 trace(" Licensing: %s\n", dd.szLicensing);
429 trace(" Features: %s\n", dd.szFeatures);
430 trace(" Supports %lu formats\n", dd.cFormatTags);
431 trace(" Supports %lu filter formats\n", dd.cFilterTags);
432 trace(" Mid: 0x%x\n", dd.wMid);
433 trace(" Pid: 0x%x\n", dd.wPid);
436 /* try bad pointer */
437 rc = acmMetrics((HACMOBJ)hadid, ACM_METRIC_DRIVER_PRIORITY, 0);
438 ok(rc == MMSYSERR_INVALPARAM,
439 "acmMetrics(): rc = %08x, should be %08x\n",
440 rc, MMSYSERR_INVALPARAM);
442 /* try bad handle */
443 rc = acmMetrics((HACMOBJ)1, ACM_METRIC_DRIVER_PRIORITY, &dwDriverPriority);
444 ok(rc == MMSYSERR_INVALHANDLE,
445 "acmMetrics(): rc = %08x, should be %08x\n",
446 rc, MMSYSERR_INVALHANDLE);
448 /* try bad pointer and handle */
449 rc = acmMetrics((HACMOBJ)1, ACM_METRIC_DRIVER_PRIORITY, 0);
450 ok(rc == MMSYSERR_INVALHANDLE,
451 "acmMetrics(): rc = %08x, should be %08x\n",
452 rc, MMSYSERR_INVALHANDLE);
454 /* try valid parameters */
455 rc = acmMetrics((HACMOBJ)hadid, ACM_METRIC_DRIVER_PRIORITY, &dwDriverSupport);
456 ok(rc == MMSYSERR_NOERROR,
457 "acmMetrics(): rc = %08x, should be %08x\n",
458 rc, MMSYSERR_NOERROR);
460 /* try bad pointer */
461 rc = acmMetrics((HACMOBJ)hadid, ACM_METRIC_DRIVER_SUPPORT, 0);
462 ok(rc == MMSYSERR_INVALPARAM,
463 "acmMetrics(): rc = %08x, should be %08x\n",
464 rc, MMSYSERR_INVALPARAM);
466 /* try bad handle */
467 rc = acmMetrics((HACMOBJ)1, ACM_METRIC_DRIVER_SUPPORT, &dwDriverSupport);
468 ok(rc == MMSYSERR_INVALHANDLE,
469 "acmMetrics(): rc = %08x, should be %08x\n",
470 rc, MMSYSERR_INVALHANDLE);
472 /* try bad pointer and handle */
473 rc = acmMetrics((HACMOBJ)1, ACM_METRIC_DRIVER_SUPPORT, 0);
474 ok(rc == MMSYSERR_INVALHANDLE,
475 "acmMetrics(): rc = %08x, should be %08x\n",
476 rc, MMSYSERR_INVALHANDLE);
478 /* try valid parameters */
479 rc = acmMetrics((HACMOBJ)hadid, ACM_METRIC_DRIVER_SUPPORT, &dwDriverSupport);
480 ok(rc == MMSYSERR_NOERROR,
481 "acmMetrics(): rc = %08x, should be %08x\n",
482 rc, MMSYSERR_NOERROR);
484 /* try invalid pointer */
485 rc = acmDriverOpen(0, hadid, 0);
486 ok(rc == MMSYSERR_INVALPARAM,
487 "acmDriverOpen(): rc = %08x, should be %08x\n",
488 rc, MMSYSERR_INVALPARAM);
490 /* try invalid handle */
491 rc = acmDriverOpen(&had, (HACMDRIVERID)1, 0);
492 ok(rc == MMSYSERR_INVALHANDLE,
493 "acmDriverOpen(): rc = %08x, should be %08x\n",
494 rc, MMSYSERR_INVALHANDLE);
496 /* try invalid open */
497 rc = acmDriverOpen(&had, hadid, -1);
498 ok(rc == MMSYSERR_INVALFLAG,
499 "acmDriverOpen(): rc = %08x, should be %08x\n",
500 rc, MMSYSERR_INVALFLAG);
502 /* try valid parameters */
503 rc = acmDriverOpen(&had, hadid, 0);
504 ok(rc == MMSYSERR_NOERROR || rc == MMSYSERR_NODRIVER,
505 "acmDriverOpen(): rc = %08x, should be %08x\n",
506 rc, MMSYSERR_NOERROR);
508 if (rc == MMSYSERR_NOERROR) {
509 DWORD dwSize;
510 HACMDRIVERID hid;
512 /* try bad pointer */
513 rc = acmDriverID((HACMOBJ)had, 0, 0);
514 ok(rc == MMSYSERR_INVALPARAM,
515 "acmDriverID(): rc = %08x, should be %08x\n",
516 rc, MMSYSERR_INVALPARAM);
518 /* try bad handle */
519 rc = acmDriverID((HACMOBJ)1, &hid, 0);
520 ok(rc == MMSYSERR_INVALHANDLE,
521 "acmDriverID(): rc = %08x, should be %08x\n",
522 rc, MMSYSERR_INVALHANDLE);
524 /* try bad handle and pointer */
525 rc = acmDriverID((HACMOBJ)1, 0, 0);
526 ok(rc == MMSYSERR_INVALHANDLE,
527 "acmDriverID(): rc = %08x, should be %08x\n",
528 rc, MMSYSERR_INVALHANDLE);
530 /* try bad flag */
531 rc = acmDriverID((HACMOBJ)had, &hid, 1);
532 ok(rc == MMSYSERR_INVALFLAG,
533 "acmDriverID(): rc = %08x, should be %08x\n",
534 rc, MMSYSERR_INVALFLAG);
536 /* try valid parameters */
537 rc = acmDriverID((HACMOBJ)had, &hid, 0);
538 ok(rc == MMSYSERR_NOERROR,
539 "acmDriverID(): rc = %08x, should be %08x\n",
540 rc, MMSYSERR_NOERROR);
541 ok(hid == hadid,
542 "acmDriverID() returned ID %p doesn't equal %p\n",
543 hid, hadid);
545 /* try bad pointer */
546 rc = acmMetrics((HACMOBJ)had, ACM_METRIC_MAX_SIZE_FORMAT, 0);
547 ok(rc == MMSYSERR_INVALPARAM,
548 "acmMetrics(): rc = %08x, should be %08x\n",
549 rc, MMSYSERR_INVALPARAM);
551 /* try bad handle */
552 rc = acmMetrics((HACMOBJ)1, ACM_METRIC_MAX_SIZE_FORMAT, &dwSize);
553 ok(rc == MMSYSERR_INVALHANDLE,
554 "acmMetrics(): rc = %08x, should be %08x\n",
555 rc, MMSYSERR_INVALHANDLE);
557 /* try bad pointer and handle */
558 rc = acmMetrics((HACMOBJ)1, ACM_METRIC_MAX_SIZE_FORMAT, 0);
559 ok(rc == MMSYSERR_INVALHANDLE,
560 "acmMetrics(): rc = %08x, should be %08x\n",
561 rc, MMSYSERR_INVALHANDLE);
563 /* try valid parameters */
564 rc = acmMetrics((HACMOBJ)had, ACM_METRIC_MAX_SIZE_FORMAT, &dwSize);
565 ok(rc == MMSYSERR_NOERROR,
566 "acmMetrics(): rc = %08x, should be %08x\n",
567 rc, MMSYSERR_NOERROR);
568 if (rc == MMSYSERR_NOERROR) {
569 ACMFORMATDETAILSA fd;
570 WAVEFORMATEX * pwfx;
571 ACMFORMATTAGDETAILSA aftd;
573 /* try bad pointer */
574 rc = acmFormatEnumA(had, 0, FormatEnumProc, 0, 0);
575 ok(rc == MMSYSERR_INVALPARAM,
576 "acmFormatEnumA(): rc = %08x, should be %08x\n",
577 rc, MMSYSERR_INVALPARAM);
579 /* try bad structure size */
580 ZeroMemory(&fd, sizeof(fd));
581 rc = acmFormatEnumA(had, &fd, FormatEnumProc, 0, 0);
582 ok(rc == MMSYSERR_INVALPARAM,
583 "acmFormatEnumA(): rc = %08x, should be %08x\n",
584 rc, MMSYSERR_INVALPARAM);
586 fd.cbStruct = sizeof(fd) - 1;
587 rc = acmFormatEnumA(had, &fd, FormatEnumProc, 0, 0);
588 ok(rc == MMSYSERR_INVALPARAM,
589 "acmFormatEnumA(): rc = %08x, should be %08x\n",
590 rc, MMSYSERR_INVALPARAM);
592 pwfx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
594 if (dwSize >= sizeof(WAVEFORMATEX))
595 pwfx->cbSize = LOWORD(dwSize) - sizeof(WAVEFORMATEX);
596 pwfx->wFormatTag = WAVE_FORMAT_UNKNOWN;
598 fd.cbStruct = sizeof(fd);
599 fd.pwfx = pwfx;
600 fd.cbwfx = dwSize;
601 fd.dwFormatTag = WAVE_FORMAT_UNKNOWN;
603 /* try bad callback */
604 rc = acmFormatEnumA(had, &fd, NULL, 0, 0);
605 ok(rc == MMSYSERR_INVALPARAM,
606 "acmFormatEnumA(): rc = %08x, should be %08x\n",
607 rc, MMSYSERR_INVALPARAM);
609 /* try bad pwfx */
610 fd.pwfx = NULL;
611 rc = acmFormatEnumA(had, &fd, FormatEnumProc, 0, 0);
612 ok(rc == MMSYSERR_INVALPARAM,
613 "acmFormatEnumA(): rc = %08x, should be %08x\n",
614 rc, MMSYSERR_INVALPARAM);
615 fd.pwfx = pwfx;
617 /* fdwSupport must be zero */
618 fd.fdwSupport = 0xdeadbeef;
619 rc = acmFormatEnumA(had, &fd, FormatEnumProc, 0, 0);
620 ok(rc == MMSYSERR_INVALPARAM,
621 "acmFormatEnumA(): rc = %08x, should be %08x\n",
622 rc, MMSYSERR_INVALPARAM);
623 fd.fdwSupport = 0;
625 /* try bad pwfx structure size */
626 fd.cbwfx = dwSize-1;
627 rc = acmFormatEnumA(had, &fd, FormatEnumProc, 0, 0);
628 ok(rc == MMSYSERR_INVALPARAM,
629 "acmFormatEnumA(): rc = %08x, should be %08x\n",
630 rc, MMSYSERR_INVALPARAM);
631 fd.cbwfx = dwSize;
633 /* try valid parameters */
634 rc = acmFormatEnumA(had, &fd, FormatEnumProc, 0, 0);
635 ok(rc == MMSYSERR_NOERROR,
636 "acmFormatEnumA(): rc = %08x, should be %08x\n",
637 rc, MMSYSERR_NOERROR);
639 /* try bad pointer */
640 rc = acmFormatTagEnumA(had, 0, FormatTagEnumProc, 0, 0);
641 ok(rc == MMSYSERR_INVALPARAM,
642 "acmFormatTagEnumA(): rc = %08x, should be %08x\n",
643 rc, MMSYSERR_INVALPARAM);
645 /* try bad structure size */
646 ZeroMemory(&aftd, sizeof(aftd));
647 rc = acmFormatTagEnumA(had, &aftd, FormatTagEnumProc, 0, 0);
648 ok(rc == MMSYSERR_INVALPARAM,
649 "acmFormatTagEnumA(): rc = %08x, should be %08x\n",
650 rc, MMSYSERR_INVALPARAM);
652 aftd.cbStruct = sizeof(aftd) - 1;
653 rc = acmFormatTagEnumA(had, &aftd, FormatTagEnumProc, 0, 0);
654 ok(rc == MMSYSERR_INVALPARAM,
655 "acmFormatTagEnumA(): rc = %08x, should be %08x\n",
656 rc, MMSYSERR_INVALPARAM);
658 aftd.cbStruct = sizeof(aftd);
659 aftd.dwFormatTag = WAVE_FORMAT_UNKNOWN;
661 /* try bad flag */
662 rc = acmFormatTagEnumA(had, &aftd, FormatTagEnumProc, 0, 1);
663 ok(rc == MMSYSERR_INVALFLAG,
664 "acmFormatTagEnumA(): rc = %08x, should be %08x\n",
665 rc, MMSYSERR_INVALFLAG);
667 /* try valid parameters */
668 rc = acmFormatTagEnumA(had, &aftd, FormatTagEnumProc, 0, 0);
669 ok(rc == MMSYSERR_NOERROR,
670 "acmFormatTagEnumA(): rc = %08x, should be %08x\n",
671 rc, MMSYSERR_NOERROR);
673 /* try bad pointer */
674 rc = acmFormatDetailsA(had, NULL, ACM_FORMATDETAILSF_INDEX);
675 ok(rc == MMSYSERR_INVALPARAM,
676 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
677 rc, MMSYSERR_INVALPARAM);
679 /* try bad structure size */
680 ZeroMemory(&fd, sizeof(fd));
681 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_INDEX);
682 ok(rc == MMSYSERR_INVALPARAM,
683 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
684 rc, MMSYSERR_INVALPARAM);
686 fd.cbStruct = sizeof(fd) - 1;
687 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_INDEX);
688 ok(rc == MMSYSERR_INVALPARAM,
689 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
690 rc, MMSYSERR_INVALPARAM);
692 fd.cbStruct = sizeof(fd);
693 fd.pwfx = pwfx;
694 ZeroMemory(fd.pwfx, dwSize);
695 fd.cbwfx = dwSize;
696 fd.dwFormatTag = WAVE_FORMAT_UNKNOWN;
698 /* try WAVE_FORMAT_UNKNOWN */
699 rc = acmFormatDetailsA(had, &fd, ACM_FORMATDETAILSF_INDEX);
700 ok(rc == MMSYSERR_INVALPARAM,
701 "acmFormatDetailsA(): rc = %08x, should be %08x\n",
702 rc, MMSYSERR_INVALPARAM);
704 HeapFree(GetProcessHeap(), 0, pwfx);
706 /* try invalid handle */
707 rc = acmDriverClose((HACMDRIVER)1, 0);
708 ok(rc == MMSYSERR_INVALHANDLE,
709 "acmDriverClose(): rc = %08x, should be %08x\n",
710 rc, MMSYSERR_INVALHANDLE);
712 /* try invalid flag */
713 rc = acmDriverClose(had, 1);
714 ok(rc == MMSYSERR_INVALFLAG,
715 "acmDriverClose(): rc = %08x, should be %08x\n",
716 rc, MMSYSERR_INVALFLAG);
718 /* try valid parameters */
719 rc = acmDriverClose(had, 0);
720 ok(rc == MMSYSERR_NOERROR,
721 "acmDriverClose(): rc = %08x, should be %08x\n",
722 rc, MMSYSERR_NOERROR);
724 /* try closing again */
725 rc = acmDriverClose(had, 0);
726 ok(rc == MMSYSERR_INVALHANDLE,
727 "acmDriverClose(): rc = %08x, should be %08x\n",
728 rc, MMSYSERR_INVALHANDLE);
732 return TRUE;
735 static const char * get_metric(UINT uMetric)
737 switch (uMetric) {
738 case ACM_METRIC_COUNT_CODECS:
739 return "ACM_METRIC_COUNT_CODECS";
740 case ACM_METRIC_COUNT_CONVERTERS:
741 return "ACM_METRIC_COUNT_CONVERTERS";
742 case ACM_METRIC_COUNT_DISABLED:
743 return "ACM_METRIC_COUNT_DISABLED";
744 case ACM_METRIC_COUNT_DRIVERS:
745 return "ACM_METRIC_COUNT_DRIVERS";
746 case ACM_METRIC_COUNT_FILTERS:
747 return "ACM_METRIC_COUNT_FILTERS";
748 case ACM_METRIC_COUNT_HARDWARE:
749 return "ACM_METRIC_COUNT_HARDWARE";
750 case ACM_METRIC_COUNT_LOCAL_CODECS:
751 return "ACM_METRIC_COUNT_LOCAL_CODECS";
752 case ACM_METRIC_COUNT_LOCAL_CONVERTERS:
753 return "ACM_METRIC_COUNT_LOCAL_CONVERTERS";
754 case ACM_METRIC_COUNT_LOCAL_DISABLED:
755 return "ACM_METRIC_COUNT_LOCAL_DISABLED";
756 case ACM_METRIC_COUNT_LOCAL_DRIVERS:
757 return "ACM_METRIC_COUNT_LOCAL_DRIVERS";
758 case ACM_METRIC_COUNT_LOCAL_FILTERS:
759 return "ACM_METRIC_COUNT_LOCAL_FILTERS";
760 case ACM_METRIC_DRIVER_PRIORITY:
761 return "ACM_METRIC_DRIVER_PRIORITY";
762 case ACM_METRIC_DRIVER_SUPPORT:
763 return "ACM_METRIC_DRIVER_SUPPORT";
764 case ACM_METRIC_HARDWARE_WAVE_INPUT:
765 return "ACM_METRIC_HARDWARE_WAVE_INPUT";
766 case ACM_METRIC_HARDWARE_WAVE_OUTPUT:
767 return "ACM_METRIC_HARDWARE_WAVE_OUTPUT";
768 case ACM_METRIC_MAX_SIZE_FILTER:
769 return "ACM_METRIC_MAX_SIZE_FILTER";
770 case ACM_METRIC_MAX_SIZE_FORMAT:
771 return "ACM_METRIC_MAX_SIZE_FORMAT";
774 return "UNKNOWN";
777 static void check_count(UINT uMetric)
779 DWORD dwMetric;
780 MMRESULT rc;
782 /* try invalid result pointer */
783 rc = acmMetrics(NULL, uMetric, 0);
784 ok(rc == MMSYSERR_INVALPARAM,
785 "acmMetrics(NULL, %s, 0): rc = 0x%08x, should be 0x%08x\n",
786 get_metric(uMetric), rc, MMSYSERR_INVALPARAM);
788 /* try invalid handle */
789 rc = acmMetrics((HACMOBJ)1, uMetric, &dwMetric);
790 ok(rc == MMSYSERR_INVALHANDLE,
791 "acmMetrics(1, %s, %p): rc = 0x%08x, should be 0x%08x\n",
792 get_metric(uMetric), &dwMetric, rc, MMSYSERR_INVALHANDLE);
794 /* try invalid result pointer and handle */
795 rc = acmMetrics((HACMOBJ)1, uMetric, 0);
796 ok(rc == MMSYSERR_INVALHANDLE,
797 "acmMetrics(1, %s, 0): rc = 0x%08x, should be 0x%08x\n",
798 get_metric(uMetric), rc, MMSYSERR_INVALHANDLE);
800 /* try valid parameters */
801 rc = acmMetrics(NULL, uMetric, &dwMetric);
802 ok(rc == MMSYSERR_NOERROR, "acmMetrics() failed: rc = 0x%08x\n", rc);
804 if (rc == MMSYSERR_NOERROR && winetest_interactive)
805 trace("%s: %lu\n", get_metric(uMetric), dwMetric);
808 static void driver_tests(void)
810 MMRESULT rc;
811 DWORD dwACMVersion = acmGetVersion();
813 if (winetest_interactive) {
814 trace("ACM version = %u.%02u build %u%s\n",
815 HIWORD(dwACMVersion) >> 8,
816 HIWORD(dwACMVersion) & 0xff,
817 LOWORD(dwACMVersion),
818 LOWORD(dwACMVersion) == 0 ? " (Retail)" : "");
821 check_count(ACM_METRIC_COUNT_CODECS);
822 check_count(ACM_METRIC_COUNT_CONVERTERS);
823 check_count(ACM_METRIC_COUNT_DISABLED);
824 check_count(ACM_METRIC_COUNT_DRIVERS);
825 check_count(ACM_METRIC_COUNT_FILTERS);
826 check_count(ACM_METRIC_COUNT_HARDWARE);
827 check_count(ACM_METRIC_COUNT_LOCAL_CODECS);
828 check_count(ACM_METRIC_COUNT_LOCAL_CONVERTERS);
829 check_count(ACM_METRIC_COUNT_LOCAL_DISABLED);
830 check_count(ACM_METRIC_COUNT_LOCAL_DRIVERS);
831 check_count(ACM_METRIC_COUNT_LOCAL_FILTERS);
833 if (winetest_interactive)
834 trace("enabled drivers:\n");
836 rc = acmDriverEnum(DriverEnumProc, 0, 0);
837 ok(rc == MMSYSERR_NOERROR,
838 "acmDriverEnum() failed, rc=%08x, should be 0x%08x\n",
839 rc, MMSYSERR_NOERROR);
842 static void test_prepareheader(void)
844 HACMSTREAM has;
845 ADPCMWAVEFORMAT *src;
846 WAVEFORMATEX dst;
847 MMRESULT mr;
848 ACMSTREAMHEADER hdr;
849 BYTE buf[sizeof(WAVEFORMATEX) + 32], pcm[2048], input[512];
850 ADPCMCOEFSET *coef;
852 src = (ADPCMWAVEFORMAT*)buf;
853 coef = src->aCoef;
854 src->wfx.cbSize = 32;
855 src->wfx.wFormatTag = WAVE_FORMAT_ADPCM;
856 src->wfx.nSamplesPerSec = 22050;
857 src->wfx.wBitsPerSample = 4;
858 src->wfx.nChannels = 1;
859 src->wfx.nBlockAlign = 512;
860 src->wfx.nAvgBytesPerSec = 11025;
861 src->wSamplesPerBlock = 0x3f4;
862 src->wNumCoef = 7;
863 coef[0].iCoef1 = 0x0100;
864 coef[0].iCoef2 = 0x0000;
865 coef[1].iCoef1 = 0x0200;
866 coef[1].iCoef2 = 0xff00;
867 coef[2].iCoef1 = 0x0000;
868 coef[2].iCoef2 = 0x0000;
869 coef[3].iCoef1 = 0x00c0;
870 coef[3].iCoef2 = 0x0040;
871 coef[4].iCoef1 = 0x00f0;
872 coef[4].iCoef2 = 0x0000;
873 coef[5].iCoef1 = 0x01cc;
874 coef[5].iCoef2 = 0xff30;
875 coef[6].iCoef1 = 0x0188;
876 coef[6].iCoef2 = 0xff18;
878 dst.cbSize = 0;
879 dst.wFormatTag = WAVE_FORMAT_PCM;
880 dst.nSamplesPerSec = 22050;
881 dst.wBitsPerSample = 8;
882 dst.nChannels = 1;
883 dst.nBlockAlign = dst.wBitsPerSample * dst.nChannels / 8;
884 dst.nAvgBytesPerSec = dst.nSamplesPerSec * dst.nBlockAlign;
886 mr = acmStreamOpen(&has, NULL, (WAVEFORMATEX*)src, &dst, NULL, 0, 0, 0);
887 ok(mr == MMSYSERR_NOERROR, "open failed: 0x%x\n", mr);
889 memset(input, 0, sizeof(input));
890 memset(&hdr, 0, sizeof(hdr));
891 hdr.cbStruct = sizeof(hdr);
892 hdr.pbSrc = input;
893 hdr.cbSrcLength = sizeof(input);
894 hdr.pbDst = pcm;
895 hdr.cbDstLength = sizeof(pcm);
897 mr = acmStreamPrepareHeader(has, &hdr, 0);
898 ok(mr == MMSYSERR_NOERROR, "prepare failed: 0x%x\n", mr);
899 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_PREPARED, "header wasn't prepared: 0x%lx\n", hdr.fdwStatus);
901 mr = acmStreamUnprepareHeader(has, &hdr, 0);
902 ok(mr == MMSYSERR_NOERROR, "unprepare failed: 0x%x\n", mr);
903 ok(hdr.fdwStatus == 0, "header wasn't unprepared: 0x%lx\n", hdr.fdwStatus);
905 memset(&hdr, 0, sizeof(hdr));
906 hdr.cbStruct = sizeof(hdr);
907 hdr.pbSrc = input;
908 hdr.cbSrcLength = 0; /* invalid source length */
909 hdr.pbDst = pcm;
910 hdr.cbDstLength = sizeof(pcm);
912 mr = acmStreamPrepareHeader(has, &hdr, 0);
913 ok(mr == MMSYSERR_INVALPARAM, "expected 0x0b, got 0x%x\n", mr);
915 hdr.cbSrcLength = src->wfx.nBlockAlign - 1; /* less than block align */
916 mr = acmStreamPrepareHeader(has, &hdr, 0);
917 ok(mr == ACMERR_NOTPOSSIBLE, "expected 0x200, got 0x%x\n", mr);
919 hdr.cbSrcLength = src->wfx.nBlockAlign + 1; /* more than block align */
920 mr = acmStreamPrepareHeader(has, &hdr, 0);
921 ok(mr == MMSYSERR_NOERROR, "prepare failed: 0x%x\n", mr);
923 mr = acmStreamUnprepareHeader(has, &hdr, 0);
924 ok(mr == MMSYSERR_NOERROR, "unprepare failed: 0x%x\n", mr);
926 hdr.cbSrcLength = src->wfx.nBlockAlign;
927 mr = acmStreamPrepareHeader(has, &hdr, 1); /* invalid use of reserved parameter */
928 ok(mr == MMSYSERR_INVALFLAG, "expected 0x0a, got 0x%x\n", mr);
930 mr = acmStreamPrepareHeader(has, &hdr, 0);
931 ok(mr == MMSYSERR_NOERROR, "prepare failed: 0x%x\n", mr);
933 mr = acmStreamUnprepareHeader(has, &hdr, 0);
934 ok(mr == MMSYSERR_NOERROR, "unprepare failed: 0x%x\n", mr);
936 memset(&hdr, 0, sizeof(hdr));
937 hdr.cbStruct = sizeof(hdr);
938 hdr.pbSrc = input;
939 hdr.cbSrcLength = sizeof(input);
940 hdr.pbDst = pcm;
941 hdr.cbDstLength = sizeof(pcm);
942 hdr.fdwStatus = ACMSTREAMHEADER_STATUSF_DONE;
944 mr = acmStreamPrepareHeader(has, &hdr, 0);
945 ok(mr == MMSYSERR_NOERROR, "prepare failed: 0x%x\n", mr);
946 ok(hdr.fdwStatus == (ACMSTREAMHEADER_STATUSF_PREPARED | ACMSTREAMHEADER_STATUSF_DONE), "header wasn't prepared: 0x%lx\n", hdr.fdwStatus);
948 hdr.cbSrcLengthUsed = 12345;
949 hdr.cbDstLengthUsed = 12345;
950 hdr.fdwStatus &= ~ACMSTREAMHEADER_STATUSF_DONE;
951 mr = acmStreamConvert(has, &hdr, ACM_STREAMCONVERTF_BLOCKALIGN);
952 ok(mr == MMSYSERR_NOERROR, "convert failed: 0x%x\n", mr);
953 ok(hdr.fdwStatus & ACMSTREAMHEADER_STATUSF_DONE, "conversion was not done: 0x%lx\n", hdr.fdwStatus);
954 ok(hdr.cbSrcLengthUsed == hdr.cbSrcLength, "expected %ld, got %ld\n", hdr.cbSrcLength, hdr.cbSrcLengthUsed);
955 todo_wine
956 ok(hdr.cbDstLengthUsed == 1010, "expected 1010, got %ld\n", hdr.cbDstLengthUsed);
958 mr = acmStreamUnprepareHeader(has, &hdr, 0);
959 ok(mr == MMSYSERR_NOERROR, "unprepare failed: 0x%x\n", mr);
960 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_DONE, "header wasn't unprepared: 0x%lx\n", hdr.fdwStatus);
962 /* The 2 next tests are related to Lost Horizon (bug 24723) */
963 memset(&hdr, 0, sizeof(hdr));
964 hdr.cbStruct = sizeof(hdr);
965 hdr.pbSrc = input;
966 hdr.cbSrcLength = sizeof(input);
967 hdr.pbDst = pcm;
968 hdr.cbDstLength = -4;
970 mr = acmStreamPrepareHeader(has, &hdr, 0);
971 if (sizeof(void *) == 4) /* 64 bit fails on this test */
973 ok(mr == MMSYSERR_NOERROR, "prepare failed: 0x%x\n", mr);
974 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_PREPARED, "header wasn't prepared: 0x%lx\n", hdr.fdwStatus);
976 hdr.cbSrcLengthUsed = 12345;
977 hdr.cbDstLengthUsed = 12345;
978 hdr.fdwStatus &= ~ACMSTREAMHEADER_STATUSF_DONE;
979 mr = acmStreamConvert(has, &hdr, ACM_STREAMCONVERTF_BLOCKALIGN);
980 ok(mr == MMSYSERR_NOERROR, "convert failed: 0x%x\n", mr);
981 ok(hdr.fdwStatus & ACMSTREAMHEADER_STATUSF_DONE, "conversion was not done: 0x%lx\n", hdr.fdwStatus);
982 ok(hdr.cbSrcLengthUsed == hdr.cbSrcLength, "expected %ld, got %ld\n", hdr.cbSrcLength, hdr.cbSrcLengthUsed);
983 todo_wine
984 ok(hdr.cbDstLengthUsed == 1010, "expected 1010, got %ld\n", hdr.cbDstLengthUsed);
986 mr = acmStreamUnprepareHeader(has, &hdr, 0);
987 ok(mr == MMSYSERR_NOERROR, "unprepare failed: 0x%x\n", mr);
988 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_DONE, "header wasn't unprepared: 0x%lx\n", hdr.fdwStatus);
990 else
991 todo_wine
992 ok(mr == MMSYSERR_INVALPARAM, "expected 0x0b, got 0x%x\n", mr);
994 memset(&hdr, 0, sizeof(hdr));
995 hdr.cbStruct = sizeof(hdr);
996 hdr.pbSrc = input;
997 hdr.cbSrcLength = 24;
998 hdr.pbDst = pcm;
999 hdr.cbDstLength = -4;
1000 mr = acmStreamPrepareHeader(has, &hdr, 0);
1001 ok(mr == ACMERR_NOTPOSSIBLE, "expected 0x200, got 0x%x\n", mr);
1002 ok(hdr.fdwStatus == 0, "expected 0, got 0x%lx\n", hdr.fdwStatus);
1004 hdr.cbSrcLengthUsed = 12345;
1005 hdr.cbDstLengthUsed = 12345;
1006 mr = acmStreamConvert(has, &hdr, ACM_STREAMCONVERTF_BLOCKALIGN);
1007 ok(mr == ACMERR_UNPREPARED, "expected 0x202, got 0x%x\n", mr);
1008 ok(hdr.cbSrcLengthUsed == 12345, "expected 12345, got %ld\n", hdr.cbSrcLengthUsed);
1009 ok(hdr.cbDstLengthUsed == 12345, "expected 12345, got %ld\n", hdr.cbDstLengthUsed);
1011 mr = acmStreamUnprepareHeader(has, &hdr, 0);
1012 ok(mr == ACMERR_UNPREPARED, "expected 0x202, got 0x%x\n", mr);
1014 /* Less output space than required */
1015 memset(&hdr, 0, sizeof(hdr));
1016 hdr.cbStruct = sizeof(hdr);
1017 hdr.pbSrc = input;
1018 hdr.cbSrcLength = sizeof(input);
1019 hdr.pbDst = pcm;
1020 hdr.cbDstLength = 32;
1022 mr = acmStreamPrepareHeader(has, &hdr, 0);
1023 ok(mr == MMSYSERR_NOERROR, "prepare failed: 0x%x\n", mr);
1024 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_PREPARED, "header wasn't prepared: 0x%lx\n", hdr.fdwStatus);
1026 hdr.cbSrcLengthUsed = 12345;
1027 hdr.cbDstLengthUsed = 12345;
1028 hdr.fdwStatus &= ~ACMSTREAMHEADER_STATUSF_DONE;
1029 mr = acmStreamConvert(has, &hdr, ACM_STREAMCONVERTF_BLOCKALIGN);
1030 ok(mr == MMSYSERR_NOERROR, "convert failed: 0x%x\n", mr);
1031 ok(hdr.fdwStatus & ACMSTREAMHEADER_STATUSF_DONE, "conversion was not done: 0x%lx\n", hdr.fdwStatus);
1032 todo_wine
1033 ok(hdr.cbSrcLengthUsed == hdr.cbSrcLength, "expected %ld, got %ld\n", hdr.cbSrcLength, hdr.cbSrcLengthUsed);
1034 todo_wine
1035 ok(hdr.cbDstLengthUsed == hdr.cbDstLength, "expected %ld, got %ld\n", hdr.cbDstLength, hdr.cbDstLengthUsed);
1037 mr = acmStreamUnprepareHeader(has, &hdr, 0);
1038 ok(mr == MMSYSERR_NOERROR, "unprepare failed: 0x%x\n", mr);
1039 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_DONE, "header wasn't unprepared: 0x%lx\n", hdr.fdwStatus);
1041 mr = acmStreamClose(has, 0);
1042 ok(mr == MMSYSERR_NOERROR, "close failed: 0x%x\n", mr);
1045 static const BYTE input[64] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63};
1047 struct stream_output
1049 WAVEFORMATEX src;
1050 WAVEFORMATEX dst;
1051 BYTE output[256];
1052 DWORD dst_used;
1053 BOOL todo;
1056 static const struct stream_output expected_output[] = {
1057 /* #0: Identical conversion */
1058 {{WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}, 64, FALSE},
1059 {{WAVE_FORMAT_PCM, 1, 44100, 88200, 2, 16}, {WAVE_FORMAT_PCM, 1, 44100, 88200, 2, 16}, {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}, 64, FALSE},
1061 /* #1: 1 -> 2 channels */
1062 {{WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {WAVE_FORMAT_PCM, 2, 8000, 16000, 2, 8}, {0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63}, 128, FALSE},
1064 /* #2: 2 -> 1 channels: all of the audio underflows due to addition */
1065 {{WAVE_FORMAT_PCM, 2, 8000, 16000, 2, 8}, {WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 32, FALSE},
1067 /* #3: 2 -> 2 channels */
1068 {{WAVE_FORMAT_PCM, 2, 8000, 16000, 2, 8}, {WAVE_FORMAT_PCM, 2, 8000, 16000, 2, 8}, {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63}, 64, FALSE},
1070 /* #4: 8 -> 16 bits per sample */
1071 {{WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {WAVE_FORMAT_PCM, 1, 8000, 16000, 2, 16}, {0,128,0,129,0,130,0,131,0,132,0,133,0,134,0,135,0,136,0,137,0,138,0,139,0,140,0,141,0,142,0,143,0,144,0,145,0,146,0,147,0,148,0,149,0,150,0,151,0,152,0,153,0,154,0,155,0,156,0,157,0,158,0,159,0,160,0,161,0,162,0,163,0,164,0,165,0,166,0,167,0,168,0,169,0,170,0,171,0,172,0,173,0,174,0,175,0,176,0,177,0,178,0,179,0,180,0,181,0,182,0,183,0,184,0,185,0,186,0,187,0,188,0,189,0,190,0,191}, 128, FALSE},
1073 /* #5: 16 -> 8 bits per sample */
1074 {{WAVE_FORMAT_PCM, 1, 8000, 16000, 2, 16}, {WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,185,187,189,191}, 32, FALSE},
1076 /* #6: 16 bits per sample, 2 -> 1 channels */
1077 {{WAVE_FORMAT_PCM, 2, 8000, 32000, 4, 16}, {WAVE_FORMAT_PCM, 1, 8000, 16000, 2, 16}, {2,4,10,12,18,20,26,28,34,36,42,44,50,52,58,60,66,68,74,76,82,84,90,92,98,100,106,108,114,116,122,124}, 32, FALSE},
1079 /* #7: 8000 -> 11025 sample rate */
1080 /* FIXME: upsampling is slightly off on wine - the algorithm is wrong whenever error > (srcrate + dstrate) / 2 */
1081 {{WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {WAVE_FORMAT_PCM, 1, 11025, 11025, 1, 8}, {0,1,1,2,3,4,4,5,6,7,7,8,9,9,10,11,12,12,13,14,15,15,16,17,17,18,19,20,20,21,22,22,23,24,25,25,26,27,28,28,29,30,30,31,32,33,33,34,35,36,36,37,38,38,39,40,41,41,42,43,44,44,45,46,46,47,48,49,49,50,51,52,52,53,54,54,55,56,57,57,58,59,60,60,61,62,62,63}, 88, TRUE},
1083 /* #8: 8000 -> 22050 sample rate */
1084 {{WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {WAVE_FORMAT_PCM, 1, 22050, 22050, 1, 8}, {0,0,1,1,1,2,2,3,3,3,4,4,4,5,5,5,6,6,7,7,7,8,8,8,9,9,9,10,10,11,11,11,12,12,12,13,13,13,14,14,15,15,15,16,16,16,17,17,17,18,18,19,19,19,20,20,20,21,21,21,22,22,22,23,23,24,24,24,25,25,25,26,26,26,27,27,28,28,28,29,29,29,30,30,30,31,31,32,32,32,33,33,33,34,34,34,35,35,36,36,36,37,37,37,38,38,38,39,39,40,40,40,41,41,41,42,42,42,43,43,44,44,44,45,45,45,46,46,46,47,47,48,48,48,49,49,49,50,50,50,51,51,52,52,52,53,53,53,54,54,54,55,55,56,56,56,57,57,57,58,58,58,59,59,60,60,60,61,61,61,62,62,62,63,63,63}, 176, TRUE},
1086 /* #9: 11025 -> 22050 sample rate */
1087 {{WAVE_FORMAT_PCM, 1, 11025, 11025, 1, 8}, {WAVE_FORMAT_PCM, 1, 22050, 22050, 1, 8}, {0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,30,30,31,31,32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,45,46,46,47,47,48,48,49,49,50,50,51,51,52,52,53,53,54,54,55,55,56,56,57,57,58,58,59,59,60,60,61,61,62,62,63,63}, 128, FALSE},
1089 /* #10: 22050 -> 11025 sample rate */
1090 {{WAVE_FORMAT_PCM, 1, 22050, 22050, 1, 8}, {WAVE_FORMAT_PCM, 1, 11025, 11025, 1, 8}, {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63}, 32, FALSE},
1092 /* #11: 11025 -> 8000 sample rate */
1093 {{WAVE_FORMAT_PCM, 1, 11025, 11025, 1, 8}, {WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {0,2,3,4,6,7,8,10,11,13,14,15,17,18,19,21,22,24,25,26,28,29,31,32,33,35,36,37,39,40,42,43,44,46,47,48,50,51,53,54,55,57,58,59,61,62}, 46, FALSE},
1095 /* #12: 22050 -> 8000 sample rate */
1096 {{WAVE_FORMAT_PCM, 1, 22050, 22050, 1, 8}, {WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {1,4,6,9,12,15,17,20,23,26,28,31,34,37,39,42,45,48,50,53,56,59,62}, 23, FALSE},
1098 /* #13: 44100 -> 8000 sample rate */
1099 {{WAVE_FORMAT_PCM, 1, 44100, 44100, 1, 8}, {WAVE_FORMAT_PCM, 1, 8000, 8000, 1, 8}, {2,8,13,19,24,30,35,41,46,52,57,63}, 12, FALSE},
1102 static void test_convert(void)
1104 HACMSTREAM has;
1105 ACMSTREAMHEADER hdr = {0};
1106 BYTE output[256];
1107 MMRESULT mmr;
1108 unsigned i;
1110 for (i = 0; i < ARRAY_SIZE(expected_output); i++)
1112 mmr = acmStreamOpen(&has, NULL, (WAVEFORMATEX *)&expected_output[i].src, (WAVEFORMATEX *)&expected_output[i].dst, NULL, 0, 0, 0);
1113 ok(mmr == MMSYSERR_NOERROR, "#%d: open failed: 0x%x\n", i, mmr);
1115 memset(&hdr, 0, sizeof(hdr));
1116 hdr.cbStruct = sizeof(hdr);
1117 hdr.pbSrc = (BYTE *)input;
1118 hdr.cbSrcLength = sizeof(input);
1119 hdr.pbDst = output;
1120 hdr.cbDstLength = sizeof(output);
1122 mmr = acmStreamPrepareHeader(has, &hdr, 0);
1123 ok(mmr == MMSYSERR_NOERROR, "#%d: prepare failed: 0x%x\n", i, mmr);
1124 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_PREPARED, "#%d: header wasn't prepared: 0x%lx\n", i, hdr.fdwStatus);
1126 memset(&output, 0, sizeof(output));
1127 mmr = acmStreamConvert(has, &hdr, ACM_STREAMCONVERTF_BLOCKALIGN);
1128 ok(mmr == MMSYSERR_NOERROR, "#%d: convert failed: 0x%x\n", i, mmr);
1129 ok(hdr.fdwStatus & ACMSTREAMHEADER_STATUSF_DONE, "#%d: conversion was not done: 0x%lx\n", i, hdr.fdwStatus);
1130 ok(hdr.cbSrcLengthUsed == hdr.cbSrcLength, "#%d: expected %ld, got %ld\n", i, hdr.cbSrcLength, hdr.cbSrcLengthUsed);
1131 ok(hdr.cbDstLengthUsed == expected_output[i].dst_used, "#%d: expected %ld, got %ld\n", i, expected_output[i].dst_used, hdr.cbDstLengthUsed);
1132 todo_wine_if(expected_output[i].todo)
1133 ok(!memcmp(expected_output[i].output, output, hdr.cbDstLengthUsed), "#%d: output does not match\n", i);
1135 mmr = acmStreamUnprepareHeader(has, &hdr, 0);
1136 ok(mmr == MMSYSERR_NOERROR, "#%d: unprepare failed: 0x%x\n", i, mmr);
1137 ok(hdr.fdwStatus == ACMSTREAMHEADER_STATUSF_DONE, "#%d: header wasn't unprepared: 0x%lx\n", i, hdr.fdwStatus);
1139 mmr = acmStreamClose(has, 0);
1140 ok(mmr == MMSYSERR_NOERROR, "#%d: close failed: 0x%x\n", i, mmr);
1144 static void test_acmFormatSuggest(void)
1146 WAVEFORMATEX src, dst;
1147 DWORD suggest;
1148 MMRESULT rc;
1149 DWORD sizeMax;
1151 acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT, &sizeMax);
1153 /* Test a valid PCM format */
1154 src.wFormatTag = WAVE_FORMAT_PCM;
1155 src.nChannels = 1;
1156 src.nSamplesPerSec = 8000;
1157 src.nAvgBytesPerSec = 16000;
1158 src.nBlockAlign = 2;
1159 src.wBitsPerSample = 16;
1160 src.cbSize = 0;
1161 suggest = 0;
1162 memset(&dst, 0, sizeof(dst));
1163 rc = acmFormatSuggest(NULL, &src, &dst, sizeof(PCMWAVEFORMAT), suggest);
1164 ok(rc == MMSYSERR_NOERROR, "failed with error 0x%x\n", rc);
1165 ok(src.wFormatTag == dst.wFormatTag, "expected %d, got %d\n", src.wFormatTag, dst.wFormatTag);
1166 ok(src.nChannels == dst.nChannels, "expected %d, got %d\n", src.nChannels, dst.nChannels);
1167 ok(src.nSamplesPerSec == dst.nSamplesPerSec, "expected %ld, got %ld\n", src.nSamplesPerSec, dst.nSamplesPerSec);
1168 ok(src.nAvgBytesPerSec == dst.nAvgBytesPerSec, "expected %ld, got %ld\n", src.nAvgBytesPerSec, dst.nAvgBytesPerSec);
1169 ok(src.nBlockAlign == dst.nBlockAlign, "expected %d, got %d\n", src.nBlockAlign, dst.nBlockAlign);
1170 ok(src.wBitsPerSample == dst.wBitsPerSample, "expected %d, got %d\n", src.wBitsPerSample, dst.wBitsPerSample);
1172 /* All parameters from destination are valid */
1173 suggest = ACM_FORMATSUGGESTF_NCHANNELS
1174 | ACM_FORMATSUGGESTF_NSAMPLESPERSEC
1175 | ACM_FORMATSUGGESTF_WBITSPERSAMPLE
1176 | ACM_FORMATSUGGESTF_WFORMATTAG;
1177 dst = src;
1178 rc = acmFormatSuggest(NULL, &src, &dst, sizeof(PCMWAVEFORMAT), suggest);
1179 ok(rc == MMSYSERR_NOERROR, "failed with error 0x%x\n", rc);
1180 ok(src.wFormatTag == dst.wFormatTag, "expected %d, got %d\n", src.wFormatTag, dst.wFormatTag);
1181 ok(src.nChannels == dst.nChannels, "expected %d, got %d\n", src.nChannels, dst.nChannels);
1182 ok(src.nSamplesPerSec == dst.nSamplesPerSec, "expected %ld, got %ld\n", src.nSamplesPerSec, dst.nSamplesPerSec);
1183 ok(src.nAvgBytesPerSec == dst.nAvgBytesPerSec, "expected %ld, got %ld\n", src.nAvgBytesPerSec, dst.nAvgBytesPerSec);
1184 ok(src.nBlockAlign == dst.nBlockAlign, "expected %d, got %d\n", src.nBlockAlign, dst.nBlockAlign);
1185 ok(src.wBitsPerSample == dst.wBitsPerSample, "expected %d, got %d\n", src.wBitsPerSample, dst.wBitsPerSample);
1187 /* Test an invalid PCM format */
1188 ZeroMemory(&dst, sizeof(dst));
1189 src.nSamplesPerSec = 0xdeadbeef;
1190 suggest = 0;
1191 rc = acmFormatSuggest(NULL, &src, &dst, sizeMax, suggest);
1192 todo_wine {
1193 ok(rc == MMSYSERR_NOERROR, "failed with error 0x%x\n", rc);
1194 ok(dst.wFormatTag == WAVE_FORMAT_PCM, "expected %d, got %d\n", WAVE_FORMAT_PCM, dst.wFormatTag);
1195 ok(dst.nSamplesPerSec == 0xdeadbeef, "expected %d, got %ld\n", 0xdeadbeef, dst.nSamplesPerSec);
1197 src.nSamplesPerSec = 8000;
1199 /* Test a nonexistent format */
1200 src.wFormatTag = 0xbeef;
1201 rc = acmFormatSuggest(NULL, &src, &dst, sizeMax-1, suggest);
1202 ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
1204 rc = acmFormatSuggest(NULL, &src, &dst, sizeMax, suggest);
1205 todo_wine
1206 ok(rc == MMSYSERR_NODRIVER, "failed with error 0x%x\n", rc);
1208 /* Test converting between two known but incompatible formats */
1209 src.wFormatTag = WAVE_FORMAT_ALAW;
1210 src.nChannels = 1;
1211 src.nSamplesPerSec = 8000;
1212 src.nAvgBytesPerSec = 8000;
1213 src.nBlockAlign = 1;
1214 src.wBitsPerSample = 8;
1215 src.cbSize = 0;
1216 suggest = ACM_FORMATSUGGESTF_WFORMATTAG;
1217 dst.wFormatTag = WAVE_FORMAT_IMA_ADPCM;
1218 rc = acmFormatSuggest(NULL, &src, &dst, sizeof(IMAADPCMWAVEFORMAT)-1, suggest);
1219 ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
1221 rc = acmFormatSuggest(NULL, &src, &dst, sizeof(IMAADPCMWAVEFORMAT), suggest);
1222 todo_wine
1223 ok(rc == MMSYSERR_NODRIVER, "failed with error 0x%x\n", rc);
1225 /* Invalid suggest flags */
1226 src.wFormatTag = WAVE_FORMAT_PCM;
1227 suggest = 0xFFFFFFFF;
1228 rc = acmFormatSuggest(NULL, &src, &dst, sizeof(dst), suggest);
1229 ok(rc == MMSYSERR_INVALFLAG, "failed with error 0x%x\n", rc);
1231 /* Invalid source and destination */
1232 suggest = 0;
1233 rc = acmFormatSuggest(NULL, NULL, &dst, sizeof(dst), suggest);
1234 ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
1235 rc = acmFormatSuggest(NULL, &src, NULL, sizeof(dst), suggest);
1236 ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
1237 rc = acmFormatSuggest(NULL, NULL, NULL, sizeof(dst), suggest);
1238 ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
1241 static void test_acmFormatTagDetails(void)
1243 ACMFORMATTAGDETAILSW aftd = {0};
1244 MMRESULT rc;
1246 aftd.cbStruct = sizeof(aftd);
1247 aftd.dwFormatTag = WAVE_FORMAT_MPEGLAYER3;
1248 rc = acmFormatTagDetailsW(NULL, &aftd, ACM_FORMATTAGDETAILSF_FORMATTAG);
1249 if (rc == MMSYSERR_NOERROR)
1250 ok(aftd.cbFormatSize == sizeof(MPEGLAYER3WAVEFORMAT), "got %ld\n", aftd.cbFormatSize);
1253 static void test_acmFormatChoose(void)
1255 ACMFORMATCHOOSEW afc = {0};
1256 WAVEFORMATEX *pwfx;
1257 DWORD sizeMax;
1258 MMRESULT rc;
1260 acmMetrics(NULL, ACM_METRIC_MAX_SIZE_FORMAT, &sizeMax);
1261 pwfx = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeMax);
1263 afc.cbStruct = sizeof(afc);
1264 afc.pwfx = pwfx;
1266 /* test invalid struct size */
1267 afc.cbStruct = sizeof(afc)-1;
1268 rc = acmFormatChooseW(&afc);
1269 ok(rc == MMSYSERR_INVALPARAM, "expected 0xb, got 0x%x\n", rc);
1270 afc.cbStruct = sizeof(afc);
1272 afc.pwfx = NULL;
1273 rc = acmFormatChooseW(&afc);
1274 ok(rc == MMSYSERR_INVALPARAM, "expected 0xb, got 0x%x\n", rc);
1275 afc.pwfx = pwfx;
1277 HeapFree(GetProcessHeap(), 0, pwfx);
1280 static void test_mp3(void)
1282 MPEGLAYER3WAVEFORMAT src;
1283 WAVEFORMATEX dst;
1284 HACMSTREAM has;
1285 DWORD output;
1286 MMRESULT mr;
1288 src.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
1289 src.wfx.nSamplesPerSec = 11025;
1290 src.wfx.wBitsPerSample = 0;
1291 src.wfx.nChannels = 1;
1292 src.wfx.nBlockAlign = 576;
1293 src.wfx.nAvgBytesPerSec = 2000;
1295 src.wID = MPEGLAYER3_ID_MPEG;
1296 src.fdwFlags = 0;
1297 src.nBlockSize = 576;
1298 src.nFramesPerBlock = 1;
1299 src.nCodecDelay = 0;
1301 dst.cbSize = 0;
1302 dst.wFormatTag = WAVE_FORMAT_PCM;
1303 dst.nSamplesPerSec = 11025;
1304 dst.wBitsPerSample = 16;
1305 dst.nChannels = 1;
1306 dst.nBlockAlign = dst.wBitsPerSample * dst.nChannels / 8;
1307 dst.nAvgBytesPerSec = dst.nSamplesPerSec * dst.nBlockAlign;
1309 src.wfx.cbSize = 0;
1311 mr = acmStreamOpen(&has, NULL, (WAVEFORMATEX*)&src, &dst, NULL, 0, 0, 0);
1312 ok(mr == ACMERR_NOTPOSSIBLE, "expected error ACMERR_NOTPOSSIBLE, got 0x%x\n", mr);
1313 if (mr == MMSYSERR_NOERROR) acmStreamClose(has, 0);
1315 src.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
1316 src.wID = 0;
1318 mr = acmStreamOpen(&has, NULL, (WAVEFORMATEX*)&src, &dst, NULL, 0, 0, 0);
1319 ok(mr == ACMERR_NOTPOSSIBLE, "expected error ACMERR_NOTPOSSIBLE, got 0x%x\n", mr);
1320 if (mr == MMSYSERR_NOERROR) acmStreamClose(has, 0);
1322 src.wID = MPEGLAYER3_ID_MPEG;
1323 src.nBlockSize = 0;
1325 mr = acmStreamOpen(&has, NULL, (WAVEFORMATEX*)&src, &dst, NULL, 0, 0, 0);
1326 ok(mr == MMSYSERR_NOERROR || broken(mr == ACMERR_NOTPOSSIBLE) /* Win 2008 */,
1327 "failed with error 0x%x\n", mr);
1328 if (mr == MMSYSERR_NOERROR)
1330 mr = acmStreamClose(has, 0);
1331 ok(mr == MMSYSERR_NOERROR, "failed with error 0x%x\n", mr);
1333 src.nBlockSize = 576;
1334 src.wfx.nAvgBytesPerSec = 0;
1336 mr = acmStreamOpen(&has, NULL, (WAVEFORMATEX*)&src, &dst, NULL, 0, 0, 0);
1337 ok(mr == MMSYSERR_NOERROR || broken(mr == ACMERR_NOTPOSSIBLE) /* Win 2008 */,
1338 "failed with error 0x%x\n", mr);
1339 if (mr == MMSYSERR_NOERROR)
1341 /* causes a division by zero exception in XP, Vista,
1342 but throws ACMERR_NOTPOSSIBLE on others */
1343 if (0) acmStreamSize(has, 4000, &output, ACM_STREAMSIZEF_SOURCE);
1344 mr = acmStreamClose(has, 0);
1345 ok(mr == MMSYSERR_NOERROR, "failed with error 0x%x\n", mr);
1348 src.wfx.nAvgBytesPerSec = 2000;
1350 mr = acmStreamOpen(&has, NULL, (WAVEFORMATEX*)&src, &dst, NULL, 0, 0, 0);
1351 ok(mr == MMSYSERR_NOERROR || broken(mr == ACMERR_NOTPOSSIBLE) /* Win 2008 */,
1352 "failed with error 0x%x\n", mr);
1353 if (mr == MMSYSERR_NOERROR)
1355 mr = acmStreamSize(has, 4000, &output, ACM_STREAMSIZEF_SOURCE);
1356 ok(mr == MMSYSERR_NOERROR, "failed with error 0x%x\n", mr);
1357 mr = acmStreamClose(has, 0);
1358 ok(mr == MMSYSERR_NOERROR, "failed with error 0x%x\n", mr);
1362 static struct
1364 struct
1366 int load, free, open, close, enable, disable, install,
1367 remove, details, notify, querycfg, about;
1368 } driver;
1369 struct
1371 int tag_details, details, suggest;
1372 } format;
1373 struct
1375 int open, close, size, convert, prepare, unprepare, reset;
1376 } stream;
1377 int other;
1378 } driver_calls;
1380 static LRESULT CALLBACK acm_driver_func(DWORD_PTR id, HDRVR handle, UINT msg, LPARAM param1, LPARAM param2)
1382 switch (msg)
1384 /* Driver messages */
1385 case DRV_LOAD:
1386 driver_calls.driver.load++;
1387 return 1;
1388 case DRV_FREE:
1389 driver_calls.driver.free++;
1390 return 1;
1391 case DRV_OPEN:
1392 driver_calls.driver.open++;
1393 return 1;
1394 case DRV_CLOSE:
1395 driver_calls.driver.close++;
1396 return 1;
1397 case DRV_ENABLE:
1398 driver_calls.driver.enable++;
1399 return 1;
1400 case DRV_DISABLE:
1401 driver_calls.driver.disable++;
1402 return 1;
1403 case DRV_QUERYCONFIGURE:
1404 driver_calls.driver.querycfg++;
1405 return 1;
1406 case DRV_INSTALL:
1407 driver_calls.driver.install++;
1408 return DRVCNF_RESTART;
1409 case DRV_REMOVE:
1410 driver_calls.driver.remove++;
1411 return DRVCNF_RESTART;
1412 case ACMDM_DRIVER_ABOUT:
1413 driver_calls.driver.about++;
1414 return MMSYSERR_NOTSUPPORTED;
1415 case ACMDM_DRIVER_DETAILS:
1417 ACMDRIVERDETAILSA *ptr = (ACMDRIVERDETAILSA *)param1;
1419 /* copied from pcmconverter.c */
1420 ptr->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
1421 ptr->fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
1422 ptr->wMid = MM_MICROSOFT;
1423 ptr->wPid = MM_MSFT_ACM_PCM;
1424 ptr->vdwACM = 0x01000000;
1425 ptr->vdwDriver = 0x01000000;
1426 ptr->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
1427 ptr->cFormatTags = 1;
1428 ptr->cFilterTags = 0;
1429 ptr->hicon = NULL;
1430 strcpy(ptr->szShortName, "TEST-CODEC");
1431 strcpy(ptr->szLongName, "Wine Test Codec");
1432 strcpy(ptr->szCopyright, "Brought to you by the Wine team...");
1433 strcpy(ptr->szLicensing, "Refer to LICENSE file");
1434 ptr->szFeatures[0] = 0;
1436 driver_calls.driver.details++;
1437 break;
1439 case ACMDM_DRIVER_NOTIFY:
1440 driver_calls.driver.notify++;
1441 return MMSYSERR_NOTSUPPORTED;
1443 /* Format messages */
1444 case ACMDM_FORMATTAG_DETAILS:
1445 driver_calls.format.tag_details++;
1446 break;
1447 case ACMDM_FORMAT_DETAILS:
1448 driver_calls.format.details++;
1449 break;
1450 case ACMDM_FORMAT_SUGGEST:
1451 driver_calls.format.suggest++;
1452 break;
1454 /* Stream messages */
1455 case ACMDM_STREAM_OPEN:
1456 driver_calls.stream.open++;
1457 break;
1458 case ACMDM_STREAM_CLOSE:
1459 driver_calls.stream.close++;
1460 break;
1461 case ACMDM_STREAM_SIZE:
1462 driver_calls.stream.size++;
1463 break;
1464 case ACMDM_STREAM_CONVERT:
1465 driver_calls.stream.convert++;
1466 break;
1467 case ACMDM_STREAM_RESET:
1468 driver_calls.stream.reset++;
1469 return MMSYSERR_NOTSUPPORTED;
1470 case ACMDM_STREAM_PREPARE:
1471 driver_calls.stream.prepare++;
1472 break;
1473 case ACMDM_STREAM_UNPREPARE:
1474 driver_calls.stream.unprepare++;
1475 break;
1477 default:
1478 driver_calls.other++;
1479 return DefDriverProc(id, handle, msg, param1, param2);
1481 return MMSYSERR_NOERROR;
1484 static void test_acmDriverAdd(void)
1486 MMRESULT res;
1487 HACMDRIVERID drvid;
1488 union
1490 ACMDRIVERDETAILSA drv_details;
1491 } acm;
1493 /* Driver load steps:
1494 * - acmDriverAdd checks the passed parameters
1495 * - DRV_LOAD message is sent - required
1496 * - DRV_ENABLE message is sent - required
1497 * - DRV_OPEN message is sent - required
1498 * - DRV_DETAILS message is sent - required
1499 * - ACMDM_FORMATTAG_DETAILS message is sent - optional
1500 * - DRV_QUERYCONFIGURE message is sent - optional
1501 * - ACMDM_DRIVER_ABOUT message is sent - optional
1504 res = acmDriverAddA(&drvid, GetModuleHandleA(NULL), (LPARAM)acm_driver_func, 0, ACM_DRIVERADDF_FUNCTION);
1505 ok(res == MMSYSERR_NOERROR, "Expected 0, got %d\n", res);
1506 todo_wine
1507 ok(driver_calls.driver.open == 1, "Expected 1, got %d\n", driver_calls.driver.open);
1508 ok(driver_calls.driver.details == 1, "Expected 1, got %d\n", driver_calls.driver.details);
1510 memset(&acm, 0, sizeof(acm));
1511 res = acmDriverDetailsA(drvid, &acm.drv_details, 0);
1512 ok(res == MMSYSERR_INVALPARAM, "Expected 11, got %d\n", res);
1514 acm.drv_details.cbStruct = sizeof(acm.drv_details);
1515 res = acmDriverDetailsA(drvid, &acm.drv_details, 0);
1516 ok(res == MMSYSERR_NOERROR, "Expected 0, got %d\n", res);
1517 todo_wine
1518 ok(driver_calls.driver.open == 1, "Expected 1, got %d\n", driver_calls.driver.open);
1519 ok(driver_calls.driver.details == 2, "Expected 2, got %d\n", driver_calls.driver.details);
1520 todo_wine
1521 ok(driver_calls.driver.close == 0, "Expected 0, got %d\n", driver_calls.driver.close);
1524 START_TEST(msacm)
1526 driver_tests();
1527 test_prepareheader();
1528 test_convert();
1529 test_acmFormatSuggest();
1530 test_acmFormatTagDetails();
1531 test_acmFormatChoose();
1532 test_mp3();
1533 /* Test acmDriverAdd in the end as it may conflict
1534 * with other tests due to codec lookup order */
1535 test_acmDriverAdd();