开发者

Custom DirectShow filter: difficulty passing variables to host app

开发者 https://www.devze.com 2023-02-13 08:19 出处:网络
My goal is to create a DirectShow filter that passes audio samples to my game. For now, it saves a few data members from the WaveFormatEx structure into private variables. I have accessor functions in

My goal is to create a DirectShow filter that passes audio samples to my game. For now, it saves a few data members from the WaveFormatEx structure into private variables. I have accessor functions in my interface class that the host app can call. Problem is, when I call these functions, I always get zero (the initialized value).

The member variables are set in my overridden CTransInPlace::CheckInputType(), and (using message boxes) the values make sense. Here's the code:

HRESULT CDrunkenFilter::CheckInputType(const CMediaType *pmt)
{
    CheckPointer(pmt, E_POINTER);

    if (pmt->majortype != MEDIATYPE_Audio)
        return VFW_E_TYPE_NOT_ACCEPTED;

    if (pmt->subtype != MEDIASUBTYPE_PCM)
        return VFW_E_TYPE_NOT_ACCEPTED;

    if (pmt->formattype != FORMAT_WaveFormatEx)
        return VFW_E_TYPE_NOT_ACCEPTED;

    WAVEFORMATEX *wfx = (WAVEFORMATEX*)pmt->Format();
    m_channels = wfx->nChannels;
    m_blockSize = wfx->nBlockAlign;
    m_bitRate = wfx->wBitsPerSample;
    m_sampleRate = wfx->nSamplesPerSec;

    stringstream ss;
    ss << "channels " << m_channels << "\n";
    ss << "blocksize " << m_blockSize << "\n";
    ss << "bitrate " << m_bitRate << "\n";
    ss << "samplerate " << m_sampleRate;

    int len = MultiByteToWideChar(0, 0, ss.str().c_str(), -1, NULL, 0);

    WCHAR *str = new WCHAR[len];
    MultiByteToWideChar(0, 0, ss.str().c_str(), -1, str, len);

    MessageBox(NULL, str, NULL, NULL);
    delete [] str;

    return NOERROR;
}

When creating a graph in GraphEdit and my host app, the values are correct. However, when I call my accessor functions, I'm always getting zer开发者_JAVA技巧o. My accessors all share the same basic definition:

STDMETHODIMP CDrunkenFilter::GetSampleRate(DWORD *ptr)
{
    (*ptr) = m_sampleRate;
    return NOERROR;
}  

I know that I am passing valid pointers to these functions.

I don't know what I'm doing wrong... probably just another case of not researching well enough. If you can point me in the right direction please don't hesitate to post!


I was wrongly creating the filter AND interface with CoCreateInstance.

I changed the interface creation to filter->QueryInterface, and everything works fine now.

0

精彩评论

暂无评论...
验证码 换一张
取 消