mpegl3.c 19.2 KB
Newer Older
1 2 3
/*
 * MPEG Layer 3 handling
 *
4 5
 * Copyright (C) 2002 Eric Pouech
 * Copyright (C) 2009 CodeWeavers, Aric Stewart
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 <mpg123.h>
26

27
#include "windef.h"
28 29 30
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
31
#include "winnls.h"
32
#include "mmsystem.h"
33
#include "mmreg.h"
34
#include "msacm.h"
35
#include "msacmdrv.h"
36 37 38 39 40 41 42
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(mpeg3);

/* table to list all supported formats... those are the basic ones. this
 * also helps given a unique index to each of the supported formats
 */
43
typedef	struct
44 45 46 47 48 49
{
    int		nChannels;
    int		nBits;
    int		rate;
} Format;

50
static const Format PCM_Formats[] =
51 52 53
{
    {1,  8,  8000}, {2,  8,  8000}, {1, 16,  8000}, {2, 16,  8000},
    {1,  8, 11025}, {2,  8, 11025}, {1, 16, 11025}, {2, 16, 11025},
54 55
    {1,  8, 12000}, {2,  8, 12000}, {1, 16, 12000}, {2, 16, 12000},
    {1,  8, 16000}, {2,  8, 16000}, {1, 16, 16000}, {2, 16, 16000},
56
    {1,  8, 22050}, {2,  8, 22050}, {1, 16, 22050}, {2, 16, 22050},
57 58
    {1,  8, 24000}, {2,  8, 24000}, {1, 16, 24000}, {2, 16, 24000},
    {1,  8, 32000}, {2,  8, 32000}, {1, 16, 32000}, {2, 16, 32000},
59
    {1,  8, 44100}, {2,  8, 44100}, {1, 16, 44100}, {2, 16, 44100},
60
    {1,  8, 48000}, {2,  8, 48000}, {1, 16, 48000}, {2, 16, 48000}
61 62
};

63
static const Format MPEG3_Formats[] =
64
{
65 66 67 68 69 70 71 72 73
    {1,  0,  8000}, {2,  0,  8000},
    {1,  0, 11025}, {2,  0, 11025},
    {1,  0, 12000}, {2,  0, 12000},
    {1,  0, 16000}, {2,  0, 16000},
    {1,  0, 22050}, {2,  0, 22050},
    {1,  0, 24000}, {2,  0, 24000},
    {1,  0, 32000}, {2,  0, 32000},
    {1,  0, 44100}, {2,  0, 44100},
    {1,  0, 48000}, {2,  0, 48000}
74 75 76 77 78 79 80 81
};

/***********************************************************************
 *           MPEG3_GetFormatIndex
 */
static	DWORD	MPEG3_GetFormatIndex(LPWAVEFORMATEX wfx)
{
    int 	i, hi;
82
    const Format *fmts;
83 84

    switch (wfx->wFormatTag)
85 86
    {
    case WAVE_FORMAT_PCM:
87
	hi = ARRAY_SIZE(PCM_Formats);
88 89
	fmts = PCM_Formats;
	break;
90
    case WAVE_FORMAT_MPEG:
91
    case WAVE_FORMAT_MPEGLAYER3:
92
	hi = ARRAY_SIZE(MPEG3_Formats);
93 94 95 96 97
	fmts = MPEG3_Formats;
	break;
    default:
	return 0xFFFFFFFF;
    }
98 99

    for (i = 0; i < hi; i++)
100 101 102
    {
	if (wfx->nChannels == fmts[i].nChannels &&
	    wfx->nSamplesPerSec == fmts[i].rate &&
103
	    (wfx->wBitsPerSample == fmts[i].nBits || !fmts[i].nBits))
104 105
	    return i;
    }
106

107 108 109
    return 0xFFFFFFFF;
}

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/***********************************************************************
 *           MPEG3_drvOpen
 */
static LRESULT MPEG3_drvOpen(LPCSTR str)
{
    mpg123_init();
    return 1;
}

/***********************************************************************
 *           MPEG3_drvClose
 */
static LRESULT MPEG3_drvClose(DWORD_PTR dwDevID)
{
    mpg123_exit();
    return 1;
}


