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