[WINEMP3.ACM] Sync with Wine 3.0. CORE-14225
[reactos.git] / dll / win32 / winemp3.acm / mpegl3.c
index 21962b4..15acdea 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "config.h"
-#include "wine/port.h"
+#include <config.h>
+//#include "wine/port.h"
 
 #include <assert.h>
 #include <stdarg.h>
-#include <string.h>
+//#include <string.h>
 
 #ifdef HAVE_MPG123_H
 # include <mpg123.h>
 # endif
 #endif
 
-#include "windef.h"
-#include "winbase.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "winnls.h"
-#include "mmsystem.h"
-#include "mmreg.h"
-#include "msacm.h"
-#include "msacmdrv.h"
-#include "wine/debug.h"
+#include <windef.h>
+#include <winbase.h>
+#include <wingdi.h>
+#include <winuser.h>
+#include <winnls.h>
+//#include "mmsystem.h"
+//#include "mmreg.h"
+//#include "msacm.h"
+#include <msacmdrv.h>
+#include <wine/debug.h>
 
 WINE_DEFAULT_DEBUG_CHANNEL(mpeg3);
 
@@ -248,11 +248,23 @@ static    LRESULT MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
         aad->convert = mp3_horse;
         aad->mh = mpg123_new(NULL,&err);
         mpg123_open_feed(aad->mh);
+
+#if MPG123_API_VERSION >= 31 /* needed for MPG123_IGNORE_FRAMEINFO enum value */
+        /* 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)
+         */
+        mpg123_param(aad->mh, MPG123_ADD_FLAGS, MPG123_IGNORE_INFOFRAME, 0);
+#endif
     }
-    /* no encoding yet
     else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&
-             adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3)
-    */
+             (adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEGLAYER3 ||
+              adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEG))
+    {
+        WARN("Encoding to MPEG is not supported\n");
+        goto theEnd;
+    }
     else goto theEnd;
     MPEG3_Reset(adsi, aad);
 
@@ -658,15 +670,15 @@ static    LRESULT MPEG3_DriverDetails(PACMDRIVERDETAILSW add)
 {
     add->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
     add->fccComp = ACMDRIVERDETAILS_FCCCOMP_UNDEFINED;
-    add->wMid = 0xFF;
-    add->wPid = 0x00;
+    add->wMid = MM_FRAUNHOFER_IIS;
+    add->wPid = MM_FHGIIS_MPEGLAYER3_DECODE;
     add->vdwACM = 0x01000000;
     add->vdwDriver = 0x01000000;
     add->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
     add->cFormatTags = 3; /* PCM, MPEG3 */
     add->cFilterTags = 0;
     add->hicon = NULL;
-    MultiByteToWideChar( CP_ACP, 0, "WINE-MPEG3", -1,
+    MultiByteToWideChar( CP_ACP, 0, "MPEG Layer-3 Codec", -1,
                          add->szShortName, sizeof(add->szShortName)/sizeof(WCHAR) );
     MultiByteToWideChar( CP_ACP, 0, "Wine MPEG3 decoder", -1,
                          add->szLongName, sizeof(add->szLongName)/sizeof(WCHAR) );
@@ -700,7 +712,7 @@ static      LRESULT MPEG3_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
             aftd->dwFormatTagIndex = 2; /* WAVE_FORMAT_MPEG is biggest */
            break;
        }
-       /* fall thru */
+       /* fall through */
     case ACM_FORMATTAGDETAILSF_FORMATTAG:
        switch (aftd->dwFormatTag)
         {
@@ -727,54 +739,19 @@ static    LRESULT MPEG3_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
     case 1:
        aftd->dwFormatTag = WAVE_FORMAT_MPEGLAYER3;
        aftd->cbFormatSize = sizeof(MPEGLAYER3WAVEFORMAT);
-       aftd->cStandardFormats = NUM_MPEG3_FORMATS;
+        aftd->cStandardFormats = 0;
         lstrcpyW(aftd->szFormatTag, szMpeg3);
        break;
     case 2:
        aftd->dwFormatTag = WAVE_FORMAT_MPEG;
        aftd->cbFormatSize = sizeof(MPEG1WAVEFORMAT);
-       aftd->cStandardFormats = NUM_MPEG3_FORMATS;
+        aftd->cStandardFormats = 0;
         lstrcpyW(aftd->szFormatTag, szMpeg);
        break;
     }
     return MMSYSERR_NOERROR;
 }
 
