自定义 DirectShow 过滤器:难以将变量传递到主机应用程序
我的目标是创建一个 DirectShow 过滤器,将音频样本传递到我的游戏。目前,它将 WaveFormatEx 结构中的一些数据成员保存到私有变量中。我的接口类中有主机应用程序可以调用的访问器函数。问题是,当我调用这些函数时,我总是得到零(初始化值)。
成员变量在我重写的 CTransInPlace::CheckInputType() 中设置,并且(使用消息框)这些值是有意义的。这是代码:
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;
}
在 GraphEdit 和我的主机应用程序中创建图形时,值是正确的。但是,当我调用访问器函数时,我总是得到零。我的访问器都共享相同的基本定义:
STDMETHODIMP CDrunkenFilter::GetSampleRate(DWORD *ptr)
{
(*ptr) = m_sampleRate;
return NOERROR;
}
我知道我正在向这些函数传递有效的指针。
我不知道我做错了什么......可能只是另一个研究不够充分的例子。如果您能指出我正确的方向,请随时发帖!
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 zero. 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我错误地使用 CoCreateInstance 创建了过滤器和接口。
我将接口创建更改为filter->QueryInterface,现在一切正常。
I was wrongly creating the filter AND interface with CoCreateInstance.
I changed the interface creation to filter->QueryInterface, and everything works fine now.