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.
A version of this page is also available for
4/8/2010

This is 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 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

Member Description

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

Member function Description

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.

Overrideable Member Functions

Member function Description

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

Method Description

Commit

Allocates memory by calling the CBaseAllocator::Allocmember function, which you must override.

Decommit

Releases any resources and enters the inactive state.

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

Method Description

NonDelegatingQueryInterface

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

Requirements

Windows Embedded CE Windows CE 2.12 and later
Windows Mobile Windows Mobile Version 5.0 and later
Note Microsoft DirectShow applications and DirectShow filters have different include file and Library requirements
For more information, see Setting Up the Build Environment