2/4 is moving the code around at the same time as making a functional change, and I can't tell why it's moving the code around.
We split get_output_samples() from process_output() in 2/4. The reason of the splitting is that, according to our tests, ProcessInput() is called between get_output_samples() and process_output(). The correct implementation should be: get_output_samples() -> ProcessInput() -> process_output(). So can't make get_output_samples() inside process_output().
Okay, that's a separate functional change from what the subject describes and implements, so it should certainly be a separate patch. And is it actually necessary?
Why does dmo_wrapper_sink_Receive() now call get_output_samples() an extra time?
We have 2 process_output() calls in dmo_wrapper_sink_Receive(), so we call it 2 times, which is the same as what we do before. (The second process_output() doesn't show in the commit diff.)
Oops, yes, I should have read more carefully.
I know 4/4 is backed by tests, but what race or deadlock is it trying to fix?
The situation is, we have a filter graph like this: [source(reader)] -> [dmo decoder] -> [renderer].
We have a worker thead in source filter, the thread will get samples from the allocator of decoder's input pin, fill the samples, then push samples downsteam. So it will call dmo_wrapper_sink_Receive() on dmo decoder filter.
And our main thread receive user inputs, it will skip the video if it got mouse click. So it will call Stop() on dmo decoder filter.
Receive() should wait for Stop() and fail eventually, the Receive() failure will then break the loop in worker thread, and make the thread terminate normally.
But if we don't sync Stop() with Receive(), the loop in worker thread will fail on sample allcating, because the allocator is decommited when calling Stop(), sample allcating failure will raise a error in the game.
So the source filter is an application component, and it's fine with VFW_E_WRONG_STATE from Receive(), but doesn't like VFW_E_NOT_COMMITTED? That sounds like a good reason then.