1 #include "PooledSubPic.h"
2 #include "../subtitles/xy_malloc.h"
5 STDMETHODIMP_(void) CPooledSubPicAllocator::ReleaseItem( void* Item
)
7 //DbgLog((LOG_TRACE, 3, "ReleaseItem::free:%d", _free.GetCount()));
8 CAutoLock
lock(&_poolLock
);
9 POSITION pos
= _using
.Find((CPooledSubPic
*)Item
);
13 _free
.AddTail((CPooledSubPic
*)Item
);
17 STDMETHODIMP_(void) CPooledSubPicAllocator::OnItemDestruct( void* Item
)
19 //DbgLog((LOG_TRACE, 3, "OnItemDestruct::free:%d", _free.GetCount()));
20 CAutoLock
lock(&_poolLock
);
21 //CPooledSubPic* typedItem = (CPooledSubPic*)Item;
22 POSITION pos
= _using
.Find((CPooledSubPic
*)Item
);
28 ASSERT(_free
.Find((CPooledSubPic
*)Item
)==NULL
);
31 bool STDMETHODCALLTYPE
CPooledSubPicAllocator::InitPool( int capacity
)
33 DbgLog((LOG_TRACE
, 3, "%s(%d), %s", __FILE__
, __LINE__
, __FUNCTION__
));
34 CAutoLock
lock(&_poolLock
);
40 //while(capacity<_capacity)
45 temp
= _free
.RemoveTail();
50 else if(!_using
.IsEmpty())
52 temp
= _using
.RemoveTail();
59 while(_capacity
<capacity
)
61 if(!(temp
= DoAlloc()))
71 //DbgLog((LOG_TRACE, 3, "InitPool::free:%d", _free.GetCount()));
75 CPooledSubPicAllocator::CPooledSubPicAllocator( int alpha_blt_dst_type
, SIZE maxsize
, int capacity
, int type
/*=-1*/ )
76 :CSubPicExAllocatorImpl(maxsize
, false, false)
77 , _alpha_blt_dst_type(alpha_blt_dst_type
)
83 switch(alpha_blt_dst_type
)
97 _type
= MSP_AYUV_PLANAR
;
109 bool CPooledSubPicAllocator::AllocEx( bool fStatic
, ISubPicEx
** ppSubPic
)
116 CAutoLock
lock(&_poolLock
);
120 CPooledSubPic
*item
= _free
.RemoveHead();
121 if(item
->m_type
!=_type
)
128 _using
.AddTail(item
);
143 CPooledSubPicAllocator::~CPooledSubPicAllocator()
145 CPooledSubPic
* item
= NULL
;
146 CAutoLock
lock(&_poolLock
);
147 for(POSITION pos
= _free
.GetHeadPosition(); pos
!=NULL
; )
149 item
= _free
.GetNext(pos
);
156 for(POSITION pos
= _using
.GetHeadPosition(); pos
!=NULL
; )
158 item
= _using
.GetNext(pos
);
167 STDMETHODIMP_(int) CPooledSubPicAllocator::SetSpdColorType( int color_type
)
169 if(_type
!=color_type
)
177 STDMETHODIMP_(bool) CPooledSubPicAllocator::IsSpdColorTypeSupported( int type
)
181 (type
==MSP_XY_AUYV
&& _alpha_blt_dst_type
== MSP_YUY2
)
183 (type
==MSP_AYUV
&& _alpha_blt_dst_type
== MSP_AYUV
)
185 (type
==MSP_AYUV_PLANAR
&& (_alpha_blt_dst_type
== MSP_IYUV
||
186 _alpha_blt_dst_type
== MSP_YV12
||
187 _alpha_blt_dst_type
== MSP_P010
||
188 _alpha_blt_dst_type
== MSP_P016
||
189 _alpha_blt_dst_type
== MSP_NV12
||
190 _alpha_blt_dst_type
== MSP_NV21
)) )
197 CPooledSubPic
* CPooledSubPicAllocator::DoAlloc()
204 spd
.bpp
= (_type
== MSP_AYUV_PLANAR
) ? 8 : 32;
205 spd
.pitch
= (spd
.w
*spd
.bpp
)>>3;
207 // if(!(spd.bits = new BYTE[spd.pitch*spd.h]))
208 if(_type
== MSP_AYUV_PLANAR
)
210 spd
.bits
= xy_malloc(spd
.pitch
*spd
.h
*4);
214 spd
.bits
= xy_malloc(spd
.pitch
*spd
.h
);
221 CPooledSubPic
* temp
= NULL
;
222 if(!(temp
= DEBUG_NEW
CPooledSubPic(spd
, _alpha_blt_dst_type
, this)))
231 void CPooledSubPicAllocator::CollectUnUsedItem()
233 POSITION pos
= _using
.GetHeadPosition();
236 CPooledSubPic
* item
= _using
.RemoveHead();
243 _using
.AddTail(item
);
248 CPooledSubPic::~CPooledSubPic()
251 _pool
->OnItemDestruct(this);