129 130
static void mp3_horse(mpg123_handle *handle, const unsigned char *src,
        DWORD *nsrc, unsigned char *dst, DWORD *ndst)
131
{
132 133
    int                 ret;
    size_t              size;
134 135
    DWORD               dpos = 0;

136

137
    if (*nsrc > 0)
138
    {
139
        ret = mpg123_feed(handle, src, *nsrc);
140
        if (ret != MPG123_OK)
141
        {
142 143 144
            ERR("Error feeding data\n");
            *ndst = *nsrc = 0;
            return;
145 146 147
        }
    }

148
    do {
149
        size = 0;
150
        ret = mpg123_read(handle, dst + dpos, *ndst - dpos, &size);
151 152 153 154 155 156 157 158 159
        if (ret == MPG123_ERR)
        {
            FIXME("Error occurred during decoding!\n");
            *ndst = *nsrc = 0;
            return;
        }

        if (ret == MPG123_NEW_FORMAT)
        {
160 161
            long rate;
            int channels, enc;
162
            mpg123_getformat(handle, &rate, &channels, &enc);
163
            TRACE("New format: %li Hz, %i channels, encoding value %i\n", rate, channels, enc);
164 165
        }
        dpos += size;
166
        if (dpos >= *ndst) break;
167
    } while (ret != MPG123_ERR && ret != MPG123_NEED_MORE);
168 169 170
    *ndst = dpos;
}

171 172 173 174
/***********************************************************************
 *           MPEG3_StreamOpen
 *
 */
175
static LRESULT MPEG3_StreamOpen(ACMDRVSTREAMINSTANCE *instance)
176
{
177
    mpg123_handle *handle;
178 179
    int err;

180
    assert(!(instance->fdwOpen & ACM_STREAMOPENF_ASYNC));
181

182 183 184
    if (MPEG3_GetFormatIndex(instance->pwfxSrc) == 0xFFFFFFFF
            || MPEG3_GetFormatIndex(instance->pwfxDst) == 0xFFFFFFFF)
        return ACMERR_NOTPOSSIBLE;
185

186 187
    if (instance->pwfxDst->wFormatTag != WAVE_FORMAT_PCM)
        return MMSYSERR_NOTSUPPORTED;
188

189 190 191
    if (instance->pwfxSrc->wFormatTag != WAVE_FORMAT_MPEGLAYER3
            && instance->pwfxSrc->wFormatTag != WAVE_FORMAT_MPEG)
        return MMSYSERR_NOTSUPPORTED;
192

193
    if (instance->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3)
194
    {
195 196 197 198 199
        MPEGLAYER3WAVEFORMAT *mp3_format = (MPEGLAYER3WAVEFORMAT *)instance->pwfxSrc;

        if (instance->pwfxSrc->cbSize < MPEGLAYER3_WFX_EXTRA_BYTES
                || mp3_format->wID != MPEGLAYER3_ID_MPEG)
            return ACMERR_NOTPOSSIBLE;
200
    }
201

202 203 204 205 206
    if (instance->pwfxSrc->nSamplesPerSec != instance->pwfxDst->nSamplesPerSec
            || instance->pwfxSrc->nChannels != instance->pwfxDst->nChannels
            || instance->pwfxDst->wBitsPerSample != 16)
        return MMSYSERR_NOTSUPPORTED;

207 208 209
    handle = mpg123_new(NULL, &err);
    instance->dwDriver = (DWORD_PTR)handle;
    mpg123_open_feed(handle);
210

211 212 213 214 215
    /* mpg123 may find a XING header in the mp3 and use that information
     * to ask for seeks in order to read specific frames in the file.
     * We cannot allow that since the caller application is feeding us.
     * This fixes problems for mp3 files encoded with LAME (bug 42361)
     */
216
    mpg123_param(handle, MPG123_ADD_FLAGS, MPG123_IGNORE_INFOFRAME, 0);
217 218 219 220 221 222 223 224

    return MMSYSERR_NOERROR;
}

/***********************************************************************
 *           MPEG3_StreamClose
 *
 */
225
static LRESULT MPEG3_StreamClose(ACMDRVSTREAMINSTANCE *instance)
226
{
227 228 229 230
    mpg123_handle *handle = (mpg123_handle *)instance->dwDriver;

    mpg123_close(handle);
    mpg123_delete(handle);
231 232 233
    return MMSYSERR_NOERROR;
}

