Microsoft Windows CE 3.0  

CBaseAllocator Class

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

CBaseAllocatoris an abstract base class that implements the basic mechanisms for an allocator with a fixed number of fixed-size buffers. The number of buffers and their size can be changed using the CBaseAllocator::SetPropertiesmember function when an input pin and an output pin negotiate the allocator between them.

The class provides the basic functionality for a memory allocator by implementing the IMemAllocatorinterface. It provides support for managing a list of CMediaSampleobjects (or objects derived from this class), including support for the IMemAllocator::Commitand IMemAllocator::Decommitmethods, and blocking the IMemAllocator::GetBuffermethod.

Any class derived from this class (such as CMemAllocator) must create CMediaSampleobjects, which this base class does not.

A signaling mechanism employing a semaphore is used so that if there are no samples, a thread can wait until there are samples or until the allocator is decommitted. The m_lFreeand m_hSemmember variables are used to implement this simple signaling mechanism as follows.

When a thread calls CBaseAllocator::GetBufferand there are no samples available, m_lWaitingis incremented and the thread calls the Microsoft Win32 WaitForSingleObjectfunction on the semaphore indicated by m_hSem.

When a sample is freed (by the IUnknown::Releasemethod returning the reference count to zero) or CBaseAllocator::Decommitis called and m_lWaitingis nonzero, the Win32 ReleaseSemaphorefunction is called on m_hSemwith a release count of m_lWaiting, and m_lWaitingis reset to zero.

All member functions in this class that return HRESULTand accept a pointer as a parameter return E_POINTER when passed a null pointer.

Protected Data Members

m_bChanged TRUE if the buffers have changed; otherwise, FALSE.
m_bCommitted If TRUE, the allocator is in a state in which all IMemAllocator::GetBuffermethods fail. The IMemAllocator::SetPropertiesmethod is the only member function permitted to operate in this state.
m_bDecommitInProgress If TRUE, the decommit process completes upon the return of all media samples. Until the decommit process has completed, any calls to IMemAllocator::GetBufferreturn E_OUTOFMEMORY.
m_hSem Semaphore for signaling.
m_lAlignment Agreed alignment of the buffer.
m_lAllocated Number of buffers actually allocated.
m_lCount Established number of buffers to provide.
m_lFree List of CMediaSampleobjects that are currently free (free list).
m_lPrefix Agreed prefix of the buffer (precedes value returned by IMediaSample::GetPointer).
m_lSize Size of each buffer.
m_lWaiting Count of threads waiting for samples.

Member Functions

CBaseAllocator Constructs a CBaseAllocatorobject.
NotifySample Notifies a waiting thread that a sample is available on the free list.
SetWaiting Increments the m_lWaitingdata member to indicate that a thread is waiting for a sample.

Overridable Member Functions

Alloc Allocates memory, instantiates CMediaSampleobjects, and adds them to the m_lAllocatedand m_lFreedata members.
Free Decommits memory when the last buffer is freed.

Implemented IMemAllocator Methods

Commit Allocates memory by calling the CBaseAllocator::Allocmember function, which you must override.
Decommit Releases any resources and enters the inactive state. Any blocking calls to IMemAllocator::GetBuffershould return with an error value, and all further calls to GetBufferfail when in the inactive state.
GetBuffer Retrieves a container for a sample.
GetProperties Determines the size, number, and alignment of blocks.
ReleaseBuffer Releases the CMediaSampleobject.
SetProperties Specifies a desired number of blocks, size of the blocks, and block alignment figure. This method returns the actual values for the same.

Implemented INonDelegatingUnknown Methods

NonDelegatingQueryInterface Passes out pointers to any interfaces added to the derived filter class.