2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 #include "DirectVobSubFilter.h"
26 #include "TextInputPin.h"
27 #include "DirectVobSubPropPage.h"
30 #include "../../../DSUtil/MediaTypes.h"
31 #include "../../../SubPic/SubPicQueueImpl.h"
32 #include "../../../SubPic/PooledSubPic.h"
33 #include "../../../subpic/color_conv_table.h"
36 #include "..\..\..\..\include\moreuuids.h"
38 #include "CAutoTiming.h"
39 #include "xy_logger.h"
41 #define MAX_SUBPIC_QUEUE_LENGTH 1
43 ///////////////////////////////////////////////////////////////////////////
46 bool g_RegOK
= true;//false; // doesn't work with the dvd graph builder
50 EXTERN_C IMAGE_DOS_HEADER __ImageBase
;
53 ////////////////////////////////////////////////////////////////////////////
58 CDirectVobSubFilter::CDirectVobSubFilter(LPUNKNOWN punk
, HRESULT
* phr
, const GUID
& clsid
)
59 : CBaseVideoFilter(NAME("CDirectVobSubFilter"), punk
, phr
, clsid
)
61 , m_fMSMpeg4Fix(false)
64 DbgLog((LOG_TRACE
, 3, _T("CDirectVobSubFilter::CDirectVobSubFilter")));
66 // and then, anywhere you need it:
69 LPTSTR strDLLPath
= new TCHAR
[_MAX_PATH
];
70 ::GetModuleFileName( reinterpret_cast<HINSTANCE
>(&__ImageBase
), strDLLPath
, _MAX_PATH
);
71 CString dllPath
= strDLLPath
;
72 dllPath
+= ".properties";
73 xy_logger::doConfigure( dllPath
.GetString() );
76 AFX_MANAGE_STATE(AfxGetStaticModuleState());
84 memset(&lf
, 0, sizeof(lf
));
85 lf
.lfCharSet
= DEFAULT_CHARSET
;
86 lf
.lfOutPrecision
= OUT_CHARACTER_PRECIS
;
87 lf
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
88 lf
.lfQuality
= ANTIALIASED_QUALITY
;
89 HDC hdc
= GetDC(NULL
);
91 //MulDiv(20, GetDeviceCaps(hdc, LOGPIXELSY), 54);
93 lf
.lfWeight
= FW_BOLD
;
94 _tcscpy(lf
.lfFaceName
, _T("Arial"));
95 m_hfont
= CreateFontIndirect(&lf
);
98 theApp
.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES
), _T("Hint"), _T("The first three are fixed, but you can add more up to ten entries."));
99 theApp
.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES
), _T("Path0"), _T("."));
100 theApp
.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES
), _T("Path1"), _T("c:\\subtitles"));
101 theApp
.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES
), _T("Path2"), _T(".\\subtitles"));
105 m_hSystrayThread
= 0;
106 m_tbid
.hSystrayWnd
= NULL
;
108 m_tbid
.fRunOnce
= false;
109 m_tbid
.fShowIcon
= (theApp
.m_AppName
.Find(_T("zplayer"), 0) < 0 || !!theApp
.GetProfileInt(ResStr(IDS_R_GENERAL
), ResStr(IDS_RG_ENABLEZPICON
), 0));
112 m_pTextInput
.Add(new CTextInputPin(this, m_pLock
, &m_csSubLock
, &hr
));
113 ASSERT(SUCCEEDED(hr
));
116 m_frd
.EndThreadEvent
.Create(0, FALSE
, FALSE
, 0);
117 m_frd
.RefreshEvent
.Create(0, FALSE
, FALSE
, 0);
119 memset(&m_CurrentVIH2
, 0, sizeof(VIDEOINFOHEADER2
));
121 m_donot_follow_upstream_preferred_order
= !m_fFollowUpstreamPreferredOrder
;
123 m_time_alphablt
= m_time_rasterization
= 0;
126 CDirectVobSubFilter::~CDirectVobSubFilter()
128 CAutoLock
cAutoLock(&m_csQueueLock
);
131 DbgLog((LOG_TRACE
, 3, "~CDirectVobSubFilter::Invalidate"));
132 m_pSubPicQueue
->Invalidate();
134 m_pSubPicQueue
= NULL
;
136 if(m_hfont
) {DeleteObject(m_hfont
); m_hfont
= 0;}
137 if(m_hbm
) {DeleteObject(m_hbm
); m_hbm
= 0;}
138 if(m_hdc
) {DeleteObject(m_hdc
); m_hdc
= 0;}
140 for(int i
= 0; i
< m_pTextInput
.GetCount(); i
++)
141 delete m_pTextInput
[i
];
143 m_frd
.EndThreadEvent
.Set();
146 DbgLog((LOG_TRACE
, 3, _T("CDirectVobSubFilter::~CDirectVobSubFilter")));
148 //Trace(_T("CDirectVobSubFilter::~CDirectVobSubFilter"));
152 STDMETHODIMP
CDirectVobSubFilter::NonDelegatingQueryInterface(REFIID riid
, void** ppv
)
154 CheckPointer(ppv
, E_POINTER
);
160 QI(ISpecifyPropertyPages
)
162 __super::NonDelegatingQueryInterface(riid
, ppv
);
167 void CDirectVobSubFilter::GetOutputSize(int& w
, int& h
, int& arx
, int& ary
)
169 CSize
s(w
, h
), os
= s
;
176 while(arx
< 100) arx
*= 10, ary
*= 10;
177 arx
= arx
* w
/ os
.cx
;
182 while(ary
< 100) arx
*= 10, ary
*= 10;
183 ary
= ary
* h
/ os
.cy
;
187 HRESULT
CDirectVobSubFilter::TryNotCopy(IMediaSample
* pIn
, const CMediaType
& mt
, const BITMAPINFOHEADER
& bihIn
)
190 CSize
in(bihIn
.biWidth
, bihIn
.biHeight
);
191 BYTE
* pDataIn
= NULL
;
192 if(FAILED(pIn
->GetPointer(&pDataIn
)) || !pDataIn
)
196 m_spd
.bits
= pDataIn
;
200 m_spd
.bits
= static_cast<BYTE
*>(m_pTempPicBuff
);
201 bool fYV12
= (mt
.subtype
== MEDIASUBTYPE_YV12
|| mt
.subtype
== MEDIASUBTYPE_I420
|| mt
.subtype
== MEDIASUBTYPE_IYUV
);
202 bool fNV12
= (mt
.subtype
== MEDIASUBTYPE_NV12
|| mt
.subtype
== MEDIASUBTYPE_NV21
);
203 bool fP010
= (mt
.subtype
== MEDIASUBTYPE_P010
|| mt
.subtype
== MEDIASUBTYPE_P016
);
205 int bpp
= fP010
? 16 : (fYV12
||fNV12
) ? 8 : bihIn
.biBitCount
;
206 DWORD black
= fP010
? 0x10001000 : (fYV12
||fNV12
) ? 0x10101010 : (bihIn
.biCompression
== '2YUY') ? 0x80108010 : 0;
209 if(FAILED(Copy((BYTE
*)m_pTempPicBuff
, pDataIn
, sub
, in
, bpp
, mt
.subtype
, black
)))
214 BYTE
* pSubV
= (BYTE
*)m_pTempPicBuff
+ (sub
.cx
*bpp
>>3)*sub
.cy
;
215 BYTE
* pInV
= pDataIn
+ (in
.cx
*bpp
>>3)*in
.cy
;
216 sub
.cx
>>= 1; sub
.cy
>>= 1; in
.cx
>>= 1; in
.cy
>>= 1;
217 BYTE
* pSubU
= pSubV
+ (sub
.cx
*bpp
>>3)*sub
.cy
;
218 BYTE
* pInU
= pInV
+ (in
.cx
*bpp
>>3)*in
.cy
;
219 if(FAILED(Copy(pSubV
, pInV
, sub
, in
, bpp
, mt
.subtype
, 0x80808080)))
221 if(FAILED(Copy(pSubU
, pInU
, sub
, in
, bpp
, mt
.subtype
, 0x80808080)))
226 BYTE
* pSubUV
= (BYTE
*)m_pTempPicBuff
+ (sub
.cx
*bpp
>>3)*sub
.cy
;
227 BYTE
* pInUV
= pDataIn
+ (in
.cx
*bpp
>>3)*in
.cy
;
228 sub
.cy
>>= 1; in
.cy
>>= 1;
229 if(FAILED(Copy(pSubUV
, pInUV
, sub
, in
, bpp
, mt
.subtype
, 0x80008000)))
233 BYTE
* pSubUV
= (BYTE
*)m_pTempPicBuff
+ (sub
.cx
*bpp
>>3)*sub
.cy
;
234 BYTE
* pInUV
= pDataIn
+ (in
.cx
*bpp
>>3)*in
.cy
;
237 if(FAILED(Copy(pSubUV
, pInUV
, sub
, in
, bpp
, mt
.subtype
, 0x80808080)))
244 HRESULT
CDirectVobSubFilter::Transform(IMediaSample
* pIn
)
246 XY_LOG_ONCE(0, _T("CDirectVobSubFilter::Transform"));
250 REFERENCE_TIME rtStart
, rtStop
;
251 if(SUCCEEDED(pIn
->GetTime(&rtStart
, &rtStop
)))
253 double dRate
= m_pInput
->CurrentRate();
255 m_tPrev
= m_pInput
->CurrentStartTime() + dRate
*rtStart
;
257 REFERENCE_TIME rtAvgTimePerFrame
= rtStop
- rtStart
;
258 if(CComQIPtr
<ISubClock2
> pSC2
= m_pSubClock
)
261 if(S_OK
== pSC2
->GetAvgTimePerFrame(&rt
))
262 rtAvgTimePerFrame
= rt
;
265 m_fps
= 10000000.0/rtAvgTimePerFrame
/ dRate
;
271 CAutoLock
cAutoLock(&m_csQueueLock
);
275 m_pSubPicQueue
->SetTime(CalcCurrentTime());
276 m_pSubPicQueue
->SetFPS(m_fps
);
283 const CMediaType
& mt
= m_pInput
->CurrentMediaType();
285 BITMAPINFOHEADER bihIn
;
286 ExtractBIH(&mt
, &bihIn
);
288 hr
= TryNotCopy(pIn
, mt
, bihIn
);
296 SubPicDesc spd
= m_spd
;
298 CComPtr
<IMediaSample
> pOut
;
299 BYTE
* pDataOut
= NULL
;
300 if(FAILED(hr
= GetDeliveryBuffer(spd
.w
, spd
.h
, &pOut
))
301 || FAILED(hr
= pOut
->GetPointer(&pDataOut
)))
303 pOut
->SetTime(&rtStart
, &rtStop
);
304 pOut
->SetMediaTime(NULL
, NULL
);
305 pOut
->SetDiscontinuity(pIn
->IsDiscontinuity() == S_OK
);
306 pOut
->SetSyncPoint(pIn
->IsSyncPoint() == S_OK
);
307 pOut
->SetPreroll(pIn
->IsPreroll() == S_OK
);
310 BITMAPINFOHEADER bihOut
;
311 ExtractBIH(&m_pOutput
->CurrentMediaType(), &bihOut
);
313 bool fInputFlipped
= bihIn
.biHeight
>= 0 && bihIn
.biCompression
<= 3;
314 bool fOutputFlipped
= bihOut
.biHeight
>= 0 && bihOut
.biCompression
<= 3;
316 bool fFlip
= fInputFlipped
!= fOutputFlipped
;
317 if(m_fFlipPicture
) fFlip
= !fFlip
;
318 if(m_fMSMpeg4Fix
) fFlip
= !fFlip
;
320 bool fFlipSub
= fOutputFlipped
;
321 if(m_fFlipSubtitles
) fFlipSub
= !fFlipSub
;
326 CAutoLock
cAutoLock(&m_csQueueLock
);
330 CComPtr
<ISubPicEx
> pSubPic
;
332 //int timeStamp1 = GetTickCount();
333 bool lookupResult
= SUCCEEDED(m_pSubPicQueue
->LookupSubPicEx(CalcCurrentTime(), &pSubPic
));
334 //int timeStamp2 = GetTickCount();
335 //m_time_rasterization += timeStamp2-timeStamp1;
337 if(lookupResult
&& pSubPic
)
340 //pSubPic->GetDirtyRect(r);
341 CAtlList
<const CRect
> rectList
;
342 pSubPic
->GetDirtyRects(rectList
);
347 POSITION pos
= rectList
.GetHeadPosition();
350 const CRect
& cRect
= rectList
.GetNext(pos
);
351 pSubPic
->AlphaBlt(cRect
, cRect
, &spd
);
352 //pSubPic->AlphaBlt(r, r, &spd);
355 //m_time_alphablt += GetTickCount() - timeStamp2;
357 DbgLog((LOG_TRACE
,3,"AlphaBlt time:%lu", (ULONG
)(CalcCurrentTime()/10000)));
361 CopyBuffer(pDataOut
, (BYTE
*)spd
.bits
, spd
.w
, abs(spd
.h
)*(fFlip
?-1:1), spd
.pitch
, mt
.subtype
);
363 PrintMessages(pDataOut
);
364 return m_pOutput
->Deliver(pOut
);
369 CBasePin
* CDirectVobSubFilter::GetPin(int n
)
371 if(n
< __super::GetPinCount())
372 return __super::GetPin(n
);
374 n
-= __super::GetPinCount();
376 if(n
>= 0 && n
< m_pTextInput
.GetCount())
377 return m_pTextInput
[n
];
379 n
-= m_pTextInput
.GetCount();
384 int CDirectVobSubFilter::GetPinCount()
386 return __super::GetPinCount() + m_pTextInput
.GetCount();
389 HRESULT
CDirectVobSubFilter::JoinFilterGraph(IFilterGraph
* pGraph
, LPCWSTR pName
)
393 AFX_MANAGE_STATE(AfxGetStaticModuleState());
395 if(!theApp
.GetProfileInt(ResStr(IDS_R_GENERAL
), ResStr(IDS_RG_SEENDIVXWARNING
), 0))
397 unsigned __int64 ver
= GetFileVersion(_T("divx_c32.ax"));
398 if(((ver
>> 48)&0xffff) == 4 && ((ver
>> 32)&0xffff) == 2)
400 DWORD dwVersion
= GetVersion();
401 DWORD dwWindowsMajorVersion
= (DWORD
)(LOBYTE(LOWORD(dwVersion
)));
402 DWORD dwWindowsMinorVersion
= (DWORD
)(HIBYTE(LOWORD(dwVersion
)));
404 if(dwVersion
< 0x80000000 && dwWindowsMajorVersion
>= 5)
406 AfxMessageBox(IDS_DIVX_WARNING
);
407 theApp
.WriteProfileInt(ResStr(IDS_R_GENERAL
), ResStr(IDS_RG_SEENDIVXWARNING
), 1);
423 SendMessage(m_tbid
.hSystrayWnd
, WM_CLOSE
, 0, 0);
425 if(WaitForSingleObject(m_hSystrayThread
, 10000) != WAIT_OBJECT_0
)
427 DbgLog((LOG_TRACE
, 0, _T("CALL THE AMBULANCE!!!")));
428 TerminateThread(m_hSystrayThread
, (DWORD
)-1);
431 m_hSystrayThread
= 0;
435 return __super::JoinFilterGraph(pGraph
, pName
);
438 STDMETHODIMP
CDirectVobSubFilter::QueryFilterInfo(FILTER_INFO
* pInfo
)
440 CheckPointer(pInfo
, E_POINTER
);
441 ValidateReadWritePtr(pInfo
, sizeof(FILTER_INFO
));
444 return __super::QueryFilterInfo(pInfo
);
446 wcscpy(pInfo
->achName
, L
"DirectVobSub (forced auto-loading version)");
447 if(pInfo
->pGraph
= m_pGraph
) m_pGraph
->AddRef();
454 HRESULT
CDirectVobSubFilter::SetMediaType(PIN_DIRECTION dir
, const CMediaType
* pmt
)
456 HRESULT hr
= __super::SetMediaType(dir
, pmt
);
457 if(FAILED(hr
)) return hr
;
459 if(dir
== PINDIR_INPUT
)
461 CAutoLock
cAutoLock(&m_csReceive
);
463 REFERENCE_TIME atpf
=
464 pmt
->formattype
== FORMAT_VideoInfo
? ((VIDEOINFOHEADER
*)pmt
->Format())->AvgTimePerFrame
:
465 pmt
->formattype
== FORMAT_VideoInfo2
? ((VIDEOINFOHEADER2
*)pmt
->Format())->AvgTimePerFrame
:
468 m_fps
= atpf
? 10000000.0 / atpf
: 25;
470 if (pmt
->formattype
== FORMAT_VideoInfo2
)
471 m_CurrentVIH2
= *(VIDEOINFOHEADER2
*)pmt
->Format();
473 DbgLog((LOG_TRACE
, 3, "SetMediaType => InitSubPicQueue"));
476 else if(dir
== PINDIR_OUTPUT
)
484 HRESULT
CDirectVobSubFilter::CheckConnect(PIN_DIRECTION dir
, IPin
* pPin
)
486 if(dir
== PINDIR_INPUT
)
489 else if(dir
== PINDIR_OUTPUT
)
492 if(HmGyanusVagyTeNekem(pPin
)) return(E_FAIL
);
495 return __super::CheckConnect(dir
, pPin
);
498 HRESULT
CDirectVobSubFilter::CompleteConnect(PIN_DIRECTION dir
, IPin
* pReceivePin
)
500 bool reconnected
= false;
501 if(dir
== PINDIR_INPUT
)
503 DbgLog((LOG_TRACE
, 3, TEXT("connect input")));
504 DumpGraph(m_pGraph
,0);
505 CComPtr
<IBaseFilter
> pFilter
;
507 // needed when we have a decoder with a version number of 3.x
508 if(SUCCEEDED(m_pGraph
->FindFilterByName(L
"DivX MPEG-4 DVD Video Decompressor ", &pFilter
))
509 && (GetFileVersion(_T("divx_c32.ax")) >> 48) <= 4
510 || SUCCEEDED(m_pGraph
->FindFilterByName(L
"Microcrap MPEG-4 Video Decompressor", &pFilter
))
511 || SUCCEEDED(m_pGraph
->FindFilterByName(L
"Microsoft MPEG-4 Video Decompressor", &pFilter
))
512 && (GetFileVersion(_T("mpg4ds32.ax")) >> 48) <= 3)
514 m_fMSMpeg4Fix
= true;
517 else if(dir
== PINDIR_OUTPUT
)
519 DbgLog((LOG_TRACE
, 3, TEXT("connect output")));
520 DumpGraph(m_pGraph
,0);
521 const CMediaType
* mtIn
= &(m_pInput
->CurrentMediaType());
522 const CMediaType
* mtOut
= &(m_pOutput
->CurrentMediaType());
523 CMediaType desiredMt
;
527 bool can_reconnect
= false;
528 bool can_transform
= (DoCheckTransform(mtIn
, mtOut
, true)==S_OK
);
529 if( mtIn
->subtype
!=mtOut
->subtype
)
531 position
= GetOutputSubtypePosition(mtOut
->subtype
);
534 hr
= GetMediaType(position
, &desiredMt
);
537 DbgLog((LOG_ERROR
, 3, TEXT("Unexpected error when GetMediaType, position:%d"), position
));
541 hr
= DoCheckTransform(&desiredMt
, mtOut
, true);
544 DbgLog((LOG_TRACE
, 3, TEXT("Transform not accept:")));
545 DisplayType(0,&desiredMt
);
546 DisplayType(0,mtOut
);
550 hr
= m_pInput
->GetConnected()->QueryAccept(&desiredMt
);
553 DbgLog((LOG_TRACE
, 3, TEXT("Upstream not accept:")));
554 DisplayType(0, &desiredMt
);
558 can_reconnect
= true;
559 DbgLog((LOG_ERROR
, 3, TEXT("Can use the same subtype!")));
566 DbgLog((LOG_ERROR
, 3, TEXT("Cannot use the same subtype!")));
569 if(!can_reconnect
&& !can_transform
)
574 hr
= GetMediaType(position
, &desiredMt
);
580 DbgLog((LOG_TRACE
, 3, TEXT("Checking reconnect with media type:")));
581 DisplayType(0, &desiredMt
);
583 if( DoCheckTransform(&desiredMt
, mtOut
, true)!=S_OK
||
584 m_pInput
->GetConnected()->QueryAccept(&desiredMt
)!=S_OK
)
590 can_reconnect
= true;
597 if (SUCCEEDED(ReconnectPin(m_pInput
, &desiredMt
)))
600 DumpGraph(m_pGraph
,0);
601 //m_pInput->SetMediaType(&desiredMt);
602 DbgLog((LOG_TRACE
, 3, TEXT("reconnected succeed!")));
605 else if(!can_transform
)
607 DbgLog((LOG_TRACE
, 3, TEXT("Failed to agree reconnect type!")));
608 if(m_pInput
->IsConnected())
610 m_pInput
->GetConnected()->Disconnect();
611 m_pInput
->Disconnect();
613 if(m_pOutput
->IsConnected())
615 m_pOutput
->GetConnected()->Disconnect();
616 m_pOutput
->Disconnect();
618 return VFW_E_TYPE_NOT_ACCEPTED
;
621 if (!reconnected
&& m_pOutput
->IsConnected())
623 if(!m_hSystrayThread
)
625 m_tbid
.graph
= m_pGraph
;
626 m_tbid
.dvs
= static_cast<IDirectVobSub
*>(this);
629 m_hSystrayThread
= CreateThread(0, 0, SystrayThreadProc
, &m_tbid
, 0, &tid
);
631 m_pInput
->SetMediaType( &m_pInput
->CurrentMediaType() );
634 HRESULT hr
= __super::CompleteConnect(dir
, pReceivePin
);
635 DbgLog((LOG_TRACE
, 3, TEXT("connect fininshed!")));
636 DumpGraph(m_pGraph
,0);
640 HRESULT
CDirectVobSubFilter::BreakConnect(PIN_DIRECTION dir
)
642 if(dir
== PINDIR_INPUT
)
644 //if(m_pOutput->IsConnected())
646 // m_pOutput->GetConnected()->Disconnect();
647 // m_pOutput->Disconnect();
650 else if(dir
== PINDIR_OUTPUT
)
652 // not really needed, but may free up a little memory
653 CAutoLock
cAutoLock(&m_csQueueLock
);
654 m_pSubPicQueue
= NULL
;
657 return __super::BreakConnect(dir
);
660 HRESULT
CDirectVobSubFilter::StartStreaming()
662 /* WARNING: calls to m_pGraph member functions from within this function will generate deadlock with Haali
663 * Video Renderer in MPC. Reason is that CAutoLock's variables in IFilterGraph functions are overriden by
669 DbgLog((LOG_TRACE
, 3, "StartStreaming => InitSubPicQueue"));
672 m_tbid
.fRunOnce
= true;
674 put_MediaFPS(m_fMediaFPSEnabled
, m_MediaFPS
);
676 return __super::StartStreaming();
679 HRESULT
CDirectVobSubFilter::StopStreaming()
681 InvalidateSubtitle();
684 //FILE * timingFile = fopen("C:\\vsfilter_timing.txt", "at");
685 //fprintf(timingFile, "%s:%ld %s:%ld\n", "m_time_alphablt", m_time_alphablt, "m_time_rasterization", m_time_rasterization);
686 //fclose(timingFile);
688 return __super::StopStreaming();
691 HRESULT
CDirectVobSubFilter::NewSegment(REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
694 return __super::NewSegment(tStart
, tStop
, dRate
);
699 REFERENCE_TIME
CDirectVobSubFilter::CalcCurrentTime()
701 REFERENCE_TIME rt
= m_pSubClock
? m_pSubClock
->GetTime() : m_tPrev
;
702 return (rt
- 10000i64
*m_SubtitleDelay
) * m_SubtitleSpeedMul
/ m_SubtitleSpeedDiv
; // no, it won't overflow if we use normal parameters (__int64 is enough for about 2000 hours if we multiply it by the max: 65536 as m_SubtitleSpeedMul)
705 void CDirectVobSubFilter::InitSubPicQueue()
707 CAutoLock
cAutoLock(&m_csQueueLock
);
708 switch(m_colourSpace
)
710 case CDirectVobSub::BT_601
:
711 ColorConvTable::SetDefaultYUVType(ColorConvTable::BT601
);
713 case CDirectVobSub::BT_709
:
714 ColorConvTable::SetDefaultYUVType(ColorConvTable::BT709
);
716 case CDirectVobSub::AUTO_GUESS
:
717 ColorConvTable::SetDefaultYUVType( (m_w
> m_bt601Width
|| m_h
> m_bt601Height
) ?
718 ColorConvTable::BT709
: ColorConvTable::BT601
);
721 CacheManager::GetPathDataMruCache()->SetMaxItemNum(m_path_data_cache_max_item_num
);
722 CacheManager::GetScanLineDataMruCache()->SetMaxItemNum(m_scan_line_data_cache_max_item_num
);
723 CacheManager::GetOverlayNoBlurMruCache()->SetMaxItemNum(m_overlay_no_blur_cache_max_item_num
);
724 CacheManager::GetOverlayMruCache()->SetMaxItemNum(m_overlay_cache_max_item_num
);
725 SubpixelPositionControler::GetGlobalControler().SetSubpixelLevel( static_cast<SubpixelPositionControler::SUBPIXEL_LEVEL
>(m_subpixel_pos_level
) );
727 m_pSubPicQueue
= NULL
;
729 const GUID
& subtype
= m_pInput
->CurrentMediaType().subtype
;
731 BITMAPINFOHEADER bihIn
;
732 ExtractBIH(&m_pInput
->CurrentMediaType(), &bihIn
);
736 if(subtype
== MEDIASUBTYPE_YV12
) m_spd
.type
= MSP_YV12
;
737 else if(subtype
== MEDIASUBTYPE_P010
) m_spd
.type
= MSP_P010
;
738 else if(subtype
== MEDIASUBTYPE_P016
) m_spd
.type
= MSP_P016
;
739 else if(subtype
== MEDIASUBTYPE_I420
|| subtype
== MEDIASUBTYPE_IYUV
) m_spd
.type
= MSP_IYUV
;
740 else if(subtype
== MEDIASUBTYPE_YUY2
) m_spd
.type
= MSP_YUY2
;
741 else if(subtype
== MEDIASUBTYPE_RGB32
) m_spd
.type
= MSP_RGB32
;
742 else if(subtype
== MEDIASUBTYPE_RGB24
) m_spd
.type
= MSP_RGB24
;
743 else if(subtype
== MEDIASUBTYPE_RGB565
) m_spd
.type
= MSP_RGB16
;
744 else if(subtype
== MEDIASUBTYPE_RGB555
) m_spd
.type
= MSP_RGB15
;
745 else if(subtype
== MEDIASUBTYPE_NV12
) m_spd
.type
= MSP_NV12
;
746 else if(subtype
== MEDIASUBTYPE_NV21
) m_spd
.type
= MSP_NV21
;
750 m_spd
.bpp
= (m_spd
.type
== MSP_P010
|| m_spd
.type
== MSP_P016
) ? 16 :
751 (m_spd
.type
== MSP_YV12
|| m_spd
.type
== MSP_IYUV
|| m_spd
.type
== MSP_NV12
|| m_spd
.type
== MSP_NV21
) ? 8 : bihIn
.biBitCount
;
752 m_spd
.pitch
= m_spd
.w
*m_spd
.bpp
>>3;
754 m_pTempPicBuff
.Free();
755 if(m_spd
.type
== MSP_YV12
|| m_spd
.type
== MSP_IYUV
)
756 m_pTempPicBuff
.Allocate(4*m_spd
.pitch
*m_spd
.h
);
757 else if(m_spd
.type
== MSP_P010
|| m_spd
.type
== MSP_P016
)
758 m_pTempPicBuff
.Allocate(m_spd
.pitch
*m_spd
.h
+m_spd
.pitch
*m_spd
.h
/2);
760 m_pTempPicBuff
.Allocate(m_spd
.pitch
*m_spd
.h
);
761 m_spd
.bits
= (void*)m_pTempPicBuff
;
763 //CComPtr<ISubPicExAllocator> pSubPicAllocator = new CMemSubPicAllocator(m_spd.type, CSize(m_w, m_h));
764 CComPtr
<ISubPicExAllocator
> pSubPicAllocator
= new CPooledSubPicAllocator(m_spd
.type
, CSize(m_w
, m_h
), MAX_SUBPIC_QUEUE_LENGTH
+ 1);
765 if(pSubPicAllocator
==NULL
)
770 CSize
video(bihIn
.biWidth
, bihIn
.biHeight
), window
= video
;
771 if(AdjustFrameSize(window
)) video
+= video
;
772 ASSERT(window
== CSize(m_w
, m_h
));
774 pSubPicAllocator
->SetCurSize(window
);
775 pSubPicAllocator
->SetCurVidRect(CRect(CPoint((window
.cx
- video
.cx
)/2, (window
.cy
- video
.cy
)/2), video
));
778 //m_pSubPicQueue = m_fDoPreBuffering
779 // ? (ISubPicQueue*)new CSubPicQueue(MAX_SUBPIC_QUEUE_LENGTH, pSubPicAllocator, &hr)
780 // : (ISubPicQueue*)new CSubPicQueueNoThread(pSubPicAllocator, &hr);
781 m_pSubPicQueue
= new CSubPicQueueNoThread(pSubPicAllocator
, &hr
);
783 if(FAILED(hr
)) m_pSubPicQueue
= NULL
;
785 UpdateSubtitle(false);
787 if(m_hbm
) {DeleteObject(m_hbm
); m_hbm
= NULL
;}
788 if(m_hdc
) {DeleteDC(m_hdc
); m_hdc
= NULL
;}
790 struct {BITMAPINFOHEADER bih
; DWORD mask
[3];} b
= {{sizeof(BITMAPINFOHEADER
), m_w
, -(int)m_h
, 1, 32, BI_BITFIELDS
, 0, 0, 0, 0, 0}, 0xFF0000, 0x00FF00, 0x0000FF};
791 m_hdc
= CreateCompatibleDC(NULL
);
792 m_hbm
= CreateDIBSection(m_hdc
, (BITMAPINFO
*)&b
, DIB_RGB_COLORS
, NULL
, NULL
, 0);
795 GetObject(m_hbm
, sizeof(bm
), &bm
);
796 memsetd(bm
.bmBits
, 0xFF000000, bm
.bmHeight
*bm
.bmWidthBytes
);
799 bool CDirectVobSubFilter::AdjustFrameSize(CSize
& s
)
801 int horizontal
, vertical
, resx2
, resx2minw
, resx2minh
;
802 get_ExtendPicture(&horizontal
, &vertical
, &resx2
, &resx2minw
, &resx2minh
);
804 bool fRet
= (resx2
== 1) || (resx2
== 2 && s
.cx
*s
.cy
<= resx2minw
*resx2minh
);
813 switch(vertical
&0x7f)
817 if(s
.cy
< h
|| !!(vertical
&0x80)) s
.cy
= (h
+ 3) & ~3;
821 if(s
.cy
< h
|| !!(vertical
&0x80)) s
.cy
= (h
+ 3) & ~3;
825 if(s
.cy
< h
|| !!(vertical
&0x80)) s
.cy
= (h
+ 3) & ~3;
829 if(s
.cy
< h
|| !!(vertical
&0x80)) s
.cy
= (h
+ 3) & ~3;
835 s
.cx
= (s
.cx
+ 31) & ~31;
836 s
.cy
= (s
.cy
+ 1) & ~1;
842 STDMETHODIMP
CDirectVobSubFilter::Count(DWORD
* pcStreams
)
844 if(!pcStreams
) return E_POINTER
;
849 if(SUCCEEDED(get_LanguageCount(&nLangs
)))
850 (*pcStreams
) += nLangs
;
852 (*pcStreams
) += 2; // enable ... disable
854 (*pcStreams
) += 2; // normal flipped
859 #define MAXPREFLANGS 5
861 int CDirectVobSubFilter::FindPreferedLanguage(bool fHideToo
)
863 AFX_MANAGE_STATE(AfxGetStaticModuleState());
866 get_LanguageCount(&nLangs
);
868 if(nLangs
<= 0) return(0);
870 for(int i
= 0; i
< MAXPREFLANGS
; i
++)
873 tmp
.Format(IDS_RL_LANG
, i
);
875 CString lang
= theApp
.GetProfileString(ResStr(IDS_R_PREFLANGS
), tmp
);
879 for(int ret
= 0; ret
< nLangs
; ret
++)
883 get_LanguageName(ret
, &pName
);
885 CoTaskMemFree(pName
);
887 if(!l
.CompareNoCase(lang
)) return(ret
);
895 void CDirectVobSubFilter::UpdatePreferedLanguages(CString l
)
897 AFX_MANAGE_STATE(AfxGetStaticModuleState());
899 CString langs
[MAXPREFLANGS
+1];
901 int i
= 0, j
= 0, k
= -1;
902 for(; i
< MAXPREFLANGS
; i
++)
905 tmp
.Format(IDS_RL_LANG
, i
);
907 langs
[j
] = theApp
.GetProfileString(ResStr(IDS_R_PREFLANGS
), tmp
);
909 if(!langs
[j
].IsEmpty())
911 if(!langs
[j
].CompareNoCase(l
)) k
= j
;
922 // move the selected to the top of the list
926 CString tmp
= langs
[k
]; langs
[k
] = langs
[k
-1]; langs
[k
-1] = tmp
;
930 // move "Hide subtitles" to the last position if it wasn't our selection
933 hidesubs
.LoadString(IDS_M_HIDESUBTITLES
);
935 for(k
= 1; k
< j
; k
++)
937 if(!langs
[k
].CompareNoCase(hidesubs
)) break;
942 CString tmp
= langs
[k
]; langs
[k
] = langs
[k
+1]; langs
[k
+1] = tmp
;
946 for(i
= 0; i
< j
; i
++)
949 tmp
.Format(IDS_RL_LANG
, i
);
951 theApp
.WriteProfileString(ResStr(IDS_R_PREFLANGS
), tmp
, langs
[i
]);
955 STDMETHODIMP
CDirectVobSubFilter::Enable(long lIndex
, DWORD dwFlags
)
957 if(!(dwFlags
& AMSTREAMSELECTENABLE_ENABLE
))
961 get_LanguageCount(&nLangs
);
963 if(!(lIndex
>= 0 && lIndex
< nLangs
+2+2))
968 if(i
== -1 && !m_fLoading
) // we need this because when loading something stupid media player pushes the first stream it founds, which is "enable" in our case
970 put_HideSubtitles(false);
972 else if(i
>= 0 && i
< nLangs
)
974 put_HideSubtitles(false);
975 put_SelectedLanguage(i
);
978 if(SUCCEEDED(get_LanguageName(i
, &pName
)))
980 UpdatePreferedLanguages(CString(pName
));
981 if(pName
) CoTaskMemFree(pName
);
984 else if(i
== nLangs
&& !m_fLoading
)
986 put_HideSubtitles(true);
988 else if((i
== nLangs
+1 || i
== nLangs
+2) && !m_fLoading
)
990 put_Flip(i
== nLangs
+2, m_fFlipSubtitles
);
996 STDMETHODIMP
CDirectVobSubFilter::Info(long lIndex
, AM_MEDIA_TYPE
** ppmt
, DWORD
* pdwFlags
, LCID
* plcid
, DWORD
* pdwGroup
, WCHAR
** ppszName
, IUnknown
** ppObject
, IUnknown
** ppUnk
)
998 AFX_MANAGE_STATE(AfxGetStaticModuleState());
1001 get_LanguageCount(&nLangs
);
1003 if(!(lIndex
>= 0 && lIndex
< nLangs
+2+2))
1004 return E_INVALIDARG
;
1008 if(ppmt
) *ppmt
= CreateMediaType(&m_pInput
->CurrentMediaType());
1014 if(i
== -1 && !m_fHideSubtitles
1015 || i
>= 0 && i
< nLangs
&& i
== m_iSelectedLanguage
1016 || i
== nLangs
&& m_fHideSubtitles
1017 || i
== nLangs
+1 && !m_fFlipPicture
1018 || i
== nLangs
+2 && m_fFlipPicture
)
1020 *pdwFlags
|= AMSTREAMSELECTINFO_ENABLED
;
1024 if(plcid
) *plcid
= 0;
1026 if(pdwGroup
) *pdwGroup
= 0x648E51;
1033 if(i
== -1) str
= ResStr(IDS_M_SHOWSUBTITLES
);
1034 else if(i
>= 0 && i
< nLangs
) get_LanguageName(i
, ppszName
);
1035 else if(i
== nLangs
) str
= ResStr(IDS_M_HIDESUBTITLES
);
1036 else if(i
== nLangs
+1) {str
= ResStr(IDS_M_ORIGINALPICTURE
); if(pdwGroup
) (*pdwGroup
)++;}
1037 else if(i
== nLangs
+2) {str
= ResStr(IDS_M_FLIPPEDPICTURE
); if(pdwGroup
) (*pdwGroup
)++;}
1041 *ppszName
= (WCHAR
*)CoTaskMemAlloc((str
.GetLength()+1)*sizeof(WCHAR
));
1042 if(*ppszName
== NULL
) return S_FALSE
;
1043 wcscpy(*ppszName
, str
);
1047 if(ppObject
) *ppObject
= NULL
;
1049 if(ppUnk
) *ppUnk
= NULL
;
1054 STDMETHODIMP
CDirectVobSubFilter::GetClassID(CLSID
* pClsid
)
1056 if(pClsid
== NULL
) return E_POINTER
;
1061 STDMETHODIMP
CDirectVobSubFilter::GetPages(CAUUID
* pPages
)
1063 CheckPointer(pPages
, E_POINTER
);
1066 pPages
->pElems
= (GUID
*)CoTaskMemAlloc(sizeof(GUID
)*pPages
->cElems
);
1068 if(pPages
->pElems
== NULL
) return E_OUTOFMEMORY
;
1071 pPages
->pElems
[i
++] = __uuidof(CDVSMainPPage
);
1072 pPages
->pElems
[i
++] = __uuidof(CDVSGeneralPPage
);
1073 pPages
->pElems
[i
++] = __uuidof(CDVSMiscPPage
);
1074 pPages
->pElems
[i
++] = __uuidof(CDVSMorePPage
);
1075 pPages
->pElems
[i
++] = __uuidof(CDVSTimingPPage
);
1076 pPages
->pElems
[i
++] = __uuidof(CDVSColorPPage
);
1077 pPages
->pElems
[i
++] = __uuidof(CDVSPathsPPage
);
1078 pPages
->pElems
[i
++] = __uuidof(CDVSAboutPPage
);
1085 STDMETHODIMP
CDirectVobSubFilter::put_FileName(WCHAR
* fn
)
1087 AMTRACE((TEXT(__FUNCTION__
),0));
1088 HRESULT hr
= CDirectVobSub::put_FileName(fn
);
1090 if(hr
== S_OK
&& !Open())
1099 STDMETHODIMP
CDirectVobSubFilter::get_LanguageCount(int* nLangs
)
1101 HRESULT hr
= CDirectVobSub::get_LanguageCount(nLangs
);
1103 if(hr
== NOERROR
&& nLangs
)
1105 CAutoLock
cAutolock(&m_csQueueLock
);
1108 POSITION pos
= m_pSubStreams
.GetHeadPosition();
1109 while(pos
) (*nLangs
) += m_pSubStreams
.GetNext(pos
)->GetStreamCount();
1115 STDMETHODIMP
CDirectVobSubFilter::get_LanguageName(int iLanguage
, WCHAR
** ppName
)
1117 HRESULT hr
= CDirectVobSub::get_LanguageName(iLanguage
, ppName
);
1119 if(!ppName
) return E_POINTER
;
1123 CAutoLock
cAutolock(&m_csQueueLock
);
1129 POSITION pos
= m_pSubStreams
.GetHeadPosition();
1130 while(i
>= 0 && pos
)
1132 CComPtr
<ISubStream
> pSubStream
= m_pSubStreams
.GetNext(pos
);
1134 if(i
< pSubStream
->GetStreamCount())
1136 pSubStream
->GetStreamInfo(i
, ppName
, NULL
);
1141 i
-= pSubStream
->GetStreamCount();
1148 STDMETHODIMP
CDirectVobSubFilter::put_SelectedLanguage(int iSelected
)
1150 HRESULT hr
= CDirectVobSub::put_SelectedLanguage(iSelected
);
1154 UpdateSubtitle(false);
1160 STDMETHODIMP
CDirectVobSubFilter::put_HideSubtitles(bool fHideSubtitles
)
1162 HRESULT hr
= CDirectVobSub::put_HideSubtitles(fHideSubtitles
);
1166 UpdateSubtitle(false);
1172 STDMETHODIMP
CDirectVobSubFilter::put_PreBuffering(bool fDoPreBuffering
)
1174 HRESULT hr
= CDirectVobSub::put_PreBuffering(fDoPreBuffering
);
1178 DbgLog((LOG_TRACE
, 3, "put_PreBuffering => InitSubPicQueue"));
1185 STDMETHODIMP
CDirectVobSubFilter::put_ColourSpace(int colourSpace
)
1187 CAutoLock
cAutolock(&m_csQueueLock
);
1188 HRESULT hr
= CDirectVobSub::put_ColourSpace(colourSpace
);
1192 switch(m_colourSpace
)
1194 case ColourSpaceOption::BT_601
:
1195 ColorConvTable::SetDefaultYUVType(ColorConvTable::BT601
);
1197 case ColourSpaceOption::BT_709
:
1198 ColorConvTable::SetDefaultYUVType(ColorConvTable::BT709
);
1200 case ColourSpaceOption::AUTO_GUESS
:
1201 ColorConvTable::SetDefaultYUVType( (m_w
> m_bt601Width
|| m_h
> m_bt601Height
) ?
1202 ColorConvTable::BT709
: ColorConvTable::BT601
);
1210 STDMETHODIMP
CDirectVobSubFilter::put_Placement(bool fOverridePlacement
, int xperc
, int yperc
)
1212 DbgLog((LOG_TRACE
, 3, "%s(%d) %s", __FILE__
, __LINE__
, __FUNCTION__
));
1213 HRESULT hr
= CDirectVobSub::put_Placement(fOverridePlacement
, xperc
, yperc
);
1217 //DbgLog((LOG_TRACE, 3, "%d %s:UpdateSubtitle(true)", __LINE__, __FUNCTION__));
1218 //UpdateSubtitle(true);
1219 UpdateSubtitle(false);
1225 STDMETHODIMP
CDirectVobSubFilter::put_VobSubSettings(bool fBuffer
, bool fOnlyShowForcedSubs
, bool fReserved
)
1227 HRESULT hr
= CDirectVobSub::put_VobSubSettings(fBuffer
, fOnlyShowForcedSubs
, fReserved
);
1231 // UpdateSubtitle(false);
1232 InvalidateSubtitle();
1238 STDMETHODIMP
CDirectVobSubFilter::put_TextSettings(void* lf
, int lflen
, COLORREF color
, bool fShadow
, bool fOutline
, bool fAdvancedRenderer
)
1240 HRESULT hr
= CDirectVobSub::put_TextSettings(lf
, lflen
, color
, fShadow
, fOutline
, fAdvancedRenderer
);
1244 // UpdateSubtitle(true);
1245 InvalidateSubtitle();
1251 STDMETHODIMP
CDirectVobSubFilter::put_SubtitleTiming(int delay
, int speedmul
, int speeddiv
)
1253 HRESULT hr
= CDirectVobSub::put_SubtitleTiming(delay
, speedmul
, speeddiv
);
1257 InvalidateSubtitle();
1263 STDMETHODIMP
CDirectVobSubFilter::put_OverlayCacheMaxItemNum( int overlay_cache_max_item_num
)
1265 CAutoLock
cAutolock(&m_csQueueLock
);
1266 HRESULT hr
= CDirectVobSub::put_OverlayCacheMaxItemNum(overlay_cache_max_item_num
);
1270 CacheManager::GetOverlayMruCache()->SetMaxItemNum(m_overlay_cache_max_item_num
);
1276 STDMETHODIMP
CDirectVobSubFilter::put_ScanLineDataCacheMaxItemNum( int scan_line_data_cache_max_item_num
)
1278 CAutoLock
cAutolock(&m_csQueueLock
);
1279 HRESULT hr
= CDirectVobSub::put_ScanLineDataCacheMaxItemNum(scan_line_data_cache_max_item_num
);
1283 CacheManager::GetScanLineDataMruCache()->SetMaxItemNum(m_scan_line_data_cache_max_item_num
);
1289 STDMETHODIMP
CDirectVobSubFilter::put_PathDataCacheMaxItemNum(int path_data_cache_max_item_num
)
1291 CAutoLock
cAutolock(&m_csQueueLock
);
1292 HRESULT hr
= CDirectVobSub::put_PathDataCacheMaxItemNum(path_data_cache_max_item_num
);
1296 CacheManager::GetPathDataMruCache()->SetMaxItemNum(m_path_data_cache_max_item_num
);
1302 STDMETHODIMP
CDirectVobSubFilter::put_OverlayNoBlurCacheMaxItemNum(int overlay_no_blur_cache_max_item_num
)
1304 CAutoLock
cAutolock(&m_csQueueLock
);
1305 HRESULT hr
= CDirectVobSub::put_OverlayNoBlurCacheMaxItemNum(overlay_no_blur_cache_max_item_num
);
1309 CacheManager::GetOverlayNoBlurMruCache()->SetMaxItemNum(m_overlay_no_blur_cache_max_item_num
);
1315 STDMETHODIMP
CDirectVobSubFilter::get_CachesInfo(CachesInfo
* caches_info
)
1317 CAutoLock
cAutoLock(&m_csQueueLock
);
1318 HRESULT hr
= CDirectVobSub::get_CachesInfo(caches_info
);
1320 caches_info
->path_cache_cur_item_num
= CacheManager::GetPathDataMruCache()->GetCurItemNum();
1321 caches_info
->path_cache_hit_count
= CacheManager::GetPathDataMruCache()->GetCacheHitCount();
1322 caches_info
->path_cache_query_count
= CacheManager::GetPathDataMruCache()->GetQueryCount();
1323 caches_info
->scanline_cache_cur_item_num
= CacheManager::GetScanLineDataMruCache()->GetCurItemNum();
1324 caches_info
->scanline_cache_hit_count
= CacheManager::GetScanLineDataMruCache()->GetCacheHitCount();
1325 caches_info
->scanline_cache_query_count
= CacheManager::GetScanLineDataMruCache()->GetQueryCount();
1326 caches_info
->non_blur_cache_cur_item_num
= CacheManager::GetOverlayNoBlurMruCache()->GetCurItemNum();
1327 caches_info
->non_blur_cache_hit_count
= CacheManager::GetOverlayNoBlurMruCache()->GetCacheHitCount();
1328 caches_info
->non_blur_cache_query_count
= CacheManager::GetOverlayNoBlurMruCache()->GetQueryCount();
1329 caches_info
->overlay_cache_cur_item_num
= CacheManager::GetOverlayMruCache()->GetCurItemNum();
1330 caches_info
->overlay_cache_hit_count
= CacheManager::GetOverlayMruCache()->GetCacheHitCount();
1331 caches_info
->overlay_cache_query_count
= CacheManager::GetOverlayMruCache()->GetQueryCount();
1333 caches_info
->interpolate_cache_cur_item_num
= CacheManager::GetSubpixelVarianceCache()->GetCurItemNum();
1334 caches_info
->interpolate_cache_hit_count
= CacheManager::GetSubpixelVarianceCache()->GetCacheHitCount();
1335 caches_info
->interpolate_cache_query_count
= CacheManager::GetSubpixelVarianceCache()->GetQueryCount();
1336 caches_info
->text_info_cache_cur_item_num
= CacheManager::GetTextInfoCache()->GetCurItemNum();
1337 caches_info
->text_info_cache_hit_count
= CacheManager::GetTextInfoCache()->GetCacheHitCount();
1338 caches_info
->text_info_cache_query_count
= CacheManager::GetTextInfoCache()->GetQueryCount();
1340 caches_info
->word_info_cache_cur_item_num
= CacheManager::GetAssTagListMruCache()->GetCurItemNum();
1341 caches_info
->word_info_cache_hit_count
= CacheManager::GetAssTagListMruCache()->GetCacheHitCount();
1342 caches_info
->word_info_cache_query_count
= CacheManager::GetAssTagListMruCache()->GetQueryCount();
1347 STDMETHODIMP
CDirectVobSubFilter::put_SubpixelPositionLevel(int subpixel_pos_level
)
1349 CAutoLock
cAutolock(&m_csQueueLock
);
1350 HRESULT hr
= CDirectVobSub::put_SubpixelPositionLevel(subpixel_pos_level
);
1354 SubpixelPositionControler::GetGlobalControler().SetSubpixelLevel( static_cast<SubpixelPositionControler::SUBPIXEL_LEVEL
>(subpixel_pos_level
) );
1360 STDMETHODIMP
CDirectVobSubFilter::put_FollowUpstreamPreferredOrder( bool fFollowUpstreamPreferredOrder
)
1362 CAutoLock
cAutolock(&m_csQueueLock
);
1363 HRESULT hr
= CDirectVobSub::put_FollowUpstreamPreferredOrder(fFollowUpstreamPreferredOrder
);
1367 m_donot_follow_upstream_preferred_order
= !m_fFollowUpstreamPreferredOrder
;
1373 STDMETHODIMP
CDirectVobSubFilter::get_MediaFPS(bool* fEnabled
, double* fps
)
1375 HRESULT hr
= CDirectVobSub::get_MediaFPS(fEnabled
, fps
);
1377 CComQIPtr
<IMediaSeeking
> pMS
= m_pGraph
;
1379 if(pMS
&& SUCCEEDED(pMS
->GetRate(&rate
)))
1381 m_MediaFPS
= rate
* m_fps
;
1382 if(fps
) *fps
= m_MediaFPS
;
1388 STDMETHODIMP
CDirectVobSubFilter::put_MediaFPS(bool fEnabled
, double fps
)
1390 HRESULT hr
= CDirectVobSub::put_MediaFPS(fEnabled
, fps
);
1392 CComQIPtr
<IMediaSeeking
> pMS
= m_pGraph
;
1397 hr
= pMS
->SetRate(m_fMediaFPSEnabled
? m_MediaFPS
/ m_fps
: 1.0);
1401 if(SUCCEEDED(pMS
->GetRate(&dRate
)))
1402 m_MediaFPS
= dRate
* m_fps
;
1408 STDMETHODIMP
CDirectVobSubFilter::get_ZoomRect(NORMALIZEDRECT
* rect
)
1413 STDMETHODIMP
CDirectVobSubFilter::put_ZoomRect(NORMALIZEDRECT
* rect
)
1420 STDMETHODIMP
CDirectVobSubFilter::put_TextSettings(STSStyle
* pDefStyle
)
1422 HRESULT hr
= CDirectVobSub::put_TextSettings(pDefStyle
);
1426 //DbgLog((LOG_TRACE, 3, "%d %s:UpdateSubtitle(true)", __LINE__, __FUNCTION__));
1427 //UpdateSubtitle(true);
1428 UpdateSubtitle(false);
1434 STDMETHODIMP
CDirectVobSubFilter::put_AspectRatioSettings(CSimpleTextSubtitle::EPARCompensationType
* ePARCompensationType
)
1436 HRESULT hr
= CDirectVobSub::put_AspectRatioSettings(ePARCompensationType
);
1440 //DbgLog((LOG_TRACE, 3, "%d %s:UpdateSubtitle(true)", __LINE__, __FUNCTION__));
1441 //UpdateSubtitle(true);
1442 UpdateSubtitle(false);
1448 // IDirectVobSubFilterColor
1450 STDMETHODIMP
CDirectVobSubFilter::HasConfigDialog(int iSelected
)
1453 if(FAILED(get_LanguageCount(&nLangs
))) return E_FAIL
;
1455 // TODO: temporally disabled since we don't have a new textsub/vobsub editor dlg for dvs yet
1456 // return(nLangs >= 0 && iSelected < nLangs ? S_OK : E_FAIL);
1459 STDMETHODIMP
CDirectVobSubFilter::ShowConfigDialog(int iSelected
, HWND hWndParent
)
1461 // TODO: temporally disabled since we don't have a new textsub/vobsub editor dlg for dvs yet
1465 ///////////////////////////////////////////////////////////////////////////
1467 CDirectVobSubFilter2::CDirectVobSubFilter2(LPUNKNOWN punk
, HRESULT
* phr
, const GUID
& clsid
) :
1468 CDirectVobSubFilter(punk
, phr
, clsid
)
1472 HRESULT
CDirectVobSubFilter2::CheckConnect(PIN_DIRECTION dir
, IPin
* pPin
)
1475 if(FAILED(pPin
->QueryPinInfo(&pi
))) return E_FAIL
;
1477 if(CComQIPtr
<IDirectVobSub
>(pi
.pFilter
)) return E_FAIL
;
1479 if(dir
== PINDIR_INPUT
)
1482 if(SUCCEEDED(pi
.pFilter
->QueryFilterInfo(&fi
))
1483 && !wcsnicmp(fi
.achName
, L
"Overlay Mixer", 13))
1490 return __super::CheckConnect(dir
, pPin
);
1493 HRESULT
CDirectVobSubFilter2::JoinFilterGraph(IFilterGraph
* pGraph
, LPCWSTR pName
)
1495 XY_AUTO_TIMING(_T("CDirectVobSubFilter2::JoinFilterGraph"));
1498 BeginEnumFilters(pGraph
, pEF
, pBF
)
1500 if(pBF
!= (IBaseFilter
*)this && CComQIPtr
<IDirectVobSub
>(pBF
))
1505 // don't look... we will do some serious graph hacking again...
1507 // we will add dvs2 to the filter graph cache
1508 // - if the main app has already added some kind of renderer or overlay mixer (anything which accepts video on its input)
1510 // - if we have a reason to auto-load (we don't want to make any trouble when there is no need :)
1512 // This whole workaround is needed because the video stream will always be connected
1513 // to the pre-added filters first, no matter how high merit we have.
1517 BeginEnumFilters(pGraph
, pEF
, pBF
)
1519 if(CComQIPtr
<IDirectVobSub
>(pBF
))
1522 CComPtr
<IPin
> pInPin
= GetFirstPin(pBF
, PINDIR_INPUT
);
1523 CComPtr
<IPin
> pOutPin
= GetFirstPin(pBF
, PINDIR_OUTPUT
);
1529 if(pInPin
&& SUCCEEDED(pInPin
->ConnectedTo(&pPin
))
1530 || pOutPin
&& SUCCEEDED(pOutPin
->ConnectedTo(&pPin
)))
1533 if(pOutPin
&& GetFilterName(pBF
) == _T("Overlay Mixer"))
1536 bool fVideoInputPin
= false;
1540 BITMAPINFOHEADER bih
= {sizeof(BITMAPINFOHEADER
), 384, 288, 1, 16, '2YUY', 384*288*2, 0, 0, 0, 0};
1543 cmt
.majortype
= MEDIATYPE_Video
;
1544 cmt
.subtype
= MEDIASUBTYPE_YUY2
;
1545 cmt
.formattype
= FORMAT_VideoInfo
;
1547 cmt
.bFixedSizeSamples
= TRUE
;
1548 cmt
.bTemporalCompression
= TRUE
;
1549 cmt
.lSampleSize
= 384*288*2;
1550 VIDEOINFOHEADER
* vih
= (VIDEOINFOHEADER
*)cmt
.AllocFormatBuffer(sizeof(VIDEOINFOHEADER
));
1551 memset(vih
, 0, sizeof(VIDEOINFOHEADER
));
1552 memcpy(&vih
->bmiHeader
, &bih
, sizeof(bih
));
1553 vih
->AvgTimePerFrame
= 400000;
1555 if(SUCCEEDED(pInPin
->QueryAccept(&cmt
)))
1557 fVideoInputPin
= true;
1561 VIDEOINFOHEADER2
* vih2
= (VIDEOINFOHEADER2
*)cmt
.AllocFormatBuffer(sizeof(VIDEOINFOHEADER2
));
1562 memset(vih2
, 0, sizeof(VIDEOINFOHEADER2
));
1563 memcpy(&vih2
->bmiHeader
, &bih
, sizeof(bih
));
1564 vih2
->AvgTimePerFrame
= 400000;
1565 vih2
->dwPictAspectRatioX
= 384;
1566 vih2
->dwPictAspectRatioY
= 288;
1568 if(SUCCEEDED(pInPin
->QueryAccept(&cmt
)))
1570 fVideoInputPin
= true;
1578 CComPtr
<IBaseFilter
> pDVS
;
1579 if(ShouldWeAutoload(pGraph
) && SUCCEEDED(pDVS
.CoCreateInstance(__uuidof(CDirectVobSubFilter2
))))
1581 CComQIPtr
<IDirectVobSub2
>(pDVS
)->put_Forced(true);
1582 CComQIPtr
<IGraphConfig
>(pGraph
)->AddFilterToCache(pDVS
);
1595 return __super::JoinFilterGraph(pGraph
, pName
);
1598 HRESULT
CDirectVobSubFilter2::CheckInputType(const CMediaType
* mtIn
)
1600 XY_AUTO_TIMING(_T("CDirectVobSubFilter2::CheckInputType"));
1601 HRESULT hr
= __super::CheckInputType(mtIn
);
1603 if(FAILED(hr
) || m_pInput
->IsConnected()) return hr
;
1605 if(!ShouldWeAutoload(m_pGraph
)) return VFW_E_TYPE_NOT_ACCEPTED
;
1607 GetRidOfInternalScriptRenderer();
1612 bool CDirectVobSubFilter2::ShouldWeAutoload(IFilterGraph
* pGraph
)
1614 XY_AUTO_TIMING(_T("CDirectVobSubFilter2::ShouldWeAutoload"));
1615 TCHAR blacklistedapps
[][32] =
1617 _T("WM8EUTIL."), // wmp8 encoder's dummy renderer releases the outputted media sample after calling Receive on its input pin (yes, even when dvobsub isn't registered at all)
1618 _T("explorer."), // as some users reported thumbnail preview loads dvobsub, I've never experienced this yet...
1619 _T("producer."), // this is real's producer
1620 _T("GoogleDesktopIndex."), // Google Desktop
1621 _T("GoogleDesktopDisplay."), // Google Desktop
1622 _T("GoogleDesktopCrawl."), // Google Desktop
1625 for(int i
= 0; i
< countof(blacklistedapps
); i
++)
1627 if(theApp
.m_AppName
.Find(blacklistedapps
[i
]) >= 0)
1632 bool m_fExternalLoad
, m_fWebLoad
, m_fEmbeddedLoad
;
1633 get_LoadSettings(&level
, &m_fExternalLoad
, &m_fWebLoad
, &m_fEmbeddedLoad
);
1635 if(level
< 0 || level
>= 2) return(false);
1640 fRet
= m_fExternalLoad
= m_fWebLoad
= m_fEmbeddedLoad
= true;
1642 // find text stream on known splitters
1644 if(!fRet
&& m_fEmbeddedLoad
)
1646 CComPtr
<IBaseFilter
> pBF
;
1647 if((pBF
= FindFilter(CLSID_OggSplitter
, pGraph
)) || (pBF
= FindFilter(CLSID_AviSplitter
, pGraph
))
1648 || (pBF
= FindFilter(L
"{34293064-02F2-41D5-9D75-CC5967ACA1AB}", pGraph
)) // matroska demux
1649 || (pBF
= FindFilter(L
"{0A68C3B5-9164-4a54-AFAF-995B2FF0E0D4}", pGraph
)) // matroska source
1650 || (pBF
= FindFilter(L
"{149D2E01-C32E-4939-80F6-C07B81015A7A}", pGraph
)) // matroska splitter
1651 || (pBF
= FindFilter(L
"{55DA30FC-F16B-49fc-BAA5-AE59FC65F82D}", pGraph
)) // Haali Media Splitter
1652 || (pBF
= FindFilter(L
"{564FD788-86C9-4444-971E-CC4A243DA150}", pGraph
)) // Haali Media Splitter (AR)
1653 || (pBF
= FindFilter(L
"{8F43B7D9-9D6B-4F48-BE18-4D787C795EEA}", pGraph
)) // Haali Simple Media Splitter
1654 || (pBF
= FindFilter(L
"{52B63861-DC93-11CE-A099-00AA00479A58}", pGraph
)) // 3ivx splitter
1655 || (pBF
= FindFilter(L
"{6D3688CE-3E9D-42F4-92CA-8A11119D25CD}", pGraph
)) // our ogg source
1656 || (pBF
= FindFilter(L
"{9FF48807-E133-40AA-826F-9B2959E5232D}", pGraph
)) // our ogg splitter
1657 || (pBF
= FindFilter(L
"{803E8280-F3CE-4201-982C-8CD8FB512004}", pGraph
)) // dsm source
1658 || (pBF
= FindFilter(L
"{0912B4DD-A30A-4568-B590-7179EBB420EC}", pGraph
)) // dsm splitter
1659 || (pBF
= FindFilter(L
"{3CCC052E-BDEE-408a-BEA7-90914EF2964B}", pGraph
)) // mp4 source
1660 || (pBF
= FindFilter(L
"{61F47056-E400-43d3-AF1E-AB7DFFD4C4AD}", pGraph
))) // mp4 splitter
1662 BeginEnumPins(pBF
, pEP
, pPin
)
1664 BeginEnumMediaTypes(pPin
, pEM
, pmt
)
1666 if(pmt
->majortype
== MEDIATYPE_Text
|| pmt
->majortype
== MEDIATYPE_Subtitle
)
1672 EndEnumMediaTypes(pmt
)
1683 BeginEnumFilters(pGraph
, pEF
, pBF
)
1685 if(CComQIPtr
<IFileSourceFilter
> pFSF
= pBF
)
1687 LPOLESTR fnw
= NULL
;
1688 if(!pFSF
|| FAILED(pFSF
->GetCurFile(&fnw
, NULL
)) || !fnw
)
1697 if((m_fExternalLoad
|| m_fWebLoad
) && (m_fWebLoad
|| !(wcsstr(fn
, L
"http://") || wcsstr(fn
, L
"mms://"))))
1699 bool fTemp
= m_fHideSubtitles
;
1700 fRet
= !fn
.IsEmpty() && SUCCEEDED(put_FileName((LPWSTR
)(LPCWSTR
)fn
))
1701 || SUCCEEDED(put_FileName(L
"c:\\tmp.srt"))
1703 if(fTemp
) m_fHideSubtitles
= true;
1709 void CDirectVobSubFilter2::GetRidOfInternalScriptRenderer()
1711 while(CComPtr
<IBaseFilter
> pBF
= FindFilter(L
"{48025243-2D39-11CE-875D-00608CB78066}", m_pGraph
))
1713 BeginEnumPins(pBF
, pEP
, pPin
)
1716 CComPtr
<IPin
> pPinTo
;
1718 if(SUCCEEDED(pPin
->QueryDirection(&dir
)) && dir
== PINDIR_INPUT
1719 && SUCCEEDED(pPin
->ConnectedTo(&pPinTo
)))
1721 m_pGraph
->Disconnect(pPinTo
);
1722 m_pGraph
->Disconnect(pPin
);
1723 m_pGraph
->ConnectDirect(pPinTo
, GetPin(2 + m_pTextInput
.GetCount()-1), NULL
);
1728 if(FAILED(m_pGraph
->RemoveFilter(pBF
)))
1733 ///////////////////////////////////////////////////////////////////////////////
1735 bool CDirectVobSubFilter::Open()
1737 AMTRACE((TEXT(__FUNCTION__
),0));
1738 XY_AUTO_TIMING(TEXT("CDirectVobSubFilter::Open"));
1740 AFX_MANAGE_STATE(AfxGetStaticModuleState());
1742 CAutoLock
cAutolock(&m_csQueueLock
);
1744 m_pSubStreams
.RemoveAll();
1746 m_frd
.files
.RemoveAll();
1748 CAtlArray
<CString
> paths
;
1750 for(int i
= 0; i
< 10; i
++)
1753 tmp
.Format(IDS_RP_PATH
, i
);
1754 CString path
= theApp
.GetProfileString(ResStr(IDS_R_DEFTEXTPATHES
), tmp
);
1755 if(!path
.IsEmpty()) paths
.Add(path
);
1758 CAtlArray
<SubFile
> ret
;
1759 GetSubFileNames(m_FileName
, paths
, ret
);
1761 for(int i
= 0; i
< ret
.GetCount(); i
++)
1763 if(m_frd
.files
.Find(ret
[i
].fn
))
1766 CComPtr
<ISubStream
> pSubStream
;
1770 // CAutoTiming t(TEXT("CRenderedTextSubtitle::Open"), 0);
1771 XY_AUTO_TIMING(TEXT("CRenderedTextSubtitle::Open"));
1772 CAutoPtr
<CRenderedTextSubtitle
> pRTS(new CRenderedTextSubtitle(&m_csSubLock
));
1773 if(pRTS
&& pRTS
->Open(ret
[i
].fn
, DEFAULT_CHARSET
) && pRTS
->GetStreamCount() > 0)
1775 pSubStream
= pRTS
.Detach();
1776 m_frd
.files
.AddTail(ret
[i
].fn
+ _T(".style"));
1782 CAutoTiming
t(TEXT("CVobSubFile::Open"), 0);
1783 CAutoPtr
<CVobSubFile
> pVSF(new CVobSubFile(&m_csSubLock
));
1784 if(pVSF
&& pVSF
->Open(ret
[i
].fn
) && pVSF
->GetStreamCount() > 0)
1786 pSubStream
= pVSF
.Detach();
1787 m_frd
.files
.AddTail(ret
[i
].fn
.Left(ret
[i
].fn
.GetLength()-4) + _T(".sub"));
1793 CAutoTiming
t(TEXT("ssf::CRenderer::Open"), 0);
1794 CAutoPtr
<ssf::CRenderer
> pSSF(new ssf::CRenderer(&m_csSubLock
));
1795 if(pSSF
&& pSSF
->Open(ret
[i
].fn
) && pSSF
->GetStreamCount() > 0)
1797 pSubStream
= pSSF
.Detach();
1803 m_pSubStreams
.AddTail(pSubStream
);
1804 m_frd
.files
.AddTail(ret
[i
].fn
);
1808 for(int i
= 0; i
< m_pTextInput
.GetCount(); i
++)
1810 if(m_pTextInput
[i
]->IsConnected())
1811 m_pSubStreams
.AddTail(m_pTextInput
[i
]->GetSubStream());
1814 if(S_FALSE
== put_SelectedLanguage(FindPreferedLanguage()))
1815 UpdateSubtitle(false); // make sure pSubPicProvider of our queue gets updated even if the stream number hasn't changed
1817 m_frd
.RefreshEvent
.Set();
1819 return(m_pSubStreams
.GetCount() > 0);
1822 void CDirectVobSubFilter::UpdateSubtitle(bool fApplyDefStyle
)
1824 CAutoLock
cAutolock(&m_csQueueLock
);
1826 if(!m_pSubPicQueue
) return;
1828 InvalidateSubtitle();
1830 CComPtr
<ISubStream
> pSubStream
;
1832 if(!m_fHideSubtitles
)
1834 int i
= m_iSelectedLanguage
;
1836 for(POSITION pos
= m_pSubStreams
.GetHeadPosition(); i
>= 0 && pos
; pSubStream
= NULL
)
1838 pSubStream
= m_pSubStreams
.GetNext(pos
);
1840 if(i
< pSubStream
->GetStreamCount())
1842 CAutoLock
cAutoLock(&m_csSubLock
);
1843 pSubStream
->SetStream(i
);
1847 i
-= pSubStream
->GetStreamCount();
1851 SetSubtitle(pSubStream
, fApplyDefStyle
);
1854 void CDirectVobSubFilter::SetSubtitle(ISubStream
* pSubStream
, bool fApplyDefStyle
)
1856 DbgLog((LOG_TRACE
, 3, "%s(%d): %s", __FILE__
, __LINE__
, __FUNCTION__
));
1857 DbgLog((LOG_TRACE
, 3, "\tpSubStream:%x fApplyDefStyle:%d", pSubStream
, (int)fApplyDefStyle
));
1858 CAutoLock
cAutolock(&m_csQueueLock
);
1862 CAutoLock
cAutolock(&m_csSubLock
);
1865 pSubStream
->GetClassID(&clsid
);
1867 if(clsid
== __uuidof(CVobSubFile
))
1869 CVobSubSettings
* pVSS
= dynamic_cast<CVobSubFile
*>(pSubStream
);
1873 pVSS
->SetAlignment(m_fOverridePlacement
, m_PlacementXperc
, m_PlacementYperc
, 1, 1);
1874 pVSS
->m_fOnlyShowForcedSubs
= m_fOnlyShowForcedVobSubs
;
1877 else if(clsid
== __uuidof(CVobSubStream
))
1879 CVobSubSettings
* pVSS
= dynamic_cast<CVobSubStream
*>(pSubStream
);
1883 pVSS
->SetAlignment(m_fOverridePlacement
, m_PlacementXperc
, m_PlacementYperc
, 1, 1);
1884 pVSS
->m_fOnlyShowForcedSubs
= m_fOnlyShowForcedVobSubs
;
1887 else if(clsid
== __uuidof(CRenderedTextSubtitle
))
1889 CRenderedTextSubtitle
* pRTS
= dynamic_cast<CRenderedTextSubtitle
*>(pSubStream
);
1891 if(fApplyDefStyle
|| pRTS
->m_fUsingAutoGeneratedDefaultStyle
)
1893 STSStyle s
= m_defStyle
;
1895 if(m_fOverridePlacement
)
1898 int w
= pRTS
->m_dstScreenSize
.cx
;
1899 int h
= pRTS
->m_dstScreenSize
.cy
;
1900 CRect tmp_rect
= s
.marginRect
.get();
1901 int mw
= w
- tmp_rect
.left
- tmp_rect
.right
;
1902 tmp_rect
.bottom
= h
- MulDiv(h
, m_PlacementYperc
, 100);
1903 tmp_rect
.left
= MulDiv(w
, m_PlacementXperc
, 100) - mw
/2;
1904 tmp_rect
.right
= w
- (tmp_rect
.left
+ mw
);
1905 s
.marginRect
= tmp_rect
;
1908 pRTS
->SetDefaultStyle(s
);
1911 pRTS
->m_ePARCompensationType
= m_ePARCompensationType
;
1912 if (m_CurrentVIH2
.dwPictAspectRatioX
!= 0 && m_CurrentVIH2
.dwPictAspectRatioY
!= 0&& m_CurrentVIH2
.bmiHeader
.biWidth
!= 0 && m_CurrentVIH2
.bmiHeader
.biHeight
!= 0)
1914 pRTS
->m_dPARCompensation
= ((double)abs(m_CurrentVIH2
.bmiHeader
.biWidth
) / (double)abs(m_CurrentVIH2
.bmiHeader
.biHeight
)) /
1915 ((double)abs((long)m_CurrentVIH2
.dwPictAspectRatioX
) / (double)abs((long)m_CurrentVIH2
.dwPictAspectRatioY
));
1920 pRTS
->m_dPARCompensation
= 1.00;
1931 POSITION pos
= m_pSubStreams
.GetHeadPosition();
1934 CComPtr
<ISubStream
> pSubStream2
= m_pSubStreams
.GetNext(pos
);
1936 if(pSubStream
== pSubStream2
)
1938 m_iSelectedLanguage
= i
+ pSubStream2
->GetStream();
1942 i
+= pSubStream2
->GetStreamCount();
1946 m_nSubtitleId
= reinterpret_cast<DWORD_PTR
>(pSubStream
);
1949 m_pSubPicQueue
->SetSubPicProviderEx(CComQIPtr
<ISubPicProviderEx
>(pSubStream
));
1952 void CDirectVobSubFilter::InvalidateSubtitle(REFERENCE_TIME rtInvalidate
, DWORD_PTR nSubtitleId
)
1954 CAutoLock
cAutolock(&m_csQueueLock
);
1958 if(nSubtitleId
== -1 || nSubtitleId
== m_nSubtitleId
)
1960 DbgLog((LOG_TRACE
, 3, "InvalidateSubtitle::Invalidate"));
1961 m_pSubPicQueue
->Invalidate(rtInvalidate
);
1966 //////////////////////////////////////////////////////////////////////////////////////////
1968 void CDirectVobSubFilter::AddSubStream(ISubStream
* pSubStream
)
1970 CAutoLock
cAutoLock(&m_csQueueLock
);
1972 POSITION pos
= m_pSubStreams
.Find(pSubStream
);
1973 if(!pos
) m_pSubStreams
.AddTail(pSubStream
);
1975 int len
= m_pTextInput
.GetCount();
1976 for(int i
= 0; i
< m_pTextInput
.GetCount(); i
++)
1977 if(m_pTextInput
[i
]->IsConnected()) len
--;
1982 m_pTextInput
.Add(new CTextInputPin(this, m_pLock
, &m_csSubLock
, &hr
));
1986 void CDirectVobSubFilter::RemoveSubStream(ISubStream
* pSubStream
)
1988 CAutoLock
cAutoLock(&m_csQueueLock
);
1990 POSITION pos
= m_pSubStreams
.Find(pSubStream
);
1991 if(pos
) m_pSubStreams
.RemoveAt(pos
);
1994 void CDirectVobSubFilter::Post_EC_OLE_EVENT(CString str
, DWORD_PTR nSubtitleId
)
1996 if(nSubtitleId
!= -1 && nSubtitleId
!= m_nSubtitleId
)
1999 CComQIPtr
<IMediaEventSink
> pMES
= m_pGraph
;
2002 CComBSTR
bstr1("Text"), bstr2(" ");
2005 if(!str
.IsEmpty()) bstr2
= CStringA(str
);
2007 pMES
->Notify(EC_OLE_EVENT
, (LONG_PTR
)bstr1
.Detach(), (LONG_PTR
)bstr2
.Detach());
2010 ////////////////////////////////////////////////////////////////
2012 void CDirectVobSubFilter::SetupFRD(CStringArray
& paths
, CAtlArray
<HANDLE
>& handles
)
2014 CAutoLock
cAutolock(&m_csSubLock
);
2016 for(int i
= 2; i
< handles
.GetCount(); i
++)
2018 FindCloseChangeNotification(handles
[i
]);
2022 handles
.RemoveAll();
2024 handles
.Add(m_frd
.EndThreadEvent
);
2025 handles
.Add(m_frd
.RefreshEvent
);
2027 m_frd
.mtime
.SetCount(m_frd
.files
.GetCount());
2029 POSITION pos
= m_frd
.files
.GetHeadPosition();
2030 for(int i
= 0; pos
; i
++)
2032 CString fn
= m_frd
.files
.GetNext(pos
);
2035 if(CFileGetStatus(fn
, status
))
2036 m_frd
.mtime
[i
] = status
.m_mtime
;
2038 fn
.Replace('\\', '/');
2039 fn
= fn
.Left(fn
.ReverseFind('/')+1);
2041 bool fFound
= false;
2043 for(int j
= 0; !fFound
&& j
< paths
.GetCount(); j
++)
2045 if(paths
[j
] == fn
) fFound
= true;
2052 HANDLE h
= FindFirstChangeNotification(fn
, FALSE
, FILE_NOTIFY_CHANGE_LAST_WRITE
);
2053 if(h
!= INVALID_HANDLE_VALUE
) handles
.Add(h
);
2058 DWORD
CDirectVobSubFilter::ThreadProc()
2060 SetThreadPriority(m_hThread
, THREAD_PRIORITY_LOWEST
/*THREAD_PRIORITY_BELOW_NORMAL*/);
2063 CAtlArray
<HANDLE
> handles
;
2065 SetupFRD(paths
, handles
);
2069 DWORD idx
= WaitForMultipleObjects(handles
.GetCount(), handles
.GetData(), FALSE
, INFINITE
);
2071 if(idx
== (WAIT_OBJECT_0
+ 0)) // m_frd.hEndThreadEvent
2075 if(idx
== (WAIT_OBJECT_0
+ 1)) // m_frd.hRefreshEvent
2077 SetupFRD(paths
, handles
);
2079 else if(idx
>= (WAIT_OBJECT_0
+ 2) && idx
< (WAIT_OBJECT_0
+ handles
.GetCount()))
2081 bool fLocked
= true;
2082 IsSubtitleReloaderLocked(&fLocked
);
2083 if(fLocked
) continue;
2085 if(FindNextChangeNotification(handles
[idx
- WAIT_OBJECT_0
]) == FALSE
)
2090 POSITION pos
= m_frd
.files
.GetHeadPosition();
2091 for(int i
= 0; pos
&& j
== 0; i
++)
2093 CString fn
= m_frd
.files
.GetNext(pos
);
2096 if(CFileGetStatus(fn
, status
) && m_frd
.mtime
[i
] != status
.m_mtime
)
2098 for(j
= 0; j
< 10; j
++)
2100 if(FILE* f
= _tfopen(fn
, _T("rb+")))
2117 SetupFRD(paths
, handles
);
2123 POSITION pos
= m_frd
.files
.GetHeadPosition();
2124 for(int i
= 0; pos
; i
++)
2127 if(CFileGetStatus(m_frd
.files
.GetNext(pos
), status
)
2128 && m_frd
.mtime
[i
] != status
.m_mtime
)
2131 SetupFRD(paths
, handles
);
2143 for(int i
= 2; i
< handles
.GetCount(); i
++)
2145 FindCloseChangeNotification(handles
[i
]);
2151 void CDirectVobSubFilter::GetInputColorspaces( ColorSpaceId
*preferredOrder
, UINT
*count
)
2153 ColorSpaceId colorspace
[MAX_COLOR_SPACE_NUM
];
2154 bool selected
[MAX_COLOR_SPACE_NUM
];
2156 if( get_InputColorFormat(colorspace
, selected
, &tempCount
)==S_OK
)
2159 for (int i
=0;i
<tempCount
;i
++)
2163 preferredOrder
[*count
] = colorspace
[i
];
2170 CBaseVideoFilter::GetInputColorspaces(preferredOrder
, count
);
2174 void CDirectVobSubFilter::GetOutputColorspaces( ColorSpaceId
*preferredOrder
, UINT
*count
)
2176 ColorSpaceId colorspace
[MAX_COLOR_SPACE_NUM
];
2177 bool selected
[MAX_COLOR_SPACE_NUM
];
2179 if( get_OutputColorFormat(colorspace
, selected
, &tempCount
)==S_OK
)
2182 for (int i
=0;i
<tempCount
;i
++)
2186 preferredOrder
[*count
] = colorspace
[i
];
2193 CBaseVideoFilter::GetInputColorspaces(preferredOrder
, count
);