234 235 236 237 238 239 240 241
/***********************************************************************
 *           MPEG3_DriverDetails
 *
 */
static	LRESULT MPEG3_DriverDetails(PACMDRIVERDETAILSW add)
{
    add->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
    add->fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
242 243
    add->wMid = MM_FRAUNHOFER_IIS;
    add->wPid = MM_FHGIIS_MPEGLAYER3_DECODE;
244 245 246
    add->vdwACM = 0x01000000;
    add->vdwDriver = 0x01000000;
    add->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
247
    add->cFormatTags = 3; /* PCM, MPEG3 */
248
    add->cFilterTags = 0;
249
    add->hicon = NULL;
250
    MultiByteToWideChar( CP_ACP, 0, "MPEG Layer-3 Codec", -1,
251
                         add->szShortName, ARRAY_SIZE( add->szShortName ));
252
    MultiByteToWideChar( CP_ACP, 0, "Wine MPEG3 decoder", -1,
253
                         add->szLongName, ARRAY_SIZE( add->szLongName ));
254
    MultiByteToWideChar( CP_ACP, 0, "Brought to you by the Wine team...", -1,
255
                         add->szCopyright, ARRAY_SIZE( add->szCopyright ));
256
    MultiByteToWideChar( CP_ACP, 0, "Refer to LICENSE file", -1,
257
                         add->szLicensing, ARRAY_SIZE( add->szLicensing ));
258
    add->szFeatures[0] = 0;
259

260 261 262 263 264 265 266 267 268
    return MMSYSERR_NOERROR;
}

/***********************************************************************
 *           MPEG3_FormatTagDetails
 *
 */
static	LRESULT	MPEG3_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
{
269 270
    static const WCHAR szPcm[]={'P','C','M',0};
    static const WCHAR szMpeg3[]={'M','P','e','g','3',0};
271
    static const WCHAR szMpeg[]={'M','P','e','g',0};
272 273

    switch (dwQuery)
274 275
    {
    case ACM_FORMATTAGDETAILSF_INDEX:
276
	if (aftd->dwFormatTagIndex > 2) return ACMERR_NOTPOSSIBLE;
277 278
	break;
    case ACM_FORMATTAGDETAILSF_LARGESTSIZE:
279
	if (aftd->dwFormatTag == WAVE_FORMAT_UNKNOWN)
280
        {
281
            aftd->dwFormatTagIndex = 2; /* WAVE_FORMAT_MPEG is biggest */
282 283
	    break;
	}
284
	/* fall through */
285 286
    case ACM_FORMATTAGDETAILSF_FORMATTAG:
	switch (aftd->dwFormatTag)
287 288 289
        {
	case WAVE_FORMAT_PCM:		aftd->dwFormatTagIndex = 0; break;
	case WAVE_FORMAT_MPEGLAYER3:    aftd->dwFormatTagIndex = 1; break;
290
	case WAVE_FORMAT_MPEG:          aftd->dwFormatTagIndex = 2; break;
291 292 293 294
	default:			return ACMERR_NOTPOSSIBLE;
	}
	break;
    default:
295
	WARN("Unsupported query %08x\n", dwQuery);
296 297
	return MMSYSERR_NOTSUPPORTED;
    }
298

299
    aftd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
300
    switch (aftd->dwFormatTagIndex)
301 302 303 304
    {
    case 0:
	aftd->dwFormatTag = WAVE_FORMAT_PCM;
	aftd->cbFormatSize = sizeof(PCMWAVEFORMAT);
305
	aftd->cStandardFormats = ARRAY_SIZE(PCM_Formats);
306 307 308 309 310
        lstrcpyW(aftd->szFormatTag, szPcm);
        break;
    case 1:
	aftd->dwFormatTag = WAVE_FORMAT_MPEGLAYER3;
	aftd->cbFormatSize = sizeof(MPEGLAYER3WAVEFORMAT);
311
        aftd->cStandardFormats = 0;
312 313
        lstrcpyW(aftd->szFormatTag, szMpeg3);
	break;
314 315 316
    case 2:
	aftd->dwFormatTag = WAVE_FORMAT_MPEG;
	aftd->cbFormatSize = sizeof(MPEG1WAVEFORMAT);
317
        aftd->cStandardFormats = 0;
318 319
        lstrcpyW(aftd->szFormatTag, szMpeg);
	break;
320 321 322 323 324 325 326 327 328 329
    }
    return MMSYSERR_NOERROR;
}

