During this time, I learned about DirectShow and wrote some weird code. When I learned how to collect audio in the past few days, I encountered this problem again.
When my program runs the imediacontrol: Run () function, s_false is returned every time. I think many people will certainly encounter this problem, but it sometimes does not affect the running of our program. This is why. Let's take a look at what msdn says.
TheRunMethod runs all the filters in the filter graph. While the graph is running, data moves through he graph and is rendered.
It can be seen from the above that sometimes it returns s_false because some filters have not changed to the running status, and may be in the running status after a period of time, this may not affect the running of our program.
To prove my understanding, I did the following experiments. Let's take a look at some comments on msdn about the returned s_false by the imediacontrol: Run () function.
If the return value is s_false, you can wait for the transition to complete by callingImediacontrol: getstateMethod. If the method fails, some filters might be in a running state. In a multistream graph, entire streams might be playing successfully. The application must determine whether to stop the graph.
So I made some modifications to my code, as shown below:
Hresult augraph: audiorun ()
{
Hresult hR = noerror;
If (m_pmc)
{
OA filterstate PFS;
HR = m_pmc-> getstate (100, & PFS); // before testing run
HR = m_pmc-> Run ();
HR = m_pmc-> getstate (100, & PFS); // after the test run
If (s_false = HR)
{
....
Return hr;
}
M_biscapture = true;
}
Return hr;
}
The test results are as follows:
After hR = m_pmc-> getstate (100, & PFS) is executed for the first time, s_ OK is returned. The PFS value is 0, it indicates that all our filters are in the stopped state (for the significance of PFS value and the usage of getstate (), you can view msdn on your own ).
After hR = m_pmc-> getstate (100, & PFS) is executed for the second time, s_ OK is returned. The PFS value is 2, indicating that all filters are in the running state.
Therefore, we can see from the above test results that sometimes it returns s_false without affecting the running of our program. However, this cannot be too absolute. You need to take a specific look at the problem.
Of course, why does my code look like this? I will share it with you after I find the reason.