在基于 CSource 的过滤器中实现 Directshow IFileSourceFilter 接口
我实现了从 CSource 过滤器派生的简单 Directshow 过滤器。效果很好。 我想要的是添加过滤器 IFileSourceFilter。所以我要做的是:
我用两种方法实现 FileSourceFilter 接口:
HRESULT Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt)
HRESULT GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt)
现在[仅用于测试目的]它们什么都不做
// Required by IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
STDMETHODIMP GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
,还将 IFileSourceFilter 接口添加到我的源过滤器的 NonDelegatingQueryInterface 方法中。
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IFileSourceFilter)
{
return GetInterface((IFileSourceFilter *)this, ppv);
}
else
{
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
}
当我将 SourceFilter 插入 grapgEdit 时,它会很好地询问我文件位置...我给出一个随机文件[ 用于测试目的 IFileSourceFilter 接口暂时不执行任何操作)...
然后我的 SourceFilter 崩溃突然在grah编辑工具...。
为什么可能是错误的?我在实现 IFileSourceFilter 接口时是否遗漏了一些东西? 有什么可能导致这种情况的建议吗?
祝愿
我的 SourceFilter 结构:
class MySourceFilter : public CSource,public IFileSourceFilter
{
public:
....
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IFileSourceFilter)
{
return GetInterface((IFileSourceFilter *)this, ppv);
}
else
{
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
}
// Required by IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
STDMETHODIMP GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
}
I implement simple Directshow Filter which derived from CSource filter. It work fine.
What i want is to add the filter IFileSourceFilter. So what i do for this is:
I implement FileSourceFilter interface with two methods:
HRESULT Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt)
HRESULT GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt)
For now [ Just for test purposses] They do nothing
// Required by IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
STDMETHODIMP GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
And also add the IFileSourceFilter interface to NonDelegatingQueryInterface method of my source filter.
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IFileSourceFilter)
{
return GetInterface((IFileSourceFilter *)this, ppv);
}
else
{
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
}
When i insert my SourceFilter into the grapgEdit it nicely ask me file location...I give a random file[ for test porposes IFileSourceFilter interfcae DO nothing for now)...
AndThen my SourceFilter Crash at the grah edit tool suddenly... .
Whay may be wrong?Do i missing something while implementing IFileSourceFilter interface?
Any suggestion ideas for which may cause this?
Best Wishes
My SourceFilter Structure:
class MySourceFilter : public CSource,public IFileSourceFilter
{
public:
....
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IFileSourceFilter)
{
return GetInterface((IFileSourceFilter *)this, ppv);
}
else
{
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
}
// Required by IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR lpwszFileName, const AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
STDMETHODIMP GetCurFile(LPOLESTR * ppszFileName, AM_MEDIA_TYPE *pmt)
{
// do nothing for now...Just for test
return S_OK;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您现在应该在
getCurFile
函数中返回E_FAIL
。 Graphedit 将询问过滤器加载了哪个文件,并期望在 GetCurFile 返回 S_OK 时收到文件名。但如果不初始化,ppszFileName 将指向随机内存。最好在
getCurFile
中实际返回一个值。使用 CoTaskMemAlloc 为文件名和媒体类型分配内存。然后设置一个虚拟文件名,并将媒体类型memset为0。(但检查指针是否不为空)。I think you should return
E_FAIL
for now in thegetCurFile
function. Graphedit will ask the filter which file is loaded, and expects to receive the filename when GetCurFile returns S_OK. But ppszFileName will point to random memory, if you don't initialize it.It would be better to actually return a value in
getCurFile
. Allocate memory using CoTaskMemAlloc for both the filename and mediatype. Then set a dummy filename, and memset the mediatype to 0. (but check if the pointers are not null).