/***********************************************************************
 *           MPEG3_FormatDetails
 *
 */
static	LRESULT	MPEG3_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
{
330
    switch (dwQuery)
331 332 333 334 335 336
    {
    case ACM_FORMATDETAILSF_FORMAT:
	if (MPEG3_GetFormatIndex(afd->pwfx) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
	break;
    case ACM_FORMATDETAILSF_INDEX:
	afd->pwfx->wFormatTag = afd->dwFormatTag;
337
	switch (afd->dwFormatTag)
338 339
        {
	case WAVE_FORMAT_PCM:
340
	    if (afd->dwFormatIndex >= ARRAY_SIZE(PCM_Formats)) return ACMERR_NOTPOSSIBLE;
341 342 343 344
	    afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels;
	    afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate;
	    afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits;
	    /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
345
	     * afd->pwfx->cbSize = 0;
346
	     */
347
	    afd->pwfx->nBlockAlign =
348
		(afd->pwfx->nChannels * afd->pwfx->wBitsPerSample) / 8;
349
	    afd->pwfx->nAvgBytesPerSec =
350 351 352
		afd->pwfx->nSamplesPerSec * afd->pwfx->nBlockAlign;
	    break;
	case WAVE_FORMAT_MPEGLAYER3:
353
	case WAVE_FORMAT_MPEG:
354 355
            WARN("Encoding to MPEG is not supported\n");
            return ACMERR_NOTPOSSIBLE;
356
	default:
357
            WARN("Unsupported tag %08x\n", afd->dwFormatTag);
358 359 360 361
	    return MMSYSERR_INVALPARAM;
	}
	break;
    default:
362
	WARN("Unsupported query %08x\n", dwQuery);
363
	return MMSYSERR_NOTSUPPORTED;
364 365 366
    }
    afd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
    afd->szFormat[0] = 0; /* let MSACM format this for us... */
367

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    return MMSYSERR_NOERROR;
}

/***********************************************************************
 *           MPEG3_FormatSuggest
 *
 */
static	LRESULT	MPEG3_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
{
    /* some tests ... */
    if (adfs->cbwfxSrc < sizeof(PCMWAVEFORMAT) ||
	adfs->cbwfxDst < sizeof(PCMWAVEFORMAT) ||
	MPEG3_GetFormatIndex(adfs->pwfxSrc) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
    /* FIXME: should do those tests against the real size (according to format tag */

    /* If no suggestion for destination, then copy source value */
    if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NCHANNELS))
	adfs->pwfxDst->nChannels = adfs->pwfxSrc->nChannels;
    if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NSAMPLESPERSEC))
        adfs->pwfxDst->nSamplesPerSec = adfs->pwfxSrc->nSamplesPerSec;
388
    if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WBITSPERSAMPLE))
389
        adfs->pwfxDst->wBitsPerSample = 16;
390
    if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG))
391
    {
392
	if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM)
393 394 395 396
        {
            WARN("Encoding to MPEG is not supported\n");
            return ACMERR_NOTPOSSIBLE;
        }
397 398 399
        else
            adfs->pwfxDst->wFormatTag = WAVE_FORMAT_PCM;
    }
400

401 402 403 404 405 406 407 408 409 410
    /* check if result is ok */
    if (MPEG3_GetFormatIndex(adfs->pwfxDst) == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;

    /* recompute other values */
    switch (adfs->pwfxDst->wFormatTag)
    {
    case WAVE_FORMAT_PCM:
        adfs->pwfxDst->nBlockAlign = (adfs->pwfxDst->nChannels * adfs->pwfxDst->wBitsPerSample) / 8;
        adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign;
        break;
411
    case WAVE_FORMAT_MPEG:
412
    case WAVE_FORMAT_MPEGLAYER3:
413 414
        WARN("Encoding to MPEG is not supported\n");
        return ACMERR_NOTPOSSIBLE;
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
        break;
    default:
        FIXME("\n");
        break;
    }

    return MMSYSERR_NOERROR;
}

