The operation could not be performed because the f

2019-07-29 11:38发布

问题:

The operation could not be performed because the filter is in the wrong state

I am getting this error when attemting to run hr = m_pGrabber->GetCurrentBuffer(&cbBuffer, NULL);.

Strange part is - it initially worked when I stopped the graph, now it fails on running or stopped graph. So - what state it should be in??

The sample grabber code in MSDN I copied does not say if the graph should be stopped or running to get the buffer size - but the way it is presented the graph is running. I assume the graph should be running to fill the buffer, but I am not getting pass the sizing the buffer.

The graph is OK, all filters are conncted and renders as required, in may app and in GraphEdit.

I am trying to save the captured still frame into bitmap file so I need the capured data in the buffer.

回答1:

Buffering and GetCurrentBuffer expose you a copy of last known media sample. Hence, you might hit conditions "no media sample available yet to copy from" and "last known media sample is released due to transition to stopped state". In both cases the request in question might fail. Copy data from SampleCB instead of buffered mode and this is going to be one hundred percent reliable.

See also: ISampleGrabber::GetCurrentBuffer() returning VFW_E_WRONG_STATE



回答2:

Using GetCurrentBuffer is a bad idea in most cases. Proper way to use sample grabber is by setting your callback and receiving data in SampleCB.



标签: directshow