How to control threads that will be started by DirectShow Filter ?

Started by
1 comment, last by Michael Tanczos 12 years, 11 months ago
I have writing a DirectShow Capture filter and now confusing with threads that will be generated by my filter class that will inherit CSourceStream, IAMStreamConfig and IKsPropertySet.

Then I met problems are occurred when I do manipulations below.

- First, start a host program that will loads the filter's DLL.
- Second, prompt a command "regsvr32 -u myfilter.ax" and "regsvr32 myfilter.ax" sequentially. This command can be executed by hands or some process.
- Then DLL will crush in the FillBuffer virtual function by manipulating the stream's memory. It seems a dirty access or a race condition... But this crush has one condition that is the defference in the SetFormat virtual function of this filter class. Below are two types of SetFormat methods.


HRESULT STDMETHODCALLTYPE CMyFilter::SetFormat(
AM_MEDIA_TYPE *pmt
)
{
DECLARE_PTR(VIDEOINFOHEADER, pvi, m_mt.pbFormat);
prev_vid_info = *pvi;

m_mt = *pmt; // this line will be cause of the error with filter's threads.

IPin* pin;
ConnectedTo(&pin);
if(pin)
{
IFilterGraph *pGraph = m_pParent->GetGraph();
pGraph->Reconnect(this);
}
return S_OK;
}



HRESULT STDMETHODCALLTYPE CMyFilter::SetFormat(
AM_MEDIA_TYPE *pmt
)
{
DECLARE_PTR(VIDEOINFOHEADER, pvi, m_mt.pbFormat);
prev_vid_info = *pvi;

// comment out the line below and error will not occurres BUT this filter will be incapable with modification of resolutions. (i.e. with the Adobe Flash Media Live Encoder)
//m_mt = *pmt;

IPin* pin;
ConnectedTo(&pin);
if(pin)
{
IFilterGraph *pGraph = m_pParent->GetGraph();
pGraph->Reconnect(this);
}
return S_OK;
}


How can I control filter's threads when I reload filter DLL with regsvr32 ?
I have tried to control this thread with IMediaControl interface's methods but these functions don't work.
I've reached informations with CSourceStream's DoBufferProcessingLoop method. But I don't get nice ideas to manipulate threads with this virtual method.
Advertisement
I had resolved this problem by myself.

I had resolved this problem by myself.


And your solution was?

This topic is closed to new replies.

Advertisement