/***********************************************************************
 *           MPEG3_StreamSize
 *
 */
static	LRESULT MPEG3_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE adss)
{
430 431
    DWORD nblocks;

432
    switch (adss->fdwSize)
433 434 435 436
    {
    case ACM_STREAMSIZEF_DESTINATION:
	/* cbDstLength => cbSrcLength */
	if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
437 438
            (adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3 ||
             adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEG))
439
        {
440
            nblocks = (adss->cbDstLength - 3000) / (DWORD)(adsi->pwfxDst->nAvgBytesPerSec * 1152 / adsi->pwfxDst->nSamplesPerSec + 0.5);
441 442 443
            if (nblocks == 0)
                return ACMERR_NOTPOSSIBLE;
            adss->cbSrcLength = nblocks * 1152 * adsi->pwfxSrc->nBlockAlign;
444
	}
445 446
        else if ((adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3 ||
                 adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEG) &&
447
                 adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
448
        {
449 450 451
            nblocks = adss->cbDstLength / (adsi->pwfxDst->nBlockAlign * 1152);
            if (nblocks == 0)
                return ACMERR_NOTPOSSIBLE;
452
            adss->cbSrcLength = nblocks * (DWORD)(adsi->pwfxSrc->nAvgBytesPerSec * 1152 / adsi->pwfxSrc->nSamplesPerSec);
453
	}
454
        else
455 456 457 458 459 460 461
        {
	    return MMSYSERR_NOTSUPPORTED;
	}
	break;
    case ACM_STREAMSIZEF_SOURCE:
	/* cbSrcLength => cbDstLength */
	if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
462 463
            (adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3 ||
             adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEG))
464
        {
465
            nblocks = adss->cbSrcLength / (adsi->pwfxSrc->nBlockAlign * 1152);
466 467 468
            if (adss->cbSrcLength % (DWORD)(adsi->pwfxSrc->nBlockAlign * 1152))
                /* Round block count up. */
                nblocks++;
469 470
            if (nblocks == 0)
                return ACMERR_NOTPOSSIBLE;
471
            adss->cbDstLength = 3000 + nblocks * (DWORD)(adsi->pwfxDst->nAvgBytesPerSec * 1152 / adsi->pwfxDst->nSamplesPerSec + 0.5);
472
	}
473 474
        else if ((adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3 ||
                 adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEG) &&
475
                 adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
476
        {
477 478 479 480
            nblocks = adss->cbSrcLength / (DWORD)(adsi->pwfxSrc->nAvgBytesPerSec * 1152 / adsi->pwfxSrc->nSamplesPerSec);
            if (adss->cbSrcLength % (DWORD)(adsi->pwfxSrc->nAvgBytesPerSec * 1152 / adsi->pwfxSrc->nSamplesPerSec))
                /* Round block count up. */
                nblocks++;
481 482
            if (nblocks == 0)
                return ACMERR_NOTPOSSIBLE;
483
            adss->cbDstLength = nblocks * 1152 * adsi->pwfxDst->nBlockAlign;
484
	}
485
        else
486 487 488 489 490
        {
	    return MMSYSERR_NOTSUPPORTED;
	}
	break;
    default:
491
	WARN("Unsupported query %08x\n", adss->fdwSize);
492
	return MMSYSERR_NOTSUPPORTED;
493 494 495 496 497 498 499 500
    }
    return MMSYSERR_NOERROR;
}

/***********************************************************************
 *           MPEG3_StreamConvert
 *
 */
