Windows Media Player DSP 插件格式协商

发布于 2024-12-27 02:21:24 字数 1550 浏览 1 评论 0原文

我正在为 Windows Media Player 编写一个音频 DSP 插件,该插件充当 DMO。我正在尝试让 WMP 以单声道 22.050 khz 音频向我发送音频数据。但是,无论我做什么,播放器都会将所有音频重新采样为立体声 44.1k 数据。即使我正在播放的文件是 22.050khz 波形文件,我仍然可以在插件中获得 44.1 音频。

我通过 GetInputType/GetOutputType 函数指定我的插件可以处理的数据,但无论调用 SetInputType/SetOutputType 时发生什么,格式都会回到 44.1k。有人知道发生了什么吗?我尝试编写 ValidateMediaType 来仅接受我想要的采样率,但后来我根本没有得到任何数据。我的 GetInputType 函数如下

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;
}

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2025-01-03 02:21:24

不幸的是,问题似乎不是我。由于这个问题给我带来了很多麻烦,我将其存档在这里以供将来参考。我找到了关于 msdn 博客上出现问题,并且在 Vista 及更高版本中您似乎无法协商媒体DMO 插件的类型设计。我不能说我同意这个决定,但我的意思是,如果我想要下采样数据,我必须自己进行转换。

希望这对遇到此“功能”的其他人有所帮助。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文