Implementing Directshow IFileSourceFilter interface in a CSource based Filter
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开发者_如何学JAVA 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;
}
}
I think you should return E_FAIL
for now in the getCurFile
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).
精彩评论