501
static LRESULT MPEG3_StreamConvert(ACMDRVSTREAMINSTANCE *instance, ACMDRVSTREAMHEADER *adsh)
502
{
503
    mpg123_handle *handle = (mpg123_handle *)instance->dwDriver;
504 505
    DWORD		nsrc = adsh->cbSrcLength;
    DWORD		ndst = adsh->cbDstLength;
506 507

    if (adsh->fdwConvert &
508 509
	~(ACM_STREAMCONVERTF_BLOCKALIGN|
	  ACM_STREAMCONVERTF_END|
510
	  ACM_STREAMCONVERTF_START))
511
    {
512
	FIXME("Unsupported fdwConvert (%08x), ignoring it\n", adsh->fdwConvert);
513 514 515 516 517 518
    }
    /* ACM_STREAMCONVERTF_BLOCKALIGN
     *	currently all conversions are block aligned, so do nothing for this flag
     * ACM_STREAMCONVERTF_END
     *	no pending data, so do nothing for this flag
     */
519
    if ((adsh->fdwConvert & ACM_STREAMCONVERTF_START))
520
    {
521 522 523
        mpg123_feedseek(handle, 0, SEEK_SET, NULL);
        mpg123_close(handle);
        mpg123_open_feed(handle);
524 525
    }

526
    mp3_horse(handle, adsh->pbSrc, &nsrc, adsh->pbDst, &ndst);
527 528
    adsh->cbSrcLengthUsed = nsrc;
    adsh->cbDstLengthUsed = ndst;
529

530 531 532 533 534 535
    return MMSYSERR_NOERROR;
}

/**************************************************************************
 * 			MPEG3_DriverProc			[exported]
 */
536
LRESULT CALLBACK MPEG3_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
537 538
					 LPARAM dwParam1, LPARAM dwParam2)
{
539 540
    TRACE("(%08lx %p %04x %08lx %08lx);\n",
	  dwDevID, hDriv, wMsg, dwParam1, dwParam2);
541 542

    switch (wMsg)
543 544 545 546 547
    {
    case DRV_LOAD:		return 1;
    case DRV_FREE:		return 1;
    case DRV_OPEN:		return MPEG3_drvOpen((LPSTR)dwParam1);
    case DRV_CLOSE:		return MPEG3_drvClose(dwDevID);
548
    case DRV_ENABLE:		return 1;
549 550 551 552 553
    case DRV_DISABLE:		return 1;
    case DRV_QUERYCONFIGURE:	return 1;
    case DRV_CONFIGURE:		MessageBoxA(0, "MPEG3 filter !", "Wine Driver", MB_OK); return 1;
    case DRV_INSTALL:		return DRVCNF_RESTART;
    case DRV_REMOVE:		return DRVCNF_RESTART;
554

555 556 557
    case ACMDM_DRIVER_NOTIFY:
	/* no caching from other ACM drivers is done so far */
	return MMSYSERR_NOERROR;
558

559 560
    case ACMDM_DRIVER_DETAILS:
	return MPEG3_DriverDetails((PACMDRIVERDETAILSW)dwParam1);
561

562 563
    case ACMDM_FORMATTAG_DETAILS:
	return MPEG3_FormatTagDetails((PACMFORMATTAGDETAILSW)dwParam1, dwParam2);
564

565 566
    case ACMDM_FORMAT_DETAILS:
	return MPEG3_FormatDetails((PACMFORMATDETAILSW)dwParam1, dwParam2);
567

568 569
    case ACMDM_FORMAT_SUGGEST:
	return MPEG3_FormatSuggest((PACMDRVFORMATSUGGEST)dwParam1);
570

571 572
    case ACMDM_STREAM_OPEN:
	return MPEG3_StreamOpen((PACMDRVSTREAMINSTANCE)dwParam1);
573

574 575
    case ACMDM_STREAM_CLOSE:
	return MPEG3_StreamClose((PACMDRVSTREAMINSTANCE)dwParam1);
576

577 578
    case ACMDM_STREAM_SIZE:
	return MPEG3_StreamSize((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMSIZE)dwParam2);
579

580 581
    case ACMDM_STREAM_CONVERT:
	return MPEG3_StreamConvert((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMHEADER)dwParam2);
582

583 584 585 586 587 588 589 590 591 592 593 594 595
    case ACMDM_HARDWARE_WAVE_CAPS_INPUT:
    case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT:
	/* this converter is not a hardware driver */
    case ACMDM_FILTERTAG_DETAILS:
    case ACMDM_FILTER_DETAILS:
	/* this converter is not a filter */
    case ACMDM_STREAM_RESET:
	/* only needed for asynchronous driver... we aren't, so just say it */
	return MMSYSERR_NOTSUPPORTED;
    case ACMDM_STREAM_PREPARE:
    case ACMDM_STREAM_UNPREPARE:
	/* nothing special to do here... so don't do anything */
	return MMSYSERR_NOERROR;
596

597 598 599 600
    default:
	return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
    }
}