Windows Media Player DSP Plugin Format Negotiation

506 Views Asked by At

I am writing an audio DSP plugin for Windows Media Player with the plugin acting as a DMO. I am trying to get WMP to send me the audio data in mono 22.050 khz audio. However, no matter what I do the player re-samples all audio to stereo 44.1k data. Even if the file I'm playing is a 22.050khz wave file I still get 44.1 audio in my plugin.

I specify the data my plugin can handle via the GetInputType/GetOutputType functions, but no matter what happens by the time SetInputType/SetOutputType is called the format is back to 44.1k. Does anyone have an idea of what is happening? I tried writing ValidateMediaType to only accept the sample rate I want, but then I just get no data at all. My GetInputType function is below

STDMETHODIMP CWMPIPSpeaker::GetInputType ( 
               DWORD dwInputStreamIndex,
               DWORD dwTypeIndex,
               DMO_MEDIA_TYPE *pmt)
{
    HRESULT hr = S_OK;

    if ( 0 != dwInputStreamIndex )
    {
        return DMO_E_INVALIDSTREAMINDEX ;
    }

    // only support one preferred type
    if ( 0 != dwTypeIndex )
    {
        return DMO_E_NO_MORE_ITEMS;
    }

    if ( NULL == pmt )
    {
       return E_POINTER;

    }


    hr = MoInitMediaType(pmt, sizeof( WAVEFORMATEX ) );

    WAVEFORMATEX* format = ((WAVEFORMATEX*)pmt->pbFormat);
    format->nChannels = 1;
    format->nSamplesPerSec = 22050;
    format->wFormatTag = WAVE_FORMAT_PCM;
    format->wBitsPerSample = 16;    
    format->cbSize = 0;
    format->nBlockAlign = (format->nChannels * format->wBitsPerSample) / 8;
    format->nAvgBytesPerSec = format->nBlockAlign * format->nSamplesPerSec;

    pmt->formattype = FORMAT_WaveFormatEx;
    pmt->lSampleSize = format->nBlockAlign;
    pmt->bFixedSizeSamples = true;
    pmt->majortype = MEDIATYPE_Audio;
    pmt->subtype = MEDIASUBTYPE_PCM;

    return hr;
}
1

There are 1 best solutions below

0
On

Well unfortunately it appears the problem isn't me. I'm archiving this here for future reference because of all the trouble this issue caused me. I found a detailed report on the problem on an msdn blog and it appears that in Vista and later you cannot negotiate media types for DMO plugins by design. I can't say I agree with this decision, but I means that I must do the conversion myself if I want to have down-sampled data.

Hopefully this helps anyone else who runs into this "feature".