-static void fill_in_mp3(unsigned cbwfx, WAVEFORMATEX* wfx, unsigned bit_rate)
-{
-    MPEGLAYER3WAVEFORMAT*   mp3wfx = (MPEGLAYER3WAVEFORMAT*)wfx;
-
-    wfx->nAvgBytesPerSec = bit_rate / 8;
-    if (cbwfx >= sizeof(WAVEFORMATEX))
-        wfx->cbSize = sizeof(MPEGLAYER3WAVEFORMAT) - sizeof(WAVEFORMATEX);
-    if (cbwfx >= sizeof(MPEGLAYER3WAVEFORMAT))
-    {
-        mp3wfx->wID = MPEGLAYER3_ID_MPEG;
-        mp3wfx->fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF;
-        mp3wfx->nBlockSize = (bit_rate * 144) / wfx->nSamplesPerSec;
-        mp3wfx->nFramesPerBlock = 1;
-        mp3wfx->nCodecDelay = 0x0571;
-    }
-}
-
-static void fill_in_mpeg(unsigned cbwfx, WAVEFORMATEX* wfx, unsigned bit_rate)
-{
-    MPEG1WAVEFORMAT*   mp3wfx = (MPEG1WAVEFORMAT*)wfx;
-
-    wfx->nAvgBytesPerSec = bit_rate / 8;
-    if (cbwfx >= sizeof(WAVEFORMATEX))
-        wfx->cbSize = sizeof(MPEG1WAVEFORMAT) - sizeof(WAVEFORMATEX);
-    if (cbwfx >= sizeof(MPEG1WAVEFORMAT))
-    {
-        mp3wfx->fwHeadLayer = ACM_MPEG_LAYER3;
-        mp3wfx->dwHeadBitrate = wfx->nAvgBytesPerSec * 8;
-        mp3wfx->fwHeadMode = ACM_MPEG_JOINTSTEREO;
-        mp3wfx->fwHeadModeExt = 0xf;
-        mp3wfx->wHeadEmphasis = 1;
-        mp3wfx->fwHeadFlags = ACM_MPEG_ID_MPEG1;
-    }
-}
-
 /***********************************************************************
  *           MPEG3_FormatDetails
  *
@@ -805,16 +782,8 @@ static     LRESULT MPEG3_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
            break;
        case WAVE_FORMAT_MPEGLAYER3:
        case WAVE_FORMAT_MPEG:
-           if (afd->dwFormatIndex >= NUM_MPEG3_FORMATS) return ACMERR_NOTPOSSIBLE;
-           afd->pwfx->nChannels = MPEG3_Formats[afd->dwFormatIndex].nChannels;
-           afd->pwfx->nSamplesPerSec = MPEG3_Formats[afd->dwFormatIndex].rate;
-           afd->pwfx->wBitsPerSample = MPEG3_Formats[afd->dwFormatIndex].nBits;
-           afd->pwfx->nBlockAlign = 1;
-           if (afd->dwFormatTag == WAVE_FORMAT_MPEGLAYER3)
-               fill_in_mp3(afd->cbwfx, afd->pwfx, 192000);
-           else
-               fill_in_mpeg(afd->cbwfx, afd->pwfx, 192000);
-           break;
+            WARN("Encoding to MPEG is not supported\n");
+            return ACMERR_NOTPOSSIBLE;
        default:
             WARN("Unsupported tag %08x\n", afd->dwFormatTag);
            return MMSYSERR_INVALPARAM;
@@ -847,18 +816,15 @@ static    LRESULT MPEG3_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
        adfs->pwfxDst->nChannels = adfs->pwfxSrc->nChannels;
     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_NSAMPLESPERSEC))
         adfs->pwfxDst->nSamplesPerSec = adfs->pwfxSrc->nSamplesPerSec;
-
     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WBITSPERSAMPLE))
-    {
-       if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM)
-            adfs->pwfxDst->wBitsPerSample = 4;
-        else
-            adfs->pwfxDst->wBitsPerSample = 16;
-    }
+        adfs->pwfxDst->wBitsPerSample = 16;
     if (!(adfs->fdwSuggest & ACM_FORMATSUGGESTF_WFORMATTAG))
     {
        if (adfs->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM)
-            adfs->pwfxDst->wFormatTag = WAVE_FORMAT_MPEGLAYER3;
+        {
+            WARN("Encoding to MPEG is not supported\n");
+            return ACMERR_NOTPOSSIBLE;
+        }
         else
             adfs->pwfxDst->wFormatTag = WAVE_FORMAT_PCM;
     }
@@ -874,12 +840,9 @@ static     LRESULT MPEG3_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
         adfs->pwfxDst->nAvgBytesPerSec = adfs->pwfxDst->nSamplesPerSec * adfs->pwfxDst->nBlockAlign;
         break;
     case WAVE_FORMAT_MPEG:
-        adfs->pwfxDst->nBlockAlign = 1;
-        fill_in_mpeg(adfs->cbwfxDst, adfs->pwfxDst, 192000);
-        break;
     case WAVE_FORMAT_MPEGLAYER3:
-        adfs->pwfxDst->nBlockAlign = 1;
-        fill_in_mp3(adfs->cbwfxDst, adfs->pwfxDst, 192000);
+        WARN("Encoding to MPEG is not supported\n");
+        return ACMERR_NOTPOSSIBLE;
         break;
     default:
         FIXME("\n");
@@ -931,11 +894,11 @@ static    LRESULT MPEG3_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE ad
              adsi->pwfxDst->wFormatTag == WAVE_FORMAT_MPEG))
         {
             nblocks = adss->cbSrcLength / (adsi->pwfxSrc->nBlockAlign * 1152);
-            if (nblocks == 0)
-                return ACMERR_NOTPOSSIBLE;
             if (adss->cbSrcLength % (DWORD)(adsi->pwfxSrc->nBlockAlign * 1152))
                 /* Round block count up. */
                 nblocks++;
+            if (nblocks == 0)
+                return ACMERR_NOTPOSSIBLE;
             adss->cbDstLength = 3000 + nblocks * (DWORD)(adsi->pwfxDst->nAvgBytesPerSec * 1152 / adsi->pwfxDst->nSamplesPerSec + 0.5);
        }
         else if ((adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_MPEGLAYER3 ||
@@ -943,11 +906,11 @@ static    LRESULT MPEG3_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE ad
                  adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM)
         {
             nblocks = adss->cbSrcLength / (DWORD)(adsi->pwfxSrc->nAvgBytesPerSec * 1152 / adsi->pwfxSrc->nSamplesPerSec);
-            if (nblocks == 0)
-                return ACMERR_NOTPOSSIBLE;
             if (adss->cbSrcLength % (DWORD)(adsi->pwfxSrc->nAvgBytesPerSec * 1152 / adsi->pwfxSrc->nSamplesPerSec))
                 /* Round block count up. */
                 nblocks++;
+            if (nblocks == 0)
+                return ACMERR_NOTPOSSIBLE;
             adss->cbDstLength = nblocks * 1152 * adsi->pwfxDst->nBlockAlign;
        }
         else