Download Automatic Detection and Analysis of Tumor Tissue in
Transcript
CHAPTER 5. IMAGE ANALYSIS TOOL
release the memory by ourselves. The main advantage is as the down-stream filters do
not need to know about how to clean up the sample but only decrease the sample’s
reference counter whenever they finished proceeding the sample. The code of such a
customized allocator is given in Listing 5.11.
c l a s s MyAllocator : p u b l i c CMemAllocator
{
public :
MyAllocator (HRESULT * phr ) :
,→CMemAllocator (TEXT( ” MyAlloc \0 ” ) ,NULL, phr ) { } ;
˜ CIAContourMemAllocator ( ) { } ;
HRESULT A l l o c ( ) {
// a l l o c a t e r e q u e s t e d memory & p r e p a r e s a m p l e s
// s e e a l s o i m p l e m e n t a t i o n o f ” CMemAllocator ”
// u s e r d e f i n e d s a m pl e s can be i n i t i a l i z e d h e r e
};
STDMETHODIMP R e l e a s e B u f f e r ( IMediaSample * pSample ) {
/ * R e l e a s e t h e COM o b j e c t b e f o r e r e u s i n g i t s a d d r e s s p o i n t e r * /
IUnknown * comObject ;
pSample−>G e t P o i n t e r ( (BYTE* * )&comObject ) ;
comObject−>R e l e a s e ( ) ;
// put sample back on f r e e l i s t f o r r e c y c l i n g
// s e e a l s o i m p l e m e n t a t i o n o f ” CMemAllocator ”
};
};
Listing 5.11: Implementation of a memory allocator.
In a next step we need to integrate the new allocator into one of our filters. Talking about the contour structure initialized in a transformation filter we have to set the
output pin’s allocator to our customized one. An important fact to know is as the
output pin by default tries to assign to the down-stream’s input pin’s allocator by calling the method “CIATransformInputPin::GetAllocator” before initializing an own one6 .
Because of that we have to overwrite two methods. Firstly, the “CIABufferTransformOutputPin::DecideAllocator” method: here, we need to skip the trial of assigning the
input pin’s allocator which would be successful if no unexpected error occurred while
building up the filter graph. In a next step the output pin tries its own allocator by
calling the “CIABufferTransformOutputPin::InitCustomOutPinAllocator” method. An
example implementation of this method is given in Listing 5.12.
6
For more details please refer to
https://msdn.microsoft.com/en-us/library/windows/desktop/dd377477(v=vs.85).aspx
45