2 #include "SimpleSubPicProviderImpl.h"
3 #include "SimpleSubPicWrapper.h"
4 #include "../subtitles/xy_bitmap.h"
5 #include "SimpleSubpicImpl.h"
6 #include "PooledSubPic.h"
7 #include "IDirectVobSubXy.h"
9 //////////////////////////////////////////////////////////////////////////
11 // SimpleSubPicProvider
15 SimpleSubPicProvider::SimpleSubPicProvider( int alpha_blt_dst_type
, SIZE spd_size
, RECT video_rect
, IDirectVobSubXy
*consumer
16 , HRESULT
* phr
/*=NULL*/ )
17 : CUnknown(NAME("CSubPicQueueImpl"), NULL
)
18 , m_alpha_blt_dst_type(alpha_blt_dst_type
)
19 , m_spd_size(spd_size
)
20 , m_video_rect(video_rect
)
23 , m_consumer(consumer
)
26 *phr
= consumer
? S_OK
: E_INVALIDARG
;
29 m_prefered_colortype
.AddTail(MSP_AYUV_PLANAR
);
30 m_prefered_colortype
.AddTail(MSP_AYUV
);
31 m_prefered_colortype
.AddTail(MSP_XY_AUYV
);
32 m_prefered_colortype
.AddTail(MSP_RGBA
);
35 SimpleSubPicProvider::~SimpleSubPicProvider()
40 STDMETHODIMP
SimpleSubPicProvider::NonDelegatingQueryInterface( REFIID riid
, void** ppv
)
43 QI(ISimpleSubPicProvider
)
44 __super::NonDelegatingQueryInterface(riid
, ppv
);
47 STDMETHODIMP
SimpleSubPicProvider::SetSubPicProvider( IUnknown
* subpic_provider
)
49 CComQIPtr
<ISubPicProviderEx2
> tmp
= subpic_provider
;
52 CAutoLock
cAutoLock(&m_csSubPicProvider
);
53 m_pSubPicProviderEx
= tmp
;
55 if(m_pSubPicProviderEx
!=NULL
)
57 POSITION pos
= m_prefered_colortype
.GetHeadPosition();
60 int color_type
= m_prefered_colortype
.GetNext(pos
);
61 if( m_pSubPicProviderEx
->IsColorTypeSupported( color_type
) &&
62 IsSpdColorTypeSupported( color_type
) )
64 m_spd_type
= color_type
;
76 STDMETHODIMP
SimpleSubPicProvider::GetSubPicProvider( IUnknown
** subpic_provider
)
78 if(!subpic_provider
) {
82 CAutoLock
cAutoLock(&m_csSubPicProvider
);
84 if(m_pSubPicProviderEx
) {
85 *subpic_provider
= m_pSubPicProviderEx
;
86 (*subpic_provider
)->AddRef();
89 return !!*subpic_provider
? S_OK
: E_FAIL
;
92 STDMETHODIMP
SimpleSubPicProvider::SetFPS( double fps
)
99 STDMETHODIMP
SimpleSubPicProvider::SetTime( REFERENCE_TIME rtNow
)
106 STDMETHODIMP
SimpleSubPicProvider::Invalidate( REFERENCE_TIME rtInvalidate
/*= -1*/ )
108 CAutoLock
cQueueLock(&m_csLock
);
110 if( m_pSubPic
&& m_subpic_stop
>= rtInvalidate
)
117 STDMETHODIMP_(bool) SimpleSubPicProvider::LookupSubPic( REFERENCE_TIME now
/*[in]*/, ISimpleSubPic
** output_subpic
/*[out]*/ )
119 if(output_subpic
!=NULL
)
121 *output_subpic
= NULL
;
122 CComPtr
<IXySubRenderFrame
> temp
= NULL
;
123 bool result
= LookupSubPicEx(now
, &temp
);
126 (*output_subpic
= new SimpleSubpic(temp
, m_alpha_blt_dst_type
))->AddRef();
133 STDMETHODIMP
SimpleSubPicProvider::GetStats( int& nSubPics
, REFERENCE_TIME
& rtNow
, REFERENCE_TIME
& rtStart
, REFERENCE_TIME
& rtStop
)
135 CAutoLock
cAutoLock(&m_csLock
);
139 rtStart
= rtStop
= 0;
144 rtStart
= m_subpic_start
;
145 rtStop
= m_subpic_stop
;
151 STDMETHODIMP
SimpleSubPicProvider::GetStats( int nSubPic
, REFERENCE_TIME
& rtStart
, REFERENCE_TIME
& rtStop
)
153 CAutoLock
cAutoLock(&m_csLock
);
155 if(!m_pSubPic
|| nSubPic
!= 0)
158 rtStart
= m_subpic_start
;
159 rtStop
= m_subpic_stop
;
164 bool SimpleSubPicProvider::LookupSubPicEx(REFERENCE_TIME rtNow
, IXySubRenderFrame
** sub_render_frame
)
166 if(!sub_render_frame
)
169 *sub_render_frame
= NULL
;
171 if(m_subpic_start
<= rtNow
&& rtNow
< m_subpic_stop
&& m_pSubPic
)
173 (*sub_render_frame
= m_pSubPic
)->AddRef();
177 CComPtr
<ISubPicProviderEx2
> pSubPicProvider
;
178 if(SUCCEEDED(GetSubPicProviderEx(&pSubPicProvider
)) && pSubPicProvider
179 && SUCCEEDED(pSubPicProvider
->Lock()))
183 if(POSITION pos
= pSubPicProvider
->GetStartPosition(rtNow
, fps
))
185 REFERENCE_TIME rtStart
= pSubPicProvider
->GetStart(pos
, fps
);
186 REFERENCE_TIME rtStop
= pSubPicProvider
->GetStop(pos
, fps
);
188 if(rtStart
<= rtNow
&& rtNow
< rtStop
)
190 RenderTo(sub_render_frame
, rtNow
, rtNow
+1, fps
, true);
194 pSubPicProvider
->Unlock();
196 if(*sub_render_frame
)
198 CAutoLock
cAutoLock(&m_csLock
);
200 m_pSubPic
= *sub_render_frame
;
204 return(!!*sub_render_frame
);
207 HRESULT
SimpleSubPicProvider::GetSubPicProviderEx( ISubPicProviderEx2
** pSubPicProviderEx
)
209 if(!pSubPicProviderEx
) {
213 CAutoLock
cAutoLock(&m_csSubPicProvider
);
215 if(m_pSubPicProviderEx
) {
216 *pSubPicProviderEx
= m_pSubPicProviderEx
;
217 (*pSubPicProviderEx
)->AddRef();
220 return !!*pSubPicProviderEx
? S_OK
: E_FAIL
;
223 HRESULT
SimpleSubPicProvider::RenderTo( IXySubRenderFrame
** pSubPic
, REFERENCE_TIME rtStart
, REFERENCE_TIME rtStop
, double fps
, BOOL bIsAnimated
)
231 CComPtr
<ISubPicProviderEx2
> pSubPicProviderEx
;
232 if(FAILED(GetSubPicProviderEx(&pSubPicProviderEx
)) || !pSubPicProviderEx
) {
236 if(FAILED(pSubPicProviderEx
->Lock())) {
240 CAtlList
<CRect
> rectList
;
242 CComPtr
<IXySubRenderFrame
> sub_render_frame
;
243 SIZE size_render_with
;
245 hr
= m_consumer
->XyGetSize(DirectVobSubXyOptions::SIZE_LAYOUT_WITH
, &size_render_with
);
251 hr
= pSubPicProviderEx
->RenderEx(pSubPic
, m_spd_type
, m_spd_size
,
252 size_render_with
, CRect(0,0,size_render_with
.cx
,size_render_with
.cy
),
253 bIsAnimated
? rtStart
: ((rtStart
+rtStop
)/2), fps
);
255 POSITION pos
= pSubPicProviderEx
->GetStartPosition(rtStart
, fps
);
257 pSubPicProviderEx
->GetStartStop(pos
, fps
, m_subpic_start
, m_subpic_stop
);
259 pSubPicProviderEx
->Unlock();
264 bool SimpleSubPicProvider::IsSpdColorTypeSupported( int type
)
268 (type
==MSP_XY_AUYV
&& m_alpha_blt_dst_type
== MSP_YUY2
)
270 (type
==MSP_AYUV
&& m_alpha_blt_dst_type
== MSP_AYUV
)//ToDo: fix me MSP_AYUV
272 (type
==MSP_AYUV_PLANAR
&& (m_alpha_blt_dst_type
== MSP_IYUV
||
273 m_alpha_blt_dst_type
== MSP_YV12
||
274 m_alpha_blt_dst_type
== MSP_P010
||
275 m_alpha_blt_dst_type
== MSP_P016
||
276 m_alpha_blt_dst_type
== MSP_NV12
||
277 m_alpha_blt_dst_type
== MSP_NV21
)) )
284 //////////////////////////////////////////////////////////////////////////
286 // SimpleSubPicProvider2
289 SimpleSubPicProvider2::SimpleSubPicProvider2( int alpha_blt_dst_type
, SIZE max_size
, SIZE cur_size
, RECT video_rect
,
290 IDirectVobSubXy
*consumer
, HRESULT
* phr
/*=NULL*/)
291 : CUnknown(NAME("SimpleSubPicProvider2"), NULL
)
292 , m_alpha_blt_dst_type(alpha_blt_dst_type
)
293 , m_max_size(max_size
)
294 , m_cur_size(cur_size
)
295 , m_video_rect(video_rect
)
298 , m_consumer(consumer
)
302 *phr
= consumer
? S_OK
: E_INVALIDARG
;
304 m_ex_provider
= NULL
;
305 m_old_provider
= NULL
;
306 m_cur_provider
= NULL
;
309 SimpleSubPicProvider2::~SimpleSubPicProvider2()
311 delete m_ex_provider
;
312 delete m_old_provider
;
315 STDMETHODIMP
SimpleSubPicProvider2::NonDelegatingQueryInterface( REFIID riid
, void** ppv
)
318 QI(ISimpleSubPicProvider
)
319 __super::NonDelegatingQueryInterface(riid
, ppv
);
322 STDMETHODIMP
SimpleSubPicProvider2::SetSubPicProvider( IUnknown
* subpic_provider
)
324 const int MAX_SUBPIC_QUEUE_LENGTH
= 1;
326 CComQIPtr
<ISubPicProviderEx2
> tmp
= subpic_provider
;
329 m_cur_provider
= NULL
;
330 delete m_old_provider
;
331 m_old_provider
= NULL
;
334 m_ex_provider
= new SimpleSubPicProvider(m_alpha_blt_dst_type
, m_cur_size
, m_video_rect
, m_consumer
, &hr
);
335 m_ex_provider
->SetFPS(m_fps
);
336 m_ex_provider
->SetTime(m_now
);
338 if (m_ex_provider
==NULL
)
340 ASSERT(m_ex_provider
!=NULL
);
343 m_cur_provider
= m_ex_provider
;
347 m_cur_provider
= NULL
;
348 delete m_ex_provider
;
349 m_ex_provider
= NULL
;
352 CComPtr
<ISubPicExAllocator
> pSubPicAllocator
= new CPooledSubPicAllocator(m_alpha_blt_dst_type
,
353 m_max_size
, MAX_SUBPIC_QUEUE_LENGTH
+ 1);
354 ASSERT(pSubPicAllocator
);
355 pSubPicAllocator
->SetCurSize(m_cur_size
);
356 pSubPicAllocator
->SetCurVidRect(m_video_rect
);
357 m_old_provider
= new CSubPicQueueNoThread(pSubPicAllocator
, &hr
);
358 m_old_provider
->SetFPS(m_fps
);
359 m_old_provider
->SetTime(m_now
);
360 if (FAILED(hr
) || m_old_provider
==NULL
)
362 ASSERT(SUCCEEDED(hr
));
366 m_cur_provider
= m_old_provider
;
368 return m_cur_provider
->SetSubPicProvider(subpic_provider
);
371 STDMETHODIMP
SimpleSubPicProvider2::GetSubPicProvider( IUnknown
** subpic_provider
)
373 ASSERT(m_cur_provider
);
378 return m_cur_provider
->GetSubPicProvider(subpic_provider
);
381 STDMETHODIMP
SimpleSubPicProvider2::SetFPS( double fps
)
384 ASSERT(m_cur_provider
);
389 return m_cur_provider
->SetFPS(fps
);
392 STDMETHODIMP
SimpleSubPicProvider2::SetTime( REFERENCE_TIME rtNow
)
395 ASSERT(m_cur_provider
);
400 return m_cur_provider
->SetTime(rtNow
);
403 STDMETHODIMP
SimpleSubPicProvider2::Invalidate( REFERENCE_TIME rtInvalidate
/*= -1*/ )
405 //ASSERT(m_cur_provider);
410 return m_cur_provider
->Invalidate(rtInvalidate
);
413 STDMETHODIMP_(bool) SimpleSubPicProvider2::LookupSubPic( REFERENCE_TIME now
/*[in]*/, ISimpleSubPic
** output_subpic
/*[out]*/ )
415 ASSERT(m_cur_provider
);
420 return m_cur_provider
->LookupSubPic(now
, output_subpic
);
423 STDMETHODIMP
SimpleSubPicProvider2::GetStats( int& nSubPics
, REFERENCE_TIME
& rtNow
, REFERENCE_TIME
& rtStart
, REFERENCE_TIME
& rtStop
)
426 ASSERT(m_cur_provider
);
431 return m_cur_provider
->GetStats(nSubPics
, rtNow
, rtStart
, rtStop
);
434 STDMETHODIMP
SimpleSubPicProvider2::GetStats( int nSubPic
, REFERENCE_TIME
& rtStart
, REFERENCE_TIME
& rtStop
)
436 ASSERT(m_cur_provider
);
441 return m_cur_provider
->GetStats(nSubPic
, rtStart
, rtStop
);