wininet: Fix behaviour of InternetTimeFromSystemTimeA/W when dealing with invalid...
[wine] / dlls / winemp3.acm / mpegl3.c
1 /*
2  * MPEG Layer 3 handling
3  *
4  *      Copyright (C) 2002              Eric Pouech
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "mmsystem.h"
31 #include "mmreg.h"
32 #include "msacm.h"
33 #include "msacmdrv.h"
34 #include "mpg123.h"
35 #include "mpglib.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(mpeg3);
40
41 /***********************************************************************
42  *           MPEG3_drvOpen
43  */
44 static LRESULT MPEG3_drvOpen(LPCSTR str)
45 {
46     return 1;
47 }
48
49 /***********************************************************************
50  *           MPEG3_drvClose
51  */
52 static LRESULT MPEG3_drvClose(DWORD_PTR dwDevID)
53 {
54     return 1;
55 }
56
57 typedef struct tagAcmMpeg3Data
58 {
59     void (*convert)(PACMDRVSTREAMINSTANCE adsi,
60                     const unsigned char*, LPDWORD, unsigned char*, LPDWORD);
61     struct mpstr mp;
62 } AcmMpeg3Data;
63
64 /* table to list all supported formats... those are the basic ones. this
65  * also helps given a unique index to each of the supported formats
66  */
67 typedef struct
68 {
69     int         nChannels;
70     int         nBits;
71     int         rate;
72 } Format;
73
74 static const Format PCM_Formats[] =
75 {
76     {1,  8,  8000}, {2,  8,  8000}, {1, 16,  8000}, {2, 16,  8000},
77     {1,  8, 11025}, {2,  8, 11025}, {1, 16, 11025}, {2, 16, 11025},
78     {1,  8, 22050}, {2,  8, 22050}, {1, 16, 22050}, {2, 16, 22050},
79     {1,  8, 44100}, {2,  8, 44100}, {1, 16, 44100}, {2, 16, 44100},
80     {1,  8, 48000}, {2,  8, 48000}, {1, 16, 48000}, {2, 16, 48000},
81 };
82
83 static const Format MPEG3_Formats[] =
84 {
85     {1,  0,  8000}, {2, 0,  8000},  {1,  0, 11025}, {2,  0, 11025},
86     {1,  0, 22050}, {2, 0, 22050},  {1,  0, 44100}, {2,  0, 44100},
87     {1,  0, 48000}, {2, 0, 48000},
88 };
89
90 #define NUM_PCM_FORMATS         (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
91 #define NUM_MPEG3_FORMATS       (sizeof(MPEG3_Formats) / sizeof(MPEG3_Formats[0]))
92
93 /***********************************************************************
94  *           MPEG3_GetFormatIndex
95  */
96 static  DWORD   MPEG3_GetFormatIndex(LPWAVEFORMATEX wfx)
97 {
98     int         i, hi;
99     const Format *fmts;
100
101     switch (wfx->wFormatTag)
102     {
103     case WAVE_FORMAT_PCM:
104         hi = NUM_PCM_FORMATS;
105         fmts = PCM_Formats;
106         break;
107     case WAVE_FORMAT_MPEGLAYER3:
108         hi = NUM_MPEG3_FORMATS;
109         fmts = MPEG3_Formats;
110         break;
111     default:
112         return 0xFFFFFFFF;
113     }
114
115     for (i = 0; i < hi; i++)
116     {
117         if (wfx->nChannels == fmts[i].nChannels &&
118             wfx->nSamplesPerSec == fmts[i].rate &&
119             (wfx->wBitsPerSample == fmts[i].nBits || !fmts[i].nBits))
120             return i;
121     }
122
123     return 0xFFFFFFFF;
124 }
125
126 static DWORD get_num_buffered_bytes(struct mpstr *mp)
127 {
128     DWORD numBuff = 0;
129     struct buf * p = mp->tail;
130     while (p) {
131         numBuff += p->size - p->pos;
132         p = p->next;
133     }
134     return numBuff;
135 }
136
137 static void mp3_horse(PACMDRVSTREAMINSTANCE adsi,
138                       const unsigned char* src, LPDWORD nsrc,
139                       unsigned char* dst, LPDWORD ndst)
140 {
141     AcmMpeg3Data*       amd = (AcmMpeg3Data*)adsi->dwDriver;
142     int                 size, ret;
143     DWORD               dpos = 0;
144     DWORD               buffered_before;
145     DWORD               buffered_during;
146     DWORD               buffered_after;
147
148     /* Skip leading ID v3 header */
149     if (amd->mp.fsizeold == -1 && !strncmp("ID3", (char*)src, 3))
150     {
151         UINT length = 10;
152         const char *header = (char *)src;
153
154         TRACE("Found ID3 v2.%d.%d\n", header[3], header[4]);
155         length += (header[6] & 0x7F) << 21;
156         length += (header[7] & 0x7F) << 14;
157         length += (header[8] & 0x7F) << 7;
158         length += (header[9] & 0x7F);
159         TRACE("Length: %u\n", length);
160         *nsrc = length;
161         *ndst = 0;
162         return;
163     }
164
165     buffered_before = get_num_buffered_bytes(&amd->mp);
166     ret = decodeMP3(&amd->mp, src, *nsrc, dst, *ndst, &size);
167     buffered_during = get_num_buffered_bytes(&amd->mp);
168     if (ret != MP3_OK)
169     {
170         if (ret == MP3_ERR)
171             FIXME("Error occurred during decoding!\n");
172         *ndst = *nsrc = 0;
173         return;
174     }
175     do {
176         dpos += size;
177         if (*ndst - dpos < 4608) break;
178         ret = decodeMP3(&amd->mp, NULL, 0,
179                         dst + dpos, *ndst - dpos, &size);
180     } while (ret == MP3_OK);
181     *ndst = dpos;
182
183     buffered_after = get_num_buffered_bytes(&amd->mp);
184     TRACE("before %d put %d during %d after %d\n", buffered_before, *nsrc, buffered_during, buffered_after);
185
186     *nsrc -= buffered_after;
187     ClearMP3Buffer(&amd->mp);
188 }
189
190 /***********************************************************************
191  *           MPEG3_DriverDetails
192  *
193  */
194 static  LRESULT MPEG3_DriverDetails(PACMDRIVERDETAILSW add)
195 {
196     add->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
197     add->fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
198     add->wMid = 0xFF;
199     add->wPid = 0x00;
200     add->vdwACM = 0x01000000;
201     add->vdwDriver = 0x01000000;
202     add->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
203     add->cFormatTags = 2; /* PCM, MPEG3 */
204     add->cFilterTags = 0;
205     add->hicon = NULL;
206     MultiByteToWideChar( CP_ACP, 0, "WINE-MPEG3", -1,
207                          add->szShortName, sizeof(add->szShortName)/sizeof(WCHAR) );
208     MultiByteToWideChar( CP_ACP, 0, "Wine MPEG3 decoder", -1,
209                          add->szLongName, sizeof(add->szLongName)/sizeof(WCHAR) );
210     MultiByteToWideChar( CP_ACP, 0, "Brought to you by the Wine team (based on mpglib by Michael Hipp)...", -1,
211                          add->szCopyright, sizeof(add->szCopyright)/sizeof(WCHAR) );
212     MultiByteToWideChar( CP_ACP, 0, "Refer to LICENSE file", -1,
213                          add->szLicensing, sizeof(add->szLicensing)/sizeof(WCHAR) );
214     add->szFeatures[0] = 0;
215
216     return MMSYSERR_NOERROR;
217 }
218
219 /***********************************************************************
220  *           MPEG3_FormatTagDetails
221  *
222  */
223 static  LRESULT MPEG3_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
224 {
225     static const WCHAR szPcm[]={'P','C','M',0};
226     static const WCHAR szMpeg3[]={'M','P','e','g','3',0};
227
228     switch (dwQuery)
229     {
230     case ACM_FORMATTAGDETAILSF_INDEX:
231         if (aftd->dwFormatTagIndex >= 2) return ACMERR_NOTPOSSIBLE;
232         break;
233     case ACM_FORMATTAGDETAILSF_LARGESTSIZE:
234         if (aftd->dwFormatTag == WAVE_FORMAT_UNKNOWN)
235         {
236             aftd->dwFormatTagIndex = 1; /* WAVE_FORMAT_MPEGLAYER3 is bigger than PCM */
237             break;
238         }
239         /* fall thru */
240     case ACM_FORMATTAGDETAILSF_FORMATTAG:
241         switch (aftd->dwFormatTag)
242         {
243         case WAVE_FORMAT_PCM:           aftd->dwFormatTagIndex = 0; break;
244         case WAVE_FORMAT_MPEGLAYER3:    aftd->dwFormatTagIndex = 1; break;
245         default:                        return ACMERR_NOTPOSSIBLE;
246         }
247         break;
248     default:
249         WARN("Unsupported query %08x\n", dwQuery);
250         return MMSYSERR_NOTSUPPORTED;
251     }
252
253     aftd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
254     switch (aftd->dwFormatTagIndex)
255     {
256     case 0:
257         aftd->dwFormatTag = WAVE_FORMAT_PCM;
258         aftd->cbFormatSize = sizeof(PCMWAVEFORMAT);
259         aftd->cStandardFormats = NUM_PCM_FORMATS;
260         lstrcpyW(aftd->szFormatTag, szPcm);
261         break;
262     case 1:
263         aftd->dwFormatTag = WAVE_FORMAT_MPEGLAYER3;
264         aftd->cbFormatSize = sizeof(MPEGLAYER3WAVEFORMAT);
265         aftd->cStandardFormats = NUM_MPEG3_FORMATS;
266         lstrcpyW(aftd->szFormatTag, szMpeg3);
267         break;
268     }
269     return MMSYSERR_NOERROR;
270 }
271
272 static void fill_in_wfx(unsigned cbwfx, WAVEFORMATEX* wfx, unsigned bit_rate)
273 {
274     MPEGLAYER3WAVEFORMAT*   mp3wfx = (MPEGLAYER3WAVEFORMAT*)wfx;
275
276     wfx->nAvgBytesPerSec = bit_rate / 8;
277     if (cbwfx >= sizeof(WAVEFORMATEX))
278         wfx->cbSize = sizeof(MPEGLAYER3WAVEFORMAT) - sizeof(WAVEFORMATEX);
279     if (cbwfx >= sizeof(MPEGLAYER3WAVEFORMAT))
280     {
281         mp3wfx->wID = MPEGLAYER3_ID_MPEG;
282         mp3wfx->fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF;
283         mp3wfx->nBlockSize = (bit_rate * 144) / wfx->nSamplesPerSec;
284         mp3wfx->nFramesPerBlock = 1;
285         mp3wfx->nCodecDelay = 0x0571;
286     }
287 }
288
289 /***********************************************************************
290  *           MPEG3_FormatDetails
291  *
292  */
293 static  LRESULT MPEG3_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
294 {
295     switch (dwQuery)
296     {
297     case ACM_FORMATDETAILSF_FORMAT:
298         if (MPEG3_GetFormatIndex(afd->pwfx) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
299         break;
300     case ACM_FORMATDETAILSF_INDEX:
301         afd->pwfx->wFormatTag = afd->dwFormatTag;
302         switch (afd->dwFormatTag)
303         {
304         case WAVE_FORMAT_PCM:
305             if (afd->dwFormatIndex >= NUM_PCM_FORMATS) return ACMERR_NOTPOSSIBLE;
306             afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels;
307             afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate;
308             afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits;
309             /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
310              * afd->pwfx->cbSize = 0;
311              */
312             afd->pwfx->nBlockAlign =
313                 (afd->pwfx->nChannels * afd->pwfx->wBitsPerSample) / 8;
314             afd->pwfx->nAvgBytesPerSec =
315                 afd->pwfx->nSamplesPerSec * afd->pwfx->nBlockAlign;
316             break;
317         case WAVE_FORMAT_MPEGLAYER3:
318             if (afd->dwFormatIndex >= NUM_MPEG3_FORMATS) return ACMERR_NOTPOSSIBLE;
319             afd->pwfx->nChannels = MPEG3_Formats[afd->dwFormatIndex].nChannels;
320             afd->pwfx->nSamplesPerSec = MPEG3_Formats[afd->dwFormatIndex].rate;
321             afd->pwfx->wBitsPerSample = MPEG3_Formats[afd->dwFormatIndex].nBits;
322             afd->pwfx->nBlockAlign = 1;
323             fill_in_wfx(afd->cbwfx, afd->pwfx, 192000);
324             break;
325         default:
326             WARN("Unsupported tag %08x\n", afd->dwFormatTag);
327             return MMSYSERR_INVALPARAM;
328         }
329         break;
330     default:
331         WARN("Unsupported query %08x\n", dwQuery);
332         return MMSYSERR_NOTSUPPORTED;
333     }
334     afd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
335     afd->szFormat[0] = 0; /* let MSACM format this for us... */
336
337     return MMSYSERR_NOERROR;
338 }
339
340 /***********************************************************************
341  *           MPEG3_FormatSuggest
342  *
343  */
344 static  LRESULT MPEG3_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
345 {
346     /* some tests ... */
347     if (adfs->cbwfxSrc < sizeof(PCMWAVEFORMAT) ||
348         adfs->cbwfxDst < sizeof(PCMWAVEFORMAT) ||
349         MPEG3_GetFormatIndex(adfs->pwfxSrc) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
350     /* FIXME: should do those tests against the real size (according to format tag */
351
352     /* If no suggestion for destination, then copy source value */
353     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NCHANNELS))
354         adfs->pwfxDst->nChannels = adfs->pwfxSrc->nChannels;
355     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NSAMPLESPERSEC))
356         adfs->pwfxDst->nSamplesPerSec = adfs->pwfxSrc->nSamplesPerSec;
357
358     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WBITSPERSAMPLE))
359     {
360         if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM)
361             adfs->pwfxDst->wBitsPerSample = 4;
362         else
363             adfs->pwfxDst->wBitsPerSample = 16;
364     }
365     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG))
366     {
367         if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM)
368             adfs->pwfxDst->wFormatTag = WAVE_FORMAT_MPEGLAYER3;
369         else
370             adfs->pwfxDst->wFormatTag = WAVE_FORMAT_PCM;
371     }
372
373     /* check if result is ok */
374     if (MPEG3_GetFormatIndex(adfs->pwfxDst) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
375
376     /* recompute other values */
377     switch (adfs->pwfxDst->wFormatTag)
378     {
379     case WAVE_FORMAT_PCM:
380         adfs->pwfxDst->nBlockAlign = (adfs->pwfxDst->nChannels * adfs->pwfxDst->wBitsPerSample) / 8;
381         adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign;
382         break;
383     case WAVE_FORMAT_MPEGLAYER3:
384         adfs->pwfxDst->nBlockAlign = 1;
385         fill_in_wfx(adfs->cbwfxDst, adfs->pwfxDst, 192000);
386         break;
387     default:
388         FIXME("\n");
389         break;
390     }
391
392     return MMSYSERR_NOERROR;
393 }
394
395 /***********************************************************************
396  *           MPEG3_Reset
397  *
398  */
399 static void MPEG3_Reset(PACMDRVSTREAMINSTANCE adsi, AcmMpeg3Data* aad)
400 {
401     ClearMP3Buffer(&aad->mp);
402     InitMP3(&aad->mp);
403 }
404
405 /***********************************************************************
406  *           MPEG3_StreamOpen
407  *
408  */
409 static  LRESULT MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
410 {
411     AcmMpeg3Data*       aad;
412
413     assert(!(adsi->fdwOpen & ACM_STREAMOPENF_ASYNC));
414
415     if (MPEG3_GetFormatIndex(adsi->pwfxSrc) == 0xFFFFFFFF ||
416         MPEG3_GetFormatIndex(adsi->pwfxDst) == 0xFFFFFFFF)
417         return ACMERR_NOTPOSSIBLE;
418
419     aad = HeapAlloc(GetProcessHeap(), 0, sizeof(AcmMpeg3Data));
420     if (aad == 0) return MMSYSERR_NOMEM;
421
422     adsi->dwDriver = (DWORD)aad;
423
424     if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
425         adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
426     {
427         goto theEnd;
428     }
429     else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3 &&
430              adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
431     {
432         /* resampling or mono <=> stereo not available
433          * MPEG3 algo only define 16 bit per sample output
434          */
435         if (adsi->pwfxSrc->nSamplesPerSec != adsi->pwfxDst->nSamplesPerSec ||
436             adsi->pwfxSrc->nChannels != adsi->pwfxDst->nChannels ||
437             adsi->pwfxDst->wBitsPerSample != 16)
438             goto theEnd;
439         aad->convert = mp3_horse;
440         InitMP3(&aad->mp);
441     }
442     /* no encoding yet
443     else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
444              adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3)
445     */
446     else goto theEnd;
447     MPEG3_Reset(adsi, aad);
448
449     return MMSYSERR_NOERROR;
450
451  theEnd:
452     HeapFree(GetProcessHeap(), 0, aad);
453     adsi->dwDriver = 0L;
454     return MMSYSERR_NOTSUPPORTED;
455 }
456
457 /***********************************************************************
458  *           MPEG3_StreamClose
459  *
460  */
461 static  LRESULT MPEG3_StreamClose(PACMDRVSTREAMINSTANCE adsi)
462 {
463     ClearMP3Buffer(&((AcmMpeg3Data*)adsi->dwDriver)->mp);
464     HeapFree(GetProcessHeap(), 0, (void*)adsi->dwDriver);
465     return MMSYSERR_NOERROR;
466 }
467
468 /***********************************************************************
469  *           MPEG3_StreamSize
470  *
471  */
472 static  LRESULT MPEG3_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE adss)
473 {
474     switch (adss->fdwSize)
475     {
476     case ACM_STREAMSIZEF_DESTINATION:
477         /* cbDstLength => cbSrcLength */
478         if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
479             adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3)
480         {
481             /* don't take block overhead into account, doesn't matter too much */
482             adss->cbSrcLength = adss->cbDstLength * 12;
483         }
484         else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3 &&
485                  adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
486         {
487             FIXME("misses the block header overhead\n");
488             adss->cbSrcLength = 256 + adss->cbDstLength / 12;
489         }
490         else
491         {
492             return MMSYSERR_NOTSUPPORTED;
493         }
494         break;
495     case ACM_STREAMSIZEF_SOURCE:
496         /* cbSrcLength => cbDstLength */
497         if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
498             adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3)
499         {
500             FIXME("misses the block header overhead\n");
501             adss->cbDstLength = 256 + adss->cbSrcLength / 12;
502         }
503         else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3 &&
504                  adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
505         {
506             /* don't take block overhead into account, doesn't matter too much */
507             adss->cbDstLength = adss->cbSrcLength * 12;
508         }
509         else
510         {
511             return MMSYSERR_NOTSUPPORTED;
512         }
513         break;
514     default:
515         WARN("Unsupported query %08x\n", adss->fdwSize);
516         return MMSYSERR_NOTSUPPORTED;
517     }
518     return MMSYSERR_NOERROR;
519 }
520
521 /***********************************************************************
522  *           MPEG3_StreamConvert
523  *
524  */
525 static LRESULT MPEG3_StreamConvert(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMHEADER adsh)
526 {
527     AcmMpeg3Data*       aad = (AcmMpeg3Data*)adsi->dwDriver;
528     DWORD               nsrc = adsh->cbSrcLength;
529     DWORD               ndst = adsh->cbDstLength;
530
531     if (adsh->fdwConvert &
532         ~(ACM_STREAMCONVERTF_BLOCKALIGN|
533           ACM_STREAMCONVERTF_END|
534           ACM_STREAMCONVERTF_START))
535     {
536         FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh->fdwConvert);
537     }
538     /* ACM_STREAMCONVERTF_BLOCKALIGN
539      *  currently all conversions are block aligned, so do nothing for this flag
540      * ACM_STREAMCONVERTF_END
541      *  no pending data, so do nothing for this flag
542      */
543     if ((adsh->fdwConvert & ACM_STREAMCONVERTF_START))
544     {
545         MPEG3_Reset(adsi, aad);
546     }
547
548     aad->convert(adsi, adsh->pbSrc, &nsrc, adsh->pbDst, &ndst);
549     adsh->cbSrcLengthUsed = nsrc;
550     adsh->cbDstLengthUsed = ndst;
551
552     return MMSYSERR_NOERROR;
553 }
554
555 /**************************************************************************
556  *                      MPEG3_DriverProc                        [exported]
557  */
558 LRESULT CALLBACK MPEG3_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
559                                          LPARAM dwParam1, LPARAM dwParam2)
560 {
561     TRACE("(%08lx %p %04x %08lx %08lx);\n",
562           dwDevID, hDriv, wMsg, dwParam1, dwParam2);
563
564     switch (wMsg)
565     {
566     case DRV_LOAD:              return 1;
567     case DRV_FREE:              return 1;
568     case DRV_OPEN:              return MPEG3_drvOpen((LPSTR)dwParam1);
569     case DRV_CLOSE:             return MPEG3_drvClose(dwDevID);
570     case DRV_ENABLE:            return 1;
571     case DRV_DISABLE:           return 1;
572     case DRV_QUERYCONFIGURE:    return 1;
573     case DRV_CONFIGURE:         MessageBoxA(0, "MPEG3 filter !", "Wine Driver", MB_OK); return 1;
574     case DRV_INSTALL:           return DRVCNF_RESTART;
575     case DRV_REMOVE:            return DRVCNF_RESTART;
576
577     case ACMDM_DRIVER_NOTIFY:
578         /* no caching from other ACM drivers is done so far */
579         return MMSYSERR_NOERROR;
580
581     case ACMDM_DRIVER_DETAILS:
582         return MPEG3_DriverDetails((PACMDRIVERDETAILSW)dwParam1);
583
584     case ACMDM_FORMATTAG_DETAILS:
585         return MPEG3_FormatTagDetails((PACMFORMATTAGDETAILSW)dwParam1, dwParam2);
586
587     case ACMDM_FORMAT_DETAILS:
588         return MPEG3_FormatDetails((PACMFORMATDETAILSW)dwParam1, dwParam2);
589
590     case ACMDM_FORMAT_SUGGEST:
591         return MPEG3_FormatSuggest((PACMDRVFORMATSUGGEST)dwParam1);
592
593     case ACMDM_STREAM_OPEN:
594         return MPEG3_StreamOpen((PACMDRVSTREAMINSTANCE)dwParam1);
595
596     case ACMDM_STREAM_CLOSE:
597         return MPEG3_StreamClose((PACMDRVSTREAMINSTANCE)dwParam1);
598
599     case ACMDM_STREAM_SIZE:
600         return MPEG3_StreamSize((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMSIZE)dwParam2);
601
602     case ACMDM_STREAM_CONVERT:
603         return MPEG3_StreamConvert((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMHEADER)dwParam2);
604
605     case ACMDM_HARDWARE_WAVE_CAPS_INPUT:
606     case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT:
607         /* this converter is not a hardware driver */
608     case ACMDM_FILTERTAG_DETAILS:
609     case ACMDM_FILTER_DETAILS:
610         /* this converter is not a filter */
611     case ACMDM_STREAM_RESET:
612         /* only needed for asynchronous driver... we aren't, so just say it */
613         return MMSYSERR_NOTSUPPORTED;
614     case ACMDM_STREAM_PREPARE:
615     case ACMDM_STREAM_UNPREPARE:
616         /* nothing special to do here... so don't do anything */
617         return MMSYSERR_NOERROR;
618
619     default:
620         return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
621     }
622 }