问题
I am looking to write a directshow source filter that reads data from an application rather that reading the same from file/socket/device. First of all is is possible? If so how can I achieve it? I have done the same in gstreamer using appsrc plugin and since I am new to directshow can somebody please explain.
Scenario: Device -> Application -> (DirectShow Source Filter) -> (DirectShow DecoderFilter) -> (DirectShow Sink)
Thanks in advance.
回答1:
It is possible but you have to implement the communication between the source filter and its source of data (application). Your source filter and the application can communicate over socket or pipe, or memory mapped files - any interprocess communication will do the trick (if the application is hosting source filter, that is within single process, you could establish direct communication). There is no standard component or even helper to attach to the source filter, you will need to deal with raw APIs.
回答2:
Thanks roman.
I am now able to pass data to the source driver from application through an interface. I took pushsource filter from the directshow samples and added an additional interface to it using the sample below
Including this in a common header file
DECLARE_INTERFACE_(IMySettingsInterface, IUnknown)
{
STDMETHOD(GetParamInt)(char* szName, int *pParam) = 0;
STDMETHOD(SetParamInt)(char* szName, int nParam) = 0;
};
// {F350FE9E-65BA-4AC1-A6C0-FD9F2979D342}
DEFINE_GUID(IID_IMySettings,
0xf350fe9e, 0x65ba, 0x4ac1, 0xa6, 0xc0, 0xfd, 0x9f, 0x29, 0x79, 0xd3, 0x42);
Change made to CPushSourceDesktop class
class CPushSourceDesktop : public CSource, public IMySettingsInterface
{
private:
// Constructor is private because you have to use CreateInstance
CPushSourceDesktop(IUnknown *pUnk, HRESULT *phr);
~CPushSourceDesktop();
CPushPinDesktop *m_pPin;
public:
DECLARE_IUNKNOWN;
static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
//Methods the interface supports
STDMETHODIMP GetParamInt(char* szName, int *pParam);
STDMETHODIMP SetParamInt(char* szName, int nParam);
};
I generated the UUID using create GUID tool of VS.
Defined these interface methods in my filter
STDMETHODIMP CPushSourceDesktop::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
if (riid == (IID_IMySettings))
{
return GetInterface((IMySettingsInterface*) this, ppv);
}
else
{
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
}
STDMETHODIMP CPushSourceDesktop::GetParamInt(char* szName, int *pParam)
{
// Example
*pParam = 10;
return 0;
}
STDMETHODIMP CPushSourceDesktop::SetParamInt(char* szName, int pParam)
{
//Example
return 0;
}
I will use another method to pass application buffers to source filter queue.
Thanks again.
来源:https://stackoverflow.com/questions/24421037/is-it-possible-to-for-a-directshow-source-filter-to-read-data-from-application