[PATCH 2/4] winemp3.acm: Disallow operations encoding to MPEG.

Zebediah Figura z.figura12 at gmail.com
Fri Jun 9 13:49:35 CDT 2017


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/msacm32/tests/msacm.c | 33 +++++++++++++++++++
 dlls/winemp3.acm/mpegl3.c  | 80 ++++++++++------------------------------------
 2 files changed, 50 insertions(+), 63 deletions(-)

diff --git a/dlls/msacm32/tests/msacm.c b/dlls/msacm32/tests/msacm.c
index 13494a6e96b..3954ed459cd 100644
--- a/dlls/msacm32/tests/msacm.c
+++ b/dlls/msacm32/tests/msacm.c
@@ -1045,6 +1045,8 @@ todo_wine
 static void test_acmFormatSuggest(void)
 {
     WAVEFORMATEX src, dst;
+    MPEGLAYER3WAVEFORMAT mp3wfx;
+    ACMFORMATTAGDETAILSA aftd = {0};
     DWORD suggest;
     MMRESULT rc;
     DWORD sizeMax;
@@ -1137,6 +1139,37 @@ static void test_acmFormatSuggest(void)
     ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
     rc = acmFormatSuggest(NULL, NULL, NULL, sizeof(dst), suggest);
     ok(rc == MMSYSERR_INVALPARAM, "failed with error 0x%x\n", rc);
+
+    /* Test MP3 (decode only) */
+    mp3wfx.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
+    mp3wfx.wfx.nChannels = 1;
+    mp3wfx.wfx.nSamplesPerSec = 44100;
+    mp3wfx.wfx.wBitsPerSample = 0;
+    mp3wfx.wfx.nBlockAlign = 1;
+    mp3wfx.wfx.nAvgBytesPerSec = 192000 / 8;
+    mp3wfx.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
+    mp3wfx.wID = MPEGLAYER3_ID_MPEG;
+    mp3wfx.fdwFlags = MPEGLAYER3_FLAG_PADDING_OFF;
+    mp3wfx.nBlockSize = 144 * (192000 / 44100);
+    mp3wfx.nFramesPerBlock = 1;
+    mp3wfx.nCodecDelay = 0;
+    aftd.cbStruct = sizeof(aftd);
+    aftd.dwFormatTag = WAVE_FORMAT_MPEGLAYER3;
+    rc = acmFormatTagDetailsA(NULL, &aftd, ACM_FORMATTAGDETAILSF_FORMATTAG);
+    ok(rc == MMSYSERR_NOERROR, "failed with error 0x%x\n", rc);
+    ok(aftd.cbFormatSize == sizeof(MPEGLAYER3WAVEFORMAT), "expected %d, got %d\n",
+       sizeof(MPEGLAYER3WAVEFORMAT), aftd.cbFormatSize);
+    ok(aftd.cStandardFormats == 0, "expected %d, got %d\n", 0, aftd.cStandardFormats);
+
+    ZeroMemory(&dst, sizeof(dst));
+    dst.wFormatTag = WAVE_FORMAT_PCM;
+    rc = acmFormatSuggest(NULL, (WAVEFORMATEX *) &mp3wfx, &dst, sizeof(PCMWAVEFORMAT), ACM_FORMATSUGGESTF_WFORMATTAG);
+    ok(rc == MMSYSERR_NOERROR, "failed with error 0x%x\n", rc);
+    ok(dst.nChannels == 1, "expected %d, got %d\n", 1, dst.nChannels);
+    ok(dst.nSamplesPerSec == 44100, "expected %d, got %d\n", 44100, dst.nSamplesPerSec);
+    ok(dst.wBitsPerSample == 16, "expected %d, got %d\n", 16, dst.wBitsPerSample);
+    ok(dst.nBlockAlign == 2, "expected %d, got %d\n", 2, dst.nBlockAlign);
+    ok(dst.nAvgBytesPerSec == 88200, "expected %d, got %d\n", 88200, dst.nAvgBytesPerSec);
 }
 
 static struct
diff --git a/dlls/winemp3.acm/mpegl3.c b/dlls/winemp3.acm/mpegl3.c
index cc6008da59e..c5d71bba524 100644
--- a/dlls/winemp3.acm/mpegl3.c
+++ b/dlls/winemp3.acm/mpegl3.c
@@ -258,10 +258,13 @@ static	LRESULT	MPEG3_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
         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);
 
@@ -736,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
  *
@@ -814,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;
@@ -856,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;
     }
@@ -883,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");
-- 
2.13.0




More information about the wine-patches mailing list