Вопрос

I have a Delphi 6 DirectShow push source video filter that uses the DSPACK component library. What aspects of the filter require me to lock the filter state before performing certain operations? For example, in my filter's FillBuffer() method do I need to lock the filter's shared state before writing the bitmap canvas? Or is it only operations like filter pin connection/disconnection events or media format negotiation, etc. that require the shared state to be locked?

Это было полезно?

Решение

You lock the filter (it is not filter specific, it applies to any object in multithreaded environment) to ensure atomic operation. It is typically either data access or serialization of actions.

For example, CTransformFilter class has two critical sections: m_csFilter and m_csReceive.

m_csFilter protects data state to make sure that while one thread is changing something, other threads don't touch the same data simultaneously. The other one, m_csReceive is used to serialize receive and end-of-stream events.

You need to lock filter state when you need that your operations are not interrupted by an action on concurrent thread. Because your lock might delay other threads, you are expected to hold the lock the minimal time to affect as little as possible execution on other threads..

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top