persiflage
persiflage

Reputation: 1204

Can IMemAllocator::GetBuffer safely be called from a worker thread as well as its streaming thread

I'm writing a source filter that needs to generate data for the samples on its output pins (1 or more pins) in a separate worker thread (the worker thread calls a library which is only safe to access from a single thread).

Is it safe to call GetBuffer on the output pins' allocators from the worker thread at the same time as normal use on the streaming threads (e.g. the allocator being decommitted when playback stops)?

I'm aware of the normal considerations such as GetBuffer blocking when there are no buffers left or returning a failure code when the allocator is decommitted. Clearly this also involves overriding SourceStream::GetDeliveryBuffer too.

The obvious alternative is for the worker to generate a queue of normal memory buffers which get copied into media samples by each streaming thread.

Upvotes: 1

Views: 130

Answers (1)

Geraint Davies
Geraint Davies

Reputation: 2847

The only case I know of where this might be problematic is pretty obscure. If the buffer you are getting is a primary surface from the (original) video renderer, then the allocation and free need to be on the same thread.

Outside of that peculiar situation, the stock mem allocator is fully thread safe.

Upvotes: 1

Related Questions