Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/filters')
-rw-r--r--src/filters/FilterApp.cpp3
-rw-r--r--src/filters/InternalPropertyPage.cpp87
-rw-r--r--src/filters/InternalPropertyPage.h19
-rw-r--r--src/filters/PinInfoWnd.cpp90
-rw-r--r--src/filters/PinInfoWnd.h3
-rw-r--r--src/filters/muxer/BaseMuxer/BaseMuxer.cpp259
-rw-r--r--src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp102
-rw-r--r--src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h3
-rw-r--r--src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp235
-rw-r--r--src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h3
-rw-r--r--src/filters/muxer/BaseMuxer/BitStream.cpp24
-rw-r--r--src/filters/muxer/BaseMuxer/BitStream.h3
-rw-r--r--src/filters/muxer/DSMMuxer/DSMMuxer.cpp123
-rw-r--r--src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp250
-rw-r--r--src/filters/muxer/MatroskaMuxer/MatroskaFile.h730
-rw-r--r--src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp834
-rw-r--r--src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h3
-rw-r--r--src/filters/muxer/WavDest/WavDest.cpp94
-rw-r--r--src/filters/parser/AviSplitter/AviFile.cpp548
-rw-r--r--src/filters/parser/AviSplitter/AviFile.h25
-rw-r--r--src/filters/parser/AviSplitter/AviReportWnd.cpp116
-rw-r--r--src/filters/parser/AviSplitter/AviReportWnd.h4
-rw-r--r--src/filters/parser/AviSplitter/AviSplitter.cpp546
-rw-r--r--src/filters/parser/AviSplitter/AviSplitter.h12
-rw-r--r--src/filters/parser/AviSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/AviSplitter/stdafx.h6
-rw-r--r--src/filters/parser/BaseSplitter/AsyncReader.cpp117
-rw-r--r--src/filters/parser/BaseSplitter/AsyncReader.h56
-rw-r--r--src/filters/parser/BaseSplitter/BaseSplitter.cpp723
-rw-r--r--src/filters/parser/BaseSplitter/BaseSplitter.h154
-rw-r--r--src/filters/parser/BaseSplitter/BaseSplitterFile.cpp88
-rw-r--r--src/filters/parser/BaseSplitter/BaseSplitterFile.h18
-rw-r--r--src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp924
-rw-r--r--src/filters/parser/BaseSplitter/BaseSplitterFileEx.h44
-rw-r--r--src/filters/parser/BaseSplitter/MultiFiles.cpp85
-rw-r--r--src/filters/parser/BaseSplitter/MultiFiles.h12
-rw-r--r--src/filters/parser/BaseSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/BaseSplitter/stdafx.h6
-rw-r--r--src/filters/parser/DSMSplitter/DSMSplitter.cpp104
-rw-r--r--src/filters/parser/DSMSplitter/DSMSplitter.h10
-rw-r--r--src/filters/parser/DSMSplitter/DSMSplitterFile.cpp213
-rw-r--r--src/filters/parser/DSMSplitter/DSMSplitterFile.h7
-rw-r--r--src/filters/parser/DSMSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/DSMSplitter/stdafx.h6
-rw-r--r--src/filters/parser/FLVSplitter/FLVSplitter.cpp646
-rw-r--r--src/filters/parser/FLVSplitter/FLVSplitter.h24
-rw-r--r--src/filters/parser/FLVSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/FLVSplitter/stdafx.h6
-rw-r--r--src/filters/parser/MP4Splitter/Ap4AsyncReaderStream.cpp33
-rw-r--r--src/filters/parser/MP4Splitter/MP4Splitter.cpp1215
-rw-r--r--src/filters/parser/MP4Splitter/MP4Splitter.h19
-rw-r--r--src/filters/parser/MP4Splitter/MP4SplitterFile.cpp8
-rw-r--r--src/filters/parser/MP4Splitter/stdafx.cpp6
-rw-r--r--src/filters/parser/MP4Splitter/stdafx.h6
-rw-r--r--src/filters/parser/MatroskaSplitter/MatroskaFile.cpp1178
-rw-r--r--src/filters/parser/MatroskaSplitter/MatroskaFile.h797
-rw-r--r--src/filters/parser/MatroskaSplitter/MatroskaSplitter.cpp789
-rw-r--r--src/filters/parser/MatroskaSplitter/MatroskaSplitter.h29
-rw-r--r--src/filters/parser/MatroskaSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/MatroskaSplitter/stdafx.h6
-rw-r--r--src/filters/parser/MpaSplitter/MpaSplitter.cpp74
-rw-r--r--src/filters/parser/MpaSplitter/MpaSplitter.h12
-rw-r--r--src/filters/parser/MpaSplitter/MpaSplitterFile.cpp199
-rw-r--r--src/filters/parser/MpaSplitter/MpaSplitterFile.h22
-rw-r--r--src/filters/parser/MpaSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/MpaSplitter/stdafx.h6
-rw-r--r--src/filters/parser/MpegSplitter/MpegSplitter.cpp1080
-rw-r--r--src/filters/parser/MpegSplitter/MpegSplitter.h26
-rw-r--r--src/filters/parser/MpegSplitter/MpegSplitterFile.cpp537
-rw-r--r--src/filters/parser/MpegSplitter/MpegSplitterFile.h69
-rw-r--r--src/filters/parser/MpegSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/MpegSplitter/stdafx.h6
-rw-r--r--src/filters/parser/OggSplitter/OggFile.cpp44
-rw-r--r--src/filters/parser/OggSplitter/OggFile.h29
-rw-r--r--src/filters/parser/OggSplitter/OggSplitter.cpp634
-rw-r--r--src/filters/parser/OggSplitter/OggSplitter.h42
-rw-r--r--src/filters/parser/OggSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/OggSplitter/stdafx.h6
-rw-r--r--src/filters/parser/RealMediaSplitter/RealMediaSplitter.cpp1367
-rw-r--r--src/filters/parser/RealMediaSplitter/RealMediaSplitter.h120
-rw-r--r--src/filters/parser/SSFSplitter/SSFSplitter.cpp110
-rw-r--r--src/filters/parser/SSFSplitter/SSFSplitter.h13
-rw-r--r--src/filters/parser/SSFSplitter/stdafx.cpp6
-rw-r--r--src/filters/parser/SSFSplitter/stdafx.h6
-rw-r--r--src/filters/parser/StreamDriveThru/StreamDriveThru.cpp330
-rw-r--r--src/filters/parser/StreamDriveThru/StreamDriveThru.h34
-rw-r--r--src/filters/parser/StreamDriveThru/stdafx.cpp6
-rw-r--r--src/filters/parser/StreamDriveThru/stdafx.h6
-rw-r--r--src/filters/reader/CDDAReader/CDDAReader.cpp254
-rw-r--r--src/filters/reader/CDDAReader/CDDAReader.h89
-rw-r--r--src/filters/reader/CDDAReader/stdafx.cpp6
-rw-r--r--src/filters/reader/CDDAReader/stdafx.h6
-rw-r--r--src/filters/reader/CDXAReader/CDXAReader.cpp228
-rw-r--r--src/filters/reader/CDXAReader/CDXAReader.h29
-rw-r--r--src/filters/reader/CDXAReader/stdafx.cpp6
-rw-r--r--src/filters/reader/CDXAReader/stdafx.h6
-rw-r--r--src/filters/reader/UDPReader/UDPReader.cpp290
-rw-r--r--src/filters/reader/UDPReader/UDPReader.h36
-rw-r--r--src/filters/reader/UDPReader/stdafx.cpp6
-rw-r--r--src/filters/reader/UDPReader/stdafx.h6
-rw-r--r--src/filters/reader/VTSReader/VTSReader.cpp76
-rw-r--r--src/filters/reader/VTSReader/VTSReader.h26
-rw-r--r--src/filters/reader/VTSReader/stdafx.cpp6
-rw-r--r--src/filters/reader/VTSReader/stdafx.h6
-rw-r--r--src/filters/renderer/MpcAudioRenderer/IMpcAudioRendererFilter.h3
-rw-r--r--src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp527
-rw-r--r--src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.h12
-rw-r--r--src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.cpp14
-rw-r--r--src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.h3
-rw-r--r--src/filters/renderer/SyncClock/Interfaces.h4
-rw-r--r--src/filters/renderer/SyncClock/SyncClock.cpp59
-rw-r--r--src/filters/renderer/SyncClock/SyncClock.h31
-rw-r--r--src/filters/renderer/SyncClock/stdafx.cpp8
-rw-r--r--src/filters/renderer/SyncClock/stdafx.h8
-rw-r--r--src/filters/renderer/VideoRenderers/AllocatorCommon.cpp408
-rw-r--r--src/filters/renderer/VideoRenderers/AllocatorCommon.h3
-rw-r--r--src/filters/renderer/VideoRenderers/AllocatorCommon7.cpp13
-rw-r--r--src/filters/renderer/VideoRenderers/D3DFont.cpp238
-rw-r--r--src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp215
-rw-r--r--src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.h48
-rw-r--r--src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp1403
-rw-r--r--src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h508
-rw-r--r--src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp734
-rw-r--r--src/filters/renderer/VideoRenderers/DX9RenderingEngine.h261
-rw-r--r--src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp141
-rw-r--r--src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.h132
-rw-r--r--src/filters/renderer/VideoRenderers/Dither.cpp3
-rw-r--r--src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp1847
-rw-r--r--src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.h489
-rw-r--r--src/filters/renderer/VideoRenderers/IPinHook.cpp449
-rw-r--r--src/filters/renderer/VideoRenderers/IPinHook.h18
-rw-r--r--src/filters/renderer/VideoRenderers/IQTVideoSurface.h3
-rw-r--r--src/filters/renderer/VideoRenderers/MacrovisionKicker.cpp18
-rw-r--r--src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp43
-rw-r--r--src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp25
-rw-r--r--src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.h40
-rw-r--r--src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp25
-rw-r--r--src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.h32
-rw-r--r--src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp77
-rw-r--r--src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.h46
-rw-r--r--src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp79
-rw-r--r--src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.h56
-rw-r--r--src/filters/renderer/VideoRenderers/RenderersSettings.cpp33
-rw-r--r--src/filters/renderer/VideoRenderers/RenderersSettings.h30
-rw-r--r--src/filters/renderer/VideoRenderers/SyncAllocatorPresenter.h3
-rw-r--r--src/filters/renderer/VideoRenderers/SyncRenderer.cpp2252
-rw-r--r--src/filters/renderer/VideoRenderers/SyncRenderer.h1168
-rw-r--r--src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.cpp118
-rw-r--r--src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.h88
-rw-r--r--src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.cpp1112
-rw-r--r--src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.h88
-rw-r--r--src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp146
-rw-r--r--src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.h134
-rw-r--r--src/filters/source/BaseSource/BaseSource.cpp82
-rw-r--r--src/filters/source/BaseSource/BaseSource.h61
-rw-r--r--src/filters/source/BaseSource/stdafx.cpp6
-rw-r--r--src/filters/source/BaseSource/stdafx.h6
-rw-r--r--src/filters/source/D2VSource/D2VSource.cpp150
-rw-r--r--src/filters/source/D2VSource/D2VSource.h20
-rw-r--r--src/filters/source/DTSAC3Source/DTSAC3Source.cpp239
-rw-r--r--src/filters/source/DTSAC3Source/DTSAC3Source.h18
-rw-r--r--src/filters/source/DTSAC3Source/stdafx.cpp6
-rw-r--r--src/filters/source/DTSAC3Source/stdafx.h6
-rw-r--r--src/filters/source/FLICSource/FLICSource.cpp437
-rw-r--r--src/filters/source/FLICSource/FLICSource.h52
-rw-r--r--src/filters/source/FLICSource/stdafx.cpp6
-rw-r--r--src/filters/source/FLICSource/stdafx.h6
-rw-r--r--src/filters/source/FlacSource/FlacSource.cpp136
-rw-r--r--src/filters/source/FlacSource/FlacSource.h24
-rw-r--r--src/filters/source/FlacSource/stdafx.cpp6
-rw-r--r--src/filters/source/FlacSource/stdafx.h6
-rw-r--r--src/filters/source/ShoutcastSource/ShoutcastSource.cpp365
-rw-r--r--src/filters/source/ShoutcastSource/ShoutcastSource.h122
-rw-r--r--src/filters/source/ShoutcastSource/stdafx.cpp6
-rw-r--r--src/filters/source/ShoutcastSource/stdafx.h6
-rw-r--r--src/filters/source/SubtitleSource/SubtitleSource.cpp388
-rw-r--r--src/filters/source/SubtitleSource/SubtitleSource.h42
-rw-r--r--src/filters/source/SubtitleSource/stdafx.cpp6
-rw-r--r--src/filters/source/SubtitleSource/stdafx.h6
-rw-r--r--src/filters/switcher/AudioSwitcher/Audio.cpp108
-rw-r--r--src/filters/switcher/AudioSwitcher/Audio.h8
-rw-r--r--src/filters/switcher/AudioSwitcher/AudioSwitcher.cpp382
-rw-r--r--src/filters/switcher/AudioSwitcher/AudioSwitcher.h24
-rw-r--r--src/filters/switcher/AudioSwitcher/StreamSwitcher.cpp779
-rw-r--r--src/filters/switcher/AudioSwitcher/StreamSwitcher.h142
-rw-r--r--src/filters/switcher/AudioSwitcher/stdafx.cpp6
-rw-r--r--src/filters/switcher/AudioSwitcher/stdafx.h6
-rw-r--r--src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.cpp320
-rw-r--r--src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.h23
-rw-r--r--src/filters/transform/AVI2AC3Filter/stdafx.cpp6
-rw-r--r--src/filters/transform/AVI2AC3Filter/stdafx.h6
-rw-r--r--src/filters/transform/BaseVideoFilter/BaseVideoFilter.cpp448
-rw-r--r--src/filters/transform/BaseVideoFilter/BaseVideoFilter.h25
-rw-r--r--src/filters/transform/BaseVideoFilter/stdafx.cpp6
-rw-r--r--src/filters/transform/BaseVideoFilter/stdafx.h6
-rw-r--r--src/filters/transform/BufferFilter/BufferFilter.cpp129
-rw-r--r--src/filters/transform/BufferFilter/BufferFilter.h49
-rw-r--r--src/filters/transform/BufferFilter/stdafx.cpp6
-rw-r--r--src/filters/transform/BufferFilter/stdafx.h6
-rw-r--r--src/filters/transform/DeCSSFilter/DeCSSFilter.cpp157
-rw-r--r--src/filters/transform/DeCSSFilter/DeCSSFilter.h18
-rw-r--r--src/filters/transform/DeCSSFilter/stdafx.cpp6
-rw-r--r--src/filters/transform/DeCSSFilter/stdafx.h6
-rw-r--r--src/filters/transform/MPCVideoDec/DXVADecoder.cpp545
-rw-r--r--src/filters/transform/MPCVideoDec/DXVADecoder.h15
-rw-r--r--src/filters/transform/MPCVideoDec/DXVADecoderH264.cpp228
-rw-r--r--src/filters/transform/MPCVideoDec/DXVADecoderMpeg2.cpp81
-rw-r--r--src/filters/transform/MPCVideoDec/DXVADecoderVC1.cpp95
-rw-r--r--src/filters/transform/MPCVideoDec/DXVADecoderVC1.h18
-rw-r--r--src/filters/transform/MPCVideoDec/FfmpegContext.c387
-rw-r--r--src/filters/transform/MPCVideoDec/FfmpegContext.h3
-rw-r--r--src/filters/transform/MPCVideoDec/H264QuantizationMatrix.h116
-rw-r--r--src/filters/transform/MPCVideoDec/IMPCVideoDecFilter.h6
-rw-r--r--src/filters/transform/MPCVideoDec/MPCAudioDecFilter.cpp96
-rw-r--r--src/filters/transform/MPCVideoDec/MPCAudioDecFilter.h2
-rw-r--r--src/filters/transform/MPCVideoDec/MPCFfmpegDec.cpp9
-rw-r--r--src/filters/transform/MPCVideoDec/MPCVideoDecFilter.cpp1038
-rw-r--r--src/filters/transform/MPCVideoDec/MPCVideoDecFilter.h61
-rw-r--r--src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.cpp131
-rw-r--r--src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.h3
-rw-r--r--src/filters/transform/MPCVideoDec/TlibavcodecExt.cpp6
-rw-r--r--src/filters/transform/MPCVideoDec/TlibavcodecExt.h3
-rw-r--r--src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.cpp70
-rw-r--r--src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.h17
-rw-r--r--src/filters/transform/MPCVideoDec/VideoDecOutputPin.cpp31
-rw-r--r--src/filters/transform/MPCVideoDec/stdafx.cpp6
-rw-r--r--src/filters/transform/MpaDecFilter/IMpaDecFilter.h6
-rw-r--r--src/filters/transform/MpaDecFilter/MpaDecFilter.cpp1641
-rw-r--r--src/filters/transform/MpaDecFilter/MpaDecFilter.h12
-rw-r--r--src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.cpp68
-rw-r--r--src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.h3
-rw-r--r--src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h10
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp1410
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h125
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp30
-rw-r--r--src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h21
-rw-r--r--src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp478
-rw-r--r--src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp767
-rw-r--r--src/filters/transform/Mpeg2DecFilter/stdafx.cpp6
-rw-r--r--src/filters/transform/Mpeg2DecFilter/stdafx.h6
-rw-r--r--src/filters/transform/VSFilter/AvgLines.cpp75
-rw-r--r--src/filters/transform/VSFilter/Copy.cpp111
-rw-r--r--src/filters/transform/VSFilter/DirectVobSub.cpp248
-rw-r--r--src/filters/transform/VSFilter/DirectVobSub.h8
-rw-r--r--src/filters/transform/VSFilter/DirectVobSubFilter.cpp848
-rw-r--r--src/filters/transform/VSFilter/DirectVobSubFilter.h3
-rw-r--r--src/filters/transform/VSFilter/DirectVobSubPropPage.cpp851
-rw-r--r--src/filters/transform/VSFilter/IDirectVobSub.h9
-rw-r--r--src/filters/transform/VSFilter/Scale2x.cpp65
-rw-r--r--src/filters/transform/VSFilter/StyleEditorDialog.cpp60
-rw-r--r--src/filters/transform/VSFilter/StyleEditorDialog.h5
-rw-r--r--src/filters/transform/VSFilter/Systray.cpp335
-rw-r--r--src/filters/transform/VSFilter/VSFilter.cpp40
-rw-r--r--src/filters/transform/VSFilter/csri.h532
-rw-r--r--src/filters/transform/VSFilter/csriapi.cpp43
-rw-r--r--src/filters/transform/VSFilter/plugins.cpp1828
-rw-r--r--src/filters/transform/VSFilter/vfr.cpp39
-rw-r--r--src/filters/transform/VSFilter/vfr.h3
258 files changed, 24526 insertions, 23561 deletions
diff --git a/src/filters/FilterApp.cpp b/src/filters/FilterApp.cpp
index 8ca000fdc..059fcda74 100644
--- a/src/filters/FilterApp.cpp
+++ b/src/filters/FilterApp.cpp
@@ -32,8 +32,9 @@ CFilterApp::CFilterApp()
BOOL CFilterApp::InitInstance()
{
- if(!__super::InitInstance())
+ if(!__super::InitInstance()) {
return FALSE;
+ }
SetRegistryKey(_T("Gabest"));
diff --git a/src/filters/InternalPropertyPage.cpp b/src/filters/InternalPropertyPage.cpp
index daeb0b339..9694d1b4c 100644
--- a/src/filters/InternalPropertyPage.cpp
+++ b/src/filters/InternalPropertyPage.cpp
@@ -37,17 +37,19 @@ CInternalPropertyPageWnd::CInternalPropertyPageWnd()
BOOL CInternalPropertyPageWnd::Create(IPropertyPageSite* pPageSite, LPCRECT pRect, CWnd* pParentWnd)
{
- if(!pPageSite || !pRect) return FALSE;
+ if(!pPageSite || !pRect) {
+ return FALSE;
+ }
m_pPageSite = pPageSite;
- if(!m_font.m_hObject)
- {
+ if(!m_font.m_hObject) {
CString face;
WORD height;
extern BOOL AFXAPI AfxGetPropSheetFont(CString& strFace, WORD& wSize, BOOL bWizard); // yay
- if(!AfxGetPropSheetFont(face, height, FALSE))
+ if(!AfxGetPropSheetFont(face, height, FALSE)) {
return FALSE;
+ }
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
@@ -57,16 +59,17 @@ BOOL CInternalPropertyPageWnd::Create(IPropertyPageSite* pPageSite, LPCRECT pRec
::ReleaseDC(0, hDC);
lf.lfWeight = FW_NORMAL;
lf.lfCharSet = DEFAULT_CHARSET;
- if(!m_font.CreateFontIndirect(&lf))
+ if(!m_font.CreateFontIndirect(&lf)) {
return FALSE;
+ }
lf.lfHeight -= -1;
_tcscpy(lf.lfFaceName, _T("Lucida Console"));
- if(!m_monospacefont.CreateFontIndirect(&lf))
- {
+ if(!m_monospacefont.CreateFontIndirect(&lf)) {
_tcscpy(lf.lfFaceName, _T("Courier New"));
- if(!m_monospacefont.CreateFontIndirect(&lf))
+ if(!m_monospacefont.CreateFontIndirect(&lf)) {
return FALSE;
+ }
}
hDC = ::GetDC(0);
@@ -80,8 +83,9 @@ BOOL CInternalPropertyPageWnd::Create(IPropertyPageSite* pPageSite, LPCRECT pRec
}
LPCTSTR wc = AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS, 0, (HBRUSH)(COLOR_BTNFACE + 1));
- if(!CreateEx(0, wc, _T("CInternalPropertyPageWnd"), WS_CHILDWINDOW, *pRect, pParentWnd, 0))
+ if(!CreateEx(0, wc, _T("CInternalPropertyPageWnd"), WS_CHILDWINDOW, *pRect, pParentWnd, 0)) {
return FALSE;
+ }
SetFont(&m_font);
@@ -90,8 +94,7 @@ BOOL CInternalPropertyPageWnd::Create(IPropertyPageSite* pPageSite, LPCRECT pRec
BOOL CInternalPropertyPageWnd::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
- if(message == WM_COMMAND || message == WM_HSCROLL || message == WM_VSCROLL)
- {
+ if(message == WM_COMMAND || message == WM_HSCROLL || message == WM_VSCROLL) {
SetDirty(true);
}
@@ -109,13 +112,14 @@ CInternalPropertyPage::CInternalPropertyPage(LPUNKNOWN lpunk, HRESULT* phr)
: CUnknown(_T("CInternalPropertyPage"), lpunk)
, m_pWnd(NULL)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CInternalPropertyPage::~CInternalPropertyPage()
{
- if(m_pWnd)
- {
+ if(m_pWnd) {
if(m_pWnd->m_hWnd) {
ASSERT(0);
m_pWnd->DestroyWindow();
@@ -138,8 +142,9 @@ STDMETHODIMP CInternalPropertyPage::SetPageSite(IPropertyPageSite* pPageSite)
{
CAutoLock cAutoLock(this);
- if(pPageSite && m_pPageSite || !pPageSite && !m_pPageSite)
+ if(pPageSite && m_pPageSite || !pPageSite && !m_pPageSite) {
return E_UNEXPECTED;
+ }
m_pPageSite = pPageSite;
@@ -154,14 +159,15 @@ STDMETHODIMP CInternalPropertyPage::Activate(HWND hwndParent, LPCRECT pRect, BOO
CheckPointer(pRect, E_POINTER);
- if(!m_pWnd || m_pWnd->m_hWnd || m_pUnks.IsEmpty())
+ if(!m_pWnd || m_pWnd->m_hWnd || m_pUnks.IsEmpty()) {
return E_UNEXPECTED;
+ }
- if(!m_pWnd->Create(m_pPageSite, pRect, CWnd::FromHandle(hwndParent)))
+ if(!m_pWnd->Create(m_pPageSite, pRect, CWnd::FromHandle(hwndParent))) {
return E_OUTOFMEMORY;
+ }
- if(!m_pWnd->OnActivate())
- {
+ if(!m_pWnd->OnActivate()) {
m_pWnd->DestroyWindow();
return E_FAIL;
}
@@ -178,8 +184,9 @@ STDMETHODIMP CInternalPropertyPage::Deactivate()
CAutoLock cAutoLock(this);
- if(!m_pWnd || !m_pWnd->m_hWnd)
+ if(!m_pWnd || !m_pWnd->m_hWnd) {
return E_UNEXPECTED;
+ }
m_pWnd->OnDeactivate();
@@ -197,7 +204,9 @@ STDMETHODIMP CInternalPropertyPage::GetPageInfo(PROPPAGEINFO* pPageInfo)
LPOLESTR pszTitle;
HRESULT hr = AMGetWideString(CStringW(GetWindowTitle()), &pszTitle);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
pPageInfo->cb = sizeof(PROPPAGEINFO);
pPageInfo->pszTitle = pszTitle;
@@ -213,32 +222,31 @@ STDMETHODIMP CInternalPropertyPage::SetObjects(ULONG cObjects, LPUNKNOWN* ppUnk)
{
CAutoLock cAutoLock(this);
- if(cObjects && m_pWnd || !cObjects && !m_pWnd)
+ if(cObjects && m_pWnd || !cObjects && !m_pWnd) {
return E_UNEXPECTED;
+ }
m_pUnks.RemoveAll();
- if(cObjects > 0)
- {
+ if(cObjects > 0) {
CheckPointer(ppUnk, E_POINTER);
- for(ULONG i = 0; i < cObjects; i++)
+ for(ULONG i = 0; i < cObjects; i++) {
m_pUnks.AddTail(ppUnk[i]);
+ }
m_pWnd = GetWindow();
- if(!m_pWnd)
+ if(!m_pWnd) {
return E_OUTOFMEMORY;
+ }
- if(!m_pWnd->OnConnect(m_pUnks))
- {
+ if(!m_pWnd->OnConnect(m_pUnks)) {
delete m_pWnd;
m_pWnd = NULL;
return E_FAIL;
}
- }
- else
- {
+ } else {
m_pWnd->OnDisconnect();
m_pWnd->DestroyWindow();
@@ -255,10 +263,13 @@ STDMETHODIMP CInternalPropertyPage::Show(UINT nCmdShow)
CAutoLock cAutoLock(this);
- if(!m_pWnd) return E_UNEXPECTED;
+ if(!m_pWnd) {
+ return E_UNEXPECTED;
+ }
- if((nCmdShow != SW_SHOW) && (nCmdShow != SW_SHOWNORMAL) && (nCmdShow != SW_HIDE))
+ if((nCmdShow != SW_SHOW) && (nCmdShow != SW_SHOWNORMAL) && (nCmdShow != SW_HIDE)) {
return E_INVALIDARG;
+ }
m_pWnd->ShowWindow(nCmdShow);
m_pWnd->Invalidate();
@@ -274,7 +285,9 @@ STDMETHODIMP CInternalPropertyPage::Move(LPCRECT pRect)
CheckPointer(pRect, E_POINTER);
- if(!m_pWnd) return E_UNEXPECTED;
+ if(!m_pWnd) {
+ return E_UNEXPECTED;
+ }
m_pWnd->MoveWindow(pRect, TRUE);
@@ -294,11 +307,13 @@ STDMETHODIMP CInternalPropertyPage::Apply()
CAutoLock cAutoLock(this);
- if(!m_pWnd || m_pUnks.IsEmpty() || !m_pPageSite)
+ if(!m_pWnd || m_pUnks.IsEmpty() || !m_pPageSite) {
return E_UNEXPECTED;
+ }
- if(m_pWnd->GetDirty() && m_pWnd->OnApply())
+ if(m_pWnd->GetDirty() && m_pWnd->OnApply()) {
m_pWnd->SetDirty(false);
+ }
return S_OK;
}
diff --git a/src/filters/InternalPropertyPage.h b/src/filters/InternalPropertyPage.h
index 013db1f97..6b293be6b 100644
--- a/src/filters/InternalPropertyPage.h
+++ b/src/filters/InternalPropertyPage.h
@@ -27,8 +27,7 @@
interface __declspec(uuid("03481710-D73E-4674-839F-03EDE2D60ED8"))
ISpecifyPropertyPages2 :
-public ISpecifyPropertyPages
-{
+public ISpecifyPropertyPages {
STDMETHOD (CreatePage) (const GUID& guid, IPropertyPage** ppPage) = 0;
};
@@ -48,7 +47,9 @@ public:
void SetDirty(bool fDirty = true) {
m_fDirty = fDirty;
- if(fDirty && m_pPageSite) m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
+ if(fDirty && m_pPageSite) {
+ m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
+ }
}
bool GetDirty() {
return m_fDirty;
@@ -110,24 +111,20 @@ public:
template<class WndClass>
class CInternalPropertyPageTempl : public CInternalPropertyPage
{
- virtual CInternalPropertyPageWnd* GetWindow()
- {
+ virtual CInternalPropertyPageWnd* GetWindow() {
return DNew WndClass();
}
- virtual LPCTSTR GetWindowTitle()
- {
+ virtual LPCTSTR GetWindowTitle() {
return WndClass::GetWindowTitle();
}
- virtual CSize GetWindowSize()
- {
+ virtual CSize GetWindowSize() {
return WndClass::GetWindowSize();
}
public:
CInternalPropertyPageTempl(LPUNKNOWN lpunk, HRESULT* phr)
- : CInternalPropertyPage(lpunk, phr)
- {
+ : CInternalPropertyPage(lpunk, phr) {
}
};
diff --git a/src/filters/PinInfoWnd.cpp b/src/filters/PinInfoWnd.cpp
index 9c652e448..0668f80ad 100644
--- a/src/filters/PinInfoWnd.cpp
+++ b/src/filters/PinInfoWnd.cpp
@@ -40,9 +40,13 @@ bool CPinInfoWnd::OnConnect(const CInterfaceList<IUnknown, &IID_IUnknown>& pUnks
m_pBF.Release();
POSITION pos = pUnks.GetHeadPosition();
- while(pos && !(m_pBF = pUnks.GetNext(pos)));
+ while(pos && !(m_pBF = pUnks.GetNext(pos))) {
+ ;
+ }
- if(!m_pBF) return false;
+ if(!m_pBF) {
+ return false;
+ }
return true;
}
@@ -56,16 +60,17 @@ static WNDPROC OldControlProc;
static LRESULT CALLBACK ControlProc(HWND control, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_KEYDOWN) {
- if (LOWORD(wParam)==VK_ESCAPE)
- return 0; // just ignore ESCAPE in edit control
+ if (LOWORD(wParam)==VK_ESCAPE) {
+ return 0; // just ignore ESCAPE in edit control
+ }
if ((LOWORD(wParam)== 'A' || LOWORD(wParam) == 'a')
- &&(GetKeyState(VK_CONTROL) < 0)) {
+ &&(GetKeyState(VK_CONTROL) < 0)) {
CEdit *pEdit = (CEdit*)CWnd::FromHandle(control);
pEdit->SetSel(0, pEdit->GetWindowTextLength(),TRUE);
return 0;
}
}
-
+
return CallWindowProc(OldControlProc, control, message, wParam, lParam); // call edit control's own windowproc
}
@@ -77,15 +82,21 @@ bool CPinInfoWnd::OnActivate()
m_pin_static.Create(_T("Pin:"), dwStyle, CRect(p + CPoint(0, 3), CSize(30, m_fontheight)), this);
m_pin_combo.Create(dwStyle|CBS_DROPDOWNLIST, CRect(p + CPoint(30, 0), CSize(450, 200)), this, IDC_PP_COMBO1);
- BeginEnumPins(m_pBF, pEP, pPin)
- {
+ BeginEnumPins(m_pBF, pEP, pPin) {
CPinInfo pi;
- if(FAILED(pPin->QueryPinInfo(&pi))) continue;
+ if(FAILED(pPin->QueryPinInfo(&pi))) {
+ continue;
+ }
CString str = CString(pi.achName);
- if(!str.Find(_T("Apple"))) str.Delete(0,1);
+ if(!str.Find(_T("Apple"))) {
+ str.Delete(0,1);
+ }
CString dir = _T("[?] ");
- if(pi.dir == PINDIR_INPUT) dir = _T("[IN] ");
- else if(pi.dir == PINDIR_OUTPUT) dir = _T("[OUT] ");
+ if(pi.dir == PINDIR_INPUT) {
+ dir = _T("[IN] ");
+ } else if(pi.dir == PINDIR_OUTPUT) {
+ dir = _T("[OUT] ");
+ }
m_pin_combo.SetItemDataPtr(m_pin_combo.AddString(dir + str), pPin);
}
EndEnumPins
@@ -98,8 +109,9 @@ bool CPinInfoWnd::OnActivate()
OnCbnSelchangeCombo1();
- for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow())
+ for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
pWnd->SetFont(&m_font, FALSE);
+ }
m_info_edit.SetFont(&m_monospacefont);
@@ -117,8 +129,7 @@ bool CPinInfoWnd::OnApply()
{
OnDeactivate();
- if(m_pBF)
- {
+ if(m_pBF) {
}
return true;
@@ -141,34 +152,35 @@ void CPinInfoWnd::OnCbnSelchangeCombo1()
m_info_edit.SetWindowText(_T(""));
int i = m_pin_combo.GetCurSel();
- if(i < 0) return;
+ if(i < 0) {
+ return;
+ }
CComPtr<IPin> pPin = (IPin*)m_pin_combo.GetItemDataPtr(i);
- if(!pPin) return;
+ if(!pPin) {
+ return;
+ }
CString str;
PIN_INFO PinInfo;
- if (SUCCEEDED (pPin->QueryPinInfo(&PinInfo)))
- {
+ if (SUCCEEDED (pPin->QueryPinInfo(&PinInfo))) {
CString strName;
CLSID FilterClsid;
FILTER_INFO FilterInfo;
- if (SUCCEEDED (PinInfo.pFilter->QueryFilterInfo (&FilterInfo)))
- {
+ if (SUCCEEDED (PinInfo.pFilter->QueryFilterInfo (&FilterInfo))) {
CRegKey key;
PinInfo.pFilter->GetClassID(&FilterClsid);
- if (ERROR_SUCCESS == key.Open (HKEY_CLASSES_ROOT, _T("CLSID\\{083863F1-70DE-11D0-BD40-00A0C911CE86}\\Instance\\") + CStringFromGUID(FilterClsid), KEY_READ))
- {
+ if (ERROR_SUCCESS == key.Open (HKEY_CLASSES_ROOT, _T("CLSID\\{083863F1-70DE-11D0-BD40-00A0C911CE86}\\Instance\\") + CStringFromGUID(FilterClsid), KEY_READ)) {
ULONG len;
TCHAR buff[128];
len = countof(buff);
key.QueryStringValue(_T("FriendlyName"), buff, &len);
strName = CString (buff);
- }
- else
+ } else {
strName = FilterInfo.achName;
+ }
str.Format (_T("Filter : %s - CLSID : %s\n\n"), strName, CStringFromGUID(FilterClsid));
AddLine(str);
FilterInfo.pGraph->Release();
@@ -179,8 +191,7 @@ void CPinInfoWnd::OnCbnSelchangeCombo1()
CMediaTypeEx cmt;
CComPtr<IPin> pPinTo;
- if(SUCCEEDED(pPin->ConnectedTo(&pPinTo)) && pPinTo)
- {
+ if(SUCCEEDED(pPin->ConnectedTo(&pPinTo)) && pPinTo) {
str.Format(_T("- Connected to:\n\nCLSID: %s\nFilter: %s\nPin: %s\n\n"),
CString(CStringFromGUID(GetCLSID(pPinTo))),
CString(GetFilterName(GetFilterFromPin(pPinTo))),
@@ -190,38 +201,35 @@ void CPinInfoWnd::OnCbnSelchangeCombo1()
AddLine(_T("- Connection media type:\n\n"));
- if(SUCCEEDED(pPin->ConnectionMediaType(&cmt)))
- {
+ if(SUCCEEDED(pPin->ConnectionMediaType(&cmt))) {
CAtlList<CString> sl;
cmt.Dump(sl);
POSITION pos = sl.GetHeadPosition();
- while(pos) AddLine(sl.GetNext(pos) + '\n');
+ while(pos) {
+ AddLine(sl.GetNext(pos) + '\n');
+ }
}
- }
- else
- {
+ } else {
str = _T("- Not connected\n\n");
}
int iMT = 0;
- BeginEnumMediaTypes(pPin, pEMT, pmt)
- {
+ BeginEnumMediaTypes(pPin, pEMT, pmt) {
CMediaTypeEx mt(*pmt);
str.Format(_T("- Enumerated media type %d:\n\n"), iMT++);
AddLine(str);
- if(cmt.majortype != GUID_NULL && mt == cmt)
- {
+ if(cmt.majortype != GUID_NULL && mt == cmt) {
AddLine(_T("Set as the current media type\n\n"));
- }
- else
- {
+ } else {
CAtlList<CString> sl;
mt.Dump(sl);
POSITION pos = sl.GetHeadPosition();
- while(pos) AddLine(sl.GetNext(pos) + '\n');
+ while(pos) {
+ AddLine(sl.GetNext(pos) + '\n');
+ }
}
}
EndEnumMediaTypes(pmt)
diff --git a/src/filters/PinInfoWnd.h b/src/filters/PinInfoWnd.h
index 520e0ec66..6ab567ca5 100644
--- a/src/filters/PinInfoWnd.h
+++ b/src/filters/PinInfoWnd.h
@@ -31,8 +31,7 @@ class __declspec(uuid("A1EB391C-6089-4A87-9988-BE50872317D4"))
{
CComQIPtr<IBaseFilter> m_pBF;
- enum
- {
+ enum {
IDC_PP_COMBO1 = 10000,
IDC_PP_EDIT1,
};
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxer.cpp b/src/filters/muxer/BaseMuxer/BaseMuxer.cpp
index fb596eaaa..4bcc3f90c 100644
--- a/src/filters/muxer/BaseMuxer/BaseMuxer.cpp
+++ b/src/filters/muxer/BaseMuxer/BaseMuxer.cpp
@@ -30,7 +30,9 @@ CBaseMuxerFilter::CBaseMuxerFilter(LPUNKNOWN pUnk, HRESULT* phr, const CLSID& cl
: CBaseFilter(NAME("CBaseMuxerFilter"), pUnk, this, clsid)
, m_rtCurrent(0)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pOutput.Attach(DNew CBaseMuxerOutputPin(L"Output", this, this, phr));
AddInput();
}
@@ -60,10 +62,11 @@ STDMETHODIMP CBaseMuxerFilter::NonDelegatingQueryInterface(REFIID riid, void** p
void CBaseMuxerFilter::AddInput()
{
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBasePin* pPin = m_pInputs.GetNext(pos);
- if(!pPin->IsConnected()) return;
+ if(!pPin->IsConnected()) {
+ return;
+ }
}
CStringW name;
@@ -117,81 +120,77 @@ DWORD CBaseMuxerFilter::ThreadProc()
POSITION pos;
- while(1)
- {
+ while(1) {
DWORD cmd = GetRequest();
- switch(cmd)
- {
- default:
- case CMD_EXIT:
- CAMThread::m_hThread = NULL;
- Reply(S_OK);
- return 0;
-
- case CMD_RUN:
- m_pActivePins.RemoveAll();
- m_pPins.RemoveAll();
-
- pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
- CBaseMuxerInputPin* pPin = m_pInputs.GetNext(pos);
- if(pPin->IsConnected())
- {
- m_pActivePins.AddTail(pPin);
- m_pPins.AddTail(pPin);
+ switch(cmd) {
+ default:
+ case CMD_EXIT:
+ CAMThread::m_hThread = NULL;
+ Reply(S_OK);
+ return 0;
+
+ case CMD_RUN:
+ m_pActivePins.RemoveAll();
+ m_pPins.RemoveAll();
+
+ pos = m_pInputs.GetHeadPosition();
+ while(pos) {
+ CBaseMuxerInputPin* pPin = m_pInputs.GetNext(pos);
+ if(pPin->IsConnected()) {
+ m_pActivePins.AddTail(pPin);
+ m_pPins.AddTail(pPin);
+ }
}
- }
- m_rtCurrent = 0;
+ m_rtCurrent = 0;
- Reply(S_OK);
+ Reply(S_OK);
- MuxInit();
+ MuxInit();
- try
- {
- MuxHeaderInternal();
+ try {
+ MuxHeaderInternal();
- while(!CheckRequest(NULL) && m_pActivePins.GetCount())
- {
- if(m_State == State_Paused) {
- Sleep(10);
- continue;
- }
+ while(!CheckRequest(NULL) && m_pActivePins.GetCount()) {
+ if(m_State == State_Paused) {
+ Sleep(10);
+ continue;
+ }
- CAutoPtr<MuxerPacket> pPacket = GetPacket();
- if(!pPacket) {
- Sleep(1);
- continue;
- }
+ CAutoPtr<MuxerPacket> pPacket = GetPacket();
+ if(!pPacket) {
+ Sleep(1);
+ continue;
+ }
- if(pPacket->IsTimeValid())
- m_rtCurrent = pPacket->rtStart;
+ if(pPacket->IsTimeValid()) {
+ m_rtCurrent = pPacket->rtStart;
+ }
- if(pPacket->IsEOS())
- m_pActivePins.RemoveAt(m_pActivePins.Find(pPacket->pPin));
+ if(pPacket->IsEOS()) {
+ m_pActivePins.RemoveAt(m_pActivePins.Find(pPacket->pPin));
+ }
- MuxPacketInternal(pPacket);
- }
+ MuxPacketInternal(pPacket);
+ }
- MuxFooterInternal();
- }
- catch(HRESULT hr)
- {
- CComQIPtr<IMediaEventSink>(m_pGraph)->Notify(EC_ERRORABORT, hr, 0);
- }
+ MuxFooterInternal();
+ } catch(HRESULT hr) {
+ CComQIPtr<IMediaEventSink>(m_pGraph)->Notify(EC_ERRORABORT, hr, 0);
+ }
- m_pOutput->DeliverEndOfStream();
+ m_pOutput->DeliverEndOfStream();
- pos = m_pRawOutputs.GetHeadPosition();
- while(pos) m_pRawOutputs.GetNext(pos)->DeliverEndOfStream();
+ pos = m_pRawOutputs.GetHeadPosition();
+ while(pos) {
+ m_pRawOutputs.GetNext(pos)->DeliverEndOfStream();
+ }
- m_pActivePins.RemoveAll();
- m_pPins.RemoveAll();
+ m_pActivePins.RemoveAll();
+ m_pPins.RemoveAll();
- break;
+ break;
}
}
@@ -205,19 +204,20 @@ void CBaseMuxerFilter::MuxHeaderInternal()
{
TRACE(_T("MuxHeader\n"));
- if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream())
+ if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream()) {
MuxHeader(pBitStream);
+ }
MuxHeader();
//
POSITION pos = m_pPins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
if(CBaseMuxerInputPin* pInput = m_pPins.GetNext(pos))
- if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin()))
+ if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin())) {
pOutput->MuxHeader(pInput->CurrentMediaType());
+ }
}
}
@@ -231,33 +231,36 @@ void CBaseMuxerFilter::MuxPacketInternal(const MuxerPacket* pPacket)
!!(pPacket->flags & MuxerPacket::bogus),
pPacket->rtStart/10000, pPacket->rtStop/10000);
- if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream())
+ if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream()) {
MuxPacket(pBitStream, pPacket);
+ }
MuxPacket(pPacket);
if(CBaseMuxerInputPin* pInput = pPacket->pPin)
- if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin()))
+ if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin())) {
pOutput->MuxPacket(pInput->CurrentMediaType(), pPacket);
+ }
}
void CBaseMuxerFilter::MuxFooterInternal()
{
TRACE(_T("MuxFooter\n"));
- if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream())
+ if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream()) {
MuxFooter(pBitStream);
+ }
MuxFooter();
//
POSITION pos = m_pPins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
if(CBaseMuxerInputPin* pInput = m_pPins.GetNext(pos))
- if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin()))
+ if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin())) {
pOutput->MuxFooter(pInput->CurrentMediaType());
+ }
}
}
@@ -268,24 +271,23 @@ CAutoPtr<MuxerPacket> CBaseMuxerFilter::GetPacket()
int i = int(m_pActivePins.GetCount());
POSITION pos = m_pActivePins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBaseMuxerInputPin* pPin = m_pActivePins.GetNext(pos);
CAutoLock cAutoLock(&pPin->m_csQueue);
- if(!pPin->m_queue.GetCount()) continue;
+ if(!pPin->m_queue.GetCount()) {
+ continue;
+ }
MuxerPacket* p = pPin->m_queue.GetHead();
- if(p->IsBogus() || !p->IsTimeValid() || p->IsEOS())
- {
+ if(p->IsBogus() || !p->IsTimeValid() || p->IsEOS()) {
pPinMin = pPin;
i = 0;
break;
}
- if(p->rtStart < rtMin)
- {
+ if(p->rtStart < rtMin) {
rtMin = p->rtStart;
pPinMin = pPin;
}
@@ -295,14 +297,13 @@ CAutoPtr<MuxerPacket> CBaseMuxerFilter::GetPacket()
CAutoPtr<MuxerPacket> pPacket;
- if(pPinMin && i == 0)
- {
+ if(pPinMin && i == 0) {
pPacket = pPinMin->PopPacket();
- }
- else
- {
+ } else {
pos = m_pActivePins.GetHeadPosition();
- while(pos) m_pActivePins.GetNext(pos)->m_evAcceptPacket.Set();
+ while(pos) {
+ m_pActivePins.GetNext(pos)->m_evAcceptPacket.Set();
+ }
}
return pPacket;
@@ -319,25 +320,24 @@ CBasePin* CBaseMuxerFilter::GetPin(int n)
{
CAutoLock cAutoLock(this);
- if(n >= 0 && n < (int)m_pInputs.GetCount())
- {
- if(POSITION pos = m_pInputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pInputs.GetCount()) {
+ if(POSITION pos = m_pInputs.FindIndex(n)) {
return m_pInputs.GetAt(pos);
+ }
}
n -= int(m_pInputs.GetCount());
- if(n == 0 && m_pOutput)
- {
+ if(n == 0 && m_pOutput) {
return m_pOutput;
}
n--;
- if(n >= 0 && n < (int)m_pRawOutputs.GetCount())
- {
- if(POSITION pos = m_pRawOutputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pRawOutputs.GetCount()) {
+ if(POSITION pos = m_pRawOutputs.FindIndex(n)) {
return m_pRawOutputs.GetAt(pos);
+ }
}
n -= int(m_pRawOutputs.GetCount());
@@ -350,7 +350,9 @@ STDMETHODIMP CBaseMuxerFilter::Stop()
CAutoLock cAutoLock(this);
HRESULT hr = __super::Stop();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
CallWorker(CMD_EXIT);
@@ -364,10 +366,11 @@ STDMETHODIMP CBaseMuxerFilter::Pause()
FILTER_STATE fs = m_State;
HRESULT hr = __super::Pause();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
- if(fs == State_Stopped && m_pOutput)
- {
+ if(fs == State_Stopped && m_pOutput) {
CAMThread::Create();
CallWorker(CMD_RUN);
}
@@ -380,7 +383,9 @@ STDMETHODIMP CBaseMuxerFilter::Run(REFERENCE_TIME tStart)
CAutoLock cAutoLock(this);
HRESULT hr = __super::Run(tStart);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
return hr;
}
@@ -394,25 +399,32 @@ STDMETHODIMP CBaseMuxerFilter::GetCapabilities(DWORD* pCapabilities)
STDMETHODIMP CBaseMuxerFilter::CheckCapabilities(DWORD* pCapabilities)
{
CheckPointer(pCapabilities, E_POINTER);
- if(*pCapabilities == 0) return S_OK;
+ if(*pCapabilities == 0) {
+ return S_OK;
+ }
DWORD caps;
GetCapabilities(&caps);
caps &= *pCapabilities;
return caps == 0 ? E_FAIL : caps == *pCapabilities ? S_OK : S_FALSE;
}
-STDMETHODIMP CBaseMuxerFilter::IsFormatSupported(const GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::IsFormatSupported(const GUID* pFormat)
+{
return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;
}
-STDMETHODIMP CBaseMuxerFilter::QueryPreferredFormat(GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::QueryPreferredFormat(GUID* pFormat)
+{
return GetTimeFormat(pFormat);
}
-STDMETHODIMP CBaseMuxerFilter::GetTimeFormat(GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::GetTimeFormat(GUID* pFormat)
+{
return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;
}
-STDMETHODIMP CBaseMuxerFilter::IsUsingTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::IsUsingTimeFormat(const GUID* pFormat)
+{
return IsFormatSupported(pFormat);
}
-STDMETHODIMP CBaseMuxerFilter::SetTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::SetTimeFormat(const GUID* pFormat)
+{
return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;
}
STDMETHODIMP CBaseMuxerFilter::GetDuration(LONGLONG* pDuration)
@@ -422,11 +434,14 @@ STDMETHODIMP CBaseMuxerFilter::GetDuration(LONGLONG* pDuration)
POSITION pos = m_pInputs.GetHeadPosition();
while(pos) {
REFERENCE_TIME rt = m_pInputs.GetNext(pos)->GetDuration();
- if(rt > *pDuration) *pDuration = rt;
+ if(rt > *pDuration) {
+ *pDuration = rt;
+ }
}
return S_OK;
}
-STDMETHODIMP CBaseMuxerFilter::GetStopPosition(LONGLONG* pStop) {
+STDMETHODIMP CBaseMuxerFilter::GetStopPosition(LONGLONG* pStop)
+{
return E_NOTIMPL;
}
STDMETHODIMP CBaseMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent)
@@ -435,22 +450,25 @@ STDMETHODIMP CBaseMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent)
*pCurrent = m_rtCurrent;
return S_OK;
}
-STDMETHODIMP CBaseMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {
+STDMETHODIMP CBaseMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
+{
return E_NOTIMPL;
}
STDMETHODIMP CBaseMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
{
FILTER_STATE fs;
- if(SUCCEEDED(GetState(0, &fs)) && fs == State_Stopped)
- {
+ if(SUCCEEDED(GetState(0, &fs)) && fs == State_Stopped) {
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBasePin* pPin = m_pInputs.GetNext(pos);
CComQIPtr<IMediaSeeking> pMS = pPin->GetConnected();
- if(!pMS) pMS = GetFilterFromPin(pPin->GetConnected());
- if(pMS) pMS->SetPositions(pCurrent, dwCurrentFlags, pStop, dwStopFlags);
+ if(!pMS) {
+ pMS = GetFilterFromPin(pPin->GetConnected());
+ }
+ if(pMS) {
+ pMS->SetPositions(pCurrent, dwCurrentFlags, pStop, dwStopFlags);
+ }
}
return S_OK;
@@ -458,18 +476,23 @@ STDMETHODIMP CBaseMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentF
return VFW_E_WRONG_STATE;
}
-STDMETHODIMP CBaseMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) {
+STDMETHODIMP CBaseMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) {
+STDMETHODIMP CBaseMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::SetRate(double dRate) {
+STDMETHODIMP CBaseMuxerFilter::SetRate(double dRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::GetRate(double* pdRate) {
+STDMETHODIMP CBaseMuxerFilter::GetRate(double* pdRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::GetPreroll(LONGLONG* pllPreroll) {
+STDMETHODIMP CBaseMuxerFilter::GetPreroll(LONGLONG* pllPreroll)
+{
return E_NOTIMPL;
}
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp
index abfb8923e..e100bfe81 100644
--- a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp
+++ b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp
@@ -68,17 +68,21 @@ void CBaseMuxerInputPin::PushPacket(CAutoPtr<MuxerPacket> pPacket)
for(int i = 0; m_pFilter->IsActive() && !m_bFlushing
&& !m_evAcceptPacket.Wait(1)
&& i < 1000;
- i++);
+ i++) {
+ ;
+ }
- if(!m_pFilter->IsActive() || m_bFlushing)
+ if(!m_pFilter->IsActive() || m_bFlushing) {
return;
+ }
CAutoLock cAutoLock(&m_csQueue);
m_queue.AddTail(pPacket);
- if(m_queue.GetCount() >= MAXQUEUESIZE)
+ if(m_queue.GetCount() >= MAXQUEUESIZE) {
m_evAcceptPacket.Reset();
+ }
}
CAutoPtr<MuxerPacket> CBaseMuxerInputPin::PopPacket()
@@ -87,46 +91,48 @@ CAutoPtr<MuxerPacket> CBaseMuxerInputPin::PopPacket()
CAutoLock cAutoLock(&m_csQueue);
- if(m_queue.GetCount())
+ if(m_queue.GetCount()) {
pPacket = m_queue.RemoveHead();
+ }
- if(m_queue.GetCount() < MAXQUEUESIZE)
+ if(m_queue.GetCount() < MAXQUEUESIZE) {
m_evAcceptPacket.Set();
+ }
return pPacket;
}
HRESULT CBaseMuxerInputPin::CheckMediaType(const CMediaType* pmt)
{
- if(pmt->formattype == FORMAT_WaveFormatEx)
- {
+ if(pmt->formattype == FORMAT_WaveFormatEx) {
WORD wFormatTag = ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag;
if((wFormatTag == WAVE_FORMAT_PCM
- || wFormatTag == WAVE_FORMAT_EXTENSIBLE
- || wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
- && pmt->subtype != FOURCCMap(wFormatTag)
- && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_EXTENSIBLE)
- && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
- && pmt->subtype != MEDIASUBTYPE_DVD_LPCM_AUDIO
- && pmt->subtype != MEDIASUBTYPE_DOLBY_AC3
- && pmt->subtype != MEDIASUBTYPE_DTS)
- {
+ || wFormatTag == WAVE_FORMAT_EXTENSIBLE
+ || wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
+ && pmt->subtype != FOURCCMap(wFormatTag)
+ && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_EXTENSIBLE)
+ && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
+ && pmt->subtype != MEDIASUBTYPE_DVD_LPCM_AUDIO
+ && pmt->subtype != MEDIASUBTYPE_DOLBY_AC3
+ && pmt->subtype != MEDIASUBTYPE_DTS) {
return E_INVALIDARG;
}
}
return pmt->majortype == MEDIATYPE_Video
- || pmt->majortype == MEDIATYPE_Audio && pmt->formattype != FORMAT_VorbisFormat
- || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
- || pmt->majortype == MEDIATYPE_Subtitle
- ? S_OK
- : E_INVALIDARG;
+ || pmt->majortype == MEDIATYPE_Audio && pmt->formattype != FORMAT_VorbisFormat
+ || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
+ || pmt->majortype == MEDIATYPE_Subtitle
+ ? S_OK
+ : E_INVALIDARG;
}
HRESULT CBaseMuxerInputPin::BreakConnect()
{
HRESULT hr = __super::BreakConnect();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
RemoveAll();
@@ -138,36 +144,37 @@ HRESULT CBaseMuxerInputPin::BreakConnect()
HRESULT CBaseMuxerInputPin::CompleteConnect(IPin* pReceivePin)
{
HRESULT hr = __super::CompleteConnect(pReceivePin);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
// duration
m_rtDuration = 0;
CComQIPtr<IMediaSeeking> pMS;
- if((pMS = GetFilterFromPin(pReceivePin)) || (pMS = pReceivePin))
+ if((pMS = GetFilterFromPin(pReceivePin)) || (pMS = pReceivePin)) {
pMS->GetDuration(&m_rtDuration);
+ }
// properties
- for(CComPtr<IPin> pPin = pReceivePin; pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin)))
- {
- if(CComQIPtr<IDSMPropertyBag> pPB = pPin)
- {
+ for(CComPtr<IPin> pPin = pReceivePin; pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin))) {
+ if(CComQIPtr<IDSMPropertyBag> pPB = pPin) {
ULONG cProperties = 0;
- if(SUCCEEDED(pPB->CountProperties(&cProperties)) && cProperties > 0)
- {
- for(ULONG iProperty = 0; iProperty < cProperties; iProperty++)
- {
+ if(SUCCEEDED(pPB->CountProperties(&cProperties)) && cProperties > 0) {
+ for(ULONG iProperty = 0; iProperty < cProperties; iProperty++) {
PROPBAG2 PropBag;
memset(&PropBag, 0, sizeof(PropBag));
ULONG cPropertiesReturned = 0;
- if(FAILED(pPB->GetPropertyInfo(iProperty, 1, &PropBag, &cPropertiesReturned)))
+ if(FAILED(pPB->GetPropertyInfo(iProperty, 1, &PropBag, &cPropertiesReturned))) {
continue;
+ }
HRESULT hr;
CComVariant var;
- if(SUCCEEDED(pPB->Read(1, &PropBag, NULL, &var, &hr)) && SUCCEEDED(hr))
+ if(SUCCEEDED(pPB->Read(1, &PropBag, NULL, &var, &hr)) && SUCCEEDED(hr)) {
SetProperty(PropBag.pstrName, &var);
+ }
CoTaskMemFree(PropBag.pstrName);
}
@@ -208,47 +215,44 @@ STDMETHODIMP CBaseMuxerInputPin::Receive(IMediaSample* pSample)
CAutoLock cAutoLock(&m_csReceive);
HRESULT hr = __super::Receive(pSample);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
CAutoPtr<MuxerPacket> pPacket(DNew MuxerPacket(this));
long len = pSample->GetActualDataLength();
BYTE* pData = NULL;
- if(FAILED(pSample->GetPointer(&pData)) || !pData)
+ if(FAILED(pSample->GetPointer(&pData)) || !pData) {
return S_OK;
+ }
pPacket->pData.SetCount(len);
memcpy(pPacket->pData.GetData(), pData, len);
- if(S_OK == pSample->IsSyncPoint() || m_mt.majortype == MEDIATYPE_Audio && !m_mt.bTemporalCompression)
- {
+ if(S_OK == pSample->IsSyncPoint() || m_mt.majortype == MEDIATYPE_Audio && !m_mt.bTemporalCompression) {
pPacket->flags |= MuxerPacket::syncpoint;
}
- if(S_OK == pSample->GetTime(&pPacket->rtStart, &pPacket->rtStop))
- {
+ if(S_OK == pSample->GetTime(&pPacket->rtStart, &pPacket->rtStop)) {
pPacket->flags |= MuxerPacket::timevalid;
pPacket->rtStart += m_tStart;
pPacket->rtStop += m_tStart;
- if((pPacket->flags & MuxerPacket::syncpoint) && pPacket->rtStart < m_rtMaxStart)
- {
+ if((pPacket->flags & MuxerPacket::syncpoint) && pPacket->rtStart < m_rtMaxStart) {
pPacket->flags &= ~MuxerPacket::syncpoint;
pPacket->flags |= MuxerPacket::bogus;
}
m_rtMaxStart = max(m_rtMaxStart, pPacket->rtStart);
- }
- else if(pPacket->flags & MuxerPacket::syncpoint)
- {
+ } else if(pPacket->flags & MuxerPacket::syncpoint) {
pPacket->flags &= ~MuxerPacket::syncpoint;
pPacket->flags |= MuxerPacket::bogus;
}
- if(S_OK == pSample->IsDiscontinuity())
- {
+ if(S_OK == pSample->IsDiscontinuity()) {
pPacket->flags |= MuxerPacket::discontinuity;
}
@@ -264,7 +268,9 @@ STDMETHODIMP CBaseMuxerInputPin::EndOfStream()
CAutoLock cAutoLock(&m_csReceive);
HRESULT hr = __super::EndOfStream();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
ASSERT(!m_fEOS);
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h
index 1ae51ae1d..788c00b03 100644
--- a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h
+++ b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h
@@ -26,8 +26,7 @@
class CBaseMuxerInputPin;
-struct MuxerPacket
-{
+struct MuxerPacket {
CBaseMuxerInputPin* pPin;
REFERENCE_TIME rtStart, rtStop;
CAtlArray<BYTE> pData;
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp b/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp
index 108549d91..45d32cd11 100644
--- a/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp
+++ b/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp
@@ -40,10 +40,8 @@ CBaseMuxerOutputPin::CBaseMuxerOutputPin(LPCWSTR pName, CBaseFilter* pFilter, CC
IBitStream* CBaseMuxerOutputPin::GetBitStream()
{
- if(!m_pBitStream)
- {
- if(CComQIPtr<IStream> pStream = GetConnected())
- {
+ if(!m_pBitStream) {
+ if(CComQIPtr<IStream> pStream = GetConnected()) {
m_pBitStream = DNew CBitStream(pStream, true);
}
}
@@ -69,9 +67,13 @@ HRESULT CBaseMuxerOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_P
pProperties->cbBuffer = 1;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
ASSERT(Actual.cBuffers == pProperties->cBuffers);
return NOERROR;
@@ -88,8 +90,12 @@ HRESULT CBaseMuxerOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
{
CAutoLock cAutoLock(m_pLock);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->ResetFormatBuffer();
pmt->InitMediaType();
@@ -133,59 +139,50 @@ STDMETHODIMP CBaseMuxerRawOutputPin::NonDelegatingQueryInterface(REFIID riid, vo
void CBaseMuxerRawOutputPin::MuxHeader(const CMediaType& mt)
{
CComQIPtr<IBitStream> pBitStream = GetBitStream();
- if(!pBitStream) return;
+ if(!pBitStream) {
+ return;
+ }
const BYTE utf8bom[3] = {0xef, 0xbb, 0xbf};
- if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO)
- {
+ if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO) {
MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.Format();
- for(DWORD i = 0; i < vih->cbSequenceHeader-2; i += 2)
- {
+ for(DWORD i = 0; i < vih->cbSequenceHeader-2; i += 2) {
pBitStream->BitWrite(0x00000001, 32);
WORD size = (((BYTE*)vih->dwSequenceHeader)[i+0]<<8) | ((BYTE*)vih->dwSequenceHeader)[i+1];
pBitStream->ByteWrite(&((BYTE*)vih->dwSequenceHeader)[i+2], size);
i += size;
}
- }
- else if(mt.subtype == MEDIASUBTYPE_UTF8)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_UTF8) {
pBitStream->ByteWrite(utf8bom, sizeof(utf8bom));
- }
- else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2) {
SUBTITLEINFO* si = (SUBTITLEINFO*)mt.Format();
BYTE* p = (BYTE*)si + si->dwOffset;
- if(memcmp(utf8bom, p, 3) != 0)
+ if(memcmp(utf8bom, p, 3) != 0) {
pBitStream->ByteWrite(utf8bom, sizeof(utf8bom));
+ }
CStringA str((char*)p, mt.FormatLength() - (p - mt.Format()));
pBitStream->StrWrite(str + '\n', true);
- if(str.Find("[Events]") < 0)
+ if(str.Find("[Events]") < 0) {
pBitStream->StrWrite("\n\n[Events]\n", true);
- }
- else if(mt.subtype == MEDIASUBTYPE_SSF)
- {
+ }
+ } else if(mt.subtype == MEDIASUBTYPE_SSF) {
DWORD dwOffset = ((SUBTITLEINFO*)mt.pbFormat)->dwOffset;
try {
m_ssf.Parse(ssf::MemoryInputStream(mt.pbFormat + dwOffset, mt.cbFormat - dwOffset, false, false));
- }
- catch(ssf::Exception&) {}
- }
- else if(mt.subtype == MEDIASUBTYPE_VOBSUB)
- {
+ } catch(ssf::Exception&) {}
+ } else if(mt.subtype == MEDIASUBTYPE_VOBSUB) {
m_idx.RemoveAll();
- }
- else if(mt.majortype == MEDIATYPE_Audio
- && (mt.subtype == MEDIASUBTYPE_PCM
- || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
- || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
- || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
- && mt.formattype == FORMAT_WaveFormatEx)
- {
+ } else if(mt.majortype == MEDIATYPE_Audio
+ && (mt.subtype == MEDIASUBTYPE_PCM
+ || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
+ && mt.formattype == FORMAT_WaveFormatEx) {
pBitStream->BitWrite('RIFF', 32);
pBitStream->BitWrite(0, 32); // file length - 8, set later
pBitStream->BitWrite('WAVE', 32);
@@ -202,34 +199,46 @@ void CBaseMuxerRawOutputPin::MuxHeader(const CMediaType& mt)
void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* pPacket)
{
CComQIPtr<IBitStream> pBitStream = GetBitStream();
- if(!pBitStream) return;
+ if(!pBitStream) {
+ return;
+ }
const BYTE* pData = pPacket->pData.GetData();
const int DataSize = int(pPacket->pData.GetCount());
- if(mt.subtype == MEDIASUBTYPE_AAC && mt.formattype == FORMAT_WaveFormatEx)
- {
+ if(mt.subtype == MEDIASUBTYPE_AAC && mt.formattype == FORMAT_WaveFormatEx) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
int profile = 0;
int srate_idx = 11;
- if(92017 <= wfe->nSamplesPerSec) srate_idx = 0;
- else if(75132 <= wfe->nSamplesPerSec) srate_idx = 1;
- else if(55426 <= wfe->nSamplesPerSec) srate_idx = 2;
- else if(46009 <= wfe->nSamplesPerSec) srate_idx = 3;
- else if(37566 <= wfe->nSamplesPerSec) srate_idx = 4;
- else if(27713 <= wfe->nSamplesPerSec) srate_idx = 5;
- else if(23004 <= wfe->nSamplesPerSec) srate_idx = 6;
- else if(18783 <= wfe->nSamplesPerSec) srate_idx = 7;
- else if(13856 <= wfe->nSamplesPerSec) srate_idx = 8;
- else if(11502 <= wfe->nSamplesPerSec) srate_idx = 9;
- else if(9391 <= wfe->nSamplesPerSec) srate_idx = 10;
+ if(92017 <= wfe->nSamplesPerSec) {
+ srate_idx = 0;
+ } else if(75132 <= wfe->nSamplesPerSec) {
+ srate_idx = 1;
+ } else if(55426 <= wfe->nSamplesPerSec) {
+ srate_idx = 2;
+ } else if(46009 <= wfe->nSamplesPerSec) {
+ srate_idx = 3;
+ } else if(37566 <= wfe->nSamplesPerSec) {
+ srate_idx = 4;
+ } else if(27713 <= wfe->nSamplesPerSec) {
+ srate_idx = 5;
+ } else if(23004 <= wfe->nSamplesPerSec) {
+ srate_idx = 6;
+ } else if(18783 <= wfe->nSamplesPerSec) {
+ srate_idx = 7;
+ } else if(13856 <= wfe->nSamplesPerSec) {
+ srate_idx = 8;
+ } else if(11502 <= wfe->nSamplesPerSec) {
+ srate_idx = 9;
+ } else if(9391 <= wfe->nSamplesPerSec) {
+ srate_idx = 10;
+ }
int channels = wfe->nChannels;
- if(wfe->cbSize >= 2)
- {
+ if(wfe->cbSize >= 2) {
BYTE* p = (BYTE*)(wfe+1);
profile = (p[0]>>3)-1;
srate_idx = ((p[0]&7)<<1)|((p[1]&0x80)>>7);
@@ -246,27 +255,22 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
hdr[6] = 0xfc;
pBitStream->ByteWrite(hdr, sizeof(hdr));
- }
- else if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO)
- {
+ } else if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO) {
const BYTE* p = pData;
int i = DataSize;
- while(i >= 4)
- {
+ while(i >= 4) {
DWORD len = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
i -= len + 4;
p += len + 4;
}
- if(i == 0)
- {
+ if(i == 0) {
p = pData;
i = DataSize;
- while(i >= 4)
- {
+ while(i >= 4) {
DWORD len = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
pBitStream->BitWrite(0x00000001, 32);
@@ -287,12 +291,12 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
return;
}
- }
- else if(mt.subtype == MEDIASUBTYPE_UTF8 || mt.majortype == MEDIATYPE_Text)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_UTF8 || mt.majortype == MEDIATYPE_Text) {
CStringA str((char*)pData, DataSize);
str.Trim();
- if(str.IsEmpty()) return;
+ if(str.IsEmpty()) {
+ return;
+ }
DVD_HMSF_TIMECODE start = RT2HMSF(pPacket->rtStart, 25);
DVD_HMSF_TIMECODE stop = RT2HMSF(pPacket->rtStop, 25);
@@ -306,12 +310,12 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
pBitStream->StrWrite(str, true);
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2) {
CStringA str((char*)pData, DataSize);
str.Trim();
- if(str.IsEmpty()) return;
+ if(str.IsEmpty()) {
+ return;
+ }
DVD_HMSF_TIMECODE start = RT2HMSF(pPacket->rtStart, 25);
DVD_HMSF_TIMECODE stop = RT2HMSF(pPacket->rtStop, 25);
@@ -320,7 +324,9 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
CAtlList<CStringA> sl;
Explode(str, sl, ',', fields);
- if(sl.GetCount() < fields) return;
+ if(sl.GetCount() < fields) {
+ return;
+ }
CStringA readorder = sl.RemoveHead(); // TODO
CStringA layer = sl.RemoveHead();
@@ -329,11 +335,15 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
CStringA left = sl.RemoveHead();
CStringA right = sl.RemoveHead();
CStringA top = sl.RemoveHead();
- if(fields == 10) top += ',' + sl.RemoveHead(); // bottom
+ if(fields == 10) {
+ top += ',' + sl.RemoveHead(); // bottom
+ }
CStringA effect = sl.RemoveHead();
str = sl.RemoveHead();
- if(mt.subtype == MEDIASUBTYPE_SSA) layer = "Marked=0";
+ if(mt.subtype == MEDIASUBTYPE_SSA) {
+ layer = "Marked=0";
+ }
str.Format("Dialogue: %s,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s,%s,%s,%s,%s,%s,%s\n",
layer,
@@ -345,20 +355,15 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
pBitStream->StrWrite(str, true);
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_SSF)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSF) {
float start = (float)pPacket->rtStart / 10000000;
float stop = (float)pPacket->rtStop / 10000000;
m_ssf.Append(ssf::WCharInputStream(UTF8To16(CStringA((char*)pData, DataSize))), start, stop, true);
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_VOBSUB)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_VOBSUB) {
bool fTimeValid = pPacket->IsTimeValid();
- if(fTimeValid)
- {
+ if(fTimeValid) {
idx_t i;
i.rt = pPacket->rtStart;
i.fp = pBitStream->GetPos();
@@ -367,8 +372,7 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
int DataSizeLeft = DataSize;
- while(DataSizeLeft > 0)
- {
+ while(DataSizeLeft > 0) {
int BytesAvail = 0x7ec - (fTimeValid ? 9 : 4);
int Size = min(BytesAvail, DataSizeLeft);
int Padding = 0x800 - Size - 20 - (fTimeValid ? 9 : 4);
@@ -378,13 +382,10 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
pBitStream->BitWrite(0x000003f8, 32);
pBitStream->BitWrite(0x000001bd, 32);
- if(fTimeValid)
- {
+ if(fTimeValid) {
pBitStream->BitWrite(Size+9, 16);
pBitStream->BitWrite(0x8180052100010001ui64, 64);
- }
- else
- {
+ } else {
pBitStream->BitWrite(Size+4, 16);
pBitStream->BitWrite(0x810000, 24);
}
@@ -396,28 +397,28 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
pData += Size;
DataSizeLeft -= Size;
- if(Padding > 0)
- {
+ if(Padding > 0) {
Padding -= 6;
ASSERT(Padding >= 0);
pBitStream->BitWrite(0x000001be, 32);
pBitStream->BitWrite(Padding, 16);
- while(Padding-- > 0) pBitStream->BitWrite(0xff, 8);
+ while(Padding-- > 0) {
+ pBitStream->BitWrite(0xff, 8);
+ }
}
fTimeValid = false;
}
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
// This code is probably totally broken for anything but 16 bits
for(int i = 0, bps = wfe->wBitsPerSample/8; i < DataSize; i += bps)
- for(int j = bps-1; j >= 0; j--)
+ for(int j = bps-1; j >= 0; j--) {
pBitStream->BitWrite(pData[i+j], 8);
+ }
return;
}
@@ -429,15 +430,16 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket*
void CBaseMuxerRawOutputPin::MuxFooter(const CMediaType& mt)
{
CComQIPtr<IBitStream> pBitStream = GetBitStream();
- if(!pBitStream) return;
+ if(!pBitStream) {
+ return;
+ }
if(mt.majortype == MEDIATYPE_Audio
&& (mt.subtype == MEDIASUBTYPE_PCM
- || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
- || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
- || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
- && mt.formattype == FORMAT_WaveFormatEx)
- {
+ || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
+ && mt.formattype == FORMAT_WaveFormatEx) {
pBitStream->BitFlush();
ASSERT(pBitStream->GetPos() <= 0xffffffff);
@@ -450,30 +452,22 @@ void CBaseMuxerRawOutputPin::MuxFooter(const CMediaType& mt)
size -= sizeof(RIFFLIST) + sizeof(RIFFCHUNK) + mt.FormatLength();
pBitStream->Seek(sizeof(RIFFLIST) + sizeof(RIFFCHUNK) + mt.FormatLength() + 4);
pBitStream->ByteWrite(&size, 4);
- }
- else if(mt.subtype == MEDIASUBTYPE_SSF)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSF) {
ssf::WCharOutputStream s;
try {
m_ssf.Dump(s);
- }
- catch(ssf::Exception&) {}
+ } catch(ssf::Exception&) {}
CStringA str = UTF16To8(s.GetString());
pBitStream->StrWrite(str, true);
- }
- else if(mt.subtype == MEDIASUBTYPE_VOBSUB)
- {
- if(CComQIPtr<IFileSinkFilter> pFSF = GetFilterFromPin(GetConnected()))
- {
+ } else if(mt.subtype == MEDIASUBTYPE_VOBSUB) {
+ if(CComQIPtr<IFileSinkFilter> pFSF = GetFilterFromPin(GetConnected())) {
WCHAR* fn = NULL;
- if(SUCCEEDED(pFSF->GetCurFile(&fn, NULL)))
- {
+ if(SUCCEEDED(pFSF->GetCurFile(&fn, NULL))) {
CPathW p(fn);
p.RenameExtension(L".idx");
CoTaskMemFree(fn);
- if(FILE* f = _tfopen(CString((LPCWSTR)p), _T("w")))
- {
+ if(FILE* f = _tfopen(CString((LPCWSTR)p), _T("w"))) {
SUBTITLEINFO* si = (SUBTITLEINFO*)mt.Format();
_ftprintf(f, _T("%s\n"), _T("# VobSub index file, v7 (do not modify this line!)"));
@@ -481,15 +475,18 @@ void CBaseMuxerRawOutputPin::MuxFooter(const CMediaType& mt)
fwrite(mt.Format() + si->dwOffset, mt.FormatLength() - si->dwOffset, 1, f);
CString iso6391 = ISO6392To6391(si->IsoLang);
- if(iso6391.IsEmpty()) iso6391 = _T("--");
+ if(iso6391.IsEmpty()) {
+ iso6391 = _T("--");
+ }
_ftprintf(f, _T("\nlangidx: 0\n\nid: %s, index: 0\n"), iso6391);
CString alt = CString(CStringW(si->TrackName));
- if(!alt.IsEmpty()) _ftprintf(f, _T("alt: %s\n"), alt);
+ if(!alt.IsEmpty()) {
+ _ftprintf(f, _T("alt: %s\n"), alt);
+ }
POSITION pos = m_idx.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
const idx_t& i = m_idx.GetNext(pos);
DVD_HMSF_TIMECODE start = RT2HMSF(i.rt, 25);
_ftprintf(f, _T("timestamp: %02d:%02d:%02d:%03d, filepos: %09I64x\n"),
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h b/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h
index 3d911ccdd..d86985190 100644
--- a/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h
+++ b/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h
@@ -23,8 +23,7 @@
interface __declspec(uuid("EE6F2741-7DB4-4AAD-A3CB-545208EE4C0A"))
IBaseMuxerRelatedPin :
-public IUnknown
-{
+public IUnknown {
STDMETHOD(SetRelatedPin) (CBasePin* pPin) = 0;
STDMETHOD_(CBasePin*, GetRelatedPin) () = 0;
};
diff --git a/src/filters/muxer/BaseMuxer/BitStream.cpp b/src/filters/muxer/BaseMuxer/BitStream.cpp
index d18fc53fa..355cc19ff 100644
--- a/src/filters/muxer/BaseMuxer/BitStream.cpp
+++ b/src/filters/muxer/BaseMuxer/BitStream.cpp
@@ -87,13 +87,14 @@ STDMETHODIMP CBitStream::ByteWrite(const void* pData, int len)
BitFlush();
- if(len > 0)
- {
+ if(len > 0) {
ULONG cbWritten = 0;
hr = m_pStream->Write(pData, len, &cbWritten);
ASSERT(SUCCEEDED(hr));
- if(m_fThrowError && FAILED(hr)) throw hr;
+ if(m_fThrowError && FAILED(hr)) {
+ throw hr;
+ }
}
return hr;
@@ -114,14 +115,15 @@ STDMETHODIMP CBitStream::BitWrite(UINT64 data, int len)
m_bitbuff |= data & ((1ui64 << len) - 1);
m_bitlen += len;
- while(m_bitlen >= 8)
- {
+ while(m_bitlen >= 8) {
BYTE b = (BYTE)(m_bitbuff >> (m_bitlen - 8));
hr = m_pStream->Write(&b, 1, NULL);
m_bitlen -= 8;
ASSERT(SUCCEEDED(hr));
- if(m_fThrowError && FAILED(hr)) throw E_FAIL;
+ if(m_fThrowError && FAILED(hr)) {
+ throw E_FAIL;
+ }
}
return hr;
@@ -131,15 +133,16 @@ STDMETHODIMP CBitStream::BitFlush()
{
HRESULT hr = S_OK;
- if(m_bitlen > 0)
- {
+ if(m_bitlen > 0) {
ASSERT(m_bitlen < 8);
BYTE b = (BYTE)(m_bitbuff << (8 - m_bitlen));
hr = m_pStream->Write(&b, 1, NULL);
m_bitlen = 0;
ASSERT(SUCCEEDED(hr));
- if(m_fThrowError && FAILED(hr)) throw E_FAIL;
+ if(m_fThrowError && FAILED(hr)) {
+ throw E_FAIL;
+ }
}
return hr;
@@ -149,8 +152,7 @@ STDMETHODIMP CBitStream::StrWrite(LPCSTR pData, BOOL bFixNewLine)
{
CStringA str = pData;
- if(bFixNewLine)
- {
+ if(bFixNewLine) {
str.Replace("\r", "");
str.Replace("\n", "\r\n");
}
diff --git a/src/filters/muxer/BaseMuxer/BitStream.h b/src/filters/muxer/BaseMuxer/BitStream.h
index 02ffbe2ce..e2f186da2 100644
--- a/src/filters/muxer/BaseMuxer/BitStream.h
+++ b/src/filters/muxer/BaseMuxer/BitStream.h
@@ -23,8 +23,7 @@
interface __declspec(uuid("30AB78C7-5259-4594-AEFE-9C0FC2F08A5E"))
IBitStream :
-public IUnknown
-{
+public IUnknown {
STDMETHOD_(UINT64, GetPos) () = 0;
STDMETHOD_(UINT64, Seek) (UINT64 pos) = 0; // it's a _stream_, please don't seek if you don't have to
STDMETHOD(ByteWrite) (const void* pData, int len) = 0;
diff --git a/src/filters/muxer/DSMMuxer/DSMMuxer.cpp b/src/filters/muxer/DSMMuxer/DSMMuxer.cpp
index 17fce671d..b3059b577 100644
--- a/src/filters/muxer/DSMMuxer/DSMMuxer.cpp
+++ b/src/filters/muxer/DSMMuxer/DSMMuxer.cpp
@@ -30,24 +30,20 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_DirectShowMedia}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, TRUE, &CLSID_NULL, NULL, 0, NULL},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CDSMMuxerFilter), L"MPC - DSM Muxer", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDSMMuxerFilter>, NULL, &sudFilter[0]}
};
@@ -69,14 +65,17 @@ CFilterApp theApp;
#endif
-template<typename T> static T myabs(T n) {
+template<typename T> static T myabs(T n)
+{
return n >= 0 ? n : -n;
}
static int GetByteLength(UINT64 data, int min = 0)
{
int i = 7;
- while(i >= min && ((BYTE*)&data)[i] == 0) i--;
+ while(i >= min && ((BYTE*)&data)[i] == 0) {
+ i--;
+ }
return ++i;
}
@@ -89,7 +88,9 @@ CDSMMuxerFilter::CDSMMuxerFilter(LPUNKNOWN pUnk, HRESULT* phr, bool fAutoChap, b
, m_fAutoChap(fAutoChap)
, m_fAutoRes(fAutoRes)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CDSMMuxerFilter::~CDSMMuxerFilter()
@@ -123,18 +124,18 @@ void CDSMMuxerFilter::MuxFileInfo(IBitStream* pBS)
int len = 1;
CSimpleMap<CStringA, CStringA> si;
- for(int i = 0; i < GetSize(); i++)
- {
+ for(int i = 0; i < GetSize(); i++) {
CStringA key = CStringA(CString(GetKeyAt(i))), value = UTF16To8(GetValueAt(i));
- if(key.GetLength() != 4) continue;
+ if(key.GetLength() != 4) {
+ continue;
+ }
si.Add(key, value);
len += 4 + value.GetLength() + 1;
}
MuxPacketHeader(pBS, DSMP_FILEINFO, len);
pBS->BitWrite(DSMF_VERSION, 8);
- for(int i = 0; i < si.GetSize(); i++)
- {
+ for(int i = 0; i < si.GetSize(); i++) {
CStringA key = si.GetKeyAt(i), value = si.GetValueAt(i);
pBS->ByteWrite((LPCSTR)key, 4);
pBS->ByteWrite((LPCSTR)value, value.GetLength()+1);
@@ -147,20 +148,19 @@ void CDSMMuxerFilter::MuxStreamInfo(IBitStream* pBS, CBaseMuxerInputPin* pPin)
int len = 1;
CSimpleMap<CStringA, CStringA> si;
- for(int i = 0; i < pPin->GetSize(); i++)
- {
+ for(int i = 0; i < pPin->GetSize(); i++) {
CStringA key = CStringA(CString(pPin->GetKeyAt(i))), value = UTF16To8(pPin->GetValueAt(i));
- if(key.GetLength() != 4) continue;
+ if(key.GetLength() != 4) {
+ continue;
+ }
si.Add(key, value);
len += 4 + value.GetLength() + 1;
}
- if(len > 1)
- {
+ if(len > 1) {
MuxPacketHeader(pBS, DSMP_STREAMINFO, len);
pBS->BitWrite(pPin->GetID(), 8);
- for(int i = 0; i < si.GetSize(); i++)
- {
+ for(int i = 0; i < si.GetSize(); i++) {
CStringA key = si.GetKeyAt(i), value = si.GetValueAt(i);
pBS->ByteWrite((LPCSTR)key, 4);
pBS->ByteWrite((LPCSTR)value, value.GetLength()+1);
@@ -186,8 +186,7 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS)
MuxFileInfo(pBS);
POSITION pos = m_pPins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBaseMuxerInputPin* pPin = m_pPins.GetNext(pos);
const CMediaType& mt = pPin->CurrentMediaType();
@@ -214,19 +213,19 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS)
CComQIPtr<IDSMChapterBag> pCB = (IUnknown*)(INonDelegatingUnknown*)this;
pos = m_pPins.GetHeadPosition();
- while(pos)
- {
- for(CComPtr<IPin> pPin = m_pPins.GetNext(pos)->GetConnected(); pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin)))
- {
- if(m_fAutoRes)
- {
+ while(pos) {
+ for(CComPtr<IPin> pPin = m_pPins.GetNext(pos)->GetConnected(); pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin))) {
+ if(m_fAutoRes) {
CComQIPtr<IDSMResourceBag> pPB = GetFilterFromPin(pPin);
- if(pPB && !pRBs.Find(pPB)) pRBs.AddTail(pPB);
+ if(pPB && !pRBs.Find(pPB)) {
+ pRBs.AddTail(pPB);
+ }
}
- if(m_fAutoChap)
- {
- if(!pCB || pCB->ChapGetCount() == 0) pCB = GetFilterFromPin(pPin);
+ if(m_fAutoChap) {
+ if(!pCB || pCB->ChapGetCount() == 0) {
+ pCB = GetFilterFromPin(pPin);
+ }
}
}
}
@@ -234,17 +233,14 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS)
// resources
pos = pRBs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
IDSMResourceBag* pRB = pRBs.GetNext(pos);
- for(DWORD i = 0, j = pRB->ResGetCount(); i < j; i++)
- {
+ for(DWORD i = 0, j = pRB->ResGetCount(); i < j; i++) {
CComBSTR name, desc, mime;
BYTE* pData = NULL;
DWORD len = 0;
- if(SUCCEEDED(pRB->ResGet(i, &name, &desc, &mime, &pData, &len, NULL)))
- {
+ if(SUCCEEDED(pRB->ResGet(i, &name, &desc, &mime, &pData, &len, NULL))) {
CStringA utf8_name = UTF16To8(name);
CStringA utf8_desc = UTF16To8(desc);
CStringA utf8_mime = UTF16To8(mime);
@@ -270,20 +266,17 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS)
// chapters
- if(pCB)
- {
+ if(pCB) {
CAtlList<CDSMChapter> chapters;
REFERENCE_TIME rtPrev = 0;
int len = 0;
pCB->ChapSort();
- for(DWORD i = 0; i < pCB->ChapGetCount(); i++)
- {
+ for(DWORD i = 0; i < pCB->ChapGetCount(); i++) {
CDSMChapter c;
CComBSTR name;
- if(SUCCEEDED(pCB->ChapGet(i, &c.rt, &name)))
- {
+ if(SUCCEEDED(pCB->ChapGet(i, &c.rt, &name))) {
REFERENCE_TIME rtDiff = c.rt - rtPrev;
rtPrev = c.rt;
c.rt = rtDiff;
@@ -293,13 +286,11 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS)
}
}
- if(chapters.GetCount())
- {
+ if(chapters.GetCount()) {
MuxPacketHeader(pBS, DSMP_CHAPTERS, len);
pos = chapters.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CDSMChapter& c = chapters.GetNext(pos);
CStringA name = UTF16To8(c.name);
int irt = GetByteLength(myabs(c.rt));
@@ -315,18 +306,19 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS)
void CDSMMuxerFilter::MuxPacket(IBitStream* pBS, const MuxerPacket* pPacket)
{
- if(pPacket->IsEOS())
+ if(pPacket->IsEOS()) {
return;
+ }
- if(pPacket->pPin->CurrentMediaType().majortype == MEDIATYPE_Text)
- {
+ if(pPacket->pPin->CurrentMediaType().majortype == MEDIATYPE_Text) {
CStringA str((char*)pPacket->pData.GetData(), pPacket->pData.GetCount());
str.Replace("\xff", " ");
str.Replace("&nbsp;", " ");
str.Replace("&nbsp", " ");
str.Trim();
- if(str.IsEmpty())
+ if(str.IsEmpty()) {
return;
+ }
}
ASSERT(!pPacket->IsSyncPoint() || pPacket->IsTimeValid());
@@ -334,8 +326,7 @@ void CDSMMuxerFilter::MuxPacket(IBitStream* pBS, const MuxerPacket* pPacket)
REFERENCE_TIME rtTimeStamp = _I64_MIN, rtDuration = 0;
int iTimeStamp = 0, iDuration = 0;
- if(pPacket->IsTimeValid())
- {
+ if(pPacket->IsTimeValid()) {
rtTimeStamp = pPacket->rtStart;
rtDuration = max(pPacket->rtStop - pPacket->rtStart, 0);
@@ -371,8 +362,7 @@ void CDSMMuxerFilter::MuxFooter(IBitStream* pBS)
UINT64 fpPrev = 0, fp;
POSITION pos = m_isps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
IndexedSyncPoint& isp = m_isps.GetNext(pos);
TRACE(_T("sp[%d]: %I64d %I64x\n"), isp.id, isp.rt, isp.fp);
@@ -392,8 +382,7 @@ void CDSMMuxerFilter::MuxFooter(IBitStream* pBS)
MuxPacketHeader(pBS, DSMP_SYNCPOINTS, len);
pos = isps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
IndexedSyncPoint& isp = isps.GetNext(pos);
int irt = GetByteLength(myabs(isp.rt));
@@ -416,8 +405,9 @@ void CDSMMuxerFilter::IndexSyncPoint(const MuxerPacket* p, __int64 fp)
// FIXME: the very last syncpoints won't get moved to m_isps because there are no more syncpoints to trigger it!
- if(fp < 0 || !p || !p->IsTimeValid() || !p->IsSyncPoint())
+ if(fp < 0 || !p || !p->IsTimeValid() || !p->IsSyncPoint()) {
return;
+ }
ASSERT(p->rtStart >= m_rtPrevSyncPoint);
m_rtPrevSyncPoint = p->rtStart;
@@ -433,8 +423,7 @@ void CDSMMuxerFilter::IndexSyncPoint(const MuxerPacket* p, __int64 fp)
SyncPoint& tail = !m_sps.IsEmpty() ? m_sps.GetTail() : sp;
REFERENCE_TIME rtfp = !m_isps.IsEmpty() ? m_isps.GetTail().rtfp : _I64_MIN;
- if(head.rtStart > rtfp + 1000000) // 100ms limit, just in case every stream had only keyframes, then sycnpoints would be too frequent
- {
+ if(head.rtStart > rtfp + 1000000) { // 100ms limit, just in case every stream had only keyframes, then sycnpoints would be too frequent
IndexedSyncPoint isp;
isp.id = head.id;
isp.rt = tail.rtStart;
@@ -445,12 +434,12 @@ void CDSMMuxerFilter::IndexSyncPoint(const MuxerPacket* p, __int64 fp)
}
POSITION pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
POSITION cur = pos;
SyncPoint& sp2 = m_sps.GetNext(pos);
- if(sp2.id == sp.id && sp2.rtStop <= sp.rtStop || sp2.rtStop <= sp.rtStart)
+ if(sp2.id == sp.id && sp2.rtStop <= sp.rtStop || sp2.rtStop <= sp.rtStart) {
m_sps.RemoveAt(cur);
+ }
}
m_sps.AddTail(sp);
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp b/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp
index d1af9a3e4..14660e5b9 100644
--- a/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp
+++ b/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp
@@ -27,8 +27,9 @@ using namespace MatroskaWriter;
static void bswap(BYTE* s, int len)
{
- for(BYTE* d = s + len-1; s < d; s++, d--)
+ for(BYTE* d = s + len-1; s < d; s++, d--) {
*s ^= *d, *d ^= *s, *s ^= *d;
+ }
}
//
@@ -65,17 +66,23 @@ HRESULT CID::HeaderWrite(IStream* pStream)
MatroskaWriter::QWORD CBinary::Size(bool fWithHeader)
{
- if(GetCount() == 0) return 0;
+ if(GetCount() == 0) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += GetCount();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CBinary::Write(IStream* pStream)
{
- if(GetCount() == 0) return S_OK;
+ if(GetCount() == 0) {
+ return S_OK;
+ }
HeaderWrite(pStream);
return pStream->Write(GetData(), GetCount(), NULL);
@@ -83,17 +90,23 @@ HRESULT CBinary::Write(IStream* pStream)
MatroskaWriter::QWORD CANSI::Size(bool fWithHeader)
{
- if(GetLength() == 0) return 0;
+ if(GetLength() == 0) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += GetLength();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CANSI::Write(IStream* pStream)
{
- if(GetLength() == 0) return S_OK;
+ if(GetLength() == 0) {
+ return S_OK;
+ }
HeaderWrite(pStream);
return pStream->Write((LPCSTR)*this, GetLength(), NULL);
@@ -101,17 +114,23 @@ HRESULT CANSI::Write(IStream* pStream)
MatroskaWriter::QWORD CUTF8::Size(bool fWithHeader)
{
- if(GetLength() == 0) return 0;
+ if(GetLength() == 0) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += UTF16To8(*this).GetLength();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CUTF8::Write(IStream* pStream)
{
- if(GetLength() == 0) return S_OK;
+ if(GetLength() == 0) {
+ return S_OK;
+ }
HeaderWrite(pStream);
CStringA str = UTF16To8(*this);
@@ -121,18 +140,24 @@ HRESULT CUTF8::Write(IStream* pStream)
template<class T, class BASE>
MatroskaWriter::QWORD CSimpleVar<T, BASE>::Size(bool fWithHeader)
{
- if(!m_fSet) return 0;
+ if(!m_fSet) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += sizeof(T);
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
template<class T, class BASE>
HRESULT CSimpleVar<T, BASE>::Write(IStream* pStream)
{
- if(!m_fSet) return S_OK;
+ if(!m_fSet) {
+ return S_OK;
+ }
HeaderWrite(pStream);
T val = m_val;
@@ -142,32 +167,33 @@ HRESULT CSimpleVar<T, BASE>::Write(IStream* pStream)
MatroskaWriter::QWORD CUInt::Size(bool fWithHeader)
{
- if(!m_fSet) return 0;
+ if(!m_fSet) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
- if(m_val == 0)
- {
+ if(m_val == 0) {
len++;
- }
- else
- {
- for(int i = 8; i > 0; i--)
- {
- if(((0xffi64<<((i-1)*8))&m_val))
- {
+ } else {
+ for(int i = 8; i > 0; i--) {
+ if(((0xffi64<<((i-1)*8))&m_val)) {
len += i;
break;
}
}
}
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CUInt::Write(IStream* pStream)
{
- if(!m_fSet) return S_OK;
+ if(!m_fSet) {
+ return S_OK;
+ }
CID::Write(pStream);
CLength l(Size(false));
@@ -179,35 +205,37 @@ HRESULT CUInt::Write(IStream* pStream)
MatroskaWriter::QWORD CInt::Size(bool fWithHeader)
{
- if(!m_fSet) return 0;
+ if(!m_fSet) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
- if(m_val == 0)
- {
+ if(m_val == 0) {
len++;
- }
- else
- {
+ } else {
UINT64 val = m_val >= 0 ? m_val : -m_val;
- for(int i = 8; i > 0; i--)
- {
- if(((0xffi64<<((i-1)*8))&val))
- {
+ for(int i = 8; i > 0; i--) {
+ if(((0xffi64<<((i-1)*8))&val)) {
len += i;
- if(m_val < 0 && !(m_val&(0x80<<(i-1))))
+ if(m_val < 0 && !(m_val&(0x80<<(i-1)))) {
len++;
+ }
break;
}
}
}
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CInt::Write(IStream* pStream)
{
- if(!m_fSet) return S_OK;
+ if(!m_fSet) {
+ return S_OK;
+ }
CID::Write(pStream);
CLength l(Size(false));
@@ -219,14 +247,13 @@ HRESULT CInt::Write(IStream* pStream)
MatroskaWriter::QWORD CLength::Size(bool fWithHeader)
{
- if(m_len == 0x00FFFFFFFFFFFFFFi64)
+ if(m_len == 0x00FFFFFFFFFFFFFFi64) {
return 8;
+ }
MatroskaWriter::QWORD len = 0;
- for(int i = 1; i <= 8; i++)
- {
- if(!(m_len&(~((1i64<<(7*i))-1))) && (m_len&((1i64<<(7*i))-1)) != ((1i64<<(7*i))-1))
- {
+ for(int i = 1; i <= 8; i++) {
+ if(!(m_len&(~((1i64<<(7*i))-1))) && (m_len&((1i64<<(7*i))-1)) != ((1i64<<(7*i))-1)) {
len += i;
break;
}
@@ -267,7 +294,9 @@ MatroskaWriter::QWORD EBML::Size(bool fWithHeader)
len += DocType.Size();
len += DocTypeVersion.Size();
len += DocTypeReadVersion.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -316,7 +345,9 @@ MatroskaWriter::QWORD Info::Size(bool fWithHeader)
len += Title.Size();
len += MuxingApp.Size();
len += WritingApp.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -346,11 +377,11 @@ Segment::Segment(DWORD id)
MatroskaWriter::QWORD Segment::Size(bool fWithHeader)
{
return 0x00FFFFFFFFFFFFFFi64;
-/*
- MatroskaWriter::QWORD len = 0;
- if(fWithHeader) len += HeaderSize(len);
- return len;
-*/
+ /*
+ MatroskaWriter::QWORD len = 0;
+ if(fWithHeader) len += HeaderSize(len);
+ return len;
+ */
}
HRESULT Segment::Write(IStream* pStream)
@@ -368,7 +399,9 @@ MatroskaWriter::QWORD Track::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
len += TrackEntries.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -428,9 +461,15 @@ MatroskaWriter::QWORD TrackEntry::Size(bool fWithHeader)
len += CodecDecodeAll.Size();
len += TrackOverlay.Size();
len += DefaultDuration.Size();
- if(DescType == TypeVideo) len += v.Size();
- if(DescType == TypeAudio) len += a.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(DescType == TypeVideo) {
+ len += v.Size();
+ }
+ if(DescType == TypeAudio) {
+ len += a.Size();
+ }
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -456,8 +495,12 @@ HRESULT TrackEntry::Write(IStream* pStream)
CodecDecodeAll.Write(pStream);
TrackOverlay.Write(pStream);
DefaultDuration.Write(pStream);
- if(DescType == TypeVideo) v.Write(pStream);
- if(DescType == TypeAudio) a.Write(pStream);
+ if(DescType == TypeVideo) {
+ v.Write(pStream);
+ }
+ if(DescType == TypeAudio) {
+ a.Write(pStream);
+ }
return S_OK;
}
@@ -491,7 +534,9 @@ MatroskaWriter::QWORD Video::Size(bool fWithHeader)
len += ColourSpace.Size();
len += GammaValue.Size();
len += FramePerSec.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -530,7 +575,9 @@ MatroskaWriter::QWORD Audio::Size(bool fWithHeader)
len += Channels.Size();
len += ChannelPositions.Size();
len += BitDepth.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -560,7 +607,9 @@ MatroskaWriter::QWORD Cluster::Size(bool fWithHeader)
len += Position.Size();
len += PrevSize.Size();
len += BlockGroups.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -593,7 +642,9 @@ MatroskaWriter::QWORD BlockGroup::Size(bool fWithHeader)
len += ReferenceVirtual.Size();
len += CodecState.Size();
len += Block.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -619,23 +670,24 @@ MatroskaWriter::QWORD CBlock::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
len += TrackNumber.Size() + 2 + 1; // TrackNumber + TimeCode + Lacing
- if(BlockData.GetCount() > 1)
- {
+ if(BlockData.GetCount() > 1) {
len += 1; // nBlockData
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
- if(pos) len += b->GetCount()/255 + 1;
+ if(pos) {
+ len += b->GetCount()/255 + 1;
+ }
}
}
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
len += b->GetCount();
}
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -648,20 +700,18 @@ HRESULT CBlock::Write(IStream* pStream)
pStream->Write(&t, 2, NULL);
BYTE Lacing = 0;
BYTE n = BlockData.GetCount();
- if(n > 1) Lacing |= 2;
+ if(n > 1) {
+ Lacing |= 2;
+ }
pStream->Write(&Lacing, 1, NULL);
- if(n > 1)
- {
+ if(n > 1) {
pStream->Write(&n, 1, NULL);
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
- if(pos)
- {
+ if(pos) {
int len = b->GetCount();
- while(len >= 0)
- {
+ while(len >= 0) {
n = min(len, 255);
pStream->Write(&n, 1, NULL);
len -= 255;
@@ -670,8 +720,7 @@ HRESULT CBlock::Write(IStream* pStream)
}
}
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
pStream->Write(b->GetData(), b->GetCount(), NULL);
}
@@ -687,7 +736,9 @@ MatroskaWriter::QWORD Cue::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
len += CuePoints.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -709,7 +760,9 @@ MatroskaWriter::QWORD CuePoint::Size(bool fWithHeader)
MatroskaWriter::QWORD len = 0;
len += CueTime.Size();
len += CueTrackPositions.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -737,8 +790,10 @@ MatroskaWriter::QWORD CueTrackPosition::Size(bool fWithHeader)
len += CueClusterPosition.Size();
len += CueBlockNumber.Size();
len += CueCodecState.Size();
-// len += CueReferences.Size();
- if(fWithHeader) len += HeaderSize(len);
+ // len += CueReferences.Size();
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -749,7 +804,7 @@ HRESULT CueTrackPosition::Write(IStream* pStream)
CueClusterPosition.Write(pStream);
CueBlockNumber.Write(pStream);
CueCodecState.Write(pStream);
-// CueReferences.Write(pStream);
+ // CueReferences.Write(pStream);
return S_OK;
}
@@ -762,7 +817,9 @@ MatroskaWriter::QWORD Seek::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
len += SeekHeads.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -783,7 +840,9 @@ MatroskaWriter::QWORD SeekID::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
len += m_id.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -805,7 +864,9 @@ MatroskaWriter::QWORD SeekHead::Size(bool fWithHeader)
MatroskaWriter::QWORD len = 0;
len += ID.Size();
len += Position.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -825,15 +886,17 @@ Tags::Tags(DWORD id)
MatroskaWriter::QWORD Tags::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
-// len += .Size();
- if(fWithHeader) len += HeaderSize(len);
+ // len += .Size();
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT Tags::Write(IStream* pStream)
{
HeaderWrite(pStream);
-// .Write(pStream);
+ // .Write(pStream);
return S_OK;
}
@@ -847,7 +910,9 @@ MatroskaWriter::QWORD Void::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
len += m_len;
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -856,7 +921,8 @@ HRESULT Void::Write(IStream* pStream)
HeaderWrite(pStream);
BYTE buff[64];
memset(buff, 0x80, sizeof(buff));
- for(int len = (int)m_len; len > 0; len -= sizeof(buff))
+ for(int len = (int)m_len; len > 0; len -= sizeof(buff)) {
pStream->Write(buff, (ULONG)min(sizeof(buff), len), NULL);
+ }
return S_OK;
}
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaFile.h b/src/filters/muxer/MatroskaMuxer/MatroskaFile.h
index feb94cd6c..477d9c990 100644
--- a/src/filters/muxer/MatroskaMuxer/MatroskaFile.h
+++ b/src/filters/muxer/MatroskaMuxer/MatroskaFile.h
@@ -26,393 +26,395 @@
namespace MatroskaWriter
{
-typedef unsigned __int64 QWORD;
+ typedef unsigned __int64 QWORD;
-class CID
-{
-protected:
- DWORD m_id;
- QWORD HeaderSize(QWORD len);
- HRESULT HeaderWrite(IStream* pStream);
-
-public:
- CID(DWORD id);
- DWORD GetID() const {
- return m_id;
- }
- virtual QWORD Size(bool fWithHeader = true);
- virtual HRESULT Write(IStream* pStream);
-};
-
-class CLength : public CID
-{
- UINT64 m_len;
-public:
- CLength(UINT64 len = 0) : CID(0), m_len(len) {}
- operator UINT64() {
- return m_len;
- }
- QWORD Size(bool fWithHeader = false);
- HRESULT Write(IStream* pStream);
-};
-
-class CBinary : public CAtlArray<BYTE>, public CID
-{
-public:
- CBinary(DWORD id) : CID(id) {}
- CBinary& operator = (const CBinary& b) {
- Copy(b);
- return(*this);
- }
- operator BYTE*() {
- return (BYTE*)GetData();
- }
- CBinary& Set(CStringA str) {
- SetCount(str.GetLength()+1);
- strcpy((char*)GetData(), str);
- return(*this);
- }
-// CBinary& Set(CStringA str) {SetCount(str.GetLength()); memcpy((char*)GetData(), str, str.GetLength()); return(*this);}
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class CANSI : public CStringA, public CID
-{
-public:
- CANSI(DWORD id) : CID(id) {}
- CANSI& Set(CStringA str) {
- CStringA::operator = (str);
- return(*this);
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class CUTF8 : public CStringW, public CID
-{
-public:
- CUTF8(DWORD id) : CID(id) {}
- CUTF8& Set(CStringW str) {
- CStringW::operator = (str);
- return(*this);
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-template<class T, class BASE>
-class CSimpleVar : public CID
-{
-protected:
- T m_val;
- bool m_fSet;
-public:
- explicit CSimpleVar(DWORD id, T val = 0) : CID(id), m_val(val) {
- m_fSet = !!val;
- }
- operator T() {
- return m_val;
- }
- BASE& Set(T val) {
- m_val = val;
- m_fSet = true;
- return(*(BASE*)this);
- }
- void UnSet() {
- m_fSet = false;
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class CUInt : public CSimpleVar<UINT64, CUInt>
-{
-public:
- explicit CUInt(DWORD id, UINT64 val = 0) : CSimpleVar<UINT64, CUInt>(id, val) {}
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class CID
+ {
+ protected:
+ DWORD m_id;
+ QWORD HeaderSize(QWORD len);
+ HRESULT HeaderWrite(IStream* pStream);
+
+ public:
+ CID(DWORD id);
+ DWORD GetID() const {
+ return m_id;
+ }
+ virtual QWORD Size(bool fWithHeader = true);
+ virtual HRESULT Write(IStream* pStream);
+ };
+
+ class CLength : public CID
+ {
+ UINT64 m_len;
+ public:
+ CLength(UINT64 len = 0) : CID(0), m_len(len) {}
+ operator UINT64() {
+ return m_len;
+ }
+ QWORD Size(bool fWithHeader = false);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CBinary : public CAtlArray<BYTE>, public CID
+ {
+ public:
+ CBinary(DWORD id) : CID(id) {}
+ CBinary& operator = (const CBinary& b) {
+ Copy(b);
+ return(*this);
+ }
+ operator BYTE*() {
+ return (BYTE*)GetData();
+ }
+ CBinary& Set(CStringA str) {
+ SetCount(str.GetLength()+1);
+ strcpy((char*)GetData(), str);
+ return(*this);
+ }
+ // CBinary& Set(CStringA str) {SetCount(str.GetLength()); memcpy((char*)GetData(), str, str.GetLength()); return(*this);}
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CANSI : public CStringA, public CID
+ {
+ public:
+ CANSI(DWORD id) : CID(id) {}
+ CANSI& Set(CStringA str) {
+ CStringA::operator = (str);
+ return(*this);
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CUTF8 : public CStringW, public CID
+ {
+ public:
+ CUTF8(DWORD id) : CID(id) {}
+ CUTF8& Set(CStringW str) {
+ CStringW::operator = (str);
+ return(*this);
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ template<class T, class BASE>
+ class CSimpleVar : public CID
+ {
+ protected:
+ T m_val;
+ bool m_fSet;
+ public:
+ explicit CSimpleVar(DWORD id, T val = 0) : CID(id), m_val(val) {
+ m_fSet = !!val;
+ }
+ operator T() {
+ return m_val;
+ }
+ BASE& Set(T val) {
+ m_val = val;
+ m_fSet = true;
+ return(*(BASE*)this);
+ }
+ void UnSet() {
+ m_fSet = false;
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CUInt : public CSimpleVar<UINT64, CUInt>
+ {
+ public:
+ explicit CUInt(DWORD id, UINT64 val = 0) : CSimpleVar<UINT64, CUInt>(id, val) {}
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CInt : public CSimpleVar<INT64, CInt>
-{
-public:
- explicit CInt(DWORD id, INT64 val = 0) : CSimpleVar<INT64, CInt>(id, val) {}
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class CInt : public CSimpleVar<INT64, CInt>
+ {
+ public:
+ explicit CInt(DWORD id, INT64 val = 0) : CSimpleVar<INT64, CInt>(id, val) {}
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CByte : public CSimpleVar<BYTE, CByte>
-{
-public:
- explicit CByte(DWORD id, BYTE val = 0) : CSimpleVar<BYTE, CByte>(id, val) {}
-};
+ class CByte : public CSimpleVar<BYTE, CByte>
+ {
+ public:
+ explicit CByte(DWORD id, BYTE val = 0) : CSimpleVar<BYTE, CByte>(id, val) {}
+ };
-class CShort : public CSimpleVar<short, CShort>
-{
-public:
- explicit CShort(DWORD id, short val = 0) : CSimpleVar<short, CShort>(id, val) {}
-};
+ class CShort : public CSimpleVar<short, CShort>
+ {
+ public:
+ explicit CShort(DWORD id, short val = 0) : CSimpleVar<short, CShort>(id, val) {}
+ };
-class CFloat : public CSimpleVar<float, CFloat>
-{
-public:
- explicit CFloat(DWORD id, float val = 0) : CSimpleVar<float, CFloat>(id, val) {}
-};
+ class CFloat : public CSimpleVar<float, CFloat>
+ {
+ public:
+ explicit CFloat(DWORD id, float val = 0) : CSimpleVar<float, CFloat>(id, val) {}
+ };
-template<class T>
-class CNode : public CAutoPtrList<T>
-{
-public:
- QWORD Size(bool fWithHeader = true)
+ template<class T>
+ class CNode : public CAutoPtrList<T>
{
- QWORD len = 0;
- POSITION pos = GetHeadPosition();
- while(pos) len += GetNext(pos)->Size(fWithHeader);
- return len;
- }
- HRESULT Write(IStream* pStream)
+ public:
+ QWORD Size(bool fWithHeader = true) {
+ QWORD len = 0;
+ POSITION pos = GetHeadPosition();
+ while(pos) {
+ len += GetNext(pos)->Size(fWithHeader);
+ }
+ return len;
+ }
+ HRESULT Write(IStream* pStream) {
+ HRESULT hr;
+ POSITION pos = GetHeadPosition();
+ while(pos) if(FAILED(hr = GetNext(pos)->Write(pStream))) {
+ return hr;
+ }
+ return S_OK;
+ }
+ };
+
+ class EBML : public CID
{
- HRESULT hr;
- POSITION pos = GetHeadPosition();
- while(pos) if(FAILED(hr = GetNext(pos)->Write(pStream))) return hr;
- return S_OK;
- }
-};
-
-class EBML : public CID
-{
-public:
- CUInt EBMLVersion, EBMLReadVersion;
- CUInt EBMLMaxIDLength, EBMLMaxSizeLength;
- CANSI DocType;
- CUInt DocTypeVersion, DocTypeReadVersion;
-
- EBML(DWORD id = 0x1A45DFA3);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Info : public CID
-{
-public:
- CBinary SegmentUID, PrevUID, NextUID;
- CUTF8 SegmentFilename, PrevFilename, NextFilename;
- CUInt TimeCodeScale; // [ns], default: 1.000.000
- CFloat Duration;
- CInt DateUTC;
- CUTF8 Title, MuxingApp, WritingApp;
-
- Info(DWORD id = 0x1549A966);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Video : public CID
-{
-public:
- CUInt FlagInterlaced, StereoMode;
- CUInt PixelWidth, PixelHeight, DisplayWidth, DisplayHeight, DisplayUnit;
- CUInt AspectRatioType;
- CUInt ColourSpace;
- CFloat GammaValue;
- CFloat FramePerSec;
-
- Video(DWORD id = 0xE0);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Audio : public CID
-{
-public:
- CFloat SamplingFrequency;
- CFloat OutputSamplingFrequency;
- CUInt Channels;
- CBinary ChannelPositions;
- CUInt BitDepth;
-
- Audio(DWORD id = 0xE1);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class TrackEntry : public CID
-{
-public:
- enum {TypeVideo = 1, TypeAudio = 2, TypeComplex = 3, TypeLogo = 0x10, TypeSubtitle = 0x11, TypeControl = 0x20};
- CUInt TrackNumber, TrackUID, TrackType;
- CUInt FlagEnabled, FlagDefault, FlagLacing;
- CUInt MinCache, MaxCache;
- CUTF8 Name;
- CANSI Language;
- CBinary CodecID;
- CBinary CodecPrivate;
- CUTF8 CodecName;
- CUTF8 CodecSettings;
- CANSI CodecInfoURL;
- CANSI CodecDownloadURL;
- CUInt CodecDecodeAll;
- CUInt TrackOverlay;
- CUInt DefaultDuration;
- enum {NoDesc = 0, DescVideo = 1, DescAudio = 2};
- int DescType;
- Video v;
- Audio a;
-
- TrackEntry(DWORD id = 0xAE);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Track : public CID
-{
-public:
- CNode<TrackEntry> TrackEntries;
+ public:
+ CUInt EBMLVersion, EBMLReadVersion;
+ CUInt EBMLMaxIDLength, EBMLMaxSizeLength;
+ CANSI DocType;
+ CUInt DocTypeVersion, DocTypeReadVersion;
+
+ EBML(DWORD id = 0x1A45DFA3);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Info : public CID
+ {
+ public:
+ CBinary SegmentUID, PrevUID, NextUID;
+ CUTF8 SegmentFilename, PrevFilename, NextFilename;
+ CUInt TimeCodeScale; // [ns], default: 1.000.000
+ CFloat Duration;
+ CInt DateUTC;
+ CUTF8 Title, MuxingApp, WritingApp;
+
+ Info(DWORD id = 0x1549A966);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Video : public CID
+ {
+ public:
+ CUInt FlagInterlaced, StereoMode;
+ CUInt PixelWidth, PixelHeight, DisplayWidth, DisplayHeight, DisplayUnit;
+ CUInt AspectRatioType;
+ CUInt ColourSpace;
+ CFloat GammaValue;
+ CFloat FramePerSec;
+
+ Video(DWORD id = 0xE0);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Audio : public CID
+ {
+ public:
+ CFloat SamplingFrequency;
+ CFloat OutputSamplingFrequency;
+ CUInt Channels;
+ CBinary ChannelPositions;
+ CUInt BitDepth;
+
+ Audio(DWORD id = 0xE1);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class TrackEntry : public CID
+ {
+ public:
+ enum {TypeVideo = 1, TypeAudio = 2, TypeComplex = 3, TypeLogo = 0x10, TypeSubtitle = 0x11, TypeControl = 0x20};
+ CUInt TrackNumber, TrackUID, TrackType;
+ CUInt FlagEnabled, FlagDefault, FlagLacing;
+ CUInt MinCache, MaxCache;
+ CUTF8 Name;
+ CANSI Language;
+ CBinary CodecID;
+ CBinary CodecPrivate;
+ CUTF8 CodecName;
+ CUTF8 CodecSettings;
+ CANSI CodecInfoURL;
+ CANSI CodecDownloadURL;
+ CUInt CodecDecodeAll;
+ CUInt TrackOverlay;
+ CUInt DefaultDuration;
+ enum {NoDesc = 0, DescVideo = 1, DescAudio = 2};
+ int DescType;
+ Video v;
+ Audio a;
+
+ TrackEntry(DWORD id = 0xAE);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Track : public CID
+ {
+ public:
+ CNode<TrackEntry> TrackEntries;
- Track(DWORD id = 0x1654AE6B);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Track(DWORD id = 0x1654AE6B);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CBlock : public CID
-{
-public:
- CLength TrackNumber;
- REFERENCE_TIME TimeCode, TimeCodeStop;
- CNode<CBinary> BlockData;
+ class CBlock : public CID
+ {
+ public:
+ CLength TrackNumber;
+ REFERENCE_TIME TimeCode, TimeCodeStop;
+ CNode<CBinary> BlockData;
- CBlock(DWORD id = 0xA1);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ CBlock(DWORD id = 0xA1);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class BlockGroup : public CID
-{
-public:
- CUInt BlockDuration;
- CUInt ReferencePriority;
- CInt ReferenceBlock;
- CInt ReferenceVirtual;
- CBinary CodecState;
- CBlock Block;
-// CNode<TimeSlice> TimeSlices;
-
- BlockGroup(DWORD id = 0xA0);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Cluster : public CID
-{
-public:
- CUInt TimeCode, Position, PrevSize;
- CNode<BlockGroup> BlockGroups;
-
- Cluster(DWORD id = 0x1F43B675);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-/* class CueReference : public CID
- {
- public:
- CUInt CueRefTime, CueRefCluster, CueRefNumber, CueRefCodecState;
-
- CueReference(DWORD id = 0xDB);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
- };
-*/
-class CueTrackPosition : public CID
-{
-public:
- CUInt CueTrack, CueClusterPosition, CueBlockNumber, CueCodecState;
-// CNode<CueReference> CueReferences;
+ class BlockGroup : public CID
+ {
+ public:
+ CUInt BlockDuration;
+ CUInt ReferencePriority;
+ CInt ReferenceBlock;
+ CInt ReferenceVirtual;
+ CBinary CodecState;
+ CBlock Block;
+ // CNode<TimeSlice> TimeSlices;
+
+ BlockGroup(DWORD id = 0xA0);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Cluster : public CID
+ {
+ public:
+ CUInt TimeCode, Position, PrevSize;
+ CNode<BlockGroup> BlockGroups;
+
+ Cluster(DWORD id = 0x1F43B675);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ /* class CueReference : public CID
+ {
+ public:
+ CUInt CueRefTime, CueRefCluster, CueRefNumber, CueRefCodecState;
+
+ CueReference(DWORD id = 0xDB);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+ */
+ class CueTrackPosition : public CID
+ {
+ public:
+ CUInt CueTrack, CueClusterPosition, CueBlockNumber, CueCodecState;
+ // CNode<CueReference> CueReferences;
- CueTrackPosition(DWORD id = 0xB7);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ CueTrackPosition(DWORD id = 0xB7);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CuePoint : public CID
-{
-public:
- CUInt CueTime;
- CNode<CueTrackPosition> CueTrackPositions;
+ class CuePoint : public CID
+ {
+ public:
+ CUInt CueTime;
+ CNode<CueTrackPosition> CueTrackPositions;
- CuePoint(DWORD id = 0xBB);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ CuePoint(DWORD id = 0xBB);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Cue : public CID
-{
-public:
- CNode<CuePoint> CuePoints;
+ class Cue : public CID
+ {
+ public:
+ CNode<CuePoint> CuePoints;
- Cue(DWORD id = 0x1C53BB6B);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Cue(DWORD id = 0x1C53BB6B);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class SeekID : public CID
-{
- CID m_id;
-public:
- SeekID(DWORD id = 0x53AB);
- void Set(DWORD id) {
- m_id = id;
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class SeekHead : public CID
-{
-public:
- SeekID ID;
- CUInt Position;
+ class SeekID : public CID
+ {
+ CID m_id;
+ public:
+ SeekID(DWORD id = 0x53AB);
+ void Set(DWORD id) {
+ m_id = id;
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class SeekHead : public CID
+ {
+ public:
+ SeekID ID;
+ CUInt Position;
- SeekHead(DWORD id = 0x4DBB);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ SeekHead(DWORD id = 0x4DBB);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Seek : public CID
-{
-public:
- CNode<SeekHead> SeekHeads;
+ class Seek : public CID
+ {
+ public:
+ CNode<SeekHead> SeekHeads;
- Seek(DWORD id = 0x114D9B74);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Seek(DWORD id = 0x114D9B74);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Segment : public CID
-{
-public:
- Segment(DWORD id = 0x18538067);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class Segment : public CID
+ {
+ public:
+ Segment(DWORD id = 0x18538067);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Tags : public CID
-{
-public:
- // TODO
+ class Tags : public CID
+ {
+ public:
+ // TODO
- Tags(DWORD id = 0x1254C367);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Tags(DWORD id = 0x1254C367);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Void : public CID
-{
- QWORD m_len;
-public:
- Void(QWORD len, DWORD id = 0xEC);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class Void : public CID
+ {
+ QWORD m_len;
+ public:
+ Void(QWORD len, DWORD id = 0xEC);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
}
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp
index 68d3b89d2..d79d30b04 100644
--- a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp
+++ b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp
@@ -31,24 +31,20 @@ using namespace MatroskaWriter;
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_Matroska}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, TRUE, &CLSID_NULL, NULL, 0, NULL},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMatroskaMuxerFilter), L"MPC - Matroska Muxer", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMatroskaMuxerFilter>, NULL, &sudFilter[0]}
};
@@ -79,7 +75,9 @@ CMatroskaMuxerFilter::CMatroskaMuxerFilter(LPUNKNOWN pUnk, HRESULT* phr)
, m_rtCurrent(0)
, m_fNegative(true), m_fPositive(false)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pOutput.Attach(DNew CMatroskaMuxerOutputPin(NAME("CMatroskaMuxerOutputPin"), this, this, phr));
@@ -100,7 +98,7 @@ STDMETHODIMP CMatroskaMuxerFilter::NonDelegatingQueryInterface(REFIID riid, void
*ppv = NULL;
return
-// QI(IAMFilterMiscFlags)
+ // QI(IAMFilterMiscFlags)
QI(IMediaSeeking)
QI(IMatroskaMuxer)
__super::NonDelegatingQueryInterface(riid, ppv);
@@ -111,11 +109,11 @@ UINT CMatroskaMuxerFilter::GetTrackNumber(CBasePin* pPin)
UINT nTrackNumber = 0;
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
nTrackNumber++;
- if(m_pInputs.GetNext(pos) == pPin)
+ if(m_pInputs.GetNext(pos) == pPin) {
return nTrackNumber;
+ }
}
return 0;
@@ -124,10 +122,11 @@ UINT CMatroskaMuxerFilter::GetTrackNumber(CBasePin* pPin)
void CMatroskaMuxerFilter::AddInput()
{
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBasePin* pPin = m_pInputs.GetNext(pos);
- if(!pPin->IsConnected()) return;
+ if(!pPin->IsConnected()) {
+ return;
+ }
}
CStringW name;
@@ -147,14 +146,13 @@ CBasePin* CMatroskaMuxerFilter::GetPin(int n)
{
CAutoLock cAutoLock(this);
- if(n >= 0 && n < (int)m_pInputs.GetCount())
- {
- if(POSITION pos = m_pInputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pInputs.GetCount()) {
+ if(POSITION pos = m_pInputs.FindIndex(n)) {
return m_pInputs.GetAt(pos);
+ }
}
- if(n == m_pInputs.GetCount() && m_pOutput)
- {
+ if(n == m_pInputs.GetCount() && m_pOutput) {
return m_pOutput;
}
@@ -167,8 +165,9 @@ STDMETHODIMP CMatroskaMuxerFilter::Stop()
HRESULT hr;
- if(FAILED(hr = __super::Stop()))
+ if(FAILED(hr = __super::Stop())) {
return hr;
+ }
CallWorker(CMD_EXIT);
@@ -183,11 +182,11 @@ STDMETHODIMP CMatroskaMuxerFilter::Pause()
HRESULT hr;
- if(FAILED(hr = __super::Pause()))
+ if(FAILED(hr = __super::Pause())) {
return hr;
+ }
- if(fs == State_Stopped && m_pOutput)
- {
+ if(fs == State_Stopped && m_pOutput) {
CAMThread::Create();
CallWorker(CMD_RUN);
}
@@ -201,8 +200,9 @@ STDMETHODIMP CMatroskaMuxerFilter::Run(REFERENCE_TIME tStart)
HRESULT hr;
- if(FAILED(hr = __super::Run(tStart)))
+ if(FAILED(hr = __super::Run(tStart))) {
return hr;
+ }
return hr;
}
@@ -225,25 +225,32 @@ STDMETHODIMP CMatroskaMuxerFilter::GetCapabilities(DWORD* pCapabilities)
STDMETHODIMP CMatroskaMuxerFilter::CheckCapabilities(DWORD* pCapabilities)
{
CheckPointer(pCapabilities, E_POINTER);
- if(*pCapabilities == 0) return S_OK;
+ if(*pCapabilities == 0) {
+ return S_OK;
+ }
DWORD caps;
GetCapabilities(&caps);
caps &= *pCapabilities;
return caps == 0 ? E_FAIL : caps == *pCapabilities ? S_OK : S_FALSE;
}
-STDMETHODIMP CMatroskaMuxerFilter::IsFormatSupported(const GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::IsFormatSupported(const GUID* pFormat)
+{
return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;
}
-STDMETHODIMP CMatroskaMuxerFilter::QueryPreferredFormat(GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::QueryPreferredFormat(GUID* pFormat)
+{
return GetTimeFormat(pFormat);
}
-STDMETHODIMP CMatroskaMuxerFilter::GetTimeFormat(GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::GetTimeFormat(GUID* pFormat)
+{
return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;
}
-STDMETHODIMP CMatroskaMuxerFilter::IsUsingTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::IsUsingTimeFormat(const GUID* pFormat)
+{
return IsFormatSupported(pFormat);
}
-STDMETHODIMP CMatroskaMuxerFilter::SetTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::SetTimeFormat(const GUID* pFormat)
+{
return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;
}
STDMETHODIMP CMatroskaMuxerFilter::GetDuration(LONGLONG* pDuration)
@@ -253,11 +260,14 @@ STDMETHODIMP CMatroskaMuxerFilter::GetDuration(LONGLONG* pDuration)
POSITION pos = m_pInputs.GetHeadPosition();
while(pos) {
REFERENCE_TIME rt = m_pInputs.GetNext(pos)->m_rtDur;
- if(rt > *pDuration) *pDuration = rt;
+ if(rt > *pDuration) {
+ *pDuration = rt;
+ }
}
return S_OK;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetStopPosition(LONGLONG* pStop) {
+STDMETHODIMP CMatroskaMuxerFilter::GetStopPosition(LONGLONG* pStop)
+{
return E_NOTIMPL;
}
STDMETHODIMP CMatroskaMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent)
@@ -266,25 +276,32 @@ STDMETHODIMP CMatroskaMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent)
*pCurrent = m_rtCurrent;
return S_OK;
}
-STDMETHODIMP CMatroskaMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) {
+STDMETHODIMP CMatroskaMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) {
+STDMETHODIMP CMatroskaMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) {
+STDMETHODIMP CMatroskaMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::SetRate(double dRate) {
+STDMETHODIMP CMatroskaMuxerFilter::SetRate(double dRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetRate(double* pdRate) {
+STDMETHODIMP CMatroskaMuxerFilter::GetRate(double* pdRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetPreroll(LONGLONG* pllPreroll) {
+STDMETHODIMP CMatroskaMuxerFilter::GetPreroll(LONGLONG* pllPreroll)
+{
return E_NOTIMPL;
}
@@ -320,14 +337,16 @@ DWORD CMatroskaMuxerFilter::ThreadProc()
{
CComQIPtr<IStream> pStream;
- if(!m_pOutput || !(pStream = m_pOutput->GetConnected()))
- {
- while(1)
- {
+ if(!m_pOutput || !(pStream = m_pOutput->GetConnected())) {
+ while(1) {
DWORD cmd = GetRequest();
- if(cmd == CMD_EXIT) CAMThread::m_hThread = NULL;
+ if(cmd == CMD_EXIT) {
+ CAMThread::m_hThread = NULL;
+ }
Reply(S_OK);
- if(cmd == CMD_EXIT) return 0;
+ if(cmd == CMD_EXIT) {
+ return 0;
+ }
}
}
@@ -350,8 +369,11 @@ DWORD CMatroskaMuxerFilter::ThreadProc()
// TODO
MatroskaWriter::QWORD voidlen = 100;
- if(rtDur > 0) voidlen += int(1.0 * rtDur / MAXCLUSTERTIME / 10000 + 0.5) * 20;
- else voidlen += int(1.0 * 1000*60*60*24 / MAXCLUSTERTIME + 0.5) * 20; // when no duration is known, allocate for 24 hours (~340k)
+ if(rtDur > 0) {
+ voidlen += int(1.0 * rtDur / MAXCLUSTERTIME / 10000 + 0.5) * 20;
+ } else {
+ voidlen += int(1.0 * 1000*60*60*24 / MAXCLUSTERTIME + 0.5) * 20; // when no duration is known, allocate for 24 hours (~340k)
+ }
ULONGLONG voidpos = GetStreamPosition(pStream);
{
Void v(voidlen);
@@ -421,257 +443,239 @@ DWORD CMatroskaMuxerFilter::ThreadProc()
CAtlList<CMatroskaMuxerInputPin*> pActivePins;
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CMatroskaMuxerInputPin* pPin = m_pInputs.GetNext(pos);
- if(pPin->IsConnected()) pActivePins.AddTail(pPin);
+ if(pPin->IsConnected()) {
+ pActivePins.AddTail(pPin);
+ }
}
- while(1)
- {
+ while(1) {
DWORD cmd = GetRequest();
- switch(cmd)
- {
- default:
- case CMD_EXIT:
- CAMThread::m_hThread = NULL;
- Reply(S_OK);
- return 0;
-
- case CMD_RUN:
- Reply(S_OK);
-
- Cue cue;
- ULONGLONG lastcueclusterpos = (ULONGLONG)-1;
- INT64 lastcuetimecode = (INT64)-1;
- UINT64 nBlocksInCueTrack = 0;
+ switch(cmd) {
+ default:
+ case CMD_EXIT:
+ CAMThread::m_hThread = NULL;
+ Reply(S_OK);
+ return 0;
+
+ case CMD_RUN:
+ Reply(S_OK);
+
+ Cue cue;
+ ULONGLONG lastcueclusterpos = (ULONGLONG)-1;
+ INT64 lastcuetimecode = (INT64)-1;
+ UINT64 nBlocksInCueTrack = 0;
+
+ while(!CheckRequest(NULL)) {
+ if(m_State == State_Paused) {
+ Sleep(10);
+ continue;
+ }
- while(!CheckRequest(NULL))
- {
- if(m_State == State_Paused)
- {
- Sleep(10);
- continue;
- }
+ int nPinsGotSomething = 0, nPinsNeeded = 0;
+ CMatroskaMuxerInputPin* pPin = NULL;
+ REFERENCE_TIME rtMin = _I64_MAX;
- int nPinsGotSomething = 0, nPinsNeeded = 0;
- CMatroskaMuxerInputPin* pPin = NULL;
- REFERENCE_TIME rtMin = _I64_MAX;
+ pos = pActivePins.GetHeadPosition();
+ while(pos) {
+ CMatroskaMuxerInputPin* pTmp = pActivePins.GetNext(pos);
- pos = pActivePins.GetHeadPosition();
- while(pos)
- {
- CMatroskaMuxerInputPin* pTmp = pActivePins.GetNext(pos);
+ CAutoLock cAutoLock(&pTmp->m_csQueue);
- CAutoLock cAutoLock(&pTmp->m_csQueue);
+ if(pTmp->m_blocks.GetCount() == 0 && pTmp->m_fEndOfStreamReceived) {
+ pActivePins.RemoveAt(pActivePins.Find(pTmp));
+ continue;
+ }
- if(pTmp->m_blocks.GetCount() == 0 && pTmp->m_fEndOfStreamReceived)
- {
- pActivePins.RemoveAt(pActivePins.Find(pTmp));
- continue;
- }
+ if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle) {
+ nPinsNeeded++;
+ }
- if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle)
- nPinsNeeded++;
+ if(pTmp->m_blocks.GetCount() > 0) {
+ if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle) {
+ nPinsGotSomething++;
+ }
- if(pTmp->m_blocks.GetCount() > 0)
- {
- if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle)
- nPinsGotSomething++;
-
- if(pTmp->m_blocks.GetCount() > 0)
- {
- REFERENCE_TIME rt = pTmp->m_blocks.GetHead()->Block.TimeCode;
- if(rt < rtMin) {
- rtMin = rt;
- pPin = pTmp;
+ if(pTmp->m_blocks.GetCount() > 0) {
+ REFERENCE_TIME rt = pTmp->m_blocks.GetHead()->Block.TimeCode;
+ if(rt < rtMin) {
+ rtMin = rt;
+ pPin = pTmp;
+ }
}
}
}
- }
-
- if(pActivePins.GetCount() == 0)
- {
- break;
- }
-
- if(!pPin || nPinsNeeded > nPinsGotSomething || !pPin && nPinsGotSomething == 0)
- {
- Sleep(1);
- continue;
- }
- if(!fTracksWritten)
- {
- CNode<Track> Tracks;
- CAutoPtr<Track> pT(DNew Track());
- POSITION pos = pActivePins.GetHeadPosition();
- for(int i = 1; pos; i++)
- {
- CMatroskaMuxerInputPin* pPin = pActivePins.GetNext(pos);
+ if(pActivePins.GetCount() == 0) {
+ break;
+ }
- CAutoPtr<TrackEntry> pTE(DNew TrackEntry());
- *pTE = *pPin->GetTrackEntry();
- if(TrackNumber == 0 && pTE->TrackType == TrackEntry::TypeVideo)
- TrackNumber = pTE->TrackNumber;
- pT->TrackEntries.AddTail(pTE);
+ if(!pPin || nPinsNeeded > nPinsGotSomething || !pPin && nPinsGotSomething == 0) {
+ Sleep(1);
+ continue;
}
- Tracks.AddTail(pT);
- Tracks.Write(pStream);
- if(TrackNumber == 0) TrackNumber = 1;
+ if(!fTracksWritten) {
+ CNode<Track> Tracks;
+ CAutoPtr<Track> pT(DNew Track());
+ POSITION pos = pActivePins.GetHeadPosition();
+ for(int i = 1; pos; i++) {
+ CMatroskaMuxerInputPin* pPin = pActivePins.GetNext(pos);
+
+ CAutoPtr<TrackEntry> pTE(DNew TrackEntry());
+ *pTE = *pPin->GetTrackEntry();
+ if(TrackNumber == 0 && pTE->TrackType == TrackEntry::TypeVideo) {
+ TrackNumber = pTE->TrackNumber;
+ }
+ pT->TrackEntries.AddTail(pTE);
+ }
+ Tracks.AddTail(pT);
+ Tracks.Write(pStream);
- fTracksWritten = true;
- }
+ if(TrackNumber == 0) {
+ TrackNumber = 1;
+ }
- ASSERT(pPin);
+ fTracksWritten = true;
+ }
- CAutoPtr<BlockGroup> b;
+ ASSERT(pPin);
- {
- CAutoLock cAutoLock(&pPin->m_csQueue);
- b = pPin->m_blocks.RemoveHead();
- }
+ CAutoPtr<BlockGroup> b;
- if(b)
- {
- if(fFirstBlock)
{
- if(b->Block.TimeCode < 0 && m_fNegative || b->Block.TimeCode > 0 && m_fPositive)
- firstTimeCode = b->Block.TimeCode;
- fFirstBlock = false;
+ CAutoLock cAutoLock(&pPin->m_csQueue);
+ b = pPin->m_blocks.RemoveHead();
}
- b->Block.TimeCode -= firstTimeCode;
- b->Block.TimeCodeStop -= firstTimeCode;
-
- /*
- TRACE(_T("Muxing (%d): %I64d-%I64d dur=%I64d (c=%d, co=%dms), cnt=%d, ref=%d\n"),
- GetTrackNumber(pPin),
- (INT64)b->Block.TimeCode, (INT64)b->Block.TimeCodeStop, (UINT64)b->BlockDuration,
- (int)((b->Block.TimeCode)/MAXCLUSTERTIME), (int)(b->Block.TimeCode%MAXCLUSTERTIME),
- b->Block.BlockData.GetCount(), (int)b->ReferenceBlock);
- */
- if(b->Block.TimeCode < SHRT_MIN /*0*/) {
- ASSERT(0);
- continue;
- }
+ if(b) {
+ if(fFirstBlock) {
+ if(b->Block.TimeCode < 0 && m_fNegative || b->Block.TimeCode > 0 && m_fPositive) {
+ firstTimeCode = b->Block.TimeCode;
+ }
+ fFirstBlock = false;
+ }
- while((INT64)(c.TimeCode + MAXCLUSTERTIME) < b->Block.TimeCode)
- {
- if(!c.BlockGroups.IsEmpty())
- {
- sh.Attach(DNew SeekHead());
- sh->ID.Set(c.GetID()/*0x1F43B675*/);
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
-
- c.Write(pStream); // TODO: write blocks
+ b->Block.TimeCode -= firstTimeCode;
+ b->Block.TimeCodeStop -= firstTimeCode;
+
+ /*
+ TRACE(_T("Muxing (%d): %I64d-%I64d dur=%I64d (c=%d, co=%dms), cnt=%d, ref=%d\n"),
+ GetTrackNumber(pPin),
+ (INT64)b->Block.TimeCode, (INT64)b->Block.TimeCodeStop, (UINT64)b->BlockDuration,
+ (int)((b->Block.TimeCode)/MAXCLUSTERTIME), (int)(b->Block.TimeCode%MAXCLUSTERTIME),
+ b->Block.BlockData.GetCount(), (int)b->ReferenceBlock);
+ */
+ if(b->Block.TimeCode < SHRT_MIN /*0*/) {
+ ASSERT(0);
+ continue;
}
- c.TimeCode.Set(c.TimeCode + MAXCLUSTERTIME);
- c.BlockGroups.RemoveAll();
- nBlocksInCueTrack = 0;
- }
+ while((INT64)(c.TimeCode + MAXCLUSTERTIME) < b->Block.TimeCode) {
+ if(!c.BlockGroups.IsEmpty()) {
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(c.GetID()/*0x1F43B675*/);
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- if(b->Block.TrackNumber == TrackNumber)
- {
- nBlocksInCueTrack++;
- }
+ c.Write(pStream); // TODO: write blocks
+ }
- if(b->ReferenceBlock == 0 && b->Block.TrackNumber == TrackNumber)
- {
- ULONGLONG clusterpos = GetStreamPosition(pStream) - segpos;
- if(lastcueclusterpos != clusterpos || lastcuetimecode + 1000 < b->Block.TimeCode)
- {
- CAutoPtr<CueTrackPosition> ctp(DNew CueTrackPosition());
- ctp->CueTrack.Set(b->Block.TrackNumber);
- ctp->CueClusterPosition.Set(clusterpos);
- if(c.BlockGroups.GetCount() > 0) ctp->CueBlockNumber.Set(nBlocksInCueTrack);
- CAutoPtr<CuePoint> cp(DNew CuePoint());
- cp->CueTime.Set(b->Block.TimeCode);
- cp->CueTrackPositions.AddTail(ctp);
- cue.CuePoints.AddTail(cp);
- lastcueclusterpos = clusterpos;
- lastcuetimecode = b->Block.TimeCode;
+ c.TimeCode.Set(c.TimeCode + MAXCLUSTERTIME);
+ c.BlockGroups.RemoveAll();
+ nBlocksInCueTrack = 0;
}
- }
- info.Duration.Set(max(info.Duration, (float)b->Block.TimeCodeStop));
+ if(b->Block.TrackNumber == TrackNumber) {
+ nBlocksInCueTrack++;
+ }
- m_rtCurrent = b->Block.TimeCode*10000;
+ if(b->ReferenceBlock == 0 && b->Block.TrackNumber == TrackNumber) {
+ ULONGLONG clusterpos = GetStreamPosition(pStream) - segpos;
+ if(lastcueclusterpos != clusterpos || lastcuetimecode + 1000 < b->Block.TimeCode) {
+ CAutoPtr<CueTrackPosition> ctp(DNew CueTrackPosition());
+ ctp->CueTrack.Set(b->Block.TrackNumber);
+ ctp->CueClusterPosition.Set(clusterpos);
+ if(c.BlockGroups.GetCount() > 0) {
+ ctp->CueBlockNumber.Set(nBlocksInCueTrack);
+ }
+ CAutoPtr<CuePoint> cp(DNew CuePoint());
+ cp->CueTime.Set(b->Block.TimeCode);
+ cp->CueTrackPositions.AddTail(ctp);
+ cue.CuePoints.AddTail(cp);
+ lastcueclusterpos = clusterpos;
+ lastcuetimecode = b->Block.TimeCode;
+ }
+ }
- b->Block.TimeCode -= c.TimeCode;
- c.BlockGroups.AddTail(b);
- }
- }
+ info.Duration.Set(max(info.Duration, (float)b->Block.TimeCodeStop));
- if(!c.BlockGroups.IsEmpty())
- {
- sh.Attach(DNew SeekHead());
- sh->ID.Set(c.GetID()/*0x1F43B675*/);
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
+ m_rtCurrent = b->Block.TimeCode*10000;
- c.Write(pStream);
- }
+ b->Block.TimeCode -= c.TimeCode;
+ c.BlockGroups.AddTail(b);
+ }
+ }
- if(!cue.CuePoints.IsEmpty())
- {
- sh.Attach(DNew SeekHead());
- sh->ID.Set(cue.GetID()/*0x1C53BB6B*/);
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
+ if(!c.BlockGroups.IsEmpty()) {
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(c.GetID()/*0x1F43B675*/);
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- cue.Write(pStream);
- }
+ c.Write(pStream);
+ }
- {
- Tags tags;
+ if(!cue.CuePoints.IsEmpty()) {
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(cue.GetID()/*0x1C53BB6B*/);
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- sh.Attach(DNew SeekHead());
- sh->ID.Set(tags.GetID());
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
+ cue.Write(pStream);
+ }
- tags.Write(pStream);
- }
+ {
+ Tags tags;
- SetStreamPosition(pStream, voidpos);
- int len = (int)(voidlen - seek.Size());
- ASSERT(len >= 0 && len != 1);
- seek.Write(pStream);
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(tags.GetID());
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- if(len == 0)
- {
- // nothing to do
- }
- else if(len >= 2)
- {
- for(int i = 0; i < 8; i++)
- {
- if(len >= (1<<i*7)-2 && len <= (1<<(i+1)*7)-2)
- {
- Void(len-2-i).Write(pStream);
- break;
+ tags.Write(pStream);
+ }
+
+ SetStreamPosition(pStream, voidpos);
+ int len = (int)(voidlen - seek.Size());
+ ASSERT(len >= 0 && len != 1);
+ seek.Write(pStream);
+
+ if(len == 0) {
+ // nothing to do
+ } else if(len >= 2) {
+ for(int i = 0; i < 8; i++) {
+ if(len >= (1<<i*7)-2 && len <= (1<<(i+1)*7)-2) {
+ Void(len-2-i).Write(pStream);
+ break;
+ }
}
}
- }
- if(abs(m_rtCurrent - (REFERENCE_TIME)info.Duration*10000) > 10000000i64)
- {
- info.Duration.Set(m_rtCurrent / 10000 + 1);
- }
+ if(abs(m_rtCurrent - (REFERENCE_TIME)info.Duration*10000) > 10000000i64) {
+ info.Duration.Set(m_rtCurrent / 10000 + 1);
+ }
- SetStreamPosition(pStream, infopos);
- info.Write(pStream);
+ SetStreamPosition(pStream, infopos);
+ info.Write(pStream);
- // TODO: write some tags
+ // TODO: write some tags
- m_pOutput->DeliverEndOfStream();
+ m_pOutput->DeliverEndOfStream();
- break;
+ break;
}
}
@@ -708,31 +712,32 @@ STDMETHODIMP CMatroskaMuxerInputPin::NonDelegatingQueryInterface(REFIID riid, vo
HRESULT CMatroskaMuxerInputPin::CheckMediaType(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Video && (pmt->formattype == FORMAT_VideoInfo
- || pmt->formattype == FORMAT_VideoInfo2)
-// || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG1Payload && pmt->formattype == FORMAT_MPEGVideo
-// || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG2_VIDEO && pmt->formattype == FORMAT_MPEG2_VIDEO
- || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_DiracVideo && pmt->formattype == FORMAT_DiracVideoInfo
- || pmt->majortype == MEDIATYPE_Audio && pmt->formattype == FORMAT_WaveFormatEx && pmt->subtype == FOURCCMap(((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag)
- || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis && pmt->formattype == FORMAT_VorbisFormat
- || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis2 && pmt->formattype == FORMAT_VorbisFormat2
- || pmt->majortype == MEDIATYPE_Audio && (pmt->subtype == MEDIASUBTYPE_14_4
- || pmt->subtype == MEDIASUBTYPE_28_8
- || pmt->subtype == MEDIASUBTYPE_ATRC
- || pmt->subtype == MEDIASUBTYPE_COOK
- || pmt->subtype == MEDIASUBTYPE_DNET
- || pmt->subtype == MEDIASUBTYPE_SIPR) && pmt->formattype == FORMAT_WaveFormatEx
- || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
- || pmt->majortype == MEDIATYPE_Subtitle && pmt->formattype == FORMAT_SubtitleInfo
- ? S_OK
- : E_INVALIDARG;
+ || pmt->formattype == FORMAT_VideoInfo2)
+ // || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG1Payload && pmt->formattype == FORMAT_MPEGVideo
+ // || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG2_VIDEO && pmt->formattype == FORMAT_MPEG2_VIDEO
+ || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_DiracVideo && pmt->formattype == FORMAT_DiracVideoInfo
+ || pmt->majortype == MEDIATYPE_Audio && pmt->formattype == FORMAT_WaveFormatEx && pmt->subtype == FOURCCMap(((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag)
+ || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis && pmt->formattype == FORMAT_VorbisFormat
+ || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis2 && pmt->formattype == FORMAT_VorbisFormat2
+ || pmt->majortype == MEDIATYPE_Audio && (pmt->subtype == MEDIASUBTYPE_14_4
+ || pmt->subtype == MEDIASUBTYPE_28_8
+ || pmt->subtype == MEDIASUBTYPE_ATRC
+ || pmt->subtype == MEDIASUBTYPE_COOK
+ || pmt->subtype == MEDIASUBTYPE_DNET
+ || pmt->subtype == MEDIASUBTYPE_SIPR) && pmt->formattype == FORMAT_WaveFormatEx
+ || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
+ || pmt->majortype == MEDIATYPE_Subtitle && pmt->formattype == FORMAT_SubtitleInfo
+ ? S_OK
+ : E_INVALIDARG;
}
HRESULT CMatroskaMuxerInputPin::BreakConnect()
{
HRESULT hr;
- if(FAILED(hr = __super::BreakConnect()))
+ if(FAILED(hr = __super::BreakConnect())) {
return hr;
+ }
m_pTE.Free();
@@ -743,13 +748,15 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CompleteConnect(pPin)))
+ if(FAILED(hr = __super::CompleteConnect(pPin))) {
return hr;
+ }
m_rtDur = 0;
CComQIPtr<IMediaSeeking> pMS;
- if((pMS = GetFilterFromPin(pPin)) || (pMS = pPin))
+ if((pMS = GetFilterFromPin(pPin)) || (pMS = pPin)) {
pMS->GetDuration(&m_rtDur);
+ }
m_pTE.Free();
m_pTE.Attach(DNew TrackEntry());
@@ -761,22 +768,18 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
hr = E_FAIL;
- if(m_mt.majortype == MEDIATYPE_Video)
- {
+ if(m_mt.majortype == MEDIATYPE_Video) {
m_pTE->TrackType.Set(TrackEntry::TypeVideo);
if(m_mt.formattype == FORMAT_VideoInfo
- && m_mt.subtype == MEDIASUBTYPE_RV10 || m_mt.subtype == MEDIASUBTYPE_RV20
- || m_mt.subtype == MEDIASUBTYPE_RV30 || m_mt.subtype == MEDIASUBTYPE_RV40)
- {
+ && m_mt.subtype == MEDIASUBTYPE_RV10 || m_mt.subtype == MEDIASUBTYPE_RV20
+ || m_mt.subtype == MEDIASUBTYPE_RV30 || m_mt.subtype == MEDIASUBTYPE_RV40) {
m_pTE->CodecID.Set("V_REAL/RV00");
m_pTE->CodecID.SetAt(9, (BYTE)(m_mt.subtype.Data1>>16));
- if(m_mt.formattype == FORMAT_VideoInfo)
- {
+ if(m_mt.formattype == FORMAT_VideoInfo) {
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)m_mt.pbFormat;
- if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER))
- {
+ if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER)) {
m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - sizeof(VIDEOINFOHEADER));
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + sizeof(VIDEOINFOHEADER), m_pTE->CodecPrivate.GetCount());
}
@@ -784,14 +787,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->DescType = TrackEntry::DescVideo;
m_pTE->v.PixelWidth.Set(vih->bmiHeader.biWidth);
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
+ }
+ } else if(m_mt.formattype == FORMAT_VideoInfo2) {
VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)m_mt.pbFormat;
- if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER2))
- {
+ if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER2)) {
m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - sizeof(VIDEOINFOHEADER2));
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + sizeof(VIDEOINFOHEADER2), m_pTE->CodecPrivate.GetCount());
}
@@ -799,21 +800,18 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->DescType = TrackEntry::DescVideo;
m_pTE->v.PixelWidth.Set(vih->bmiHeader.biWidth);
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
+ }
m_pTE->v.DisplayWidth.Set(vih->dwPictAspectRatioX);
m_pTE->v.DisplayHeight.Set(vih->dwPictAspectRatioY);
- }
- else
- {
+ } else {
ASSERT(0);
return hr;
}
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo)
- {
+ } else if(m_mt.formattype == FORMAT_VideoInfo) {
m_pTE->CodecID.Set("V_MS/VFW/FOURCC");
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)m_mt.pbFormat;
@@ -823,13 +821,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->DescType = TrackEntry::DescVideo;
m_pTE->v.PixelWidth.Set(vih->bmiHeader.biWidth);
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
+ }
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
+ } else if(m_mt.formattype == FORMAT_VideoInfo2) {
m_pTE->CodecID.Set("V_MS/VFW/FOURCC");
VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)m_mt.pbFormat;
@@ -841,13 +838,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
m_pTE->v.DisplayWidth.Set(vih->dwPictAspectRatioX);
m_pTE->v.DisplayHeight.Set(vih->dwPictAspectRatioY);
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
+ }
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_DiracVideoInfo)
- {
+ } else if(m_mt.formattype == FORMAT_DiracVideoInfo) {
m_pTE->CodecID.Set("V_DIRAC");
DIRACINFOHEADER* vih = (DIRACINFOHEADER*)m_mt.pbFormat;
@@ -859,8 +855,9 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->v.PixelHeight.Set(abs(vih->hdr.bmiHeader.biHeight));
// m_pTE->v.DisplayWidth.Set(vih->dwPictAspectRatioX);
// m_pTE->v.DisplayHeight.Set(vih->dwPictAspectRatioY);
- if(vih->hdr.AvgTimePerFrame > 0)
+ if(vih->hdr.AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->hdr.AvgTimePerFrame));
+ }
hr = S_OK;
}
@@ -898,15 +895,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
hr = S_OK;
}
*/
- }
- else if(m_mt.majortype == MEDIATYPE_Audio)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Audio) {
m_pTE->TrackType.Set(TrackEntry::TypeAudio);
if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_AAC
- && m_mt.cbFormat >= sizeof(WAVEFORMATEX)+2)
- {
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_AAC
+ && m_mt.cbFormat >= sizeof(WAVEFORMATEX)+2) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
BYTE* p = (BYTE*)(wfe+1);
@@ -918,8 +912,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
int exttype = 0;
int rate2 = rate1;
- if(wfe->cbSize >= 5)
- {
+ if(wfe->cbSize >= 5) {
profile = 4;
exttype = (p[2]<<3)|(p[3]>>5);
@@ -928,31 +921,29 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
ASSERT((p[4]>>7) == 1);
rate2 = ((p[4]>>3)&15);
- if(rate2 < rate1)
- {
+ if(rate2 < rate1) {
m_pTE->a.OutputSamplingFrequency.Set((float)nSamplesPerSec);
nSamplesPerSec /= 2;
}
}
- switch(profile)
- {
- default:
- case 0:
- m_pTE->CodecID.Set("A_AAC/MPEG2/MAIN");
- break;
- case 1:
- m_pTE->CodecID.Set("A_AAC/MPEG2/LC");
- break;
- case 2:
- m_pTE->CodecID.Set("A_AAC/MPEG2/SSR");
- break;
- case 3:
- m_pTE->CodecID.Set("A_AAC/MPEG4/LTP");
- break;
- case 4:
- m_pTE->CodecID.Set("A_AAC/MPEG4/LC/SBR");
- break;
+ switch(profile) {
+ default:
+ case 0:
+ m_pTE->CodecID.Set("A_AAC/MPEG2/MAIN");
+ break;
+ case 1:
+ m_pTE->CodecID.Set("A_AAC/MPEG2/LC");
+ break;
+ case 2:
+ m_pTE->CodecID.Set("A_AAC/MPEG2/SSR");
+ break;
+ case 3:
+ m_pTE->CodecID.Set("A_AAC/MPEG4/LTP");
+ break;
+ case 4:
+ m_pTE->CodecID.Set("A_AAC/MPEG4/LC/SBR");
+ break;
}
ASSERT(channels == wfe->nChannels);
@@ -963,10 +954,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3) {
m_pTE->CodecID.Set("A_AC3");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -976,10 +965,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS) {
m_pTE->CodecID.Set("A_DTS");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -989,10 +976,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_FLAC)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_FLAC) {
m_pTE->CodecID.Set("A_FLAC");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -1001,37 +986,33 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.Channels.Set(wfe->nChannels);
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
- if(wfe->cbSize)
- {
+ if(wfe->cbSize) {
m_pTE->CodecPrivate.SetCount(wfe->cbSize);
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + sizeof(WAVEFORMATEX), wfe->cbSize);
}
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && (m_mt.subtype == MEDIASUBTYPE_14_4
- || m_mt.subtype == MEDIASUBTYPE_28_8
- || m_mt.subtype == MEDIASUBTYPE_ATRC
- || m_mt.subtype == MEDIASUBTYPE_COOK
- || m_mt.subtype == MEDIASUBTYPE_DNET
- || m_mt.subtype == MEDIASUBTYPE_SIPR))
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && (m_mt.subtype == MEDIASUBTYPE_14_4
+ || m_mt.subtype == MEDIASUBTYPE_28_8
+ || m_mt.subtype == MEDIASUBTYPE_ATRC
+ || m_mt.subtype == MEDIASUBTYPE_COOK
+ || m_mt.subtype == MEDIASUBTYPE_DNET
+ || m_mt.subtype == MEDIASUBTYPE_SIPR)) {
CStringA id;
id.Format("A_REAL/%c%c%c%c",
- (char)((m_mt.subtype.Data1>>0)&0xff),
- (char)((m_mt.subtype.Data1>>8)&0xff),
- (char)((m_mt.subtype.Data1>>16)&0xff),
- (char)((m_mt.subtype.Data1>>24)&0xff));
+ (char)((m_mt.subtype.Data1>>0)&0xff),
+ (char)((m_mt.subtype.Data1>>8)&0xff),
+ (char)((m_mt.subtype.Data1>>16)&0xff),
+ (char)((m_mt.subtype.Data1>>24)&0xff));
m_pTE->CodecID.Set(id);
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
DWORD cbSize = sizeof(WAVEFORMATEX) + wfe->cbSize;
- if(m_mt.cbFormat > cbSize)
- {
- m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - cbSize);
- memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + cbSize, m_pTE->CodecPrivate.GetCount());
+ if(m_mt.cbFormat > cbSize) {
+ m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - cbSize);
+ memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + cbSize, m_pTE->CodecPrivate.GetCount());
}
m_pTE->DescType = TrackEntry::DescAudio;
m_pTE->a.SamplingFrequency.Set((float)wfe->nSamplesPerSec);
@@ -1039,10 +1020,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM) {
m_pTE->CodecID.Set("A_PCM/INT/LIT");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -1052,9 +1031,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx) {
m_pTE->CodecID.Set("A_MS/ACM");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -1066,9 +1043,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VorbisFormat)
- {
+ } else if(m_mt.formattype == FORMAT_VorbisFormat) {
m_pTE->CodecID.Set("A_VORBIS");
VORBISFORMAT* pvf = (VORBISFORMAT*)m_mt.pbFormat;
@@ -1079,9 +1054,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
// m_pTE->CodecPrivate will be filled later
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VorbisFormat2)
- {
+ } else if(m_mt.formattype == FORMAT_VorbisFormat2) {
m_pTE->CodecID.Set("A_VORBIS");
VORBISFORMAT2* pvf2 = (VORBISFORMAT2*)m_mt.pbFormat;
@@ -1091,8 +1064,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_pTE->a.BitDepth.Set(pvf2->BitsPerSample);
int len = 1;
- for(int i = 0; i < 2; i++) len += pvf2->HeaderSize[i]/255 + 1;
- for(int i = 0; i < 3; i++) len += pvf2->HeaderSize[i];
+ for(int i = 0; i < 2; i++) {
+ len += pvf2->HeaderSize[i]/255 + 1;
+ }
+ for(int i = 0; i < 3; i++) {
+ len += pvf2->HeaderSize[i];
+ }
m_pTE->CodecPrivate.SetCount(len);
BYTE* src = (BYTE*)m_mt.pbFormat + sizeof(VORBISFORMAT2);
@@ -1100,8 +1077,9 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
*dst++ = 2;
for(int i = 0; i < 2; i++)
- for(int len = pvf2->HeaderSize[i]; len >= 0; len -= 255)
+ for(int len = pvf2->HeaderSize[i]; len >= 0; len -= 255) {
*dst++ = min(len, 255);
+ }
memcpy(dst, src, pvf2->HeaderSize[0]);
dst += pvf2->HeaderSize[0];
@@ -1118,19 +1096,14 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
hr = S_OK;
}
- }
- else if(m_mt.majortype == MEDIATYPE_Text)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Text) {
m_pTE->TrackType.Set(TrackEntry::TypeSubtitle);
- if(m_mt.formattype == FORMAT_None)
- {
+ if(m_mt.formattype == FORMAT_None) {
m_pTE->CodecID.Set("S_TEXT/ASCII");
hr = S_OK;
}
- }
- else if(m_mt.majortype == MEDIATYPE_Subtitle)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Subtitle) {
m_pTE->TrackType.Set(TrackEntry::TypeSubtitle);
m_pTE->CodecID.Set(
@@ -1141,21 +1114,18 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin)
m_mt.subtype == MEDIASUBTYPE_VOBSUB ? "S_VOBSUB" :
"");
- if(!m_pTE->CodecID.IsEmpty())
- {
+ if(!m_pTE->CodecID.IsEmpty()) {
hr = S_OK;
SUBTITLEINFO* psi = (SUBTITLEINFO*)m_mt.pbFormat;
- if(psi->dwOffset)
- {
+ if(psi->dwOffset) {
m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - psi->dwOffset);
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + psi->dwOffset, m_pTE->CodecPrivate.GetCount());
}
}
}
- if(S_OK == hr)
- {
+ if(S_OK == hr) {
(static_cast<CMatroskaMuxerFilter*>(m_pFilter))->AddInput();
}
@@ -1204,23 +1174,26 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample)
CAutoLock cAutoLock(&m_csReceive);
- while(m_fActive)
- {
+ while(m_fActive) {
{
CAutoLock cAutoLock2(&m_csQueue);
- if(m_blocks.GetCount() < MAXBLOCKS)
+ if(m_blocks.GetCount() < MAXBLOCKS) {
break;
+ }
}
Sleep(1);
}
- if(!m_fActive) return S_FALSE;
+ if(!m_fActive) {
+ return S_FALSE;
+ }
HRESULT hr;
- if(FAILED(hr = __super::Receive(pSample)))
+ if(FAILED(hr = __super::Receive(pSample))) {
return hr;
+ }
BYTE* pData = NULL;
pSample->GetPointer(&pData);
@@ -1230,15 +1203,14 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample)
REFERENCE_TIME rtStart = -1, rtStop = -1;
hr = pSample->GetTime(&rtStart, &rtStop);
- if(FAILED(hr) || rtStart == -1 || rtStop == -1)
- {
+ if(FAILED(hr) || rtStart == -1 || rtStop == -1) {
TRACE(_T("No timestamp was set on the sample!!!"));
m_pFilter->NotifyEvent(EC_ERRORABORT, VFW_E_SAMPLE_TIME_NOT_SET, 0);
return VFW_E_SAMPLE_TIME_NOT_SET;
}
-// rtStart += m_tStart;
-// rtStop += m_tStart;
+ // rtStart += m_tStart;
+ // rtStop += m_tStart;
/**/
TRACE(_T("Received (%d): %I64d-%I64d (c=%d, co=%dms), len=%d, d%d p%d s%d\n"),
@@ -1249,29 +1221,31 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample)
pSample->IsPreroll() == S_OK ? 1 : 0,
pSample->IsSyncPoint() == S_OK ? 1 : 0);
- if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_pVorbisHdrs.GetCount() < 3)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_pVorbisHdrs.GetCount() < 3) {
CAutoPtr<CBinary> data(DNew CBinary(0));
data->SetCount(len);
memcpy(data->GetData(), pData, len);
m_pVorbisHdrs.Add(data);
- if(m_pVorbisHdrs.GetCount() == 3)
- {
+ if(m_pVorbisHdrs.GetCount() == 3) {
int len = 1;
- for(int i = 0; i < 2; i++) len += m_pVorbisHdrs[i]->GetCount()/255 + 1;
- for(int i = 0; i < 3; i++) len += m_pVorbisHdrs[i]->GetCount();
+ for(int i = 0; i < 2; i++) {
+ len += m_pVorbisHdrs[i]->GetCount()/255 + 1;
+ }
+ for(int i = 0; i < 3; i++) {
+ len += m_pVorbisHdrs[i]->GetCount();
+ }
m_pTE->CodecPrivate.SetCount(len);
BYTE* dst = m_pTE->CodecPrivate.GetData();
*dst++ = 2;
for(int i = 0; i < 2; i++)
- for(int len = m_pVorbisHdrs[i]->GetCount(); len >= 0; len -= 255)
+ for(int len = m_pVorbisHdrs[i]->GetCount(); len >= 0; len -= 255) {
*dst++ = min(len, 255);
+ }
- for(int i = 0; i < 3; i++)
- {
+ for(int i = 0; i < 3; i++) {
memcpy(dst, m_pVorbisHdrs[i]->GetData(), m_pVorbisHdrs[i]->GetCount());
dst += m_pVorbisHdrs[i]->GetCount();
}
@@ -1281,21 +1255,21 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample)
}
if(m_mt.formattype == FORMAT_WaveFormatEx
- && (((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM
- || ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_MPEGLAYER3))
- pSample->SetSyncPoint(TRUE); // HACK: some capture filters don't set this
+ && (((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM
+ || ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_MPEGLAYER3)) {
+ pSample->SetSyncPoint(TRUE); // HACK: some capture filters don't set this
+ }
CAutoPtr<BlockGroup> b(DNew BlockGroup());
-/*
- // TODO: test this with a longer capture (pcm, mp3)
- if(S_OK == pSample->IsSyncPoint() && rtStart < m_rtLastStart)
- {
- TRACE(_T("!!! timestamp went backwards, dropping this frame !!! rtStart (%I64) < m_rtLastStart (%I64)"), rtStart, m_rtLastStart);
- return S_OK;
- }
-*/
- if((S_OK != pSample->IsSyncPoint() || m_rtLastStart == rtStart) && m_rtLastStart >= 0 /*&& m_rtLastStart < rtStart*/)
- {
+ /*
+ // TODO: test this with a longer capture (pcm, mp3)
+ if(S_OK == pSample->IsSyncPoint() && rtStart < m_rtLastStart)
+ {
+ TRACE(_T("!!! timestamp went backwards, dropping this frame !!! rtStart (%I64) < m_rtLastStart (%I64)"), rtStart, m_rtLastStart);
+ return S_OK;
+ }
+ */
+ if((S_OK != pSample->IsSyncPoint() || m_rtLastStart == rtStart) && m_rtLastStart >= 0 /*&& m_rtLastStart < rtStart*/) {
ASSERT(m_rtLastStart - rtStart <= 0);
REFERENCE_TIME rtDiff = m_rtLastStart - rtStart;
b->ReferenceBlock.Set((rtDiff + (rtDiff >= 0 ? 5000 : -5000)) / 10000);
@@ -1306,8 +1280,7 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample)
b->Block.TimeCode = (rtStart + 5000) / 10000;
b->Block.TimeCodeStop = (rtStop + 5000) / 10000;
- if(m_pTE->TrackType == TrackEntry::TypeSubtitle)
- {
+ if(m_pTE->TrackType == TrackEntry::TypeSubtitle) {
b->BlockDuration.Set((rtStop - rtStart + 5000) / 10000);
}
@@ -1329,8 +1302,9 @@ STDMETHODIMP CMatroskaMuxerInputPin::EndOfStream()
{
HRESULT hr;
- if(FAILED(hr = __super::EndOfStream()))
+ if(FAILED(hr = __super::EndOfStream())) {
return hr;
+ }
CAutoLock cAutoLock(&m_csQueue);
@@ -1371,9 +1345,13 @@ HRESULT CMatroskaMuxerOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCAT
pProperties->cbBuffer = 1;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
ASSERT(Actual.cBuffers == pProperties->cBuffers);
return NOERROR;
@@ -1390,8 +1368,12 @@ HRESULT CMatroskaMuxerOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
{
CAutoLock cAutoLock(m_pLock);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->ResetFormatBuffer();
pmt->InitMediaType();
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h
index 4a29b8bb5..4c8eddbd4 100644
--- a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h
+++ b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h
@@ -87,8 +87,7 @@ public:
interface __declspec(uuid("38E2D43D-915D-493C-B373-888DB16EE3DC"))
IMatroskaMuxer :
-public IUnknown
-{
+public IUnknown {
STDMETHOD (CorrectTimeOffset) (bool fNegative, bool fPositive) = 0;
// TODO: chapters
};
diff --git a/src/filters/muxer/WavDest/WavDest.cpp b/src/filters/muxer/WavDest/WavDest.cpp
index 9cd6e2833..05d68a2a5 100644
--- a/src/filters/muxer/WavDest/WavDest.cpp
+++ b/src/filters/muxer/WavDest/WavDest.cpp
@@ -27,29 +27,24 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_WAVE},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CWavDestFilter), L"MPC - WavDest", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{L"WavDest", &__uuidof(CWavDestFilter), CreateInstance<CWavDestFilter>, NULL, &sudFilter[0]}
};
@@ -78,26 +73,25 @@ CFilterApp theApp;
CWavDestFilter::CWavDestFilter(LPUNKNOWN pUnk, HRESULT* phr)
: CTransformFilter(NAME("WavDest filter"), pUnk, __uuidof(this))
{
- if(SUCCEEDED(*phr))
- {
- if(CWavDestOutputPin* pOut = DNew CWavDestOutputPin(this, phr))
- {
- if(SUCCEEDED(*phr)) m_pOutput = pOut;
- else delete pOut;
- }
- else
- {
+ if(SUCCEEDED(*phr)) {
+ if(CWavDestOutputPin* pOut = DNew CWavDestOutputPin(this, phr)) {
+ if(SUCCEEDED(*phr)) {
+ m_pOutput = pOut;
+ } else {
+ delete pOut;
+ }
+ } else {
*phr = E_OUTOFMEMORY;
return;
}
- if(CTransformInputPin* pIn = DNew CTransformInputPin(NAME("Transform input pin"), this, phr, L"In"))
- {
- if(SUCCEEDED(*phr)) m_pInput = pIn;
- else delete pIn;
- }
- else
- {
+ if(CTransformInputPin* pIn = DNew CTransformInputPin(NAME("Transform input pin"), this, phr, L"In")) {
+ if(SUCCEEDED(*phr)) {
+ m_pInput = pIn;
+ } else {
+ delete pIn;
+ }
+ } else {
*phr = E_OUTOFMEMORY;
return;
}
@@ -119,8 +113,9 @@ HRESULT CWavDestFilter::Receive(IMediaSample* pSample)
HRESULT hr = CTransformFilter::Receive(pSample);
// don't update the count if Deliver() downstream fails.
- if(hr != S_OK)
+ if(hr != S_OK) {
m_cbWavData = cbOld;
+ }
return hr;
}
@@ -130,14 +125,16 @@ HRESULT CWavDestFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
REFERENCE_TIME rtStart, rtEnd;
HRESULT hr = Copy(pIn, pOut);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
// Prepare it for writing
LONG lActual = pOut->GetActualDataLength();
- if(m_cbWavData + m_cbHeader + lActual < m_cbWavData + m_cbHeader ) // overflow
+ if(m_cbWavData + m_cbHeader + lActual < m_cbWavData + m_cbHeader ) { // overflow
return E_FAIL;
+ }
rtStart = m_cbWavData + m_cbHeader;
rtEnd = rtStart + lActual;
@@ -166,12 +163,14 @@ HRESULT CWavDestFilter::Copy(IMediaSample* pSource, IMediaSample* pDest) const
// Copy the sample times
REFERENCE_TIME TimeStart, TimeEnd;
- if(NOERROR == pSource->GetTime(&TimeStart, &TimeEnd))
+ if(NOERROR == pSource->GetTime(&TimeStart, &TimeEnd)) {
pDest->SetTime(&TimeStart, &TimeEnd);
+ }
LONGLONG MediaStart, MediaEnd;
- if(pSource->GetMediaTime(&MediaStart, &MediaEnd) == NOERROR)
+ if(pSource->GetMediaTime(&MediaStart, &MediaEnd) == NOERROR) {
pDest->SetMediaTime(&MediaStart, &MediaEnd);
+ }
// Copy the media type
AM_MEDIA_TYPE* pMediaType;
@@ -195,8 +194,7 @@ HRESULT CWavDestFilter::GetMediaType(int iPosition, CMediaType* pMediaType)
{
ASSERT(iPosition == 0 || iPosition == 1);
- if(iPosition == 0)
- {
+ if(iPosition == 0) {
pMediaType->SetType(&MEDIATYPE_Stream);
pMediaType->SetSubtype(&MEDIASUBTYPE_WAVE);
return S_OK;
@@ -207,8 +205,9 @@ HRESULT CWavDestFilter::GetMediaType(int iPosition, CMediaType* pMediaType)
HRESULT CWavDestFilter::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE)
+ if(m_pInput->IsConnected() == FALSE) {
return E_UNEXPECTED;
+ }
ASSERT(pAlloc);
ASSERT(pProperties);
@@ -221,26 +220,23 @@ HRESULT CWavDestFilter::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPER
CComPtr<IMemAllocator> pInAlloc;
ALLOCATOR_PROPERTIES InProps;
if(SUCCEEDED(hr = m_pInput->GetAllocator(&pInAlloc))
- && SUCCEEDED(hr = pInAlloc->GetProperties(&InProps)))
- {
+ && SUCCEEDED(hr = pInAlloc->GetProperties(&InProps))) {
pProperties->cbBuffer = InProps.cbBuffer;
- }
- else
- {
+ } else {
return hr;
}
ASSERT(pProperties->cbBuffer);
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties,&Actual)))
+ if(FAILED(hr = pAlloc->SetProperties(pProperties,&Actual))) {
return hr;
+ }
ASSERT(Actual.cBuffers == 1);
if(pProperties->cBuffers > Actual.cBuffers
- || pProperties->cbBuffer > Actual.cbBuffer)
- {
+ || pProperties->cbBuffer > Actual.cbBuffer) {
return E_FAIL;
}
@@ -271,17 +267,18 @@ HRESULT CWavDestFilter::StartStreaming()
HRESULT CWavDestFilter::StopStreaming()
{
IStream* pStream;
- if (m_pOutput->IsConnected() == FALSE)
+ if (m_pOutput->IsConnected() == FALSE) {
return E_FAIL;
+ }
IPin* pDwnstrmInputPin = m_pOutput->GetConnected();
- if (!pDwnstrmInputPin)
+ if (!pDwnstrmInputPin) {
return E_FAIL;
+ }
HRESULT hr = ((IMemInputPin *) pDwnstrmInputPin)->QueryInterface(IID_IStream, (void **)&pStream);
- if(SUCCEEDED(hr))
- {
+ if(SUCCEEDED(hr)) {
BYTE *pb = (BYTE *)_alloca(m_cbHeader);
RIFFLIST *pRiffWave = (RIFFLIST *)pb;
@@ -324,8 +321,9 @@ STDMETHODIMP CWavDestOutputPin::EnumMediaTypes(IEnumMediaTypes** ppEnum)
HRESULT CWavDestOutputPin::CheckMediaType(const CMediaType* pmt)
{
- if(pmt->majortype == MEDIATYPE_Stream && pmt->subtype == MEDIASUBTYPE_WAVE)
+ if(pmt->majortype == MEDIATYPE_Stream && pmt->subtype == MEDIASUBTYPE_WAVE) {
return S_OK;
- else
+ } else {
return S_FALSE;
+ }
}
diff --git a/src/filters/parser/AviSplitter/AviFile.cpp b/src/filters/parser/AviSplitter/AviFile.cpp
index 8e98d906b..96958a710 100644
--- a/src/filters/parser/AviSplitter/AviFile.cpp
+++ b/src/filters/parser/AviSplitter/AviFile.cpp
@@ -8,7 +8,9 @@
CAviFile::CAviFile(IAsyncReader* pAsyncReader, HRESULT& hr)
: CBaseSplitterFile(pAsyncReader, hr)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
m_isamv = false;
hr = Init();
}
@@ -17,38 +19,43 @@ HRESULT CAviFile::Init()
{
Seek(0);
DWORD dw[3];
- if(S_OK != Read(dw) || dw[0] != FCC('RIFF') || (dw[2] != FCC('AVI ') && dw[2] != FCC('AVIX') && dw[2] != FCC('AMV ')))
+ if(S_OK != Read(dw) || dw[0] != FCC('RIFF') || (dw[2] != FCC('AVI ') && dw[2] != FCC('AVIX') && dw[2] != FCC('AMV '))) {
return E_FAIL;
+ }
m_isamv = (dw[2] == FCC('AMV '));
Seek(0);
HRESULT hr = Parse(0, GetLength());
UNUSED_ALWAYS(hr);
- if(m_movis.GetCount() == 0) // FAILED(hr) is allowed as long as there was a movi chunk found
+ if(m_movis.GetCount() == 0) { // FAILED(hr) is allowed as long as there was a movi chunk found
return E_FAIL;
+ }
- if(m_avih.dwStreams == 0 && m_strms.GetCount() > 0)
+ if(m_avih.dwStreams == 0 && m_strms.GetCount() > 0) {
m_avih.dwStreams = m_strms.GetCount();
+ }
- if(m_avih.dwStreams != m_strms.GetCount())
+ if(m_avih.dwStreams != m_strms.GetCount()) {
return E_FAIL;
+ }
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
strm_t* s = m_strms[i];
- if(s->strh.fccType != FCC('auds')) continue;
+ if(s->strh.fccType != FCC('auds')) {
+ continue;
+ }
WAVEFORMATEX* wfe = (WAVEFORMATEX*)s->strf.GetData();
- if(wfe->wFormatTag == 0x55 && wfe->nBlockAlign == 1152
- && s->strh.dwScale == 1 && s->strh.dwRate != wfe->nSamplesPerSec)
- {
+ if(wfe->wFormatTag == 0x55 && wfe->nBlockAlign == 1152
+ && s->strh.dwScale == 1 && s->strh.dwRate != wfe->nSamplesPerSec) {
// correcting encoder bugs...
s->strh.dwScale = 1152;
s->strh.dwRate = wfe->nSamplesPerSec;
}
}
- if (!m_isamv && (FAILED(BuildIndex())))
+ if (!m_isamv && (FAILED(BuildIndex()))) {
EmptyIndex();
+ }
return S_OK;
}
@@ -60,26 +67,24 @@ HRESULT CAviFile::BuildAMVIndex()
ULONG ulSize;
memset (&NewChunk, 0, sizeof(strm_t::chunk));
- while((Read(ulType) == S_OK) && (Read(ulSize) == S_OK))
- {
- switch (ulType)
- {
- case FCC('00dc'): // 01bw : JPeg
- NewChunk.size = ulSize;
- NewChunk.filepos = GetPos();
- NewChunk.orgsize = ulSize;
- NewChunk.fKeyFrame = true;
- m_strms[0]->cs.Add (NewChunk);
- break;
- case FCC('01wb') : // 00dc : Audio
- NewChunk.size = ulSize;
- NewChunk.orgsize = ulSize;
- NewChunk.fKeyFrame = true;
- NewChunk.filepos = GetPos();
- m_strms[1]->cs.Add (NewChunk);
- break;
+ while((Read(ulType) == S_OK) && (Read(ulSize) == S_OK)) {
+ switch (ulType) {
+ case FCC('00dc'): // 01bw : JPeg
+ NewChunk.size = ulSize;
+ NewChunk.filepos = GetPos();
+ NewChunk.orgsize = ulSize;
+ NewChunk.fKeyFrame = true;
+ m_strms[0]->cs.Add (NewChunk);
+ break;
+ case FCC('01wb') : // 00dc : Audio
+ NewChunk.size = ulSize;
+ NewChunk.orgsize = ulSize;
+ NewChunk.fKeyFrame = true;
+ NewChunk.filepos = GetPos();
+ m_strms[1]->cs.Add (NewChunk);
+ break;
}
- Seek(GetPos() + ulSize);
+ Seek(GetPos() + ulSize);
}
TRACE ("Video packet : %d Audio packet :%d\n", m_strms[0]->cs.GetCount(), m_strms[1]->cs.GetCount());
@@ -93,177 +98,188 @@ HRESULT CAviFile::Parse(DWORD parentid, __int64 end)
CAutoPtr<strm_t> strm;
- while(S_OK == hr && GetPos() < end)
- {
+ while(S_OK == hr && GetPos() < end) {
UINT64 pos = GetPos();
DWORD id = 0, size;
- if(S_OK != Read(id) || id == 0)
+ if(S_OK != Read(id) || id == 0) {
return E_FAIL;
+ }
- if(id == FCC('RIFF') || id == FCC('LIST'))
- {
- if(S_OK != Read(size) || S_OK != Read(id))
+ if(id == FCC('RIFF') || id == FCC('LIST')) {
+ if(S_OK != Read(size) || S_OK != Read(id)) {
return E_FAIL;
+ }
- if (m_isamv) size = end - GetPos() - 8; // No size set in AVM : guess end of file...
+ if (m_isamv) {
+ size = end - GetPos() - 8; // No size set in AVM : guess end of file...
+ }
size += (size&1) + 8;
- TRACE(_T("CAviFile::Parse(..): LIST '%c%c%c%c'\n"),
- TCHAR((id>>0)&0xff),
- TCHAR((id>>8)&0xff),
- TCHAR((id>>16)&0xff),
- TCHAR((id>>24)&0xff));
+ TRACE(_T("CAviFile::Parse(..): LIST '%c%c%c%c'\n"),
+ TCHAR((id>>0)&0xff),
+ TCHAR((id>>8)&0xff),
+ TCHAR((id>>16)&0xff),
+ TCHAR((id>>24)&0xff));
- if(id == FCC('movi'))
- {
+ if(id == FCC('movi')) {
m_movis.AddTail(pos);
- if (m_isamv) BuildAMVIndex();
- }
- else
- {
+ if (m_isamv) {
+ BuildAMVIndex();
+ }
+ } else {
hr = Parse(id, pos + size);
}
- }
- else
- {
- if(S_OK != Read(size))
+ } else {
+ if(S_OK != Read(size)) {
return E_FAIL;
+ }
- TRACE(_T("CAviFile::Parse(..): '%c%c%c%c'\n"),
- TCHAR((id>>0)&0xff),
- TCHAR((id>>8)&0xff),
- TCHAR((id>>16)&0xff),
- TCHAR((id>>24)&0xff));
-
- if(parentid == FCC('INFO') && size > 0)
- {
- switch(id)
- {
- case FCC('IARL'): // Archival Location. Indicates where the subject of the file is archived.
- case FCC('IART'): // Artist. Lists the artist of the original subject of the file; for example, “Michaelangelo.”
- case FCC('ICMS'): // Commissioned. Lists the name of the person or organization that commissioned the subject of the file; for example, “Pope Julian II.”
- case FCC('ICMT'): // Comments. Provides general comments about the file or the subject of the file. If the comment is several sentences long, end each sentence with a period. Do not include new-line characters.
- case FCC('ICOP'): // Copyright. Records the copyright information for the file; for example, “Copyright Encyclopedia International 1991.” If there are multiple copyrights, separate them by a semicolon followed by a space.
- case FCC('ICRD'): // Creation date. Specifies the date the subject of the file was created. List dates in year-month-day format, padding one-digit months and days with a zero on the left; for example, “1553-05-03” for May 3, 1553.
- case FCC('ICRP'): // Cropped. Describes whether an image has been cropped and, if so, how it was cropped; for example, “lower-right corner.”
- case FCC('IDIM'): // Dimensions. Specifies the size of the original subject of the file; for example, “8.5 in h, 11 in w.”
- case FCC('IDPI'): // Dots Per Inch. Stores dots per inch setting of the digitizer used to produce the file, such as “300.”
- case FCC('IENG'): // Engineer. Stores the name of the engineer who worked on the file. If there are multiple engineers, separate the names by a semicolon and a blank; for example, “Smith, John; Adams, Joe.”
- case FCC('IGNR'): // Genre. Describes the original work, such as “landscape,” “portrait,” “still life,” etc.
- case FCC('IKEY'): // Keywords. Provides a list of keywords that refer to the file or subject of the file. Separate multiple keywords with a semicolon and a blank; for example, “Seattle; aerial view; scenery.”
- case FCC('ILGT'): // Lightness. Describes the changes in lightness settings on the digitizer required to produce the file. Note that the format of this information depends on hardware used.
- case FCC('IMED'): // Medium. Describes the original subject of the file, such as “computer image,” “drawing,” “lithograph,” and so on.
- case FCC('INAM'): // Name. Stores the title of the subject of the file, such as “Seattle From Above.”
- case FCC('IPLT'): // Palette Setting. Specifies the number of colors requested when digitizing an image, such as “256.”
- case FCC('IPRD'): // Product. Specifies the name of the title the file was originally intended for, such as “Encyclopedia of Pacific Northwest Geography.”
- case FCC('ISBJ'): // Subject. Describes the contents of the file, such as “Aerial view of Seattle.”
- case FCC('ISFT'): // Software. Identifies the name of the software package used to create the file, such as “Microsoft WaveEdit.”
- case FCC('ISHP'): // Sharpness. Identifies the changes in sharpness for the digitizer required to produce the file (the format depends on the hardware used).
- case FCC('ISRC'): // Source. Identifies the name of the person or organization who supplied the original subject of the file; for example, “Trey Research.”
- case FCC('ISRF'): // Source Form. Identifies the original form of the material that was digitized, such as “slide,” “paper,” “map,” and so on. This is not necessarily the same as IMED.
- case FCC('ITCH'): // Technician. Identifies the technician who digitized the subject file; for example, “Smith, John.”
- {
+ TRACE(_T("CAviFile::Parse(..): '%c%c%c%c'\n"),
+ TCHAR((id>>0)&0xff),
+ TCHAR((id>>8)&0xff),
+ TCHAR((id>>16)&0xff),
+ TCHAR((id>>24)&0xff));
+
+ if(parentid == FCC('INFO') && size > 0) {
+ switch(id) {
+ case FCC('IARL'): // Archival Location. Indicates where the subject of the file is archived.
+ case FCC('IART'): // Artist. Lists the artist of the original subject of the file; for example, “Michaelangelo.”
+ case FCC('ICMS'): // Commissioned. Lists the name of the person or organization that commissioned the subject of the file; for example, “Pope Julian II.”
+ case FCC('ICMT'): // Comments. Provides general comments about the file or the subject of the file. If the comment is several sentences long, end each sentence with a period. Do not include new-line characters.
+ case FCC('ICOP'): // Copyright. Records the copyright information for the file; for example, “Copyright Encyclopedia International 1991.” If there are multiple copyrights, separate them by a semicolon followed by a space.
+ case FCC('ICRD'): // Creation date. Specifies the date the subject of the file was created. List dates in year-month-day format, padding one-digit months and days with a zero on the left; for example, “1553-05-03” for May 3, 1553.
+ case FCC('ICRP'): // Cropped. Describes whether an image has been cropped and, if so, how it was cropped; for example, “lower-right corner.”
+ case FCC('IDIM'): // Dimensions. Specifies the size of the original subject of the file; for example, “8.5 in h, 11 in w.”
+ case FCC('IDPI'): // Dots Per Inch. Stores dots per inch setting of the digitizer used to produce the file, such as “300.”
+ case FCC('IENG'): // Engineer. Stores the name of the engineer who worked on the file. If there are multiple engineers, separate the names by a semicolon and a blank; for example, “Smith, John; Adams, Joe.”
+ case FCC('IGNR'): // Genre. Describes the original work, such as “landscape,” “portrait,” “still life,” etc.
+ case FCC('IKEY'): // Keywords. Provides a list of keywords that refer to the file or subject of the file. Separate multiple keywords with a semicolon and a blank; for example, “Seattle; aerial view; scenery.”
+ case FCC('ILGT'): // Lightness. Describes the changes in lightness settings on the digitizer required to produce the file. Note that the format of this information depends on hardware used.
+ case FCC('IMED'): // Medium. Describes the original subject of the file, such as “computer image,” “drawing,” “lithograph,” and so on.
+ case FCC('INAM'): // Name. Stores the title of the subject of the file, such as “Seattle From Above.”
+ case FCC('IPLT'): // Palette Setting. Specifies the number of colors requested when digitizing an image, such as “256.”
+ case FCC('IPRD'): // Product. Specifies the name of the title the file was originally intended for, such as “Encyclopedia of Pacific Northwest Geography.”
+ case FCC('ISBJ'): // Subject. Describes the contents of the file, such as “Aerial view of Seattle.”
+ case FCC('ISFT'): // Software. Identifies the name of the software package used to create the file, such as “Microsoft WaveEdit.”
+ case FCC('ISHP'): // Sharpness. Identifies the changes in sharpness for the digitizer required to produce the file (the format depends on the hardware used).
+ case FCC('ISRC'): // Source. Identifies the name of the person or organization who supplied the original subject of the file; for example, “Trey Research.”
+ case FCC('ISRF'): // Source Form. Identifies the original form of the material that was digitized, such as “slide,” “paper,” “map,” and so on. This is not necessarily the same as IMED.
+ case FCC('ITCH'): { // Technician. Identifies the technician who digitized the subject file; for example, “Smith, John.”
CStringA str;
- if(S_OK != ByteRead((BYTE*)str.GetBufferSetLength(size), size)) return E_FAIL;
+ if(S_OK != ByteRead((BYTE*)str.GetBufferSetLength(size), size)) {
+ return E_FAIL;
+ }
m_info[id] = str;
break;
}
}
}
- switch(id)
- {
- case FCC('amvh'):
- case FCC('avih'):
- m_avih.fcc = id;
- m_avih.cb = size;
- if(S_OK != Read(m_avih, 8)) return E_FAIL;
- break;
- case FCC('strh'):
- if(!strm) strm.Attach(DNew strm_t());
- strm->strh.fcc = FCC('strh');
- strm->strh.cb = size;
- if(S_OK != Read(strm->strh, 8)) return E_FAIL;
- if (m_isamv)
- {
- // First alway video, second always audio
- strm->strh.fccType = m_strms.GetCount() == 0 ? FCC('vids') : FCC('amva');
- strm->strh.dwRate = m_avih.dwReserved[0]*1000; // dwReserved[0] = fps!
- strm->strh.dwScale = 1000;
- }
- break;
- case FCC('strn'):
- if(S_OK != ByteRead((BYTE*)strm->strn.GetBufferSetLength(size), size)) return E_FAIL;
- break;
- case FCC('strf'):
- if(!strm) strm.Attach(DNew strm_t());
- strm->strf.SetCount(size);
- if(S_OK != ByteRead(strm->strf.GetData(), size)) return E_FAIL;
- if (m_isamv)
- {
- if (strm->strh.fccType == FCC('vids'))
- {
- strm->strf.SetCount(sizeof(BITMAPINFOHEADER));
- BITMAPINFOHEADER* pbmi = &((BITMAPINFO*)strm->strf.GetData())->bmiHeader;
- pbmi->biSize = sizeof(BITMAPINFOHEADER);
- pbmi->biHeight = m_avih.dwHeight;
- pbmi->biWidth = m_avih.dwWidth;
- pbmi->biCompression = FCC('AMVV');
- pbmi->biPlanes = 1;
- pbmi->biBitCount = 24;
- pbmi->biSizeImage = pbmi->biHeight * pbmi->biWidth * (pbmi->biBitCount/8);
+ switch(id) {
+ case FCC('amvh'):
+ case FCC('avih'):
+ m_avih.fcc = id;
+ m_avih.cb = size;
+ if(S_OK != Read(m_avih, 8)) {
+ return E_FAIL;
+ }
+ break;
+ case FCC('strh'):
+ if(!strm) {
+ strm.Attach(DNew strm_t());
+ }
+ strm->strh.fcc = FCC('strh');
+ strm->strh.cb = size;
+ if(S_OK != Read(strm->strh, 8)) {
+ return E_FAIL;
+ }
+ if (m_isamv) {
+ // First alway video, second always audio
+ strm->strh.fccType = m_strms.GetCount() == 0 ? FCC('vids') : FCC('amva');
+ strm->strh.dwRate = m_avih.dwReserved[0]*1000; // dwReserved[0] = fps!
+ strm->strh.dwScale = 1000;
+ }
+ break;
+ case FCC('strn'):
+ if(S_OK != ByteRead((BYTE*)strm->strn.GetBufferSetLength(size), size)) {
+ return E_FAIL;
+ }
+ break;
+ case FCC('strf'):
+ if(!strm) {
+ strm.Attach(DNew strm_t());
+ }
+ strm->strf.SetCount(size);
+ if(S_OK != ByteRead(strm->strf.GetData(), size)) {
+ return E_FAIL;
+ }
+ if (m_isamv) {
+ if (strm->strh.fccType == FCC('vids')) {
+ strm->strf.SetCount(sizeof(BITMAPINFOHEADER));
+ BITMAPINFOHEADER* pbmi = &((BITMAPINFO*)strm->strf.GetData())->bmiHeader;
+ pbmi->biSize = sizeof(BITMAPINFOHEADER);
+ pbmi->biHeight = m_avih.dwHeight;
+ pbmi->biWidth = m_avih.dwWidth;
+ pbmi->biCompression = FCC('AMVV');
+ pbmi->biPlanes = 1;
+ pbmi->biBitCount = 24;
+ pbmi->biSizeImage = pbmi->biHeight * pbmi->biWidth * (pbmi->biBitCount/8);
+ }
+ m_strms.Add(strm);
}
- m_strms.Add(strm);
- }
- break;
- case FCC('indx'):
- if(!strm) strm.Attach(DNew strm_t());
- ASSERT(strm->indx == NULL);
- AVISUPERINDEX* pSuperIndex;
- if (size < MAXDWORD-8)
- {
- // Fix buffer overrun vulnerability : http://www.vulnhunt.com/advisories/CAL-20070912-1_Multiple_vendor_produce_handling_AVI_file_vulnerabilities.txt
- TRY
- {
- pSuperIndex = (AVISUPERINDEX*)DNew unsigned char [(size_t)(size + 8)];
+ break;
+ case FCC('indx'):
+ if(!strm) {
+ strm.Attach(DNew strm_t());
+ }
+ ASSERT(strm->indx == NULL);
+ AVISUPERINDEX* pSuperIndex;
+ if (size < MAXDWORD-8) {
+ // Fix buffer overrun vulnerability : http://www.vulnhunt.com/advisories/CAL-20070912-1_Multiple_vendor_produce_handling_AVI_file_vulnerabilities.txt
+ TRY {
+ pSuperIndex = (AVISUPERINDEX*)DNew unsigned char [(size_t)(size + 8)];
+ }
+ CATCH (CMemoryException, e) {
+ pSuperIndex = NULL;
+ }
+ END_CATCH
+ if (pSuperIndex) {
+ strm->indx.Attach(pSuperIndex);
+ strm->indx->fcc = FCC('indx');
+ strm->indx->cb = size;
+ if(S_OK != ByteRead((BYTE*)(AVISUPERINDEX*)strm->indx + 8, size)) {
+ return E_FAIL;
+ }
+ ASSERT(strm->indx->wLongsPerEntry == 4 && strm->indx->bIndexType == AVI_INDEX_OF_INDEXES);
+ }
}
- CATCH (CMemoryException, e)
- {
- pSuperIndex = NULL;
+ break;
+ case FCC('dmlh'):
+ if(S_OK != Read(m_dmlh)) {
+ return E_FAIL;
}
- END_CATCH
- if (pSuperIndex)
- {
- strm->indx.Attach(pSuperIndex);
- strm->indx->fcc = FCC('indx');
- strm->indx->cb = size;
- if(S_OK != ByteRead((BYTE*)(AVISUPERINDEX*)strm->indx + 8, size)) return E_FAIL;
- ASSERT(strm->indx->wLongsPerEntry == 4 && strm->indx->bIndexType == AVI_INDEX_OF_INDEXES);
+ break;
+ case FCC('vprp'):
+ // if(S_OK != Read(m_vprp)) return E_FAIL;
+ break;
+ case FCC('idx1'):
+ ASSERT(m_idx1 == NULL);
+ m_idx1.Attach((AVIOLDINDEX*)DNew BYTE[size + 8]);
+ m_idx1->fcc = FCC('idx1');
+ m_idx1->cb = size;
+ if(S_OK != ByteRead((BYTE*)(AVIOLDINDEX*)m_idx1 + 8, size)) {
+ return E_FAIL;
}
- }
- break;
- case FCC('dmlh'):
- if(S_OK != Read(m_dmlh)) return E_FAIL;
- break;
- case FCC('vprp'):
-// if(S_OK != Read(m_vprp)) return E_FAIL;
- break;
- case FCC('idx1'):
- ASSERT(m_idx1 == NULL);
- m_idx1.Attach((AVIOLDINDEX*)DNew BYTE[size + 8]);
- m_idx1->fcc = FCC('idx1');
- m_idx1->cb = size;
- if(S_OK != ByteRead((BYTE*)(AVIOLDINDEX*)m_idx1 + 8, size)) return E_FAIL;
- break;
- default :
- TRACE(_T("CAviFile::Parse(..): unknown tag '%c%c%c%c'\n"),
- TCHAR((id>>0)&0xff),
- TCHAR((id>>8)&0xff),
- TCHAR((id>>16)&0xff),
- TCHAR((id>>24)&0xff));
- break;
+ break;
+ default :
+ TRACE(_T("CAviFile::Parse(..): unknown tag '%c%c%c%c'\n"),
+ TCHAR((id>>0)&0xff),
+ TCHAR((id>>8)&0xff),
+ TCHAR((id>>16)&0xff),
+ TCHAR((id>>24)&0xff));
+ break;
}
size += (size&1) + 8;
@@ -272,7 +288,9 @@ HRESULT CAviFile::Parse(DWORD parentid, __int64 end)
Seek(pos + size);
}
- if(strm) m_strms.Add(strm);
+ if(strm) {
+ m_strms.Add(strm);
+ }
return hr;
}
@@ -281,14 +299,15 @@ REFERENCE_TIME CAviFile::GetTotalTime()
{
REFERENCE_TIME t = 0/*10i64*m_avih.dwMicroSecPerFrame*m_avih.dwTotalFrames*/;
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
strm_t* s = m_strms[i];
REFERENCE_TIME t2 = s->GetRefTime(s->cs.GetCount(), s->totalsize);
t = max(t, t2);
}
- if(t == 0) t = 10i64*m_avih.dwMicroSecPerFrame*m_avih.dwTotalFrames;
+ if(t == 0) {
+ t = 10i64*m_avih.dwMicroSecPerFrame*m_avih.dwTotalFrames;
+ }
return(t);
}
@@ -299,63 +318,56 @@ HRESULT CAviFile::BuildIndex()
DWORD nSuperIndexes = 0;
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
strm_t* s = m_strms[i];
- if(s->indx && s->indx->nEntriesInUse > 0) nSuperIndexes++;
+ if(s->indx && s->indx->nEntriesInUse > 0) {
+ nSuperIndexes++;
+ }
}
- if(nSuperIndexes == m_avih.dwStreams)
- {
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ if(nSuperIndexes == m_avih.dwStreams) {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
strm_t* s = m_strms[i];
AVISUPERINDEX* idx = (AVISUPERINDEX*)s->indx;
DWORD nEntriesInUse = 0;
- for(int j = 0; j < (int)idx->nEntriesInUse; j++)
- {
+ for(int j = 0; j < (int)idx->nEntriesInUse; j++) {
Seek(idx->aIndex[j].qwOffset);
AVISTDINDEX stdidx;
- if(S_OK != ByteRead((BYTE*)&stdidx, FIELD_OFFSET(AVISTDINDEX, aIndex)))
- {
+ if(S_OK != ByteRead((BYTE*)&stdidx, FIELD_OFFSET(AVISTDINDEX, aIndex))) {
EmptyIndex();
return E_FAIL;
}
nEntriesInUse += stdidx.nEntriesInUse;
- }
+ }
s->cs.SetCount(nEntriesInUse);
DWORD frame = 0;
UINT64 size = 0;
- for(int j = 0; j < (int)idx->nEntriesInUse; j++)
- {
+ for(int j = 0; j < (int)idx->nEntriesInUse; j++) {
Seek(idx->aIndex[j].qwOffset);
CAutoPtr<AVISTDINDEX> p((AVISTDINDEX*)DNew BYTE[idx->aIndex[j].dwSize]);
- if(!p || S_OK != ByteRead((BYTE*)(AVISTDINDEX*)p, idx->aIndex[j].dwSize))
- {
+ if(!p || S_OK != ByteRead((BYTE*)(AVISTDINDEX*)p, idx->aIndex[j].dwSize)) {
EmptyIndex();
return E_FAIL;
}
- for(int k = 0; k < (int)p->nEntriesInUse; k++)
- {
+ for(int k = 0; k < (int)p->nEntriesInUse; k++) {
s->cs[frame].size = size;
s->cs[frame].filepos = p->qwBaseOffset + p->aIndex[k].dwOffset;
- s->cs[frame].fKeyFrame = !(p->aIndex[k].dwSize&AVISTDINDEX_DELTAFRAME)
- || s->strh.fccType == FCC('auds');
+ s->cs[frame].fKeyFrame = !(p->aIndex[k].dwSize&AVISTDINDEX_DELTAFRAME)
+ || s->strh.fccType == FCC('auds');
s->cs[frame].fChunkHdr = false;
s->cs[frame].orgsize = p->aIndex[k].dwSize&AVISTDINDEX_SIZEMASK;
- if(m_idx1)
- {
+ if(m_idx1) {
s->cs[frame].filepos -= 8;
s->cs[frame].fChunkHdr = true;
}
@@ -367,23 +379,20 @@ HRESULT CAviFile::BuildIndex()
s->totalsize = size;
}
- }
- else if(AVIOLDINDEX* idx = m_idx1)
- {
+ } else if(AVIOLDINDEX* idx = m_idx1) {
int len = idx->cb/sizeof(idx->aIndex[0]);
UINT64 offset = m_movis.GetHead() + 8;
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
strm_t* s = m_strms[i];
int nFrames = 0;
- for(int j = 0; j < len; j++)
- {
- if(TRACKNUM(idx->aIndex[j].dwChunkId) == i)
+ for(int j = 0; j < len; j++) {
+ if(TRACKNUM(idx->aIndex[j].dwChunkId) == i) {
nFrames++;
+ }
}
s->cs.SetCount(nFrames);
@@ -391,19 +400,15 @@ HRESULT CAviFile::BuildIndex()
DWORD frame = 0;
UINT64 size = 0;
- for(int j = 0; j < len; j++)
- {
+ for(int j = 0; j < len; j++) {
DWORD TrackNumber = TRACKNUM(idx->aIndex[j].dwChunkId);
- if(TrackNumber == i)
- {
- if(j == 0 && idx->aIndex[j].dwOffset > offset)
- {
+ if(TrackNumber == i) {
+ if(j == 0 && idx->aIndex[j].dwOffset > offset) {
DWORD id;
Seek(offset + idx->aIndex[j].dwOffset);
Read(id);
- if(id != idx->aIndex[j].dwChunkId)
- {
+ if(id != idx->aIndex[j].dwChunkId) {
TRACE(_T("WARNING: CAviFile::Init() detected absolute chunk addressing in \'idx1\'"));
offset = 0;
}
@@ -411,9 +416,9 @@ HRESULT CAviFile::BuildIndex()
s->cs[frame].size = size;
s->cs[frame].filepos = offset + idx->aIndex[j].dwOffset;
- s->cs[frame].fKeyFrame = !!(idx->aIndex[j].dwFlags&AVIIF_KEYFRAME)
- || s->strh.fccType == FCC('auds') // FIXME: some audio index is without any kf flag
- || frame == 0; // grrr
+ s->cs[frame].fKeyFrame = !!(idx->aIndex[j].dwFlags&AVIIF_KEYFRAME)
+ || s->strh.fccType == FCC('auds') // FIXME: some audio index is without any kf flag
+ || frame == 0; // grrr
s->cs[frame].fChunkHdr = j == len-1 || idx->aIndex[j].dwOffset != idx->aIndex[j+1].dwOffset;
s->cs[frame].orgsize = idx->aIndex[j].dwSize;
@@ -427,16 +432,16 @@ HRESULT CAviFile::BuildIndex()
}
m_idx1.Free();
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
m_strms[i]->indx.Free();
+ }
return S_OK;
}
void CAviFile::EmptyIndex()
{
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
strm_t* s = m_strms[i];
s->cs.RemoveAll();
s->totalsize = 0;
@@ -445,14 +450,16 @@ void CAviFile::EmptyIndex()
bool CAviFile::IsInterleaved(bool fKeepInfo)
{
- if(m_strms.GetCount() < 2)
- return(true);
-/*
- if(m_avih.dwFlags&AVIF_ISINTERLEAVED) // not reliable, nandub can write f*cked up files and still sets it
+ if(m_strms.GetCount() < 2) {
return(true);
-*/
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
+ }
+ /*
+ if(m_avih.dwFlags&AVIF_ISINTERLEAVED) // not reliable, nandub can write f*cked up files and still sets it
+ return(true);
+ */
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
m_strms[i]->cs2.SetCount(m_strms[i]->cs.GetCount());
+ }
DWORD* curchunks = DNew DWORD[m_avih.dwStreams];
UINT64* cursizes = DNew UINT64[m_avih.dwStreams];
@@ -462,30 +469,34 @@ bool CAviFile::IsInterleaved(bool fKeepInfo)
int end = 0;
- while(1)
- {
+ while(1) {
UINT64 fpmin = _I64_MAX;
DWORD n = (DWORD)-1;
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
int curchunk = curchunks[i];
CAtlArray<strm_t::chunk>& cs = m_strms[i]->cs;
- if(curchunk >= cs.GetCount()) continue;
- UINT64 fp = cs[curchunk].filepos;
- if(fp < fpmin) {fpmin = fp; n = i;}
+ if(curchunk >= cs.GetCount()) {
+ continue;
+ }
+ UINT64 fp = cs[curchunk].filepos;
+ if(fp < fpmin) {
+ fpmin = fp;
+ n = i;
+ }
+ }
+ if(n == -1) {
+ break;
}
- if(n == -1) break;
strm_t* s = m_strms[n];
DWORD& curchunk = curchunks[n];
UINT64& cursize = cursizes[n];
- if(!s->IsRawSubtitleStream())
- {
+ if(!s->IsRawSubtitleStream()) {
strm_t::chunk2& cs2 = s->cs2[curchunk];
cs2.t = (DWORD)(s->GetRefTime(curchunk, cursize)>>13); // for comparing later it is just as good as /10000 to get a near [ms] accuracy
-// cs2.t = (DWORD)(s->GetRefTime(curchunk, cursize)/10000);
+ // cs2.t = (DWORD)(s->GetRefTime(curchunk, cursize)/10000);
cs2.n = end++;
}
@@ -499,24 +510,30 @@ bool CAviFile::IsInterleaved(bool fKeepInfo)
bool fInterleaved = true;
- while(fInterleaved)
- {
+ while(fInterleaved) {
strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX};
int n = -1;
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
int curchunk = curchunks[i];
- if(curchunk >= m_strms[i]->cs2.GetCount()) continue;
+ if(curchunk >= m_strms[i]->cs2.GetCount()) {
+ continue;
+ }
strm_t::chunk2& cs2 = m_strms[i]->cs2[curchunk];
- if(cs2.t < cs2min.t) {cs2min = cs2; n = i;}
+ if(cs2.t < cs2min.t) {
+ cs2min = cs2;
+ n = i;
+ }
+ }
+ if(n == -1) {
+ break;
}
- if(n == -1) break;
curchunks[n]++;
- if(cs2last.t >= 0 && abs((int)cs2min.n - (int)cs2last.n) >= 1000)
+ if(cs2last.t >= 0 && abs((int)cs2min.n - (int)cs2last.n) >= 1000) {
fInterleaved = false;
+ }
cs2last = cs2min;
}
@@ -524,11 +541,11 @@ bool CAviFile::IsInterleaved(bool fKeepInfo)
delete [] curchunks;
delete [] cursizes;
- if(fInterleaved && !fKeepInfo)
- {
+ if(fInterleaved && !fKeepInfo) {
// this is not needed anymore, let's save a little memory then
- for(int i = 0; i < (int)m_avih.dwStreams; i++)
+ for(int i = 0; i < (int)m_avih.dwStreams; i++) {
m_strms[i]->cs2.RemoveAll();
+ }
}
return(fInterleaved);
@@ -538,8 +555,7 @@ REFERENCE_TIME CAviFile::strm_t::GetRefTime(DWORD frame, UINT64 size)
{
float dframe = frame;
- if(strh.fccType == FCC('auds'))
- {
+ if(strh.fccType == FCC('auds')) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)strf.GetData();
dframe = wfe->nBlockAlign ? 1.0f * size / wfe->nBlockAlign : 0;
@@ -556,27 +572,24 @@ int CAviFile::strm_t::GetFrame(REFERENCE_TIME rt)
float rate_per_scale = strh.dwScale ? 1.0f * strh.dwRate / strh.dwScale : 0;
- if(strh.fccType == FCC('auds'))
- {
+ if(strh.fccType == FCC('auds')) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)strf.GetData();
__int64 size = (__int64)(rate_per_scale * wfe->nBlockAlign * rt / 10000000 + 0.5f);
- for(frame = 0; frame < cs.GetCount(); frame++)
- {
- if(cs[frame].size > size)
- {
+ for(frame = 0; frame < cs.GetCount(); frame++) {
+ if(cs[frame].size > size) {
frame--;
break;
}
}
- }
- else
- {
+ } else {
frame = (int)(rate_per_scale * rt / 10000000 + 0.5f);
}
- if(frame >= cs.GetCount()) frame = cs.GetCount()-1;
+ if(frame >= cs.GetCount()) {
+ frame = cs.GetCount()-1;
+ }
return frame;
}
@@ -584,14 +597,17 @@ int CAviFile::strm_t::GetFrame(REFERENCE_TIME rt)
int CAviFile::strm_t::GetKeyFrame(REFERENCE_TIME rt)
{
int i = GetFrame(rt);
- for(; i > 0; i--) {if(cs[i].fKeyFrame) break;}
+ for(; i > 0; i--) {
+ if(cs[i].fKeyFrame) {
+ break;
+ }
+ }
return(i);
}
DWORD CAviFile::strm_t::GetChunkSize(DWORD size)
{
- if(strh.fccType == FCC('auds'))
- {
+ if(strh.fccType == FCC('auds')) {
WORD nBlockAlign = ((WAVEFORMATEX*)strf.GetData())->nBlockAlign;
size = nBlockAlign ? (size + (nBlockAlign-1)) / nBlockAlign * nBlockAlign : 0; // round up for nando's vbr hack
}
diff --git a/src/filters/parser/AviSplitter/AviFile.h b/src/filters/parser/AviSplitter/AviFile.h
index dfc851426..ed35fd958 100644
--- a/src/filters/parser/AviSplitter/AviFile.h
+++ b/src/filters/parser/AviSplitter/AviFile.h
@@ -14,23 +14,27 @@ public:
//using CBaseSplitterFile::Read;
template<typename T>
- HRESULT Read(T& var, int offset = 0)
- {
+ HRESULT Read(T& var, int offset = 0) {
memset(&var, 0, sizeof(var));
HRESULT hr = ByteRead((BYTE*)&var + offset, sizeof(var) - offset);
return hr;
}
AVIMAINHEADER m_avih;
- struct ODMLExtendedAVIHeader {DWORD dwTotalFrames;} m_dmlh;
-// VideoPropHeader m_vprp;
- struct strm_t
- {
+ struct ODMLExtendedAVIHeader {
+ DWORD dwTotalFrames;
+ } m_dmlh;
+ // VideoPropHeader m_vprp;
+ struct strm_t {
AVISTREAMHEADER strh;
CAtlArray<BYTE> strf;
CStringA strn;
CAutoPtr<AVISUPERINDEX> indx;
- struct chunk {UINT64 fKeyFrame:1, fChunkHdr:1, size:62; UINT64 filepos; DWORD orgsize;};
+ struct chunk {
+ UINT64 fKeyFrame:1, fChunkHdr:1, size:62;
+ UINT64 filepos;
+ DWORD orgsize;
+ };
CAtlArray<chunk> cs;
UINT64 totalsize;
REFERENCE_TIME GetRefTime(DWORD frame, UINT64 size);
@@ -41,7 +45,10 @@ public:
bool IsRawSubtitleStream();
// tmp
- struct chunk2 {DWORD t; DWORD n;};
+ struct chunk2 {
+ DWORD t;
+ DWORD n;
+ };
CAtlArray<chunk2> cs2;
};
CAutoPtrArray<strm_t> m_strms;
@@ -50,7 +57,7 @@ public:
CAtlList<UINT64> m_movis;
bool m_isamv;
-
+
REFERENCE_TIME GetTotalTime();
HRESULT BuildIndex();
void EmptyIndex();
diff --git a/src/filters/parser/AviSplitter/AviReportWnd.cpp b/src/filters/parser/AviSplitter/AviReportWnd.cpp
index f9489f566..18b2dc44f 100644
--- a/src/filters/parser/AviSplitter/AviReportWnd.cpp
+++ b/src/filters/parser/AviSplitter/AviReportWnd.cpp
@@ -15,10 +15,11 @@ bool CAviReportWnd::DoModal(CAviFile* pAF, bool fHideChecked, bool fShowWarningT
m_nChunks = 0;
m_rtDur = 0;
- for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) {
int cnt = pAF->m_strms[i]->cs2.GetCount();
- if(cnt <= 0) continue;
+ if(cnt <= 0) {
+ continue;
+ }
CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1];
m_nChunks = max(m_nChunks, c2.n);
m_rtDur = max(m_rtDur, (REFERENCE_TIME)c2.t<<13);
@@ -29,9 +30,9 @@ bool CAviReportWnd::DoModal(CAviFile* pAF, bool fHideChecked, bool fShowWarningT
r.DeflateRect(r.Width()/4, r.Height()/4);
LPCTSTR wndclass = AfxRegisterWndClass(
- CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS,
- AfxGetApp()->LoadStandardCursor(IDC_ARROW),
- (HBRUSH)(COLOR_BTNFACE + 1), 0);
+ CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS,
+ AfxGetApp()->LoadStandardCursor(IDC_ARROW),
+ (HBRUSH)(COLOR_BTNFACE + 1), 0);
CreateEx(0, wndclass, TITLE, WS_POPUPWINDOW|WS_CAPTION|WS_CLIPCHILDREN, r, NULL, 0);
@@ -76,14 +77,11 @@ bool CAviReportWnd::DoModal(CAviFile* pAF, bool fHideChecked, bool fShowWarningT
//
- if(!fShowWarningText)
- {
+ if(!fShowWarningText) {
m_message.ShowWindow(SW_HIDE);
m_checkbox.ShowWindow(SW_HIDE);
r = cr;
- }
- else
- {
+ } else {
r.SetRect(cr.left, r.bottom + 10, cr.right, cr.bottom);
}
@@ -124,8 +122,7 @@ void CAviReportWnd::OnMouseMove(UINT nFlags, CPoint p)
r.bottom -= GRAPHFOOTER;
r2.top = r.bottom;
- if(r.PtInRect(p))
- {
+ if(r.PtInRect(p)) {
SetCapture();
int x = p.x - r.left;
@@ -146,20 +143,18 @@ void CAviReportWnd::OnMouseMove(UINT nFlags, CPoint p)
CString str;
str.Format(_T("%s (%d - %d:%02d:%02d.%03d)"), TITLE, chunk, h, m, s, ms);
SetWindowText(str);
- }
- else if(r2.PtInRect(p))
- {
+ } else if(r2.PtInRect(p)) {
SetCapture();
int dist = m_graph.GetChunkDist(p.x - r2.left);
CString str;
str.Format(_T("%s (chunk distance: %d"), TITLE, dist);
- if(dist >= 1000) str += _T(" - over the limit!");
+ if(dist >= 1000) {
+ str += _T(" - over the limit!");
+ }
str += ")";
SetWindowText(str);
- }
- else if(GetCapture() == this)
- {
+ } else if(GetCapture() == this) {
SetWindowText(TITLE);
ReleaseCapture();
@@ -176,8 +171,9 @@ CAviPlotterWnd::CAviPlotterWnd()
bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
{
- if(!CreateEx(WS_EX_CLIENTEDGE, _T("STATIC"), _T(""), WS_CHILD|WS_VISIBLE, r, pParentWnd, 0))
+ if(!CreateEx(WS_EX_CLIENTEDGE, _T("STATIC"), _T(""), WS_CHILD|WS_VISIBLE, r, pParentWnd, 0)) {
return(false);
+ }
GetClientRect(r);
int w = r.Width();
@@ -189,14 +185,26 @@ bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
ReleaseDC(pDC);
CBitmap* pOldBitmap = m_dc.SelectObject(&m_bm);
-
+
m_dc.FillSolidRect(r, 0);
{
CPen pen(PS_DOT, 1, 0x008000);
CPen* pOldPen = m_dc.SelectObject(&pen);
- for(int y = 0, dy = max(h/10,1); y < h; y += dy) {if(y == 0) continue; m_dc.MoveTo(0, y); m_dc.LineTo(w, y);}
- for(int x = 0, dx = max(w/10,1); x < w; x += dx) {if(x == 0) continue; m_dc.MoveTo(x, 0); m_dc.LineTo(x, w);}
+ for(int y = 0, dy = max(h/10,1); y < h; y += dy) {
+ if(y == 0) {
+ continue;
+ }
+ m_dc.MoveTo(0, y);
+ m_dc.LineTo(w, y);
+ }
+ for(int x = 0, dx = max(w/10,1); x < w; x += dx) {
+ if(x == 0) {
+ continue;
+ }
+ m_dc.MoveTo(x, 0);
+ m_dc.LineTo(x, w);
+ }
m_dc.SelectObject(pOldPen);
}
@@ -208,7 +216,7 @@ bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
m_dc.LineTo(19, 10);
m_dc.LineTo(11, 10);
m_dc.LineTo(15, 2);
- m_dc.MoveTo(w-30-10, h-15);
+ m_dc.MoveTo(w-30-10, h-15);
m_dc.LineTo(w-2-10, h-15);
m_dc.LineTo(w-10-10, h-19);
m_dc.LineTo(w-10-10, h-11);
@@ -224,8 +232,7 @@ bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
COLORREF clr[] = {0x0000ff,0xff0000,0x40ffff,0xff40ff,0xffff40,0xffffff};
- for(int i = 0, y = 40, dy = m_dc.GetTextExtent(_T("Stream N")).cy + 1; i < (int)pAF->m_avih.dwStreams; i++, y += dy)
- {
+ for(int i = 0, y = 40, dy = m_dc.GetTextExtent(_T("Stream N")).cy + 1; i < (int)pAF->m_avih.dwStreams; i++, y += dy) {
m_dc.SetTextColor(clr[i%pAF->m_avih.dwStreams]);
m_dc.SetBkMode(TRANSPARENT);
CString str;
@@ -235,26 +242,28 @@ bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
DWORD nmax = 0, tmax = 0;
- for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) {
int cnt = pAF->m_strms[i]->cs2.GetCount();
- if(cnt <= 0) continue;
+ if(cnt <= 0) {
+ continue;
+ }
CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1];
nmax = max(nmax, c2.n);
tmax = max(tmax, c2.t);
}
- if(nmax > 0 && tmax > 0)
- {
+ if(nmax > 0 && tmax > 0) {
CAtlArray<CPen> pen;
pen.SetCount(pAF->m_avih.dwStreams);
- for(int i = 0; i < pen.GetCount(); i++)
+ for(int i = 0; i < pen.GetCount(); i++) {
pen[i].CreatePen(PS_SOLID, 2, clr[i]);
+ }
CAtlArray<CPoint> pp;
pp.SetCount(pAF->m_avih.dwStreams);
- for(int i = 0; i < pen.GetCount(); i++)
+ for(int i = 0; i < pen.GetCount(); i++) {
pp[i].SetPoint(-1, -1);
+ }
m_chunkdist.SetCount(w);
memset(m_chunkdist.GetData(), 0, sizeof(int)*w);
@@ -264,39 +273,45 @@ bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
CAviFile::strm_t::chunk2 cs2last = {(DWORD)-1, 0};
- while(1)
- {
+ while(1) {
CAviFile::strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX};
int n = -1;
- for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++)
- {
+ for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++) {
int curchunk = curchunks[i];
- if(curchunk >= pAF->m_strms[i]->cs2.GetCount()) continue;
+ if(curchunk >= pAF->m_strms[i]->cs2.GetCount()) {
+ continue;
+ }
CAviFile::strm_t::chunk2& cs2 = pAF->m_strms[i]->cs2[curchunk];
- if(cs2.t < cs2min.t) {cs2min = cs2; n = i;}
+ if(cs2.t < cs2min.t) {
+ cs2min = cs2;
+ n = i;
+ }
+ }
+ if(n == -1) {
+ break;
}
- if(n == -1) break;
CPoint p;
p.x = (int)(1.0 * w * cs2min.t / tmax);
p.y = (int)(h - 1.0 * h * cs2min.n / nmax);
- if(pp[n] != p)
- {
+ if(pp[n] != p) {
CPen* pOldPen = m_dc.SelectObject(&pen[n]);
- if(pp[n] == CPoint(-1, -1)) m_dc.MoveTo(p);
- else {m_dc.MoveTo(pp[n]); m_dc.LineTo(p);}
+ if(pp[n] == CPoint(-1, -1)) {
+ m_dc.MoveTo(p);
+ } else {
+ m_dc.MoveTo(pp[n]);
+ m_dc.LineTo(p);
+ }
m_dc.SelectObject(pOldPen);
pp[n] = p;
}
int dist = abs((int)cs2min.n - (int)cs2last.n);
- if(cs2last.t >= 0 /*&& dist >= 1000*/)
- {
- if(p.x >= 0 && p.x < w)
- {
+ if(cs2last.t >= 0 /*&& dist >= 1000*/) {
+ if(p.x >= 0 && p.x < w) {
m_chunkdist[p.x] = max(m_chunkdist[p.x], dist);
}
}
@@ -308,8 +323,7 @@ bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
CPen red(PS_SOLID, 1, 0x0000ff);
CPen green(PS_SOLID, 1, 0x00ff00);
- for(int x = 0; x < w; x++)
- {
+ for(int x = 0; x < w; x++) {
CPen* pOldPen = m_dc.SelectObject(m_chunkdist[x] >= 1000 ? &red : &green);
m_dc.MoveTo(x, h);
m_dc.LineTo(x, h + GRAPHFOOTER);
diff --git a/src/filters/parser/AviSplitter/AviReportWnd.h b/src/filters/parser/AviSplitter/AviReportWnd.h
index cd5c3b331..c68e6f618 100644
--- a/src/filters/parser/AviSplitter/AviReportWnd.h
+++ b/src/filters/parser/AviSplitter/AviReportWnd.h
@@ -16,7 +16,9 @@ public:
CAviPlotterWnd();
bool Create(CAviFile* pAF, CRect r, CWnd* pParentWnd);
- int GetChunkDist(int x) {return x >= 0 && x < m_chunkdist.GetCount() ? m_chunkdist[x] : 0;}
+ int GetChunkDist(int x) {
+ return x >= 0 && x < m_chunkdist.GetCount() ? m_chunkdist[x] : 0;
+ }
DECLARE_MESSAGE_MAP()
afx_msg void OnPaint();
diff --git a/src/filters/parser/AviSplitter/AviSplitter.cpp b/src/filters/parser/AviSplitter/AviSplitter.cpp
index 3f1e5a0c7..805c624a7 100644
--- a/src/filters/parser/AviSplitter/AviSplitter.cpp
+++ b/src/filters/parser/AviSplitter/AviSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,26 +27,22 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_Avi},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CAviSplitterFilter), L"MPC - Avi Splitter", MERIT_NORMAL+1, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CAviSourceFilter), L"MPC - Avi Source", MERIT_NORMAL+1, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CAviSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CAviSourceFilter>, NULL, &sudFilter[1]},
};
@@ -61,9 +57,9 @@ STDAPI DllRegisterServer()
chkbytes.AddTail(_T("0,4,,52494646,8,4,,414D5620")); // 'RIFF' ... 'AMV '
RegisterSourceFilter(
- CLSID_AsyncReader,
- MEDIASUBTYPE_Avi,
- chkbytes,
+ CLSID_AsyncReader,
+ MEDIASUBTYPE_Avi,
+ chkbytes,
_T(".avi"), _T(".divx"), _T(".vp6"), _T(".amv"), NULL);
return AMovieDllRegisterServer2(TRUE);
@@ -71,7 +67,7 @@ STDAPI DllRegisterServer()
STDAPI DllUnregisterServer()
{
-// UnRegisterSourceFilter(MEDIASUBTYPE_Avi);
+ // UnRegisterSourceFilter(MEDIASUBTYPE_Avi);
return AMovieDllRegisterServer2(FALSE);
}
@@ -83,21 +79,20 @@ class CAviSplitterApp : public CWinApp
public:
CAviSplitterApp() {}
- BOOL InitInstance()
- {
- if(!__super::InitInstance()) return FALSE;
+ BOOL InitInstance() {
+ if(!__super::InitInstance()) {
+ return FALSE;
+ }
DllEntryPoint(m_hInstance, DLL_PROCESS_ATTACH, 0);
return TRUE;
}
- BOOL ExitInstance()
- {
+ BOOL ExitInstance() {
DllEntryPoint(m_hInstance, DLL_PROCESS_DETACH, 0);
return __super::ExitInstance();
}
- void SetDefaultRegistryKey()
- {
+ void SetDefaultRegistryKey() {
SetRegistryKey(_T("Gabest"));
}
@@ -127,7 +122,7 @@ STDMETHODIMP CAviSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void**
*ppv = NULL;
- return
+ return
__super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -141,29 +136,34 @@ HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_tFrame.Free();
m_pFile.Attach(DNew CAviFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
bool fShiftDown = !!(::GetKeyState(VK_SHIFT)&0x8000);
bool fShowWarningText = !m_pFile->IsInterleaved(fShiftDown);
- if(SUCCEEDED(hr) && (fShowWarningText || fShiftDown))
- {
+ if(SUCCEEDED(hr) && (fShowWarningText || fShiftDown)) {
#ifdef REGISTER_FILTER
AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
bool fHideWarning = !!AfxGetApp()->GetProfileInt(_T("Settings"), _T("HideAviSplitterWarning"), 0);
- if(!fHideWarning && !dynamic_cast<CAviSourceFilter*>(this) || fShiftDown)
- {
+ if(!fHideWarning && !dynamic_cast<CAviSourceFilter*>(this) || fShiftDown) {
CAviReportWnd wnd;
fHideWarning = wnd.DoModal(m_pFile, fHideWarning, fShowWarningText);
AfxGetApp()->WriteProfileInt(_T("Settings"), _T("HideAviSplitterWarning"), fHideWarning);
}
- if(fShowWarningText) hr = E_FAIL;
+ if(fShowWarningText) {
+ hr = E_FAIL;
+ }
}
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->GetTotalTime();
@@ -171,22 +171,23 @@ HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
bool fHasIndex = false;
for(DWORD i = 0; !fHasIndex && i < m_pFile->m_strms.GetCount(); i++)
- if(m_pFile->m_strms[i]->cs.GetCount() > 0)
+ if(m_pFile->m_strms[i]->cs.GetCount() > 0) {
fHasIndex = true;
+ }
- for(DWORD i = 0; i < m_pFile->m_strms.GetCount(); i++)
- {
+ for(DWORD i = 0; i < m_pFile->m_strms.GetCount(); i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
- if(fHasIndex && s->cs.GetCount() == 0) continue;
+ if(fHasIndex && s->cs.GetCount() == 0) {
+ continue;
+ }
CMediaType mt;
CAtlArray<CMediaType> mts;
-
+
CStringW name, label;
- if(s->strh.fccType == FCC('vids'))
- {
+ if(s->strh.fccType == FCC('vids')) {
label = L"Video";
ASSERT(s->strf.GetCount() >= sizeof(BITMAPINFOHEADER));
@@ -199,10 +200,13 @@ HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + s->strf.GetCount() - sizeof(BITMAPINFOHEADER));
memset(mt.Format(), 0, mt.FormatLength());
memcpy(&pvih->bmiHeader, s->strf.GetData(), s->strf.GetCount());
- if(s->strh.dwRate > 0) pvih->AvgTimePerFrame = 10000000i64 * s->strh.dwScale / s->strh.dwRate;
- switch(pbmi->biCompression)
- {
- case BI_RGB: case BI_BITFIELDS: mt.subtype =
+ if(s->strh.dwRate > 0) {
+ pvih->AvgTimePerFrame = 10000000i64 * s->strh.dwScale / s->strh.dwRate;
+ }
+ switch(pbmi->biCompression) {
+ case BI_RGB:
+ case BI_BITFIELDS:
+ mt.subtype =
pbmi->biBitCount == 1 ? MEDIASUBTYPE_RGB1 :
pbmi->biBitCount == 4 ? MEDIASUBTYPE_RGB4 :
pbmi->biBitCount == 8 ? MEDIASUBTYPE_RGB8 :
@@ -210,77 +214,78 @@ HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
pbmi->biBitCount == 24 ? MEDIASUBTYPE_RGB24 :
pbmi->biBitCount == 32 ? MEDIASUBTYPE_ARGB32 :
MEDIASUBTYPE_NULL;
- break;
-// case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break;
-// case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break;
+ break;
+ // case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break;
+ // case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break;
}
- if(s->cs.GetCount() && pvih->AvgTimePerFrame > 0)
- {
+ if(s->cs.GetCount() && pvih->AvgTimePerFrame > 0) {
__int64 size = 0;
- for(int i = 0; i < s->cs.GetCount(); i++)
+ for(int i = 0; i < s->cs.GetCount(); i++) {
size += s->cs[i].orgsize;
+ }
pvih->dwBitRate = size*8 / s->cs.GetCount() * 10000000i64 / pvih->AvgTimePerFrame;
}
- mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
- ? s->strh.dwSuggestedBufferSize*3/2
- : (pvih->bmiHeader.biWidth*pvih->bmiHeader.biHeight*4));
+ mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
+ ? s->strh.dwSuggestedBufferSize*3/2
+ : (pvih->bmiHeader.biWidth*pvih->bmiHeader.biHeight*4));
mts.Add(mt);
- }
- else if(s->strh.fccType == FCC('auds') || s->strh.fccType == FCC('amva'))
- {
+ } else if(s->strh.fccType == FCC('auds') || s->strh.fccType == FCC('amva')) {
label = L"Audio";
ASSERT(s->strf.GetCount() >= sizeof(WAVEFORMATEX)
- || s->strf.GetCount() == sizeof(PCMWAVEFORMAT));
+ || s->strf.GetCount() == sizeof(PCMWAVEFORMAT));
- WAVEFORMATEX* pwfe = (WAVEFORMATEX*)s->strf.GetData();
+ WAVEFORMATEX* pwfe = (WAVEFORMATEX*)s->strf.GetData();
- if(pwfe->nBlockAlign == 0) continue;
+ if(pwfe->nBlockAlign == 0) {
+ continue;
+ }
mt.majortype = MEDIATYPE_Audio;
- if (m_pFile->m_isamv)
+ if (m_pFile->m_isamv) {
mt.subtype = FOURCCMap(MAKEFOURCC('A','M','V','A'));
- else
+ } else {
mt.subtype = FOURCCMap(pwfe->wFormatTag);
+ }
mt.formattype = FORMAT_WaveFormatEx;
mt.SetFormat(s->strf.GetData(), max(s->strf.GetCount(), sizeof(WAVEFORMATEX)));
pwfe = (WAVEFORMATEX*)mt.Format();
- if(s->strf.GetCount() == sizeof(PCMWAVEFORMAT)) pwfe->cbSize = 0;
- if(pwfe->wFormatTag == WAVE_FORMAT_PCM) pwfe->nBlockAlign = pwfe->nChannels*pwfe->wBitsPerSample>>3;
- if(pwfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) mt.subtype = FOURCCMap(WAVE_FORMAT_PCM); // audio renderer doesn't accept fffe in the subtype
- mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
- ? s->strh.dwSuggestedBufferSize*3/2
- : (pwfe->nChannels*pwfe->nSamplesPerSec*32>>3));
+ if(s->strf.GetCount() == sizeof(PCMWAVEFORMAT)) {
+ pwfe->cbSize = 0;
+ }
+ if(pwfe->wFormatTag == WAVE_FORMAT_PCM) {
+ pwfe->nBlockAlign = pwfe->nChannels*pwfe->wBitsPerSample>>3;
+ }
+ if(pwfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
+ mt.subtype = FOURCCMap(WAVE_FORMAT_PCM); // audio renderer doesn't accept fffe in the subtype
+ }
+ mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
+ ? s->strh.dwSuggestedBufferSize*3/2
+ : (pwfe->nChannels*pwfe->nSamplesPerSec*32>>3));
mts.Add(mt);
- }
- else if(s->strh.fccType == FCC('mids'))
- {
+ } else if(s->strh.fccType == FCC('mids')) {
label = L"Midi";
mt.majortype = MEDIATYPE_Midi;
mt.subtype = MEDIASUBTYPE_NULL;
mt.formattype = FORMAT_None;
- mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
- ? s->strh.dwSuggestedBufferSize*3/2
- : (1024*1024));
+ mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
+ ? s->strh.dwSuggestedBufferSize*3/2
+ : (1024*1024));
mts.Add(mt);
- }
- else if(s->strh.fccType == FCC('txts'))
- {
+ } else if(s->strh.fccType == FCC('txts')) {
label = L"Text";
mt.majortype = MEDIATYPE_Text;
mt.subtype = MEDIASUBTYPE_NULL;
mt.formattype = FORMAT_None;
- mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
- ? s->strh.dwSuggestedBufferSize*3/2
- : (1024*1024));
+ mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
+ ? s->strh.dwSuggestedBufferSize*3/2
+ : (1024*1024));
mts.Add(mt);
- }
- else if(s->strh.fccType == FCC('iavs'))
- {
+ } else if(s->strh.fccType == FCC('iavs')) {
label = L"Interleaved";
ASSERT(s->strh.fccHandler == FCC('dvsd'));
@@ -289,25 +294,25 @@ HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mt.subtype = FOURCCMap(s->strh.fccHandler);
mt.formattype = FORMAT_DvInfo;
mt.SetFormat(s->strf.GetData(), max(s->strf.GetCount(), sizeof(DVINFO)));
- mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
- ? s->strh.dwSuggestedBufferSize*3/2
- : (1024*1024));
+ mt.SetSampleSize(s->strh.dwSuggestedBufferSize > 0
+ ? s->strh.dwSuggestedBufferSize*3/2
+ : (1024*1024));
mts.Add(mt);
}
- if(mts.IsEmpty())
- {
+ if(mts.IsEmpty()) {
TRACE(_T("CAviSourceFilter: Unsupported stream (%d)\n"), i);
continue;
}
//Put filename at front sometime(eg. ~temp.avi) will cause filter graph
//stop check this pin. Not sure the reason exactly. but it happens.
- //If you know why, please emailto: tomasen@gmail.com
- if(s->strn.IsEmpty())
+ //If you know why, please emailto: tomasen@gmail.com
+ if(s->strn.IsEmpty()) {
name.Format(L"%s %d", label , i);
- else
+ } else {
name.Format(L"%s %d %s", label , i , CStringW(s->strn) );
+ }
HRESULT hr;
@@ -316,18 +321,24 @@ HRESULT CAviSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
}
POSITION pos = m_pFile->m_info.GetStartPosition();
- while(pos)
- {
+ while(pos) {
DWORD fcc;
CStringA value;
m_pFile->m_info.GetNextAssoc(pos, fcc, value);
- switch(fcc)
- {
- case FCC('INAM'): SetProperty(L"TITL", CStringW(value)); break;
- case FCC('IART'): SetProperty(L"AUTH", CStringW(value)); break;
- case FCC('ICOP'): SetProperty(L"CPYR", CStringW(value)); break;
- case FCC('ISBJ'): SetProperty(L"DESC", CStringW(value)); break;
+ switch(fcc) {
+ case FCC('INAM'):
+ SetProperty(L"TITL", CStringW(value));
+ break;
+ case FCC('IART'):
+ SetProperty(L"AUTH", CStringW(value));
+ break;
+ case FCC('ICOP'):
+ SetProperty(L"CPYR", CStringW(value));
+ break;
+ case FCC('ISBJ'):
+ SetProperty(L"DESC", CStringW(value));
+ break;
}
}
@@ -340,20 +351,21 @@ bool CAviSplitterFilter::DemuxInit()
{
SetThreadName((DWORD)-1, "CAviSplitterFilter");
- if(!m_pFile) return(false);
+ if(!m_pFile) {
+ return(false);
+ }
// reindex if needed
bool fReIndex = false;
- for(int i = 0; i < (int)m_pFile->m_avih.dwStreams && !fReIndex; i++)
- {
- if(m_pFile->m_strms[i]->cs.GetCount() == 0 && GetOutputPin(i))
+ for(int i = 0; i < (int)m_pFile->m_avih.dwStreams && !fReIndex; i++) {
+ if(m_pFile->m_strms[i]->cs.GetCount() == 0 && GetOutputPin(i)) {
fReIndex = true;
+ }
}
- if(fReIndex)
- {
+ if(fReIndex) {
m_pFile->EmptyIndex();
m_fAbort = false;
@@ -365,9 +377,11 @@ bool CAviSplitterFilter::DemuxInit()
pSize.Allocate(m_pFile->m_avih.dwStreams);
memset((UINT64*)pSize, 0, sizeof(UINT64)*m_pFile->m_avih.dwStreams);
m_pFile->Seek(0);
- ReIndex(m_pFile->GetLength(), pSize);
+ ReIndex(m_pFile->GetLength(), pSize);
- if(m_fAbort) m_pFile->EmptyIndex();
+ if(m_fAbort) {
+ m_pFile->EmptyIndex();
+ }
m_fAbort = false;
m_nOpenProgress = 100;
@@ -380,40 +394,38 @@ HRESULT CAviSplitterFilter::ReIndex(__int64 end, UINT64* pSize)
{
HRESULT hr = S_OK;
- while(S_OK == hr && m_pFile->GetPos() < end && SUCCEEDED(hr) && !m_fAbort)
- {
+ while(S_OK == hr && m_pFile->GetPos() < end && SUCCEEDED(hr) && !m_fAbort) {
__int64 pos = m_pFile->GetPos();
DWORD id = 0, size;
- if(S_OK != m_pFile->Read(id) || id == 0)
+ if(S_OK != m_pFile->Read(id) || id == 0) {
return E_FAIL;
+ }
- if(id == FCC('RIFF') || id == FCC('LIST'))
- {
- if(S_OK != m_pFile->Read(size) || S_OK != m_pFile->Read(id))
+ if(id == FCC('RIFF') || id == FCC('LIST')) {
+ if(S_OK != m_pFile->Read(size) || S_OK != m_pFile->Read(id)) {
return E_FAIL;
+ }
size += (size&1) + 8;
- if(id == FCC('AVI ') || id == FCC('AVIX') || id == FCC('movi') || id == FCC('rec '))
+ if(id == FCC('AVI ') || id == FCC('AVIX') || id == FCC('movi') || id == FCC('rec ')) {
hr = ReIndex(pos + size, pSize);
- }
- else
- {
- if(S_OK != m_pFile->Read(size))
+ }
+ } else {
+ if(S_OK != m_pFile->Read(size)) {
return E_FAIL;
+ }
DWORD TrackNumber = TRACKNUM(id);
- if(TrackNumber < m_pFile->m_strms.GetCount())
- {
+ if(TrackNumber < m_pFile->m_strms.GetCount()) {
CAviFile::strm_t* s = m_pFile->m_strms[TrackNumber];
WORD type = TRACKTYPE(id);
if(type == 'db' || type == 'dc' || /*type == 'pc' ||*/ type == 'wb'
- || type == 'iv' || type == '__' || type == 'xx')
- {
+ || type == 'iv' || type == '__' || type == 'xx') {
CAviFile::strm_t::chunk c;
c.filepos = pos;
c.size = pSize[TrackNumber];
@@ -437,10 +449,12 @@ HRESULT CAviSplitterFilter::ReIndex(__int64 end, UINT64* pSize)
m_nOpenProgress = m_pFile->GetPos()*100/m_pFile->GetLength();
DWORD cmd;
- if(CheckRequest(&cmd))
- {
- if(cmd == CMD_EXIT) m_fAbort = true;
- else Reply(S_OK);
+ if(CheckRequest(&cmd)) {
+ if(cmd == CMD_EXIT) {
+ m_fAbort = true;
+ } else {
+ Reply(S_OK);
+ }
}
}
@@ -454,30 +468,26 @@ void CAviSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
DbgLog((LOG_TRACE, 0, _T("Seek: %I64d"), rt/10000));
- if(rt > 0)
- {
+ if(rt > 0) {
UINT64 minfp = _I64_MAX;
- for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++)
- {
+ for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++) {
CAviFile::strm_t* s = m_pFile->m_strms[j];
int f = s->GetKeyFrame(rt);
UINT64 fp = f >= 0 ? s->cs[f].filepos : m_pFile->GetLength();
- if(!s->IsRawSubtitleStream())
+ if(!s->IsRawSubtitleStream()) {
minfp = min(minfp, fp);
+ }
}
- for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++)
- {
+ for(int j = 0; j < (int)m_pFile->m_strms.GetCount(); j++) {
CAviFile::strm_t* s = m_pFile->m_strms[j];
- for(int i = 0; i < s->cs.GetCount(); i++)
- {
+ for(int i = 0; i < s->cs.GetCount(); i++) {
CAviFile::strm_t::chunk& c = s->cs[i];
- if(c.filepos >= minfp)
- {
+ if(c.filepos >= minfp) {
m_tFrame[j] = i;
break;
}
@@ -498,66 +508,62 @@ bool CAviSplitterFilter::DemuxLoop()
fDiscontinuity.SetCount(nTracks);
memset(fDiscontinuity.GetData(), 0, nTracks*sizeof(bool));
- while(SUCCEEDED(hr) && !CheckRequest(NULL))
- {
+ while(SUCCEEDED(hr) && !CheckRequest(NULL)) {
int minTrack = nTracks;
UINT64 minFilePos = _I64_MAX;
- for(int i = 0; i < nTracks; i++)
- {
+ for(int i = 0; i < nTracks; i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
DWORD f = m_tFrame[i];
- if(f >= (DWORD)s->cs.GetCount()) continue;
+ if(f >= (DWORD)s->cs.GetCount()) {
+ continue;
+ }
bool fUrgent = s->IsRawSubtitleStream();
- if(fUrgent || s->cs[f].filepos < minFilePos)
- {
+ if(fUrgent || s->cs[f].filepos < minFilePos) {
minTrack = i;
minFilePos = s->cs[f].filepos;
}
- if(fUrgent) break;
+ if(fUrgent) {
+ break;
+ }
}
- if(minTrack == nTracks)
+ if(minTrack == nTracks) {
break;
+ }
DWORD& f = m_tFrame[minTrack];
- do
- {
+ do {
CAviFile::strm_t* s = m_pFile->m_strms[minTrack];
m_pFile->Seek(s->cs[f].filepos);
DWORD size = 0;
- if(s->cs[f].fChunkHdr)
- {
+ if(s->cs[f].fChunkHdr) {
DWORD id = 0;
if(S_OK != m_pFile->Read(id) || id == 0 || minTrack != TRACKNUM(id)
- || S_OK != m_pFile->Read(size))
- {
+ || S_OK != m_pFile->Read(size)) {
fDiscontinuity[minTrack] = true;
break;
}
UINT64 expectedsize = (UINT64)-1;
expectedsize = f < (DWORD)s->cs.GetCount()-1
- ? s->cs[f+1].size - s->cs[f].size
- : s->totalsize - s->cs[f].size;
+ ? s->cs[f+1].size - s->cs[f].size
+ : s->totalsize - s->cs[f].size;
- if(expectedsize != s->GetChunkSize(size))
- {
+ if(expectedsize != s->GetChunkSize(size)) {
fDiscontinuity[minTrack] = true;
// ASSERT(0);
break;
}
- }
- else
- {
+ } else {
size = s->cs[f].orgsize;
}
@@ -568,22 +574,22 @@ bool CAviSplitterFilter::DemuxLoop()
p->bDiscontinuity = fDiscontinuity[minTrack];
p->rtStart = s->GetRefTime(f, s->cs[f].size);
p->rtStop = s->GetRefTime(f+1, f+1 < (DWORD)s->cs.GetCount() ? s->cs[f+1].size : s->totalsize);
-
+
p->SetCount(size);
- if(S_OK != (hr = m_pFile->ByteRead(p->GetData(), p->GetCount())))
- return(true); // break;
-/*
- DbgLog((LOG_TRACE, 0, _T("%d (%d): %I64d - %I64d, %I64d - %I64d (size = %d)"),
- minTrack, (int)p->bSyncPoint,
- (p->rtStart)/10000, (p->rtStop)/10000,
- (p->rtStart-m_rtStart)/10000, (p->rtStop-m_rtStart)/10000,
- size));
-*/
+ if(S_OK != (hr = m_pFile->ByteRead(p->GetData(), p->GetCount()))) {
+ return(true); // break;
+ }
+ /*
+ DbgLog((LOG_TRACE, 0, _T("%d (%d): %I64d - %I64d, %I64d - %I64d (size = %d)"),
+ minTrack, (int)p->bSyncPoint,
+ (p->rtStart)/10000, (p->rtStop)/10000,
+ (p->rtStart-m_rtStart)/10000, (p->rtStop-m_rtStart)/10000,
+ size));
+ */
hr = DeliverPacket(p);
fDiscontinuity[minTrack] = false;
- }
- while(0);
+ } while(0);
f++;
}
@@ -598,13 +604,10 @@ STDMETHODIMP CAviSplitterFilter::GetDuration(LONGLONG* pDuration)
CheckPointer(pDuration, E_POINTER);
CheckPointer(m_pFile, VFW_E_NOT_CONNECTED);
- if(m_timeformat == TIME_FORMAT_FRAME)
- {
- for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++)
- {
+ if(m_timeformat == TIME_FORMAT_FRAME) {
+ for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
- if(s->strh.fccType == FCC('vids'))
- {
+ if(s->strh.fccType == FCC('vids')) {
*pDuration = s->cs.GetCount();
return S_OK;
}
@@ -622,7 +625,9 @@ STDMETHODIMP CAviSplitterFilter::IsFormatSupported(const GUID* pFormat)
{
CheckPointer(pFormat, E_POINTER);
HRESULT hr = __super::IsFormatSupported(pFormat);
- if(S_OK == hr) return hr;
+ if(S_OK == hr) {
+ return hr;
+ }
return *pFormat == TIME_FORMAT_FRAME ? S_OK : S_FALSE;
}
@@ -642,7 +647,9 @@ STDMETHODIMP CAviSplitterFilter::IsUsingTimeFormat(const GUID* pFormat)
STDMETHODIMP CAviSplitterFilter::SetTimeFormat(const GUID* pFormat)
{
CheckPointer(pFormat, E_POINTER);
- if(S_OK != IsFormatSupported(pFormat)) return E_FAIL;
+ if(S_OK != IsFormatSupported(pFormat)) {
+ return E_FAIL;
+ }
m_timeformat = *pFormat;
return S_OK;
}
@@ -650,10 +657,16 @@ STDMETHODIMP CAviSplitterFilter::SetTimeFormat(const GUID* pFormat)
STDMETHODIMP CAviSplitterFilter::GetStopPosition(LONGLONG* pStop)
{
CheckPointer(pStop, E_POINTER);
- if(FAILED(__super::GetStopPosition(pStop))) return E_FAIL;
- if(m_timeformat == TIME_FORMAT_MEDIA_TIME) return S_OK;
+ if(FAILED(__super::GetStopPosition(pStop))) {
+ return E_FAIL;
+ }
+ if(m_timeformat == TIME_FORMAT_MEDIA_TIME) {
+ return S_OK;
+ }
LONGLONG rt = *pStop;
- if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, rt, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL;
+ if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, rt, &TIME_FORMAT_MEDIA_TIME))) {
+ return E_FAIL;
+ }
return S_OK;
}
@@ -663,101 +676,119 @@ STDMETHODIMP CAviSplitterFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID
const GUID& SourceFormat = pSourceFormat ? *pSourceFormat : m_timeformat;
const GUID& TargetFormat = pTargetFormat ? *pTargetFormat : m_timeformat;
-
- if(TargetFormat == SourceFormat)
- {
- *pTarget = Source;
+
+ if(TargetFormat == SourceFormat) {
+ *pTarget = Source;
return S_OK;
- }
- else if(TargetFormat == TIME_FORMAT_FRAME && SourceFormat == TIME_FORMAT_MEDIA_TIME)
- {
- for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++)
- {
+ } else if(TargetFormat == TIME_FORMAT_FRAME && SourceFormat == TIME_FORMAT_MEDIA_TIME) {
+ for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
- if(s->strh.fccType == FCC('vids'))
- {
+ if(s->strh.fccType == FCC('vids')) {
*pTarget = s->GetFrame(Source);
return S_OK;
}
}
- }
- else if(TargetFormat == TIME_FORMAT_MEDIA_TIME && SourceFormat == TIME_FORMAT_FRAME)
- {
- for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++)
- {
+ } else if(TargetFormat == TIME_FORMAT_MEDIA_TIME && SourceFormat == TIME_FORMAT_FRAME) {
+ for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
- if(s->strh.fccType == FCC('vids'))
- {
- if(Source < 0 || Source >= s->cs.GetCount()) return E_FAIL;
+ if(s->strh.fccType == FCC('vids')) {
+ if(Source < 0 || Source >= s->cs.GetCount()) {
+ return E_FAIL;
+ }
CAviFile::strm_t::chunk& c = s->cs[(int)Source];
*pTarget = s->GetRefTime((DWORD)Source, c.size);
return S_OK;
}
}
}
-
+
return E_FAIL;
}
STDMETHODIMP CAviSplitterFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
{
HRESULT hr;
- if(FAILED(hr = __super::GetPositions(pCurrent, pStop)) || m_timeformat != TIME_FORMAT_FRAME)
+ if(FAILED(hr = __super::GetPositions(pCurrent, pStop)) || m_timeformat != TIME_FORMAT_FRAME) {
return hr;
+ }
if(pCurrent)
- if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_FRAME, *pCurrent, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL;
+ if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_FRAME, *pCurrent, &TIME_FORMAT_MEDIA_TIME))) {
+ return E_FAIL;
+ }
if(pStop)
- if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, *pStop, &TIME_FORMAT_MEDIA_TIME))) return E_FAIL;
+ if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_FRAME, *pStop, &TIME_FORMAT_MEDIA_TIME))) {
+ return E_FAIL;
+ }
return S_OK;
}
HRESULT CAviSplitterFilter::SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
{
- if(m_timeformat != TIME_FORMAT_FRAME)
+ if(m_timeformat != TIME_FORMAT_FRAME) {
return __super::SetPositionsInternal(id, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
+ }
if(!pCurrent && !pStop
- || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning
- && (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning)
+ || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning
+ && (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning) {
return S_OK;
+ }
- REFERENCE_TIME
- rtCurrent = m_rtCurrent,
- rtStop = m_rtStop;
+ REFERENCE_TIME
+ rtCurrent = m_rtCurrent,
+ rtStop = m_rtStop;
if((dwCurrentFlags&AM_SEEKING_PositioningBitsMask)
- && FAILED(ConvertTimeFormat(&rtCurrent, &TIME_FORMAT_FRAME, rtCurrent, &TIME_FORMAT_MEDIA_TIME)))
+ && FAILED(ConvertTimeFormat(&rtCurrent, &TIME_FORMAT_FRAME, rtCurrent, &TIME_FORMAT_MEDIA_TIME))) {
return E_FAIL;
+ }
if((dwStopFlags&AM_SEEKING_PositioningBitsMask)
- && FAILED(ConvertTimeFormat(&rtStop, &TIME_FORMAT_FRAME, rtStop, &TIME_FORMAT_MEDIA_TIME)))
+ && FAILED(ConvertTimeFormat(&rtStop, &TIME_FORMAT_FRAME, rtStop, &TIME_FORMAT_MEDIA_TIME))) {
return E_FAIL;
+ }
if(pCurrent)
- switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask)
- {
- case AM_SEEKING_NoPositioning: break;
- case AM_SEEKING_AbsolutePositioning: rtCurrent = *pCurrent; break;
- case AM_SEEKING_RelativePositioning: rtCurrent = rtCurrent + *pCurrent; break;
- case AM_SEEKING_IncrementalPositioning: rtCurrent = rtCurrent + *pCurrent; break;
- }
+ switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask) {
+ case AM_SEEKING_NoPositioning:
+ break;
+ case AM_SEEKING_AbsolutePositioning:
+ rtCurrent = *pCurrent;
+ break;
+ case AM_SEEKING_RelativePositioning:
+ rtCurrent = rtCurrent + *pCurrent;
+ break;
+ case AM_SEEKING_IncrementalPositioning:
+ rtCurrent = rtCurrent + *pCurrent;
+ break;
+ }
if(pStop)
- switch(dwStopFlags&AM_SEEKING_PositioningBitsMask)
- {
- case AM_SEEKING_NoPositioning: break;
- case AM_SEEKING_AbsolutePositioning: rtStop = *pStop; break;
- case AM_SEEKING_RelativePositioning: rtStop += *pStop; break;
- case AM_SEEKING_IncrementalPositioning: rtStop = rtCurrent + *pStop; break;
- }
+ switch(dwStopFlags&AM_SEEKING_PositioningBitsMask) {
+ case AM_SEEKING_NoPositioning:
+ break;
+ case AM_SEEKING_AbsolutePositioning:
+ rtStop = *pStop;
+ break;
+ case AM_SEEKING_RelativePositioning:
+ rtStop += *pStop;
+ break;
+ case AM_SEEKING_IncrementalPositioning:
+ rtStop = rtCurrent + *pStop;
+ break;
+ }
if((dwCurrentFlags&AM_SEEKING_PositioningBitsMask)
- && pCurrent)
- if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_MEDIA_TIME, rtCurrent, &TIME_FORMAT_FRAME))) return E_FAIL;
+ && pCurrent)
+ if(FAILED(ConvertTimeFormat(pCurrent, &TIME_FORMAT_MEDIA_TIME, rtCurrent, &TIME_FORMAT_FRAME))) {
+ return E_FAIL;
+ }
if((dwStopFlags&AM_SEEKING_PositioningBitsMask)
- && pStop)
- if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_MEDIA_TIME, rtStop, &TIME_FORMAT_FRAME))) return E_FAIL;
+ && pStop)
+ if(FAILED(ConvertTimeFormat(pStop, &TIME_FORMAT_MEDIA_TIME, rtStop, &TIME_FORMAT_FRAME))) {
+ return E_FAIL;
+ }
return __super::SetPositionsInternal(id, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
}
@@ -766,25 +797,30 @@ HRESULT CAviSplitterFilter::SetPositionsInternal(void* id, LONGLONG* pCurrent, D
STDMETHODIMP CAviSplitterFilter::GetKeyFrameCount(UINT& nKFs)
{
- if(!m_pFile) return E_UNEXPECTED;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
HRESULT hr = S_OK;
nKFs = 0;
- for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++)
- {
+ for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
- if(s->strh.fccType != FCC('vids')) continue;
+ if(s->strh.fccType != FCC('vids')) {
+ continue;
+ }
- for(int j = 0; j < s->cs.GetCount(); j++)
- {
+ for(int j = 0; j < s->cs.GetCount(); j++) {
CAviFile::strm_t::chunk& c = s->cs[j];
- if(c.fKeyFrame) nKFs++;
+ if(c.fKeyFrame) {
+ nKFs++;
+ }
}
- if(nKFs == s->cs.GetCount())
+ if(nKFs == s->cs.GetCount()) {
hr = S_FALSE;
+ }
break;
}
@@ -797,22 +833,27 @@ STDMETHODIMP CAviSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIM
CheckPointer(pFormat, E_POINTER);
CheckPointer(pKFs, E_POINTER);
- if(!m_pFile) return E_UNEXPECTED;
- if(*pFormat != TIME_FORMAT_MEDIA_TIME && *pFormat != TIME_FORMAT_FRAME) return E_INVALIDARG;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
+ if(*pFormat != TIME_FORMAT_MEDIA_TIME && *pFormat != TIME_FORMAT_FRAME) {
+ return E_INVALIDARG;
+ }
UINT nKFsTmp = 0;
- for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++)
- {
+ for(int i = 0; i < (int)m_pFile->m_strms.GetCount(); i++) {
CAviFile::strm_t* s = m_pFile->m_strms[i];
- if(s->strh.fccType != FCC('vids')) continue;
+ if(s->strh.fccType != FCC('vids')) {
+ continue;
+ }
bool fConvertToRefTime = !!(*pFormat == TIME_FORMAT_MEDIA_TIME);
- for(int j = 0; j < s->cs.GetCount() && nKFsTmp < nKFs; j++)
- {
- if(s->cs[j].fKeyFrame)
+ for(int j = 0; j < s->cs.GetCount() && nKFsTmp < nKFs; j++) {
+ if(s->cs[j].fKeyFrame) {
pKFs[nKFsTmp++] = fConvertToRefTime ? s->GetRefTime(j, s->cs[j].size) : j;
+ }
}
break;
@@ -847,16 +888,15 @@ HRESULT CAviSplitterOutputPin::CheckConnect(IPin* pPin)
{
int iPosition = 0;
CMediaType mt;
- while(S_OK == GetMediaType(iPosition++, &mt))
- {
- if(mt.majortype == MEDIATYPE_Video
- && (mt.subtype == FOURCCMap(FCC('IV32'))
- || mt.subtype == FOURCCMap(FCC('IV31'))
- || mt.subtype == FOURCCMap(FCC('IF09'))))
- {
+ while(S_OK == GetMediaType(iPosition++, &mt)) {
+ if(mt.majortype == MEDIATYPE_Video
+ && (mt.subtype == FOURCCMap(FCC('IV32'))
+ || mt.subtype == FOURCCMap(FCC('IV31'))
+ || mt.subtype == FOURCCMap(FCC('IF09')))) {
CLSID clsid = GetCLSID(GetFilterFromPin(pPin));
- if(clsid == CLSID_VideoMixingRenderer || clsid == CLSID_OverlayMixer)
+ if(clsid == CLSID_VideoMixingRenderer || clsid == CLSID_OverlayMixer) {
return E_FAIL;
+ }
}
mt.InitMediaType();
diff --git a/src/filters/parser/AviSplitter/AviSplitter.h b/src/filters/parser/AviSplitter/AviSplitter.h
index e022cc0c9..c414c5175 100644
--- a/src/filters/parser/AviSplitter/AviSplitter.h
+++ b/src/filters/parser/AviSplitter/AviSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -36,7 +36,7 @@ public:
};
class __declspec(uuid("9736D831-9D6C-4E72-B6E7-560EF9181001"))
-CAviSplitterFilter : public CBaseSplitterFilter
+ CAviSplitterFilter : public CBaseSplitterFilter
{
CAutoVectorPtr<DWORD> m_tFrame;
@@ -54,7 +54,7 @@ public:
CAviSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr);
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IMediaSeeking
@@ -79,7 +79,7 @@ public:
};
class __declspec(uuid("CEA8DEFF-0AF7-4DB9-9A38-FB3C3AEFC0DE"))
-CAviSourceFilter : public CAviSplitterFilter
+ CAviSourceFilter : public CAviSplitterFilter
{
public:
CAviSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/AviSplitter/stdafx.cpp b/src/filters/parser/AviSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/AviSplitter/stdafx.cpp
+++ b/src/filters/parser/AviSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/AviSplitter/stdafx.h b/src/filters/parser/AviSplitter/stdafx.h
index 7e2652f5d..37bcea3a7 100644
--- a/src/filters/parser/AviSplitter/stdafx.h
+++ b/src/filters/parser/AviSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/BaseSplitter/AsyncReader.cpp b/src/filters/parser/BaseSplitter/AsyncReader.cpp
index deb21fd1d..cfe36e69a 100644
--- a/src/filters/parser/BaseSplitter/AsyncReader.cpp
+++ b/src/filters/parser/BaseSplitter/AsyncReader.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -30,30 +30,34 @@
// CAsyncFileReader
//
-CAsyncFileReader::CAsyncFileReader(CString fn, HRESULT& hr)
+CAsyncFileReader::CAsyncFileReader(CString fn, HRESULT& hr)
: CUnknown(NAME("CAsyncFileReader"), NULL, &hr)
, m_len((ULONGLONG)-1)
, m_hBreakEvent(NULL)
, m_lOsError(0)
{
hr = Open(fn, modeRead|shareDenyNone|typeBinary|osSequentialScan) ? S_OK : E_FAIL;
- if(SUCCEEDED(hr)) m_len = GetLength();
+ if(SUCCEEDED(hr)) {
+ m_len = GetLength();
+ }
}
-CAsyncFileReader::CAsyncFileReader(CAtlList<CHdmvClipInfo::PlaylistItem>& Items, HRESULT& hr)
+CAsyncFileReader::CAsyncFileReader(CAtlList<CHdmvClipInfo::PlaylistItem>& Items, HRESULT& hr)
: CUnknown(NAME("CAsyncFileReader"), NULL, &hr)
, m_len((ULONGLONG)-1)
, m_hBreakEvent(NULL)
, m_lOsError(0)
{
hr = OpenFiles(Items, modeRead|shareDenyNone|typeBinary|osSequentialScan) ? S_OK : E_FAIL;
- if(SUCCEEDED(hr)) m_len = GetLength();
+ if(SUCCEEDED(hr)) {
+ m_len = GetLength();
+ }
}
STDMETHODIMP CAsyncFileReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IAsyncReader)
QI(ISyncReader)
QI(IFileHandle)
@@ -64,36 +68,46 @@ STDMETHODIMP CAsyncFileReader::NonDelegatingQueryInterface(REFIID riid, void** p
STDMETHODIMP CAsyncFileReader::SyncRead(LONGLONG llPosition, LONG lLength, BYTE* pBuffer)
{
- do
- {
- try
- {
- if((ULONGLONG)llPosition+lLength > GetLength()) return E_FAIL; // strange, but the Seek below can return llPosition even if the file is not that big (?)
- if((ULONGLONG)llPosition != Seek(llPosition, begin)) return E_FAIL;
- if((UINT)lLength < Read(pBuffer, lLength)) return E_FAIL;
+ do {
+ try {
+ if((ULONGLONG)llPosition+lLength > GetLength()) {
+ return E_FAIL; // strange, but the Seek below can return llPosition even if the file is not that big (?)
+ }
+ if((ULONGLONG)llPosition != Seek(llPosition, begin)) {
+ return E_FAIL;
+ }
+ if((UINT)lLength < Read(pBuffer, lLength)) {
+ return E_FAIL;
+ }
#if 0 // def DEBUG
static __int64 s_total = 0, s_laststoppos = 0;
s_total += lLength;
- if(s_laststoppos > llPosition)
+ if(s_laststoppos > llPosition) {
TRACE(_T("[%I64d - %I64d] %d (%I64d)\n"), llPosition, llPosition + lLength, lLength, s_total);
+ }
s_laststoppos = llPosition + lLength;
#endif
return S_OK;
- }
- catch(CFileException* e)
- {
+ } catch(CFileException* e) {
m_lOsError = e->m_lOsError;
e->Delete();
Sleep(1);
CString fn = m_strFileName;
- try {Close();} catch(CFileException* e) {e->Delete();}
- try {Open(fn, modeRead|shareDenyNone|typeBinary|osSequentialScan);} catch(CFileException* e) {e->Delete();}
+ try {
+ Close();
+ } catch(CFileException* e) {
+ e->Delete();
+ }
+ try {
+ Open(fn, modeRead|shareDenyNone|typeBinary|osSequentialScan);
+ } catch(CFileException* e) {
+ e->Delete();
+ }
m_strFileName = fn;
}
- }
- while(m_hBreakEvent && WaitForSingleObject(m_hBreakEvent, 0) == WAIT_TIMEOUT);
+ } while(m_hBreakEvent && WaitForSingleObject(m_hBreakEvent, 0) == WAIT_TIMEOUT);
return E_FAIL;
}
@@ -101,8 +115,12 @@ STDMETHODIMP CAsyncFileReader::SyncRead(LONGLONG llPosition, LONG lLength, BYTE*
STDMETHODIMP CAsyncFileReader::Length(LONGLONG* pTotal, LONGLONG* pAvailable)
{
LONGLONG len = m_len >= 0 ? m_len : GetLength();
- if(pTotal) *pTotal = len;
- if(pAvailable) *pAvailable = len;
+ if(pTotal) {
+ *pTotal = len;
+ }
+ if(pAvailable) {
+ *pAvailable = len;
+ }
return S_OK;
}
@@ -122,15 +140,18 @@ STDMETHODIMP_(LPCTSTR) CAsyncFileReader::GetFileName()
// CAsyncUrlReader
//
-CAsyncUrlReader::CAsyncUrlReader(CString url, HRESULT& hr)
+CAsyncUrlReader::CAsyncUrlReader(CString url, HRESULT& hr)
: CAsyncFileReader(url, hr)
{
- if(SUCCEEDED(hr)) return;
+ if(SUCCEEDED(hr)) {
+ return;
+ }
m_url = url;
- if(CAMThread::Create())
+ if(CAMThread::Create()) {
CallWorker(CMD_INIT);
+ }
hr = Open(m_fn, modeRead|shareDenyRead|typeBinary|osSequentialScan) ? S_OK : E_FAIL;
m_len = (ULONGLONG)-1; // force GetLength() return actual length always
@@ -138,11 +159,11 @@ CAsyncUrlReader::CAsyncUrlReader(CString url, HRESULT& hr)
CAsyncUrlReader::~CAsyncUrlReader()
{
- if(ThreadExists())
+ if(ThreadExists()) {
CallWorker(CMD_EXIT);
+ }
- if(!m_fn.IsEmpty())
- {
+ if(!m_fn.IsEmpty()) {
CMultiFiles::Close();
DeleteFile(m_fn);
}
@@ -152,7 +173,9 @@ CAsyncUrlReader::~CAsyncUrlReader()
STDMETHODIMP CAsyncUrlReader::Length(LONGLONG* pTotal, LONGLONG* pAvailable)
{
- if(pTotal) *pTotal = 0;
+ if(pTotal) {
+ *pTotal = 0;
+ }
return __super::Length(NULL, pAvailable);
}
@@ -163,41 +186,41 @@ DWORD CAsyncUrlReader::ThreadProc()
AfxSocketInit(NULL);
DWORD cmd = GetRequest();
- if(cmd != CMD_INIT) {Reply((DWORD)E_FAIL); return (DWORD)-1;}
+ if(cmd != CMD_INIT) {
+ Reply((DWORD)E_FAIL);
+ return (DWORD)-1;
+ }
- try
- {
+ try {
CInternetSession is;
CAutoPtr<CStdioFile> fin(is.OpenURL(m_url, 1, INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_NO_CACHE_WRITE));
TCHAR path[_MAX_PATH], fn[_MAX_PATH];
CFile fout;
if(GetTempPath(MAX_PATH, path) && GetTempFileName(path, _T("mpc_http"), 0, fn)
- && fout.Open(fn, modeCreate|modeWrite|shareDenyWrite|typeBinary))
- {
+ && fout.Open(fn, modeCreate|modeWrite|shareDenyWrite|typeBinary)) {
m_fn = fn;
char buff[1024];
int len = fin->Read(buff, sizeof(buff));
- if(len > 0) fout.Write(buff, len);
+ if(len > 0) {
+ fout.Write(buff, len);
+ }
Reply(S_OK);
- while(!CheckRequest(&cmd))
- {
+ while(!CheckRequest(&cmd)) {
int len = fin->Read(buff, sizeof(buff));
- if(len > 0) fout.Write(buff, len);
+ if(len > 0) {
+ fout.Write(buff, len);
+ }
}
- }
- else
- {
+ } else {
Reply((DWORD)E_FAIL);
}
fin->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying
- }
- catch(CInternetException* ie)
- {
+ } catch(CInternetException* ie) {
ie->Delete();
Reply((DWORD)E_FAIL);
}
diff --git a/src/filters/parser/BaseSplitter/AsyncReader.h b/src/filters/parser/BaseSplitter/AsyncReader.h
index 64c4e9113..f649ac102 100644
--- a/src/filters/parser/BaseSplitter/AsyncReader.h
+++ b/src/filters/parser/BaseSplitter/AsyncReader.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,8 +24,8 @@
#include "MultiFiles.h"
interface __declspec(uuid("6DDB4EE7-45A0-4459-A508-BD77B32C91B2"))
-ISyncReader : public IUnknown
-{
+ISyncReader :
+public IUnknown {
STDMETHOD_(void, SetBreakEvent) (HANDLE hBreakEvent) = 0;
STDMETHOD_(bool, HasErrors) () = 0;
STDMETHOD_(void, ClearErrors) () = 0;
@@ -33,8 +33,8 @@ ISyncReader : public IUnknown
};
interface __declspec(uuid("7D55F67A-826E-40B9-8A7D-3DF0CBBD272D"))
-IFileHandle : public IUnknown
-{
+IFileHandle :
+public IUnknown {
STDMETHOD_(HANDLE, GetFileHandle)() = 0;
STDMETHOD_(LPCTSTR, GetFileName)() = 0;
};
@@ -55,21 +55,41 @@ public:
// IAsyncReader
- STDMETHODIMP RequestAllocator(IMemAllocator* pPreferred, ALLOCATOR_PROPERTIES* pProps, IMemAllocator** ppActual) {return E_NOTIMPL;}
- STDMETHODIMP Request(IMediaSample* pSample, DWORD_PTR dwUser) {return E_NOTIMPL;}
- STDMETHODIMP WaitForNext(DWORD dwTimeout, IMediaSample** ppSample, DWORD_PTR* pdwUser) {return E_NOTIMPL;}
- STDMETHODIMP SyncReadAligned(IMediaSample* pSample) {return E_NOTIMPL;}
+ STDMETHODIMP RequestAllocator(IMemAllocator* pPreferred, ALLOCATOR_PROPERTIES* pProps, IMemAllocator** ppActual) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP Request(IMediaSample* pSample, DWORD_PTR dwUser) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP WaitForNext(DWORD dwTimeout, IMediaSample** ppSample, DWORD_PTR* pdwUser) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SyncReadAligned(IMediaSample* pSample) {
+ return E_NOTIMPL;
+ }
STDMETHODIMP SyncRead(LONGLONG llPosition, LONG lLength, BYTE* pBuffer);
STDMETHODIMP Length(LONGLONG* pTotal, LONGLONG* pAvailable);
- STDMETHODIMP BeginFlush() {return E_NOTIMPL;}
- STDMETHODIMP EndFlush() {return E_NOTIMPL;}
+ STDMETHODIMP BeginFlush() {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP EndFlush() {
+ return E_NOTIMPL;
+ }
// ISyncReader
- STDMETHODIMP_(void) SetBreakEvent(HANDLE hBreakEvent) {m_hBreakEvent = hBreakEvent;}
- STDMETHODIMP_(bool) HasErrors() {return m_lOsError != 0;}
- STDMETHODIMP_(void) ClearErrors() {m_lOsError = 0;}
- STDMETHODIMP_(void) SetPTSOffset (REFERENCE_TIME* rtPTSOffset) { m_pCurrentPTSOffset = rtPTSOffset;};
+ STDMETHODIMP_(void) SetBreakEvent(HANDLE hBreakEvent) {
+ m_hBreakEvent = hBreakEvent;
+ }
+ STDMETHODIMP_(bool) HasErrors() {
+ return m_lOsError != 0;
+ }
+ STDMETHODIMP_(void) ClearErrors() {
+ m_lOsError = 0;
+ }
+ STDMETHODIMP_(void) SetPTSOffset (REFERENCE_TIME* rtPTSOffset) {
+ m_pCurrentPTSOffset = rtPTSOffset;
+ };
// IFileHandle
@@ -84,7 +104,7 @@ class CAsyncUrlReader : public CAsyncFileReader, protected CAMThread
protected:
enum {CMD_EXIT, CMD_INIT};
- DWORD ThreadProc();
+ DWORD ThreadProc();
public:
CAsyncUrlReader(CString url, HRESULT& hr);
diff --git a/src/filters/parser/BaseSplitter/BaseSplitter.cpp b/src/filters/parser/BaseSplitter/BaseSplitter.cpp
index 173442b29..c23a2cd8a 100644
--- a/src/filters/parser/BaseSplitter/BaseSplitter.cpp
+++ b/src/filters/parser/BaseSplitter/BaseSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -45,15 +45,13 @@ void CPacketQueue::Add(CAutoPtr<Packet> p)
{
CAutoLock cAutoLock(this);
- if(p)
- {
+ if(p) {
m_size += p->GetDataSize();
if(p->bAppendable && !p->bDiscontinuity && !p->pmt
- && p->rtStart == Packet::INVALID_TIME
- && !IsEmpty() && GetTail()->rtStart != Packet::INVALID_TIME)
- {
- Packet* tail = GetTail();
+ && p->rtStart == Packet::INVALID_TIME
+ && !IsEmpty() && GetTail()->rtStart != Packet::INVALID_TIME) {
+ Packet* tail = GetTail();
int oldsize = tail->GetCount();
int newsize = tail->GetCount() + p->GetCount();
tail->SetCount(newsize, max(1024, newsize)); // doubles the reserved buffer size
@@ -73,7 +71,9 @@ CAutoPtr<Packet> CPacketQueue::Remove()
CAutoLock cAutoLock(this);
ASSERT(__super::GetCount() > 0);
CAutoPtr<Packet> p = RemoveHead();
- if(p) m_size -= p->GetDataSize();
+ if(p) {
+ m_size -= p->GetDataSize();
+ }
return p;
}
@@ -86,13 +86,13 @@ void CPacketQueue::RemoveAll()
int CPacketQueue::GetCount()
{
- CAutoLock cAutoLock(this);
+ CAutoLock cAutoLock(this);
return __super::GetCount();
}
int CPacketQueue::GetSize()
{
- CAutoLock cAutoLock(this);
+ CAutoLock cAutoLock(this);
return m_size;
}
@@ -122,25 +122,26 @@ STDMETHODIMP CBaseSplitterInputPin::NonDelegatingQueryInterface(REFIID riid, voi
{
CheckPointer(ppv, E_POINTER);
- return
+ return
__super::NonDelegatingQueryInterface(riid, ppv);
}
HRESULT CBaseSplitterInputPin::CheckMediaType(const CMediaType* pmt)
{
return S_OK;
-/*
- return pmt->majortype == MEDIATYPE_Stream
- ? S_OK
- : E_INVALIDARG;
-*/
+ /*
+ return pmt->majortype == MEDIATYPE_Stream
+ ? S_OK
+ : E_INVALIDARG;
+ */
}
HRESULT CBaseSplitterInputPin::CheckConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CheckConnect(pPin)))
+ if(FAILED(hr = __super::CheckConnect(pPin))) {
return hr;
+ }
return CComQIPtr<IAsyncReader>(pPin) ? S_OK : E_NOINTERFACE;
}
@@ -149,11 +150,13 @@ HRESULT CBaseSplitterInputPin::BreakConnect()
{
HRESULT hr;
- if(FAILED(hr = __super::BreakConnect()))
+ if(FAILED(hr = __super::BreakConnect())) {
return hr;
+ }
- if(FAILED(hr = (static_cast<CBaseSplitterFilter*>(m_pFilter))->BreakConnect(PINDIR_INPUT, this)))
+ if(FAILED(hr = (static_cast<CBaseSplitterFilter*>(m_pFilter))->BreakConnect(PINDIR_INPUT, this))) {
return hr;
+ }
m_pAsyncReader.Release();
@@ -164,15 +167,17 @@ HRESULT CBaseSplitterInputPin::CompleteConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CompleteConnect(pPin)))
+ if(FAILED(hr = __super::CompleteConnect(pPin))) {
return hr;
+ }
CheckPointer(pPin, E_POINTER);
m_pAsyncReader = pPin;
CheckPointer(m_pAsyncReader, E_NOINTERFACE);
- if(FAILED(hr = (static_cast<CBaseSplitterFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this)))
+ if(FAILED(hr = (static_cast<CBaseSplitterFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this))) {
return hr;
+ }
return S_OK;
}
@@ -222,8 +227,8 @@ STDMETHODIMP CBaseSplitterOutputPin::NonDelegatingQueryInterface(REFIID riid, vo
{
CheckPointer(ppv, E_POINTER);
- return
-// riid == __uuidof(IMediaSeeking) ? m_pFilter->QueryInterface(riid, ppv) :
+ return
+ // riid == __uuidof(IMediaSeeking) ? m_pFilter->QueryInterface(riid, ppv) :
QI(IMediaSeeking)
QI(IPropertyBag)
QI(IPropertyBag2)
@@ -235,7 +240,9 @@ STDMETHODIMP CBaseSplitterOutputPin::NonDelegatingQueryInterface(REFIID riid, vo
HRESULT CBaseSplitterOutputPin::SetName(LPCWSTR pName)
{
CheckPointer(pName, E_POINTER);
- if(m_pName) delete [] m_pName;
+ if(m_pName) {
+ delete [] m_pName;
+ }
m_pName = DNew WCHAR[wcslen(pName)+1];
CheckPointer(m_pName, E_OUTOFMEMORY);
wcscpy(m_pName, pName);
@@ -244,35 +251,38 @@ HRESULT CBaseSplitterOutputPin::SetName(LPCWSTR pName)
HRESULT CBaseSplitterOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
pProperties->cBuffers = m_nBuffers;
pProperties->cbBuffer = max(m_mt.lSampleSize, 1);
- if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_mt.formattype == FORMAT_VorbisFormat)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_mt.formattype == FORMAT_VorbisFormat) {
// oh great, the oggds vorbis decoder assumes there will be two at least, stupid thing...
pProperties->cBuffers = max(pProperties->cBuffers, 2);
}
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CBaseSplitterOutputPin::CheckMediaType(const CMediaType* pmt)
{
- for(int i = 0; i < m_mts.GetCount(); i++)
- {
- if(*pmt == m_mts[i])
+ for(int i = 0; i < m_mts.GetCount(); i++) {
+ if(*pmt == m_mts[i]) {
return S_OK;
+ }
}
return E_INVALIDARG;
@@ -280,10 +290,14 @@ HRESULT CBaseSplitterOutputPin::CheckMediaType(const CMediaType* pmt)
HRESULT CBaseSplitterOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pLock);
+ CAutoLock cAutoLock(m_pLock);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition >= m_mts.GetCount()) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition >= m_mts.GetCount()) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
*pmt = m_mts[iPosition];
@@ -299,20 +313,22 @@ STDMETHODIMP CBaseSplitterOutputPin::Notify(IBaseFilter* pSender, Quality q)
HRESULT CBaseSplitterOutputPin::Active()
{
- CAutoLock cAutoLock(m_pLock);
+ CAutoLock cAutoLock(m_pLock);
- if(m_Connected)
+ if(m_Connected) {
Create();
+ }
return __super::Active();
}
HRESULT CBaseSplitterOutputPin::Inactive()
{
- CAutoLock cAutoLock(m_pLock);
+ CAutoLock cAutoLock(m_pLock);
- if(ThreadExists())
+ if(ThreadExists()) {
CallWorker(CMD_EXIT);
+ }
return __super::Inactive();
}
@@ -325,13 +341,17 @@ HRESULT CBaseSplitterOutputPin::DeliverBeginFlush()
m_hrDeliver = S_FALSE;
m_queue.RemoveAll();
HRESULT hr = IsConnected() ? GetConnected()->BeginFlush() : S_OK;
- if(S_OK != hr) m_eEndFlush.Set();
+ if(S_OK != hr) {
+ m_eEndFlush.Set();
+ }
return(hr);
}
HRESULT CBaseSplitterOutputPin::DeliverEndFlush()
{
- if(!ThreadExists()) return S_FALSE;
+ if(!ThreadExists()) {
+ return S_FALSE;
+ }
HRESULT hr = IsConnected() ? GetConnected()->EndFlush() : S_OK;
m_hrDeliver = S_OK;
m_fFlushing = false;
@@ -343,11 +363,17 @@ HRESULT CBaseSplitterOutputPin::DeliverEndFlush()
HRESULT CBaseSplitterOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
{
m_brs.rtLastDeliverTime = Packet::INVALID_TIME;
- if(m_fFlushing) return S_FALSE;
+ if(m_fFlushing) {
+ return S_FALSE;
+ }
m_rtStart = tStart;
- if(!ThreadExists()) return S_FALSE;
+ if(!ThreadExists()) {
+ return S_FALSE;
+ }
HRESULT hr = __super::DeliverNewSegment(tStart, tStop, dRate);
- if(S_OK != hr) return hr;
+ if(S_OK != hr) {
+ return hr;
+ }
MakeISCRHappy();
return hr;
}
@@ -369,15 +395,19 @@ HRESULT CBaseSplitterOutputPin::QueueEndOfStream()
HRESULT CBaseSplitterOutputPin::QueuePacket(CAutoPtr<Packet> p)
{
- if(!ThreadExists()) return S_FALSE;
+ if(!ThreadExists()) {
+ return S_FALSE;
+ }
- while(S_OK == m_hrDeliver
- && (!(static_cast<CBaseSplitterFilter*>(m_pFilter))->IsAnyPinDrying()
- || m_queue.GetSize() > MAXPACKETSIZE*100))
+ while(S_OK == m_hrDeliver
+ && (!(static_cast<CBaseSplitterFilter*>(m_pFilter))->IsAnyPinDrying()
+ || m_queue.GetSize() > MAXPACKETSIZE*100)) {
Sleep(1);
+ }
- if(S_OK != m_hrDeliver)
+ if(S_OK != m_hrDeliver) {
return m_hrDeliver;
+ }
m_queue.Add(p);
@@ -387,25 +417,24 @@ HRESULT CBaseSplitterOutputPin::QueuePacket(CAutoPtr<Packet> p)
bool CBaseSplitterOutputPin::IsDiscontinuous()
{
return m_mt.majortype == MEDIATYPE_Text
- || m_mt.majortype == MEDIATYPE_ScriptCommand
- || m_mt.majortype == MEDIATYPE_Subtitle
- || m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE
- || m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE
- || m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE;
+ || m_mt.majortype == MEDIATYPE_ScriptCommand
+ || m_mt.majortype == MEDIATYPE_Subtitle
+ || m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE
+ || m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE
+ || m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE;
}
bool CBaseSplitterOutputPin::IsActive()
{
CComPtr<IPin> pPin = this;
- do
- {
+ do {
CComPtr<IPin> pPinTo;
CComQIPtr<IStreamSwitcherInputPin> pSSIP;
- if(S_OK == pPin->ConnectedTo(&pPinTo) && (pSSIP = pPinTo) && !pSSIP->IsActive())
+ if(S_OK == pPin->ConnectedTo(&pPinTo) && (pSSIP = pPinTo) && !pSSIP->IsActive()) {
return(false);
+ }
pPin = GetFirstPin(GetFilterFromPin(pPinTo), PINDIR_OUTPUT);
- }
- while(pPin);
+ } while(pPin);
return(true);
}
@@ -417,13 +446,11 @@ DWORD CBaseSplitterOutputPin::ThreadProc()
m_fFlushing = m_fFlushed = false;
m_eEndFlush.Set();
- while(1)
- {
+ while(1) {
Sleep(1);
DWORD cmd;
- if(CheckRequest(&cmd))
- {
+ if(CheckRequest(&cmd)) {
m_hThread = NULL;
cmd = GetRequest();
Reply(S_OK);
@@ -432,39 +459,36 @@ DWORD CBaseSplitterOutputPin::ThreadProc()
}
int cnt = 0;
- do
- {
+ do {
CAutoPtr<Packet> p;
{
CAutoLock cAutoLock(&m_queue);
- if((cnt = m_queue.GetCount()) > 0)
+ if((cnt = m_queue.GetCount()) > 0) {
p = m_queue.Remove();
+ }
}
- if(S_OK == m_hrDeliver && cnt > 0)
- {
+ if(S_OK == m_hrDeliver && cnt > 0) {
ASSERT(!m_fFlushing);
m_fFlushed = false;
// flushing can still start here, to release a blocked deliver call
- HRESULT hr = p
- ? DeliverPacket(p)
- : DeliverEndOfStream();
+ HRESULT hr = p
+ ? DeliverPacket(p)
+ : DeliverEndOfStream();
m_eEndFlush.Wait(); // .. so we have to wait until it is done
- if(hr != S_OK && !m_fFlushed) // and only report the error in m_hrDeliver if we didn't flush the stream
- {
+ if(hr != S_OK && !m_fFlushed) { // and only report the error in m_hrDeliver if we didn't flush the stream
// CAutoLock cAutoLock(&m_csQueueLock);
m_hrDeliver = hr;
break;
}
}
- }
- while(--cnt > 0);
+ } while(--cnt > 0);
}
}
@@ -474,23 +498,19 @@ HRESULT CBaseSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
INT_PTR nBytes = p->GetCount();
- if(nBytes == 0)
- {
+ if(nBytes == 0) {
return S_OK;
}
m_brs.nBytesSinceLastDeliverTime += nBytes;
- if(p->rtStart != Packet::INVALID_TIME)
- {
- if(m_brs.rtLastDeliverTime == Packet::INVALID_TIME)
- {
+ if(p->rtStart != Packet::INVALID_TIME) {
+ if(m_brs.rtLastDeliverTime == Packet::INVALID_TIME) {
m_brs.rtLastDeliverTime = p->rtStart;
m_brs.nBytesSinceLastDeliverTime = 0;
}
- if(m_brs.rtLastDeliverTime + 10000000 < p->rtStart)
- {
+ if(m_brs.rtLastDeliverTime + 10000000 < p->rtStart) {
REFERENCE_TIME rtDiff = p->rtStart - m_brs.rtLastDeliverTime;
double secs, bits;
@@ -508,80 +528,106 @@ HRESULT CBaseSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
m_brs.rtLastDeliverTime = p->rtStart;
m_brs.nBytesSinceLastDeliverTime = 0;
-/*
- TRACE(_T("[%d] c: %d kbps, a: %d kbps\n"),
- p->TrackNumber,
- (m_brs.nCurrentBitRate+500)/1000,
- (m_brs.nAverageBitRate+500)/1000);
-*/
+ /*
+ TRACE(_T("[%d] c: %d kbps, a: %d kbps\n"),
+ p->TrackNumber,
+ (m_brs.nCurrentBitRate+500)/1000,
+ (m_brs.nAverageBitRate+500)/1000);
+ */
}
double dRate = 1.0;
- if(SUCCEEDED((static_cast<CBaseSplitterFilter*>(m_pFilter))->GetRate(&dRate)))
- {
+ if(SUCCEEDED((static_cast<CBaseSplitterFilter*>(m_pFilter))->GetRate(&dRate))) {
p->rtStart = (REFERENCE_TIME)((double)p->rtStart / dRate);
p->rtStop = (REFERENCE_TIME)((double)p->rtStop / dRate);
}
}
- do
- {
+ do {
CComPtr<IMediaSample> pSample;
- if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) break;
+ if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) {
+ break;
+ }
- if(nBytes > pSample->GetSize())
- {
+ if(nBytes > pSample->GetSize()) {
pSample.Release();
ALLOCATOR_PROPERTIES props, actual;
- if(S_OK != (hr = m_pAllocator->GetProperties(&props))) break;
+ if(S_OK != (hr = m_pAllocator->GetProperties(&props))) {
+ break;
+ }
props.cbBuffer = nBytes*3/2;
- if(props.cBuffers > 1)
- {
- if(S_OK != (hr = __super::DeliverBeginFlush())) break;
- if(S_OK != (hr = __super::DeliverEndFlush())) break;
+ if(props.cBuffers > 1) {
+ if(S_OK != (hr = __super::DeliverBeginFlush())) {
+ break;
+ }
+ if(S_OK != (hr = __super::DeliverEndFlush())) {
+ break;
+ }
}
- if(S_OK != (hr = m_pAllocator->Decommit())) break;
- if(S_OK != (hr = m_pAllocator->SetProperties(&props, &actual))) break;
- if(S_OK != (hr = m_pAllocator->Commit())) break;
- if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) break;
+ if(S_OK != (hr = m_pAllocator->Decommit())) {
+ break;
+ }
+ if(S_OK != (hr = m_pAllocator->SetProperties(&props, &actual))) {
+ break;
+ }
+ if(S_OK != (hr = m_pAllocator->Commit())) {
+ break;
+ }
+ if(S_OK != (hr = GetDeliveryBuffer(&pSample, NULL, NULL, 0))) {
+ break;
+ }
}
- if(p->pmt)
- {
+ if(p->pmt) {
pSample->SetMediaType(p->pmt);
p->bDiscontinuity = true;
- CAutoLock cAutoLock(m_pLock);
+ CAutoLock cAutoLock(m_pLock);
m_mts.RemoveAll();
m_mts.Add(*p->pmt);
}
bool fTimeValid = p->rtStart != Packet::INVALID_TIME;
-/*
-//if(p->TrackNumber == 1)
-//if(p->rtStart != Packet::INVALID_TIME)
-TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"),
- p->TrackNumber,
- p->bDiscontinuity, p->bSyncPoint, fTimeValid && p->rtStart < 0,
- nBytes, p->rtStart, p->rtStop);
-*/
+ /*
+ //if(p->TrackNumber == 1)
+ //if(p->rtStart != Packet::INVALID_TIME)
+ TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"),
+ p->TrackNumber,
+ p->bDiscontinuity, p->bSyncPoint, fTimeValid && p->rtStart < 0,
+ nBytes, p->rtStart, p->rtStop);
+ */
ASSERT(!p->bSyncPoint || fTimeValid);
BYTE* pData = NULL;
- if(S_OK != (hr = pSample->GetPointer(&pData)) || !pData) break;
+ if(S_OK != (hr = pSample->GetPointer(&pData)) || !pData) {
+ break;
+ }
memcpy(pData, p->GetData(), nBytes);
- if(S_OK != (hr = pSample->SetActualDataLength(nBytes))) break;
- if(S_OK != (hr = pSample->SetTime(fTimeValid ? &p->rtStart : NULL, fTimeValid ? &p->rtStop : NULL))) break;
- if(S_OK != (hr = pSample->SetMediaTime(NULL, NULL))) break;
- if(S_OK != (hr = pSample->SetDiscontinuity(p->bDiscontinuity))) break;
- if(S_OK != (hr = pSample->SetSyncPoint(p->bSyncPoint))) break;
- if(S_OK != (hr = pSample->SetPreroll(fTimeValid && p->rtStart < 0))) break;
- if(S_OK != (hr = Deliver(pSample))) break;
- }
- while(false);
+ if(S_OK != (hr = pSample->SetActualDataLength(nBytes))) {
+ break;
+ }
+ if(S_OK != (hr = pSample->SetTime(fTimeValid ? &p->rtStart : NULL, fTimeValid ? &p->rtStop : NULL))) {
+ break;
+ }
+ if(S_OK != (hr = pSample->SetMediaTime(NULL, NULL))) {
+ break;
+ }
+ if(S_OK != (hr = pSample->SetDiscontinuity(p->bDiscontinuity))) {
+ break;
+ }
+ if(S_OK != (hr = pSample->SetSyncPoint(p->bSyncPoint))) {
+ break;
+ }
+ if(S_OK != (hr = pSample->SetPreroll(fTimeValid && p->rtStart < 0))) {
+ break;
+ }
+ if(S_OK != (hr = Deliver(pSample))) {
+ break;
+ }
+ } while(false);
return hr;
}
@@ -589,17 +635,16 @@ TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"),
void CBaseSplitterOutputPin::MakeISCRHappy()
{
CComPtr<IPin> pPinTo = this, pTmp;
- while(pPinTo && SUCCEEDED(pPinTo->ConnectedTo(&pTmp)) && (pPinTo = pTmp))
- {
+ while(pPinTo && SUCCEEDED(pPinTo->ConnectedTo(&pTmp)) && (pPinTo = pTmp)) {
pTmp = NULL;
CComPtr<IBaseFilter> pBF = GetFilterFromPin(pPinTo);
- if(GetCLSID(pBF) == GUIDFromCString(_T("{48025243-2D39-11CE-875D-00608CB78066}"))) // ISCR
- {
+ if(GetCLSID(pBF) == GUIDFromCString(_T("{48025243-2D39-11CE-875D-00608CB78066}"))) { // ISCR
CAutoPtr<Packet> p(DNew Packet());
p->TrackNumber = (DWORD)-1;
- p->rtStart = -1; p->rtStop = 0;
+ p->rtStart = -1;
+ p->rtStop = 0;
p->bSyncPoint = FALSE;
p->SetData(" ", 2);
QueuePacket(p);
@@ -705,7 +750,9 @@ CBaseSplitterFilter::CBaseSplitterFilter(LPCTSTR pName, LPUNKNOWN pUnk, HRESULT*
, m_rtLastStop(_I64_MIN)
, m_priority(THREAD_PRIORITY_NORMAL)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pInput.Attach(DNew CBaseSplitterInputPin(NAME("CBaseSplitterInputPin"), this, this, phr));
}
@@ -724,10 +771,11 @@ STDMETHODIMP CBaseSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void*
*ppv = NULL;
- if(m_pInput && riid == __uuidof(IFileSourceFilter))
+ if(m_pInput && riid == __uuidof(IFileSourceFilter)) {
return E_NOINTERFACE;
+ }
- return
+ return
QI(IFileSourceFilter)
QI(IMediaSeeking)
QI(IAMOpenProgress)
@@ -747,7 +795,7 @@ CBaseSplitterOutputPin* CBaseSplitterFilter::GetOutputPin(DWORD TrackNum)
{
CAutoLock cAutoLock(&m_csPinMap);
- CBaseSplitterOutputPin* pPin = NULL;
+ CBaseSplitterOutputPin* pPin = NULL;
m_pPinMap.Lookup(TrackNum, pPin);
return pPin;
}
@@ -757,12 +805,13 @@ DWORD CBaseSplitterFilter::GetOutputTrackNum(CBaseSplitterOutputPin* pPin)
CAutoLock cAutoLock(&m_csPinMap);
POSITION pos = m_pPinMap.GetStartPosition();
- while(pos)
- {
+ while(pos) {
DWORD TrackNum;
CBaseSplitterOutputPin* pPinTmp;
m_pPinMap.GetNextAssoc(pos, TrackNum, pPinTmp);
- if(pPinTmp == pPin) return TrackNum;
+ if(pPinTmp == pPin) {
+ return TrackNum;
+ }
}
return (DWORD)-1;
@@ -773,19 +822,17 @@ HRESULT CBaseSplitterFilter::RenameOutputPin(DWORD TrackNumSrc, DWORD TrackNumDs
CAutoLock cAutoLock(&m_csPinMap);
CBaseSplitterOutputPin* pPin;
- if(m_pPinMap.Lookup(TrackNumSrc, pPin))
- {
- if(CComQIPtr<IPin> pPinTo = pPin->GetConnected())
- {
- if(pmt && S_OK != pPinTo->QueryAccept(pmt))
+ if(m_pPinMap.Lookup(TrackNumSrc, pPin)) {
+ if(CComQIPtr<IPin> pPinTo = pPin->GetConnected()) {
+ if(pmt && S_OK != pPinTo->QueryAccept(pmt)) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
m_pPinMap.RemoveKey(TrackNumSrc);
m_pPinMap[TrackNumDst] = pPin;
- if(pmt)
- {
+ if(pmt) {
CAutoLock cAutoLock(&m_csmtnew);
m_mtnew[TrackNumDst] = *pmt;
}
@@ -800,7 +847,9 @@ HRESULT CBaseSplitterFilter::AddOutputPin(DWORD TrackNum, CAutoPtr<CBaseSplitter
{
CAutoLock cAutoLock(&m_csPinMap);
- if(!pPin) return E_INVALIDARG;
+ if(!pPin) {
+ return E_INVALIDARG;
+ }
m_pPinMap[TrackNum] = pPin;
m_pOutputs.AddTail(pPin);
return S_OK;
@@ -813,12 +862,15 @@ HRESULT CBaseSplitterFilter::DeleteOutputs()
m_pRetiredOutputs.RemoveAll();
CAutoLock cAutoLockF(this);
- if(m_State != State_Stopped) return VFW_E_NOT_STOPPED;
+ if(m_State != State_Stopped) {
+ return VFW_E_NOT_STOPPED;
+ }
- while(m_pOutputs.GetCount())
- {
+ while(m_pOutputs.GetCount()) {
CAutoPtr<CBaseSplitterOutputPin> pPin = m_pOutputs.RemoveHead();
- if(IPin* pPinTo = pPin->GetConnected()) pPinTo->Disconnect();
+ if(IPin* pPinTo = pPin->GetConnected()) {
+ pPinTo->Disconnect();
+ }
pPin->Disconnect();
// we can't just let it be deleted now, something might have AddRefed on it (graphedit...)
m_pRetiredOutputs.AddTail(pPin);
@@ -845,40 +897,45 @@ void CBaseSplitterFilter::DeliverBeginFlush()
{
m_fFlushing = true;
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos) m_pOutputs.GetNext(pos)->DeliverBeginFlush();
+ while(pos) {
+ m_pOutputs.GetNext(pos)->DeliverBeginFlush();
+ }
}
void CBaseSplitterFilter::DeliverEndFlush()
{
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos) m_pOutputs.GetNext(pos)->DeliverEndFlush();
+ while(pos) {
+ m_pOutputs.GetNext(pos)->DeliverEndFlush();
+ }
m_fFlushing = false;
m_eEndFlush.Set();
}
DWORD CBaseSplitterFilter::ThreadProc()
{
- if(m_pSyncReader)
+ if(m_pSyncReader) {
m_pSyncReader->SetBreakEvent(GetRequestHandle());
+ }
- if(!DemuxInit())
- {
- while(1)
- {
+ if(!DemuxInit()) {
+ while(1) {
DWORD cmd = GetRequest();
- if(cmd == CMD_EXIT) CAMThread::m_hThread = NULL;
+ if(cmd == CMD_EXIT) {
+ CAMThread::m_hThread = NULL;
+ }
Reply(S_OK);
- if(cmd == CMD_EXIT) return 0;
+ if(cmd == CMD_EXIT) {
+ return 0;
+ }
}
}
m_eEndFlush.Set();
m_fFlushing = false;
- for(DWORD cmd = (DWORD)-1; ; cmd = GetRequest())
- {
- if(cmd == CMD_EXIT)
- {
+ for(DWORD cmd = (DWORD)-1; ; cmd = GetRequest()) {
+ if(cmd == CMD_EXIT) {
m_hThread = NULL;
Reply(S_OK);
return 0;
@@ -891,30 +948,31 @@ DWORD CBaseSplitterFilter::ThreadProc()
DemuxSeek(m_rtStart);
- if(cmd != (DWORD)-1)
+ if(cmd != (DWORD)-1) {
Reply(S_OK);
+ }
m_eEndFlush.Wait();
m_pActivePins.RemoveAll();
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos && !m_fFlushing)
- {
+ while(pos && !m_fFlushing) {
CBaseSplitterOutputPin* pPin = m_pOutputs.GetNext(pos);
- if(pPin->IsConnected() && pPin->IsActive())
- {
+ if(pPin->IsConnected() && pPin->IsActive()) {
m_pActivePins.AddTail(pPin);
pPin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate);
}
}
- do {m_bDiscontinuitySent.RemoveAll();}
- while(!DemuxLoop());
+ do {
+ m_bDiscontinuitySent.RemoveAll();
+ } while(!DemuxLoop());
pos = m_pActivePins.GetHeadPosition();
- while(pos && !CheckRequest(&cmd))
+ while(pos && !CheckRequest(&cmd)) {
m_pActivePins.GetNext(pos)->QueueEndOfStream();
+ }
}
ASSERT(0); // we should only exit via CMD_EXIT
@@ -928,11 +986,11 @@ HRESULT CBaseSplitterFilter::DeliverPacket(CAutoPtr<Packet> p)
HRESULT hr = S_FALSE;
CBaseSplitterOutputPin* pPin = GetOutputPin(p->TrackNumber);
- if(!pPin || !pPin->IsConnected() || !m_pActivePins.Find(pPin))
+ if(!pPin || !pPin->IsConnected() || !m_pActivePins.Find(pPin)) {
return S_FALSE;
+ }
- if(p->rtStart != Packet::INVALID_TIME)
- {
+ if(p->rtStart != Packet::INVALID_TIME) {
m_rtCurrent = p->rtStart;
p->rtStart -= m_rtStart;
@@ -945,42 +1003,44 @@ HRESULT CBaseSplitterFilter::DeliverPacket(CAutoPtr<Packet> p)
CAutoLock cAutoLock(&m_csmtnew);
CMediaType mt;
- if(m_mtnew.Lookup(p->TrackNumber, mt))
- {
+ if(m_mtnew.Lookup(p->TrackNumber, mt)) {
p->pmt = CreateMediaType(&mt);
m_mtnew.RemoveKey(p->TrackNumber);
}
}
- if(!m_bDiscontinuitySent.Find(p->TrackNumber))
+ if(!m_bDiscontinuitySent.Find(p->TrackNumber)) {
p->bDiscontinuity = TRUE;
+ }
DWORD TrackNumber = p->TrackNumber;
BOOL bDiscontinuity = p->bDiscontinuity;
-/*
-//if(p->TrackNumber == 1)
-//if(p->rtStart != Packet::INVALID_TIME)
-TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"),
- p->TrackNumber,
- p->bDiscontinuity, p->bSyncPoint, p->rtStart != Packet::INVALID_TIME && p->rtStart < 0,
- p->GetCount(), p->rtStart, p->rtStop);
-*/
+ /*
+ //if(p->TrackNumber == 1)
+ //if(p->rtStart != Packet::INVALID_TIME)
+ TRACE(_T("[%d]: d%d s%d p%d, b=%d, %I64d-%I64d \n"),
+ p->TrackNumber,
+ p->bDiscontinuity, p->bSyncPoint, p->rtStart != Packet::INVALID_TIME && p->rtStart < 0,
+ p->GetCount(), p->rtStart, p->rtStop);
+ */
hr = pPin->QueuePacket(p);
- if(S_OK != hr)
- {
- if(POSITION pos = m_pActivePins.Find(pPin))
+ if(S_OK != hr) {
+ if(POSITION pos = m_pActivePins.Find(pPin)) {
m_pActivePins.RemoveAt(pos);
+ }
- if(!m_pActivePins.IsEmpty()) // only die when all pins are down
+ if(!m_pActivePins.IsEmpty()) { // only die when all pins are down
hr = S_OK;
+ }
return hr;
}
- if(bDiscontinuity)
+ if(bDiscontinuity) {
m_bDiscontinuitySent.AddTail(TrackNumber);
+ }
return hr;
}
@@ -990,19 +1050,18 @@ bool CBaseSplitterFilter::IsAnyPinDrying()
int totalcount = 0, totalsize = 0;
POSITION pos = m_pActivePins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBaseSplitterOutputPin* pPin = m_pActivePins.GetNext(pos);
int count = pPin->QueueCount();
int size = pPin->QueueSize();
- if(!pPin->IsDiscontinuous() && (count < MINPACKETS || size < MINPACKETSIZE))
- {
-// if(m_priority != THREAD_PRIORITY_ABOVE_NORMAL && (count < MINPACKETS/3 || size < MINPACKETSIZE/3))
- if(m_priority != THREAD_PRIORITY_BELOW_NORMAL && (count < MINPACKETS/3 || size < MINPACKETSIZE/3))
- {
+ if(!pPin->IsDiscontinuous() && (count < MINPACKETS || size < MINPACKETSIZE)) {
+ // if(m_priority != THREAD_PRIORITY_ABOVE_NORMAL && (count < MINPACKETS/3 || size < MINPACKETSIZE/3))
+ if(m_priority != THREAD_PRIORITY_BELOW_NORMAL && (count < MINPACKETS/3 || size < MINPACKETSIZE/3)) {
// SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_ABOVE_NORMAL);
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos) m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);
+ while(pos) {
+ m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_BELOW_NORMAL);
+ }
m_priority = THREAD_PRIORITY_BELOW_NORMAL;
}
return(true);
@@ -1011,16 +1070,18 @@ bool CBaseSplitterFilter::IsAnyPinDrying()
totalsize += size;
}
- if(m_priority != THREAD_PRIORITY_NORMAL && (totalcount > MAXPACKETS*2/3 || totalsize > MAXPACKETSIZE*2/3))
- {
-// SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_NORMAL);
+ if(m_priority != THREAD_PRIORITY_NORMAL && (totalcount > MAXPACKETS*2/3 || totalsize > MAXPACKETSIZE*2/3)) {
+ // SetThreadPriority(m_hThread, m_priority = THREAD_PRIORITY_NORMAL);
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos) m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_NORMAL);
+ while(pos) {
+ m_pOutputs.GetNext(pos)->SetThreadPriority(THREAD_PRIORITY_NORMAL);
+ }
m_priority = THREAD_PRIORITY_NORMAL;
}
- if(totalcount < MAXPACKETS && totalsize < MAXPACKETSIZE)
+ if(totalcount < MAXPACKETS && totalsize < MAXPACKETSIZE) {
return(true);
+ }
return(false);
}
@@ -1029,15 +1090,10 @@ HRESULT CBaseSplitterFilter::BreakConnect(PIN_DIRECTION dir, CBasePin* pPin)
{
CheckPointer(pPin, E_POINTER);
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
DeleteOutputs();
- }
- else if(dir == PINDIR_OUTPUT)
- {
- }
- else
- {
+ } else if(dir == PINDIR_OUTPUT) {
+ } else {
return E_UNEXPECTED;
}
@@ -1048,28 +1104,24 @@ HRESULT CBaseSplitterFilter::CompleteConnect(PIN_DIRECTION dir, CBasePin* pPin)
{
CheckPointer(pPin, E_POINTER);
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
CBaseSplitterInputPin* pIn = static_cast<CBaseSplitterInputPin*>(pPin);
HRESULT hr;
CComPtr<IAsyncReader> pAsyncReader;
if(FAILED(hr = pIn->GetAsyncReader(&pAsyncReader))
- || FAILED(hr = DeleteOutputs())
- || FAILED(hr = CreateOutputs(pAsyncReader)))
+ || FAILED(hr = DeleteOutputs())
+ || FAILED(hr = CreateOutputs(pAsyncReader))) {
return hr;
+ }
ChapSort();
m_pSyncReader = pAsyncReader;
- }
- else if(dir == PINDIR_OUTPUT)
- {
+ } else if(dir == PINDIR_OUTPUT) {
m_pRetiredOutputs.RemoveAll();
- }
- else
- {
+ } else {
return E_UNEXPECTED;
}
@@ -1083,16 +1135,15 @@ int CBaseSplitterFilter::GetPinCount()
CBasePin* CBaseSplitterFilter::GetPin(int n)
{
- CAutoLock cAutoLock(this);
+ CAutoLock cAutoLock(this);
- if(n >= 0 && n < (int)m_pOutputs.GetCount())
- {
- if(POSITION pos = m_pOutputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pOutputs.GetCount()) {
+ if(POSITION pos = m_pOutputs.FindIndex(n)) {
return m_pOutputs.GetAt(pos);
+ }
}
- if(n == (int)m_pOutputs.GetCount() && m_pInput)
- {
+ if(n == (int)m_pOutputs.GetCount() && m_pInput) {
return m_pInput;
}
@@ -1108,8 +1159,9 @@ STDMETHODIMP CBaseSplitterFilter::Stop()
DeliverEndFlush();
HRESULT hr;
- if(FAILED(hr = __super::Stop()))
+ if(FAILED(hr = __super::Stop())) {
return hr;
+ }
return S_OK;
}
@@ -1121,11 +1173,11 @@ STDMETHODIMP CBaseSplitterFilter::Pause()
FILTER_STATE fs = m_State;
HRESULT hr;
- if(FAILED(hr = __super::Pause()))
+ if(FAILED(hr = __super::Pause())) {
return hr;
+ }
- if(fs == State_Stopped)
- {
+ if(fs == State_Stopped) {
Create();
}
@@ -1137,8 +1189,9 @@ STDMETHODIMP CBaseSplitterFilter::Run(REFERENCE_TIME tStart)
CAutoLock cAutoLock(this);
HRESULT hr;
- if(FAILED(hr = __super::Run(tStart)))
+ if(FAILED(hr = __super::Run(tStart))) {
return hr;
+ }
return S_OK;
}
@@ -1153,14 +1206,14 @@ STDMETHODIMP CBaseSplitterFilter::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYP
HRESULT hr = E_FAIL;
CComPtr<IAsyncReader> pAsyncReader;
CAtlList<CHdmvClipInfo::PlaylistItem> Items;
- if (BuildPlaylist (pszFileName, Items))
+ if (BuildPlaylist (pszFileName, Items)) {
pAsyncReader = (IAsyncReader*)DNew CAsyncFileReader(Items, hr);
- else
+ } else {
pAsyncReader = (IAsyncReader*)DNew CAsyncFileReader(CString(pszFileName), hr);
+ }
if(FAILED(hr)
- || FAILED(hr = DeleteOutputs())
- || FAILED(hr = CreateOutputs(pAsyncReader)))
- {
+ || FAILED(hr = DeleteOutputs())
+ || FAILED(hr = CreateOutputs(pAsyncReader))) {
m_fn = "";
return hr;
}
@@ -1176,8 +1229,9 @@ STDMETHODIMP CBaseSplitterFilter::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TY
{
CheckPointer(ppszFileName, E_POINTER);
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
return S_OK;
}
@@ -1192,87 +1246,150 @@ LPCTSTR CBaseSplitterFilter::GetPartFilename(IAsyncReader* pAsyncReader)
STDMETHODIMP CBaseSplitterFilter::GetCapabilities(DWORD* pCapabilities)
{
- return pCapabilities ? *pCapabilities =
- AM_SEEKING_CanGetStopPos|
- AM_SEEKING_CanGetDuration|
- AM_SEEKING_CanSeekAbsolute|
- AM_SEEKING_CanSeekForwards|
- AM_SEEKING_CanSeekBackwards, S_OK : E_POINTER;
+ return pCapabilities ? *pCapabilities =
+ AM_SEEKING_CanGetStopPos|
+ AM_SEEKING_CanGetDuration|
+ AM_SEEKING_CanSeekAbsolute|
+ AM_SEEKING_CanSeekForwards|
+ AM_SEEKING_CanSeekBackwards, S_OK : E_POINTER;
}
STDMETHODIMP CBaseSplitterFilter::CheckCapabilities(DWORD* pCapabilities)
{
CheckPointer(pCapabilities, E_POINTER);
- if(*pCapabilities == 0) return S_OK;
+ if(*pCapabilities == 0) {
+ return S_OK;
+ }
DWORD caps;
GetCapabilities(&caps);
- if((caps&*pCapabilities) == 0) return E_FAIL;
- if(caps == *pCapabilities) return S_OK;
+ if((caps&*pCapabilities) == 0) {
+ return E_FAIL;
+ }
+ if(caps == *pCapabilities) {
+ return S_OK;
+ }
return S_FALSE;
}
-STDMETHODIMP CBaseSplitterFilter::IsFormatSupported(const GUID* pFormat) {return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;}
-STDMETHODIMP CBaseSplitterFilter::QueryPreferredFormat(GUID* pFormat) {return GetTimeFormat(pFormat);}
-STDMETHODIMP CBaseSplitterFilter::GetTimeFormat(GUID* pFormat) {return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;}
-STDMETHODIMP CBaseSplitterFilter::IsUsingTimeFormat(const GUID* pFormat) {return IsFormatSupported(pFormat);}
-STDMETHODIMP CBaseSplitterFilter::SetTimeFormat(const GUID* pFormat) {return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;}
-STDMETHODIMP CBaseSplitterFilter::GetDuration(LONGLONG* pDuration) {CheckPointer(pDuration, E_POINTER); *pDuration = m_rtDuration; return S_OK;}
-STDMETHODIMP CBaseSplitterFilter::GetStopPosition(LONGLONG* pStop) {return GetDuration(pStop);}
-STDMETHODIMP CBaseSplitterFilter::GetCurrentPosition(LONGLONG* pCurrent) {return E_NOTIMPL;}
-STDMETHODIMP CBaseSplitterFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {return E_NOTIMPL;}
+STDMETHODIMP CBaseSplitterFilter::IsFormatSupported(const GUID* pFormat)
+{
+ return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;
+}
+STDMETHODIMP CBaseSplitterFilter::QueryPreferredFormat(GUID* pFormat)
+{
+ return GetTimeFormat(pFormat);
+}
+STDMETHODIMP CBaseSplitterFilter::GetTimeFormat(GUID* pFormat)
+{
+ return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;
+}
+STDMETHODIMP CBaseSplitterFilter::IsUsingTimeFormat(const GUID* pFormat)
+{
+ return IsFormatSupported(pFormat);
+}
+STDMETHODIMP CBaseSplitterFilter::SetTimeFormat(const GUID* pFormat)
+{
+ return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;
+}
+STDMETHODIMP CBaseSplitterFilter::GetDuration(LONGLONG* pDuration)
+{
+ CheckPointer(pDuration, E_POINTER);
+ *pDuration = m_rtDuration;
+ return S_OK;
+}
+STDMETHODIMP CBaseSplitterFilter::GetStopPosition(LONGLONG* pStop)
+{
+ return GetDuration(pStop);
+}
+STDMETHODIMP CBaseSplitterFilter::GetCurrentPosition(LONGLONG* pCurrent)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CBaseSplitterFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
+{
+ return E_NOTIMPL;
+}
STDMETHODIMP CBaseSplitterFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
{
return SetPositionsInternal(this, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
}
STDMETHODIMP CBaseSplitterFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
{
- if(pCurrent) *pCurrent = m_rtCurrent;
- if(pStop) *pStop = m_rtStop;
+ if(pCurrent) {
+ *pCurrent = m_rtCurrent;
+ }
+ if(pStop) {
+ *pStop = m_rtStop;
+ }
return S_OK;
}
STDMETHODIMP CBaseSplitterFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
{
- if(pEarliest) *pEarliest = 0;
+ if(pEarliest) {
+ *pEarliest = 0;
+ }
return GetDuration(pLatest);
}
-STDMETHODIMP CBaseSplitterFilter::SetRate(double dRate) {return dRate > 0 ? m_dRate = dRate, S_OK : E_INVALIDARG;}
-STDMETHODIMP CBaseSplitterFilter::GetRate(double* pdRate) {return pdRate ? *pdRate = m_dRate, S_OK : E_POINTER;}
-STDMETHODIMP CBaseSplitterFilter::GetPreroll(LONGLONG* pllPreroll) {return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER;}
+STDMETHODIMP CBaseSplitterFilter::SetRate(double dRate)
+{
+ return dRate > 0 ? m_dRate = dRate, S_OK : E_INVALIDARG;
+}
+STDMETHODIMP CBaseSplitterFilter::GetRate(double* pdRate)
+{
+ return pdRate ? *pdRate = m_dRate, S_OK : E_POINTER;
+}
+STDMETHODIMP CBaseSplitterFilter::GetPreroll(LONGLONG* pllPreroll)
+{
+ return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER;
+}
HRESULT CBaseSplitterFilter::SetPositionsInternal(void* id, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
{
CAutoLock cAutoLock(this);
if(!pCurrent && !pStop
- || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning
- && (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning)
+ || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning
+ && (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning) {
return S_OK;
+ }
- REFERENCE_TIME
- rtCurrent = m_rtCurrent,
- rtStop = m_rtStop;
+ REFERENCE_TIME
+ rtCurrent = m_rtCurrent,
+ rtStop = m_rtStop;
if(pCurrent)
- switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask)
- {
- case AM_SEEKING_NoPositioning: break;
- case AM_SEEKING_AbsolutePositioning: rtCurrent = *pCurrent; break;
- case AM_SEEKING_RelativePositioning: rtCurrent = rtCurrent + *pCurrent; break;
- case AM_SEEKING_IncrementalPositioning: rtCurrent = rtCurrent + *pCurrent; break;
- }
+ switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask) {
+ case AM_SEEKING_NoPositioning:
+ break;
+ case AM_SEEKING_AbsolutePositioning:
+ rtCurrent = *pCurrent;
+ break;
+ case AM_SEEKING_RelativePositioning:
+ rtCurrent = rtCurrent + *pCurrent;
+ break;
+ case AM_SEEKING_IncrementalPositioning:
+ rtCurrent = rtCurrent + *pCurrent;
+ break;
+ }
if(pStop)
- switch(dwStopFlags&AM_SEEKING_PositioningBitsMask)
- {
- case AM_SEEKING_NoPositioning: break;
- case AM_SEEKING_AbsolutePositioning: rtStop = *pStop; break;
- case AM_SEEKING_RelativePositioning: rtStop += *pStop; break;
- case AM_SEEKING_IncrementalPositioning: rtStop = rtCurrent + *pStop; break;
- }
+ switch(dwStopFlags&AM_SEEKING_PositioningBitsMask) {
+ case AM_SEEKING_NoPositioning:
+ break;
+ case AM_SEEKING_AbsolutePositioning:
+ rtStop = *pStop;
+ break;
+ case AM_SEEKING_RelativePositioning:
+ rtStop += *pStop;
+ break;
+ case AM_SEEKING_IncrementalPositioning:
+ rtStop = rtCurrent + *pStop;
+ break;
+ }
- if(m_rtCurrent == rtCurrent && m_rtStop == rtStop)
+ if(m_rtCurrent == rtCurrent && m_rtStop == rtStop) {
return S_OK;
+ }
- if(m_rtLastStart == rtCurrent && m_rtLastStop == rtStop && !m_LastSeekers.Find(id))
- {
+ if(m_rtLastStart == rtCurrent && m_rtLastStop == rtStop && !m_LastSeekers.Find(id)) {
m_LastSeekers.AddTail(id);
return S_OK;
}
@@ -1282,19 +1399,18 @@ HRESULT CBaseSplitterFilter::SetPositionsInternal(void* id, LONGLONG* pCurrent,
m_LastSeekers.RemoveAll();
m_LastSeekers.AddTail(id);
-DbgLog((LOG_TRACE, 0, _T("Seek Started %I64d"), rtCurrent));
+ DbgLog((LOG_TRACE, 0, _T("Seek Started %I64d"), rtCurrent));
m_rtNewStart = m_rtCurrent = rtCurrent;
m_rtNewStop = rtStop;
- if(ThreadExists())
- {
+ if(ThreadExists()) {
DeliverBeginFlush();
CallWorker(CMD_SEEK);
DeliverEndFlush();
}
-DbgLog((LOG_TRACE, 0, _T("Seek Ended")));
+ DbgLog((LOG_TRACE, 0, _T("Seek Ended")));
return S_OK;
}
@@ -1351,7 +1467,9 @@ STDMETHODIMP CBaseSplitterFilter::get_ExSeekCapabilities(long* pExCapabilities)
{
CheckPointer(pExCapabilities, E_POINTER);
*pExCapabilities = AM_EXSEEK_CANSEEK;
- if(ChapGetCount()) *pExCapabilities |= AM_EXSEEK_MARKERSEEK;
+ if(ChapGetCount()) {
+ *pExCapabilities |= AM_EXSEEK_MARKERSEEK;
+ }
return S_OK;
}
@@ -1367,7 +1485,9 @@ STDMETHODIMP CBaseSplitterFilter::get_CurrentMarker(long* pCurrentMarker)
CheckPointer(pCurrentMarker, E_POINTER);
REFERENCE_TIME rt = m_rtCurrent;
long i = ChapLookup(&rt);
- if(i < 0) return E_FAIL;
+ if(i < 0) {
+ return E_FAIL;
+ }
*pCurrentMarker = i+1;
return S_OK;
}
@@ -1376,7 +1496,9 @@ STDMETHODIMP CBaseSplitterFilter::GetMarkerTime(long MarkerNum, double* pMarkerT
{
CheckPointer(pMarkerTime, E_POINTER);
REFERENCE_TIME rt;
- if(FAILED(ChapGet((int)MarkerNum-1, &rt))) return E_FAIL;
+ if(FAILED(ChapGet((int)MarkerNum-1, &rt))) {
+ return E_FAIL;
+ }
*pMarkerTime = (double)rt / 10000000;
return S_OK;
}
@@ -1411,8 +1533,7 @@ STDMETHODIMP CBaseSplitterFilter::GetStatus(int i, int& samples, int& size)
{
CAutoLock cAutoLock(m_pLock);
- if(POSITION pos = m_pOutputs.FindIndex(i))
- {
+ if(POSITION pos = m_pOutputs.FindIndex(i)) {
CBaseSplitterOutputPin* pPin = m_pOutputs.GetAt(pos);
samples = pPin->QueueCount();
size = pPin->QueueSize();
@@ -1424,5 +1545,5 @@ STDMETHODIMP CBaseSplitterFilter::GetStatus(int i, int& samples, int& size)
STDMETHODIMP_(DWORD) CBaseSplitterFilter::GetPriority()
{
- return m_priority;
+ return m_priority;
}
diff --git a/src/filters/parser/BaseSplitter/BaseSplitter.h b/src/filters/parser/BaseSplitter/BaseSplitter.h
index 656fafa81..e030187c1 100644
--- a/src/filters/parser/BaseSplitter/BaseSplitter.h
+++ b/src/filters/parser/BaseSplitter/BaseSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -40,13 +40,25 @@ public:
static const REFERENCE_TIME INVALID_TIME = _I64_MIN;
REFERENCE_TIME rtStart, rtStop;
AM_MEDIA_TYPE* pmt;
- Packet() {pmt = NULL; bDiscontinuity = bAppendable = FALSE;}
- virtual ~Packet() {if(pmt) DeleteMediaType(pmt);}
- virtual int GetDataSize() {return GetCount();}
- void SetData(const void* ptr, DWORD len) {SetCount(len); memcpy(GetData(), ptr, len);}
+ Packet() {
+ pmt = NULL;
+ bDiscontinuity = bAppendable = FALSE;
+ }
+ virtual ~Packet() {
+ if(pmt) {
+ DeleteMediaType(pmt);
+ }
+ }
+ virtual int GetDataSize() {
+ return GetCount();
+ }
+ void SetData(const void* ptr, DWORD len) {
+ SetCount(len);
+ memcpy(GetData(), ptr, len);
+ }
};
-class CPacketQueue
+class CPacketQueue
: public CCritSec
, protected CAutoPtrList<Packet>
{
@@ -62,7 +74,7 @@ public:
class CBaseSplitterFilter;
-class CBaseSplitterInputPin
+class CBaseSplitterInputPin
: public CBasePin
{
protected:
@@ -75,19 +87,19 @@ public:
HRESULT GetAsyncReader(IAsyncReader** ppAsyncReader);
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- HRESULT CheckMediaType(const CMediaType* pmt);
+ HRESULT CheckMediaType(const CMediaType* pmt);
- HRESULT CheckConnect(IPin* pPin);
- HRESULT BreakConnect();
+ HRESULT CheckConnect(IPin* pPin);
+ HRESULT BreakConnect();
HRESULT CompleteConnect(IPin* pPin);
STDMETHODIMP BeginFlush();
STDMETHODIMP EndFlush();
};
-class CBaseSplitterOutputPin
+class CBaseSplitterOutputPin
: public CBaseOutputPin
, public IDSMPropertyBagImpl
, protected CAMThread
@@ -107,18 +119,17 @@ private:
CAMEvent m_eEndFlush;
enum {CMD_EXIT};
- DWORD ThreadProc();
+ DWORD ThreadProc();
void MakeISCRHappy();
// please only use DeliverPacket from the derived class
- HRESULT GetDeliveryBuffer(IMediaSample** ppSample, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags);
- HRESULT Deliver(IMediaSample* pSample);
+ HRESULT GetDeliveryBuffer(IMediaSample** ppSample, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags);
+ HRESULT Deliver(IMediaSample* pSample);
// bitrate stats
- struct
- {
+ struct {
UINT64 nTotalBytesDelivered;
REFERENCE_TIME rtTotalTimeDelivered;
UINT64 nBytesSinceLastDeliverTime;
@@ -160,32 +171,41 @@ public:
virtual ~CBaseSplitterOutputPin();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT SetName(LPCWSTR pName);
- HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT CheckMediaType(const CMediaType* pmt);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- CMediaType& CurrentMediaType() {return m_mt;}
+ HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT CheckMediaType(const CMediaType* pmt);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ CMediaType& CurrentMediaType() {
+ return m_mt;
+ }
STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
// Queueing
- HANDLE GetThreadHandle() {ASSERT(m_hThread != NULL); return m_hThread;}
- void SetThreadPriority(int nPriority) {if(m_hThread) ::SetThreadPriority(m_hThread, nPriority);}
+ HANDLE GetThreadHandle() {
+ ASSERT(m_hThread != NULL);
+ return m_hThread;
+ }
+ void SetThreadPriority(int nPriority) {
+ if(m_hThread) {
+ ::SetThreadPriority(m_hThread, nPriority);
+ }
+ }
HRESULT Active();
- HRESULT Inactive();
+ HRESULT Inactive();
- HRESULT DeliverBeginFlush();
+ HRESULT DeliverBeginFlush();
HRESULT DeliverEndFlush();
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
int QueueCount();
int QueueSize();
- HRESULT QueueEndOfStream();
+ HRESULT QueueEndOfStream();
HRESULT QueuePacket(CAutoPtr<Packet> p);
// returns true for everything which (the lack of) would not block other streams (subtitle streams, basically)
@@ -196,11 +216,15 @@ public:
// IBitRateInfo
- STDMETHODIMP_(DWORD) GetCurrentBitRate() {return m_brs.nCurrentBitRate;}
- STDMETHODIMP_(DWORD) GetAverageBitRate() {return m_brs.nAverageBitRate;}
+ STDMETHODIMP_(DWORD) GetCurrentBitRate() {
+ return m_brs.nCurrentBitRate;
+ }
+ STDMETHODIMP_(DWORD) GetAverageBitRate() {
+ return m_brs.nAverageBitRate;
+ }
};
-class CBaseSplitterFilter
+class CBaseSplitterFilter
: public CBaseFilter
, public CCritSec
, public IDSMPropertyBagImpl
@@ -262,20 +286,22 @@ protected:
protected:
enum {CMD_EXIT, CMD_SEEK};
- DWORD ThreadProc();
+ DWORD ThreadProc();
// ... and also override all these too
virtual bool DemuxInit() = 0;
virtual void DemuxSeek(REFERENCE_TIME rt) = 0;
virtual bool DemuxLoop() = 0;
- virtual bool BuildPlaylist(LPCTSTR pszFileName, CAtlList<CHdmvClipInfo::PlaylistItem>& Items) { return false; };
+ virtual bool BuildPlaylist(LPCTSTR pszFileName, CAtlList<CHdmvClipInfo::PlaylistItem>& Items) {
+ return false;
+ };
public:
CBaseSplitterFilter(LPCTSTR pName, LPUNKNOWN pUnk, HRESULT* phr, const CLSID& clsid);
virtual ~CBaseSplitterFilter();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
bool IsAnyPinDrying();
@@ -330,10 +356,18 @@ public:
// IDispatch
- STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;}
- STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {return E_NOTIMPL;}
- STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {return E_NOTIMPL;}
- STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {return E_NOTIMPL;}
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {
+ return E_NOTIMPL;
+ }
// IAMMediaContent
@@ -342,14 +376,30 @@ public:
STDMETHODIMP get_Rating(BSTR* pbstrRating);
STDMETHODIMP get_Description(BSTR* pbstrDescription);
STDMETHODIMP get_Copyright(BSTR* pbstrCopyright);
- STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {return E_NOTIMPL;}
- STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {return E_NOTIMPL;}
+ STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {
+ return E_NOTIMPL;
+ }
// IAMExtendedSeeking
@@ -358,8 +408,12 @@ public:
STDMETHODIMP get_CurrentMarker(long* pCurrentMarker);
STDMETHODIMP GetMarkerTime(long MarkerNum, double* pMarkerTime);
STDMETHODIMP GetMarkerName(long MarkerNum, BSTR* pbstrMarkerName);
- STDMETHODIMP put_PlaybackSpeed(double Speed) {return E_NOTIMPL;}
- STDMETHODIMP get_PlaybackSpeed(double* pSpeed) {return E_NOTIMPL;}
+ STDMETHODIMP put_PlaybackSpeed(double Speed) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_PlaybackSpeed(double* pSpeed) {
+ return E_NOTIMPL;
+ }
// IKeyFrameInfo
diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp b/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp
index 483c3c7a2..36521c465 100644
--- a/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp
+++ b/src/filters/parser/BaseSplitter/BaseSplitterFile.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -35,7 +35,10 @@ CBaseSplitterFile::CBaseSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr, in
, m_bitbuff(0), m_bitlen(0)
, m_cachepos(0), m_cachelen(0)
{
- if(!m_pAsyncReader) {hr = E_UNEXPECTED; return;}
+ if(!m_pAsyncReader) {
+ hr = E_UNEXPECTED;
+ return;
+ }
LONGLONG total = 0, available;
hr = m_pAsyncReader->Length(&total, &available);
@@ -44,15 +47,13 @@ CBaseSplitterFile::CBaseSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr, in
m_fRandomAccess = total > 0 && total == available;
m_len = total;
- if(FAILED(hr) || fRandomAccess && !m_fRandomAccess || !fStreaming && m_fStreaming || m_len < 0)
- {
+ if(FAILED(hr) || fRandomAccess && !m_fRandomAccess || !fStreaming && m_fStreaming || m_len < 0) {
hr = E_FAIL;
return;
}
- if(!SetCacheSize(cachelen))
- {
- hr = E_OUTOFMEMORY;
+ if(!SetCacheSize(cachelen)) {
+ hr = E_OUTOFMEMORY;
return;
}
@@ -64,7 +65,9 @@ bool CBaseSplitterFile::SetCacheSize(int cachelen)
m_pCache.Free();
m_cachetotal = 0;
m_pCache.Allocate((size_t)cachelen);
- if(!m_pCache) return false;
+ if(!m_pCache) {
+ return false;
+ }
m_cachetotal = cachelen;
m_cachelen = 0;
return true;
@@ -84,12 +87,9 @@ __int64 CBaseSplitterFile::GetAvailable()
__int64 CBaseSplitterFile::GetLength(bool fUpdate)
{
- if(m_fStreaming)
- {
+ if(m_fStreaming) {
m_len = GetAvailable();
- }
- else if(fUpdate)
- {
+ } else if(fUpdate) {
LONGLONG total = 0, available;
m_pAsyncReader->Length(&total, &available);
m_len = total;
@@ -111,15 +111,16 @@ HRESULT CBaseSplitterFile::Read(BYTE* pData, __int64 len)
HRESULT hr = S_OK;
- if(!m_fRandomAccess)
- {
+ if(!m_fRandomAccess) {
LONGLONG total = 0, available = -1;
m_pAsyncReader->Length(&total, &available);
- if(total == available) {m_fRandomAccess = true; OnComplete();}
+ if(total == available) {
+ m_fRandomAccess = true;
+ OnComplete();
+ }
}
- if(m_cachetotal == 0 || !m_pCache)
- {
+ if(m_cachetotal == 0 || !m_pCache) {
hr = m_pAsyncReader->SyncRead(m_pos, (long)len, pData);
m_pos += len;
return hr;
@@ -127,8 +128,7 @@ HRESULT CBaseSplitterFile::Read(BYTE* pData, __int64 len)
BYTE* pCache = m_pCache;
- if(m_cachepos <= m_pos && m_pos < m_cachepos + m_cachelen)
- {
+ if(m_cachepos <= m_pos && m_pos < m_cachepos + m_cachelen) {
__int64 minlen = min(len, m_cachelen - (m_pos - m_cachepos));
memcpy(pData, &pCache[m_pos - m_cachepos], (size_t)minlen);
@@ -138,25 +138,29 @@ HRESULT CBaseSplitterFile::Read(BYTE* pData, __int64 len)
pData += minlen;
}
- while(len > m_cachetotal)
- {
+ while(len > m_cachetotal) {
hr = m_pAsyncReader->SyncRead(m_pos, (long)m_cachetotal, pData);
- if(S_OK != hr) return hr;
+ if(S_OK != hr) {
+ return hr;
+ }
len -= m_cachetotal;
m_pos += m_cachetotal;
pData += m_cachetotal;
}
- while(len > 0)
- {
+ while(len > 0) {
__int64 tmplen = GetLength();
__int64 maxlen = min(tmplen - m_pos, m_cachetotal);
__int64 minlen = min(len, maxlen);
- if(minlen <= 0) return S_FALSE;
+ if(minlen <= 0) {
+ return S_FALSE;
+ }
hr = m_pAsyncReader->SyncRead(m_pos, (long)maxlen, pCache);
- if(S_OK != hr) return hr;
+ if(S_OK != hr) {
+ return hr;
+ }
m_cachepos = m_pos;
m_cachelen = maxlen;
@@ -175,10 +179,11 @@ UINT64 CBaseSplitterFile::BitRead(int nBits, bool fPeek)
{
ASSERT(nBits >= 0 && nBits <= 64);
- while(m_bitlen < nBits)
- {
+ while(m_bitlen < nBits) {
m_bitbuff <<= 8;
- if(S_OK != Read((BYTE*)&m_bitbuff, 1)) {return 0;} // EOF? // ASSERT(0);
+ if(S_OK != Read((BYTE*)&m_bitbuff, 1)) {
+ return 0; // EOF? // ASSERT(0);
+ }
m_bitlen += 8;
}
@@ -186,8 +191,7 @@ UINT64 CBaseSplitterFile::BitRead(int nBits, bool fPeek)
UINT64 ret = (m_bitbuff >> bitlen) & ((1ui64 << nBits) - 1);
- if(!fPeek)
- {
+ if(!fPeek) {
m_bitbuff &= ((1ui64 << bitlen) - 1);
m_bitlen = bitlen;
}
@@ -207,14 +211,16 @@ void CBaseSplitterFile::BitFlush()
HRESULT CBaseSplitterFile::ByteRead(BYTE* pData, __int64 len)
{
- Seek(GetPos());
+ Seek(GetPos());
return Read(pData, len);
}
UINT64 CBaseSplitterFile::UExpGolombRead()
{
int n = -1;
- for(BYTE b = 0; !b; n++) b = BitRead(1);
+ for(BYTE b = 0; !b; n++) {
+ b = BitRead(1);
+ }
return (1ui64 << n) - 1 + BitRead(n);
}
@@ -228,14 +234,14 @@ HRESULT CBaseSplitterFile::HasMoreData(__int64 len, DWORD ms)
{
__int64 available = GetLength() - GetPos();
- if(!m_fStreaming)
- {
+ if(!m_fStreaming) {
return available < 1 ? E_FAIL : S_OK;
}
- if(available < len)
- {
- if(ms > 0) Sleep(ms);
+ if(available < len) {
+ if(ms > 0) {
+ Sleep(ms);
+ }
return S_FALSE;
}
diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFile.h b/src/filters/parser/BaseSplitter/BaseSplitterFile.h
index 8b61961e1..279471748 100644
--- a/src/filters/parser/BaseSplitter/BaseSplitterFile.h
+++ b/src/filters/parser/BaseSplitter/BaseSplitterFile.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -51,7 +51,9 @@ public:
__int64 GetPos();
__int64 GetAvailable();
__int64 GetLength(bool fUpdate = false);
- __int64 GetRemaining() {return max(0, GetLength() - GetPos());}
+ __int64 GetRemaining() {
+ return max(0, GetLength() - GetPos());
+ }
virtual void Seek(__int64 pos);
UINT64 UExpGolombRead();
@@ -61,8 +63,12 @@ public:
void BitByteAlign(), BitFlush();
HRESULT ByteRead(BYTE* pData, __int64 len);
- bool IsStreaming() const {return m_fStreaming;}
- bool IsRandomAccess() const {return m_fRandomAccess;}
+ bool IsStreaming() const {
+ return m_fStreaming;
+ }
+ bool IsRandomAccess() const {
+ return m_fRandomAccess;
+ }
HRESULT HasMoreData(__int64 len = 1, DWORD ms = 1);
};
diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp
index 85e259fc3..3a0df88ee 100644
--- a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp
+++ b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -50,12 +50,12 @@ bool CBaseSplitterFileEx::NextMpegStartCode(BYTE& code, __int64 len)
{
BitByteAlign();
DWORD dw = (DWORD)-1;
- do
- {
- if(len-- == 0 || !GetRemaining()) return(false);
+ do {
+ if(len-- == 0 || !GetRemaining()) {
+ return(false);
+ }
dw = (dw << 8) | (BYTE)BitRead(8);
- }
- while((dw&0xffffff00) != 0x00000100);
+ } while((dw&0xffffff00) != 0x00000100);
code = (BYTE)(dw&0xff);
return(true);
}
@@ -70,36 +70,44 @@ bool CBaseSplitterFileEx::Read(pshdr& h)
BYTE b = (BYTE)BitRead(8, true);
- if((b&0xf1) == 0x21)
- {
+ if((b&0xf1) == 0x21) {
h.type = mpeg1;
EXECUTE_ASSERT(BitRead(4) == 2);
h.scr = 0;
- h.scr |= BitRead(3) << 30; MARKER; // 32..30
- h.scr |= BitRead(15) << 15; MARKER; // 29..15
- h.scr |= BitRead(15); MARKER; MARKER; // 14..0
- h.bitrate = BitRead(22); MARKER;
- }
- else if((b&0xc4) == 0x44)
- {
+ h.scr |= BitRead(3) << 30;
+ MARKER; // 32..30
+ h.scr |= BitRead(15) << 15;
+ MARKER; // 29..15
+ h.scr |= BitRead(15);
+ MARKER;
+ MARKER; // 14..0
+ h.bitrate = BitRead(22);
+ MARKER;
+ } else if((b&0xc4) == 0x44) {
h.type = mpeg2;
EXECUTE_ASSERT(BitRead(2) == 1);
h.scr = 0;
- h.scr |= BitRead(3) << 30; MARKER; // 32..30
- h.scr |= BitRead(15) << 15; MARKER; // 29..15
- h.scr |= BitRead(15); MARKER; // 14..0
- h.scr = (h.scr*300 + BitRead(9)) * 10 / 27; MARKER;
- h.bitrate = BitRead(22); MARKER; MARKER;
+ h.scr |= BitRead(3) << 30;
+ MARKER; // 32..30
+ h.scr |= BitRead(15) << 15;
+ MARKER; // 29..15
+ h.scr |= BitRead(15);
+ MARKER; // 14..0
+ h.scr = (h.scr*300 + BitRead(9)) * 10 / 27;
+ MARKER;
+ h.bitrate = BitRead(22);
+ MARKER;
+ MARKER;
BitRead(5); // reserved
UINT64 stuffing = BitRead(3);
- while(stuffing-- > 0) EXECUTE_ASSERT(BitRead(8) == 0xff);
- }
- else
- {
+ while(stuffing-- > 0) {
+ EXECUTE_ASSERT(BitRead(8) == 0xff);
+ }
+ } else {
return(false);
}
@@ -112,19 +120,21 @@ bool CBaseSplitterFileEx::Read(pssyshdr& h)
{
memset(&h, 0, sizeof(h));
- WORD len = (WORD)BitRead(16); MARKER;
- h.rate_bound = (DWORD)BitRead(22); MARKER;
+ WORD len = (WORD)BitRead(16);
+ MARKER;
+ h.rate_bound = (DWORD)BitRead(22);
+ MARKER;
h.audio_bound = (BYTE)BitRead(6);
h.fixed_rate = !!BitRead(1);
h.csps = !!BitRead(1);
h.sys_audio_loc_flag = !!BitRead(1);
- h.sys_video_loc_flag = !!BitRead(1); MARKER;
+ h.sys_video_loc_flag = !!BitRead(1);
+ MARKER;
h.video_bound = (BYTE)BitRead(5);
EXECUTE_ASSERT((BitRead(8)&0x7f) == 0x7f); // reserved (should be 0xff, but not in reality)
- for(len -= 6; len > 3; len -= 3) // TODO: also store these, somewhere, if needed
- {
+ for(len -= 6; len > 3; len -= 3) { // TODO: also store these, somewhere, if needed
UINT64 stream_id = BitRead(8);
UNUSED_ALWAYS(stream_id);
EXECUTE_ASSERT(BitRead(2) == 3);
@@ -139,42 +149,42 @@ bool CBaseSplitterFileEx::Read(peshdr& h, BYTE code)
{
memset(&h, 0, sizeof(h));
- if(!(code >= 0xbd && code < 0xf0 || code == 0xfd)) // 0xfd => blu-ray (.m2ts)
+ if(!(code >= 0xbd && code < 0xf0 || code == 0xfd)) { // 0xfd => blu-ray (.m2ts)
return(false);
+ }
h.len = (WORD)BitRead(16);
- if(code == 0xbe || code == 0xbf)
+ if(code == 0xbe || code == 0xbf) {
return(true);
+ }
// mpeg1 stuffing (ff ff .. , max 16x)
- for(int i = 0; i < 16 && BitRead(8, true) == 0xff; i++)
- {
- BitRead(8);
- if(h.len) h.len--;
+ for(int i = 0; i < 16 && BitRead(8, true) == 0xff; i++) {
+ BitRead(8);
+ if(h.len) {
+ h.len--;
+ }
}
h.type = (BYTE)BitRead(2, true) == mpeg2 ? mpeg2 : mpeg1;
- if(h.type == mpeg1)
- {
+ if(h.type == mpeg1) {
BYTE b = (BYTE)BitRead(2);
- if(b == 1)
- {
+ if(b == 1) {
h.std_buff_size = (BitRead(1)?1024:128)*BitRead(13);
- if(h.len) h.len -= 2;
+ if(h.len) {
+ h.len -= 2;
+ }
b = (BYTE)BitRead(2);
}
- if(b == 0)
- {
+ if(b == 0) {
h.fpts = (BYTE)BitRead(1);
h.fdts = (BYTE)BitRead(1);
}
- }
- else if(h.type == mpeg2)
- {
+ } else if(h.type == mpeg2) {
EXECUTE_ASSERT(BitRead(2) == mpeg2);
h.scrambling = (BYTE)BitRead(2);
h.priority = (BYTE)BitRead(1);
@@ -190,17 +200,15 @@ bool CBaseSplitterFileEx::Read(peshdr& h, BYTE code)
h.crc = (BYTE)BitRead(1);
h.extension = (BYTE)BitRead(1);
h.hdrlen = (BYTE)BitRead(8);
- }
- else
- {
- if(h.len) while(h.len-- > 0) BitRead(8);
+ } else {
+ if(h.len) while(h.len-- > 0) {
+ BitRead(8);
+ }
return(false);
}
- if(h.fpts)
- {
- if(h.type == mpeg2)
- {
+ if(h.fpts) {
+ if(h.type == mpeg2) {
// Temporary(dirty) fix - needs more testing
//BYTE b = (BYTE)BitRead(4);
//if(!(h.fdts && b == 3 || !h.fdts && b == 2)) {ASSERT(0); return(false);}
@@ -208,57 +216,73 @@ bool CBaseSplitterFileEx::Read(peshdr& h, BYTE code)
}
h.pts = 0;
- h.pts |= BitRead(3) << 30; MARKER; // 32..30
- h.pts |= BitRead(15) << 15; MARKER; // 29..15
- h.pts |= BitRead(15); MARKER; // 14..0
+ h.pts |= BitRead(3) << 30;
+ MARKER; // 32..30
+ h.pts |= BitRead(15) << 15;
+ MARKER; // 29..15
+ h.pts |= BitRead(15);
+ MARKER; // 14..0
h.pts = 10000*h.pts/90 + m_rtPTSOffset;
}
- if(h.fdts)
- {
+ if(h.fdts) {
// Temporary(dirty) fix - needs more testing
//if((BYTE)BitRead(4) != 1) {ASSERT(0); return(false);}
BitRead(4);
h.dts = 0;
- h.dts |= BitRead(3) << 30; MARKER; // 32..30
- h.dts |= BitRead(15) << 15; MARKER; // 29..15
- h.dts |= BitRead(15); MARKER; // 14..0
+ h.dts |= BitRead(3) << 30;
+ MARKER; // 32..30
+ h.dts |= BitRead(15) << 15;
+ MARKER; // 29..15
+ h.dts |= BitRead(15);
+ MARKER; // 14..0
h.dts = 10000*h.dts/90 + m_rtPTSOffset;
}
// skip to the end of header
- if(h.type == mpeg1)
- {
- if(!h.fpts && !h.fdts && BitRead(4) != 0xf) {/*ASSERT(0);*/ return(false);}
+ if(h.type == mpeg1) {
+ if(!h.fpts && !h.fdts && BitRead(4) != 0xf) {
+ /*ASSERT(0);*/ return(false);
+ }
- if(h.len)
- {
+ if(h.len) {
h.len--;
- if(h.pts) h.len -= 4;
- if(h.dts) h.len -= 5;
+ if(h.pts) {
+ h.len -= 4;
+ }
+ if(h.dts) {
+ h.len -= 5;
+ }
}
}
- if(h.type == mpeg2)
- {
- if(h.len) h.len -= 3+h.hdrlen;
+ if(h.type == mpeg2) {
+ if(h.len) {
+ h.len -= 3+h.hdrlen;
+ }
int left = h.hdrlen;
- if(h.fpts) left -= 5;
- if(h.fdts) left -= 5;
- while(left-- > 0) BitRead(8);
-/*
- // mpeg2 stuffing (ff ff .. , max 32x)
- while(BitRead(8, true) == 0xff) {BitRead(8); if(h.len) h.len--;}
- Seek(GetPos()); // put last peeked byte back for Read()
-
- // FIXME: this doesn't seems to be here,
- // infact there can be ff's as part of the data
- // right at the beginning of the packet, which
- // we should not skip...
-*/
+ if(h.fpts) {
+ left -= 5;
+ }
+ if(h.fdts) {
+ left -= 5;
+ }
+ while(left-- > 0) {
+ BitRead(8);
+ }
+ /*
+ // mpeg2 stuffing (ff ff .. , max 32x)
+ while(BitRead(8, true) == 0xff) {BitRead(8); if(h.len) h.len--;}
+ Seek(GetPos()); // put last peeked byte back for Read()
+
+ // FIXME: this doesn't seems to be here,
+ // infact there can be ff's as part of the data
+ // right at the beginning of the packet, which
+ // we should not skip...
+ */
}
return(true);
@@ -270,40 +294,43 @@ bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt)
BYTE id = 0;
- while(GetPos() < endpos && id != 0xb3)
- {
- if(!NextMpegStartCode(id, len))
+ while(GetPos() < endpos && id != 0xb3) {
+ if(!NextMpegStartCode(id, len)) {
return(false);
+ }
}
- if(id != 0xb3)
+ if(id != 0xb3) {
return(false);
+ }
__int64 shpos = GetPos() - 4;
h.width = (WORD)BitRead(12);
h.height = (WORD)BitRead(12);
h.ar = BitRead(4);
- static int ifps[16] = {0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, 0, 0, 0, 0, 0, 0, 0};
+ static int ifps[16] = {0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000, 0, 0, 0, 0, 0, 0, 0};
h.ifps = ifps[BitRead(4)];
- h.bitrate = (DWORD)BitRead(18); MARKER;
+ h.bitrate = (DWORD)BitRead(18);
+ MARKER;
h.vbv = (DWORD)BitRead(10);
h.constrained = BitRead(1);
h.fiqm = BitRead(1);
if(h.fiqm)
- for(int i = 0; i < countof(h.iqm); i++)
+ for(int i = 0; i < countof(h.iqm); i++) {
h.iqm[i] = (BYTE)BitRead(8);
+ }
h.fniqm = BitRead(1);
if(h.fniqm)
- for(int i = 0; i < countof(h.niqm); i++)
+ for(int i = 0; i < countof(h.niqm); i++) {
h.niqm[i] = (BYTE)BitRead(8);
+ }
__int64 shlen = GetPos() - shpos;
- static float ar[] =
- {
+ static float ar[] = {
1.0000f,1.0000f,0.6735f,0.7031f,0.7615f,0.8055f,0.8437f,0.8935f,
0.9157f,0.9815f,1.0255f,1.0695f,1.0950f,1.1575f,1.2015f,1.0000f
};
@@ -315,8 +342,7 @@ bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt)
__int64 shextpos = 0, shextlen = 0;
- if(NextMpegStartCode(id, 8) && id == 0xb5) // sequence header ext
- {
+ if(NextMpegStartCode(id, 8) && id == 0xb5) { // sequence header ext
shextpos = GetPos() - 4;
h.startcodeid = BitRead(4);
@@ -327,14 +353,17 @@ bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt)
h.chroma = BitRead(2);
h.width |= (BitRead(2)<<12);
h.height |= (BitRead(2)<<12);
- h.bitrate |= (BitRead(12)<<18); MARKER;
+ h.bitrate |= (BitRead(12)<<18);
+ MARKER;
h.vbv |= (BitRead(8)<<10);
h.lowdelay = BitRead(1);
h.ifps = (DWORD)(h.ifps * (BitRead(2)+1) / (BitRead(5)+1));
shextlen = GetPos() - shextpos;
- struct {DWORD x, y;} ar[] = {{h.width,h.height},{4,3},{16,9},{221,100},{h.width,h.height}};
+ struct {
+ DWORD x, y;
+ } ar[] = {{h.width,h.height},{4,3},{16,9},{221,100},{h.width,h.height}};
int i = min(max(h.ar, 1), 5)-1;
h.arx = ar[i].x;
h.ary = ar[i].y;
@@ -346,15 +375,22 @@ bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt)
h.bitrate = h.bitrate == (1<<30)-1 ? 0 : h.bitrate * 400;
DWORD a = h.arx, b = h.ary;
- while(a) {DWORD tmp = a; a = b % tmp; b = tmp;}
- if(b) h.arx /= b, h.ary /= b;
+ while(a) {
+ DWORD tmp = a;
+ a = b % tmp;
+ b = tmp;
+ }
+ if(b) {
+ h.arx /= b, h.ary /= b;
+ }
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
pmt->majortype = MEDIATYPE_Video;
- if(type == mpeg1)
- {
+ if(type == mpeg1) {
pmt->subtype = MEDIASUBTYPE_MPEG1Payload;
pmt->formattype = FORMAT_MPEGVideo;
int len = FIELD_OFFSET(MPEG1VIDEOINFO, bSequenceHeader) + shlen + shextlen;
@@ -370,13 +406,13 @@ bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt)
vi->cbSequenceHeader = shlen + shextlen;
Seek(shpos);
ByteRead((BYTE*)&vi->bSequenceHeader[0], shlen);
- if(shextpos && shextlen) Seek(shextpos);
+ if(shextpos && shextlen) {
+ Seek(shextpos);
+ }
ByteRead((BYTE*)&vi->bSequenceHeader[0] + shlen, shextlen);
pmt->SetFormat((BYTE*)vi, len);
delete [] vi;
- }
- else if(type == mpeg2)
- {
+ } else if(type == mpeg2) {
pmt->subtype = MEDIASUBTYPE_MPEG2_VIDEO;
pmt->formattype = FORMAT_MPEG2_VIDEO;
int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + shlen + shextlen;
@@ -394,13 +430,13 @@ bool CBaseSplitterFileEx::Read(seqhdr& h, int len, CMediaType* pmt)
vi->cbSequenceHeader = shlen + shextlen;
Seek(shpos);
ByteRead((BYTE*)&vi->dwSequenceHeader[0], shlen);
- if(shextpos && shextlen) Seek(shextpos);
+ if(shextpos && shextlen) {
+ Seek(shextpos);
+ }
ByteRead((BYTE*)&vi->dwSequenceHeader[0] + shlen, shextlen);
pmt->SetFormat((BYTE*)vi, len);
delete [] vi;
- }
- else
- {
+ } else {
return(false);
}
@@ -413,11 +449,13 @@ bool CBaseSplitterFileEx::Read(mpahdr& h, int len, bool fAllowV25, CMediaType* p
int syncbits = fAllowV25 ? 11 : 12;
- for(; len >= 4 && BitRead(syncbits, true) != (1<<syncbits) - 1; len--)
+ for(; len >= 4 && BitRead(syncbits, true) != (1<<syncbits) - 1; len--) {
BitRead(8);
+ }
- if(len < 4)
+ if(len < 4) {
return(false);
+ }
h.sync = BitRead(11);
h.version = BitRead(2);
@@ -433,22 +471,22 @@ bool CBaseSplitterFileEx::Read(mpahdr& h, int len, bool fAllowV25, CMediaType* p
h.original = BitRead(1);
h.emphasis = BitRead(2);
- if(h.version == 1 || h.layer == 0 || h.freq == 3 || h.bitrate == 15 || h.emphasis == 2)
+ if(h.version == 1 || h.layer == 0 || h.freq == 3 || h.bitrate == 15 || h.emphasis == 2) {
return(false);
+ }
- if(h.version == 3 && h.layer == 2)
- {
+ if(h.version == 3 && h.layer == 2) {
if((h.bitrate == 1 || h.bitrate == 2 || h.bitrate == 3 || h.bitrate == 5) && h.channels != 3
- && (h.bitrate >= 11 && h.bitrate <= 14) && h.channels == 3)
+ && (h.bitrate >= 11 && h.bitrate <= 14) && h.channels == 3) {
return(false);
+ }
}
h.layer = 4 - h.layer;
//
- static int brtbl[][5] =
- {
+ static int brtbl[][5] = {
{0,0,0,0,0},
{32,32,32,32,8},
{64,48,40,48,16},
@@ -469,7 +507,9 @@ bool CBaseSplitterFileEx::Read(mpahdr& h, int len, bool fAllowV25, CMediaType* p
static int brtblcol[][4] = {{0,3,4,4},{0,0,1,2}};
int bitrate = 1000*brtbl[h.bitrate][brtblcol[h.version&1][h.layer]];
- if(bitrate == 0) return(false);
+ if(bitrate == 0) {
+ return(false);
+ }
static int freq[][4] = {{11025,0,22050,44100},{12000,0,24000,48000},{8000,0,16000,32000}};
@@ -477,42 +517,51 @@ bool CBaseSplitterFileEx::Read(mpahdr& h, int len, bool fAllowV25, CMediaType* p
h.nSamplesPerSec = freq[h.freq][h.version];
h.FrameSize = h.layer == 1
- ? (12 * bitrate / h.nSamplesPerSec + h.padding) * 4
- : (l3ext ? 72 : 144) * bitrate / h.nSamplesPerSec + h.padding;
+ ? (12 * bitrate / h.nSamplesPerSec + h.padding) * 4
+ : (l3ext ? 72 : 144) * bitrate / h.nSamplesPerSec + h.padding;
h.rtDuration = 10000000i64 * (h.layer == 1 ? 384 : l3ext ? 576 : 1152) / h.nSamplesPerSec;// / (h.channels == 3 ? 1 : 2);
h.nBytesPerSec = bitrate / 8;
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
- /*int*/ len = h.layer == 3
- ? sizeof(WAVEFORMATEX/*MPEGLAYER3WAVEFORMAT*/) // no need to overcomplicate this...
- : sizeof(MPEG1WAVEFORMAT);
+ /*int*/ len = h.layer == 3
+ ? sizeof(WAVEFORMATEX/*MPEGLAYER3WAVEFORMAT*/) // no need to overcomplicate this...
+ : sizeof(MPEG1WAVEFORMAT);
WAVEFORMATEX* wfe = (WAVEFORMATEX*)DNew BYTE[len];
memset(wfe, 0, len);
wfe->cbSize = len - sizeof(WAVEFORMATEX);
- if(h.layer == 3)
- {
+ if(h.layer == 3) {
wfe->wFormatTag = WAVE_FORMAT_MP3;
-/* MPEGLAYER3WAVEFORMAT* f = (MPEGLAYER3WAVEFORMAT*)wfe;
- f->wfx.wFormatTag = WAVE_FORMAT_MP3;
- f->wID = MPEGLAYER3_ID_UNKNOWN;
- f->fdwFlags = h.padding ? MPEGLAYER3_FLAG_PADDING_ON : MPEGLAYER3_FLAG_PADDING_OFF; // _OFF or _ISO ?
-*/
- }
- else
- {
+ /* MPEGLAYER3WAVEFORMAT* f = (MPEGLAYER3WAVEFORMAT*)wfe;
+ f->wfx.wFormatTag = WAVE_FORMAT_MP3;
+ f->wID = MPEGLAYER3_ID_UNKNOWN;
+ f->fdwFlags = h.padding ? MPEGLAYER3_FLAG_PADDING_ON : MPEGLAYER3_FLAG_PADDING_OFF; // _OFF or _ISO ?
+ */
+ } else {
MPEG1WAVEFORMAT* f = (MPEG1WAVEFORMAT*)wfe;
f->wfx.wFormatTag = WAVE_FORMAT_MPEG;
f->fwHeadMode = 1 << h.channels;
f->fwHeadModeExt = 1 << h.modeext;
f->wHeadEmphasis = h.emphasis+1;
- if(h.privatebit) f->fwHeadFlags |= ACM_MPEG_PRIVATEBIT;
- if(h.copyright) f->fwHeadFlags |= ACM_MPEG_COPYRIGHT;
- if(h.original) f->fwHeadFlags |= ACM_MPEG_ORIGINALHOME;
- if(h.crc == 0) f->fwHeadFlags |= ACM_MPEG_PROTECTIONBIT;
- if(h.version == 3) f->fwHeadFlags |= ACM_MPEG_ID_MPEG1;
+ if(h.privatebit) {
+ f->fwHeadFlags |= ACM_MPEG_PRIVATEBIT;
+ }
+ if(h.copyright) {
+ f->fwHeadFlags |= ACM_MPEG_COPYRIGHT;
+ }
+ if(h.original) {
+ f->fwHeadFlags |= ACM_MPEG_ORIGINALHOME;
+ }
+ if(h.crc == 0) {
+ f->fwHeadFlags |= ACM_MPEG_PROTECTIONBIT;
+ }
+ if(h.version == 3) {
+ f->fwHeadFlags |= ACM_MPEG_ID_MPEG1;
+ }
f->fwHeadLayer = 1 << (h.layer-1);
f->dwHeadBitrate = bitrate;
}
@@ -536,11 +585,13 @@ bool CBaseSplitterFileEx::Read(aachdr& h, int len, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- for(; len >= 7 && BitRead(12, true) != 0xfff; len--)
+ for(; len >= 7 && BitRead(12, true) != 0xfff; len--) {
BitRead(8);
+ }
- if(len < 7)
+ if(len < 7) {
return(false);
+ }
h.sync = BitRead(12);
h.version = BitRead(1);
@@ -559,17 +610,22 @@ bool CBaseSplitterFileEx::Read(aachdr& h, int len, CMediaType* pmt)
h.adts_buffer_fullness = BitRead(11);
h.no_raw_data_blocks_in_frame = BitRead(2);
- if(h.fcrc == 0) h.crc = BitRead(16);
+ if(h.fcrc == 0) {
+ h.crc = BitRead(16);
+ }
- if(h.layer != 0 || h.freq >= 12 || h.aac_frame_length <= (h.fcrc == 0 ? 9 : 7))
+ if(h.layer != 0 || h.freq >= 12 || h.aac_frame_length <= (h.fcrc == 0 ? 9 : 7)) {
return(false);
+ }
h.FrameSize = h.aac_frame_length - (h.fcrc == 0 ? 9 : 7);
- static int freq[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000};
+ static int freq[] = {96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000};
h.nBytesPerSec = h.aac_frame_length * freq[h.freq] / 1024; // ok?
h.rtDuration = 10000000i64 * 1024 / freq[h.freq]; // ok?
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
WAVEFORMATEX* wfe = (WAVEFORMATEX*)DNew BYTE[sizeof(WAVEFORMATEX)+5];
memset(wfe, 0, sizeof(WAVEFORMATEX)+5);
@@ -597,33 +653,45 @@ bool CBaseSplitterFileEx::Read(ac3hdr& h, int len, CMediaType* pmt)
memset(&h, 0, sizeof(h));
- for(; len >= 7 && BitRead(16, true) != 0x0b77; len--)
+ for(; len >= 7 && BitRead(16, true) != 0x0b77; len--) {
BitRead(8);
+ }
- if(len < 7)
+ if(len < 7) {
return(false);
+ }
h.sync = (WORD)BitRead(16);
- if(h.sync != 0x0B77)
+ if(h.sync != 0x0B77) {
return(false);
+ }
_int64 pos = GetPos();
h.crc1 = (WORD)BitRead(16);
h.fscod = BitRead(2);
h.frmsizecod = BitRead(6);
h.bsid = BitRead(5);
- if(h.bsid > 16)
+ if(h.bsid > 16) {
return(false);
+ }
if(h.bsid <= 10) {
/* Normal AC-3 */
- if(h.fscod == 3)
+ if(h.fscod == 3) {
return(false);
- if(h.frmsizecod > 37)
+ }
+ if(h.frmsizecod > 37) {
return(false);
+ }
h.bsmod = BitRead(3);
h.acmod = BitRead(3);
- if(h.acmod == 2) h.dsurmod = BitRead(2);
- if((h.acmod & 1) && h.acmod != 1) h.cmixlev = BitRead(2);
- if(h.acmod & 4) h.surmixlev = BitRead(2);
+ if(h.acmod == 2) {
+ h.dsurmod = BitRead(2);
+ }
+ if((h.acmod & 1) && h.acmod != 1) {
+ h.cmixlev = BitRead(2);
+ }
+ if(h.acmod & 4) {
+ h.surmixlev = BitRead(2);
+ }
h.lfeon = BitRead(1);
h.sr_shift = max(h.bsid, 8) - 8;
} else {
@@ -632,22 +700,22 @@ bool CBaseSplitterFileEx::Read(ac3hdr& h, int len, CMediaType* pmt)
Seek(pos);
h.frame_type = BitRead(2);
h.substreamid = BitRead(3);
- if(h.frame_type || h.substreamid)
+ if(h.frame_type || h.substreamid) {
return(false);
+ }
h.frame_size = (BitRead(11) + 1) << 1;
- if(h.frame_size < 7)
+ if(h.frame_size < 7) {
return(false);
+ }
h.sr_code = BitRead(2);
- if(h.sr_code == 3)
- {
+ if(h.sr_code == 3) {
int sr_code2 = BitRead(2);
- if(sr_code2 == 3)
+ if(sr_code2 == 3) {
return(false);
+ }
h.sample_rate = freq[sr_code2] / 2;
h.sr_shift = 1;
- }
- else
- {
+ } else {
static int eac3_blocks[4] = {1, 2, 3, 6};
h.num_blocks = eac3_blocks[BitRead(2)];
h.sample_rate = freq[h.sr_code];
@@ -657,34 +725,34 @@ bool CBaseSplitterFileEx::Read(ac3hdr& h, int len, CMediaType* pmt)
h.lfeon = BitRead(1);
}
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
WAVEFORMATEX wfe;
memset(&wfe, 0, sizeof(wfe));
wfe.wFormatTag = WAVE_FORMAT_DOLBY_AC3;
-
+
static int channels[] = {2, 1, 2, 3, 3, 4, 4, 5};
wfe.nChannels = channels[h.acmod] + h.lfeon;
- if(h.bsid <= 10)
- {
+ if(h.bsid <= 10) {
wfe.nSamplesPerSec = freq[h.fscod] >> h.sr_shift;
static int rate[] = {32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 512, 576, 640, 768, 896, 1024, 1152, 1280};
wfe.nAvgBytesPerSec = ((rate[h.frmsizecod>>1] * 1000) >> h.sr_shift) / 8;
- }
- else
- {
+ } else {
wfe.nSamplesPerSec = h.sample_rate;
wfe.nAvgBytesPerSec = h.frame_size * h.sample_rate / (h.num_blocks * 256);
}
-
+
wfe.nBlockAlign = (WORD)(1536 * wfe.nAvgBytesPerSec / wfe.nSamplesPerSec);
pmt->majortype = MEDIATYPE_Audio;
- if(e_ac3)
+ if(e_ac3) {
pmt->subtype = MEDIASUBTYPE_DOLBY_DDPLUS;
- else
+ } else {
pmt->subtype = MEDIASUBTYPE_DOLBY_AC3;
+ }
pmt->formattype = FORMAT_WaveFormatEx;
pmt->SetFormat((BYTE*)&wfe, sizeof(wfe));
@@ -695,11 +763,13 @@ bool CBaseSplitterFileEx::Read(dtshdr& h, int len, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- for(; len >= 10 && BitRead(32, true) != 0x7ffe8001; len--)
+ for(; len >= 10 && BitRead(32, true) != 0x7ffe8001; len--) {
BitRead(8);
+ }
- if(len < 10)
+ if(len < 10) {
return(false);
+ }
h.sync = (DWORD)BitRead(32);
h.frametype = BitRead(1);
@@ -711,19 +781,21 @@ bool CBaseSplitterFileEx::Read(dtshdr& h, int len, CMediaType* pmt)
h.sfreq = BitRead(4);
h.rate = BitRead(5);
- h.downmix = BitRead(1);
- h.dynrange = BitRead(1);
- h.timestamp = BitRead(1);
- h.aux_data = BitRead(1);
- h.hdcd = BitRead(1);
- h.ext_descr = BitRead(3);
- h.ext_coding = BitRead(1);
- h.aspf = BitRead(1);
- h.lfe = BitRead(2);
- h.predictor_history = BitRead(1);
+ h.downmix = BitRead(1);
+ h.dynrange = BitRead(1);
+ h.timestamp = BitRead(1);
+ h.aux_data = BitRead(1);
+ h.hdcd = BitRead(1);
+ h.ext_descr = BitRead(3);
+ h.ext_coding = BitRead(1);
+ h.aspf = BitRead(1);
+ h.lfe = BitRead(2);
+ h.predictor_history = BitRead(1);
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
WAVEFORMATEX wfe;
memset(&wfe, 0, sizeof(wfe));
@@ -731,18 +803,17 @@ bool CBaseSplitterFileEx::Read(dtshdr& h, int len, CMediaType* pmt)
static int channels[] = {1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8};
- if(h.amode < countof(channels))
- {
+ if(h.amode < countof(channels)) {
wfe.nChannels = channels[h.amode];
- if (h.lfe > 0)
+ if (h.lfe > 0) {
++wfe.nChannels;
+ }
}
static int freq[] = {0,8000,16000,32000,0,0,11025,22050,44100,0,0,12000,24000,48000,0,0};
wfe.nSamplesPerSec = freq[h.sfreq];
- static int rate[] =
- {
+ static int rate[] = {
32000,56000,64000,96000,112000,128000,192000,224000,
256000,320000,384000,448000,512000,576000,640000,754500,
960000,1024000,1152000,1280000,1344000,1408000,1411200,1472000,
@@ -769,12 +840,15 @@ bool CBaseSplitterFileEx::Read(hdmvlpcmhdr& h, CMediaType* pmt)
h.samplerate = BitRead(4);
h.bitpersample = BitRead(2);
- if (h.channels==0 || h.channels==2 ||
- (h.samplerate != 1 && h.samplerate!= 4 && h.samplerate!= 5) ||
- h.bitpersample<0 || h.bitpersample>3)
+ if (h.channels==0 || h.channels==2 ||
+ (h.samplerate != 1 && h.samplerate!= 4 && h.samplerate!= 5) ||
+ h.bitpersample<0 || h.bitpersample>3) {
return(false);
+ }
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
WAVEFORMATEX_HDMV_LPCM wfe;
wfe.wFormatTag = WAVE_FORMAT_PCM;
@@ -814,10 +888,13 @@ bool CBaseSplitterFileEx::Read(lpcmhdr& h, CMediaType* pmt)
h.channels = BitRead(3);
h.drc = (BYTE)BitRead(8);
- if(h.quantwordlen == 3 || h.reserved1 || h.reserved2)
+ if(h.quantwordlen == 3 || h.reserved1 || h.reserved2) {
return(false);
+ }
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
WAVEFORMATEX wfe;
memset(&wfe, 0, sizeof(wfe));
@@ -825,17 +902,16 @@ bool CBaseSplitterFileEx::Read(lpcmhdr& h, CMediaType* pmt)
wfe.nChannels = h.channels+1;
static int freq[] = {48000, 96000, 44100, 32000};
wfe.nSamplesPerSec = freq[h.freq];
- switch (h.quantwordlen)
- {
- case 0:
- wfe.wBitsPerSample = 16;
- break;
- case 1:
- wfe.wBitsPerSample = 20;
- break;
- case 2:
- wfe.wBitsPerSample = 24;
- break;
+ switch (h.quantwordlen) {
+ case 0:
+ wfe.wBitsPerSample = 16;
+ break;
+ case 1:
+ wfe.wBitsPerSample = 20;
+ break;
+ case 2:
+ wfe.wBitsPerSample = 24;
+ break;
}
wfe.nBlockAlign = (wfe.nChannels*2*wfe.wBitsPerSample) / 8;
wfe.nAvgBytesPerSec = (wfe.nBlockAlign*wfe.nSamplesPerSec) / 2;
@@ -854,7 +930,9 @@ bool CBaseSplitterFileEx::Read(dvdspuhdr& h, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
pmt->majortype = MEDIATYPE_Video;
pmt->subtype = MEDIASUBTYPE_DVD_SUBPICTURE;
@@ -867,15 +945,16 @@ bool CBaseSplitterFileEx::Read(hdmvsubhdr& h, CMediaType* pmt, const char* langu
{
memset(&h, 0, sizeof(h));
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
pmt->majortype = MEDIATYPE_Subtitle;
pmt->subtype = MEDIASUBTYPE_HDMVSUB;
pmt->formattype = FORMAT_None;
SUBTITLEINFO* psi = (SUBTITLEINFO*)pmt->AllocFormatBuffer(sizeof(SUBTITLEINFO));
- if (psi)
- {
+ if (psi) {
memset(psi, 0, pmt->FormatLength());
strcpy(psi->IsoLang, language_code ? language_code : "eng");
}
@@ -887,7 +966,9 @@ bool CBaseSplitterFileEx::Read(svcdspuhdr& h, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
pmt->majortype = MEDIATYPE_Video;
pmt->subtype = MEDIASUBTYPE_SVCD_SUBPICTURE;
@@ -900,7 +981,9 @@ bool CBaseSplitterFileEx::Read(cvdspuhdr& h, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
pmt->majortype = MEDIATYPE_Video;
pmt->subtype = MEDIASUBTYPE_CVD_SUBPICTURE;
@@ -913,26 +996,23 @@ bool CBaseSplitterFileEx::Read(ps2audhdr& h, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- if(BitRead(16, true) != 'SS')
+ if(BitRead(16, true) != 'SS') {
return(false);
+ }
__int64 pos = GetPos();
- while(BitRead(16, true) == 'SS')
- {
+ while(BitRead(16, true) == 'SS') {
DWORD tag = (DWORD)BitRead(32, true);
DWORD size = 0;
-
- if(tag == 'SShd')
- {
+
+ if(tag == 'SShd') {
BitRead(32);
ByteRead((BYTE*)&size, sizeof(size));
ASSERT(size == 0x18);
Seek(GetPos());
ByteRead((BYTE*)&h, sizeof(h));
- }
- else if(tag == 'SSbd')
- {
+ } else if(tag == 'SSbd') {
BitRead(32);
ByteRead((BYTE*)&size, sizeof(size));
break;
@@ -941,11 +1021,13 @@ bool CBaseSplitterFileEx::Read(ps2audhdr& h, CMediaType* pmt)
Seek(pos);
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
WAVEFORMATEXPS2 wfe;
- wfe.wFormatTag =
- h.unk1 == 0x01 ? WAVE_FORMAT_PS2_PCM :
+ wfe.wFormatTag =
+ h.unk1 == 0x01 ? WAVE_FORMAT_PS2_PCM :
h.unk1 == 0x10 ? WAVE_FORMAT_PS2_ADPCM :
WAVE_FORMAT_UNKNOWN;
wfe.nChannels = (WORD)h.channels;
@@ -967,7 +1049,9 @@ bool CBaseSplitterFileEx::Read(ps2subhdr& h, CMediaType* pmt)
{
memset(&h, 0, sizeof(h));
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
pmt->majortype = MEDIATYPE_Subtitle;
pmt->subtype = MEDIASUBTYPE_PS2_SUB;
@@ -982,19 +1066,22 @@ bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync)
BitByteAlign();
- if(m_tslen == 0)
- {
+ if(m_tslen == 0) {
__int64 pos = GetPos();
- for(int i = 0; i < 192; i++)
- {
- if(BitRead(8, true) == 0x47)
- {
+ for(int i = 0; i < 192; i++) {
+ if(BitRead(8, true) == 0x47) {
__int64 pos = GetPos();
Seek(pos + 188);
- if(BitRead(8, true) == 0x47) {m_tslen = 188; break;} // TS stream
+ if(BitRead(8, true) == 0x47) {
+ m_tslen = 188; // TS stream
+ break;
+ }
Seek(pos + 192);
- if(BitRead(8, true) == 0x47) {m_tslen = 192; break;} // M2TS stream
+ if(BitRead(8, true) == 0x47) {
+ m_tslen = 192; // M2TS stream
+ break;
+ }
}
BitRead(8);
@@ -1002,32 +1089,35 @@ bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync)
Seek(pos);
- if(m_tslen == 0)
- {
+ if(m_tslen == 0) {
return(false);
}
}
- if(fSync)
- {
- for(int i = 0; i < m_tslen; i++)
- {
- if(BitRead(8, true) == 0x47)
- {
- if(i == 0) break;
+ if(fSync) {
+ for(int i = 0; i < m_tslen; i++) {
+ if(BitRead(8, true) == 0x47) {
+ if(i == 0) {
+ break;
+ }
Seek(GetPos()+m_tslen);
- if(BitRead(8, true) == 0x47) {Seek(GetPos()-m_tslen); break;}
+ if(BitRead(8, true) == 0x47) {
+ Seek(GetPos()-m_tslen);
+ break;
+ }
}
BitRead(8);
- if(i == m_tslen-1)
+ if(i == m_tslen-1) {
return(false);
+ }
}
}
- if(BitRead(8, true) != 0x47)
+ if(BitRead(8, true) != 0x47) {
return(false);
+ }
h.next = GetPos() + m_tslen;
@@ -1043,12 +1133,10 @@ bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync)
h.bytes = 188 - 4;
- if(h.adapfield)
- {
+ if(h.adapfield) {
h.length = (BYTE)BitRead(8);
- if(h.length > 0)
- {
+ if(h.length > 0) {
h.discontinuity = BitRead(1);
h.randomaccess = BitRead(1);
h.priority = BitRead(1);
@@ -1060,8 +1148,7 @@ bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync)
int i = 1;
- if(h.fPCR)
- {
+ if(h.fPCR) {
h.PCR = BitRead(33);
BitRead(6);
UINT64 PCRExt = BitRead(9);
@@ -1071,13 +1158,17 @@ bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync)
ASSERT(i <= h.length);
- for(; i < h.length; i++)
+ for(; i < h.length; i++) {
BitRead(8);
+ }
}
h.bytes -= h.length+1;
- if(h.bytes < 0) {ASSERT(0); return false;}
+ if(h.bytes < 0) {
+ ASSERT(0);
+ return false;
+ }
}
return true;
@@ -1086,7 +1177,9 @@ bool CBaseSplitterFileEx::Read(trhdr& h, bool fSync)
bool CBaseSplitterFileEx::Read(trsechdr& h)
{
BYTE pointer_field = BitRead(8);
- while(pointer_field-- > 0) BitRead(8);
+ while(pointer_field-- > 0) {
+ BitRead(8);
+ }
h.table_id = BitRead(8);
h.section_syntax_indicator = BitRead(1);
h.zero = BitRead(1);
@@ -1107,18 +1200,18 @@ bool CBaseSplitterFileEx::Read(pvahdr& h, bool fSync)
BitByteAlign();
- if(fSync)
- {
- for(int i = 0; i < 65536; i++)
- {
- if((BitRead(64, true)&0xfffffc00ffe00000i64) == 0x4156000055000000i64)
+ if(fSync) {
+ for(int i = 0; i < 65536; i++) {
+ if((BitRead(64, true)&0xfffffc00ffe00000i64) == 0x4156000055000000i64) {
break;
+ }
BitRead(8);
}
}
- if((BitRead(64, true)&0xfffffc00ffe00000i64) != 0x4156000055000000i64)
+ if((BitRead(64, true)&0xfffffc00ffe00000i64) != 0x4156000055000000i64) {
return(false);
+ }
h.sync = (WORD)BitRead(16);
h.streamid = (BYTE)BitRead(8);
@@ -1130,24 +1223,28 @@ bool CBaseSplitterFileEx::Read(pvahdr& h, bool fSync)
h.prebytes = BitRead(2);
h.length = (WORD)BitRead(16);
- if(h.length > 6136)
+ if(h.length > 6136) {
return(false);
+ }
__int64 pos = GetPos();
- if(h.streamid == 1 && h.fpts)
- {
+ if(h.streamid == 1 && h.fpts) {
h.pts = 10000*BitRead(32)/90 + m_rtPTSOffset;
- }
- else if(h.streamid == 2 && (h.fpts || (BitRead(32, true)&0xffffffe0) == 0x000001c0))
- {
+ } else if(h.streamid == 2 && (h.fpts || (BitRead(32, true)&0xffffffe0) == 0x000001c0)) {
BYTE b;
- if(!NextMpegStartCode(b, 4)) return(false);
+ if(!NextMpegStartCode(b, 4)) {
+ return(false);
+ }
peshdr h2;
- if(!Read(h2, b)) return(false);
+ if(!Read(h2, b)) {
+ return(false);
+ }
// Maybe bug, code before: if(h.fpts = h2.fpts) h.pts = h2.pts;
h.fpts = h2.fpts;
- if(h.fpts) h.pts = h2.pts;
+ if(h.fpts) {
+ h.pts = h2.pts;
+ }
}
BitRead(8*h.prebytes);
@@ -1159,26 +1256,27 @@ bool CBaseSplitterFileEx::Read(pvahdr& h, bool fSync)
void CBaseSplitterFileEx::RemoveMpegEscapeCode(BYTE* dst, BYTE* src, int length)
-{
- int si=0;
+{
+ int si=0;
int di=0;
- while(si+2<length){
- //remove escapes (very rare 1:2^22)
- if(src[si+2]>3){
- dst[di++]= src[si++];
- dst[di++]= src[si++];
- }else if(src[si]==0 && src[si+1]==0){
- if(src[si+2]==3){ //escape
- dst[di++]= 0;
- dst[di++]= 0;
- si+=3;
- continue;
- }else //next start code
- return;
- }
-
- dst[di++]= src[si++];
- }
+ while(si+2<length) {
+ //remove escapes (very rare 1:2^22)
+ if(src[si+2]>3) {
+ dst[di++]= src[si++];
+ dst[di++]= src[si++];
+ } else if(src[si]==0 && src[si+1]==0) {
+ if(src[si+2]==3) { //escape
+ dst[di++]= 0;
+ dst[di++]= 0;
+ si+=3;
+ continue;
+ } else { //next start code
+ return;
+ }
+ }
+
+ dst[di++]= src[si++];
+ }
}
bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
@@ -1187,10 +1285,8 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
DWORD dwStartCode;
- while(GetPos() < endpos+4 /*&& BitRead(32, true) == 0x00000001*/ && (!h.spslen || !h.ppslen))
- {
- if (BitRead(32, true) != 0x00000001)
- {
+ while(GetPos() < endpos+4 /*&& BitRead(32, true) == 0x00000001*/ && (!h.spslen || !h.ppslen)) {
+ if (BitRead(32, true) != 0x00000001) {
BitRead(8);
continue;
}
@@ -1198,9 +1294,8 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
BitRead(32);
BYTE id = BitRead(8);
-
- if((id&0x9f) == 0x07 && (id&0x60) != 0)
- {
+
+ if((id&0x9f) == 0x07 && (id&0x60) != 0) {
#if 1
BYTE SPSTemp[MAX_SPS];
BYTE SPSBuff[MAX_SPS];
@@ -1221,10 +1316,8 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
gb.UExpGolombRead(); // seq_parameter_set_id
- if(h.profile >= 100) // high profile
- {
- if(gb.UExpGolombRead() == 3) // chroma_format_idc
- {
+ if(h.profile >= 100) { // high profile
+ if(gb.UExpGolombRead() == 3) { // chroma_format_idc
gb.BitRead(1); // residue_transform_flag
}
@@ -1236,26 +1329,25 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
if(gb.BitRead(1)) // seq_scaling_matrix_present_flag
for(int i = 0; i < 8; i++)
if(gb.BitRead(1)) // seq_scaling_list_present_flag
- for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j)
+ for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) {
next = (next + gb.SExpGolombRead() + 256) & 255;
+ }
}
gb.UExpGolombRead(); // log2_max_frame_num_minus4
UINT64 pic_order_cnt_type = gb.UExpGolombRead();
- if(pic_order_cnt_type == 0)
- {
+ if(pic_order_cnt_type == 0) {
gb.UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4
- }
- else if(pic_order_cnt_type == 1)
- {
+ } else if(pic_order_cnt_type == 1) {
gb.BitRead(1); // delta_pic_order_always_zero_flag
gb.SExpGolombRead(); // offset_for_non_ref_pic
gb.SExpGolombRead(); // offset_for_top_to_bottom_field
UINT64 num_ref_frames_in_pic_order_cnt_cycle = gb.UExpGolombRead();
- for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++)
- gb.SExpGolombRead(); // offset_for_ref_frame[i]
+ for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
+ gb.SExpGolombRead(); // offset_for_ref_frame[i]
+ }
}
gb.UExpGolombRead(); // num_ref_frames
@@ -1268,75 +1360,66 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
h.width = (pic_width_in_mbs_minus1 + 1) * 16;
h.height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16;
- if (h.height == 1088) h.height = 1080; // Prevent blur lines
+ if (h.height == 1088) {
+ h.height = 1080; // Prevent blur lines
+ }
- if (!frame_mbs_only_flag)
- gb.BitRead(1); // mb_adaptive_frame_field_flag
+ if (!frame_mbs_only_flag) {
+ gb.BitRead(1); // mb_adaptive_frame_field_flag
+ }
gb.BitRead(1); // direct_8x8_inference_flag
- if (gb.BitRead(1)) // frame_cropping_flag
- {
+ if (gb.BitRead(1)) { // frame_cropping_flag
gb.UExpGolombRead(); // frame_cropping_rect_left_offset
gb.UExpGolombRead(); // frame_cropping_rect_right_offset
gb.UExpGolombRead(); // frame_cropping_rect_top_offset
gb.UExpGolombRead(); // frame_cropping_rect_bottom_offset
}
-
- if (gb.BitRead(1)) // vui_parameters_present_flag
- {
- if (gb.BitRead(1)) // aspect_ratio_info_present_flag
- {
- if (255==(BYTE)gb.BitRead(8)) // aspect_ratio_idc)
- {
+
+ if (gb.BitRead(1)) { // vui_parameters_present_flag
+ if (gb.BitRead(1)) { // aspect_ratio_info_present_flag
+ if (255==(BYTE)gb.BitRead(8)) { // aspect_ratio_idc)
gb.BitRead(16); // sar_width
gb.BitRead(16); // sar_height
}
}
- if (gb.BitRead(1)) // overscan_info_present_flag
- {
+ if (gb.BitRead(1)) { // overscan_info_present_flag
gb.BitRead(1); // overscan_appropriate_flag
}
- if (gb.BitRead(1)) // video_signal_type_present_flag
- {
+ if (gb.BitRead(1)) { // video_signal_type_present_flag
gb.BitRead(3); // video_format
gb.BitRead(1); // video_full_range_flag
- if(gb.BitRead(1)) // colour_description_present_flag
- {
+ if(gb.BitRead(1)) { // colour_description_present_flag
gb.BitRead(8); // colour_primaries
gb.BitRead(8); // transfer_characteristics
gb.BitRead(8); // matrix_coefficients
}
}
- if(gb.BitRead(1)) // chroma_location_info_present_flag
- {
+ if(gb.BitRead(1)) { // chroma_location_info_present_flag
gb.UExpGolombRead(); // chroma_sample_loc_type_top_field
gb.UExpGolombRead(); // chroma_sample_loc_type_bottom_field
}
- if (gb.BitRead(1)) // timing_info_present_flag
- {
+ if (gb.BitRead(1)) { // timing_info_present_flag
num_units_in_tick = gb.BitRead(32);
time_scale = gb.BitRead(32);
fixed_frame_rate_flag = gb.BitRead(1);
// Trick for weird parameters (10x to Madshi)!
- if ((num_units_in_tick < 1000) || (num_units_in_tick > 1001))
- {
- if ((time_scale % num_units_in_tick != 0) && ((time_scale*1001) % num_units_in_tick == 0))
- {
+ if ((num_units_in_tick < 1000) || (num_units_in_tick > 1001)) {
+ if ((time_scale % num_units_in_tick != 0) && ((time_scale*1001) % num_units_in_tick == 0)) {
time_scale = (time_scale * 1001) / num_units_in_tick;
num_units_in_tick = 1001;
- }
- else
- {
+ } else {
time_scale = (time_scale * 1000) / num_units_in_tick;
num_units_in_tick = 1000;
}
}
time_scale = time_scale / 2; // VUI consider fields even for progressive stream : divide by 2!
- if (time_scale)
+ if (time_scale) {
h.AvgTimePerFrame = (10000000I64*num_units_in_tick)/time_scale;
+ }
}
}
@@ -1354,10 +1437,8 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
UExpGolombRead(); // seq_parameter_set_id
- if(h.profile >= 100) // high profile
- {
- if(UExpGolombRead() == 3) // chroma_format_idc
- {
+ if(h.profile >= 100) { // high profile
+ if(UExpGolombRead() == 3) { // chroma_format_idc
BitRead(1); // residue_transform_flag
}
@@ -1369,26 +1450,25 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
if(BitRead(1)) // seq_scaling_matrix_present_flag
for(int i = 0; i < 8; i++)
if(BitRead(1)) // seq_scaling_list_present_flag
- for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j)
+ for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) {
next = (next + SExpGolombRead() + 256) & 255;
+ }
}
UExpGolombRead(); // log2_max_frame_num_minus4
UINT64 pic_order_cnt_type = UExpGolombRead();
- if(pic_order_cnt_type == 0)
- {
+ if(pic_order_cnt_type == 0) {
UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4
- }
- else if(pic_order_cnt_type == 1)
- {
+ } else if(pic_order_cnt_type == 1) {
BitRead(1); // delta_pic_order_always_zero_flag
SExpGolombRead(); // offset_for_non_ref_pic
SExpGolombRead(); // offset_for_top_to_bottom_field
UINT64 num_ref_frames_in_pic_order_cnt_cycle = UExpGolombRead();
- for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++)
- SExpGolombRead(); // offset_for_ref_frame[i]
+ for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
+ SExpGolombRead(); // offset_for_ref_frame[i]
+ }
}
UExpGolombRead(); // num_ref_frames
@@ -1401,119 +1481,112 @@ bool CBaseSplitterFileEx::Read(avchdr& h, int len, CMediaType* pmt)
h.width = (pic_width_in_mbs_minus1 + 1) * 16;
h.height = (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16;
- if (h.height == 1088) h.height = 1080; // Prevent blur lines
+ if (h.height == 1088) {
+ h.height = 1080; // Prevent blur lines
+ }
- if (!frame_mbs_only_flag)
- BitRead(1); // mb_adaptive_frame_field_flag
+ if (!frame_mbs_only_flag) {
+ BitRead(1); // mb_adaptive_frame_field_flag
+ }
BitRead(1); // direct_8x8_inference_flag
- if (BitRead(1)) // frame_cropping_flag
- {
+ if (BitRead(1)) { // frame_cropping_flag
UExpGolombRead(); // frame_cropping_rect_left_offset
UExpGolombRead(); // frame_cropping_rect_right_offset
UExpGolombRead(); // frame_cropping_rect_top_offset
UExpGolombRead(); // frame_cropping_rect_bottom_offset
}
-
- if (BitRead(1)) // vui_parameters_present_flag
- {
- if (BitRead(1)) // aspect_ratio_info_present_flag
- {
- if (255==(BYTE)BitRead(8)) // aspect_ratio_idc)
- {
+
+ if (BitRead(1)) { // vui_parameters_present_flag
+ if (BitRead(1)) { // aspect_ratio_info_present_flag
+ if (255==(BYTE)BitRead(8)) { // aspect_ratio_idc)
BitRead(16); // sar_width
BitRead(16); // sar_height
}
}
- if (BitRead(1)) // overscan_info_present_flag
- {
+ if (BitRead(1)) { // overscan_info_present_flag
BitRead(1); // overscan_appropriate_flag
}
- if (BitRead(1)) // video_signal_type_present_flag
- {
+ if (BitRead(1)) { // video_signal_type_present_flag
BitRead(3); // video_format
BitRead(1); // video_full_range_flag
- if(BitRead(1)) // colour_description_present_flag
- {
+ if(BitRead(1)) { // colour_description_present_flag
BitRead(8); // colour_primaries
BitRead(8); // transfer_characteristics
BitRead(8); // matrix_coefficients
}
}
- if(BitRead(1)) // chroma_location_info_present_flag
- {
+ if(BitRead(1)) { // chroma_location_info_present_flag
UExpGolombRead(); // chroma_sample_loc_type_top_field
UExpGolombRead(); // chroma_sample_loc_type_bottom_field
}
- if (BitRead(1)) // timing_info_present_flag
- {
+ if (BitRead(1)) { // timing_info_present_flag
num_units_in_tick = BitRead(32);
time_scale = BitRead(32);
fixed_frame_rate_flag = BitRead(1);
// Trick for weird parameters (10x to Madshi)!
- if ((num_units_in_tick < 1000) || (num_units_in_tick > 1001))
- {
- if ((time_scale % num_units_in_tick != 0) && ((time_scale*1001) % num_units_in_tick == 0))
- {
+ if ((num_units_in_tick < 1000) || (num_units_in_tick > 1001)) {
+ if ((time_scale % num_units_in_tick != 0) && ((time_scale*1001) % num_units_in_tick == 0)) {
time_scale = (time_scale * 1001) / num_units_in_tick;
num_units_in_tick = 1001;
- }
- else
- {
+ } else {
time_scale = (time_scale * 1000) / num_units_in_tick;
num_units_in_tick = 1000;
}
}
time_scale = time_scale / 2; // VUI consider fields even for progressive stream : divide by 2!
- if (time_scale)
+ if (time_scale) {
h.AvgTimePerFrame = (10000000I64*num_units_in_tick)/time_scale;
+ }
}
}
#endif
- }
- else if((id&0x9f) == 0x08 && (id&0x60) != 0)
- {
+ } else if((id&0x9f) == 0x08 && (id&0x60) != 0) {
h.ppspos = pos;
}
BitByteAlign();
dwStartCode = BitRead(32, true);
- while(GetPos() < endpos+4 && (dwStartCode != 0x00000001) && (dwStartCode & 0xFFFFFF00) != 0x00000100)
- {
+ while(GetPos() < endpos+4 && (dwStartCode != 0x00000001) && (dwStartCode & 0xFFFFFF00) != 0x00000100) {
BitRead(8);
dwStartCode = BitRead(32, true);
}
- if(h.spspos != 0 && h.spslen == 0)
+ if(h.spspos != 0 && h.spslen == 0) {
h.spslen = GetPos() - h.spspos;
- else if(h.ppspos != 0 && h.ppslen == 0)
+ } else if(h.ppspos != 0 && h.ppslen == 0) {
h.ppslen = GetPos() - h.ppspos;
+ }
}
- if(!h.spspos || !h.spslen || !h.ppspos || !h.ppslen)
+ if(!h.spspos || !h.spslen || !h.ppspos || !h.ppslen) {
return(false);
-
+ }
+
if(!h.AvgTimePerFrame || !(
- (h.level == 10) || (h.level == 11) || (h.level == 12) || (h.level == 13) ||
- (h.level == 20) || (h.level == 21) || (h.level == 22) ||
- (h.level == 30) || (h.level == 31) || (h.level == 32) ||
- (h.level == 40) || (h.level == 41) || (h.level == 42) ||
- (h.level == 50) || (h.level == 51)))
+ (h.level == 10) || (h.level == 11) || (h.level == 12) || (h.level == 13) ||
+ (h.level == 20) || (h.level == 21) || (h.level == 22) ||
+ (h.level == 30) || (h.level == 31) || (h.level == 32) ||
+ (h.level == 40) || (h.level == 41) || (h.level == 42) ||
+ (h.level == 50) || (h.level == 51))) {
return(false);
+ }
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
{
int extra = 2+h.spslen-4 + 2+h.ppslen-4;
pmt->majortype = MEDIATYPE_Video;
pmt->subtype = FOURCCMap('1CVA');
-//pmt->subtype = MEDIASUBTYPE_H264; // TODO : put MEDIASUBTYPE_H264 to support Windows 7 decoder !
+ //pmt->subtype = MEDIASUBTYPE_H264; // TODO : put MEDIASUBTYPE_H264 to support Windows 7 decoder !
pmt->formattype = FORMAT_MPEG2_VIDEO;
int len = FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + extra;
MPEG2VIDEOINFO* vi = (MPEG2VIDEOINFO*)DNew BYTE[len];
@@ -1555,8 +1628,7 @@ bool CBaseSplitterFileEx::Read(vc1hdr& h, int len, CMediaType* pmt)
__int64 extrapos = 0, extralen = 0;
int nFrameRateNum = 0, nFrameRateDen = 1;
- if (GetPos() < endpos+4 && BitRead(32, true) == 0x0000010F)
- {
+ if (GetPos() < endpos+4 && BitRead(32, true) == 0x0000010F) {
extrapos = GetPos();
BitRead(32);
@@ -1564,7 +1636,9 @@ bool CBaseSplitterFileEx::Read(vc1hdr& h, int len, CMediaType* pmt)
h.profile = BitRead(2);
// Check if advanced profile
- if (h.profile != 3) return(false);
+ if (h.profile != 3) {
+ return(false);
+ }
h.level = BitRead (3);
h.chromaformat = BitRead (2);
@@ -1584,41 +1658,36 @@ bool CBaseSplitterFileEx::Read(vc1hdr& h, int len, CMediaType* pmt)
h.finterpflag = BitRead (1);
BitRead (1); // reserved
h.psf = BitRead (1);
- if(BitRead (1))
- {
+ if(BitRead (1)) {
int ar = 0;
h.ArX = BitRead (14) + 1;
h.ArY = BitRead (14) + 1;
- if(BitRead (1))
+ if(BitRead (1)) {
ar = BitRead (4);
- // TODO : next is not the true A/R!
- if(ar && ar < 14)
- {
-// h.ArX = ff_vc1_pixel_aspect[ar].num;
-// h.ArY = ff_vc1_pixel_aspect[ar].den;
}
- else if(ar == 15)
- {
+ // TODO : next is not the true A/R!
+ if(ar && ar < 14) {
+ // h.ArX = ff_vc1_pixel_aspect[ar].num;
+ // h.ArY = ff_vc1_pixel_aspect[ar].den;
+ } else if(ar == 15) {
/*h.ArX =*/ BitRead (8);
- /*h.ArY =*/ BitRead (8);
+ /*h.ArY =*/
+ BitRead (8);
}
// Read framerate
const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 },
- ff_vc1_fps_dr[2] = { 1000, 1001 };
+ ff_vc1_fps_dr[2] = { 1000, 1001 };
- if(BitRead (1))
- {
- if(BitRead (1))
- {
+ if(BitRead (1)) {
+ if(BitRead (1)) {
nFrameRateNum = 32;
nFrameRateDen = BitRead (16) + 1;
} else {
int nr, dr;
nr = BitRead (8);
dr = BitRead (4);
- if(nr && nr < 8 && dr && dr < 3)
- {
+ if(nr && nr < 8 && dr && dr < 3) {
nFrameRateNum = ff_vc1_fps_dr[dr - 1];
nFrameRateDen = ff_vc1_fps_nr[nr - 1] * 1000;
}
@@ -1631,17 +1700,19 @@ bool CBaseSplitterFileEx::Read(vc1hdr& h, int len, CMediaType* pmt)
extralen = 0;
long parse = 0;
- while (GetPos() < endpos+4 && ((parse == 0x0000010E) || (parse & 0xFFFFFF00) != 0x00000100))
- {
+ while (GetPos() < endpos+4 && ((parse == 0x0000010E) || (parse & 0xFFFFFF00) != 0x00000100)) {
parse = (parse<<8) | BitRead(8);
extralen++;
}
}
- if(!extrapos || !extralen)
+ if(!extrapos || !extralen) {
return(false);
+ }
- if(!pmt) return(true);
+ if(!pmt) {
+ return(true);
+ }
{
//pmt->majortype = MEDIATYPE_Video;
@@ -1695,8 +1766,7 @@ bool CBaseSplitterFileEx::Read(vc1hdr& h, int len, CMediaType* pmt)
bool CBaseSplitterFileEx::Read(dvbsub& h, int len, CMediaType* pmt)
{
- if ((BitRead(32, true) & 0xFFFFFF00) == 0x20000f00)
- {
+ if ((BitRead(32, true) & 0xFFFFFF00) == 0x20000f00) {
static const SUBTITLEINFO SubFormat = { 0, "", L"" };
pmt->majortype = MEDIATYPE_Subtitle;
diff --git a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h
index 0d55a9366..942cfa4bc 100644
--- a/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h
+++ b/src/filters/parser/BaseSplitter/BaseSplitterFileEx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -42,22 +42,19 @@ public:
enum mpeg_t {mpegunk, mpeg1, mpeg2};
- struct pshdr
- {
+ struct pshdr {
mpeg_t type;
UINT64 scr, bitrate;
};
- struct pssyshdr
- {
+ struct pssyshdr {
DWORD rate_bound;
BYTE video_bound, audio_bound;
bool fixed_rate, csps;
bool sys_video_loc_flag, sys_audio_loc_flag;
};
- struct peshdr
- {
+ struct peshdr {
WORD len;
BYTE type:2, fpts:1, fdts:1;
@@ -71,7 +68,9 @@ public:
BYTE escr:1, esrate:1, dsmtrickmode:1, morecopyright:1, crc:1, extension:1;
BYTE hdrlen;
- struct peshdr() {memset(this, 0, sizeof(*this));}
+ struct peshdr() {
+ memset(this, 0, sizeof(*this));
+ }
};
class seqhdr
@@ -116,7 +115,7 @@ public:
WORD copyright:1;
WORD original:1;
WORD emphasis:2;
-
+
int nSamplesPerSec, FrameSize, nBytesPerSec;
REFERENCE_TIME rtDuration;
};
@@ -232,7 +231,7 @@ public:
public:
// nothing ;)
};
-
+
class svcdspuhdr
{
public:
@@ -264,8 +263,7 @@ public:
// nothing ;)
};
- struct trhdr
- {
+ struct trhdr {
BYTE sync; // 0x47
BYTE error:1;
BYTE payloadstart:1;
@@ -292,8 +290,7 @@ public:
__int64 next;
};
- struct trsechdr
- {
+ struct trsechdr {
BYTE table_id;
WORD section_syntax_indicator:1;
WORD zero:1;
@@ -309,8 +306,7 @@ public:
// http://www.technotrend.de/download/av_format_v1.pdf
- struct pvahdr
- {
+ struct pvahdr {
WORD sync; // 'VA'
BYTE streamid; // 1 - video, 2 - audio
BYTE counter;
@@ -323,16 +319,14 @@ public:
REFERENCE_TIME pts;
};
- struct avchdr
- {
+ struct avchdr {
BYTE profile, level;
unsigned int width, height;
__int64 spspos, spslen;
__int64 ppspos, ppslen;
__int64 AvgTimePerFrame;
- avchdr()
- {
+ avchdr() {
spspos = 0;
spslen = 0;
ppspos = 0;
@@ -341,8 +335,7 @@ public:
}
};
- struct vc1hdr
- {
+ struct vc1hdr {
BYTE profile;
BYTE level;
BYTE chromaformat;
@@ -359,8 +352,7 @@ public:
unsigned int width, height;
};
- struct dvbsub
- {
+ struct dvbsub {
};
#pragma pack(pop)
diff --git a/src/filters/parser/BaseSplitter/MultiFiles.cpp b/src/filters/parser/BaseSplitter/MultiFiles.cpp
index beb3a2e84..853fca54c 100644
--- a/src/filters/parser/BaseSplitter/MultiFiles.cpp
+++ b/src/filters/parser/BaseSplitter/MultiFiles.cpp
@@ -28,10 +28,10 @@
IMPLEMENT_DYNAMIC(CMultiFiles, CObject)
CMultiFiles::CMultiFiles()
- : m_hFile(INVALID_HANDLE_VALUE)
- , m_llTotalLength(0)
- , m_nCurPart(-1)
- , m_pCurrentPTSOffset(NULL)
+ : m_hFile(INVALID_HANDLE_VALUE)
+ , m_llTotalLength(0)
+ , m_nCurPart(-1)
+ , m_pCurrentPTSOffset(NULL)
{
}
@@ -59,11 +59,12 @@ BOOL CMultiFiles::OpenFiles(CAtlList<CHdmvClipInfo::PlaylistItem>& files, UINT n
REFERENCE_TIME rtDur = 0;
Reset();
- while(pos)
- {
+ while(pos) {
CHdmvClipInfo::PlaylistItem& s = files.GetNext(pos);
m_strFiles.Add(s.m_strFileName);
- if (!OpenPart(nPos)) return false;
+ if (!OpenPart(nPos)) {
+ return false;
+ }
llSize.QuadPart = 0;
GetFileSizeEx (m_hFile, &llSize);
@@ -74,8 +75,10 @@ BOOL CMultiFiles::OpenFiles(CAtlList<CHdmvClipInfo::PlaylistItem>& files, UINT n
nPos++;
}
- if (files.GetCount() > 1) ClosePart();
-
+ if (files.GetCount() > 1) {
+ ClosePart();
+ }
+
return TRUE;
}
@@ -85,21 +88,17 @@ ULONGLONG CMultiFiles::Seek(LONGLONG lOff, UINT nFrom)
LARGE_INTEGER llNewPos;
LARGE_INTEGER llOff;
- if (m_strFiles.GetCount() == 1)
- {
+ if (m_strFiles.GetCount() == 1) {
llOff.QuadPart = lOff;
SetFilePointerEx (m_hFile, llOff, &llNewPos, nFrom);
return llNewPos.QuadPart;
- }
- else
- {
+ } else {
LONGLONG lAbsolutePos = GetAbsolutePosition(lOff, nFrom);
int nNewPart = 0;
ULONGLONG llSum = 0;
- while (m_FilesSize[nNewPart]+llSum <= lAbsolutePos)
- {
+ while (m_FilesSize[nNewPart]+llSum <= lAbsolutePos) {
llSum += m_FilesSize[nNewPart];
nNewPart++;
}
@@ -117,42 +116,39 @@ ULONGLONG CMultiFiles::GetAbsolutePosition(LONGLONG lOff, UINT nFrom)
LARGE_INTEGER llNoMove = {0, 0};
LARGE_INTEGER llCurPos;
- switch (nFrom)
- {
- case begin :
- return lOff;
- case current :
- SetFilePointerEx (m_hFile, llNoMove, &llCurPos, FILE_CURRENT);
- return llCurPos.QuadPart + lOff;
- case end :
- return m_llTotalLength - lOff;
- default:
- return 0; // just used to quash "not all control paths return a value" warning
+ switch (nFrom) {
+ case begin :
+ return lOff;
+ case current :
+ SetFilePointerEx (m_hFile, llNoMove, &llCurPos, FILE_CURRENT);
+ return llCurPos.QuadPart + lOff;
+ case end :
+ return m_llTotalLength - lOff;
+ default:
+ return 0; // just used to quash "not all control paths return a value" warning
}
}
ULONGLONG CMultiFiles::GetLength() const
{
- if (m_strFiles.GetCount() == 1)
- {
+ if (m_strFiles.GetCount() == 1) {
LARGE_INTEGER llSize;
GetFileSizeEx (m_hFile, &llSize);
return llSize.QuadPart;
- }
- else
+ } else {
return m_llTotalLength;
+ }
}
UINT CMultiFiles::Read(void* lpBuf, UINT nCount)
{
DWORD dwRead;
- do
- {
- if (!ReadFile(m_hFile, lpBuf, nCount, &dwRead, NULL))
+ do {
+ if (!ReadFile(m_hFile, lpBuf, nCount, &dwRead, NULL)) {
break;
-
- if (dwRead != nCount && m_nCurPart < m_strFiles.GetCount()-1)
- {
+ }
+
+ if (dwRead != nCount && m_nCurPart < m_strFiles.GetCount()-1) {
OpenPart (m_nCurPart+1);
lpBuf = (void*)((BYTE*)lpBuf + dwRead);
nCount -= dwRead;
@@ -174,10 +170,9 @@ CMultiFiles::~CMultiFiles()
BOOL CMultiFiles::OpenPart(int nPart)
{
- if (m_nCurPart == nPart)
+ if (m_nCurPart == nPart) {
return TRUE;
- else
- {
+ } else {
CString fn;
ClosePart();
@@ -185,10 +180,11 @@ BOOL CMultiFiles::OpenPart(int nPart)
fn = m_strFiles.GetAt(nPart);
m_hFile = CreateFile (fn, GENERIC_READ, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- if (m_hFile != INVALID_HANDLE_VALUE)
- {
+ if (m_hFile != INVALID_HANDLE_VALUE) {
m_nCurPart = nPart;
- if (m_pCurrentPTSOffset != NULL) *m_pCurrentPTSOffset = m_rtPtsOffsets[nPart];
+ if (m_pCurrentPTSOffset != NULL) {
+ *m_pCurrentPTSOffset = m_rtPtsOffsets[nPart];
+ }
}
return (m_hFile != INVALID_HANDLE_VALUE);
@@ -198,8 +194,7 @@ BOOL CMultiFiles::OpenPart(int nPart)
void CMultiFiles::ClosePart()
{
- if (m_hFile != INVALID_HANDLE_VALUE)
- {
+ if (m_hFile != INVALID_HANDLE_VALUE) {
CloseHandle (m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
m_nCurPart = -1;
diff --git a/src/filters/parser/BaseSplitter/MultiFiles.h b/src/filters/parser/BaseSplitter/MultiFiles.h
index b07862a0a..dbb700fed 100644
--- a/src/filters/parser/BaseSplitter/MultiFiles.h
+++ b/src/filters/parser/BaseSplitter/MultiFiles.h
@@ -31,7 +31,7 @@ class CMultiFiles : public CObject
DECLARE_DYNAMIC(CMultiFiles)
public:
-// Flag values
+ // Flag values
enum OpenFlags {
modeRead = (int) 0x00000,
modeWrite = (int) 0x00001,
@@ -50,7 +50,7 @@ public:
osWriteThrough = (int) 0x20000,
osRandomAccess = (int) 0x40000,
osSequentialScan = (int) 0x80000,
- };
+ };
enum Attribute {
normal = 0x00,
@@ -60,16 +60,16 @@ public:
volume = 0x08,
directory = 0x10,
archive = 0x20
- };
+ };
enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };
-// Constructors
+ // Constructors
CMultiFiles();
CString m_strFileName;
-// Operations
+ // Operations
virtual BOOL Open(LPCTSTR lpszFileName, UINT nOpenFlags);
virtual BOOL OpenFiles(CAtlList<CHdmvClipInfo::PlaylistItem>& files, UINT nOpenFlags);
@@ -80,7 +80,7 @@ public:
virtual UINT Read(void* lpBuf, UINT nCount);
virtual void Close();
-// Implementation
+ // Implementation
public:
virtual ~CMultiFiles();
diff --git a/src/filters/parser/BaseSplitter/stdafx.cpp b/src/filters/parser/BaseSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/BaseSplitter/stdafx.cpp
+++ b/src/filters/parser/BaseSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/BaseSplitter/stdafx.h b/src/filters/parser/BaseSplitter/stdafx.h
index 4811c9499..eb1a0a29e 100644
--- a/src/filters/parser/BaseSplitter/stdafx.h
+++ b/src/filters/parser/BaseSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/DSMSplitter/DSMSplitter.cpp b/src/filters/parser/DSMSplitter/DSMSplitter.cpp
index 3b562b417..eaac42a0a 100644
--- a/src/filters/parser/DSMSplitter/DSMSplitter.cpp
+++ b/src/filters/parser/DSMSplitter/DSMSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,26 +28,22 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_DirectShowMedia},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CDSMSplitterFilter), L"MPC - DSM Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CDSMSourceFilter), L"MPC - DSM Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDSMSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CDSMSourceFilter>, NULL, &sudFilter[1]},
};
@@ -61,8 +57,8 @@ STDAPI DllRegisterServer()
str.Format(CString(str), DSMSW);
RegisterSourceFilter(
- CLSID_AsyncReader,
- MEDIASUBTYPE_DirectShowMedia,
+ CLSID_AsyncReader,
+ MEDIASUBTYPE_DirectShowMedia,
str, NULL);
return AMovieDllRegisterServer2(TRUE);
@@ -94,7 +90,10 @@ CDSMSplitterFilter::~CDSMSplitterFilter()
{
}
-static int compare_id(const void* id1, const void* id2) {return (int)*(BYTE*)id1 - (int)*(BYTE*)id2;}
+static int compare_id(const void* id1, const void* id2)
+{
+ return (int)*(BYTE*)id1 - (int)*(BYTE*)id2;
+}
HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
{
@@ -104,8 +103,13 @@ HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CDSMSplitterFile(pAsyncReader, hr, *this, *this));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->m_rtDuration;
@@ -113,8 +117,7 @@ HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
CAtlArray<BYTE> ids;
POSITION pos = m_pFile->m_mts.GetStartPosition();
- while(pos)
- {
+ while(pos) {
BYTE id;
CMediaType mt;
m_pFile->m_mts.GetNextAssoc(pos, id, mt);
@@ -123,8 +126,7 @@ HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
qsort(ids.GetData(), ids.GetCount(), sizeof(BYTE), compare_id);
- for(int i = 0; i < ids.GetCount(); i++)
- {
+ for(int i = 0; i < ids.GetCount(); i++) {
BYTE id = ids[i];
CMediaType& mt = m_pFile->m_mts[id];
@@ -135,24 +137,32 @@ HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mts.Add(mt);
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CBaseSplitterOutputPin(mts, name, this, this, &hr));
-
+
name.Empty();
pos = m_pFile->m_sim[id].GetStartPosition();
- while(pos)
- {
- CStringA key; CStringW value;
+ while(pos) {
+ CStringA key;
+ CStringW value;
m_pFile->m_sim[id].GetNextAssoc(pos, key, value);
pPinOut->SetProperty(CStringW(key), value);
- if(key == "NAME") name = value;
- if(key == "LANG") if((lang = ISO6392ToLanguage(CStringA(CString(value)))).IsEmpty()) lang = value;
+ if(key == "NAME") {
+ name = value;
+ }
+ if(key == "LANG") if((lang = ISO6392ToLanguage(CStringA(CString(value)))).IsEmpty()) {
+ lang = value;
+ }
}
- if(!name.IsEmpty() || !lang.IsEmpty())
- {
- if(!name.IsEmpty()) {if(!lang.IsEmpty()) name += L" (" + lang + L")";}
- else if(!lang.IsEmpty()) name = lang;
+ if(!name.IsEmpty() || !lang.IsEmpty()) {
+ if(!name.IsEmpty()) {
+ if(!lang.IsEmpty()) {
+ name += L" (" + lang + L")";
+ }
+ } else if(!lang.IsEmpty()) {
+ name = lang;
+ }
pPinOut->SetName(name);
}
@@ -160,18 +170,18 @@ HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
}
pos = m_pFile->m_fim.GetStartPosition();
- while(pos)
- {
- CStringA key; CStringW value;
+ while(pos) {
+ CStringA key;
+ CStringW value;
m_pFile->m_fim.GetNextAssoc(pos, key, value);
SetProperty(CStringW(key), value);
}
- for(int i = 0; i < m_resources.GetCount(); i++)
- {
+ for(int i = 0; i < m_resources.GetCount(); i++) {
const CDSMResource& r = m_resources[i];
- if(r.mime == "application/x-truetype-font")
+ if(r.mime == "application/x-truetype-font") {
m_fontinst.InstallFont(r.data);
+ }
}
return m_pOutputs.GetCount() > 0 ? S_OK : E_FAIL;
@@ -192,23 +202,20 @@ bool CDSMSplitterFilter::DemuxLoop()
{
HRESULT hr = S_OK;
- while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining())
- {
+ while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining()) {
dsmp_t type;
UINT64 len;
- if(!m_pFile->Sync(type, len))
+ if(!m_pFile->Sync(type, len)) {
continue;
+ }
__int64 pos = m_pFile->GetPos();
- if(type == DSMP_SAMPLE)
- {
+ if(type == DSMP_SAMPLE) {
CAutoPtr<Packet> p(DNew Packet());
- if(m_pFile->Read(len, p))
- {
- if(p->rtStart != Packet::INVALID_TIME)
- {
+ if(m_pFile->Read(len, p)) {
+ if(p->rtStart != Packet::INVALID_TIME) {
p->rtStart -= m_pFile->m_rtFirst;
p->rtStop -= m_pFile->m_rtFirst;
}
@@ -238,11 +245,14 @@ STDMETHODIMP CDSMSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIM
CheckPointer(pKFs, E_POINTER);
CheckPointer(m_pFile, E_UNEXPECTED);
- if(*pFormat != TIME_FORMAT_MEDIA_TIME) return E_INVALIDARG;
+ if(*pFormat != TIME_FORMAT_MEDIA_TIME) {
+ return E_INVALIDARG;
+ }
// these aren't really the keyframes, but quicky accessable points in the stream
- for(nKFs = 0; nKFs < m_pFile->m_sps.GetCount(); nKFs++)
+ for(nKFs = 0; nKFs < m_pFile->m_sps.GetCount(); nKFs++) {
pKFs[nKFs] = m_pFile->m_sps[nKFs].rt;
+ }
return S_OK;
}
diff --git a/src/filters/parser/DSMSplitter/DSMSplitter.h b/src/filters/parser/DSMSplitter/DSMSplitter.h
index ef57df9a3..616d84b0d 100644
--- a/src/filters/parser/DSMSplitter/DSMSplitter.h
+++ b/src/filters/parser/DSMSplitter/DSMSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,7 +27,7 @@
#include "../BaseSplitter/BaseSplitter.h"
class __declspec(uuid("0912B4DD-A30A-4568-B590-7179EBB420EC"))
-CDSMSplitterFilter : public CBaseSplitterFilter
+ CDSMSplitterFilter : public CBaseSplitterFilter
{
protected:
CAutoPtr<CDSMSplitterFile> m_pFile;
@@ -48,7 +48,7 @@ public:
};
class __declspec(uuid("803E8280-F3CE-4201-982C-8CD8FB512004"))
-CDSMSourceFilter : public CDSMSplitterFilter
+ CDSMSourceFilter : public CDSMSplitterFilter
{
public:
CDSMSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp b/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp
index cb58bd929..b46bc4cd2 100644
--- a/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp
+++ b/src/filters/parser/DSMSplitter/DSMSplitterFile.cpp
@@ -3,12 +3,14 @@
#include "../../../DSUtil/DSUtil.h"
#include <moreuuids.h>
-CDSMSplitterFile::CDSMSplitterFile(IAsyncReader* pReader, HRESULT& hr, IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap)
+CDSMSplitterFile::CDSMSplitterFile(IAsyncReader* pReader, HRESULT& hr, IDSMResourceBagImpl& res, IDSMChapterBagImpl& chap)
: CBaseSplitterFile(pReader, hr, DEFAULT_CACHE_LENGTH, false)
, m_rtFirst(0)
, m_rtDuration(0)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
hr = Init(res, chap);
}
@@ -17,8 +19,9 @@ HRESULT CDSMSplitterFile::Init(IDSMResourceBagImpl& res, IDSMChapterBagImpl& cha
{
Seek(0);
- if(BitRead(DSMSW_SIZE<<3) != DSMSW || BitRead(5) != DSMP_FILEINFO)
+ if(BitRead(DSMSW_SIZE<<3) != DSMSW || BitRead(5) != DSMP_FILEINFO) {
return E_FAIL;
+ }
Seek(0);
@@ -35,68 +38,72 @@ HRESULT CDSMSplitterFile::Init(IDSMResourceBagImpl& res, IDSMChapterBagImpl& cha
// examine the beginning of the file ...
- while(Sync(type, len, 0))
- {
+ while(Sync(type, len, 0)) {
__int64 pos = GetPos();
- if(type == DSMP_MEDIATYPE)
- {
+ if(type == DSMP_MEDIATYPE) {
BYTE id;
CMediaType mt;
- if(Read(len, id, mt)) m_mts[id] = mt;
- }
- else if(type == DSMP_SAMPLE)
- {
+ if(Read(len, id, mt)) {
+ m_mts[id] = mt;
+ }
+ } else if(type == DSMP_SAMPLE) {
Packet p;
- if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME)
- {
+ if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) {
m_rtFirst = p.rtStart;
break;
}
+ } else if(type == DSMP_FILEINFO) {
+ if((BYTE)BitRead(8) > DSMF_VERSION) {
+ return E_FAIL;
+ }
+ Read(len-1, m_fim);
+ } else if(type == DSMP_STREAMINFO) {
+ Read(len-1, m_sim[(BYTE)BitRead(8)]);
+ } else if(type == DSMP_SYNCPOINTS) {
+ Read(len, m_sps);
+ } else if(type == DSMP_RESOURCE) {
+ Read(len, res);
+ } else if(type == DSMP_CHAPTERS) {
+ Read(len, chap);
}
- else if(type == DSMP_FILEINFO) {if((BYTE)BitRead(8) > DSMF_VERSION) return E_FAIL; Read(len-1, m_fim);}
- else if(type == DSMP_STREAMINFO) {Read(len-1, m_sim[(BYTE)BitRead(8)]);}
- else if(type == DSMP_SYNCPOINTS) {Read(len, m_sps);}
- else if(type == DSMP_RESOURCE) {Read(len, res);}
- else if(type == DSMP_CHAPTERS) {Read(len, chap);}
Seek(pos + len);
}
- if(type != DSMP_SAMPLE)
+ if(type != DSMP_SAMPLE) {
return E_FAIL;
+ }
- // ... and the end
+ // ... and the end
if(IsRandomAccess())
- for(int i = 1, j = (int)((GetLength()+limit/2)/limit); i <= j; i++)
- {
- __int64 seekpos = max(0, (__int64)GetLength()-i*limit);
- Seek(seekpos);
-
- while(Sync(type, len, limit) && GetPos() < seekpos+limit)
- {
- __int64 pos = GetPos();
+ for(int i = 1, j = (int)((GetLength()+limit/2)/limit); i <= j; i++) {
+ __int64 seekpos = max(0, (__int64)GetLength()-i*limit);
+ Seek(seekpos);
+
+ while(Sync(type, len, limit) && GetPos() < seekpos+limit) {
+ __int64 pos = GetPos();
+
+ if(type == DSMP_SAMPLE) {
+ Packet p;
+ if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) {
+ m_rtDuration = max(m_rtDuration, p.rtStop - m_rtFirst); // max isn't really needed, only for safety
+ i = j;
+ }
+ } else if(type == DSMP_SYNCPOINTS) {
+ Read(len, m_sps);
+ } else if(type == DSMP_RESOURCE) {
+ Read(len, res);
+ } else if(type == DSMP_CHAPTERS) {
+ Read(len, chap);
+ }
- if(type == DSMP_SAMPLE)
- {
- Packet p;
- if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME)
- {
- m_rtDuration = max(m_rtDuration, p.rtStop - m_rtFirst); // max isn't really needed, only for safety
- i = j;
- }
+ Seek(pos + len);
}
- else if(type == DSMP_SYNCPOINTS) {Read(len, m_sps);}
- else if(type == DSMP_RESOURCE) {Read(len, res);}
- else if(type == DSMP_CHAPTERS) {Read(len, chap);}
-
- Seek(pos + len);
}
- }
- if(m_rtFirst < 0)
- {
+ if(m_rtFirst < 0) {
m_rtDuration += m_rtFirst;
m_rtFirst = 0;
}
@@ -116,10 +123,10 @@ bool CDSMSplitterFile::Sync(UINT64& syncpos, dsmp_t& type, UINT64& len, __int64
limit += DSMSW_SIZE;
- for(UINT64 id = 0; (id&((1ui64<<(DSMSW_SIZE<<3))-1)) != DSMSW; id = (id << 8) | (BYTE)BitRead(8))
- {
- if(limit-- <= 0 || GetRemaining() <= 2)
+ for(UINT64 id = 0; (id&((1ui64<<(DSMSW_SIZE<<3))-1)) != DSMSW; id = (id << 8) | (BYTE)BitRead(8)) {
+ if(limit-- <= 0 || GetRemaining() <= 2) {
return(false);
+ }
}
syncpos = GetPos() - (DSMSW_SIZE<<3);
@@ -140,14 +147,20 @@ bool CDSMSplitterFile::Read(__int64 len, BYTE& id, CMediaType& mt)
ByteRead((BYTE*)&mt.formattype, sizeof(mt.formattype));
len -= 5 + sizeof(GUID)*3;
ASSERT(len >= 0);
- if(len > 0) {mt.AllocFormatBuffer((LONG)len); ByteRead(mt.Format(), mt.FormatLength());}
- else mt.ResetFormatBuffer();
+ if(len > 0) {
+ mt.AllocFormatBuffer((LONG)len);
+ ByteRead(mt.Format(), mt.FormatLength());
+ } else {
+ mt.ResetFormatBuffer();
+ }
return true;
}
bool CDSMSplitterFile::Read(__int64 len, Packet* p, bool fData)
{
- if(!p) return false;
+ if(!p) {
+ return false;
+ }
p->TrackNumber = (DWORD)BitRead(8);
p->bSyncPoint = (BOOL)BitRead(1);
@@ -155,21 +168,17 @@ bool CDSMSplitterFile::Read(__int64 len, Packet* p, bool fData)
int iTimeStamp = (int)BitRead(3);
int iDuration = (int)BitRead(3);
- if(fSign && !iTimeStamp)
- {
+ if(fSign && !iTimeStamp) {
ASSERT(!iDuration);
p->rtStart = Packet::INVALID_TIME;
p->rtStop = Packet::INVALID_TIME + 1;
- }
- else
- {
+ } else {
p->rtStart = (REFERENCE_TIME)BitRead(iTimeStamp<<3) * (fSign ? -1 : 1);
p->rtStop = p->rtStart + BitRead(iDuration<<3);
}
- if(fData)
- {
- p->SetCount((INT_PTR)len - (2 + iTimeStamp + iDuration));
+ if(fData) {
+ p->SetCount((INT_PTR)len - (2 + iTimeStamp + iDuration));
ByteRead(p->GetData(), p->GetCount());
}
@@ -181,8 +190,7 @@ bool CDSMSplitterFile::Read(__int64 len, CAtlArray<SyncPoint>& sps)
SyncPoint sp = {0, 0};
sps.RemoveAll();
- while(len > 0)
- {
+ while(len > 0) {
bool fSign = !!BitRead(1);
int iTimeStamp = (int)BitRead(3);
int iFilePos = (int)BitRead(3);
@@ -195,8 +203,7 @@ bool CDSMSplitterFile::Read(__int64 len, CAtlArray<SyncPoint>& sps)
len -= 1 + iTimeStamp + iFilePos;
}
- if(len != 0)
- {
+ if(len != 0) {
sps.RemoveAll();
return false;
}
@@ -208,8 +215,7 @@ bool CDSMSplitterFile::Read(__int64 len, CAtlArray<SyncPoint>& sps)
bool CDSMSplitterFile::Read(__int64 len, CStreamInfoMap& im)
{
- while(len >= 5)
- {
+ while(len >= 5) {
CStringA key;
ByteRead((BYTE*)key.GetBufferSetLength(4), 4);
len -= 4;
@@ -231,7 +237,9 @@ bool CDSMSplitterFile::Read(__int64 len, IDSMResourceBagImpl& res)
len -= Read(len, r.desc);
len -= Read(len, r.mime);
- if(compression != 0) return false; // TODO
+ if(compression != 0) {
+ return false; // TODO
+ }
r.data.SetCount(len);
ByteRead(r.data.GetData(), r.data.GetCount());
@@ -245,8 +253,7 @@ bool CDSMSplitterFile::Read(__int64 len, IDSMChapterBagImpl& chap)
{
CDSMChapter c(0, L"");
- while(len > 0)
- {
+ while(len > 0) {
bool fSign = !!BitRead(1);
int iTimeStamp = (int)BitRead(3);
BitRead(4); // reserved
@@ -269,21 +276,23 @@ __int64 CDSMSplitterFile::Read(__int64 len, CStringW& str)
char c;
CStringA s;
__int64 i = 0;
- while(i++ < len && (c = (char)BitRead(8)) != 0) s += c;
+ while(i++ < len && (c = (char)BitRead(8)) != 0) {
+ s += c;
+ }
str = UTF8To16(s);
return i;
}
__int64 CDSMSplitterFile::FindSyncPoint(REFERENCE_TIME rt)
{
- if(/*!m_sps.IsEmpty()*/ m_sps.GetCount() > 1)
- {
+ if(/*!m_sps.IsEmpty()*/ m_sps.GetCount() > 1) {
int i = range_bsearch(m_sps, m_rtFirst + rt);
return i >= 0 ? m_sps[i].fp : 0;
}
- if(m_rtDuration <= 0 || rt <= m_rtFirst)
+ if(m_rtDuration <= 0 || rt <= m_rtFirst) {
return 0;
+ }
// ok, do the hard way then
@@ -294,25 +303,25 @@ __int64 CDSMSplitterFile::FindSyncPoint(REFERENCE_TIME rt)
__int64 minpos = 0, maxpos = GetLength();
- for(int i = 0; i < 10 && (maxpos - minpos) >= 1024*1024; i++)
- {
+ for(int i = 0; i < 10 && (maxpos - minpos) >= 1024*1024; i++) {
Seek((minpos + maxpos) / 2);
- while(GetPos() < maxpos)
- {
- if(!Sync(syncpos, type, len))
+ while(GetPos() < maxpos) {
+ if(!Sync(syncpos, type, len)) {
continue;
+ }
__int64 pos = GetPos();
- if(type == DSMP_SAMPLE)
- {
+ if(type == DSMP_SAMPLE) {
Packet p;
- if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME)
- {
+ if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) {
REFERENCE_TIME dt = (p.rtStart -= m_rtFirst) - rt;
- if(dt >= 0) maxpos = max((__int64)syncpos - 65536, minpos);
- else minpos = syncpos;
+ if(dt >= 0) {
+ maxpos = max((__int64)syncpos - 65536, minpos);
+ } else {
+ minpos = syncpos;
+ }
break;
}
}
@@ -325,20 +334,21 @@ __int64 CDSMSplitterFile::FindSyncPoint(REFERENCE_TIME rt)
Seek(minpos);
- while(GetRemaining())
- {
- if(!Sync(syncpos, type, len))
+ while(GetRemaining()) {
+ if(!Sync(syncpos, type, len)) {
continue;
+ }
__int64 pos = GetPos();
- if(type == DSMP_SAMPLE)
- {
+ if(type == DSMP_SAMPLE) {
Packet p;
- if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME)
- {
+ if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME) {
REFERENCE_TIME dt = (p.rtStart -= m_rtFirst) - rt;
- if(dt >= 0) {maxpos = (__int64)syncpos; break;}
+ if(dt >= 0) {
+ maxpos = (__int64)syncpos;
+ break;
+ }
}
}
@@ -351,40 +361,35 @@ __int64 CDSMSplitterFile::FindSyncPoint(REFERENCE_TIME rt)
{
POSITION pos = m_mts.GetStartPosition();
- while(pos)
- {
+ while(pos) {
BYTE id;
CMediaType mt;
m_mts.GetNextAssoc(pos, id, mt);
- if(mt.majortype != MEDIATYPE_Text && mt.majortype != MEDIATYPE_Subtitle)
+ if(mt.majortype != MEDIATYPE_Text && mt.majortype != MEDIATYPE_Subtitle) {
ids[id] = 0;
+ }
}
}
__int64 ret = maxpos;
- while(maxpos > 0 && !ids.IsEmpty())
- {
+ while(maxpos > 0 && !ids.IsEmpty()) {
minpos = max(0, maxpos - 65536);
Seek(minpos);
- while(Sync(syncpos, type, len) && GetPos() < maxpos)
- {
+ while(Sync(syncpos, type, len) && GetPos() < maxpos) {
UINT64 pos = GetPos();
- if(type == DSMP_SAMPLE)
- {
+ if(type == DSMP_SAMPLE) {
Packet p;
- if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME && p.bSyncPoint)
- {
+ if(Read(len, &p, false) && p.rtStart != Packet::INVALID_TIME && p.bSyncPoint) {
BYTE id = (BYTE)p.TrackNumber, tmp;
- if(ids.Lookup(id, tmp))
- {
+ if(ids.Lookup(id, tmp)) {
ids.RemoveKey((BYTE)p.TrackNumber);
ret = min(ret, (__int64)syncpos);
}
- }
+ }
}
Seek(pos + len);
diff --git a/src/filters/parser/DSMSplitter/DSMSplitterFile.h b/src/filters/parser/DSMSplitter/DSMSplitterFile.h
index 7c350db2f..b61e5e1b7 100644
--- a/src/filters/parser/DSMSplitter/DSMSplitterFile.h
+++ b/src/filters/parser/DSMSplitter/DSMSplitterFile.h
@@ -14,7 +14,10 @@ public:
CAtlMap<BYTE, CMediaType> m_mts;
REFERENCE_TIME m_rtFirst, m_rtDuration;
- struct SyncPoint {REFERENCE_TIME rt; __int64 fp;};
+ struct SyncPoint {
+ REFERENCE_TIME rt;
+ __int64 fp;
+ };
CAtlArray<SyncPoint> m_sps;
typedef CAtlMap<CStringA, CStringW, CStringElementTraits<CStringA>, CStringElementTraits<CStringW> > CStreamInfoMap;
@@ -30,6 +33,6 @@ public:
bool Read(__int64 len, IDSMResourceBagImpl& res);
bool Read(__int64 len, IDSMChapterBagImpl& chap);
__int64 Read(__int64 len, CStringW& str);
-
+
__int64 FindSyncPoint(REFERENCE_TIME rt);
};
diff --git a/src/filters/parser/DSMSplitter/stdafx.cpp b/src/filters/parser/DSMSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/DSMSplitter/stdafx.cpp
+++ b/src/filters/parser/DSMSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/DSMSplitter/stdafx.h b/src/filters/parser/DSMSplitter/stdafx.h
index cdc946aa0..9b252ac14 100644
--- a/src/filters/parser/DSMSplitter/stdafx.h
+++ b/src/filters/parser/DSMSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/FLVSplitter/FLVSplitter.cpp b/src/filters/parser/FLVSplitter/FLVSplitter.cpp
index e7495dc5a..9dfd01bb6 100644
--- a/src/filters/parser/FLVSplitter/FLVSplitter.cpp
+++ b/src/filters/parser/FLVSplitter/FLVSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,31 +28,26 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_FLV},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut2[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut2[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CFLVSplitterFilter), L"MPC - FLV Splitter (Gabest)", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CFLVSourceFilter), L"MPC - FLV Source (Gabest)", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFLVSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CFLVSourceFilter>, NULL, &sudFilter[1]},
};
@@ -92,8 +87,9 @@ CFLVSplitterFilter::CFLVSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr)
bool CFLVSplitterFilter::ReadTag(Tag& t)
{
- if(m_pFile->GetRemaining() < 15)
+ if(m_pFile->GetRemaining() < 15) {
return false;
+ }
t.PreviousTagSize = (UINT32)m_pFile->BitRead(32);
t.TagType = (BYTE)m_pFile->BitRead(8);
@@ -107,8 +103,9 @@ bool CFLVSplitterFilter::ReadTag(Tag& t)
bool CFLVSplitterFilter::ReadTag(AudioTag& at)
{
- if(!m_pFile->GetRemaining())
+ if(!m_pFile->GetRemaining()) {
return false;
+ }
at.SoundFormat = (BYTE)m_pFile->BitRead(4);
at.SoundRate = (BYTE)m_pFile->BitRead(2);
@@ -120,8 +117,9 @@ bool CFLVSplitterFilter::ReadTag(AudioTag& at)
bool CFLVSplitterFilter::ReadTag(VideoTag& vt)
{
- if(!m_pFile->GetRemaining())
+ if(!m_pFile->GetRemaining()) {
return false;
+ }
vt.FrameType = (BYTE)m_pFile->BitRead(4);
vt.CodecID = (BYTE)m_pFile->BitRead(4);
@@ -132,8 +130,9 @@ bool CFLVSplitterFilter::ReadTag(VideoTag& vt)
#ifndef NOVIDEOTWEAK
bool CFLVSplitterFilter::ReadTag(VideoTweak& vt)
{
- if(!m_pFile->GetRemaining())
+ if(!m_pFile->GetRemaining()) {
return false;
+ }
vt.x = (BYTE)m_pFile->BitRead(4);
vt.y = (BYTE)m_pFile->BitRead(4);
@@ -146,13 +145,16 @@ bool CFLVSplitterFilter::Sync(__int64& pos)
{
m_pFile->Seek(pos);
- while(m_pFile->GetRemaining() >= 15)
- {
+ while(m_pFile->GetRemaining() >= 15) {
__int64 limit = m_pFile->GetRemaining();
while (true) {
BYTE b = m_pFile->BitRead(8);
- if (b == 8 || b == 9) break;
- if (--limit < 15) return false;
+ if (b == 8 || b == 9) {
+ break;
+ }
+ if (--limit < 15) {
+ return false;
+ }
}
pos = m_pFile->GetPos() - 5;
@@ -164,16 +166,14 @@ bool CFLVSplitterFilter::Sync(__int64& pos)
if(next == m_pFile->GetLength() - 4) {
m_pFile->Seek(pos);
return true;
- }
- else if (next <= m_pFile->GetLength() - 19) {
+ } else if (next <= m_pFile->GetLength() - 19) {
m_pFile->Seek(next);
Tag nt;
if (ReadTag(nt) && (nt.TagType == 8 || nt.TagType == 9 || nt.TagType == 18)) {
if ((nt.PreviousTagSize == ct.DataSize + 11) ||
- (m_IgnorePrevSizes &&
- nt.TimeStamp >= ct.TimeStamp &&
- nt.TimeStamp - ct.TimeStamp <= 1000))
- {
+ (m_IgnorePrevSizes &&
+ nt.TimeStamp >= ct.TimeStamp &&
+ nt.TimeStamp - ct.TimeStamp <= 1000)) {
m_pFile->Seek(pos);
return true;
}
@@ -195,14 +195,20 @@ HRESULT CFLVSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CBaseSplitterFileEx(pAsyncReader, hr, DEFAULT_CACHE_LENGTH, false));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = 0;
- if(m_pFile->BitRead(24) != 'FLV' || m_pFile->BitRead(8) != 1)
+ if(m_pFile->BitRead(24) != 'FLV' || m_pFile->BitRead(8) != 1) {
return E_FAIL;
+ }
EXECUTE_ASSERT(m_pFile->BitRead(5) == 0); // TypeFlagsReserved
bool fTypeFlagsAudio = !!m_pFile->BitRead(1);
@@ -222,8 +228,7 @@ HRESULT CFLVSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile->Seek(m_DataOffset);
- for(int i = 0; ReadTag(t) && (fTypeFlagsVideo || fTypeFlagsAudio) && i < 100; i++)
- {
+ for(int i = 0; ReadTag(t) && (fTypeFlagsVideo || fTypeFlagsAudio) && i < 100; i++) {
UINT64 next = m_pFile->GetPos() + t.DataSize;
CStringW name;
@@ -237,14 +242,12 @@ HRESULT CFLVSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
}
prevTagSize = t.DataSize + 11;
- if(t.TagType == 8 && t.DataSize != 0 && fTypeFlagsAudio)
- {
+ if(t.TagType == 8 && t.DataSize != 0 && fTypeFlagsAudio) {
UNREFERENCED_PARAMETER(at);
AudioTag at;
name = L"Audio";
- if(ReadTag(at))
- {
+ if(ReadTag(at)) {
int dataSize = t.DataSize - 1;
fTypeFlagsAudio = false;
@@ -256,83 +259,84 @@ HRESULT CFLVSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
wfe->nSamplesPerSec = 44100*(1<<at.SoundRate)/8;
wfe->wBitsPerSample = 8*(at.SoundSize+1);
wfe->nChannels = 1*(at.SoundType+1);
-
- switch(at.SoundFormat)
- {
- case 0: // FLV_CODECID_PCM_BE
- mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_PCM);
- break;
- case 1: // FLV_CODECID_ADPCM
- mt.subtype = FOURCCMap(MAKEFOURCC('A','S','W','F'));
- break;
- case 2: // FLV_CODECID_MP3
- mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_MP3);
-
- {
- CBaseSplitterFileEx::mpahdr h;
- CMediaType mt2;
- if(m_pFile->Read(h, 4, false, &mt2))
- mt = mt2;
- }
- break;
- case 3 : // FLV_CODECID_PCM_LE
- // ToDo
- break;
- case 4 : // unknown
- break;
- case 5 : // FLV_CODECID_NELLYMOSER_8HZ_MONO
- mt.subtype = FOURCCMap(MAKEFOURCC('N','E','L','L'));
- wfe->nSamplesPerSec = 8000;
- break;
- case 6 : // FLV_CODECID_NELLYMOSER
- mt.subtype = FOURCCMap(MAKEFOURCC('N','E','L','L'));
- break;
- case 10: { // FLV_CODECID_AAC
- if (dataSize < 1 || m_pFile->BitRead(8) != 0) { // packet type 0 == aac header
- fTypeFlagsAudio = true;
+
+ switch(at.SoundFormat) {
+ case 0: // FLV_CODECID_PCM_BE
+ mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_PCM);
+ break;
+ case 1: // FLV_CODECID_ADPCM
+ mt.subtype = FOURCCMap(MAKEFOURCC('A','S','W','F'));
+ break;
+ case 2: // FLV_CODECID_MP3
+ mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_MP3);
+
+ {
+ CBaseSplitterFileEx::mpahdr h;
+ CMediaType mt2;
+ if(m_pFile->Read(h, 4, false, &mt2)) {
+ mt = mt2;
+ }
+ }
+ break;
+ case 3 : // FLV_CODECID_PCM_LE
+ // ToDo
break;
+ case 4 : // unknown
+ break;
+ case 5 : // FLV_CODECID_NELLYMOSER_8HZ_MONO
+ mt.subtype = FOURCCMap(MAKEFOURCC('N','E','L','L'));
+ wfe->nSamplesPerSec = 8000;
+ break;
+ case 6 : // FLV_CODECID_NELLYMOSER
+ mt.subtype = FOURCCMap(MAKEFOURCC('N','E','L','L'));
+ break;
+ case 10: { // FLV_CODECID_AAC
+ if (dataSize < 1 || m_pFile->BitRead(8) != 0) { // packet type 0 == aac header
+ fTypeFlagsAudio = true;
+ break;
+ }
+
+ const int sampleRates[] = {
+ 96000, 88200, 64000, 48000, 44100, 32000, 24000,
+ 22050, 16000, 12000, 11025, 8000, 7350
+ };
+ const int channels[] = {
+ 0, 1, 2, 3, 4, 5, 6, 8
+ };
+
+ __int64 configOffset = m_pFile->GetPos();
+ UINT32 configSize = dataSize - 1;
+ if (configSize < 2) {
+ break;
+ }
+
+ // Might break depending on the AAC profile, see ff_mpeg4audio_get_config in ffmpeg's mpeg4audio.c
+ m_pFile->BitRead(5);
+ int iSampleRate = m_pFile->BitRead(4);
+ int iChannels = m_pFile->BitRead(4);
+ if (iSampleRate > 12 || iChannels > 7) {
+ break;
+ }
+
+ wfe = (WAVEFORMATEX*)mt.AllocFormatBuffer(sizeof(WAVEFORMATEX) + configSize);
+ memset(wfe, 0, mt.FormatLength());
+ wfe->nSamplesPerSec = sampleRates[iSampleRate];
+ wfe->wBitsPerSample = 16;
+ wfe->nChannels = channels[iChannels];
+ wfe->cbSize = configSize;
+
+ m_pFile->Seek(configOffset);
+ m_pFile->ByteRead((BYTE*)(wfe+1), configSize);
+
+ mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_AAC);
}
- const int sampleRates[] = {
- 96000, 88200, 64000, 48000, 44100, 32000, 24000,
- 22050, 16000, 12000, 11025, 8000, 7350
- };
- const int channels[] = {
- 0, 1, 2, 3, 4, 5, 6, 8
- };
-
- __int64 configOffset = m_pFile->GetPos();
- UINT32 configSize = dataSize - 1;
- if (configSize < 2) break;
-
- // Might break depending on the AAC profile, see ff_mpeg4audio_get_config in ffmpeg's mpeg4audio.c
- m_pFile->BitRead(5);
- int iSampleRate = m_pFile->BitRead(4);
- int iChannels = m_pFile->BitRead(4);
- if (iSampleRate > 12 || iChannels > 7) break;
-
- wfe = (WAVEFORMATEX*)mt.AllocFormatBuffer(sizeof(WAVEFORMATEX) + configSize);
- memset(wfe, 0, mt.FormatLength());
- wfe->nSamplesPerSec = sampleRates[iSampleRate];
- wfe->wBitsPerSample = 16;
- wfe->nChannels = channels[iChannels];
- wfe->cbSize = configSize;
-
- m_pFile->Seek(configOffset);
- m_pFile->ByteRead((BYTE*)(wfe+1), configSize);
-
- mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_AAC);
- }
-
}
}
- }
- else if(t.TagType == 9 && t.DataSize != 0 && fTypeFlagsVideo)
- {
+ } else if(t.TagType == 9 && t.DataSize != 0 && fTypeFlagsVideo) {
UNREFERENCED_PARAMETER(vt);
VideoTag vt;
- if(ReadTag(vt) && vt.FrameType == 1)
- {
+ if(ReadTag(vt) && vt.FrameType == 1) {
int dataSize = t.DataSize - 1;
fTypeFlagsVideo = false;
@@ -347,188 +351,202 @@ HRESULT CFLVSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
int w, h, arx, ary;
- switch(vt.CodecID)
- {
- case 2: // H.263
- if(m_pFile->BitRead(17) != 1) break;
-
- m_pFile->BitRead(13); // Version (5), TemporalReference (8)
-
- switch(BYTE PictureSize = (BYTE)m_pFile->BitRead(3)) // w00t
- {
- case 0: case 1:
- vih->bmiHeader.biWidth = (WORD)m_pFile->BitRead(8*(PictureSize+1));
- vih->bmiHeader.biHeight = (WORD)m_pFile->BitRead(8*(PictureSize+1));
- break;
- case 2: case 3: case 4:
- vih->bmiHeader.biWidth = 704 / PictureSize;
- vih->bmiHeader.biHeight = 576 / PictureSize;
- break;
- case 5: case 6:
- PictureSize -= 3;
- vih->bmiHeader.biWidth = 640 / PictureSize;
- vih->bmiHeader.biHeight = 480 / PictureSize;
- break;
- }
+ switch(vt.CodecID) {
+ case 2: // H.263
+ if(m_pFile->BitRead(17) != 1) {
+ break;
+ }
- if(!vih->bmiHeader.biWidth || !vih->bmiHeader.biHeight) break;
+ m_pFile->BitRead(13); // Version (5), TemporalReference (8)
+
+ switch(BYTE PictureSize = (BYTE)m_pFile->BitRead(3)) { // w00t
+ case 0:
+ case 1:
+ vih->bmiHeader.biWidth = (WORD)m_pFile->BitRead(8*(PictureSize+1));
+ vih->bmiHeader.biHeight = (WORD)m_pFile->BitRead(8*(PictureSize+1));
+ break;
+ case 2:
+ case 3:
+ case 4:
+ vih->bmiHeader.biWidth = 704 / PictureSize;
+ vih->bmiHeader.biHeight = 576 / PictureSize;
+ break;
+ case 5:
+ case 6:
+ PictureSize -= 3;
+ vih->bmiHeader.biWidth = 640 / PictureSize;
+ vih->bmiHeader.biHeight = 480 / PictureSize;
+ break;
+ }
- mt.subtype = FOURCCMap(vih->bmiHeader.biCompression = '1VLF');
+ if(!vih->bmiHeader.biWidth || !vih->bmiHeader.biHeight) {
+ break;
+ }
- break;
+ mt.subtype = FOURCCMap(vih->bmiHeader.biCompression = '1VLF');
- case 5: // VP6 with alpha
- m_pFile->BitRead(24);
- case 4: { // VP6
- #ifdef NOVIDEOTWEAK
- m_pFile->BitRead(8);
- #else
- VideoTweak fudge;
- ReadTag(fudge);
- #endif
-
- if (m_pFile->BitRead(1)) {
- // Delta (inter) frame
- fTypeFlagsVideo = true;
break;
- }
- m_pFile->BitRead(6);
- bool fSeparatedCoeff = !!m_pFile->BitRead(1);
- m_pFile->BitRead(5);
- int filterHeader = m_pFile->BitRead(2);
- m_pFile->BitRead(1);
- if (fSeparatedCoeff || !filterHeader) {
- m_pFile->BitRead(16);
- }
- h = m_pFile->BitRead(8) * 16;
- w = m_pFile->BitRead(8) * 16;
-
- ary = m_pFile->BitRead(8) * 16;
- arx = m_pFile->BitRead(8) * 16;
+ case 5: // VP6 with alpha
+ m_pFile->BitRead(24);
+ case 4: { // VP6
+#ifdef NOVIDEOTWEAK
+ m_pFile->BitRead(8);
+#else
+ VideoTweak fudge;
+ ReadTag(fudge);
+#endif
- if(arx && arx != w || ary && ary != h) {
- VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER2));
- memset(vih2, 0, sizeof(VIDEOINFOHEADER2));
- vih2->dwPictAspectRatioX = arx;
- vih2->dwPictAspectRatioY = ary;
- bih = &vih2->bmiHeader;
- mt.formattype = FORMAT_VideoInfo2;
- vih = (VIDEOINFOHEADER *)vih2;
- }
+ if (m_pFile->BitRead(1)) {
+ // Delta (inter) frame
+ fTypeFlagsVideo = true;
+ break;
+ }
+ m_pFile->BitRead(6);
+ bool fSeparatedCoeff = !!m_pFile->BitRead(1);
+ m_pFile->BitRead(5);
+ int filterHeader = m_pFile->BitRead(2);
+ m_pFile->BitRead(1);
+ if (fSeparatedCoeff || !filterHeader) {
+ m_pFile->BitRead(16);
+ }
- bih->biWidth = w;
- bih->biHeight = h;
- #ifndef NOVIDEOTWEAK
- SetRect(&vih->rcSource, 0, 0, w - fudge.x, h - fudge.y);
- SetRect(&vih->rcTarget, 0, 0, w - fudge.x, h - fudge.y);
- #endif
+ h = m_pFile->BitRead(8) * 16;
+ w = m_pFile->BitRead(8) * 16;
- mt.subtype = FOURCCMap(bih->biCompression = '4VLF');
+ ary = m_pFile->BitRead(8) * 16;
+ arx = m_pFile->BitRead(8) * 16;
- break;
- }
- case 7: { // H.264
- if (dataSize < 4 || m_pFile->BitRead(8) != 0) { // packet type 0 == avc header
- fTypeFlagsVideo = true;
- break;
- }
- m_pFile->BitRead(24); // composition time
-
- __int64 headerOffset = m_pFile->GetPos();
- UINT32 headerSize = dataSize - 4;
- BYTE *headerData = DNew BYTE[headerSize];
-
- m_pFile->ByteRead(headerData, headerSize);
+ if(arx && arx != w || ary && ary != h) {
+ VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER2));
+ memset(vih2, 0, sizeof(VIDEOINFOHEADER2));
+ vih2->dwPictAspectRatioX = arx;
+ vih2->dwPictAspectRatioY = ary;
+ bih = &vih2->bmiHeader;
+ mt.formattype = FORMAT_VideoInfo2;
+ vih = (VIDEOINFOHEADER *)vih2;
+ }
- m_pFile->Seek(headerOffset + 9);
+ bih->biWidth = w;
+ bih->biHeight = h;
+#ifndef NOVIDEOTWEAK
+ SetRect(&vih->rcSource, 0, 0, w - fudge.x, h - fudge.y);
+ SetRect(&vih->rcTarget, 0, 0, w - fudge.x, h - fudge.y);
+#endif
- mt.formattype = FORMAT_MPEG2Video;
- MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + headerSize);
- memset(vih, 0, mt.FormatLength());
- vih->hdr.bmiHeader.biSize = sizeof(vih->hdr.bmiHeader);
- vih->hdr.bmiHeader.biPlanes = 1;
- vih->hdr.bmiHeader.biBitCount = 24;
- vih->dwFlags = (headerData[4] & 0x03) + 1; // nal length size
+ mt.subtype = FOURCCMap(bih->biCompression = '4VLF');
- vih->dwProfile = (BYTE)m_pFile->BitRead(8);
- m_pFile->BitRead(8);
- vih->dwLevel = (BYTE)m_pFile->BitRead(8);
- m_pFile->UExpGolombRead(); // seq_parameter_set_id
- if(vih->dwProfile >= 100) { // high profile
- if(m_pFile->UExpGolombRead() == 3) // chroma_format_idc
- m_pFile->BitRead(1); // residue_transform_flag
- m_pFile->UExpGolombRead(); // bit_depth_luma_minus8
- m_pFile->UExpGolombRead(); // bit_depth_chroma_minus8
- m_pFile->BitRead(1); // qpprime_y_zero_transform_bypass_flag
- if(m_pFile->BitRead(1)) // seq_scaling_matrix_present_flag
- for(int i = 0; i < 8; i++)
- if(m_pFile->BitRead(1)) // seq_scaling_list_present_flag
- for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j)
- next = (next + m_pFile->SExpGolombRead() + 256) & 255;
- }
- m_pFile->UExpGolombRead(); // log2_max_frame_num_minus4
- UINT64 pic_order_cnt_type = m_pFile->UExpGolombRead();
- if(pic_order_cnt_type == 0) {
- m_pFile->UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4
- }
- else if(pic_order_cnt_type == 1) {
- m_pFile->BitRead(1); // delta_pic_order_always_zero_flag
- m_pFile->SExpGolombRead(); // offset_for_non_ref_pic
- m_pFile->SExpGolombRead(); // offset_for_top_to_bottom_field
- UINT64 num_ref_frames_in_pic_order_cnt_cycle = m_pFile->UExpGolombRead();
- for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++)
- m_pFile->SExpGolombRead(); // offset_for_ref_frame[i]
+ break;
}
- m_pFile->UExpGolombRead(); // num_ref_frames
- m_pFile->BitRead(1); // gaps_in_frame_num_value_allowed_flag
- UINT64 pic_width_in_mbs_minus1 = m_pFile->UExpGolombRead();
- UINT64 pic_height_in_map_units_minus1 = m_pFile->UExpGolombRead();
- BYTE frame_mbs_only_flag = (BYTE)m_pFile->BitRead(1);
- vih->hdr.bmiHeader.biWidth = vih->hdr.dwPictAspectRatioX = (LONG)((pic_width_in_mbs_minus1 + 1) * 16);
- vih->hdr.bmiHeader.biHeight = vih->hdr.dwPictAspectRatioY = (LONG)((2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16);
-
- BYTE* src = (BYTE*)headerData + 5;
- BYTE* dst = (BYTE*)vih->dwSequenceHeader;
- BYTE* src_end = (BYTE*)headerData + headerSize;
- BYTE* dst_end = (BYTE*)vih->dwSequenceHeader + headerSize;
- int spsCount = *(src++) & 0x1F;
- int ppsCount = -1;
-
- vih->cbSequenceHeader = 0;
-
- while (src < src_end - 1) {
- if (spsCount == 0 && ppsCount == -1) {
- ppsCount = *(src++);
- continue;
+ case 7: { // H.264
+ if (dataSize < 4 || m_pFile->BitRead(8) != 0) { // packet type 0 == avc header
+ fTypeFlagsVideo = true;
+ break;
+ }
+ m_pFile->BitRead(24); // composition time
+
+ __int64 headerOffset = m_pFile->GetPos();
+ UINT32 headerSize = dataSize - 4;
+ BYTE *headerData = DNew BYTE[headerSize];
+
+ m_pFile->ByteRead(headerData, headerSize);
+
+ m_pFile->Seek(headerOffset + 9);
+
+ mt.formattype = FORMAT_MPEG2Video;
+ MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + headerSize);
+ memset(vih, 0, mt.FormatLength());
+ vih->hdr.bmiHeader.biSize = sizeof(vih->hdr.bmiHeader);
+ vih->hdr.bmiHeader.biPlanes = 1;
+ vih->hdr.bmiHeader.biBitCount = 24;
+ vih->dwFlags = (headerData[4] & 0x03) + 1; // nal length size
+
+ vih->dwProfile = (BYTE)m_pFile->BitRead(8);
+ m_pFile->BitRead(8);
+ vih->dwLevel = (BYTE)m_pFile->BitRead(8);
+ m_pFile->UExpGolombRead(); // seq_parameter_set_id
+ if(vih->dwProfile >= 100) { // high profile
+ if(m_pFile->UExpGolombRead() == 3) { // chroma_format_idc
+ m_pFile->BitRead(1); // residue_transform_flag
+ }
+ m_pFile->UExpGolombRead(); // bit_depth_luma_minus8
+ m_pFile->UExpGolombRead(); // bit_depth_chroma_minus8
+ m_pFile->BitRead(1); // qpprime_y_zero_transform_bypass_flag
+ if(m_pFile->BitRead(1)) // seq_scaling_matrix_present_flag
+ for(int i = 0; i < 8; i++)
+ if(m_pFile->BitRead(1)) // seq_scaling_list_present_flag
+ for(int j = 0, size = i < 6 ? 16 : 64, next = 8; j < size && next != 0; ++j) {
+ next = (next + m_pFile->SExpGolombRead() + 256) & 255;
+ }
+ }
+ m_pFile->UExpGolombRead(); // log2_max_frame_num_minus4
+ UINT64 pic_order_cnt_type = m_pFile->UExpGolombRead();
+ if(pic_order_cnt_type == 0) {
+ m_pFile->UExpGolombRead(); // log2_max_pic_order_cnt_lsb_minus4
+ } else if(pic_order_cnt_type == 1) {
+ m_pFile->BitRead(1); // delta_pic_order_always_zero_flag
+ m_pFile->SExpGolombRead(); // offset_for_non_ref_pic
+ m_pFile->SExpGolombRead(); // offset_for_top_to_bottom_field
+ UINT64 num_ref_frames_in_pic_order_cnt_cycle = m_pFile->UExpGolombRead();
+ for(int i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
+ m_pFile->SExpGolombRead(); // offset_for_ref_frame[i]
+ }
+ }
+ m_pFile->UExpGolombRead(); // num_ref_frames
+ m_pFile->BitRead(1); // gaps_in_frame_num_value_allowed_flag
+ UINT64 pic_width_in_mbs_minus1 = m_pFile->UExpGolombRead();
+ UINT64 pic_height_in_map_units_minus1 = m_pFile->UExpGolombRead();
+ BYTE frame_mbs_only_flag = (BYTE)m_pFile->BitRead(1);
+ vih->hdr.bmiHeader.biWidth = vih->hdr.dwPictAspectRatioX = (LONG)((pic_width_in_mbs_minus1 + 1) * 16);
+ vih->hdr.bmiHeader.biHeight = vih->hdr.dwPictAspectRatioY = (LONG)((2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1) * 16);
+
+ BYTE* src = (BYTE*)headerData + 5;
+ BYTE* dst = (BYTE*)vih->dwSequenceHeader;
+ BYTE* src_end = (BYTE*)headerData + headerSize;
+ BYTE* dst_end = (BYTE*)vih->dwSequenceHeader + headerSize;
+ int spsCount = *(src++) & 0x1F;
+ int ppsCount = -1;
+
+ vih->cbSequenceHeader = 0;
+
+ while (src < src_end - 1) {
+ if (spsCount == 0 && ppsCount == -1) {
+ ppsCount = *(src++);
+ continue;
+ }
+
+ if (spsCount > 0) {
+ spsCount--;
+ } else if (ppsCount > 0) {
+ ppsCount--;
+ } else {
+ break;
+ }
+
+ int len = ((src[0] << 8) | src[1]) + 2;
+ if(src + len > src_end || dst + len > dst_end) {
+ ASSERT(0);
+ break;
+ }
+ memcpy(dst, src, len);
+ src += len;
+ dst += len;
+ vih->cbSequenceHeader += len;
}
- if (spsCount > 0) spsCount--;
- else if (ppsCount > 0) ppsCount--;
- else break;
-
- int len = ((src[0] << 8) | src[1]) + 2;
- if(src + len > src_end || dst + len > dst_end) {ASSERT(0); break;}
- memcpy(dst, src, len);
- src += len;
- dst += len;
- vih->cbSequenceHeader += len;
- }
-
- delete[] headerData;
+ delete[] headerData;
- mt.subtype = FOURCCMap(vih->hdr.bmiHeader.biCompression = '1CVA');
+ mt.subtype = FOURCCMap(vih->hdr.bmiHeader.biCompression = '1CVA');
- break;
- }
- default:
- fTypeFlagsVideo = true;
+ break;
+ }
+ default:
+ fTypeFlagsVideo = true;
}
}
}
-
- if(mt.subtype != GUID_NULL)
- {
+
+ if(mt.subtype != GUID_NULL) {
CAtlArray<CMediaType> mts;
mts.Add(mt);
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CBaseSplitterOutputPin(mts, name, this, this, &hr));
@@ -538,23 +556,19 @@ HRESULT CFLVSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile->Seek(next);
}
- if(m_pFile->IsRandomAccess())
- {
+ if(m_pFile->IsRandomAccess()) {
__int64 pos = max(m_DataOffset, m_pFile->GetLength() - 256 * 1024);
- if(Sync(pos))
- {
+ if(Sync(pos)) {
Tag t;
AudioTag at;
VideoTag vt;
- while(ReadTag(t))
- {
+ while(ReadTag(t)) {
UINT64 next = m_pFile->GetPos() + t.DataSize;
- if(t.TagType == 8 && ReadTag(at) || t.TagType == 9 && ReadTag(vt))
- {
- m_rtDuration = max(m_rtDuration, 10000i64 * t.TimeStamp);
+ if(t.TagType == 8 && ReadTag(at) || t.TagType == 9 && ReadTag(vt)) {
+ m_rtDuration = max(m_rtDuration, 10000i64 * t.TimeStamp);
}
m_pFile->Seek(next);
@@ -577,11 +591,9 @@ void CFLVSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
{
if(!m_rtDuration || rt <= 0) {
m_pFile->Seek(m_DataOffset);
- }
- else if (!m_IgnorePrevSizes) {
+ } else if (!m_IgnorePrevSizes) {
NormalSeek(rt);
- }
- else {
+ } else {
AlternateSeek(rt);
}
}
@@ -593,8 +605,7 @@ void CFLVSplitterFilter::NormalSeek(REFERENCE_TIME rt)
__int64 pos = m_DataOffset + 1.0 * rt / m_rtDuration * (m_pFile->GetLength() - m_DataOffset);
- if(!Sync(pos))
- {
+ if(!Sync(pos)) {
ASSERT(0);
m_pFile->Seek(m_DataOffset);
return;
@@ -604,10 +615,8 @@ void CFLVSplitterFilter::NormalSeek(REFERENCE_TIME rt)
AudioTag at;
VideoTag vt;
- while(ReadTag(t))
- {
- if(10000i64 * t.TimeStamp >= rt)
- {
+ while(ReadTag(t)) {
+ if(10000i64 * t.TimeStamp >= rt) {
m_pFile->Seek(m_pFile->GetPos() - 15);
break;
}
@@ -615,18 +624,13 @@ void CFLVSplitterFilter::NormalSeek(REFERENCE_TIME rt)
m_pFile->Seek(m_pFile->GetPos() + t.DataSize);
}
- while(m_pFile->GetPos() >= m_DataOffset && (fAudio || fVideo) && ReadTag(t))
- {
+ while(m_pFile->GetPos() >= m_DataOffset && (fAudio || fVideo) && ReadTag(t)) {
UINT64 prev = m_pFile->GetPos() - 15 - t.PreviousTagSize - 4;
- if(10000i64 * t.TimeStamp <= rt)
- {
- if(t.TagType == 8 && ReadTag(at))
- {
+ if(10000i64 * t.TimeStamp <= rt) {
+ if(t.TagType == 8 && ReadTag(at)) {
fAudio = false;
- }
- else if(t.TagType == 9 && ReadTag(vt) && vt.FrameType == 1)
- {
+ } else if(t.TagType == 9 && ReadTag(vt) && vt.FrameType == 1) {
fVideo = false;
}
}
@@ -634,8 +638,7 @@ void CFLVSplitterFilter::NormalSeek(REFERENCE_TIME rt)
m_pFile->Seek(prev);
}
- if(fAudio || fVideo)
- {
+ if(fAudio || fVideo) {
ASSERT(0);
m_pFile->Seek(m_DataOffset);
}
@@ -668,9 +671,10 @@ void CFLVSplitterFilter::AlternateSeek(REFERENCE_TIME rt)
if (hasAudio && t.TagType == 8 && ReadTag(at)) {
foundAudio = true;
- if (!hasVideo) bestPos = cur;
- }
- else if (hasVideo && t.TagType == 9 && ReadTag(vt) && vt.FrameType == 1) {
+ if (!hasVideo) {
+ bestPos = cur;
+ }
+ } else if (hasVideo && t.TagType == 9 && ReadTag(vt) && vt.FrameType == 1) {
foundVideo = true;
bestPos = cur;
}
@@ -684,8 +688,7 @@ void CFLVSplitterFilter::AlternateSeek(REFERENCE_TIME rt)
m_pFile->Seek(m_DataOffset);
return;
}
- }
- else {
+ } else {
m_pFile->Seek(bestPos);
return;
}
@@ -702,35 +705,44 @@ bool CFLVSplitterFilter::DemuxLoop()
AudioTag at;
VideoTag vt;
- while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining())
- {
- if(!ReadTag(t)) break;
+ while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining()) {
+ if(!ReadTag(t)) {
+ break;
+ }
__int64 next = m_pFile->GetPos() + t.DataSize;
- if((t.DataSize > 0) && (t.TagType == 8 && ReadTag(at) || t.TagType == 9 && ReadTag(vt)))
- {
+ if((t.DataSize > 0) && (t.TagType == 8 && ReadTag(at) || t.TagType == 9 && ReadTag(vt))) {
UINT32 tsOffset = 0;
- if(t.TagType == 9)
- {
- if(vt.FrameType == 5) goto NextTag; // video info/command frame
- if(vt.CodecID == 4) m_pFile->BitRead(8);
- else if(vt.CodecID == 5) m_pFile->BitRead(32);
- else if(vt.CodecID == 7) {
- if (m_pFile->BitRead(8) != 1) goto NextTag;
+ if(t.TagType == 9) {
+ if(vt.FrameType == 5) {
+ goto NextTag; // video info/command frame
+ }
+ if(vt.CodecID == 4) {
+ m_pFile->BitRead(8);
+ } else if(vt.CodecID == 5) {
+ m_pFile->BitRead(32);
+ } else if(vt.CodecID == 7) {
+ if (m_pFile->BitRead(8) != 1) {
+ goto NextTag;
+ }
// Tag timestamps specify decode time, this is the display time offset
tsOffset = m_pFile->BitRead(24);
tsOffset = (tsOffset + 0xff800000) ^ 0xff800000; // sign extension
}
}
if(t.TagType == 8 && at.SoundFormat == 10) {
- if (m_pFile->BitRead(8) != 1) goto NextTag;
+ if (m_pFile->BitRead(8) != 1) {
+ goto NextTag;
+ }
}
__int64 dataSize = next - m_pFile->GetPos();
- if (dataSize <= 0) goto NextTag;
+ if (dataSize <= 0) {
+ goto NextTag;
+ }
p.Attach(DNew Packet());
p->TrackNumber = t.TagType;
- p->rtStart = 10000i64 * (t.TimeStamp + tsOffset);
+ p->rtStart = 10000i64 * (t.TimeStamp + tsOffset);
p->rtStop = p->rtStart + 1;
p->bSyncPoint = t.TagType == 9 ? vt.FrameType == 1 : true;
p->SetCount(dataSize);
diff --git a/src/filters/parser/FLVSplitter/FLVSplitter.h b/src/filters/parser/FLVSplitter/FLVSplitter.h
index 4899ef8cc..3e1690384 100644
--- a/src/filters/parser/FLVSplitter/FLVSplitter.h
+++ b/src/filters/parser/FLVSplitter/FLVSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,23 +25,21 @@
#include "../BaseSplitter/BaseSplitter.h"
class __declspec(uuid("47E792CF-0BBE-4F7A-859C-194B0768650A"))
-CFLVSplitterFilter : public CBaseSplitterFilter
+ CFLVSplitterFilter : public CBaseSplitterFilter
{
UINT32 m_DataOffset;
bool m_IgnorePrevSizes;
bool Sync(__int64& pos);
- struct VideoTweak
- {
+ struct VideoTweak {
BYTE x;
BYTE y;
};
bool ReadTag(VideoTweak& t);
-
- struct Tag
- {
+
+ struct Tag {
UINT32 PreviousTagSize;
BYTE TagType;
UINT32 DataSize;
@@ -51,8 +49,7 @@ CFLVSplitterFilter : public CBaseSplitterFilter
bool ReadTag(Tag& t);
- struct AudioTag
- {
+ struct AudioTag {
BYTE SoundFormat;
BYTE SoundRate;
BYTE SoundSize;
@@ -61,8 +58,7 @@ CFLVSplitterFilter : public CBaseSplitterFilter
bool ReadTag(AudioTag& at);
- struct VideoTag
- {
+ struct VideoTag {
BYTE FrameType;
BYTE CodecID;
};
@@ -85,7 +81,7 @@ public:
};
class __declspec(uuid("C9ECE7B3-1D8E-41F5-9F24-B255DF16C087"))
-CFLVSourceFilter : public CFLVSplitterFilter
+ CFLVSourceFilter : public CFLVSplitterFilter
{
public:
CFLVSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/FLVSplitter/stdafx.cpp b/src/filters/parser/FLVSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/FLVSplitter/stdafx.cpp
+++ b/src/filters/parser/FLVSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/FLVSplitter/stdafx.h b/src/filters/parser/FLVSplitter/stdafx.h
index cdc946aa0..9b252ac14 100644
--- a/src/filters/parser/FLVSplitter/stdafx.h
+++ b/src/filters/parser/FLVSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MP4Splitter/Ap4AsyncReaderStream.cpp b/src/filters/parser/MP4Splitter/Ap4AsyncReaderStream.cpp
index 1f0240054..496efa659 100644
--- a/src/filters/parser/MP4Splitter/Ap4AsyncReaderStream.cpp
+++ b/src/filters/parser/MP4Splitter/Ap4AsyncReaderStream.cpp
@@ -1,7 +1,7 @@
#include "stdafx.h"
#include "Ap4AsyncReaderStream.h"
-AP4_AsyncReaderStream::AP4_AsyncReaderStream(CBaseSplitterFile* pFile)
+AP4_AsyncReaderStream::AP4_AsyncReaderStream(CBaseSplitterFile* pFile)
: m_refs(1)
, m_pFile(pFile)
{
@@ -15,45 +15,50 @@ AP4_AsyncReaderStream::~AP4_AsyncReaderStream()
void AP4_AsyncReaderStream::AddReference()
{
- ASSERT(m_refs > 0);
+ ASSERT(m_refs > 0);
++m_refs;
}
void AP4_AsyncReaderStream::Release()
{
- ASSERT(m_refs > 0);
- if(--m_refs == 0) delete this;
+ ASSERT(m_refs > 0);
+ if(--m_refs == 0) {
+ delete this;
+ }
}
AP4_Result AP4_AsyncReaderStream::Read(void* buffer, AP4_Size bytesToRead, AP4_Size* bytesRead)
{
__int64 bytesAvail = m_pFile->GetRemaining();
- if(bytesAvail < bytesToRead)
- {
- if(bytesRead) *bytesRead = bytesAvail;
+ if(bytesAvail < bytesToRead) {
+ if(bytesRead) {
+ *bytesRead = bytesAvail;
+ }
bytesToRead = bytesAvail;
}
- if(bytesAvail == 0)
- {
+ if(bytesAvail == 0) {
return AP4_ERROR_EOS;
}
- if(FAILED(m_pFile->ByteRead((BYTE*)buffer, bytesToRead)))
- {
- if(bytesRead) *bytesRead = 0;
+ if(FAILED(m_pFile->ByteRead((BYTE*)buffer, bytesToRead))) {
+ if(bytesRead) {
+ *bytesRead = 0;
+ }
return AP4_ERROR_READ_FAILED;
}
- if(bytesRead) *bytesRead = bytesToRead;
+ if(bytesRead) {
+ *bytesRead = bytesToRead;
+ }
return AP4_SUCCESS;
}
AP4_Result AP4_AsyncReaderStream::Write(const void* buffer, AP4_Size bytesToWrite, AP4_Size* bytesWritten)
{
- return AP4_ERROR_WRITE_FAILED;
+ return AP4_ERROR_WRITE_FAILED;
}
AP4_Result AP4_AsyncReaderStream::Seek(AP4_Offset offset)
diff --git a/src/filters/parser/MP4Splitter/MP4Splitter.cpp b/src/filters/parser/MP4Splitter/MP4Splitter.cpp
index b395e590a..d0d641aec 100644
--- a/src/filters/parser/MP4Splitter/MP4Splitter.cpp
+++ b/src/filters/parser/MP4Splitter/MP4Splitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -39,28 +39,24 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MP4},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMP4SplitterFilter), L"MPC - MP4 Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CMP4SourceFilter), L"MPC - MP4 Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
{&__uuidof(CMPEG4VideoSplitterFilter), L"MPC - MPEG4 Video Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
- {&__uuidof(CMPEG4VideoSourceFilter), L"MPC - MPEG4 Video Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
+ {&__uuidof(CMPEG4VideoSourceFilter), L"MPC - MPEG4 Video Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMP4SplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CMP4SourceFilter>, NULL, &sudFilter[1]},
{sudFilter[2].strName, sudFilter[2].clsID, CreateInstance<CMPEG4VideoSplitterFilter>, NULL, &sudFilter[2]},
@@ -127,32 +123,37 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CMP4SplitterFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = 0;
m_framesize.SetSize(640, 480);
- if(AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie())
- {
+ if(AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie()) {
for(AP4_List<AP4_Track>::Item* item = movie->GetTracks().FirstItem();
- item;
- item = item->GetNext())
- {
+ item;
+ item = item->GetNext()) {
AP4_Track* track = item->GetData();
- if(track->GetType() != AP4_Track::TYPE_VIDEO
- && track->GetType() != AP4_Track::TYPE_AUDIO
- && track->GetType() != AP4_Track::TYPE_TEXT
- && track->GetType() != AP4_Track::TYPE_SUBP)
+ if(track->GetType() != AP4_Track::TYPE_VIDEO
+ && track->GetType() != AP4_Track::TYPE_AUDIO
+ && track->GetType() != AP4_Track::TYPE_TEXT
+ && track->GetType() != AP4_Track::TYPE_SUBP) {
continue;
+ }
AP4_Sample sample;
- if(!AP4_SUCCEEDED(track->GetSample(0, sample)) || sample.GetDescriptionIndex() == 0xFFFFFFFF)
+ if(!AP4_SUCCEEDED(track->GetSample(0, sample)) || sample.GetDescriptionIndex() == 0xFFFFFFFF) {
continue;
+ }
CStringW TrackName = UTF8To16(track->GetTrackName().c_str());
CStringA TrackLanguage = track->GetTrackLanguage().c_str();
@@ -167,25 +168,22 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
AP4_DataBuffer empty;
- if(AP4_SampleDescription* desc = track->GetSampleDescription(sample.GetDescriptionIndex()))
- {
+ if(AP4_SampleDescription* desc = track->GetSampleDescription(sample.GetDescriptionIndex())) {
AP4_MpegSampleDescription* mpeg_desc = NULL;
- if(desc->GetType() == AP4_SampleDescription::TYPE_MPEG)
- {
+ if(desc->GetType() == AP4_SampleDescription::TYPE_MPEG) {
mpeg_desc = dynamic_cast<AP4_MpegSampleDescription*>(desc);
- }
- else if(desc->GetType() == AP4_SampleDescription::TYPE_ISMACRYP)
- {
+ } else if(desc->GetType() == AP4_SampleDescription::TYPE_ISMACRYP) {
AP4_IsmaCrypSampleDescription* isma_desc = dynamic_cast<AP4_IsmaCrypSampleDescription*>(desc);
mpeg_desc = isma_desc->GetOriginalSampleDescription();
}
- if(AP4_MpegVideoSampleDescription* video_desc =
- dynamic_cast<AP4_MpegVideoSampleDescription*>(mpeg_desc))
- {
+ if(AP4_MpegVideoSampleDescription* video_desc =
+ dynamic_cast<AP4_MpegVideoSampleDescription*>(mpeg_desc)) {
const AP4_DataBuffer* di = video_desc->GetDecoderInfo();
- if(!di) di = &empty;
+ if(!di) {
+ di = &empty;
+ }
mt.majortype = MEDIATYPE_Video;
mt.formattype = FORMAT_VideoInfo;
@@ -197,68 +195,68 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
vih->bmiHeader.biHeight = (LONG)video_desc->GetHeight();
memcpy(vih + 1, di->GetData(), di->GetDataSize());
- switch(video_desc->GetObjectTypeId())
- {
- case AP4_MPEG4_VISUAL_OTI:
- mt.subtype = FOURCCMap('v4pm');
- mt.formattype = FORMAT_MPEG2Video;
- {
- MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + di->GetDataSize());
- memset(vih, 0, mt.FormatLength());
- vih->hdr.bmiHeader.biSize = sizeof(vih->hdr.bmiHeader);
- vih->hdr.bmiHeader.biWidth = (LONG)video_desc->GetWidth();
- vih->hdr.bmiHeader.biHeight = (LONG)video_desc->GetHeight();
- vih->hdr.bmiHeader.biCompression = 'v4pm';
- vih->hdr.bmiHeader.biPlanes = 1;
- vih->hdr.bmiHeader.biBitCount = 24;
- vih->hdr.dwPictAspectRatioX = vih->hdr.bmiHeader.biWidth;
- vih->hdr.dwPictAspectRatioY = vih->hdr.bmiHeader.biHeight;
- vih->cbSequenceHeader = di->GetDataSize();
- memcpy(vih->dwSequenceHeader, di->GetData(), di->GetDataSize());
- mts.Add(mt);
- mt.subtype = FOURCCMap(vih->hdr.bmiHeader.biCompression = 'V4PM');
- mts.Add(mt);
- }
- break;
- case AP4_MPEG2_VISUAL_SIMPLE_OTI:
- case AP4_MPEG2_VISUAL_MAIN_OTI:
- case AP4_MPEG2_VISUAL_SNR_OTI:
- case AP4_MPEG2_VISUAL_SPATIAL_OTI:
- case AP4_MPEG2_VISUAL_HIGH_OTI:
- case AP4_MPEG2_VISUAL_422_OTI:
- mt.subtype = MEDIASUBTYPE_MPEG2_VIDEO;
- {
- m_pFile->Seek(sample.GetOffset());
- CBaseSplitterFileEx::seqhdr h;
- CMediaType mt2;
- if(m_pFile->Read(h, sample.GetSize(), &mt2))
- mt = mt2;
- }
- mts.Add(mt);
- break;
- case AP4_MPEG1_VISUAL_OTI: // ???
- mt.subtype = MEDIASUBTYPE_MPEG1Payload;
- {
- m_pFile->Seek(sample.GetOffset());
- CBaseSplitterFileEx::seqhdr h;
- CMediaType mt2;
- if(m_pFile->Read(h, sample.GetSize(), &mt2))
- mt = mt2;
- }
- mts.Add(mt);
- break;
+ switch(video_desc->GetObjectTypeId()) {
+ case AP4_MPEG4_VISUAL_OTI:
+ mt.subtype = FOURCCMap('v4pm');
+ mt.formattype = FORMAT_MPEG2Video;
+ {
+ MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + di->GetDataSize());
+ memset(vih, 0, mt.FormatLength());
+ vih->hdr.bmiHeader.biSize = sizeof(vih->hdr.bmiHeader);
+ vih->hdr.bmiHeader.biWidth = (LONG)video_desc->GetWidth();
+ vih->hdr.bmiHeader.biHeight = (LONG)video_desc->GetHeight();
+ vih->hdr.bmiHeader.biCompression = 'v4pm';
+ vih->hdr.bmiHeader.biPlanes = 1;
+ vih->hdr.bmiHeader.biBitCount = 24;
+ vih->hdr.dwPictAspectRatioX = vih->hdr.bmiHeader.biWidth;
+ vih->hdr.dwPictAspectRatioY = vih->hdr.bmiHeader.biHeight;
+ vih->cbSequenceHeader = di->GetDataSize();
+ memcpy(vih->dwSequenceHeader, di->GetData(), di->GetDataSize());
+ mts.Add(mt);
+ mt.subtype = FOURCCMap(vih->hdr.bmiHeader.biCompression = 'V4PM');
+ mts.Add(mt);
+ }
+ break;
+ case AP4_MPEG2_VISUAL_SIMPLE_OTI:
+ case AP4_MPEG2_VISUAL_MAIN_OTI:
+ case AP4_MPEG2_VISUAL_SNR_OTI:
+ case AP4_MPEG2_VISUAL_SPATIAL_OTI:
+ case AP4_MPEG2_VISUAL_HIGH_OTI:
+ case AP4_MPEG2_VISUAL_422_OTI:
+ mt.subtype = MEDIASUBTYPE_MPEG2_VIDEO;
+ {
+ m_pFile->Seek(sample.GetOffset());
+ CBaseSplitterFileEx::seqhdr h;
+ CMediaType mt2;
+ if(m_pFile->Read(h, sample.GetSize(), &mt2)) {
+ mt = mt2;
+ }
+ }
+ mts.Add(mt);
+ break;
+ case AP4_MPEG1_VISUAL_OTI: // ???
+ mt.subtype = MEDIASUBTYPE_MPEG1Payload;
+ {
+ m_pFile->Seek(sample.GetOffset());
+ CBaseSplitterFileEx::seqhdr h;
+ CMediaType mt2;
+ if(m_pFile->Read(h, sample.GetSize(), &mt2)) {
+ mt = mt2;
+ }
+ }
+ mts.Add(mt);
+ break;
}
- if(mt.subtype == GUID_NULL)
- {
+ if(mt.subtype == GUID_NULL) {
TRACE(_T("Unknown video OBI: %02x\n"), video_desc->GetObjectTypeId());
}
- }
- else if(AP4_MpegAudioSampleDescription* audio_desc =
- dynamic_cast<AP4_MpegAudioSampleDescription*>(mpeg_desc))
- {
+ } else if(AP4_MpegAudioSampleDescription* audio_desc =
+ dynamic_cast<AP4_MpegAudioSampleDescription*>(mpeg_desc)) {
const AP4_DataBuffer* di = audio_desc->GetDecoderInfo();
- if(!di) di = &empty;
+ if(!di) {
+ di = &empty;
+ }
mt.majortype = MEDIATYPE_Audio;
mt.formattype = FORMAT_WaveFormatEx;
@@ -274,103 +272,96 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
memcpy(wfe + 1, di->GetData(), di->GetDataSize());
- switch(audio_desc->GetObjectTypeId())
- {
- case AP4_MPEG4_AUDIO_OTI:
- case AP4_MPEG2_AAC_AUDIO_MAIN_OTI: // ???
- case AP4_MPEG2_AAC_AUDIO_LC_OTI: // ???
- case AP4_MPEG2_AAC_AUDIO_SSRP_OTI: // ???
- mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_AAC);
- if(wfe->cbSize >= 2) wfe->nChannels = (((BYTE*)(wfe+1))[1]>>3) & 0xf;
- mts.Add(mt);
- break;
- case AP4_MPEG2_PART3_AUDIO_OTI: // ???
- case AP4_MPEG1_AUDIO_OTI:
- mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_MP3);
- {
- m_pFile->Seek(sample.GetOffset());
- CBaseSplitterFileEx::mpahdr h;
- CMediaType mt2;
- if(m_pFile->Read(h, sample.GetSize(), false, &mt2))
- mt = mt2;
- }
- mts.Add(mt);
- break;
+ switch(audio_desc->GetObjectTypeId()) {
+ case AP4_MPEG4_AUDIO_OTI:
+ case AP4_MPEG2_AAC_AUDIO_MAIN_OTI: // ???
+ case AP4_MPEG2_AAC_AUDIO_LC_OTI: // ???
+ case AP4_MPEG2_AAC_AUDIO_SSRP_OTI: // ???
+ mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_AAC);
+ if(wfe->cbSize >= 2) {
+ wfe->nChannels = (((BYTE*)(wfe+1))[1]>>3) & 0xf;
+ }
+ mts.Add(mt);
+ break;
+ case AP4_MPEG2_PART3_AUDIO_OTI: // ???
+ case AP4_MPEG1_AUDIO_OTI:
+ mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_MP3);
+ {
+ m_pFile->Seek(sample.GetOffset());
+ CBaseSplitterFileEx::mpahdr h;
+ CMediaType mt2;
+ if(m_pFile->Read(h, sample.GetSize(), false, &mt2)) {
+ mt = mt2;
+ }
+ }
+ mts.Add(mt);
+ break;
}
- if(mt.subtype == GUID_NULL)
- {
+ if(mt.subtype == GUID_NULL) {
TRACE(_T("Unknown audio OBI: %02x\n"), audio_desc->GetObjectTypeId());
}
- }
- else if(AP4_MpegSystemSampleDescription* system_desc =
- dynamic_cast<AP4_MpegSystemSampleDescription*>(desc))
- {
+ } else if(AP4_MpegSystemSampleDescription* system_desc =
+ dynamic_cast<AP4_MpegSystemSampleDescription*>(desc)) {
const AP4_DataBuffer* di = system_desc->GetDecoderInfo();
- if(!di) di = &empty;
-
- switch(system_desc->GetObjectTypeId())
- {
- case AP4_NERO_VOBSUB:
- if(di->GetDataSize() >= 16*4)
- {
- CSize size(720, 576);
- if(AP4_TkhdAtom* tkhd = dynamic_cast<AP4_TkhdAtom*>(track->GetTrakAtom()->GetChild(AP4_ATOM_TYPE_TKHD)))
- {
- size.cx = tkhd->GetWidth()>>16;
- size.cy = tkhd->GetHeight()>>16;
- }
+ if(!di) {
+ di = &empty;
+ }
- const AP4_Byte* pal = di->GetData();
- CAtlList<CStringA> sl;
- for(int i = 0; i < 16*4; i += 4)
- {
- BYTE y = (pal[i+1]-16)*255/219;
- BYTE u = pal[i+2];
- BYTE v = pal[i+3];
- BYTE r = (BYTE)min(max(1.0*y + 1.4022*(v-128), 0), 255);
- BYTE g = (BYTE)min(max(1.0*y - 0.3456*(u-128) - 0.7145*(v-128), 0), 255);
- BYTE b = (BYTE)min(max(1.0*y + 1.7710*(u-128), 0) , 255);
- CStringA str;
- str.Format("%02x%02x%02x", r, g, b);
- sl.AddTail(str);
- }
+ switch(system_desc->GetObjectTypeId()) {
+ case AP4_NERO_VOBSUB:
+ if(di->GetDataSize() >= 16*4) {
+ CSize size(720, 576);
+ if(AP4_TkhdAtom* tkhd = dynamic_cast<AP4_TkhdAtom*>(track->GetTrakAtom()->GetChild(AP4_ATOM_TYPE_TKHD))) {
+ size.cx = tkhd->GetWidth()>>16;
+ size.cy = tkhd->GetHeight()>>16;
+ }
- CStringA hdr;
- hdr.Format(
- "# VobSub index file, v7 (do not modify this line!)\n"
- "size: %dx%d\n"
- "palette: %s\n",
- size.cx, size.cy,
- Implode(sl, ','));
-
- mt.majortype = MEDIATYPE_Subtitle;
- mt.subtype = MEDIASUBTYPE_VOBSUB;
- mt.formattype = FORMAT_SubtitleInfo;
- SUBTITLEINFO* si = (SUBTITLEINFO*)mt.AllocFormatBuffer(sizeof(SUBTITLEINFO) + hdr.GetLength());
- memset(si, 0, mt.FormatLength());
- si->dwOffset = sizeof(SUBTITLEINFO);
- strcpy_s(si->IsoLang, countof(si->IsoLang), CStringA(TrackLanguage));
- wcscpy_s(si->TrackName, countof(si->TrackName), TrackName);
- memcpy(si + 1, (LPCSTR)hdr, hdr.GetLength());
- mts.Add(mt);
- }
- break;
+ const AP4_Byte* pal = di->GetData();
+ CAtlList<CStringA> sl;
+ for(int i = 0; i < 16*4; i += 4) {
+ BYTE y = (pal[i+1]-16)*255/219;
+ BYTE u = pal[i+2];
+ BYTE v = pal[i+3];
+ BYTE r = (BYTE)min(max(1.0*y + 1.4022*(v-128), 0), 255);
+ BYTE g = (BYTE)min(max(1.0*y - 0.3456*(u-128) - 0.7145*(v-128), 0), 255);
+ BYTE b = (BYTE)min(max(1.0*y + 1.7710*(u-128), 0) , 255);
+ CStringA str;
+ str.Format("%02x%02x%02x", r, g, b);
+ sl.AddTail(str);
+ }
+
+ CStringA hdr;
+ hdr.Format(
+ "# VobSub index file, v7 (do not modify this line!)\n"
+ "size: %dx%d\n"
+ "palette: %s\n",
+ size.cx, size.cy,
+ Implode(sl, ','));
+
+ mt.majortype = MEDIATYPE_Subtitle;
+ mt.subtype = MEDIASUBTYPE_VOBSUB;
+ mt.formattype = FORMAT_SubtitleInfo;
+ SUBTITLEINFO* si = (SUBTITLEINFO*)mt.AllocFormatBuffer(sizeof(SUBTITLEINFO) + hdr.GetLength());
+ memset(si, 0, mt.FormatLength());
+ si->dwOffset = sizeof(SUBTITLEINFO);
+ strcpy_s(si->IsoLang, countof(si->IsoLang), CStringA(TrackLanguage));
+ wcscpy_s(si->TrackName, countof(si->TrackName), TrackName);
+ memcpy(si + 1, (LPCSTR)hdr, hdr.GetLength());
+ mts.Add(mt);
+ }
+ break;
}
- if(mt.subtype == GUID_NULL)
- {
+ if(mt.subtype == GUID_NULL) {
TRACE(_T("Unknown audio OBI: %02x\n"), system_desc->GetObjectTypeId());
}
- }
- else if(AP4_UnknownSampleDescription* unknown_desc =
- dynamic_cast<AP4_UnknownSampleDescription*>(desc)) // TEMP
- {
+ } else if(AP4_UnknownSampleDescription* unknown_desc =
+ dynamic_cast<AP4_UnknownSampleDescription*>(desc)) { // TEMP
AP4_SampleEntry* sample_entry = unknown_desc->GetSampleEntry();
if(dynamic_cast<AP4_TextSampleEntry*>(sample_entry)
- || dynamic_cast<AP4_Tx3gSampleEntry*>(sample_entry))
- {
+ || dynamic_cast<AP4_Tx3gSampleEntry*>(sample_entry)) {
mt.majortype = MEDIATYPE_Subtitle;
mt.subtype = MEDIASUBTYPE_ASS2;
mt.formattype = FORMAT_SubtitleInfo;
@@ -384,7 +375,7 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
"[V4++ Styles]\n"
"Style: Text,Arial,12,&H00ffffff,&H0000ffff,&H00000000,&H80000000,0,0,0,0,100,100,0,0.00,3,0,0,2,0,0,0,0,1,1\n",
// "Style: Text,Arial,12,&H00ffffff,&H0000ffff,&H00000000,&H80000000,0,0,0,0,100,100,0,0.00,1,0,0,2,0,0,0,0,1,1\n",
- m_framesize.cx,
+ m_framesize.cx,
m_framesize.cy);
SUBTITLEINFO* si = (SUBTITLEINFO*)mt.AllocFormatBuffer(sizeof(SUBTITLEINFO) + hdr.GetLength());
memset(si, 0, mt.FormatLength());
@@ -395,14 +386,13 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mts.Add(mt);
}
}
- }
- else if(AP4_Avc1SampleEntry* avc1 = dynamic_cast<AP4_Avc1SampleEntry*>(
- track->GetTrakAtom()->FindChild("mdia/minf/stbl/stsd/avc1")))
- {
- if(AP4_AvcCAtom* avcC = dynamic_cast<AP4_AvcCAtom*>(avc1->GetChild(AP4_ATOM_TYPE_AVCC)))
- {
+ } else if(AP4_Avc1SampleEntry* avc1 = dynamic_cast<AP4_Avc1SampleEntry*>(
+ track->GetTrakAtom()->FindChild("mdia/minf/stbl/stsd/avc1"))) {
+ if(AP4_AvcCAtom* avcC = dynamic_cast<AP4_AvcCAtom*>(avc1->GetChild(AP4_ATOM_TYPE_AVCC))) {
const AP4_DataBuffer* di = avcC->GetDecoderInfo();
- if(!di) di = &empty;
+ if(!di) {
+ di = &empty;
+ }
const AP4_Byte* data = di->GetData();
AP4_Size size = di->GetDataSize();
@@ -421,8 +411,9 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
vih->hdr.bmiHeader.biBitCount = 24;
vih->hdr.dwPictAspectRatioX = vih->hdr.bmiHeader.biWidth;
vih->hdr.dwPictAspectRatioY = vih->hdr.bmiHeader.biHeight;
- if (item->GetData()->GetSampleCount() > 1)
+ if (item->GetData()->GetSampleCount() > 1) {
vih->hdr.AvgTimePerFrame = item->GetData()->GetDurationMs()*10000 / (item->GetData()->GetSampleCount()-1);
+ }
vih->dwProfile = data[1];
vih->dwLevel = data[3];
vih->dwFlags = (data[4] & 3) + 1;
@@ -435,14 +426,15 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
BYTE* src_end = (BYTE*)data + size;
BYTE* dst_end = (BYTE*)vih->dwSequenceHeader + size;
- for(int i = 0; i < 2; i++)
- {
- for(int n = *src++ & 0x1f; n > 0; n--)
- {
+ for(int i = 0; i < 2; i++) {
+ for(int n = *src++ & 0x1f; n > 0; n--) {
int len = ((src[0] << 8) | src[1]) + 2;
- if(src + len > src_end || dst + len > dst_end) {ASSERT(0); break;}
+ if(src + len > src_end || dst + len > dst_end) {
+ ASSERT(0);
+ break;
+ }
memcpy(dst, src, len);
- src += len;
+ src += len;
dst += len;
vih->cbSequenceHeader += len;
}
@@ -453,44 +445,33 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mt.subtype = FOURCCMap(vih->hdr.bmiHeader.biCompression = '1CVA');
mts.Add(mt);
}
- }
- else if(AP4_StsdAtom* stsd = dynamic_cast<AP4_StsdAtom*>(
- track->GetTrakAtom()->FindChild("mdia/minf/stbl/stsd")))
- {
+ } else if(AP4_StsdAtom* stsd = dynamic_cast<AP4_StsdAtom*>(
+ track->GetTrakAtom()->FindChild("mdia/minf/stbl/stsd"))) {
const AP4_DataBuffer& db = stsd->GetDataBuffer();
- for(AP4_List<AP4_Atom>::Item* item = stsd->GetChildren().FirstItem();
- item;
- item = item->GetNext())
- {
+ for(AP4_List<AP4_Atom>::Item* item = stsd->GetChildren().FirstItem();
+ item;
+ item = item->GetNext()) {
AP4_Atom* atom = item->GetData();
AP4_Atom::Type type = atom->GetType();
DWORD fourcc;
- if((type & 0xffff0000) == AP4_ATOM_TYPE('m', 's', 0, 0))
- {
+ if((type & 0xffff0000) == AP4_ATOM_TYPE('m', 's', 0, 0)) {
fourcc = type & 0xffff;
- }
- else if(type == AP4_ATOM_TYPE__MP3)
- {
+ } else if(type == AP4_ATOM_TYPE__MP3) {
fourcc = 0x0055;
- }
- else if((type == AP4_ATOM_TYPE__AC3) || (type == AP4_ATOM_TYPE_SAC3))
- {
+ } else if((type == AP4_ATOM_TYPE__AC3) || (type == AP4_ATOM_TYPE_SAC3)) {
fourcc = 0x2000;
- }
- else
- {
- fourcc =
+ } else {
+ fourcc =
((type >> 24) & 0x000000ff) |
((type >> 8) & 0x0000ff00) |
((type << 8) & 0x00ff0000) |
((type << 24) & 0xff000000);
}
- if(AP4_VisualSampleEntry* vse = dynamic_cast<AP4_VisualSampleEntry*>(atom))
- {
+ if(AP4_VisualSampleEntry* vse = dynamic_cast<AP4_VisualSampleEntry*>(atom)) {
mt.majortype = MEDIATYPE_Video;
mt.subtype = FOURCCMap(fourcc);
mt.formattype = FORMAT_VideoInfo;
@@ -511,8 +492,7 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
strlwr((char*)&buff);
AP4_Atom::Type typelwr = *(AP4_Atom::Type*)buff;
- if(typelwr != fourcc)
- {
+ if(typelwr != fourcc) {
mt.subtype = FOURCCMap(vih->bmiHeader.biCompression = typelwr);
mts.Add(mt);
}
@@ -520,28 +500,27 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
strupr((char*)&buff);
AP4_Atom::Type typeupr = *(AP4_Atom::Type*)buff;
- if(typeupr != fourcc)
- {
+ if(typeupr != fourcc) {
mt.subtype = FOURCCMap(vih->bmiHeader.biCompression = typeupr);
mts.Add(mt);
}
break;
- }
- else if(AP4_AudioSampleEntry* ase = dynamic_cast<AP4_AudioSampleEntry*>(atom))
- {
- if (ase->IsLittleEndian()==1)
- {
+ } else if(AP4_AudioSampleEntry* ase = dynamic_cast<AP4_AudioSampleEntry*>(atom)) {
+ if (ase->IsLittleEndian()==1) {
if (type==AP4_ATOM_TYPE_IN24 || type==AP4_ATOM_TYPE_IN32 ||
- type==AP4_ATOM_TYPE_FL32 || type==AP4_ATOM_TYPE_FL64)
- fourcc = type; //reverse fourcc
+ type==AP4_ATOM_TYPE_FL32 || type==AP4_ATOM_TYPE_FL64) {
+ fourcc = type; //reverse fourcc
+ }
}
mt.majortype = MEDIATYPE_Audio;
mt.subtype = FOURCCMap(fourcc);
mt.formattype = FORMAT_WaveFormatEx;
wfe = (WAVEFORMATEX*)mt.AllocFormatBuffer(sizeof(WAVEFORMATEX) + db.GetDataSize());
memset(wfe, 0, mt.FormatLength());
- if(!(fourcc & 0xffff0000)) wfe->wFormatTag = (WORD)fourcc;
+ if(!(fourcc & 0xffff0000)) {
+ wfe->wFormatTag = (WORD)fourcc;
+ }
wfe->nSamplesPerSec = ase->GetSampleRate();
wfe->nChannels = ase->GetChannelCount();
wfe->wBitsPerSample = ase->GetSampleSize();
@@ -551,37 +530,39 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
memcpy(wfe+1, db.GetData(), db.GetDataSize());
mts.Add(mt);
break;
- }else{
+ } else {
TRACE(_T("Unknow MP4 Steam %x") , fourcc);
}
}
}
- if(mts.IsEmpty()) continue;
+ if(mts.IsEmpty()) {
+ continue;
+ }
REFERENCE_TIME rtDuration = 10000i64 * track->GetDurationMs();
- if(m_rtDuration < rtDuration) m_rtDuration = rtDuration;
+ if(m_rtDuration < rtDuration) {
+ m_rtDuration = rtDuration;
+ }
DWORD id = track->GetId();
CStringW name, lang;
name.Format(L"Output %d", id);
- if(!TrackName.IsEmpty())
- {
+ if(!TrackName.IsEmpty()) {
name = TrackName;
}
- if(!TrackLanguage.IsEmpty())
- {
- if(TrackLanguage != L"und") name += " (" + TrackLanguage + ")";
+ if(!TrackLanguage.IsEmpty()) {
+ if(TrackLanguage != L"und") {
+ name += " (" + TrackLanguage + ")";
+ }
}
- for(int i = 0, j = mts.GetCount(); i < j; i++)
- {
+ for(int i = 0, j = mts.GetCount(); i < j; i++) {
BITMAPINFOHEADER bih;
- if(ExtractBIH(&mts[i], &bih))
- {
+ if(ExtractBIH(&mts[i], &bih)) {
m_framesize.cx = bih.biWidth;
m_framesize.cy = abs(bih.biHeight);
}
@@ -589,15 +570,18 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CBaseSplitterOutputPin(mts, name, this, this, &hr));
- if(!TrackName.IsEmpty()) pPinOut->SetProperty(L"NAME", TrackName);
- if(!TrackLanguage.IsEmpty()) pPinOut->SetProperty(L"LANG", CStringW(TrackLanguage));
+ if(!TrackName.IsEmpty()) {
+ pPinOut->SetProperty(L"NAME", TrackName);
+ }
+ if(!TrackLanguage.IsEmpty()) {
+ pPinOut->SetProperty(L"LANG", CStringW(TrackLanguage));
+ }
EXECUTE_ASSERT(SUCCEEDED(AddOutputPin(id, pPinOut)));
m_trackpos[id] = trackpos();
- if(mts.GetCount() == 1 && mts[0].subtype == MEDIASUBTYPE_ASS2)
- {
+ if(mts.GetCount() == 1 && mts[0].subtype == MEDIASUBTYPE_ASS2) {
LPCWSTR postfix = L" (plain text)";
mts[0].subtype = MEDIASUBTYPE_UTF8;
@@ -609,19 +593,21 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CBaseSplitterOutputPin(mts, name + postfix, this, this, &hr));
- if(!TrackName.IsEmpty()) pPinOut->SetProperty(L"NAME", TrackName + postfix);
- if(!TrackLanguage.IsEmpty()) pPinOut->SetProperty(L"LANG", CStringW(TrackLanguage));
+ if(!TrackName.IsEmpty()) {
+ pPinOut->SetProperty(L"NAME", TrackName + postfix);
+ }
+ if(!TrackLanguage.IsEmpty()) {
+ pPinOut->SetProperty(L"LANG", CStringW(TrackLanguage));
+ }
EXECUTE_ASSERT(SUCCEEDED(AddOutputPin(id, pPinOut)));
}
}
- if(AP4_ChplAtom* chpl = dynamic_cast<AP4_ChplAtom*>(movie->GetMoovAtom()->FindChild("udta/chpl")))
- {
+ if(AP4_ChplAtom* chpl = dynamic_cast<AP4_ChplAtom*>(movie->GetMoovAtom()->FindChild("udta/chpl"))) {
AP4_Array<AP4_ChplAtom::AP4_Chapter>& chapters = chpl->GetChapters();
- for(AP4_Cardinal i = 0; i < chapters.ItemCount(); i++)
- {
+ for(AP4_Cardinal i = 0; i < chapters.ItemCount(); i++) {
AP4_ChplAtom::AP4_Chapter& chapter = chapters[i];
ChapAppend(chapter.Time, UTF8To16(ConvertMBCS(chapter.Name.c_str(), ANSI_CHARSET, CP_UTF8))); // this is b0rked, thx to nero :P
}
@@ -629,64 +615,88 @@ HRESULT CMP4SplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
ChapSort();
}
- if(AP4_ContainerAtom* ilst = dynamic_cast<AP4_ContainerAtom*>(movie->GetMoovAtom()->FindChild("udta/meta/ilst")))
- {
+ if(AP4_ContainerAtom* ilst = dynamic_cast<AP4_ContainerAtom*>(movie->GetMoovAtom()->FindChild("udta/meta/ilst"))) {
CStringW title, artist, writer, album, year, appl, desc, gen, track;
for(AP4_List<AP4_Atom>::Item* item = ilst->GetChildren().FirstItem();
- item;
- item = item->GetNext())
- {
- if(AP4_ContainerAtom* atom = dynamic_cast<AP4_ContainerAtom*>(item->GetData()))
- {
- if(AP4_DataAtom* data = dynamic_cast<AP4_DataAtom*>(atom->GetChild(AP4_ATOM_TYPE_DATA)))
- {
+ item;
+ item = item->GetNext()) {
+ if(AP4_ContainerAtom* atom = dynamic_cast<AP4_ContainerAtom*>(item->GetData())) {
+ if(AP4_DataAtom* data = dynamic_cast<AP4_DataAtom*>(atom->GetChild(AP4_ATOM_TYPE_DATA))) {
const AP4_DataBuffer* db = data->GetData();
- if(atom->GetType() == AP4_ATOM_TYPE_TRKN)
- {
- if(db->GetDataSize() >= 4)
- {
+ if(atom->GetType() == AP4_ATOM_TYPE_TRKN) {
+ if(db->GetDataSize() >= 4) {
unsigned short n = (db->GetData()[2] << 8) | db->GetData()[3];
- if(n > 0 && n < 100) track.Format(L"%02d", n);
- else if(n >= 100) track.Format(L"%d", n);
+ if(n > 0 && n < 100) {
+ track.Format(L"%02d", n);
+ } else if(n >= 100) {
+ track.Format(L"%d", n);
+ }
}
- }
- else
- {
+ } else {
CStringW str = UTF8To16(CStringA((LPCSTR)db->GetData(), db->GetDataSize()));
- switch(atom->GetType())
- {
- case AP4_ATOM_TYPE_NAM: title = str; break;
- case AP4_ATOM_TYPE_ART: artist = str; break;
- case AP4_ATOM_TYPE_WRT: writer = str; break;
- case AP4_ATOM_TYPE_ALB: album = str; break;
- case AP4_ATOM_TYPE_DAY: year = str; break;
- case AP4_ATOM_TYPE_TOO: appl = str; break;
- case AP4_ATOM_TYPE_CMT: desc = str; break;
- case AP4_ATOM_TYPE_GEN: gen = str; break;
+ switch(atom->GetType()) {
+ case AP4_ATOM_TYPE_NAM:
+ title = str;
+ break;
+ case AP4_ATOM_TYPE_ART:
+ artist = str;
+ break;
+ case AP4_ATOM_TYPE_WRT:
+ writer = str;
+ break;
+ case AP4_ATOM_TYPE_ALB:
+ album = str;
+ break;
+ case AP4_ATOM_TYPE_DAY:
+ year = str;
+ break;
+ case AP4_ATOM_TYPE_TOO:
+ appl = str;
+ break;
+ case AP4_ATOM_TYPE_CMT:
+ desc = str;
+ break;
+ case AP4_ATOM_TYPE_GEN:
+ gen = str;
+ break;
}
}
}
}
}
- if(!title.IsEmpty())
- {
- if(!track.IsEmpty()) title = track + L" - " + title;
- if(!album.IsEmpty()) title = album + L" - " + title;
- if(!year.IsEmpty()) title += L" - " + year;
- if(!gen.IsEmpty()) title += L" - " + gen;
+ if(!title.IsEmpty()) {
+ if(!track.IsEmpty()) {
+ title = track + L" - " + title;
+ }
+ if(!album.IsEmpty()) {
+ title = album + L" - " + title;
+ }
+ if(!year.IsEmpty()) {
+ title += L" - " + year;
+ }
+ if(!gen.IsEmpty()) {
+ title += L" - " + gen;
+ }
SetProperty(L"TITL", title);
}
- if(!artist.IsEmpty()) SetProperty(L"AUTH", artist);
- else if(!writer.IsEmpty()) SetProperty(L"AUTH", writer);
+ if(!artist.IsEmpty()) {
+ SetProperty(L"AUTH", artist);
+ } else if(!writer.IsEmpty()) {
+ SetProperty(L"AUTH", writer);
+ }
- if(!appl.IsEmpty()) SetProperty(L"APPL", appl);
+ if(!appl.IsEmpty()) {
+ SetProperty(L"APPL", appl);
+ }
- if(!desc.IsEmpty()) SetProperty(L"DESC", desc);
+ if(!desc.IsEmpty()) {
+ SetProperty(L"DESC", desc);
+ }
}
}
@@ -702,8 +712,7 @@ bool CMP4SplitterFilter::DemuxInit()
AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie();
POSITION pos = m_trackpos.GetStartPosition();
- while(pos)
- {
+ while(pos) {
CAtlMap<DWORD, trackpos>::CPair* pPair = m_trackpos.GetNext(pos);
pPair->m_value.index = 0;
@@ -712,8 +721,9 @@ bool CMP4SplitterFilter::DemuxInit()
AP4_Track* track = movie->GetTrack(pPair->m_key);
AP4_Sample sample;
- if(AP4_SUCCEEDED(track->GetSample(0, sample)))
+ if(AP4_SUCCEEDED(track->GetSample(0, sample))) {
pPair->m_value.ts = sample.GetCts();
+ }
}
return true;
@@ -726,42 +736,48 @@ void CMP4SplitterFilter::DemuxSeek(REFERENCE_TIME rt)
AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie();
POSITION pos = m_trackpos.GetStartPosition();
- while(pos)
- {
+ while(pos) {
CAtlMap<DWORD, trackpos>::CPair* pPair = m_trackpos.GetNext(pos);
AP4_Track* track = movie->GetTrack(pPair->m_key);
- if(AP4_FAILED(track->GetSampleIndexForTimeStampMs(ts, pPair->m_value.index)))
+ if(AP4_FAILED(track->GetSampleIndexForTimeStampMs(ts, pPair->m_value.index))) {
pPair->m_value.index = 0;
+ }
AP4_Sample sample;
- if(AP4_SUCCEEDED(track->GetSample(pPair->m_value.index, sample)))
+ if(AP4_SUCCEEDED(track->GetSample(pPair->m_value.index, sample))) {
pPair->m_value.ts = sample.GetCts();
+ }
// FIXME: slow search & stss->m_Entries is private
- if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss")))
- {
- if(stss->m_Entries.ItemCount() > 0)
- {
+ if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss"))) {
+ if(stss->m_Entries.ItemCount() > 0) {
AP4_Cardinal i = -1;
- while(++i < stss->m_Entries.ItemCount() && stss->m_Entries[i]-1 <= pPair->m_value.index);
- if(i > 0) i--;
+ while(++i < stss->m_Entries.ItemCount() && stss->m_Entries[i]-1 <= pPair->m_value.index) {
+ ;
+ }
+ if(i > 0) {
+ i--;
+ }
pPair->m_value.index = stss->m_Entries[i]-1;
}
}
}
}
-struct SSACharacter {CString pre, post; WCHAR c;};
+struct SSACharacter {
+ CString pre, post;
+ WCHAR c;
+};
static CStringW ConvertTX3GToSSA(
- CStringW str,
- const AP4_Tx3gSampleEntry::AP4_Tx3gDescription& desc,
+ CStringW str,
+ const AP4_Tx3gSampleEntry::AP4_Tx3gDescription& desc,
CStringW font,
- const AP4_Byte* mods,
- int size,
+ const AP4_Byte* mods,
+ int size,
CSize framesize,
CPoint translation,
int durationms,
@@ -770,7 +786,9 @@ static CStringW ConvertTX3GToSSA(
int str_len = str.GetLength();
SSACharacter* chars = DNew SSACharacter[str_len];
- for(int i = 0; i < str_len; i++) chars[i].c = str[i];
+ for(int i = 0; i < str_len; i++) {
+ chars[i].c = str[i];
+ }
str.Empty();
//
@@ -780,21 +798,35 @@ static CStringW ConvertTX3GToSSA(
int align = 2;
signed char h = (signed char)desc.HorizontalJustification;
signed char v = (signed char)desc.VerticalJustification;
- if(h == 0 && v < 0) align = 1;
- else if(h > 0 && v < 0) align = 2;
- else if(h < 0 && v < 0) align = 3;
- else if(h == 0 && v > 0) align = 4;
- else if(h > 0 && v > 0) align = 5;
- else if(h < 0 && v > 0) align = 6;
- else if(h == 0 && v == 0) align = 7;
- else if(h > 0 && v == 0) align = 8;
- else if(h < 0 && v == 0) align = 9;
+ if(h == 0 && v < 0) {
+ align = 1;
+ } else if(h > 0 && v < 0) {
+ align = 2;
+ } else if(h < 0 && v < 0) {
+ align = 3;
+ } else if(h == 0 && v > 0) {
+ align = 4;
+ } else if(h > 0 && v > 0) {
+ align = 5;
+ } else if(h < 0 && v > 0) {
+ align = 6;
+ } else if(h == 0 && v == 0) {
+ align = 7;
+ } else if(h > 0 && v == 0) {
+ align = 8;
+ } else if(h < 0 && v == 0) {
+ align = 9;
+ }
str.Format(L"{\\an%d}%s", align, CStringW(str));
- if(!font.CompareNoCase(L"serif")) font = L"Times New Roman";
- else if(!font.CompareNoCase(L"sans-serif")) font = L"Arial";
- else if(!font.CompareNoCase(L"monospace")) font = L"Courier New";
- str.Format(L"{\\fn%s}%s", font, CStringW(str));
+ if(!font.CompareNoCase(L"serif")) {
+ font = L"Times New Roman";
+ } else if(!font.CompareNoCase(L"sans-serif")) {
+ font = L"Arial";
+ } else if(!font.CompareNoCase(L"monospace")) {
+ font = L"Courier New";
+ }
+ str.Format(L"{\\fn%s}%s", font, CStringW(str));
const AP4_Byte* fclr = (const AP4_Byte*)&desc.Style.Font.Color;
@@ -809,42 +841,49 @@ static CStringW ConvertTX3GToSSA(
str = font_size + str;
CStringW font_flags;
- font_flags.Format(L"{\\b%d\\i%d\\u%d}",
- (desc.Style.Font.Face&1) ? 1 : 0,
- (desc.Style.Font.Face&2) ? 1 : 0,
- (desc.Style.Font.Face&4) ? 1 : 0);
+ font_flags.Format(L"{\\b%d\\i%d\\u%d}",
+ (desc.Style.Font.Face&1) ? 1 : 0,
+ (desc.Style.Font.Face&2) ? 1 : 0,
+ (desc.Style.Font.Face&4) ? 1 : 0);
str = font_flags + str;
//
const AP4_Byte* hclr = (const AP4_Byte*)&desc.BackgroundColor;
- while(size > 8)
- {
- DWORD tag_size = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]); mods += 4;
- DWORD tag = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]); mods += 4;
+ while(size > 8) {
+ DWORD tag_size = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]);
+ mods += 4;
+ DWORD tag = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]);
+ mods += 4;
size -= tag_size;
tag_size -= 8;
const AP4_Byte* next = mods + tag_size;
- if(tag == 'styl')
- {
- WORD styl_count = (mods[0]<<8)|(mods[1]); mods += 2;
-
- while(styl_count-- > 0)
- {
- WORD start = (mods[0]<<8)|(mods[1]); mods += 2;
- WORD end = (mods[0]<<8)|(mods[1]); mods += 2;
- WORD font_id = (mods[0]<<8)|(mods[1]); mods += 2;
- WORD flags = mods[0]; mods += 1;
- WORD size = mods[0]; mods += 1;
- const AP4_Byte* color = mods; mods += 4;
-
- if(end > str_len) end = str_len;
+ if(tag == 'styl') {
+ WORD styl_count = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+
+ while(styl_count-- > 0) {
+ WORD start = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ WORD end = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ WORD font_id = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ WORD flags = mods[0];
+ mods += 1;
+ WORD size = mods[0];
+ mods += 1;
+ const AP4_Byte* color = mods;
+ mods += 4;
+
+ if(end > str_len) {
+ end = str_len;
+ }
- if(start < end)
- {
+ if(start < end) {
CStringW s;
s.Format(L"{\\1c%02x%02x%02x\\1a%02x}", color[2], color[1], color[0], 255 - color[3]);
@@ -856,24 +895,23 @@ static CStringW ConvertTX3GToSSA(
chars[end-1].post += font_size;
s.Format(L"{\\b%d\\i%d\\u%d}", (flags&1) ? 1 : 0, (flags&2) ? 1 : 0, (flags&4) ? 1 : 0);
- chars[start].pre += s;
+ chars[start].pre += s;
chars[end-1].post += font_flags;
}
}
- }
- else if(tag == 'hclr')
- {
+ } else if(tag == 'hclr') {
hclr = mods;
- }
- else if(tag == 'hlit')
- {
- WORD start = (mods[0]<<8)|(mods[1]); mods += 2;
- WORD end = (mods[0]<<8)|(mods[1]); mods += 2;
-
- if(end > str_len) end = str_len;
+ } else if(tag == 'hlit') {
+ WORD start = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ WORD end = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+
+ if(end > str_len) {
+ end = str_len;
+ }
- if(start < end)
- {
+ if(start < end) {
CStringW s;
s.Format(L"{\\3c%02x%02x%02x\\3a%02x}", hclr[2], hclr[1], hclr[0], 255 - hclr[3]);
@@ -883,20 +921,20 @@ static CStringW ConvertTX3GToSSA(
chars[start].pre += L"{\\bord0.1}";
chars[end-1].post += L"{\\bord}";
}
- }
- else if(tag == 'blnk')
- {
- WORD start = (mods[0]<<8)|(mods[1]); mods += 2;
- WORD end = (mods[0]<<8)|(mods[1]); mods += 2;
-
- if(end > str_len) end = str_len;
+ } else if(tag == 'blnk') {
+ WORD start = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ WORD end = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+
+ if(end > str_len) {
+ end = str_len;
+ }
- if(start < end)
- {
+ if(start < end) {
// cheap...
- for(int i = 0, alpha = 255; i < durationms; i += 750, alpha = 255 - alpha)
- {
+ for(int i = 0, alpha = 255; i < durationms; i += 750, alpha = 255 - alpha) {
CStringW s;
s.Format(L"{\\t(%d, %d, \\alpha&H%02x&)}", i, i + 750, alpha);
chars[start].pre += s;
@@ -904,29 +942,34 @@ static CStringW ConvertTX3GToSSA(
chars[end-1].post += L"{\\alpha}";
}
- }
- else if(tag == 'tbox')
- {
- rbox.top = (mods[0]<<8)|(mods[1]); mods += 2;
- rbox.left = (mods[0]<<8)|(mods[1]); mods += 2;
- rbox.bottom = (mods[0]<<8)|(mods[1]); mods += 2;
- rbox.right = (mods[0]<<8)|(mods[1]); mods += 2;
- }
- else if(tag == 'krok' && !(desc.DisplayFlags & 0x800))
- {
- DWORD start_time = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]); mods += 4;
- WORD krok_count = (mods[0]<<8)|(mods[1]); mods += 2;
-
- while(krok_count-- > 0)
- {
- DWORD end_time = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]); mods += 4;
- WORD start = (mods[0]<<8)|(mods[1]); mods += 2;
- WORD end = (mods[0]<<8)|(mods[1]); mods += 2;
-
- if(end > str_len) end = str_len;
+ } else if(tag == 'tbox') {
+ rbox.top = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ rbox.left = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ rbox.bottom = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ rbox.right = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ } else if(tag == 'krok' && !(desc.DisplayFlags & 0x800)) {
+ DWORD start_time = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]);
+ mods += 4;
+ WORD krok_count = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+
+ while(krok_count-- > 0) {
+ DWORD end_time = (mods[0]<<24)|(mods[1]<<16)|(mods[2]<<8)|(mods[3]);
+ mods += 4;
+ WORD start = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+ WORD end = (mods[0]<<8)|(mods[1]);
+ mods += 2;
+
+ if(end > str_len) {
+ end = str_len;
+ }
- if(start < end)
- {
+ if(start < end) {
CStringW s;
s.Format(L"{\\kt%d\\kf%d}", start_time/10, (end_time - start_time)/10);
@@ -945,8 +988,7 @@ static CStringW ConvertTX3GToSSA(
// continous karaoke
- if(desc.DisplayFlags & 0x800)
- {
+ if(desc.DisplayFlags & 0x800) {
CStringW s;
s.Format(L"{\\1c%02x%02x%02x\\1a%02x}", hclr[2], hclr[1], hclr[0], 255 - hclr[3]);
@@ -954,22 +996,17 @@ static CStringW ConvertTX3GToSSA(
int breaks = 0;
- for(int i = 0, j = 0; i <= str_len; i++)
- {
- if(chars[i].c == '\n' /*|| chars[i].c == ' '*/)
- {
+ for(int i = 0, j = 0; i <= str_len; i++) {
+ if(chars[i].c == '\n' /*|| chars[i].c == ' '*/) {
breaks++;
}
}
- if(str_len > breaks)
- {
+ if(str_len > breaks) {
float dur = (float)max(durationms - 500, 0) / 10;
- for(int i = 0, j = 0; i <= str_len; i++)
- {
- if(i == str_len || chars[i].c == '\n' /*|| chars[i].c == ' '*/)
- {
+ for(int i = 0, j = 0; i <= str_len; i++) {
+ if(i == str_len || chars[i].c == '\n' /*|| chars[i].c == ' '*/) {
s.Format(L"{\\kf%d}", (int)(dur * (i - j) / (str_len - breaks)));
chars[j].pre += s;
j = i+1;
@@ -980,11 +1017,12 @@ static CStringW ConvertTX3GToSSA(
//
- for(int i = 0; i < str_len; i++)
- {
+ for(int i = 0; i < str_len; i++) {
str += chars[i].pre;
str += chars[i].c;
- if(desc.DisplayFlags & 0x20000) str += L"\\N";
+ if(desc.DisplayFlags & 0x20000) {
+ str += L"\\N";
+ }
str += chars[i].post;
}
@@ -992,20 +1030,28 @@ static CStringW ConvertTX3GToSSA(
//
- if(rbox.IsRectEmpty()) rbox.SetRect(0, 0, framesize.cx, framesize.cy);
+ if(rbox.IsRectEmpty()) {
+ rbox.SetRect(0, 0, framesize.cx, framesize.cy);
+ }
rbox.OffsetRect(translation);
CRect rbox2 = rbox;
rbox2.DeflateRect(2, 2);
CRect r(0,0,0,0);
- if(rbox2.Height() > 0) {r.top = rbox2.top; r.bottom = framesize.cy - rbox2.bottom;}
- if(rbox2.Width() > 0) {r.left = rbox2.left; r.right = framesize.cx - rbox2.right;}
+ if(rbox2.Height() > 0) {
+ r.top = rbox2.top;
+ r.bottom = framesize.cy - rbox2.bottom;
+ }
+ if(rbox2.Width() > 0) {
+ r.left = rbox2.left;
+ r.right = framesize.cx - rbox2.right;
+ }
CStringW hdr;
- hdr.Format(L"0,0,Text,,%d,%d,%d,%d,,{\\clip(%d,%d,%d,%d)}",
- r.left, r.right, r.top, r.bottom,
- rbox.left, rbox.top, rbox.right, rbox.bottom);
+ hdr.Format(L"0,0,Text,,%d,%d,%d,%d,,{\\clip(%d,%d,%d,%d)}",
+ r.left, r.right, r.top, r.bottom,
+ rbox.left, rbox.top, rbox.right, rbox.bottom);
//
@@ -1018,31 +1064,32 @@ bool CMP4SplitterFilter::DemuxLoop()
AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie();
- while(SUCCEEDED(hr) && !CheckRequest(NULL))
- {
+ while(SUCCEEDED(hr) && !CheckRequest(NULL)) {
CAtlMap<DWORD, trackpos>::CPair* pPairNext = NULL;
REFERENCE_TIME rtNext = 0;
POSITION pos = m_trackpos.GetStartPosition();
- while(pos)
- {
+ while(pos) {
CAtlMap<DWORD, trackpos>::CPair* pPair = m_trackpos.GetNext(pos);
AP4_Track* track = movie->GetTrack(pPair->m_key);
CBaseSplitterOutputPin* pPin = GetOutputPin((DWORD)track->GetId());
- if(!pPin->IsConnected()) continue;
+ if(!pPin->IsConnected()) {
+ continue;
+ }
REFERENCE_TIME rt = (REFERENCE_TIME)(10000000.0 / track->GetMediaTimeScale() * pPair->m_value.ts);
- if(pPair->m_value.index < track->GetSampleCount() && (!pPairNext || rt < rtNext))
- {
+ if(pPair->m_value.index < track->GetSampleCount() && (!pPairNext || rt < rtNext)) {
pPairNext = pPair;
rtNext = rt;
}
}
- if(!pPairNext) break;
+ if(!pPairNext) {
+ break;
+ }
AP4_Track* track = movie->GetTrack(pPairNext->m_key);
@@ -1051,8 +1098,7 @@ bool CMP4SplitterFilter::DemuxLoop()
AP4_Sample sample;
AP4_DataBuffer data;
- if(pPin && pPin->IsConnected() && AP4_SUCCEEDED(track->ReadSample(pPairNext->m_value.index, sample, data)))
- {
+ if(pPin && pPin->IsConnected() && AP4_SUCCEEDED(track->ReadSample(pPairNext->m_value.index, sample, data))) {
const CMediaType& mt = pPin->CurrentMediaType();
CAutoPtr<Packet> p(DNew Packet());
@@ -1063,29 +1109,26 @@ bool CMP4SplitterFilter::DemuxLoop()
// FIXME: slow search & stss->m_Entries is private
- if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss")))
- {
- if(stss->m_Entries.ItemCount() > 0)
- {
+ if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss"))) {
+ if(stss->m_Entries.ItemCount() > 0) {
p->bSyncPoint = FALSE;
AP4_Cardinal i = -1;
while(++i < stss->m_Entries.ItemCount())
- if(stss->m_Entries[i]-1 == pPairNext->m_value.index)
+ if(stss->m_Entries[i]-1 == pPairNext->m_value.index) {
p->bSyncPoint = TRUE;
+ }
}
}
//
- if(track->GetType() == AP4_Track::TYPE_AUDIO && data.GetDataSize() == 1)
- {
+ if(track->GetType() == AP4_Track::TYPE_AUDIO && data.GetDataSize() == 1) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
int nBlockAlign = 1200;
- if(wfe->nBlockAlign > 1)
- {
+ if(wfe->nBlockAlign > 1) {
nBlockAlign = wfe->nBlockAlign;
pPairNext->m_value.index -= pPairNext->m_value.index % wfe->nBlockAlign;
}
@@ -1094,109 +1137,102 @@ bool CMP4SplitterFilter::DemuxLoop()
TRACE(_T("track->GetSampleCount() %d %d "), track->GetSampleCount(),pPairNext->m_value.index);
int fFirst = true;
- while(AP4_SUCCEEDED(track->ReadSample(pPairNext->m_value.index, sample, data)))
- {
+ while(AP4_SUCCEEDED(track->ReadSample(pPairNext->m_value.index, sample, data))) {
AP4_Size size = data.GetDataSize();
const AP4_Byte* ptr = data.GetData();
- for(int i = 0; i < size; i++) p->Add(ptr[i]);
+ for(int i = 0; i < size; i++) {
+ p->Add(ptr[i]);
+ }
- if(fFirst) {p->rtStart = p->rtStop = (REFERENCE_TIME)(10000000.0 / track->GetMediaTimeScale() * sample.GetCts()); fFirst = false;}
+ if(fFirst) {
+ p->rtStart = p->rtStop = (REFERENCE_TIME)(10000000.0 / track->GetMediaTimeScale() * sample.GetCts());
+ fFirst = false;
+ }
p->rtStop += (REFERENCE_TIME)(10000000.0 / track->GetMediaTimeScale() * sample.GetDuration());
- if(pPairNext->m_value.index+1 >= track->GetSampleCount() || p->GetCount() >= nBlockAlign)
+ if(pPairNext->m_value.index+1 >= track->GetSampleCount() || p->GetCount() >= nBlockAlign) {
break;
+ }
pPairNext->m_value.index++;
}
- }
- else if(track->GetType() == AP4_Track::TYPE_TEXT)
- {
+ } else if(track->GetType() == AP4_Track::TYPE_TEXT) {
CStringA dlgln_bkg, dlgln_plaintext;
const AP4_Byte* ptr = data.GetData();
AP4_Size avail = data.GetDataSize();
- if(avail > 2)
- {
+ if(avail > 2) {
AP4_UI16 size = (ptr[0] << 8) | ptr[1];
- if(size <= avail-2)
- {
+ if(size <= avail-2) {
CStringA str;
- if(size >= 2 && ptr[2] == 0xfe && ptr[3] == 0xff)
- {
+ if(size >= 2 && ptr[2] == 0xfe && ptr[3] == 0xff) {
CStringW wstr = CStringW((LPCWSTR)&ptr[2], size/2);
- for(int i = 0; i < wstr.GetLength(); i++) wstr.SetAt(i, ((WORD)wstr[i] >> 8) | ((WORD)wstr[i] << 8));
+ for(int i = 0; i < wstr.GetLength(); i++) {
+ wstr.SetAt(i, ((WORD)wstr[i] >> 8) | ((WORD)wstr[i] << 8));
+ }
str = UTF16To8(wstr);
- }
- else
- {
+ } else {
str = CStringA((LPCSTR)&ptr[2], size);
}
CStringA dlgln = str;
- if(mt.subtype == MEDIASUBTYPE_ASS2)
- {
+ if(mt.subtype == MEDIASUBTYPE_ASS2) {
AP4_SampleDescription* desc = track->GetSampleDescription(sample.GetDescriptionIndex());
dlgln = "0,0,Text,,0000,0000,0000,0000,," + str;
dlgln_plaintext = str;
CPoint translation(0, 0);
- if(AP4_TkhdAtom* tkhd = dynamic_cast<AP4_TkhdAtom*>(track->GetTrakAtom()->GetChild(AP4_ATOM_TYPE_TKHD)))
- {
+ if(AP4_TkhdAtom* tkhd = dynamic_cast<AP4_TkhdAtom*>(track->GetTrakAtom()->GetChild(AP4_ATOM_TYPE_TKHD))) {
AP4_Float x, y;
tkhd->GetTranslation(x, y);
translation.SetPoint((int)x, (int)y);
}
- if(AP4_UnknownSampleDescription* unknown_desc = dynamic_cast<AP4_UnknownSampleDescription*>(desc)) // TEMP
- {
+ if(AP4_UnknownSampleDescription* unknown_desc = dynamic_cast<AP4_UnknownSampleDescription*>(desc)) { // TEMP
AP4_SampleEntry* sample_entry = unknown_desc->GetSampleEntry();
- if(AP4_TextSampleEntry* text = dynamic_cast<AP4_TextSampleEntry*>(sample_entry))
- {
+ if(AP4_TextSampleEntry* text = dynamic_cast<AP4_TextSampleEntry*>(sample_entry)) {
const AP4_TextSampleEntry::AP4_TextDescription& d = text->GetDescription();
// TODO
- }
- else if(AP4_Tx3gSampleEntry* tx3g = dynamic_cast<AP4_Tx3gSampleEntry*>(sample_entry))
- {
+ } else if(AP4_Tx3gSampleEntry* tx3g = dynamic_cast<AP4_Tx3gSampleEntry*>(sample_entry)) {
const AP4_Tx3gSampleEntry::AP4_Tx3gDescription& desc = tx3g->GetDescription();
CStringW font = L"Arial";
- if(AP4_FtabAtom* ftab = dynamic_cast<AP4_FtabAtom*>(tx3g->GetChild(AP4_ATOM_TYPE_FTAB)))
- {
+ if(AP4_FtabAtom* ftab = dynamic_cast<AP4_FtabAtom*>(tx3g->GetChild(AP4_ATOM_TYPE_FTAB))) {
AP4_String Name;
- if(AP4_SUCCEEDED(ftab->LookupFont(desc.Style.Font.Id, Name)))
+ if(AP4_SUCCEEDED(ftab->LookupFont(desc.Style.Font.Id, Name))) {
font = Name.c_str();
- }
+ }
+ }
CRect rbox;
CStringW ssa = ConvertTX3GToSSA(
- UTF8To16(str), desc, font,
- ptr + (2 + size), avail - (2 + size),
- m_framesize, translation,
- (p->rtStop - p->rtStart)/10000,
- rbox);
+ UTF8To16(str), desc, font,
+ ptr + (2 + size), avail - (2 + size),
+ m_framesize, translation,
+ (p->rtStop - p->rtStart)/10000,
+ rbox);
dlgln = UTF16To8(ssa);
const AP4_Byte* bclr = (const AP4_Byte*)&desc.BackgroundColor;
- if(bclr[3])
- {
+ if(bclr[3]) {
CPoint tl = rbox.TopLeft();
rbox.OffsetRect(-tl.x, -tl.y);
dlgln_bkg.Format(
- "0,-1,Text,,0,0,0,0,,{\\an7\\pos(%d,%d)\\1c%02x%02x%02x\\1a%02x\\bord0\\shad0}{\\p1}m %d %d l %d %d l %d %d l %d %d {\\p0}",
- tl.x, tl.y,
- bclr[2], bclr[1], bclr[0],
+ "0,-1,Text,,0,0,0,0,,{\\an7\\pos(%d,%d)\\1c%02x%02x%02x\\1a%02x\\bord0\\shad0}{\\p1}m %d %d l %d %d l %d %d l %d %d {\\p0}",
+ tl.x, tl.y,
+ bclr[2], bclr[1], bclr[0],
255 - bclr[3],
- rbox.left, rbox.top,
+ rbox.left, rbox.top,
rbox.right, rbox.top,
rbox.right, rbox.bottom,
rbox.left, rbox.bottom);
@@ -1212,8 +1248,7 @@ bool CMP4SplitterFilter::DemuxLoop()
}
}
- if(!dlgln_bkg.IsEmpty())
- {
+ if(!dlgln_bkg.IsEmpty()) {
CAutoPtr<Packet> p2(DNew Packet());
p2->TrackNumber = p->TrackNumber;
p2->rtStart = p->rtStart;
@@ -1223,8 +1258,7 @@ bool CMP4SplitterFilter::DemuxLoop()
hr = DeliverPacket(p2);
}
- if(!dlgln_plaintext.IsEmpty())
- {
+ if(!dlgln_plaintext.IsEmpty()) {
CAutoPtr<Packet> p2(DNew Packet());
p2->TrackNumber = p->TrackNumber ^ 0x80402010;
p2->rtStart = p->rtStart;
@@ -1233,9 +1267,7 @@ bool CMP4SplitterFilter::DemuxLoop()
p2->SetData((LPCSTR)dlgln_plaintext, dlgln_plaintext.GetLength());
hr = DeliverPacket(p2);
}
- }
- else
- {
+ } else {
p->SetData(data.GetData(), data.GetDataSize());
}
@@ -1244,8 +1276,9 @@ bool CMP4SplitterFilter::DemuxLoop()
{
AP4_Sample sample;
- if(AP4_SUCCEEDED(track->GetSample(++pPairNext->m_value.index, sample)))
+ if(AP4_SUCCEEDED(track->GetSample(++pPairNext->m_value.index, sample))) {
pPairNext->m_value.ts = sample.GetCts();
+ }
}
}
@@ -1259,22 +1292,23 @@ STDMETHODIMP CMP4SplitterFilter::GetKeyFrameCount(UINT& nKFs)
{
CheckPointer(m_pFile, E_UNEXPECTED);
- if(!m_pFile) return E_UNEXPECTED;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie();
POSITION pos = m_trackpos.GetStartPosition();
- while(pos)
- {
+ while(pos) {
CAtlMap<DWORD, trackpos>::CPair* pPair = m_trackpos.GetNext(pos);
AP4_Track* track = movie->GetTrack(pPair->m_key);
- if(track->GetType() != AP4_Track::TYPE_VIDEO)
+ if(track->GetType() != AP4_Track::TYPE_VIDEO) {
continue;
+ }
- if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss")))
- {
+ if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss"))) {
nKFs = stss->m_Entries.ItemCount();
return S_OK;
}
@@ -1289,31 +1323,34 @@ STDMETHODIMP CMP4SplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENCE_TIM
CheckPointer(pKFs, E_POINTER);
CheckPointer(m_pFile, E_UNEXPECTED);
- if(*pFormat != TIME_FORMAT_MEDIA_TIME) return E_INVALIDARG;
+ if(*pFormat != TIME_FORMAT_MEDIA_TIME) {
+ return E_INVALIDARG;
+ }
- if(!m_pFile) return E_UNEXPECTED;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
AP4_Movie* movie = (AP4_Movie*)m_pFile->GetMovie();
POSITION pos = m_trackpos.GetStartPosition();
- while(pos)
- {
+ while(pos) {
CAtlMap<DWORD, trackpos>::CPair* pPair = m_trackpos.GetNext(pos);
AP4_Track* track = movie->GetTrack(pPair->m_key);
- if(track->GetType() != AP4_Track::TYPE_VIDEO)
+ if(track->GetType() != AP4_Track::TYPE_VIDEO) {
continue;
+ }
- if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss")))
- {
+ if(AP4_StssAtom* stss = dynamic_cast<AP4_StssAtom*>(track->GetTrakAtom()->FindChild("mdia/minf/stbl/stss"))) {
nKFs = 0;
- for(AP4_Cardinal i = 0; i < stss->m_Entries.ItemCount(); i++)
- {
+ for(AP4_Cardinal i = 0; i < stss->m_Entries.ItemCount(); i++) {
AP4_Sample sample;
- if(AP4_SUCCEEDED(track->GetSample(stss->m_Entries[i]-1, sample)))
+ if(AP4_SUCCEEDED(track->GetSample(stss->m_Entries[i]-1, sample))) {
pKFs[nKFs++] = 10000000i64 * sample.GetCts() / track->GetMediaTimeScale();
+ }
}
return S_OK;
@@ -1347,8 +1384,9 @@ void CMPEG4VideoSplitterFilter::SkipUserData()
{
m_pFile->BitByteAlign();
while(m_pFile->BitRead(32, true) == 0x000001b2)
- while(m_pFile->BitRead(24, true) != 0x000001)
+ while(m_pFile->BitRead(24, true) != 0x000001) {
m_pFile->BitRead(8);
+ }
}
HRESULT CMPEG4VideoSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
@@ -1359,8 +1397,13 @@ HRESULT CMPEG4VideoSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CBaseSplitterFileEx(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = 0;
@@ -1373,36 +1416,31 @@ HRESULT CMPEG4VideoSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
BYTE pary = 1;
REFERENCE_TIME atpf = 400000;
- if(m_pFile->BitRead(24, true) != 0x000001)
+ if(m_pFile->BitRead(24, true) != 0x000001) {
return E_FAIL;
+ }
BYTE id;
- while(m_pFile->NextMpegStartCode(id, 1024 - m_pFile->GetPos()))
- {
- if(id == 0xb5)
- {
+ while(m_pFile->NextMpegStartCode(id, 1024 - m_pFile->GetPos())) {
+ if(id == 0xb5) {
BYTE is_visual_object_identifier = (BYTE)m_pFile->BitRead(1);
- if(is_visual_object_identifier)
- {
+ if(is_visual_object_identifier) {
BYTE visual_object_verid = (BYTE)m_pFile->BitRead(4);
BYTE visual_object_priority = (BYTE)m_pFile->BitRead(3);
}
BYTE visual_object_type = (BYTE)m_pFile->BitRead(4);
-
- if(visual_object_type == 1 || visual_object_type == 2)
- {
+
+ if(visual_object_type == 1 || visual_object_type == 2) {
BYTE video_signal_type = (BYTE)m_pFile->BitRead(1);
-
- if(video_signal_type)
- {
+
+ if(video_signal_type) {
BYTE video_format = (BYTE)m_pFile->BitRead(3);
BYTE video_range = (BYTE)m_pFile->BitRead(1);
BYTE colour_description = (BYTE)m_pFile->BitRead(1);
- if(colour_description)
- {
+ if(colour_description) {
BYTE colour_primaries = (BYTE)m_pFile->BitRead(8);
BYTE transfer_characteristics = (BYTE)m_pFile->BitRead(8);
BYTE matrix_coefficients = (BYTE)m_pFile->BitRead(8);
@@ -1412,111 +1450,147 @@ HRESULT CMPEG4VideoSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
SkipUserData();
- if(visual_object_type == 1)
- {
- if(m_pFile->BitRead(24) != 0x000001)
+ if(visual_object_type == 1) {
+ if(m_pFile->BitRead(24) != 0x000001) {
break;
+ }
BYTE video_object_start_code = (BYTE)m_pFile->BitRead(8);
- if(video_object_start_code < 0x00 || video_object_start_code > 0x1f)
+ if(video_object_start_code < 0x00 || video_object_start_code > 0x1f) {
break;
+ }
- if(m_pFile->BitRead(24) != 0x000001)
+ if(m_pFile->BitRead(24) != 0x000001) {
break;
+ }
BYTE video_object_layer_start_code = (DWORD)m_pFile->BitRead(8);
- if(video_object_layer_start_code < 0x20 || video_object_layer_start_code > 0x2f)
+ if(video_object_layer_start_code < 0x20 || video_object_layer_start_code > 0x2f) {
break;
+ }
BYTE random_accessible_vol = (BYTE)m_pFile->BitRead(1);
BYTE video_object_type_indication = (BYTE)m_pFile->BitRead(8);
- if(video_object_type_indication == 0x12) // Fine Granularity Scalable
- break; // huh
+ if(video_object_type_indication == 0x12) { // Fine Granularity Scalable
+ break; // huh
+ }
BYTE is_object_layer_identifier = (BYTE)m_pFile->BitRead(1);
BYTE video_object_layer_verid = 0;
- if(is_object_layer_identifier)
- {
+ if(is_object_layer_identifier) {
video_object_layer_verid = (BYTE)m_pFile->BitRead(4);
BYTE video_object_layer_priority = (BYTE)m_pFile->BitRead(3);
}
BYTE aspect_ratio_info = (BYTE)m_pFile->BitRead(4);
- switch(aspect_ratio_info)
- {
- default: ASSERT(0); break;
- case 1: parx = 1; pary = 1; break;
- case 2: parx = 12; pary = 11; break;
- case 3: parx = 10; pary = 11; break;
- case 4: parx = 16; pary = 11; break;
- case 5: parx = 40; pary = 33; break;
- case 15: parx = (BYTE)m_pFile->BitRead(8); pary = (BYTE)m_pFile->BitRead(8); break;
+ switch(aspect_ratio_info) {
+ default:
+ ASSERT(0);
+ break;
+ case 1:
+ parx = 1;
+ pary = 1;
+ break;
+ case 2:
+ parx = 12;
+ pary = 11;
+ break;
+ case 3:
+ parx = 10;
+ pary = 11;
+ break;
+ case 4:
+ parx = 16;
+ pary = 11;
+ break;
+ case 5:
+ parx = 40;
+ pary = 33;
+ break;
+ case 15:
+ parx = (BYTE)m_pFile->BitRead(8);
+ pary = (BYTE)m_pFile->BitRead(8);
+ break;
}
BYTE vol_control_parameters = (BYTE)m_pFile->BitRead(1);
- if(vol_control_parameters)
- {
+ if(vol_control_parameters) {
BYTE chroma_format = (BYTE)m_pFile->BitRead(2);
BYTE low_delay = (BYTE)m_pFile->BitRead(1);
BYTE vbv_parameters = (BYTE)m_pFile->BitRead(1);
- if(vbv_parameters)
- {
+ if(vbv_parameters) {
WORD first_half_bit_rate = (WORD)m_pFile->BitRead(15);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
WORD latter_half_bit_rate = (WORD)m_pFile->BitRead(15);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
WORD first_half_vbv_buffer_size = (WORD)m_pFile->BitRead(15);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
BYTE latter_half_vbv_buffer_size = (BYTE)m_pFile->BitRead(3);
WORD first_half_vbv_occupancy = (WORD)m_pFile->BitRead(11);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
WORD latter_half_vbv_occupancy = (WORD)m_pFile->BitRead(15);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
}
}
BYTE video_object_layer_shape = (BYTE)m_pFile->BitRead(2);
- if(video_object_layer_shape == 3 && video_object_layer_verid != 1)
- {
+ if(video_object_layer_shape == 3 && video_object_layer_verid != 1) {
BYTE video_object_layer_shape_extension = (BYTE)m_pFile->BitRead(4);
}
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
WORD vop_time_increment_resolution = (WORD)m_pFile->BitRead(16);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
BYTE fixed_vop_rate = (BYTE)m_pFile->BitRead(1);
- if(fixed_vop_rate)
- {
+ if(fixed_vop_rate) {
int bits = 0;
- for(WORD i = vop_time_increment_resolution; i; i /= 2)
+ for(WORD i = vop_time_increment_resolution; i; i /= 2) {
bits++;
+ }
WORD fixed_vop_time_increment = m_pFile->BitRead(bits);
- if(fixed_vop_time_increment)
- {
+ if(fixed_vop_time_increment) {
atpf = 10000000i64 * fixed_vop_time_increment / vop_time_increment_resolution;
}
}
- if(video_object_layer_shape != 2)
- {
- if(video_object_layer_shape == 0)
- {
- if(!m_pFile->BitRead(1)) break;
+ if(video_object_layer_shape != 2) {
+ if(video_object_layer_shape == 0) {
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
width = (WORD)m_pFile->BitRead(13);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
height = (WORD)m_pFile->BitRead(13);
- if(!m_pFile->BitRead(1)) break;
+ if(!m_pFile->BitRead(1)) {
+ break;
+ }
}
BYTE interlaced = (BYTE)m_pFile->BitRead(1);
@@ -1525,15 +1599,14 @@ HRESULT CMPEG4VideoSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
// ...
}
}
- }
- else if(id == 0xb6)
- {
- m_seqhdrsize = m_pFile->GetPos() - 4;
+ } else if(id == 0xb6) {
+ m_seqhdrsize = m_pFile->GetPos() - 4;
}
}
- if(!width || !height)
+ if(!width || !height) {
return E_FAIL;
+ }
CAtlArray<CMediaType> mts;
@@ -1592,28 +1665,26 @@ bool CMPEG4VideoSplitterFilter::DemuxLoop()
DWORD sync = ~0;
- while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining())
- {
- for(int i = 0; i < 65536; i++) // don't call CheckRequest so often
- {
+ while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetRemaining()) {
+ for(int i = 0; i < 65536; i++) { // don't call CheckRequest so often
bool eof = !m_pFile->GetRemaining();
- if(p && !p->IsEmpty() && (m_pFile->BitRead(32, true) == 0x000001b6 || eof))
- {
+ if(p && !p->IsEmpty() && (m_pFile->BitRead(32, true) == 0x000001b6 || eof)) {
hr = DeliverPacket(p);
}
- if(eof) break;
+ if(eof) {
+ break;
+ }
- if(!p)
- {
+ if(!p) {
p.Attach(DNew Packet());
p->SetCount(0, 1024);
p->TrackNumber = 0;
- p->rtStart = rt;
+ p->rtStart = rt;
p->rtStop = rt + atpf;
p->bSyncPoint = FALSE;
- rt += atpf;
+ rt += atpf;
// rt = Packet::INVALID_TIME;
}
diff --git a/src/filters/parser/MP4Splitter/MP4Splitter.h b/src/filters/parser/MP4Splitter/MP4Splitter.h
index 62d4e9c30..49f7b243a 100644
--- a/src/filters/parser/MP4Splitter/MP4Splitter.h
+++ b/src/filters/parser/MP4Splitter/MP4Splitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,9 +27,12 @@
#include "../BaseSplitter/BaseSplitter.h"
class __declspec(uuid("61F47056-E400-43d3-AF1E-AB7DFFD4C4AD"))
-CMP4SplitterFilter : public CBaseSplitterFilter
+ CMP4SplitterFilter : public CBaseSplitterFilter
{
- struct trackpos {DWORD /*AP4_Ordinal*/ index; unsigned __int64 /*AP4_TimeStamp*/ ts;};
+ struct trackpos {
+ DWORD /*AP4_Ordinal*/ index;
+ unsigned __int64 /*AP4_TimeStamp*/ ts;
+ };
CAtlMap<DWORD, trackpos> m_trackpos;
CSize m_framesize;
@@ -52,7 +55,7 @@ public:
};
class __declspec(uuid("3CCC052E-BDEE-408a-BEA7-90914EF2964B"))
-CMP4SourceFilter : public CMP4SplitterFilter
+ CMP4SourceFilter : public CMP4SplitterFilter
{
public:
CMP4SourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
@@ -61,7 +64,7 @@ public:
// for raw mpeg4 elementary streams:
class __declspec(uuid("D3D9D58B-45B5-48AB-B199-B8C40560AEC7"))
-CMPEG4VideoSplitterFilter : public CBaseSplitterFilter
+ CMPEG4VideoSplitterFilter : public CBaseSplitterFilter
{
__int64 m_seqhdrsize;
int NextStartCode();
@@ -80,7 +83,7 @@ public:
};
class __declspec(uuid("E2B98EEA-EE55-4E9B-A8C1-6E5288DF785A"))
-CMPEG4VideoSourceFilter : public CMPEG4VideoSplitterFilter
+ CMPEG4VideoSourceFilter : public CMPEG4VideoSplitterFilter
{
public:
CMPEG4VideoSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/MP4Splitter/MP4SplitterFile.cpp b/src/filters/parser/MP4Splitter/MP4SplitterFile.cpp
index c28950291..88ce5ebfa 100644
--- a/src/filters/parser/MP4Splitter/MP4SplitterFile.cpp
+++ b/src/filters/parser/MP4Splitter/MP4SplitterFile.cpp
@@ -2,11 +2,13 @@
#include "MP4SplitterFile.h"
#include "Ap4AsyncReaderStream.h"
-CMP4SplitterFile::CMP4SplitterFile(IAsyncReader* pReader, HRESULT& hr)
+CMP4SplitterFile::CMP4SplitterFile(IAsyncReader* pReader, HRESULT& hr)
: CBaseSplitterFileEx(pReader, hr, DEFAULT_CACHE_LENGTH, false)
, m_pAp4File(NULL)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
hr = Init();
}
@@ -31,7 +33,7 @@ HRESULT CMP4SplitterFile::Init()
AP4_ByteStream* stream = DNew AP4_AsyncReaderStream(this);
m_pAp4File = DNew AP4_File(*stream);
-
+
AP4_Movie* movie = ((AP4_File*)m_pAp4File)->GetMovie();
stream->Release();
diff --git a/src/filters/parser/MP4Splitter/stdafx.cpp b/src/filters/parser/MP4Splitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/MP4Splitter/stdafx.cpp
+++ b/src/filters/parser/MP4Splitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MP4Splitter/stdafx.h b/src/filters/parser/MP4Splitter/stdafx.h
index cdc946aa0..9b252ac14 100644
--- a/src/filters/parser/MP4Splitter/stdafx.h
+++ b/src/filters/parser/MP4Splitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MatroskaSplitter/MatroskaFile.cpp b/src/filters/parser/MatroskaSplitter/MatroskaFile.cpp
index e498af087..8fc4b7afa 100644
--- a/src/filters/parser/MatroskaSplitter/MatroskaFile.cpp
+++ b/src/filters/parser/MatroskaSplitter/MatroskaFile.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,15 +25,14 @@
#include "../../../thirdparty/zlib/zlib.h"
#define DOCTYPE _T("matroska")
-#define DOCTYPE_WEBM _T("webm")
+#define DOCTYPE_WEBM _T("webm")
#define DOCTYPEVERSION 2
static void LOG(LPCTSTR fmt, ...)
{
va_list args;
va_start(args, fmt);
- if(FILE* f = _tfopen(_T("c:\\matroskasplitterlog.txt"), _T("at")))
- {
+ if(FILE* f = _tfopen(_T("c:\\matroskasplitterlog.txt"), _T("at"))) {
fseek(f, 0, 2);
_vftprintf(f, fmt, args);
fclose(f);
@@ -53,46 +52,50 @@ using namespace MatroskaReader;
{ \
switch(pMN->m_id) \
{ \
-
+
#define EndChunk \
} \
} \
while(pMN->Next()); \
\
return S_OK; \
-
+
static void bswap(BYTE* s, int len)
{
- for(BYTE* d = s + len-1; s < d; s++, d--)
+ for(BYTE* d = s + len-1; s < d; s++, d--) {
*s ^= *d, *d ^= *s, *s ^= *d;
+ }
}
//
// CMatroskaFile
//
-CMatroskaFile::CMatroskaFile(IAsyncReader* pAsyncReader, HRESULT& hr)
+CMatroskaFile::CMatroskaFile(IAsyncReader* pAsyncReader, HRESULT& hr)
: CBaseSplitterFile(pAsyncReader, hr, DEFAULT_CACHE_LENGTH, false)
, m_rtOffset(0)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
hr = Init();
}
HRESULT CMatroskaFile::Init()
{
DWORD dw;
- if(FAILED(Read(dw)) || dw != 0x1A45DFA3)
+ if(FAILED(Read(dw)) || dw != 0x1A45DFA3) {
return E_FAIL;
+ }
CMatroskaNode Root(this);
- if(FAILED(Parse(&Root)))
+ if(FAILED(Parse(&Root))) {
return E_FAIL;
+ }
CAutoPtr<CMatroskaNode> pSegment, pCluster;
if((pSegment = Root.Child(0x18538067))
- && (pCluster = pSegment->Child(0x1F43B675)))
- {
+ && (pCluster = pSegment->Child(0x1F43B675))) {
Cluster c0;
c0.ParseTimeCode(pCluster);
m_rtOffset = m_segment.GetRefTime(c0.TimeCode);
@@ -105,19 +108,26 @@ template <class T>
HRESULT CMatroskaFile::Read(T& var)
{
HRESULT hr = ByteRead((BYTE*)&var, sizeof(var));
- if(S_OK == hr) bswap((BYTE*)&var, sizeof(var));
+ if(S_OK == hr) {
+ bswap((BYTE*)&var, sizeof(var));
+ }
return hr;
}
HRESULT CMatroskaFile::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x1A45DFA3:
- m_ebml.Parse(pMN);
- if((m_ebml.DocType != DOCTYPE || m_ebml.DocTypeReadVersion > DOCTYPEVERSION) && m_ebml.DocType != DOCTYPE_WEBM)
- return E_FAIL;
- break;
- case 0x18538067: if(m_segment.SegmentInfo.SegmentUID.IsEmpty()) m_segment.ParseMinimal(pMN); break;
+case 0x1A45DFA3:
+ m_ebml.Parse(pMN);
+ if((m_ebml.DocType != DOCTYPE || m_ebml.DocTypeReadVersion > DOCTYPEVERSION) && m_ebml.DocType != DOCTYPE_WEBM) {
+ return E_FAIL;
+ }
+ break;
+case 0x18538067:
+ if(m_segment.SegmentInfo.SegmentUID.IsEmpty()) {
+ m_segment.ParseMinimal(pMN);
+ }
+ break;
EndChunk
}
@@ -126,13 +136,27 @@ HRESULT CMatroskaFile::Parse(CMatroskaNode* pMN0)
HRESULT EBML::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x4286: EBMLVersion.Parse(pMN); break;
- case 0x42F7: EBMLReadVersion.Parse(pMN); break;
- case 0x42F2: EBMLMaxIDLength.Parse(pMN); break;
- case 0x42F3: EBMLMaxSizeLength.Parse(pMN); break;
- case 0x4282: DocType.Parse(pMN); break;
- case 0x4287: DocTypeVersion.Parse(pMN); break;
- case 0x4285: DocTypeReadVersion.Parse(pMN); break;
+case 0x4286:
+ EBMLVersion.Parse(pMN);
+ break;
+case 0x42F7:
+ EBMLReadVersion.Parse(pMN);
+ break;
+case 0x42F2:
+ EBMLMaxIDLength.Parse(pMN);
+ break;
+case 0x42F3:
+ EBMLMaxSizeLength.Parse(pMN);
+ break;
+case 0x4282:
+ DocType.Parse(pMN);
+ break;
+case 0x4287:
+ DocTypeVersion.Parse(pMN);
+ break;
+case 0x4285:
+ DocTypeReadVersion.Parse(pMN);
+ break;
EndChunk
}
@@ -141,14 +165,28 @@ HRESULT Segment::Parse(CMatroskaNode* pMN0)
pos = pMN0->GetPos();
BeginChunk
- case 0x1549A966: SegmentInfo.Parse(pMN); break;
- case 0x114D9B74: MetaSeekInfo.Parse(pMN); break;
- case 0x1654AE6B: Tracks.Parse(pMN); break;
- case 0x1F43B675: Clusters.Parse(pMN); break;
- case 0x1C53BB6B: Cues.Parse(pMN); break;
- case 0x1941A469: Attachments.Parse(pMN); break;
- case 0x1043A770: Chapters.Parse(pMN); break;
-// case 0x1254C367: Tags.Parse(pMN); break;
+case 0x1549A966:
+ SegmentInfo.Parse(pMN);
+ break;
+case 0x114D9B74:
+ MetaSeekInfo.Parse(pMN);
+ break;
+case 0x1654AE6B:
+ Tracks.Parse(pMN);
+ break;
+case 0x1F43B675:
+ Clusters.Parse(pMN);
+ break;
+case 0x1C53BB6B:
+ Cues.Parse(pMN);
+ break;
+case 0x1941A469:
+ Attachments.Parse(pMN);
+ break;
+case 0x1043A770:
+ Chapters.Parse(pMN);
+ break;
+ // case 0x1254C367: Tags.Parse(pMN); break;
EndChunk
}
@@ -160,53 +198,65 @@ HRESULT Segment::ParseMinimal(CMatroskaNode* pMN0)
len = pMN0->m_len;
CAutoPtr<CMatroskaNode> pMN = pMN0->Child();
- if(!pMN) return S_FALSE;
+ if(!pMN) {
+ return S_FALSE;
+ }
int n = 0;
- do
- {
- switch(pMN->m_id)
- {
- case 0x1549A966: SegmentInfo.Parse(pMN); n++; break;
- case 0x114D9B74: MetaSeekInfo.Parse(pMN); n++; break;
- case 0x1654AE6B: Tracks.Parse(pMN); n++; break;
- case 0x1C53BB6B: Cues.Parse(pMN); break;
+ do {
+ switch(pMN->m_id) {
+ case 0x1549A966:
+ SegmentInfo.Parse(pMN);
+ n++;
+ break;
+ case 0x114D9B74:
+ MetaSeekInfo.Parse(pMN);
+ n++;
+ break;
+ case 0x1654AE6B:
+ Tracks.Parse(pMN);
+ n++;
+ break;
+ case 0x1C53BB6B:
+ Cues.Parse(pMN);
+ break;
}
- }
- while(n < 3 && pMN->Next());
+ } while(n < 3 && pMN->Next());
- if(!pMN->IsRandomAccess())
- {
+ if(!pMN->IsRandomAccess()) {
return S_OK;
}
- while(MatroskaReader::QWORD pos = pMN->FindPos(0x114D9B74, pMN->GetPos()))
- {
+ while(MatroskaReader::QWORD pos = pMN->FindPos(0x114D9B74, pMN->GetPos())) {
pMN->SeekTo(pos);
pMN->Parse();
- if(pMN->m_id != 0x114D9B74) {ASSERT(0); break;}
+ if(pMN->m_id != 0x114D9B74) {
+ ASSERT(0);
+ break;
+ }
MetaSeekInfo.Parse(pMN);
}
- if(n == 3)
- {
- if(Cues.IsEmpty() && (pMN = pMN0->Child(0x1C53BB6B, false)))
- {
- do {Cues.Parse(pMN);}
- while(pMN->Next(true));
+ if(n == 3) {
+ if(Cues.IsEmpty() && (pMN = pMN0->Child(0x1C53BB6B, false))) {
+ do {
+ Cues.Parse(pMN);
+ } while(pMN->Next(true));
}
- if(Chapters.IsEmpty() && (pMN = pMN0->Child(0x1043A770, false)))
- {
- do {Chapters.Parse(pMN); /*BIG UGLY HACK:*/ break;}
- while(pMN->Next(true));
+ if(Chapters.IsEmpty() && (pMN = pMN0->Child(0x1043A770, false))) {
+ do {
+ Chapters.Parse(pMN); /*BIG UGLY HACK:*/
+ break;
+ } while(pMN->Next(true));
}
- if(Attachments.IsEmpty() && (pMN = pMN0->Child(0x1941A469, false)))
- {
- do {Attachments.Parse(pMN); /*BIG UGLY HACK:*/ break;}
- while (pMN->Next(true));
+ if(Attachments.IsEmpty() && (pMN = pMN0->Child(0x1941A469, false))) {
+ do {
+ Attachments.Parse(pMN); /*BIG UGLY HACK:*/
+ break;
+ } while (pMN->Next(true));
}
}
@@ -218,43 +268,44 @@ UINT64 Segment::GetMasterTrack()
UINT64 TrackNumber = 0, AltTrackNumber = 0;
POSITION pos1 = Tracks.GetHeadPosition();
- while(pos1 && TrackNumber == 0)
- {
+ while(pos1 && TrackNumber == 0) {
Track* pT = Tracks.GetNext(pos1);
-
+
POSITION pos2 = pT->TrackEntries.GetHeadPosition();
- while(pos2 && TrackNumber == 0)
- {
+ while(pos2 && TrackNumber == 0) {
TrackEntry* pTE = pT->TrackEntries.GetNext(pos2);
- if(pTE->TrackType == TrackEntry::TypeVideo)
- {
+ if(pTE->TrackType == TrackEntry::TypeVideo) {
TrackNumber = pTE->TrackNumber;
break;
- }
- else if(pTE->TrackType == TrackEntry::TypeAudio && AltTrackNumber == 0)
- {
+ } else if(pTE->TrackType == TrackEntry::TypeAudio && AltTrackNumber == 0) {
AltTrackNumber = pTE->TrackNumber;
}
}
}
- if(TrackNumber == 0) TrackNumber = AltTrackNumber;
- if(TrackNumber == 0) TrackNumber = 1;
+ if(TrackNumber == 0) {
+ TrackNumber = AltTrackNumber;
+ }
+ if(TrackNumber == 0) {
+ TrackNumber = 1;
+ }
return TrackNumber;
}
ChapterAtom* ChapterAtom::FindChapterAtom(UINT64 id)
{
- if(ChapterUID == id)
+ if(ChapterUID == id) {
return(this);
+ }
POSITION pos = ChapterAtoms.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
ChapterAtom* ca = ChapterAtoms.GetNext(pos)->FindChapterAtom(id);
- if(ca) return ca;
+ if(ca) {
+ return ca;
+ }
}
return(NULL);
@@ -263,17 +314,14 @@ ChapterAtom* ChapterAtom::FindChapterAtom(UINT64 id)
ChapterAtom* Segment::FindChapterAtom(UINT64 id, int nEditionEntry)
{
POSITION pos1 = Chapters.GetHeadPosition();
- while(pos1)
- {
+ while(pos1) {
Chapter* c = Chapters.GetNext(pos1);
POSITION pos2 = c->EditionEntries.GetHeadPosition();
- while(pos2)
- {
+ while(pos2) {
EditionEntry* ee = c->EditionEntries.GetNext(pos2);
- if(nEditionEntry-- == 0)
- {
+ if(nEditionEntry-- == 0) {
return id == 0 ? ee : ee->FindChapterAtom(id);
}
}
@@ -285,70 +333,155 @@ ChapterAtom* Segment::FindChapterAtom(UINT64 id, int nEditionEntry)
HRESULT Info::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x73A4: SegmentUID.Parse(pMN); break;
- case 0x7384: SegmentFilename.Parse(pMN); break;
- case 0x3CB923: PrevUID.Parse(pMN); break;
- case 0x3C83AB: PrevFilename.Parse(pMN); break;
- case 0x3EB923: NextUID.Parse(pMN); break;
- case 0x3E83BB: NextFilename.Parse(pMN); break;
- case 0x2AD7B1: TimeCodeScale.Parse(pMN); break;
- case 0x4489: Duration.Parse(pMN); break;
- case 0x4461: DateUTC.Parse(pMN); break;
- case 0x7BA9: Title.Parse(pMN); break;
- case 0x4D80: MuxingApp.Parse(pMN); break;
- case 0x5741: WritingApp.Parse(pMN); break;
+case 0x73A4:
+ SegmentUID.Parse(pMN);
+ break;
+case 0x7384:
+ SegmentFilename.Parse(pMN);
+ break;
+case 0x3CB923:
+ PrevUID.Parse(pMN);
+ break;
+case 0x3C83AB:
+ PrevFilename.Parse(pMN);
+ break;
+case 0x3EB923:
+ NextUID.Parse(pMN);
+ break;
+case 0x3E83BB:
+ NextFilename.Parse(pMN);
+ break;
+case 0x2AD7B1:
+ TimeCodeScale.Parse(pMN);
+ break;
+case 0x4489:
+ Duration.Parse(pMN);
+ break;
+case 0x4461:
+ DateUTC.Parse(pMN);
+ break;
+case 0x7BA9:
+ Title.Parse(pMN);
+ break;
+case 0x4D80:
+ MuxingApp.Parse(pMN);
+ break;
+case 0x5741:
+ WritingApp.Parse(pMN);
+ break;
EndChunk
}
HRESULT Seek::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x4DBB: SeekHeads.Parse(pMN); break;
+case 0x4DBB:
+ SeekHeads.Parse(pMN);
+ break;
EndChunk
}
HRESULT SeekHead::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x53AB: SeekID.Parse(pMN); break;
- case 0x53AC: SeekPosition.Parse(pMN); break;
+case 0x53AB:
+ SeekID.Parse(pMN);
+ break;
+case 0x53AC:
+ SeekPosition.Parse(pMN);
+ break;
EndChunk
}
HRESULT Track::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xAE: TrackEntries.Parse(pMN); break;
+case 0xAE:
+ TrackEntries.Parse(pMN);
+ break;
EndChunk
}
HRESULT TrackEntry::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xD7: TrackNumber.Parse(pMN); break;
- case 0x73C5: TrackUID.Parse(pMN); break;
- case 0x83: TrackType.Parse(pMN); break;
- case 0xB9: FlagEnabled.Parse(pMN); break;
- case 0x88: FlagDefault.Parse(pMN); break;
- case 0x9C: FlagLacing.Parse(pMN); break;
- case 0x55AA: FlagForced.Parse(pMN); break;
- case 0x6DE7: MinCache.Parse(pMN); break;
- case 0x6DF8: MaxCache.Parse(pMN); break;
- case 0x536E: Name.Parse(pMN); break;
- case 0x22B59C: Language.Parse(pMN); break;
- case 0x86: CodecID.Parse(pMN); break;
- case 0x63A2: CodecPrivate.Parse(pMN); break;
- case 0x258688: CodecName.Parse(pMN); break;
- case 0x3A9697: CodecSettings.Parse(pMN); break;
- case 0x3B4040: CodecInfoURL.Parse(pMN); break;
- case 0x26B240: CodecDownloadURL.Parse(pMN); break;
- case 0xAA: CodecDecodeAll.Parse(pMN); break;
- case 0x6FAB: TrackOverlay.Parse(pMN); break;
- case 0x23E383: case 0x2383E3: DefaultDuration.Parse(pMN); break;
- case 0x23314F: TrackTimecodeScale.Parse(pMN); break;
- case 0xE0: if(S_OK == v.Parse(pMN)) DescType |= DescVideo; break;
- case 0xE1: if(S_OK == a.Parse(pMN)) DescType |= DescAudio; break;
- case 0x6D80: ces.Parse(pMN); break;
+case 0xD7:
+ TrackNumber.Parse(pMN);
+ break;
+case 0x73C5:
+ TrackUID.Parse(pMN);
+ break;
+case 0x83:
+ TrackType.Parse(pMN);
+ break;
+case 0xB9:
+ FlagEnabled.Parse(pMN);
+ break;
+case 0x88:
+ FlagDefault.Parse(pMN);
+ break;
+case 0x9C:
+ FlagLacing.Parse(pMN);
+ break;
+case 0x55AA:
+ FlagForced.Parse(pMN);
+ break;
+case 0x6DE7:
+ MinCache.Parse(pMN);
+ break;
+case 0x6DF8:
+ MaxCache.Parse(pMN);
+ break;
+case 0x536E:
+ Name.Parse(pMN);
+ break;
+case 0x22B59C:
+ Language.Parse(pMN);
+ break;
+case 0x86:
+ CodecID.Parse(pMN);
+ break;
+case 0x63A2:
+ CodecPrivate.Parse(pMN);
+ break;
+case 0x258688:
+ CodecName.Parse(pMN);
+ break;
+case 0x3A9697:
+ CodecSettings.Parse(pMN);
+ break;
+case 0x3B4040:
+ CodecInfoURL.Parse(pMN);
+ break;
+case 0x26B240:
+ CodecDownloadURL.Parse(pMN);
+ break;
+case 0xAA:
+ CodecDecodeAll.Parse(pMN);
+ break;
+case 0x6FAB:
+ TrackOverlay.Parse(pMN);
+ break;
+case 0x23E383:
+case 0x2383E3:
+ DefaultDuration.Parse(pMN);
+ break;
+case 0x23314F:
+ TrackTimecodeScale.Parse(pMN);
+ break;
+case 0xE0:
+ if(S_OK == v.Parse(pMN)) {
+ DescType |= DescVideo;
+ }
+ break;
+case 0xE1:
+ if(S_OK == a.Parse(pMN)) {
+ DescType |= DescAudio;
+ }
+ break;
+case 0x6D80:
+ ces.Parse(pMN);
+ break;
EndChunk
}
@@ -358,32 +491,34 @@ static int cesort(const void* a, const void* b)
UINT64 ce2 = (static_cast<ContentEncoding*>(const_cast<void *>(b)))->ContentEncodingOrder;
return (int)ce1 - (int)ce2;
-//return static_cast<int>(ce1) - static_cast<int>(ce2);
+ //return static_cast<int>(ce1) - static_cast<int>(ce2);
}
bool TrackEntry::Expand(CBinary& data, UINT64 Scope)
{
- if(ces.ce.GetCount() == 0) return(true);
+ if(ces.ce.GetCount() == 0) {
+ return(true);
+ }
CAtlArray<ContentEncoding*> cearray;
POSITION pos = ces.ce.GetHeadPosition();
- while(pos) cearray.Add(ces.ce.GetNext(pos));
+ while(pos) {
+ cearray.Add(ces.ce.GetNext(pos));
+ }
qsort(cearray.GetData(), cearray.GetCount(), sizeof(ContentEncoding*), cesort);
- for(int i = cearray.GetCount()-1; i >= 0; i--)
- {
+ for(int i = cearray.GetCount()-1; i >= 0; i--) {
ContentEncoding* ce = cearray[i];
- if(!(ce->ContentEncodingScope & Scope))
+ if(!(ce->ContentEncodingScope & Scope)) {
continue;
+ }
- if(ce->ContentEncodingType == ContentEncoding::Compression)
- {
- if(!data.Decompress(ce->cc))
+ if(ce->ContentEncodingType == ContentEncoding::Compression) {
+ if(!data.Decompress(ce->cc)) {
return(false);
- }
- else if(ce->ContentEncodingType == ContentEncoding::Encryption)
- {
+ }
+ } else if(ce->ContentEncodingType == ContentEncoding::Encryption) {
// TODO
return(false);
}
@@ -395,102 +530,200 @@ bool TrackEntry::Expand(CBinary& data, UINT64 Scope)
HRESULT Video::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x9A: FlagInterlaced.Parse(pMN); break;
- case 0x53B8: StereoMode.Parse(pMN); break;
- case 0xB0: PixelWidth.Parse(pMN);
- if (!DisplayWidth) DisplayWidth.Set(PixelWidth); break;
- case 0xBA: PixelHeight.Parse(pMN);
- if (!DisplayHeight) DisplayHeight.Set(PixelHeight); break;
- case 0x54B0: DisplayWidth.Parse(pMN); break;
- case 0x54BA: DisplayHeight.Parse(pMN); break;
- case 0x54B2: DisplayUnit.Parse(pMN); break;
- case 0x54B3: AspectRatioType.Parse(pMN); break;
- case 0x2EB524: ColourSpace.Parse(pMN); break;
- case 0x2FB523: GammaValue.Parse(pMN); break;
- case 0x2383E3: FramePerSec.Parse(pMN); break;
+case 0x9A:
+ FlagInterlaced.Parse(pMN);
+ break;
+case 0x53B8:
+ StereoMode.Parse(pMN);
+ break;
+case 0xB0:
+ PixelWidth.Parse(pMN);
+ if (!DisplayWidth) {
+ DisplayWidth.Set(PixelWidth);
+ }
+ break;
+case 0xBA:
+ PixelHeight.Parse(pMN);
+ if (!DisplayHeight) {
+ DisplayHeight.Set(PixelHeight);
+ }
+ break;
+case 0x54B0:
+ DisplayWidth.Parse(pMN);
+ break;
+case 0x54BA:
+ DisplayHeight.Parse(pMN);
+ break;
+case 0x54B2:
+ DisplayUnit.Parse(pMN);
+ break;
+case 0x54B3:
+ AspectRatioType.Parse(pMN);
+ break;
+case 0x2EB524:
+ ColourSpace.Parse(pMN);
+ break;
+case 0x2FB523:
+ GammaValue.Parse(pMN);
+ break;
+case 0x2383E3:
+ FramePerSec.Parse(pMN);
+ break;
EndChunk
}
HRESULT Audio::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xB5: SamplingFrequency.Parse(pMN);
- if (!OutputSamplingFrequency) OutputSamplingFrequency.Set(SamplingFrequency); break;
- case 0x78B5: OutputSamplingFrequency.Parse(pMN); break;
- case 0x9F: Channels.Parse(pMN); break;
- case 0x7D7B: ChannelPositions.Parse(pMN); break;
- case 0x6264: BitDepth.Parse(pMN); break;
+case 0xB5:
+ SamplingFrequency.Parse(pMN);
+ if (!OutputSamplingFrequency) {
+ OutputSamplingFrequency.Set(SamplingFrequency);
+ }
+ break;
+case 0x78B5:
+ OutputSamplingFrequency.Parse(pMN);
+ break;
+case 0x9F:
+ Channels.Parse(pMN);
+ break;
+case 0x7D7B:
+ ChannelPositions.Parse(pMN);
+ break;
+case 0x6264:
+ BitDepth.Parse(pMN);
+ break;
EndChunk
}
HRESULT ContentEncodings::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x6240: ce.Parse(pMN); break;
+case 0x6240:
+ ce.Parse(pMN);
+ break;
EndChunk
}
HRESULT ContentEncoding::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x5031: ContentEncodingOrder.Parse(pMN); break;
- case 0x5032: ContentEncodingScope.Parse(pMN); break;
- case 0x5033: ContentEncodingType.Parse(pMN); break;
- case 0x5034: cc.Parse(pMN); break;
- case 0x5035: ce.Parse(pMN); break;
+case 0x5031:
+ ContentEncodingOrder.Parse(pMN);
+ break;
+case 0x5032:
+ ContentEncodingScope.Parse(pMN);
+ break;
+case 0x5033:
+ ContentEncodingType.Parse(pMN);
+ break;
+case 0x5034:
+ cc.Parse(pMN);
+ break;
+case 0x5035:
+ ce.Parse(pMN);
+ break;
EndChunk
}
HRESULT ContentCompression::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x4254: ContentCompAlgo.Parse(pMN); break;
- case 0x4255: ContentCompSettings.Parse(pMN); break;
+case 0x4254:
+ ContentCompAlgo.Parse(pMN);
+ break;
+case 0x4255:
+ ContentCompSettings.Parse(pMN);
+ break;
EndChunk
}
HRESULT ContentEncryption::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x47e1: ContentEncAlgo.Parse(pMN); break;
- case 0x47e2: ContentEncKeyID.Parse(pMN); break;
- case 0x47e3: ContentSignature.Parse(pMN); break;
- case 0x47e4: ContentSigKeyID.Parse(pMN); break;
- case 0x47e5: ContentSigAlgo.Parse(pMN); break;
- case 0x47e6: ContentSigHashAlgo.Parse(pMN); break;
+case 0x47e1:
+ ContentEncAlgo.Parse(pMN);
+ break;
+case 0x47e2:
+ ContentEncKeyID.Parse(pMN);
+ break;
+case 0x47e3:
+ ContentSignature.Parse(pMN);
+ break;
+case 0x47e4:
+ ContentSigKeyID.Parse(pMN);
+ break;
+case 0x47e5:
+ ContentSigAlgo.Parse(pMN);
+ break;
+case 0x47e6:
+ ContentSigHashAlgo.Parse(pMN);
+ break;
EndChunk
}
HRESULT Cluster::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xE7: TimeCode.Parse(pMN); break;
- case 0xA7: Position.Parse(pMN); break;
- case 0xAB: PrevSize.Parse(pMN); break;
- case 0xA0: BlockGroups.Parse(pMN, true); break;
- case 0xA3: SimpleBlocks.Parse(pMN, true); break;
+case 0xE7:
+ TimeCode.Parse(pMN);
+ break;
+case 0xA7:
+ Position.Parse(pMN);
+ break;
+case 0xAB:
+ PrevSize.Parse(pMN);
+ break;
+case 0xA0:
+ BlockGroups.Parse(pMN, true);
+ break;
+case 0xA3:
+ SimpleBlocks.Parse(pMN, true);
+ break;
EndChunk
}
HRESULT Cluster::ParseTimeCode(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xE7: TimeCode.Parse(pMN); return S_OK;
+case 0xE7:
+ TimeCode.Parse(pMN);
+ return S_OK;
EndChunk
}
HRESULT BlockGroup::Parse(CMatroskaNode* pMN0, bool fFull)
{
BeginChunk
- case 0xA1: Block.Parse(pMN, fFull); break;
- case 0xA2: /* TODO: multiple virt blocks? */; break;
- case 0x9B: BlockDuration.Parse(pMN); break;
- case 0xFA: ReferencePriority.Parse(pMN); break;
- case 0xFB: ReferenceBlock.Parse(pMN); break;
- case 0xFD: ReferenceVirtual.Parse(pMN); break;
- case 0xA4: CodecState.Parse(pMN); break;
- case 0xE8: TimeSlices.Parse(pMN); break;
- case 0x75A1: if(fFull) ba.Parse(pMN); break;
+case 0xA1:
+ Block.Parse(pMN, fFull);
+ break;
+case 0xA2: /* TODO: multiple virt blocks? */
+ ;
+ break;
+case 0x9B:
+ BlockDuration.Parse(pMN);
+ break;
+case 0xFA:
+ ReferencePriority.Parse(pMN);
+ break;
+case 0xFB:
+ ReferenceBlock.Parse(pMN);
+ break;
+case 0xFD:
+ ReferenceVirtual.Parse(pMN);
+ break;
+case 0xA4:
+ CodecState.Parse(pMN);
+ break;
+case 0xE8:
+ TimeSlices.Parse(pMN);
+ break;
+case 0x75A1:
+ if(fFull) {
+ ba.Parse(pMN);
+ }
+ break;
EndChunk
}
@@ -498,71 +731,75 @@ HRESULT SimpleBlock::Parse(CMatroskaNode* pMN, bool fFull)
{
pMN->SeekTo(pMN->m_start);
- TrackNumber.Parse(pMN);
- CShort s; s.Parse(pMN); TimeCode.Set(s);
+ TrackNumber.Parse(pMN);
+ CShort s;
+ s.Parse(pMN);
+ TimeCode.Set(s);
Lacing.Parse(pMN);
-
- if(!fFull) return S_OK;
+
+ if(!fFull) {
+ return S_OK;
+ }
CAtlList<MatroskaReader::QWORD> lens;
MatroskaReader::QWORD tlen = 0;
MatroskaReader::QWORD FrameSize;
BYTE FramesInLaceLessOne;
- switch((Lacing & 0x06) >> 1)
- {
- case 0:
- // No lacing
- lens.AddTail((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen));
- break;
- case 1:
- // Xiph lacing
- BYTE n;
- pMN->Read(n);
- while(n-- > 0)
- {
- BYTE b;
- MatroskaReader::QWORD len = 0;
- do {pMN->Read(b); len += b;} while(b == 0xff);
- lens.AddTail(len);
- tlen += len;
- }
- lens.AddTail((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen));
- break;
- case 2:
- // Fixed-size lacing
- pMN->Read(FramesInLaceLessOne);
- FramesInLaceLessOne++;
- FrameSize = ((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen)) / FramesInLaceLessOne;
- while(FramesInLaceLessOne-- > 0)
- lens.AddTail(FrameSize);
- break;
- case 3:
- // EBML lacing
- pMN->Read(FramesInLaceLessOne);
-
- CLength FirstFrameSize;
- FirstFrameSize.Parse(pMN);
- lens.AddTail(FirstFrameSize);
- FramesInLaceLessOne--;
- tlen = FirstFrameSize;
-
- CSignedLength DiffSize;
- FrameSize = FirstFrameSize;
- while(FramesInLaceLessOne--)
- {
- DiffSize.Parse(pMN);
- FrameSize += DiffSize;
- lens.AddTail(FrameSize);
- tlen += FrameSize;
- }
- lens.AddTail((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen));
- break;
+ switch((Lacing & 0x06) >> 1) {
+ case 0:
+ // No lacing
+ lens.AddTail((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen));
+ break;
+ case 1:
+ // Xiph lacing
+ BYTE n;
+ pMN->Read(n);
+ while(n-- > 0) {
+ BYTE b;
+ MatroskaReader::QWORD len = 0;
+ do {
+ pMN->Read(b);
+ len += b;
+ } while(b == 0xff);
+ lens.AddTail(len);
+ tlen += len;
+ }
+ lens.AddTail((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen));
+ break;
+ case 2:
+ // Fixed-size lacing
+ pMN->Read(FramesInLaceLessOne);
+ FramesInLaceLessOne++;
+ FrameSize = ((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen)) / FramesInLaceLessOne;
+ while(FramesInLaceLessOne-- > 0) {
+ lens.AddTail(FrameSize);
+ }
+ break;
+ case 3:
+ // EBML lacing
+ pMN->Read(FramesInLaceLessOne);
+
+ CLength FirstFrameSize;
+ FirstFrameSize.Parse(pMN);
+ lens.AddTail(FirstFrameSize);
+ FramesInLaceLessOne--;
+ tlen = FirstFrameSize;
+
+ CSignedLength DiffSize;
+ FrameSize = FirstFrameSize;
+ while(FramesInLaceLessOne--) {
+ DiffSize.Parse(pMN);
+ FrameSize += DiffSize;
+ lens.AddTail(FrameSize);
+ tlen += FrameSize;
+ }
+ lens.AddTail((pMN->m_start+pMN->m_len) - (pMN->GetPos()+tlen));
+ break;
}
POSITION pos = lens.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
MatroskaReader::QWORD len = lens.GetNext(pos);
CAutoPtr<CBinary> p(DNew CBinary());
p->SetCount((INT_PTR)len);
@@ -576,119 +813,191 @@ HRESULT SimpleBlock::Parse(CMatroskaNode* pMN, bool fFull)
HRESULT BlockAdditions::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xA6: bm.Parse(pMN); break;
+case 0xA6:
+ bm.Parse(pMN);
+ break;
EndChunk
}
HRESULT BlockMore::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xEE: BlockAddID.Parse(pMN); break;
- case 0xA5: BlockAdditional.Parse(pMN); break;
+case 0xEE:
+ BlockAddID.Parse(pMN);
+ break;
+case 0xA5:
+ BlockAdditional.Parse(pMN);
+ break;
EndChunk
}
HRESULT TimeSlice::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xCC: LaceNumber.Parse(pMN); break;
- case 0xCD: FrameNumber.Parse(pMN); break;
- case 0xCE: Delay.Parse(pMN); break;
- case 0xCF: Duration.Parse(pMN); break;
+case 0xCC:
+ LaceNumber.Parse(pMN);
+ break;
+case 0xCD:
+ FrameNumber.Parse(pMN);
+ break;
+case 0xCE:
+ Delay.Parse(pMN);
+ break;
+case 0xCF:
+ Duration.Parse(pMN);
+ break;
EndChunk
}
HRESULT Cue::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xBB: CuePoints.Parse(pMN); break;
+case 0xBB:
+ CuePoints.Parse(pMN);
+ break;
EndChunk
}
HRESULT CuePoint::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xB3: CueTime.Parse(pMN); break;
- case 0xB7: CueTrackPositions.Parse(pMN); break;
+case 0xB3:
+ CueTime.Parse(pMN);
+ break;
+case 0xB7:
+ CueTrackPositions.Parse(pMN);
+ break;
EndChunk
}
HRESULT CueTrackPosition::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xF7: CueTrack.Parse(pMN); break;
- case 0xF1: CueClusterPosition.Parse(pMN); break;
- case 0x5387: CueBlockNumber.Parse(pMN); break;
- case 0xEA: CueCodecState.Parse(pMN); break;
- case 0xDB: CueReferences.Parse(pMN); break;
+case 0xF7:
+ CueTrack.Parse(pMN);
+ break;
+case 0xF1:
+ CueClusterPosition.Parse(pMN);
+ break;
+case 0x5387:
+ CueBlockNumber.Parse(pMN);
+ break;
+case 0xEA:
+ CueCodecState.Parse(pMN);
+ break;
+case 0xDB:
+ CueReferences.Parse(pMN);
+ break;
EndChunk
}
HRESULT CueReference::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x96: CueRefTime.Parse(pMN); break;
- case 0x97: CueRefCluster.Parse(pMN); break;
- case 0x535F: CueRefNumber.Parse(pMN); break;
- case 0xEB: CueRefCodecState.Parse(pMN); break;
+case 0x96:
+ CueRefTime.Parse(pMN);
+ break;
+case 0x97:
+ CueRefCluster.Parse(pMN);
+ break;
+case 0x535F:
+ CueRefNumber.Parse(pMN);
+ break;
+case 0xEB:
+ CueRefCodecState.Parse(pMN);
+ break;
EndChunk
}
HRESULT Attachment::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x61A7: AttachedFiles.Parse(pMN); break;
+case 0x61A7:
+ AttachedFiles.Parse(pMN);
+ break;
EndChunk
}
HRESULT AttachedFile::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x467E: FileDescription.Parse(pMN); break;
- case 0x466E: FileName.Parse(pMN); break;
- case 0x4660: FileMimeType.Parse(pMN); break;
- case 0x465C: // binary
- FileDataLen = (INT_PTR)pMN->m_len;
- FileDataPos = pMN->m_start;
- break;
- case 0x46AE: FileUID.Parse(pMN); break;
+case 0x467E:
+ FileDescription.Parse(pMN);
+ break;
+case 0x466E:
+ FileName.Parse(pMN);
+ break;
+case 0x4660:
+ FileMimeType.Parse(pMN);
+ break;
+case 0x465C: // binary
+ FileDataLen = (INT_PTR)pMN->m_len;
+ FileDataPos = pMN->m_start;
+ break;
+case 0x46AE:
+ FileUID.Parse(pMN);
+ break;
EndChunk
}
HRESULT Chapter::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x45B9: EditionEntries.Parse(pMN); break;
+case 0x45B9:
+ EditionEntries.Parse(pMN);
+ break;
EndChunk
}
HRESULT EditionEntry::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0xB6: ChapterAtoms.Parse(pMN); break;
+case 0xB6:
+ ChapterAtoms.Parse(pMN);
+ break;
EndChunk
}
HRESULT ChapterAtom::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x73C4: ChapterUID.Parse(pMN); break;
- case 0x91: ChapterTimeStart.Parse(pMN); break;
- case 0x92: ChapterTimeEnd.Parse(pMN); break;
-// case 0x8F: // TODO
- case 0x80: ChapterDisplays.Parse(pMN); break;
- case 0xB6: ChapterAtoms.Parse(pMN); break;
- case 0x98: ChapterFlagHidden.Parse(pMN); break;
- case 0x4598: ChapterFlagEnabled.Parse(pMN); break;
+case 0x73C4:
+ ChapterUID.Parse(pMN);
+ break;
+case 0x91:
+ ChapterTimeStart.Parse(pMN);
+ break;
+case 0x92:
+ ChapterTimeEnd.Parse(pMN);
+ break;
+ // case 0x8F: // TODO
+case 0x80:
+ ChapterDisplays.Parse(pMN);
+ break;
+case 0xB6:
+ ChapterAtoms.Parse(pMN);
+ break;
+case 0x98:
+ ChapterFlagHidden.Parse(pMN);
+ break;
+case 0x4598:
+ ChapterFlagEnabled.Parse(pMN);
+ break;
EndChunk
}
HRESULT ChapterDisplay::Parse(CMatroskaNode* pMN0)
{
BeginChunk
- case 0x85: ChapString.Parse(pMN); break;
- case 0x437C: ChapLanguage.Parse(pMN); break;
- case 0x437E: ChapCountry.Parse(pMN); break;
+case 0x85:
+ ChapString.Parse(pMN);
+ break;
+case 0x437C:
+ ChapLanguage.Parse(pMN);
+ break;
+case 0x437E:
+ ChapCountry.Parse(pMN);
+ break;
EndChunk
}
@@ -703,8 +1012,7 @@ HRESULT CBinary::Parse(CMatroskaNode* pMN)
bool CBinary::Compress(ContentCompression& cc)
{
- if(cc.ContentCompAlgo == ContentCompression::ZLIB)
- {
+ if(cc.ContentCompAlgo == ContentCompression::ZLIB) {
int res;
z_stream c_stream;
@@ -712,26 +1020,24 @@ bool CBinary::Compress(ContentCompression& cc)
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
- if(Z_OK != (res = deflateInit(&c_stream, 9)))
+ if(Z_OK != (res = deflateInit(&c_stream, 9))) {
return(false);
+ }
c_stream.next_in = GetData();
c_stream.avail_in = GetCount();
BYTE* dst = NULL;
int n = 0;
- do
- {
+ do {
dst = (BYTE*)realloc(dst, ++n*10);
c_stream.next_out = &dst[(n-1)*10];
c_stream.avail_out = 10;
- if(Z_OK != (res = deflate(&c_stream, Z_FINISH)) && Z_STREAM_END != res)
- {
+ if(Z_OK != (res = deflate(&c_stream, Z_FINISH)) && Z_STREAM_END != res) {
free(dst);
return(false);
}
- }
- while(0 == c_stream.avail_out && Z_STREAM_END != res);
+ } while(0 == c_stream.avail_out && Z_STREAM_END != res);
deflateEnd(&c_stream);
@@ -748,8 +1054,7 @@ bool CBinary::Compress(ContentCompression& cc)
bool CBinary::Decompress(ContentCompression& cc)
{
- if(cc.ContentCompAlgo == ContentCompression::ZLIB)
- {
+ if(cc.ContentCompAlgo == ContentCompression::ZLIB) {
int res;
z_stream d_stream;
@@ -757,26 +1062,24 @@ bool CBinary::Decompress(ContentCompression& cc)
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
- if(Z_OK != (res = inflateInit(&d_stream)))
+ if(Z_OK != (res = inflateInit(&d_stream))) {
return(false);
+ }
d_stream.next_in = GetData();
d_stream.avail_in = GetCount();
BYTE* dst = NULL;
int n = 0;
- do
- {
+ do {
dst = (unsigned char *)realloc(dst, ++n*1000);
d_stream.next_out = &dst[(n-1)*1000];
d_stream.avail_out = 1000;
- if(Z_OK != (res = inflate(&d_stream, Z_NO_FLUSH)) && Z_STREAM_END != res)
- {
+ if(Z_OK != (res = inflate(&d_stream, Z_NO_FLUSH)) && Z_STREAM_END != res) {
free(dst);
return(false);
}
- }
- while(0 == d_stream.avail_out && 0 != d_stream.avail_in && Z_STREAM_END != res);
+ } while(0 == d_stream.avail_out && 0 != d_stream.avail_in && Z_STREAM_END != res);
inflateEnd(&d_stream);
@@ -786,9 +1089,7 @@ bool CBinary::Decompress(ContentCompression& cc)
free(dst);
return(true);
- }
- else if(cc.ContentCompAlgo == ContentCompression::HDRSTRIP)
- {
+ } else if(cc.ContentCompAlgo == ContentCompression::HDRSTRIP) {
InsertArrayAt(0, &cc.ContentCompSettings);
}
@@ -801,8 +1102,9 @@ HRESULT CANSI::Parse(CMatroskaNode* pMN)
MatroskaReader::QWORD len = pMN->m_len;
CHAR c;
- while(len-- > 0 && SUCCEEDED(pMN->Read(c)))
+ while(len-- > 0 && SUCCEEDED(pMN->Read(c))) {
*this += c;
+ }
return(len == -1 ? S_OK : E_FAIL);
}
@@ -811,8 +1113,9 @@ HRESULT CUTF8::Parse(CMatroskaNode* pMN)
{
Empty();
CAutoVectorPtr<BYTE> buff;
- if(!buff.Allocate((UINT)pMN->m_len + 1) || S_OK != pMN->Read(buff, pMN->m_len))
+ if(!buff.Allocate((UINT)pMN->m_len + 1) || S_OK != pMN->Read(buff, pMN->m_len)) {
return E_FAIL;
+ }
buff[pMN->m_len] = 0;
CStringW::operator = (UTF8To16((LPCSTR)(BYTE*)buff));
return S_OK;
@@ -821,11 +1124,12 @@ HRESULT CUTF8::Parse(CMatroskaNode* pMN)
HRESULT CUInt::Parse(CMatroskaNode* pMN)
{
m_val = 0;
- for(int i = 0; i < (int)pMN->m_len; i++)
- {
+ for(int i = 0; i < (int)pMN->m_len; i++) {
m_val <<= 8;
HRESULT hr = pMN->Read(*(BYTE*)&m_val);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
}
m_fValid = true;
return S_OK;
@@ -834,10 +1138,11 @@ HRESULT CUInt::Parse(CMatroskaNode* pMN)
HRESULT CInt::Parse(CMatroskaNode* pMN)
{
m_val = 0;
- for(int i = 0; i < (int)pMN->m_len; i++)
- {
+ for(int i = 0; i < (int)pMN->m_len; i++) {
HRESULT hr = pMN->Read(*((BYTE*)&m_val+7-i));
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
}
m_val >>= (8-pMN->m_len)*8;
m_fValid = true;
@@ -849,16 +1154,16 @@ HRESULT CFloat::Parse(CMatroskaNode* pMN)
HRESULT hr = E_FAIL;
m_val = 0;
- if(pMN->m_len == 4)
- {
+ if(pMN->m_len == 4) {
float val = 0;
hr = pMN->Read(val);
m_val = val;
} else if(pMN->m_len == 8) {
hr = pMN->Read(m_val);
}
- if(SUCCEEDED(hr))
+ if(SUCCEEDED(hr)) {
m_fValid = true;
+ }
return hr;
}
@@ -877,21 +1182,34 @@ HRESULT CID::Parse(CMatroskaNode* pMN)
BYTE b = 0;
HRESULT hr = pMN->Read(b);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
int nMoreBytes = 0;
- if((b&0x80) == 0x80) {m_val = b&0xff; nMoreBytes = 0;}
- else if((b&0xc0) == 0x40) {m_val = b&0x7f; nMoreBytes = 1;}
- else if((b&0xe0) == 0x20) {m_val = b&0x3f; nMoreBytes = 2;}
- else if((b&0xf0) == 0x10) {m_val = b&0x1f; nMoreBytes = 3;}
- else return E_FAIL;
+ if((b&0x80) == 0x80) {
+ m_val = b&0xff;
+ nMoreBytes = 0;
+ } else if((b&0xc0) == 0x40) {
+ m_val = b&0x7f;
+ nMoreBytes = 1;
+ } else if((b&0xe0) == 0x20) {
+ m_val = b&0x3f;
+ nMoreBytes = 2;
+ } else if((b&0xf0) == 0x10) {
+ m_val = b&0x1f;
+ nMoreBytes = 3;
+ } else {
+ return E_FAIL;
+ }
- while(nMoreBytes-- > 0)
- {
+ while(nMoreBytes-- > 0) {
m_val <<= 8;
hr = pMN->Read(*(BYTE*)&m_val);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
}
m_fValid = true;
@@ -905,39 +1223,60 @@ HRESULT CLength::Parse(CMatroskaNode* pMN)
BYTE b = 0;
HRESULT hr = pMN->Read(b);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
int nMoreBytes = 0, nMoreBytesTmp = 0;
- if((b&0x80) == 0x80) {m_val = b&0x7f; nMoreBytes = 0;}
- else if((b&0xc0) == 0x40) {m_val = b&0x3f; nMoreBytes = 1;}
- else if((b&0xe0) == 0x20) {m_val = b&0x1f; nMoreBytes = 2;}
- else if((b&0xf0) == 0x10) {m_val = b&0x0f; nMoreBytes = 3;}
- else if((b&0xf8) == 0x08) {m_val = b&0x07; nMoreBytes = 4;}
- else if((b&0xfc) == 0x04) {m_val = b&0x03; nMoreBytes = 5;}
- else if((b&0xfe) == 0x02) {m_val = b&0x01; nMoreBytes = 6;}
- else if((b&0xff) == 0x01) {m_val = b&0x00; nMoreBytes = 7;}
- else return E_FAIL;
+ if((b&0x80) == 0x80) {
+ m_val = b&0x7f;
+ nMoreBytes = 0;
+ } else if((b&0xc0) == 0x40) {
+ m_val = b&0x3f;
+ nMoreBytes = 1;
+ } else if((b&0xe0) == 0x20) {
+ m_val = b&0x1f;
+ nMoreBytes = 2;
+ } else if((b&0xf0) == 0x10) {
+ m_val = b&0x0f;
+ nMoreBytes = 3;
+ } else if((b&0xf8) == 0x08) {
+ m_val = b&0x07;
+ nMoreBytes = 4;
+ } else if((b&0xfc) == 0x04) {
+ m_val = b&0x03;
+ nMoreBytes = 5;
+ } else if((b&0xfe) == 0x02) {
+ m_val = b&0x01;
+ nMoreBytes = 6;
+ } else if((b&0xff) == 0x01) {
+ m_val = b&0x00;
+ nMoreBytes = 7;
+ } else {
+ return E_FAIL;
+ }
nMoreBytesTmp = nMoreBytes;
MatroskaReader::QWORD UnknownSize = (1i64<<(7*(nMoreBytes+1)))-1;
- while(nMoreBytes-- > 0)
- {
+ while(nMoreBytes-- > 0) {
m_val <<= 8;
hr = pMN->Read(*(BYTE*)&m_val);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
}
- if(m_val == UnknownSize)
- {
+ if(m_val == UnknownSize) {
m_val = pMN->GetLength() - pMN->GetPos();
TRACE(_T("CLength: Unspecified chunk size at %I64d (corrected to %I64d)\n"), pMN->GetPos(), m_val);
}
- if(m_fSigned)
+ if(m_fSigned) {
m_val -= (UnknownSize >> 1);
+ }
m_fValid = true;
@@ -996,7 +1335,9 @@ HRESULT CNode<T>::Parse(CMatroskaNode* pMN)
{
CAutoPtr<T> p(DNew T());
HRESULT hr = E_OUTOFMEMORY;
- if(!p || FAILED(hr = p->Parse(pMN))) return hr;
+ if(!p || FAILED(hr = p->Parse(pMN))) {
+ return hr;
+ }
AddTail(p);
return S_OK;
}
@@ -1005,7 +1346,9 @@ HRESULT CBlockGroupNode::Parse(CMatroskaNode* pMN, bool fFull)
{
CAutoPtr<BlockGroup> p(DNew BlockGroup());
HRESULT hr = E_OUTOFMEMORY;
- if(!p || FAILED(hr = p->Parse(pMN, fFull))) return hr;
+ if(!p || FAILED(hr = p->Parse(pMN, fFull))) {
+ return hr;
+ }
AddTail(p);
return S_OK;
}
@@ -1014,7 +1357,9 @@ HRESULT CSimpleBlockNode::Parse(CMatroskaNode* pMN, bool fFull)
{
CAutoPtr<SimpleBlock> p(DNew SimpleBlock());
HRESULT hr = E_OUTOFMEMORY;
- if(!p || FAILED(hr = p->Parse(pMN, fFull))) return hr;
+ if(!p || FAILED(hr = p->Parse(pMN, fFull))) {
+ return hr;
+ }
AddTail(p);
return S_OK;
}
@@ -1027,7 +1372,7 @@ CMatroskaNode::CMatroskaNode(CMatroskaFile* pMF)
{
ASSERT(m_pMF);
m_start = m_filepos = 0;
- m_len.Set(m_pMF ? m_pMF->GetLength() : 0);
+ m_len.Set(m_pMF ? m_pMF->GetLength() : 0);
}
CMatroskaNode::CMatroskaNode(CMatroskaNode* pParent)
@@ -1040,40 +1385,46 @@ CMatroskaNode::CMatroskaNode(CMatroskaNode* pParent)
HRESULT CMatroskaNode::Parse()
{
m_filepos = GetPos();
- if(FAILED(m_id.Parse(this)) || FAILED(m_len.Parse(this)))
+ if(FAILED(m_id.Parse(this)) || FAILED(m_len.Parse(this))) {
return E_FAIL;
+ }
m_start = GetPos();
return S_OK;
}
CAutoPtr<CMatroskaNode> CMatroskaNode::Child(DWORD id, bool fSearch)
{
- if(m_len == 0) return CAutoPtr<CMatroskaNode>();
+ if(m_len == 0) {
+ return CAutoPtr<CMatroskaNode>();
+ }
SeekTo(m_start);
CAutoPtr<CMatroskaNode> pMN(DNew CMatroskaNode(this));
- if(id && !pMN->Find(id, fSearch)) pMN.Free();
+ if(id && !pMN->Find(id, fSearch)) {
+ pMN.Free();
+ }
return pMN;
}
bool CMatroskaNode::Next(bool fSame)
{
- if(!m_pParent)
+ if(!m_pParent) {
return(false);
+ }
CID id = m_id;
- while(m_start+m_len < m_pParent->m_start+m_pParent->m_len)
- {
+ while(m_start+m_len < m_pParent->m_start+m_pParent->m_len) {
SeekTo(m_start+m_len);
- if(FAILED(Parse()))
- {
- if(!Resync())
+ if(FAILED(Parse())) {
+ if(!Resync()) {
return(false);
+ }
}
- if(!fSame || m_id == id)
+ if(!fSame || m_id == id) {
return(true);
+ }
}
return(false);
@@ -1081,45 +1432,58 @@ bool CMatroskaNode::Next(bool fSame)
bool CMatroskaNode::Find(DWORD id, bool fSearch)
{
- MatroskaReader::QWORD pos = m_pParent && m_pParent->m_id == 0x18538067 /*segment?*/
- ? FindPos(id)
- : 0;
+ MatroskaReader::QWORD pos = m_pParent && m_pParent->m_id == 0x18538067 /*segment?*/
+ ? FindPos(id)
+ : 0;
- if(pos)
- {
+ if(pos) {
SeekTo(pos);
Parse();
- }
- else if(fSearch)
- {
- while(m_id != id && Next());
+ } else if(fSearch) {
+ while(m_id != id && Next()) {
+ ;
+ }
}
return(m_id == id);
}
-void CMatroskaNode::SeekTo(MatroskaReader::QWORD pos) {m_pMF->Seek(pos);}
-MatroskaReader::QWORD CMatroskaNode::GetPos() {return m_pMF->GetPos();}
-MatroskaReader::QWORD CMatroskaNode::GetLength() {return m_pMF->GetLength();}
-template <class T>
-HRESULT CMatroskaNode::Read(T& var) {return m_pMF->Read(var);}
-HRESULT CMatroskaNode::Read(BYTE* pData, MatroskaReader::QWORD len) {return m_pMF->ByteRead(pData, len);}
+void CMatroskaNode::SeekTo(MatroskaReader::QWORD pos)
+{
+ m_pMF->Seek(pos);
+}
+MatroskaReader::QWORD CMatroskaNode::GetPos()
+{
+ return m_pMF->GetPos();
+}
+MatroskaReader::QWORD CMatroskaNode::GetLength()
+{
+ return m_pMF->GetLength();
+}
+template <class T>
+HRESULT CMatroskaNode::Read(T& var)
+{
+ return m_pMF->Read(var);
+}
+HRESULT CMatroskaNode::Read(BYTE* pData, MatroskaReader::QWORD len)
+{
+ return m_pMF->ByteRead(pData, len);
+}
MatroskaReader::QWORD CMatroskaNode::FindPos(DWORD id, MatroskaReader::QWORD start)
{
Segment& sm = m_pMF->m_segment;
POSITION pos = sm.MetaSeekInfo.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
Seek* s = sm.MetaSeekInfo.GetNext(pos);
POSITION pos2 = s->SeekHeads.GetHeadPosition();
- while(pos2)
- {
+ while(pos2) {
SeekHead* sh = s->SeekHeads.GetNext(pos2);
- if(sh->SeekID == id && sh->SeekPosition+sm.pos >= start)
+ if(sh->SeekID == id && sh->SeekPosition+sm.pos >= start) {
return sh->SeekPosition+sm.pos;
+ }
}
}
@@ -1140,30 +1504,34 @@ CAutoPtr<CMatroskaNode> CMatroskaNode::Copy()
CAutoPtr<CMatroskaNode> CMatroskaNode::GetFirstBlock()
{
CAutoPtr<CMatroskaNode> pNode = Child();
- do {if(pNode->m_id == 0xA0 || pNode->m_id == 0xA3) return pNode;}
- while(pNode->Next());
+ do {
+ if(pNode->m_id == 0xA0 || pNode->m_id == 0xA3) {
+ return pNode;
+ }
+ } while(pNode->Next());
return CAutoPtr<CMatroskaNode>();
}
bool CMatroskaNode::NextBlock()
{
- if(!m_pParent)
+ if(!m_pParent) {
return(false);
+ }
CID id = m_id;
- while(m_start+m_len < m_pParent->m_start+m_pParent->m_len)
- {
+ while(m_start+m_len < m_pParent->m_start+m_pParent->m_len) {
SeekTo(m_start+m_len);
- if(FAILED(Parse()))
- {
- if(!Resync())
+ if(FAILED(Parse())) {
+ if(!Resync()) {
return(false);
+ }
}
- if(m_id == 0xA0 || m_id == 0xA3)
+ if(m_id == 0xA0 || m_id == 0xA3) {
return(true);
+ }
}
return(false);
@@ -1171,34 +1539,32 @@ bool CMatroskaNode::NextBlock()
bool CMatroskaNode::Resync()
{
- if(m_pParent->m_id == 0x18538067) /*segment?*/
- {
+ if(m_pParent->m_id == 0x18538067) { /*segment?*/
SeekTo(m_filepos);
- for(BYTE b = 0; S_OK == Read(b); b = 0)
- {
- if((b&0xf0) != 0x10)
+ for(BYTE b = 0; S_OK == Read(b); b = 0) {
+ if((b&0xf0) != 0x10) {
continue;
+ }
- DWORD dw = b;
+ DWORD dw = b;
Read((BYTE*)&dw+1, 3);
bswap((BYTE*)&dw, 4);
- switch(dw)
- {
- case 0x1549A966: // SegmentInfo
- case 0x114D9B74: // MetaSeekInfo
- case 0x1654AE6B: // Tracks
- case 0x1F43B675: // Clusters
- case 0x1C53BB6B: // Cues
- case 0x1941A469: // Attachments
- case 0x1043A770: // Chapters
- case 0x1254C367: // Tags
- SeekTo(GetPos()-4);
- return(SUCCEEDED(Parse()));
- default:
- SeekTo(GetPos()-3);
- break;
+ switch(dw) {
+ case 0x1549A966: // SegmentInfo
+ case 0x114D9B74: // MetaSeekInfo
+ case 0x1654AE6B: // Tracks
+ case 0x1F43B675: // Clusters
+ case 0x1C53BB6B: // Cues
+ case 0x1941A469: // Attachments
+ case 0x1043A770: // Chapters
+ case 0x1254C367: // Tags
+ SeekTo(GetPos()-4);
+ return(SUCCEEDED(Parse()));
+ default:
+ SeekTo(GetPos()-3);
+ break;
}
}
}
diff --git a/src/filters/parser/MatroskaSplitter/MatroskaFile.h b/src/filters/parser/MatroskaSplitter/MatroskaFile.h
index 183fca217..67c1a9b2c 100644
--- a/src/filters/parser/MatroskaSplitter/MatroskaFile.h
+++ b/src/filters/parser/MatroskaSplitter/MatroskaFile.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -31,8 +31,16 @@ namespace MatroskaReader
typedef unsigned __int64 QWORD;
- class CANSI : public CStringA {public: HRESULT Parse(CMatroskaNode* pMN);};
- class CUTF8 : public CStringW {public: HRESULT Parse(CMatroskaNode* pMN);};
+ class CANSI : public CStringA
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+ class CUTF8 : public CStringW
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
template<class T, class BASE>
class CSimpleVar
@@ -42,36 +50,86 @@ namespace MatroskaReader
bool m_fValid;
public:
CSimpleVar(T val = 0) : m_val(val), m_fValid(false) {}
- BASE& operator = (const BASE& v) {m_val = v.m_val; m_fValid = true; return(*this);}
- BASE& operator = (T val) {m_val = val; m_fValid = true; return(*this);}
- operator T() const {return m_val;}
- BASE& Set(T val) {m_val = val; m_fValid = true; return(*(BASE*)this);}
- bool IsValid() const {return m_fValid;}
+ BASE& operator = (const BASE& v) {
+ m_val = v.m_val;
+ m_fValid = true;
+ return(*this);
+ }
+ BASE& operator = (T val) {
+ m_val = val;
+ m_fValid = true;
+ return(*this);
+ }
+ operator T() const {
+ return m_val;
+ }
+ BASE& Set(T val) {
+ m_val = val;
+ m_fValid = true;
+ return(*(BASE*)this);
+ }
+ bool IsValid() const {
+ return m_fValid;
+ }
virtual HRESULT Parse(CMatroskaNode* pMN);
};
- class CUInt : public CSimpleVar<UINT64, CUInt> {public: HRESULT Parse(CMatroskaNode* pMN);};
- class CInt : public CSimpleVar<INT64, CInt> {public: HRESULT Parse(CMatroskaNode* pMN);};
+ class CUInt : public CSimpleVar<UINT64, CUInt>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+ class CInt : public CSimpleVar<INT64, CInt>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
class CByte : public CSimpleVar<BYTE, CByte> {};
class CShort : public CSimpleVar<short, CShort> {};
- class CFloat : public CSimpleVar<double, CFloat> {public: HRESULT Parse(CMatroskaNode* pMN);};
- class CID : public CSimpleVar<DWORD, CID> {public: HRESULT Parse(CMatroskaNode* pMN);};
- class CLength : public CSimpleVar<UINT64, CLength> {bool m_fSigned; public: CLength(bool fSigned = false) : m_fSigned(fSigned) {} HRESULT Parse(CMatroskaNode* pMN);};
- class CSignedLength : public CLength {public: CSignedLength() : CLength(true) {}};
+ class CFloat : public CSimpleVar<double, CFloat>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+ class CID : public CSimpleVar<DWORD, CID>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+ class CLength : public CSimpleVar<UINT64, CLength>
+ {
+ bool m_fSigned;
+ public:
+ CLength(bool fSigned = false) : m_fSigned(fSigned) {} HRESULT Parse(CMatroskaNode* pMN);
+ };
+ class CSignedLength : public CLength
+ {
+ public:
+ CSignedLength() : CLength(true) {}
+ };
class ContentCompression;
class CBinary : public CAtlArray<BYTE>
{
public:
- CBinary& operator = (const CBinary& b) {Copy(b); return(*this);}
- CStringA ToString() {return CStringA((LPCSTR)GetData(), GetCount());}
+ CBinary& operator = (const CBinary& b) {
+ Copy(b);
+ return(*this);
+ }
+ CStringA ToString() {
+ return CStringA((LPCSTR)GetData(), GetCount());
+ }
bool Compress(ContentCompression& cc), Decompress(ContentCompression& cc);
HRESULT Parse(CMatroskaNode* pMN);
};
template<class T>
- class CNode : public CAutoPtrList<T> {public: HRESULT Parse(CMatroskaNode* pMN);};
+ class CNode : public CAutoPtrList<T>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
class EBML
{
@@ -84,321 +142,378 @@ namespace MatroskaReader
HRESULT Parse(CMatroskaNode* pMN);
};
- class Info
- {
- public:
- CBinary SegmentUID, PrevUID, NextUID;
- CUTF8 SegmentFilename, PrevFilename, NextFilename;
- CUInt TimeCodeScale; // [ns], default: 1.000.000
- CFloat Duration;
- CInt DateUTC;
- CUTF8 Title, MuxingApp, WritingApp;
-
- Info() {TimeCodeScale.Set(1000000ui64);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class SeekHead
- {
- public:
- CID SeekID;
- CUInt SeekPosition;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class Seek
- {
- public:
- CNode<SeekHead> SeekHeads;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class TimeSlice
- {
- public:
- CUInt LaceNumber, FrameNumber;
- CUInt Delay, Duration;
-
- TimeSlice() {LaceNumber.Set(0); FrameNumber.Set(0); Delay.Set(0); Duration.Set(0);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class SimpleBlock
- {
- public:
- CLength TrackNumber;
- CInt TimeCode;
- CByte Lacing;
- CAutoPtrList<CBinary> BlockData;
-
- HRESULT Parse(CMatroskaNode* pMN, bool fFull);
- };
-
- class BlockMore
- {
- public:
- CInt BlockAddID;
- CBinary BlockAdditional;
-
- BlockMore() {BlockAddID.Set(1);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class BlockAdditions
- {
- public:
- CNode<BlockMore> bm;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class BlockGroup
- {
- public:
- SimpleBlock Block;
-// BlockVirtual
- CUInt BlockDuration;
- CUInt ReferencePriority;
- CInt ReferenceBlock;
- CInt ReferenceVirtual;
- CBinary CodecState;
- CNode<TimeSlice> TimeSlices;
- BlockAdditions ba;
-
- HRESULT Parse(CMatroskaNode* pMN, bool fFull);
- };
-
- class CBlockGroupNode : public CNode<BlockGroup>
- {
- public:
- HRESULT Parse(CMatroskaNode* pMN, bool fFull);
- };
-
- class CSimpleBlockNode : public CNode<SimpleBlock>
- {
- public:
- HRESULT Parse(CMatroskaNode* pMN, bool fFull);
- };
-
- class Cluster
- {
- public:
- CUInt TimeCode, Position, PrevSize;
- CBlockGroupNode BlockGroups;
- CSimpleBlockNode SimpleBlocks;
-
- HRESULT Parse(CMatroskaNode* pMN);
- HRESULT ParseTimeCode(CMatroskaNode* pMN);
- };
-
- class Video
- {
- public:
- CUInt FlagInterlaced, StereoMode;
- CUInt PixelWidth, PixelHeight, DisplayWidth, DisplayHeight, DisplayUnit;
- CUInt AspectRatioType;
- CUInt ColourSpace;
- CFloat GammaValue;
- CFloat FramePerSec;
-
- Video() {FlagInterlaced.Set(0); StereoMode.Set(0); DisplayUnit.Set(0); AspectRatioType.Set(0);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class Audio
- {
- public:
- CFloat SamplingFrequency;
- CFloat OutputSamplingFrequency;
- CUInt Channels;
- CBinary ChannelPositions;
- CUInt BitDepth;
-
- Audio() {SamplingFrequency.Set(8000.0); Channels.Set(1);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class ContentCompression
- {
- public:
- CUInt ContentCompAlgo; enum {ZLIB, BZLIB, LZO1X, HDRSTRIP};
- CBinary ContentCompSettings;
-
- ContentCompression() {ContentCompAlgo.Set(ZLIB);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class ContentEncryption
- {
- public:
- CUInt ContentEncAlgo; enum {UNKE, DES, THREEDES, TWOFISH, BLOWFISH, AES};
- CBinary ContentEncKeyID, ContentSignature, ContentSigKeyID;
- CUInt ContentSigAlgo; enum {UNKS, RSA};
- CUInt ContentSigHashAlgo; enum {UNKSH, SHA1_160, MD5};
-
- ContentEncryption() {ContentEncAlgo.Set(0); ContentSigAlgo.Set(0); ContentSigHashAlgo.Set(0);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class ContentEncoding
- {
- public:
- CUInt ContentEncodingOrder;
- CUInt ContentEncodingScope; enum {AllFrameContents = 1, TracksPrivateData = 2};
- CUInt ContentEncodingType; enum {Compression, Encryption};
- ContentCompression cc;
- ContentEncryption ce;
-
- ContentEncoding() {ContentEncodingOrder.Set(0); ContentEncodingScope.Set(AllFrameContents); ContentEncodingType.Set(Compression);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class ContentEncodings
- {
- public:
- CNode<ContentEncoding> ce;
-
- ContentEncodings() {}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class TrackEntry
- {
- public:
- enum {TypeVideo = 1, TypeAudio = 2, TypeComplex = 3, TypeLogo = 0x10, TypeSubtitle = 0x11, TypeControl = 0x20};
- CUInt TrackNumber, TrackUID, TrackType;
- CUInt FlagEnabled, FlagDefault, FlagLacing, FlagForced;
- CUInt MinCache, MaxCache;
- CUTF8 Name;
- CANSI Language;
- CBinary CodecID;
- CBinary CodecPrivate;
- CUTF8 CodecName;
- CUTF8 CodecSettings;
- CANSI CodecInfoURL;
- CANSI CodecDownloadURL;
- CUInt CodecDecodeAll;
- CUInt TrackOverlay;
- CUInt DefaultDuration;
- CUInt MaxBlockAdditionID;
- CFloat TrackTimecodeScale;
- enum {NoDesc = 0, DescVideo = 1, DescAudio = 2};
- unsigned int DescType;
- Video v;
- Audio a;
- ContentEncodings ces;
- TrackEntry() {DescType = NoDesc; FlagEnabled.Set(1); FlagDefault.Set(1); FlagLacing.Set(1); FlagForced.Set(0); MinCache.Set(0); TrackTimecodeScale.Set(1.0f);
- Language.CStringA::operator = ("eng"); MaxBlockAdditionID.Set(0); CodecDecodeAll.Set(1);}
- HRESULT Parse(CMatroskaNode* pMN);
-
- bool Expand(CBinary& data, UINT64 Scope);
- };
-
- class Track
- {
- public:
- CNode<TrackEntry> TrackEntries;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class CueReference
- {
- public:
- CUInt CueRefTime, CueRefCluster, CueRefNumber, CueRefCodecState;
-
- CueReference() {CueRefNumber.Set(1); CueRefCodecState.Set(0);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class CueTrackPosition
- {
- public:
- CUInt CueTrack, CueClusterPosition, CueBlockNumber, CueCodecState;
- CNode<CueReference> CueReferences;
-
- CueTrackPosition() {CueBlockNumber.Set(1); CueCodecState.Set(0);}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class CuePoint
- {
- public:
- CUInt CueTime;
- CNode<CueTrackPosition> CueTrackPositions;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class Cue
- {
- public:
- CNode<CuePoint> CuePoints;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class AttachedFile
- {
- public:
- CUTF8 FileDescription;
- CUTF8 FileName;
- CANSI FileMimeType;
- QWORD FileDataPos, FileDataLen; // BYTE* FileData
- CUInt FileUID;
-
- AttachedFile() {FileDataPos = FileDataLen = 0;}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class Attachment
- {
- public:
- CNode<AttachedFile> AttachedFiles;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class ChapterDisplay
- {
- public:
- CUTF8 ChapString;
- CANSI ChapLanguage;
- CANSI ChapCountry;
-
- ChapterDisplay() {ChapLanguage.CStringA::operator = ("eng");}
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class ChapterAtom
- {
- public:
- CUInt ChapterUID;
- CUInt ChapterTimeStart, ChapterTimeEnd, ChapterFlagHidden, ChapterFlagEnabled;
-// CNode<CUInt> ChapterTracks; // TODO
- CNode<ChapterDisplay> ChapterDisplays;
- CNode<ChapterAtom> ChapterAtoms;
-
- ChapterAtom() {ChapterUID.Set(rand());ChapterFlagHidden.Set(0);ChapterFlagEnabled.Set(1);}
- HRESULT Parse(CMatroskaNode* pMN);
- ChapterAtom* FindChapterAtom(UINT64 id);
- };
-
- class EditionEntry : public ChapterAtom
- {
- public:
- HRESULT Parse(CMatroskaNode* pMN);
- };
-
- class Chapter
- {
- public:
- CNode<EditionEntry> EditionEntries;
-
- HRESULT Parse(CMatroskaNode* pMN);
- };
+ class Info
+ {
+ public:
+ CBinary SegmentUID, PrevUID, NextUID;
+ CUTF8 SegmentFilename, PrevFilename, NextFilename;
+ CUInt TimeCodeScale; // [ns], default: 1.000.000
+ CFloat Duration;
+ CInt DateUTC;
+ CUTF8 Title, MuxingApp, WritingApp;
+
+ Info() {
+ TimeCodeScale.Set(1000000ui64);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class SeekHead
+ {
+ public:
+ CID SeekID;
+ CUInt SeekPosition;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class Seek
+ {
+ public:
+ CNode<SeekHead> SeekHeads;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class TimeSlice
+ {
+ public:
+ CUInt LaceNumber, FrameNumber;
+ CUInt Delay, Duration;
+
+ TimeSlice() {
+ LaceNumber.Set(0);
+ FrameNumber.Set(0);
+ Delay.Set(0);
+ Duration.Set(0);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class SimpleBlock
+ {
+ public:
+ CLength TrackNumber;
+ CInt TimeCode;
+ CByte Lacing;
+ CAutoPtrList<CBinary> BlockData;
+
+ HRESULT Parse(CMatroskaNode* pMN, bool fFull);
+ };
+
+ class BlockMore
+ {
+ public:
+ CInt BlockAddID;
+ CBinary BlockAdditional;
+
+ BlockMore() {
+ BlockAddID.Set(1);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class BlockAdditions
+ {
+ public:
+ CNode<BlockMore> bm;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class BlockGroup
+ {
+ public:
+ SimpleBlock Block;
+ // BlockVirtual
+ CUInt BlockDuration;
+ CUInt ReferencePriority;
+ CInt ReferenceBlock;
+ CInt ReferenceVirtual;
+ CBinary CodecState;
+ CNode<TimeSlice> TimeSlices;
+ BlockAdditions ba;
+
+ HRESULT Parse(CMatroskaNode* pMN, bool fFull);
+ };
+
+ class CBlockGroupNode : public CNode<BlockGroup>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN, bool fFull);
+ };
+
+ class CSimpleBlockNode : public CNode<SimpleBlock>
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN, bool fFull);
+ };
+
+ class Cluster
+ {
+ public:
+ CUInt TimeCode, Position, PrevSize;
+ CBlockGroupNode BlockGroups;
+ CSimpleBlockNode SimpleBlocks;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ HRESULT ParseTimeCode(CMatroskaNode* pMN);
+ };
+
+ class Video
+ {
+ public:
+ CUInt FlagInterlaced, StereoMode;
+ CUInt PixelWidth, PixelHeight, DisplayWidth, DisplayHeight, DisplayUnit;
+ CUInt AspectRatioType;
+ CUInt ColourSpace;
+ CFloat GammaValue;
+ CFloat FramePerSec;
+
+ Video() {
+ FlagInterlaced.Set(0);
+ StereoMode.Set(0);
+ DisplayUnit.Set(0);
+ AspectRatioType.Set(0);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class Audio
+ {
+ public:
+ CFloat SamplingFrequency;
+ CFloat OutputSamplingFrequency;
+ CUInt Channels;
+ CBinary ChannelPositions;
+ CUInt BitDepth;
+
+ Audio() {
+ SamplingFrequency.Set(8000.0);
+ Channels.Set(1);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class ContentCompression
+ {
+ public:
+ CUInt ContentCompAlgo;
+ enum {ZLIB, BZLIB, LZO1X, HDRSTRIP};
+ CBinary ContentCompSettings;
+
+ ContentCompression() {
+ ContentCompAlgo.Set(ZLIB);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class ContentEncryption
+ {
+ public:
+ CUInt ContentEncAlgo;
+ enum {UNKE, DES, THREEDES, TWOFISH, BLOWFISH, AES};
+ CBinary ContentEncKeyID, ContentSignature, ContentSigKeyID;
+ CUInt ContentSigAlgo;
+ enum {UNKS, RSA};
+ CUInt ContentSigHashAlgo;
+ enum {UNKSH, SHA1_160, MD5};
+
+ ContentEncryption() {
+ ContentEncAlgo.Set(0);
+ ContentSigAlgo.Set(0);
+ ContentSigHashAlgo.Set(0);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class ContentEncoding
+ {
+ public:
+ CUInt ContentEncodingOrder;
+ CUInt ContentEncodingScope;
+ enum {AllFrameContents = 1, TracksPrivateData = 2};
+ CUInt ContentEncodingType;
+ enum {Compression, Encryption};
+ ContentCompression cc;
+ ContentEncryption ce;
+
+ ContentEncoding() {
+ ContentEncodingOrder.Set(0);
+ ContentEncodingScope.Set(AllFrameContents);
+ ContentEncodingType.Set(Compression);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class ContentEncodings
+ {
+ public:
+ CNode<ContentEncoding> ce;
+
+ ContentEncodings() {}
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class TrackEntry
+ {
+ public:
+ enum {TypeVideo = 1, TypeAudio = 2, TypeComplex = 3, TypeLogo = 0x10, TypeSubtitle = 0x11, TypeControl = 0x20};
+ CUInt TrackNumber, TrackUID, TrackType;
+ CUInt FlagEnabled, FlagDefault, FlagLacing, FlagForced;
+ CUInt MinCache, MaxCache;
+ CUTF8 Name;
+ CANSI Language;
+ CBinary CodecID;
+ CBinary CodecPrivate;
+ CUTF8 CodecName;
+ CUTF8 CodecSettings;
+ CANSI CodecInfoURL;
+ CANSI CodecDownloadURL;
+ CUInt CodecDecodeAll;
+ CUInt TrackOverlay;
+ CUInt DefaultDuration;
+ CUInt MaxBlockAdditionID;
+ CFloat TrackTimecodeScale;
+ enum {NoDesc = 0, DescVideo = 1, DescAudio = 2};
+ unsigned int DescType;
+ Video v;
+ Audio a;
+ ContentEncodings ces;
+ TrackEntry() {
+ DescType = NoDesc;
+ FlagEnabled.Set(1);
+ FlagDefault.Set(1);
+ FlagLacing.Set(1);
+ FlagForced.Set(0);
+ MinCache.Set(0);
+ TrackTimecodeScale.Set(1.0f);
+ Language.CStringA::operator = ("eng");
+ MaxBlockAdditionID.Set(0);
+ CodecDecodeAll.Set(1);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+
+ bool Expand(CBinary& data, UINT64 Scope);
+ };
+
+ class Track
+ {
+ public:
+ CNode<TrackEntry> TrackEntries;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class CueReference
+ {
+ public:
+ CUInt CueRefTime, CueRefCluster, CueRefNumber, CueRefCodecState;
+
+ CueReference() {
+ CueRefNumber.Set(1);
+ CueRefCodecState.Set(0);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class CueTrackPosition
+ {
+ public:
+ CUInt CueTrack, CueClusterPosition, CueBlockNumber, CueCodecState;
+ CNode<CueReference> CueReferences;
+
+ CueTrackPosition() {
+ CueBlockNumber.Set(1);
+ CueCodecState.Set(0);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class CuePoint
+ {
+ public:
+ CUInt CueTime;
+ CNode<CueTrackPosition> CueTrackPositions;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class Cue
+ {
+ public:
+ CNode<CuePoint> CuePoints;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class AttachedFile
+ {
+ public:
+ CUTF8 FileDescription;
+ CUTF8 FileName;
+ CANSI FileMimeType;
+ QWORD FileDataPos, FileDataLen; // BYTE* FileData
+ CUInt FileUID;
+
+ AttachedFile() {
+ FileDataPos = FileDataLen = 0;
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class Attachment
+ {
+ public:
+ CNode<AttachedFile> AttachedFiles;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class ChapterDisplay
+ {
+ public:
+ CUTF8 ChapString;
+ CANSI ChapLanguage;
+ CANSI ChapCountry;
+
+ ChapterDisplay() {
+ ChapLanguage.CStringA::operator = ("eng");
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class ChapterAtom
+ {
+ public:
+ CUInt ChapterUID;
+ CUInt ChapterTimeStart, ChapterTimeEnd, ChapterFlagHidden, ChapterFlagEnabled;
+ // CNode<CUInt> ChapterTracks; // TODO
+ CNode<ChapterDisplay> ChapterDisplays;
+ CNode<ChapterAtom> ChapterAtoms;
+
+ ChapterAtom() {
+ ChapterUID.Set(rand());
+ ChapterFlagHidden.Set(0);
+ ChapterFlagEnabled.Set(1);
+ }
+ HRESULT Parse(CMatroskaNode* pMN);
+ ChapterAtom* FindChapterAtom(UINT64 id);
+ };
+
+ class EditionEntry : public ChapterAtom
+ {
+ public:
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
+
+ class Chapter
+ {
+ public:
+ CNode<EditionEntry> EditionEntries;
+
+ HRESULT Parse(CMatroskaNode* pMN);
+ };
class Segment
{
@@ -419,7 +534,9 @@ namespace MatroskaReader
UINT64 GetMasterTrack();
- REFERENCE_TIME GetRefTime(INT64 t) const {return t*(REFERENCE_TIME)(SegmentInfo.TimeCodeScale)/100;}
+ REFERENCE_TIME GetRefTime(INT64 t) const {
+ return t*(REFERENCE_TIME)(SegmentInfo.TimeCodeScale)/100;
+ }
ChapterAtom* FindChapterAtom(UINT64 id, int nEditionEntry = 0);
};
@@ -459,7 +576,9 @@ namespace MatroskaReader
CMatroskaNode(CMatroskaFile* pMF); // creates the root
CMatroskaNode(CMatroskaNode* pParent);
- CMatroskaNode* Parent() {return m_pParent;}
+ CMatroskaNode* Parent() {
+ return m_pParent;
+ }
CAutoPtr<CMatroskaNode> Child(DWORD id = 0, bool fSearch = true);
bool Next(bool fSame = false);
bool Find(DWORD id, bool fSearch = true);
@@ -472,10 +591,12 @@ namespace MatroskaReader
HRESULT Read(BYTE* pData, QWORD len);
CAutoPtr<CMatroskaNode> Copy();
-
+
CAutoPtr<CMatroskaNode> GetFirstBlock();
bool NextBlock();
- bool IsRandomAccess() {return m_pMF->IsRandomAccess();}
+ bool IsRandomAccess() {
+ return m_pMF->IsRandomAccess();
+ }
};
}
diff --git a/src/filters/parser/MatroskaSplitter/MatroskaSplitter.cpp b/src/filters/parser/MatroskaSplitter/MatroskaSplitter.cpp
index f9ded756e..78f1b6080 100644
--- a/src/filters/parser/MatroskaSplitter/MatroskaSplitter.cpp
+++ b/src/filters/parser/MatroskaSplitter/MatroskaSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -31,26 +31,22 @@ using namespace MatroskaReader;
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_Matroska},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMatroskaSplitterFilter), L"MPC - Matroska Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CMatroskaSourceFilter), L"MPC - Matroska Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMatroskaSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CMatroskaSourceFilter>, NULL, &sudFilter[1]},
};
@@ -60,9 +56,9 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
RegisterSourceFilter(
- __uuidof(CMatroskaSourceFilter),
- MEDIASUBTYPE_Matroska,
- _T("0,4,,1A45DFA3"),
+ __uuidof(CMatroskaSourceFilter),
+ MEDIASUBTYPE_Matroska,
+ _T("0,4,,1A45DFA3"),
_T(".mkv"), _T(".mka"), _T(".mks"), NULL);
return AMovieDllRegisterServer2(TRUE);
@@ -98,7 +94,7 @@ STDMETHODIMP CMatroskaSplitterFilter::NonDelegatingQueryInterface(REFIID riid, v
{
CheckPointer(ppv, E_POINTER);
- return
+ return
QI(ITrackInfo)
__super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -119,8 +115,13 @@ HRESULT CMatroskaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
CAtlArray<TrackEntry*> pinOutTE;
m_pFile.Attach(DNew CMatroskaFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = 0;
@@ -128,19 +129,18 @@ HRESULT CMatroskaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
int iVideo = 1, iAudio = 1, iSubtitle = 1;
POSITION pos = m_pFile->m_segment.Tracks.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
Track* pT = m_pFile->m_segment.Tracks.GetNext(pos);
POSITION pos2 = pT->TrackEntries.GetHeadPosition();
- while(pos2)
- {
+ while(pos2) {
TrackEntry* pTE = pT->TrackEntries.GetNext(pos2);
bool isSub = false;
- if(!pTE->Expand(pTE->CodecPrivate, ContentEncoding::TracksPrivateData))
+ if(!pTE->Expand(pTE->CodecPrivate, ContentEncoding::TracksPrivateData)) {
continue;
+ }
CStringA CodecID = pTE->CodecID.ToString();
@@ -152,82 +152,83 @@ HRESULT CMatroskaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mt.SetSampleSize(1);
- if(pTE->TrackType == TrackEntry::TypeVideo)
- {
+ if(pTE->TrackType == TrackEntry::TypeVideo) {
Name.Format(L"Video %d", iVideo++);
mt.majortype = MEDIATYPE_Video;
- if(CodecID == "V_MS/VFW/FOURCC")
- {
+ if(CodecID == "V_MS/VFW/FOURCC") {
mt.formattype = FORMAT_VideoInfo;
VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount() - sizeof(BITMAPINFOHEADER));
memset(mt.Format(), 0, mt.FormatLength());
memcpy(&pvih->bmiHeader, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
mt.subtype = FOURCCMap(pvih->bmiHeader.biCompression);
- switch(pvih->bmiHeader.biCompression)
- {
- case BI_RGB: case BI_BITFIELDS: mt.subtype =
- pvih->bmiHeader.biBitCount == 1 ? MEDIASUBTYPE_RGB1 :
- pvih->bmiHeader.biBitCount == 4 ? MEDIASUBTYPE_RGB4 :
- pvih->bmiHeader.biBitCount == 8 ? MEDIASUBTYPE_RGB8 :
- pvih->bmiHeader.biBitCount == 16 ? MEDIASUBTYPE_RGB565 :
- pvih->bmiHeader.biBitCount == 24 ? MEDIASUBTYPE_RGB24 :
- pvih->bmiHeader.biBitCount == 32 ? MEDIASUBTYPE_ARGB32 :
- MEDIASUBTYPE_NULL;
- break;
-// case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break;
-// case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break;
+ switch(pvih->bmiHeader.biCompression) {
+ case BI_RGB:
+ case BI_BITFIELDS:
+ mt.subtype =
+ pvih->bmiHeader.biBitCount == 1 ? MEDIASUBTYPE_RGB1 :
+ pvih->bmiHeader.biBitCount == 4 ? MEDIASUBTYPE_RGB4 :
+ pvih->bmiHeader.biBitCount == 8 ? MEDIASUBTYPE_RGB8 :
+ pvih->bmiHeader.biBitCount == 16 ? MEDIASUBTYPE_RGB565 :
+ pvih->bmiHeader.biBitCount == 24 ? MEDIASUBTYPE_RGB24 :
+ pvih->bmiHeader.biBitCount == 32 ? MEDIASUBTYPE_ARGB32 :
+ MEDIASUBTYPE_NULL;
+ break;
+ // case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break;
+ // case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break;
}
mts.Add(mt);
- }
- else if(CodecID == "V_UNCOMPRESSED")
- {
- }
- else if(CodecID.Find("V_MPEG4/ISO/AVC") == 0 && pTE->CodecPrivate.GetCount() >= 6)
- {
+ } else if(CodecID == "V_UNCOMPRESSED") {
+ } else if(CodecID.Find("V_MPEG4/ISO/AVC") == 0 && pTE->CodecPrivate.GetCount() >= 6) {
BYTE sps = pTE->CodecPrivate[5] & 0x1f;
- std::vector<BYTE> avcC;
- for(int i = 0, j = pTE->CodecPrivate.GetCount(); i < j; i++)
- avcC.push_back(pTE->CodecPrivate[i]);
+ std::vector<BYTE> avcC;
+ for(int i = 0, j = pTE->CodecPrivate.GetCount(); i < j; i++) {
+ avcC.push_back(pTE->CodecPrivate[i]);
+ }
- std::vector<BYTE> sh;
+ std::vector<BYTE> sh;
- unsigned jj = 6;
+ unsigned jj = 6;
- while (sps--) {
- if (jj + 2 > avcC.size())
- goto avcfail;
- unsigned spslen = ((unsigned)avcC[jj] << 8) | avcC[jj+1];
- if (jj + 2 + spslen > avcC.size())
- goto avcfail;
- unsigned cur = sh.size();
- sh.resize(cur + spslen + 2, 0);
- std::copy(avcC.begin() + jj, avcC.begin() + jj + 2 + spslen,sh.begin() + cur);
- jj += 2 + spslen;
- }
+ while (sps--) {
+ if (jj + 2 > avcC.size()) {
+ goto avcfail;
+ }
+ unsigned spslen = ((unsigned)avcC[jj] << 8) | avcC[jj+1];
+ if (jj + 2 + spslen > avcC.size()) {
+ goto avcfail;
+ }
+ unsigned cur = sh.size();
+ sh.resize(cur + spslen + 2, 0);
+ std::copy(avcC.begin() + jj, avcC.begin() + jj + 2 + spslen,sh.begin() + cur);
+ jj += 2 + spslen;
+ }
- if (jj + 1 > avcC.size())
- continue;
-
- unsigned pps = avcC[jj++];
-
- while (pps--) {
- if (jj + 2 > avcC.size())
- goto avcfail;
- unsigned ppslen = ((unsigned)avcC[jj] << 8) | avcC[jj+1];
- if (jj + 2 + ppslen > avcC.size())
- goto avcfail;
- unsigned cur = sh.size();
- sh.resize(cur + ppslen + 2, 0);
- std::copy(avcC.begin() + jj, avcC.begin() + jj + 2 + ppslen, sh.begin() + cur);
- jj += 2 + ppslen;
- }
+ if (jj + 1 > avcC.size()) {
+ continue;
+ }
+
+ unsigned pps = avcC[jj++];
+
+ while (pps--) {
+ if (jj + 2 > avcC.size()) {
+ goto avcfail;
+ }
+ unsigned ppslen = ((unsigned)avcC[jj] << 8) | avcC[jj+1];
+ if (jj + 2 + ppslen > avcC.size()) {
+ goto avcfail;
+ }
+ unsigned cur = sh.size();
+ sh.resize(cur + ppslen + 2, 0);
+ std::copy(avcC.begin() + jj, avcC.begin() + jj + 2 + ppslen, sh.begin() + cur);
+ jj += 2 + ppslen;
+ }
- goto avcsuccess;
+ goto avcsuccess;
avcfail:
- continue;
+ continue;
avcsuccess:
CAtlArray<BYTE> data;
@@ -251,9 +252,7 @@ avcsuccess:
memcpy(pSequenceHeader, data.GetData(), data.GetCount());
pm2vi->cbSequenceHeader = data.GetCount();
mts.Add(mt);
- }
- else if(CodecID.Find("V_MPEG4/") == 0)
- {
+ } else if(CodecID.Find("V_MPEG4/") == 0) {
mt.subtype = FOURCCMap('V4PM');
mt.formattype = FORMAT_MPEG2Video;
MPEG2VIDEOINFO* pm2vi = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + pTE->CodecPrivate.GetCount());
@@ -268,9 +267,7 @@ avcsuccess:
memcpy(pSequenceHeader, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
pm2vi->cbSequenceHeader = pTE->CodecPrivate.GetCount();
mts.Add(mt);
- }
- else if(CodecID.Find("V_REAL/RV") == 0)
- {
+ } else if(CodecID.Find("V_REAL/RV") == 0) {
mt.subtype = FOURCCMap('00VR' + ((CodecID[9]-0x30)<<16));
mt.formattype = FORMAT_VideoInfo;
VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount());
@@ -281,9 +278,7 @@ avcsuccess:
pvih->bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
pvih->bmiHeader.biCompression = mt.subtype.Data1;
mts.Add(mt);
- }
- else if(CodecID == "V_DIRAC")
- {
+ } else if(CodecID == "V_DIRAC") {
mt.subtype = MEDIASUBTYPE_DiracVideo;
mt.formattype = FORMAT_DiracVideoInfo;
DIRACINFOHEADER* dvih = (DIRACINFOHEADER*)mt.AllocFormatBuffer(FIELD_OFFSET(DIRACINFOHEADER, dwSequenceHeader) + pTE->CodecPrivate.GetCount());
@@ -299,19 +294,16 @@ avcsuccess:
dvih->cbSequenceHeader = pTE->CodecPrivate.GetCount();
mts.Add(mt);
- }
- else if(CodecID == "V_MPEG2")
- {
+ } else if(CodecID == "V_MPEG2") {
BYTE* seqhdr = pTE->CodecPrivate.GetData();
DWORD len = pTE->CodecPrivate.GetCount();
int w = pTE->v.PixelWidth;
int h = pTE->v.PixelHeight;
- if(MakeMPEG2MediaType(mt, seqhdr, len, w, h))
+ if(MakeMPEG2MediaType(mt, seqhdr, len, w, h)) {
mts.Add(mt);
- }
- else if(CodecID == "V_THEORA")
- {
+ }
+ } else if(CodecID == "V_THEORA") {
BYTE* thdr = pTE->CodecPrivate.GetData() + 3;
mt.majortype = MEDIATYPE_Video;
@@ -327,7 +319,9 @@ avcsuccess:
vih->hdr.bmiHeader.biBitCount = 24;
int nFpsNum = (thdr[22]<<24)|(thdr[23]<<16)|(thdr[24]<<8)|thdr[25];
int nFpsDenum = (thdr[26]<<24)|(thdr[27]<<16)|(thdr[28]<<8)|thdr[29];
- if(nFpsNum) vih->hdr.AvgTimePerFrame = (REFERENCE_TIME)(10000000.0 * nFpsDenum / nFpsNum);
+ if(nFpsNum) {
+ vih->hdr.AvgTimePerFrame = (REFERENCE_TIME)(10000000.0 * nFpsDenum / nFpsNum);
+ }
vih->hdr.dwPictAspectRatioX = (thdr[14]<<16)|(thdr[15]<<8)|thdr[16];
vih->hdr.dwPictAspectRatioY = (thdr[17]<<16)|(thdr[18]<<8)|thdr[19];
mt.bFixedSizeSamples = 0;
@@ -336,58 +330,51 @@ avcsuccess:
memcpy (&vih->dwSequenceHeader, pTE->CodecPrivate.GetData(), vih->cbSequenceHeader);
mts.Add(mt);
- }
- else if(CodecID.Find("V_VP8") == 0)
- {
- mt.subtype = FOURCCMap('08PV');
- mt.formattype = FORMAT_VideoInfo;
- VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount());
- memset(mt.Format(), 0, mt.FormatLength());
- memcpy(mt.Format() + sizeof(VIDEOINFOHEADER), pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
- pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
- pvih->bmiHeader.biWidth = (LONG)pTE->v.PixelWidth;
- pvih->bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
- pvih->bmiHeader.biCompression = mt.subtype.Data1;
- mts.Add(mt);
- }
-/*
- else if(CodecID == "V_DSHOW/MPEG1VIDEO") // V_MPEG1
- {
- mt.majortype = MEDIATYPE_Video;
- mt.subtype = MEDIASUBTYPE_MPEG1Payload;
- mt.formattype = FORMAT_MPEGVideo;
- MPEG1VIDEOINFO* pm1vi = (MPEG1VIDEOINFO*)mt.AllocFormatBuffer(pTE->CodecPrivate.GetCount());
- memcpy(pm1vi, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
- mt.SetSampleSize(pm1vi->hdr.bmiHeader.biWidth*pm1vi->hdr.bmiHeader.biHeight*4);
+ } else if(CodecID.Find("V_VP8") == 0) {
+ mt.subtype = FOURCCMap('08PV');
+ mt.formattype = FORMAT_VideoInfo;
+ VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount());
+ memset(mt.Format(), 0, mt.FormatLength());
+ memcpy(mt.Format() + sizeof(VIDEOINFOHEADER), pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
+ pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
+ pvih->bmiHeader.biWidth = (LONG)pTE->v.PixelWidth;
+ pvih->bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
+ pvih->bmiHeader.biCompression = mt.subtype.Data1;
mts.Add(mt);
}
-*/
+ /*
+ else if(CodecID == "V_DSHOW/MPEG1VIDEO") // V_MPEG1
+ {
+ mt.majortype = MEDIATYPE_Video;
+ mt.subtype = MEDIASUBTYPE_MPEG1Payload;
+ mt.formattype = FORMAT_MPEGVideo;
+ MPEG1VIDEOINFO* pm1vi = (MPEG1VIDEOINFO*)mt.AllocFormatBuffer(pTE->CodecPrivate.GetCount());
+ memcpy(pm1vi, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
+ mt.SetSampleSize(pm1vi->hdr.bmiHeader.biWidth*pm1vi->hdr.bmiHeader.biHeight*4);
+ mts.Add(mt);
+ }
+ */
REFERENCE_TIME AvgTimePerFrame = 0;
- if(pTE->v.FramePerSec > 0)
+ if(pTE->v.FramePerSec > 0) {
AvgTimePerFrame = (REFERENCE_TIME)(10000000i64 / pTE->v.FramePerSec);
- else if(pTE->DefaultDuration > 0)
+ } else if(pTE->DefaultDuration > 0) {
AvgTimePerFrame = (REFERENCE_TIME)pTE->DefaultDuration / 100;
+ }
- if(AvgTimePerFrame)
- {
- for(int i = 0; i < mts.GetCount(); i++)
- {
+ if(AvgTimePerFrame) {
+ for(int i = 0; i < mts.GetCount(); i++) {
if(mts[i].formattype == FORMAT_VideoInfo
- || mts[i].formattype == FORMAT_VideoInfo2
- || mts[i].formattype == FORMAT_MPEG2Video)
- {
+ || mts[i].formattype == FORMAT_VideoInfo2
+ || mts[i].formattype == FORMAT_MPEG2Video) {
((VIDEOINFOHEADER*)mts[i].Format())->AvgTimePerFrame = AvgTimePerFrame;
}
}
}
- if(pTE->v.DisplayWidth != 0 && pTE->v.DisplayHeight != 0)
- {
- for(int i = 0; i < mts.GetCount(); i++)
- {
- if(mts[i].formattype == FORMAT_VideoInfo)
- {
+ if(pTE->v.DisplayWidth != 0 && pTE->v.DisplayHeight != 0) {
+ for(int i = 0; i < mts.GetCount(); i++) {
+ if(mts[i].formattype == FORMAT_VideoInfo) {
DWORD vih1 = FIELD_OFFSET(VIDEOINFOHEADER, bmiHeader);
DWORD vih2 = FIELD_OFFSET(VIDEOINFOHEADER2, bmiHeader);
DWORD bmi = mts[i].FormatLength() - FIELD_OFFSET(VIDEOINFOHEADER, bmiHeader);
@@ -399,17 +386,13 @@ avcsuccess:
((VIDEOINFOHEADER2*)mt.Format())->dwPictAspectRatioX = (DWORD)pTE->v.DisplayWidth;
((VIDEOINFOHEADER2*)mt.Format())->dwPictAspectRatioY = (DWORD)pTE->v.DisplayHeight;
mts.InsertAt(i++, mt);
- }
- else if(mts[i].formattype == FORMAT_MPEG2Video)
- {
+ } else if(mts[i].formattype == FORMAT_MPEG2Video) {
((MPEG2VIDEOINFO*)mts[i].Format())->hdr.dwPictAspectRatioX = (DWORD)pTE->v.DisplayWidth;
((MPEG2VIDEOINFO*)mts[i].Format())->hdr.dwPictAspectRatioY = (DWORD)pTE->v.DisplayHeight;
}
}
}
- }
- else if(pTE->TrackType == TrackEntry::TypeAudio)
- {
+ } else if(pTE->TrackType == TrackEntry::TypeAudio) {
Name.Format(L"Audio %d", iAudio++);
mt.majortype = MEDIATYPE_Audio;
@@ -425,8 +408,7 @@ avcsuccess:
static CAtlMap<CStringA, int, CStringElementTraits<CStringA> > id2ft;
- if(id2ft.IsEmpty())
- {
+ if(id2ft.IsEmpty()) {
id2ft["A_MPEG/L3"] = WAVE_FORMAT_MP3;
id2ft["A_MPEG/L2"] = WAVE_FORMAT_MPEG;
id2ft["A_MPEG/L1"] = WAVE_FORMAT_MPEG;
@@ -444,10 +426,8 @@ avcsuccess:
}
int wFormatTag;
- if(id2ft.Lookup(CodecID, wFormatTag))
- {
- if(wFormatTag < 0)
- {
+ if(id2ft.Lookup(CodecID, wFormatTag)) {
+ if(wFormatTag < 0) {
wFormatTag = -wFormatTag;
wfe->cbSize = pTE->CodecPrivate.GetCount();
wfe = (WAVEFORMATEX*)mt.ReallocFormatBuffer(sizeof(WAVEFORMATEX) + pTE->CodecPrivate.GetCount());
@@ -457,32 +437,30 @@ avcsuccess:
mt.subtype = FOURCCMap(wfe->wFormatTag = wFormatTag);
mts.Add(mt);
- if(wFormatTag == WAVE_FORMAT_FLAC)
- {
+ if(wFormatTag == WAVE_FORMAT_FLAC) {
mt.subtype = MEDIASUBTYPE_FLAC_FRAMED;
mts.InsertAt(0, mt);
}
- }
- else if(CodecID == "A_VORBIS")
- {
+ } else if(CodecID == "A_VORBIS") {
BYTE* p = pTE->CodecPrivate.GetData();
CAtlArray<int> sizes;
- for(BYTE n = *p++; n > 0; n--)
- {
+ for(BYTE n = *p++; n > 0; n--) {
int size = 0;
- do {size += *p;} while(*p++ == 0xff);
+ do {
+ size += *p;
+ } while(*p++ == 0xff);
sizes.Add(size);
}
int totalsize = 0;
- for(int i = 0; i < sizes.GetCount(); i++)
+ for(int i = 0; i < sizes.GetCount(); i++) {
totalsize += sizes[i];
+ }
sizes.Add(pTE->CodecPrivate.GetCount() - (p - pTE->CodecPrivate.GetData()) - totalsize);
totalsize += sizes[sizes.GetCount()-1];
- if(sizes.GetCount() == 3)
- {
+ if(sizes.GetCount() == 3) {
mt.subtype = MEDIASUBTYPE_Vorbis2;
mt.formattype = FORMAT_VorbisFormat2;
VORBISFORMAT2* pvf2 = (VORBISFORMAT2*)mt.AllocFormatBuffer(sizeof(VORBISFORMAT2) + totalsize);
@@ -491,8 +469,9 @@ avcsuccess:
pvf2->SamplesPerSec = (DWORD)pTE->a.SamplingFrequency;
pvf2->BitsPerSample = (DWORD)pTE->a.BitDepth;
BYTE* p2 = mt.Format() + sizeof(VORBISFORMAT2);
- for(int i = 0; i < sizes.GetCount(); p += sizes[i], p2 += sizes[i], i++)
+ for(int i = 0; i < sizes.GetCount(); p += sizes[i], p2 += sizes[i], i++) {
memcpy(p2, p, pvf2->HeaderSize[i] = sizes[i]);
+ }
mts.Add(mt);
}
@@ -505,44 +484,44 @@ avcsuccess:
vf->nSamplesPerSec = (DWORD)pTE->a.SamplingFrequency;
vf->nMinBitsPerSec = vf->nMaxBitsPerSec = vf->nAvgBitsPerSec = (DWORD)-1;
mts.Add(mt);
- }
- else if(CodecID == "A_MS/ACM")
- {
+ } else if(CodecID == "A_MS/ACM") {
wfe = (WAVEFORMATEX*)mt.AllocFormatBuffer(pTE->CodecPrivate.GetCount());
memcpy(wfe, (WAVEFORMATEX*)pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
mt.subtype = FOURCCMap(wfe->wFormatTag);
mts.Add(mt);
- }
- else if(CodecID.Find("A_AAC/") == 0)
- {
+ } else if(CodecID.Find("A_AAC/") == 0) {
mt.subtype = FOURCCMap(wfe->wFormatTag = WAVE_FORMAT_AAC);
wfe = (WAVEFORMATEX*)mt.ReallocFormatBuffer(sizeof(WAVEFORMATEX) + 5);
wfe->cbSize = 2;
int profile;
- if(CodecID.Find("/MAIN") > 0) profile = 0;
- else if(CodecID.Find("/SBR") > 0) profile = -1;
- else if(CodecID.Find("/LC") > 0) profile = 1;
- else if(CodecID.Find("/SSR") > 0) profile = 2;
- else if(CodecID.Find("/LTP") > 0) profile = 3;
- else continue;
+ if(CodecID.Find("/MAIN") > 0) {
+ profile = 0;
+ } else if(CodecID.Find("/SBR") > 0) {
+ profile = -1;
+ } else if(CodecID.Find("/LC") > 0) {
+ profile = 1;
+ } else if(CodecID.Find("/SSR") > 0) {
+ profile = 2;
+ } else if(CodecID.Find("/LTP") > 0) {
+ profile = 3;
+ } else {
+ continue;
+ }
WORD cbSize = MakeAACInitData((BYTE*)(wfe + 1), profile, wfe->nSamplesPerSec, pTE->a.Channels);
mts.Add(mt);
- if(profile < 0)
- {
+ if(profile < 0) {
wfe->cbSize = cbSize;
wfe->nSamplesPerSec *= 2;
wfe->nAvgBytesPerSec *= 2;
mts.InsertAt(0, mt);
}
- }
- else if(CodecID.Find("A_REAL/") == 0 && CodecID.GetLength() >= 11)
- {
+ } else if(CodecID.Find("A_REAL/") == 0 && CodecID.GetLength() >= 11) {
mt.subtype = FOURCCMap((DWORD)CodecID[7]|((DWORD)CodecID[8]<<8)|((DWORD)CodecID[9]<<16)|((DWORD)CodecID[10]<<24));
mt.bTemporalCompression = TRUE;
wfe->cbSize = pTE->CodecPrivate.GetCount();
@@ -551,25 +530,22 @@ avcsuccess:
wfe->cbSize = 0; // IMPORTANT: this is screwed, but cbSize has to be 0 and the extra data from codec priv must be after WAVEFORMATEX
mts.Add(mt);
}
- }
- else if(pTE->TrackType == TrackEntry::TypeSubtitle)
- {
- if(iSubtitle == 1) InstallFonts();
+ } else if(pTE->TrackType == TrackEntry::TypeSubtitle) {
+ if(iSubtitle == 1) {
+ InstallFonts();
+ }
Name.Format(L"Subtitle %d", iSubtitle++);
mt.SetSampleSize(1);
- if(CodecID == "S_TEXT/ASCII")
- {
+ if(CodecID == "S_TEXT/ASCII") {
mt.majortype = MEDIATYPE_Text;
mt.subtype = MEDIASUBTYPE_NULL;
mt.formattype = FORMAT_None;
mts.Add(mt);
isSub = true;
- }
- else
- {
+ } else {
mt.majortype = MEDIATYPE_Subtitle;
mt.formattype = FORMAT_SubtitleInfo;
SUBTITLEINFO* psi = (SUBTITLEINFO*)mt.AllocFormatBuffer(sizeof(SUBTITLEINFO) + pTE->CodecPrivate.GetCount());
@@ -578,7 +554,7 @@ avcsuccess:
wcsncpy(psi->TrackName, pTE->Name, countof(psi->TrackName)-1);
memcpy(mt.pbFormat + (psi->dwOffset = sizeof(SUBTITLEINFO)), pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
- mt.subtype =
+ mt.subtype =
CodecID == "S_TEXT/UTF8" ? MEDIASUBTYPE_UTF8 :
CodecID == "S_TEXT/SSA" || CodecID == "S_SSA" ? MEDIASUBTYPE_SSA :
CodecID == "S_TEXT/ASS" || CodecID == "S_ASS" ? MEDIASUBTYPE_ASS :
@@ -595,22 +571,25 @@ avcsuccess:
}
}
- if(mts.IsEmpty())
- {
+ if(mts.IsEmpty()) {
TRACE(_T("CMatroskaSourceFilter: Unsupported TrackType %s (%I64d)\n"), CString(CodecID), (UINT64)pTE->TrackType);
continue;
}
Name = CStringW(pTE->Language.IsEmpty() ? L"English" : CStringW(ISO6392ToLanguage(pTE->Language)))
- + (pTE->Name.IsEmpty() ? L"" : L", " + pTE->Name)
- + (L" (" + Name + L")");
+ + (pTE->Name.IsEmpty() ? L"" : L", " + pTE->Name)
+ + (L" (" + Name + L")");
HRESULT hr;
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CMatroskaSplitterOutputPin((int)pTE->MinCache, pTE->DefaultDuration/100, mts, Name, this, this, &hr));
- if(!pTE->Name.IsEmpty()) pPinOut->SetProperty(L"NAME", pTE->Name);
- if(pTE->Language.GetLength() == 3) pPinOut->SetProperty(L"LANG", CStringW(CString(pTE->Language)));
-
+ if(!pTE->Name.IsEmpty()) {
+ pPinOut->SetProperty(L"NAME", pTE->Name);
+ }
+ if(pTE->Language.GetLength() == 3) {
+ pPinOut->SetProperty(L"LANG", CStringW(CString(pTE->Language)));
+ }
+
if (!isSub) {
pinOut.InsertAt((iVideo+iAudio-3),DNew CMatroskaSplitterOutputPin((int)pTE->MinCache, pTE->DefaultDuration/100, mts, Name, this, this, &hr),1);
pinOutTE.InsertAt((iVideo+iAudio-3),pTE,1);
@@ -627,20 +606,18 @@ avcsuccess:
CAutoPtr<CBaseSplitterOutputPin> pPinOut;
pPinOut.Attach(pinOut[i]);
TrackEntry* pTE = pinOutTE[i];
-
- if (pTE != NULL)
- {
+
+ if (pTE != NULL) {
AddOutputPin((DWORD)pTE->TrackNumber, pPinOut);
m_pTrackEntryMap[(DWORD)pTE->TrackNumber] = pTE;
m_pOrderedTrackArray.Add(pTE);
}
}
-
-
+
+
Info& info = m_pFile->m_segment.SegmentInfo;
- if(m_pFile->IsRandomAccess())
- {
+ if(m_pFile->IsRandomAccess()) {
m_rtDuration = (REFERENCE_TIME)(info.Duration * info.TimeCodeScale / 100);
}
@@ -666,32 +643,32 @@ avcsuccess:
{
POSITION pos = m_pFile->m_segment.Attachments.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
Attachment* pA = m_pFile->m_segment.Attachments.GetNext(pos);
POSITION pos = pA->AttachedFiles.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
AttachedFile* pF = pA->AttachedFiles.GetNext(pos);
CAtlArray<BYTE> pData;
pData.SetCount(pF->FileDataLen);
m_pFile->Seek(pF->FileDataPos);
- if(SUCCEEDED(m_pFile->ByteRead(pData.GetData(), pData.GetCount())))
+ if(SUCCEEDED(m_pFile->ByteRead(pData.GetData(), pData.GetCount()))) {
ResAppend(pF->FileName, pF->FileDescription, CStringW(pF->FileMimeType), pData.GetData(), pData.GetCount());
+ }
}
}
}
// chapters
- if(ChapterAtom* caroot = m_pFile->m_segment.FindChapterAtom(0))
- {
+ if(ChapterAtom* caroot = m_pFile->m_segment.FindChapterAtom(0)) {
CStringA str;
str.ReleaseBufferSetLength(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, str.GetBuffer(3), 3));
CStringA ChapLanguage = CStringA(ISO6391To6392(str));
- if(ChapLanguage.GetLength() < 3) ChapLanguage = "eng";
+ if(ChapLanguage.GetLength() < 3) {
+ ChapLanguage = "eng";
+ }
SetupChapters(ChapLanguage, caroot);
}
@@ -703,36 +680,38 @@ void CMatroskaSplitterFilter::SetupChapters(LPCSTR lng, ChapterAtom* parent, int
{
CStringW tabs('+', level);
- if(!tabs.IsEmpty()) tabs += ' ';
+ if(!tabs.IsEmpty()) {
+ tabs += ' ';
+ }
POSITION pos = parent->ChapterAtoms.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
// ChapUID zero not allow by Matroska specs
UINT64 ChapUID = parent->ChapterAtoms.GetNext(pos)->ChapterUID;
ChapterAtom* ca = (ChapUID == 0) ? NULL : m_pFile->m_segment.FindChapterAtom(ChapUID);
- if(ca)
- {
+ if(ca) {
CStringW name, first;
POSITION pos = ca->ChapterDisplays.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
ChapterDisplay* cd = ca->ChapterDisplays.GetNext(pos);
- if(first.IsEmpty()) first = cd->ChapString;
- if(cd->ChapLanguage == lng) name = cd->ChapString;
+ if(first.IsEmpty()) {
+ first = cd->ChapString;
+ }
+ if(cd->ChapLanguage == lng) {
+ name = cd->ChapString;
+ }
}
name = tabs + (!name.IsEmpty() ? name : first);
ChapAppend(ca->ChapterTimeStart / 100 - m_pFile->m_rtOffset, name);
- if(!ca->ChapterAtoms.IsEmpty())
- {
+ if(!ca->ChapterAtoms.IsEmpty()) {
SetupChapters(lng, ca, level+1);
}
- }
+ }
}
}
@@ -740,25 +719,22 @@ void CMatroskaSplitterFilter::SetupChapters(LPCSTR lng, ChapterAtom* parent, int
void CMatroskaSplitterFilter::InstallFonts()
{
POSITION pos = m_pFile->m_segment.Attachments.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
Attachment* pA = m_pFile->m_segment.Attachments.GetNext(pos);
POSITION p2 = pA->AttachedFiles.GetHeadPosition();
- while(p2)
- {
+ while(p2) {
AttachedFile* pF = pA->AttachedFiles.GetNext(p2);
- if(pF->FileMimeType == "application/x-truetype-font")
- {
+ if(pF->FileMimeType == "application/x-truetype-font") {
// assume this is a font resource
- if(BYTE* pData = DNew BYTE[(UINT)pF->FileDataLen])
- {
+ if(BYTE* pData = DNew BYTE[(UINT)pF->FileDataLen]) {
m_pFile->Seek(pF->FileDataPos);
- if(SUCCEEDED(m_pFile->ByteRead(pData, pF->FileDataLen)))
+ if(SUCCEEDED(m_pFile->ByteRead(pData, pF->FileDataLen))) {
m_fontinst.InstallFont(pData, (UINT)pF->FileDataLen);
+ }
delete [] pData;
}
@@ -772,28 +748,28 @@ void CMatroskaSplitterFilter::SendVorbisHeaderSample()
HRESULT hr;
POSITION pos = m_pTrackEntryMap.GetStartPosition();
- while(pos)
- {
+ while(pos) {
DWORD TrackNumber = 0;
TrackEntry* pTE = NULL;
m_pTrackEntryMap.GetNextAssoc(pos, TrackNumber, pTE);
CBaseSplitterOutputPin* pPin = GetOutputPin(TrackNumber);
- if(!(pTE && pPin && pPin->IsConnected()))
+ if(!(pTE && pPin && pPin->IsConnected())) {
continue;
+ }
if(pTE->CodecID.ToString() == "A_VORBIS" && pPin->CurrentMediaType().subtype == MEDIASUBTYPE_Vorbis
- && pTE->CodecPrivate.GetCount() > 0)
- {
+ && pTE->CodecPrivate.GetCount() > 0) {
BYTE* ptr = pTE->CodecPrivate.GetData();
CAtlList<int> sizes;
long last = 0;
- for(BYTE n = *ptr++; n > 0; n--)
- {
+ for(BYTE n = *ptr++; n > 0; n--) {
int size = 0;
- do {size += *ptr;} while(*ptr++ == 0xff);
+ do {
+ size += *ptr;
+ } while(*ptr++ == 0xff);
sizes.AddTail(size);
last += size;
}
@@ -802,23 +778,24 @@ void CMatroskaSplitterFilter::SendVorbisHeaderSample()
hr = S_OK;
POSITION pos = sizes.GetHeadPosition();
- while(pos && SUCCEEDED(hr))
- {
+ while(pos && SUCCEEDED(hr)) {
long len = sizes.GetNext(pos);
CAutoPtr<Packet> p(DNew Packet());
p->TrackNumber = (DWORD)pTE->TrackNumber;
- p->rtStart = 0; p->rtStop = 1;
+ p->rtStart = 0;
+ p->rtStop = 1;
p->bSyncPoint = FALSE;
-
+
p->SetData(ptr, len);
ptr += len;
-
+
hr = DeliverPacket(p);
}
- if(FAILED(hr))
+ if(FAILED(hr)) {
TRACE(_T("ERROR: Vorbis initialization failed for stream %I64d\n"), TrackNumber);
+ }
}
}
}
@@ -829,14 +806,14 @@ bool CMatroskaSplitterFilter::DemuxInit()
CMatroskaNode Root(m_pFile);
if(!m_pFile
- || !(m_pSegment = Root.Child(0x18538067))
- || !(m_pCluster = m_pSegment->Child(0x1F43B675)))
+ || !(m_pSegment = Root.Child(0x18538067))
+ || !(m_pCluster = m_pSegment->Child(0x1F43B675))) {
return(false);
+ }
// reindex if needed
- if(m_pFile->IsRandomAccess() && m_pFile->m_segment.Cues.GetCount() == 0)
- {
+ if(m_pFile->IsRandomAccess() && m_pFile->m_segment.Cues.GetCount() == 0) {
m_nOpenProgress = 0;
m_pFile->m_segment.SegmentInfo.Duration.Set(0);
@@ -844,8 +821,7 @@ bool CMatroskaSplitterFilter::DemuxInit()
CAutoPtr<Cue> pCue(DNew Cue());
- do
- {
+ do {
Cluster c;
c.ParseTimeCode(m_pCluster);
@@ -862,17 +838,20 @@ bool CMatroskaSplitterFilter::DemuxInit()
m_nOpenProgress = m_pFile->GetPos()*100/m_pFile->GetLength();
DWORD cmd;
- if(CheckRequest(&cmd))
- {
- if(cmd == CMD_EXIT) m_fAbort = true;
- else Reply(S_OK);
+ if(CheckRequest(&cmd)) {
+ if(cmd == CMD_EXIT) {
+ m_fAbort = true;
+ } else {
+ Reply(S_OK);
+ }
}
- }
- while(!m_fAbort && m_pCluster->Next(true));
+ } while(!m_fAbort && m_pCluster->Next(true));
m_nOpenProgress = 100;
- if(!m_fAbort) m_pFile->m_segment.Cues.AddTail(pCue);
+ if(!m_fAbort) {
+ m_pFile->m_segment.Cues.AddTail(pCue);
+ }
m_fAbort = false;
}
@@ -888,8 +867,7 @@ void CMatroskaSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
m_pCluster = m_pSegment->Child(0x1F43B675);
m_pBlock.Free();
- if(rt > 0)
- {
+ if(rt > 0) {
rt += m_pFile->m_rtOffset;
MatroskaReader::QWORD lastCueClusterPosition = (MatroskaReader::QWORD)-1;
@@ -899,28 +877,28 @@ void CMatroskaSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
UINT64 TrackNumber = s.GetMasterTrack();
POSITION pos1 = s.Cues.GetHeadPosition();
- while(pos1)
- {
+ while(pos1) {
Cue* pCue = s.Cues.GetNext(pos1);
POSITION pos2 = pCue->CuePoints.GetTailPosition();
- while(pos2)
- {
+ while(pos2) {
CuePoint* pCuePoint = pCue->CuePoints.GetPrev(pos2);
- if(rt < s.GetRefTime(pCuePoint->CueTime))
+ if(rt < s.GetRefTime(pCuePoint->CueTime)) {
continue;
+ }
POSITION pos3 = pCuePoint->CueTrackPositions.GetHeadPosition();
- while(pos3)
- {
+ while(pos3) {
CueTrackPosition* pCueTrackPositions = pCuePoint->CueTrackPositions.GetNext(pos3);
- if(TrackNumber != pCueTrackPositions->CueTrack)
+ if(TrackNumber != pCueTrackPositions->CueTrack) {
continue;
+ }
- if(lastCueClusterPosition == pCueTrackPositions->CueClusterPosition)
+ if(lastCueClusterPosition == pCueTrackPositions->CueClusterPosition) {
continue;
+ }
lastCueClusterPosition = pCueTrackPositions->CueClusterPosition;
@@ -928,68 +906,60 @@ void CMatroskaSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
m_pCluster->Parse();
bool fFoundKeyFrame = false;
-/*
- if(pCueTrackPositions->CueBlockNumber > 0)
- {
- // TODO: CueBlockNumber only tells the block num of the track and not for all mixed in the cluster
- m_nLastBlock = (int)pCueTrackPositions->CueBlockNumber;
- fFoundKeyFrame = true;
- }
- else
-*/
+ /*
+ if(pCueTrackPositions->CueBlockNumber > 0)
+ {
+ // TODO: CueBlockNumber only tells the block num of the track and not for all mixed in the cluster
+ m_nLastBlock = (int)pCueTrackPositions->CueBlockNumber;
+ fFoundKeyFrame = true;
+ }
+ else
+ */
{
Cluster c;
c.ParseTimeCode(m_pCluster);
- if(CAutoPtr<CMatroskaNode> pBlock = m_pCluster->GetFirstBlock())
- {
+ if(CAutoPtr<CMatroskaNode> pBlock = m_pCluster->GetFirstBlock()) {
bool fPassedCueTime = false;
- do
- {
+ do {
CBlockGroupNode bgn;
- if(pBlock->m_id == 0xA0)
- {
+ if(pBlock->m_id == 0xA0) {
bgn.Parse(pBlock, true);
- }
- else if(pBlock->m_id == 0xA3)
- {
+ } else if(pBlock->m_id == 0xA3) {
CAutoPtr<BlockGroup> bg(DNew BlockGroup());
bg->Block.Parse(pBlock, true);
- if(!(bg->Block.Lacing & 0x80)) bg->ReferenceBlock.Set(0); // not a kf
+ if(!(bg->Block.Lacing & 0x80)) {
+ bg->ReferenceBlock.Set(0); // not a kf
+ }
bgn.AddTail(bg);
}
POSITION pos4 = bgn.GetHeadPosition();
- while(!fPassedCueTime && pos4)
- {
+ while(!fPassedCueTime && pos4) {
BlockGroup* bg = bgn.GetNext(pos4);
if(bg->Block.TrackNumber == pCueTrackPositions->CueTrack && rt < s.GetRefTime(c.TimeCode + bg->Block.TimeCode)
- || rt + 5000000i64 < s.GetRefTime(c.TimeCode + bg->Block.TimeCode)) // allow 500ms difference between tracks, just in case intreleaving wasn't that much precise
- {
+ || rt + 5000000i64 < s.GetRefTime(c.TimeCode + bg->Block.TimeCode)) { // allow 500ms difference between tracks, just in case intreleaving wasn't that much precise
fPassedCueTime = true;
- }
- else if(bg->Block.TrackNumber == pCueTrackPositions->CueTrack && !bg->ReferenceBlock.IsValid())
- {
+ } else if(bg->Block.TrackNumber == pCueTrackPositions->CueTrack && !bg->ReferenceBlock.IsValid()) {
fFoundKeyFrame = true;
m_pBlock = pBlock->Copy();
}
}
- }
- while(!fPassedCueTime && pBlock->NextBlock());
+ } while(!fPassedCueTime && pBlock->NextBlock());
}
}
- if(fFoundKeyFrame)
+ if(fFoundKeyFrame) {
pos1 = pos2 = pos3 = NULL;
+ }
}
}
}
- if(!m_pBlock)
- {
+ if(!m_pBlock) {
m_pCluster = m_pSegment->Child(0x1F43B675);
}
}
@@ -998,35 +968,35 @@ void CMatroskaSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
bool CMatroskaSplitterFilter::DemuxLoop()
{
HRESULT hr = S_OK;
-
+
SendVorbisHeaderSample(); // HACK: init vorbis decoder with the headers
- do
- {
+ do {
Cluster c;
c.ParseTimeCode(m_pCluster);
- if(!m_pBlock) m_pBlock = m_pCluster->GetFirstBlock();
- if(!m_pBlock) continue;
+ if(!m_pBlock) {
+ m_pBlock = m_pCluster->GetFirstBlock();
+ }
+ if(!m_pBlock) {
+ continue;
+ }
- do
- {
+ do {
CBlockGroupNode bgn;
- if(m_pBlock->m_id == 0xA0)
- {
+ if(m_pBlock->m_id == 0xA0) {
bgn.Parse(m_pBlock, true);
- }
- else if(m_pBlock->m_id == 0xA3)
- {
+ } else if(m_pBlock->m_id == 0xA3) {
CAutoPtr<BlockGroup> bg(DNew BlockGroup());
bg->Block.Parse(m_pBlock, true);
- if(!(bg->Block.Lacing & 0x80)) bg->ReferenceBlock.Set(0); // not a kf
+ if(!(bg->Block.Lacing & 0x80)) {
+ bg->ReferenceBlock.Set(0); // not a kf
+ }
bgn.AddTail(bg);
}
- while(bgn.GetCount() && SUCCEEDED(hr))
- {
+ while(bgn.GetCount() && SUCCEEDED(hr)) {
CAutoPtr<MatroskaPacket> p(DNew MatroskaPacket());
p->bg = bgn.RemoveHead();
@@ -1034,22 +1004,22 @@ bool CMatroskaSplitterFilter::DemuxLoop()
p->TrackNumber = (DWORD)p->bg->Block.TrackNumber;
TrackEntry* pTE = NULL;
-
- if (!m_pTrackEntryMap.Lookup (p->TrackNumber, pTE) || !pTE) continue;
+
+ if (!m_pTrackEntryMap.Lookup (p->TrackNumber, pTE) || !pTE) {
+ continue;
+ }
p->rtStart = m_pFile->m_segment.GetRefTime((REFERENCE_TIME)c.TimeCode + p->bg->Block.TimeCode);
p->rtStop = p->rtStart + (p->bg->BlockDuration.IsValid() ? m_pFile->m_segment.GetRefTime(p->bg->BlockDuration) : 1);
// Fix subtitle with duration = 0
- if(pTE->TrackType == TrackEntry::TypeSubtitle && !p->bg->BlockDuration.IsValid())
- {
+ if(pTE->TrackType == TrackEntry::TypeSubtitle && !p->bg->BlockDuration.IsValid()) {
p->bg->BlockDuration.Set(1); // just setting it to be valid
p->rtStop = p->rtStart;
}
POSITION pos = p->bg->Block.BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* pb = p->bg->Block.BlockData.GetNext(pos);
pTE->Expand(*pb, ContentEncoding::AllFrameContents);
}
@@ -1060,13 +1030,11 @@ bool CMatroskaSplitterFilter::DemuxLoop()
hr = DeliverPacket(p);
}
- }
- while(m_pBlock->NextBlock() && SUCCEEDED(hr) && !CheckRequest(NULL));
+ } while(m_pBlock->NextBlock() && SUCCEEDED(hr) && !CheckRequest(NULL));
m_pBlock.Free();
- }
- while(m_pFile->GetPos() < m_pFile->m_segment.pos + m_pFile->m_segment.len
- && m_pCluster->Next(true) && SUCCEEDED(hr) && !CheckRequest(NULL));
+ } while(m_pFile->GetPos() < m_pFile->m_segment.pos + m_pFile->m_segment.len
+ && m_pCluster->Next(true) && SUCCEEDED(hr) && !CheckRequest(NULL));
m_pCluster.Free();
@@ -1077,14 +1045,18 @@ bool CMatroskaSplitterFilter::DemuxLoop()
STDMETHODIMP CMatroskaSplitterFilter::GetKeyFrameCount(UINT& nKFs)
{
- if(!m_pFile) return E_UNEXPECTED;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
HRESULT hr = S_OK;
nKFs = 0;
POSITION pos = m_pFile->m_segment.Cues.GetHeadPosition();
- while(pos) nKFs += m_pFile->m_segment.Cues.GetNext(pos)->CuePoints.GetCount();
+ while(pos) {
+ nKFs += m_pFile->m_segment.Cues.GetNext(pos)->CuePoints.GetCount();
+ }
return hr;
}
@@ -1094,19 +1066,23 @@ STDMETHODIMP CMatroskaSplitterFilter::GetKeyFrames(const GUID* pFormat, REFERENC
CheckPointer(pFormat, E_POINTER);
CheckPointer(pKFs, E_POINTER);
- if(!m_pFile) return E_UNEXPECTED;
- if(*pFormat != TIME_FORMAT_MEDIA_TIME) return E_INVALIDARG;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
+ if(*pFormat != TIME_FORMAT_MEDIA_TIME) {
+ return E_INVALIDARG;
+ }
UINT nKFsTmp = 0;
POSITION pos1 = m_pFile->m_segment.Cues.GetHeadPosition();
- while(pos1 && nKFsTmp < nKFs)
- {
+ while(pos1 && nKFsTmp < nKFs) {
Cue* pCue = m_pFile->m_segment.Cues.GetNext(pos1);
POSITION pos2 = pCue->CuePoints.GetHeadPosition();
- while(pos2 && nKFsTmp < nKFs)
+ while(pos2 && nKFsTmp < nKFs) {
pKFs[nKFsTmp++] = m_pFile->m_segment.GetRefTime(pCue->CuePoints.GetNext(pos2)->CueTime);
+ }
}
nKFs = nKFsTmp;
@@ -1130,8 +1106,8 @@ CMatroskaSourceFilter::CMatroskaSourceFilter(LPUNKNOWN pUnk, HRESULT* phr)
//
CMatroskaSplitterOutputPin::CMatroskaSplitterOutputPin(
- int nMinCache, REFERENCE_TIME rtDefaultDuration,
- CAtlArray<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr)
+ int nMinCache, REFERENCE_TIME rtDefaultDuration,
+ CAtlArray<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr)
: CBaseSplitterOutputPin(mts, pName, pFilter, pLock, phr)
, m_nMinCache(nMinCache), m_rtDefaultDuration(rtDefaultDuration)
{
@@ -1160,22 +1136,23 @@ HRESULT CMatroskaSplitterOutputPin::DeliverEndOfStream()
// send out the last remaining packets from the queue
- while(m_rob.GetCount())
- {
+ while(m_rob.GetCount()) {
MatroskaPacket* mp = m_rob.RemoveHead();
- if(m_rob.GetCount() && !mp->bg->BlockDuration.IsValid())
+ if(m_rob.GetCount() && !mp->bg->BlockDuration.IsValid()) {
mp->rtStop = m_rob.GetHead()->rtStart;
- else if(m_rob.GetCount() == 0 && m_rtDefaultDuration > 0)
+ } else if(m_rob.GetCount() == 0 && m_rtDefaultDuration > 0) {
mp->rtStop = mp->rtStart + m_rtDefaultDuration;
+ }
timeoverride to = {mp->rtStart, mp->rtStop};
m_tos.AddTail(to);
}
- while(m_packets.GetCount())
- {
+ while(m_packets.GetCount()) {
HRESULT hr = DeliverBlock(m_packets.RemoveHead());
- if(hr != S_OK) return hr;
+ if(hr != S_OK) {
+ return hr;
+ }
}
return __super::DeliverEndOfStream();
@@ -1184,7 +1161,9 @@ HRESULT CMatroskaSplitterOutputPin::DeliverEndOfStream()
HRESULT CMatroskaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
{
MatroskaPacket* mp = dynamic_cast<MatroskaPacket*>(p.m_p);
- if(!mp) return __super::DeliverPacket(p);
+ if(!mp) {
+ return __super::DeliverPacket(p);
+ }
// don't try to understand what's happening here, it's magic
@@ -1196,50 +1175,52 @@ HRESULT CMatroskaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
m_packets.AddTail(p2);
POSITION pos = m_rob.GetTailPosition();
- for(int i = m_nMinCache-1; i > 0 && pos && mp->bg->ReferencePriority < m_rob.GetAt(pos)->bg->ReferencePriority; i--)
+ for(int i = m_nMinCache-1; i > 0 && pos && mp->bg->ReferencePriority < m_rob.GetAt(pos)->bg->ReferencePriority; i--) {
m_rob.GetPrev(pos);
+ }
- if(!pos) m_rob.AddHead(mp);
- else m_rob.InsertAfter(pos, mp);
+ if(!pos) {
+ m_rob.AddHead(mp);
+ } else {
+ m_rob.InsertAfter(pos, mp);
+ }
mp = NULL;
- if(m_rob.GetCount() == m_nMinCache+1)
- {
+ if(m_rob.GetCount() == m_nMinCache+1) {
ASSERT(m_nMinCache > 0);
pos = m_rob.GetHeadPosition();
MatroskaPacket* mp1 = m_rob.GetNext(pos);
MatroskaPacket* mp2 = m_rob.GetNext(pos);
- if(!mp1->bg->BlockDuration.IsValid())
- {
+ if(!mp1->bg->BlockDuration.IsValid()) {
mp1->bg->BlockDuration.Set(1); // just to set it valid
- if(mp1->rtStart >= mp2->rtStart)
- {
-/* CString str;
- str.Format(_T("mp1->rtStart (%I64d) >= mp2->rtStart (%I64d)!!!\n"), mp1->rtStart, mp2->rtStart);
- AfxMessageBox(str);
-*/
+ if(mp1->rtStart >= mp2->rtStart) {
+ /* CString str;
+ str.Format(_T("mp1->rtStart (%I64d) >= mp2->rtStart (%I64d)!!!\n"), mp1->rtStart, mp2->rtStart);
+ AfxMessageBox(str);
+ */
// TRACE(_T("mp1->rtStart (%I64d) >= mp2->rtStart (%I64d)!!!\n"), mp1->rtStart, mp2->rtStart);
- }
- else
- {
+ } else {
mp1->rtStop = mp2->rtStart;
}
}
}
- while(m_packets.GetCount())
- {
+ while(m_packets.GetCount()) {
mp = m_packets.GetHead();
- if(!mp->bg->BlockDuration.IsValid()) break;
-
+ if(!mp->bg->BlockDuration.IsValid()) {
+ break;
+ }
+
mp = m_rob.RemoveHead();
timeoverride to = {mp->rtStart, mp->rtStop};
m_tos.AddTail(to);
HRESULT hr = DeliverBlock(m_packets.RemoveHead());
- if(hr != S_OK) return hr;
+ if(hr != S_OK) {
+ return hr;
+ }
}
return S_OK;
@@ -1249,26 +1230,24 @@ HRESULT CMatroskaSplitterOutputPin::DeliverBlock(MatroskaPacket* p)
{
HRESULT hr = S_FALSE;
- if(m_tos.GetCount())
- {
+ if(m_tos.GetCount()) {
timeoverride to = m_tos.RemoveHead();
-// if(p->TrackNumber == 2)
- TRACE(_T("(track=%d) %I64d, %I64d -> %I64d, %I64d (buffcnt=%d)\n"),
- p->TrackNumber, p->rtStart, p->rtStop, to.rtStart, to.rtStop,
- QueueCount());
-/**/
+ // if(p->TrackNumber == 2)
+ TRACE(_T("(track=%d) %I64d, %I64d -> %I64d, %I64d (buffcnt=%d)\n"),
+ p->TrackNumber, p->rtStart, p->rtStop, to.rtStart, to.rtStop,
+ QueueCount());
+ /**/
p->rtStart = to.rtStart;
p->rtStop = to.rtStop;
}
-
- REFERENCE_TIME
- rtStart = p->rtStart,
- rtDelta = (p->rtStop - p->rtStart) / p->bg->Block.BlockData.GetCount(),
- rtStop = p->rtStart + rtDelta;
+
+ REFERENCE_TIME
+ rtStart = p->rtStart,
+ rtDelta = (p->rtStop - p->rtStart) / p->bg->Block.BlockData.GetCount(),
+ rtStop = p->rtStart + rtDelta;
POSITION pos = p->bg->Block.BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CAutoPtr<Packet> tmp(DNew Packet());
tmp->TrackNumber = p->TrackNumber;
tmp->bDiscontinuity = p->bDiscontinuity;
@@ -1276,7 +1255,9 @@ HRESULT CMatroskaSplitterOutputPin::DeliverBlock(MatroskaPacket* p)
tmp->rtStart = rtStart;
tmp->rtStop = rtStop;
tmp->Copy(*p->bg->Block.BlockData.GetNext(pos));
- if(S_OK != (hr = DeliverPacket(tmp))) break;
+ if(S_OK != (hr = DeliverPacket(tmp))) {
+ break;
+ }
rtStart += rtDelta;
rtStop += rtDelta;
@@ -1285,11 +1266,9 @@ HRESULT CMatroskaSplitterOutputPin::DeliverBlock(MatroskaPacket* p)
p->bDiscontinuity = false;
}
- if(m_mt.subtype == FOURCCMap(WAVE_FORMAT_WAVPACK4))
- {
+ if(m_mt.subtype == FOURCCMap(WAVE_FORMAT_WAVPACK4)) {
POSITION pos = p->bg->ba.bm.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
const BlockMore* bm = p->bg->ba.bm.GetNext(pos);
CAutoPtr<Packet> tmp(DNew Packet());
tmp->TrackNumber = p->TrackNumber;
@@ -1298,7 +1277,9 @@ HRESULT CMatroskaSplitterOutputPin::DeliverBlock(MatroskaPacket* p)
tmp->rtStart = p->rtStart;
tmp->rtStop = p->rtStop;
tmp->Copy(bm->BlockAdditional);
- if(S_OK != (hr = DeliverPacket(tmp))) break;
+ if(S_OK != (hr = DeliverPacket(tmp))) {
+ break;
+ }
}
}
@@ -1309,28 +1290,31 @@ HRESULT CMatroskaSplitterOutputPin::DeliverBlock(MatroskaPacket* p)
TrackEntry* CMatroskaSplitterFilter::GetTrackEntryAt(UINT aTrackIdx)
{
- if(aTrackIdx < 0 || aTrackIdx >= m_pOrderedTrackArray.GetCount())
- return NULL;
+ if(aTrackIdx < 0 || aTrackIdx >= m_pOrderedTrackArray.GetCount()) {
+ return NULL;
+ }
return m_pOrderedTrackArray[aTrackIdx];
}
STDMETHODIMP_(UINT) CMatroskaSplitterFilter::GetTrackCount()
-{
+{
return m_pTrackEntryMap.GetCount();
}
STDMETHODIMP_(BOOL) CMatroskaSplitterFilter::GetTrackInfo(UINT aTrackIdx, struct TrackElement* pStructureToFill)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return FALSE;
+ }
pStructureToFill->FlagDefault = !!pTE->FlagDefault;
pStructureToFill->FlagForced = !!pTE->FlagForced;
pStructureToFill->FlagLacing = !!pTE->FlagLacing;
strncpy(pStructureToFill->Language, pTE->Language, 3);
- if(pStructureToFill->Language[0] == '\0')
+ if(pStructureToFill->Language[0] == '\0') {
strncpy(pStructureToFill->Language, "eng", 3);
+ }
pStructureToFill->Language[3] = '\0';
pStructureToFill->MaxCache = (UINT)pTE->MaxCache;
pStructureToFill->MinCache = (UINT)pTE->MinCache;
@@ -1341,15 +1325,15 @@ STDMETHODIMP_(BOOL) CMatroskaSplitterFilter::GetTrackInfo(UINT aTrackIdx, struct
STDMETHODIMP_(BOOL) CMatroskaSplitterFilter::GetTrackExtendedInfo(UINT aTrackIdx, void* pStructureToFill)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return FALSE;
+ }
- if(pTE->TrackType == TrackEntry::TypeVideo)
- {
+ if(pTE->TrackType == TrackEntry::TypeVideo) {
TrackExtendedInfoVideo* pTEIV = (TrackExtendedInfoVideo*)pStructureToFill;
- pTEIV->AspectRatioType = (BYTE)pTE->v.AspectRatioType;
+ pTEIV->AspectRatioType = (BYTE)pTE->v.AspectRatioType;
pTEIV->DisplayUnit = (BYTE)pTE->v.DisplayUnit;
- pTEIV->DisplayWidth = (UINT)pTE->v.DisplayWidth;
+ pTEIV->DisplayWidth = (UINT)pTE->v.DisplayWidth;
pTEIV->DisplayHeight = (UINT)pTE->v.DisplayHeight;
pTEIV->Interlaced = !!pTE->v.FlagInterlaced;
pTEIV->PixelWidth = (UINT)pTE->v.PixelWidth;
@@ -1363,46 +1347,51 @@ STDMETHODIMP_(BOOL) CMatroskaSplitterFilter::GetTrackExtendedInfo(UINT aTrackIdx
} else {
return FALSE;
}
-
+
return TRUE;
}
STDMETHODIMP_(BSTR) CMatroskaSplitterFilter::GetTrackName(UINT aTrackIdx)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return NULL;
+ }
return pTE->Name.AllocSysString();
}
STDMETHODIMP_(BSTR) CMatroskaSplitterFilter::GetTrackCodecID(UINT aTrackIdx)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return NULL;
+ }
return pTE->CodecID.ToString().AllocSysString();
}
STDMETHODIMP_(BSTR) CMatroskaSplitterFilter::GetTrackCodecName(UINT aTrackIdx)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return NULL;
+ }
return pTE->CodecName.AllocSysString();
}
STDMETHODIMP_(BSTR) CMatroskaSplitterFilter::GetTrackCodecInfoURL(UINT aTrackIdx)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return NULL;
+ }
return pTE->CodecInfoURL.AllocSysString();
}
STDMETHODIMP_(BSTR) CMatroskaSplitterFilter::GetTrackCodecDownloadURL(UINT aTrackIdx)
{
TrackEntry* pTE = GetTrackEntryAt(aTrackIdx);
- if(pTE == NULL)
+ if(pTE == NULL) {
return NULL;
+ }
return pTE->CodecDownloadURL.AllocSysString();
}
diff --git a/src/filters/parser/MatroskaSplitter/MatroskaSplitter.h b/src/filters/parser/MatroskaSplitter/MatroskaSplitter.h
index ae47a7d83..a81b6d45a 100644
--- a/src/filters/parser/MatroskaSplitter/MatroskaSplitter.h
+++ b/src/filters/parser/MatroskaSplitter/MatroskaSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -30,11 +30,12 @@
class MatroskaPacket : public Packet
{
protected:
- int GetDataSize()
- {
+ int GetDataSize() {
int size = 0;
POSITION pos = bg->Block.BlockData.GetHeadPosition();
- while(pos) {size += bg->Block.BlockData.GetNext(pos)->GetCount();}
+ while(pos) {
+ size += bg->Block.BlockData.GetNext(pos)->GetCount();
+ }
return size;
}
public:
@@ -52,7 +53,9 @@ class CMatroskaSplitterOutputPin : public CBaseSplitterOutputPin
CAutoPtrList<MatroskaPacket> m_packets;
CAtlList<MatroskaPacket*> m_rob;
- typedef struct {REFERENCE_TIME rtStart, rtStop;} timeoverride;
+ typedef struct {
+ REFERENCE_TIME rtStart, rtStop;
+ } timeoverride;
CAtlList<timeoverride> m_tos;
protected:
@@ -60,7 +63,7 @@ protected:
public:
CMatroskaSplitterOutputPin(
- int nMinCache, REFERENCE_TIME rtDefaultDuration,
+ int nMinCache, REFERENCE_TIME rtDefaultDuration,
CAtlArray<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
virtual ~CMatroskaSplitterOutputPin();
@@ -69,7 +72,7 @@ public:
};
class __declspec(uuid("149D2E01-C32E-4939-80F6-C07B81015A7A"))
-CMatroskaSplitterFilter : public CBaseSplitterFilter, public ITrackInfo
+ CMatroskaSplitterFilter : public CBaseSplitterFilter, public ITrackInfo
{
void SetupChapters(LPCSTR lng, MatroskaReader::ChapterAtom* parent, int level = 0);
void InstallFonts();
@@ -83,7 +86,7 @@ protected:
CAtlMap<DWORD, MatroskaReader::TrackEntry*> m_pTrackEntryMap;
CAtlArray<MatroskaReader::TrackEntry* > m_pOrderedTrackArray;
- MatroskaReader::TrackEntry* GetTrackEntryAt(UINT aTrackIdx);
+ MatroskaReader::TrackEntry* GetTrackEntryAt(UINT aTrackIdx);
bool DemuxInit();
void DemuxSeek(REFERENCE_TIME rt);
@@ -94,7 +97,7 @@ public:
virtual ~CMatroskaSplitterFilter();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IKeyFrameInfo
@@ -104,7 +107,7 @@ public:
// ITrackInfo
STDMETHODIMP_(UINT) GetTrackCount();
- STDMETHODIMP_(BOOL) GetTrackInfo(UINT aTrackIdx, struct TrackElement* pStructureToFill);
+ STDMETHODIMP_(BOOL) GetTrackInfo(UINT aTrackIdx, struct TrackElement* pStructureToFill);
STDMETHODIMP_(BOOL) GetTrackExtendedInfo(UINT aTrackIdx, void* pStructureToFill);
STDMETHODIMP_(BSTR) GetTrackName(UINT aTrackIdx);
STDMETHODIMP_(BSTR) GetTrackCodecID(UINT aTrackIdx);
@@ -114,7 +117,7 @@ public:
};
class __declspec(uuid("0A68C3B5-9164-4a54-AFAF-995B2FF0E0D4"))
-CMatroskaSourceFilter : public CMatroskaSplitterFilter
+ CMatroskaSourceFilter : public CMatroskaSplitterFilter
{
public:
CMatroskaSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/MatroskaSplitter/stdafx.cpp b/src/filters/parser/MatroskaSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/MatroskaSplitter/stdafx.cpp
+++ b/src/filters/parser/MatroskaSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MatroskaSplitter/stdafx.h b/src/filters/parser/MatroskaSplitter/stdafx.h
index 7e2652f5d..37bcea3a7 100644
--- a/src/filters/parser/MatroskaSplitter/stdafx.h
+++ b/src/filters/parser/MatroskaSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MpaSplitter/MpaSplitter.cpp b/src/filters/parser/MpaSplitter/MpaSplitter.cpp
index fef3f7d1a..11f7322c9 100644
--- a/src/filters/parser/MpaSplitter/MpaSplitter.cpp
+++ b/src/filters/parser/MpaSplitter/MpaSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,26 +27,22 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1Audio},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMpaSplitterFilter), L"MPC - Mpa Splitter", MERIT_NORMAL+1, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CMpaSourceFilter), L"MPC - Mpa Source", MERIT_NORMAL+1, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMpaSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CMpaSourceFilter>, NULL, &sudFilter[1]},
};
@@ -85,9 +81,9 @@ CMpaSplitterFilter::CMpaSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr)
STDMETHODIMP CMpaSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
__super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -100,8 +96,13 @@ HRESULT CMpaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CMpaSplitterFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
CAtlArray<CMediaType> mts;
mts.Add(m_pFile->GetMediaType());
@@ -113,12 +114,24 @@ HRESULT CMpaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->GetDuration();
CStringW str, title;
- if(m_pFile->m_tags.Lookup('TIT2', str)) title = str;
- if(m_pFile->m_tags.Lookup('TYER', str) && !title.IsEmpty() && !str.IsEmpty()) title += L" (" + str + L")";
- if(!title.IsEmpty()) SetProperty(L"TITL", title);
- if(m_pFile->m_tags.Lookup('TPE1', str)) SetProperty(L"AUTH", str);
- if(m_pFile->m_tags.Lookup('TCOP', str)) SetProperty(L"CPYR", str);
- if(m_pFile->m_tags.Lookup('COMM', str)) SetProperty(L"DESC", str);
+ if(m_pFile->m_tags.Lookup('TIT2', str)) {
+ title = str;
+ }
+ if(m_pFile->m_tags.Lookup('TYER', str) && !title.IsEmpty() && !str.IsEmpty()) {
+ title += L" (" + str + L")";
+ }
+ if(!title.IsEmpty()) {
+ SetProperty(L"TITL", title);
+ }
+ if(m_pFile->m_tags.Lookup('TPE1', str)) {
+ SetProperty(L"AUTH", str);
+ }
+ if(m_pFile->m_tags.Lookup('TCOP', str)) {
+ SetProperty(L"CPYR", str);
+ }
+ if(m_pFile->m_tags.Lookup('COMM', str)) {
+ SetProperty(L"DESC", str);
+ }
return m_pOutputs.GetCount() > 0 ? S_OK : E_FAIL;
}
@@ -136,7 +149,9 @@ STDMETHODIMP CMpaSplitterFilter::GetDuration(LONGLONG* pDuration)
bool CMpaSplitterFilter::DemuxInit()
{
SetThreadName((DWORD)-1, "CMpaSplitterFilter");
- if(!m_pFile) return(false);
+ if(!m_pFile) {
+ return(false);
+ }
// TODO
@@ -148,13 +163,10 @@ void CMpaSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
__int64 startpos = m_pFile->GetStartPos();
__int64 endpos = m_pFile->GetEndPos();
- if(rt <= 0 || m_pFile->GetDuration() <= 0)
- {
+ if(rt <= 0 || m_pFile->GetDuration() <= 0) {
m_pFile->Seek(startpos);
m_rtStart = 0;
- }
- else
- {
+ } else {
m_pFile->Seek(startpos + (__int64)((1.0 * rt / m_pFile->GetDuration()) * (endpos - startpos)));
m_rtStart = rt;
}
@@ -168,9 +180,11 @@ bool CMpaSplitterFilter::DemuxLoop()
int FrameSize;
REFERENCE_TIME rtDuration;
- while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetPos() < m_pFile->GetEndPos() - 9)
- {
- if(!m_pFile->Sync(FrameSize, rtDuration)) {Sleep(1); continue;}
+ while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->GetPos() < m_pFile->GetEndPos() - 9) {
+ if(!m_pFile->Sync(FrameSize, rtDuration)) {
+ Sleep(1);
+ continue;
+ }
CAutoPtr<Packet> p(DNew Packet());
p->SetCount(FrameSize);
diff --git a/src/filters/parser/MpaSplitter/MpaSplitter.h b/src/filters/parser/MpaSplitter/MpaSplitter.h
index cae3c8b9a..064a91d36 100644
--- a/src/filters/parser/MpaSplitter/MpaSplitter.h
+++ b/src/filters/parser/MpaSplitter/MpaSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,7 +25,7 @@
#include "MpaSplitterFile.h"
class __declspec(uuid("0E9D4BF7-CBCB-46C7-BD80-4EF223A3DC2B"))
-CMpaSplitterFilter : public CBaseSplitterFilter
+ CMpaSplitterFilter : public CBaseSplitterFilter
{
REFERENCE_TIME m_rtStart;
@@ -43,11 +43,11 @@ public:
CMpaSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr);
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
};
class __declspec(uuid("59A0DB73-0287-4C9A-9D3C-8CFF39F8E5DB"))
-CMpaSourceFilter : public CMpaSplitterFilter
+ CMpaSourceFilter : public CMpaSplitterFilter
{
public:
CMpaSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp b/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp
index fc5f8399c..d26b70bb7 100644
--- a/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp
+++ b/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,43 +28,42 @@
//
-static const LPCTSTR s_genre[] =
-{
+static const LPCTSTR s_genre[] = {
_T("Blues"), _T("Classic Rock"), _T("Country"), _T("Dance"),
_T("Disco"), _T("Funk"), _T("Grunge"), _T("Hip-Hop"),
- _T("Jazz"), _T("Metal"), _T("New Age"), _T("Oldies"),
+ _T("Jazz"), _T("Metal"), _T("New Age"), _T("Oldies"),
_T("Other"), _T("Pop"), _T("R&B"), _T("Rap"),
- _T("Reggae"), _T("Rock"), _T("Techno"), _T("Industrial"),
+ _T("Reggae"), _T("Rock"), _T("Techno"), _T("Industrial"),
_T("Alternative"), _T("Ska"), _T("Death Metal"), _T("Pranks"),
_T("Soundtrack"), _T("Euro-Techno"), _T("Ambient"), _T("Trip-Hop"),
_T("Vocal"), _T("Jazz+Funk"), _T("Fusion"), _T("Trance"),
- _T("Classical"), _T("Instrumental"), _T("Acid"), _T("House"),
+ _T("Classical"), _T("Instrumental"), _T("Acid"), _T("House"),
_T("Game"), _T("Sound Clip"), _T("Gospel"), _T("Noise"),
- _T("Alternative Rock"), _T("Bass"), _T("Soul"), _T("Punk"),
+ _T("Alternative Rock"), _T("Bass"), _T("Soul"), _T("Punk"),
_T("Space"), _T("Meditative"), _T("Instrumental Pop"), _T("Instrumental Rock"),
_T("Ethnic"), _T("Gothic"), _T("Darkwave"), _T("Techno-Industrial"),
_T("Electronic"), _T("Pop-Folk"), _T("Eurodance"), _T("Dream"),
_T("Southern Rock"), _T("Comedy"), _T("Cult"), _T("Gangsta"),
_T("Top 40"), _T("Christian Rap"), _T("Pop/Funk"), _T("Jungle"),
- _T("Native US"), _T("Cabaret"), _T("New Wave"), _T("Psychadelic"),
+ _T("Native US"), _T("Cabaret"), _T("New Wave"), _T("Psychadelic"),
_T("Rave"), _T("Showtunes"), _T("Trailer"), _T("Lo-Fi"),
_T("Tribal"), _T("Acid Punk"), _T("Acid Jazz"), _T("Polka"),
_T("Retro"), _T("Musical"), _T("Rock & Roll"), _T("Hard Rock"),
_T("Folk"), _T("Folk-Rock"), _T("National Folk"), _T("Swing"),
_T("Fast Fusion"), _T("Bebob"), _T("Latin"), _T("Revival"),
- _T("Celtic"), _T("Bluegrass"), _T("Avantgarde"), _T("Gothic Rock"),
+ _T("Celtic"), _T("Bluegrass"), _T("Avantgarde"), _T("Gothic Rock"),
_T("Progressive Rock"), _T("Psychedelic Rock"), _T("Symphonic Rock"), _T("Slow Rock"),
_T("Big Band"), _T("Chorus"), _T("Easy Listening"), _T("Acoustic"),
- _T("Humour"), _T("Speech"), _T("Chanson"), _T("Opera"),
- _T("Chamber Music"), _T("Sonata"), _T("Symphony"), _T("Booty Bass"),
+ _T("Humour"), _T("Speech"), _T("Chanson"), _T("Opera"),
+ _T("Chamber Music"), _T("Sonata"), _T("Symphony"), _T("Booty Bass"),
_T("Primus"), _T("Porn Groove"), _T("Satire"), _T("Slow Jam"),
- _T("Club"), _T("Tango"), _T("Samba"), _T("Folklore"),
+ _T("Club"), _T("Tango"), _T("Samba"), _T("Folklore"),
_T("Ballad"), _T("Power Ballad"), _T("Rhytmic Soul"), _T("Freestyle"),
- _T("Duet"), _T("Punk Rock"), _T("Drum Solo"), _T("Acapella"),
+ _T("Duet"), _T("Punk Rock"), _T("Drum Solo"), _T("Acapella"),
_T("Euro-House"), _T("Dance Hall"), _T("Goa"), _T("Drum & Bass"),
_T("Club-House"), _T("Hardcore"), _T("Terror"), _T("Indie"),
_T("BritPop"), _T("Negerpunk"), _T("Polsk Punk"), _T("Beat"),
- _T("Christian Gangsta"), _T("Heavy Metal"), _T("Black Metal"),
+ _T("Christian Gangsta"), _T("Heavy Metal"), _T("Black Metal"),
_T("Crossover"), _T("Contemporary C"), _T("Christian Rock"), _T("Merengue"), _T("Salsa"),
_T("Thrash Metal"), _T("Anime"), _T("JPop"), _T("SynthPop"),
};
@@ -79,7 +78,9 @@ CMpaSplitterFile::CMpaSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr)
, m_endpos(0)
, m_totalbps(0)
{
- if(SUCCEEDED(hr)) hr = Init();
+ if(SUCCEEDED(hr)) {
+ hr = Init();
+ }
}
HRESULT CMpaSplitterFile::Init()
@@ -89,19 +90,18 @@ HRESULT CMpaSplitterFile::Init()
Seek(0);
- if(BitRead(24, true) == 0x000001)
+ if(BitRead(24, true) == 0x000001) {
return E_FAIL;
+ }
- if(m_endpos > 128 && IsRandomAccess())
- {
+ if(m_endpos > 128 && IsRandomAccess()) {
Seek(m_endpos - 128);
- if(BitRead(24) == 'TAG')
- {
+ if(BitRead(24) == 'TAG') {
m_endpos -= 128;
CStringA str;
-
+
// title
ByteRead((BYTE*)str.GetBufferSetLength(30), 30);
m_tags['TIT2'] = CStringW(str).Trim();
@@ -120,17 +120,19 @@ HRESULT CMpaSplitterFile::Init()
// comment
ByteRead((BYTE*)str.GetBufferSetLength(30), 30);
- m_tags['COMM'] = CStringW(str).Trim();
+ m_tags['COMM'] = CStringW(str).Trim();
// track
LPCSTR s = str;
- if(s[28] == 0 && s[29] != 0)
- m_tags['TRCK'].Format(L"%d", s[29]);
+ if(s[28] == 0 && s[29] != 0) {
+ m_tags['TRCK'].Format(L"%d", s[29]);
+ }
// genre
BYTE genre = (BYTE)BitRead(8);
- if(genre < countof(s_genre))
+ if(genre < countof(s_genre)) {
m_tags['TCON'] = CStringW(s_genre[genre]);
+ }
}
}
@@ -138,8 +140,7 @@ HRESULT CMpaSplitterFile::Init()
bool MP3_find = false;
- while(BitRead(24, true) == 'ID3')
- {
+ while(BitRead(24, true) == 'ID3') {
MP3_find = true;
BitRead(24);
@@ -151,25 +152,31 @@ HRESULT CMpaSplitterFile::Init()
BYTE flags = (BYTE)BitRead(8);
UNUSED_ALWAYS(flags);
DWORD size = 0;
- if(BitRead(1) != 0) return E_FAIL;
+ if(BitRead(1) != 0) {
+ return E_FAIL;
+ }
size |= BitRead(7) << 21;
- if(BitRead(1) != 0) return E_FAIL;
+ if(BitRead(1) != 0) {
+ return E_FAIL;
+ }
size |= BitRead(7) << 14;
- if(BitRead(1) != 0) return E_FAIL;
+ if(BitRead(1) != 0) {
+ return E_FAIL;
+ }
size |= BitRead(7) << 7;
- if(BitRead(1) != 0) return E_FAIL;
+ if(BitRead(1) != 0) {
+ return E_FAIL;
+ }
size |= BitRead(7);
m_startpos = GetPos() + size;
// TODO: read extended header
- if(major <= 4)
- {
+ if(major <= 4) {
__int64 pos = GetPos();
- while(pos < m_startpos)
- {
+ while(pos < m_startpos) {
Seek(pos);
DWORD tag = (DWORD)BitRead(32);
@@ -183,16 +190,16 @@ HRESULT CMpaSplitterFile::Init()
pos += 4+4+2+size;
- if(!size || pos >= m_startpos)
+ if(!size || pos >= m_startpos) {
break;
+ }
if(tag == 'TIT2'
- || tag == 'TPE1'
- || tag == 'TALB'
- || tag == 'TYER'
- || tag == 'COMM'
- || tag == 'TRCK')
- {
+ || tag == 'TPE1'
+ || tag == 'TALB'
+ || tag == 'TYER'
+ || tag == 'COMM'
+ || tag == 'TRCK') {
BYTE encoding = (BYTE)BitRead(8);
size--;
@@ -201,45 +208,41 @@ HRESULT CMpaSplitterFile::Init()
CStringA str;
CStringW wstr;
- if(encoding > 0 && size >= 2 && bom == 0xfffe)
- {
- BitRead(16);
+ if(encoding > 0 && size >= 2 && bom == 0xfffe) {
+ BitRead(16);
size = (size - 2) / 2;
ByteRead((BYTE*)wstr.GetBufferSetLength(size), size*2);
m_tags[tag] = wstr.Trim();
- }
- else if(encoding > 0 && size >= 2 && bom == 0xfeff)
- {
+ } else if(encoding > 0 && size >= 2 && bom == 0xfeff) {
BitRead(16);
size = (size - 2) / 2;
ByteRead((BYTE*)wstr.GetBufferSetLength(size), size*2);
- for(int i = 0, j = wstr.GetLength(); i < j; i++) wstr.SetAt(i, (wstr[i]<<8)|(wstr[i]>>8));
+ for(int i = 0, j = wstr.GetLength(); i < j; i++) {
+ wstr.SetAt(i, (wstr[i]<<8)|(wstr[i]>>8));
+ }
m_tags[tag] = wstr.Trim();
- }
- else
- {
+ } else {
ByteRead((BYTE*)str.GetBufferSetLength(size), size);
m_tags[tag] = (encoding > 0 ? UTF8To16(str) : CStringW(str)).Trim();
- }
+ }
}
}
}
Seek(m_startpos);
- for(int i = 0; i < (1<<20) && m_startpos < m_endpos && BitRead(8, true) == 0; i++)
+ for(int i = 0; i < (1<<20) && m_startpos < m_endpos && BitRead(8, true) == 0; i++) {
BitRead(8), m_startpos++;
+ }
}
__int64 searchlen;
__int64 startpos;
__int64 syncpos;
- if(MP3_find)
- {
+ if(MP3_find) {
__int64 startpos_mp3 = m_startpos;
- while (m_mode == none)
- {
+ while (m_mode == none) {
searchlen = min(m_endpos - startpos_mp3, 0x200);
Seek(startpos_mp3);
@@ -247,45 +250,48 @@ HRESULT CMpaSplitterFile::Init()
syncpos = startpos_mp3 + searchlen;
// Check for a valid MPA header
- if(Read(m_mpahdr, searchlen, true, &m_mt))
- {
+ if(Read(m_mpahdr, searchlen, true, &m_mt)) {
m_mode = mpa;
syncpos = GetPos();
startpos = syncpos - 4;
-
+
// make sure the first frame is followed by another of the same kind (validates m_mpahdr basically)
Seek(startpos + m_mpahdr.FrameSize);
- if(!Sync(4))
+ if(!Sync(4)) {
m_mode = none;
- else
+ } else {
break;
+ }
}
// If we have enough room to search for a valid header, then skip ahead and try again
- if (m_endpos - syncpos >= 8)
+ if (m_endpos - syncpos >= 8) {
startpos_mp3 = syncpos;
- else
+ } else {
break;
+ }
}
}
searchlen = min(m_endpos - m_startpos, m_startpos > 0 ? 0x200 : 7);
Seek(m_startpos);
- if(m_mode == none && Read(m_aachdr, searchlen, &m_mt))
- {
+ if(m_mode == none && Read(m_aachdr, searchlen, &m_mt)) {
m_mode = mp4a;
startpos = GetPos() - (m_aachdr.fcrc?7:9);
// make sure the first frame is followed by another of the same kind (validates m_aachdr basically)
Seek(startpos + m_aachdr.aac_frame_length);
- if(!Sync(9)) m_mode = none;
+ if(!Sync(9)) {
+ m_mode = none;
+ }
}
- if(m_mode == none)
+ if(m_mode == none) {
return E_FAIL;
+ }
m_startpos = startpos;
@@ -293,12 +299,13 @@ HRESULT CMpaSplitterFile::Init()
REFERENCE_TIME rtFrameDur, rtPrevDur = -1;
clock_t start = clock();
int i = 0;
- while(Sync(FrameSize, rtFrameDur) && (clock() - start) < CLOCKS_PER_SEC)
- {
+ while(Sync(FrameSize, rtFrameDur) && (clock() - start) < CLOCKS_PER_SEC) {
TRACE(_T("%I64d\n"), m_rtDuration);
Seek(GetPos() + FrameSize);
i = rtPrevDur == m_rtDuration ? i+1 : 0;
- if(i == 10) break;
+ if(i == 10) {
+ break;
+ }
rtPrevDur = m_rtDuration;
}
@@ -316,18 +323,14 @@ bool CMpaSplitterFile::Sync(int& FrameSize, REFERENCE_TIME& rtDuration, int limi
{
__int64 endpos = min(m_endpos, GetPos() + limit);
- if(m_mode == mpa)
- {
- while(GetPos() <= endpos - 4)
- {
+ if(m_mode == mpa) {
+ while(GetPos() <= endpos - 4) {
mpahdr h;
- if(Read(h, endpos - GetPos(), true))
- {
+ if(Read(h, endpos - GetPos(), true)) {
if (m_mpahdr.version == h.version
- && m_mpahdr.layer == h.layer
- && m_mpahdr.channels == h.channels)
- {
+ && m_mpahdr.layer == h.layer
+ && m_mpahdr.channels == h.channels) {
Seek(GetPos() - 4);
AdjustDuration(h.nBytesPerSec);
@@ -336,23 +339,18 @@ bool CMpaSplitterFile::Sync(int& FrameSize, REFERENCE_TIME& rtDuration, int limi
return true;
}
- }
- else
+ } else {
break;
+ }
}
- }
- else if(m_mode == mp4a)
- {
- while(GetPos() <= endpos - 9)
- {
+ } else if(m_mode == mp4a) {
+ while(GetPos() <= endpos - 9) {
aachdr h;
- if(Read(h, endpos - GetPos()))
- {
+ if(Read(h, endpos - GetPos())) {
if (m_aachdr.version == h.version
- && m_aachdr.layer == h.layer
- && m_aachdr.channels == h.channels)
- {
+ && m_aachdr.layer == h.layer
+ && m_aachdr.channels == h.channels) {
Seek(GetPos() - (h.fcrc?7:9));
AdjustDuration(h.nBytesPerSec);
Seek(GetPos() + (h.fcrc?7:9));
@@ -362,9 +360,9 @@ bool CMpaSplitterFile::Sync(int& FrameSize, REFERENCE_TIME& rtDuration, int limi
return true;
}
- }
- else
+ } else {
break;
+ }
}
}
@@ -376,10 +374,11 @@ void CMpaSplitterFile::AdjustDuration(int nBytesPerSec)
ASSERT(nBytesPerSec);
int rValue;
- if(!m_pos2bps.Lookup(GetPos(), rValue))
- {
+ if(!m_pos2bps.Lookup(GetPos(), rValue)) {
m_totalbps += nBytesPerSec;
- if(!m_totalbps) return;
+ if(!m_totalbps) {
+ return;
+ }
m_pos2bps.SetAt(GetPos(), nBytesPerSec);
__int64 avgbps = m_totalbps / m_pos2bps.GetCount();
m_rtDuration = 10000000i64 * (m_endpos - m_startpos) / avgbps;
diff --git a/src/filters/parser/MpaSplitter/MpaSplitterFile.h b/src/filters/parser/MpaSplitter/MpaSplitterFile.h
index 2bd3a9a40..2c95f4af7 100644
--- a/src/filters/parser/MpaSplitter/MpaSplitterFile.h
+++ b/src/filters/parser/MpaSplitter/MpaSplitterFile.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -45,11 +45,19 @@ public:
CAtlMap<DWORD, CStringW> m_tags;
- const CMediaType& GetMediaType() {return m_mt;}
- REFERENCE_TIME GetDuration() {return IsRandomAccess() ? m_rtDuration : 0;}
+ const CMediaType& GetMediaType() {
+ return m_mt;
+ }
+ REFERENCE_TIME GetDuration() {
+ return IsRandomAccess() ? m_rtDuration : 0;
+ }
- __int64 GetStartPos() {return m_startpos;}
- __int64 GetEndPos() {return m_endpos;}
+ __int64 GetStartPos() {
+ return m_startpos;
+ }
+ __int64 GetEndPos() {
+ return m_endpos;
+ }
bool Sync(int limit = 0x2000);
bool Sync(int& FrameSize, REFERENCE_TIME& rtDuration, int limit = 0x2000);
diff --git a/src/filters/parser/MpaSplitter/stdafx.cpp b/src/filters/parser/MpaSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/MpaSplitter/stdafx.cpp
+++ b/src/filters/parser/MpaSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MpaSplitter/stdafx.h b/src/filters/parser/MpaSplitter/stdafx.h
index 7fbf4d9ac..114712db9 100644
--- a/src/filters/parser/MpaSplitter/stdafx.h
+++ b/src/filters/parser/MpaSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MpegSplitter/MpegSplitter.cpp b/src/filters/parser/MpegSplitter/MpegSplitter.cpp
index 879a773de..0f260e6d0 100644
--- a/src/filters/parser/MpegSplitter/MpegSplitter.cpp
+++ b/src/filters/parser/MpegSplitter/MpegSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* (C) 2003-2006 Gabest
* (C) 2006-2010 see AUTHORS
* http://www.gabest.org
@@ -7,12 +7,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -31,30 +31,26 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1System},
-// {&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1VideoCD}, // cdxa filter should take care of this
+ // {&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG1VideoCD}, // cdxa filter should take care of this
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG2_PROGRAM},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG2_TRANSPORT},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG2_PVA},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL},
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL},
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMpegSplitterFilter), L"MPC - Mpeg Splitter (Gabest)", MERIT_NORMAL+1, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CMpegSourceFilter), L"MPC - Mpeg Source (Gabest)", MERIT_UNLIKELY, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMpegSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CMpegSourceFilter>, NULL, &sudFilter[1]},
};
@@ -73,15 +69,15 @@ STDAPI DllRegisterServer()
chkbytes.AddTail(_T("0,1,,47,188,1,,47,376,1,,47"));
chkbytes.AddTail(_T("4,1,,47,196,1,,47,388,1,,47"));
chkbytes.AddTail(_T("0,4,,54467263,1660,1,,47")); // TFrc
- RegisterSourceFilter(CLSID_AsyncReader, MEDIASUBTYPE_MPEG2_TRANSPORT, chkbytes, NULL);
+ RegisterSourceFilter(CLSID_AsyncReader, MEDIASUBTYPE_MPEG2_TRANSPORT, chkbytes, NULL);
return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
-// UnRegisterSourceFilter(MEDIASUBTYPE_MPEG1System);
-// UnRegisterSourceFilter(MEDIASUBTYPE_MPEG2_PROGRAM);
+ // UnRegisterSourceFilter(MEDIASUBTYPE_MPEG1System);
+ // UnRegisterSourceFilter(MEDIASUBTYPE_MPEG2_PROGRAM);
return AMovieDllRegisterServer2(FALSE);
}
@@ -104,19 +100,21 @@ static int GetHighestBitSet32(unsigned long _Value)
{
unsigned long Ret;
unsigned char bNonZero = _BitScanReverse(&Ret, _Value);
- if (bNonZero)
+ if (bNonZero) {
return Ret;
- else
+ } else {
return -1;
+ }
}
CString FormatBitrate(double _Bitrate)
{
CString Temp;
- if (_Bitrate > 20000000) // More than 2 mbit
+ if (_Bitrate > 20000000) { // More than 2 mbit
Temp.Format(L"%.2f mbit/s", double(_Bitrate)/1000000.0);
- else
+ } else {
Temp.Format(L"%.1f kbit/s", double(_Bitrate)/1000.0);
+ }
return Temp;
}
@@ -138,55 +136,49 @@ CString GetMediaTypeDesc(const CMediaType *_pMediaType, const CHdmvClipInfo::Str
{
const WCHAR *pPresentationDesc = NULL;
- if (pClipInfo)
+ if (pClipInfo) {
pPresentationDesc = StreamTypeToName(pClipInfo->m_Type);
- else
+ } else {
pPresentationDesc = StreamTypeToName((PES_STREAM_TYPE)_PresentationType);
+ }
CString MajorType;
CAtlList<CString> Infos;
- if (_pMediaType->majortype == MEDIATYPE_Video)
- {
+ if (_pMediaType->majortype == MEDIATYPE_Video) {
MajorType = "Video";
- if (pClipInfo)
- {
+ if (pClipInfo) {
CString name = ISO6392ToLanguage(pClipInfo->m_LanguageCode);
- if (!name.IsEmpty())
+ if (!name.IsEmpty()) {
Infos.AddTail(name);
+ }
}
const VIDEOINFOHEADER *pVideoInfo = NULL;
const VIDEOINFOHEADER2 *pVideoInfo2 = NULL;
- if (_pMediaType->formattype == FORMAT_MPEGVideo)
- {
+ if (_pMediaType->formattype == FORMAT_MPEGVideo) {
Infos.AddTail(L"MPEG");
const MPEG1VIDEOINFO *pInfo = GetFormatHelper(pInfo, _pMediaType);
pVideoInfo = &pInfo->hdr;
- }
- else if (_pMediaType->formattype == FORMAT_MPEG2_VIDEO)
- {
+ } else if (_pMediaType->formattype == FORMAT_MPEG2_VIDEO) {
const MPEG2VIDEOINFO *pInfo = GetFormatHelper(pInfo, _pMediaType);
pVideoInfo2 = &pInfo->hdr;
bool bIsAVC = false;
- if (pInfo->hdr.bmiHeader.biCompression == '1CVA')
- {
+ if (pInfo->hdr.bmiHeader.biCompression == '1CVA') {
bIsAVC = true;
Infos.AddTail(L"AVC (H.264)");
- }
- else if (pInfo->hdr.bmiHeader.biCompression == 0)
+ } else if (pInfo->hdr.bmiHeader.biCompression == 0) {
Infos.AddTail(L"MPEG2");
- else
- {
+ } else {
WCHAR Temp[5];
memset(Temp, 0, sizeof(Temp));
Temp[0] = (pInfo->hdr.bmiHeader.biCompression >> 0) & 0xFF;
@@ -196,70 +188,96 @@ CString GetMediaTypeDesc(const CMediaType *_pMediaType, const CHdmvClipInfo::Str
Infos.AddTail(Temp);
}
- switch (pInfo->dwProfile)
- {
- case AM_MPEG2Profile_Simple: Infos.AddTail(L"Simple Profile"); break;
- case AM_MPEG2Profile_Main: Infos.AddTail(L"Main Profile"); break;
- case AM_MPEG2Profile_SNRScalable: Infos.AddTail(L"SNR Scalable Profile"); break;
- case AM_MPEG2Profile_SpatiallyScalable: Infos.AddTail(L"Spatially Scalable Profile"); break;
- case AM_MPEG2Profile_High: Infos.AddTail(L"High Profile"); break;
- default:
- if (pInfo->dwProfile)
- {
- if (bIsAVC)
- {
- switch (pInfo->dwProfile)
- {
- case 44: Infos.AddTail(L"CAVLC Profile"); break;
- case 66: Infos.AddTail(L"Baseline Profile"); break;
- case 77: Infos.AddTail(L"Main Profile"); break;
- case 88: Infos.AddTail(L"Extended Profile"); break;
- case 100: Infos.AddTail(L"High Profile"); break;
- case 110: Infos.AddTail(L"High 10 Profile"); break;
- case 122: Infos.AddTail(L"High 4:2:2 Profile"); break;
- case 244: Infos.AddTail(L"High 4:4:4 Profile"); break;
-
- default: Infos.AddTail(FormatString(L"Profile %d", pInfo->dwProfile)); break;
+ switch (pInfo->dwProfile) {
+ case AM_MPEG2Profile_Simple:
+ Infos.AddTail(L"Simple Profile");
+ break;
+ case AM_MPEG2Profile_Main:
+ Infos.AddTail(L"Main Profile");
+ break;
+ case AM_MPEG2Profile_SNRScalable:
+ Infos.AddTail(L"SNR Scalable Profile");
+ break;
+ case AM_MPEG2Profile_SpatiallyScalable:
+ Infos.AddTail(L"Spatially Scalable Profile");
+ break;
+ case AM_MPEG2Profile_High:
+ Infos.AddTail(L"High Profile");
+ break;
+ default:
+ if (pInfo->dwProfile) {
+ if (bIsAVC) {
+ switch (pInfo->dwProfile) {
+ case 44:
+ Infos.AddTail(L"CAVLC Profile");
+ break;
+ case 66:
+ Infos.AddTail(L"Baseline Profile");
+ break;
+ case 77:
+ Infos.AddTail(L"Main Profile");
+ break;
+ case 88:
+ Infos.AddTail(L"Extended Profile");
+ break;
+ case 100:
+ Infos.AddTail(L"High Profile");
+ break;
+ case 110:
+ Infos.AddTail(L"High 10 Profile");
+ break;
+ case 122:
+ Infos.AddTail(L"High 4:2:2 Profile");
+ break;
+ case 244:
+ Infos.AddTail(L"High 4:4:4 Profile");
+ break;
+
+ default:
+ Infos.AddTail(FormatString(L"Profile %d", pInfo->dwProfile));
+ break;
+ }
+ } else {
+ Infos.AddTail(FormatString(L"Profile %d", pInfo->dwProfile));
}
}
- else
- Infos.AddTail(FormatString(L"Profile %d", pInfo->dwProfile));
- }
- break;
+ break;
}
- switch (pInfo->dwLevel)
- {
- case AM_MPEG2Level_Low: Infos.AddTail(L"Low Level"); break;
- case AM_MPEG2Level_Main: Infos.AddTail(L"Main Level"); break;
- case AM_MPEG2Level_High1440: Infos.AddTail(L"High1440 Level"); break;
- case AM_MPEG2Level_High: Infos.AddTail(L"High Level"); break;
- default:
- if (pInfo->dwLevel)
- {
- if (bIsAVC)
- Infos.AddTail(FormatString(L"Level %1.1f", double(pInfo->dwLevel)/10.0));
- else
- Infos.AddTail(FormatString(L"Level %d", pInfo->dwLevel));
- }
- break;
+ switch (pInfo->dwLevel) {
+ case AM_MPEG2Level_Low:
+ Infos.AddTail(L"Low Level");
+ break;
+ case AM_MPEG2Level_Main:
+ Infos.AddTail(L"Main Level");
+ break;
+ case AM_MPEG2Level_High1440:
+ Infos.AddTail(L"High1440 Level");
+ break;
+ case AM_MPEG2Level_High:
+ Infos.AddTail(L"High Level");
+ break;
+ default:
+ if (pInfo->dwLevel) {
+ if (bIsAVC) {
+ Infos.AddTail(FormatString(L"Level %1.1f", double(pInfo->dwLevel)/10.0));
+ } else {
+ Infos.AddTail(FormatString(L"Level %d", pInfo->dwLevel));
+ }
+ }
+ break;
}
- }
- else if (_pMediaType->formattype == FORMAT_VIDEOINFO2)
- {
+ } else if (_pMediaType->formattype == FORMAT_VIDEOINFO2) {
const VIDEOINFOHEADER2 *pInfo = GetFormatHelper(pInfo, _pMediaType);
pVideoInfo2 = pInfo;
bool bIsVC1 = false;
DWORD CodecType = pInfo->bmiHeader.biCompression;
- if (CodecType == '1CVW')
- {
+ if (CodecType == '1CVW') {
bIsVC1 = true;
Infos.AddTail(L"VC-1");
- }
- else if (CodecType)
- {
+ } else if (CodecType) {
WCHAR Temp[5];
memset(Temp, 0, sizeof(Temp));
Temp[0] = (CodecType >> 0) & 0xFF;
@@ -268,109 +286,91 @@ CString GetMediaTypeDesc(const CMediaType *_pMediaType, const CHdmvClipInfo::Str
Temp[3] = (CodecType >> 24) & 0xFF;
Infos.AddTail(Temp);
}
- }
- else if (_pMediaType->subtype == MEDIASUBTYPE_DVD_SUBPICTURE)
- {
+ } else if (_pMediaType->subtype == MEDIASUBTYPE_DVD_SUBPICTURE) {
Infos.AddTail(L"DVD Sub Picture");
- }
- else if (_pMediaType->subtype == MEDIASUBTYPE_SVCD_SUBPICTURE)
- {
+ } else if (_pMediaType->subtype == MEDIASUBTYPE_SVCD_SUBPICTURE) {
Infos.AddTail(L"SVCD Sub Picture");
- }
- else if (_pMediaType->subtype == MEDIASUBTYPE_CVD_SUBPICTURE)
- {
+ } else if (_pMediaType->subtype == MEDIASUBTYPE_CVD_SUBPICTURE) {
Infos.AddTail(L"CVD Sub Picture");
}
- if (pVideoInfo2)
- {
- if (pVideoInfo2->bmiHeader.biWidth && pVideoInfo2->bmiHeader.biHeight)
+ if (pVideoInfo2) {
+ if (pVideoInfo2->bmiHeader.biWidth && pVideoInfo2->bmiHeader.biHeight) {
Infos.AddTail(FormatString(L"%dx%d", pVideoInfo2->bmiHeader.biWidth, pVideoInfo2->bmiHeader.biHeight));
- if (pVideoInfo2->AvgTimePerFrame)
+ }
+ if (pVideoInfo2->AvgTimePerFrame) {
Infos.AddTail(FormatString(L"%.3f fps", 10000000.0/double(pVideoInfo2->AvgTimePerFrame)));
- if (pVideoInfo2->dwBitRate)
+ }
+ if (pVideoInfo2->dwBitRate) {
Infos.AddTail(FormatBitrate(pVideoInfo2->dwBitRate));
- }
- else if (pVideoInfo)
- {
- if (pVideoInfo->bmiHeader.biWidth && pVideoInfo->bmiHeader.biHeight)
+ }
+ } else if (pVideoInfo) {
+ if (pVideoInfo->bmiHeader.biWidth && pVideoInfo->bmiHeader.biHeight) {
Infos.AddTail(FormatString(L"%dx%d", pVideoInfo->bmiHeader.biWidth, pVideoInfo->bmiHeader.biHeight));
- if (pVideoInfo->AvgTimePerFrame)
+ }
+ if (pVideoInfo->AvgTimePerFrame) {
Infos.AddTail(FormatString(L"%.3f fps", 10000000.0/double(pVideoInfo->AvgTimePerFrame)));
- if (pVideoInfo->dwBitRate)
+ }
+ if (pVideoInfo->dwBitRate) {
Infos.AddTail(FormatBitrate(pVideoInfo->dwBitRate));
+ }
}
-
- }
- else if (_pMediaType->majortype == MEDIATYPE_Audio)
- {
+
+ } else if (_pMediaType->majortype == MEDIATYPE_Audio) {
MajorType = "Audio";
- if (pClipInfo)
- {
+ if (pClipInfo) {
CString name = ISO6392ToLanguage(pClipInfo->m_LanguageCode);
- if (!name.IsEmpty())
+ if (!name.IsEmpty()) {
Infos.AddTail(name);
+ }
}
- if (_pMediaType->formattype == FORMAT_WaveFormatEx)
- {
+ if (_pMediaType->formattype == FORMAT_WaveFormatEx) {
const WAVEFORMATEX *pInfo = GetFormatHelper(pInfo, _pMediaType);
- if (_pMediaType->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO)
- {
+ if (_pMediaType->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
Infos.AddTail(L"DVD LPCM");
- }
- else if (_pMediaType->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO)
- {
+ } else if (_pMediaType->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO) {
const WAVEFORMATEX_HDMV_LPCM *pInfoHDMV = GetFormatHelper(pInfoHDMV, _pMediaType);
UNUSED_ALWAYS(pInfoHDMV);
Infos.AddTail(L"HDMV LPCM");
}
- if (_pMediaType->subtype == MEDIASUBTYPE_DOLBY_DDPLUS)
- {
+ if (_pMediaType->subtype == MEDIASUBTYPE_DOLBY_DDPLUS) {
Infos.AddTail(L"Dolby Digital Plus");
- }
- else
- {
- switch (pInfo->wFormatTag)
- {
- case WAVE_FORMAT_PS2_PCM:
- {
+ } else {
+ switch (pInfo->wFormatTag) {
+ case WAVE_FORMAT_PS2_PCM: {
Infos.AddTail(L"PS2 PCM");
}
break;
- case WAVE_FORMAT_PS2_ADPCM:
- {
+ case WAVE_FORMAT_PS2_ADPCM: {
Infos.AddTail(L"PS2 ADPCM");
}
break;
- case WAVE_FORMAT_DVD_DTS:
- {
- if (pPresentationDesc)
+ case WAVE_FORMAT_DVD_DTS: {
+ if (pPresentationDesc) {
Infos.AddTail(pPresentationDesc);
- else
+ } else {
Infos.AddTail(L"DTS");
+ }
}
break;
- case WAVE_FORMAT_DOLBY_AC3:
- {
- if (pPresentationDesc)
+ case WAVE_FORMAT_DOLBY_AC3: {
+ if (pPresentationDesc) {
Infos.AddTail(pPresentationDesc);
- else
+ } else {
Infos.AddTail(L"Dolby Digital");
+ }
}
break;
- case WAVE_FORMAT_AAC:
- {
+ case WAVE_FORMAT_AAC: {
Infos.AddTail(L"AAC");
}
break;
- case WAVE_FORMAT_MP3:
- {
+ case WAVE_FORMAT_MP3: {
Infos.AddTail(L"MP3");
}
break;
- case WAVE_FORMAT_MPEG:
- {
+ case WAVE_FORMAT_MPEG: {
const MPEG1WAVEFORMAT* pInfoMPEG1 = GetFormatHelper(pInfoMPEG1, _pMediaType);
int layer = GetHighestBitSet32(pInfoMPEG1->fwHeadLayer) + 1;
@@ -380,59 +380,57 @@ CString GetMediaTypeDesc(const CMediaType *_pMediaType, const CHdmvClipInfo::Str
}
}
- if (pClipInfo && (pClipInfo->m_SampleRate == BDVM_SampleRate_48_192 || pClipInfo->m_SampleRate == BDVM_SampleRate_48_96))
- {
- switch (pClipInfo->m_SampleRate)
- {
- case BDVM_SampleRate_48_192:
- Infos.AddTail(FormatString(L"192(48) kHz"));
- break;
- case BDVM_SampleRate_48_96:
- Infos.AddTail(FormatString(L"96(48) kHz"));
- break;
+ if (pClipInfo && (pClipInfo->m_SampleRate == BDVM_SampleRate_48_192 || pClipInfo->m_SampleRate == BDVM_SampleRate_48_96)) {
+ switch (pClipInfo->m_SampleRate) {
+ case BDVM_SampleRate_48_192:
+ Infos.AddTail(FormatString(L"192(48) kHz"));
+ break;
+ case BDVM_SampleRate_48_96:
+ Infos.AddTail(FormatString(L"96(48) kHz"));
+ break;
}
- }
- else if (pInfo->nSamplesPerSec)
+ } else if (pInfo->nSamplesPerSec) {
Infos.AddTail(FormatString(L"%.1f kHz", double(pInfo->nSamplesPerSec)/1000.0));
- if (pInfo->nChannels)
+ }
+ if (pInfo->nChannels) {
Infos.AddTail(FormatString(L"%d chn", pInfo->nChannels));
- if (pInfo->wBitsPerSample)
+ }
+ if (pInfo->wBitsPerSample) {
Infos.AddTail(FormatString(L"%d bit", pInfo->wBitsPerSample));
- if (pInfo->nAvgBytesPerSec)
+ }
+ if (pInfo->nAvgBytesPerSec) {
Infos.AddTail(FormatBitrate(pInfo->nAvgBytesPerSec * 8));
+ }
}
- }
- else if (_pMediaType->majortype == MEDIATYPE_Subtitle)
- {
+ } else if (_pMediaType->majortype == MEDIATYPE_Subtitle) {
MajorType = "Subtitle";
- if (pPresentationDesc)
+ if (pPresentationDesc) {
Infos.AddTail(pPresentationDesc);
+ }
- if (_pMediaType->cbFormat == sizeof(SUBTITLEINFO))
- {
+ if (_pMediaType->cbFormat == sizeof(SUBTITLEINFO)) {
const SUBTITLEINFO *pInfo = GetFormatHelper(pInfo, _pMediaType);
CString name = ISO6392ToLanguage(pInfo->IsoLang);
- if (pInfo->TrackName[0])
+ if (pInfo->TrackName[0]) {
Infos.AddHead(pInfo->TrackName);
- if (!name.IsEmpty())
+ }
+ if (!name.IsEmpty()) {
Infos.AddHead(name);
- }
- else
- {
- if (pClipInfo)
- {
+ }
+ } else {
+ if (pClipInfo) {
CString name = ISO6392ToLanguage(pClipInfo->m_LanguageCode);
- if (!name.IsEmpty())
+ if (!name.IsEmpty()) {
Infos.AddHead(name);
+ }
}
}
}
- if (!Infos.IsEmpty())
- {
+ if (!Infos.IsEmpty()) {
CString Ret;
Ret += MajorType;
@@ -440,14 +438,14 @@ CString GetMediaTypeDesc(const CMediaType *_pMediaType, const CHdmvClipInfo::Str
bool bFirst = true;
- for(POSITION pos = Infos.GetHeadPosition(); pos; Infos.GetNext(pos))
- {
+ for(POSITION pos = Infos.GetHeadPosition(); pos; Infos.GetNext(pos)) {
CString& String = Infos.GetAt(pos);
- if (bFirst)
+ if (bFirst) {
Ret += String;
- else
+ } else {
Ret += L", " + String;
+ }
bFirst = false;
}
@@ -470,9 +468,9 @@ CMpegSplitterFilter::CMpegSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr, const CLS
STDMETHODIMP CMpegSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IAMStreamSelect)
__super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -481,32 +479,30 @@ STDMETHODIMP CMpegSplitterFilter::GetClassID(CLSID* pClsID)
{
CheckPointer (pClsID, E_POINTER);
- if (m_pPipoBimbo)
- {
+ if (m_pPipoBimbo) {
memcpy (pClsID, &CLSID_WMAsfReader, sizeof (GUID));
return S_OK;
- }
- else
+ } else {
return __super::GetClassID(pClsID);
+ }
}
void CMpegSplitterFilter::ReadClipInfo(LPCOLESTR pszFileName)
{
- if (wcslen (pszFileName) > 0)
- {
+ if (wcslen (pszFileName) > 0) {
WCHAR Drive[_MAX_DRIVE];
WCHAR Dir[_MAX_PATH];
WCHAR Filename[_MAX_PATH];
WCHAR Ext[_MAX_EXT];
-
- if (_wsplitpath_s (pszFileName, Drive, countof(Drive), Dir, countof(Dir), Filename, countof(Filename), Ext, countof(Ext)) == 0)
- {
+
+ if (_wsplitpath_s (pszFileName, Drive, countof(Drive), Dir, countof(Dir), Filename, countof(Filename), Ext, countof(Ext)) == 0) {
CString strClipInfo;
- if (Drive[0])
+ if (Drive[0]) {
strClipInfo.Format (_T("%s\\%s\\..\\CLIPINF\\%s.clpi"), Drive, Dir, Filename);
- else
+ } else {
strClipInfo.Format (_T("%s\\..\\CLIPINF\\%s.clpi"), Dir, Filename);
+ }
m_ClipInfo.ReadInfo (strClipInfo);
}
@@ -516,7 +512,7 @@ void CMpegSplitterFilter::ReadClipInfo(LPCOLESTR pszFileName)
STDMETHODIMP CMpegSplitterFilter::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
HRESULT hr;
-
+
return __super::Load (pszFileName, pmt);
}
@@ -526,22 +522,21 @@ HRESULT CMpegSplitterFilter::DemuxNextPacket(REFERENCE_TIME rtStartOffset)
HRESULT hr;
BYTE b;
- if(m_pFile->m_type == CMpegSplitterFile::ps || m_pFile->m_type == CMpegSplitterFile::es)
- {
- if(!m_pFile->NextMpegStartCode(b))
+ if(m_pFile->m_type == CMpegSplitterFile::ps || m_pFile->m_type == CMpegSplitterFile::es) {
+ if(!m_pFile->NextMpegStartCode(b)) {
return S_FALSE;
+ }
- if(b == 0xba) // program stream header
- {
+ if(b == 0xba) { // program stream header
CMpegSplitterFile::pshdr h;
- if(!m_pFile->Read(h))
+ if(!m_pFile->Read(h)) {
return S_FALSE;
- }
- else if(b == 0xbb) // program stream system header
- {
+ }
+ } else if(b == 0xbb) { // program stream system header
CMpegSplitterFile::pssyshdr h;
- if(!m_pFile->Read(h))
+ if(!m_pFile->Read(h)) {
return S_FALSE;
+ }
}
#if (EVO_SUPPORT == 0)
else if(b >= 0xbd && b < 0xf0) // pes packet
@@ -551,10 +546,11 @@ HRESULT CMpegSplitterFilter::DemuxNextPacket(REFERENCE_TIME rtStartOffset)
{
CMpegSplitterFile::peshdr h;
- if(!m_pFile->Read(h, b) || !h.len) return S_FALSE;
+ if(!m_pFile->Read(h, b) || !h.len) {
+ return S_FALSE;
+ }
- if(h.type == CMpegSplitterFile::mpeg2 && h.scrambling)
- {
+ if(h.type == CMpegSplitterFile::mpeg2 && h.scrambling) {
ASSERT(0);
return E_FAIL;
}
@@ -563,8 +559,7 @@ HRESULT CMpegSplitterFilter::DemuxNextPacket(REFERENCE_TIME rtStartOffset)
DWORD TrackNumber = m_pFile->AddStream(0, b, h.len);
- if(GetOutputPin(TrackNumber))
- {
+ if(GetOutputPin(TrackNumber)) {
CAutoPtr<Packet> p(DNew Packet());
p->TrackNumber = TrackNumber;
@@ -580,52 +575,46 @@ HRESULT CMpegSplitterFilter::DemuxNextPacket(REFERENCE_TIME rtStartOffset)
}
m_pFile->Seek(pos + h.len);
}
- }
- else if(m_pFile->m_type == CMpegSplitterFile::ts)
- {
+ } else if(m_pFile->m_type == CMpegSplitterFile::ts) {
CMpegSplitterFile::trhdr h;
- if(!m_pFile->Read(h))
+ if(!m_pFile->Read(h)) {
return S_FALSE;
+ }
__int64 pos = m_pFile->GetPos();
- if(h.payload && h.payloadstart)
+ if(h.payload && h.payloadstart) {
m_pFile->UpdatePrograms(h);
+ }
- if(h.payload && h.pid >= 16 && h.pid < 0x1fff && !h.scrambling)
- {
+ if(h.payload && h.pid >= 16 && h.pid < 0x1fff && !h.scrambling) {
DWORD TrackNumber = h.pid;
CMpegSplitterFile::peshdr h2;
- if(h.payloadstart && m_pFile->NextMpegStartCode(b, 4) && m_pFile->Read(h2, b)) // pes packet
- {
- if(h2.type == CMpegSplitterFile::mpeg2 && h2.scrambling)
- {
+ if(h.payloadstart && m_pFile->NextMpegStartCode(b, 4) && m_pFile->Read(h2, b)) { // pes packet
+ if(h2.type == CMpegSplitterFile::mpeg2 && h2.scrambling) {
ASSERT(0);
return E_FAIL;
}
TrackNumber = m_pFile->AddStream(h.pid, b, h.bytes - (DWORD)(m_pFile->GetPos() - pos));
}
- if(GetOutputPin(TrackNumber))
- {
+ if(GetOutputPin(TrackNumber)) {
CAutoPtr<Packet> p(DNew Packet());
p->TrackNumber = TrackNumber;
p->bSyncPoint = !!h2.fpts;
p->bAppendable = !h2.fpts;
- if (h.fPCR)
- {
+ if (h.fPCR) {
CRefTime rtNow;
StreamTime(rtNow);
TRACE ("Now=%S PCR=%S\n", ReftimeToString(rtNow.m_time), ReftimeToString(h.PCR));
}
- if (h2.fpts && h.pid == 241)
- {
+ if (h2.fpts && h.pid == 241) {
TRACE ("Sub=%S\n", ReftimeToString(h2.pts - rtStartOffset));
}
@@ -641,19 +630,17 @@ HRESULT CMpegSplitterFilter::DemuxNextPacket(REFERENCE_TIME rtStartOffset)
}
m_pFile->Seek(h.next);
- }
- else if(m_pFile->m_type == CMpegSplitterFile::pva)
- {
+ } else if(m_pFile->m_type == CMpegSplitterFile::pva) {
CMpegSplitterFile::pvahdr h;
- if(!m_pFile->Read(h))
+ if(!m_pFile->Read(h)) {
return S_FALSE;
+ }
DWORD TrackNumber = h.streamid;
__int64 pos = m_pFile->GetPos();
- if(GetOutputPin(TrackNumber))
- {
+ if(GetOutputPin(TrackNumber)) {
CAutoPtr<Packet> p(DNew Packet());
p->TrackNumber = TrackNumber;
@@ -686,22 +673,20 @@ HRESULT CMpegSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
ReadClipInfo (GetPartFilename(pAsyncReader));
m_pFile.Attach(DNew CMpegSplitterFile(pAsyncReader, hr, m_ClipInfo.IsHdmv(), m_ClipInfo));
- if(!m_pFile) return E_OUTOFMEMORY;
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
m_pFile.Free();
return hr;
}
// Create
- if (m_ClipInfo.IsHdmv())
- {
- for (int i=0; i<m_ClipInfo.GetStreamNumber(); i++)
- {
+ if (m_ClipInfo.IsHdmv()) {
+ for (int i=0; i<m_ClipInfo.GetStreamNumber(); i++) {
CHdmvClipInfo::Stream* stream = m_ClipInfo.GetStreamByIndex (i);
- if (stream->m_Type == PRESENTATION_GRAPHICS_STREAM)
- {
+ if (stream->m_Type == PRESENTATION_GRAPHICS_STREAM) {
m_pFile->AddHdmvPGStream (stream->m_PID, stream->m_LanguageCode);
}
}
@@ -710,24 +695,19 @@ HRESULT CMpegSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = 0;
- for(int i = 0; i < countof(m_pFile->m_streams); i++)
- {
+ for(int i = 0; i < countof(m_pFile->m_streams); i++) {
POSITION pos = m_pFile->m_streams[i].GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CMpegSplitterFile::stream& s = m_pFile->m_streams[i].GetNext(pos);
CAtlArray<CMediaType> mts;
mts.Add(s.mt);
-
+
CStringW name = CMpegSplitterFile::CStreamList::ToString(i);
CStringW str;
- if (i == CMpegSplitterFile::subpic && s.pid == NO_SUBTITLE_PID)
- {
+ if (i == CMpegSplitterFile::subpic && s.pid == NO_SUBTITLE_PID) {
str = _T("No subtitles");
- }
- else
- {
+ } else {
int iProgram;
const CHdmvClipInfo::Stream *pClipInfo;
const CMpegSplitterFile::program * pProgram = m_pFile->FindProgram(s.pid, iProgram, pClipInfo);
@@ -737,28 +717,28 @@ HRESULT CMpegSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
CString FormatDesc = GetMediaTypeDesc(&s.mt, pClipInfo, StreamType);
- if (!FormatDesc.IsEmpty())
- str.Format(L"%s (%04x,%02x,%02x)", FormatDesc.GetString(), s.pid, s.pesid, s.ps1id); // TODO: make this nicer
- else if (pStreamName)
- str.Format(L"%s - %s (%04x,%02x,%02x)", name, pStreamName, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
- else
- str.Format(L"%s (%04x,%02x,%02x)", name, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ if (!FormatDesc.IsEmpty()) {
+ str.Format(L"%s (%04x,%02x,%02x)", FormatDesc.GetString(), s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ } else if (pStreamName) {
+ str.Format(L"%s - %s (%04x,%02x,%02x)", name, pStreamName, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ } else {
+ str.Format(L"%s (%04x,%02x,%02x)", name, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ }
}
-
+
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CMpegSplitterOutputPin(mts, str, this, this, &hr));
- if (i == CMpegSplitterFile::subpic)
+ if (i == CMpegSplitterFile::subpic) {
(static_cast<CMpegSplitterOutputPin*>(pPinOut.m_p))->SetMaxShift (_I64_MAX);
- if(S_OK == AddOutputPin(s, pPinOut))
+ }
+ if(S_OK == AddOutputPin(s, pPinOut)) {
break;
+ }
}
}
- if(m_rtPlaylistDuration)
- {
+ if(m_rtPlaylistDuration) {
m_rtNewStop = m_rtStop = m_rtDuration = m_rtPlaylistDuration;
- }
- else if(m_pFile->IsRandomAccess() && m_pFile->m_rate)
- {
+ } else if(m_pFile->IsRandomAccess() && m_pFile->m_rate) {
m_rtNewStop = m_rtStop = m_rtDuration = 10000000i64 * m_pFile->GetLength() / m_pFile->m_rate;
}
@@ -768,7 +748,9 @@ HRESULT CMpegSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
bool CMpegSplitterFilter::DemuxInit()
{
SetThreadName((DWORD)-1, "CMpegSplitterFilter");
- if(!m_pFile) return(false);
+ if(!m_pFile) {
+ return(false);
+ }
m_rtStartOffset = 0;
@@ -779,27 +761,22 @@ void CMpegSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
{
CAtlList<CMpegSplitterFile::stream>* pMasterStream = m_pFile->GetMasterStream();
- if(!pMasterStream)
- {
+ if(!pMasterStream) {
ASSERT(0);
return;
}
- if(m_pFile->IsStreaming())
- {
+ if(m_pFile->IsStreaming()) {
m_pFile->Seek(max(0, m_pFile->GetLength() - 100*1024));
m_rtStartOffset = m_pFile->m_rtMin + m_pFile->NextPTS(pMasterStream->GetHead());
return;
}
REFERENCE_TIME rtPreroll = 10000000;
-
- if(rt <= rtPreroll || m_rtDuration <= 0)
- {
+
+ if(rt <= rtPreroll || m_rtDuration <= 0) {
m_pFile->Seek(0);
- }
- else
- {
+ } else {
__int64 len = m_pFile->GetLength();
__int64 seekpos = (__int64)(1.0*rt/m_rtDuration*len);
__int64 minseekpos = _I64_MAX;
@@ -808,50 +785,46 @@ void CMpegSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
REFERENCE_TIME rtmin = rtmax - 5000000;
if(m_rtStartOffset == 0)
- for(int i = 0; i < countof(m_pFile->m_streams)-1; i++)
- {
- POSITION pos = m_pFile->m_streams[i].GetHeadPosition();
- while(pos)
- {
- DWORD TrackNum = m_pFile->m_streams[i].GetNext(pos);
+ for(int i = 0; i < countof(m_pFile->m_streams)-1; i++) {
+ POSITION pos = m_pFile->m_streams[i].GetHeadPosition();
+ while(pos) {
+ DWORD TrackNum = m_pFile->m_streams[i].GetNext(pos);
- CBaseSplitterOutputPin* pPin = GetOutputPin(TrackNum);
- if(pPin && pPin->IsConnected())
- {
- m_pFile->Seek(seekpos);
+ CBaseSplitterOutputPin* pPin = GetOutputPin(TrackNum);
+ if(pPin && pPin->IsConnected()) {
+ m_pFile->Seek(seekpos);
- REFERENCE_TIME pdt = _I64_MIN;
+ REFERENCE_TIME pdt = _I64_MIN;
- for(int j = 0; j < 10; j++)
- {
- REFERENCE_TIME rt = m_pFile->NextPTS(TrackNum);
+ for(int j = 0; j < 10; j++) {
+ REFERENCE_TIME rt = m_pFile->NextPTS(TrackNum);
- if(rt < 0) break;
+ if(rt < 0) {
+ break;
+ }
- REFERENCE_TIME dt = rt - rtmax;
- if(dt > 0 && dt == pdt) dt = 10000000i64;
+ REFERENCE_TIME dt = rt - rtmax;
+ if(dt > 0 && dt == pdt) {
+ dt = 10000000i64;
+ }
- if(rtmin <= rt && rt <= rtmax || pdt > 0 && dt < 0)
- {
- minseekpos = min(minseekpos, m_pFile->GetPos());
- break;
- }
+ if(rtmin <= rt && rt <= rtmax || pdt > 0 && dt < 0) {
+ minseekpos = min(minseekpos, m_pFile->GetPos());
+ break;
+ }
+
+ m_pFile->Seek(m_pFile->GetPos() - (__int64)(1.0*dt/m_rtDuration*len));
- m_pFile->Seek(m_pFile->GetPos() - (__int64)(1.0*dt/m_rtDuration*len));
-
- pdt = dt;
+ pdt = dt;
+ }
}
}
}
- }
- if(minseekpos != _I64_MAX)
- {
+ if(minseekpos != _I64_MAX) {
seekpos = minseekpos;
- }
- else
- {
+ } else {
// this file is probably screwed up, try plan B, seek simply by bitrate
rt -= rtPreroll;
@@ -869,11 +842,11 @@ bool CMpegSplitterFilter::DemuxLoop()
REFERENCE_TIME rtStartOffset = m_rtStartOffset ? m_rtStartOffset : m_pFile->m_rtMin;
HRESULT hr = S_OK;
- while(SUCCEEDED(hr) && !CheckRequest(NULL))
- {
+ while(SUCCEEDED(hr) && !CheckRequest(NULL)) {
if((hr = m_pFile->HasMoreData(1024*500)) == S_OK)
- if((hr = DemuxNextPacket(rtStartOffset)) == S_FALSE)
+ if((hr = DemuxNextPacket(rtStartOffset)) == S_FALSE) {
Sleep(1);
+ }
}
return(true);
@@ -893,63 +866,67 @@ STDMETHODIMP CMpegSplitterFilter::Count(DWORD* pcStreams)
*pcStreams = 0;
- for(int i = 0; i < countof(m_pFile->m_streams); i++)
+ for(int i = 0; i < countof(m_pFile->m_streams); i++) {
(*pcStreams) += m_pFile->m_streams[i].GetCount();
+ }
return S_OK;
}
STDMETHODIMP CMpegSplitterFilter::Enable(long lIndex, DWORD dwFlags)
{
- if(!(dwFlags & AMSTREAMSELECTENABLE_ENABLE))
+ if(!(dwFlags & AMSTREAMSELECTENABLE_ENABLE)) {
return E_NOTIMPL;
+ }
- for(int i = 0, j = 0; i < countof(m_pFile->m_streams); i++)
- {
+ for(int i = 0, j = 0; i < countof(m_pFile->m_streams); i++) {
int cnt = m_pFile->m_streams[i].GetCount();
-
- if(lIndex >= j && lIndex < j+cnt)
- {
+
+ if(lIndex >= j && lIndex < j+cnt) {
lIndex -= j;
POSITION pos = m_pFile->m_streams[i].FindIndex(lIndex);
- if(!pos) return E_UNEXPECTED;
+ if(!pos) {
+ return E_UNEXPECTED;
+ }
CMpegSplitterFile::stream& to = m_pFile->m_streams[i].GetAt(pos);
pos = m_pFile->m_streams[i].GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CMpegSplitterFile::stream& from = m_pFile->m_streams[i].GetNext(pos);
- if(!GetOutputPin(from)) continue;
+ if(!GetOutputPin(from)) {
+ continue;
+ }
HRESULT hr;
- if(FAILED(hr = RenameOutputPin(from, to, &to.mt)))
+ if(FAILED(hr = RenameOutputPin(from, to, &to.mt))) {
return hr;
+ }
// Don't rename other pin for Hdmv!
int iProgram;
const CHdmvClipInfo::Stream *pClipInfo;
const CMpegSplitterFile::program* p = m_pFile->FindProgram(to.pid, iProgram, pClipInfo);
- if(p!=NULL && !m_ClipInfo.IsHdmv() && !m_pFile->IsHdmv())
- {
- for(int k = 0; k < countof(m_pFile->m_streams); k++)
- {
- if(k == i) continue;
+ if(p!=NULL && !m_ClipInfo.IsHdmv() && !m_pFile->IsHdmv()) {
+ for(int k = 0; k < countof(m_pFile->m_streams); k++) {
+ if(k == i) {
+ continue;
+ }
pos = m_pFile->m_streams[k].GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CMpegSplitterFile::stream& from = m_pFile->m_streams[k].GetNext(pos);
- if(!GetOutputPin(from)) continue;
+ if(!GetOutputPin(from)) {
+ continue;
+ }
- for(int l = 0; l < countof(p->streams); l++)
- {
- if(const CMpegSplitterFile::stream* s = m_pFile->m_streams[k].FindStream(p->streams[l].pid))
- {
- if(from != *s)
+ for(int l = 0; l < countof(p->streams); l++) {
+ if(const CMpegSplitterFile::stream* s = m_pFile->m_streams[k].FindStream(p->streams[l].pid)) {
+ if(from != *s) {
hr = RenameOutputPin(from, *s, &s->mt);
+ }
break;
}
}
@@ -969,67 +946,52 @@ STDMETHODIMP CMpegSplitterFilter::Enable(long lIndex, DWORD dwFlags)
LONGLONG GetMediaTypeQuality(const CMediaType *_pMediaType, int _PresentationFormat)
{
- if (_pMediaType->formattype == FORMAT_WaveFormatEx)
- {
+ if (_pMediaType->formattype == FORMAT_WaveFormatEx) {
__int64 Ret = 0;
const WAVEFORMATEX *pInfo = GetFormatHelper(pInfo, _pMediaType);
int TypePriority = 0;
- if (_pMediaType->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO)
- {
- TypePriority = 12;
- }
- else if (_pMediaType->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO)
- {
+ if (_pMediaType->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
TypePriority = 12;
- }
- else
- {
- if (_PresentationFormat == AUDIO_STREAM_DTS_HD_MASTER_AUDIO)
+ } else if (_pMediaType->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO) {
+ TypePriority = 12;
+ } else {
+ if (_PresentationFormat == AUDIO_STREAM_DTS_HD_MASTER_AUDIO) {
TypePriority = 12;
- else if (_PresentationFormat == AUDIO_STREAM_DTS_HD)
+ } else if (_PresentationFormat == AUDIO_STREAM_DTS_HD) {
TypePriority = 11;
- else if (_PresentationFormat == AUDIO_STREAM_AC3_TRUE_HD)
+ } else if (_PresentationFormat == AUDIO_STREAM_AC3_TRUE_HD) {
TypePriority = 12;
- else if (_PresentationFormat == AUDIO_STREAM_AC3_PLUS)
+ } else if (_PresentationFormat == AUDIO_STREAM_AC3_PLUS) {
TypePriority = 10;
- else
- {
- switch (pInfo->wFormatTag)
- {
- case WAVE_FORMAT_PS2_PCM:
- {
+ } else {
+ switch (pInfo->wFormatTag) {
+ case WAVE_FORMAT_PS2_PCM: {
TypePriority = 12;
}
break;
- case WAVE_FORMAT_PS2_ADPCM:
- {
+ case WAVE_FORMAT_PS2_ADPCM: {
TypePriority = 4;
}
break;
- case WAVE_FORMAT_DVD_DTS:
- {
+ case WAVE_FORMAT_DVD_DTS: {
TypePriority = 9;
}
break;
- case WAVE_FORMAT_DOLBY_AC3:
- {
+ case WAVE_FORMAT_DOLBY_AC3: {
TypePriority = 8;
}
break;
- case WAVE_FORMAT_AAC:
- {
+ case WAVE_FORMAT_AAC: {
TypePriority = 7;
}
break;
- case WAVE_FORMAT_MP3:
- {
+ case WAVE_FORMAT_MP3: {
TypePriority = 6;
}
break;
- case WAVE_FORMAT_MPEG:
- {
+ case WAVE_FORMAT_MPEG: {
TypePriority = 5;
}
break;
@@ -1053,8 +1015,7 @@ LONGLONG GetMediaTypeQuality(const CMediaType *_pMediaType, int _PresentationFor
bool CMpegSplitterFile::stream::operator < (const stream &_Other) const
{
- if (mt.majortype == MEDIATYPE_Audio && _Other.mt.majortype == MEDIATYPE_Audio)
- {
+ if (mt.majortype == MEDIATYPE_Audio && _Other.mt.majortype == MEDIATYPE_Audio) {
int iProgram0;
const CHdmvClipInfo::Stream *pClipInfo0;
const CMpegSplitterFile::program * pProgram0 = m_pFile->FindProgram(pid, iProgram0, pClipInfo0);
@@ -1063,18 +1024,22 @@ bool CMpegSplitterFile::stream::operator < (const stream &_Other) const
const CHdmvClipInfo::Stream *pClipInfo1;
const CMpegSplitterFile::program * pProgram1 = m_pFile->FindProgram(_Other.pid, iProgram1, pClipInfo1);
int StreamType1 = pClipInfo1 ? pClipInfo1->m_Type : pProgram1 ? pProgram1->streams[iProgram1].type : 0;
-
- if (mt.formattype == FORMAT_WaveFormatEx && _Other.mt.formattype != FORMAT_WaveFormatEx)
+
+ if (mt.formattype == FORMAT_WaveFormatEx && _Other.mt.formattype != FORMAT_WaveFormatEx) {
return true;
- if (mt.formattype != FORMAT_WaveFormatEx && _Other.mt.formattype == FORMAT_WaveFormatEx)
+ }
+ if (mt.formattype != FORMAT_WaveFormatEx && _Other.mt.formattype == FORMAT_WaveFormatEx) {
return false;
+ }
LONGLONG Quality0 = GetMediaTypeQuality(&mt, StreamType0);
LONGLONG Quality1 = GetMediaTypeQuality(&_Other.mt, StreamType1);
- if (Quality0 > Quality1)
+ if (Quality0 > Quality1) {
return true;
- if (Quality0 < Quality1)
+ }
+ if (Quality0 < Quality1) {
return false;
+ }
}
DWORD DefaultFirst = *this;
DWORD DefaultSecond = _Other;
@@ -1083,41 +1048,49 @@ bool CMpegSplitterFile::stream::operator < (const stream &_Other) const
STDMETHODIMP CMpegSplitterFilter::Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD* pdwFlags, LCID* plcid, DWORD* pdwGroup, WCHAR** ppszName, IUnknown** ppObject, IUnknown** ppUnk)
{
- for(int i = 0, j = 0; i < countof(m_pFile->m_streams); i++)
- {
+ for(int i = 0, j = 0; i < countof(m_pFile->m_streams); i++) {
int cnt = m_pFile->m_streams[i].GetCount();
-
- if(lIndex >= j && lIndex < j+cnt)
- {
+
+ if(lIndex >= j && lIndex < j+cnt) {
lIndex -= j;
-
+
POSITION pos = m_pFile->m_streams[i].FindIndex(lIndex);
- if(!pos) return E_UNEXPECTED;
+ if(!pos) {
+ return E_UNEXPECTED;
+ }
CMpegSplitterFile::stream& s = m_pFile->m_streams[i].GetAt(pos);
CHdmvClipInfo::Stream* pStream = m_ClipInfo.FindStream (s.pid);
- if(ppmt) *ppmt = CreateMediaType(&s.mt);
- if(pdwFlags) *pdwFlags = GetOutputPin(s) ? (AMSTREAMSELECTINFO_ENABLED|AMSTREAMSELECTINFO_EXCLUSIVE) : 0;
- if(plcid) *plcid = pStream ? pStream->m_LCID : 0;
- if(pdwGroup) *pdwGroup = i;
- if(ppObject) *ppObject = NULL;
- if(ppUnk) *ppUnk = NULL;
+ if(ppmt) {
+ *ppmt = CreateMediaType(&s.mt);
+ }
+ if(pdwFlags) {
+ *pdwFlags = GetOutputPin(s) ? (AMSTREAMSELECTINFO_ENABLED|AMSTREAMSELECTINFO_EXCLUSIVE) : 0;
+ }
+ if(plcid) {
+ *plcid = pStream ? pStream->m_LCID : 0;
+ }
+ if(pdwGroup) {
+ *pdwGroup = i;
+ }
+ if(ppObject) {
+ *ppObject = NULL;
+ }
+ if(ppUnk) {
+ *ppUnk = NULL;
+ }
+
-
- if(ppszName)
- {
+ if(ppszName) {
CStringW name = CMpegSplitterFile::CStreamList::ToString(i);
CStringW str;
- if (i == CMpegSplitterFile::subpic && s.pid == NO_SUBTITLE_PID)
- {
+ if (i == CMpegSplitterFile::subpic && s.pid == NO_SUBTITLE_PID) {
str = _T("No subtitles");
*plcid = (LCID)LCID_NOSUBTITLES;
- }
- else
- {
+ } else {
int iProgram;
const CHdmvClipInfo::Stream *pClipInfo;
const CMpegSplitterFile::program * pProgram = m_pFile->FindProgram(s.pid, iProgram, pClipInfo);
@@ -1127,16 +1100,19 @@ STDMETHODIMP CMpegSplitterFilter::Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD*
CString FormatDesc = GetMediaTypeDesc(&s.mt, pClipInfo, StreamType);
- if (!FormatDesc.IsEmpty())
- str.Format(L"%s (%04x,%02x,%02x)", FormatDesc.GetString(), s.pid, s.pesid, s.ps1id); // TODO: make this nicer
- else if (pStreamName)
- str.Format(L"%s - %s (%04x,%02x,%02x)", name, pStreamName, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
- else
- str.Format(L"%s (%04x,%02x,%02x)", name, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ if (!FormatDesc.IsEmpty()) {
+ str.Format(L"%s (%04x,%02x,%02x)", FormatDesc.GetString(), s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ } else if (pStreamName) {
+ str.Format(L"%s - %s (%04x,%02x,%02x)", name, pStreamName, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ } else {
+ str.Format(L"%s (%04x,%02x,%02x)", name, s.pid, s.pesid, s.ps1id); // TODO: make this nicer
+ }
}
*ppszName = (WCHAR*)CoTaskMemAlloc((str.GetLength()+1)*sizeof(WCHAR));
- if(*ppszName == NULL) return E_OUTOFMEMORY;
+ if(*ppszName == NULL) {
+ return E_OUTOFMEMORY;
+ }
wcscpy_s(*ppszName, str.GetLength()+1, str);
}
@@ -1200,14 +1176,14 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
{
CAutoLock cAutoLock(this);
- if(p->rtStart != Packet::INVALID_TIME)
- {
+ if(p->rtStart != Packet::INVALID_TIME) {
REFERENCE_TIME rt = p->rtStart + m_rtOffset;
// Filter invalid PTS (if too different from previous packet)
if(m_rtPrev != Packet::INVALID_TIME)
- if(_abs64(rt - m_rtPrev) > m_rtMaxShift)
- m_rtOffset += m_rtPrev - rt;
+ if(_abs64(rt - m_rtPrev) > m_rtMaxShift) {
+ m_rtOffset += m_rtPrev - rt;
+ }
p->rtStart += m_rtOffset;
p->rtStop += m_rtOffset;
@@ -1215,60 +1191,57 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
m_rtPrev = p->rtStart;
}
-
- if (p->pmt)
- {
- if (*((CMediaType *)p->pmt) != m_mt)
+
+ if (p->pmt) {
+ if (*((CMediaType *)p->pmt) != m_mt) {
SetMediaType ((CMediaType*)p->pmt);
+ }
}
- if(m_mt.subtype == MEDIASUBTYPE_AAC) // special code for aac, the currently available decoders only like whole frame samples
- {
- if(m_p && m_p->GetCount() == 1 && m_p->GetAt(0) == 0xff && !(!p->IsEmpty() && (p->GetAt(0) & 0xf6) == 0xf0))
+ if(m_mt.subtype == MEDIASUBTYPE_AAC) { // special code for aac, the currently available decoders only like whole frame samples
+ if(m_p && m_p->GetCount() == 1 && m_p->GetAt(0) == 0xff && !(!p->IsEmpty() && (p->GetAt(0) & 0xf6) == 0xf0)) {
m_p.Free();
+ }
- if(!m_p)
- {
+ if(!m_p) {
BYTE* base = p->GetData();
BYTE* s = base;
BYTE* e = s + p->GetCount();
- for(; s < e; s++)
- {
- if(*s != 0xff) continue;
+ for(; s < e; s++) {
+ if(*s != 0xff) {
+ continue;
+ }
- if(s == e-1 || (s[1]&0xf6) == 0xf0)
- {
+ if(s == e-1 || (s[1]&0xf6) == 0xf0) {
memmove(base, s, e - s);
p->SetCount(e - s);
m_p = p;
break;
}
}
- }
- else
- {
+ } else {
m_p->Append(*p);
}
- while(m_p && m_p->GetCount() > 9)
- {
+ while(m_p && m_p->GetCount() > 9) {
BYTE* base = m_p->GetData();
BYTE* s = base;
BYTE* e = s + m_p->GetCount();
int len = ((s[3]&3)<<11)|(s[4]<<3)|(s[5]>>5);
bool crc = !(s[1]&1);
- s += 7; len -= 7;
- if(crc) s += 2, len -= 2;
+ s += 7;
+ len -= 7;
+ if(crc) {
+ s += 2, len -= 2;
+ }
- if(e - s < len)
- {
+ if(e - s < len) {
break;
}
- if(len <= 0 || e - s >= len + 2 && (s[len] != 0xff || (s[len+1]&0xf6) != 0xf0))
- {
+ if(len <= 0 || e - s >= len + 2 && (s[len] != 0xff || (s[len+1]&0xf6) != 0xf0)) {
m_p.Free();
break;
}
@@ -1285,7 +1258,8 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
p2->rtStop = m_p->rtStop;
m_p->rtStop = Packet::INVALID_TIME;
- p2->pmt = m_p->pmt; m_p->pmt = NULL;
+ p2->pmt = m_p->pmt;
+ m_p->pmt = NULL;
p2->SetData(s, len);
s += len;
@@ -1293,26 +1267,32 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
m_p->SetCount(e - s);
HRESULT hr = __super::DeliverPacket(p2);
- if(hr != S_OK) return hr;
+ if(hr != S_OK) {
+ return hr;
+ }
}
- if(m_p && p)
- {
- if(!m_p->bDiscontinuity) m_p->bDiscontinuity = p->bDiscontinuity;
- if(!m_p->bSyncPoint) m_p->bSyncPoint = p->bSyncPoint;
- if(m_p->rtStart == Packet::INVALID_TIME) m_p->rtStart = p->rtStart, m_p->rtStop = p->rtStop;
- if(m_p->pmt) DeleteMediaType(m_p->pmt);
-
+ if(m_p && p) {
+ if(!m_p->bDiscontinuity) {
+ m_p->bDiscontinuity = p->bDiscontinuity;
+ }
+ if(!m_p->bSyncPoint) {
+ m_p->bSyncPoint = p->bSyncPoint;
+ }
+ if(m_p->rtStart == Packet::INVALID_TIME) {
+ m_p->rtStart = p->rtStart, m_p->rtStop = p->rtStop;
+ }
+ if(m_p->pmt) {
+ DeleteMediaType(m_p->pmt);
+ }
+
m_p->pmt = p->pmt;
p->pmt = NULL;
}
return S_OK;
- }
- else if(m_mt.subtype == FOURCCMap('1CVA') || m_mt.subtype == FOURCCMap('1cva')) // just like aac, this has to be starting nalus, more can be packed together
- {
- if(!m_p)
- {
+ } else if(m_mt.subtype == FOURCCMap('1CVA') || m_mt.subtype == FOURCCMap('1cva')) { // just like aac, this has to be starting nalus, more can be packed together
+ if(!m_p) {
m_p.Attach(DNew Packet());
m_p->TrackNumber = p->TrackNumber;
m_p->bDiscontinuity = p->bDiscontinuity;
@@ -1333,15 +1313,20 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
BYTE* start = m_p->GetData();
BYTE* end = start + m_p->GetCount();
- while(start <= end-4 && *(DWORD*)start != 0x01000000) start++;
+ while(start <= end-4 && *(DWORD*)start != 0x01000000) {
+ start++;
+ }
- while(start <= end-4)
- {
+ while(start <= end-4) {
BYTE* next = start+1;
- while(next <= end-4 && *(DWORD*)next != 0x01000000) next++;
+ while(next <= end-4 && *(DWORD*)next != 0x01000000) {
+ next++;
+ }
- if(next >= end-4) break;
+ if(next >= end-4) {
+ break;
+ }
int size = next - start;
@@ -1350,24 +1335,24 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
CAutoPtr<Packet> p2;
- while (Nalu.ReadNext())
- {
- DWORD dwNalLength =
+ while (Nalu.ReadNext()) {
+ DWORD dwNalLength =
((Nalu.GetDataLength() >> 24) & 0x000000ff) |
((Nalu.GetDataLength() >> 8) & 0x0000ff00) |
((Nalu.GetDataLength() << 8) & 0x00ff0000) |
((Nalu.GetDataLength() << 24) & 0xff000000);
CAutoPtr<Packet> p3(DNew Packet());
-
+
p3->SetCount (Nalu.GetDataLength()+sizeof(dwNalLength));
memcpy (p3->GetData(), &dwNalLength, sizeof(dwNalLength));
memcpy (p3->GetData()+sizeof(dwNalLength), Nalu.GetDataBuffer(), Nalu.GetDataLength());
-
- if (p2 == NULL)
+
+ if (p2 == NULL) {
p2 = p3;
- else
+ } else {
p2->Append(*p3);
+ }
}
p2->TrackNumber = m_p->TrackNumber;
@@ -1377,74 +1362,72 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
p2->bSyncPoint = m_p->bSyncPoint;
m_p->bSyncPoint = FALSE;
- p2->rtStart = m_p->rtStart; m_p->rtStart = Packet::INVALID_TIME;
+ p2->rtStart = m_p->rtStart;
+ m_p->rtStart = Packet::INVALID_TIME;
p2->rtStop = m_p->rtStop;
m_p->rtStop = Packet::INVALID_TIME;
- p2->pmt = m_p->pmt; m_p->pmt = NULL;
+ p2->pmt = m_p->pmt;
+ m_p->pmt = NULL;
m_pl.AddTail(p2);
- if(p->rtStart != Packet::INVALID_TIME)
- {
+ if(p->rtStart != Packet::INVALID_TIME) {
m_p->rtStart = p->rtStart;
m_p->rtStop = p->rtStop;
p->rtStart = Packet::INVALID_TIME;
}
- if(p->bDiscontinuity)
- {
+ if(p->bDiscontinuity) {
m_p->bDiscontinuity = p->bDiscontinuity;
p->bDiscontinuity = FALSE;
}
- if(p->bSyncPoint)
- {
+ if(p->bSyncPoint) {
m_p->bSyncPoint = p->bSyncPoint;
p->bSyncPoint = FALSE;
}
- if(m_p->pmt)
+ if(m_p->pmt) {
DeleteMediaType(m_p->pmt);
-
+ }
+
m_p->pmt = p->pmt;
p->pmt = NULL;
start = next;
}
- if(start > m_p->GetData())
- {
+ if(start > m_p->GetData()) {
m_p->RemoveAt(0, start - m_p->GetData());
}
- for(POSITION pos = m_pl.GetHeadPosition(); pos; m_pl.GetNext(pos))
- {
- if(pos == m_pl.GetHeadPosition())
+ for(POSITION pos = m_pl.GetHeadPosition(); pos; m_pl.GetNext(pos)) {
+ if(pos == m_pl.GetHeadPosition()) {
continue;
+ }
Packet* pPacket = m_pl.GetAt(pos);
BYTE* pData = pPacket->GetData();
- if((pData[4]&0x1f) == 0x09) m_fHasAccessUnitDelimiters = true;
+ if((pData[4]&0x1f) == 0x09) {
+ m_fHasAccessUnitDelimiters = true;
+ }
- if((pData[4]&0x1f) == 0x09 || !m_fHasAccessUnitDelimiters && pPacket->rtStart != Packet::INVALID_TIME)
- {
+ if((pData[4]&0x1f) == 0x09 || !m_fHasAccessUnitDelimiters && pPacket->rtStart != Packet::INVALID_TIME) {
p = m_pl.RemoveHead();
- while(pos != m_pl.GetHeadPosition())
- {
+ while(pos != m_pl.GetHeadPosition()) {
CAutoPtr<Packet> p2 = m_pl.RemoveHead();
p->Append(*p2);
}
HRESULT hr = __super::DeliverPacket(p);
- if(hr != S_OK) return hr;
+ if(hr != S_OK) {
+ return hr;
+ }
}
}
return S_OK;
- }
- else if(m_mt.subtype == FOURCCMap('1CVW') || m_mt.subtype == FOURCCMap('1cvw')) // just like aac, this has to be starting nalus, more can be packed together
- {
- if(!m_p)
- {
+ } else if(m_mt.subtype == FOURCCMap('1CVW') || m_mt.subtype == FOURCCMap('1cvw')) { // just like aac, this has to be starting nalus, more can be packed together
+ if(!m_p) {
m_p.Attach(DNew Packet());
m_p->TrackNumber = p->TrackNumber;
m_p->bDiscontinuity = p->bDiscontinuity;
@@ -1466,35 +1449,34 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
BYTE* end = start + m_p->GetCount();
bool bSeqFound = false;
- while(start <= end-4)
- {
- if (*(DWORD*)start == 0x0D010000)
- {
+ while(start <= end-4) {
+ if (*(DWORD*)start == 0x0D010000) {
bSeqFound = true;
break;
- }
- else if (*(DWORD*)start == 0x0F010000)
+ } else if (*(DWORD*)start == 0x0F010000) {
break;
+ }
start++;
}
- while(start <= end-4)
- {
+ while(start <= end-4) {
BYTE* next = start+1;
- while(next <= end-4)
- {
- if (*(DWORD*)next == 0x0D010000)
- {
- if (bSeqFound) break;
+ while(next <= end-4) {
+ if (*(DWORD*)next == 0x0D010000) {
+ if (bSeqFound) {
+ break;
+ }
bSeqFound = true;
- }
- else if (*(DWORD*)next == 0x0F010000)
+ } else if (*(DWORD*)next == 0x0F010000) {
break;
+ }
next++;
}
- if(next >= end-4) break;
+ if(next >= end-4) {
+ break;
+ }
int size = next - start - 4;
UNUSED_ALWAYS(size);
@@ -1519,27 +1501,27 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
p2->SetData(start, next - start);
HRESULT hr = __super::DeliverPacket(p2);
- if(hr != S_OK) return hr;
+ if(hr != S_OK) {
+ return hr;
+ }
- if(p->rtStart != Packet::INVALID_TIME)
- {
+ if(p->rtStart != Packet::INVALID_TIME) {
m_p->rtStart = p->rtStart;
m_p->rtStop = p->rtStop;
p->rtStart = Packet::INVALID_TIME;
}
- if(p->bDiscontinuity)
- {
+ if(p->bDiscontinuity) {
m_p->bDiscontinuity = p->bDiscontinuity;
p->bDiscontinuity = FALSE;
}
- if(p->bSyncPoint)
- {
+ if(p->bSyncPoint) {
m_p->bSyncPoint = p->bSyncPoint;
p->bSyncPoint = FALSE;
}
- if(m_p->pmt)
+ if(m_p->pmt) {
DeleteMediaType(m_p->pmt);
-
+ }
+
m_p->pmt = p->pmt;
p->pmt = NULL;
@@ -1547,60 +1529,58 @@ HRESULT CMpegSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
bSeqFound = (*(DWORD*)start == 0x0D010000);
}
- if(start > m_p->GetData())
- {
+ if(start > m_p->GetData()) {
m_p->RemoveAt(0, start - m_p->GetData());
}
return S_OK;
}
// DTS HD MA data is causing trouble with some filters, lets just remove it
- else if (m_bFilterDTSMA && ((m_mt.subtype == MEDIASUBTYPE_DTS || m_mt.subtype == MEDIASUBTYPE_WAVE_DTS)))
- {
+ else if (m_bFilterDTSMA && ((m_mt.subtype == MEDIASUBTYPE_DTS || m_mt.subtype == MEDIASUBTYPE_WAVE_DTS))) {
BYTE* start = p->GetData();
BYTE* end = start + p->GetCount();
- if (end - start < 4 && !p->pmt)
- return S_OK; // Should be invalid packet
+ if (end - start < 4 && !p->pmt) {
+ return S_OK; // Should be invalid packet
+ }
BYTE* hdr = start;
int Type;
- // 16 bits big endian bitstream
- if (hdr[0] == 0x7f && hdr[1] == 0xfe &&
- hdr[2] == 0x80 && hdr[3] == 0x01)
+ // 16 bits big endian bitstream
+ if (hdr[0] == 0x7f && hdr[1] == 0xfe &&
+ hdr[2] == 0x80 && hdr[3] == 0x01) {
Type = 16 + 32;
+ }
- // 16 bits low endian bitstream
- else if (hdr[0] == 0xfe && hdr[1] == 0x7f &&
- hdr[2] == 0x01 && hdr[3] == 0x80)
+ // 16 bits low endian bitstream
+ else if (hdr[0] == 0xfe && hdr[1] == 0x7f &&
+ hdr[2] == 0x01 && hdr[3] == 0x80) {
Type = 16;
+ }
- // 14 bits big endian bitstream
- else if (hdr[0] == 0x1f && hdr[1] == 0xff &&
- hdr[2] == 0xe8 && hdr[3] == 0x00 &&
- hdr[4] == 0x07 && (hdr[5] & 0xf0) == 0xf0)
+ // 14 bits big endian bitstream
+ else if (hdr[0] == 0x1f && hdr[1] == 0xff &&
+ hdr[2] == 0xe8 && hdr[3] == 0x00 &&
+ hdr[4] == 0x07 && (hdr[5] & 0xf0) == 0xf0) {
Type = 14 + 32;
+ }
- // 14 bits low endian bitstream
- else if (hdr[0] == 0xff && hdr[1] == 0x1f &&
- hdr[2] == 0x00 && hdr[3] == 0xe8 &&
- (hdr[4] & 0xf0) == 0xf0 && hdr[5] == 0x07)
+ // 14 bits low endian bitstream
+ else if (hdr[0] == 0xff && hdr[1] == 0x1f &&
+ hdr[2] == 0x00 && hdr[3] == 0xe8 &&
+ (hdr[4] & 0xf0) == 0xf0 && hdr[5] == 0x07) {
Type = 14;
+ }
- // no sync
- else if (!p->pmt)
- {
- return S_OK;
- }
- }
- else if (m_mt.subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO)
- {
+ // no sync
+ else if (!p->pmt) {
+ return S_OK;
+ }
+ } else if (m_mt.subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO) {
BYTE* start = p->GetData();
p->SetData(start + 4, p->GetCount() - 4);
- }
- else
- {
+ } else {
m_p.Free();
m_pl.RemoveAll();
}
@@ -1615,15 +1595,15 @@ STDMETHODIMP CMpegSplitterOutputPin::Connect(IPin* pReceivePin, const AM_MEDIA_T
PIN_INFO PinInfo;
GUID FilterClsid;
- if (SUCCEEDED (pReceivePin->QueryPinInfo (&PinInfo)))
- {
- if (SUCCEEDED (PinInfo.pFilter->GetClassID(&FilterClsid)))
- {
- if (FilterClsid == CLSID_DMOWrapperFilter)
+ if (SUCCEEDED (pReceivePin->QueryPinInfo (&PinInfo))) {
+ if (SUCCEEDED (PinInfo.pFilter->GetClassID(&FilterClsid))) {
+ if (FilterClsid == CLSID_DMOWrapperFilter) {
(static_cast<CMpegSplitterFilter*>(m_pFilter))->SetPipo(true);
+ }
// AC3 Filter did not support DTS-MA
- else if (FilterClsid == CLSID_AC3Filter)
+ else if (FilterClsid == CLSID_AC3Filter) {
m_bFilterDTSMA = true;
+ }
}
PinInfo.pFilter->Release();
}
diff --git a/src/filters/parser/MpegSplitter/MpegSplitter.h b/src/filters/parser/MpegSplitter/MpegSplitter.h
index a5155fa8c..abceb4cd9 100644
--- a/src/filters/parser/MpegSplitter/MpegSplitter.h
+++ b/src/filters/parser/MpegSplitter/MpegSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,7 +25,7 @@
#include "MpegSplitterFile.h"
class __declspec(uuid("DC257063-045F-4BE2-BD5B-E12279C464F0"))
-CMpegSplitterFilter : public CBaseSplitterFilter, public IAMStreamSelect
+ CMpegSplitterFilter : public CBaseSplitterFilter, public IAMStreamSelect
{
REFERENCE_TIME m_rtStartOffset;
bool m_pPipoBimbo;
@@ -47,22 +47,24 @@ protected:
public:
CMpegSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr, const CLSID& clsid = __uuidof(CMpegSplitterFilter));
- void SetPipo(bool bPipo) { m_pPipoBimbo = bPipo; };
+ void SetPipo(bool bPipo) {
+ m_pPipoBimbo = bPipo;
+ };
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
STDMETHODIMP GetClassID(CLSID* pClsID);
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
// IAMStreamSelect
- STDMETHODIMP Count(DWORD* pcStreams);
- STDMETHODIMP Enable(long lIndex, DWORD dwFlags);
- STDMETHODIMP Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD* pdwFlags, LCID* plcid, DWORD* pdwGroup, WCHAR** ppszName, IUnknown** ppObject, IUnknown** ppUnk);
+ STDMETHODIMP Count(DWORD* pcStreams);
+ STDMETHODIMP Enable(long lIndex, DWORD dwFlags);
+ STDMETHODIMP Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD* pdwFlags, LCID* plcid, DWORD* pdwGroup, WCHAR** ppszName, IUnknown** ppObject, IUnknown** ppUnk);
};
class __declspec(uuid("1365BE7A-C86A-473C-9A41-C0A6E82C9FA3"))
-CMpegSourceFilter : public CMpegSplitterFilter
+ CMpegSourceFilter : public CMpegSplitterFilter
{
public:
CMpegSourceFilter(LPUNKNOWN pUnk, HRESULT* phr, const CLSID& clsid = __uuidof(CMpegSourceFilter));
@@ -85,5 +87,7 @@ public:
CMpegSplitterOutputPin(CAtlArray<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
virtual ~CMpegSplitterOutputPin();
STDMETHODIMP Connect(IPin* pReceivePin, const AM_MEDIA_TYPE* pmt);
- void SetMaxShift(REFERENCE_TIME rtMaxShift) { m_rtMaxShift = rtMaxShift; };
+ void SetMaxShift(REFERENCE_TIME rtMaxShift) {
+ m_rtMaxShift = rtMaxShift;
+ };
};
diff --git a/src/filters/parser/MpegSplitter/MpegSplitterFile.cpp b/src/filters/parser/MpegSplitter/MpegSplitterFile.cpp
index 5200baec4..a3a129745 100644
--- a/src/filters/parser/MpegSplitter/MpegSplitterFile.cpp
+++ b/src/filters/parser/MpegSplitter/MpegSplitterFile.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -39,7 +39,9 @@ CMpegSplitterFile::CMpegSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr, bo
, m_ClipInfo(ClipInfo)
{
- if(SUCCEEDED(hr)) hr = Init();
+ if(SUCCEEDED(hr)) {
+ hr = Init();
+ }
}
HRESULT CMpegSplitterFile::Init()
@@ -52,104 +54,109 @@ HRESULT CMpegSplitterFile::Init()
Seek(0);
- if(m_type == us)
- {
- if(BitRead(32, true) == 'TFrc') Seek(0x67c);
+ if(m_type == us) {
+ if(BitRead(32, true) == 'TFrc') {
+ Seek(0x67c);
+ }
int cnt = 0, limit = 4;
- for(trhdr h; cnt < limit && Read(h); cnt++) Seek(h.next);
- if(cnt >= limit) m_type = ts;
+ for(trhdr h; cnt < limit && Read(h); cnt++) {
+ Seek(h.next);
+ }
+ if(cnt >= limit) {
+ m_type = ts;
+ }
}
Seek(0);
- if(m_type == us)
- {
+ if(m_type == us) {
int cnt = 0, limit = 4;
- for(pvahdr h; cnt < limit && Read(h); cnt++) Seek(GetPos() + h.length);
- if(cnt >= limit) m_type = pva;
+ for(pvahdr h; cnt < limit && Read(h); cnt++) {
+ Seek(GetPos() + h.length);
+ }
+ if(cnt >= limit) {
+ m_type = pva;
+ }
}
Seek(0);
- if(m_type == us)
- {
+ if(m_type == us) {
BYTE b;
- for(int i = 0; (i < 4 || GetPos() < 65536) && m_type == us && NextMpegStartCode(b); i++)
- {
- if(b == 0xba)
- {
+ for(int i = 0; (i < 4 || GetPos() < 65536) && m_type == us && NextMpegStartCode(b); i++) {
+ if(b == 0xba) {
pshdr h;
- if(Read(h))
- {
+ if(Read(h)) {
m_type = ps;
m_rate = int(h.bitrate/8);
break;
}
- }
- else if((b&0xe0) == 0xc0 // audio, 110xxxxx, mpeg1/2/3
- || (b&0xf0) == 0xe0 // video, 1110xxxx, mpeg1/2
- // || (b&0xbd) == 0xbd) // private stream 1, 0xbd, ac3/dts/lpcm/subpic
- || b == 0xbd) // private stream 1, 0xbd, ac3/dts/lpcm/subpic
- {
+ } else if((b&0xe0) == 0xc0 // audio, 110xxxxx, mpeg1/2/3
+ || (b&0xf0) == 0xe0 // video, 1110xxxx, mpeg1/2
+ // || (b&0xbd) == 0xbd) // private stream 1, 0xbd, ac3/dts/lpcm/subpic
+ || b == 0xbd) { // private stream 1, 0xbd, ac3/dts/lpcm/subpic
peshdr h;
- if(Read(h, b) && BitRead(24, true) == 0x000001)
+ if(Read(h, b) && BitRead(24, true) == 0x000001) {
m_type = es;
+ }
}
}
}
Seek(0);
- if(m_type == us)
+ if(m_type == us) {
return E_FAIL;
+ }
// min/max pts & bitrate
m_rtMin = m_posMin = _I64_MAX;
m_rtMax = m_posMax = 0;
- if(IsRandomAccess() || IsStreaming())
- {
- if(IsStreaming())
- {
- for(int i = 0; i < 20 || i < 50 && S_OK != HasMoreData(1024*100, 100); i++);
+ if(IsRandomAccess() || IsStreaming()) {
+ if(IsStreaming()) {
+ for(int i = 0; i < 20 || i < 50 && S_OK != HasMoreData(1024*100, 100); i++) {
+ ;
+ }
}
CAtlList<__int64> fps;
- for(int i = 0, j = 5; i <= j; i++)
+ for(int i = 0, j = 5; i <= j; i++) {
fps.AddTail(i*GetLength()/j);
+ }
- for(__int64 pfp = 0; fps.GetCount(); )
- {
+ for(__int64 pfp = 0; fps.GetCount(); ) {
__int64 fp = fps.RemoveHead();
fp = min(GetLength() - MEGABYTE/8, fp);
fp = max(pfp, fp);
__int64 nfp = fp + (pfp == 0 ? 5*MEGABYTE : MEGABYTE/8);
- if(FAILED(hr = SearchStreams(fp, nfp)))
+ if(FAILED(hr = SearchStreams(fp, nfp))) {
return hr;
+ }
pfp = nfp;
}
- }
- else
- {
- if(FAILED(hr = SearchStreams(0, MEGABYTE/8)))
+ } else {
+ if(FAILED(hr = SearchStreams(0, MEGABYTE/8))) {
return hr;
+ }
}
- if(m_posMax - m_posMin <= 0 || m_rtMax - m_rtMin <= 0)
+ if(m_posMax - m_posMin <= 0 || m_rtMax - m_rtMin <= 0) {
return E_FAIL;
+ }
int indicated_rate = m_rate;
int detected_rate = int(10000000i64 * (m_posMax - m_posMin) / (m_rtMax - m_rtMin));
// normally "detected" should always be less than "indicated", but sometimes it can be a few percent higher (+10% is allowed here)
// (update: also allowing +/-50k/s)
- if(indicated_rate == 0 || ((float)detected_rate / indicated_rate) < 1.1 || abs(detected_rate - indicated_rate) < 50*1024)
+ if(indicated_rate == 0 || ((float)detected_rate / indicated_rate) < 1.1 || abs(detected_rate - indicated_rate) < 50*1024) {
m_rate = detected_rate;
- else ; // TODO: in this case disable seeking, or try doing something less drastical...
+ } else {
+ ; // TODO: in this case disable seeking, or try doing something less drastical...
+ }
- if(m_streams[video].GetCount())
- {
- if (!m_bIsHdmv && m_streams[subpic].GetCount())
- {
+ if(m_streams[video].GetCount()) {
+ if (!m_bIsHdmv && m_streams[subpic].GetCount()) {
#ifndef DEBUG
stream s;
s.mt.majortype = m_streams[subpic].GetHead().mt.majortype;
@@ -157,9 +164,7 @@ HRESULT CMpegSplitterFile::Init()
s.mt.formattype = m_streams[subpic].GetHead().mt.formattype;
m_streams[subpic].Insert(s, this);
#endif
- }
- else
- {
+ } else {
// Add fake stream for "No subtitle"
//AddHdmvPGStream (NO_SUBTITLE_PID, "---");
}
@@ -174,15 +179,16 @@ void CMpegSplitterFile::OnComplete()
{
__int64 pos = GetPos();
- if(SUCCEEDED(SearchStreams(GetLength() - 500*1024, GetLength())))
- {
+ if(SUCCEEDED(SearchStreams(GetLength() - 500*1024, GetLength()))) {
int indicated_rate = m_rate;
int detected_rate = int(m_rtMax > m_rtMin ? 10000000i64 * (m_posMax - m_posMin) / (m_rtMax - m_rtMin) : 0);
// normally "detected" should always be less than "indicated", but sometimes it can be a few percent higher (+10% is allowed here)
// (update: also allowing +/-50k/s)
- if(indicated_rate == 0 || ((float)detected_rate / indicated_rate) < 1.1 || abs(detected_rate - indicated_rate) < 50*1024)
+ if(indicated_rate == 0 || ((float)detected_rate / indicated_rate) < 1.1 || abs(detected_rate - indicated_rate) < 50*1024) {
m_rate = detected_rate;
- else ; // TODO: in this case disable seeking, or try doing something less drastical...
+ } else {
+ ; // TODO: in this case disable seeking, or try doing something less drastical...
+ }
}
Seek(pos);
@@ -195,12 +201,9 @@ REFERENCE_TIME CMpegSplitterFile::NextPTS(DWORD TrackNum)
BYTE b;
- while(GetRemaining())
- {
- if(m_type == ps || m_type == es)
- {
- if(!NextMpegStartCode(b)) // continue;
- {
+ while(GetRemaining()) {
+ if(m_type == ps || m_type == es) {
+ if(!NextMpegStartCode(b)) { // continue;
ASSERT(0);
break;
}
@@ -214,12 +217,13 @@ REFERENCE_TIME CMpegSplitterFile::NextPTS(DWORD TrackNum)
#endif
{
peshdr h;
- if(!Read(h, b) || !h.len) continue;
+ if(!Read(h, b) || !h.len) {
+ continue;
+ }
__int64 pos = GetPos();
- if(h.fpts && AddStream(0, b, h.len) == TrackNum)
- {
+ if(h.fpts && AddStream(0, b, h.len) == TrackNum) {
ASSERT(h.pts >= m_rtMin && h.pts <= m_rtMax);
rt = h.pts;
break;
@@ -227,21 +231,18 @@ REFERENCE_TIME CMpegSplitterFile::NextPTS(DWORD TrackNum)
Seek(pos + h.len);
}
- }
- else if(m_type == ts)
- {
+ } else if(m_type == ts) {
trhdr h;
- if(!Read(h)) continue;
+ if(!Read(h)) {
+ continue;
+ }
rtpos = GetPos()-4;
- if(h.payload && h.payloadstart && ISVALIDPID(h.pid))
- {
+ if(h.payload && h.payloadstart && ISVALIDPID(h.pid)) {
peshdr h2;
- if(NextMpegStartCode(b, 4) && Read(h2, b)) // pes packet
- {
- if(h2.fpts && AddStream(h.pid, b, DWORD(h.bytes - (GetPos() - rtpos)) == TrackNum))
- {
+ if(NextMpegStartCode(b, 4) && Read(h2, b)) { // pes packet
+ if(h2.fpts && AddStream(h.pid, b, DWORD(h.bytes - (GetPos() - rtpos)) == TrackNum)) {
ASSERT(h2.pts >= m_rtMin && h2.pts <= m_rtMax);
rt = h2.pts;
break;
@@ -250,22 +251,25 @@ REFERENCE_TIME CMpegSplitterFile::NextPTS(DWORD TrackNum)
}
Seek(h.next);
- }
- else if(m_type == pva)
- {
+ } else if(m_type == pva) {
pvahdr h;
- if(!Read(h)) continue;
+ if(!Read(h)) {
+ continue;
+ }
- if(h.fpts)
- {
+ if(h.fpts) {
rt = h.pts;
break;
}
}
}
- if(rtpos >= 0) Seek(rtpos);
- if(rt >= 0) rt -= m_rtMin;
+ if(rtpos >= 0) {
+ Seek(rtpos);
+ }
+ if(rt >= 0) {
+ rt -= m_rtMin;
+ }
return rt;
}
@@ -275,23 +279,24 @@ HRESULT CMpegSplitterFile::SearchStreams(__int64 start, __int64 stop)
Seek(start);
stop = min(stop, GetLength());
- while(GetPos() < stop)
- {
+ while(GetPos() < stop) {
BYTE b;
- if(m_type == ps || m_type == es)
- {
- if(!NextMpegStartCode(b)) continue;
+ if(m_type == ps || m_type == es) {
+ if(!NextMpegStartCode(b)) {
+ continue;
+ }
- if(b == 0xba) // program stream header
- {
+ if(b == 0xba) { // program stream header
pshdr h;
- if(!Read(h)) continue;
- }
- else if(b == 0xbb) // program stream system header
- {
+ if(!Read(h)) {
+ continue;
+ }
+ } else if(b == 0xbb) { // program stream system header
pssyshdr h;
- if(!Read(h)) continue;
+ if(!Read(h)) {
+ continue;
+ }
}
#if (EVO_SUPPORT == 0)
else if(b >= 0xbd && b < 0xf0) // pes packet
@@ -300,80 +305,84 @@ HRESULT CMpegSplitterFile::SearchStreams(__int64 start, __int64 stop)
#endif
{
peshdr h;
- if(!Read(h, b)) continue;
+ if(!Read(h, b)) {
+ continue;
+ }
- if(h.type == mpeg2 && h.scrambling) {ASSERT(0); return E_FAIL;}
+ if(h.type == mpeg2 && h.scrambling) {
+ ASSERT(0);
+ return E_FAIL;
+ }
- if(h.fpts)
- {
- if(m_rtMin == _I64_MAX) {m_rtMin = h.pts; m_posMin = GetPos();}
- if(m_rtMin < h.pts && m_rtMax < h.pts) {m_rtMax = h.pts; m_posMax = GetPos();}
+ if(h.fpts) {
+ if(m_rtMin == _I64_MAX) {
+ m_rtMin = h.pts;
+ m_posMin = GetPos();
+ }
+ if(m_rtMin < h.pts && m_rtMax < h.pts) {
+ m_rtMax = h.pts;
+ m_posMax = GetPos();
+ }
}
__int64 pos = GetPos();
AddStream(0, b, h.len);
- if(h.len) Seek(pos + h.len);
+ if(h.len) {
+ Seek(pos + h.len);
+ }
}
- }
- else if(m_type == ts)
- {
+ } else if(m_type == ts) {
trhdr h;
- if(!Read(h)) continue;
+ if(!Read(h)) {
+ continue;
+ }
__int64 pos = GetPos();
- if(h.payload && h.payloadstart)
+ if(h.payload && h.payloadstart) {
UpdatePrograms(h);
-
- if(h.payload && ISVALIDPID(h.pid))
- {
+ }
+
+ if(h.payload && ISVALIDPID(h.pid)) {
peshdr h2;
- if(h.payloadstart && NextMpegStartCode(b, 4) && Read(h2, b)) // pes packet
- {
- if(h2.type == mpeg2 && h2.scrambling)
- {
+ if(h.payloadstart && NextMpegStartCode(b, 4) && Read(h2, b)) { // pes packet
+ if(h2.type == mpeg2 && h2.scrambling) {
ASSERT(0);
return E_FAIL;
}
- if(h2.fpts)
- {
- if(m_rtMin == _I64_MAX)
- {
+ if(h2.fpts) {
+ if(m_rtMin == _I64_MAX) {
m_rtMin = h2.pts;
m_posMin = GetPos();
}
-
- if(m_rtMin < h2.pts && m_rtMax < h2.pts)
- {
+
+ if(m_rtMin < h2.pts && m_rtMax < h2.pts) {
m_rtMax = h2.pts;
m_posMax = GetPos();
}
}
- }
- else
+ } else {
b = 0;
+ }
AddStream(h.pid, b, DWORD(h.bytes - (GetPos() - pos)));
}
Seek(h.next);
- }
- else if(m_type == pva)
- {
+ } else if(m_type == pva) {
pvahdr h;
- if(!Read(h)) continue;
+ if(!Read(h)) {
+ continue;
+ }
- if(h.fpts)
- {
- if(m_rtMin == _I64_MAX)
- {
+ if(h.fpts) {
+ if(m_rtMin == _I64_MAX) {
m_rtMin = h.pts;
m_posMin = GetPos();
}
- if(m_rtMin < h.pts && m_rtMax < h.pts)
- {
+ if(m_rtMin < h.pts && m_rtMax < h.pts) {
m_rtMax = h.pts;
m_posMax = GetPos();
}
@@ -381,13 +390,15 @@ HRESULT CMpegSplitterFile::SearchStreams(__int64 start, __int64 stop)
__int64 pos = GetPos();
- if(h.streamid == 1)
+ if(h.streamid == 1) {
AddStream(h.streamid, 0xe0, h.length);
- else if(h.streamid == 2)
+ } else if(h.streamid == 2) {
AddStream(h.streamid, 0xc0, h.length);
+ }
- if(h.length)
+ if(h.length) {
Seek(pos + h.length);
+ }
}
}
@@ -396,10 +407,12 @@ HRESULT CMpegSplitterFile::SearchStreams(__int64 start, __int64 stop)
DWORD CMpegSplitterFile::AddStream(WORD pid, BYTE pesid, DWORD len)
{
- if(pid)
- {
- if(pesid) m_pid2pes[pid] = pesid;
- else m_pid2pes.Lookup(pid, pesid);
+ if(pid) {
+ if(pesid) {
+ m_pid2pes[pid] = pesid;
+ } else {
+ m_pid2pes.Lookup(pid, pesid);
+ }
}
stream s;
@@ -408,113 +421,102 @@ DWORD CMpegSplitterFile::AddStream(WORD pid, BYTE pesid, DWORD len)
int type = unknown;
- if(pesid >= 0xe0 && pesid < 0xf0) // mpeg video
- {
+ if(pesid >= 0xe0 && pesid < 0xf0) { // mpeg video
__int64 pos = GetPos();
- if(type == unknown)
- {
+ if(type == unknown) {
CMpegSplitterFile::seqhdr h;
- if(!m_streams[video].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[video].Find(s) && Read(h, len, &s.mt)) {
type = video;
+ }
}
Seek(pos);
- if(type == unknown)
- {
-// CMpegSplitterFile::avchdr h; <= PPS and SPS can be present on differents packets !
- if(!m_streams[video].Find(s) && Read(avch, len, &s.mt))
+ if(type == unknown) {
+ // CMpegSplitterFile::avchdr h; <= PPS and SPS can be present on differents packets !
+ if(!m_streams[video].Find(s) && Read(avch, len, &s.mt)) {
type = video;
+ }
}
- }
- else if(pesid >= 0xc0 && pesid < 0xe0) // mpeg audio
- {
+ } else if(pesid >= 0xc0 && pesid < 0xe0) { // mpeg audio
__int64 pos = GetPos();
- if(type == unknown)
- {
+ if(type == unknown) {
CMpegSplitterFile::mpahdr h;
- if(!m_streams[audio].Find(s) && Read(h, len, false, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, len, false, &s.mt)) {
type = audio;
+ }
}
Seek(pos);
- if(type == unknown)
- {
+ if(type == unknown) {
CMpegSplitterFile::aachdr h;
- if(!m_streams[audio].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, len, &s.mt)) {
type = audio;
+ }
}
- }
- else if(pesid == 0xbd || pesid == 0xfd) // private stream 1
- {
- if(s.pid)
- {
- if(!m_streams[audio].Find(s) && !m_streams[video].Find(s))
- {
+ } else if(pesid == 0xbd || pesid == 0xfd) { // private stream 1
+ if(s.pid) {
+ if(!m_streams[audio].Find(s) && !m_streams[video].Find(s)) {
__int64 pos = GetPos();
// AC3
- if(type == unknown)
- {
+ if(type == unknown) {
CMpegSplitterFile::ac3hdr h;
- if(Read(h, len, &s.mt))
+ if(Read(h, len, &s.mt)) {
type = audio;
+ }
}
// DTS
Seek(pos);
- if(type == unknown)
- {
+ if(type == unknown) {
CMpegSplitterFile::dtshdr h;
- if(Read(h, len, &s.mt))
+ if(Read(h, len, &s.mt)) {
type = audio;
+ }
}
// VC1
- Seek(pos);
- if(type == unknown)
- {
+ Seek(pos);
+ if(type == unknown) {
CMpegSplitterFile::vc1hdr h;
- if(!m_streams[video].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[video].Find(s) && Read(h, len, &s.mt)) {
type = video;
+ }
}
// DVB subtitles
- Seek(pos);
- if(type == unknown)
- {
+ Seek(pos);
+ if(type == unknown) {
CMpegSplitterFile::dvbsub h;
- if(!m_streams[video].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[video].Find(s) && Read(h, len, &s.mt)) {
type = subpic;
+ }
}
int iProgram;
const CHdmvClipInfo::Stream *pClipInfo;
const program* pProgram = FindProgram (s.pid, iProgram, pClipInfo);
- if((type == unknown) && (pProgram != NULL))
- {
+ if((type == unknown) && (pProgram != NULL)) {
PES_STREAM_TYPE StreamType = INVALID;
-
+
Seek(pos);
StreamType = pProgram->streams[iProgram].type;
- switch (StreamType)
- {
- case AUDIO_STREAM_LPCM :
- {
+ switch (StreamType) {
+ case AUDIO_STREAM_LPCM : {
CMpegSplitterFile::hdmvlpcmhdr h;
- if(!m_streams[audio].Find(s) && Read(h, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, &s.mt)) {
type = audio;
+ }
}
break;
- case PRESENTATION_GRAPHICS_STREAM :
- {
+ case PRESENTATION_GRAPHICS_STREAM : {
CMpegSplitterFile::hdmvsubhdr h;
- if(!m_streams[subpic].Find(s) && Read(h, &s.mt, pClipInfo ? pClipInfo->m_LanguageCode : NULL))
- {
+ if(!m_streams[subpic].Find(s) && Read(h, &s.mt, pClipInfo ? pClipInfo->m_LanguageCode : NULL)) {
m_bIsHdmv = true;
type = subpic;
}
@@ -525,129 +527,110 @@ DWORD CMpegSplitterFile::AddStream(WORD pid, BYTE pesid, DWORD len)
}
}
#if (EVO_SUPPORT != 0)
- else if (pesid == 0xfd) // TODO EVO SUPPORT
- {
+ else if (pesid == 0xfd) { // TODO EVO SUPPORT
CMpegSplitterFile::vc1hdr h;
- if(!m_streams[video].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[video].Find(s) && Read(h, len, &s.mt)) {
type = video;
+ }
}
#endif
- else
- {
+ else {
BYTE b = (BYTE)BitRead(8, true);
WORD w = (WORD)BitRead(16, true);
DWORD dw = (DWORD)BitRead(32, true);
- if(b >= 0x80 && b < 0x88 || w == 0x0b77) // ac3
- {
+ if(b >= 0x80 && b < 0x88 || w == 0x0b77) { // ac3
s.ps1id = (b >= 0x80 && b < 0x88) ? (BYTE)(BitRead(32) >> 24) : 0x80;
-
+
CMpegSplitterFile::ac3hdr h;
- if(!m_streams[audio].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, len, &s.mt)) {
type = audio;
- }
- else if(b >= 0x88 && b < 0x90 || dw == 0x7ffe8001) // dts
- {
+ }
+ } else if(b >= 0x88 && b < 0x90 || dw == 0x7ffe8001) { // dts
s.ps1id = (b >= 0x88 && b < 0x90) ? (BYTE)(BitRead(32) >> 24) : 0x88;
CMpegSplitterFile::dtshdr h;
- if(!m_streams[audio].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, len, &s.mt)) {
type = audio;
- }
- else if(b >= 0xa0 && b < 0xa8) // lpcm
- {
+ }
+ } else if(b >= 0xa0 && b < 0xa8) { // lpcm
s.ps1id = (b >= 0xa0 && b < 0xa8) ? (BYTE)(BitRead(32) >> 24) : 0xa0;
-
+
CMpegSplitterFile::lpcmhdr h;
- if(Read(h, &s.mt) && !m_streams[audio].Find(s)) // note the reversed order, the header should be stripped always even if it's not a new stream
+ if(Read(h, &s.mt) && !m_streams[audio].Find(s)) { // note the reversed order, the header should be stripped always even if it's not a new stream
type = audio;
- }
- else if(b >= 0x20 && b < 0x40) // DVD subpic
- {
+ }
+ } else if(b >= 0x20 && b < 0x40) { // DVD subpic
s.ps1id = (BYTE)BitRead(8);
CMpegSplitterFile::dvdspuhdr h;
- if(!m_streams[subpic].Find(s) && Read(h, &s.mt))
+ if(!m_streams[subpic].Find(s) && Read(h, &s.mt)) {
type = subpic;
- }
- else if(b >= 0x70 && b < 0x80) // SVCD subpic
- {
+ }
+ } else if(b >= 0x70 && b < 0x80) { // SVCD subpic
s.ps1id = (BYTE)BitRead(8);
CMpegSplitterFile::svcdspuhdr h;
- if(!m_streams[subpic].Find(s) && Read(h, &s.mt))
+ if(!m_streams[subpic].Find(s) && Read(h, &s.mt)) {
type = subpic;
- }
- else if(b >= 0x00 && b < 0x10) // CVD subpic
- {
+ }
+ } else if(b >= 0x00 && b < 0x10) { // CVD subpic
s.ps1id = (BYTE)BitRead(8);
CMpegSplitterFile::cvdspuhdr h;
- if(!m_streams[subpic].Find(s) && Read(h, &s.mt))
+ if(!m_streams[subpic].Find(s) && Read(h, &s.mt)) {
type = subpic;
- }
- else if(w == 0xffa0 || w == 0xffa1) // ps2-mpg audio
- {
+ }
+ } else if(w == 0xffa0 || w == 0xffa1) { // ps2-mpg audio
s.ps1id = (BYTE)BitRead(8);
s.pid = (WORD)((BitRead(8) << 8) | BitRead(16)); // pid = 0xa000 | track id
CMpegSplitterFile::ps2audhdr h;
- if(!m_streams[audio].Find(s) && Read(h, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, &s.mt)) {
type = audio;
- }
- else if(w == 0xff90) // ps2-mpg ac3 or subtitles
- {
+ }
+ } else if(w == 0xff90) { // ps2-mpg ac3 or subtitles
s.ps1id = (BYTE)BitRead(8);
s.pid = (WORD)((BitRead(8) << 8) | BitRead(16)); // pid = 0x9000 | track id
w = (WORD)BitRead(16, true);
- if(w == 0x0b77)
- {
+ if(w == 0x0b77) {
CMpegSplitterFile::ac3hdr h;
- if(!m_streams[audio].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, len, &s.mt)) {
type = audio;
- }
- else if(w == 0x0000) // usually zero...
- {
+ }
+ } else if(w == 0x0000) { // usually zero...
CMpegSplitterFile::ps2subhdr h;
- if(!m_streams[subpic].Find(s) && Read(h, &s.mt))
+ if(!m_streams[subpic].Find(s) && Read(h, &s.mt)) {
type = subpic;
+ }
}
}
#if (EVO_SUPPORT != 0)
- else if(b >= 0xc0 && b < 0xc8) // dolby digital +
- {
+ else if(b >= 0xc0 && b < 0xc8) { // dolby digital +
s.ps1id = (BYTE)BitRead(8);
s.pid = (WORD)((BitRead(8) << 8) | BitRead(16)); // pid = 0x9000 | track id
w = (WORD)BitRead(16, true);
- if(w == 0x0b77)
- {
+ if(w == 0x0b77) {
CMpegSplitterFile::ac3hdr h;
- if(!m_streams[audio].Find(s) && Read(h, len, &s.mt))
+ if(!m_streams[audio].Find(s) && Read(h, len, &s.mt)) {
type = audio;
+ }
}
}
#endif
}
- }
- else if(pesid == 0xbe) // padding
- {
- }
- else if(pesid == 0xbf) // private stream 2
- {
+ } else if(pesid == 0xbe) { // padding
+ } else if(pesid == 0xbf) { // private stream 2
}
- if(type != unknown && !m_streams[type].Find(s))
- {
- if(s.pid)
- {
- for(int i = 0; i < unknown; i++)
- {
- if(m_streams[i].Find(s))
- {
+ if(type != unknown && !m_streams[type].Find(s)) {
+ if(s.pid) {
+ for(int i = 0; i < unknown; i++) {
+ if(m_streams[i].Find(s)) {
/*ASSERT(0);*/
return s;
}
@@ -669,8 +652,7 @@ void CMpegSplitterFile::AddHdmvPGStream(WORD pid, const char* language_code)
s.pesid = 0xbd;
CMpegSplitterFile::hdmvsubhdr h;
- if(!m_streams[subpic].Find(s) && Read(h, &s.mt, language_code))
- {
+ if(!m_streams[subpic].Find(s) && Read(h, &s.mt, language_code)) {
m_streams[subpic].Insert(s, this);
}
}
@@ -690,46 +672,37 @@ void CMpegSplitterFile::UpdatePrograms(const trhdr& h)
{
CAutoLock cAutoLock(&m_csProps);
- if(h.pid == 0)
- {
+ if(h.pid == 0) {
trsechdr h2;
- if(Read(h2) && h2.table_id == 0)
- {
+ if(Read(h2) && h2.table_id == 0) {
CAtlMap<WORD, bool> newprograms;
int len = h2.section_length;
len -= 5+4;
- for(int i = len/4; i > 0; i--)
- {
+ for(int i = len/4; i > 0; i--) {
WORD program_number = (WORD)BitRead(16);
BYTE reserved = (BYTE)BitRead(3);
WORD pid = (WORD)BitRead(13);
UNUSED_ALWAYS(reserved);
- if(program_number != 0)
- {
+ if(program_number != 0) {
m_programs[pid].program_number = program_number;
newprograms[program_number] = true;
}
}
POSITION pos = m_programs.GetStartPosition();
- while(pos)
- {
+ while(pos) {
const CAtlMap<WORD, program>::CPair* pPair = m_programs.GetNext(pos);
- if(!newprograms.Lookup(pPair->m_value.program_number))
- {
+ if(!newprograms.Lookup(pPair->m_value.program_number)) {
m_programs.RemoveKey(pPair->m_key);
}
}
}
- }
- else if(CAtlMap<WORD, program>::CPair* pPair = m_programs.Lookup(h.pid))
- {
+ } else if(CAtlMap<WORD, program>::CPair* pPair = m_programs.Lookup(h.pid)) {
trsechdr h2;
- if(Read(h2) && h2.table_id == 2)
- {
+ if(Read(h2) && h2.table_id == 2) {
memset(pPair->m_value.streams, 0, sizeof(pPair->m_value.streams));
int len = h2.section_length;
@@ -745,11 +718,11 @@ void CMpegSplitterFile::UpdatePrograms(const trhdr& h)
len -= 4+program_info_length;
- while(program_info_length-- > 0)
+ while(program_info_length-- > 0) {
BitRead(8);
+ }
- for(int i = 0; i < countof(pPair->m_value.streams) && len >= 5; i++)
- {
+ for(int i = 0; i < countof(pPair->m_value.streams) && len >= 5; i++) {
BYTE stream_type = (BYTE)BitRead(8);
BYTE nreserved1 = (BYTE)BitRead(3);
WORD pid = (WORD)BitRead(13);
@@ -760,8 +733,9 @@ void CMpegSplitterFile::UpdatePrograms(const trhdr& h)
len -= 5+ES_info_length;
- while(ES_info_length-- > 0)
+ while(ES_info_length-- > 0) {
BitRead(8);
+ }
pPair->m_value.streams[i].pid = pid;
pPair->m_value.streams[i].type = (PES_STREAM_TYPE)stream_type;
@@ -789,14 +763,11 @@ const CMpegSplitterFile::program* CMpegSplitterFile::FindProgram(WORD pid, int &
POSITION pos = m_programs.GetStartPosition();
- while(pos)
- {
+ while(pos) {
program* p = &m_programs.GetNextValue(pos);
- for(int i = 0; i < countof(p->streams); i++)
- {
- if(p->streams[i].pid == pid)
- {
+ for(int i = 0; i < countof(p->streams); i++) {
+ if(p->streams[i].pid == pid) {
iStream = i;
return p;
}
diff --git a/src/filters/parser/MpegSplitter/MpegSplitterFile.h b/src/filters/parser/MpegSplitter/MpegSplitterFile.h
index 1e52ea697..899cef789 100644
--- a/src/filters/parser/MpegSplitter/MpegSplitterFile.h
+++ b/src/filters/parser/MpegSplitter/MpegSplitterFile.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -53,16 +53,21 @@ public:
__int64 m_posMin, m_posMax;
int m_rate; // byte/sec
- struct stream
- {
+ struct stream {
CMpegSplitterFile *m_pFile;
CMediaType mt;
WORD pid;
BYTE pesid, ps1id;
bool operator < (const stream &_Other) const;
- struct stream() {pid = pesid = ps1id = 0;}
- operator DWORD() const {return pid ? pid : ((pesid<<8)|ps1id);}
- bool operator == (const struct stream& s) const {return (DWORD)*this == (DWORD)s;}
+ struct stream() {
+ pid = pesid = ps1id = 0;
+ }
+ operator DWORD() const {
+ return pid ? pid : ((pesid<<8)|ps1id);
+ }
+ bool operator == (const struct stream& s) const {
+ return (DWORD)*this == (DWORD)s;
+ }
};
enum {video, audio, subpic, unknown};
@@ -70,33 +75,33 @@ public:
class CStreamList : public CAtlList<stream>
{
public:
- void Insert(stream& s, CMpegSplitterFile *_pFile)
- {
+ void Insert(stream& s, CMpegSplitterFile *_pFile) {
s.m_pFile = _pFile;
- for(POSITION pos = GetHeadPosition(); pos; GetNext(pos))
- {
+ for(POSITION pos = GetHeadPosition(); pos; GetNext(pos)) {
stream& s2 = GetAt(pos);
- if(s < s2) {InsertBefore(pos, s); return;}
+ if(s < s2) {
+ InsertBefore(pos, s);
+ return;
+ }
}
AddTail(s);
}
- static CStringW ToString(int type)
- {
- return
- type == video ? L"Video" :
- type == audio ? L"Audio" :
- type == subpic ? L"Subtitle" :
+ static CStringW ToString(int type) {
+ return
+ type == video ? L"Video" :
+ type == audio ? L"Audio" :
+ type == subpic ? L"Subtitle" :
L"Unknown";
}
- const stream* FindStream(int pid)
- {
- for(POSITION pos = GetHeadPosition(); pos; GetNext(pos))
- {
+ const stream* FindStream(int pid) {
+ for(POSITION pos = GetHeadPosition(); pos; GetNext(pos)) {
const stream& s = GetAt(pos);
- if(s.pid == pid) return &s;
+ if(s.pid == pid) {
+ return &s;
+ }
}
return NULL;
@@ -108,19 +113,21 @@ public:
DWORD AddStream(WORD pid, BYTE pesid, DWORD len);
void AddHdmvPGStream(WORD pid, const char* language_code);
CAtlList<stream>* GetMasterStream();
- bool IsHdmv() { return m_bIsHdmv; };
+ bool IsHdmv() {
+ return m_bIsHdmv;
+ };
- struct program
- {
+ struct program {
WORD program_number;
- struct stream
- {
+ struct stream {
WORD pid;
PES_STREAM_TYPE type;
};
stream streams[64];
- struct program() {memset(this, 0, sizeof(*this));}
+ struct program() {
+ memset(this, 0, sizeof(*this));
+ }
};
CAtlMap<WORD, program> m_programs;
@@ -128,5 +135,5 @@ public:
void UpdatePrograms(const trhdr& h);
const program* FindProgram(WORD pid, int &iStream, const CHdmvClipInfo::Stream * &_pClipInfo);
-
+
};
diff --git a/src/filters/parser/MpegSplitter/stdafx.cpp b/src/filters/parser/MpegSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/MpegSplitter/stdafx.cpp
+++ b/src/filters/parser/MpegSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/MpegSplitter/stdafx.h b/src/filters/parser/MpegSplitter/stdafx.h
index a72e6f179..5560c6425 100644
--- a/src/filters/parser/MpegSplitter/stdafx.h
+++ b/src/filters/parser/MpegSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/OggSplitter/OggFile.cpp b/src/filters/parser/OggSplitter/OggFile.cpp
index e8a3a6d1f..d90237a22 100644
--- a/src/filters/parser/OggSplitter/OggFile.cpp
+++ b/src/filters/parser/OggSplitter/OggFile.cpp
@@ -4,14 +4,18 @@
COggFile::COggFile(IAsyncReader* pAsyncReader, HRESULT& hr)
: CBaseSplitterFile(pAsyncReader, hr, DEFAULT_CACHE_LENGTH, false)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
hr = Init();
}
HRESULT COggFile::Init()
{
Seek(0);
- if(!Sync()) return E_FAIL;
+ if(!Sync()) {
+ return E_FAIL;
+ }
return S_OK;
}
@@ -22,12 +26,10 @@ bool COggFile::Sync(HANDLE hBreak)
DWORD dw;
for(__int64 i = 0, j = hBreak ? GetLength() - start : 65536;
- i < j && S_OK == ByteRead((BYTE*)&dw, sizeof(dw))
- && ((i&0xffff) || !hBreak || WaitForSingleObject(hBreak, 0) != WAIT_OBJECT_0);
- i++, Seek(start + i))
- {
- if(dw == 'SggO')
- {
+ i < j && S_OK == ByteRead((BYTE*)&dw, sizeof(dw))
+ && ((i&0xffff) || !hBreak || WaitForSingleObject(hBreak, 0) != WAIT_OBJECT_0);
+ i++, Seek(start + i)) {
+ if(dw == 'SggO') {
Seek(start + i);
return(true);
}
@@ -49,26 +51,30 @@ bool COggFile::Read(OggPage& page, bool fFull, HANDLE hBreak)
page.m_lens.RemoveAll();
page.SetCount(0);
- if(!Read(page.m_hdr, hBreak))
+ if(!Read(page.m_hdr, hBreak)) {
return(false);
+ }
int pagelen = 0, packetlen = 0;
- for(BYTE i = 0; i < page.m_hdr.number_page_segments; i++)
- {
+ for(BYTE i = 0; i < page.m_hdr.number_page_segments; i++) {
BYTE b;
- if(S_OK != ByteRead(&b, 1)) return(false);
+ if(S_OK != ByteRead(&b, 1)) {
+ return(false);
+ }
packetlen += b;
- if(1/*b < 0xff*/) {page.m_lens.AddTail(packetlen); pagelen += packetlen; packetlen = 0;}
+ if(1/*b < 0xff*/) {
+ page.m_lens.AddTail(packetlen);
+ pagelen += packetlen;
+ packetlen = 0;
+ }
}
- if(fFull)
- {
+ if(fFull) {
page.SetCount(pagelen);
- if(S_OK != ByteRead(page.GetData(), page.GetCount()))
+ if(S_OK != ByteRead(page.GetData(), page.GetCount())) {
return(false);
- }
- else
- {
+ }
+ } else {
Seek(GetPos() + pagelen);
page.m_lens.RemoveAll();
}
diff --git a/src/filters/parser/OggSplitter/OggFile.h b/src/filters/parser/OggSplitter/OggFile.h
index f37f01c0c..204013ddc 100644
--- a/src/filters/parser/OggSplitter/OggFile.h
+++ b/src/filters/parser/OggSplitter/OggFile.h
@@ -4,11 +4,11 @@
#pragma pack(push, 1)
-struct OggPageHeader
-{
+struct OggPageHeader {
DWORD capture_pattern;
BYTE stream_structure_version;
- BYTE header_type_flag; enum {continued=1, first=2, last=4};
+ BYTE header_type_flag;
+ enum {continued=1, first=2, last=4};
__int64 granule_position;
DWORD bitstream_serial_number;
DWORD page_sequence_number;
@@ -16,8 +16,7 @@ struct OggPageHeader
BYTE number_page_segments;
};
-struct OggVorbisIdHeader
-{
+struct OggVorbisIdHeader {
DWORD vorbis_version;
BYTE audio_channels;
DWORD audio_sample_rate;
@@ -29,27 +28,27 @@ struct OggVorbisIdHeader
BYTE framing_flag;
};
-struct OggVideoHeader
-{
+struct OggVideoHeader {
DWORD w, h;
};
-struct OggAudioHeader
-{
+struct OggAudioHeader {
WORD nChannels, nBlockAlign;
DWORD nAvgBytesPerSec;
};
-struct OggStreamHeader
-{
+struct OggStreamHeader {
char streamtype[8], subtype[4];
DWORD size;
__int64 time_unit, samples_per_unit;
DWORD default_len;
- DWORD buffersize;
+ DWORD buffersize;
WORD bps;
WORD alignmentfix1;
- union {OggVideoHeader v; OggAudioHeader a;};
+ union {
+ OggVideoHeader v;
+ OggAudioHeader a;
+ };
DWORD alignmentfix2;
};
#pragma pack(pop)
@@ -59,7 +58,9 @@ class OggPage : public CAtlArray<BYTE>
public:
OggPageHeader m_hdr;
CAtlList<int> m_lens;
- OggPage() {memset(&m_hdr, 0, sizeof(m_hdr));}
+ OggPage() {
+ memset(&m_hdr, 0, sizeof(m_hdr));
+ }
};
class COggFile : public CBaseSplitterFile
diff --git a/src/filters/parser/OggSplitter/OggSplitter.cpp b/src/filters/parser/OggSplitter/OggSplitter.cpp
index fa348c31f..7a341b12b 100644
--- a/src/filters/parser/OggSplitter/OggSplitter.cpp
+++ b/src/filters/parser/OggSplitter/OggSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -38,25 +38,21 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(COggSplitterFilter), L"MPC - Ogg Splitter", MERIT_NORMAL+1, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(COggSourceFilter), L"MPC - Ogg Source", MERIT_NORMAL+1, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<COggSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<COggSourceFilter>, NULL, &sudFilter[1]},
};
@@ -66,8 +62,8 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
RegisterSourceFilter(
- CLSID_AsyncReader,
- MEDIASUBTYPE_Ogg,
+ CLSID_AsyncReader,
+ MEDIASUBTYPE_Ogg,
_T("0,4,,4F676753"), // OggS
_T(".ogg"), _T(".ogm"), NULL);
@@ -96,35 +92,42 @@ class bitstream
BYTE* m_p;
int m_len, m_pos;
public:
- bitstream(BYTE* p, int len, bool rev = false) : m_p(p), m_len(len*8) {m_pos = !rev ? 0 : len*8;}
- bool hasbits(int cnt)
- {
+ bitstream(BYTE* p, int len, bool rev = false) : m_p(p), m_len(len*8) {
+ m_pos = !rev ? 0 : len*8;
+ }
+ bool hasbits(int cnt) {
int pos = m_pos+cnt;
return(pos >= 0 && pos < m_len);
}
- unsigned int showbits(int cnt) // a bit unclean, but works and can read backwards too! :P
- {
- if(!hasbits(cnt)) {ASSERT(0); return 0;}
+ unsigned int showbits(int cnt) { // a bit unclean, but works and can read backwards too! :P
+ if(!hasbits(cnt)) {
+ ASSERT(0);
+ return 0;
+ }
unsigned int ret = 0, off = 0;
BYTE* p = m_p;
- if(cnt < 0)
- {
+ if(cnt < 0) {
p += (m_pos+cnt)>>3;
off = (m_pos+cnt)&7;
cnt = abs(cnt);
- ret = (*p++&(~0<<off))>>off; off = 8 - off; cnt -= off;
- }
- else
- {
+ ret = (*p++&(~0<<off))>>off;
+ off = 8 - off;
+ cnt -= off;
+ } else {
p += m_pos>>3;
off = m_pos&7;
- ret = (*p++>>off)&((1<<min(cnt,8))-1); off = 0; cnt -= 8 - off;
+ ret = (*p++>>off)&((1<<min(cnt,8))-1);
+ off = 0;
+ cnt -= 8 - off;
+ }
+ while(cnt > 0) {
+ ret |= (*p++&((1<<min(cnt,8))-1)) << off;
+ off += 8;
+ cnt -= 8;
}
- while(cnt > 0) {ret |= (*p++&((1<<min(cnt,8))-1)) << off; off += 8; cnt -= 8;}
return ret;
}
- unsigned int getbits(int cnt)
- {
+ unsigned int getbits(int cnt) {
unsigned int ret = showbits(cnt);
m_pos += cnt;
return ret;
@@ -153,8 +156,13 @@ HRESULT COggSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew COggFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = 0;
@@ -163,12 +171,10 @@ HRESULT COggSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile->Seek(0);
OggPage page;
- for(int i = 0, nWaitForMore = 0; m_pFile->Read(page); i++)
- {
+ for(int i = 0, nWaitForMore = 0; m_pFile->Read(page); i++) {
BYTE* p = page.GetData();
- if(!(page.m_hdr.header_type_flag & OggPageHeader::continued))
- {
+ if(!(page.m_hdr.header_type_flag & OggPageHeader::continued)) {
BYTE type = *p++;
CStringW name;
@@ -176,110 +182,90 @@ HRESULT COggSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
HRESULT hr;
- if(type >= 0x80 && type <= 0x82 && !memcmp(p, "theora", 6))
- {
- if(type == 0x80)
- {
+ if(type >= 0x80 && type <= 0x82 && !memcmp(p, "theora", 6)) {
+ if(type == 0x80) {
name.Format(L"Theora %d", i);
CAutoPtr<CBaseSplitterOutputPin> pPinOut;
pPinOut.Attach(DNew COggTheoraOutputPin(page.GetData(), name, this, this, &hr));
AddOutputPin(page.m_hdr.bitstream_serial_number, pPinOut);
nWaitForMore++;
}
- }
- else if(type == 1 && (page.m_hdr.header_type_flag & OggPageHeader::first))
- {
+ } else if(type == 1 && (page.m_hdr.header_type_flag & OggPageHeader::first)) {
CAutoPtr<CBaseSplitterOutputPin> pPinOut;
- if(!memcmp(p, "vorbis", 6))
- {
+ if(!memcmp(p, "vorbis", 6)) {
name.Format(L"Vorbis %d", i);
pPinOut.Attach(DNew COggVorbisOutputPin((OggVorbisIdHeader*)(p+6), name, this, this, &hr));
nWaitForMore++;
- }
- else if(!memcmp(p, "video", 5))
- {
+ } else if(!memcmp(p, "video", 5)) {
name.Format(L"Video %d", i);
pPinOut.Attach(DNew COggVideoOutputPin((OggStreamHeader*)p, name, this, this, &hr));
- }
- else if(!memcmp(p, "audio", 5))
- {
+ } else if(!memcmp(p, "audio", 5)) {
name.Format(L"Audio %d", i);
pPinOut.Attach(DNew COggAudioOutputPin((OggStreamHeader*)p, name, this, this, &hr));
- }
- else if(!memcmp(p, "text", 4))
- {
+ } else if(!memcmp(p, "text", 4)) {
name.Format(L"Text %d", i);
pPinOut.Attach(DNew COggTextOutputPin((OggStreamHeader*)p, name, this, this, &hr));
- }
- else if(!memcmp(p, "Direct Show Samples embedded in Ogg", 35))
- {
+ } else if(!memcmp(p, "Direct Show Samples embedded in Ogg", 35)) {
name.Format(L"DirectShow %d", i);
pPinOut.Attach(DNew COggDirectShowOutputPin((AM_MEDIA_TYPE*)(p+35+sizeof(GUID)), name, this, this, &hr));
}
AddOutputPin(page.m_hdr.bitstream_serial_number, pPinOut);
- }
- else if(type == 3 && !memcmp(p, "vorbis", 6))
- {
- if(COggSplitterOutputPin* pOggPin =
- dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number)))
- {
+ } else if(type == 3 && !memcmp(p, "vorbis", 6)) {
+ if(COggSplitterOutputPin* pOggPin =
+ dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number))) {
pOggPin->AddComment(p+6, page.GetCount()-6-1);
}
- }
- else if(type == 0x7F && page.GetCount()>12 && *(long*)(p+8) == 0x43614C66) // Flac
- {
+ } else if(type == 0x7F && page.GetCount()>12 && *(long*)(p+8) == 0x43614C66) { // Flac
// Ogg Flac : method 1
CAutoPtr<CBaseSplitterOutputPin> pPinOut;
name.Format(L"Flac %d", i);
pPinOut.Attach(DNew COggFlacOutputPin(p+12, page.GetCount()-14, name, this, this, &hr));
AddOutputPin(page.m_hdr.bitstream_serial_number, pPinOut);
- }
- else if (*(long*)(p-1) == 0x43614C66)
- {
+ } else if (*(long*)(p-1) == 0x43614C66) {
//bFlac = true;
//nWaitForMore++;
- if (m_pFile->Read(page))
- {
+ if (m_pFile->Read(page)) {
CAutoPtr<CBaseSplitterOutputPin> pPinOut;
name.Format(L"Flac %d", i);
p = page.GetData();
pPinOut.Attach(DNew COggFlacOutputPin(p, page.GetCount(), name, this, this, &hr));
AddOutputPin(page.m_hdr.bitstream_serial_number, pPinOut);
}
- }
- else if(!(type&1) && nWaitForMore == 0)
- {
+ } else if(!(type&1) && nWaitForMore == 0) {
break;
}
}
- if(COggTheoraOutputPin* p = dynamic_cast<COggTheoraOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number)))
- {
+ if(COggTheoraOutputPin* p = dynamic_cast<COggTheoraOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number))) {
p->UnpackInitPage(page);
- if(p->IsInitialized()) nWaitForMore--;
+ if(p->IsInitialized()) {
+ nWaitForMore--;
+ }
}
- if(COggVorbisOutputPin* p = dynamic_cast<COggVorbisOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number)))
- {
+ if(COggVorbisOutputPin* p = dynamic_cast<COggVorbisOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number))) {
p->UnpackInitPage(page);
- if(p->IsInitialized()) nWaitForMore--;
+ if(p->IsInitialized()) {
+ nWaitForMore--;
+ }
}
}
- if(m_pOutputs.IsEmpty())
+ if(m_pOutputs.IsEmpty()) {
return E_FAIL;
+ }
- if(m_pFile->IsRandomAccess())
- {
+ if(m_pFile->IsRandomAccess()) {
m_pFile->Seek(max(m_pFile->GetLength()-65536, 0));
OggPage page;
- while(m_pFile->Read(page))
- {
+ while(m_pFile->Read(page)) {
COggSplitterOutputPin* pOggPin = dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number));
- if(!pOggPin || page.m_hdr.granule_position == -1) continue;
+ if(!pOggPin || page.m_hdr.granule_position == -1) {
+ continue;
+ }
REFERENCE_TIME rt = pOggPin->GetRefTime(page.m_hdr.granule_position);
m_rtDuration = max(rt, m_rtDuration);
}
@@ -298,20 +284,19 @@ HRESULT COggSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
tagmap[L"DESCRIPTION"] = L"DESC";
POSITION pos2 = tagmap.GetStartPosition();
- while(pos2)
- {
+ while(pos2) {
CStringW oggtag, dsmtag;
tagmap.GetNextAssoc(pos2, oggtag, dsmtag);
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
COggSplitterOutputPin* pOggPin = dynamic_cast<COggSplitterOutputPin*>((CBaseOutputPin*)m_pOutputs.GetNext(pos));
- if(!pOggPin) continue;
+ if(!pOggPin) {
+ continue;
+ }
CStringW value = pOggPin->GetComment(oggtag);
- if(!value.IsEmpty())
- {
+ if(!value.IsEmpty()) {
SetProperty(dsmtag, value);
break;
}
@@ -319,23 +304,29 @@ HRESULT COggSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
}
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos && !ChapGetCount())
- {
+ while(pos && !ChapGetCount()) {
COggSplitterOutputPin* pOggPin = dynamic_cast<COggSplitterOutputPin*>((CBaseOutputPin*)m_pOutputs.GetNext(pos));
- if(!pOggPin) continue;
+ if(!pOggPin) {
+ continue;
+ }
- for(int i = 1; pOggPin; i++)
- {
- CStringW key;
+ for(int i = 1; pOggPin; i++) {
+ CStringW key;
key.Format(L"CHAPTER%02d", i);
CStringW time = pOggPin->GetComment(key);
- if(time.IsEmpty()) break;
+ if(time.IsEmpty()) {
+ break;
+ }
key.Format(L"CHAPTER%02dNAME", i);
CStringW name = pOggPin->GetComment(key);
- if(name.IsEmpty()) name.Format(L"Chapter %d", i);
+ if(name.IsEmpty()) {
+ name.Format(L"Chapter %d", i);
+ }
int h, m, s, ms;
WCHAR c;
- if(7 != swscanf(time, L"%d%c%d%c%d%c%d", &h, &c, &m, &c, &s, &c, &ms)) break;
+ if(7 != swscanf(time, L"%d%c%d%c%d%c%d", &h, &c, &m, &c, &s, &c, &ms)) {
+ break;
+ }
REFERENCE_TIME rt = ((((REFERENCE_TIME)h*60+m)*60+s)*1000+ms)*10000;
ChapAppend(rt, name);
}
@@ -348,19 +339,18 @@ HRESULT COggSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
bool COggSplitterFilter::DemuxInit()
{
SetThreadName((DWORD)-1, "COggSplitterFilter");
- if(!m_pFile) return(false);
+ if(!m_pFile) {
+ return(false);
+ }
return(true);
}
void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
{
- if(rt <= 0 )
- {
+ if(rt <= 0 ) {
m_pFile->Seek(0);
- }
- else if(m_rtDuration > 0)
- {
+ } else if(m_rtDuration > 0) {
// oh, the horror...
__int64 len = m_pFile->GetLength();
@@ -369,19 +359,22 @@ void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
REFERENCE_TIME rtMinDiff = _I64_MAX;
- while(1)
- {
+ while(1) {
__int64 endpos = startpos;
REFERENCE_TIME rtPos = -1;
OggPage page;
m_pFile->Seek(startpos);
- while(m_pFile->Read(page, false))
- {
- if(page.m_hdr.granule_position == -1) continue;
+ while(m_pFile->Read(page, false)) {
+ if(page.m_hdr.granule_position == -1) {
+ continue;
+ }
COggSplitterOutputPin* pOggPin = dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number));
- if(!pOggPin) {ASSERT(0); continue;}
+ if(!pOggPin) {
+ ASSERT(0);
+ continue;
+ }
rtPos = pOggPin->GetRefTime(page.m_hdr.granule_position);
endpos = m_pFile->GetPos();
@@ -391,12 +384,10 @@ void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
__int64 rtDiff = rtPos - rt;
- if(rtDiff < 0)
- {
+ if(rtDiff < 0) {
rtDiff = -rtDiff;
- if(rtDiff < 1000000 || rtDiff >= rtMinDiff)
- {
+ if(rtDiff < 1000000 || rtDiff >= rtMinDiff) {
m_pFile->Seek(startpos);
break;
}
@@ -406,23 +397,20 @@ void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
__int64 newpos = startpos;
- if(rtPos < rt && rtPos < m_rtDuration)
- {
+ if(rtPos < rt && rtPos < m_rtDuration) {
newpos = startpos + (__int64)((1.0*(rt - rtPos)/(m_rtDuration - rtPos)) * (len - startpos)) + 1024;
- if(newpos < endpos) newpos = endpos + 1024;
- }
- else if(rtPos > rt && rtPos > 0)
- {
+ if(newpos < endpos) {
+ newpos = endpos + 1024;
+ }
+ } else if(rtPos > rt && rtPos > 0) {
newpos = startpos - (__int64)((1.0*(rtPos - rt)/(rtPos - 0)) * (startpos - 0)) - 1024;
- if(newpos >= startpos) newpos = startpos - 1024;
- }
- else if(rtPos == rt)
- {
+ if(newpos >= startpos) {
+ newpos = startpos - 1024;
+ }
+ } else if(rtPos == rt) {
m_pFile->Seek(startpos);
break;
- }
- else
- {
+ } else {
ASSERT(0);
m_pFile->Seek(0);
break;
@@ -436,55 +424,51 @@ void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
m_pFile->Seek(startpos);
POSITION pos = m_pOutputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
COggSplitterOutputPin* pPin = dynamic_cast<COggSplitterOutputPin*>(static_cast<CBaseSplitterOutputPin*>(m_pOutputs.GetNext(pos)));
- if(!dynamic_cast<COggVideoOutputPin*>(pPin) && !dynamic_cast<COggTheoraOutputPin*>(pPin))
+ if(!dynamic_cast<COggVideoOutputPin*>(pPin) && !dynamic_cast<COggTheoraOutputPin*>(pPin)) {
continue;
+ }
bool fKeyFrameFound = false, fSkipKeyFrame = true;
__int64 endpos = _I64_MAX;
- while(!(fKeyFrameFound && !fSkipKeyFrame) && startpos > 0)
- {
+ while(!(fKeyFrameFound && !fSkipKeyFrame) && startpos > 0) {
OggPage page;
- while(!(fKeyFrameFound && !fSkipKeyFrame) && m_pFile->GetPos() < endpos && m_pFile->Read(page))
- {
- if(page.m_hdr.granule_position == -1)
+ while(!(fKeyFrameFound && !fSkipKeyFrame) && m_pFile->GetPos() < endpos && m_pFile->Read(page)) {
+ if(page.m_hdr.granule_position == -1) {
continue;
+ }
- if(pPin != dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number)))
+ if(pPin != dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number))) {
continue;
+ }
- if(pPin->GetRefTime(page.m_hdr.granule_position) > rt)
+ if(pPin->GetRefTime(page.m_hdr.granule_position) > rt) {
break;
+ }
- if(!fKeyFrameFound)
- {
+ if(!fKeyFrameFound) {
pPin->UnpackPage(page);
CAutoPtr<OggPacket> p;
- while(p = pPin->GetPacket())
- {
- if(p->bSyncPoint)
- {
+ while(p = pPin->GetPacket()) {
+ if(p->bSyncPoint) {
fKeyFrameFound = true;
fSkipKeyFrame = p->fSkip;
}
}
- if(fKeyFrameFound) break;
- }
- else
- {
+ if(fKeyFrameFound) {
+ break;
+ }
+ } else {
pPin->UnpackPage(page);
CAutoPtr<OggPacket> p;
- while(p = pPin->GetPacket())
- {
- if(!p->fSkip)
- {
+ while(p = pPin->GetPacket()) {
+ if(!p->fSkip) {
fSkipKeyFrame = false;
break;
}
@@ -492,7 +476,10 @@ void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
}
}
- if(!(fKeyFrameFound && !fSkipKeyFrame)) {endpos = startpos; startpos = max(startpos - 10*65536, 0);}
+ if(!(fKeyFrameFound && !fSkipKeyFrame)) {
+ endpos = startpos;
+ startpos = max(startpos - 10*65536, 0);
+ }
m_pFile->Seek(startpos);
}
@@ -504,24 +491,25 @@ void COggSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
fKeyFrameFound = false;
OggPage page;
- while(!fKeyFrameFound && m_pFile->Read(page))
- {
- if(page.m_hdr.granule_position == -1) continue;
+ while(!fKeyFrameFound && m_pFile->Read(page)) {
+ if(page.m_hdr.granule_position == -1) {
+ continue;
+ }
- if(pPin != dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number)))
+ if(pPin != dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number))) {
continue;
+ }
REFERENCE_TIME rtPos = pPin->GetRefTime(page.m_hdr.granule_position);
- if(rtPos > rt)
+ if(rtPos > rt) {
break;
+ }
pPin->UnpackPage(page);
CAutoPtr<OggPacket> p;
- while(p = pPin->GetPacket())
- {
- if(p->bSyncPoint)
- {
+ while(p = pPin->GetPacket()) {
+ if(p->bSyncPoint) {
fKeyFrameFound = true;
break;
}
@@ -543,17 +531,24 @@ bool COggSplitterFilter::DemuxLoop()
HRESULT hr = S_OK;
OggPage page;
- while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->Read(page, true, GetRequestHandle()))
- {
+ while(SUCCEEDED(hr) && !CheckRequest(NULL) && m_pFile->Read(page, true, GetRequestHandle())) {
COggSplitterOutputPin* pOggPin = dynamic_cast<COggSplitterOutputPin*>(GetOutputPin(page.m_hdr.bitstream_serial_number));
- if(!pOggPin) {ASSERT(0); continue;}
- if(!pOggPin->IsConnected()) continue;
- if(FAILED(hr = pOggPin->UnpackPage(page))) {ASSERT(0); break;}
+ if(!pOggPin) {
+ ASSERT(0);
+ continue;
+ }
+ if(!pOggPin->IsConnected()) {
+ continue;
+ }
+ if(FAILED(hr = pOggPin->UnpackPage(page))) {
+ ASSERT(0);
+ break;
+ }
CAutoPtr<OggPacket> p;
- while(!CheckRequest(NULL) && SUCCEEDED(hr) && (p = pOggPin->GetPacket()))
- {
- if(!p->fSkip)
+ while(!CheckRequest(NULL) && SUCCEEDED(hr) && (p = pOggPin->GetPacket())) {
+ if(!p->fSkip) {
hr = DeliverPacket(p);
+ }
}
}
@@ -585,34 +580,27 @@ void COggSplitterOutputPin::AddComment(BYTE* p, int len)
{
bitstream bs(p, len);
bs.getbits(bs.getbits(32)*8);
- for(int n = bs.getbits(32); n-- > 0; )
- {
+ for(int n = bs.getbits(32); n-- > 0; ) {
CStringA str;
- for(int len = bs.getbits(32); len-- > 0; )
+ for(int len = bs.getbits(32); len-- > 0; ) {
str += (CHAR)bs.getbits(8);
+ }
CAtlList<CStringA> sl;
Explode(str, sl, '=', 2);
- if(sl.GetCount() == 2)
- {
+ if(sl.GetCount() == 2) {
CAutoPtr<CComment> p(DNew CComment(UTF8To16(sl.GetHead()), UTF8To16(sl.GetTail())));
- if(p->m_key == L"LANGUAGE")
- {
+ if(p->m_key == L"LANGUAGE") {
CString lang = ISO6392ToLanguage(sl.GetTail()), iso6392 = LanguageToISO6392(CString(p->m_value));
- if(p->m_value.GetLength() == 3 && !lang.IsEmpty())
- {
+ if(p->m_value.GetLength() == 3 && !lang.IsEmpty()) {
SetName(CStringW(lang));
SetProperty(L"LANG", p->m_value);
- }
- else if(!iso6392.IsEmpty())
- {
+ } else if(!iso6392.IsEmpty()) {
SetName(p->m_value);
SetProperty(L"LANG", CStringW(iso6392));
- }
- else
- {
+ } else {
SetName(p->m_value);
SetProperty(L"NAME", p->m_value);
}
@@ -629,10 +617,11 @@ CStringW COggSplitterOutputPin::GetComment(CStringW key)
key.MakeUpper();
CAtlList<CStringW> sl;
POSITION pos = m_pComments.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CComment* p = m_pComments.GetNext(pos);
- if(key == p->m_key) sl.AddTail(p->m_value);
+ if(key == p->m_key) {
+ sl.AddTail(p->m_value);
+ }
}
return Implode(sl, ';');
}
@@ -649,87 +638,88 @@ void COggSplitterOutputPin::ResetState(DWORD seqnum)
HRESULT COggSplitterOutputPin::UnpackPage(OggPage& page)
{
- if(m_lastseqnum != page.m_hdr.page_sequence_number-1)
- {
+ if(m_lastseqnum != page.m_hdr.page_sequence_number-1) {
ResetState(page.m_hdr.page_sequence_number);
return S_FALSE; // FIXME
- }
- else
- {
+ } else {
m_lastseqnum = page.m_hdr.page_sequence_number;
}
POSITION first = page.m_lens.GetHeadPosition();
- while(first && page.m_lens.GetAt(first) == 255) page.m_lens.GetNext(first);
- if(!first) first = page.m_lens.GetTailPosition();
+ while(first && page.m_lens.GetAt(first) == 255) {
+ page.m_lens.GetNext(first);
+ }
+ if(!first) {
+ first = page.m_lens.GetTailPosition();
+ }
POSITION last = page.m_lens.GetTailPosition();
- while(last && page.m_lens.GetAt(last) == 255) page.m_lens.GetPrev(last);
- if(!last) last = page.m_lens.GetTailPosition();
+ while(last && page.m_lens.GetAt(last) == 255) {
+ page.m_lens.GetPrev(last);
+ }
+ if(!last) {
+ last = page.m_lens.GetTailPosition();
+ }
BYTE* pData = page.GetData();
int i = 0, j = 0, len = 0;
- for(POSITION pos = page.m_lens.GetHeadPosition(); pos; page.m_lens.GetNext(pos))
- {
+ for(POSITION pos = page.m_lens.GetHeadPosition(); pos; page.m_lens.GetNext(pos)) {
len = page.m_lens.GetAt(pos);
j += len;
- if(len < 255 || pos == page.m_lens.GetTailPosition())
- {
- if(first == pos && (page.m_hdr.header_type_flag & OggPageHeader::continued))
- {
-// ASSERT(m_lastpacket);
+ if(len < 255 || pos == page.m_lens.GetTailPosition()) {
+ if(first == pos && (page.m_hdr.header_type_flag & OggPageHeader::continued)) {
+ // ASSERT(m_lastpacket);
- if(m_lastpacket)
- {
+ if(m_lastpacket) {
int size = m_lastpacket->GetCount();
m_lastpacket->SetCount(size + j-i);
memcpy(m_lastpacket->GetData() + size, pData + i, j-i);
CAutoLock csAutoLock(&m_csPackets);
- if(len < 255) m_packets.AddTail(m_lastpacket);
+ if(len < 255) {
+ m_packets.AddTail(m_lastpacket);
+ }
}
- }
- else
- {
+ } else {
CAutoPtr<OggPacket> p(DNew OggPacket());
- if(last == pos && page.m_hdr.granule_position != -1)
- {
+ if(last == pos && page.m_hdr.granule_position != -1) {
p->bDiscontinuity = m_fSkip;
-REFERENCE_TIME rtLast = m_rtLast;
+ REFERENCE_TIME rtLast = m_rtLast;
m_rtLast = GetRefTime(page.m_hdr.granule_position);
-// some bad encodings have a +/-1 frame difference from the normal timeline,
-// but these seem to cancel eachother out nicely so we can just ignore them
-// to make it play a bit more smooth.
-if(abs(rtLast - m_rtLast) == GetRefTime(1)) m_rtLast = rtLast; // FIXME
+ // some bad encodings have a +/-1 frame difference from the normal timeline,
+ // but these seem to cancel eachother out nicely so we can just ignore them
+ // to make it play a bit more smooth.
+ if(abs(rtLast - m_rtLast) == GetRefTime(1)) {
+ m_rtLast = rtLast; // FIXME
+ }
m_fSkip = false;
}
p->TrackNumber = page.m_hdr.bitstream_serial_number;
- if(S_OK == UnpackPacket(p, pData + i, j-i))
- {
-//if(p->TrackNumber == 1)
-//TRACE(_T("[%d]: %d, %I64d -> %I64d (skip=%d, disc=%d, sync=%d)\n"),
-// (int)p->TrackNumber, p->GetCount(), p->rtStart, p->rtStop,
-// (int)m_fSkip, (int)p->bDiscontinuity, (int)p->bSyncPoint);
+ if(S_OK == UnpackPacket(p, pData + i, j-i)) {
+ //if(p->TrackNumber == 1)
+ //TRACE(_T("[%d]: %d, %I64d -> %I64d (skip=%d, disc=%d, sync=%d)\n"),
+ // (int)p->TrackNumber, p->GetCount(), p->rtStart, p->rtStop,
+ // (int)m_fSkip, (int)p->bDiscontinuity, (int)p->bSyncPoint);
- if(p->rtStart <= p->rtStop && p->rtStop <= p->rtStart + 10000000i64*60)
- {
+ if(p->rtStart <= p->rtStop && p->rtStop <= p->rtStart + 10000000i64*60) {
CAutoLock csAutoLock(&m_csPackets);
m_rtLast = p->rtStop;
p->fSkip = m_fSkip;
- if(len < 255) m_packets.AddTail(p);
- else m_lastpacket = p;
- }
- else
- {
+ if(len < 255) {
+ m_packets.AddTail(p);
+ } else {
+ m_lastpacket = p;
+ }
+ } else {
ASSERT(0);
}
}
@@ -746,7 +736,9 @@ CAutoPtr<OggPacket> COggSplitterOutputPin::GetPacket()
{
CAutoPtr<OggPacket> p;
CAutoLock csAutoLock(&m_csPackets);
- if(m_packets.GetCount()) p = m_packets.RemoveHead();
+ if(m_packets.GetCount()) {
+ p = m_packets.RemoveHead();
+ }
return p;
}
@@ -807,17 +799,16 @@ HRESULT COggVorbisOutputPin::UnpackInitPage(OggPage& page)
{
HRESULT hr = __super::UnpackPage(page);
- while(m_packets.GetCount())
- {
+ while(m_packets.GetCount()) {
Packet* p = m_packets.GetHead();
- if(p->GetCount() >= 6 && p->GetAt(0) == 0x05)
- {
+ if(p->GetCount() >= 6 && p->GetAt(0) == 0x05) {
// yeah, right, we are going to be parsing this backwards! :P
bitstream bs(p->GetData(), p->GetCount(), true);
- while(bs.hasbits(-1) && bs.getbits(-1) != 1);
- for(int cnt = 0; bs.hasbits(-8-16-16-1-6); cnt++)
- {
+ while(bs.hasbits(-1) && bs.getbits(-1) != 1) {
+ ;
+ }
+ for(int cnt = 0; bs.hasbits(-8-16-16-1-6); cnt++) {
unsigned int modes = bs.showbits(-6)+1;
unsigned int mapping = bs.getbits(-8);
@@ -826,8 +817,7 @@ HRESULT COggVorbisOutputPin::UnpackInitPage(OggPage& page)
unsigned int blockflag = bs.getbits(-1);
UNUSED_ALWAYS(mapping);
- if(transformtype != 0 || windowtype != 0)
- {
+ if(transformtype != 0 || windowtype != 0) {
ASSERT(modes == cnt);
break;
}
@@ -837,14 +827,13 @@ HRESULT COggVorbisOutputPin::UnpackInitPage(OggPage& page)
}
int cnt = m_initpackets.GetCount();
- if(cnt <= 3)
- {
+ if(cnt <= 3) {
ASSERT(p->GetCount() >= 6 && p->GetAt(0) == 1+cnt*2);
VORBISFORMAT2* vf2 = (VORBISFORMAT2*)m_mts[0].Format();
vf2->HeaderSize[cnt] = p->GetCount();
int len = m_mts[0].FormatLength();
memcpy(
- m_mts[0].ReallocFormatBuffer(len + p->GetCount()) + len,
+ m_mts[0].ReallocFormatBuffer(len + p->GetCount()) + len,
p->GetData(), p->GetCount());
}
@@ -862,15 +851,18 @@ REFERENCE_TIME COggVorbisOutputPin::GetRefTime(__int64 granule_position)
HRESULT COggVorbisOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, int len)
{
- if(len > 0 && m_blockflags.GetCount())
- {
+ if(len > 0 && m_blockflags.GetCount()) {
bitstream bs(pData, len);
- if(bs.getbits(1) == 0)
- {
+ if(bs.getbits(1) == 0) {
int x = m_blockflags.GetCount()-1, n = 0;
- while(x) {n++; x >>= 1;}
+ while(x) {
+ n++;
+ x >>= 1;
+ }
DWORD blocksize = m_blocksize[m_blockflags[bs.getbits(n)]?1:0];
- if(m_lastblocksize) m_rtLast += GetRefTime((m_lastblocksize + blocksize) >> 2);
+ if(m_lastblocksize) {
+ m_rtLast += GetRefTime((m_lastblocksize + blocksize) >> 2);
+ }
m_lastblocksize = blocksize;
}
}
@@ -885,8 +877,9 @@ HRESULT COggVorbisOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, i
HRESULT COggVorbisOutputPin::DeliverPacket(CAutoPtr<OggPacket> p)
{
- if(p->GetCount() > 0 && (p->GetAt(0)&1))
+ if(p->GetCount() > 0 && (p->GetAt(0)&1)) {
return S_OK;
+ }
return __super::DeliverPacket(p);
}
@@ -897,11 +890,9 @@ HRESULT COggVorbisOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_
m_lastblocksize = 0;
- if(m_mt.subtype == MEDIASUBTYPE_Vorbis)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_Vorbis) {
POSITION pos = m_initpackets.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
Packet* pi = m_initpackets.GetNext(pos);
CAutoPtr<OggPacket> p(DNew OggPacket());
p->TrackNumber = pi->TrackNumber;
@@ -926,9 +917,10 @@ COggFlacOutputPin::COggFlacOutputPin(BYTE* h, int nCount, LPCWSTR pName, CBaseFi
Buffer.BitRead(1); // Last-metadata-block flag
- if (Buffer.BitRead(7) != 0) // Should be a STREAMINFO block
- {
- if(phr) *phr = VFW_E_INVALID_FILE_FORMAT;
+ if (Buffer.BitRead(7) != 0) { // Should be a STREAMINFO block
+ if(phr) {
+ *phr = VFW_E_INVALID_FILE_FORMAT;
+ }
return;
}
@@ -941,7 +933,7 @@ COggFlacOutputPin::COggFlacOutputPin(BYTE* h, int nCount, LPCWSTR pName, CBaseFi
m_nChannels = (int)Buffer.BitRead(3) + 1;
m_wBitsPerSample = (WORD)Buffer.BitRead(5) + 1;
Buffer.BitRead(36); // m_i64TotalNumSamples
- m_nAvgBytesPerSec = (m_nChannels * (m_wBitsPerSample >> 3)) * m_nSamplesPerSec;
+ m_nAvgBytesPerSec = (m_nChannels * (m_wBitsPerSample >> 3)) * m_nSamplesPerSec;
CMediaType mt;
@@ -971,8 +963,7 @@ REFERENCE_TIME COggFlacOutputPin::GetRefTime(__int64 granule_position)
HRESULT COggFlacOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, int len)
{
- if (pData[0] != 0xFF || (pData[1] & 0xFE) != 0xF8)
- {
+ if (pData[0] != 0xFF || (pData[1] & 0xFE) != 0xF8) {
return S_FALSE;
}
@@ -986,8 +977,9 @@ HRESULT COggFlacOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, int
HRESULT COggFlacOutputPin::DeliverPacket(CAutoPtr<OggPacket> p)
{
- if(p->GetCount() > 0 && (p->GetAt(0)&1))
+ if(p->GetCount() > 0 && (p->GetAt(0)&1)) {
return S_OK;
+ }
return __super::DeliverPacket(p);
}
@@ -998,11 +990,9 @@ HRESULT COggFlacOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TI
m_lastblocksize = 0;
- if(m_mt.subtype == MEDIASUBTYPE_FLAC_FRAMED)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_FLAC_FRAMED) {
POSITION pos = m_initpackets.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
Packet* pi = m_initpackets.GetNext(pos);
CAutoPtr<OggPacket> p(DNew OggPacket());
p->TrackNumber = pi->TrackNumber;
@@ -1026,20 +1016,18 @@ COggDirectShowOutputPin::COggDirectShowOutputPin(AM_MEDIA_TYPE* pmt, LPCWSTR pNa
memcpy((AM_MEDIA_TYPE*)&mt, pmt, FIELD_OFFSET(AM_MEDIA_TYPE, pUnk));
mt.SetFormat((BYTE*)(pmt+1), pmt->cbFormat);
mt.SetSampleSize(1);
- if(mt.majortype == MEDIATYPE_Video) // TODO: find samples for audio and find out what to return in GetRefTime...
+ if(mt.majortype == MEDIATYPE_Video) { // TODO: find samples for audio and find out what to return in GetRefTime...
m_mts.Add(mt);
+ }
}
REFERENCE_TIME COggDirectShowOutputPin::GetRefTime(__int64 granule_position)
{
REFERENCE_TIME rt = 0;
- if(m_mt.majortype == MEDIATYPE_Video)
- {
+ if(m_mt.majortype == MEDIATYPE_Video) {
rt = granule_position * ((VIDEOINFOHEADER*)m_mt.Format())->AvgTimePerFrame;
- }
- else if(m_mt.majortype == MEDIATYPE_Audio)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Audio) {
rt = granule_position; // ((WAVEFORMATEX*)m_mt.Format())-> // TODO
}
@@ -1052,15 +1040,18 @@ HRESULT COggDirectShowOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pDat
BYTE hdr = pData[i++];
- if(!(hdr&1))
- {
+ if(!(hdr&1)) {
// TODO: verify if this was still present in the old format (haven't found one sample yet)
BYTE nLenBytes = (hdr>>6)|((hdr&2)<<1);
__int64 Length = 0;
- for(int j = 0; j < nLenBytes; j++)
+ for(int j = 0; j < nLenBytes; j++) {
Length |= (__int64)pData[i++] << (j << 3);
+ }
- if(len < i) {ASSERT(0); return E_FAIL;}
+ if(len < i) {
+ ASSERT(0);
+ return E_FAIL;
+ }
p->bSyncPoint = !!(hdr&8);
p->rtStart = m_rtLast;
@@ -1096,14 +1087,17 @@ HRESULT COggStreamOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, i
BYTE hdr = pData[i++];
- if(!(hdr&1))
- {
+ if(!(hdr&1)) {
BYTE nLenBytes = (hdr>>6)|((hdr&2)<<1);
__int64 Length = 0;
- for(int j = 0; j < nLenBytes; j++)
+ for(int j = 0; j < nLenBytes; j++) {
Length |= (__int64)pData[i++] << (j << 3);
+ }
- if(len < i) {ASSERT(0); return E_FAIL;}
+ if(len < i) {
+ ASSERT(0);
+ return E_FAIL;
+ }
p->bSyncPoint = !!(hdr&8);
p->rtStart = m_rtLast;
@@ -1124,7 +1118,7 @@ COggVideoOutputPin::COggVideoOutputPin(OggStreamHeader* h, LPCWSTR pName, CBaseF
: COggStreamOutputPin(h, pName, pFilter, pLock, phr)
{
int extra = (int)h->size - sizeof(OggStreamHeader);
- extra = max(extra, 0);
+ extra = max(extra, 0);
CMediaType mt;
mt.majortype = MEDIATYPE_Video;
@@ -1138,19 +1132,24 @@ COggVideoOutputPin::COggVideoOutputPin(OggStreamHeader* h, LPCWSTR pName, CBaseF
pvih->bmiHeader.biHeight = h->v.h;
pvih->bmiHeader.biBitCount = (WORD)h->bps;
pvih->bmiHeader.biCompression = mt.subtype.Data1;
- switch(pvih->bmiHeader.biCompression)
- {
- case BI_RGB: case BI_BITFIELDS: mt.subtype =
- pvih->bmiHeader.biBitCount == 1 ? MEDIASUBTYPE_RGB1 :
- pvih->bmiHeader.biBitCount == 4 ? MEDIASUBTYPE_RGB4 :
- pvih->bmiHeader.biBitCount == 8 ? MEDIASUBTYPE_RGB8 :
- pvih->bmiHeader.biBitCount == 16 ? MEDIASUBTYPE_RGB565 :
- pvih->bmiHeader.biBitCount == 24 ? MEDIASUBTYPE_RGB24 :
- pvih->bmiHeader.biBitCount == 32 ? MEDIASUBTYPE_RGB32 :
- MEDIASUBTYPE_NULL;
- break;
- case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break;
- case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break;
+ switch(pvih->bmiHeader.biCompression) {
+ case BI_RGB:
+ case BI_BITFIELDS:
+ mt.subtype =
+ pvih->bmiHeader.biBitCount == 1 ? MEDIASUBTYPE_RGB1 :
+ pvih->bmiHeader.biBitCount == 4 ? MEDIASUBTYPE_RGB4 :
+ pvih->bmiHeader.biBitCount == 8 ? MEDIASUBTYPE_RGB8 :
+ pvih->bmiHeader.biBitCount == 16 ? MEDIASUBTYPE_RGB565 :
+ pvih->bmiHeader.biBitCount == 24 ? MEDIASUBTYPE_RGB24 :
+ pvih->bmiHeader.biBitCount == 32 ? MEDIASUBTYPE_RGB32 :
+ MEDIASUBTYPE_NULL;
+ break;
+ case BI_RLE8:
+ mt.subtype = MEDIASUBTYPE_RGB8;
+ break;
+ case BI_RLE4:
+ mt.subtype = MEDIASUBTYPE_RGB4;
+ break;
}
mt.SetSampleSize(max(h->buffersize, 1));
m_mts.Add(mt);
@@ -1164,7 +1163,7 @@ COggAudioOutputPin::COggAudioOutputPin(OggStreamHeader* h, LPCWSTR pName, CBaseF
: COggStreamOutputPin(h, pName, pFilter, pLock, phr)
{
int extra = (int)h->size - sizeof(OggStreamHeader);
- extra = max(extra, 0);
+ extra = max(extra, 0);
CMediaType mt;
mt.majortype = MEDIATYPE_Audio;
@@ -1218,18 +1217,19 @@ COggTheoraOutputPin::COggTheoraOutputPin(BYTE* p, LPCWSTR pName, CBaseFilter* pF
vih->hdr.bmiHeader.biBitCount = 24;
m_nFpsNum = (p[22]<<24)|(p[23]<<16)|(p[24]<<8)|p[25];
m_nFpsDenum = (p[26]<<24)|(p[27]<<16)|(p[28]<<8)|p[29];
- if(m_nFpsNum)
- {
+ if(m_nFpsNum) {
m_rtAvgTimePerFrame = (REFERENCE_TIME)(10000000.0 * m_nFpsDenum / m_nFpsNum);
vih->hdr.AvgTimePerFrame = m_rtAvgTimePerFrame;
}
vih->hdr.dwPictAspectRatioX = (p[14]<<16)|(p[15]<<8)|p[16];
vih->hdr.dwPictAspectRatioY = (p[17]<<16)|(p[18]<<8)|p[19];
-
+
m_KfgShift = (((p[40]<<8)+p[41]) &0x3E0) >> 5;
m_nIndexOffset = TH_VERSION_CHECK(p[7],p[8],p[9],3,2,1);
-
- if (m_KfgShift == 0) m_KfgShift = 6; // Is it really default value ?
+
+ if (m_KfgShift == 0) {
+ m_KfgShift = 6; // Is it really default value ?
+ }
mt.bFixedSizeSamples = 0;
m_mts.Add(mt);
@@ -1239,17 +1239,16 @@ HRESULT COggTheoraOutputPin::UnpackInitPage(OggPage& page)
{
HRESULT hr = __super::UnpackPage(page);
- while(m_packets.GetCount())
- {
+ while(m_packets.GetCount()) {
Packet* p = m_packets.GetHead();
CMediaType& mt = m_mts[0];
int size = p->GetCount();
ASSERT(size <= 0xffff);
MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.ReallocFormatBuffer(
- FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) +
- ((MPEG2VIDEOINFO*)mt.Format())->cbSequenceHeader +
- 2 + size);
+ FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) +
+ ((MPEG2VIDEOINFO*)mt.Format())->cbSequenceHeader +
+ 2 + size);
*(WORD*)((BYTE*)vih->dwSequenceHeader + vih->cbSequenceHeader) = (size>>8)|(size<<8);
memcpy((BYTE*)vih->dwSequenceHeader + vih->cbSequenceHeader + 2, p->GetData(), size);
vih->cbSequenceHeader += 2 + size;
@@ -1262,15 +1261,15 @@ HRESULT COggTheoraOutputPin::UnpackInitPage(OggPage& page)
REFERENCE_TIME COggTheoraOutputPin::GetRefTime(__int64 granule_position)
{
- LONGLONG iframe;
- LONGLONG pframe;
+ LONGLONG iframe;
+ LONGLONG pframe;
- iframe=granule_position>>m_KfgShift;
- pframe=granule_position-(iframe<<m_KfgShift);
- /*3.2.0 streams store the frame index in the granule position.
- 3.2.1 and later store the frame count.
- We return the index, so adjust the value if we have a 3.2.1 or later
- stream.*/
+ iframe=granule_position>>m_KfgShift;
+ pframe=granule_position-(iframe<<m_KfgShift);
+ /*3.2.0 streams store the frame index in the granule position.
+ 3.2.1 and later store the frame count.
+ We return the index, so adjust the value if we have a 3.2.1 or later
+ stream.*/
REFERENCE_TIME rt = 0;
rt = (iframe+pframe-m_nIndexOffset) * m_rtAvgTimePerFrame;
@@ -1284,8 +1283,9 @@ HRESULT COggTheoraOutputPin::UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, i
p->rtStop = m_rtLast+1;
p->SetData(pData, len);
- if(!(*pData & 0x80) && m_mt.majortype == MEDIATYPE_Video)
+ if(!(*pData & 0x80) && m_mt.majortype == MEDIATYPE_Video) {
p->rtStop = p->rtStart + ((MPEG2VIDEOINFO*)m_mt.Format())->hdr.AvgTimePerFrame;
+ }
return S_OK;
}
diff --git a/src/filters/parser/OggSplitter/OggSplitter.h b/src/filters/parser/OggSplitter/OggSplitter.h
index 5790ccad0..3d7ae5975 100644
--- a/src/filters/parser/OggSplitter/OggSplitter.h
+++ b/src/filters/parser/OggSplitter/OggSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -29,7 +29,9 @@
class OggPacket : public Packet
{
public:
- OggPacket() {fSkip = false;}
+ OggPacket() {
+ fSkip = false;
+ }
bool fSkip;
};
@@ -37,9 +39,11 @@ class COggSplitterOutputPin : public CBaseSplitterOutputPin
{
class CComment
{
- public:
- CStringW m_key, m_value;
- CComment(CStringW key, CStringW value) : m_key(key), m_value(value) {m_key.MakeUpper();}
+ public:
+ CStringW m_key, m_value;
+ CComment(CStringW key, CStringW value) : m_key(key), m_value(value) {
+ m_key.MakeUpper();
+ }
};
CAutoPtrList<CComment> m_pComments;
@@ -64,9 +68,9 @@ public:
virtual HRESULT UnpackPacket(CAutoPtr<OggPacket>& p, BYTE* pData, int len) = 0;
virtual REFERENCE_TIME GetRefTime(__int64 granule_position) = 0;
CAutoPtr<OggPacket> GetPacket();
-
+
HRESULT DeliverEndFlush();
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
};
class COggVorbisOutputPin : public COggSplitterOutputPin
@@ -81,13 +85,15 @@ class COggVorbisOutputPin : public COggSplitterOutputPin
virtual REFERENCE_TIME GetRefTime(__int64 granule_position);
HRESULT DeliverPacket(CAutoPtr<OggPacket> p);
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
public:
COggVorbisOutputPin(OggVorbisIdHeader* h, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
HRESULT UnpackInitPage(OggPage& page);
- bool IsInitialized() {return m_initpackets.GetCount() >= 3;}
+ bool IsInitialized() {
+ return m_initpackets.GetCount() >= 3;
+ }
};
class COggFlacOutputPin : public COggSplitterOutputPin
@@ -106,12 +112,14 @@ class COggFlacOutputPin : public COggSplitterOutputPin
virtual REFERENCE_TIME GetRefTime(__int64 granule_position);
HRESULT DeliverPacket(CAutoPtr<OggPacket> p);
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
public:
COggFlacOutputPin(BYTE* h, int nCount, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
- bool IsInitialized() {return m_initpackets.GetCount() >= 3;}
+ bool IsInitialized() {
+ return m_initpackets.GetCount() >= 3;
+ }
};
class COggDirectShowOutputPin : public COggSplitterOutputPin
@@ -169,11 +177,13 @@ public:
COggTheoraOutputPin(BYTE* p, LPCWSTR pName, CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
HRESULT UnpackInitPage(OggPage& page);
- bool IsInitialized() {return m_initpackets.GetCount() >= 3;}
+ bool IsInitialized() {
+ return m_initpackets.GetCount() >= 3;
+ }
};
class __declspec(uuid("9FF48807-E133-40AA-826F-9B2959E5232D"))
-COggSplitterFilter : public CBaseSplitterFilter
+ COggSplitterFilter : public CBaseSplitterFilter
{
protected:
CAutoPtr<COggFile> m_pFile;
@@ -189,7 +199,7 @@ public:
};
class __declspec(uuid("6D3688CE-3E9D-42F4-92CA-8A11119D25CD"))
-COggSourceFilter : public COggSplitterFilter
+ COggSourceFilter : public COggSplitterFilter
{
public:
COggSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/OggSplitter/stdafx.cpp b/src/filters/parser/OggSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/OggSplitter/stdafx.cpp
+++ b/src/filters/parser/OggSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/OggSplitter/stdafx.h b/src/filters/parser/OggSplitter/stdafx.h
index 01aef1f91..f8e9cd301 100644
--- a/src/filters/parser/OggSplitter/stdafx.h
+++ b/src/filters/parser/OggSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/RealMediaSplitter/RealMediaSplitter.cpp b/src/filters/parser/RealMediaSplitter/RealMediaSplitter.cpp
index a3da7019f..50b9c752b 100644
--- a/src/filters/parser/RealMediaSplitter/RealMediaSplitter.cpp
+++ b/src/filters/parser/RealMediaSplitter/RealMediaSplitter.cpp
@@ -38,8 +38,9 @@ template<typename T>
static void bswap(T& var)
{
BYTE* s = (BYTE*)&var;
- for(BYTE* d = s + sizeof(var)-1; s < d; s++, d--)
+ for(BYTE* d = s + sizeof(var)-1; s < d; s++, d--) {
*s ^= *d, *d ^= *s, *s ^= *d;
+ }
}
void rvinfo::bswap()
@@ -86,38 +87,32 @@ using namespace RMFF;
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn2[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn2[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_RV20},
{&MEDIATYPE_Video, &MEDIASUBTYPE_RV30},
{&MEDIATYPE_Video, &MEDIASUBTYPE_RV40},
{&MEDIATYPE_Video, &MEDIASUBTYPE_RV41},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut2[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut2[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins2[] =
-{
+const AMOVIESETUP_PIN sudpPins2[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn2), sudPinTypesIn2},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut2), sudPinTypesOut2}
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn3[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn3[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_14_4},
{&MEDIATYPE_Audio, &MEDIASUBTYPE_28_8},
{&MEDIATYPE_Audio, &MEDIASUBTYPE_ATRC},
@@ -129,27 +124,23 @@ const AMOVIESETUP_MEDIATYPE sudPinTypesIn3[] =
{&MEDIATYPE_Audio, &MEDIASUBTYPE_RACP},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut3[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut3[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_PCM},
};
-const AMOVIESETUP_PIN sudpPins3[] =
-{
+const AMOVIESETUP_PIN sudpPins3[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn3), sudPinTypesIn3},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut3), sudPinTypesOut3}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CRealMediaSplitterFilter), L"MPC - RealMedia Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CRealMediaSourceFilter), L"MPC - RealMedia Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
{&__uuidof(CRealVideoDecoder), L"MPC - RealVideo Decoder", MERIT_NORMAL, countof(sudpPins2), sudpPins2, CLSID_LegacyAmFilterCategory},
{&__uuidof(CRealAudioDecoder), L"MPC - RealAudio Decoder", MERIT_NORMAL, countof(sudpPins3), sudpPins3, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CRealMediaSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CRealMediaSourceFilter>, NULL, &sudFilter[1]},
{sudFilter[2].strName, sudFilter[2].clsID, CreateInstance<CRealVideoDecoder>, NULL, &sudFilter[2]},
@@ -197,8 +188,9 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
{
DWORD dw;
- if(FAILED(pAsyncReader->SyncRead(0, 4, (BYTE*)&dw)) || dw != 'FMR.')
+ if(FAILED(pAsyncReader->SyncRead(0, 4, (BYTE*)&dw)) || dw != 'FMR.') {
return E_FAIL;
+ }
}
HRESULT hr = E_FAIL;
@@ -206,7 +198,9 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CRMFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
if(FAILED(hr)) {
m_pFile.Free();
return hr;
@@ -218,21 +212,21 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_rtStop = 10000i64*m_pFile->m_p.tDuration;
POSITION pos = m_pFile->m_mps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
MediaProperies* pmp = m_pFile->m_mps.GetNext(pos);
CStringW name;
name.Format(L"Output %02d", pmp->stream);
- if(!pmp->name.IsEmpty()) name += L" (" + CStringW(pmp->name) + L")";
+ if(!pmp->name.IsEmpty()) {
+ name += L" (" + CStringW(pmp->name) + L")";
+ }
CAtlArray<CMediaType> mts;
CMediaType mt;
mt.SetSampleSize(max(pmp->maxPacketSize*16/**/, 1));
- if(pmp->mime == "video/x-pn-realvideo")
- {
+ if(pmp->mime == "video/x-pn-realvideo") {
mt.majortype = MEDIATYPE_Video;
mt.formattype = FORMAT_VideoInfo;
@@ -247,7 +241,9 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
ASSERT(rvi.fcc1 == 'ODIV');
mt.subtype = FOURCCMap(rvi.fcc2);
- if(rvi.fps > 0x10000) pvih->AvgTimePerFrame = REFERENCE_TIME(10000000i64 / ((float)rvi.fps/0x10000));
+ if(rvi.fps > 0x10000) {
+ pvih->AvgTimePerFrame = REFERENCE_TIME(10000000i64 / ((float)rvi.fps/0x10000));
+ }
pvih->dwBitRate = pmp->avgBitRate;
pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
pvih->bmiHeader.biWidth = rvi.w;
@@ -259,8 +255,7 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mts.Add(mt);
- if(pmp->width > 0 && pmp->height > 0)
- {
+ if(pmp->width > 0 && pmp->height > 0) {
BITMAPINFOHEADER bmi = pvih->bmiHeader;
mt.formattype = FORMAT_VideoInfo2;
VIDEOINFOHEADER2* pvih2 = (VIDEOINFOHEADER2*)mt.ReallocFormatBuffer(sizeof(VIDEOINFOHEADER2) + pmp->typeSpecData.GetCount());
@@ -274,9 +269,7 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
mts.InsertAt(0, mt);
}
- }
- else if(pmp->mime == "audio/x-pn-realaudio")
- {
+ } else if(pmp->mime == "audio/x-pn-realaudio") {
mt.majortype = MEDIATYPE_Audio;
mt.formattype = FORMAT_WaveFormatEx;
mt.bTemporalCompression = 1;
@@ -294,10 +287,10 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
fccstr[4] = 0;
BYTE* fmt = pmp->typeSpecData.GetData();
- for(int i = 0; i < pmp->typeSpecData.GetCount()-4; i++, fmt++)
- {
- if(fmt[0] == '.' || fmt[1] == 'r' || fmt[2] == 'a')
+ for(int i = 0; i < pmp->typeSpecData.GetCount()-4; i++, fmt++) {
+ if(fmt[0] == '.' || fmt[1] == 'r' || fmt[2] == 'a') {
break;
+ }
}
rainfo rai = *(rainfo*)fmt;
@@ -305,8 +298,7 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
BYTE* extra = NULL;
- if(rai.version2 == 4)
- {
+ if(rai.version2 == 4) {
rainfo4 rai4 = *(rainfo4*)fmt;
rai4.bswap();
pwfe->nChannels = rai4.channels;
@@ -318,12 +310,11 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
p += len;
len = *p++;
ASSERT(len == 4);
- if(len == 4)
+ if(len == 4) {
fcc = MAKEFOURCC(p[0],p[1],p[2],p[3]);
+ }
extra = p + len + 3;
- }
- else if(rai.version2 == 5)
- {
+ } else if(rai.version2 == 5) {
rainfo5 rai5 = *(rainfo5*)fmt;
rai5.bswap();
pwfe->nChannels = rai5.channels;
@@ -332,9 +323,7 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
pwfe->nBlockAlign = rai5.frame_size;
fcc = rai5.fourcc3;
extra = fmt + sizeof(rainfo5) + 4;
- }
- else
- {
+ } else {
continue;
}
@@ -344,69 +333,59 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
bswap(fcc);
- switch(fcc)
- {
- case '14_4':
- pwfe->wFormatTag = WAVE_FORMAT_14_4;
- break;
- case '28_8':
- pwfe->wFormatTag = WAVE_FORMAT_28_8;
- break;
- case 'ATRC':
- pwfe->wFormatTag = WAVE_FORMAT_ATRC;
- break;
- case 'COOK':
- pwfe->wFormatTag = WAVE_FORMAT_COOK;
- break;
- case 'DNET':
- pwfe->wFormatTag = WAVE_FORMAT_DNET;
- break;
- case 'SIPR':
- pwfe->wFormatTag = WAVE_FORMAT_SIPR;
- break;
- case 'RAAC':
- pwfe->wFormatTag = WAVE_FORMAT_RAAC;
- break;
- case 'RACP':
- pwfe->wFormatTag = WAVE_FORMAT_RACP;
- break;
+ switch(fcc) {
+ case '14_4':
+ pwfe->wFormatTag = WAVE_FORMAT_14_4;
+ break;
+ case '28_8':
+ pwfe->wFormatTag = WAVE_FORMAT_28_8;
+ break;
+ case 'ATRC':
+ pwfe->wFormatTag = WAVE_FORMAT_ATRC;
+ break;
+ case 'COOK':
+ pwfe->wFormatTag = WAVE_FORMAT_COOK;
+ break;
+ case 'DNET':
+ pwfe->wFormatTag = WAVE_FORMAT_DNET;
+ break;
+ case 'SIPR':
+ pwfe->wFormatTag = WAVE_FORMAT_SIPR;
+ break;
+ case 'RAAC':
+ pwfe->wFormatTag = WAVE_FORMAT_RAAC;
+ break;
+ case 'RACP':
+ pwfe->wFormatTag = WAVE_FORMAT_RACP;
+ break;
}
- if(pwfe->wFormatTag)
- {
+ if(pwfe->wFormatTag) {
mts.Add(mt);
- if(fcc == 'DNET')
- {
+ if(fcc == 'DNET') {
mt.subtype = FOURCCMap(pwfe->wFormatTag = WAVE_FORMAT_DOLBY_AC3);
mts.InsertAt(0, mt);
- }
- else if(fcc == 'RAAC' || fcc == 'RACP')
- {
+ } else if(fcc == 'RAAC' || fcc == 'RACP') {
mt.subtype = FOURCCMap(pwfe->wFormatTag = WAVE_FORMAT_AAC);
int extralen = *(DWORD*)extra;
extra += 4;
::bswap(extralen);
ASSERT(*extra == 2); // always 2? why? what does it mean?
- if(*extra == 2)
- {
+ if(*extra == 2) {
extra++;
extralen--;
WAVEFORMATEX* pwfe = (WAVEFORMATEX*)mt.ReallocFormatBuffer(sizeof(WAVEFORMATEX) + extralen);
pwfe->cbSize = extralen;
memcpy(pwfe + 1, extra, extralen);
- }
- else
- {
+ } else {
WAVEFORMATEX* pwfe = (WAVEFORMATEX*)mt.ReallocFormatBuffer(sizeof(WAVEFORMATEX) + 5);
pwfe->cbSize = MakeAACInitData((BYTE*)(pwfe+1), 0, pwfe->nSamplesPerSec, pwfe->nChannels);
}
mts.InsertAt(0, mt);
}
}
- }
- else if(pmp->mime == "logical-fileinfo")
- {
+ } else if(pmp->mime == "logical-fileinfo") {
CAtlMap<CStringA, CStringA, CStringElementTraits<CStringA> > lfi;
CStringA key, value;
@@ -418,21 +397,21 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
bswap(cnt);
p += 4;
- if(cnt > 0xffff) // different format?
- {
+ if(cnt > 0xffff) { // different format?
p += 2;
cnt = p <= end-4 ? *(DWORD*)p : 0;
bswap(cnt);
p += 4;
}
- while(p < end-4 && cnt-- > 0)
- {
+ while(p < end-4 && cnt-- > 0) {
BYTE* base = p;
DWORD len = *(DWORD*)p;
bswap(len);
p += 4;
- if(base + len > end) break;
+ if(base + len > end) {
+ break;
+ }
p++;
WORD keylen = *(WORD*)p;
@@ -455,22 +434,22 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
}
POSITION pos = lfi.GetStartPosition();
- while(pos)
- {
+ while(pos) {
lfi.GetNextAssoc(pos, key, value);
int n = 0;
if(key.Find("CHAPTER") == 0 && key.Find("TIME") == key.GetLength()-4
- && (n = strtol(key.Mid(7), NULL, 10)) > 0)
- {
+ && (n = strtol(key.Mid(7), NULL, 10)) > 0) {
int h, m, s, ms;
char c;
- if(7 != sscanf(value, "%d%c%d%c%d%c%d", &h, &c, &m, &c, &s, &c, &ms))
+ if(7 != sscanf(value, "%d%c%d%c%d%c%d", &h, &c, &m, &c, &s, &c, &ms)) {
continue;
+ }
key.Format("CHAPTER%02dNAME", n);
- if(!lfi.Lookup(key, value) || value.IsEmpty())
+ if(!lfi.Lookup(key, value) || value.IsEmpty()) {
value.Format("Chapter %d", n);
+ }
ChapAppend(
((((REFERENCE_TIME)h*60+m)*60+s)*1000+ms)*10000,
@@ -479,8 +458,7 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
}
}
- if(mts.IsEmpty())
- {
+ if(mts.IsEmpty()) {
TRACE(_T("Unsupported RealMedia stream (%d): %s\n"), pmp->stream, CString(pmp->mime));
continue;
}
@@ -488,21 +466,22 @@ HRESULT CRealMediaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
HRESULT hr;
CAutoPtr<CBaseSplitterOutputPin> pPinOut(DNew CRealMediaSplitterOutputPin(mts, name, this, this, &hr));
- if(SUCCEEDED(AddOutputPin((DWORD)pmp->stream, pPinOut)))
- {
- if(!m_rtStop)
+ if(SUCCEEDED(AddOutputPin((DWORD)pmp->stream, pPinOut))) {
+ if(!m_rtStop) {
m_pFile->m_p.tDuration = max(m_pFile->m_p.tDuration, pmp->tDuration);
+ }
}
}
pos = m_pFile->m_subs.GetHeadPosition();
- for(DWORD stream = 0; pos; stream++)
- {
+ for(DWORD stream = 0; pos; stream++) {
CRMFile::subtitle& s = m_pFile->m_subs.GetNext(pos);
CStringW name;
name.Format(L"Subtitle %02d", stream);
- if(!s.name.IsEmpty()) name += L" (" + CStringW(CString(s.name)) + L")";
+ if(!s.name.IsEmpty()) {
+ name += L" (" + CStringW(CString(s.name)) + L")";
+ }
CMediaType mt;
mt.SetSampleSize(1);
@@ -531,12 +510,13 @@ bool CRealMediaSplitterFilter::DemuxInit()
{
SetThreadName((DWORD)-1, "CRealMediaSplitterFilter");
- if(!m_pFile) return(false);
+ if(!m_pFile) {
+ return(false);
+ }
// reindex if needed
- if(m_pFile->m_irs.GetCount() == 0)
- {
+ if(m_pFile->m_irs.GetCount() == 0) {
m_nOpenProgress = 0;
m_rtDuration = 0;
@@ -546,26 +526,24 @@ bool CRealMediaSplitterFilter::DemuxInit()
UINT32 nPacket = 0;
POSITION pos = m_pFile->m_dcs.GetHeadPosition();
- while(pos && !m_fAbort)
- {
+ while(pos && !m_fAbort) {
DataChunk* pdc = m_pFile->m_dcs.GetNext(pos);
m_pFile->Seek(pdc->pos);
- for(UINT32 i = 0; i < pdc->nPackets && !m_fAbort; i++, nPacket++)
- {
+ for(UINT32 i = 0; i < pdc->nPackets && !m_fAbort; i++, nPacket++) {
UINT64 filepos = m_pFile->GetPos();
HRESULT hr;
MediaPacketHeader mph;
- if(S_OK != (hr = m_pFile->Read(mph, false)))
+ if(S_OK != (hr = m_pFile->Read(mph, false))) {
break;
+ }
m_rtDuration = max((__int64)(10000i64*mph.tStart), m_rtDuration);
- if(mph.stream == stream && (mph.flags&MediaPacketHeader::PN_KEYFRAME_FLAG) && tLastStart != mph.tStart)
- {
+ if(mph.stream == stream && (mph.flags&MediaPacketHeader::PN_KEYFRAME_FLAG) && tLastStart != mph.tStart) {
CAutoPtr<IndexRecord> pir(DNew IndexRecord);
pir->tStart = mph.tStart;
pir->ptrFilePos = (UINT32)filepos;
@@ -578,17 +556,21 @@ bool CRealMediaSplitterFilter::DemuxInit()
m_nOpenProgress = m_pFile->GetPos()*100/m_pFile->GetLength();
DWORD cmd;
- if(CheckRequest(&cmd))
- {
- if(cmd == CMD_EXIT) m_fAbort = true;
- else Reply(S_OK);
+ if(CheckRequest(&cmd)) {
+ if(cmd == CMD_EXIT) {
+ m_fAbort = true;
+ } else {
+ Reply(S_OK);
+ }
}
}
}
m_nOpenProgress = 100;
- if(m_fAbort) m_pFile->m_irs.RemoveAll();
+ if(m_fAbort) {
+ m_pFile->m_irs.RemoveAll();
+ }
m_fAbort = false;
}
@@ -602,83 +584,74 @@ bool CRealMediaSplitterFilter::DemuxInit()
void CRealMediaSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
{
- if(rt <= 0)
- {
+ if(rt <= 0) {
m_seekpos = m_pFile->m_dcs.GetHeadPosition();
m_seekpacket = 0;
m_seekfilepos = m_pFile->m_dcs.GetHead()->pos;
- }
- else
- {
+ } else {
m_seekpos = NULL;
POSITION pos = m_pFile->m_irs.GetTailPosition();
- while(pos && !m_seekpos)
- {
+ while(pos && !m_seekpos) {
IndexRecord* pir = m_pFile->m_irs.GetPrev(pos);
- if(pir->tStart <= rt/10000)
- {
+ if(pir->tStart <= rt/10000) {
m_seekpacket = pir->packet;
pos = m_pFile->m_dcs.GetTailPosition();
- while(pos && !m_seekpos)
- {
+ while(pos && !m_seekpos) {
POSITION tmp = pos;
DataChunk* pdc = m_pFile->m_dcs.GetPrev(pos);
- if(pdc->pos <= pir->ptrFilePos)
- {
+ if(pdc->pos <= pir->ptrFilePos) {
m_seekpos = tmp;
m_seekfilepos = pir->ptrFilePos;
POSITION pos = m_pFile->m_dcs.GetHeadPosition();
- while(pos != m_seekpos)
- {
+ while(pos != m_seekpos) {
m_seekpacket -= m_pFile->m_dcs.GetNext(pos)->nPackets;
}
}
}
// search the closest keyframe to the seek time (commented out 'cause rm seems to index all of its keyframes...)
-/*
- if(m_seekpos)
- {
- DataChunk* pdc = m_pFile->m_dcs.GetAt(m_seekpos);
-
- m_pFile->Seek(m_seekfilepos);
-
- REFERENCE_TIME seektime = -1;
- UINT32 seekstream = -1;
-
- for(UINT32 i = m_seekpacket; i < pdc->nPackets; i++)
- {
- UINT64 filepos = m_pFile->GetPos();
-
- MediaPacketHeader mph;
- if(S_OK != m_pFile->Read(mph, false))
- break;
-
- if(seekstream == -1) seekstream = mph.stream;
- if(seekstream != mph.stream) continue;
-
- if(seektime == 10000i64*mph.tStart) continue;
- if(rt < 10000i64*mph.tStart) break;
-
- if((mph.flags&MediaPacketHeader::PN_KEYFRAME_FLAG))
- {
- m_seekpacket = i;
- m_seekfilepos = filepos;
- seektime = 10000i64*mph.tStart;
- }
- }
- }
-*/
+ /*
+ if(m_seekpos)
+ {
+ DataChunk* pdc = m_pFile->m_dcs.GetAt(m_seekpos);
+
+ m_pFile->Seek(m_seekfilepos);
+
+ REFERENCE_TIME seektime = -1;
+ UINT32 seekstream = -1;
+
+ for(UINT32 i = m_seekpacket; i < pdc->nPackets; i++)
+ {
+ UINT64 filepos = m_pFile->GetPos();
+
+ MediaPacketHeader mph;
+ if(S_OK != m_pFile->Read(mph, false))
+ break;
+
+ if(seekstream == -1) seekstream = mph.stream;
+ if(seekstream != mph.stream) continue;
+
+ if(seektime == 10000i64*mph.tStart) continue;
+ if(rt < 10000i64*mph.tStart) break;
+
+ if((mph.flags&MediaPacketHeader::PN_KEYFRAME_FLAG))
+ {
+ m_seekpacket = i;
+ m_seekfilepos = filepos;
+ seektime = 10000i64*mph.tStart;
+ }
+ }
+ }
+ */
}
}
- if(!m_seekpos)
- {
+ if(!m_seekpos) {
m_seekpos = m_pFile->m_dcs.GetHeadPosition();
m_seekpacket = 0;
m_seekfilepos = m_pFile->m_dcs.GetAt(m_seekpos)->pos;
@@ -692,8 +665,7 @@ bool CRealMediaSplitterFilter::DemuxLoop()
POSITION pos;
pos = m_pFile->m_subs.GetHeadPosition();
- for(DWORD stream = 0; pos && SUCCEEDED(hr) && !CheckRequest(NULL); stream++)
- {
+ for(DWORD stream = 0; pos && SUCCEEDED(hr) && !CheckRequest(NULL); stream++) {
CRMFile::subtitle& s = m_pFile->m_subs.GetNext(pos);
CAutoPtr<Packet> p(DNew Packet);
@@ -727,17 +699,16 @@ bool CRealMediaSplitterFilter::DemuxLoop()
}
pos = m_seekpos;
- while(pos && SUCCEEDED(hr) && !CheckRequest(NULL))
- {
+ while(pos && SUCCEEDED(hr) && !CheckRequest(NULL)) {
DataChunk* pdc = m_pFile->m_dcs.GetNext(pos);
m_pFile->Seek(m_seekfilepos > 0 ? m_seekfilepos : pdc->pos);
- for(UINT32 i = m_seekpacket; i < pdc->nPackets && SUCCEEDED(hr) && !CheckRequest(NULL); i++)
- {
+ for(UINT32 i = m_seekpacket; i < pdc->nPackets && SUCCEEDED(hr) && !CheckRequest(NULL); i++) {
MediaPacketHeader mph;
- if(S_OK != (hr = m_pFile->Read(mph)))
+ if(S_OK != (hr = m_pFile->Read(mph))) {
break;
+ }
CAutoPtr<Packet> p(DNew Packet);
p->TrackNumber = mph.stream;
@@ -759,7 +730,9 @@ bool CRealMediaSplitterFilter::DemuxLoop()
STDMETHODIMP CRealMediaSplitterFilter::GetKeyFrameCount(UINT& nKFs)
{
- if(!m_pFile) return E_UNEXPECTED;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
nKFs = m_pFile->m_irs.GetCount();
return S_OK;
}
@@ -769,13 +742,18 @@ STDMETHODIMP CRealMediaSplitterFilter::GetKeyFrames(const GUID* pFormat, REFEREN
CheckPointer(pFormat, E_POINTER);
CheckPointer(pKFs, E_POINTER);
- if(!m_pFile) return E_UNEXPECTED;
- if(*pFormat != TIME_FORMAT_MEDIA_TIME) return E_INVALIDARG;
+ if(!m_pFile) {
+ return E_UNEXPECTED;
+ }
+ if(*pFormat != TIME_FORMAT_MEDIA_TIME) {
+ return E_INVALIDARG;
+ }
UINT nKFsTmp = 0;
POSITION pos = m_pFile->m_irs.GetHeadPosition();
- for(int i = 0; pos && nKFsTmp < nKFs; i++)
+ for(int i = 0; pos && nKFsTmp < nKFs; i++) {
pKFs[nKFsTmp++] = 10000i64*m_pFile->m_irs.GetNext(pos)->tStart;
+ }
nKFs = nKFsTmp;
return S_OK;
@@ -808,8 +786,7 @@ HRESULT CRealMediaSplitterOutputPin::DeliverSegments()
{
HRESULT hr;
- if(m_segments.GetCount() == 0)
- {
+ if(m_segments.GetCount() == 0) {
m_segments.Clear();
return S_OK;
}
@@ -824,8 +801,7 @@ HRESULT CRealMediaSplitterOutputPin::DeliverSegments()
DWORD len = 0, total = 0;
POSITION pos = m_segments.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
segment* s = m_segments.GetNext(pos);
len = max(len, s->offset + s->data.GetCount());
total += s->data.GetCount();
@@ -839,18 +815,14 @@ HRESULT CRealMediaSplitterOutputPin::DeliverSegments()
*pData++ = m_segments.fMerged ? 0 : m_segments.GetCount()-1;
- if(m_segments.fMerged)
- {
+ if(m_segments.fMerged) {
*((DWORD*)pData) = 1;
pData += 4;
*((DWORD*)pData) = 0;
pData += 4;
- }
- else
- {
+ } else {
pos = m_segments.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
*((DWORD*)pData) = 1;
pData += 4;
*((DWORD*)pData) = m_segments.GetNext(pos)->offset;
@@ -859,8 +831,7 @@ HRESULT CRealMediaSplitterOutputPin::DeliverSegments()
}
pos = m_segments.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
segment* s = m_segments.GetNext(pos);
memcpy(pData + s->offset, s->data.GetData(), s->data.GetCount());
}
@@ -878,74 +849,77 @@ HRESULT CRealMediaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
ASSERT(p->rtStart < p->rtStop);
- if(m_mt.subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3) {
WORD* s = (WORD*)p->GetData();
WORD* e = s + p->GetCount()/2;
- while(s < e) bswap(*s++);
+ while(s < e) {
+ bswap(*s++);
+ }
}
if(m_mt.subtype == MEDIASUBTYPE_RV10 || m_mt.subtype == MEDIASUBTYPE_RV20
|| m_mt.subtype == MEDIASUBTYPE_RV30 || m_mt.subtype == MEDIASUBTYPE_RV40
- || m_mt.subtype == MEDIASUBTYPE_RV41)
- {
+ || m_mt.subtype == MEDIASUBTYPE_RV41) {
CAutoLock cAutoLock(&m_csQueue);
int len = p->GetCount();
BYTE* pIn = p->GetData();
BYTE* pInOrg = pIn;
- if(m_segments.rtStart != p->rtStart)
- {
- if(S_OK != (hr = DeliverSegments()))
+ if(m_segments.rtStart != p->rtStart) {
+ if(S_OK != (hr = DeliverSegments())) {
return hr;
+ }
}
- if(!m_segments.fDiscontinuity && p->bDiscontinuity)
+ if(!m_segments.fDiscontinuity && p->bDiscontinuity) {
m_segments.fDiscontinuity = true;
+ }
m_segments.fSyncPoint = !!p->bSyncPoint;
m_segments.rtStart = p->rtStart;
- while(pIn - pInOrg < len)
- {
+ while(pIn - pInOrg < len) {
BYTE hdr = *pIn++, subseq = 0, seqnum = 0;
DWORD packetlen = 0, packetoffset = 0;
- if((hdr&0xc0) == 0x40)
- {
+ if((hdr&0xc0) == 0x40) {
pIn++;
packetlen = len - (pIn - pInOrg);
- }
- else
- {
- if((hdr&0x40) == 0)
+ } else {
+ if((hdr&0x40) == 0) {
subseq = (*pIn++)&0x7f;
+ }
#define GetWORD(var) \
var = (var<<8)|(*pIn++); \
var = (var<<8)|(*pIn++); \
GetWORD(packetlen);
- if(packetlen&0x8000) m_segments.fMerged = true;
+ if(packetlen&0x8000) {
+ m_segments.fMerged = true;
+ }
if((packetlen&0x4000) == 0) {
GetWORD(packetlen);
packetlen &= 0x3fffffff;
+ } else {
+ packetlen &= 0x3fff;
}
- else packetlen &= 0x3fff;
GetWORD(packetoffset);
if((packetoffset&0x4000) == 0) {
GetWORD(packetoffset);
packetoffset &= 0x3fffffff;
+ } else {
+ packetoffset &= 0x3fff;
}
- else packetoffset &= 0x3fff;
#undef GetWORD
- if((hdr&0xc0) == 0xc0)
+ if((hdr&0xc0) == 0xc0) {
m_segments.rtStart = 10000i64*packetoffset - m_rtStart, packetoffset = 0;
- else if((hdr&0xc0) == 0x80)
+ } else if((hdr&0xc0) == 0x80) {
packetoffset = packetlen - packetoffset;
+ }
seqnum = *pIn++;
}
@@ -960,16 +934,14 @@ HRESULT CRealMediaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
pIn += len2;
- if((hdr&0x80) || packetoffset+len2 >= packetlen)
- {
- if(S_OK != (hr = DeliverSegments()))
+ if((hdr&0x80) || packetoffset+len2 >= packetlen) {
+ if(S_OK != (hr = DeliverSegments())) {
return hr;
+ }
}
}
- }
- else if(m_mt.subtype == MEDIASUBTYPE_RAAC || m_mt.subtype == MEDIASUBTYPE_RACP
- || m_mt.subtype == MEDIASUBTYPE_AAC)
- {
+ } else if(m_mt.subtype == MEDIASUBTYPE_RAAC || m_mt.subtype == MEDIASUBTYPE_RACP
+ || m_mt.subtype == MEDIASUBTYPE_AAC) {
BYTE* ptr = p->GetData()+2;
CAtlList<WORD> sizes;
@@ -977,8 +949,7 @@ HRESULT CRealMediaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
int remaining = p->GetCount()-2;
int expected = *(ptr-1)>>4;
- while(total < remaining)
- {
+ while(total < remaining) {
int size = (ptr[0]<<8)|(ptr[1]);
sizes.AddTail(size);
total += size;
@@ -996,8 +967,7 @@ HRESULT CRealMediaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
BOOL bDiscontinuity = p->bDiscontinuity;
POSITION pos = sizes.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
WORD size = sizes.GetNext(pos);
CAutoPtr<Packet> p(DNew Packet);
@@ -1008,12 +978,11 @@ HRESULT CRealMediaSplitterOutputPin::DeliverPacket(CAutoPtr<Packet> p)
p->SetData(ptr, size);
ptr += size;
bDiscontinuity = false;
- if(S_OK != (hr = __super::DeliverPacket(p)))
+ if(S_OK != (hr = __super::DeliverPacket(p))) {
break;
+ }
}
- }
- else
- {
+ } else {
hr = __super::DeliverPacket(p);
}
@@ -1038,7 +1007,9 @@ CRealMediaSourceFilter::CRealMediaSourceFilter(LPUNKNOWN pUnk, HRESULT* phr)
CRMFile::CRMFile(IAsyncReader* pAsyncReader, HRESULT& hr)
: CBaseSplitterFile(pAsyncReader, hr)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
hr = Init();
}
@@ -1056,8 +1027,9 @@ HRESULT CRMFile::Read(ChunkHdr& hdr)
HRESULT hr;
if(S_OK != (hr = Read(hdr.object_id))
|| S_OK != (hr = Read(hdr.size))
- || S_OK != (hr = Read(hdr.object_version)))
+ || S_OK != (hr = Read(hdr.object_version))) {
return hr;
+ }
return S_OK;
}
@@ -1069,16 +1041,21 @@ HRESULT CRMFile::Read(MediaPacketHeader& mph, bool fFull)
HRESULT hr;
UINT16 object_version;
- if(S_OK != (hr = Read(object_version))) return hr;
- if(object_version != 0 && object_version != 1) return S_OK;
+ if(S_OK != (hr = Read(object_version))) {
+ return hr;
+ }
+ if(object_version != 0 && object_version != 1) {
+ return S_OK;
+ }
UINT8 flags;
if(S_OK != (hr = Read(mph.len))
|| S_OK != (hr = Read(mph.stream))
|| S_OK != (hr = Read(mph.tStart))
|| S_OK != (hr = Read(mph.reserved))
- || S_OK != (hr = Read(flags)))
+ || S_OK != (hr = Read(flags))) {
return hr;
+ }
mph.flags = (MediaPacketHeader::flag_t)flags;
LONG len = mph.len;
@@ -1088,14 +1065,12 @@ HRESULT CRMFile::Read(MediaPacketHeader& mph, bool fFull)
ASSERT(len >= 0);
len = max(len, 0);
- if(fFull)
- {
+ if(fFull) {
mph.pData.SetCount(len);
- if(mph.len > 0 && S_OK != (hr = ByteRead(mph.pData.GetData(), len)))
+ if(mph.len > 0 && S_OK != (hr = ByteRead(mph.pData.GetData(), len))) {
return hr;
- }
- else
- {
+ }
+ } else {
Seek(GetPos() + len);
}
@@ -1112,143 +1087,230 @@ HRESULT CRMFile::Init()
HRESULT hr;
ChunkHdr hdr;
- while(GetRemaining() && S_OK == (hr = Read(hdr)))
- {
+ while(GetRemaining() && S_OK == (hr = Read(hdr))) {
__int64 pos = GetPos() - sizeof(hdr);
- if(fFirstChunk && hdr.object_id != '.RMF')
+ if(fFirstChunk && hdr.object_id != '.RMF') {
return E_FAIL;
+ }
fFirstChunk = false;
- if(pos + hdr.size > GetLength() && hdr.object_id != 'DATA') // truncated?
+ if(pos + hdr.size > GetLength() && hdr.object_id != 'DATA') { // truncated?
break;
+ }
- if(hdr.object_id == 0x2E7261FD) // '.ra+0xFD'
+ if(hdr.object_id == 0x2E7261FD) { // '.ra+0xFD'
return E_FAIL;
+ }
- if(hdr.object_version == 0)
- {
- switch(hdr.object_id)
- {
- case '.RMF':
- if(S_OK != (hr = Read(m_fh.version))) return hr;
- if(hdr.size == 0x10) {
- WORD w = 0;
- if(S_OK != (hr = Read(w))) return hr;
- m_fh.nHeaders = w;
+ if(hdr.object_version == 0) {
+ switch(hdr.object_id) {
+ case '.RMF':
+ if(S_OK != (hr = Read(m_fh.version))) {
+ return hr;
+ }
+ if(hdr.size == 0x10) {
+ WORD w = 0;
+ if(S_OK != (hr = Read(w))) {
+ return hr;
+ }
+ m_fh.nHeaders = w;
+ } else if(S_OK != (hr = Read(m_fh.nHeaders))) {
+ return hr;
+ }
+ break;
+ case 'CONT':
+ UINT16 slen;
+ if(S_OK != (hr = Read(slen))) {
+ return hr;
+ }
+ if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.title.GetBufferSetLength(slen), slen))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(slen))) {
+ return hr;
+ }
+ if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.author.GetBufferSetLength(slen), slen))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(slen))) {
+ return hr;
+ }
+ if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.copyright.GetBufferSetLength(slen), slen))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(slen))) {
+ return hr;
+ }
+ if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.comment.GetBufferSetLength(slen), slen))) {
+ return hr;
+ }
+ break;
+ case 'PROP':
+ if(S_OK != (hr = Read(m_p.maxBitRate))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.avgBitRate))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.maxPacketSize))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.avgPacketSize))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.nPackets))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.tDuration))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.tPreroll))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.ptrIndex))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.ptrData))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(m_p.nStreams))) {
+ return hr;
+ }
+ UINT16 flags;
+ if(S_OK != (hr = Read(flags))) {
+ return hr;
+ }
+ m_p.flags = (Properies::flags_t)flags;
+ break;
+ case 'MDPR': {
+ CAutoPtr<MediaProperies> mp(DNew MediaProperies);
+ if(S_OK != (hr = Read(mp->stream))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->maxBitRate))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->avgBitRate))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->maxPacketSize))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->avgPacketSize))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->tStart))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->tPreroll))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(mp->tDuration))) {
+ return hr;
+ }
+ UINT8 slen;
+ if(S_OK != (hr = Read(slen))) {
+ return hr;
+ }
+ if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)mp->name.GetBufferSetLength(slen), slen))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(slen))) {
+ return hr;
+ }
+ if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)mp->mime.GetBufferSetLength(slen), slen))) {
+ return hr;
+ }
+ UINT32 tsdlen;
+ if(S_OK != (hr = Read(tsdlen))) {
+ return hr;
+ }
+ mp->typeSpecData.SetCount(tsdlen);
+ if(tsdlen > 0 && S_OK != (hr = ByteRead(mp->typeSpecData.GetData(), tsdlen))) {
+ return hr;
+ }
+ mp->width = mp->height = 0;
+ mp->interlaced = mp->top_field_first = false;
+ m_mps.AddTail(mp);
+ break;
}
- else if(S_OK != (hr = Read(m_fh.nHeaders))) return hr;
- break;
- case 'CONT':
- UINT16 slen;
- if(S_OK != (hr = Read(slen))) return hr;
- if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.title.GetBufferSetLength(slen), slen))) return hr;
- if(S_OK != (hr = Read(slen))) return hr;
- if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.author.GetBufferSetLength(slen), slen))) return hr;
- if(S_OK != (hr = Read(slen))) return hr;
- if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.copyright.GetBufferSetLength(slen), slen))) return hr;
- if(S_OK != (hr = Read(slen))) return hr;
- if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)m_cd.comment.GetBufferSetLength(slen), slen))) return hr;
- break;
- case 'PROP':
- if(S_OK != (hr = Read(m_p.maxBitRate))) return hr;
- if(S_OK != (hr = Read(m_p.avgBitRate))) return hr;
- if(S_OK != (hr = Read(m_p.maxPacketSize))) return hr;
- if(S_OK != (hr = Read(m_p.avgPacketSize))) return hr;
- if(S_OK != (hr = Read(m_p.nPackets))) return hr;
- if(S_OK != (hr = Read(m_p.tDuration))) return hr;
- if(S_OK != (hr = Read(m_p.tPreroll))) return hr;
- if(S_OK != (hr = Read(m_p.ptrIndex))) return hr;
- if(S_OK != (hr = Read(m_p.ptrData))) return hr;
- if(S_OK != (hr = Read(m_p.nStreams))) return hr;
- UINT16 flags;
- if(S_OK != (hr = Read(flags))) return hr;
- m_p.flags = (Properies::flags_t)flags;
- break;
- case 'MDPR':
- {
- CAutoPtr<MediaProperies> mp(DNew MediaProperies);
- if(S_OK != (hr = Read(mp->stream))) return hr;
- if(S_OK != (hr = Read(mp->maxBitRate))) return hr;
- if(S_OK != (hr = Read(mp->avgBitRate))) return hr;
- if(S_OK != (hr = Read(mp->maxPacketSize))) return hr;
- if(S_OK != (hr = Read(mp->avgPacketSize))) return hr;
- if(S_OK != (hr = Read(mp->tStart))) return hr;
- if(S_OK != (hr = Read(mp->tPreroll))) return hr;
- if(S_OK != (hr = Read(mp->tDuration))) return hr;
- UINT8 slen;
- if(S_OK != (hr = Read(slen))) return hr;
- if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)mp->name.GetBufferSetLength(slen), slen))) return hr;
- if(S_OK != (hr = Read(slen))) return hr;
- if(slen > 0 && S_OK != (hr = ByteRead((BYTE*)mp->mime.GetBufferSetLength(slen), slen))) return hr;
- UINT32 tsdlen;
- if(S_OK != (hr = Read(tsdlen))) return hr;
- mp->typeSpecData.SetCount(tsdlen);
- if(tsdlen > 0 && S_OK != (hr = ByteRead(mp->typeSpecData.GetData(), tsdlen))) return hr;
- mp->width = mp->height = 0;
- mp->interlaced = mp->top_field_first = false;
- m_mps.AddTail(mp);
- break;
- }
- case 'DATA':
- {
- CAutoPtr<DataChunk> dc(DNew DataChunk);
- if(S_OK != (hr = Read(dc->nPackets))) return hr;
- if(S_OK != (hr = Read(dc->ptrNext))) return hr;
- dc->pos = GetPos();
- m_dcs.AddTail(dc);
- GetDimensions();
- break;
- }
- case 'INDX':
- {
- IndexChunkHeader ich;
- if(S_OK != (hr = Read(ich.nIndices))) return hr;
- if(S_OK != (hr = Read(ich.stream))) return hr;
- if(S_OK != (hr = Read(ich.ptrNext))) return hr;
- int stream = GetMasterStream();
- while(ich.nIndices-- > 0)
- {
- UINT16 object_version;
- if(S_OK != (hr = Read(object_version))) return hr;
- if(object_version == 0)
- {
- CAutoPtr<IndexRecord> ir(DNew IndexRecord);
- if(S_OK != (hr = Read(ir->tStart))) return hr;
- if(S_OK != (hr = Read(ir->ptrFilePos))) return hr;
- if(S_OK != (hr = Read(ir->packet))) return hr;
- if(ich.stream == stream) m_irs.AddTail(ir);
+ case 'DATA': {
+ CAutoPtr<DataChunk> dc(DNew DataChunk);
+ if(S_OK != (hr = Read(dc->nPackets))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(dc->ptrNext))) {
+ return hr;
}
+ dc->pos = GetPos();
+ m_dcs.AddTail(dc);
+ GetDimensions();
+ break;
}
- break;
- }
- case '.SUB':
- if(hdr.size > sizeof(hdr))
- {
- int size = hdr.size - sizeof(hdr);
- CAutoVectorPtr<char> buff;
- if(!buff.Allocate(size)) return E_OUTOFMEMORY;
- char* p = buff;
- if(S_OK != (hr = ByteRead((BYTE*)p, size))) return hr;
- for(char* end = p + size; p < end; )
- {
- subtitle s;
- s.name = p;
- p += s.name.GetLength()+1;
- CStringA len(p);
- p += len.GetLength()+1;
- s.data = CStringA(p, strtol(len, NULL, 10));
- p += s.data.GetLength();
- m_subs.AddTail(s);
+ case 'INDX': {
+ IndexChunkHeader ich;
+ if(S_OK != (hr = Read(ich.nIndices))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(ich.stream))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(ich.ptrNext))) {
+ return hr;
}
+ int stream = GetMasterStream();
+ while(ich.nIndices-- > 0) {
+ UINT16 object_version;
+ if(S_OK != (hr = Read(object_version))) {
+ return hr;
+ }
+ if(object_version == 0) {
+ CAutoPtr<IndexRecord> ir(DNew IndexRecord);
+ if(S_OK != (hr = Read(ir->tStart))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(ir->ptrFilePos))) {
+ return hr;
+ }
+ if(S_OK != (hr = Read(ir->packet))) {
+ return hr;
+ }
+ if(ich.stream == stream) {
+ m_irs.AddTail(ir);
+ }
+ }
+ }
+ break;
}
- break;
+ case '.SUB':
+ if(hdr.size > sizeof(hdr)) {
+ int size = hdr.size - sizeof(hdr);
+ CAutoVectorPtr<char> buff;
+ if(!buff.Allocate(size)) {
+ return E_OUTOFMEMORY;
+ }
+ char* p = buff;
+ if(S_OK != (hr = ByteRead((BYTE*)p, size))) {
+ return hr;
+ }
+ for(char* end = p + size; p < end; ) {
+ subtitle s;
+ s.name = p;
+ p += s.name.GetLength()+1;
+ CStringA len(p);
+ p += len.GetLength()+1;
+ s.data = CStringA(p, strtol(len, NULL, 10));
+ p += s.data.GetLength();
+ m_subs.AddTail(s);
+ }
+ }
+ break;
}
}
- if(hdr.object_id == 'CONT' && BitRead(32, true) == 'DATA')
- {
+ if(hdr.object_id == 'CONT' && BitRead(32, true) == 'DATA') {
hdr.size = GetPos() - pos;
}
@@ -1257,8 +1319,9 @@ HRESULT CRMFile::Init()
|| GetPos() == pos + sizeof(hdr));
pos += hdr.size;
- if(pos > GetPos())
+ if(pos > GetPos()) {
Seek(pos);
+ }
}
return S_OK;
@@ -1272,8 +1335,7 @@ unsigned int GetBits2(int n, unsigned char*& p, unsigned int& bit_offset, unsign
bit_offset += n;
bit_buffer <<= n;
- if(bit_offset > (32-16))
- {
+ if(bit_offset > (32-16)) {
p += bit_offset >> 3;
bit_offset &= 7;
bit_buffer = (unsigned int)p[0] << 24;
@@ -1303,32 +1365,25 @@ void GetDimensions(unsigned char* p, unsigned int* wi, unsigned int* hi)
GetBits(13);
w = cw[GetBits(3)];
- if(w == 0)
- {
- do
- {
+ if(w == 0) {
+ do {
c = GetBits(8);
w += (c << 2);
- }
- while(c == 255);
+ } while(c == 255);
}
c = GetBits(3);
h = ch1[c];
- if(h == 0)
- {
+ if(h == 0) {
c = ((c << 1) | GetBits(1)) & 3;
h = ch2[c];
- if(h == 0)
- {
- do
- {
+ if(h == 0) {
+ do {
c = GetBits(8);
h += (c << 2);
- }
- while(c == 255);
+ } while(c == 255);
}
}
@@ -1355,53 +1410,49 @@ void GetDimensions_X10(unsigned char* p, unsigned int* wi, unsigned int* hi,
*top_field_first = false;
*repeat_field = false;
c = GetBits(1);
- if (c)
- {
+ if (c) {
c = GetBits(1);
- if (c)
+ if (c) {
*interlaced = true;
+ }
c = GetBits(1);
- if (c)
+ if (c) {
*top_field_first = true;
+ }
c = GetBits(1);
- if (c)
+ if (c) {
*repeat_field = true;
+ }
c = GetBits(1);
c = GetBits(1);
- if (c)
+ if (c) {
GetBits(2);
+ }
}
GetBits(16);
w = cw[GetBits(3)];
- if(w == 0)
- {
- do
- {
+ if(w == 0) {
+ do {
c = GetBits(8);
w += (c << 2);
- }
- while(c == 255);
+ } while(c == 255);
}
c = GetBits(3);
h = ch1[c];
- if(h == 0)
- {
+ if(h == 0) {
c = ((c << 1) | GetBits(1)) & 3;
h = ch2[c];
- if(h == 0)
- {
- do
- {
+ if(h == 0) {
+ do {
c = GetBits(8);
h += (c << 2);
- }
- while(c == 255);
+ } while(c == 255);
}
}
@@ -1412,27 +1463,26 @@ void GetDimensions_X10(unsigned char* p, unsigned int* wi, unsigned int* hi,
void CRMFile::GetDimensions()
{
POSITION pos = m_mps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
UINT64 filepos = GetPos();
MediaProperies* pmp = m_mps.GetNext(pos);
- if(pmp->mime == "video/x-pn-realvideo")
- {
+ if(pmp->mime == "video/x-pn-realvideo") {
pmp->width = pmp->height = 0;
rvinfo rvi = *(rvinfo*)pmp->typeSpecData.GetData();
rvi.bswap();
- if(rvi.fcc2 != '04VR' && rvi.fcc2 != '14VR')
+ if(rvi.fcc2 != '04VR' && rvi.fcc2 != '14VR') {
continue;
+ }
MediaPacketHeader mph;
- while(S_OK == Read(mph))
- {
+ while(S_OK == Read(mph)) {
if(mph.stream != pmp->stream || mph.len == 0
- || !(mph.flags&MediaPacketHeader::PN_KEYFRAME_FLAG))
+ || !(mph.flags&MediaPacketHeader::PN_KEYFRAME_FLAG)) {
continue;
+ }
BYTE* p = mph.pData.GetData();
BYTE* p0 = p;
@@ -1441,13 +1491,12 @@ void CRMFile::GetDimensions()
BYTE hdr = *p++;
DWORD packetlen = 0, packetoffset = 0;
- if((hdr&0xc0) == 0x40)
- {
+ if((hdr&0xc0) == 0x40) {
packetlen = len - (++p - p0);
- }
- else
- {
- if((hdr&0x40) == 0) p++;
+ } else {
+ if((hdr&0x40) == 0) {
+ p++;
+ }
#define GetWORD(var) \
var = (var<<8)|(*p++); \
@@ -1457,34 +1506,42 @@ void CRMFile::GetDimensions()
if((packetlen&0x4000) == 0) {
GetWORD(packetlen);
packetlen &= 0x3fffffff;
+ } else {
+ packetlen &= 0x3fff;
}
- else packetlen &= 0x3fff;
GetWORD(packetoffset);
if((packetoffset&0x4000) == 0) {
GetWORD(packetoffset);
packetoffset &= 0x3fffffff;
+ } else {
+ packetoffset &= 0x3fff;
}
- else packetoffset &= 0x3fff;
#undef GetWORD
- if((hdr&0xc0) == 0xc0) packetoffset = 0;
- else if((hdr&0xc0) == 0x80) packetoffset = packetlen - packetoffset;
+ if((hdr&0xc0) == 0xc0) {
+ packetoffset = 0;
+ } else if((hdr&0xc0) == 0x80) {
+ packetoffset = packetlen - packetoffset;
+ }
p++;
}
len = min(len - (p - p0), packetlen - packetoffset);
- if(len > 0)
- {
+ if(len > 0) {
bool repeat_field;
- if(rvi.fcc2 == '14VR') ::GetDimensions_X10(p, &pmp->width, &pmp->height, &pmp->interlaced, &pmp->top_field_first, &repeat_field);
- else ::GetDimensions(p, &pmp->width, &pmp->height);
+ if(rvi.fcc2 == '14VR') {
+ ::GetDimensions_X10(p, &pmp->width, &pmp->height, &pmp->interlaced, &pmp->top_field_first, &repeat_field);
+ } else {
+ ::GetDimensions(p, &pmp->width, &pmp->height);
+ }
- if(rvi.w == pmp->width && rvi.h == pmp->height)
+ if(rvi.w == pmp->width && rvi.h == pmp->height) {
pmp->width = pmp->height = 0;
+ }
break;
}
@@ -1500,18 +1557,19 @@ int CRMFile::GetMasterStream()
int s1 = -1, s2 = -1;
POSITION pos = m_mps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
MediaProperies* pmp = m_mps.GetNext(pos);
if(pmp->mime == "video/x-pn-realvideo") {
s1 = pmp->stream;
break;
+ } else if(pmp->mime == "audio/x-pn-realaudio" && s2 == -1) {
+ s2 = pmp->stream;
}
- else if(pmp->mime == "audio/x-pn-realaudio" && s2 == -1) s2 = pmp->stream;
}
- if(s1 == -1)
+ if(s1 == -1) {
s1 = s2;
+ }
return s1;
}
@@ -1533,7 +1591,9 @@ CRealVideoDecoder::CRealVideoDecoder(LPUNKNOWN lpunk, HRESULT* phr)
CRealVideoDecoder::~CRealVideoDecoder()
{
- if(m_hDrvDll) FreeLibrary(m_hDrvDll);
+ if(m_hDrvDll) {
+ FreeLibrary(m_hDrvDll);
+ }
}
HRESULT CRealVideoDecoder::InitRV(const CMediaType* pmt)
@@ -1553,17 +1613,18 @@ HRESULT CRealVideoDecoder::InitRV(const CMediaType* pmt)
{11, rvi.w, rvi.h, 0, 0, rvi.type1, 1, rvi.type2};
#pragma pack(pop)
- if(FAILED(hr = RVInit(&i, &m_dwCookie)))
+ if(FAILED(hr = RVInit(&i, &m_dwCookie))) {
return hr;
+ }
- if(rvi.fcc2 <= '03VR' && rvi.type2 >= 0x20200002)
- {
+ if(rvi.fcc2 <= '03VR' && rvi.type2 >= 0x20200002) {
int nWidthHeight = (1+((rvi.type1>>16)&7));
UINT32* pWH = DNew UINT32[nWidthHeight*2];
pWH[0] = rvi.w;
pWH[1] = rvi.h;
- for(int i = 2; i < nWidthHeight*2; i++)
+ for(int i = 2; i < nWidthHeight*2; i++) {
pWH[i] = rvi.morewh[i-2]*4;
+ }
#pragma pack(push, 1)
struct {
UINT32 data1;
@@ -1581,8 +1642,7 @@ HRESULT CRealVideoDecoder::InitRV(const CMediaType* pmt)
void CRealVideoDecoder::FreeRV()
{
- if(m_dwCookie)
- {
+ if(m_dwCookie) {
RVFree(m_dwCookie);
m_dwCookie = 0;
}
@@ -1595,11 +1655,14 @@ HRESULT CRealVideoDecoder::Transform(IMediaSample* pIn)
HRESULT hr;
BYTE* pDataIn = NULL;
- if(FAILED(hr = pIn->GetPointer(&pDataIn)))
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
return hr;
+ }
long len = pIn->GetActualDataLength();
- if(len <= 0) return S_OK; // nothing to do
+ if(len <= 0) {
+ return S_OK; // nothing to do
+ }
REFERENCE_TIME rtStart, rtStop;
pIn->GetTime(&rtStart, &rtStop);
@@ -1623,8 +1686,7 @@ HRESULT CRealVideoDecoder::Transform(IMediaSample* pIn)
pDataIn += offset;
- if(m_fDropFrames && m_timestamp+1 == transform_in.timestamp)
- {
+ if(m_fDropFrames && m_timestamp+1 == transform_in.timestamp) {
m_timestamp = transform_in.timestamp;
return S_OK;
}
@@ -1635,36 +1697,29 @@ HRESULT CRealVideoDecoder::Transform(IMediaSample* pIn)
::GetDimensions_X10(pDataIn, &tmp1, &tmp2, &interlaced, &tmp3, &tmp4);
int size = tmp1*tmp2;
- if( m_lastBuffSizeDim < size )
- {
+ if( m_lastBuffSizeDim < size ) {
_aligned_free(m_pI420);
_aligned_free(m_pI420Tmp);
m_lastBuffSizeDim = size;
ATLTRACE("resize out put buff %d" ,size);
- if ( m_pI420 = static_cast<BYTE*>(_aligned_malloc(size*3/2, 16)))
- {
+ if ( m_pI420 = static_cast<BYTE*>(_aligned_malloc(size*3/2, 16))) {
ATLTRACE(" m_pI420.Allocated 1" );
memset(m_pI420, 0, size);
ATLTRACE(" m_pI420.Allocated 2" );
memset(m_pI420 + size, 0x80, size/2);
ATLTRACE(" m_pI420.Allocated 3" );
- }
- else
- {
+ } else {
ATLTRACE(" m_pI420.Allocate fail %d" ,size*3/2);
return S_OK;
}
- if( m_pI420Tmp = static_cast<BYTE*>(_aligned_malloc(size*3/2, 16)))
- {
+ if( m_pI420Tmp = static_cast<BYTE*>(_aligned_malloc(size*3/2, 16))) {
ATLTRACE(" m_pI420Tmp.Allocated 1" );
memset(m_pI420Tmp, 0, size);
ATLTRACE(" m_pI420Tmp.Allocated 2" );
memset(m_pI420Tmp + size, 0x80, size/2);
ATLTRACE(" m_pI420Tmp.Allocated 3" );
- }
- else
- {
+ } else {
ATLTRACE(" m_pI420Tmp.Allocate fail %d" ,size*3/2);
return S_OK;
}
@@ -1674,27 +1729,27 @@ HRESULT CRealVideoDecoder::Transform(IMediaSample* pIn)
m_timestamp = transform_in.timestamp;
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
TRACE(_T("RV returned an error code!!!\n"));
ASSERT(!(transform_out.unk1&1)); // error allowed when the "render" flag is not set
-// return hr;
+ // return hr;
}
- if(pIn->IsPreroll() == S_OK || rtStart < 0 || !(transform_out.unk1&1))
+ if(pIn->IsPreroll() == S_OK || rtStart < 0 || !(transform_out.unk1&1)) {
return S_OK;
+ }
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
if(/*FAILED(hr = GetDeliveryBuffer(transform_out.w, transform_out.h, &pOut)) // TODO
&& */ FAILED(hr = GetDeliveryBuffer(m_w, m_h, &pOut))
- || FAILED(hr = pOut->GetPointer(&pDataOut)))
+ || FAILED(hr = pOut->GetPointer(&pDataOut))) {
return hr;
+ }
BYTE* pI420[3] = {m_pI420, m_pI420Tmp, NULL};
- if(interlaced)
- {
+ if(interlaced) {
int size = m_w*m_h;
DeinterlaceBlend(pI420[1], pI420[0], m_w, m_h, m_w, m_w);
DeinterlaceBlend(pI420[1]+size, pI420[0]+size, m_w/2, m_h/2, m_w/2, m_w/2);
@@ -1702,12 +1757,12 @@ HRESULT CRealVideoDecoder::Transform(IMediaSample* pIn)
pI420[2] = pI420[1], pI420[1] = pI420[0], pI420[0] = pI420[2];
}
- if(transform_out.w != m_w || transform_out.h != m_h)
- {
+ if(transform_out.w != m_w || transform_out.h != m_h) {
Resize(pI420[0], transform_out.w, transform_out.h, pI420[1], m_w, m_h);
// only one of these can be true, and when it happens the result image must be in the tmp buffer
- if(transform_out.w == m_w || transform_out.h == m_h)
+ if(transform_out.w == m_w || transform_out.h == m_h) {
pI420[2] = pI420[1], pI420[1] = pI420[0], pI420[0] = pI420[2];
+ }
}
rtStart = 10000i64*transform_out.timestamp - m_tStart;
@@ -1719,7 +1774,7 @@ HRESULT CRealVideoDecoder::Transform(IMediaSample* pIn)
CopyBuffer(pDataOut, pI420[0], m_w, m_h, m_w, MEDIASUBTYPE_I420);
DbgLog((LOG_TRACE, 0, _T("V: rtStart=%I64d, rtStop=%I64d, disc=%d, sync=%d"),
- rtStart, rtStop, pOut->IsDiscontinuity() == S_OK, pOut->IsSyncPoint() == S_OK));
+ rtStart, rtStop, pOut->IsDiscontinuity() == S_OK, pOut->IsSyncPoint() == S_OK));
return m_pOutput->Deliver(pOut);
}
@@ -1729,22 +1784,23 @@ void CRealVideoDecoder::Resize(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD
int si = wi*hi, so = wo*ho;
ASSERT(((si*so)&3) == 0);
- if(wi < wo)
- {
+ if(wi < wo) {
ResizeWidth(pIn, wi, hi, pOut, wo, ho);
ResizeWidth(pIn + si, wi/2, hi/2, pOut + so, wo/2, ho/2);
ResizeWidth(pIn + si + si/4, wi/2, hi/2, pOut + so + so/4, wo/2, ho/2);
- if(hi == ho) return;
+ if(hi == ho) {
+ return;
+ }
ResizeHeight(pOut, wo, hi, pIn, wo, ho);
ResizeHeight(pOut + so, wo/2, hi/2, pIn + so, wo/2, ho/2);
ResizeHeight(pOut + so + so/4, wo/2, hi/2, pIn + so + so/4, wo/2, ho/2);
- }
- else if(hi < ho)
- {
+ } else if(hi < ho) {
ResizeHeight(pIn, wi, hi, pOut, wo, ho);
ResizeHeight(pIn + si, wi/2, hi/2, pOut + so, wo/2, ho/2);
ResizeHeight(pIn + si + si/4, wi/2, hi/2, pOut + so + so/4, wo/2, ho/2);
- if(wi == wo) return;
+ if(wi == wo) {
+ return;
+ }
ASSERT(0); // this is uncreachable code, but anyway... looks nice being so symmetric
ResizeWidth(pOut, wi, ho, pIn, wo, ho);
ResizeWidth(pOut + so, wi/2, ho/2, pIn + so, wo/2, ho/2);
@@ -1754,23 +1810,23 @@ void CRealVideoDecoder::Resize(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD
void CRealVideoDecoder::ResizeWidth(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD wo, DWORD ho)
{
- for(DWORD y = 0; y < hi; y++, pIn += wi, pOut += wo)
- {
- if(wi == wo) memcpy(pOut, pIn, wo);
- else ResizeRow(pIn, wi, 1, pOut, wo, 1);
+ for(DWORD y = 0; y < hi; y++, pIn += wi, pOut += wo) {
+ if(wi == wo) {
+ memcpy(pOut, pIn, wo);
+ } else {
+ ResizeRow(pIn, wi, 1, pOut, wo, 1);
+ }
}
}
void CRealVideoDecoder::ResizeHeight(BYTE* pIn, DWORD wi, DWORD hi, BYTE* pOut, DWORD wo, DWORD ho)
{
- if(hi == ho)
- {
+ if(hi == ho) {
memcpy(pOut, pIn, wo*ho);
- }
- else
- {
- for(DWORD x = 0; x < wo; x++, pIn++, pOut++)
+ } else {
+ for(DWORD x = 0; x < wo; x++, pIn++, pOut++) {
ResizeRow(pIn, hi, wo, pOut, ho, wo);
+ }
}
}
@@ -1778,10 +1834,9 @@ void CRealVideoDecoder::ResizeRow(BYTE* pIn, DWORD wi, DWORD dpi, BYTE* pOut, DW
{
ASSERT(wi < wo);
- if(dpo == 1)
- {
+ if(dpo == 1) {
for(DWORD i = 0, j = 0, dj = (wi<<16)/wo; i < wo-1; i++, pOut++, j += dj)
-// pOut[i] = pIn[j>>16];
+ // pOut[i] = pIn[j>>16];
{
BYTE* p = &pIn[j>>16];
DWORD jf = j&0xffff;
@@ -1789,11 +1844,9 @@ void CRealVideoDecoder::ResizeRow(BYTE* pIn, DWORD wi, DWORD dpi, BYTE* pOut, DW
}
*pOut = pIn[wi-1];
- }
- else
- {
+ } else {
for(DWORD i = 0, j = 0, dj = (wi<<16)/wo; i < wo-1; i++, pOut += dpo, j += dj)
-// *pOut = pIn[dpi*(j>>16)];
+ // *pOut = pIn[dpi*(j>>16)];
{
BYTE* p = &pIn[dpi*(j>>16)];
DWORD jf = j&0xffff;
@@ -1807,22 +1860,22 @@ void CRealVideoDecoder::ResizeRow(BYTE* pIn, DWORD wi, DWORD dpi, BYTE* pOut, DW
HRESULT CRealVideoDecoder::CheckInputType(const CMediaType* mtIn)
{
if(mtIn->majortype != MEDIATYPE_Video
- || mtIn->subtype != MEDIASUBTYPE_RV20
- && mtIn->subtype != MEDIASUBTYPE_RV30
- && mtIn->subtype != MEDIASUBTYPE_RV40
- && mtIn->subtype != MEDIASUBTYPE_RV41)
+ || mtIn->subtype != MEDIASUBTYPE_RV20
+ && mtIn->subtype != MEDIASUBTYPE_RV30
+ && mtIn->subtype != MEDIASUBTYPE_RV40
+ && mtIn->subtype != MEDIASUBTYPE_RV41) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(mtIn->formattype == FORMAT_VideoInfo2)
- {
+ if(mtIn->formattype == FORMAT_VideoInfo2) {
VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)mtIn->Format();
if(vih2->dwPictAspectRatioX < vih2->bmiHeader.biWidth
- || vih2->dwPictAspectRatioY < vih2->bmiHeader.biHeight)
+ || vih2->dwPictAspectRatioY < vih2->bmiHeader.biHeight) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
- if(!m_pInput->IsConnected())
- {
+ if(!m_pInput->IsConnected()) {
if(m_hDrvDll) {
FreeLibrary(m_hDrvDll);
m_hDrvDll = NULL;
@@ -1833,65 +1886,88 @@ HRESULT CRealVideoDecoder::CheckInputType(const CMediaType* mtIn)
olddll.Format(_T("drv%c3260.dll"), (TCHAR)((mtIn->subtype.Data1>>16)&0xff));
newdll =
- mtIn->subtype == FOURCCMap('14VR') ? _T("drvi.dll") :
- mtIn->subtype == FOURCCMap('02VR') ? _T("drv2.dll") :
- _T("drvc.dll");
+ mtIn->subtype == FOURCCMap('14VR') ? _T("drvi.dll") :
+ mtIn->subtype == FOURCCMap('02VR') ? _T("drv2.dll") :
+ _T("drvc.dll");
CRegKey key;
TCHAR buff[_MAX_PATH];
ULONG len = sizeof(buff);
if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, _T("Software\\RealNetworks\\Preferences\\DT_Codecs"), KEY_READ)
- && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0)
- {
+ && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0) {
oldpath = buff;
TCHAR c = oldpath[oldpath.GetLength()-1];
- if(c != '\\' && c != '/') oldpath += '\\';
+ if(c != '\\' && c != '/') {
+ oldpath += '\\';
+ }
key.Close();
}
len = sizeof(buff);
if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, _T("Helix\\HelixSDK\\10.0\\Preferences\\DT_Codecs"), KEY_READ)
- && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0)
- {
+ && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0) {
newpath = buff;
TCHAR c = newpath[newpath.GetLength()-1];
- if(c != '\\' && c != '/') newpath += '\\';
+ if(c != '\\' && c != '/') {
+ newpath += '\\';
+ }
key.Close();
}
- if(!newpath.IsEmpty()) paths.AddTail(newpath + newdll);
- if(!oldpath.IsEmpty()) paths.AddTail(oldpath + newdll);
+ if(!newpath.IsEmpty()) {
+ paths.AddTail(newpath + newdll);
+ }
+ if(!oldpath.IsEmpty()) {
+ paths.AddTail(oldpath + newdll);
+ }
paths.AddTail(newdll); // default dll paths
- if(!newpath.IsEmpty()) paths.AddTail(newpath + olddll);
- if(!oldpath.IsEmpty()) paths.AddTail(oldpath + olddll);
+ if(!newpath.IsEmpty()) {
+ paths.AddTail(newpath + olddll);
+ }
+ if(!oldpath.IsEmpty()) {
+ paths.AddTail(oldpath + olddll);
+ }
paths.AddTail(olddll); // default dll paths
POSITION pos = paths.GetHeadPosition();
do {
- if (pos) m_hDrvDll = LoadLibrary(paths.GetNext(pos));
+ if (pos) {
+ m_hDrvDll = LoadLibrary(paths.GetNext(pos));
+ }
} while(pos && !m_hDrvDll);
- if(m_hDrvDll)
- {
+ if(m_hDrvDll) {
RVCustomMessage = (PRVCustomMessage)GetProcAddress(m_hDrvDll, "RV20toYUV420CustomMessage");
RVFree = (PRVFree)GetProcAddress(m_hDrvDll, "RV20toYUV420Free");
RVHiveMessage = (PRVHiveMessage)GetProcAddress(m_hDrvDll, "RV20toYUV420HiveMessage");
RVInit = (PRVInit)GetProcAddress(m_hDrvDll, "RV20toYUV420Init");
RVTransform = (PRVTransform)GetProcAddress(m_hDrvDll, "RV20toYUV420Transform");
- if(!RVCustomMessage) RVCustomMessage = (PRVCustomMessage)GetProcAddress(m_hDrvDll, "RV40toYUV420CustomMessage");
- if(!RVFree) RVFree = (PRVFree)GetProcAddress(m_hDrvDll, "RV40toYUV420Free");
- if(!RVHiveMessage) RVHiveMessage = (PRVHiveMessage)GetProcAddress(m_hDrvDll, "RV40toYUV420HiveMessage");
- if(!RVInit) RVInit = (PRVInit)GetProcAddress(m_hDrvDll, "RV40toYUV420Init");
- if(!RVTransform) RVTransform = (PRVTransform)GetProcAddress(m_hDrvDll, "RV40toYUV420Transform");
+ if(!RVCustomMessage) {
+ RVCustomMessage = (PRVCustomMessage)GetProcAddress(m_hDrvDll, "RV40toYUV420CustomMessage");
+ }
+ if(!RVFree) {
+ RVFree = (PRVFree)GetProcAddress(m_hDrvDll, "RV40toYUV420Free");
+ }
+ if(!RVHiveMessage) {
+ RVHiveMessage = (PRVHiveMessage)GetProcAddress(m_hDrvDll, "RV40toYUV420HiveMessage");
+ }
+ if(!RVInit) {
+ RVInit = (PRVInit)GetProcAddress(m_hDrvDll, "RV40toYUV420Init");
+ }
+ if(!RVTransform) {
+ RVTransform = (PRVTransform)GetProcAddress(m_hDrvDll, "RV40toYUV420Transform");
+ }
}
if(!m_hDrvDll || !RVCustomMessage
- || !RVFree || !RVHiveMessage
- || !RVInit || !RVTransform)
+ || !RVFree || !RVHiveMessage
+ || !RVInit || !RVTransform) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(FAILED(InitRV(mtIn)))
+ if(FAILED(InitRV(mtIn))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
return S_OK;
@@ -1899,12 +1975,12 @@ HRESULT CRealVideoDecoder::CheckInputType(const CMediaType* mtIn)
HRESULT CRealVideoDecoder::CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut)
{
- if(m_pOutput && m_pOutput->IsConnected())
- {
+ if(m_pOutput && m_pOutput->IsConnected()) {
BITMAPINFOHEADER bih1, bih2;
if(ExtractBIH(mtOut, &bih1) && ExtractBIH(&m_pOutput->CurrentMediaType(), &bih2)
- && abs(bih1.biHeight) != abs(bih2.biHeight))
+ && abs(bih1.biHeight) != abs(bih2.biHeight)) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
return __super::CheckTransform(mtIn, mtOut);
@@ -1913,8 +1989,9 @@ HRESULT CRealVideoDecoder::CheckTransform(const CMediaType* mtIn, const CMediaTy
HRESULT CRealVideoDecoder::StartStreaming()
{
const CMediaType& mt = m_pInput->CurrentMediaType();
- if(FAILED(InitRV(&mt)))
+ if(FAILED(InitRV(&mt))) {
return E_FAIL;
+ }
int size = m_w*m_h;
m_lastBuffSizeDim = size;
@@ -1954,9 +2031,13 @@ HRESULT CRealVideoDecoder::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tSto
HRESULT CRealVideoDecoder::AlterQuality(Quality q)
{
- if(q.Late > 500*10000i64) m_fDropFrames = true;
- if(q.Late <= 0) m_fDropFrames = false;
-// TRACE(_T("CRealVideoDecoder::AlterQuality: Type=%d, Proportion=%d, Late=%I64d, TimeStamp=%I64d\n"), q.Type, q.Proportion, q.Late, q.TimeStamp);
+ if(q.Late > 500*10000i64) {
+ m_fDropFrames = true;
+ }
+ if(q.Late <= 0) {
+ m_fDropFrames = false;
+ }
+ // TRACE(_T("CRealVideoDecoder::AlterQuality: Type=%d, Proportion=%d, Late=%I64d, TimeStamp=%I64d\n"), q.Type, q.Proportion, q.Late, q.TimeStamp);
return E_NOTIMPL;
}
@@ -1971,13 +2052,17 @@ CRealAudioDecoder::CRealAudioDecoder(LPUNKNOWN lpunk, HRESULT* phr)
, m_hDrvDll(NULL)
, m_dwCookie(0)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CRealAudioDecoder::~CRealAudioDecoder()
{
-// FreeRA();
- if(m_hDrvDll) FreeLibrary(m_hDrvDll);
+ // FreeRA();
+ if(m_hDrvDll) {
+ FreeLibrary(m_hDrvDll);
+ }
}
HRESULT CRealAudioDecoder::InitRA(const CMediaType* pmt)
@@ -1987,8 +2072,9 @@ HRESULT CRealAudioDecoder::InitRA(const CMediaType* pmt)
HRESULT hr;
if(RAOpenCodec2 && FAILED(hr = RAOpenCodec2(&m_dwCookie, m_dllpath))
- || RAOpenCodec && FAILED(hr = RAOpenCodec(&m_dwCookie)))
+ || RAOpenCodec && FAILED(hr = RAOpenCodec(&m_dwCookie))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
WAVEFORMATEX* pwfe = (WAVEFORMATEX*)pmt->Format();
@@ -2002,7 +2088,9 @@ HRESULT CRealAudioDecoder::InitRA(const CMediaType* pmt)
}
WORD wBitsPerSample = pwfe->wBitsPerSample;
- if(!wBitsPerSample) wBitsPerSample = 16;
+ if(!wBitsPerSample) {
+ wBitsPerSample = 16;
+ }
#pragma pack(push, 1)
struct {
@@ -2010,33 +2098,31 @@ HRESULT CRealAudioDecoder::InitRA(const CMediaType* pmt)
WORD bpsample, channels, quality;
DWORD bpframe, packetsize, extralen;
void* extra;
- } initdata =
- { pwfe->nSamplesPerSec, wBitsPerSample, pwfe->nChannels, 100,
+ } initdata = {
+ pwfe->nSamplesPerSec, wBitsPerSample, pwfe->nChannels, 100,
0, 0, 0, NULL
};
#pragma pack(pop)
CAutoVectorPtr<BYTE> pBuff;
- if(pmt->subtype == MEDIASUBTYPE_AAC)
- {
+ if(pmt->subtype == MEDIASUBTYPE_AAC) {
pBuff.Allocate(cbSize+1);
pBuff[0] = 0x02;
memcpy(pBuff+1, pwfe+1, cbSize);
initdata.extralen = cbSize+1;
initdata.extra = pBuff;
- }
- else
- {
- if(pmt->FormatLength() <= sizeof(WAVEFORMATEX) + cbSize) // must have type_specific_data appended
+ } else {
+ if(pmt->FormatLength() <= sizeof(WAVEFORMATEX) + cbSize) { // must have type_specific_data appended
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
BYTE* fmt = pmt->Format() + sizeof(WAVEFORMATEX) + cbSize;
- for(int i = 0, len = pmt->FormatLength() - (sizeof(WAVEFORMATEX) + cbSize); i < len-4; i++, fmt++)
- {
- if(fmt[0] == '.' || fmt[1] == 'r' || fmt[2] == 'a')
+ for(int i = 0, len = pmt->FormatLength() - (sizeof(WAVEFORMATEX) + cbSize); i < len-4; i++, fmt++) {
+ if(fmt[0] == '.' || fmt[1] == 'r' || fmt[2] == 'a') {
break;
+ }
}
m_rai = *(rainfo*)fmt;
@@ -2044,26 +2130,23 @@ HRESULT CRealAudioDecoder::InitRA(const CMediaType* pmt)
BYTE* p;
- if(m_rai.version2 == 4)
- {
+ if(m_rai.version2 == 4) {
p = (BYTE*)((rainfo4*)fmt+1);
int len = *p++;
p += len;
len = *p++;
p += len;
ASSERT(len == 4);
- }
- else if(m_rai.version2 == 5)
- {
+ } else if(m_rai.version2 == 5) {
p = (BYTE*)((rainfo5*)fmt+1);
- }
- else
- {
+ } else {
return VFW_E_TYPE_NOT_ACCEPTED;
}
p += 3;
- if(m_rai.version2 == 5) p++;
+ if(m_rai.version2 == 5) {
+ p++;
+ }
initdata.bpframe = m_rai.sub_packet_size;
initdata.packetsize = m_rai.coded_frame_size;
@@ -2071,22 +2154,24 @@ HRESULT CRealAudioDecoder::InitRA(const CMediaType* pmt)
initdata.extra = p + 4;
}
- if(FAILED(hr = RAInitDecoder(m_dwCookie, &initdata)))
+ if(FAILED(hr = RAInitDecoder(m_dwCookie, &initdata))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(RASetPwd)
+ if(RASetPwd) {
RASetPwd(m_dwCookie, "Ardubancel Quazanga");
+ }
- if(RASetFlavor && FAILED(hr = RASetFlavor(m_dwCookie, m_rai.flavor)))
+ if(RASetFlavor && FAILED(hr = RASetFlavor(m_dwCookie, m_rai.flavor))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
return S_OK;
}
void CRealAudioDecoder::FreeRA()
{
- if(m_dwCookie)
- {
+ if(m_dwCookie) {
RAFreeDecoder(m_dwCookie);
RACloseCodec(m_dwCookie);
m_dwCookie = 0;
@@ -2100,26 +2185,30 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
HRESULT hr;
AM_SAMPLE2_PROPERTIES* const pProps = m_pInput->SampleProps();
- if(pProps->dwStreamId != AM_STREAM_MEDIA)
+ if(pProps->dwStreamId != AM_STREAM_MEDIA) {
return m_pOutput->Deliver(pIn);
+ }
BYTE* pDataIn = NULL;
- if(FAILED(hr = pIn->GetPointer(&pDataIn))) return hr;
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
+ return hr;
+ }
BYTE* pDataInOrg = pDataIn;
UNUSED_ALWAYS(pDataInOrg);
long len = pIn->GetActualDataLength();
- if(len <= 0) return S_OK;
+ if(len <= 0) {
+ return S_OK;
+ }
REFERENCE_TIME rtStart, rtStop;
pIn->GetTime(&rtStart, &rtStop);
-/*
- if(pIn->IsPreroll() == S_OK || rtStart < 0)
- return S_OK;
-*/
+ /*
+ if(pIn->IsPreroll() == S_OK || rtStart < 0)
+ return S_OK;
+ */
- if(S_OK == pIn->IsSyncPoint())
- {
+ if(S_OK == pIn->IsSyncPoint()) {
m_bufflen = 0;
m_rtBuffStart = rtStart;
m_fBuffDiscontinuity = pIn->IsDiscontinuity() == S_OK;
@@ -2134,21 +2223,17 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
if(m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_RAAC
|| m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_RACP
- || m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_AAC)
- {
+ || m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_AAC) {
src = pDataIn;
dst = pDataIn + len;
w = len;
- }
- else
- {
+ } else {
memcpy(&m_buff[m_bufflen], pDataIn, len);
m_bufflen += len;
len = w*h;
- if(m_bufflen >= len)
- {
+ if(m_bufflen >= len) {
ASSERT(m_bufflen == len);
src = m_buff;
@@ -2156,12 +2241,9 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
if(sps > 0
&& (m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_COOK
- || m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_ATRC))
- {
- for(int y = 0; y < h; y++)
- {
- for(int x = 0, w2 = w / sps; x < w2; x++)
- {
+ || m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_ATRC)) {
+ for(int y = 0; y < h; y++) {
+ for(int x = 0, w2 = w / sps; x < w2; x++) {
// TRACE(_T("--- %d, %d\n"), (h*x+((h+1)/2)*(y&1)+(y>>1)), sps*(h*x+((h+1)/2)*(y&1)+(y>>1)));
memcpy(dst + sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), src, sps);
src += sps;
@@ -2170,9 +2252,7 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
src = m_buff + len;
dst = m_buff + len*2;
- }
- else if(m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_SIPR)
- {
+ } else if(m_pInput->CurrentMediaType().subtype == MEDIASUBTYPE_SIPR) {
// http://mplayerhq.hu/pipermail/mplayer-dev-eng/2002-August/010569.html
static BYTE sipr_swaps[38][2]= {
@@ -2191,10 +2271,16 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
for(int j=0; j<bs; j++) {
int x=(i&1) ? (src[(i>>1)]>>4) : (src[(i>>1)]&15);
int y=(o&1) ? (src[(o>>1)]>>4) : (src[(o>>1)]&15);
- if(o&1) src[(o>>1)]=(src[(o>>1)]&0x0F)|(x<<4);
- else src[(o>>1)]=(src[(o>>1)]&0xF0)|x;
- if(i&1) src[(i>>1)]=(src[(i>>1)]&0x0F)|(y<<4);
- else src[(i>>1)]=(src[(i>>1)]&0xF0)|y;
+ if(o&1) {
+ src[(o>>1)]=(src[(o>>1)]&0x0F)|(x<<4);
+ } else {
+ src[(o>>1)]=(src[(o>>1)]&0xF0)|x;
+ }
+ if(i&1) {
+ src[(i>>1)]=(src[(i>>1)]&0x0F)|(y<<4);
+ } else {
+ src[(i>>1)]=(src[(i>>1)]&0xF0)|y;
+ }
++i;
++o;
}
@@ -2207,17 +2293,16 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
rtStart = m_rtBuffStart;
- for(; src < dst; src += w)
- {
+ for(; src < dst; src += w) {
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
if(FAILED(hr = m_pOutput->GetDeliveryBuffer(&pOut, NULL, NULL, 0))
- || FAILED(hr = pOut->GetPointer(&pDataOut)))
+ || FAILED(hr = pOut->GetPointer(&pDataOut))) {
return hr;
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pOut->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pOut->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
m_pOutput->SetMediaType(&mt);
DeleteMediaType(pmt);
@@ -2225,11 +2310,10 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
hr = RADecode(m_dwCookie, src, w, pDataOut, &len, -1);
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
TRACE(_T("RA returned an error code!!!\n"));
continue;
-// return hr;
+ // return hr;
}
WAVEFORMATEX* pwfe = (WAVEFORMATEX*)m_pOutput->CurrentMediaType().Format();
@@ -2247,8 +2331,9 @@ HRESULT CRealAudioDecoder::Receive(IMediaSample* pIn)
DbgLog((LOG_TRACE, 0, _T("A: rtStart=%I64d, rtStop=%I64d, disc=%d, sync=%d"),
rtStart, rtStop, pOut->IsDiscontinuity() == S_OK, pOut->IsSyncPoint() == S_OK));
- if(rtStart >= 0 && S_OK != (hr = m_pOutput->Deliver(pOut)))
+ if(rtStart >= 0 && S_OK != (hr = m_pOutput->Deliver(pOut))) {
return hr;
+ }
rtStart = rtStop;
}
@@ -2269,11 +2354,11 @@ HRESULT CRealAudioDecoder::CheckInputType(const CMediaType* mtIn)
&& mtIn->subtype != MEDIASUBTYPE_SIPR
&& mtIn->subtype != MEDIASUBTYPE_RAAC
&& mtIn->subtype != MEDIASUBTYPE_RACP
- && mtIn->subtype != MEDIASUBTYPE_AAC)
+ && mtIn->subtype != MEDIASUBTYPE_AAC) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(!m_pInput->IsConnected())
- {
+ if(!m_pInput->IsConnected()) {
if(m_hDrvDll) {
FreeLibrary(m_hDrvDll);
m_hDrvDll = NULL;
@@ -2282,8 +2367,7 @@ HRESULT CRealAudioDecoder::CheckInputType(const CMediaType* mtIn)
CAtlList<CString> paths;
CString olddll, newdll, oldpath, newpath;
- TCHAR fourcc[5] =
- {
+ TCHAR fourcc[5] = {
(TCHAR)((mtIn->subtype.Data1>>0)&0xff),
(TCHAR)((mtIn->subtype.Data1>>8)&0xff),
(TCHAR)((mtIn->subtype.Data1>>16)&0xff),
@@ -2291,8 +2375,9 @@ HRESULT CRealAudioDecoder::CheckInputType(const CMediaType* mtIn)
0
};
- if(!_tcscmp(_T("RACP"), fourcc) || !_tcscmp(_T("\xff"), fourcc))
+ if(!_tcscmp(_T("RACP"), fourcc) || !_tcscmp(_T("\xff"), fourcc)) {
_tcscpy(fourcc, _T("RAAC"));
+ }
olddll.Format(_T("%s3260.dll"), fourcc);
newdll.Format(_T("%s.dll"), fourcc);
@@ -2301,37 +2386,48 @@ HRESULT CRealAudioDecoder::CheckInputType(const CMediaType* mtIn)
TCHAR buff[_MAX_PATH];
ULONG len = sizeof(buff);
if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, _T("Software\\RealNetworks\\Preferences\\DT_Codecs"), KEY_READ)
- && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0)
- {
+ && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0) {
oldpath = buff;
TCHAR c = oldpath[oldpath.GetLength()-1];
- if(c != '\\' && c != '/') oldpath += '\\';
+ if(c != '\\' && c != '/') {
+ oldpath += '\\';
+ }
key.Close();
}
len = sizeof(buff);
if(ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, _T("Helix\\HelixSDK\\10.0\\Preferences\\DT_Codecs"), KEY_READ)
- && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0)
- {
+ && ERROR_SUCCESS == key.QueryStringValue(NULL, buff, &len) && _tcslen(buff) > 0) {
newpath = buff;
TCHAR c = newpath[newpath.GetLength()-1];
- if(c != '\\' && c != '/') newpath += '\\';
+ if(c != '\\' && c != '/') {
+ newpath += '\\';
+ }
key.Close();
}
- if(!newpath.IsEmpty()) paths.AddTail(newpath + newdll);
- if(!oldpath.IsEmpty()) paths.AddTail(oldpath + newdll);
+ if(!newpath.IsEmpty()) {
+ paths.AddTail(newpath + newdll);
+ }
+ if(!oldpath.IsEmpty()) {
+ paths.AddTail(oldpath + newdll);
+ }
paths.AddTail(newdll); // default dll paths
- if(!newpath.IsEmpty()) paths.AddTail(newpath + olddll);
- if(!oldpath.IsEmpty()) paths.AddTail(oldpath + olddll);
+ if(!newpath.IsEmpty()) {
+ paths.AddTail(newpath + olddll);
+ }
+ if(!oldpath.IsEmpty()) {
+ paths.AddTail(oldpath + olddll);
+ }
paths.AddTail(olddll); // default dll paths
POSITION pos = paths.GetHeadPosition();
do {
- if (pos) m_hDrvDll = LoadLibrary(paths.GetNext(pos));
+ if (pos) {
+ m_hDrvDll = LoadLibrary(paths.GetNext(pos));
+ }
} while(pos && !m_hDrvDll);
- if(m_hDrvDll)
- {
+ if(m_hDrvDll) {
RACloseCodec = (PCloseCodec)GetProcAddress(m_hDrvDll, "RACloseCodec");
RADecode = (PDecode)GetProcAddress(m_hDrvDll, "RADecode");
RAFlush = (PFlush)GetProcAddress(m_hDrvDll, "RAFlush");
@@ -2347,23 +2443,25 @@ HRESULT CRealAudioDecoder::CheckInputType(const CMediaType* mtIn)
if(!m_hDrvDll || !RACloseCodec || !RADecode /*|| !RAFlush*/
|| !RAFreeDecoder || !RAGetFlavorProperty || !RAInitDecoder
- || !(RAOpenCodec || RAOpenCodec2) /*|| !RASetFlavor*/)
+ || !(RAOpenCodec || RAOpenCodec2) /*|| !RASetFlavor*/) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(m_hDrvDll)
- {
+ if(m_hDrvDll) {
char buff[_MAX_PATH];
GetModuleFileNameA(m_hDrvDll, buff, MAX_PATH);
CPathA p(buff);
p.RemoveFileSpec();
p.AddBackslash();
m_dllpath = p.m_strPath;
- if(RASetDLLAccessPath)
+ if(RASetDLLAccessPath) {
RASetDLLAccessPath("DT_Codecs=" + m_dllpath);
+ }
}
- if(FAILED(InitRA(mtIn)))
+ if(FAILED(InitRA(mtIn))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
return S_OK;
@@ -2387,16 +2485,22 @@ HRESULT CRealAudioDecoder::CheckTransform(const CMediaType* mtIn, const CMediaTy
HRESULT CRealAudioDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
CComPtr<IMemAllocator> pAllocatorIn;
m_pInput->GetAllocator(&pAllocatorIn);
- if(!pAllocatorIn) return E_UNEXPECTED;
+ if(!pAllocatorIn) {
+ return E_UNEXPECTED;
+ }
WAVEFORMATEX* pwfe = (WAVEFORMATEX*)m_pOutput->CurrentMediaType().Format();
WORD wBitsPerSample = pwfe->wBitsPerSample;
- if(!wBitsPerSample) wBitsPerSample = 16;
+ if(!wBitsPerSample) {
+ wBitsPerSample = 16;
+ }
// ok, maybe this is too much...
pProperties->cBuffers = 8;
@@ -2406,8 +2510,9 @@ HRESULT CRealAudioDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
? E_FAIL
@@ -2416,26 +2521,32 @@ HRESULT CRealAudioDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR
HRESULT CRealAudioDecoder::GetMediaType(int iPosition, CMediaType* pmt)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
*pmt = m_pInput->CurrentMediaType();
pmt->subtype = MEDIASUBTYPE_PCM;
WAVEFORMATEX* pwfe = (WAVEFORMATEX*)pmt->ReallocFormatBuffer(sizeof(WAVEFORMATEX));
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > (pwfe->nChannels > 2 && pwfe->nChannels <= 6 ? 1 : 0)) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > (pwfe->nChannels > 2 && pwfe->nChannels <= 6 ? 1 : 0)) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
- if(!pwfe->wBitsPerSample) pwfe->wBitsPerSample = 16;
+ if(!pwfe->wBitsPerSample) {
+ pwfe->wBitsPerSample = 16;
+ }
pwfe->cbSize = 0;
pwfe->wFormatTag = WAVE_FORMAT_PCM;
pwfe->nBlockAlign = pwfe->nChannels*pwfe->wBitsPerSample>>3;
pwfe->nAvgBytesPerSec = pwfe->nSamplesPerSec*pwfe->nBlockAlign;
- if(iPosition == 0 && pwfe->nChannels > 2 && pwfe->nChannels <= 6)
- {
- static DWORD chmask[] =
- {
+ if(iPosition == 0 && pwfe->nChannels > 2 && pwfe->nChannels <= 6) {
+ static DWORD chmask[] = {
KSAUDIO_SPEAKER_DIRECTOUT,
KSAUDIO_SPEAKER_MONO,
KSAUDIO_SPEAKER_STEREO,
diff --git a/src/filters/parser/RealMediaSplitter/RealMediaSplitter.h b/src/filters/parser/RealMediaSplitter/RealMediaSplitter.h
index b97121801..89f2e0b59 100644
--- a/src/filters/parser/RealMediaSplitter/RealMediaSplitter.h
+++ b/src/filters/parser/RealMediaSplitter/RealMediaSplitter.h
@@ -30,64 +30,60 @@
namespace RMFF
{
-typedef struct {
- union {
- char id[4];
- UINT32 object_id;
- };
- UINT32 size;
- UINT16 object_version;
-} ChunkHdr;
-typedef struct {
- UINT32 version, nHeaders;
-} FileHdr;
-typedef struct
-{
- UINT32 maxBitRate, avgBitRate;
- UINT32 maxPacketSize, avgPacketSize, nPackets;
- UINT32 tDuration, tPreroll;
- UINT32 ptrIndex, ptrData;
- UINT16 nStreams;
- enum flags_t {PN_SAVE_ENABLED=1, PN_PERFECT_PLAY_ENABLED=2, PN_LIVE_BROADCAST=4} flags;
-} Properies;
-typedef struct
-{
- UINT16 stream;
- UINT32 maxBitRate, avgBitRate;
- UINT32 maxPacketSize, avgPacketSize;
- UINT32 tStart, tPreroll, tDuration;
- CStringA name, mime;
- CAtlArray<BYTE> typeSpecData;
- UINT32 width, height;
- bool interlaced, top_field_first;
-} MediaProperies;
-typedef struct {
- CStringA title, author, copyright, comment;
-} ContentDesc;
-typedef struct {
- UINT64 pos;
- UINT32 nPackets, ptrNext;
-} DataChunk;
-typedef struct
-{
- UINT16 len, stream;
- UINT32 tStart;
- UINT8 reserved;
- enum flag_t {PN_RELIABLE_FLAG=1, PN_KEYFRAME_FLAG=2} flags; // UINT8
- CAtlArray<BYTE> pData;
-} MediaPacketHeader;
-typedef struct {
- UINT32 nIndices;
- UINT16 stream;
- UINT32 ptrNext;
-} IndexChunkHeader;
-typedef struct {
- UINT32 tStart, ptrFilePos, packet;
-} IndexRecord;
+ typedef struct {
+ union {
+ char id[4];
+ UINT32 object_id;
+ };
+ UINT32 size;
+ UINT16 object_version;
+ } ChunkHdr;
+ typedef struct {
+ UINT32 version, nHeaders;
+ } FileHdr;
+ typedef struct {
+ UINT32 maxBitRate, avgBitRate;
+ UINT32 maxPacketSize, avgPacketSize, nPackets;
+ UINT32 tDuration, tPreroll;
+ UINT32 ptrIndex, ptrData;
+ UINT16 nStreams;
+ enum flags_t {PN_SAVE_ENABLED=1, PN_PERFECT_PLAY_ENABLED=2, PN_LIVE_BROADCAST=4} flags;
+ } Properies;
+ typedef struct {
+ UINT16 stream;
+ UINT32 maxBitRate, avgBitRate;
+ UINT32 maxPacketSize, avgPacketSize;
+ UINT32 tStart, tPreroll, tDuration;
+ CStringA name, mime;
+ CAtlArray<BYTE> typeSpecData;
+ UINT32 width, height;
+ bool interlaced, top_field_first;
+ } MediaProperies;
+ typedef struct {
+ CStringA title, author, copyright, comment;
+ } ContentDesc;
+ typedef struct {
+ UINT64 pos;
+ UINT32 nPackets, ptrNext;
+ } DataChunk;
+ typedef struct {
+ UINT16 len, stream;
+ UINT32 tStart;
+ UINT8 reserved;
+ enum flag_t {PN_RELIABLE_FLAG=1, PN_KEYFRAME_FLAG=2} flags; // UINT8
+ CAtlArray<BYTE> pData;
+ } MediaPacketHeader;
+ typedef struct {
+ UINT32 nIndices;
+ UINT16 stream;
+ UINT32 ptrNext;
+ } IndexChunkHeader;
+ typedef struct {
+ UINT32 tStart, ptrFilePos, packet;
+ } IndexRecord;
}
-struct rvinfo
-{
+struct rvinfo {
DWORD dwSize, fcc1, fcc2;
WORD w, h, bpp;
DWORD unk1, fps, type1, type2;
@@ -95,8 +91,7 @@ struct rvinfo
void bswap();
};
-struct rainfo
-{
+struct rainfo {
DWORD fourcc1; // '.', 'r', 'a', 0xfd
WORD version1; // 4 or 5
WORD unknown1; // 00 000
@@ -116,8 +111,7 @@ struct rainfo
void bswap();
};
-struct rainfo4 : rainfo
-{
+struct rainfo4 : rainfo {
WORD sample_rate;
WORD unknown8; // 0
WORD sample_size;
@@ -125,8 +119,7 @@ struct rainfo4 : rainfo
void bswap();
};
-struct rainfo5 : rainfo
-{
+struct rainfo5 : rainfo {
BYTE unknown7[6]; // 0, srate, 0
WORD sample_rate;
WORD unknown8; // 0
@@ -181,8 +174,7 @@ private:
public:
REFERENCE_TIME rtStart;
bool fDiscontinuity, fSyncPoint, fMerged;
- void Clear()
- {
+ void Clear() {
CAutoLock cAutoLock(this);
rtStart = 0;
fDiscontinuity = fSyncPoint = fMerged = false;
diff --git a/src/filters/parser/SSFSplitter/SSFSplitter.cpp b/src/filters/parser/SSFSplitter/SSFSplitter.cpp
index 917e35cc0..e581a8a62 100644
--- a/src/filters/parser/SSFSplitter/SSFSplitter.cpp
+++ b/src/filters/parser/SSFSplitter/SSFSplitter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -26,26 +26,22 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_SSF},
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, 0, NULL}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CSSFSplitterFilter), L"MPC - SSF Splitter", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CSSFSourceFilter), L"MPC - SSF Source", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CSSFSplitterFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CSSFSourceFilter>, NULL, &sudFilter[1]},
};
@@ -79,16 +75,18 @@ namespace ssf
CBaseSplitterFile* m_pFile;
public:
- InputStreamBSF(CBaseSplitterFile* pFile)
- : m_pFile(pFile)
- {
+ InputStreamBSF(CBaseSplitterFile* pFile)
+ : m_pFile(pFile) {
ASSERT(m_pFile);
}
- int InputStreamBSF::NextByte()
- {
- if(!m_pFile) ThrowError(_T("m_pFile is NULL"));
- if(!m_pFile->GetRemaining()) return EOS;
+ int InputStreamBSF::NextByte() {
+ if(!m_pFile) {
+ ThrowError(_T("m_pFile is NULL"));
+ }
+ if(!m_pFile->GetRemaining()) {
+ return EOS;
+ }
return (int)m_pFile->BitRead(8);
}
};
@@ -98,8 +96,12 @@ int CSSFSplitterFilter::SegmentItemEx::Compare(const void* a, const void* b)
{
const SegmentItemEx* si1 = (const SegmentItemEx*)a;
const SegmentItemEx* si2 = (const SegmentItemEx*)b;
- if(si1->start < si2->start) return -1;
- if(si2->start < si1->start) return +1;
+ if(si1->start < si2->start) {
+ return -1;
+ }
+ if(si2->start < si1->start) {
+ return +1;
+ }
return 0;
}
@@ -120,33 +122,36 @@ HRESULT CSSFSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
m_pFile.Free();
m_pFile.Attach(DNew CBaseSplitterFile(pAsyncReader, hr));
- if(!m_pFile) return E_OUTOFMEMORY;
- if(FAILED(hr)) {m_pFile.Free(); return hr;}
+ if(!m_pFile) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ m_pFile.Free();
+ return hr;
+ }
+
+ try {
+ m_ssf.Parse(ssf::InputStreamBSF(m_pFile));
+ } catch(ssf::Exception&) {
+ return E_FAIL;
+ }
- try {m_ssf.Parse(ssf::InputStreamBSF(m_pFile));}
- catch(ssf::Exception&) {return E_FAIL;}
-
//
m_rtNewStart = m_rtCurrent = 0;
m_rtNewStop = m_rtStop = m_rtDuration = 0;
- if(ssf::Reference* pRootRef = m_ssf.GetRootRef())
- {
+ if(ssf::Reference* pRootRef = m_ssf.GetRootRef()) {
ssf::WCharOutputStream s;
ssf::StringMapW<float> offset;
POSITION pos = pRootRef->m_nodes.GetHeadPosition();
- while(pos)
- {
- if(ssf::Definition* pDef = dynamic_cast<ssf::Definition*>(pRootRef->m_nodes.GetNext(pos)))
- {
- try
- {
+ while(pos) {
+ if(ssf::Definition* pDef = dynamic_cast<ssf::Definition*>(pRootRef->m_nodes.GetNext(pos))) {
+ try {
ssf::Definition::Time time;
- if(pDef->m_type == L"subtitle" && pDef->GetAsTime(time, offset) && (*pDef)[L"@"].IsValue())
- {
+ if(pDef->m_type == L"subtitle" && pDef->GetAsTime(time, offset) && (*pDef)[L"@"].IsValue()) {
SegmentItemEx si;
si.pDef = pDef;
si.start = time.start.value;
@@ -157,12 +162,10 @@ HRESULT CSSFSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
continue;
}
- }
- catch(ssf::Exception&)
- {
+ } catch(ssf::Exception&) {
}
- pDef->Dump(s);
+ pDef->Dump(s);
}
}
@@ -178,7 +181,9 @@ HRESULT CSSFSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
memset(si, 0, sizeof(*si));
si->dwOffset = sizeof(*si);
BYTE* p = (BYTE*)(si+1);
- p[0] = 0xef; p[1] = 0xbb; p[2] = 0xbf;
+ p[0] = 0xef;
+ p[1] = 0xbb;
+ p[2] = 0xbf;
memcpy(&p[3], (LPCSTR)hdr, hdr.GetLength());
mts.Add(mt);
@@ -188,13 +193,16 @@ HRESULT CSSFSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
CAtlArray<SegmentItemEx> subs;
subs.SetCount(m_subs.GetCount());
pos = m_subs.GetHeadPosition();
- for(size_t i = 0; pos; i++) subs.SetAt(i, m_subs.GetNext(pos));
+ for(size_t i = 0; pos; i++) {
+ subs.SetAt(i, m_subs.GetNext(pos));
+ }
qsort(subs.GetData(), subs.GetCount(), sizeof(SegmentItemEx), SegmentItemEx::Compare);
m_subs.RemoveAll();
- for(size_t i = 0; i < subs.GetCount(); i++) m_subs.AddTail(subs[i]);
+ for(size_t i = 0; i < subs.GetCount(); i++) {
+ m_subs.AddTail(subs[i]);
+ }
- if(!m_ssf.m_segments.IsEmpty())
- {
+ if(!m_ssf.m_segments.IsEmpty()) {
m_rtNewStop = m_rtStop = m_rtDuration = 10000000i64*m_ssf.m_segments.GetTail().m_stop;
}
}
@@ -210,11 +218,8 @@ bool CSSFSplitterFilter::DemuxInit()
void CSSFSplitterFilter::DemuxSeek(REFERENCE_TIME rt)
{
- if(rt <= 0)
- {
- }
- else
- {
+ if(rt <= 0) {
+ } else {
// TODO
}
}
@@ -225,8 +230,7 @@ bool CSSFSplitterFilter::DemuxLoop()
POSITION pos = m_subs.GetHeadPosition();
- while(pos && SUCCEEDED(hr) && !CheckRequest(NULL))
- {
+ while(pos && SUCCEEDED(hr) && !CheckRequest(NULL)) {
SegmentItemEx& si = m_subs.GetNext(pos);
ssf::WCharOutputStream s;
diff --git a/src/filters/parser/SSFSplitter/SSFSplitter.h b/src/filters/parser/SSFSplitter/SSFSplitter.h
index 35f95c507..de76e1211 100644
--- a/src/filters/parser/SSFSplitter/SSFSplitter.h
+++ b/src/filters/parser/SSFSplitter/SSFSplitter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,14 +25,13 @@
#include "../../../Subtitles/libssf/SubtitleFile.h"
class __declspec(uuid("95C3F9F6-1E05-4C34-8122-504476EACB51"))
-CSSFSplitterFilter : public CBaseSplitterFilter
+ CSSFSplitterFilter : public CBaseSplitterFilter
{
CAutoPtr<CBaseSplitterFile> m_pFile;
ssf::SubtitleFile m_ssf;
- struct SegmentItemEx : public ssf::SubtitleFile::SegmentItem
- {
+ struct SegmentItemEx : public ssf::SubtitleFile::SegmentItem {
static int Compare(const void* a, const void* b);
};
@@ -50,7 +49,7 @@ public:
};
class __declspec(uuid("57F46A2A-6DC9-4A9F-B5FA-DFDD62B8BAFB"))
-CSSFSourceFilter : public CSSFSplitterFilter
+ CSSFSourceFilter : public CSSFSplitterFilter
{
public:
CSSFSourceFilter(LPUNKNOWN pUnk, HRESULT* phr);
diff --git a/src/filters/parser/SSFSplitter/stdafx.cpp b/src/filters/parser/SSFSplitter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/SSFSplitter/stdafx.cpp
+++ b/src/filters/parser/SSFSplitter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/SSFSplitter/stdafx.h b/src/filters/parser/SSFSplitter/stdafx.h
index 55763f8a3..432a74d80 100644
--- a/src/filters/parser/SSFSplitter/stdafx.h
+++ b/src/filters/parser/SSFSplitter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/StreamDriveThru/StreamDriveThru.cpp b/src/filters/parser/StreamDriveThru/StreamDriveThru.cpp
index f4003196c..3ca6b5489 100644
--- a/src/filters/parser/StreamDriveThru/StreamDriveThru.cpp
+++ b/src/filters/parser/StreamDriveThru/StreamDriveThru.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,29 +25,24 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CStreamDriveThruFilter), L"MPC - StreamDriveThru", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CStreamDriveThruFilter>, NULL, &sudFilter[0]}
};
@@ -77,7 +72,9 @@ CStreamDriveThruFilter::CStreamDriveThruFilter(LPUNKNOWN pUnk, HRESULT* phr)
: CBaseFilter(NAME("CStreamDriveThruFilter"), pUnk, &m_csLock, __uuidof(this))
, m_position(0)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pInput = DNew CStreamDriveThruInputPin(NAME("CStreamDriveThruInputPin"), this, &m_csLock, phr);
m_pOutput = DNew CStreamDriveThruOutputPin(NAME("CStreamDriveThruOutputPin"), this, &m_csLock, phr);
@@ -100,7 +97,7 @@ STDMETHODIMP CStreamDriveThruFilter::NonDelegatingQueryInterface(REFIID riid, vo
{
CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IMediaSeeking)
__super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -109,107 +106,98 @@ STDMETHODIMP CStreamDriveThruFilter::NonDelegatingQueryInterface(REFIID riid, vo
DWORD CStreamDriveThruFilter::ThreadProc()
{
- while(1)
- {
+ while(1) {
DWORD cmd = GetRequest();
- switch(cmd)
- {
- default:
- case CMD_EXIT:
- Reply(S_OK);
- return 0;
- case CMD_STOP:
- Reply(S_OK);
- break;
- case CMD_PAUSE:
- Reply(S_OK);
- break;
- case CMD_RUN:
- Reply(S_OK);
-
- do
- {
- CComPtr<IAsyncReader> pAsyncReader;
- CComPtr<IStream> pStream;
-
- if(!m_pInput || !m_pInput->IsConnected() || FAILED(m_pInput->GetAsyncReader(&pAsyncReader))
- || !m_pOutput || !m_pOutput->IsConnected() || FAILED(m_pOutput->GetStream(&pStream)))
- break;
-
- LARGE_INTEGER li = {0};
- ULARGE_INTEGER uli = {0};
-
- if(FAILED(pStream->Seek(li, STREAM_SEEK_SET, NULL))
- || FAILED(pStream->SetSize(uli)))
- break;
-
- if(CComQIPtr<IFileSinkFilter2> pFSF = GetFilterFromPin(m_pOutput->GetConnected()))
- {
- pFSF->SetMode(AM_FILE_OVERWRITE);
-
- LPOLESTR pfn;
- if(SUCCEEDED(pFSF->GetCurFile(&pfn, NULL)))
- {
- pFSF->SetFileName(pfn, NULL);
- CoTaskMemFree(pfn);
+ switch(cmd) {
+ default:
+ case CMD_EXIT:
+ Reply(S_OK);
+ return 0;
+ case CMD_STOP:
+ Reply(S_OK);
+ break;
+ case CMD_PAUSE:
+ Reply(S_OK);
+ break;
+ case CMD_RUN:
+ Reply(S_OK);
+
+ do {
+ CComPtr<IAsyncReader> pAsyncReader;
+ CComPtr<IStream> pStream;
+
+ if(!m_pInput || !m_pInput->IsConnected() || FAILED(m_pInput->GetAsyncReader(&pAsyncReader))
+ || !m_pOutput || !m_pOutput->IsConnected() || FAILED(m_pOutput->GetStream(&pStream))) {
+ break;
}
- }
-
- m_position = 0;
- BYTE buff[PACKETSIZE];
-
- do
- {
- while(!CheckRequest(&cmd))
- {
- CAutoLock csAutoLock(&m_csLock);
-
- LONGLONG total = 0, available = 0;
- if(FAILED(pAsyncReader->Length(&total, &available)) || m_position >= total)
- {
- cmd = CMD_STOP;
- break;
- }
- LONG size = (LONG)min(PACKETSIZE, total - m_position);
- if(FAILED(pAsyncReader->SyncRead(m_position, size, buff)))
- {
- cmd = CMD_STOP;
- break;
- }
+ LARGE_INTEGER li = {0};
+ ULARGE_INTEGER uli = {0};
- ULONG written = 0;
- if(FAILED(pStream->Write(buff, (ULONG)size, &written)) || (ULONG)size != written)
- {
- cmd = CMD_STOP;
- break;
- }
+ if(FAILED(pStream->Seek(li, STREAM_SEEK_SET, NULL))
+ || FAILED(pStream->SetSize(uli))) {
+ break;
+ }
- m_position += size;
+ if(CComQIPtr<IFileSinkFilter2> pFSF = GetFilterFromPin(m_pOutput->GetConnected())) {
+ pFSF->SetMode(AM_FILE_OVERWRITE);
+
+ LPOLESTR pfn;
+ if(SUCCEEDED(pFSF->GetCurFile(&pfn, NULL))) {
+ pFSF->SetFileName(pfn, NULL);
+ CoTaskMemFree(pfn);
+ }
}
- if(cmd == CMD_PAUSE)
- {
- Reply(S_OK); // reply to CMD_PAUSE
+ m_position = 0;
+ BYTE buff[PACKETSIZE];
- while(!CheckRequest(&cmd))
- Sleep(50);
+ do {
+ while(!CheckRequest(&cmd)) {
+ CAutoLock csAutoLock(&m_csLock);
- Reply(S_OK); // reply to something
- }
- }
- while(cmd == CMD_RUN);
+ LONGLONG total = 0, available = 0;
+ if(FAILED(pAsyncReader->Length(&total, &available)) || m_position >= total) {
+ cmd = CMD_STOP;
+ break;
+ }
+
+ LONG size = (LONG)min(PACKETSIZE, total - m_position);
+ if(FAILED(pAsyncReader->SyncRead(m_position, size, buff))) {
+ cmd = CMD_STOP;
+ break;
+ }
- uli.QuadPart = m_position;
- pStream->SetSize(uli);
+ ULONG written = 0;
+ if(FAILED(pStream->Write(buff, (ULONG)size, &written)) || (ULONG)size != written) {
+ cmd = CMD_STOP;
+ break;
+ }
- if(CComPtr<IPin> pPin = m_pOutput->GetConnected())
- pPin->EndOfStream();
- }
- while(false);
+ m_position += size;
+ }
+
+ if(cmd == CMD_PAUSE) {
+ Reply(S_OK); // reply to CMD_PAUSE
+
+ while(!CheckRequest(&cmd)) {
+ Sleep(50);
+ }
+
+ Reply(S_OK); // reply to something
+ }
+ } while(cmd == CMD_RUN);
+
+ uli.QuadPart = m_position;
+ pStream->SetSize(uli);
+
+ if(CComPtr<IPin> pPin = m_pOutput->GetConnected()) {
+ pPin->EndOfStream();
+ }
+ } while(false);
- break;
+ break;
}
}
@@ -223,20 +211,24 @@ int CStreamDriveThruFilter::GetPinCount()
CBasePin* CStreamDriveThruFilter::GetPin(int n)
{
- CAutoLock csAutoLock(&m_csLock);
+ CAutoLock csAutoLock(&m_csLock);
- if(n == 0) return m_pInput;
- else if(n == 1) return m_pOutput;
+ if(n == 0) {
+ return m_pInput;
+ } else if(n == 1) {
+ return m_pOutput;
+ }
- return NULL;
+ return NULL;
}
STDMETHODIMP CStreamDriveThruFilter::Stop()
{
HRESULT hr;
-
- if(FAILED(hr = __super::Stop()))
+
+ if(FAILED(hr = __super::Stop())) {
return hr;
+ }
CallWorker(CMD_STOP);
@@ -246,9 +238,10 @@ STDMETHODIMP CStreamDriveThruFilter::Stop()
STDMETHODIMP CStreamDriveThruFilter::Pause()
{
HRESULT hr;
-
- if(FAILED(hr = __super::Pause()))
+
+ if(FAILED(hr = __super::Pause())) {
return hr;
+ }
CallWorker(CMD_PAUSE);
@@ -258,9 +251,10 @@ STDMETHODIMP CStreamDriveThruFilter::Pause()
STDMETHODIMP CStreamDriveThruFilter::Run(REFERENCE_TIME tStart)
{
HRESULT hr;
-
- if(FAILED(hr = __super::Run(tStart)))
+
+ if(FAILED(hr = __super::Run(tStart))) {
return hr;
+ }
CallWorker(CMD_RUN);
@@ -277,7 +271,9 @@ STDMETHODIMP CStreamDriveThruFilter::CheckCapabilities(DWORD* pCapabilities)
{
CheckPointer(pCapabilities, E_POINTER);
- if(*pCapabilities == 0) return S_OK;
+ if(*pCapabilities == 0) {
+ return S_OK;
+ }
DWORD caps;
GetCapabilities(&caps);
@@ -311,11 +307,9 @@ STDMETHODIMP CStreamDriveThruFilter::GetDuration(LONGLONG* pDuration)
CheckPointer(pDuration, E_POINTER);
CheckPointer(m_pInput, VFW_E_NOT_CONNECTED);
- if(CComQIPtr<IAsyncReader> pAsyncReader = m_pInput->GetConnected())
- {
+ if(CComQIPtr<IAsyncReader> pAsyncReader = m_pInput->GetConnected()) {
LONGLONG total, available;
- if(SUCCEEDED(pAsyncReader->Length(&total, &available)))
- {
+ if(SUCCEEDED(pAsyncReader->Length(&total, &available))) {
*pDuration = total;
return S_OK;
}
@@ -331,12 +325,30 @@ STDMETHODIMP CStreamDriveThruFilter::GetCurrentPosition(LONGLONG* pCurrent)
{
return pCurrent ? *pCurrent = m_position, S_OK : E_POINTER;
}
-STDMETHODIMP CStreamDriveThruFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {return E_NOTIMPL;}
-STDMETHODIMP CStreamDriveThruFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) {return E_NOTIMPL;}
-STDMETHODIMP CStreamDriveThruFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) {return E_NOTIMPL;}
-STDMETHODIMP CStreamDriveThruFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) {return E_NOTIMPL;}
-STDMETHODIMP CStreamDriveThruFilter::SetRate(double dRate) {return E_NOTIMPL;}
-STDMETHODIMP CStreamDriveThruFilter::GetRate(double* pdRate) {return E_NOTIMPL;}
+STDMETHODIMP CStreamDriveThruFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CStreamDriveThruFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CStreamDriveThruFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CStreamDriveThruFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CStreamDriveThruFilter::SetRate(double dRate)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CStreamDriveThruFilter::GetRate(double* pdRate)
+{
+ return E_NOTIMPL;
+}
STDMETHODIMP CStreamDriveThruFilter::GetPreroll(LONGLONG* pllPreroll)
{
return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER;
@@ -372,26 +384,28 @@ STDMETHODIMP CStreamDriveThruInputPin::NonDelegatingQueryInterface(REFIID riid,
{
CheckPointer(ppv, E_POINTER);
- return
+ return
__super::NonDelegatingQueryInterface(riid, ppv);
}
HRESULT CStreamDriveThruInputPin::CheckMediaType(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Stream
- ? S_OK
- : E_INVALIDARG;
+ ? S_OK
+ : E_INVALIDARG;
}
HRESULT CStreamDriveThruInputPin::CheckConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CheckConnect(pPin)))
+ if(FAILED(hr = __super::CheckConnect(pPin))) {
return hr;
+ }
- if(!CComQIPtr<IAsyncReader>(pPin))
+ if(!CComQIPtr<IAsyncReader>(pPin)) {
return E_NOINTERFACE;
+ }
return S_OK;
}
@@ -400,8 +414,9 @@ HRESULT CStreamDriveThruInputPin::BreakConnect()
{
HRESULT hr;
- if(FAILED(hr = __super::BreakConnect()))
+ if(FAILED(hr = __super::BreakConnect())) {
return hr;
+ }
m_pAsyncReader.Release();
@@ -412,8 +427,9 @@ HRESULT CStreamDriveThruInputPin::CompleteConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CompleteConnect(pPin)))
+ if(FAILED(hr = __super::CompleteConnect(pPin))) {
return hr;
+ }
CheckPointer(pPin, E_POINTER);
m_pAsyncReader = pPin;
@@ -462,42 +478,50 @@ STDMETHODIMP CStreamDriveThruOutputPin::NonDelegatingQueryInterface(REFIID riid,
{
CheckPointer(ppv, E_POINTER);
- return
+ return
__super::NonDelegatingQueryInterface(riid, ppv);
}
HRESULT CStreamDriveThruOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
pProperties->cBuffers = 1;
pProperties->cbBuffer = PACKETSIZE;
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CStreamDriveThruOutputPin::CheckMediaType(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Stream
- ? S_OK
- : E_INVALIDARG;
+ ? S_OK
+ : E_INVALIDARG;
}
HRESULT CStreamDriveThruOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pLock);
+ CAutoLock cAutoLock(m_pLock);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->majortype = MEDIATYPE_Stream;
pmt->subtype = GUID_NULL;
@@ -511,11 +535,13 @@ HRESULT CStreamDriveThruOutputPin::CheckConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CheckConnect(pPin)))
+ if(FAILED(hr = __super::CheckConnect(pPin))) {
return hr;
+ }
- if(!CComQIPtr<IStream>(pPin))
+ if(!CComQIPtr<IStream>(pPin)) {
return E_NOINTERFACE;
+ }
return S_OK;
}
@@ -524,8 +550,9 @@ HRESULT CStreamDriveThruOutputPin::BreakConnect()
{
HRESULT hr;
- if(FAILED(hr = __super::BreakConnect()))
+ if(FAILED(hr = __super::BreakConnect())) {
return hr;
+ }
m_pStream.Release();
@@ -536,8 +563,9 @@ HRESULT CStreamDriveThruOutputPin::CompleteConnect(IPin* pPin)
{
HRESULT hr;
- if(FAILED(hr = __super::CompleteConnect(pPin)))
+ if(FAILED(hr = __super::CompleteConnect(pPin))) {
return hr;
+ }
CheckPointer(pPin, E_POINTER);
m_pStream = pPin;
diff --git a/src/filters/parser/StreamDriveThru/StreamDriveThru.h b/src/filters/parser/StreamDriveThru/StreamDriveThru.h
index d55b7aeca..62bd97bcd 100644
--- a/src/filters/parser/StreamDriveThru/StreamDriveThru.h
+++ b/src/filters/parser/StreamDriveThru/StreamDriveThru.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -36,12 +36,12 @@ public:
HRESULT GetAsyncReader(IAsyncReader** ppAsyncReader);
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- HRESULT CheckMediaType(const CMediaType* pmt);
+ HRESULT CheckMediaType(const CMediaType* pmt);
- HRESULT CheckConnect(IPin* pPin);
- HRESULT BreakConnect();
+ HRESULT CheckConnect(IPin* pPin);
+ HRESULT BreakConnect();
HRESULT CompleteConnect(IPin* pPin);
STDMETHODIMP BeginFlush();
@@ -59,16 +59,16 @@ public:
HRESULT GetStream(IStream** ppStream);
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT CheckMediaType(const CMediaType* pmt);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ HRESULT CheckMediaType(const CMediaType* pmt);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- HRESULT CheckConnect(IPin* pPin);
- HRESULT BreakConnect();
- HRESULT CompleteConnect(IPin* pPin);
+ HRESULT CheckConnect(IPin* pPin);
+ HRESULT BreakConnect();
+ HRESULT CompleteConnect(IPin* pPin);
STDMETHODIMP BeginFlush();
STDMETHODIMP EndFlush();
@@ -77,7 +77,7 @@ public:
};
class __declspec(uuid("534FE6FD-F1F0-4aec-9F45-FF397320CE33"))
-CStreamDriveThruFilter : public CBaseFilter, protected CAMThread, public IMediaSeeking
+ CStreamDriveThruFilter : public CBaseFilter, protected CAMThread, public IMediaSeeking
{
CCritSec m_csLock;
@@ -86,7 +86,7 @@ CStreamDriveThruFilter : public CBaseFilter, protected CAMThread, public IMediaS
protected:
enum {CMD_EXIT, CMD_STOP, CMD_PAUSE, CMD_RUN};
- DWORD ThreadProc();
+ DWORD ThreadProc();
LONGLONG m_position;
@@ -95,7 +95,7 @@ public:
virtual ~CStreamDriveThruFilter();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
int GetPinCount();
CBasePin* GetPin(int n);
diff --git a/src/filters/parser/StreamDriveThru/stdafx.cpp b/src/filters/parser/StreamDriveThru/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/parser/StreamDriveThru/stdafx.cpp
+++ b/src/filters/parser/StreamDriveThru/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/parser/StreamDriveThru/stdafx.h b/src/filters/parser/StreamDriveThru/stdafx.h
index b55bcba79..a8c9e282b 100644
--- a/src/filters/parser/StreamDriveThru/stdafx.h
+++ b/src/filters/parser/StreamDriveThru/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/CDDAReader/CDDAReader.cpp b/src/filters/reader/CDDAReader/CDDAReader.cpp
index bc74ac8a5..d0515786b 100644
--- a/src/filters/reader/CDDAReader/CDDAReader.cpp
+++ b/src/filters/reader/CDDAReader/CDDAReader.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -29,23 +29,19 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut},
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CCDDAReader), L"MPC - CDDA Reader", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CCDDAReader>, NULL, &sudFilter[0]}
};
@@ -53,22 +49,21 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- if(GetVersion()&0x80000000)
- {
+ if(GetVersion()&0x80000000) {
::MessageBox(NULL, _T("Sorry, this will only run on Windows NT based operating system."), _T("CDDA Reader"), MB_OK);
return E_NOTIMPL;
}
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{54A35221-2C8D-4a31-A5DF-6D809847E393}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{54A35221-2C8D-4a31-A5DF-6D809847E393}"),
_T("0"), _T("0,4,,52494646,8,4,,43444441")); // "RIFFxxxxCDDA"
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{54A35221-2C8D-4a31-A5DF-6D809847E393}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{54A35221-2C8D-4a31-A5DF-6D809847E393}"),
_T("Source Filter"), _T("{54A35221-2C8D-4a31-A5DF-6D809847E393}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".cda"),
+ _T("Media Type\\Extensions"), _T(".cda"),
_T("Source Filter"), _T("{54A35221-2C8D-4a31-A5DF-6D809847E393}"));
return AMovieDllRegisterServer2(TRUE);
@@ -95,11 +90,14 @@ CFilterApp theApp;
CCDDAReader::CCDDAReader(IUnknown* pUnk, HRESULT* phr)
: CAsyncReader(NAME("CCDDAReader"), pUnk, &m_stream, phr, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
- if(GetVersion()&0x80000000)
- {
- if(phr) *phr = E_NOTIMPL;
+ if(GetVersion()&0x80000000) {
+ if(phr) {
+ *phr = E_NOTIMPL;
+ }
return;
}
}
@@ -110,9 +108,9 @@ CCDDAReader::~CCDDAReader()
STDMETHODIMP CCDDAReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
QI2(IAMMediaContent)
__super::NonDelegatingQueryInterface(riid, ppv);
@@ -120,10 +118,11 @@ STDMETHODIMP CCDDAReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
// IFileSourceFilter
-STDMETHODIMP CCDDAReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CCDDAReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(!m_stream.Load(pszFileName))
+ if(!m_stream.Load(pszFileName)) {
return E_FAIL;
+ }
m_fn = pszFileName;
@@ -140,8 +139,9 @@ STDMETHODIMP CCDDAReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
CheckPointer(ppszFileName, E_POINTER);
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -150,16 +150,30 @@ STDMETHODIMP CCDDAReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
// IAMMediaContent
-STDMETHODIMP CCDDAReader::GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {return E_NOTIMPL;}
+STDMETHODIMP CCDDAReader::GetTypeInfoCount(UINT* pctinfo)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr)
+{
+ return E_NOTIMPL;
+}
STDMETHODIMP CCDDAReader::get_AuthorName(BSTR* pbstrAuthorName)
{
CheckPointer(pbstrAuthorName, E_POINTER);
CString str = m_stream.m_trackArtist;
- if(str.IsEmpty()) str = m_stream.m_discArtist;
+ if(str.IsEmpty()) {
+ str = m_stream.m_discArtist;
+ }
*pbstrAuthorName = str.AllocSysString();
return S_OK;
}
@@ -168,22 +182,57 @@ STDMETHODIMP CCDDAReader::get_Title(BSTR* pbstrTitle)
{
CheckPointer(pbstrTitle, E_POINTER);
CString str = m_stream.m_trackTitle;
- if(str.IsEmpty()) str = m_stream.m_discTitle;
+ if(str.IsEmpty()) {
+ str = m_stream.m_discTitle;
+ }
*pbstrTitle = str.AllocSysString();
return S_OK;
}
-STDMETHODIMP CCDDAReader::get_Rating(BSTR* pbstrRating) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_Description(BSTR* pbstrDescription) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_Copyright(BSTR* pbstrCopyright) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_BaseURL(BSTR* pbstrBaseURL) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_LogoURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_LogoIconURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_WatermarkURL(BSTR* pbstrWatermarkURL) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {return E_NOTIMPL;}
-STDMETHODIMP CCDDAReader::get_MoreInfoText(BSTR* pbstrMoreInfoText) {return E_NOTIMPL;}
+STDMETHODIMP CCDDAReader::get_Rating(BSTR* pbstrRating)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_Description(BSTR* pbstrDescription)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_Copyright(BSTR* pbstrCopyright)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_BaseURL(BSTR* pbstrBaseURL)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_LogoURL(BSTR* pbstrLogoURL)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_LogoIconURL(BSTR* pbstrLogoURL)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_WatermarkURL(BSTR* pbstrWatermarkURL)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_MoreInfoURL(BSTR* pbstrMoreInfoURL)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL)
+{
+ return E_NOTIMPL;
+}
+STDMETHODIMP CCDDAReader::get_MoreInfoText(BSTR* pbstrMoreInfoText)
+{
+ return E_NOTIMPL;
+}
// CCDDAStream
@@ -212,8 +261,7 @@ CCDDAStream::CCDDAStream()
CCDDAStream::~CCDDAStream()
{
- if(m_hDrive != INVALID_HANDLE_VALUE)
- {
+ if(m_hDrive != INVALID_HANDLE_VALUE) {
CloseHandle(m_hDrive);
m_hDrive = INVALID_HANDLE_VALUE;
}
@@ -225,31 +273,32 @@ bool CCDDAStream::Load(const WCHAR* fnw)
int iDriveLetter = path.Find(_T(":\\"))-1;
int iTrackIndex = CString(path).MakeLower().Find(_T(".cda"))-1;
- if(iDriveLetter < 0 || iTrackIndex <= iDriveLetter)
+ if(iDriveLetter < 0 || iTrackIndex <= iDriveLetter) {
return(false);
+ }
CString drive = CString(_T("\\\\.\\")) + path[iDriveLetter] + _T(":");
- while(iTrackIndex > 0 && _istdigit(path[iTrackIndex-1])) iTrackIndex--;
- if(1 != _stscanf(path.Mid(iTrackIndex), _T("%d"), &iTrackIndex))
+ while(iTrackIndex > 0 && _istdigit(path[iTrackIndex-1])) {
+ iTrackIndex--;
+ }
+ if(1 != _stscanf(path.Mid(iTrackIndex), _T("%d"), &iTrackIndex)) {
return(false);
+ }
- if(m_hDrive != INVALID_HANDLE_VALUE)
- {
+ if(m_hDrive != INVALID_HANDLE_VALUE) {
CloseHandle(m_hDrive);
m_hDrive = INVALID_HANDLE_VALUE;
}
- m_hDrive = CreateFile(drive, GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_READONLY|FILE_FLAG_SEQUENTIAL_SCAN, (HANDLE)NULL);
- if(m_hDrive == INVALID_HANDLE_VALUE)
- {
+ m_hDrive = CreateFile(drive, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_READONLY|FILE_FLAG_SEQUENTIAL_SCAN, (HANDLE)NULL);
+ if(m_hDrive == INVALID_HANDLE_VALUE) {
return(false);
}
DWORD BytesReturned;
if(!DeviceIoControl(m_hDrive, IOCTL_CDROM_READ_TOC, NULL, 0, &m_TOC, sizeof(m_TOC), &BytesReturned, 0)
- || !(m_TOC.FirstTrack <= iTrackIndex && iTrackIndex <= m_TOC.LastTrack))
- {
+ || !(m_TOC.FirstTrack <= iTrackIndex && iTrackIndex <= m_TOC.LastTrack)) {
CloseHandle(m_hDrive);
m_hDrive = INVALID_HANDLE_VALUE;
return(false);
@@ -257,15 +306,15 @@ bool CCDDAStream::Load(const WCHAR* fnw)
// MMC-3 Draft Revision 10g: Table 222 – Q Sub-channel control field
m_TOC.TrackData[iTrackIndex-1].Control &= 5;
- if(!(m_TOC.TrackData[iTrackIndex-1].Control == 0 || m_TOC.TrackData[iTrackIndex-1].Control == 1))
- {
+ if(!(m_TOC.TrackData[iTrackIndex-1].Control == 0 || m_TOC.TrackData[iTrackIndex-1].Control == 1)) {
CloseHandle(m_hDrive);
m_hDrive = INVALID_HANDLE_VALUE;
return(false);
}
- if(m_TOC.TrackData[iTrackIndex-1].Control&8)
+ if(m_TOC.TrackData[iTrackIndex-1].Control&8) {
m_header.frm.pcm.wf.nChannels = 4;
+ }
m_nStartSector = MSF2UINT(m_TOC.TrackData[iTrackIndex-1].Address) - 150;//MSF2UINT(m_TOC.TrackData[0].Address);
m_nStopSector = MSF2UINT(m_TOC.TrackData[iTrackIndex].Address) - 150;//MSF2UINT(m_TOC.TrackData[0].Address);
@@ -275,16 +324,16 @@ bool CCDDAStream::Load(const WCHAR* fnw)
m_header.riff.hdr.chunkSize = (long)(m_llLength + sizeof(m_header) - 8);
m_header.data.hdr.chunkSize = (long)(m_llLength);
- do
- {
+ do {
CDROM_READ_TOC_EX TOCEx;
memset(&TOCEx, 0, sizeof(TOCEx));
TOCEx.Format = CDROM_READ_TOC_EX_FORMAT_CDTEXT;
TOCEx.SessionTrack = iTrackIndex;
WORD size = 0;
ASSERT(MINIMUM_CDROM_READ_TOC_EX_SIZE == sizeof(size));
- if(!DeviceIoControl(m_hDrive, IOCTL_CDROM_READ_TOC_EX, &TOCEx, sizeof(TOCEx), &size, sizeof(size), &BytesReturned, 0))
+ if(!DeviceIoControl(m_hDrive, IOCTL_CDROM_READ_TOC_EX, &TOCEx, sizeof(TOCEx), &size, sizeof(size), &BytesReturned, 0)) {
break;
+ }
size = ((size>>8)|(size<<8)) + sizeof(size);
@@ -292,50 +341,48 @@ bool CCDDAStream::Load(const WCHAR* fnw)
pCDTextData.Allocate(size);
memset(pCDTextData, 0, size);
- if(!DeviceIoControl(m_hDrive, IOCTL_CDROM_READ_TOC_EX, &TOCEx, sizeof(TOCEx), pCDTextData, size, &BytesReturned, 0))
+ if(!DeviceIoControl(m_hDrive, IOCTL_CDROM_READ_TOC_EX, &TOCEx, sizeof(TOCEx), pCDTextData, size, &BytesReturned, 0)) {
break;
+ }
size = (WORD)(BytesReturned - sizeof(CDROM_TOC_CD_TEXT_DATA));
CDROM_TOC_CD_TEXT_DATA_BLOCK* pDesc = ((CDROM_TOC_CD_TEXT_DATA*)(BYTE*)pCDTextData)->Descriptors;
CStringArray str[16];
- for(int i = 0; i < 16; i++) str[i].SetSize(1+m_TOC.LastTrack);
+ for(int i = 0; i < 16; i++) {
+ str[i].SetSize(1+m_TOC.LastTrack);
+ }
CString last;
- for(int i = 0; size >= sizeof(CDROM_TOC_CD_TEXT_DATA_BLOCK); i++, size -= sizeof(CDROM_TOC_CD_TEXT_DATA_BLOCK), pDesc++)
- {
- if(pDesc->TrackNumber > m_TOC.LastTrack)
+ for(int i = 0; size >= sizeof(CDROM_TOC_CD_TEXT_DATA_BLOCK); i++, size -= sizeof(CDROM_TOC_CD_TEXT_DATA_BLOCK), pDesc++) {
+ if(pDesc->TrackNumber > m_TOC.LastTrack) {
continue;
+ }
const int lenU = countof(pDesc->Text);
const int lenW = countof(pDesc->WText);
- CString text = !pDesc->Unicode
- ? CString(CStringA((CHAR*)pDesc->Text, lenU))
- : CString(CStringW((WCHAR*)pDesc->WText, lenW));
+ CString text = !pDesc->Unicode
+ ? CString(CStringA((CHAR*)pDesc->Text, lenU))
+ : CString(CStringW((WCHAR*)pDesc->WText, lenW));
int tlen = text.GetLength();
CString tmp = (tlen < 12-1)
- ? (!pDesc->Unicode
- ? CString(CStringA((CHAR*)pDesc->Text+tlen+1, lenU-(tlen+1)))
- : CString(CStringW((WCHAR*)pDesc->WText+tlen+1, lenW-(tlen+1))))
- : _T("");
+ ? (!pDesc->Unicode
+ ? CString(CStringA((CHAR*)pDesc->Text+tlen+1, lenU-(tlen+1)))
+ : CString(CStringW((WCHAR*)pDesc->WText+tlen+1, lenW-(tlen+1))))
+ : _T("");
- if((pDesc->PackType -= 0x80) >= 0x10)
+ if((pDesc->PackType -= 0x80) >= 0x10) {
continue;
+ }
- if(pDesc->CharacterPosition == 0)
- {
+ if(pDesc->CharacterPosition == 0) {
str[pDesc->PackType][pDesc->TrackNumber] = text;
- }
- else if(pDesc->CharacterPosition <= 0xf)
- {
- if(pDesc->CharacterPosition < 0xf && last.GetLength() > 0)
- {
+ } else if(pDesc->CharacterPosition <= 0xf) {
+ if(pDesc->CharacterPosition < 0xf && last.GetLength() > 0) {
str[pDesc->PackType][pDesc->TrackNumber] = last + text;
- }
- else
- {
+ } else {
str[pDesc->PackType][pDesc->TrackNumber] += text;
}
}
@@ -347,16 +394,17 @@ bool CCDDAStream::Load(const WCHAR* fnw)
m_trackTitle = str[0][iTrackIndex];
m_discArtist = str[1][0];
m_trackArtist = str[1][iTrackIndex];
- }
- while(0);
-
+ } while(0);
+
return(true);
}
HRESULT CCDDAStream::SetPointer(LONGLONG llPos)
{
- if(llPos < 0 || llPos > m_llLength) return S_FALSE;
+ if(llPos < 0 || llPos > m_llLength) {
+ return S_FALSE;
+ }
m_llPosition = llPos;
return S_OK;
}
@@ -371,8 +419,7 @@ HRESULT CCDDAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
LONGLONG pos = m_llPosition;
size_t len = (size_t)dwBytesToRead;
- if(pos < sizeof(m_header) && len > 0)
- {
+ if(pos < sizeof(m_header) && len > 0) {
size_t l = (size_t)min(len, sizeof(m_header) - pos);
memcpy(pbBuffer, &((BYTE*)&m_header)[pos], l);
pbBuffer += l;
@@ -382,8 +429,7 @@ HRESULT CCDDAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
pos -= sizeof(m_header);
- while(pos >= 0 && pos < m_llLength && len > 0)
- {
+ while(pos >= 0 && pos < m_llLength && len > 0) {
RAW_READ_INFO rawreadinfo;
rawreadinfo.SectorCount = 1;
rawreadinfo.TrackMode = CDDA;
@@ -394,10 +440,10 @@ HRESULT CCDDAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
rawreadinfo.DiskOffset.QuadPart = sector*2048;
DWORD BytesReturned = 0;
BOOL b = DeviceIoControl(
- m_hDrive, IOCTL_CDROM_RAW_READ,
- &rawreadinfo, sizeof(rawreadinfo),
- buff, RAW_SECTOR_SIZE,
- &BytesReturned, 0);
+ m_hDrive, IOCTL_CDROM_RAW_READ,
+ &rawreadinfo, sizeof(rawreadinfo),
+ buff, RAW_SECTOR_SIZE,
+ &BytesReturned, 0);
UNUSED_ALWAYS(b);
size_t l = (size_t)min(min(len, RAW_SECTOR_SIZE - offset), m_llLength - pos);
@@ -408,7 +454,9 @@ HRESULT CCDDAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
len -= l;
}
- if(pdwBytesRead) *pdwBytesRead = pbBuffer - pbBufferOrg;
+ if(pdwBytesRead) {
+ *pdwBytesRead = pbBuffer - pbBufferOrg;
+ }
m_llPosition += pbBuffer - pbBufferOrg;
return S_OK;
@@ -417,22 +465,24 @@ HRESULT CCDDAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
LONGLONG CCDDAStream::Size(LONGLONG* pSizeAvailable)
{
LONGLONG size = sizeof(m_header) + m_llLength;
- if(pSizeAvailable) *pSizeAvailable = size;
- return size;
+ if(pSizeAvailable) {
+ *pSizeAvailable = size;
+ }
+ return size;
}
DWORD CCDDAStream::Alignment()
{
- return 1;
+ return 1;
}
void CCDDAStream::Lock()
{
- m_csLock.Lock();
+ m_csLock.Lock();
}
void CCDDAStream::Unlock()
{
- m_csLock.Unlock();
+ m_csLock.Unlock();
}
diff --git a/src/filters/reader/CDDAReader/CDDAReader.h b/src/filters/reader/CDDAReader/CDDAReader.h
index cccee0987..f491b38ce 100644
--- a/src/filters/reader/CDDAReader/CDDAReader.h
+++ b/src/filters/reader/CDDAReader/CDDAReader.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,24 +28,39 @@
#include "../AsyncReader/asyncio.h"
#include "../AsyncReader/asyncrdr.h"
-typedef struct {UINT chunkID; long chunkSize;} ChunkHeader;
+typedef struct {
+ UINT chunkID;
+ long chunkSize;
+} ChunkHeader;
-#define RIFFID 'FFIR'
-#define WAVEID 'EVAW'
-typedef struct {ChunkHeader hdr; UINT WAVE;} RIFFChunk;
+#define RIFFID 'FFIR'
+#define WAVEID 'EVAW'
+typedef struct {
+ ChunkHeader hdr;
+ UINT WAVE;
+} RIFFChunk;
-#define FormatID ' tmf'
-typedef struct {ChunkHeader hdr; PCMWAVEFORMAT pcm;} FormatChunk;
+#define FormatID ' tmf'
+typedef struct {
+ ChunkHeader hdr;
+ PCMWAVEFORMAT pcm;
+} FormatChunk;
#define DataID 'atad'
-typedef struct {ChunkHeader hdr;} DataChunk;
+typedef struct {
+ ChunkHeader hdr;
+} DataChunk;
-typedef struct {RIFFChunk riff; FormatChunk frm; DataChunk data;} WAVEChunck;
+typedef struct {
+ RIFFChunk riff;
+ FormatChunk frm;
+ DataChunk data;
+} WAVEChunck;
class CCDDAStream : public CAsyncStream
{
private:
- CCritSec m_csLock;
+ CCritSec m_csLock;
LONGLONG m_llPosition, m_llLength;
@@ -65,29 +80,29 @@ public:
bool Load(const WCHAR* fnw);
// overrides
- HRESULT SetPointer(LONGLONG llPos);
- HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
- LONGLONG Size(LONGLONG* pSizeAvailable);
- DWORD Alignment();
- void Lock();
+ HRESULT SetPointer(LONGLONG llPos);
+ HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
+ LONGLONG Size(LONGLONG* pSizeAvailable);
+ DWORD Alignment();
+ void Lock();
void Unlock();
};
class __declspec(uuid("54A35221-2C8D-4a31-A5DF-6D809847E393"))
-CCDDAReader
+ CCDDAReader
: public CAsyncReader
, public IFileSourceFilter
, public IAMMediaContent
{
- CCDDAStream m_stream;
+ CCDDAStream m_stream;
CStringW m_fn;
public:
- CCDDAReader(IUnknown* pUnk, HRESULT* phr);
+ CCDDAReader(IUnknown* pUnk, HRESULT* phr);
~CCDDAReader();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
@@ -96,23 +111,23 @@ public:
// IAMMediaContent
- STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid);
- STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
-
- STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName);
- STDMETHODIMP get_Title(BSTR* pbstrTitle);
- STDMETHODIMP get_Rating(BSTR* pbstrRating);
- STDMETHODIMP get_Description(BSTR* pbstrDescription);
- STDMETHODIMP get_Copyright(BSTR* pbstrCopyright);
- STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL);
- STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL);
- STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL);
- STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL);
- STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL);
- STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage);
- STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL);
- STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText);
+ STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
+
+ STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName);
+ STDMETHODIMP get_Title(BSTR* pbstrTitle);
+ STDMETHODIMP get_Rating(BSTR* pbstrRating);
+ STDMETHODIMP get_Description(BSTR* pbstrDescription);
+ STDMETHODIMP get_Copyright(BSTR* pbstrCopyright);
+ STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL);
+ STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL);
+ STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL);
+ STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL);
+ STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL);
+ STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage);
+ STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL);
+ STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText);
};
diff --git a/src/filters/reader/CDDAReader/stdafx.cpp b/src/filters/reader/CDDAReader/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/reader/CDDAReader/stdafx.cpp
+++ b/src/filters/reader/CDDAReader/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/CDDAReader/stdafx.h b/src/filters/reader/CDDAReader/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/reader/CDDAReader/stdafx.h
+++ b/src/filters/reader/CDDAReader/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/CDXAReader/CDXAReader.cpp b/src/filters/reader/CDXAReader/CDXAReader.cpp
index aa17fe3d6..099c56d45 100644
--- a/src/filters/reader/CDXAReader/CDXAReader.cpp
+++ b/src/filters/reader/CDXAReader/CDXAReader.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,8 +28,7 @@
/////////
-static DWORD EDC_crctable[256] =
-{
+static DWORD EDC_crctable[256] = {
0x00000000l, 0x90910101l, 0x91210201l, 0x01b00300l,
0x92410401l, 0x02d00500l, 0x03600600l, 0x93f10701l,
0x94810801l, 0x04100900l, 0x05a00a00l, 0x95310b01l,
@@ -101,9 +100,10 @@ static DWORD build_edc(const void* in, unsigned from, unsigned upto)
const BYTE* p = (BYTE*)in + from;
DWORD result = 0;
- for(; from < upto; from++)
+ for(; from < upto; from++) {
result = EDC_crctable[(result ^ *p++) & 0xffL] ^ (result >> 8);
-
+ }
+
return result;
}
@@ -111,23 +111,19 @@ static DWORD build_edc(const void* in, unsigned from, unsigned upto)
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL}
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CCDXAReader), L"MPC - CDXA Reader", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CCDXAReader>, NULL, &sudFilter[0]}
};
@@ -136,11 +132,11 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{D367878E-F3B8-4235-A968-F378EF1B9A44}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{D367878E-F3B8-4235-A968-F378EF1B9A44}"),
_T("0"), _T("0,4,,52494646,8,4,,43445841")); // "RIFFxxxxCDXA"
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{D367878E-F3B8-4235-A968-F378EF1B9A44}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{D367878E-F3B8-4235-A968-F378EF1B9A44}"),
_T("Source Filter"), _T("{D367878E-F3B8-4235-A968-F378EF1B9A44}"));
return AMovieDllRegisterServer2(TRUE);
@@ -166,7 +162,9 @@ CFilterApp theApp;
CCDXAReader::CCDXAReader(IUnknown* pUnk, HRESULT* phr)
: CAsyncReader(NAME("CCDXAReader"), pUnk, &m_stream, phr, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CCDXAReader::~CCDXAReader()
@@ -175,18 +173,19 @@ CCDXAReader::~CCDXAReader()
STDMETHODIMP CCDXAReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- return
+ return
QI(IFileSourceFilter)
__super::NonDelegatingQueryInterface(riid, ppv);
}
-STDMETHODIMP CCDXAReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE *pmt)
+STDMETHODIMP CCDXAReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE *pmt)
{
CMediaType mt;
m_mt = mt;
- if(!m_stream.Load(pszFileName))
+ if(!m_stream.Load(pszFileName)) {
return E_FAIL;
+ }
m_fn = pszFileName;
@@ -199,11 +198,14 @@ STDMETHODIMP CCDXAReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE *pmt)
STDMETHODIMP CCDXAReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -215,7 +217,7 @@ STDMETHODIMP CCDXAReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
CCDXAStream::CCDXAStream()
{
m_subtype = MEDIASUBTYPE_NULL;
-
+
m_hFile = INVALID_HANDLE_VALUE;
m_llPosition = m_llLength = 0;
@@ -225,8 +227,7 @@ CCDXAStream::CCDXAStream()
CCDXAStream::~CCDXAStream()
{
- if(m_hFile != INVALID_HANDLE_VALUE)
- {
+ if(m_hFile != INVALID_HANDLE_VALUE) {
CloseHandle(m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
}
@@ -234,25 +235,22 @@ CCDXAStream::~CCDXAStream()
bool CCDXAStream::Load(const WCHAR* fnw)
{
- if(m_hFile != INVALID_HANDLE_VALUE)
- {
+ if(m_hFile != INVALID_HANDLE_VALUE) {
CloseHandle(m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
}
- m_hFile = CreateFile(CString(fnw), GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_READONLY|FILE_FLAG_SEQUENTIAL_SCAN, (HANDLE)NULL);
- if(m_hFile == INVALID_HANDLE_VALUE)
- {
+ m_hFile = CreateFile(CString(fnw), GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_READONLY|FILE_FLAG_SEQUENTIAL_SCAN, (HANDLE)NULL);
+ if(m_hFile == INVALID_HANDLE_VALUE) {
return(false);
}
BYTE hdr[RIFFCDXA_HEADER_SIZE];
DWORD NumberOfBytesRead;
if(!ReadFile(m_hFile, (LPVOID)hdr, RIFFCDXA_HEADER_SIZE, &NumberOfBytesRead, NULL)
- || *((DWORD*)&hdr[0]) != 'FFIR' || *((DWORD*)&hdr[8]) != 'AXDC'
- || *((DWORD*)&hdr[4]) != (*((DWORD*)&hdr[0x28])+0x24))
- {
+ || *((DWORD*)&hdr[0]) != 'FFIR' || *((DWORD*)&hdr[8]) != 'AXDC'
+ || *((DWORD*)&hdr[4]) != (*((DWORD*)&hdr[0x28])+0x24)) {
CloseHandle(m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
return(false);
@@ -263,8 +261,7 @@ bool CCDXAStream::Load(const WCHAR* fnw)
m_llLength = int((size.QuadPart - RIFFCDXA_HEADER_SIZE) / RAW_SECTOR_SIZE) * RAW_DATA_SIZE;
- if(!LookForMediaSubType())
- {
+ if(!LookForMediaSubType()) {
m_llPosition = m_llLength = 0;
CloseHandle(m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
@@ -290,13 +287,11 @@ HRESULT CCDXAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
PBYTE pbBufferOrg = pbBuffer;
LONGLONG pos = m_llPosition;
- while(pos >= 0 && pos < m_llLength && dwBytesToRead > 0)
- {
+ while(pos >= 0 && pos < m_llLength && dwBytesToRead > 0) {
UINT sector = m_nFirstSector + int(pos/RAW_DATA_SIZE);
__int64 offset = pos%RAW_DATA_SIZE;
- if(m_nBufferedSector != (int)sector)
- {
+ if(m_nBufferedSector != (int)sector) {
LARGE_INTEGER FilePointer;
FilePointer.QuadPart = RIFFCDXA_HEADER_SIZE + sector*RAW_SECTOR_SIZE;
SetFilePointer(m_hFile, (LONG)FilePointer.LowPart, (PLONG)&FilePointer.HighPart, FILE_BEGIN);
@@ -306,18 +301,20 @@ HRESULT CCDXAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
DWORD NumberOfBytesRead = 0;
int nRetries = 3;
- while(nRetries--)
- {
+ while(nRetries--) {
NumberOfBytesRead = 0;
if(!ReadFile(m_hFile, m_sector, RAW_SECTOR_SIZE, &NumberOfBytesRead, NULL)
- || NumberOfBytesRead != RAW_SECTOR_SIZE)
+ || NumberOfBytesRead != RAW_SECTOR_SIZE) {
break;
+ }
- if(*(DWORD*)&m_sector[RAW_SECTOR_SIZE-4] == 0) // no CRC? it happens...
+ if(*(DWORD*)&m_sector[RAW_SECTOR_SIZE-4] == 0) { // no CRC? it happens...
break;
+ }
- if(build_edc(m_sector, RAW_SYNC_SIZE + RAW_HEADER_SIZE, RAW_SECTOR_SIZE) == 0)
+ if(build_edc(m_sector, RAW_SYNC_SIZE + RAW_HEADER_SIZE, RAW_SECTOR_SIZE) == 0) {
break;
+ }
TRACE(_T("CCDXAStream: CRC error at sector %d (fp=0x%I64x, retriesleft=%d)\n"), sector, FilePointer.QuadPart, nRetries);
}
@@ -333,33 +330,39 @@ HRESULT CCDXAStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDW
dwBytesToRead -= l;
}
- if(pdwBytesRead) *pdwBytesRead = pbBuffer - pbBufferOrg;
+ if(pdwBytesRead) {
+ *pdwBytesRead = pbBuffer - pbBufferOrg;
+ }
m_llPosition += pbBuffer - pbBufferOrg;
- if(dwBytesToRead != 0) return S_FALSE;
+ if(dwBytesToRead != 0) {
+ return S_FALSE;
+ }
return S_OK;
}
LONGLONG CCDXAStream::Size(LONGLONG* pSizeAvailable)
{
- if(pSizeAvailable) *pSizeAvailable = m_llLength;
- return m_llLength;
+ if(pSizeAvailable) {
+ *pSizeAvailable = m_llLength;
+ }
+ return m_llLength;
}
DWORD CCDXAStream::Alignment()
{
- return 1;
+ return 1;
}
void CCDXAStream::Lock()
{
- m_csLock.Lock();
+ m_csLock.Lock();
}
void CCDXAStream::Unlock()
{
- m_csLock.Unlock();
+ m_csLock.Unlock();
}
//
@@ -373,22 +376,21 @@ bool CCDXAStream::LookForMediaSubType()
m_llPosition = 0;
for(int iSectorsRead = 0;
- Read(buff, RAW_DATA_SIZE, 1, NULL) == S_OK && iSectorsRead < 1000;
- iSectorsRead++)
- {
- if(*((DWORD*)&buff[0]) == 0xba010000)
- {
+ Read(buff, RAW_DATA_SIZE, 1, NULL) == S_OK && iSectorsRead < 1000;
+ iSectorsRead++) {
+ if(*((DWORD*)&buff[0]) == 0xba010000) {
m_llPosition = 0;
m_llLength -= iSectorsRead*RAW_DATA_SIZE;
m_nFirstSector = iSectorsRead;
- if((buff[4]&0xc4) == 0x44) m_subtype = MEDIASUBTYPE_MPEG2_PROGRAM;
- else if((buff[4]&0xf1) == 0x21) m_subtype = MEDIASUBTYPE_MPEG1System;
+ if((buff[4]&0xc4) == 0x44) {
+ m_subtype = MEDIASUBTYPE_MPEG2_PROGRAM;
+ } else if((buff[4]&0xf1) == 0x21) {
+ m_subtype = MEDIASUBTYPE_MPEG1System;
+ }
return m_subtype != MEDIASUBTYPE_NULL;
- }
- else if(*((DWORD*)&buff[0]) == 'SggO')
- {
+ } else if(*((DWORD*)&buff[0]) == 'SggO') {
m_llPosition = 0;
m_llLength -= iSectorsRead*RAW_DATA_SIZE;
m_nFirstSector = iSectorsRead;
@@ -396,9 +398,7 @@ bool CCDXAStream::LookForMediaSubType()
m_subtype = MEDIASUBTYPE_Ogg;
return(true);
- }
- else if(*((DWORD*)&buff[0]) == 0xA3DF451A)
- {
+ } else if(*((DWORD*)&buff[0]) == 0xA3DF451A) {
m_llPosition = 0;
m_llLength -= iSectorsRead*RAW_DATA_SIZE;
m_nFirstSector = iSectorsRead;
@@ -406,9 +406,7 @@ bool CCDXAStream::LookForMediaSubType()
m_subtype = MEDIASUBTYPE_Matroska;
return(true);
- }
- else if(*((DWORD*)&buff[0]) == 'FMR.')
- {
+ } else if(*((DWORD*)&buff[0]) == 'FMR.') {
m_llPosition = 0;
m_llLength -= iSectorsRead*RAW_DATA_SIZE;
m_nFirstSector = iSectorsRead;
@@ -416,26 +414,22 @@ bool CCDXAStream::LookForMediaSubType()
m_subtype = MEDIASUBTYPE_RealMedia;
return(true);
- }
- else if(*((DWORD*)&buff[0]) == 'FFIR' && *((DWORD*)&buff[8]) == ' IVA')
- {
+ } else if(*((DWORD*)&buff[0]) == 'FFIR' && *((DWORD*)&buff[8]) == ' IVA') {
m_llPosition = 0;
m_llLength = min(m_llLength, *((DWORD*)&buff[4])+8);
m_nFirstSector = iSectorsRead;
m_subtype = MEDIASUBTYPE_Avi;
-
+
return(true);
- }
- else if(*((DWORD*)&buff[4]) == 'voom' || *((DWORD*)&buff[4]) == 'tadm'
- || *((DWORD*)&buff[4]) == 'pytf' && *((DWORD*)&buff[8]) == 'mosi' && *((DWORD*)&buff[16]) == '14pm')
- {
+ } else if(*((DWORD*)&buff[4]) == 'voom' || *((DWORD*)&buff[4]) == 'tadm'
+ || *((DWORD*)&buff[4]) == 'pytf' && *((DWORD*)&buff[8]) == 'mosi' && *((DWORD*)&buff[16]) == '14pm') {
m_llPosition = 0;
m_llLength -= iSectorsRead*RAW_DATA_SIZE;
m_nFirstSector = iSectorsRead;
m_subtype = MEDIASUBTYPE_QTMovie;
-
+
return(true);
}
}
@@ -444,25 +438,24 @@ bool CCDXAStream::LookForMediaSubType()
CRegKey majorkey;
CString majortype = _T("\\Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}");
- if(ERROR_SUCCESS == majorkey.Open(HKEY_CLASSES_ROOT, majortype, KEY_READ))
- {
+ if(ERROR_SUCCESS == majorkey.Open(HKEY_CLASSES_ROOT, majortype, KEY_READ)) {
TCHAR subtype[256+1];
DWORD len = 256;
- for(int i = 0; ERROR_SUCCESS == majorkey.EnumKey(i, subtype, &len); i++, len = 256)
- {
+ for(int i = 0; ERROR_SUCCESS == majorkey.EnumKey(i, subtype, &len); i++, len = 256) {
CRegKey subkey;
- if(ERROR_SUCCESS != subkey.Open(HKEY_CLASSES_ROOT, majortype + _T("\\") + subtype, KEY_READ))
+ if(ERROR_SUCCESS != subkey.Open(HKEY_CLASSES_ROOT, majortype + _T("\\") + subtype, KEY_READ)) {
continue;
+ }
- for(int j = 0; true; j++)
- {
+ for(int j = 0; true; j++) {
TCHAR number[10];
_stprintf(number, _T("%d"), j);
TCHAR pattern[256+1];
ULONG len = 256;
- if(ERROR_SUCCESS != subkey.QueryStringValue(number, pattern, &len))
+ if(ERROR_SUCCESS != subkey.QueryStringValue(number, pattern, &len)) {
break;
+ }
CString p = pattern;
p += ',';
@@ -473,59 +466,66 @@ bool CCDXAStream::LookForMediaSubType()
int nMatches = 0, nTries = 0;
- for(int k = 0, l; nTries >= 0 && (l = p.Find(',', k)) >= 0; k = l+1, nTries++)
- {
+ for(int k = 0, l; nTries >= 0 && (l = p.Find(',', k)) >= 0; k = l+1, nTries++) {
CString s = p.Mid(k, l-k);
TRACE(s + '\n');
TCHAR* end = NULL;
- switch(nTries&3)
- {
- case 0: offset = _tcstol(s, &end, 10); break;
- case 1: cb = _tcstol(s, &end, 10); break;
- case 2: CStringToBin(s, mask); break;
- case 3: CStringToBin(s, val); break;
- default: nTries = -1; break;
+ switch(nTries&3) {
+ case 0:
+ offset = _tcstol(s, &end, 10);
+ break;
+ case 1:
+ cb = _tcstol(s, &end, 10);
+ break;
+ case 2:
+ CStringToBin(s, mask);
+ break;
+ case 3:
+ CStringToBin(s, val);
+ break;
+ default:
+ nTries = -1;
+ break;
}
- if(nTries >= 0 && (nTries&3) == 3)
- {
- if(cb > 0 && val.GetCount() > 0 && cb == val.GetCount())
- {
+ if(nTries >= 0 && (nTries&3) == 3) {
+ if(cb > 0 && val.GetCount() > 0 && cb == val.GetCount()) {
if(offset >= 0 && S_OK == SetPointer(offset)
- || S_OK == SetPointer(m_llLength + offset))
- {
+ || S_OK == SetPointer(m_llLength + offset)) {
CAutoVectorPtr<BYTE> pData;
- if(pData.Allocate(cb))
- {
+ if(pData.Allocate(cb)) {
DWORD BytesRead = 0;
- if(S_OK == Read(pData, cb, 1, &BytesRead) && cb == BytesRead)
- {
- if(mask.GetCount() < cb)
- {
+ if(S_OK == Read(pData, cb, 1, &BytesRead) && cb == BytesRead) {
+ if(mask.GetCount() < cb) {
int i = mask.GetCount();
mask.SetCount(cb);
- for(; i < cb; i++) mask[i] = 0xff;
+ for(; i < cb; i++) {
+ mask[i] = 0xff;
+ }
}
- for(int i = 0; i < cb; i++)
+ for(int i = 0; i < cb; i++) {
pData[i] &= (BYTE)mask[i];
+ }
- if(memcmp(pData, val.GetData(), cb) == 0)
+ if(memcmp(pData, val.GetData(), cb) == 0) {
nMatches++;
+ }
}
}
}
- offset = 0; cb = 0;
- mask.RemoveAll(); val.RemoveAll();
+ offset = 0;
+ cb = 0;
+ mask.RemoveAll();
+ val.RemoveAll();
}
}
}
- if(nMatches > 0 && nMatches*4 == nTries)
- {
+ if(nMatches > 0 && nMatches*4 == nTries) {
m_subtype = GUIDFromCString(subtype);
return S_OK;
}
diff --git a/src/filters/reader/CDXAReader/CDXAReader.h b/src/filters/reader/CDXAReader/CDXAReader.h
index f923b9429..74dd1a2c2 100644
--- a/src/filters/reader/CDXAReader/CDXAReader.h
+++ b/src/filters/reader/CDXAReader/CDXAReader.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,8 +28,7 @@
class CCDXAStream : public CAsyncStream
{
private:
- enum
- {
+ enum {
RIFFCDXA_HEADER_SIZE = 44, // usually...
RAW_SYNC_SIZE = 12, // 00 FF .. FF 00
RAW_HEADER_SIZE = 4,
@@ -39,7 +38,7 @@ private:
RAW_SECTOR_SIZE = 2352
};
- CCritSec m_csLock;
+ CCritSec m_csLock;
HANDLE m_hFile;
LONGLONG m_llPosition, m_llLength;
@@ -56,18 +55,18 @@ public:
bool Load(const WCHAR* fnw);
- HRESULT SetPointer(LONGLONG llPos);
- HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
- LONGLONG Size(LONGLONG* pSizeAvailable);
- DWORD Alignment();
- void Lock();
+ HRESULT SetPointer(LONGLONG llPos);
+ HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
+ LONGLONG Size(LONGLONG* pSizeAvailable);
+ DWORD Alignment();
+ void Lock();
void Unlock();
GUID m_subtype;
};
class __declspec(uuid("D367878E-F3B8-4235-A968-F378EF1B9A44"))
-CCDXAReader
+ CCDXAReader
: public CAsyncReader
, public IFileSourceFilter
{
@@ -75,11 +74,11 @@ CCDXAReader
CStringW m_fn;
public:
- CCDXAReader(IUnknown* pUnk, HRESULT* phr);
+ CCDXAReader(IUnknown* pUnk, HRESULT* phr);
~CCDXAReader();
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
diff --git a/src/filters/reader/CDXAReader/stdafx.cpp b/src/filters/reader/CDXAReader/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/reader/CDXAReader/stdafx.cpp
+++ b/src/filters/reader/CDXAReader/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/CDXAReader/stdafx.h b/src/filters/reader/CDXAReader/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/reader/CDXAReader/stdafx.h
+++ b/src/filters/reader/CDXAReader/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/UDPReader/UDPReader.cpp b/src/filters/reader/UDPReader/UDPReader.cpp
index d1fc5e25d..1fe035f6a 100644
--- a/src/filters/reader/UDPReader/UDPReader.cpp
+++ b/src/filters/reader/UDPReader/UDPReader.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,23 +25,19 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CUDPReader), L"MPC - UDP Reader", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CUDPReader>, NULL, &sudFilter[0]}
};
@@ -78,7 +74,9 @@ CFilterApp theApp;
CUDPReader::CUDPReader(IUnknown* pUnk, HRESULT* phr)
: CAsyncReader(NAME("CUDPReader"), pUnk, &m_stream, phr, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CUDPReader::~CUDPReader()
@@ -87,19 +85,20 @@ CUDPReader::~CUDPReader()
STDMETHODIMP CUDPReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
__super::NonDelegatingQueryInterface(riid, ppv);
}
// IFileSourceFilter
-STDMETHODIMP CUDPReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CUDPReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(!m_stream.Load(pszFileName))
+ if(!m_stream.Load(pszFileName)) {
return E_FAIL;
+ }
m_fn = pszFileName;
@@ -113,11 +112,14 @@ STDMETHODIMP CUDPReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
STDMETHODIMP CUDPReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
+
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -140,13 +142,17 @@ CUDPStream::~CUDPStream()
void CUDPStream::Clear()
{
- if(m_socket !=INVALID_SOCKET) {closesocket(m_socket); m_socket = INVALID_SOCKET;}
- if(CAMThread::ThreadExists())
- {
+ if(m_socket !=INVALID_SOCKET) {
+ closesocket(m_socket);
+ m_socket = INVALID_SOCKET;
+ }
+ if(CAMThread::ThreadExists()) {
CAMThread::CallWorker(CMD_EXIT);
CAMThread::Close();
}
- while(!m_packets.IsEmpty()) delete m_packets.RemoveHead();
+ while(!m_packets.IsEmpty()) {
+ delete m_packets.RemoveHead();
+ }
m_pos = m_len = 0;
m_drop = false;
}
@@ -155,22 +161,20 @@ void CUDPStream::Append(BYTE* buff, int len)
{
CAutoLock cAutoLock(&m_csLock);
- if(m_packets.GetCount() > 1)
- {
+ if(m_packets.GetCount() > 1) {
__int64 size = m_packets.GetTail()->m_end - m_packets.GetHead()->m_start;
- if(!m_drop && (m_pos >= BUFF_SIZE_FIRST && size >= BUFF_SIZE_FIRST || size >= 2*BUFF_SIZE_FIRST))
- {
+ if(!m_drop && (m_pos >= BUFF_SIZE_FIRST && size >= BUFF_SIZE_FIRST || size >= 2*BUFF_SIZE_FIRST)) {
m_drop = true;
TRACE(_T("DROP ON\n"));
- }
- else if(m_drop && size <= BUFF_SIZE_FIRST)
- {
+ } else if(m_drop && size <= BUFF_SIZE_FIRST) {
m_drop = false;
TRACE(_T("DROP OFF\n"));
}
-
- if(m_drop) return;
+
+ if(m_drop) {
+ return;
+ }
}
m_packets.AddTail(DNew packet_t(buff, m_len, m_len + len));
@@ -184,14 +188,16 @@ bool CUDPStream::Load(const WCHAR* fnw)
CStringW url = CStringW(fnw);
#ifdef DEBUG
-// url = L"udp://:1234/";
-// url = L"udp://239.255.255.250:1234/{e436eb8e-524f-11ce-9f53-0020af0ba770}";
-// url = L"udp://239.255.255.19:2345/";
+ // url = L"udp://:1234/";
+ // url = L"udp://239.255.255.250:1234/{e436eb8e-524f-11ce-9f53-0020af0ba770}";
+ // url = L"udp://239.255.255.19:2345/";
#endif
CAtlList<CStringW> sl;
Explode(url, sl, ':');
- if(sl.GetCount() != 3) return false;
+ if(sl.GetCount() != 3) {
+ return false;
+ }
CStringW protocol = sl.RemoveHead();
// if(protocol != L"udp") return false;
@@ -199,22 +205,25 @@ bool CUDPStream::Load(const WCHAR* fnw)
m_ip = CString(sl.RemoveHead()).TrimLeft('/');
int port = _wtoi(Explode(sl.RemoveHead(), sl, '/', 2));
- if(port < 0 || port > 0xffff) return false;
+ if(port < 0 || port > 0xffff) {
+ return false;
+ }
m_port = port;
- if(sl.GetCount() != 2 || FAILED(GUIDFromCString(CString(sl.GetTail()), m_subtype)))
- m_subtype = MEDIASUBTYPE_NULL; // TODO: detect subtype
+ if(sl.GetCount() != 2 || FAILED(GUIDFromCString(CString(sl.GetTail()), m_subtype))) {
+ m_subtype = MEDIASUBTYPE_NULL; // TODO: detect subtype
+ }
CAMThread::Create();
- if(FAILED(CAMThread::CallWorker(CMD_RUN)))
- {
+ if(FAILED(CAMThread::CallWorker(CMD_RUN))) {
Clear();
return false;
}
clock_t start = clock();
- while(clock() - start < 3000 && m_len < 1000000)
+ while(clock() - start < 3000 && m_len < 1000000) {
Sleep(100);
+ }
return true;
}
@@ -224,9 +233,8 @@ HRESULT CUDPStream::SetPointer(LONGLONG llPos)
CAutoLock cAutoLock(&m_csLock);
if(m_packets.IsEmpty() && llPos != 0
- || !m_packets.IsEmpty() && llPos < m_packets.GetHead()->m_start
- || !m_packets.IsEmpty() && llPos > m_packets.GetTail()->m_end)
- {
+ || !m_packets.IsEmpty() && llPos < m_packets.GetHead()->m_start
+ || !m_packets.IsEmpty() && llPos > m_packets.GetTail()->m_end) {
TRACE(_T("CUDPStream: SetPointer error\n"));
return E_FAIL;
}
@@ -243,25 +251,19 @@ HRESULT CUDPStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWO
DWORD len = dwBytesToRead;
BYTE* ptr = pbBuffer;
- while(len > 0 && !m_packets.IsEmpty())
- {
+ while(len > 0 && !m_packets.IsEmpty()) {
POSITION pos = m_packets.GetHeadPosition();
- while(pos && len > 0)
- {
+ while(pos && len > 0) {
packet_t* p = m_packets.GetNext(pos);
- if(p->m_start <= m_pos && m_pos < p->m_end)
- {
+ if(p->m_start <= m_pos && m_pos < p->m_end) {
int size;
- if(m_pos < p->m_start)
- {
+ if(m_pos < p->m_start) {
ASSERT(0);
size = min(len, p->m_start - m_pos);
memset(ptr, 0, size);
- }
- else
- {
+ } else {
size = min(len, p->m_end - m_pos);
memcpy(ptr, &p->m_buff[m_pos - p->m_start], size);
}
@@ -272,17 +274,18 @@ HRESULT CUDPStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWO
len -= size;
}
- if(p->m_end <= m_pos - 2048 && BUFF_SIZE_FIRST <= m_pos)
- {
- while(m_packets.GetHeadPosition() != pos)
+ if(p->m_end <= m_pos - 2048 && BUFF_SIZE_FIRST <= m_pos) {
+ while(m_packets.GetHeadPosition() != pos) {
delete m_packets.RemoveHead();
+ }
}
}
}
- if(pdwBytesRead)
+ if(pdwBytesRead) {
*pdwBytesRead = ptr - pbBuffer;
+ }
return S_OK;
}
@@ -290,23 +293,25 @@ HRESULT CUDPStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWO
LONGLONG CUDPStream::Size(LONGLONG* pSizeAvailable)
{
CAutoLock cAutoLock(&m_csLock);
- if(pSizeAvailable) *pSizeAvailable = m_len;
+ if(pSizeAvailable) {
+ *pSizeAvailable = m_len;
+ }
return 0;
}
DWORD CUDPStream::Alignment()
{
- return 1;
+ return 1;
}
void CUDPStream::Lock()
{
- m_csLock.Lock();
+ m_csLock.Lock();
}
void CUDPStream::Unlock()
{
- m_csLock.Unlock();
+ m_csLock.Unlock();
}
DWORD CUDPStream::ThreadProc()
@@ -320,32 +325,30 @@ DWORD CUDPStream::ThreadProc()
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons((u_short)m_port);
- ip_mreq imr;
+ ip_mreq imr;
imr.imr_multiaddr.s_addr = inet_addr(CStringA(m_ip));
imr.imr_interface.s_addr = INADDR_ANY;
- if((m_socket = socket(AF_INET, SOCK_DGRAM, 0))!=INVALID_SOCKET)
- {
-/* u_long argp = 1;
- ioctlsocket(m_socket, FIONBIO, &argp);
-*/
+ if((m_socket = socket(AF_INET, SOCK_DGRAM, 0))!=INVALID_SOCKET) {
+ /* u_long argp = 1;
+ ioctlsocket(m_socket, FIONBIO, &argp);
+ */
DWORD dw = TRUE;
- if(setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&dw, sizeof(dw))==SOCKET_ERROR)
- {
+ if(setsockopt(m_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&dw, sizeof(dw))==SOCKET_ERROR) {
closesocket(m_socket);
m_socket = INVALID_SOCKET;
}
- if(bind(m_socket, (struct sockaddr*)&addr, sizeof(addr))==SOCKET_ERROR)
- {
+ if(bind(m_socket, (struct sockaddr*)&addr, sizeof(addr))==SOCKET_ERROR) {
closesocket(m_socket);
m_socket = INVALID_SOCKET;
}
- if(IN_MULTICAST(htonl(imr.imr_multiaddr.s_addr)))
- {
+ if(IN_MULTICAST(htonl(imr.imr_multiaddr.s_addr))) {
int ret = setsockopt(m_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*)&imr, sizeof(imr));
- if(ret < 0) ret = ::WSAGetLastError();
+ if(ret < 0) {
+ ret = ::WSAGetLastError();
+ }
ret = ret;
}
}
@@ -354,91 +357,96 @@ DWORD CUDPStream::ThreadProc()
#ifdef _DEBUG
FILE* dump = NULL;
-// dump = _tfopen(_T("c:\\udp.ts"), _T("wb"));
+ // dump = _tfopen(_T("c:\\udp.ts"), _T("wb"));
FILE* log = NULL;
-// log = _tfopen(_T("c:\\udp.txt"), _T("wt"));
+ // log = _tfopen(_T("c:\\udp.txt"), _T("wt"));
#endif
- while(1)
- {
+ while(1) {
DWORD cmd = GetRequest();
- switch(cmd)
- {
- default:
- case CMD_EXIT:
- if(m_socket!=INVALID_SOCKET) {closesocket(m_socket); m_socket = INVALID_SOCKET;}
- WSACleanup();
+ switch(cmd) {
+ default:
+ case CMD_EXIT:
+ if(m_socket!=INVALID_SOCKET) {
+ closesocket(m_socket);
+ m_socket = INVALID_SOCKET;
+ }
+ WSACleanup();
#ifdef _DEBUG
- if(dump) fclose(dump);
- if(log) fclose(log);
+ if(dump) {
+ fclose(dump);
+ }
+ if(log) {
+ fclose(log);
+ }
#endif
- Reply(S_OK);
- return 0;
- case CMD_RUN:
- Reply(m_socket!=INVALID_SOCKET ? S_OK : E_FAIL);
+ Reply(S_OK);
+ return 0;
+ case CMD_RUN:
+ Reply(m_socket!=INVALID_SOCKET ? S_OK : E_FAIL);
- {
- char buff[65536*2];
- int buffsize = 0;
-
- for(unsigned int i = 0; ; i++)
{
- if(!(i&0xff))
- {
- if(CheckRequest(NULL))
- break;
- }
+ char buff[65536*2];
+ int buffsize = 0;
- int fromlen = sizeof(addr);
- int len = recvfrom(m_socket, &buff[buffsize], 65536, 0, (SOCKADDR*)&addr, &fromlen);
- if(len <= 0) {Sleep(1); continue;}
+ for(unsigned int i = 0; ; i++) {
+ if(!(i&0xff)) {
+ if(CheckRequest(NULL)) {
+ break;
+ }
+ }
+
+ int fromlen = sizeof(addr);
+ int len = recvfrom(m_socket, &buff[buffsize], 65536, 0, (SOCKADDR*)&addr, &fromlen);
+ if(len <= 0) {
+ Sleep(1);
+ continue;
+ }
#ifdef _DEBUG
- if(log)
- {
- if(buffsize >= len && !memcmp(&buff[buffsize-len], &buff[buffsize], len))
- {
- DWORD pid = ((buff[buffsize+1]<<8)|buff[buffsize+2])&0x1fff;
- DWORD counter = buff[buffsize+3]&0xf;
- _ftprintf(log, _T("%04d %2d DUP\n"), pid, counter);
+ if(log) {
+ if(buffsize >= len && !memcmp(&buff[buffsize-len], &buff[buffsize], len)) {
+ DWORD pid = ((buff[buffsize+1]<<8)|buff[buffsize+2])&0x1fff;
+ DWORD counter = buff[buffsize+3]&0xf;
+ _ftprintf(log, _T("%04d %2d DUP\n"), pid, counter);
+ }
}
- }
#endif
- buffsize += len;
-
- if(buffsize >= 65536 || m_len == 0)
- {
+ buffsize += len;
+
+ if(buffsize >= 65536 || m_len == 0) {
#ifdef _DEBUG
- if(dump)
- {
- fwrite(buff, buffsize, 1, dump);
- }
+ if(dump) {
+ fwrite(buff, buffsize, 1, dump);
+ }
- if(log)
- {
- static BYTE pid2counter[0x2000];
- static bool init = false;
- if(!init) {memset(pid2counter, 0, sizeof(pid2counter)); init = true;}
-
- for(int i = 0; i < buffsize; i += 188)
- {
- DWORD pid = ((buff[i+1]<<8)|buff[i+2])&0x1fff;
- DWORD counter = buff[i+3]&0xf;
- if(pid2counter[pid] != ((counter-1+16)&15))
- _ftprintf(log, _T("%04x %2d -> %2d\n"), pid, pid2counter[pid], counter);
- pid2counter[pid] = counter;
+ if(log) {
+ static BYTE pid2counter[0x2000];
+ static bool init = false;
+ if(!init) {
+ memset(pid2counter, 0, sizeof(pid2counter));
+ init = true;
+ }
+
+ for(int i = 0; i < buffsize; i += 188) {
+ DWORD pid = ((buff[i+1]<<8)|buff[i+2])&0x1fff;
+ DWORD counter = buff[i+3]&0xf;
+ if(pid2counter[pid] != ((counter-1+16)&15)) {
+ _ftprintf(log, _T("%04x %2d -> %2d\n"), pid, pid2counter[pid], counter);
+ }
+ pid2counter[pid] = counter;
+ }
}
- }
#endif
- Append((BYTE*)buff, buffsize);
- buffsize = 0;
+ Append((BYTE*)buff, buffsize);
+ buffsize = 0;
+ }
}
}
- }
- break;
+ break;
}
}
@@ -446,7 +454,7 @@ DWORD CUDPStream::ThreadProc()
return (DWORD)-1;
}
-CUDPStream::packet_t::packet_t(BYTE* p, __int64 start, __int64 end)
+CUDPStream::packet_t::packet_t(BYTE* p, __int64 start, __int64 end)
: m_start(start)
, m_end(end)
{
diff --git a/src/filters/reader/UDPReader/UDPReader.h b/src/filters/reader/UDPReader/UDPReader.h
index 42f778e34..41cd86f03 100644
--- a/src/filters/reader/UDPReader/UDPReader.h
+++ b/src/filters/reader/UDPReader/UDPReader.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,15 +28,17 @@
class CUDPStream : public CAsyncStream, public CAMThread
{
private:
- CCritSec m_csLock;
+ CCritSec m_csLock;
class packet_t
{
public:
- BYTE* m_buff;
+ BYTE* m_buff;
__int64 m_start, m_end;
packet_t(BYTE* p, __int64 start, __int64 end);
- virtual ~packet_t() {delete [] m_buff;}
+ virtual ~packet_t() {
+ delete [] m_buff;
+ }
};
int m_port;
@@ -58,18 +60,20 @@ public:
virtual ~CUDPStream();
bool Load(const WCHAR* fnw);
- const GUID& GetSubType() {return m_subtype;}
+ const GUID& GetSubType() {
+ return m_subtype;
+ }
- HRESULT SetPointer(LONGLONG llPos);
- HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
- LONGLONG Size(LONGLONG* pSizeAvailable);
- DWORD Alignment();
- void Lock();
+ HRESULT SetPointer(LONGLONG llPos);
+ HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
+ LONGLONG Size(LONGLONG* pSizeAvailable);
+ DWORD Alignment();
+ void Lock();
void Unlock();
};
class __declspec(uuid("0E4221A9-9718-48D5-A5CF-4493DAD4A015"))
-CUDPReader
+ CUDPReader
: public CAsyncReader
, public IFileSourceFilter
{
@@ -77,11 +81,11 @@ CUDPReader
CStringW m_fn;
public:
- CUDPReader(IUnknown* pUnk, HRESULT* phr);
+ CUDPReader(IUnknown* pUnk, HRESULT* phr);
~CUDPReader();
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
diff --git a/src/filters/reader/UDPReader/stdafx.cpp b/src/filters/reader/UDPReader/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/reader/UDPReader/stdafx.cpp
+++ b/src/filters/reader/UDPReader/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/UDPReader/stdafx.h b/src/filters/reader/UDPReader/stdafx.h
index e39f2d6f1..934cd148d 100644
--- a/src/filters/reader/UDPReader/stdafx.h
+++ b/src/filters/reader/UDPReader/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/VTSReader/VTSReader.cpp b/src/filters/reader/VTSReader/VTSReader.cpp
index 9fb53e679..424cc1b90 100644
--- a/src/filters/reader/VTSReader/VTSReader.cpp
+++ b/src/filters/reader/VTSReader/VTSReader.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -26,23 +26,19 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_MPEG2_PROGRAM},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CVTSReader), L"MPC - VTS Reader", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CVTSReader>, NULL, &sudFilter[0]}
};
@@ -50,15 +46,16 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- if(GetVersion()&0x80000000)
+ if(GetVersion()&0x80000000) {
return E_NOTIMPL;
+ }
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"),
_T("0"), _T("0,12,,445644564944454F2D565453")); // "DVDVIDEO-VTS"
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"),
_T("Source Filter"), _T("{773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73}"));
return AMovieDllRegisterServer2(TRUE);
@@ -84,11 +81,14 @@ CFilterApp theApp;
CVTSReader::CVTSReader(IUnknown* pUnk, HRESULT* phr)
: CAsyncReader(NAME("CVTSReader"), pUnk, &m_stream, phr, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
- if(GetVersion()&0x80000000)
- {
- if(phr) *phr = E_NOTIMPL;
+ if(GetVersion()&0x80000000) {
+ if(phr) {
+ *phr = E_NOTIMPL;
+ }
return;
}
}
@@ -99,19 +99,20 @@ CVTSReader::~CVTSReader()
STDMETHODIMP CVTSReader::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
__super::NonDelegatingQueryInterface(riid, ppv);
}
// IFileSourceFilter
-STDMETHODIMP CVTSReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CVTSReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(!m_stream.Load(pszFileName))
+ if(!m_stream.Load(pszFileName)) {
return E_FAIL;
+ }
m_fn = pszFileName;
@@ -125,11 +126,14 @@ STDMETHODIMP CVTSReader::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
STDMETHODIMP CVTSReader::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
+
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -168,11 +172,11 @@ HRESULT CVTSStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWO
DWORD len = dwBytesToRead;
BYTE* ptr = pbBuffer;
- while(len > 0)
- {
+ while(len > 0) {
BYTE buff[2048];
- if(!m_vob->Read(buff))
+ if(!m_vob->Read(buff)) {
break;
+ }
int size = min(2048 - m_off, min(len, 2048));
@@ -180,15 +184,17 @@ HRESULT CVTSStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWO
m_off = (m_off + size)&2047;
- if(m_off > 0)
+ if(m_off > 0) {
m_vob->Seek(m_vob->GetPosition()-1);
+ }
ptr += size;
len -= size;
}
- if(pdwBytesRead)
+ if(pdwBytesRead) {
*pdwBytesRead = ptr - pbBuffer;
+ }
return S_OK;
}
@@ -196,22 +202,24 @@ HRESULT CVTSStream::Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWO
LONGLONG CVTSStream::Size(LONGLONG* pSizeAvailable)
{
LONGLONG len = 2048i64*m_vob->GetLength();
- if(pSizeAvailable) *pSizeAvailable = len;
+ if(pSizeAvailable) {
+ *pSizeAvailable = len;
+ }
return(len);
}
DWORD CVTSStream::Alignment()
{
- return 1;
+ return 1;
}
void CVTSStream::Lock()
{
- m_csLock.Lock();
+ m_csLock.Lock();
}
void CVTSStream::Unlock()
{
- m_csLock.Unlock();
+ m_csLock.Unlock();
}
diff --git a/src/filters/reader/VTSReader/VTSReader.h b/src/filters/reader/VTSReader/VTSReader.h
index 4326f43aa..bbd963cab 100644
--- a/src/filters/reader/VTSReader/VTSReader.h
+++ b/src/filters/reader/VTSReader/VTSReader.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -30,7 +30,7 @@ class CVobFile;
class CVTSStream : public CAsyncStream
{
private:
- CCritSec m_csLock;
+ CCritSec m_csLock;
CAutoPtr<CVobFile> m_vob;
int m_off;
@@ -41,16 +41,16 @@ public:
bool Load(const WCHAR* fnw);
- HRESULT SetPointer(LONGLONG llPos);
- HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
- LONGLONG Size(LONGLONG* pSizeAvailable);
- DWORD Alignment();
- void Lock();
+ HRESULT SetPointer(LONGLONG llPos);
+ HRESULT Read(PBYTE pbBuffer, DWORD dwBytesToRead, BOOL bAlign, LPDWORD pdwBytesRead);
+ LONGLONG Size(LONGLONG* pSizeAvailable);
+ DWORD Alignment();
+ void Lock();
void Unlock();
};
class __declspec(uuid("773EAEDE-D5EE-4fce-9C8F-C4F53D0A2F73"))
-CVTSReader
+ CVTSReader
: public CAsyncReader
, public IFileSourceFilter
{
@@ -58,11 +58,11 @@ CVTSReader
CStringW m_fn;
public:
- CVTSReader(IUnknown* pUnk, HRESULT* phr);
+ CVTSReader(IUnknown* pUnk, HRESULT* phr);
~CVTSReader();
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
diff --git a/src/filters/reader/VTSReader/stdafx.cpp b/src/filters/reader/VTSReader/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/reader/VTSReader/stdafx.cpp
+++ b/src/filters/reader/VTSReader/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/reader/VTSReader/stdafx.h b/src/filters/reader/VTSReader/stdafx.h
index 6188a0bd8..d8d4e35e7 100644
--- a/src/filters/reader/VTSReader/stdafx.h
+++ b/src/filters/reader/VTSReader/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/renderer/MpcAudioRenderer/IMpcAudioRendererFilter.h b/src/filters/renderer/MpcAudioRenderer/IMpcAudioRendererFilter.h
index e4f46fa9b..a63bb9f8d 100644
--- a/src/filters/renderer/MpcAudioRenderer/IMpcAudioRendererFilter.h
+++ b/src/filters/renderer/MpcAudioRenderer/IMpcAudioRendererFilter.h
@@ -26,8 +26,7 @@
interface __declspec(uuid("495D2C66-D430-439b-9DEE-40F9B7929BBA"))
IMpcAudioRendererFilter :
-public IUnknown
-{
+public IUnknown {
STDMETHOD(Apply()) = 0;
STDMETHOD(SetWasapiMode(BOOL nValue)) = 0;
diff --git a/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp b/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp
index 208c8b9db..1989af1de 100644
--- a/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp
+++ b/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.cpp
@@ -65,23 +65,19 @@ DEFINE_GUIDSTRUCT("0000000b-0cea-0010-8000-00aa00389b71", KSDATAFORMAT_SUBTYPE_I
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&GUID_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMpcAudioRenderer), L"MPC - Audio Renderer", 0x40000001, countof(sudpPins), sudpPins,CLSID_AudioRendererCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, &__uuidof(CMpcAudioRenderer), CreateInstance<CMpcAudioRenderer>, NULL, &sudFilter[0]},
{L"CMpcAudioRendererPropertyPage", &__uuidof(CMpcAudioRendererSettingsWnd), CreateInstance<CInternalPropertyPageTempl<CMpcAudioRendererSettingsWnd> >},
};
@@ -131,28 +127,29 @@ CMpcAudioRenderer::CMpcAudioRenderer(LPUNKNOWN punk, HRESULT *phr)
HMODULE hLib;
CRegKey key;
- if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Audio Renderer"), KEY_READ))
- {
+ if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Audio Renderer"), KEY_READ)) {
DWORD dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("UseWasapi"), dw)) m_useWASAPI = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("MuteFastForward"), dw)) m_bMuteFastForward = dw;
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("UseWasapi"), dw)) {
+ m_useWASAPI = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("MuteFastForward"), dw)) {
+ m_bMuteFastForward = dw;
+ }
}
m_useWASAPIAfterRestart = m_useWASAPI;
// Load Vista specifics DLLs
hLib = LoadLibrary (L"AVRT.dll");
- if (hLib != NULL)
- {
+ if (hLib != NULL) {
pfAvSetMmThreadCharacteristicsW = (PTR_AvSetMmThreadCharacteristicsW) GetProcAddress (hLib, "AvSetMmThreadCharacteristicsW");
pfAvRevertMmThreadCharacteristics = (PTR_AvRevertMmThreadCharacteristics) GetProcAddress (hLib, "AvRevertMmThreadCharacteristics");
+ } else {
+ m_useWASAPI = false; // Wasapi not available below Vista
}
- else
- m_useWASAPI = false; // Wasapi not available below Vista
TRACE(_T("CMpcAudioRenderer constructor"));
- if (!m_useWASAPI)
- {
+ if (!m_useWASAPI) {
m_pSoundTouch = new soundtouch::SoundTouch();
*phr = DirectSoundCreate8 (NULL, &m_pDS, NULL);
}
@@ -171,20 +168,17 @@ CMpcAudioRenderer::~CMpcAudioRenderer()
SAFE_RELEASE (pAudioClient);
SAFE_RELEASE (pMMDevice);
- if (m_pReferenceClock)
- {
+ if (m_pReferenceClock) {
SetSyncSource(NULL);
SAFE_RELEASE (m_pReferenceClock);
}
- if (m_pWaveFileFormat)
- {
+ if (m_pWaveFileFormat) {
BYTE *p = (BYTE *)m_pWaveFileFormat;
SAFE_DELETE_ARRAY(p);
}
- if (hTask != NULL && pfAvRevertMmThreadCharacteristics != NULL)
- {
+ if (hTask != NULL && pfAvRevertMmThreadCharacteristics != NULL) {
pfAvRevertMmThreadCharacteristics(hTask);
}
}
@@ -198,42 +192,39 @@ HRESULT CMpcAudioRenderer::CheckInputType(const CMediaType *pmt)
HRESULT CMpcAudioRenderer::CheckMediaType(const CMediaType *pmt)
{
HRESULT hr = S_OK;
- if (pmt == NULL) return E_INVALIDARG;
+ if (pmt == NULL) {
+ return E_INVALIDARG;
+ }
TRACE(_T("CMpcAudioRenderer::CheckMediaType"));
WAVEFORMATEX *pwfx = (WAVEFORMATEX *) pmt->Format();
- if (pwfx == NULL) return VFW_E_TYPE_NOT_ACCEPTED;
+ if (pwfx == NULL) {
+ return VFW_E_TYPE_NOT_ACCEPTED;
+ }
if ((pmt->majortype != MEDIATYPE_Audio ) ||
- (pmt->formattype != FORMAT_WaveFormatEx ))
- {
+ (pmt->formattype != FORMAT_WaveFormatEx )) {
TRACE(_T("CMpcAudioRenderer::CheckMediaType Not supported"));
return VFW_E_TYPE_NOT_ACCEPTED;
}
- if(m_useWASAPI)
- {
+ if(m_useWASAPI) {
hr=CheckAudioClient((WAVEFORMATEX *)NULL);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
TRACE(_T("CMpcAudioRenderer::CheckMediaType Error on check audio client"));
return hr;
}
- if (!pAudioClient)
- {
+ if (!pAudioClient) {
TRACE(_T("CMpcAudioRenderer::CheckMediaType Error, audio client not loaded"));
return VFW_E_CANNOT_CONNECT;
}
- if (pAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL) != S_OK)
- {
+ if (pAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL) != S_OK) {
TRACE(_T("CMpcAudioRenderer::CheckMediaType WASAPI client refused the format"));
return VFW_E_TYPE_NOT_ACCEPTED;
}
TRACE(_T("CMpcAudioRenderer::CheckMediaType WASAPI client accepted the format"));
- }
- else if (pwfx->wFormatTag != WAVE_FORMAT_PCM)
- {
+ } else if (pwfx->wFormatTag != WAVE_FORMAT_PCM) {
return VFW_E_TYPE_NOT_ACCEPTED;
}
return S_OK;
@@ -241,8 +232,9 @@ HRESULT CMpcAudioRenderer::CheckMediaType(const CMediaType *pmt)
void CMpcAudioRenderer::OnReceiveFirstSample(IMediaSample *pMediaSample)
{
- if (!m_useWASAPI)
+ if (!m_useWASAPI) {
ClearBuffer();
+ }
}
BOOL CMpcAudioRenderer::ScheduleSample(IMediaSample *pMediaSample)
@@ -251,35 +243,39 @@ BOOL CMpcAudioRenderer::ScheduleSample(IMediaSample *pMediaSample)
REFERENCE_TIME EndSample;
// Is someone pulling our leg
- if (pMediaSample == NULL) return FALSE;
+ if (pMediaSample == NULL) {
+ return FALSE;
+ }
// Get the next sample due up for rendering. If there aren't any ready
// then GetNextSampleTimes returns an error. If there is one to be done
// then it succeeds and yields the sample times. If it is due now then
// it returns S_OK other if it's to be done when due it returns S_FALSE
HRESULT hr = GetSampleTimes(pMediaSample, &StartSample, &EndSample);
- if (FAILED(hr)) return FALSE;
+ if (FAILED(hr)) {
+ return FALSE;
+ }
// If we don't have a reference clock then we cannot set up the advise
// time so we simply set the event indicating an image to render. This
// will cause us to run flat out without any timing or synchronisation
- if (hr == S_OK)
- {
+ if (hr == S_OK) {
EXECUTE_ASSERT(SetEvent((HANDLE) m_RenderEvent));
return TRUE;
}
- if (m_dRate <= 1.1)
- {
+ if (m_dRate <= 1.1) {
ASSERT(m_dwAdvise == 0);
ASSERT(m_pClock);
WaitForSingleObject((HANDLE)m_RenderEvent,0);
hr = m_pClock->AdviseTime( (REFERENCE_TIME) m_tStart, StartSample, (HEVENT)(HANDLE) m_RenderEvent, &m_dwAdvise);
- if (SUCCEEDED(hr)) return TRUE;
- }
- else
+ if (SUCCEEDED(hr)) {
+ return TRUE;
+ }
+ } else {
hr = DoRenderSample (pMediaSample);
+ }
// We could not schedule the next sample for rendering despite the fact
// we have a valid sample here. This is a fair indication that either
@@ -291,37 +287,27 @@ BOOL CMpcAudioRenderer::ScheduleSample(IMediaSample *pMediaSample)
HRESULT CMpcAudioRenderer::DoRenderSample(IMediaSample *pMediaSample)
{
- if (m_useWASAPI)
+ if (m_useWASAPI) {
return DoRenderSampleWasapi(pMediaSample);
- else
+ } else {
return DoRenderSampleDirectSound(pMediaSample);
+ }
}
STDMETHODIMP CMpcAudioRenderer::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
- if (riid == IID_IReferenceClock)
- {
+ if (riid == IID_IReferenceClock) {
return GetReferenceClockInterface(riid, ppv);
- }
- else if (riid == IID_IDispatch)
- {
+ } else if (riid == IID_IDispatch) {
return GetInterface(static_cast<IDispatch*>(this), ppv);
- }
- else if (riid == IID_IBasicAudio)
- {
+ } else if (riid == IID_IBasicAudio) {
return GetInterface(static_cast<IBasicAudio*>(this), ppv);
- }
- else if (riid == __uuidof(ISpecifyPropertyPages))
- {
+ } else if (riid == __uuidof(ISpecifyPropertyPages)) {
return GetInterface(static_cast<ISpecifyPropertyPages*>(this), ppv);
- }
- else if (riid == __uuidof(ISpecifyPropertyPages2))
- {
+ } else if (riid == __uuidof(ISpecifyPropertyPages2)) {
return GetInterface(static_cast<ISpecifyPropertyPages2*>(this), ppv);
- }
- else if (riid == __uuidof(IMpcAudioRendererFilter))
- {
+ } else if (riid == __uuidof(IMpcAudioRendererFilter)) {
return GetInterface(static_cast<IMpcAudioRendererFilter*>(this), ppv);
}
@@ -330,42 +316,40 @@ STDMETHODIMP CMpcAudioRenderer::NonDelegatingQueryInterface(REFIID riid, void **
HRESULT CMpcAudioRenderer::SetMediaType(const CMediaType *pmt)
{
- if (! pmt) return E_POINTER;
+ if (! pmt) {
+ return E_POINTER;
+ }
int size = 0;
TRACE(_T("CMpcAudioRenderer::SetMediaType"));
- if (m_useWASAPI)
- {
+ if (m_useWASAPI) {
// New media type set but render client already initialized => reset it
- if (pRenderClient!=NULL)
- {
+ if (pRenderClient!=NULL) {
WAVEFORMATEX *pNewWf = (WAVEFORMATEX *) pmt->Format();
TRACE(_T("CMpcAudioRenderer::SetMediaType Render client already initialized. Reinitialization..."));
CheckAudioClient(pNewWf);
}
}
- if (m_pWaveFileFormat)
- {
+ if (m_pWaveFileFormat) {
BYTE *p = (BYTE *)m_pWaveFileFormat;
SAFE_DELETE_ARRAY(p);
}
m_pWaveFileFormat=NULL;
WAVEFORMATEX *pwf = (WAVEFORMATEX *) pmt->Format();
- if (pwf!=NULL)
- {
+ if (pwf!=NULL) {
size = sizeof(WAVEFORMATEX) + pwf->cbSize;
m_pWaveFileFormat = (WAVEFORMATEX *)new BYTE[size];
- if (! m_pWaveFileFormat)
+ if (! m_pWaveFileFormat) {
return E_OUTOFMEMORY;
+ }
memcpy(m_pWaveFileFormat, pwf, size);
- if (!m_useWASAPI && m_pSoundTouch && (pwf->nChannels <= 2))
- {
+ if (!m_useWASAPI && m_pSoundTouch && (pwf->nChannels <= 2)) {
m_pSoundTouch->setSampleRate (pwf->nSamplesPerSec);
m_pSoundTouch->setChannels (pwf->nChannels);
m_pSoundTouch->setTempoChange (0);
@@ -381,16 +365,25 @@ HRESULT CMpcAudioRenderer::CompleteConnect(IPin *pReceivePin)
HRESULT hr = S_OK;
TRACE(_T("CMpcAudioRenderer::CompleteConnect"));
- if (!m_useWASAPI && ! m_pDS) return E_FAIL;
+ if (!m_useWASAPI && ! m_pDS) {
+ return E_FAIL;
+ }
- if (SUCCEEDED(hr)) hr = CBaseRenderer::CompleteConnect(pReceivePin);
- if (SUCCEEDED(hr)) hr = InitCoopLevel();
+ if (SUCCEEDED(hr)) {
+ hr = CBaseRenderer::CompleteConnect(pReceivePin);
+ }
+ if (SUCCEEDED(hr)) {
+ hr = InitCoopLevel();
+ }
- if (!m_useWASAPI)
- {
- if (SUCCEEDED(hr)) hr = CreateDSBuffer();
+ if (!m_useWASAPI) {
+ if (SUCCEEDED(hr)) {
+ hr = CreateDSBuffer();
+ }
+ }
+ if (SUCCEEDED(hr)) {
+ TRACE(_T("CMpcAudioRenderer::CompleteConnect Success"));
}
- if (SUCCEEDED(hr)) TRACE(_T("CMpcAudioRenderer::CompleteConnect Success"));
return hr;
}
@@ -398,13 +391,13 @@ STDMETHODIMP CMpcAudioRenderer::Run(REFERENCE_TIME tStart)
{
HRESULT hr;
- if (m_State == State_Running) return NOERROR;
+ if (m_State == State_Running) {
+ return NOERROR;
+ }
- if (m_useWASAPI)
- {
+ if (m_useWASAPI) {
hr=CheckAudioClient(m_pWaveFileFormat);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
TRACE(_T("CMpcAudioRenderer::Run Error on check audio client"));
return hr;
}
@@ -415,32 +408,28 @@ STDMETHODIMP CMpcAudioRenderer::Run(REFERENCE_TIME tStart)
TRACE(_T("CMpcAudioRenderer::Run Start error"));
return hr;
}*/
- }
- else
- {
+ } else {
if (m_pDSBuffer &&
- m_pPosition &&
- m_pWaveFileFormat &&
- SUCCEEDED(m_pPosition->GetRate(&m_dRate)))
- {
- if (m_dRate < 1.0)
- {
+ m_pPosition &&
+ m_pWaveFileFormat &&
+ SUCCEEDED(m_pPosition->GetRate(&m_dRate))) {
+ if (m_dRate < 1.0) {
hr = m_pDSBuffer->SetFrequency ((long)(m_pWaveFileFormat->nSamplesPerSec * m_dRate));
- if (FAILED (hr)) return hr;
+ if (FAILED (hr)) {
+ return hr;
+ }
+ } else {
+ hr = m_pDSBuffer->SetFrequency ((long)m_pWaveFileFormat->nSamplesPerSec);
+ m_pSoundTouch->setRateChange((float)(m_dRate-1.0)*100);
+
+ if (m_bMuteFastForward) {
+ if (m_dRate == 1.0) {
+ m_pDSBuffer->SetVolume(m_lVolume);
+ } else {
+ m_pDSBuffer->SetVolume(DSBVOLUME_MIN);
+ }
+ }
}
- else
- {
- hr = m_pDSBuffer->SetFrequency ((long)m_pWaveFileFormat->nSamplesPerSec);
- m_pSoundTouch->setRateChange((float)(m_dRate-1.0)*100);
-
- if (m_bMuteFastForward)
- {
- if (m_dRate == 1.0)
- m_pDSBuffer->SetVolume(m_lVolume);
- else
- m_pDSBuffer->SetVolume(DSBVOLUME_MIN);
- }
- }
}
ClearBuffer();
@@ -452,7 +441,9 @@ STDMETHODIMP CMpcAudioRenderer::Run(REFERENCE_TIME tStart)
STDMETHODIMP CMpcAudioRenderer::Stop()
{
- if (m_pDSBuffer) m_pDSBuffer->Stop();
+ if (m_pDSBuffer) {
+ m_pDSBuffer->Stop();
+ }
isAudioClientStarted=false;
return CBaseRenderer::Stop();
@@ -461,8 +452,12 @@ STDMETHODIMP CMpcAudioRenderer::Stop()
STDMETHODIMP CMpcAudioRenderer::Pause()
{
- if (m_pDSBuffer) m_pDSBuffer->Stop();
- if (pAudioClient && isAudioClientStarted) pAudioClient->Stop();
+ if (m_pDSBuffer) {
+ m_pDSBuffer->Stop();
+ }
+ if (pAudioClient && isAudioClientStarted) {
+ pAudioClient->Stop();
+ }
isAudioClientStarted=false;
return CBaseRenderer::Pause();
@@ -493,32 +488,36 @@ STDMETHODIMP CMpcAudioRenderer::Invoke(DISPID dispidMember, REFIID riid, LCID lc
STDMETHODIMP CMpcAudioRenderer::put_Volume(long lVolume)
{
m_lVolume = lVolume;
- if (!m_useWASAPI && m_pDSBuffer)
+ if (!m_useWASAPI && m_pDSBuffer) {
return m_pDSBuffer->SetVolume(lVolume);
+ }
return S_OK;
}
STDMETHODIMP CMpcAudioRenderer::get_Volume(long *plVolume)
{
- if (!m_useWASAPI && m_pDSBuffer)
+ if (!m_useWASAPI && m_pDSBuffer) {
return m_pDSBuffer->GetVolume(plVolume);
+ }
return S_OK;
}
STDMETHODIMP CMpcAudioRenderer::put_Balance(long lBalance)
{
- if (!m_useWASAPI && m_pDSBuffer)
+ if (!m_useWASAPI && m_pDSBuffer) {
return m_pDSBuffer->SetPan(lBalance);
+ }
return S_OK;
}
STDMETHODIMP CMpcAudioRenderer::get_Balance(long *plBalance)
{
- if (!m_useWASAPI && m_pDSBuffer)
+ if (!m_useWASAPI && m_pDSBuffer) {
return m_pDSBuffer->GetPan(plBalance);
+ }
return S_OK;
}
@@ -540,12 +539,13 @@ STDMETHODIMP CMpcAudioRenderer::CreatePage(const GUID& guid, IPropertyPage** ppP
{
CheckPointer(ppPage, E_POINTER);
- if(*ppPage != NULL) return E_INVALIDARG;
+ if(*ppPage != NULL) {
+ return E_INVALIDARG;
+ }
HRESULT hr;
- if(guid == __uuidof(CMpcAudioRendererSettingsWnd))
- {
+ if(guid == __uuidof(CMpcAudioRendererSettingsWnd)) {
(*ppPage = DNew CInternalPropertyPageTempl<CMpcAudioRendererSettingsWnd>(NULL, &hr))->AddRef();
}
@@ -556,8 +556,7 @@ STDMETHODIMP CMpcAudioRenderer::CreatePage(const GUID& guid, IPropertyPage** ppP
STDMETHODIMP CMpcAudioRenderer::Apply()
{
CRegKey key;
- if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Audio Renderer")))
- {
+ if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Audio Renderer"))) {
key.SetDWORDValue(_T("UseWasapi"), m_useWASAPIAfterRestart);
key.SetDWORDValue(_T("MuteFastForward"), m_bMuteFastForward);
}
@@ -593,18 +592,19 @@ HRESULT CMpcAudioRenderer::GetReferenceClockInterface(REFIID riid, void **ppv)
{
HRESULT hr = S_OK;
- if (m_pReferenceClock)
+ if (m_pReferenceClock) {
return m_pReferenceClock->NonDelegatingQueryInterface(riid, ppv);
+ }
m_pReferenceClock = new CBaseReferenceClock (NAME("Mpc Audio Clock"), NULL, &hr);
- if (! m_pReferenceClock)
+ if (! m_pReferenceClock) {
return E_OUTOFMEMORY;
+ }
m_pReferenceClock->AddRef();
hr = SetSyncSource(m_pReferenceClock);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
SetSyncSource(NULL);
return hr;
}
@@ -616,9 +616,13 @@ HRESULT CMpcAudioRenderer::GetReferenceClockInterface(REFIID riid, void **ppv)
HRESULT CMpcAudioRenderer::EndOfStream(void)
{
- if (m_pDSBuffer) m_pDSBuffer->Stop();
+ if (m_pDSBuffer) {
+ m_pDSBuffer->Stop();
+ }
#if !FILEWRITER
- if (pAudioClient && isAudioClientStarted) pAudioClient->Stop();
+ if (pAudioClient && isAudioClientStarted) {
+ pAudioClient->Stop();
+ }
#endif
isAudioClientStarted=false;
@@ -631,7 +635,9 @@ HRESULT CMpcAudioRenderer::EndOfStream(void)
HRESULT CMpcAudioRenderer::CreateDSBuffer()
{
- if (! m_pWaveFileFormat) return E_POINTER;
+ if (! m_pWaveFileFormat) {
+ return E_POINTER;
+ }
HRESULT hr = S_OK;
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
@@ -647,8 +653,7 @@ HRESULT CMpcAudioRenderer::CreateDSBuffer()
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = NULL;
- if (SUCCEEDED (hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL )))
- {
+ if (SUCCEEDED (hr = m_pDS->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL ))) {
hr = pDSBPrimary->SetFormat(m_pWaveFileFormat);
ATLASSERT(SUCCEEDED(hr));
SAFE_RELEASE (pDSBPrimary);
@@ -670,13 +675,11 @@ HRESULT CMpcAudioRenderer::CreateDSBuffer()
hr = m_pDS->CreateSoundBuffer (&cDSBufferDesc, &m_pDSBuffer, NULL);
m_nDSBufSize = 0;
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
bufferCaps.dwSize = sizeof(bufferCaps);
hr = m_pDSBuffer->GetCaps(&bufferCaps);
}
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
m_nDSBufSize = bufferCaps.dwBufferBytes;
hr = ClearBuffer();
m_pDSBuffer->SetFrequency ((long)(m_pWaveFileFormat->nSamplesPerSec * m_dRate));
@@ -693,14 +696,12 @@ HRESULT CMpcAudioRenderer::ClearBuffer()
VOID* pDSLockedBuffer = NULL;
DWORD dwDSLockedSize = 0;
- if (m_pDSBuffer)
- {
+ if (m_pDSBuffer) {
m_dwDSWriteOff = 0;
m_pDSBuffer->SetCurrentPosition(0);
hr = m_pDSBuffer->Lock (0, 0, &pDSLockedBuffer, &dwDSLockedSize, NULL, NULL, DSBLOCK_ENTIREBUFFER);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
memset (pDSLockedBuffer, 0, dwDSLockedSize);
hr = m_pDSBuffer->Unlock (pDSLockedBuffer, dwDSLockedSize, NULL, NULL);
}
@@ -717,32 +718,29 @@ HRESULT CMpcAudioRenderer::InitCoopLevel()
CComBSTR bstrCaption;
hr = m_pGraph->QueryInterface (__uuidof(IVideoWindow), (void**) &pVideoWindow);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
pVideoWindow->get_Owner((OAHWND*)&hWnd);
SAFE_RELEASE (pVideoWindow);
}
- if (!hWnd)
- {
+ if (!hWnd) {
hWnd = GetTopWindow(NULL);
}
ATLASSERT(hWnd != NULL);
- if (!m_useWASAPI)
+ if (!m_useWASAPI) {
hr = m_pDS->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
- else if (hTask == NULL)
- {
+ } else if (hTask == NULL) {
// Ask MMCSS to temporarily boost the thread priority
// to reduce glitches while the low-latency stream plays.
DWORD taskIndex = 0;
- if (pfAvSetMmThreadCharacteristicsW)
- {
+ if (pfAvSetMmThreadCharacteristicsW) {
hTask = pfAvSetMmThreadCharacteristicsW(TEXT("Pro Audio"), &taskIndex);
TRACE(_T("CMpcAudioRenderer::InitCoopLevel Putting thread in higher priority for Wasapi mode (lowest latency)"));
hr=GetLastError();
- if (hTask == NULL)
+ if (hTask == NULL) {
return hr;
+ }
}
}
@@ -759,19 +757,20 @@ HRESULT CMpcAudioRenderer::DoRenderSampleDirectSound(IMediaSample *pMediaSample)
hr = m_pDSBuffer->GetStatus(&dwStatus);
- if (SUCCEEDED(hr) && (dwStatus & DSBSTATUS_BUFFERLOST))
+ if (SUCCEEDED(hr) && (dwStatus & DSBSTATUS_BUFFERLOST)) {
hr = m_pDSBuffer->Restore();
+ }
- if ((SUCCEEDED(hr)) && ((dwStatus & DSBSTATUS_PLAYING) != DSBSTATUS_PLAYING))
- {
+ if ((SUCCEEDED(hr)) && ((dwStatus & DSBSTATUS_PLAYING) != DSBSTATUS_PLAYING)) {
hr = m_pDSBuffer->Play( 0, 0, DSBPLAY_LOOPING);
ATLASSERT(SUCCEEDED(hr));
}
- if (SUCCEEDED(hr)) hr = m_pDSBuffer->GetCurrentPosition(&dwPlayCursor, &dwWriteCursor);
+ if (SUCCEEDED(hr)) {
+ hr = m_pDSBuffer->GetCurrentPosition(&dwPlayCursor, &dwWriteCursor);
+ }
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
if ( ( (dwPlayCursor < dwWriteCursor) &&
(
((m_dwDSWriteOff >= dwPlayCursor) && (m_dwDSWriteOff <= dwWriteCursor))
@@ -783,25 +782,27 @@ HRESULT CMpcAudioRenderer::DoRenderSampleDirectSound(IMediaSample *pMediaSample)
( (dwWriteCursor < dwPlayCursor) &&
(
(m_dwDSWriteOff >= dwPlayCursor) || (m_dwDSWriteOff < dwWriteCursor)
- ) ) )
- {
+ ) ) ) {
m_dwDSWriteOff = dwWriteCursor;
}
- if (m_dwDSWriteOff >= (DWORD)m_nDSBufSize)
- {
+ if (m_dwDSWriteOff >= (DWORD)m_nDSBufSize) {
m_dwDSWriteOff = 0;
}
}
- if (SUCCEEDED(hr)) hr = WriteSampleToDSBuffer(pMediaSample, NULL);
+ if (SUCCEEDED(hr)) {
+ hr = WriteSampleToDSBuffer(pMediaSample, NULL);
+ }
return hr;
}
HRESULT CMpcAudioRenderer::WriteSampleToDSBuffer(IMediaSample *pMediaSample, bool *looped)
{
- if (! m_pDSBuffer) return E_POINTER;
+ if (! m_pDSBuffer) {
+ return E_POINTER;
+ }
REFERENCE_TIME rtStart = 0;
REFERENCE_TIME rtStop = 0;
@@ -814,8 +815,7 @@ HRESULT CMpcAudioRenderer::WriteSampleToDSBuffer(IMediaSample *pMediaSample, boo
hr = pMediaSample->GetPointer(&pMediaBuffer);
- if (m_dRate > 1.0)
- {
+ if (m_dRate > 1.0) {
int nBytePerSample = m_pWaveFileFormat->nChannels * (m_pWaveFileFormat->wBitsPerSample/8);
m_pSoundTouch->putSamples((const short*)pMediaBuffer, lSize / nBytePerSample);
lSize = m_pSoundTouch->receiveSamples ((short*)pMediaBuffer, lSize / nBytePerSample) * nBytePerSample;
@@ -823,8 +823,7 @@ HRESULT CMpcAudioRenderer::WriteSampleToDSBuffer(IMediaSample *pMediaSample, boo
pMediaSample->GetTime (&rtStart, &rtStop);
- if (rtStart < 0)
- {
+ if (rtStart < 0) {
DWORD dwPercent = (DWORD) ((-rtStart * 100) / (rtStop - rtStart));
DWORD dwRemove = (lSize*dwPercent/100);
@@ -833,18 +832,16 @@ HRESULT CMpcAudioRenderer::WriteSampleToDSBuffer(IMediaSample *pMediaSample, boo
lSize -= dwRemove;
}
- if (SUCCEEDED (hr))
+ if (SUCCEEDED (hr)) {
hr = m_pDSBuffer->Lock (m_dwDSWriteOff, lSize, &pDSLockedBuffers[0], &dwDSLockedSize[0], &pDSLockedBuffers[1], &dwDSLockedSize[1], 0 );
- if (SUCCEEDED (hr))
- {
- if (pDSLockedBuffers [0] != NULL)
- {
+ }
+ if (SUCCEEDED (hr)) {
+ if (pDSLockedBuffers [0] != NULL) {
memcpy(pDSLockedBuffers[0], pMediaBuffer, dwDSLockedSize[0]);
m_dwDSWriteOff += dwDSLockedSize[0];
}
- if (pDSLockedBuffers [1] != NULL)
- {
+ if (pDSLockedBuffers [1] != NULL) {
memcpy(pDSLockedBuffers[1], &pMediaBuffer[dwDSLockedSize[0]], dwDSLockedSize[1]);
m_dwDSWriteOff = dwDSLockedSize[1];
loop = true;
@@ -854,7 +851,9 @@ HRESULT CMpcAudioRenderer::WriteSampleToDSBuffer(IMediaSample *pMediaSample, boo
ATLASSERT (dwDSLockedSize [0] + dwDSLockedSize [1] == (DWORD)lSize);
}
- if (SUCCEEDED(hr) && looped) *looped = loop;
+ if (SUCCEEDED(hr) && looped) {
+ *looped = loop;
+ }
return hr;
}
@@ -877,15 +876,14 @@ HRESULT CMpcAudioRenderer::DoRenderSampleWasapi(IMediaSample *pMediaSample)
pMediaSample->GetTime (&rtStart, &rtStop);
AM_MEDIA_TYPE *pmt;
- if (SUCCEEDED(pMediaSample->GetMediaType(&pmt)) && pmt!=NULL)
- {
+ if (SUCCEEDED(pMediaSample->GetMediaType(&pmt)) && pmt!=NULL) {
CMediaType mt(*pmt);
- if ((WAVEFORMATEXTENSIBLE*)mt.Format() != NULL)
+ if ((WAVEFORMATEXTENSIBLE*)mt.Format() != NULL) {
hr=CheckAudioClient(&(((WAVEFORMATEXTENSIBLE*)mt.Format())->Format));
- else
+ } else {
hr=CheckAudioClient((WAVEFORMATEX*)mt.Format());
- if (FAILED(hr))
- {
+ }
+ if (FAILED(hr)) {
TRACE(_T("CMpcAudioRenderer::DoRenderSampleWasapi Error while checking audio client with input media type"));
return hr;
}
@@ -895,7 +893,9 @@ HRESULT CMpcAudioRenderer::DoRenderSampleWasapi(IMediaSample *pMediaSample)
// Initialization
hr = pMediaSample->GetPointer(&pMediaBuffer);
- if (FAILED (hr)) return hr;
+ if (FAILED (hr)) {
+ return hr;
+ }
pInputBufferPointer=&pMediaBuffer[0];
pInputBufferEnd=&pMediaBuffer[0]+lSize;
@@ -905,15 +905,13 @@ HRESULT CMpcAudioRenderer::DoRenderSampleWasapi(IMediaSample *pMediaSample)
// Sleep for half the buffer duration since last buffer feed
DWORD currentTime=GetTickCount();
- if (lastBufferTime!=0 && hnsActualDuration!= 0 && lastBufferTime<currentTime && (currentTime-lastBufferTime)<hnsActualDuration)
- {
+ if (lastBufferTime!=0 && hnsActualDuration!= 0 && lastBufferTime<currentTime && (currentTime-lastBufferTime)<hnsActualDuration) {
hnsActualDuration=hnsActualDuration-(currentTime-lastBufferTime);
Sleep(hnsActualDuration);
}
// Each loop fills one of the two buffers.
- while (pInputBufferPointer < pInputBufferEnd)
- {
+ while (pInputBufferPointer < pInputBufferEnd) {
UINT32 numFramesPadding=0;
pAudioClient->GetCurrentPadding(&numFramesPadding);
UINT32 numFramesAvailable = nFramesInBuffer - numFramesPadding;
@@ -921,46 +919,40 @@ HRESULT CMpcAudioRenderer::DoRenderSampleWasapi(IMediaSample *pMediaSample)
UINT32 nAvailableBytes=numFramesAvailable*frameSize;
UINT32 nBytesToWrite=nAvailableBytes;
// More room than enough in the output buffer
- if (nAvailableBytes > pInputBufferEnd - pInputBufferPointer)
- {
+ if (nAvailableBytes > pInputBufferEnd - pInputBufferPointer) {
nBytesToWrite=pInputBufferEnd - pInputBufferPointer;
numFramesAvailable=(UINT32)((float)nBytesToWrite/frameSize);
}
// Grab the next empty buffer from the audio device.
hr = pRenderClient->GetBuffer(numFramesAvailable, &pData);
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
TRACE(_T("CMpcAudioRenderer::DoRenderSampleWasapi GetBuffer failed with size %ld : (error %lx)"),nFramesInBuffer,hr);
return hr;
}
// Load the buffer with data from the audio source.
- if (pData != NULL)
- {
+ if (pData != NULL) {
memcpy(&pData[0], pInputBufferPointer, nBytesToWrite);
pInputBufferPointer += nBytesToWrite;
- }
- else
+ } else {
TRACE(_T("CMpcAudioRenderer::DoRenderSampleWasapi Output buffer is NULL"));
+ }
hr = pRenderClient->ReleaseBuffer(numFramesAvailable, 0); // no flags
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
TRACE(_T("CMpcAudioRenderer::DoRenderSampleWasapi ReleaseBuffer failed with size %ld (error %lx)"),nFramesInBuffer,hr);
return hr;
}
- if (!isAudioClientStarted)
- {
+ if (!isAudioClientStarted) {
TRACE(_T("CMpcAudioRenderer::DoRenderSampleWasapi Starting audio client"));
pAudioClient->Start();
isAudioClientStarted=true;
}
- if (pInputBufferPointer >= pInputBufferEnd)
- {
+ if (pInputBufferPointer >= pInputBufferEnd) {
lastBufferTime=GetTickCount();
// This is the duration of the filled buffer
hnsActualDuration=(double)REFTIMES_PER_SEC * numFramesAvailable / m_pWaveFileFormat->nSamplesPerSec;
@@ -983,55 +975,59 @@ HRESULT CMpcAudioRenderer::CheckAudioClient(WAVEFORMATEX *pWaveFormatEx)
HRESULT hr = S_OK;
CAutoLock cAutoLock(&m_csCheck);
TRACE(_T("CMpcAudioRenderer::CheckAudioClient"));
- if (pMMDevice == NULL) hr=GetDefaultAudioDevice(&pMMDevice);
+ if (pMMDevice == NULL) {
+ hr=GetDefaultAudioDevice(&pMMDevice);
+ }
// If no WAVEFORMATEX structure provided and client already exists, return it
- if (pAudioClient != NULL && pWaveFormatEx == NULL) return hr;
+ if (pAudioClient != NULL && pWaveFormatEx == NULL) {
+ return hr;
+ }
// Just create the audio client if no WAVEFORMATEX provided
- if (pAudioClient == NULL && pWaveFormatEx==NULL)
- {
- if (SUCCEEDED (hr)) hr=CreateAudioClient(pMMDevice, &pAudioClient);
+ if (pAudioClient == NULL && pWaveFormatEx==NULL) {
+ if (SUCCEEDED (hr)) {
+ hr=CreateAudioClient(pMMDevice, &pAudioClient);
+ }
return hr;
}
// Compare the exisiting WAVEFORMATEX with the one provided
WAVEFORMATEX *pNewWaveFormatEx = NULL;
- if (CheckFormatChanged(pWaveFormatEx, &pNewWaveFormatEx))
- {
+ if (CheckFormatChanged(pWaveFormatEx, &pNewWaveFormatEx)) {
// Format has changed, audio client has to be reinitialized
TRACE(_T("CMpcAudioRenderer::CheckAudioClient Format changed, reinitialize the audio client"));
- if (m_pWaveFileFormat)
- {
+ if (m_pWaveFileFormat) {
BYTE *p = (BYTE *)m_pWaveFileFormat;
SAFE_DELETE_ARRAY(p);
}
m_pWaveFileFormat=pNewWaveFormatEx;
hr = pAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, pWaveFormatEx, NULL);
- if (SUCCEEDED(hr))
- {
- if (pAudioClient!=NULL && isAudioClientStarted) pAudioClient->Stop();
+ if (SUCCEEDED(hr)) {
+ if (pAudioClient!=NULL && isAudioClientStarted) {
+ pAudioClient->Stop();
+ }
isAudioClientStarted=false;
SAFE_RELEASE(pRenderClient);
SAFE_RELEASE(pAudioClient);
- if (SUCCEEDED (hr)) hr=CreateAudioClient(pMMDevice, &pAudioClient);
- }
- else
- {
+ if (SUCCEEDED (hr)) {
+ hr=CreateAudioClient(pMMDevice, &pAudioClient);
+ }
+ } else {
TRACE(_T("CMpcAudioRenderer::CheckAudioClient New format not supported, accept it anyway"));
return S_OK;
}
- }
- else if (pRenderClient == NULL)
- {
+ } else if (pRenderClient == NULL) {
TRACE(_T("CMpcAudioRenderer::CheckAudioClient First initialization of the audio renderer"));
- }
- else
+ } else {
return hr;
+ }
SAFE_RELEASE(pRenderClient);
- if (SUCCEEDED (hr)) hr=InitAudioClient(pWaveFormatEx, pAudioClient, &pRenderClient);
+ if (SUCCEEDED (hr)) {
+ hr=InitAudioClient(pWaveFormatEx, pAudioClient, &pRenderClient);
+ }
return hr;
}
@@ -1054,42 +1050,51 @@ HRESULT CMpcAudioRenderer::GetDefaultAudioDevice(IMMDevice **ppMMDevice)
bool CMpcAudioRenderer::CheckFormatChanged(WAVEFORMATEX *pWaveFormatEx, WAVEFORMATEX **ppNewWaveFormatEx)
{
bool formatChanged=false;
- if (m_pWaveFileFormat==NULL)
+ if (m_pWaveFileFormat==NULL) {
formatChanged=true;
- else if (pWaveFormatEx->wFormatTag != m_pWaveFileFormat->wFormatTag
- || pWaveFormatEx->nChannels != m_pWaveFileFormat->nChannels
- || pWaveFormatEx->wBitsPerSample != m_pWaveFileFormat->wBitsPerSample) // TODO : improve the checks
+ } else if (pWaveFormatEx->wFormatTag != m_pWaveFileFormat->wFormatTag
+ || pWaveFormatEx->nChannels != m_pWaveFileFormat->nChannels
+ || pWaveFormatEx->wBitsPerSample != m_pWaveFileFormat->wBitsPerSample) { // TODO : improve the checks
formatChanged=true;
+ }
- if (!formatChanged) return false;
+ if (!formatChanged) {
+ return false;
+ }
int size = sizeof(WAVEFORMATEX) + pWaveFormatEx->cbSize; // Always true, even for WAVEFORMATEXTENSIBLE and WAVEFORMATEXTENSIBLE_IEC61937
*ppNewWaveFormatEx = (WAVEFORMATEX *)new BYTE[size];
- if (! *ppNewWaveFormatEx)
+ if (! *ppNewWaveFormatEx) {
return false;
+ }
memcpy(*ppNewWaveFormatEx, pWaveFormatEx, size);
return true;
}
HRESULT CMpcAudioRenderer::GetBufferSize(WAVEFORMATEX *pWaveFormatEx, REFERENCE_TIME *pHnsBufferPeriod)
{
- if (pWaveFormatEx==NULL) return S_OK;
- if (pWaveFormatEx->cbSize <22) //WAVEFORMATEX
+ if (pWaveFormatEx==NULL) {
return S_OK;
+ }
+ if (pWaveFormatEx->cbSize <22) { //WAVEFORMATEX
+ return S_OK;
+ }
WAVEFORMATEXTENSIBLE *wfext=(WAVEFORMATEXTENSIBLE*)pWaveFormatEx;
if (bufferSize==0)
- if (wfext->SubFormat==KSDATAFORMAT_SUBTYPE_IEC61937_DOLBY_MLP)
+ if (wfext->SubFormat==KSDATAFORMAT_SUBTYPE_IEC61937_DOLBY_MLP) {
bufferSize=61440;
- else if (wfext->SubFormat==KSDATAFORMAT_SUBTYPE_IEC61937_DTS_HD)
+ } else if (wfext->SubFormat==KSDATAFORMAT_SUBTYPE_IEC61937_DTS_HD) {
bufferSize=32768;
- else if (wfext->SubFormat==KSDATAFORMAT_SUBTYPE_IEC61937_DOLBY_DIGITAL_PLUS)
+ } else if (wfext->SubFormat==KSDATAFORMAT_SUBTYPE_IEC61937_DOLBY_DIGITAL_PLUS) {
bufferSize=24576;
- else if (wfext->Format.wFormatTag==WAVE_FORMAT_DOLBY_AC3_SPDIF)
+ } else if (wfext->Format.wFormatTag==WAVE_FORMAT_DOLBY_AC3_SPDIF) {
bufferSize=6144;
- else return S_OK;
+ } else {
+ return S_OK;
+ }
*pHnsBufferPeriod = (REFERENCE_TIME)( (REFERENCE_TIME)bufferSize * 10000 * 8 / ((REFERENCE_TIME)pWaveFormatEx->nChannels * pWaveFormatEx->wBitsPerSample *
1.0 * pWaveFormatEx->nSamplesPerSec) /*+ 0.5*/);
@@ -1109,23 +1114,22 @@ HRESULT CMpcAudioRenderer::InitAudioClient(WAVEFORMATEX *pWaveFormatEx, IAudioCl
hnsPeriod=500000; //50 ms is the best according to James @Slysoft
hr = pAudioClient->IsFormatSupported(AUDCLNT_SHAREMODE_EXCLUSIVE, pWaveFormatEx, NULL);
- if (FAILED(hr))
+ if (FAILED(hr)) {
TRACE(_T("CMpcAudioRenderer::InitAudioClient not supported (0x%08x)"), hr);
- else
+ } else {
TRACE(_T("CMpcAudioRenderer::InitAudioClient format supported"));
+ }
GetBufferSize(pWaveFormatEx, &hnsPeriod);
if (SUCCEEDED (hr)) hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_EXCLUSIVE,0/*AUDCLNT_STREAMFLAGS_EVENTCALLBACK*/,
hnsPeriod,hnsPeriod,pWaveFormatEx,NULL);
- if (FAILED (hr) && hr != AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED)
- {
+ if (FAILED (hr) && hr != AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) {
TRACE(_T("CMpcAudioRenderer::InitAudioClient failed (0x%08x)"), hr);
return hr;
}
- if (AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED == hr)
- {
+ if (AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED == hr) {
// if the buffer size was not aligned, need to do the alignment dance
TRACE(_T("CMpcAudioRenderer::InitAudioClient Buffer size not aligned. Realigning"));
@@ -1146,28 +1150,34 @@ HRESULT CMpcAudioRenderer::InitAudioClient(WAVEFORMATEX *pWaveFormatEx, IAudioCl
+ 0.5 // rounding
);
- if (SUCCEEDED (hr)) hr=CreateAudioClient(pMMDevice, &pAudioClient);
+ if (SUCCEEDED (hr)) {
+ hr=CreateAudioClient(pMMDevice, &pAudioClient);
+ }
TRACE(_T("CMpcAudioRenderer::InitAudioClient Trying again with periodicity of %I64u hundred-nanoseconds, or %u frames.\n"), hnsPeriod, nFramesInBuffer);
if (SUCCEEDED (hr))
hr = pAudioClient->Initialize(AUDCLNT_SHAREMODE_EXCLUSIVE,0/*AUDCLNT_STREAMFLAGS_EVENTCALLBACK*/,
hnsPeriod, hnsPeriod, pWaveFormatEx, NULL);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
TRACE(_T("CMpcAudioRenderer::InitAudioClient Failed to reinitialize the audio client"));
return hr;
}
} // if (AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED == hr)
// get the buffer size, which is aligned
- if (SUCCEEDED (hr)) hr = pAudioClient->GetBufferSize(&nFramesInBuffer);
+ if (SUCCEEDED (hr)) {
+ hr = pAudioClient->GetBufferSize(&nFramesInBuffer);
+ }
// calculate the new period
- if (SUCCEEDED (hr)) hr = pAudioClient->GetService(__uuidof(IAudioRenderClient), (void**)(ppRenderClient));
+ if (SUCCEEDED (hr)) {
+ hr = pAudioClient->GetService(__uuidof(IAudioRenderClient), (void**)(ppRenderClient));
+ }
- if (FAILED (hr))
+ if (FAILED (hr)) {
TRACE(_T("CMpcAudioRenderer::InitAudioClient service initialization failed (0x%08x)"), hr);
- else
+ } else {
TRACE(_T("CMpcAudioRenderer::InitAudioClient service initialization success"));
+ }
return hr;
}
@@ -1180,24 +1190,25 @@ HRESULT CMpcAudioRenderer::CreateAudioClient(IMMDevice *pMMDevice, IAudioClient
TRACE(_T("CMpcAudioRenderer::CreateAudioClient"));
- if (*ppAudioClient)
- {
- if (isAudioClientStarted) (*ppAudioClient)->Stop();
+ if (*ppAudioClient) {
+ if (isAudioClientStarted) {
+ (*ppAudioClient)->Stop();
+ }
SAFE_RELEASE(*ppAudioClient);
isAudioClientStarted=false;
}
- if (pMMDevice==NULL)
- {
+ if (pMMDevice==NULL) {
TRACE(_T("CMpcAudioRenderer::CreateAudioClient failed, device not loaded"));
return E_FAIL;
}
hr = pMMDevice->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL, reinterpret_cast<void**>(ppAudioClient));
- if (FAILED(hr))
+ if (FAILED(hr)) {
TRACE(_T("CMpcAudioRenderer::CreateAudioClient activation failed (0x%08x)"), hr);
- else
+ } else {
TRACE(_T("CMpcAudioRenderer::CreateAudioClient success"));
+ }
return hr;
}
diff --git a/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.h b/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.h
index 414dc1df9..fea836181 100644
--- a/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.h
+++ b/src/filters/renderer/MpcAudioRenderer/MpcAudioRenderer.h
@@ -45,9 +45,9 @@
class __declspec(uuid("601D2A2B-9CDE-40bd-8650-0485E3522727"))
CMpcAudioRenderer : public CBaseRenderer
- , public IBasicAudio
- , public ISpecifyPropertyPages2
- , public IMpcAudioRendererFilter
+ , public IBasicAudio
+ , public ISpecifyPropertyPages2
+ , public IMpcAudioRendererFilter
{
public:
CMpcAudioRenderer(LPUNKNOWN punk, HRESULT *phr);
@@ -98,7 +98,7 @@ public:
STDMETHODIMP SetMuteFastForward(BOOL nValue);
STDMETHODIMP_(BOOL) GetMuteFastForward();
-// CMpcAudioRenderer
+ // CMpcAudioRenderer
private:
HRESULT DoRenderSampleDirectSound(IMediaSample *pMediaSample);
@@ -120,7 +120,7 @@ private:
soundtouch::SoundTouch* m_pSoundTouch;
CCritSec m_csProps;
-// CMpcAudioRenderer WASAPI methods
+ // CMpcAudioRenderer WASAPI methods
HRESULT GetDefaultAudioDevice(IMMDevice **ppMMDevice);
HRESULT CreateAudioClient(IMMDevice *pMMDevice, IAudioClient **ppAudioClient);
HRESULT InitAudioClient(WAVEFORMATEX *pWaveFormatEx, IAudioClient *pAudioClient, IAudioRenderClient **ppRenderClient);
@@ -130,7 +130,7 @@ private:
HRESULT GetBufferSize(WAVEFORMATEX *pWaveFormatEx, REFERENCE_TIME *pHnsBufferPeriod);
-// WASAPI variables
+ // WASAPI variables
bool m_useWASAPI;
bool m_useWASAPIAfterRestart;
bool m_bMuteFastForward;
diff --git a/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.cpp b/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.cpp
index d934e278f..3294071ed 100644
--- a/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.cpp
+++ b/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.cpp
@@ -46,9 +46,13 @@ bool CMpcAudioRendererSettingsWnd::OnConnect(const CInterfaceList<IUnknown, &IID
m_pMAR.Release();
POSITION pos = pUnks.GetHeadPosition();
- while(pos && !(m_pMAR = pUnks.GetNext(pos)));
+ while(pos && !(m_pMAR = pUnks.GetNext(pos))) {
+ ;
+ }
- if(!m_pMAR) return false;
+ if(!m_pMAR) {
+ return false;
+ }
return true;
}
@@ -73,8 +77,9 @@ bool CMpcAudioRendererSettingsWnd::OnActivate()
m_cbMuteFastForward.SetCheck(m_pMAR->GetMuteFastForward());
- for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow())
+ for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
pWnd->SetFont(&m_font, FALSE);
+ }
return true;
}
@@ -87,8 +92,7 @@ bool CMpcAudioRendererSettingsWnd::OnApply()
{
OnDeactivate();
- if(m_pMAR)
- {
+ if(m_pMAR) {
m_pMAR->SetWasapiMode(m_cbWasapiMode.GetCheck());
m_pMAR->SetMuteFastForward(m_cbMuteFastForward.GetCheck());
m_pMAR->Apply();
diff --git a/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.h b/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.h
index c643adca3..fc75abace 100644
--- a/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.h
+++ b/src/filters/renderer/MpcAudioRenderer/MpcAudioRendererSettingsWnd.h
@@ -38,8 +38,7 @@ private :
CButton m_cbWasapiMode;
CButton m_cbMuteFastForward;
- enum
- {
+ enum {
IDC_PP_WASAPI_MODE = 10000,
IDC_PP_MUTE_FAST_FORWARD,
};
diff --git a/src/filters/renderer/SyncClock/Interfaces.h b/src/filters/renderer/SyncClock/Interfaces.h
index a4bff0b25..d7be17e73 100644
--- a/src/filters/renderer/SyncClock/Interfaces.h
+++ b/src/filters/renderer/SyncClock/Interfaces.h
@@ -3,8 +3,8 @@
const IID IID_ISyncClock = {0xa62888fb, 0x8e37, 0x44d2, {0x88, 0x50, 0xb3, 0xe3, 0xf2, 0xc1, 0x16, 0x9f}};
MIDL_INTERFACE("A62888FB-8E37-44d2-8850-B3E3F2C1169F")
-ISyncClock: public IUnknown
-{
+ISyncClock:
+public IUnknown {
public:
virtual HRESULT STDMETHODCALLTYPE AdjustClock(DOUBLE adjustment) = 0;
virtual HRESULT STDMETHODCALLTYPE SetBias(DOUBLE bias) = 0;
diff --git a/src/filters/renderer/SyncClock/SyncClock.cpp b/src/filters/renderer/SyncClock/SyncClock.cpp
index 51743b592..fcd760db8 100644
--- a/src/filters/renderer/SyncClock/SyncClock.cpp
+++ b/src/filters/renderer/SyncClock/SyncClock.cpp
@@ -8,13 +8,11 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CSyncClockFilter), L"SyncClock", MERIT_NORMAL, 0, NULL, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CSyncClockFilter>, NULL, &sudFilter[0]}
};
@@ -22,12 +20,12 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
- return AMovieDllRegisterServer2(TRUE);
+ return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
- return AMovieDllRegisterServer2(FALSE);
+ return AMovieDllRegisterServer2(FALSE);
}
#include "../../FilterApp.h"
@@ -37,8 +35,8 @@ CFilterApp theApp;
#endif
CSyncClockFilter::CSyncClockFilter(LPUNKNOWN pUnk, HRESULT *phr)
- : CBaseFilter(NAME("SyncClock"), NULL, &m_Lock, CLSID_NULL)
- , m_Clock(static_cast<IBaseFilter*>(this), phr)
+ : CBaseFilter(NAME("SyncClock"), NULL, &m_Lock, CLSID_NULL)
+ , m_Clock(static_cast<IBaseFilter*>(this), phr)
{
}
@@ -73,49 +71,43 @@ STDMETHODIMP CSyncClockFilter::GetStartTime(REFERENCE_TIME *startTime)
STDMETHODIMP CSyncClockFilter::NonDelegatingQueryInterface( REFIID riid, void ** ppv )
{
- CheckPointer(ppv, E_POINTER);
-
- if(riid == IID_IReferenceClock)
- {
- return GetInterface(static_cast<IReferenceClock*>(&m_Clock), ppv);
- }
- else
- if(riid == IID_ISyncClock)
- {
- return GetInterface(static_cast<ISyncClock*>(this), ppv);
- }
- else
- {
- return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
- }
+ CheckPointer(ppv, E_POINTER);
+
+ if(riid == IID_IReferenceClock) {
+ return GetInterface(static_cast<IReferenceClock*>(&m_Clock), ppv);
+ } else if(riid == IID_ISyncClock) {
+ return GetInterface(static_cast<ISyncClock*>(this), ppv);
+ } else {
+ return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
+ }
}
int CSyncClockFilter::GetPinCount()
{
- return 0;
+ return 0;
}
CBasePin *CSyncClockFilter::GetPin(int i)
{
- UNREFERENCED_PARAMETER(i);
- return NULL;
+ UNREFERENCED_PARAMETER(i);
+ return NULL;
}
// CSyncClock methods
CSyncClock::CSyncClock(LPUNKNOWN pUnk, HRESULT *phr)
- : CBaseReferenceClock(NAME("SyncClock"), pUnk, phr)
- , m_pCurrentRefClock(0), m_pPrevRefClock(0)
+ : CBaseReferenceClock(NAME("SyncClock"), pUnk, phr)
+ , m_pCurrentRefClock(0), m_pPrevRefClock(0)
{
QueryPerformanceFrequency((LARGE_INTEGER*)&m_llPerfFrequency);
- m_rtPrivateTime = GetTicks100ns();
- m_rtPrevTime = m_rtPrivateTime;
+ m_rtPrivateTime = GetTicks100ns();
+ m_rtPrevTime = m_rtPrivateTime;
adjustment = 1.0;
bias = 1.0;
}
REFERENCE_TIME CSyncClock::GetPrivateTime()
{
- CAutoLock cObjectLock(this);
+ CAutoLock cObjectLock(this);
REFERENCE_TIME rtTime = GetTicks100ns();
@@ -125,14 +117,13 @@ REFERENCE_TIME CSyncClock::GetPrivateTime()
delta = (REFERENCE_TIME)((DOUBLE)delta * adjustment * bias);
m_rtPrivateTime = m_rtPrivateTime + delta;
- return m_rtPrivateTime;
+ return m_rtPrivateTime;
}
REFERENCE_TIME CSyncClock::GetTicks100ns()
{
LONGLONG i64Ticks100ns;
- if (m_llPerfFrequency != 0)
- {
+ if (m_llPerfFrequency != 0) {
QueryPerformanceCounter((LARGE_INTEGER*)&i64Ticks100ns);
i64Ticks100ns = LONGLONG((double(i64Ticks100ns) * 10000000) / double(m_llPerfFrequency) + 0.5);
return (REFERENCE_TIME)i64Ticks100ns;
diff --git a/src/filters/renderer/SyncClock/SyncClock.h b/src/filters/renderer/SyncClock/SyncClock.h
index 110a318f8..fdb90420e 100644
--- a/src/filters/renderer/SyncClock/SyncClock.h
+++ b/src/filters/renderer/SyncClock/SyncClock.h
@@ -8,37 +8,36 @@ class CSyncClockFilter;
class CSyncClock: public CBaseReferenceClock
{
- friend class CSyncClockFilter;
+ friend class CSyncClockFilter;
public:
- CSyncClock(LPUNKNOWN pUnk, HRESULT *phr);
+ CSyncClock(LPUNKNOWN pUnk, HRESULT *phr);
REFERENCE_TIME GetPrivateTime();
- IUnknown * pUnk()
- {
+ IUnknown * pUnk() {
return static_cast<IUnknown*>(static_cast<IReferenceClock*>(this));
}
DOUBLE adjustment; // For adjusting speed temporarily
DOUBLE bias; // For changing speed permanently
private:
- REFERENCE_TIME m_rtPrivateTime;
+ REFERENCE_TIME m_rtPrivateTime;
LONGLONG m_llPerfFrequency;
REFERENCE_TIME m_rtPrevTime;
- CCritSec m_csClock;
- IReferenceClock * m_pCurrentRefClock;
- IReferenceClock * m_pPrevRefClock;
+ CCritSec m_csClock;
+ IReferenceClock * m_pCurrentRefClock;
+ IReferenceClock * m_pPrevRefClock;
REFERENCE_TIME GetTicks100ns();
};
class __declspec(uuid("57797fe5-ee9b-4408-98a9-20b134e7e8f0"))
-CSyncClockFilter: public ISyncClock, public CBaseFilter
+ CSyncClockFilter: public ISyncClock, public CBaseFilter
{
public:
- CSyncClockFilter(LPUNKNOWN pUnk, HRESULT *phr);
+ CSyncClockFilter(LPUNKNOWN pUnk, HRESULT *phr);
virtual ~CSyncClockFilter();
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface( REFIID riid, void ** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface( REFIID riid, void ** ppv);
// ISyncClock
STDMETHODIMP AdjustClock(DOUBLE adjustment);
@@ -46,12 +45,12 @@ public:
STDMETHODIMP GetBias(DOUBLE *bias);
STDMETHODIMP GetStartTime(REFERENCE_TIME *startTime);
- // CBaseFilter methods
- int CSyncClockFilter::GetPinCount();
- CBasePin *CSyncClockFilter::GetPin(int iPin);
+ // CBaseFilter methods
+ int CSyncClockFilter::GetPinCount();
+ CBasePin *CSyncClockFilter::GetPin(int iPin);
private:
- CSyncClock m_Clock;
- CCritSec m_Lock;
+ CSyncClock m_Clock;
+ CCritSec m_Lock;
};
diff --git a/src/filters/renderer/SyncClock/stdafx.cpp b/src/filters/renderer/SyncClock/stdafx.cpp
index 8905f2db5..0385cc615 100644
--- a/src/filters/renderer/SyncClock/stdafx.cpp
+++ b/src/filters/renderer/SyncClock/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/renderer/SyncClock/stdafx.h b/src/filters/renderer/SyncClock/stdafx.h
index c35359c38..a9f666228 100644
--- a/src/filters/renderer/SyncClock/stdafx.h
+++ b/src/filters/renderer/SyncClock/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,15 +6,15 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
diff --git a/src/filters/renderer/VideoRenderers/AllocatorCommon.cpp b/src/filters/renderer/VideoRenderers/AllocatorCommon.cpp
index fc63325bf..47b2e6ec1 100644
--- a/src/filters/renderer/VideoRenderers/AllocatorCommon.cpp
+++ b/src/filters/renderer/VideoRenderers/AllocatorCommon.cpp
@@ -35,7 +35,9 @@
bool IsVMR9InGraph(IFilterGraph* pFG)
{
BeginEnumFilters(pFG, pEF, pBF)
- if(CComQIPtr<IVMRWindowlessControl9>(pBF)) return(true);
+ if(CComQIPtr<IVMRWindowlessControl9>(pBF)) {
+ return(true);
+ }
EndEnumFilters
return(false);
}
@@ -56,25 +58,24 @@ HRESULT CreateAP9(const CLSID& clsid, HWND hWnd, bool bFullscreen, ISubPicAlloca
|| clsid == CLSID_RM9AllocatorPresenter && !(*ppAP = DNew CRM9AllocatorPresenter(hWnd, bFullscreen, hr, Error))
|| clsid == CLSID_QT9AllocatorPresenter && !(*ppAP = DNew CQT9AllocatorPresenter(hWnd, bFullscreen, hr, Error))
|| clsid == CLSID_DXRAllocatorPresenter && !(*ppAP = DNew CDXRAllocatorPresenter(hWnd, hr, Error))
- || clsid == CLSID_madVRAllocatorPresenter && !(*ppAP = DNew CmadVRAllocatorPresenter(hWnd, bFullscreen, hr, Error)))
+ || clsid == CLSID_madVRAllocatorPresenter && !(*ppAP = DNew CmadVRAllocatorPresenter(hWnd, bFullscreen, hr, Error))) {
return E_OUTOFMEMORY;
+ }
- if(*ppAP == NULL)
+ if(*ppAP == NULL) {
return E_FAIL;
+ }
(*ppAP)->AddRef();
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
Error += L"\n";
Error += GetWindowsErrorMessage(hr, NULL);
MessageBox(hWnd, Error, L"Error creating DX9 allocation presenter", MB_OK|MB_ICONERROR);
(*ppAP)->Release();
*ppAP = NULL;
- }
- else if (!Error.IsEmpty())
- {
+ } else if (!Error.IsEmpty()) {
MessageBox(hWnd, Error, L"Warning creating DX9 allocation presenter", MB_OK|MB_ICONWARNING);
}
@@ -84,22 +85,18 @@ HRESULT CreateAP9(const CLSID& clsid, HWND hWnd, bool bFullscreen, ISubPicAlloca
HRESULT CreateEVR(const CLSID& clsid, HWND hWnd, bool bFullscreen, ISubPicAllocatorPresenter** ppAP)
{
HRESULT hr = E_FAIL;
- if (clsid == CLSID_EVRAllocatorPresenter)
- {
+ if (clsid == CLSID_EVRAllocatorPresenter) {
CString Error;
*ppAP = DNew DSObjects::CEVRAllocatorPresenter(hWnd, bFullscreen, hr, Error);
(*ppAP)->AddRef();
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
Error += L"\n";
Error += GetWindowsErrorMessage(hr, NULL);
MessageBox(hWnd, Error, L"Error creating EVR Custom renderer", MB_OK | MB_ICONERROR);
(*ppAP)->Release();
*ppAP = NULL;
- }
- else if (!Error.IsEmpty())
- {
+ } else if (!Error.IsEmpty()) {
MessageBox(hWnd, Error, L"Warning creating EVR Custom renderer", MB_OK|MB_ICONWARNING);
}
}
@@ -110,75 +107,73 @@ HRESULT CreateEVR(const CLSID& clsid, HWND hWnd, bool bFullscreen, ISubPicAlloca
CString GetWindowsErrorMessage(HRESULT _Error, HMODULE _Module)
{
- switch (_Error)
- {
- case D3DERR_WRONGTEXTUREFORMAT :
- return _T("D3DERR_WRONGTEXTUREFORMAT");
- case D3DERR_UNSUPPORTEDCOLOROPERATION :
- return _T("D3DERR_UNSUPPORTEDCOLOROPERATION");
- case D3DERR_UNSUPPORTEDCOLORARG :
- return _T("D3DERR_UNSUPPORTEDCOLORARG");
- case D3DERR_UNSUPPORTEDALPHAOPERATION :
- return _T("D3DERR_UNSUPPORTEDALPHAOPERATION");
- case D3DERR_UNSUPPORTEDALPHAARG :
- return _T("D3DERR_UNSUPPORTEDALPHAARG");
- case D3DERR_TOOMANYOPERATIONS :
- return _T("D3DERR_TOOMANYOPERATIONS");
- case D3DERR_CONFLICTINGTEXTUREFILTER :
- return _T("D3DERR_CONFLICTINGTEXTUREFILTER");
- case D3DERR_UNSUPPORTEDFACTORVALUE :
- return _T("D3DERR_UNSUPPORTEDFACTORVALUE");
- case D3DERR_CONFLICTINGRENDERSTATE :
- return _T("D3DERR_CONFLICTINGRENDERSTATE");
- case D3DERR_UNSUPPORTEDTEXTUREFILTER :
- return _T("D3DERR_UNSUPPORTEDTEXTUREFILTER");
- case D3DERR_CONFLICTINGTEXTUREPALETTE :
- return _T("D3DERR_CONFLICTINGTEXTUREPALETTE");
- case D3DERR_DRIVERINTERNALERROR :
- return _T("D3DERR_DRIVERINTERNALERROR");
- case D3DERR_NOTFOUND :
- return _T("D3DERR_NOTFOUND");
- case D3DERR_MOREDATA :
- return _T("D3DERR_MOREDATA");
- case D3DERR_DEVICELOST :
- return _T("D3DERR_DEVICELOST");
- case D3DERR_DEVICENOTRESET :
- return _T("D3DERR_DEVICENOTRESET");
- case D3DERR_NOTAVAILABLE :
- return _T("D3DERR_NOTAVAILABLE");
- case D3DERR_OUTOFVIDEOMEMORY :
- return _T("D3DERR_OUTOFVIDEOMEMORY");
- case D3DERR_INVALIDDEVICE :
- return _T("D3DERR_INVALIDDEVICE");
- case D3DERR_INVALIDCALL :
- return _T("D3DERR_INVALIDCALL");
- case D3DERR_DRIVERINVALIDCALL :
- return _T("D3DERR_DRIVERINVALIDCALL");
- case D3DERR_WASSTILLDRAWING :
- return _T("D3DERR_WASSTILLDRAWING");
- case D3DOK_NOAUTOGEN :
- return _T("D3DOK_NOAUTOGEN");
- case D3DERR_DEVICEREMOVED :
- return _T("D3DERR_DEVICEREMOVED");
- case S_NOT_RESIDENT :
- return _T("S_NOT_RESIDENT");
- case S_RESIDENT_IN_SHARED_MEMORY :
- return _T("S_RESIDENT_IN_SHARED_MEMORY");
- case S_PRESENT_MODE_CHANGED :
- return _T("S_PRESENT_MODE_CHANGED");
- case S_PRESENT_OCCLUDED :
- return _T("S_PRESENT_OCCLUDED");
- case D3DERR_DEVICEHUNG :
- return _T("D3DERR_DEVICEHUNG");
- case E_UNEXPECTED :
- return _T("E_UNEXPECTED");
+ switch (_Error) {
+ case D3DERR_WRONGTEXTUREFORMAT :
+ return _T("D3DERR_WRONGTEXTUREFORMAT");
+ case D3DERR_UNSUPPORTEDCOLOROPERATION :
+ return _T("D3DERR_UNSUPPORTEDCOLOROPERATION");
+ case D3DERR_UNSUPPORTEDCOLORARG :
+ return _T("D3DERR_UNSUPPORTEDCOLORARG");
+ case D3DERR_UNSUPPORTEDALPHAOPERATION :
+ return _T("D3DERR_UNSUPPORTEDALPHAOPERATION");
+ case D3DERR_UNSUPPORTEDALPHAARG :
+ return _T("D3DERR_UNSUPPORTEDALPHAARG");
+ case D3DERR_TOOMANYOPERATIONS :
+ return _T("D3DERR_TOOMANYOPERATIONS");
+ case D3DERR_CONFLICTINGTEXTUREFILTER :
+ return _T("D3DERR_CONFLICTINGTEXTUREFILTER");
+ case D3DERR_UNSUPPORTEDFACTORVALUE :
+ return _T("D3DERR_UNSUPPORTEDFACTORVALUE");
+ case D3DERR_CONFLICTINGRENDERSTATE :
+ return _T("D3DERR_CONFLICTINGRENDERSTATE");
+ case D3DERR_UNSUPPORTEDTEXTUREFILTER :
+ return _T("D3DERR_UNSUPPORTEDTEXTUREFILTER");
+ case D3DERR_CONFLICTINGTEXTUREPALETTE :
+ return _T("D3DERR_CONFLICTINGTEXTUREPALETTE");
+ case D3DERR_DRIVERINTERNALERROR :
+ return _T("D3DERR_DRIVERINTERNALERROR");
+ case D3DERR_NOTFOUND :
+ return _T("D3DERR_NOTFOUND");
+ case D3DERR_MOREDATA :
+ return _T("D3DERR_MOREDATA");
+ case D3DERR_DEVICELOST :
+ return _T("D3DERR_DEVICELOST");
+ case D3DERR_DEVICENOTRESET :
+ return _T("D3DERR_DEVICENOTRESET");
+ case D3DERR_NOTAVAILABLE :
+ return _T("D3DERR_NOTAVAILABLE");
+ case D3DERR_OUTOFVIDEOMEMORY :
+ return _T("D3DERR_OUTOFVIDEOMEMORY");
+ case D3DERR_INVALIDDEVICE :
+ return _T("D3DERR_INVALIDDEVICE");
+ case D3DERR_INVALIDCALL :
+ return _T("D3DERR_INVALIDCALL");
+ case D3DERR_DRIVERINVALIDCALL :
+ return _T("D3DERR_DRIVERINVALIDCALL");
+ case D3DERR_WASSTILLDRAWING :
+ return _T("D3DERR_WASSTILLDRAWING");
+ case D3DOK_NOAUTOGEN :
+ return _T("D3DOK_NOAUTOGEN");
+ case D3DERR_DEVICEREMOVED :
+ return _T("D3DERR_DEVICEREMOVED");
+ case S_NOT_RESIDENT :
+ return _T("S_NOT_RESIDENT");
+ case S_RESIDENT_IN_SHARED_MEMORY :
+ return _T("S_RESIDENT_IN_SHARED_MEMORY");
+ case S_PRESENT_MODE_CHANGED :
+ return _T("S_PRESENT_MODE_CHANGED");
+ case S_PRESENT_OCCLUDED :
+ return _T("S_PRESENT_OCCLUDED");
+ case D3DERR_DEVICEHUNG :
+ return _T("D3DERR_DEVICEHUNG");
+ case E_UNEXPECTED :
+ return _T("E_UNEXPECTED");
}
CString errmsg;
LPVOID lpMsgBuf;
if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_HMODULE,
- _Module, _Error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL))
- {
+ _Module, _Error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL)) {
errmsg = (LPCTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
}
@@ -189,134 +184,133 @@ CString GetWindowsErrorMessage(HRESULT _Error, HMODULE _Module)
const wchar_t *GetD3DFormatStr(D3DFORMAT Format)
{
- switch (Format)
- {
- case D3DFMT_R8G8B8 :
- return L"R8G8B8";
- case D3DFMT_A8R8G8B8 :
- return L"A8R8G8B8";
- case D3DFMT_X8R8G8B8 :
- return L"X8R8G8B8";
- case D3DFMT_R5G6B5 :
- return L"R5G6B5";
- case D3DFMT_X1R5G5B5 :
- return L"X1R5G5B5";
- case D3DFMT_A1R5G5B5 :
- return L"A1R5G5B5";
- case D3DFMT_A4R4G4B4 :
- return L"A4R4G4B4";
- case D3DFMT_R3G3B2 :
- return L"R3G3B2";
- case D3DFMT_A8 :
- return L"A8";
- case D3DFMT_A8R3G3B2 :
- return L"A8R3G3B2";
- case D3DFMT_X4R4G4B4 :
- return L"X4R4G4B4";
- case D3DFMT_A2B10G10R10:
- return L"A2B10G10R10";
- case D3DFMT_A8B8G8R8 :
- return L"A8B8G8R8";
- case D3DFMT_X8B8G8R8 :
- return L"X8B8G8R8";
- case D3DFMT_G16R16 :
- return L"G16R16";
- case D3DFMT_A2R10G10B10:
- return L"A2R10G10B10";
- case D3DFMT_A16B16G16R16 :
- return L"A16B16G16R16";
- case D3DFMT_A8P8 :
- return L"A8P8";
- case D3DFMT_P8 :
- return L"P8";
- case D3DFMT_L8 :
- return L"L8";
- case D3DFMT_A8L8 :
- return L"A8L8";
- case D3DFMT_A4L4 :
- return L"A4L4";
- case D3DFMT_V8U8 :
- return L"V8U8";
- case D3DFMT_L6V5U5 :
- return L"L6V5U5";
- case D3DFMT_X8L8V8U8 :
- return L"X8L8V8U8";
- case D3DFMT_Q8W8V8U8 :
- return L"Q8W8V8U8";
- case D3DFMT_V16U16 :
- return L"V16U16";
- case D3DFMT_A2W10V10U10:
- return L"A2W10V10U10";
- case D3DFMT_UYVY :
- return L"UYVY";
- case D3DFMT_R8G8_B8G8:
- return L"R8G8_B8G8";
- case D3DFMT_YUY2 :
- return L"YUY2";
- case D3DFMT_G8R8_G8B8:
- return L"G8R8_G8B8";
- case D3DFMT_DXT1 :
- return L"DXT1";
- case D3DFMT_DXT2 :
- return L"DXT2";
- case D3DFMT_DXT3 :
- return L"DXT3";
- case D3DFMT_DXT4 :
- return L"DXT4";
- case D3DFMT_DXT5 :
- return L"DXT5";
- case D3DFMT_D16_LOCKABLE :
- return L"D16_LOCKABLE";
- case D3DFMT_D32:
- return L"D32";
- case D3DFMT_D15S1:
- return L"D15S1";
- case D3DFMT_D24S8:
- return L"D24S8";
- case D3DFMT_D24X8:
- return L"D24X8";
- case D3DFMT_D24X4S4:
- return L"D24X4S4";
- case D3DFMT_D16:
- return L"D16";
- case D3DFMT_D32F_LOCKABLE:
- return L"D32F_LOCKABLE";
- case D3DFMT_D24FS8 :
- return L"D24FS8";
- case D3DFMT_D32_LOCKABLE :
- return L"D32_LOCKABLE";
- case D3DFMT_S8_LOCKABLE:
- return L"S8_LOCKABLE";
- case D3DFMT_L16:
- return L"L16";
- case D3DFMT_VERTEXDATA :
- return L"VERTEXDATA";
- case D3DFMT_INDEX16:
- return L"INDEX16";
- case D3DFMT_INDEX32:
- return L"INDEX32";
- case D3DFMT_Q16W16V16U16 :
- return L"Q16W16V16U16";
- case D3DFMT_MULTI2_ARGB8 :
- return L"MULTI2_ARGB8";
- case D3DFMT_R16F :
- return L"R16F";
- case D3DFMT_G16R16F:
- return L"G16R16F";
- case D3DFMT_A16B16G16R16F:
- return L"A16B16G16R16F";
- case D3DFMT_R32F :
- return L"R32F";
- case D3DFMT_G32R32F:
- return L"G32R32F";
- case D3DFMT_A32B32G32R32F:
- return L"A32B32G32R32F";
- case D3DFMT_CxV8U8 :
- return L"CxV8U8";
- case D3DFMT_A1 :
- return L"A1";
- case D3DFMT_BINARYBUFFER :
- return L"BINARYBUFFER";
+ switch (Format) {
+ case D3DFMT_R8G8B8 :
+ return L"R8G8B8";
+ case D3DFMT_A8R8G8B8 :
+ return L"A8R8G8B8";
+ case D3DFMT_X8R8G8B8 :
+ return L"X8R8G8B8";
+ case D3DFMT_R5G6B5 :
+ return L"R5G6B5";
+ case D3DFMT_X1R5G5B5 :
+ return L"X1R5G5B5";
+ case D3DFMT_A1R5G5B5 :
+ return L"A1R5G5B5";
+ case D3DFMT_A4R4G4B4 :
+ return L"A4R4G4B4";
+ case D3DFMT_R3G3B2 :
+ return L"R3G3B2";
+ case D3DFMT_A8 :
+ return L"A8";
+ case D3DFMT_A8R3G3B2 :
+ return L"A8R3G3B2";
+ case D3DFMT_X4R4G4B4 :
+ return L"X4R4G4B4";
+ case D3DFMT_A2B10G10R10:
+ return L"A2B10G10R10";
+ case D3DFMT_A8B8G8R8 :
+ return L"A8B8G8R8";
+ case D3DFMT_X8B8G8R8 :
+ return L"X8B8G8R8";
+ case D3DFMT_G16R16 :
+ return L"G16R16";
+ case D3DFMT_A2R10G10B10:
+ return L"A2R10G10B10";
+ case D3DFMT_A16B16G16R16 :
+ return L"A16B16G16R16";
+ case D3DFMT_A8P8 :
+ return L"A8P8";
+ case D3DFMT_P8 :
+ return L"P8";
+ case D3DFMT_L8 :
+ return L"L8";
+ case D3DFMT_A8L8 :
+ return L"A8L8";
+ case D3DFMT_A4L4 :
+ return L"A4L4";
+ case D3DFMT_V8U8 :
+ return L"V8U8";
+ case D3DFMT_L6V5U5 :
+ return L"L6V5U5";
+ case D3DFMT_X8L8V8U8 :
+ return L"X8L8V8U8";
+ case D3DFMT_Q8W8V8U8 :
+ return L"Q8W8V8U8";
+ case D3DFMT_V16U16 :
+ return L"V16U16";
+ case D3DFMT_A2W10V10U10:
+ return L"A2W10V10U10";
+ case D3DFMT_UYVY :
+ return L"UYVY";
+ case D3DFMT_R8G8_B8G8:
+ return L"R8G8_B8G8";
+ case D3DFMT_YUY2 :
+ return L"YUY2";
+ case D3DFMT_G8R8_G8B8:
+ return L"G8R8_G8B8";
+ case D3DFMT_DXT1 :
+ return L"DXT1";
+ case D3DFMT_DXT2 :
+ return L"DXT2";
+ case D3DFMT_DXT3 :
+ return L"DXT3";
+ case D3DFMT_DXT4 :
+ return L"DXT4";
+ case D3DFMT_DXT5 :
+ return L"DXT5";
+ case D3DFMT_D16_LOCKABLE :
+ return L"D16_LOCKABLE";
+ case D3DFMT_D32:
+ return L"D32";
+ case D3DFMT_D15S1:
+ return L"D15S1";
+ case D3DFMT_D24S8:
+ return L"D24S8";
+ case D3DFMT_D24X8:
+ return L"D24X8";
+ case D3DFMT_D24X4S4:
+ return L"D24X4S4";
+ case D3DFMT_D16:
+ return L"D16";
+ case D3DFMT_D32F_LOCKABLE:
+ return L"D32F_LOCKABLE";
+ case D3DFMT_D24FS8 :
+ return L"D24FS8";
+ case D3DFMT_D32_LOCKABLE :
+ return L"D32_LOCKABLE";
+ case D3DFMT_S8_LOCKABLE:
+ return L"S8_LOCKABLE";
+ case D3DFMT_L16:
+ return L"L16";
+ case D3DFMT_VERTEXDATA :
+ return L"VERTEXDATA";
+ case D3DFMT_INDEX16:
+ return L"INDEX16";
+ case D3DFMT_INDEX32:
+ return L"INDEX32";
+ case D3DFMT_Q16W16V16U16 :
+ return L"Q16W16V16U16";
+ case D3DFMT_MULTI2_ARGB8 :
+ return L"MULTI2_ARGB8";
+ case D3DFMT_R16F :
+ return L"R16F";
+ case D3DFMT_G16R16F:
+ return L"G16R16F";
+ case D3DFMT_A16B16G16R16F:
+ return L"A16B16G16R16F";
+ case D3DFMT_R32F :
+ return L"R32F";
+ case D3DFMT_G32R32F:
+ return L"G32R32F";
+ case D3DFMT_A32B32G32R32F:
+ return L"A32B32G32R32F";
+ case D3DFMT_CxV8U8 :
+ return L"CxV8U8";
+ case D3DFMT_A1 :
+ return L"A1";
+ case D3DFMT_BINARYBUFFER :
+ return L"BINARYBUFFER";
}
return L"Unknown";
}
diff --git a/src/filters/renderer/VideoRenderers/AllocatorCommon.h b/src/filters/renderer/VideoRenderers/AllocatorCommon.h
index 6a57a06f8..fd0ea9091 100644
--- a/src/filters/renderer/VideoRenderers/AllocatorCommon.h
+++ b/src/filters/renderer/VideoRenderers/AllocatorCommon.h
@@ -70,8 +70,7 @@ DEFINE_GUID(IID_IVMRffdshow9,
MIDL_INTERFACE("A273C7F6-25D4-46b0-B2C8-4F7FADC44E37")
IVMRffdshow9 :
-public IUnknown
-{
+public IUnknown {
public:
virtual STDMETHODIMP support_ffdshow(void) = 0;
};
diff --git a/src/filters/renderer/VideoRenderers/AllocatorCommon7.cpp b/src/filters/renderer/VideoRenderers/AllocatorCommon7.cpp
index eac9d6ad3..5ccb89a19 100644
--- a/src/filters/renderer/VideoRenderers/AllocatorCommon7.cpp
+++ b/src/filters/renderer/VideoRenderers/AllocatorCommon7.cpp
@@ -35,7 +35,9 @@
bool IsVMR7InGraph(IFilterGraph* pFG)
{
BeginEnumFilters(pFG, pEF, pBF)
- if(CComQIPtr<IVMRWindowlessControl>(pBF)) return(true);
+ if(CComQIPtr<IVMRWindowlessControl>(pBF)) {
+ return(true);
+ }
EndEnumFilters
return(false);
}
@@ -53,16 +55,17 @@ HRESULT CreateAP7(const CLSID& clsid, HWND hWnd, ISubPicAllocatorPresenter** ppA
HRESULT hr = S_OK;
if(clsid == CLSID_VMR7AllocatorPresenter && !(*ppAP = DNew CVMR7AllocatorPresenter(hWnd, hr))
|| clsid == CLSID_RM7AllocatorPresenter && !(*ppAP = DNew CRM7AllocatorPresenter(hWnd, hr))
- || clsid == CLSID_QT7AllocatorPresenter && !(*ppAP = DNew CQT7AllocatorPresenter(hWnd, hr)))
+ || clsid == CLSID_QT7AllocatorPresenter && !(*ppAP = DNew CQT7AllocatorPresenter(hWnd, hr))) {
return E_OUTOFMEMORY;
+ }
- if(*ppAP == NULL)
+ if(*ppAP == NULL) {
return E_FAIL;
+ }
(*ppAP)->AddRef();
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
(*ppAP)->Release();
*ppAP = NULL;
}
diff --git a/src/filters/renderer/VideoRenderers/D3DFont.cpp b/src/filters/renderer/VideoRenderers/D3DFont.cpp
index 49c5293b8..46d9fdbc7 100644
--- a/src/filters/renderer/VideoRenderers/D3DFont.cpp
+++ b/src/filters/renderer/VideoRenderers/D3DFont.cpp
@@ -39,14 +39,12 @@
//-----------------------------------------------------------------------------
#define MAX_NUM_VERTICES 50*6
-struct FONT2DVERTEX
-{
+struct FONT2DVERTEX {
D3DXVECTOR4 p;
DWORD color;
FLOAT tu, tv;
};
-struct FONT3DVERTEX
-{
+struct FONT3DVERTEX {
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT tu, tv;
@@ -136,8 +134,9 @@ HRESULT CD3DFont::CreateGDIFont( HDC hDC, HFONT* pFont )
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
VARIABLE_PITCH, m_strFontName );
- if( *pFont == NULL )
+ if( *pFont == NULL ) {
return E_FAIL;
+ }
return S_OK;
}
@@ -157,8 +156,9 @@ HRESULT CD3DFont::PaintAlphabet( HDC hDC, BOOL bMeasureOnly )
TCHAR str[2] = _T("x"); // One-character, null-terminated string
// Calculate the spacing between characters based on line height
- if( 0 == GetTextExtentPoint32( hDC, str, 1, &size ) )
+ if( 0 == GetTextExtentPoint32( hDC, str, 1, &size ) ) {
return E_FAIL;
+ }
m_dwSpacing = (DWORD) ceil(size.cy * 0.3f);
// Set the starting point for the drawing
@@ -166,27 +166,27 @@ HRESULT CD3DFont::PaintAlphabet( HDC hDC, BOOL bMeasureOnly )
DWORD y = 0;
// For each character, draw text on the DC and advance the current position
- for( char c = 32; c < 127; c++ )
- {
+ for( char c = 32; c < 127; c++ ) {
str[0] = c;
- if( 0 == GetTextExtentPoint32( hDC, str, 1, &size ) )
+ if( 0 == GetTextExtentPoint32( hDC, str, 1, &size ) ) {
return E_FAIL;
+ }
- if( (DWORD)(x + size.cx + m_dwSpacing) > m_dwTexWidth )
- {
+ if( (DWORD)(x + size.cx + m_dwSpacing) > m_dwTexWidth ) {
x = m_dwSpacing;
y += size.cy + 1;
}
// Check to see if there's room to write the character here
- if( y + size.cy > m_dwTexHeight )
+ if( y + size.cy > m_dwTexHeight ) {
return D3DERR_MOREDATA;
+ }
- if( !bMeasureOnly )
- {
+ if( !bMeasureOnly ) {
// Perform the actual drawing
- if( 0 == ExtTextOut( hDC, x+0, y+0, ETO_OPAQUE, NULL, str, 1, NULL ) )
+ if( 0 == ExtTextOut( hDC, x+0, y+0, ETO_OPAQUE, NULL, str, 1, NULL ) ) {
return E_FAIL;
+ }
m_fTexCoords[c-32][0] = ((FLOAT)(x + 0 - m_dwSpacing))/m_dwTexWidth;
m_fTexCoords[c-32][1] = ((FLOAT)(y + 0 + 0 ))/m_dwTexHeight;
@@ -229,55 +229,55 @@ HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
SetMapMode( hDC, MM_TEXT );
hr = CreateGDIFont( hDC, &hFont );
- if( FAILED(hr) )
+ if( FAILED(hr) ) {
goto LCleanReturn;
+ }
hFontOld = (HFONT) SelectObject( hDC, hFont );
// Calculate the dimensions for the smallest power-of-two texture which
// can hold all the printable characters
m_dwTexWidth = m_dwTexHeight = 128;
- while( D3DERR_MOREDATA == ( hr = PaintAlphabet( hDC, true ) ) )
- {
+ while( D3DERR_MOREDATA == ( hr = PaintAlphabet( hDC, true ) ) ) {
m_dwTexWidth *= 2;
m_dwTexHeight *= 2;
}
- if( FAILED(hr) )
+ if( FAILED(hr) ) {
goto LCleanReturn;
+ }
// If requested texture is too big, use a smaller texture and smaller font,
// and scale up when rendering.
D3DCAPS9 d3dCaps;
m_pd3dDevice->GetDeviceCaps( &d3dCaps );
- if( m_dwTexWidth > d3dCaps.MaxTextureWidth )
- {
+ if( m_dwTexWidth > d3dCaps.MaxTextureWidth ) {
m_fTextScale = (FLOAT)d3dCaps.MaxTextureWidth / (FLOAT)m_dwTexWidth;
m_dwTexWidth = m_dwTexHeight = d3dCaps.MaxTextureWidth;
bool bFirstRun = true; // Flag clear after first run
- do
- {
+ do {
// If we've already tried fitting the new text, the scale is still
// too large. Reduce and try again.
- if( !bFirstRun)
+ if( !bFirstRun) {
m_fTextScale *= 0.9f;
+ }
// The font has to be scaled to fit on the maximum texture size; our
// current font is too big and needs to be recreated to scale.
DeleteObject( SelectObject( hDC, hFontOld ) );
hr = CreateGDIFont( hDC, &hFont );
- if( FAILED(hr) )
+ if( FAILED(hr) ) {
goto LCleanReturn;
+ }
hFontOld = (HFONT) SelectObject( hDC, hFont );
bFirstRun = false;
- }
- while( D3DERR_MOREDATA == ( hr = PaintAlphabet( hDC, true ) ) );
+ } while( D3DERR_MOREDATA == ( hr = PaintAlphabet( hDC, true ) ) );
}
@@ -285,8 +285,9 @@ HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
hr = m_pd3dDevice->CreateTexture( m_dwTexWidth, m_dwTexHeight, 1,
0, D3DFMT_A4R4G4B4,
D3DPOOL_MANAGED, &m_pTexture, NULL );
- if( FAILED(hr) )
+ if( FAILED(hr) ) {
goto LCleanReturn;
+ }
// Prepare to create a bitmap
DWORD* pBitmapBits;
@@ -312,8 +313,9 @@ HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
// Paint the alphabet onto the selected bitmap
hr = PaintAlphabet( hDC, false );
- if( FAILED(hr) )
+ if( FAILED(hr) ) {
goto LCleanReturn;
+ }
// Lock the surface and write the alpha values for the set pixels
D3DLOCKED_RECT d3dlr;
@@ -324,18 +326,13 @@ HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
BYTE bAlpha; // 4-bit measure of pixel intensity
DWORD x, y;
- for( y=0; y < m_dwTexHeight; y++ )
- {
+ for( y=0; y < m_dwTexHeight; y++ ) {
pDst16 = (WORD*)pDstRow;
- for( x=0; x < m_dwTexWidth; x++ )
- {
+ for( x=0; x < m_dwTexWidth; x++ ) {
bAlpha = (BYTE)((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4);
- if (bAlpha > 0)
- {
+ if (bAlpha > 0) {
*pDst16++ = (WORD) ((bAlpha << 12) | 0x0fff);
- }
- else
- {
+ } else {
*pDst16++ = 0x0000;
}
}
@@ -346,8 +343,9 @@ HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
// Done updating texture, so clean up used objects
LCleanReturn:
- if( m_pTexture )
+ if( m_pTexture ) {
m_pTexture->UnlockRect(0);
+ }
SelectObject( hDC, hbmOld );
SelectObject( hDC, hFontOld );
@@ -373,28 +371,24 @@ HRESULT CD3DFont::RestoreDeviceObjects()
int vertexSize = max( sizeof(FONT2DVERTEX), sizeof(FONT3DVERTEX ) );
if( FAILED( hr = m_pd3dDevice->CreateVertexBuffer( MAX_NUM_VERTICES * vertexSize,
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
- D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )
- {
+ D3DPOOL_DEFAULT, &m_pVB, NULL ) ) ) {
return hr;
}
bool bSupportsAlphaBlend = true;
LPDIRECT3D9 pd3d9 = NULL;
- if( SUCCEEDED( m_pd3dDevice->GetDirect3D( &pd3d9 ) ) )
- {
+ if( SUCCEEDED( m_pd3dDevice->GetDirect3D( &pd3d9 ) ) ) {
D3DCAPS9 Caps;
D3DDISPLAYMODE Mode;
LPDIRECT3DSURFACE9 pSurf = NULL;
D3DSURFACE_DESC Desc;
m_pd3dDevice->GetDeviceCaps( &Caps );
m_pd3dDevice->GetDisplayMode( 0, &Mode );
- if( SUCCEEDED( m_pd3dDevice->GetRenderTarget( 0, &pSurf ) ) )
- {
+ if( SUCCEEDED( m_pd3dDevice->GetRenderTarget( 0, &pSurf ) ) ) {
pSurf->GetDesc( &Desc );
if( FAILED( pd3d9->CheckDeviceFormat( Caps.AdapterOrdinal, Caps.DeviceType, Mode.Format,
D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_SURFACE,
- Desc.Format ) ) )
- {
+ Desc.Format ) ) ) {
bSupportsAlphaBlend = false;
}
SAFE_RELEASE( pSurf );
@@ -403,24 +397,21 @@ HRESULT CD3DFont::RestoreDeviceObjects()
}
// Create the state blocks for rendering text
- for( UINT which=0; which<2; which++ )
- {
+ for( UINT which=0; which<2; which++ ) {
m_pd3dDevice->BeginStateBlock();
m_pd3dDevice->SetTexture( 0, m_pTexture );
- if ( D3DFONT_ZENABLE & m_dwFontFlags )
+ if ( D3DFONT_ZENABLE & m_dwFontFlags ) {
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
- else
+ } else {
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
+ }
- if( bSupportsAlphaBlend )
- {
+ if( bSupportsAlphaBlend ) {
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
m_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
- }
- else
- {
+ } else {
m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}
m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
@@ -451,10 +442,11 @@ HRESULT CD3DFont::RestoreDeviceObjects()
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
- if( which==0 )
+ if( which==0 ) {
m_pd3dDevice->EndStateBlock( &m_pStateBlockSaved );
- else
+ } else {
m_pd3dDevice->EndStateBlock( &m_pStateBlockDrawText );
+ }
}
return S_OK;
@@ -500,34 +492,35 @@ HRESULT CD3DFont::DeleteDeviceObjects()
//-----------------------------------------------------------------------------
HRESULT CD3DFont::GetTextExtent( const TCHAR* strText, SIZE* pSize )
{
- if( NULL==strText || NULL==pSize )
+ if( NULL==strText || NULL==pSize ) {
return E_FAIL;
+ }
FLOAT fRowWidth = 0.0f;
FLOAT fRowHeight = (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight;
FLOAT fWidth = 0.0f;
FLOAT fHeight = fRowHeight;
- while( *strText )
- {
+ while( *strText ) {
TCHAR c = *strText++;
- if( c == _T('\n') )
- {
+ if( c == _T('\n') ) {
fRowWidth = 0.0f;
fHeight += fRowHeight;
}
- if( (c-32) < 0 || (c-32) >= 128-32 )
+ if( (c-32) < 0 || (c-32) >= 128-32 ) {
continue;
+ }
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT tx2 = m_fTexCoords[c-32][2];
fRowWidth += (tx2-tx1)*m_dwTexWidth - 2*m_dwSpacing;
- if( fRowWidth > fWidth )
+ if( fRowWidth > fWidth ) {
fWidth = fRowWidth;
+ }
}
pSize->cx = (int)fWidth;
@@ -551,8 +544,9 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
FLOAT fXScale, FLOAT fYScale, DWORD dwColor,
const TCHAR* strText, DWORD dwFlags )
{
- if( m_pd3dDevice == NULL )
+ if( m_pd3dDevice == NULL ) {
return E_FAIL;
+ }
// Set up renderstate
m_pStateBlockSaved->Capture();
@@ -562,8 +556,7 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
m_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(FONT2DVERTEX) );
// Set filter states
- if( dwFlags & D3DFONT_FILTERED )
- {
+ if( dwFlags & D3DFONT_FILTERED ) {
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
}
@@ -573,19 +566,19 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
FLOAT fLineHeight = ( m_fTexCoords[0][3] - m_fTexCoords[0][1] ) * m_dwTexHeight;
// Center the text block in the viewport
- if( dwFlags & D3DFONT_CENTERED_X )
- {
+ if( dwFlags & D3DFONT_CENTERED_X ) {
const TCHAR* strTextTmp = strText;
float xFinal = 0.0f;
- while( *strTextTmp )
- {
+ while( *strTextTmp ) {
TCHAR c = *strTextTmp++;
- if( c == _T('\n') )
- break; // Isn't supported.
- if( (c-32) < 0 || (c-32) >= 128-32 )
+ if( c == _T('\n') ) {
+ break; // Isn't supported.
+ }
+ if( (c-32) < 0 || (c-32) >= 128-32 ) {
continue;
+ }
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT tx2 = m_fTexCoords[c-32][2];
@@ -599,8 +592,7 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
x = -xFinal/vp.Width;
}
- if( dwFlags & D3DFONT_CENTERED_Y )
- {
+ if( dwFlags & D3DFONT_CENTERED_Y ) {
y = -fLineHeight/vp.Height;
}
@@ -618,18 +610,17 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
DWORD dwNumTriangles = 0L;
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
- while( *strText )
- {
+ while( *strText ) {
TCHAR c = *strText++;
- if( c == _T('\n') )
- {
+ if( c == _T('\n') ) {
sx = fStartX;
sy += fYScale*vp.Height;
}
- if( (c-32) < 0 || (c-32) >= 128-32 )
+ if( (c-32) < 0 || (c-32) >= 128-32 ) {
continue;
+ }
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT ty1 = m_fTexCoords[c-32][1];
@@ -642,8 +633,7 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
w *= (fXScale*vp.Height)/fLineHeight;
h *= (fYScale*vp.Height)/fLineHeight;
- if( c != _T(' ') )
- {
+ if( c != _T(' ') ) {
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,sz,rhw), dwColor, tx1, ty2 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,sz,rhw), dwColor, tx1, ty1 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,sz,rhw), dwColor, tx2, ty2 );
@@ -652,8 +642,7 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,sz,rhw), dwColor, tx1, ty1 );
dwNumTriangles += 2;
- if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) )
- {
+ if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) ) {
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
@@ -667,8 +656,9 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
// Unlock and render the vertex buffer
m_pVB->Unlock();
- if( dwNumTriangles > 0 )
+ if( dwNumTriangles > 0 ) {
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
+ }
// Restore the modified renderstates
m_pStateBlockSaved->Apply();
@@ -686,8 +676,9 @@ HRESULT CD3DFont::DrawTextScaled( FLOAT x, FLOAT y, FLOAT z,
HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
const TCHAR* strText, DWORD dwFlags )
{
- if( m_pd3dDevice == NULL )
+ if( m_pd3dDevice == NULL ) {
return E_FAIL;
+ }
// Setup renderstate
m_pStateBlockSaved->Capture();
@@ -697,28 +688,27 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
m_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(FONT2DVERTEX) );
// Set filter states
- if( dwFlags & D3DFONT_FILTERED )
- {
+ if( dwFlags & D3DFONT_FILTERED ) {
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
}
// Center the text block in the viewport
- if( dwFlags & D3DFONT_CENTERED_X )
- {
+ if( dwFlags & D3DFONT_CENTERED_X ) {
D3DVIEWPORT9 vp;
m_pd3dDevice->GetViewport( &vp );
const TCHAR* strTextTmp = strText;
float xFinal = 0.0f;
- while( *strTextTmp )
- {
+ while( *strTextTmp ) {
TCHAR c = *strTextTmp++;
- if( c == _T('\n') )
- break; // Isn't supported.
- if( (c-32) < 0 || (c-32) >= 128-32 )
+ if( c == _T('\n') ) {
+ break; // Isn't supported.
+ }
+ if( (c-32) < 0 || (c-32) >= 128-32 ) {
continue;
+ }
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT tx2 = m_fTexCoords[c-32][2];
@@ -730,8 +720,7 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
sx = (vp.Width-xFinal)/2.0f;
}
- if( dwFlags & D3DFONT_CENTERED_Y )
- {
+ if( dwFlags & D3DFONT_CENTERED_Y ) {
D3DVIEWPORT9 vp;
m_pd3dDevice->GetViewport( &vp );
float fLineHeight = ((m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight);
@@ -747,18 +736,17 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
DWORD dwNumTriangles = 0;
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
- while( *strText )
- {
+ while( *strText ) {
TCHAR c = *strText++;
- if( c == _T('\n') )
- {
+ if( c == _T('\n') ) {
sx = fStartX;
sy += (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight;
}
- if( (c-32) < 0 || (c-32) >= 128-32 )
+ if( (c-32) < 0 || (c-32) >= 128-32 ) {
continue;
+ }
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT ty1 = m_fTexCoords[c-32][1];
@@ -768,8 +756,7 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
FLOAT w = (tx2-tx1) * m_dwTexWidth / m_fTextScale;
FLOAT h = (ty2-ty1) * m_dwTexHeight / m_fTextScale;
- if( c != _T(' ') )
- {
+ if( c != _T(' ') ) {
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx1, ty2 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
@@ -778,8 +765,7 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
*pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
dwNumTriangles += 2;
- if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) )
- {
+ if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) ) {
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
@@ -794,8 +780,9 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
// Unlock and render the vertex buffer
m_pVB->Unlock();
- if( dwNumTriangles > 0 )
+ if( dwNumTriangles > 0 ) {
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
+ }
// Restore the modified renderstates
m_pStateBlockSaved->Apply();
@@ -812,8 +799,9 @@ HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
//-----------------------------------------------------------------------------
HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
{
- if( m_pd3dDevice == NULL )
+ if( m_pd3dDevice == NULL ) {
return E_FAIL;
+ }
// Setup renderstate
m_pStateBlockSaved->Capture();
@@ -823,8 +811,7 @@ HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
m_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(FONT3DVERTEX) );
// Set filter states
- if( dwFlags & D3DFONT_FILTERED )
- {
+ if( dwFlags & D3DFONT_FILTERED ) {
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
}
@@ -834,22 +821,21 @@ HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
FLOAT y = 0.0f;
// Center the text block at the origin (not the viewport)
- if( dwFlags & D3DFONT_CENTERED_X )
- {
+ if( dwFlags & D3DFONT_CENTERED_X ) {
SIZE sz;
GetTextExtent( strText, &sz );
x = -(((FLOAT)sz.cx)/10.0f)/2.0f;
}
- if( dwFlags & D3DFONT_CENTERED_Y )
- {
+ if( dwFlags & D3DFONT_CENTERED_Y ) {
SIZE sz;
GetTextExtent( strText, &sz );
y = -(((FLOAT)sz.cy)/10.0f)/2.0f;
}
// Turn off culling for two-sided text
- if( dwFlags & D3DFONT_TWOSIDED )
+ if( dwFlags & D3DFONT_TWOSIDED ) {
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
+ }
// Adjust for character spacing
x -= m_dwSpacing / 10.0f;
@@ -861,16 +847,15 @@ HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
DWORD dwNumTriangles = 0L;
m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );
- while( (c = *strText++) != 0 )
- {
- if( c == '\n' )
- {
+ while( (c = *strText++) != 0 ) {
+ if( c == '\n' ) {
x = fStartX;
y -= (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight/10.0f;
}
- if( (c-32) < 0 || (c-32) >= 128-32 )
+ if( (c-32) < 0 || (c-32) >= 128-32 ) {
continue;
+ }
FLOAT tx1 = m_fTexCoords[c-32][0];
FLOAT ty1 = m_fTexCoords[c-32][1];
@@ -880,8 +865,7 @@ HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
FLOAT w = (tx2-tx1) * m_dwTexWidth / ( 10.0f * m_fTextScale );
FLOAT h = (ty2-ty1) * m_dwTexHeight / ( 10.0f * m_fTextScale );
- if( c != _T(' ') )
- {
+ if( c != _T(' ') ) {
*pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+0,y+0,0), D3DXVECTOR3(0,0,-1), tx1, ty2 );
*pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+0,y+h,0), D3DXVECTOR3(0,0,-1), tx1, ty1 );
*pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+w,y+0,0), D3DXVECTOR3(0,0,-1), tx2, ty2 );
@@ -890,8 +874,7 @@ HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
*pVertices++ = InitFont3DVertex( D3DXVECTOR3(x+0,y+h,0), D3DXVECTOR3(0,0,-1), tx1, ty1 );
dwNumTriangles += 2;
- if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) )
- {
+ if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) ) {
// Unlock, render, and relock the vertex buffer
m_pVB->Unlock();
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
@@ -905,8 +888,9 @@ HRESULT CD3DFont::Render3DText( const TCHAR* strText, DWORD dwFlags )
// Unlock and render the vertex buffer
m_pVB->Unlock();
- if( dwNumTriangles > 0 )
+ if( dwNumTriangles > 0 ) {
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
+ }
// Restore the modified renderstates
m_pStateBlockSaved->Apply();
diff --git a/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp
index a57bdcca6..c3fed705f 100644
--- a/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.cpp
@@ -34,37 +34,35 @@ using namespace DSObjects;
static HRESULT TextureBlt(IDirect3DDevice7* pD3DDev, IDirectDrawSurface7* pTexture, Vector dst[4], CRect src)
{
- if(!pTexture)
+ if(!pTexture) {
return E_POINTER;
+ }
ASSERT(pD3DDev);
HRESULT hr;
- do
- {
+ do {
DDSURFACEDESC2 ddsd;
INITDDSTRUCT(ddsd);
- if(FAILED(hr = pTexture->GetSurfaceDesc(&ddsd)))
+ if(FAILED(hr = pTexture->GetSurfaceDesc(&ddsd))) {
break;
+ }
float w = (float)ddsd.dwWidth;
float h = (float)ddsd.dwHeight;
- struct
- {
+ struct {
float x, y, z, rhw;
float tu, tv;
}
- pVertices[] =
- {
+ pVertices[] = {
{(float)dst[0].x, (float)dst[0].y, (float)dst[0].z, 1.0f/(float)dst[0].z, (float)src.left / w, (float)src.top / h},
{(float)dst[1].x, (float)dst[1].y, (float)dst[1].z, 1.0f/(float)dst[1].z, (float)src.right / w, (float)src.top / h},
{(float)dst[2].x, (float)dst[2].y, (float)dst[2].z, 1.0f/(float)dst[2].z, (float)src.left / w, (float)src.bottom / h},
{(float)dst[3].x, (float)dst[3].y, (float)dst[3].z, 1.0f/(float)dst[3].z, (float)src.right / w, (float)src.bottom / h},
};
- for(int i = 0; i < countof(pVertices); i++)
- {
+ for(int i = 0; i < countof(pVertices); i++) {
pVertices[i].x -= 0.5;
pVertices[i].y -= 0.5;
}
@@ -84,8 +82,9 @@ static HRESULT TextureBlt(IDirect3DDevice7* pD3DDev, IDirectDrawSurface7* pTextu
//
- if(FAILED(hr = pD3DDev->BeginScene()))
+ if(FAILED(hr = pD3DDev->BeginScene())) {
break;
+ }
hr = pD3DDev->DrawPrimitive(D3DPT_TRIANGLESTRIP,
D3DFVF_XYZRHW | D3DFVF_TEX1,
@@ -97,8 +96,7 @@ static HRESULT TextureBlt(IDirect3DDevice7* pD3DDev, IDirectDrawSurface7* pTextu
pD3DDev->SetTexture(0, NULL);
return S_OK;
- }
- while(0);
+ } while(0);
return E_FAIL;
}
@@ -114,32 +112,34 @@ CDX7AllocatorPresenter::CDX7AllocatorPresenter(HWND hWnd, HRESULT& hr)
: CSubPicAllocatorPresenterImpl(hWnd, hr, NULL)
, m_ScreenSize(0, 0)
{
- if(FAILED(hr)) return;
+ if(FAILED(hr)) {
+ return;
+ }
DirectDrawCreateExPtr pDirectDrawCreateEx = NULL;
HMODULE hDDrawLib = NULL;
hDDrawLib = LoadLibrary (_T("ddraw.dll"));
- if (hDDrawLib) pDirectDrawCreateEx = (DirectDrawCreateExPtr)GetProcAddress (hDDrawLib, "DirectDrawCreateEx");
- if (pDirectDrawCreateEx == NULL)
- {
+ if (hDDrawLib) {
+ pDirectDrawCreateEx = (DirectDrawCreateExPtr)GetProcAddress (hDDrawLib, "DirectDrawCreateEx");
+ }
+ if (pDirectDrawCreateEx == NULL) {
hr = E_FAIL;
return;
}
if(FAILED(hr = pDirectDrawCreateEx(NULL, (VOID**)&m_pDD, IID_IDirectDraw7, NULL))
- || FAILED(hr = m_pDD->SetCooperativeLevel(AfxGetMainWnd()->GetSafeHwnd(), DDSCL_NORMAL)))
+ || FAILED(hr = m_pDD->SetCooperativeLevel(AfxGetMainWnd()->GetSafeHwnd(), DDSCL_NORMAL))) {
return;
+ }
- if(!(m_pD3D = m_pDD))
- {
+ if(!(m_pD3D = m_pDD)) {
hr = E_NOINTERFACE;
return;
}
hr = CreateDevice();
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
TRACE("CreateDevice failed: 0x%08x\n", (LONG)hr);
}
}
@@ -154,8 +154,9 @@ HRESULT CDX7AllocatorPresenter::CreateDevice()
DDSURFACEDESC2 ddsd;
INITDDSTRUCT(ddsd);
if(FAILED(m_pDD->GetDisplayMode(&ddsd)) ||
- ddsd.ddpfPixelFormat.dwRGBBitCount <= 8)
+ ddsd.ddpfPixelFormat.dwRGBBitCount <= 8) {
return DDERR_INVALIDMODE;
+ }
m_ScreenSize.SetSize(ddsd.dwWidth, ddsd.dwHeight);
@@ -166,12 +167,14 @@ HRESULT CDX7AllocatorPresenter::CreateDevice()
INITDDSTRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
- if(FAILED(hr = m_pDD->CreateSurface(&ddsd, &m_pPrimary, NULL)))
+ if(FAILED(hr = m_pDD->CreateSurface(&ddsd, &m_pPrimary, NULL))) {
return hr;
+ }
CComPtr<IDirectDrawClipper> pcClipper;
- if(FAILED(hr = m_pDD->CreateClipper(0, &pcClipper, NULL)))
+ if(FAILED(hr = m_pDD->CreateClipper(0, &pcClipper, NULL))) {
return hr;
+ }
pcClipper->SetHWnd(0, m_hWnd);
m_pPrimary->SetClipper(pcClipper);
@@ -182,12 +185,14 @@ HRESULT CDX7AllocatorPresenter::CreateDevice()
ddsd.ddsCaps.dwCaps = /*DDSCAPS_OFFSCREENPLAIN |*/ DDSCAPS_VIDEOMEMORY | DDSCAPS_3DDEVICE;
ddsd.dwWidth = m_ScreenSize.cx;
ddsd.dwHeight = m_ScreenSize.cy;
- if(FAILED(hr = m_pDD->CreateSurface(&ddsd, &m_pBackBuffer, NULL)))
+ if(FAILED(hr = m_pDD->CreateSurface(&ddsd, &m_pBackBuffer, NULL))) {
return hr;
+ }
pcClipper = NULL;
- if(FAILED(hr = m_pDD->CreateClipper(0, &pcClipper, NULL)))
+ if(FAILED(hr = m_pDD->CreateClipper(0, &pcClipper, NULL))) {
return hr;
+ }
BYTE rgnDataBuffer[1024];
HRGN hrgn = CreateRectRgn(0, 0, ddsd.dwWidth, ddsd.dwHeight);
GetRegionData(hrgn, sizeof(rgnDataBuffer), (RGNDATA*)rgnDataBuffer);
@@ -197,69 +202,72 @@ HRESULT CDX7AllocatorPresenter::CreateDevice()
// m_pD3DDev
- if(FAILED(hr = m_pD3D->CreateDevice(IID_IDirect3DHALDevice, m_pBackBuffer, &m_pD3DDev))) // this seems to fail if the desktop size is too large (width or height >2048)
+ if(FAILED(hr = m_pD3D->CreateDevice(IID_IDirect3DHALDevice, m_pBackBuffer, &m_pD3DDev))) { // this seems to fail if the desktop size is too large (width or height >2048)
return hr;
+ }
//
CComPtr<ISubPicProvider> pSubPicProvider;
- if(m_pSubPicQueue) m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
+ if(m_pSubPicQueue) {
+ m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
+ }
CSize size;
- switch(GetRenderersSettings().nSPCMaxRes)
- {
- case 0:
- default:
- size = m_ScreenSize;
- break;
- case 1:
- size.SetSize(1024, 768);
- break;
- case 2:
- size.SetSize(800, 600);
- break;
- case 3:
- size.SetSize(640, 480);
- break;
- case 4:
- size.SetSize(512, 384);
- break;
- case 5:
- size.SetSize(384, 288);
- break;
- case 6:
- size.SetSize(2560, 1600);
- break;
- case 7:
- size.SetSize(1920, 1080);
- break;
- case 8:
- size.SetSize(1320, 900);
- break;
- case 9:
- size.SetSize(1280, 720);
- break;
- }
-
- if(m_pAllocator)
- {
- m_pAllocator->ChangeDevice(m_pD3DDev);
+ switch(GetRenderersSettings().nSPCMaxRes) {
+ case 0:
+ default:
+ size = m_ScreenSize;
+ break;
+ case 1:
+ size.SetSize(1024, 768);
+ break;
+ case 2:
+ size.SetSize(800, 600);
+ break;
+ case 3:
+ size.SetSize(640, 480);
+ break;
+ case 4:
+ size.SetSize(512, 384);
+ break;
+ case 5:
+ size.SetSize(384, 288);
+ break;
+ case 6:
+ size.SetSize(2560, 1600);
+ break;
+ case 7:
+ size.SetSize(1920, 1080);
+ break;
+ case 8:
+ size.SetSize(1320, 900);
+ break;
+ case 9:
+ size.SetSize(1280, 720);
+ break;
}
- else
- {
+
+ if(m_pAllocator) {
+ m_pAllocator->ChangeDevice(m_pD3DDev);
+ } else {
m_pAllocator = DNew CDX7SubPicAllocator(m_pD3DDev, size, GetRenderersSettings().fSPCPow2Tex);
- if(!m_pAllocator || FAILED(hr))
+ if(!m_pAllocator || FAILED(hr)) {
return E_FAIL;
+ }
}
hr = S_OK;
m_pSubPicQueue = GetRenderersSettings().nSPCSize > 0
? (ISubPicQueue*)DNew CSubPicQueue(GetRenderersSettings().nSPCSize, !GetRenderersSettings().fSPCAllowAnimationWhenBuffering, m_pAllocator, &hr)
: (ISubPicQueue*)DNew CSubPicQueueNoThread(m_pAllocator, &hr);
- if(!m_pSubPicQueue || FAILED(hr))
+ if(!m_pSubPicQueue || FAILED(hr)) {
return E_FAIL;
+ }
- if(pSubPicProvider) m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ if(pSubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ }
return S_OK;
}
@@ -286,23 +294,20 @@ HRESULT CDX7AllocatorPresenter::AllocSurfaces()
ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00;
ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
- if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
- {
+ if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
ddsd.ddsCaps.dwCaps |= DDSCAPS_TEXTURE;
-// ddsd.ddpfPixelFormat.dwFlags |= DDPF_ALPHAPIXELS;
-// ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xFF000000;
+ // ddsd.ddpfPixelFormat.dwFlags |= DDPF_ALPHAPIXELS;
+ // ddsd.ddpfPixelFormat.dwRGBAlphaBitMask = 0xFF000000;
}
HRESULT hr = m_pDD->CreateSurface(&ddsd, &m_pVideoSurface, NULL);
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
// FIXME: eh, dx9 has no problem creating a 32bpp surface under a 16bpp desktop, but dx7 fails here (textures are ok)
DDSURFACEDESC2 ddsd2;
INITDDSTRUCT(ddsd2);
if(!(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
&& SUCCEEDED(m_pDD->GetDisplayMode(&ddsd2))
- && ddsd2.ddpfPixelFormat.dwRGBBitCount == 16)
- {
+ && ddsd2.ddpfPixelFormat.dwRGBBitCount == 16) {
ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
ddsd.ddpfPixelFormat.dwRBitMask = 0x0000F800;
ddsd.ddpfPixelFormat.dwGBitMask = 0x000007E0;
@@ -310,12 +315,14 @@ HRESULT CDX7AllocatorPresenter::AllocSurfaces()
hr = m_pDD->CreateSurface(&ddsd, &m_pVideoSurface, NULL);
}
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
}
- if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
+ if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
m_pVideoTexture = m_pVideoSurface;
+ }
DDBLTFX fx;
INITDDSTRUCT(fx);
@@ -342,8 +349,7 @@ STDMETHODIMP CDX7AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool fAll)
{
- if (m_bPendingResetDevice)
- {
+ if (m_bPendingResetDevice) {
SendResetRequest();
return false;
}
@@ -352,8 +358,9 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool fAll)
if(m_WindowRect.right <= m_WindowRect.left || m_WindowRect.bottom <= m_WindowRect.top
|| m_NativeVideoSize.cx <= 0 || m_NativeVideoSize.cy <= 0
- || !m_pPrimary || !m_pBackBuffer || !m_pVideoSurface)
+ || !m_pPrimary || !m_pBackBuffer || !m_pVideoSurface) {
return(false);
+ }
HRESULT hr;
@@ -364,8 +371,7 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool fAll)
CRect rDstPri(m_WindowRect);
MapWindowRect(m_hWnd, HWND_DESKTOP, &rDstPri);
- if(fAll)
- {
+ if(fAll) {
// clear the backbuffer
CRect rl(0, 0, rDstVid.left, rSrcPri.bottom);
@@ -380,16 +386,12 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool fAll)
// paint the video on the backbuffer
- if(!rDstVid.IsRectEmpty())
- {
- if(m_pVideoTexture)
- {
+ if(!rDstVid.IsRectEmpty()) {
+ if(m_pVideoTexture) {
Vector v[4];
Transform(rDstVid, v);
hr = TextureBlt(m_pD3DDev, m_pVideoTexture, v, rSrcVid);
- }
- else
- {
+ } else {
hr = m_pBackBuffer->Blt(rDstVid, m_pVideoSurface, rSrcVid, DDBLT_WAIT, NULL);
}
}
@@ -407,8 +409,7 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool fAll)
hr = m_pPrimary->Blt(rDstPri, m_pBackBuffer, rSrcPri, DDBLT_WAIT, NULL);
- if(hr == DDERR_SURFACELOST)
- {
+ if(hr == DDERR_SURFACELOST) {
m_bPendingResetDevice = true;
SendResetRequest();
return false;
@@ -419,8 +420,7 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::Paint(bool fAll)
void CDX7AllocatorPresenter::SendResetRequest()
{
- if (!m_bDeviceResetRequested)
- {
+ if (!m_bDeviceResetRequested) {
m_bDeviceResetRequested = true;
AfxGetApp()->m_pMainWnd->PostMessage(WM_RESET_DEVICE);
}
@@ -430,8 +430,7 @@ STDMETHODIMP_(bool) CDX7AllocatorPresenter::ResetDevice()
{
HRESULT hr;
DeleteSurfaces();
- if(FAILED(hr = CreateDevice()) || FAILED(hr = AllocSurfaces()))
- {
+ if(FAILED(hr = CreateDevice()) || FAILED(hr = AllocSurfaces())) {
//DDERR_UNSUPPORTEDMODE - 0x8876024e
TRACE("ResetDevice failed: 0x%08x\n", (LONG)hr);
m_bDeviceResetRequested = false;
@@ -451,24 +450,26 @@ STDMETHODIMP CDX7AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
DDSURFACEDESC2 ddsd;
INITDDSTRUCT(ddsd);
- if(FAILED(m_pVideoSurface->GetSurfaceDesc(&ddsd)))
+ if(FAILED(m_pVideoSurface->GetSurfaceDesc(&ddsd))) {
return E_FAIL;
+ }
- if(ddsd.ddpfPixelFormat.dwRGBBitCount != 16 && ddsd.ddpfPixelFormat.dwRGBBitCount != 32)
+ if(ddsd.ddpfPixelFormat.dwRGBBitCount != 16 && ddsd.ddpfPixelFormat.dwRGBBitCount != 32) {
return E_FAIL;
+ }
DWORD required = sizeof(BITMAPINFOHEADER) + (ddsd.dwWidth*ddsd.dwHeight*32>>3);
- if(!lpDib)
- {
+ if(!lpDib) {
*size = required;
return S_OK;
}
- if(*size < required) return E_OUTOFMEMORY;
+ if(*size < required) {
+ return E_OUTOFMEMORY;
+ }
*size = required;
INITDDSTRUCT(ddsd);
- if(FAILED(hr = m_pVideoSurface->Lock(NULL, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_READONLY|DDLOCK_NOSYSLOCK, NULL)))
- {
+ if(FAILED(hr = m_pVideoSurface->Lock(NULL, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_READONLY|DDLOCK_NOSYSLOCK, NULL))) {
// TODO
return hr;
}
diff --git a/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.h
index d2afff38f..a98438695 100644
--- a/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/DX7AllocatorPresenter.h
@@ -31,35 +31,35 @@
namespace DSObjects
{
-class CDX7AllocatorPresenter
- : public CSubPicAllocatorPresenterImpl
-{
-protected:
- CSize m_ScreenSize;
+ class CDX7AllocatorPresenter
+ : public CSubPicAllocatorPresenterImpl
+ {
+ protected:
+ CSize m_ScreenSize;
- CComPtr<IDirectDraw7> m_pDD;
- CComQIPtr<IDirect3D7, &IID_IDirect3D7> m_pD3D;
- CComPtr<IDirect3DDevice7> m_pD3DDev;
+ CComPtr<IDirectDraw7> m_pDD;
+ CComQIPtr<IDirect3D7, &IID_IDirect3D7> m_pD3D;
+ CComPtr<IDirect3DDevice7> m_pD3DDev;
- CComPtr<IDirectDrawSurface7> m_pPrimary;
- CComPtr<IDirectDrawSurface7> m_pBackBuffer;
- CComPtr<IDirectDrawSurface7> m_pVideoTexture;
- CComPtr<IDirectDrawSurface7> m_pVideoSurface;
+ CComPtr<IDirectDrawSurface7> m_pPrimary;
+ CComPtr<IDirectDrawSurface7> m_pBackBuffer;
+ CComPtr<IDirectDrawSurface7> m_pVideoTexture;
+ CComPtr<IDirectDrawSurface7> m_pVideoSurface;
- virtual HRESULT CreateDevice();
- virtual HRESULT AllocSurfaces();
- virtual void DeleteSurfaces();
+ virtual HRESULT CreateDevice();
+ virtual HRESULT AllocSurfaces();
+ virtual void DeleteSurfaces();
- void SendResetRequest();
+ void SendResetRequest();
-public:
- CDX7AllocatorPresenter(HWND hWnd, HRESULT& hr);
+ public:
+ CDX7AllocatorPresenter(HWND hWnd, HRESULT& hr);
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
- STDMETHODIMP_(bool) ResetDevice();
-};
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
+ STDMETHODIMP_(bool) ResetDevice();
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp
index e8eaee177..8844f2bb5 100644
--- a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.cpp
@@ -73,8 +73,7 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
{
HINSTANCE hDll;
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
_Error += L"ISubPicAllocatorPresenterImpl failed\n";
return;
}
@@ -84,15 +83,12 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
m_pD3DXCreateFont = NULL;
m_pD3DXCreateSprite = NULL;
hDll = GetRenderersData()->GetD3X9Dll();
- if(hDll)
- {
+ if(hDll) {
(FARPROC&)m_pD3DXLoadSurfaceFromMemory = GetProcAddress(hDll, "D3DXLoadSurfaceFromMemory");
(FARPROC&)m_pD3DXCreateLine = GetProcAddress(hDll, "D3DXCreateLine");
(FARPROC&)m_pD3DXCreateFont = GetProcAddress(hDll, "D3DXCreateFontW");
(FARPROC&)m_pD3DXCreateSprite = GetProcAddress(hDll, "D3DXCreateSprite");
- }
- else
- {
+ } else {
_Error += L"The installed DirectX End-User Runtime is outdated. Please download and install the ";
_Error += DIRECTX_SDK_DATE;
_Error += L" release or newer in order for MPC-HC to function properly.\n";
@@ -101,8 +97,7 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
m_pDwmIsCompositionEnabled = NULL;
m_pDwmEnableComposition = NULL;
m_hDWMAPI = LoadLibrary(L"dwmapi.dll");
- if (m_hDWMAPI)
- {
+ if (m_hDWMAPI) {
(FARPROC &)m_pDwmIsCompositionEnabled = GetProcAddress(m_hDWMAPI, "DwmIsCompositionEnabled");
(FARPROC &)m_pDwmEnableComposition = GetProcAddress(m_hDWMAPI, "DwmEnableComposition");
}
@@ -110,24 +105,25 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
m_pDirect3DCreate9Ex = NULL;
m_hD3D9 = LoadLibrary(L"d3d9.dll");
#ifndef DISABLE_USING_D3D9EX
- if (m_hD3D9)
+ if (m_hD3D9) {
(FARPROC &)m_pDirect3DCreate9Ex = GetProcAddress(m_hD3D9, "Direct3DCreate9Ex");
+ }
#endif
- if (m_pDirect3DCreate9Ex)
- {
+ if (m_pDirect3DCreate9Ex) {
m_pDirect3DCreate9Ex(D3D_SDK_VERSION, &m_pD3DEx);
- if(!m_pD3DEx)
+ if(!m_pD3DEx) {
m_pDirect3DCreate9Ex(D3D9b_SDK_VERSION, &m_pD3DEx);
+ }
}
- if(!m_pD3DEx)
- {
+ if(!m_pD3DEx) {
m_pD3D.Attach(Direct3DCreate9(D3D_SDK_VERSION));
- if(!m_pD3D)
+ if(!m_pD3D) {
m_pD3D.Attach(Direct3DCreate9(D3D9b_SDK_VERSION));
- }
- else
+ }
+ } else {
m_pD3D = m_pD3DEx;
+ }
m_DetectedFrameRate = 0.0;
m_DetectedFrameTime = 0.0;
@@ -147,14 +143,12 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
m_DetectedRefreshRate = 0;
CRenderersSettings& s = GetRenderersSettings();
- if (s.m_RenderSettings.iVMRDisableDesktopComposition)
- {
+ if (s.m_RenderSettings.iVMRDisableDesktopComposition) {
m_bDesktopCompositionDisabled = true;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(0);
- }
- else
- {
+ }
+ } else {
m_bDesktopCompositionDisabled = false;
}
@@ -174,11 +168,11 @@ CDX9AllocatorPresenter::CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
CDX9AllocatorPresenter::~CDX9AllocatorPresenter()
{
- if (m_bDesktopCompositionDisabled)
- {
+ if (m_bDesktopCompositionDisabled) {
m_bDesktopCompositionDisabled = false;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(1);
+ }
}
StopWorkerThreads();
@@ -191,13 +185,11 @@ CDX9AllocatorPresenter::~CDX9AllocatorPresenter()
m_pD3D = NULL;
m_pD3DEx = NULL;
- if (m_hDWMAPI)
- {
+ if (m_hDWMAPI) {
FreeLibrary(m_hDWMAPI);
m_hDWMAPI = NULL;
}
- if (m_hD3D9)
- {
+ if (m_hD3D9) {
FreeLibrary(m_hD3D9);
m_hD3D9 = NULL;
}
@@ -210,42 +202,37 @@ class CRandom31
{
public:
- CRandom31()
- {
+ CRandom31() {
m_Seed = 12164;
}
- void f_SetSeed(int32 _Seed)
- {
+ void f_SetSeed(int32 _Seed) {
m_Seed = _Seed;
}
- int32 f_GetSeed()
- {
+ int32 f_GetSeed() {
return m_Seed;
}
/*
Park and Miller's psuedo-random number generator.
*/
int32 m_Seed;
- int32 f_Get()
- {
+ int32 f_Get() {
static const int32 A = 16807;
static const int32 M = 2147483647; // 2^31 - 1
static const int32 q = M / A; // M / A
static const int32 r = M % A; // M % A
m_Seed = A * (m_Seed % q) - r * (m_Seed / q);
- if (m_Seed < 0)
+ if (m_Seed < 0) {
m_Seed += M;
+ }
return m_Seed;
}
- static int32 fs_Max()
- {
+ static int32 fs_Max() {
return 2147483646;
}
- double f_GetFloat()
- {
+ double f_GetFloat() {
return double(f_Get()) * (1.0 / double(fs_Max()));
}
};
@@ -256,8 +243,7 @@ private:
class CHistoryEntry
{
public:
- CHistoryEntry()
- {
+ CHistoryEntry() {
m_Time = 0;
m_ScanLine = -1;
}
@@ -268,8 +254,7 @@ private:
class CSolution
{
public:
- CSolution()
- {
+ CSolution() {
m_ScanLines = 1000;
m_ScanLinesPerSecond = m_ScanLines * 100;
}
@@ -277,47 +262,46 @@ private:
double m_ScanLinesPerSecond;
double m_SqrSum;
- void f_Mutate(double _Amount, CRandom31 &_Random, int _MinScans)
- {
+ void f_Mutate(double _Amount, CRandom31 &_Random, int _MinScans) {
int ToDo = _Random.f_Get() % 10;
- if (ToDo == 0)
+ if (ToDo == 0) {
m_ScanLines = m_ScanLines / 2;
- else if (ToDo == 1)
+ } else if (ToDo == 1) {
m_ScanLines = m_ScanLines * 2;
+ }
m_ScanLines = m_ScanLines * (1.0 + (_Random.f_GetFloat() * _Amount) - _Amount * 0.5);
m_ScanLines = max(m_ScanLines, _MinScans);
- if (ToDo == 2)
+ if (ToDo == 2) {
m_ScanLinesPerSecond /= (_Random.f_Get() % 4) + 1;
- else if (ToDo == 3)
+ } else if (ToDo == 3) {
m_ScanLinesPerSecond *= (_Random.f_Get() % 4) + 1;
+ }
m_ScanLinesPerSecond *= 1.0 + (_Random.f_GetFloat() * _Amount) - _Amount * 0.5;
}
- void f_SpawnInto(CSolution &_Other, CRandom31 &_Random, int _MinScans)
- {
+ void f_SpawnInto(CSolution &_Other, CRandom31 &_Random, int _MinScans) {
_Other = *this;
_Other.f_Mutate(_Random.f_GetFloat() * 0.1, _Random, _MinScans);
}
- static int fs_Compare(const void *_pFirst, const void *_pSecond)
- {
+ static int fs_Compare(const void *_pFirst, const void *_pSecond) {
const CSolution *pFirst = (const CSolution *)_pFirst;
const CSolution *pSecond = (const CSolution *)_pSecond;
- if (pFirst->m_SqrSum < pSecond->m_SqrSum)
+ if (pFirst->m_SqrSum < pSecond->m_SqrSum) {
return -1;
- else if (pFirst->m_SqrSum > pSecond->m_SqrSum)
+ } else if (pFirst->m_SqrSum > pSecond->m_SqrSum) {
return 1;
+ }
return 0;
}
};
- enum
- {
+ enum {
ENumHistory = 128
};
@@ -328,19 +312,19 @@ private:
CRandom31 m_Random;
- double fp_GetSquareSum(double _ScansPerSecond, double _ScanLines)
- {
+ double fp_GetSquareSum(double _ScansPerSecond, double _ScanLines) {
double SquareSum = 0;
int nHistory = min(m_nHistory, ENumHistory);
int iHistory = m_iHistory - nHistory;
- if (iHistory < 0)
+ if (iHistory < 0) {
iHistory += ENumHistory;
- for (int i = 1; i < nHistory; ++i)
- {
+ }
+ for (int i = 1; i < nHistory; ++i) {
int iHistory0 = iHistory + i - 1;
int iHistory1 = iHistory + i;
- if (iHistory0 < 0)
+ if (iHistory0 < 0) {
iHistory0 += ENumHistory;
+ }
iHistory0 = iHistory0 % ENumHistory;
iHistory1 = iHistory1 % ENumHistory;
ASSERT(m_History[iHistory0].m_Time != 0);
@@ -359,31 +343,26 @@ private:
int m_nHistory;
public:
- CVSyncEstimation()
- {
+ CVSyncEstimation() {
m_iHistory = 0;
m_nHistory = 0;
}
- void f_AddSample(int _ScanLine, LONGLONG _Time)
- {
+ void f_AddSample(int _ScanLine, LONGLONG _Time) {
m_History[m_iHistory].m_ScanLine = _ScanLine;
m_History[m_iHistory].m_Time = _Time;
++m_nHistory;
m_iHistory = (m_iHistory + 1) % ENumHistory;
}
- void f_GetEstimation(double &_RefreshRate, int &_ScanLines, int _ScreenSizeY, int _WindowsRefreshRate)
- {
+ void f_GetEstimation(double &_RefreshRate, int &_ScanLines, int _ScreenSizeY, int _WindowsRefreshRate) {
_RefreshRate = 0;
_ScanLines = 0;
int iHistory = m_iHistory;
// We have a full history
- if (m_nHistory > 10)
- {
- for (int l = 0; l < 5; ++l)
- {
+ if (m_nHistory > 10) {
+ for (int l = 0; l < 5; ++l) {
const int nSol = 3+5+5+3;
CSolution Solutions[nSol];
@@ -393,31 +372,35 @@ public:
Solutions[2].m_ScanLinesPerSecond = _ScreenSizeY * _WindowsRefreshRate;
int iStart = 3;
- for (int i = iStart; i < iStart + 5; ++i)
+ for (int i = iStart; i < iStart + 5; ++i) {
Solutions[0].f_SpawnInto(Solutions[i], m_Random, _ScreenSizeY);
+ }
iStart += 5;
- for (int i = iStart; i < iStart + 5; ++i)
+ for (int i = iStart; i < iStart + 5; ++i) {
Solutions[1].f_SpawnInto(Solutions[i], m_Random, _ScreenSizeY);
+ }
iStart += 5;
- for (int i = iStart; i < iStart + 3; ++i)
+ for (int i = iStart; i < iStart + 3; ++i) {
Solutions[2].f_SpawnInto(Solutions[i], m_Random, _ScreenSizeY);
+ }
int Start = 2;
- if (l == 0)
+ if (l == 0) {
Start = 0;
- for (int i = Start; i < nSol; ++i)
+ }
+ for (int i = Start; i < nSol; ++i) {
Solutions[i].m_SqrSum = fp_GetSquareSum(Solutions[i].m_ScanLinesPerSecond, Solutions[i].m_ScanLines);
+ }
qsort(Solutions, nSol, sizeof(Solutions[0]), &CSolution::fs_Compare);
- for (int i = 0; i < 2; ++i)
+ for (int i = 0; i < 2; ++i) {
m_OldSolutions[i] = Solutions[i];
+ }
}
_ScanLines = m_OldSolutions[0].m_ScanLines + 0.5;
_RefreshRate = 1.0 / (m_OldSolutions[0].m_ScanLines / m_OldSolutions[0].m_ScanLinesPerSecond);
- }
- else
- {
+ } else {
m_OldSolutions[0].m_ScanLines = _ScreenSizeY;
m_OldSolutions[1].m_ScanLines = _ScreenSizeY;
}
@@ -449,152 +432,140 @@ void CDX9AllocatorPresenter::VSyncThread()
CRenderersData *pApp = GetRenderersData();
CRenderersSettings& s = GetRenderersSettings();
- while (!bQuit)
- {
+ while (!bQuit) {
DWORD dwObject = WaitForMultipleObjects (countof(hEvts), hEvts, FALSE, 1);
- switch (dwObject)
- {
- case WAIT_OBJECT_0 :
- bQuit = true;
- break;
- case WAIT_TIMEOUT :
- {
- // Do our stuff
- if (m_pD3DDev && s.m_RenderSettings.iVMR9VSync)
- {
+ switch (dwObject) {
+ case WAIT_OBJECT_0 :
+ bQuit = true;
+ break;
+ case WAIT_TIMEOUT : {
+ // Do our stuff
+ if (m_pD3DDev && s.m_RenderSettings.iVMR9VSync) {
- int VSyncPos = GetVBlackPos();
- int WaitRange = max(m_ScreenSize.cy / 40, 5);
- int MinRange = max(min(int(0.003 * double(m_ScreenSize.cy) * double(m_RefreshRate) + 0.5), m_ScreenSize.cy/3), 5); // 1.8 ms or max 33 % of Time
-
- VSyncPos += MinRange + WaitRange;
-
- VSyncPos = VSyncPos % m_ScreenSize.cy;
- if (VSyncPos < 0)
- VSyncPos += m_ScreenSize.cy;
-
- int ScanLine = 0;
- int StartScanLine = ScanLine;
- UNUSED_ALWAYS(StartScanLine);
- int LastPos = ScanLine;
- UNUSED_ALWAYS(LastPos);
- ScanLine = (VSyncPos + 1) % m_ScreenSize.cy;
- if (ScanLine < 0)
- ScanLine += m_ScreenSize.cy;
- int ScanLineMiddle = ScanLine + m_ScreenSize.cy/2;
- ScanLineMiddle = ScanLineMiddle % m_ScreenSize.cy;
- if (ScanLineMiddle < 0)
- ScanLineMiddle += m_ScreenSize.cy;
-
- int ScanlineStart = ScanLine;
- bool bTakenLock;
- WaitForVBlankRange(ScanlineStart, 5, true, true, false, bTakenLock);
- LONGLONG TimeStart = pApp->GetPerfCounter();
-
- WaitForVBlankRange(ScanLineMiddle, 5, true, true, false, bTakenLock);
- LONGLONG TimeMiddle = pApp->GetPerfCounter();
-
- int ScanlineEnd = ScanLine;
- WaitForVBlankRange(ScanlineEnd, 5, true, true, false, bTakenLock);
- LONGLONG TimeEnd = pApp->GetPerfCounter();
-
- double nSeconds = double(TimeEnd - TimeStart) / 10000000.0;
- LONGLONG DiffMiddle = TimeMiddle - TimeStart;
- LONGLONG DiffEnd = TimeEnd - TimeMiddle;
- double DiffDiff;
- if (DiffEnd > DiffMiddle)
- DiffDiff = double(DiffEnd) / double(DiffMiddle);
- else
- DiffDiff = double(DiffMiddle) / double(DiffEnd);
- if (nSeconds > 0.003 && DiffDiff < 1.3)
- {
- double ScanLineSeconds;
- double nScanLines;
- if (ScanLineMiddle > ScanlineEnd)
- {
- ScanLineSeconds = double(TimeMiddle - TimeStart) / 10000000.0;
- nScanLines = ScanLineMiddle - ScanlineStart;
- }
- else
- {
- ScanLineSeconds = double(TimeEnd - TimeMiddle) / 10000000.0;
- nScanLines = ScanlineEnd - ScanLineMiddle;
- }
+ int VSyncPos = GetVBlackPos();
+ int WaitRange = max(m_ScreenSize.cy / 40, 5);
+ int MinRange = max(min(int(0.003 * double(m_ScreenSize.cy) * double(m_RefreshRate) + 0.5), m_ScreenSize.cy/3), 5); // 1.8 ms or max 33 % of Time
- double ScanLineTime = ScanLineSeconds / nScanLines;
+ VSyncPos += MinRange + WaitRange;
- int iPos = m_DetectedRefreshRatePos % 100;
- m_ldDetectedScanlineRateList[iPos] = ScanLineTime;
- if (m_DetectedScanlineTime && ScanlineStart != ScanlineEnd)
- {
- int Diff = ScanlineEnd - ScanlineStart;
- nSeconds -= double(Diff) * m_DetectedScanlineTime;
- }
- m_ldDetectedRefreshRateList[iPos] = nSeconds;
- double Average = 0;
- double AverageScanline = 0;
- int nPos = min(iPos + 1, 100);
- for (int i = 0; i < nPos; ++i)
- {
- Average += m_ldDetectedRefreshRateList[i];
- AverageScanline += m_ldDetectedScanlineRateList[i];
+ VSyncPos = VSyncPos % m_ScreenSize.cy;
+ if (VSyncPos < 0) {
+ VSyncPos += m_ScreenSize.cy;
}
- if (nPos)
- {
- Average /= double(nPos);
- AverageScanline /= double(nPos);
+ int ScanLine = 0;
+ int StartScanLine = ScanLine;
+ UNUSED_ALWAYS(StartScanLine);
+ int LastPos = ScanLine;
+ UNUSED_ALWAYS(LastPos);
+ ScanLine = (VSyncPos + 1) % m_ScreenSize.cy;
+ if (ScanLine < 0) {
+ ScanLine += m_ScreenSize.cy;
}
- else
- {
- Average = 0;
- AverageScanline = 0;
+ int ScanLineMiddle = ScanLine + m_ScreenSize.cy/2;
+ ScanLineMiddle = ScanLineMiddle % m_ScreenSize.cy;
+ if (ScanLineMiddle < 0) {
+ ScanLineMiddle += m_ScreenSize.cy;
}
- double ThisValue = Average;
+ int ScanlineStart = ScanLine;
+ bool bTakenLock;
+ WaitForVBlankRange(ScanlineStart, 5, true, true, false, bTakenLock);
+ LONGLONG TimeStart = pApp->GetPerfCounter();
+
+ WaitForVBlankRange(ScanLineMiddle, 5, true, true, false, bTakenLock);
+ LONGLONG TimeMiddle = pApp->GetPerfCounter();
+
+ int ScanlineEnd = ScanLine;
+ WaitForVBlankRange(ScanlineEnd, 5, true, true, false, bTakenLock);
+ LONGLONG TimeEnd = pApp->GetPerfCounter();
+
+ double nSeconds = double(TimeEnd - TimeStart) / 10000000.0;
+ LONGLONG DiffMiddle = TimeMiddle - TimeStart;
+ LONGLONG DiffEnd = TimeEnd - TimeMiddle;
+ double DiffDiff;
+ if (DiffEnd > DiffMiddle) {
+ DiffDiff = double(DiffEnd) / double(DiffMiddle);
+ } else {
+ DiffDiff = double(DiffMiddle) / double(DiffEnd);
+ }
+ if (nSeconds > 0.003 && DiffDiff < 1.3) {
+ double ScanLineSeconds;
+ double nScanLines;
+ if (ScanLineMiddle > ScanlineEnd) {
+ ScanLineSeconds = double(TimeMiddle - TimeStart) / 10000000.0;
+ nScanLines = ScanLineMiddle - ScanlineStart;
+ } else {
+ ScanLineSeconds = double(TimeEnd - TimeMiddle) / 10000000.0;
+ nScanLines = ScanlineEnd - ScanLineMiddle;
+ }
+
+ double ScanLineTime = ScanLineSeconds / nScanLines;
- if (Average > 0.0 && AverageScanline > 0.0)
- {
- CAutoLock Lock(&m_RefreshRateLock);
- ++m_DetectedRefreshRatePos;
- if (m_DetectedRefreshTime == 0 || m_DetectedRefreshTime / ThisValue > 1.01 || m_DetectedRefreshTime / ThisValue < 0.99)
- {
- m_DetectedRefreshTime = ThisValue;
- m_DetectedRefreshTimePrim = 0;
+ int iPos = m_DetectedRefreshRatePos % 100;
+ m_ldDetectedScanlineRateList[iPos] = ScanLineTime;
+ if (m_DetectedScanlineTime && ScanlineStart != ScanlineEnd) {
+ int Diff = ScanlineEnd - ScanlineStart;
+ nSeconds -= double(Diff) * m_DetectedScanlineTime;
}
- ModerateFloat(m_DetectedRefreshTime, ThisValue, m_DetectedRefreshTimePrim, 1.5);
- if (m_DetectedRefreshTime > 0.0)
- m_DetectedRefreshRate = 1.0/m_DetectedRefreshTime;
- else
- m_DetectedRefreshRate = 0.0;
-
- if (m_DetectedScanlineTime == 0 || m_DetectedScanlineTime / AverageScanline > 1.01 || m_DetectedScanlineTime / AverageScanline < 0.99)
- {
- m_DetectedScanlineTime = AverageScanline;
- m_DetectedScanlineTimePrim = 0;
+ m_ldDetectedRefreshRateList[iPos] = nSeconds;
+ double Average = 0;
+ double AverageScanline = 0;
+ int nPos = min(iPos + 1, 100);
+ for (int i = 0; i < nPos; ++i) {
+ Average += m_ldDetectedRefreshRateList[i];
+ AverageScanline += m_ldDetectedScanlineRateList[i];
}
- ModerateFloat(m_DetectedScanlineTime, AverageScanline, m_DetectedScanlineTimePrim, 1.5);
- if (m_DetectedScanlineTime > 0.0)
- m_DetectedScanlinesPerFrame = m_DetectedRefreshTime / m_DetectedScanlineTime;
- else
- m_DetectedScanlinesPerFrame = 0;
+
+ if (nPos) {
+ Average /= double(nPos);
+ AverageScanline /= double(nPos);
+ } else {
+ Average = 0;
+ AverageScanline = 0;
+ }
+
+ double ThisValue = Average;
+
+ if (Average > 0.0 && AverageScanline > 0.0) {
+ CAutoLock Lock(&m_RefreshRateLock);
+ ++m_DetectedRefreshRatePos;
+ if (m_DetectedRefreshTime == 0 || m_DetectedRefreshTime / ThisValue > 1.01 || m_DetectedRefreshTime / ThisValue < 0.99) {
+ m_DetectedRefreshTime = ThisValue;
+ m_DetectedRefreshTimePrim = 0;
+ }
+ ModerateFloat(m_DetectedRefreshTime, ThisValue, m_DetectedRefreshTimePrim, 1.5);
+ if (m_DetectedRefreshTime > 0.0) {
+ m_DetectedRefreshRate = 1.0/m_DetectedRefreshTime;
+ } else {
+ m_DetectedRefreshRate = 0.0;
+ }
+
+ if (m_DetectedScanlineTime == 0 || m_DetectedScanlineTime / AverageScanline > 1.01 || m_DetectedScanlineTime / AverageScanline < 0.99) {
+ m_DetectedScanlineTime = AverageScanline;
+ m_DetectedScanlineTimePrim = 0;
+ }
+ ModerateFloat(m_DetectedScanlineTime, AverageScanline, m_DetectedScanlineTimePrim, 1.5);
+ if (m_DetectedScanlineTime > 0.0) {
+ m_DetectedScanlinesPerFrame = m_DetectedRefreshTime / m_DetectedScanlineTime;
+ } else {
+ m_DetectedScanlinesPerFrame = 0;
+ }
+ }
+ //TRACE("Refresh: %f\n", RefreshRate);
}
- //TRACE("Refresh: %f\n", RefreshRate);
+ } else {
+ m_DetectedRefreshRate = 0.0;
+ m_DetectedScanlinesPerFrame = 0.0;
}
}
- else
- {
- m_DetectedRefreshRate = 0.0;
- m_DetectedScanlinesPerFrame = 0.0;
- }
- }
- break;
+ break;
}
}
timeEndPeriod (dwResolution);
-// if (pfAvRevertMmThreadCharacteristics) pfAvRevertMmThreadCharacteristics (hAvrt);
+ // if (pfAvRevertMmThreadCharacteristics) pfAvRevertMmThreadCharacteristics (hAvrt);
}
@@ -610,30 +581,25 @@ void CDX9AllocatorPresenter::StartWorkerThreads()
{
DWORD dwThreadId;
- if ( m_bIsEVR )
- {
+ if ( m_bIsEVR ) {
m_hEvtQuit = CreateEvent( NULL, TRUE, FALSE, NULL );
- if ( m_hEvtQuit != NULL ) // Don't create a thread with no stop switch
- {
+ if ( m_hEvtQuit != NULL ) { // Don't create a thread with no stop switch
m_hVSyncThread = ::CreateThread( NULL, 0, VSyncThreadStatic, (LPVOID)this, 0, &dwThreadId );
- if ( m_hVSyncThread != NULL )
+ if ( m_hVSyncThread != NULL ) {
SetThreadPriority( m_hVSyncThread, THREAD_PRIORITY_HIGHEST );
+ }
}
}
}
void CDX9AllocatorPresenter::StopWorkerThreads()
{
- if ( m_bIsEVR )
- {
- if ( m_hEvtQuit != NULL )
- {
+ if ( m_bIsEVR ) {
+ if ( m_hEvtQuit != NULL ) {
SetEvent( m_hEvtQuit );
- if ( m_hVSyncThread != NULL )
- {
- if ( WaitForSingleObject(m_hVSyncThread, 10000) == WAIT_TIMEOUT )
- {
+ if ( m_hVSyncThread != NULL ) {
+ if ( WaitForSingleObject(m_hVSyncThread, 10000) == WAIT_TIMEOUT ) {
ASSERT(FALSE);
TerminateThread( m_hVSyncThread, 0xDEAD );
}
@@ -659,34 +625,27 @@ bool CDX9AllocatorPresenter::SettingsNeedResetDevice()
bRet = bRet || New.fVMR9AlterativeVSync != Current.fVMR9AlterativeVSync;
bRet = bRet || New.iVMR9VSyncAccurate != Current.iVMR9VSyncAccurate;
- if (m_bIsFullscreen)
- {
+ if (m_bIsFullscreen) {
bRet = bRet || New.iVMR9FullscreenGUISupport != Current.iVMR9FullscreenGUISupport;
- }
- else
- {
- if (Current.iVMRDisableDesktopComposition)
- {
- if (!m_bDesktopCompositionDisabled)
- {
+ } else {
+ if (Current.iVMRDisableDesktopComposition) {
+ if (!m_bDesktopCompositionDisabled) {
m_bDesktopCompositionDisabled = true;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(0);
+ }
}
- }
- else
- {
- if (m_bDesktopCompositionDisabled)
- {
+ } else {
+ if (m_bDesktopCompositionDisabled) {
m_bDesktopCompositionDisabled = false;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(1);
+ }
}
}
}
- if (m_bIsEVR)
- {
+ if (m_bIsEVR) {
bRet = bRet || New.iEVRHighColorResolution != Current.iEVRHighColorResolution;
bRet = bRet || New.iEVRForceInputHighColorResolution != Current.iEVRForceInputHighColorResolution;
}
@@ -746,8 +705,7 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
CleanupRenderingEngine();
- if(!m_pD3D)
- {
+ if(!m_pD3D) {
_Error += L"Failed to create D3D9\n";
return E_UNEXPECTED;
}
@@ -790,17 +748,15 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
*/
-//#define ENABLE_DDRAWSYNC
+ //#define ENABLE_DDRAWSYNC
#ifdef ENABLE_DDRAWSYNC
hr = DirectDrawCreate(NULL, &m_pDirectDraw, NULL) ;
- if (hr == S_OK)
- {
+ if (hr == S_OK) {
hr = m_pDirectDraw->SetCooperativeLevel(m_hWnd, DDSCL_NORMAL) ;
}
#endif
- if (!SetCurrentDisplayMode())
- {
+ if (!SetCurrentDisplayMode()) {
_Error += L"GetAdapterDisplayMode failed\n";
return E_UNEXPECTED;
}
@@ -809,43 +765,41 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
ZeroMemory(&pp, sizeof(pp));
BOOL bCompositionEnabled = false;
- if (m_pDwmIsCompositionEnabled)
+ if (m_pDwmIsCompositionEnabled) {
m_pDwmIsCompositionEnabled(&bCompositionEnabled);
+ }
m_bCompositionEnabled = bCompositionEnabled != 0;
m_bAlternativeVSync = s.m_RenderSettings.fVMR9AlterativeVSync;
m_bHighColorResolution = s.m_RenderSettings.iEVRHighColorResolution && m_bIsEVR;
- if (m_bIsFullscreen)
- {
+ if (m_bIsFullscreen) {
pp.Windowed = false;
pp.BackBufferWidth = m_ScreenSize.cx;
pp.BackBufferHeight = m_ScreenSize.cy;
pp.hDeviceWindow = m_hWnd;
- if(m_bAlternativeVSync)
- {
+ if(m_bAlternativeVSync) {
pp.BackBufferCount = 3;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Ne pas mettre D3DSWAPEFFECT_COPY car cela entraine une desynchro audio sur les MKV ! // Copy needed for sync now? FLIP only stutters.
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- }
- else
- {
+ } else {
pp.BackBufferCount = 3;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Ne pas mettre D3DSWAPEFFECT_COPY car cela entraine une desynchro audio sur les MKV ! // Copy needed for sync now? FLIP only stutters.
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
pp.Flags = D3DPRESENTFLAG_VIDEO;
- if (s.m_RenderSettings.iVMR9FullscreenGUISupport && !m_bHighColorResolution)
+ if (s.m_RenderSettings.iVMR9FullscreenGUISupport && !m_bHighColorResolution) {
pp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
- if (m_bHighColorResolution)
+ }
+ if (m_bHighColorResolution) {
pp.BackBufferFormat = D3DFMT_A2R10G10B10;
- else
+ } else {
pp.BackBufferFormat = m_DisplayType;
+ }
m_D3DDevExError = L"No m_pD3DEx";
- if (m_pD3DEx)
- {
+ if (m_pD3DEx) {
D3DDISPLAYMODEEX DisplayMode;
ZeroMemory(&DisplayMode, sizeof(DisplayMode));
DisplayMode.Size = sizeof(DisplayMode);
@@ -861,35 +815,29 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
&pp, &DisplayMode, &m_pD3DDevEx);
m_D3DDevExError = GetWindowsErrorMessage(hr, m_hD3D9);
- if (m_pD3DDevEx)
- {
+ if (m_pD3DDevEx) {
m_pD3DDev = m_pD3DDevEx;
m_BackbufferType = pp.BackBufferFormat;
m_DisplayType = DisplayMode.Format;
}
}
- if (!m_pD3DDev)
- {
+ if (!m_pD3DDev) {
m_CurrentAdapter = GetAdapter(m_pD3D, true);
hr = m_pD3D->CreateDevice(
m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
GetVertexProcessing() | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED, //D3DCREATE_MANAGED
&pp, &m_pD3DDev);
- if (m_pD3DDev)
- {
+ if (m_pD3DDev) {
m_BackbufferType = pp.BackBufferFormat;
}
}
- if (m_pD3DDev && s.m_RenderSettings.iVMR9FullscreenGUISupport && !m_bHighColorResolution)
- {
+ if (m_pD3DDev && s.m_RenderSettings.iVMR9FullscreenGUISupport && !m_bHighColorResolution) {
m_pD3DDev->SetDialogBoxMode(true);
//if (m_pD3DDev->SetDialogBoxMode(true) != S_OK)
// ExitProcess(0);
}
- }
- else
- {
+ } else {
pp.Windowed = TRUE;
pp.hDeviceWindow = m_hWnd;
pp.SwapEffect = D3DSWAPEFFECT_COPY;
@@ -898,36 +846,30 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
pp.BackBufferWidth = m_ScreenSize.cx;
pp.BackBufferHeight = m_ScreenSize.cy;
m_BackbufferType = m_DisplayType;
- if (m_bHighColorResolution)
- {
+ if (m_bHighColorResolution) {
m_BackbufferType = D3DFMT_A2R10G10B10;
pp.BackBufferFormat = D3DFMT_A2R10G10B10;
}
- if (bCompositionEnabled || m_bAlternativeVSync)
- {
+ if (bCompositionEnabled || m_bAlternativeVSync) {
// Desktop composition takes care of the VSYNC
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- }
- else
- {
+ } else {
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
-// if(m_fVMRSyncFix = GetRenderersData()->m_s.fVMRSyncFix)
-// pp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
+ // if(m_fVMRSyncFix = GetRenderersData()->m_s.fVMRSyncFix)
+ // pp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
m_CurrentAdapter = GetAdapter(m_pD3D, true);
- if (m_pD3DEx)
- {
+ if (m_pD3DEx) {
hr = m_pD3DEx->CreateDeviceEx(
m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
GetVertexProcessing() | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED | D3DCREATE_ENABLE_PRESENTSTATS, //D3DCREATE_MANAGED
&pp, NULL, &m_pD3DDevEx);
- if (m_pD3DDevEx)
+ if (m_pD3DDevEx) {
m_pD3DDev = m_pD3DDevEx;
- }
- else
- {
+ }
+ } else {
hr = m_pD3D->CreateDevice(
m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
GetVertexProcessing() | D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED, //D3DCREATE_MANAGED
@@ -935,13 +877,11 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
}
}
- while(hr == D3DERR_DEVICELOST)
- {
+ while(hr == D3DERR_DEVICELOST) {
TRACE("D3DERR_DEVICELOST. Trying to Reset.\n");
hr = m_pD3DDev->TestCooperativeLevel();
}
- if (hr == D3DERR_DEVICENOTRESET)
- {
+ if (hr == D3DERR_DEVICENOTRESET) {
TRACE("D3DERR_DEVICENOTRESET\n");
hr = m_pD3DDev->Reset(&pp);
}
@@ -951,13 +891,11 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
m_MainThreadId = GetCurrentThreadId();
- if (m_pD3DDevEx)
- {
+ if (m_pD3DDevEx) {
m_pD3DDevEx->SetGPUThreadPriority(7);
}
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
_Error += L"CreateDevice failed\n";
return hr;
@@ -974,53 +912,50 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
m_bForceInputHighColorResolution = s.m_RenderSettings.iEVRForceInputHighColorResolution && m_bIsEVR && renderersData->m_b10bitSupport;
CComPtr<ISubPicProvider> pSubPicProvider;
- if(m_pSubPicQueue) m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
+ if(m_pSubPicQueue) {
+ m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
+ }
CSize size;
- switch(GetRenderersSettings().nSPCMaxRes)
- {
- case 0:
- default:
- size = m_ScreenSize;
- break;
- case 1:
- size.SetSize(1024, 768);
- break;
- case 2:
- size.SetSize(800, 600);
- break;
- case 3:
- size.SetSize(640, 480);
- break;
- case 4:
- size.SetSize(512, 384);
- break;
- case 5:
- size.SetSize(384, 288);
- break;
- case 6:
- size.SetSize(2560, 1600);
- break;
- case 7:
- size.SetSize(1920, 1080);
- break;
- case 8:
- size.SetSize(1320, 900);
- break;
- case 9:
- size.SetSize(1280, 720);
- break;
- }
-
- if(m_pAllocator)
- {
- m_pAllocator->ChangeDevice(m_pD3DDev);
+ switch(GetRenderersSettings().nSPCMaxRes) {
+ case 0:
+ default:
+ size = m_ScreenSize;
+ break;
+ case 1:
+ size.SetSize(1024, 768);
+ break;
+ case 2:
+ size.SetSize(800, 600);
+ break;
+ case 3:
+ size.SetSize(640, 480);
+ break;
+ case 4:
+ size.SetSize(512, 384);
+ break;
+ case 5:
+ size.SetSize(384, 288);
+ break;
+ case 6:
+ size.SetSize(2560, 1600);
+ break;
+ case 7:
+ size.SetSize(1920, 1080);
+ break;
+ case 8:
+ size.SetSize(1320, 900);
+ break;
+ case 9:
+ size.SetSize(1280, 720);
+ break;
}
- else
- {
+
+ if(m_pAllocator) {
+ m_pAllocator->ChangeDevice(m_pD3DDev);
+ } else {
m_pAllocator = DNew CDX9SubPicAllocator(m_pD3DDev, size, GetRenderersSettings().fSPCPow2Tex);
- if(!m_pAllocator)
- {
+ if(!m_pAllocator) {
_Error += L"CDX9SubPicAllocator failed\n";
return E_FAIL;
@@ -1031,18 +966,18 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
m_pSubPicQueue = GetRenderersSettings().nSPCSize > 0
? (ISubPicQueue*)DNew CSubPicQueue(GetRenderersSettings().nSPCSize, !GetRenderersSettings().fSPCAllowAnimationWhenBuffering, m_pAllocator, &hr)
: (ISubPicQueue*)DNew CSubPicQueueNoThread(m_pAllocator, &hr);
- if(!m_pSubPicQueue || FAILED(hr))
- {
+ if(!m_pSubPicQueue || FAILED(hr)) {
_Error += L"m_pSubPicQueue failed\n";
return E_FAIL;
}
- if(pSubPicProvider) m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ if(pSubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ }
m_pFont = NULL;
- if (m_pD3DXCreateFont)
- {
+ if (m_pD3DXCreateFont) {
int MinSize = 1600;
int CurrentSize = min(m_ScreenSize.cx, MinSize);
double Scale = double(CurrentSize) / double(MinSize);
@@ -1064,15 +999,15 @@ HRESULT CDX9AllocatorPresenter::CreateDevice(CString &_Error)
m_pSprite = NULL;
- if (m_pD3DXCreateSprite)
- {
+ if (m_pD3DXCreateSprite) {
m_pD3DXCreateSprite( m_pD3DDev, // D3D device
&m_pSprite);
}
m_pLine = NULL;
- if (m_pD3DXCreateLine)
+ if (m_pD3DXCreateLine) {
m_pD3DXCreateLine (m_pD3DDev, &m_pLine);
+ }
m_LastAdapterCheck = GetRenderersData()->GetPerfCounter();
@@ -1101,8 +1036,9 @@ bool CDX9AllocatorPresenter::SetCurrentDisplayMode()
{
D3DDISPLAYMODE d3ddm;
ZeroMemory(&d3ddm, sizeof(d3ddm));
- if(FAILED(m_pD3D->GetAdapterDisplayMode(m_CurrentAdapter, &d3ddm)))
+ if(FAILED(m_pD3D->GetAdapterDisplayMode(m_CurrentAdapter, &d3ddm))) {
return false;
+ }
m_RefreshRate = d3ddm.RefreshRate;
m_ScreenSize.SetSize(d3ddm.Width, d3ddm.Height);
m_DisplayType = d3ddm.Format;
@@ -1111,22 +1047,19 @@ bool CDX9AllocatorPresenter::SetCurrentDisplayMode()
UINT CDX9AllocatorPresenter::GetAdapter(IDirect3D9* pD3D, bool bCreateDevice)
{
- if(m_hWnd == NULL || pD3D == NULL)
+ if(m_hWnd == NULL || pD3D == NULL) {
return D3DADAPTER_DEFAULT;
+ }
CRenderersSettings& s = GetRenderersSettings();
- if(bCreateDevice && (pD3D->GetAdapterCount()>1) && (s.D3D9RenderDevice != _T("")))
- {
+ if(bCreateDevice && (pD3D->GetAdapterCount()>1) && (s.D3D9RenderDevice != _T(""))) {
TCHAR strGUID[50];
D3DADAPTER_IDENTIFIER9 adapterIdentifier;
m_D3D9Device = _T("");
- for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp)
- {
- if (pD3D->GetAdapterIdentifier(adp, 0, &adapterIdentifier) == S_OK)
- {
- if ((::StringFromGUID2(adapterIdentifier.DeviceIdentifier, strGUID, 50) > 0) && (s.D3D9RenderDevice == strGUID))
- {
+ for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp) {
+ if (pD3D->GetAdapterIdentifier(adp, 0, &adapterIdentifier) == S_OK) {
+ if ((::StringFromGUID2(adapterIdentifier.DeviceIdentifier, strGUID, 50) > 0) && (s.D3D9RenderDevice == strGUID)) {
m_D3D9Device = adapterIdentifier.Description;
return adp;
}
@@ -1135,18 +1068,18 @@ UINT CDX9AllocatorPresenter::GetAdapter(IDirect3D9* pD3D, bool bCreateDevice)
}
HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
- if(hMonitor == NULL) return D3DADAPTER_DEFAULT;
+ if(hMonitor == NULL) {
+ return D3DADAPTER_DEFAULT;
+ }
- for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp)
- {
+ for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp) {
HMONITOR hAdpMon = pD3D->GetAdapterMonitor(adp);
- if(hAdpMon == hMonitor)
- {
- if(bCreateDevice)
- {
+ if(hAdpMon == hMonitor) {
+ if(bCreateDevice) {
D3DADAPTER_IDENTIFIER9 adapterIdentifier;
- if (pD3D->GetAdapterIdentifier(adp, 0, &adapterIdentifier) == S_OK)
+ if (pD3D->GetAdapterIdentifier(adp, 0, &adapterIdentifier) == S_OK) {
m_D3D9Device = adapterIdentifier.Description;
+ }
}
return adp;
}
@@ -1161,12 +1094,12 @@ DWORD CDX9AllocatorPresenter::GetVertexProcessing()
D3DCAPS9 caps;
hr = m_pD3D->GetDeviceCaps(m_CurrentAdapter, D3DDEVTYPE_HAL, &caps);
- if (FAILED(hr))
+ if (FAILED(hr)) {
return D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+ }
if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||
- caps.VertexShaderVersion < D3DVS_VERSION(2, 0))
- {
+ caps.VertexShaderVersion < D3DVS_VERSION(2, 0)) {
return D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
@@ -1184,8 +1117,7 @@ void CDX9AllocatorPresenter::CalculateJitter(LONGLONG PerfCounter)
{
// Calculate the jitter!
LONGLONG llPerf = PerfCounter;
- if ((m_rtTimePerFrame != 0) && (labs ((long)(llPerf - m_llLastPerf)) < m_rtTimePerFrame*3) )
- {
+ if ((m_rtTimePerFrame != 0) && (labs ((long)(llPerf - m_llLastPerf)) < m_rtTimePerFrame*3) ) {
m_nNextJitter = (m_nNextJitter+1) % NB_JITTER;
m_pllJitter[m_nNextJitter] = llPerf - m_llLastPerf;
@@ -1195,8 +1127,7 @@ void CDX9AllocatorPresenter::CalculateJitter(LONGLONG PerfCounter)
// Calculate the real FPS
LONGLONG llJitterSum = 0;
LONGLONG llJitterSumAvg = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
LONGLONG Jitter = m_pllJitter[i];
llJitterSum += Jitter;
llJitterSumAvg += Jitter;
@@ -1204,8 +1135,7 @@ void CDX9AllocatorPresenter::CalculateJitter(LONGLONG PerfCounter)
double FrameTimeMean = double(llJitterSumAvg)/NB_JITTER;
m_fJitterMean = FrameTimeMean;
double DeviationSum = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
LONGLONG DevInt = m_pllJitter[i] - FrameTimeMean;
double Deviation = DevInt;
DeviationSum += Deviation*Deviation;
@@ -1225,53 +1155,54 @@ void CDX9AllocatorPresenter::CalculateJitter(LONGLONG PerfCounter)
bool CDX9AllocatorPresenter::GetVBlank(int &_ScanLine, int &_bInVBlank, bool _bMeasureTime)
{
LONGLONG llPerf = 0;
- if (_bMeasureTime)
+ if (_bMeasureTime) {
llPerf = GetRenderersData()->GetPerfCounter();
+ }
int ScanLine = 0;
_ScanLine = 0;
_bInVBlank = 0;
- if (m_bPendingResetDevice)
+ if (m_bPendingResetDevice) {
return false;
- if (m_pDirectDraw)
- {
+ }
+ if (m_pDirectDraw) {
DWORD ScanLineGet = 0;
m_pDirectDraw->GetScanLine(&ScanLineGet);
BOOL InVBlank;
- if (m_pDirectDraw->GetVerticalBlankStatus (&InVBlank) != S_OK)
+ if (m_pDirectDraw->GetVerticalBlankStatus (&InVBlank) != S_OK) {
return false;
+ }
ScanLine = ScanLineGet;
_bInVBlank = InVBlank;
- if (InVBlank)
+ if (InVBlank) {
ScanLine = 0;
- }
- else
- {
+ }
+ } else {
D3DRASTER_STATUS RasterStatus;
- if (m_pD3DDev->GetRasterStatus(0, &RasterStatus) != S_OK)
+ if (m_pD3DDev->GetRasterStatus(0, &RasterStatus) != S_OK) {
return false;
+ }
ScanLine = RasterStatus.ScanLine;
_bInVBlank = RasterStatus.InVBlank;
}
- if (_bMeasureTime)
- {
+ if (_bMeasureTime) {
m_VBlankMax = max(m_VBlankMax, ScanLine);
- if (ScanLine != 0 && !_bInVBlank)
+ if (ScanLine != 0 && !_bInVBlank) {
m_VBlankMinCalc = min(m_VBlankMinCalc, ScanLine);
+ }
m_VBlankMin = m_VBlankMax - m_ScreenSize.cy;
}
- if (_bInVBlank)
+ if (_bInVBlank) {
_ScanLine = 0;
- else if (m_VBlankMin != 300000)
+ } else if (m_VBlankMin != 300000) {
_ScanLine = ScanLine - m_VBlankMin;
- else
+ } else {
_ScanLine = ScanLine;
+ }
- if (_bMeasureTime)
- {
+ if (_bMeasureTime) {
LONGLONG Time = GetRenderersData()->GetPerfCounter() - llPerf;
- if (Time > 5000000) // 0.5 sec
- {
+ if (Time > 5000000) { // 0.5 sec
TRACE("GetVBlank too long (%f sec)\n", Time / 10000000.0);
}
m_RasterStatusWaitTimeMaxCalc = max(m_RasterStatusWaitTimeMaxCalc, Time);
@@ -1282,71 +1213,67 @@ bool CDX9AllocatorPresenter::GetVBlank(int &_ScanLine, int &_bInVBlank, bool _bM
bool CDX9AllocatorPresenter::WaitForVBlankRange(int &_RasterStart, int _RasterSize, bool _bWaitIfInside, bool _bNeedAccurate, bool _bMeasure, bool &_bTakenLock)
{
- if (_bMeasure)
+ if (_bMeasure) {
m_RasterStatusWaitTimeMaxCalc = 0;
+ }
bool bWaited = false;
int ScanLine = 0;
int InVBlank = 0;
LONGLONG llPerf = 0;
- if (_bMeasure)
+ if (_bMeasure) {
llPerf = GetRenderersData()->GetPerfCounter();
+ }
GetVBlank(ScanLine, InVBlank, _bMeasure);
- if (_bMeasure)
+ if (_bMeasure) {
m_VBlankStartWait = ScanLine;
+ }
static bool bOneWait = true;
- if (bOneWait && _bMeasure)
- {
+ if (bOneWait && _bMeasure) {
bOneWait = false;
// If we are already in the wanted interval we need to wait until we aren't, this improves sync when for example you are playing 23.976 Hz material on a 24 Hz refresh rate
int nInVBlank = 0;
- while (1)
- {
- if (!GetVBlank(ScanLine, InVBlank, _bMeasure))
+ while (1) {
+ if (!GetVBlank(ScanLine, InVBlank, _bMeasure)) {
break;
+ }
- if (InVBlank && nInVBlank == 0)
- {
+ if (InVBlank && nInVBlank == 0) {
nInVBlank = 1;
- }
- else if (!InVBlank && nInVBlank == 1)
- {
+ } else if (!InVBlank && nInVBlank == 1) {
nInVBlank = 2;
- }
- else if (InVBlank && nInVBlank == 2)
- {
+ } else if (InVBlank && nInVBlank == 2) {
nInVBlank = 3;
- }
- else if (!InVBlank && nInVBlank == 3)
- {
+ } else if (!InVBlank && nInVBlank == 3) {
break;
}
}
}
- if (_bWaitIfInside)
- {
+ if (_bWaitIfInside) {
int ScanLineDiff = long(ScanLine) - _RasterStart;
- if (ScanLineDiff > m_ScreenSize.cy / 2)
+ if (ScanLineDiff > m_ScreenSize.cy / 2) {
ScanLineDiff -= m_ScreenSize.cy;
- else if (ScanLineDiff < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiff < -m_ScreenSize.cy / 2) {
ScanLineDiff += m_ScreenSize.cy;
+ }
- if (ScanLineDiff >= 0 && ScanLineDiff <= _RasterSize)
- {
+ if (ScanLineDiff >= 0 && ScanLineDiff <= _RasterSize) {
bWaited = true;
// If we are already in the wanted interval we need to wait until we aren't, this improves sync when for example you are playing 23.976 Hz material on a 24 Hz refresh rate
int LastLineDiff = ScanLineDiff;
- while (1)
- {
- if (!GetVBlank(ScanLine, InVBlank, _bMeasure))
+ while (1) {
+ if (!GetVBlank(ScanLine, InVBlank, _bMeasure)) {
break;
+ }
int ScanLineDiff = long(ScanLine) - _RasterStart;
- if (ScanLineDiff > m_ScreenSize.cy / 2)
+ if (ScanLineDiff > m_ScreenSize.cy / 2) {
ScanLineDiff -= m_ScreenSize.cy;
- else if (ScanLineDiff < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiff < -m_ScreenSize.cy / 2) {
ScanLineDiff += m_ScreenSize.cy;
- if (!(ScanLineDiff >= 0 && ScanLineDiff <= _RasterSize) || (LastLineDiff < 0 && ScanLineDiff > 0))
+ }
+ if (!(ScanLineDiff >= 0 && ScanLineDiff <= _RasterSize) || (LastLineDiff < 0 && ScanLineDiff > 0)) {
break;
+ }
LastLineDiff = ScanLineDiff;
Sleep(1); // Just sleep
}
@@ -1357,66 +1284,72 @@ bool CDX9AllocatorPresenter::WaitForVBlankRange(int &_RasterStart, int _RasterSi
int MinRange = max(min(int(0.0015 * double(ScanLines) * RefreshRate + 0.5), ScanLines/3), 5); // 1.5 ms or max 33 % of Time
int NoSleepStart = _RasterStart - MinRange;
int NoSleepRange = MinRange;
- if (NoSleepStart < 0)
+ if (NoSleepStart < 0) {
NoSleepStart += m_ScreenSize.cy;
+ }
int MinRange2 = max(min(int(0.0050 * double(ScanLines) * RefreshRate + 0.5), ScanLines/3), 5); // 5 ms or max 33 % of Time
int D3DDevLockStart = _RasterStart - MinRange2;
int D3DDevLockRange = MinRange2;
- if (D3DDevLockStart < 0)
+ if (D3DDevLockStart < 0) {
D3DDevLockStart += m_ScreenSize.cy;
+ }
int ScanLineDiff = ScanLine - _RasterStart;
- if (ScanLineDiff > m_ScreenSize.cy / 2)
+ if (ScanLineDiff > m_ScreenSize.cy / 2) {
ScanLineDiff -= m_ScreenSize.cy;
- else if (ScanLineDiff < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiff < -m_ScreenSize.cy / 2) {
ScanLineDiff += m_ScreenSize.cy;
+ }
int LastLineDiff = ScanLineDiff;
int ScanLineDiffSleep = long(ScanLine) - NoSleepStart;
- if (ScanLineDiffSleep > m_ScreenSize.cy / 2)
+ if (ScanLineDiffSleep > m_ScreenSize.cy / 2) {
ScanLineDiffSleep -= m_ScreenSize.cy;
- else if (ScanLineDiffSleep < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiffSleep < -m_ScreenSize.cy / 2) {
ScanLineDiffSleep += m_ScreenSize.cy;
+ }
int LastLineDiffSleep = ScanLineDiffSleep;
int ScanLineDiffLock = long(ScanLine) - D3DDevLockStart;
- if (ScanLineDiffLock > m_ScreenSize.cy / 2)
+ if (ScanLineDiffLock > m_ScreenSize.cy / 2) {
ScanLineDiffLock -= m_ScreenSize.cy;
- else if (ScanLineDiffLock < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiffLock < -m_ScreenSize.cy / 2) {
ScanLineDiffLock += m_ScreenSize.cy;
+ }
int LastLineDiffLock = ScanLineDiffLock;
LONGLONG llPerfLock = 0;
- while (1)
- {
- if (!GetVBlank(ScanLine, InVBlank, _bMeasure))
+ while (1) {
+ if (!GetVBlank(ScanLine, InVBlank, _bMeasure)) {
break;
+ }
int ScanLineDiff = long(ScanLine) - _RasterStart;
- if (ScanLineDiff > m_ScreenSize.cy / 2)
+ if (ScanLineDiff > m_ScreenSize.cy / 2) {
ScanLineDiff -= m_ScreenSize.cy;
- else if (ScanLineDiff < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiff < -m_ScreenSize.cy / 2) {
ScanLineDiff += m_ScreenSize.cy;
- if ((ScanLineDiff >= 0 && ScanLineDiff <= _RasterSize) || (LastLineDiff < 0 && ScanLineDiff > 0))
+ }
+ if ((ScanLineDiff >= 0 && ScanLineDiff <= _RasterSize) || (LastLineDiff < 0 && ScanLineDiff > 0)) {
break;
+ }
LastLineDiff = ScanLineDiff;
bWaited = true;
int ScanLineDiffLock = long(ScanLine) - D3DDevLockStart;
- if (ScanLineDiffLock > m_ScreenSize.cy / 2)
+ if (ScanLineDiffLock > m_ScreenSize.cy / 2) {
ScanLineDiffLock -= m_ScreenSize.cy;
- else if (ScanLineDiffLock < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiffLock < -m_ScreenSize.cy / 2) {
ScanLineDiffLock += m_ScreenSize.cy;
+ }
- if (((ScanLineDiffLock >= 0 && ScanLineDiffLock <= D3DDevLockRange) || (LastLineDiffLock < 0 && ScanLineDiffLock > 0)))
- {
- if (!_bTakenLock && _bMeasure)
- {
+ if (((ScanLineDiffLock >= 0 && ScanLineDiffLock <= D3DDevLockRange) || (LastLineDiffLock < 0 && ScanLineDiffLock > 0))) {
+ if (!_bTakenLock && _bMeasure) {
_bTakenLock = true;
llPerfLock = GetRenderersData()->GetPerfCounter();
LockD3DDevice();
@@ -1426,30 +1359,28 @@ bool CDX9AllocatorPresenter::WaitForVBlankRange(int &_RasterStart, int _RasterSi
int ScanLineDiffSleep = long(ScanLine) - NoSleepStart;
- if (ScanLineDiffSleep > m_ScreenSize.cy / 2)
+ if (ScanLineDiffSleep > m_ScreenSize.cy / 2) {
ScanLineDiffSleep -= m_ScreenSize.cy;
- else if (ScanLineDiffSleep < -m_ScreenSize.cy / 2)
+ } else if (ScanLineDiffSleep < -m_ScreenSize.cy / 2) {
ScanLineDiffSleep += m_ScreenSize.cy;
+ }
- if (!((ScanLineDiffSleep >= 0 && ScanLineDiffSleep <= NoSleepRange) || (LastLineDiffSleep < 0 && ScanLineDiffSleep > 0)) || !_bNeedAccurate)
- {
+ if (!((ScanLineDiffSleep >= 0 && ScanLineDiffSleep <= NoSleepRange) || (LastLineDiffSleep < 0 && ScanLineDiffSleep > 0)) || !_bNeedAccurate) {
//TRACE("%d\n", RasterStatus.ScanLine);
Sleep(1); // Don't sleep for the last 1.5 ms scan lines, so we get maximum precision
}
LastLineDiffSleep = ScanLineDiffSleep;
}
_RasterStart = ScanLine;
- if (_bMeasure)
- {
+ if (_bMeasure) {
m_VBlankEndWait = ScanLine;
m_VBlankWaitTime = GetRenderersData()->GetPerfCounter() - llPerf;
- if (_bTakenLock)
- {
+ if (_bTakenLock) {
m_VBlankLockTime = GetRenderersData()->GetPerfCounter() - llPerfLock;
- }
- else
+ } else {
m_VBlankLockTime = 0;
+ }
m_RasterStatusWaitTime = m_RasterStatusWaitTimeMaxCalc;
m_RasterStatusWaitTimeMin = min(m_RasterStatusWaitTimeMin, m_RasterStatusWaitTime);
@@ -1465,21 +1396,15 @@ int CDX9AllocatorPresenter::GetVBlackPos()
BOOL bCompositionEnabled = m_bCompositionEnabled;
int WaitRange = max(m_ScreenSize.cy / 40, 5);
- if (!bCompositionEnabled)
- {
- if (m_bAlternativeVSync)
- {
+ if (!bCompositionEnabled) {
+ if (m_bAlternativeVSync) {
return s.m_RenderSettings.iVMR9VSyncOffset;
- }
- else
- {
+ } else {
int MinRange = max(min(int(0.005 * double(m_ScreenSize.cy) * GetRefreshRate() + 0.5), m_ScreenSize.cy/3), 5); // 5 ms or max 33 % of Time
int WaitFor = m_ScreenSize.cy - (MinRange + WaitRange);
return WaitFor;
}
- }
- else
- {
+ } else {
int WaitFor = m_ScreenSize.cy / 2;
return WaitFor;
}
@@ -1489,8 +1414,7 @@ int CDX9AllocatorPresenter::GetVBlackPos()
bool CDX9AllocatorPresenter::WaitForVBlank(bool &_Waited, bool &_bTakenLock)
{
CRenderersSettings& s = GetRenderersSettings();
- if (!s.m_RenderSettings.iVMR9VSync)
- {
+ if (!s.m_RenderSettings.iVMR9VSync) {
_Waited = true;
m_VBlankWaitTime = 0;
m_VBlankLockTime = 0;
@@ -1498,27 +1422,21 @@ bool CDX9AllocatorPresenter::WaitForVBlank(bool &_Waited, bool &_bTakenLock)
m_VBlankStartWait = 0;
return true;
}
-// _Waited = true;
-// return false;
+ // _Waited = true;
+ // return false;
BOOL bCompositionEnabled = m_bCompositionEnabled;
int WaitFor = GetVBlackPos();
- if (!bCompositionEnabled)
- {
- if (m_bAlternativeVSync)
- {
+ if (!bCompositionEnabled) {
+ if (m_bAlternativeVSync) {
_Waited = WaitForVBlankRange(WaitFor, 0, false, true, true, _bTakenLock);
return false;
- }
- else
- {
+ } else {
_Waited = WaitForVBlankRange(WaitFor, 0, false, s.m_RenderSettings.iVMR9VSyncAccurate, true, _bTakenLock);
return true;
}
- }
- else
- {
+ } else {
// Instead we wait for VBlack after the present, this seems to fix the stuttering problem. It's also possible to fix by removing the Sleep above, but that isn't an option.
WaitForVBlankRange(WaitFor, 0, false, s.m_RenderSettings.iVMR9VSyncAccurate, true, _bTakenLock);
@@ -1530,20 +1448,20 @@ void CDX9AllocatorPresenter::UpdateAlphaBitmap()
{
m_VMR9AlphaBitmapData.Free();
- if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0)
- {
+ if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0) {
HBITMAP hBitmap = (HBITMAP)GetCurrentObject (m_VMR9AlphaBitmap.hdc, OBJ_BITMAP);
- if (!hBitmap)
+ if (!hBitmap) {
return;
+ }
DIBSECTION info = {0};
- if (!::GetObject(hBitmap, sizeof( DIBSECTION ), &info ))
+ if (!::GetObject(hBitmap, sizeof( DIBSECTION ), &info )) {
return;
+ }
m_VMR9AlphaBitmapRect = CRect(0, 0, info.dsBm.bmWidth, info.dsBm.bmHeight);
m_VMR9AlphaBitmapWidthBytes = info.dsBm.bmWidthBytes;
- if (m_VMR9AlphaBitmapData.Allocate(info.dsBm.bmWidthBytes * info.dsBm.bmHeight))
- {
+ if (m_VMR9AlphaBitmapData.Allocate(info.dsBm.bmWidthBytes * info.dsBm.bmHeight)) {
memcpy((BYTE *)m_VMR9AlphaBitmapData, info.dsBm.bmBits, info.dsBm.bmWidthBytes * info.dsBm.bmHeight);
}
}
@@ -1551,23 +1469,19 @@ void CDX9AllocatorPresenter::UpdateAlphaBitmap()
STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
{
- if (m_bPendingResetDevice)
- {
+ if (m_bPendingResetDevice) {
SendResetRequest();
return false;
}
CRenderersSettings& s = GetRenderersSettings();
-// TRACE("Thread: %d\n", (LONG)((CRITICAL_SECTION &)m_RenderLock).OwningThread);
+ // TRACE("Thread: %d\n", (LONG)((CRITICAL_SECTION &)m_RenderLock).OwningThread);
#if 0
- if (TryEnterCriticalSection (&(CRITICAL_SECTION &)(*((CCritSec *)this))))
- {
+ if (TryEnterCriticalSection (&(CRITICAL_SECTION &)(*((CCritSec *)this)))) {
LeaveCriticalSection((&(CRITICAL_SECTION &)(*((CCritSec *)this))));
- }
- else
- {
+ } else {
__debugbreak();
}
#endif
@@ -1579,13 +1493,11 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
if(m_WindowRect.right <= m_WindowRect.left || m_WindowRect.bottom <= m_WindowRect.top
|| m_NativeVideoSize.cx <= 0 || m_NativeVideoSize.cy <= 0
- || !m_pVideoSurface)
- {
- if (m_OrderedPaint)
+ || !m_pVideoSurface) {
+ if (m_OrderedPaint) {
--m_OrderedPaint;
- else
- {
-// TRACE("UNORDERED PAINT!!!!!!\n");
+ } else {
+ // TRACE("UNORDERED PAINT!!!!!!\n");
}
@@ -1614,18 +1526,15 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
// Render the current video frame
hr = RenderVideo(pBackBuffer, rSrcVid, rDstVid);
- if (FAILED(hr))
- {
- if (m_RenderingPath == RENDERING_PATH_STRETCHRECT)
- {
+ if (FAILED(hr)) {
+ if (m_RenderingPath == RENDERING_PATH_STRETCHRECT) {
// Support ffdshow queueing
// m_pD3DDev->StretchRect may fail if ffdshow is using queue output samples.
// Here we don't want to show the black buffer.
- if (m_OrderedPaint)
+ if (m_OrderedPaint) {
--m_OrderedPaint;
- else
- {
-// TRACE("UNORDERED PAINT!!!!!!\n");
+ } else {
+ // TRACE("UNORDERED PAINT!!!!!!\n");
}
return false;
@@ -1636,21 +1545,17 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
AlphaBltSubPic(rSrcPri.Size());
// Casimir666 : show OSD
- if (m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_UPDATE)
- {
+ if (m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_UPDATE) {
CAutoLock BitMapLock(&m_VMR9AlphaBitmapLock);
CRect rcSrc (m_VMR9AlphaBitmap.rSrc);
m_pOSDTexture = NULL;
m_pOSDSurface = NULL;
- if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0 && (BYTE *)m_VMR9AlphaBitmapData)
- {
+ if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0 && (BYTE *)m_VMR9AlphaBitmapData) {
if( (m_pD3DXLoadSurfaceFromMemory != NULL) &&
SUCCEEDED(hr = m_pD3DDev->CreateTexture(rcSrc.Width(), rcSrc.Height(), 1,
D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
- D3DPOOL_DEFAULT, &m_pOSDTexture, NULL)) )
- {
- if (SUCCEEDED (hr = m_pOSDTexture->GetSurfaceLevel(0, &m_pOSDSurface)))
- {
+ D3DPOOL_DEFAULT, &m_pOSDTexture, NULL)) ) {
+ if (SUCCEEDED (hr = m_pOSDTexture->GetSurfaceLevel(0, &m_pOSDSurface))) {
hr = m_pD3DXLoadSurfaceFromMemory (m_pOSDSurface,
NULL,
NULL,
@@ -1662,8 +1567,7 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
D3DX_FILTER_NONE,
m_VMR9AlphaBitmap.clrSrcKey);
}
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
m_pOSDTexture = NULL;
m_pOSDSurface = NULL;
}
@@ -1673,8 +1577,9 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
}
- if (pApp->m_fDisplayStats)
+ if (pApp->m_fDisplayStats) {
DrawStats();
+ }
{
CString Temp;
@@ -1683,7 +1588,9 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
//TRACE("%ws\n", Temp.GetString());
}
- if (m_pOSDTexture) AlphaBlt(rSrcPri, rDstPri, m_pOSDTexture);
+ if (m_pOSDTexture) {
+ AlphaBlt(rSrcPri, rDstPri, m_pOSDTexture);
+ }
m_pD3DDev->EndScene();
@@ -1692,47 +1599,48 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
bool bDoVSyncInPresent = (!bCompositionEnabled && !m_bAlternativeVSync) || !s.m_RenderSettings.iVMR9VSync;
LONGLONG PresentWaitTime = 0;
-/*
- if(fAll && m_fVMRSyncFix && bDoVSyncInPresent)
- {
- LONGLONG llPerf = pApp->GetPerfCounter();
- D3DLOCKED_RECT lr;
- if(SUCCEEDED(pBackBuffer->LockRect(&lr, NULL, 0)))
- pBackBuffer->UnlockRect();
- PresentWaitTime = pApp->GetPerfCounter() - llPerf;
- }
-*/
+ /*
+ if(fAll && m_fVMRSyncFix && bDoVSyncInPresent)
+ {
+ LONGLONG llPerf = pApp->GetPerfCounter();
+ D3DLOCKED_RECT lr;
+ if(SUCCEEDED(pBackBuffer->LockRect(&lr, NULL, 0)))
+ pBackBuffer->UnlockRect();
+ PresentWaitTime = pApp->GetPerfCounter() - llPerf;
+ }
+ */
CComPtr<IDirect3DQuery9> pEventQuery;
m_pD3DDev->CreateQuery(D3DQUERYTYPE_EVENT, &pEventQuery);
- if (pEventQuery)
+ if (pEventQuery) {
pEventQuery->Issue(D3DISSUE_END);
+ }
- if (s.m_RenderSettings.iVMRFlushGPUBeforeVSync && pEventQuery)
- {
+ if (s.m_RenderSettings.iVMRFlushGPUBeforeVSync && pEventQuery) {
LONGLONG llPerf = pApp->GetPerfCounter();
BOOL Data;
//Sleep(5);
LONGLONG FlushStartTime = pApp->GetPerfCounter();
- while(S_FALSE == pEventQuery->GetData( &Data, sizeof(Data), D3DGETDATA_FLUSH ))
- {
- if (!s.m_RenderSettings.iVMRFlushGPUWait)
+ while(S_FALSE == pEventQuery->GetData( &Data, sizeof(Data), D3DGETDATA_FLUSH )) {
+ if (!s.m_RenderSettings.iVMRFlushGPUWait) {
break;
+ }
Sleep(1);
- if (pApp->GetPerfCounter() - FlushStartTime > 500000)
- break; // timeout after 50 ms
+ if (pApp->GetPerfCounter() - FlushStartTime > 500000) {
+ break; // timeout after 50 ms
+ }
}
- if (s.m_RenderSettings.iVMRFlushGPUWait)
+ if (s.m_RenderSettings.iVMRFlushGPUWait) {
m_WaitForGPUTime = pApp->GetPerfCounter() - llPerf;
- else
+ } else {
m_WaitForGPUTime = 0;
- }
- else
+ }
+ } else {
m_WaitForGPUTime = 0;
+ }
- if (fAll)
- {
+ if (fAll) {
m_PaintTime = (GetRenderersData()->GetPerfCounter() - StartPaint);
m_PaintTimeMin = min(m_PaintTimeMin, m_PaintTime);
m_PaintTimeMax = max(m_PaintTimeMax, m_PaintTime);
@@ -1740,17 +1648,16 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
bool bWaited = false;
bool bTakenLock = false;
- if (fAll)
- {
+ if (fAll) {
// Only sync to refresh when redrawing all
bool bTest = WaitForVBlank(bWaited, bTakenLock);
ASSERT(bTest == bDoVSyncInPresent);
- if (!bDoVSyncInPresent)
- {
+ if (!bDoVSyncInPresent) {
LONGLONG Time = pApp->GetPerfCounter();
OnVBlankFinished(fAll, Time);
- if (!m_bIsEVR || m_OrderedPaint)
+ if (!m_bIsEVR || m_OrderedPaint) {
CalculateJitter(Time);
+ }
}
}
@@ -1762,35 +1669,35 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
m_pD3DDev->CreateQuery(D3DQUERYTYPE_EVENT, &pEventQuery);
LONGLONG llPerf = pApp->GetPerfCounter();
- if (m_pD3DDevEx)
- {
- if (m_bIsFullscreen)
+ if (m_pD3DDevEx) {
+ if (m_bIsFullscreen) {
hr = m_pD3DDevEx->PresentEx(NULL, NULL, NULL, NULL, NULL);
- else
+ } else {
hr = m_pD3DDevEx->PresentEx(rSrcPri, rDstPri, NULL, NULL, NULL);
- }
- else
- {
- if (m_bIsFullscreen)
+ }
+ } else {
+ if (m_bIsFullscreen) {
hr = m_pD3DDev->Present(NULL, NULL, NULL, NULL);
- else
+ } else {
hr = m_pD3DDev->Present(rSrcPri, rDstPri, NULL, NULL);
+ }
}
// Issue an End event
- if (pEventQuery)
+ if (pEventQuery) {
pEventQuery->Issue(D3DISSUE_END);
+ }
BOOL Data;
- if (s.m_RenderSettings.iVMRFlushGPUAfterPresent && pEventQuery)
- {
+ if (s.m_RenderSettings.iVMRFlushGPUAfterPresent && pEventQuery) {
LONGLONG FlushStartTime = pApp->GetPerfCounter();
- while (S_FALSE == pEventQuery->GetData( &Data, sizeof(Data), D3DGETDATA_FLUSH ))
- {
- if (!s.m_RenderSettings.iVMRFlushGPUWait)
+ while (S_FALSE == pEventQuery->GetData( &Data, sizeof(Data), D3DGETDATA_FLUSH )) {
+ if (!s.m_RenderSettings.iVMRFlushGPUWait) {
break;
- if (pApp->GetPerfCounter() - FlushStartTime > 500000)
- break; // timeout after 50 ms
+ }
+ if (pApp->GetPerfCounter() - FlushStartTime > 500000) {
+ break; // timeout after 50 ms
+ }
}
}
@@ -1798,43 +1705,39 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
int bInVBlank;
GetVBlank(ScanLine, bInVBlank, false);
- if (fAll && (!m_bIsEVR || m_OrderedPaint))
- {
+ if (fAll && (!m_bIsEVR || m_OrderedPaint)) {
m_VBlankEndPresent = ScanLine;
}
- while (ScanLine == 0 || bInVBlank)
- {
+ while (ScanLine == 0 || bInVBlank) {
GetVBlank(ScanLine, bInVBlank, false);
}
m_VBlankStartMeasureTime = pApp->GetPerfCounter();
m_VBlankStartMeasure = ScanLine;
- if (fAll && bDoVSyncInPresent)
- {
+ if (fAll && bDoVSyncInPresent) {
m_PresentWaitTime = (pApp->GetPerfCounter() - llPerf) + PresentWaitTime;
m_PresentWaitTimeMin = min(m_PresentWaitTimeMin, m_PresentWaitTime);
m_PresentWaitTimeMax = max(m_PresentWaitTimeMax, m_PresentWaitTime);
- }
- else
- {
+ } else {
m_PresentWaitTime = 0;
m_PresentWaitTimeMin = min(m_PresentWaitTimeMin, m_PresentWaitTime);
m_PresentWaitTimeMax = max(m_PresentWaitTimeMax, m_PresentWaitTime);
}
}
- if (bDoVSyncInPresent)
- {
+ if (bDoVSyncInPresent) {
LONGLONG Time = pApp->GetPerfCounter();
- if (!m_bIsEVR || m_OrderedPaint)
+ if (!m_bIsEVR || m_OrderedPaint) {
CalculateJitter(Time);
+ }
OnVBlankFinished(fAll, Time);
}
- if (bTakenLock)
+ if (bTakenLock) {
UnlockD3DDevice();
+ }
/*if (!bWaited)
{
@@ -1849,12 +1752,10 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
}
}*/
- if (!m_bPendingResetDevice)
- {
+ if (!m_bPendingResetDevice) {
bool fResetDevice = false;
- if(hr == D3DERR_DEVICELOST && m_pD3DDev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
- {
+ if(hr == D3DERR_DEVICELOST && m_pD3DDev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) {
TRACE("Reset Device: D3D Device Lost\n");
fResetDevice = true;
}
@@ -1865,66 +1766,55 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
// fResetDevice = true;
//}
- if (SettingsNeedResetDevice())
- {
+ if (SettingsNeedResetDevice()) {
TRACE("Reset Device: settings changed\n");
fResetDevice = true;
}
bCompositionEnabled = false;
- if (m_pDwmIsCompositionEnabled)
+ if (m_pDwmIsCompositionEnabled) {
m_pDwmIsCompositionEnabled(&bCompositionEnabled);
- if ((bCompositionEnabled != 0) != m_bCompositionEnabled)
- {
- if (m_bIsFullscreen)
- {
+ }
+ if ((bCompositionEnabled != 0) != m_bCompositionEnabled) {
+ if (m_bIsFullscreen) {
m_bCompositionEnabled = (bCompositionEnabled != 0);
- }
- else
- {
+ } else {
TRACE("Reset Device: DWM composition changed\n");
fResetDevice = true;
}
}
- if(s.fResetDevice)
- {
+ if(s.fResetDevice) {
LONGLONG time = GetRenderersData()->GetPerfCounter();
- if (time > m_LastAdapterCheck + 20000000) // check every 2 sec.
- {
+ if (time > m_LastAdapterCheck + 20000000) { // check every 2 sec.
m_LastAdapterCheck = time;
#ifdef _DEBUG
D3DDEVICE_CREATION_PARAMETERS Parameters;
- if(SUCCEEDED(m_pD3DDev->GetCreationParameters(&Parameters)))
- {
+ if(SUCCEEDED(m_pD3DDev->GetCreationParameters(&Parameters))) {
ASSERT(Parameters.AdapterOrdinal == m_CurrentAdapter);
}
#endif
- if(m_CurrentAdapter != GetAdapter(m_pD3D))
- {
+ if(m_CurrentAdapter != GetAdapter(m_pD3D)) {
TRACE("Reset Device: D3D adapter changed\n");
fResetDevice = true;
}
#ifdef _DEBUG
- else
- {
+ else {
ASSERT(m_pD3D->GetAdapterMonitor(m_CurrentAdapter) == m_pD3D->GetAdapterMonitor(GetAdapter(m_pD3D)));
}
#endif
}
}
- if(fResetDevice)
- {
+ if(fResetDevice) {
m_bPendingResetDevice = true;
SendResetRequest();
}
}
- if (m_OrderedPaint)
+ if (m_OrderedPaint) {
--m_OrderedPaint;
- else
- {
+ } else {
//if (m_bIsEVR)
// TRACE("UNORDERED PAINT!!!!!!\n");
}
@@ -1933,24 +1823,25 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::Paint(bool fAll)
double CDX9AllocatorPresenter::GetFrameTime()
{
- if (m_DetectedLock)
+ if (m_DetectedLock) {
return m_DetectedFrameTime;
+ }
return m_rtTimePerFrame / 10000000.0;
}
double CDX9AllocatorPresenter::GetFrameRate()
{
- if (m_DetectedLock)
+ if (m_DetectedLock) {
return m_DetectedFrameRate;
+ }
return 10000000.0 / m_rtTimePerFrame;
}
void CDX9AllocatorPresenter::SendResetRequest()
{
- if (!m_bDeviceResetRequested)
- {
+ if (!m_bDeviceResetRequested) {
m_bDeviceResetRequested = true;
AfxGetApp()->m_pMainWnd->PostMessage(WM_RESET_DEVICE);
}
@@ -1966,8 +1857,7 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::ResetDevice()
CString Error;
// TODO: Report error messages here
- if(FAILED(hr = CreateDevice(Error)) || FAILED(hr = AllocSurfaces()))
- {
+ if(FAILED(hr = CreateDevice(Error)) || FAILED(hr = AllocSurfaces())) {
// TODO: We should probably pause player
#ifdef _DEBUG
Error += GetWindowsErrorMessage(hr, NULL);
@@ -1985,40 +1875,50 @@ STDMETHODIMP_(bool) CDX9AllocatorPresenter::ResetDevice()
void CDX9AllocatorPresenter::DrawText(const RECT &rc, const CString &strText, int _Priority)
{
- if (_Priority < 1)
+ if (_Priority < 1) {
return;
+ }
int Quality = 1;
D3DXCOLOR Color1( 1.0f, 0.2f, 0.2f, 1.0f );
D3DXCOLOR Color0( 0.0f, 0.0f, 0.0f, 1.0f );
RECT Rect1 = rc;
RECT Rect2 = rc;
- if (Quality == 1)
+ if (Quality == 1) {
OffsetRect (&Rect2 , 2, 2);
- else
+ } else {
OffsetRect (&Rect2 , -1, -1);
- if (Quality > 0)
+ }
+ if (Quality > 0) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 1, 0);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 1, 0);
- if (Quality > 2)
+ if (Quality > 2) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 0, 1);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 0, 1);
- if (Quality > 1)
+ if (Quality > 1) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , -1, 0);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , -1, 0);
- if (Quality > 2)
+ if (Quality > 2) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 0, -1);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
m_pFont->DrawText( m_pSprite, strText, -1, &Rect1, DT_NOCLIP, Color1);
}
@@ -2028,17 +1928,16 @@ void CDX9AllocatorPresenter::DrawStats()
CRenderersSettings& s = GetRenderersSettings();
CRenderersData * pApp = GetRenderersData();
int bDetailedStats = 2;
- switch (pApp->m_fDisplayStats)
- {
- case 1:
- bDetailedStats = 2;
- break;
- case 2:
- bDetailedStats = 1;
- break;
- case 3:
- bDetailedStats = 0;
- break;
+ switch (pApp->m_fDisplayStats) {
+ case 1:
+ bDetailedStats = 2;
+ break;
+ case 2:
+ bDetailedStats = 1;
+ break;
+ case 3:
+ bDetailedStats = 0;
+ break;
}
LONGLONG llMaxJitter = m_MaxJitter;
@@ -2046,77 +1945,92 @@ void CDX9AllocatorPresenter::DrawStats()
LONGLONG llMaxSyncOffset = m_MaxSyncOffset;
LONGLONG llMinSyncOffset = m_MinSyncOffset;
RECT rc = {40, 40, 0, 0 };
- if (m_pFont && m_pSprite)
- {
+ if (m_pFont && m_pSprite) {
m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);
CString strText;
int TextHeight = 25.0*m_TextScale + 0.5;
-// strText.Format(L"Frame rate : %7.03f (%7.3f ms = %.03f, %s) (%7.3f ms = %.03f%s) Clock: %7.3f ms %+1.4f %% %+1.9f %+1.9f", m_fAvrFps, double(m_rtTimePerFrame) / 10000.0, 10000000.0 / (double)(m_rtTimePerFrame), m_bInterlaced ? L"I" : L"P", GetFrameTime() * 1000.0, GetFrameRate(), m_DetectedLock ? L" L" : L"", m_ClockDiff/10000.0, m_ModeratedTimeSpeed*100.0 - 100.0, m_ModeratedTimeSpeedDiff, m_ClockDiffCalc/10000.0);
- if (bDetailedStats > 1)
- {
- if (m_bIsEVR)
+ // strText.Format(L"Frame rate : %7.03f (%7.3f ms = %.03f, %s) (%7.3f ms = %.03f%s) Clock: %7.3f ms %+1.4f %% %+1.9f %+1.9f", m_fAvrFps, double(m_rtTimePerFrame) / 10000.0, 10000000.0 / (double)(m_rtTimePerFrame), m_bInterlaced ? L"I" : L"P", GetFrameTime() * 1000.0, GetFrameRate(), m_DetectedLock ? L" L" : L"", m_ClockDiff/10000.0, m_ModeratedTimeSpeed*100.0 - 100.0, m_ModeratedTimeSpeedDiff, m_ClockDiffCalc/10000.0);
+ if (bDetailedStats > 1) {
+ if (m_bIsEVR) {
strText.Format(L"Frame rate : %7.03f (%7.3f ms = %.03f, %s) (%7.3f ms = %.03f%s, %2.03f StdDev) Clock: %1.4f %%", m_fAvrFps, double(m_rtTimePerFrame) / 10000.0, 10000000.0 / (double)(m_rtTimePerFrame), m_bInterlaced ? L"I" : L"P", GetFrameTime() * 1000.0, GetFrameRate(), m_DetectedLock ? L" L" : L"", m_DetectedFrameTimeStdDev / 10000.0, m_ModeratedTimeSpeed*100.0);
- else
+ } else {
strText.Format(L"Frame rate : %7.03f (%7.3f ms = %.03f, %s)", m_fAvrFps, double(m_rtTimePerFrame) / 10000.0, 10000000.0 / (double)(m_rtTimePerFrame), m_bInterlaced ? L"I" : L"P");
+ }
}
-// strText.Format(L"Frame rate : %7.03f (%7.3f ms = %.03f, %s) (%7.3f ms = %.03f%s, %2.03f StdDev)", m_fAvrFps, double(m_rtTimePerFrame) / 10000.0, 10000000.0 / (double)(m_rtTimePerFrame), m_bInterlaced ? L"I" : L"P", GetFrameTime() * 1000.0, GetFrameRate(), m_DetectedLock ? L" L" : L"", m_DetectedFrameTimeStdDev / 10000.0);
- else
+ // strText.Format(L"Frame rate : %7.03f (%7.3f ms = %.03f, %s) (%7.3f ms = %.03f%s, %2.03f StdDev)", m_fAvrFps, double(m_rtTimePerFrame) / 10000.0, 10000000.0 / (double)(m_rtTimePerFrame), m_bInterlaced ? L"I" : L"P", GetFrameTime() * 1000.0, GetFrameRate(), m_DetectedLock ? L" L" : L"", m_DetectedFrameTimeStdDev / 10000.0);
+ else {
strText.Format(L"Frame rate : %7.03f (%.03f%s)", m_fAvrFps, GetFrameRate(), m_DetectedLock ? L" L" : L"");
+ }
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
- if (bDetailedStats > 1)
- {
+ if (bDetailedStats > 1) {
strText.Format(L"Settings : ");
- if (m_bIsEVR)
+ if (m_bIsEVR) {
strText += "EVR ";
- else
+ } else {
strText += "VMR9 ";
+ }
- if (m_bIsFullscreen)
+ if (m_bIsFullscreen) {
strText += "FS ";
- if (s.m_RenderSettings.iVMR9FullscreenGUISupport)
+ }
+ if (s.m_RenderSettings.iVMR9FullscreenGUISupport) {
strText += "FSGui ";
+ }
- if (s.m_RenderSettings.iVMRDisableDesktopComposition)
+ if (s.m_RenderSettings.iVMRDisableDesktopComposition) {
strText += "DisDC ";
+ }
- if (m_bColorManagement)
+ if (m_bColorManagement) {
strText += "ColorMan ";
+ }
- if (s.m_RenderSettings.iVMRFlushGPUBeforeVSync)
+ if (s.m_RenderSettings.iVMRFlushGPUBeforeVSync) {
strText += "GPUFlushBV ";
- if (s.m_RenderSettings.iVMRFlushGPUAfterPresent)
+ }
+ if (s.m_RenderSettings.iVMRFlushGPUAfterPresent) {
strText += "GPUFlushAP ";
+ }
- if (s.m_RenderSettings.iVMRFlushGPUWait)
+ if (s.m_RenderSettings.iVMRFlushGPUWait) {
strText += "GPUFlushWt ";
+ }
- if (s.m_RenderSettings.iVMR9VSync)
+ if (s.m_RenderSettings.iVMR9VSync) {
strText += "VS ";
- if (s.m_RenderSettings.fVMR9AlterativeVSync)
+ }
+ if (s.m_RenderSettings.fVMR9AlterativeVSync) {
strText += "AltVS ";
- if (s.m_RenderSettings.iVMR9VSyncAccurate)
+ }
+ if (s.m_RenderSettings.iVMR9VSyncAccurate) {
strText += "AccVS ";
- if (s.m_RenderSettings.iVMR9VSyncOffset)
+ }
+ if (s.m_RenderSettings.iVMR9VSyncOffset) {
strText.AppendFormat(L"VSOfst(%d)", s.m_RenderSettings.iVMR9VSyncOffset);
+ }
- if (m_bFullFloatingPointProcessing)
+ if (m_bFullFloatingPointProcessing) {
strText += "FullFP ";
+ }
- if (m_bIsEVR)
- {
- if (m_bHighColorResolution)
+ if (m_bIsEVR) {
+ if (m_bHighColorResolution) {
strText += "10bitOut ";
- if (m_bForceInputHighColorResolution)
+ }
+ if (m_bForceInputHighColorResolution) {
strText += "For10bitIn ";
- if (s.m_RenderSettings.iEVREnableFrameTimeCorrection)
+ }
+ if (s.m_RenderSettings.iEVREnableFrameTimeCorrection) {
strText += "FTC ";
- if (s.m_RenderSettings.iEVROutputRange == 0)
+ }
+ if (s.m_RenderSettings.iEVROutputRange == 0) {
strText += "0-255 ";
- else if (s.m_RenderSettings.iEVROutputRange == 1)
+ } else if (s.m_RenderSettings.iEVROutputRange == 1) {
strText += "16-235 ";
+ }
}
@@ -2125,39 +2039,35 @@ void CDX9AllocatorPresenter::DrawStats()
}
- if (bDetailedStats > 1)
- {
+ if (bDetailedStats > 1) {
strText.Format(L"Formats : Surface %s Backbuffer %s Display %s Device %s D3DExError: %s", GetD3DFormatStr(m_SurfaceType), GetD3DFormatStr(m_BackbufferType), GetD3DFormatStr(m_DisplayType), m_pD3DDevEx ? L"D3DDevEx" : L"D3DDev", m_D3DDevExError.GetString());
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
- if (m_bIsEVR)
- {
+ if (m_bIsEVR) {
strText.Format(L"Refresh rate : %.05f Hz SL: %4d (%3d Hz) Last Duration: %10.6f Corrected Frame Time: %s", m_DetectedRefreshRate, int(m_DetectedScanlinesPerFrame + 0.5), m_RefreshRate, double(m_LastFrameDuration)/10000.0, m_bCorrectedFrameTime?L"Yes":L"No");
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
}
}
- if (m_bSyncStatsAvailable)
- {
- if (bDetailedStats > 1)
+ if (m_bSyncStatsAvailable) {
+ if (bDetailedStats > 1) {
strText.Format(L"Sync offset : Min = %+8.3f ms, Max = %+8.3f ms, StdDev = %7.3f ms, Avr = %7.3f ms, Mode = %d", (double(llMinSyncOffset)/10000.0), (double(llMaxSyncOffset)/10000.0), m_fSyncOffsetStdDev/10000.0, m_fSyncOffsetAvr/10000.0, m_VSyncMode);
- else
+ } else {
strText.Format(L"Sync offset : Mode = %d", m_VSyncMode);
+ }
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
}
- if (bDetailedStats > 1)
- {
+ if (bDetailedStats > 1) {
strText.Format(L"Jitter : Min = %+8.3f ms, Max = %+8.3f ms, StdDev = %7.3f ms", (double(llMinJitter)/10000.0), (double(llMaxJitter)/10000.0), m_fJitterStdDev/10000.0);
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
}
- if (m_pAllocator && bDetailedStats > 1)
- {
+ if (m_pAllocator && bDetailedStats > 1) {
CDX9SubPicAllocator *pAlloc = (CDX9SubPicAllocator *)m_pAllocator.p;
int nFree = 0;
int nAlloc = 0;
@@ -2165,13 +2075,14 @@ void CDX9AllocatorPresenter::DrawStats()
REFERENCE_TIME QueueNow = 0;
REFERENCE_TIME QueueStart = 0;
REFERENCE_TIME QueueEnd = 0;
- if (m_pSubPicQueue)
- {
+ if (m_pSubPicQueue) {
m_pSubPicQueue->GetStats(nSubPic, QueueNow, QueueStart, QueueEnd);
- if (QueueStart)
+ if (QueueStart) {
QueueStart -= QueueNow;
- if (QueueEnd)
+ }
+ if (QueueEnd) {
QueueEnd -= QueueNow;
+ }
}
pAlloc->GetStats(nFree, nAlloc);
strText.Format(L"Subtitles : Free %d Allocated %d Buffered %d QueueStart %7.3f QueueEnd %7.3f", nFree, nAlloc, nSubPic, (double(QueueStart)/10000000.0), (double(QueueEnd)/10000000.0));
@@ -2179,19 +2090,18 @@ void CDX9AllocatorPresenter::DrawStats()
OffsetRect (&rc, 0, TextHeight);
}
- if (bDetailedStats > 1)
- {
- if (m_VBlankEndPresent == -100000)
+ if (bDetailedStats > 1) {
+ if (m_VBlankEndPresent == -100000) {
strText.Format(L"VBlank Wait : Start %4d End %4d Wait %7.3f ms Lock %7.3f ms Offset %4d Max %4d", m_VBlankStartWait, m_VBlankEndWait, (double(m_VBlankWaitTime)/10000.0), (double(m_VBlankLockTime)/10000.0), m_VBlankMin, m_VBlankMax - m_VBlankMin);
- else
+ } else {
strText.Format(L"VBlank Wait : Start %4d End %4d Wait %7.3f ms Lock %7.3f ms Offset %4d Max %4d EndPresent %4d", m_VBlankStartWait, m_VBlankEndWait, (double(m_VBlankWaitTime)/10000.0), (double(m_VBlankLockTime)/10000.0), m_VBlankMin, m_VBlankMax - m_VBlankMin, m_VBlankEndPresent);
- }
- else
- {
- if (m_VBlankEndPresent == -100000)
+ }
+ } else {
+ if (m_VBlankEndPresent == -100000) {
strText.Format(L"VBlank Wait : Start %4d End %4d", m_VBlankStartWait, m_VBlankEndWait);
- else
+ } else {
strText.Format(L"VBlank Wait : Start %4d End %4d EP %4d", m_VBlankStartWait, m_VBlankEndWait, m_VBlankEndPresent);
+ }
}
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
@@ -2200,64 +2110,59 @@ void CDX9AllocatorPresenter::DrawStats()
bool bDoVSyncInPresent = (!bCompositionEnabled && !m_bAlternativeVSync) || !s.m_RenderSettings.iVMR9VSync;
- if (bDetailedStats > 1 && bDoVSyncInPresent)
- {
+ if (bDetailedStats > 1 && bDoVSyncInPresent) {
strText.Format(L"Present Wait : Wait %7.3f ms Min %7.3f ms Max %7.3f ms", (double(m_PresentWaitTime)/10000.0), (double(m_PresentWaitTimeMin)/10000.0), (double(m_PresentWaitTimeMax)/10000.0));
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
}
- if (bDetailedStats > 1)
- {
- if (m_WaitForGPUTime)
+ if (bDetailedStats > 1) {
+ if (m_WaitForGPUTime) {
strText.Format(L"Paint Time : Draw %7.3f ms Min %7.3f ms Max %7.3f ms GPU %7.3f ms", (double(m_PaintTime-m_WaitForGPUTime)/10000.0), (double(m_PaintTimeMin)/10000.0), (double(m_PaintTimeMax)/10000.0), (double(m_WaitForGPUTime)/10000.0));
- else
+ } else {
strText.Format(L"Paint Time : Draw %7.3f ms Min %7.3f ms Max %7.3f ms", (double(m_PaintTime-m_WaitForGPUTime)/10000.0), (double(m_PaintTimeMin)/10000.0), (double(m_PaintTimeMax)/10000.0));
- }
- else
- {
- if (m_WaitForGPUTime)
+ }
+ } else {
+ if (m_WaitForGPUTime) {
strText.Format(L"Paint Time : Draw %7.3f ms GPU %7.3f ms", (double(m_PaintTime - m_WaitForGPUTime)/10000.0), (double(m_WaitForGPUTime)/10000.0));
- else
+ } else {
strText.Format(L"Paint Time : Draw %7.3f ms", (double(m_PaintTime - m_WaitForGPUTime)/10000.0));
+ }
}
DrawText(rc, strText, 2);
OffsetRect (&rc, 0, TextHeight);
- if (bDetailedStats > 1)
- {
+ if (bDetailedStats > 1) {
strText.Format(L"Raster Status: Wait %7.3f ms Min %7.3f ms Max %7.3f ms", (double(m_RasterStatusWaitTime)/10000.0), (double(m_RasterStatusWaitTimeMin)/10000.0), (double(m_RasterStatusWaitTimeMax)/10000.0));
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
}
- if (bDetailedStats > 1)
- {
- if (m_bIsEVR)
+ if (bDetailedStats > 1) {
+ if (m_bIsEVR) {
strText.Format(L"Buffering : Buffered %3d Free %3d Current Surface %3d", m_nUsedBuffer, m_nNbDXSurface - m_nUsedBuffer, m_nCurSurface, m_nVMR9Surfaces, m_iVMR9Surface);
- else
+ } else {
strText.Format(L"Buffering : VMR9Surfaces %3d VMR9Surface %3d", m_nVMR9Surfaces, m_iVMR9Surface);
- }
- else
+ }
+ } else {
strText.Format(L"Buffered : %3d", m_nUsedBuffer);
+ }
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
- if (bDetailedStats > 1)
- {
+ if (bDetailedStats > 1) {
strText.Format(L"Video size : %d x %d (AR = %d : %d)", m_NativeVideoSize.cx, m_NativeVideoSize.cy, m_AspectRatio.cx, m_AspectRatio.cy);
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
- if (m_pVideoTexture[0] || m_pVideoSurface[0])
- {
+ if (m_pVideoTexture[0] || m_pVideoSurface[0]) {
D3DSURFACE_DESC desc;
- if (m_pVideoTexture[0])
+ if (m_pVideoTexture[0]) {
m_pVideoTexture[0]->GetLevelDesc(0, &desc);
- else if (m_pVideoSurface[0])
+ } else if (m_pVideoSurface[0]) {
m_pVideoSurface[0]->GetDesc(&desc);
+ }
- if (desc.Width != (UINT)m_NativeVideoSize.cx || desc.Height != (UINT)m_NativeVideoSize.cy)
- {
+ if (desc.Width != (UINT)m_NativeVideoSize.cx || desc.Height != (UINT)m_NativeVideoSize.cy) {
strText.Format(L"Texture size : %d x %d", desc.Width, desc.Height);
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
@@ -2269,8 +2174,7 @@ void CDX9AllocatorPresenter::DrawStats()
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
- if(m_D3D9Device != _T(""))
- {
+ if(m_D3D9Device != _T("")) {
strText = "Render device: " + m_D3D9Device;
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
@@ -2280,10 +2184,8 @@ void CDX9AllocatorPresenter::DrawStats()
DrawText(rc, strText, 1);
OffsetRect (&rc, 0, TextHeight);
- for (int i=0; i<6; i++)
- {
- if (m_strStatsMsg[i][0])
- {
+ for (int i=0; i<6; i++) {
+ if (m_strStatsMsg[i][0]) {
DrawText(rc, m_strStatsMsg[i], 1);
OffsetRect (&rc, 0, TextHeight);
}
@@ -2293,8 +2195,7 @@ void CDX9AllocatorPresenter::DrawStats()
OffsetRect(&rc, 0, TextHeight); // Extra "line feed"
}
- if (m_pLine && bDetailedStats)
- {
+ if (m_pLine && bDetailedStats) {
D3DXVECTOR2 Points[NB_JITTER];
int nIndex;
@@ -2310,44 +2211,43 @@ void CDX9AllocatorPresenter::DrawStats()
DrawRect(RGB(0,0,0), Alpha, CRect(StartX, StartY, StartX + DrawWidth, StartY + DrawHeight));
// === Jitter Graduation
-// m_pLine->SetWidth(2.2); // Width
-// m_pLine->SetAntialias(1);
+ // m_pLine->SetWidth(2.2); // Width
+ // m_pLine->SetAntialias(1);
m_pLine->SetWidth(2.5); // Width
m_pLine->SetAntialias(1);
-// m_pLine->SetGLLines(1);
+ // m_pLine->SetGLLines(1);
m_pLine->Begin();
- for (int i=10; i<250*ScaleY; i+= 10*ScaleY)
- {
+ for (int i=10; i<250*ScaleY; i+= 10*ScaleY) {
Points[0].x = (FLOAT)StartX;
Points[0].y = (FLOAT)(StartY + i);
Points[1].x = (FLOAT)(StartX + ((i-10)%40 ? 50 : 625 * ScaleX));
Points[1].y = (FLOAT)(StartY + i);
- if (i == 130) Points[1].x += 50;
+ if (i == 130) {
+ Points[1].x += 50;
+ }
m_pLine->Draw (Points, 2, D3DCOLOR_XRGB(100,100,255));
}
// === Jitter curve
- if (m_rtTimePerFrame)
- {
- for (int i=0; i<NB_JITTER; i++)
- {
+ if (m_rtTimePerFrame) {
+ for (int i=0; i<NB_JITTER; i++) {
nIndex = (m_nNextJitter+1+i) % NB_JITTER;
- if (nIndex < 0)
+ if (nIndex < 0) {
nIndex += NB_JITTER;
+ }
double Jitter = m_pllJitter[nIndex] - m_fJitterMean;
Points[i].x = (FLOAT)(StartX + (i*5*ScaleX+5));
Points[i].y = (FLOAT)(StartY + ((Jitter*ScaleY)/5000.0 + 125.0* ScaleY));
}
m_pLine->Draw (Points, NB_JITTER, D3DCOLOR_XRGB(255,100,100));
- if (m_bSyncStatsAvailable)
- {
- for (int i=0; i<NB_JITTER; i++)
- {
+ if (m_bSyncStatsAvailable) {
+ for (int i=0; i<NB_JITTER; i++) {
nIndex = (m_nNextSyncOffset+1+i) % NB_JITTER;
- if (nIndex < 0)
+ if (nIndex < 0) {
nIndex += NB_JITTER;
+ }
Points[i].x = (FLOAT)(StartX + (i*5*ScaleX+5));
Points[i].y = (FLOAT)(StartY + ((m_pllSyncOffset[nIndex]*ScaleY)/5000 + 125*ScaleY));
}
@@ -2372,23 +2272,24 @@ STDMETHODIMP CDX9AllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
m_pVideoSurface[m_nCurSurface]->GetDesc(&desc);
DWORD required = sizeof(BITMAPINFOHEADER) + (desc.Width * desc.Height * 32 >> 3);
- if(!lpDib)
- {
+ if(!lpDib) {
*size = required;
return S_OK;
}
- if(*size < required) return E_OUTOFMEMORY;
+ if(*size < required) {
+ return E_OUTOFMEMORY;
+ }
*size = required;
CComPtr<IDirect3DSurface9> pSurface = m_pVideoSurface[m_nCurSurface];
D3DLOCKED_RECT r;
- if(FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY)))
- {
+ if(FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY))) {
pSurface = NULL;
if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pSurface, NULL))
|| FAILED(hr = m_pD3DDev->GetRenderTargetData(m_pVideoSurface[m_nCurSurface], pSurface))
- || FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY)))
+ || FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY))) {
return hr;
+ }
}
BITMAPINFOHEADER* bih = (BITMAPINFOHEADER*)lpDib;
diff --git a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h
index c91bc9118..6d8bd84a3 100644
--- a/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/DX9AllocatorPresenter.h
@@ -35,269 +35,265 @@ extern bool g_bExternalSubtitleTime;
namespace DSObjects
{
-class CDX9AllocatorPresenter
- : public CDX9RenderingEngine
-{
-public:
- CCritSec m_VMR9AlphaBitmapLock;
- void UpdateAlphaBitmap();
-protected:
- UINT m_RefreshRate;
-
-// bool m_fVMRSyncFix;
- bool m_bAlternativeVSync;
- bool m_bCompositionEnabled;
- bool m_bIsEVR;
- int m_OrderedPaint;
- int m_VSyncMode;
- bool m_bDesktopCompositionDisabled;
- bool m_bIsFullscreen;
- bool m_bNeedCheckSample;
- DWORD m_MainThreadId;
-
- CRenderersSettings::CRendererSettingsEVR m_LastRendererSettings;
-
- HRESULT (__stdcall * m_pDwmIsCompositionEnabled)(__out BOOL* pfEnabled);
- HRESULT (__stdcall * m_pDwmEnableComposition)(UINT uCompositionAction);
-
- HMODULE m_hDWMAPI;
+ class CDX9AllocatorPresenter
+ : public CDX9RenderingEngine
+ {
+ public:
+ CCritSec m_VMR9AlphaBitmapLock;
+ void UpdateAlphaBitmap();
+ protected:
+ UINT m_RefreshRate;
+
+ // bool m_fVMRSyncFix;
+ bool m_bAlternativeVSync;
+ bool m_bCompositionEnabled;
+ bool m_bIsEVR;
+ int m_OrderedPaint;
+ int m_VSyncMode;
+ bool m_bDesktopCompositionDisabled;
+ bool m_bIsFullscreen;
+ bool m_bNeedCheckSample;
+ DWORD m_MainThreadId;
+
+ CRenderersSettings::CRendererSettingsEVR m_LastRendererSettings;
+
+ HRESULT (__stdcall * m_pDwmIsCompositionEnabled)(__out BOOL* pfEnabled);
+ HRESULT (__stdcall * m_pDwmEnableComposition)(UINT uCompositionAction);
+
+ HMODULE m_hDWMAPI;
+
+ HRESULT (__stdcall * m_pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex**);
+ HMODULE m_hD3D9;
+
+ CCritSec m_RenderLock;
+ CComPtr<IDirectDraw> m_pDirectDraw;
+
+ void LockD3DDevice() {
+ if (m_pD3DDev) {
+ _RTL_CRITICAL_SECTION *pCritSec = (_RTL_CRITICAL_SECTION *)((size_t)m_pD3DDev.p + sizeof(size_t));
+
+ if (!IsBadReadPtr(pCritSec, sizeof(*pCritSec)) && !IsBadWritePtr(pCritSec, sizeof(*pCritSec))
+ && !IsBadReadPtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo))) && !IsBadWritePtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo)))) {
+ if (pCritSec->DebugInfo->CriticalSection == pCritSec) {
+ EnterCriticalSection(pCritSec);
+ }
+ }
+ }
+ }
- HRESULT (__stdcall * m_pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex**);
- HMODULE m_hD3D9;
+ void UnlockD3DDevice() {
+ if (m_pD3DDev) {
+ _RTL_CRITICAL_SECTION *pCritSec = (_RTL_CRITICAL_SECTION *)((size_t)m_pD3DDev.p + sizeof(size_t));
- CCritSec m_RenderLock;
- CComPtr<IDirectDraw> m_pDirectDraw;
+ if (!IsBadReadPtr(pCritSec, sizeof(*pCritSec)) && !IsBadWritePtr(pCritSec, sizeof(*pCritSec))
+ && !IsBadReadPtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo))) && !IsBadWritePtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo)))) {
+ if (pCritSec->DebugInfo->CriticalSection == pCritSec) {
+ LeaveCriticalSection(pCritSec);
+ }
+ }
+ }
+ }
- void LockD3DDevice()
- {
- if (m_pD3DDev)
- {
- _RTL_CRITICAL_SECTION *pCritSec = (_RTL_CRITICAL_SECTION *)((size_t)m_pD3DDev.p + sizeof(size_t));
-
- if (!IsBadReadPtr(pCritSec, sizeof(*pCritSec)) && !IsBadWritePtr(pCritSec, sizeof(*pCritSec))
- && !IsBadReadPtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo))) && !IsBadWritePtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo))))
- {
- if (pCritSec->DebugInfo->CriticalSection == pCritSec)
- EnterCriticalSection(pCritSec);
+ CString m_D3DDevExError;
+ CComPtr<IDirect3DTexture9> m_pOSDTexture;
+ CComPtr<IDirect3DSurface9> m_pOSDSurface;
+ CComPtr<ID3DXLine> m_pLine;
+ CComPtr<ID3DXFont> m_pFont;
+ CComPtr<ID3DXSprite> m_pSprite;
+
+ bool SettingsNeedResetDevice();
+
+ virtual HRESULT CreateDevice(CString &_Error);
+ virtual HRESULT AllocSurfaces(D3DFORMAT Format = D3DFMT_A8R8G8B8);
+ virtual void DeleteSurfaces();
+
+ // Thread stuff
+ HANDLE m_hEvtQuit; // Stop rendering thread event
+ HANDLE m_hVSyncThread;
+ static DWORD WINAPI VSyncThreadStatic(LPVOID lpParam);
+ void VSyncThread();
+ void StartWorkerThreads();
+ void StopWorkerThreads();
+
+ LONGLONG m_LastAdapterCheck;
+ UINT GetAdapter(IDirect3D9 *pD3D, bool GetAdapter = false);
+ DWORD GetVertexProcessing();
+
+ bool GetVBlank(int &_ScanLine, int &_bInVBlank, bool _bMeasureTime);
+ bool WaitForVBlankRange(int &_RasterStart, int _RasterEnd, bool _bWaitIfInside, bool _bNeedAccurate, bool _bMeasure, bool &_bTakenLock);
+ bool WaitForVBlank(bool &_Waited, bool &_bTakenLock);
+ int GetVBlackPos();
+ void CalculateJitter(LONGLONG PerformanceCounter);
+ virtual void OnVBlankFinished(bool fAll, LONGLONG PerformanceCounter) {}
+
+ // Casimir666
+ typedef HRESULT (WINAPI * D3DXLoadSurfaceFromMemoryPtr)(
+ LPDIRECT3DSURFACE9 pDestSurface,
+ CONST PALETTEENTRY* pDestPalette,
+ CONST RECT* pDestRect,
+ LPCVOID pSrcMemory,
+ D3DFORMAT SrcFormat,
+ UINT SrcPitch,
+ CONST PALETTEENTRY* pSrcPalette,
+ CONST RECT* pSrcRect,
+ DWORD Filter,
+ D3DCOLOR ColorKey);
+
+ typedef HRESULT (WINAPI* D3DXCreateLinePtr) (LPDIRECT3DDEVICE9 pDevice, LPD3DXLINE* ppLine);
+
+ typedef HRESULT (WINAPI* D3DXCreateFontPtr)(
+ LPDIRECT3DDEVICE9 pDevice,
+ int Height,
+ UINT Width,
+ UINT Weight,
+ UINT MipLevels,
+ bool Italic,
+ DWORD CharSet,
+ DWORD OutputPrecision,
+ DWORD Quality,
+ DWORD PitchAndFamily,
+ LPCWSTR pFaceName,
+ LPD3DXFONT* ppFont);
+
+
+ void DrawText(const RECT &rc, const CString &strText, int _Priority);
+ void DrawStats();
+ virtual void OnResetDevice() {};
+ void SendResetRequest();
+
+ double GetFrameTime();
+ double GetFrameRate();
+
+
+ int m_nTearingPos;
+ VMR9AlphaBitmap m_VMR9AlphaBitmap;
+ CAutoVectorPtr<BYTE> m_VMR9AlphaBitmapData;
+ CRect m_VMR9AlphaBitmapRect;
+ int m_VMR9AlphaBitmapWidthBytes;
+
+ D3DXLoadSurfaceFromMemoryPtr m_pD3DXLoadSurfaceFromMemory;
+ D3DXCreateLinePtr m_pD3DXCreateLine;
+ D3DXCreateFontPtr m_pD3DXCreateFont;
+ HRESULT (__stdcall *m_pD3DXCreateSprite)(LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE * ppSprite);
+
+
+
+ int m_nVMR9Surfaces; // Total number of DX Surfaces
+ int m_iVMR9Surface;
+ long m_nUsedBuffer;
+
+ double m_fAvrFps; // Estimate the real FPS
+ double m_fJitterStdDev; // Estimate the Jitter std dev
+ double m_fJitterMean;
+ double m_fSyncOffsetStdDev;
+ double m_fSyncOffsetAvr;
+ double m_DetectedRefreshRate;
+
+ CCritSec m_RefreshRateLock;
+ double m_DetectedRefreshTime;
+ double m_DetectedRefreshTimePrim;
+ double m_DetectedScanlineTime;
+ double m_DetectedScanlineTimePrim;
+ double m_DetectedScanlinesPerFrame;
+
+ bool SetCurrentDisplayMode();
+
+ double GetRefreshRate() {
+ if (m_DetectedRefreshRate) {
+ return m_DetectedRefreshRate;
}
+ return m_RefreshRate;
}
- }
- void UnlockD3DDevice()
- {
- if (m_pD3DDev)
- {
- _RTL_CRITICAL_SECTION *pCritSec = (_RTL_CRITICAL_SECTION *)((size_t)m_pD3DDev.p + sizeof(size_t));
-
- if (!IsBadReadPtr(pCritSec, sizeof(*pCritSec)) && !IsBadWritePtr(pCritSec, sizeof(*pCritSec))
- && !IsBadReadPtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo))) && !IsBadWritePtr(pCritSec->DebugInfo, sizeof(*(pCritSec->DebugInfo))))
- {
- if (pCritSec->DebugInfo->CriticalSection == pCritSec)
- LeaveCriticalSection(pCritSec);
+ LONG GetScanLines() {
+ if (m_DetectedRefreshRate) {
+ return m_DetectedScanlinesPerFrame;
}
+ return m_ScreenSize.cy;
}
- }
-
- CString m_D3DDevExError;
- CComPtr<IDirect3DTexture9> m_pOSDTexture;
- CComPtr<IDirect3DSurface9> m_pOSDSurface;
- CComPtr<ID3DXLine> m_pLine;
- CComPtr<ID3DXFont> m_pFont;
- CComPtr<ID3DXSprite> m_pSprite;
-
- bool SettingsNeedResetDevice();
-
- virtual HRESULT CreateDevice(CString &_Error);
- virtual HRESULT AllocSurfaces(D3DFORMAT Format = D3DFMT_A8R8G8B8);
- virtual void DeleteSurfaces();
-
- // Thread stuff
- HANDLE m_hEvtQuit; // Stop rendering thread event
- HANDLE m_hVSyncThread;
- static DWORD WINAPI VSyncThreadStatic(LPVOID lpParam);
- void VSyncThread();
- void StartWorkerThreads();
- void StopWorkerThreads();
-
- LONGLONG m_LastAdapterCheck;
- UINT GetAdapter(IDirect3D9 *pD3D, bool GetAdapter = false);
- DWORD GetVertexProcessing();
-
- bool GetVBlank(int &_ScanLine, int &_bInVBlank, bool _bMeasureTime);
- bool WaitForVBlankRange(int &_RasterStart, int _RasterEnd, bool _bWaitIfInside, bool _bNeedAccurate, bool _bMeasure, bool &_bTakenLock);
- bool WaitForVBlank(bool &_Waited, bool &_bTakenLock);
- int GetVBlackPos();
- void CalculateJitter(LONGLONG PerformanceCounter);
- virtual void OnVBlankFinished(bool fAll, LONGLONG PerformanceCounter) {}
-
- // Casimir666
- typedef HRESULT (WINAPI * D3DXLoadSurfaceFromMemoryPtr)(
- LPDIRECT3DSURFACE9 pDestSurface,
- CONST PALETTEENTRY* pDestPalette,
- CONST RECT* pDestRect,
- LPCVOID pSrcMemory,
- D3DFORMAT SrcFormat,
- UINT SrcPitch,
- CONST PALETTEENTRY* pSrcPalette,
- CONST RECT* pSrcRect,
- DWORD Filter,
- D3DCOLOR ColorKey);
-
- typedef HRESULT (WINAPI* D3DXCreateLinePtr) (LPDIRECT3DDEVICE9 pDevice, LPD3DXLINE* ppLine);
-
- typedef HRESULT (WINAPI* D3DXCreateFontPtr)(
- LPDIRECT3DDEVICE9 pDevice,
- int Height,
- UINT Width,
- UINT Weight,
- UINT MipLevels,
- bool Italic,
- DWORD CharSet,
- DWORD OutputPrecision,
- DWORD Quality,
- DWORD PitchAndFamily,
- LPCWSTR pFaceName,
- LPD3DXFONT* ppFont);
-
-
- void DrawText(const RECT &rc, const CString &strText, int _Priority);
- void DrawStats();
- virtual void OnResetDevice() {};
- void SendResetRequest();
-
- double GetFrameTime();
- double GetFrameRate();
-
-
- int m_nTearingPos;
- VMR9AlphaBitmap m_VMR9AlphaBitmap;
- CAutoVectorPtr<BYTE> m_VMR9AlphaBitmapData;
- CRect m_VMR9AlphaBitmapRect;
- int m_VMR9AlphaBitmapWidthBytes;
-
- D3DXLoadSurfaceFromMemoryPtr m_pD3DXLoadSurfaceFromMemory;
- D3DXCreateLinePtr m_pD3DXCreateLine;
- D3DXCreateFontPtr m_pD3DXCreateFont;
- HRESULT (__stdcall *m_pD3DXCreateSprite)(LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE * ppSprite);
-
-
-
- int m_nVMR9Surfaces; // Total number of DX Surfaces
- int m_iVMR9Surface;
- long m_nUsedBuffer;
-
- double m_fAvrFps; // Estimate the real FPS
- double m_fJitterStdDev; // Estimate the Jitter std dev
- double m_fJitterMean;
- double m_fSyncOffsetStdDev;
- double m_fSyncOffsetAvr;
- double m_DetectedRefreshRate;
-
- CCritSec m_RefreshRateLock;
- double m_DetectedRefreshTime;
- double m_DetectedRefreshTimePrim;
- double m_DetectedScanlineTime;
- double m_DetectedScanlineTimePrim;
- double m_DetectedScanlinesPerFrame;
-
- bool SetCurrentDisplayMode();
-
- double GetRefreshRate()
- {
- if (m_DetectedRefreshRate)
- return m_DetectedRefreshRate;
- return m_RefreshRate;
- }
- LONG GetScanLines()
- {
- if (m_DetectedRefreshRate)
- return m_DetectedScanlinesPerFrame;
- return m_ScreenSize.cy;
- }
-
- double m_ldDetectedRefreshRateList[100];
- double m_ldDetectedScanlineRateList[100];
- int m_DetectedRefreshRatePos;
- bool m_bSyncStatsAvailable;
- LONGLONG m_pllJitter [NB_JITTER]; // Jitter buffer for stats
- LONGLONG m_pllSyncOffset [NB_JITTER]; // Jitter buffer for stats
- LONGLONG m_llLastPerf;
- LONGLONG m_JitterStdDev;
- LONGLONG m_MaxJitter;
- LONGLONG m_MinJitter;
- LONGLONG m_MaxSyncOffset;
- LONGLONG m_MinSyncOffset;
- int m_nNextJitter;
- int m_nNextSyncOffset;
- REFERENCE_TIME m_rtTimePerFrame;
- double m_DetectedFrameRate;
- double m_DetectedFrameTime;
- double m_DetectedFrameTimeStdDev;
- bool m_DetectedLock;
- LONGLONG m_DetectedFrameTimeHistory[60];
- double m_DetectedFrameTimeHistoryHistory[500];
- int m_DetectedFrameTimePos;
- int m_bInterlaced;
-
- double m_TextScale;
-
- int m_VBlankEndWait;
- int m_VBlankStartWait;
- LONGLONG m_VBlankWaitTime;
- LONGLONG m_VBlankLockTime;
- int m_VBlankMin;
- int m_VBlankMinCalc;
- int m_VBlankMax;
- int m_VBlankEndPresent;
- LONGLONG m_VBlankStartMeasureTime;
- int m_VBlankStartMeasure;
-
- LONGLONG m_PresentWaitTime;
- LONGLONG m_PresentWaitTimeMin;
- LONGLONG m_PresentWaitTimeMax;
-
- LONGLONG m_PaintTime;
- LONGLONG m_PaintTimeMin;
- LONGLONG m_PaintTimeMax;
-
- LONGLONG m_WaitForGPUTime;
-
- LONGLONG m_RasterStatusWaitTime;
- LONGLONG m_RasterStatusWaitTimeMin;
- LONGLONG m_RasterStatusWaitTimeMax;
- LONGLONG m_RasterStatusWaitTimeMaxCalc;
-
- double m_ClockDiffCalc;
- double m_ClockDiffPrim;
- double m_ClockDiff;
-
- double m_TimeChangeHistory[100];
- double m_ClockChangeHistory[100];
- int m_ClockTimeChangeHistoryPos;
- double m_ModeratedTimeSpeed;
- double m_ModeratedTimeSpeedPrim;
- double m_ModeratedTimeSpeedDiff;
-
- bool m_bCorrectedFrameTime;
- int m_FrameTimeCorrection;
- LONGLONG m_LastFrameDuration;
- LONGLONG m_LastSampleTime;
-
- CString m_strStatsMsg[10];
-
- CString m_D3D9Device;
-
-public:
- CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, bool bIsEVR, CString &_Error);
- ~CDX9AllocatorPresenter();
-
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
- STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
- STDMETHODIMP SetPixelShader2(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace);
- STDMETHODIMP_(bool) ResetDevice();
-};
+ double m_ldDetectedRefreshRateList[100];
+ double m_ldDetectedScanlineRateList[100];
+ int m_DetectedRefreshRatePos;
+ bool m_bSyncStatsAvailable;
+ LONGLONG m_pllJitter [NB_JITTER]; // Jitter buffer for stats
+ LONGLONG m_pllSyncOffset [NB_JITTER]; // Jitter buffer for stats
+ LONGLONG m_llLastPerf;
+ LONGLONG m_JitterStdDev;
+ LONGLONG m_MaxJitter;
+ LONGLONG m_MinJitter;
+ LONGLONG m_MaxSyncOffset;
+ LONGLONG m_MinSyncOffset;
+ int m_nNextJitter;
+ int m_nNextSyncOffset;
+ REFERENCE_TIME m_rtTimePerFrame;
+ double m_DetectedFrameRate;
+ double m_DetectedFrameTime;
+ double m_DetectedFrameTimeStdDev;
+ bool m_DetectedLock;
+ LONGLONG m_DetectedFrameTimeHistory[60];
+ double m_DetectedFrameTimeHistoryHistory[500];
+ int m_DetectedFrameTimePos;
+ int m_bInterlaced;
+
+ double m_TextScale;
+
+ int m_VBlankEndWait;
+ int m_VBlankStartWait;
+ LONGLONG m_VBlankWaitTime;
+ LONGLONG m_VBlankLockTime;
+ int m_VBlankMin;
+ int m_VBlankMinCalc;
+ int m_VBlankMax;
+ int m_VBlankEndPresent;
+ LONGLONG m_VBlankStartMeasureTime;
+ int m_VBlankStartMeasure;
+
+ LONGLONG m_PresentWaitTime;
+ LONGLONG m_PresentWaitTimeMin;
+ LONGLONG m_PresentWaitTimeMax;
+
+ LONGLONG m_PaintTime;
+ LONGLONG m_PaintTimeMin;
+ LONGLONG m_PaintTimeMax;
+
+ LONGLONG m_WaitForGPUTime;
+
+ LONGLONG m_RasterStatusWaitTime;
+ LONGLONG m_RasterStatusWaitTimeMin;
+ LONGLONG m_RasterStatusWaitTimeMax;
+ LONGLONG m_RasterStatusWaitTimeMaxCalc;
+
+ double m_ClockDiffCalc;
+ double m_ClockDiffPrim;
+ double m_ClockDiff;
+
+ double m_TimeChangeHistory[100];
+ double m_ClockChangeHistory[100];
+ int m_ClockTimeChangeHistoryPos;
+ double m_ModeratedTimeSpeed;
+ double m_ModeratedTimeSpeedPrim;
+ double m_ModeratedTimeSpeedDiff;
+
+ bool m_bCorrectedFrameTime;
+ int m_FrameTimeCorrection;
+ LONGLONG m_LastFrameDuration;
+ LONGLONG m_LastSampleTime;
+
+ CString m_strStatsMsg[10];
+
+ CString m_D3D9Device;
+
+ public:
+ CDX9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, bool bIsEVR, CString &_Error);
+ ~CDX9AllocatorPresenter();
+
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
+ STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
+ STDMETHODIMP SetPixelShader2(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace);
+ STDMETHODIMP_(bool) ResetDevice();
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp b/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp
index 7dfabc7f5..7c34f1703 100644
--- a/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp
+++ b/src/filters/renderer/VideoRenderers/DX9RenderingEngine.cpp
@@ -29,17 +29,14 @@
#pragma pack(push, 1)
template<int texcoords>
-struct MYD3DVERTEX
-{
+struct MYD3DVERTEX {
float x, y, z, rhw;
- struct
- {
+ struct {
float u, v;
} t[texcoords];
};
template<>
-struct MYD3DVERTEX<0>
-{
+struct MYD3DVERTEX<0> {
float x, y, z, rhw;
DWORD Diffuse;
};
@@ -50,19 +47,16 @@ static void AdjustQuad(MYD3DVERTEX<texcoords>* v, double dx, double dy)
{
double offset = 0.5;
- for(int i = 0; i < 4; i++)
- {
+ for(int i = 0; i < 4; i++) {
v[i].x -= offset;
v[i].y -= offset;
- for(int j = 0; j < max(texcoords-1, 1); j++)
- {
+ for(int j = 0; j < max(texcoords-1, 1); j++) {
v[i].t[j].u -= offset*dx;
v[i].t[j].v -= offset*dy;
}
- if(texcoords > 1)
- {
+ if(texcoords > 1) {
v[i].t[texcoords-1].u -= offset;
v[i].t[texcoords-1].v -= offset;
}
@@ -72,39 +66,39 @@ static void AdjustQuad(MYD3DVERTEX<texcoords>* v, double dx, double dy)
template<int texcoords>
static HRESULT TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[4], D3DTEXTUREFILTERTYPE filter = D3DTEXF_LINEAR)
{
- if(!pD3DDev)
+ if(!pD3DDev) {
return E_POINTER;
+ }
DWORD FVF = 0;
- switch(texcoords)
- {
- case 1:
- FVF = D3DFVF_TEX1;
- break;
- case 2:
- FVF = D3DFVF_TEX2;
- break;
- case 3:
- FVF = D3DFVF_TEX3;
- break;
- case 4:
- FVF = D3DFVF_TEX4;
- break;
- case 5:
- FVF = D3DFVF_TEX5;
- break;
- case 6:
- FVF = D3DFVF_TEX6;
- break;
- case 7:
- FVF = D3DFVF_TEX7;
- break;
- case 8:
- FVF = D3DFVF_TEX8;
- break;
- default:
- return E_FAIL;
+ switch(texcoords) {
+ case 1:
+ FVF = D3DFVF_TEX1;
+ break;
+ case 2:
+ FVF = D3DFVF_TEX2;
+ break;
+ case 3:
+ FVF = D3DFVF_TEX3;
+ break;
+ case 4:
+ FVF = D3DFVF_TEX4;
+ break;
+ case 5:
+ FVF = D3DFVF_TEX5;
+ break;
+ case 6:
+ FVF = D3DFVF_TEX6;
+ break;
+ case 7:
+ FVF = D3DFVF_TEX7;
+ break;
+ case 8:
+ FVF = D3DFVF_TEX8;
+ break;
+ default:
+ return E_FAIL;
}
HRESULT hr;
@@ -118,8 +112,7 @@ static HRESULT TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[4]
hr = pD3DDev->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
hr = pD3DDev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_RED);
- for(int i = 0; i < texcoords; i++)
- {
+ for(int i = 0; i < texcoords; i++) {
hr = pD3DDev->SetSamplerState(i, D3DSAMP_MAGFILTER, filter);
hr = pD3DDev->SetSamplerState(i, D3DSAMP_MINFILTER, filter);
hr = pD3DDev->SetSamplerState(i, D3DSAMP_MIPFILTER, filter);
@@ -140,8 +133,7 @@ static HRESULT TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[4]
//
- for(int i = 0; i < texcoords; i++)
- {
+ for(int i = 0; i < texcoords; i++) {
pD3DDev->SetTexture(i, NULL);
}
@@ -162,8 +154,7 @@ CDX9RenderingEngine::CDX9RenderingEngine(HWND hWnd, HRESULT& hr, CString *_pErro
HINSTANCE hDll = GetRenderersData()->GetD3X9Dll();
m_bD3DX = hDll != NULL;
- if (m_bD3DX)
- {
+ if (m_bD3DX) {
(FARPROC&)m_pD3DXFloat32To16Array = GetProcAddress(hDll, "D3DXFloat32To16Array");
}
}
@@ -176,8 +167,9 @@ void CDX9RenderingEngine::InitRenderingEngine()
// Detect supported StrechRect filter
m_StretchRectFilter = D3DTEXF_NONE;
if((m_Caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MINFLINEAR)
- && (m_Caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR))
+ && (m_Caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR)) {
m_StretchRectFilter = D3DTEXF_LINEAR;
+ }
// Detect FP16 support
renderersData->m_bFP16Support = true;
@@ -218,26 +210,24 @@ void CDX9RenderingEngine::CleanupRenderingEngine()
{
m_pPSC.Free();
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
m_pResizerPixelShaders[i] = NULL;
+ }
CleanupFinalPass();
POSITION pos = m_pCustomScreenSpacePixelShaders.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CExternalPixelShader &Shader = m_pCustomScreenSpacePixelShaders.GetNext(pos);
Shader.m_pPixelShader = NULL;
}
pos = m_pCustomPixelShaders.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CExternalPixelShader &Shader = m_pCustomPixelShaders.GetNext(pos);
Shader.m_pPixelShader = NULL;
}
- for (int i = 0; i < 2; i++)
- {
+ for (int i = 0; i < 2; i++) {
m_pTemporaryVideoTextures[i] = NULL;
m_pTemporaryScreenSpaceTextures[i] = NULL;
}
@@ -252,48 +242,46 @@ HRESULT CDX9RenderingEngine::CreateVideoSurfaces(D3DFORMAT format)
FreeVideoSurfaces();
// Free previously allocated temporary video textures, because the native video size might have been changed!
- for (int i = 0; i < 2; i++)
+ for (int i = 0; i < 2; i++) {
m_pTemporaryVideoTextures[i] = NULL;
+ }
m_SurfaceType = format;
- if (settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
- {
+ if (settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
int nTexturesNeeded = settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D ? m_nNbDXSurface : 1;
- for (int i = 0; i < nTexturesNeeded; i++)
- {
+ for (int i = 0; i < nTexturesNeeded; i++) {
if(FAILED(hr = m_pD3DDev->CreateTexture(
m_NativeVideoSize.cx, m_NativeVideoSize.cy, 1,
D3DUSAGE_RENDERTARGET, format,
- D3DPOOL_DEFAULT, &m_pVideoTexture[i], NULL)))
+ D3DPOOL_DEFAULT, &m_pVideoTexture[i], NULL))) {
return hr;
+ }
- if (FAILED(hr = m_pVideoTexture[i]->GetSurfaceLevel(0, &m_pVideoSurface[i])))
+ if (FAILED(hr = m_pVideoTexture[i]->GetSurfaceLevel(0, &m_pVideoSurface[i]))) {
return hr;
+ }
}
- if (settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D)
- {
+ if (settings.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D) {
m_RenderingPath = RENDERING_PATH_STRETCHRECT;
- for (int i = 0; i < m_nNbDXSurface; i++)
+ for (int i = 0; i < m_nNbDXSurface; i++) {
m_pVideoTexture[i] = NULL;
- }
- else
- {
+ }
+ } else {
m_RenderingPath = RENDERING_PATH_DRAW;
}
- }
- else
- {
+ } else {
m_RenderingPath = RENDERING_PATH_STRETCHRECT;
if (FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(
m_NativeVideoSize.cx, m_NativeVideoSize.cy,
format,
- D3DPOOL_DEFAULT, &m_pVideoSurface[m_nCurSurface], NULL)))
+ D3DPOOL_DEFAULT, &m_pVideoSurface[m_nCurSurface], NULL))) {
return hr;
+ }
}
hr = m_pD3DDev->ColorFill(m_pVideoSurface[m_nCurSurface], NULL, 0);
@@ -303,8 +291,7 @@ HRESULT CDX9RenderingEngine::CreateVideoSurfaces(D3DFORMAT format)
void CDX9RenderingEngine::FreeVideoSurfaces()
{
- for (int i = 0; i < m_nNbDXSurface; i++)
- {
+ for (int i = 0; i < m_nNbDXSurface; i++) {
m_pVideoTexture[i] = NULL;
m_pVideoSurface[i] = NULL;
}
@@ -312,13 +299,15 @@ void CDX9RenderingEngine::FreeVideoSurfaces()
HRESULT CDX9RenderingEngine::RenderVideo(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect)
{
- if (destRect.IsRectEmpty())
+ if (destRect.IsRectEmpty()) {
return S_OK;
+ }
- if (m_RenderingPath == RENDERING_PATH_DRAW)
+ if (m_RenderingPath == RENDERING_PATH_DRAW) {
return RenderVideoDrawPath(pRenderTarget, srcRect, destRect);
- else
+ } else {
return RenderVideoStretchRectPath(pRenderTarget, srcRect, destRect);
+ }
}
HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect)
@@ -326,8 +315,9 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
HRESULT hr;
// Return if the video texture is not initialized
- if (m_pVideoTexture[m_nCurSurface] == 0)
+ if (m_pVideoTexture[m_nCurSurface] == 0) {
return S_OK;
+ }
CRenderersSettings& settings = GetRenderersSettings();
@@ -340,31 +330,31 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
int screenSpacePassCount = 0;
DWORD iDX9Resizer = settings.iDX9Resizer;
- if (m_bD3DX)
- {
+ if (m_bD3DX) {
// Final pass. Must be initialized first!
hr = InitFinalPass();
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
bFinalPass = m_bFinalPass;
- else
+ } else {
bFinalPass = false;
+ }
- if (bFinalPass)
+ if (bFinalPass) {
++screenSpacePassCount;
+ }
// Resizers
float bicubicA = 0;
- switch (iDX9Resizer)
- {
- case 3:
- bicubicA = -0.60f;
- break;
- case 4:
- bicubicA = -0.751f;
- break; // FIXME : 0.75 crash recent D3D, or eat CPU
- case 5:
- bicubicA = -1.00f;
- break;
+ switch (iDX9Resizer) {
+ case 3:
+ bicubicA = -0.60f;
+ break;
+ case 4:
+ bicubicA = -0.751f;
+ break; // FIXME : 0.75 crash recent D3D, or eat CPU
+ case 5:
+ bicubicA = -1.00f;
+ break;
}
hr = InitResizers(bicubicA);
@@ -374,18 +364,18 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
// Custom screen space pixel shaders
bCustomScreenSpacePixelShaders = !m_pCustomScreenSpacePixelShaders.IsEmpty();
- if (bCustomScreenSpacePixelShaders)
+ if (bCustomScreenSpacePixelShaders) {
screenSpacePassCount += m_pCustomScreenSpacePixelShaders.GetCount();
+ }
// Custom pixel shaders
bCustomPixelShaders = !m_pCustomPixelShaders.IsEmpty();
hr = InitTemporaryVideoTextures(min(m_pCustomPixelShaders.GetCount(), 2));
- if (FAILED(hr))
+ if (FAILED(hr)) {
bCustomPixelShaders = false;
- }
- else
- {
+ }
+ } else {
bCustomPixelShaders = false;
bResizerShaders = false;
bCustomScreenSpacePixelShaders = false;
@@ -393,8 +383,7 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
}
hr = InitScreenSpacePipeline(screenSpacePassCount, pRenderTarget);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
bCustomScreenSpacePixelShaders = false;
bFinalPass = false;
}
@@ -402,30 +391,29 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
// Apply the custom pixel shaders if there are any. Result: pVideoTexture
CComPtr<IDirect3DTexture9> pVideoTexture = m_pVideoTexture[m_nCurSurface];
- if (bCustomPixelShaders)
- {
+ if (bCustomPixelShaders) {
static __int64 counter = 0;
static long start = clock();
long stop = clock();
long diff = stop - start;
- if(diff >= 10*60*CLOCKS_PER_SEC) start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ if(diff >= 10*60*CLOCKS_PER_SEC) {
+ start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ }
#if 1
D3DSURFACE_DESC desc;
m_pVideoTexture[m_nCurSurface]->GetLevelDesc(0, &desc);
- float fConstData[][4] =
- {
+ float fConstData[][4] = {
{(float)desc.Width, (float)desc.Height, (float)(counter++), (float)diff / CLOCKS_PER_SEC},
{1.0f / desc.Width, 1.0f / desc.Height, 0, 0},
};
#else
CSize VideoSize = GetVisibleVideoSize();
- float fConstData[][4] =
- {
+ float fConstData[][4] = {
{(float)VideoSize.cx, (float)VideoSize.cy, (float)(counter++), (float)diff / CLOCKS_PER_SEC},
{1.0f / VideoSize.cx, 1.0f / VideoSize.cy, 0, 0},
};
@@ -438,24 +426,21 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
bool first = true;
POSITION pos = m_pCustomPixelShaders.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CComPtr<IDirect3DSurface9> pTemporarySurface;
hr = m_pTemporaryVideoTextures[dest]->GetSurfaceLevel(0, &pTemporarySurface);
hr = m_pD3DDev->SetRenderTarget(0, pTemporarySurface);
CExternalPixelShader &Shader = m_pCustomPixelShaders.GetNext(pos);
- if (!Shader.m_pPixelShader)
+ if (!Shader.m_pPixelShader) {
Shader.Compile(m_pPSC);
+ }
hr = m_pD3DDev->SetPixelShader(Shader.m_pPixelShader);
- if (first)
- {
+ if (first) {
TextureCopy(m_pVideoTexture[m_nCurSurface]);
first = false;
- }
- else
- {
+ } else {
TextureCopy(m_pTemporaryVideoTextures[src]);
}
@@ -471,40 +456,36 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
hr = BeginScreenSpacePass();
- if (m_ScreenSpacePassCount > 0)
+ if (m_ScreenSpacePassCount > 0) {
hr = m_pD3DDev->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0);
+ }
- if (srcRect.Size() != destRect.Size())
- {
- if (iDX9Resizer == 0 || iDX9Resizer == 1 || !bResizerShaders)
- {
+ if (srcRect.Size() != destRect.Size()) {
+ if (iDX9Resizer == 0 || iDX9Resizer == 1 || !bResizerShaders) {
D3DTEXTUREFILTERTYPE Filter = iDX9Resizer == 0 ? D3DTEXF_POINT : D3DTEXF_LINEAR;
hr = TextureResize(pVideoTexture, dst, Filter, srcRect);
- }
- else if (iDX9Resizer == 2)
- {
+ } else if (iDX9Resizer == 2) {
hr = TextureResizeBilinear(pVideoTexture, dst, srcRect);
- }
- else if (iDX9Resizer >= 3)
- {
+ } else if (iDX9Resizer >= 3) {
hr = TextureResizeBicubic1pass(pVideoTexture, dst, srcRect);
}
+ } else {
+ hr = TextureResize(pVideoTexture, dst, D3DTEXF_POINT, srcRect);
}
- else hr = TextureResize(pVideoTexture, dst, D3DTEXF_POINT, srcRect);
// Apply the custom screen size pixel shaders
- if (bCustomScreenSpacePixelShaders)
- {
+ if (bCustomScreenSpacePixelShaders) {
static __int64 counter = 555;
static long start = clock() + 333;
long stop = clock() + 333;
long diff = stop - start;
- if (diff >= 10*60*CLOCKS_PER_SEC) start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ if (diff >= 10*60*CLOCKS_PER_SEC) {
+ start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ }
- float fConstData[][4] =
- {
+ float fConstData[][4] = {
{(float)m_TemporaryScreenSpaceTextureSize.cx, (float)m_TemporaryScreenSpaceTextureSize.cy, (float)(counter++), (float)diff / CLOCKS_PER_SEC},
{1.0f / m_TemporaryScreenSpaceTextureSize.cx, 1.0f / m_TemporaryScreenSpaceTextureSize.cy, 0, 0},
};
@@ -512,21 +493,20 @@ HRESULT CDX9RenderingEngine::RenderVideoDrawPath(IDirect3DSurface9* pRenderTarge
hr = m_pD3DDev->SetPixelShaderConstantF(0, (float*)fConstData, countof(fConstData));
POSITION pos = m_pCustomScreenSpacePixelShaders.GetHeadPosition();
- while (pos)
- {
+ while (pos) {
BeginScreenSpacePass();
CExternalPixelShader &Shader = m_pCustomScreenSpacePixelShaders.GetNext(pos);
- if (!Shader.m_pPixelShader)
+ if (!Shader.m_pPixelShader) {
Shader.Compile(m_pPSC);
+ }
hr = m_pD3DDev->SetPixelShader(Shader.m_pPixelShader);
TextureCopy(m_pTemporaryScreenSpaceTextures[m_ScreenSpacePassSrc]);
}
}
// Final pass
- if (bFinalPass)
- {
+ if (bFinalPass) {
hr = BeginScreenSpacePass();
hr = FinalPass(m_pTemporaryScreenSpaceTextures[m_ScreenSpacePassSrc]);
}
@@ -541,8 +521,9 @@ HRESULT CDX9RenderingEngine::RenderVideoStretchRectPath(IDirect3DSurface9* pRend
HRESULT hr;
// Return if the render target or the video surface is not initialized
- if (pRenderTarget == 0 || m_pVideoSurface[m_nCurSurface] == 0)
+ if (pRenderTarget == 0 || m_pVideoSurface[m_nCurSurface] == 0) {
return S_OK;
+ }
CRect rSrcVid(srcRect);
CRect rDstVid(destRect);
@@ -562,32 +543,28 @@ HRESULT CDX9RenderingEngine::InitTemporaryVideoTextures(int count)
{
HRESULT hr = S_OK;
- for (int i = 0; i < count; i++)
- {
- if (m_pTemporaryVideoTextures[i] == NULL)
- {
+ for (int i = 0; i < count; i++) {
+ if (m_pTemporaryVideoTextures[i] == NULL) {
D3DFORMAT format;
- if (m_bFullFloatingPointProcessing)
- {
+ if (m_bFullFloatingPointProcessing) {
format = D3DFMT_A16B16G16R16F;
- }
- else
- {
- if (m_bHighColorResolution || m_bForceInputHighColorResolution)
+ } else {
+ if (m_bHighColorResolution || m_bForceInputHighColorResolution) {
format = D3DFMT_A2R10G10B10;
- else
+ } else {
format = D3DFMT_A8R8G8B8;
+ }
}
hr = m_pD3DDev->CreateTexture(
m_NativeVideoSize.cx, m_NativeVideoSize.cy, 1, D3DUSAGE_RENDERTARGET, format,
D3DPOOL_DEFAULT, &m_pTemporaryVideoTextures[i], NULL);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
// Free all textures
- for (int j = 0; j < 2; j++)
+ for (int j = 0; j < 2; j++) {
m_pTemporaryVideoTextures[j] = NULL;
+ }
return hr;
}
@@ -595,8 +572,9 @@ HRESULT CDX9RenderingEngine::InitTemporaryVideoTextures(int count)
}
// Free unnecessary textures
- for (int i = count; i < 2; i++)
+ for (int i = count; i < 2; i++) {
m_pTemporaryVideoTextures[i] = NULL;
+ }
return hr;
}
@@ -611,8 +589,9 @@ HRESULT CDX9RenderingEngine::InitScreenSpacePipeline(int passCount, IDirect3DSur
HRESULT hr = InitTemporaryScreenSpaceTextures(min(passCount - 1, 2));
// If the initialized have failed, disable the pipeline
- if (FAILED(hr))
+ if (FAILED(hr)) {
m_ScreenSpacePassCount = 1;
+ }
return hr;
}
@@ -621,35 +600,31 @@ HRESULT CDX9RenderingEngine::InitTemporaryScreenSpaceTextures(int count)
{
HRESULT hr = S_OK;
- for (int i = 0; i < count; i++)
- {
- if (m_pTemporaryScreenSpaceTextures[i] == NULL)
- {
+ for (int i = 0; i < count; i++) {
+ if (m_pTemporaryScreenSpaceTextures[i] == NULL) {
m_TemporaryScreenSpaceTextureSize = CSize(min(m_ScreenSize.cx, (int)m_Caps.MaxTextureWidth),
- min(max(m_ScreenSize.cy, m_NativeVideoSize.cy), (int)m_Caps.MaxTextureHeight));
+ min(max(m_ScreenSize.cy, m_NativeVideoSize.cy), (int)m_Caps.MaxTextureHeight));
D3DFORMAT format;
- if (m_bFullFloatingPointProcessing)
- {
+ if (m_bFullFloatingPointProcessing) {
format = D3DFMT_A16B16G16R16F;
- }
- else
- {
- if (m_bHighColorResolution || m_bForceInputHighColorResolution)
+ } else {
+ if (m_bHighColorResolution || m_bForceInputHighColorResolution) {
format = D3DFMT_A2R10G10B10;
- else
+ } else {
format = D3DFMT_A8R8G8B8;
+ }
}
hr = m_pD3DDev->CreateTexture(
m_TemporaryScreenSpaceTextureSize.cx, m_TemporaryScreenSpaceTextureSize.cy, 1, D3DUSAGE_RENDERTARGET, format,
D3DPOOL_DEFAULT, &m_pTemporaryScreenSpaceTextures[i], NULL);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
// Free all textures
- for (int j = 0; j < 2; j++)
+ for (int j = 0; j < 2; j++) {
m_pTemporaryScreenSpaceTextures[j] = NULL;
+ }
return hr;
}
@@ -657,8 +632,9 @@ HRESULT CDX9RenderingEngine::InitTemporaryScreenSpaceTextures(int count)
}
// Free unnecessary textures
- for (int i = count; i < 2; i++)
+ for (int i = count; i < 2; i++) {
m_pTemporaryScreenSpaceTextures[i] = NULL;
+ }
return hr;
}
@@ -670,16 +646,14 @@ HRESULT CDX9RenderingEngine::BeginScreenSpacePass()
swap(m_ScreenSpacePassSrc, m_ScreenSpacePassDest);
--m_ScreenSpacePassCount;
- if (m_ScreenSpacePassCount > 0)
- {
+ if (m_ScreenSpacePassCount > 0) {
CComPtr<IDirect3DSurface9> pTemporarySurface;
hr = m_pTemporaryScreenSpaceTextures[m_ScreenSpacePassDest]->GetSurfaceLevel(0, &pTemporarySurface);
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = m_pD3DDev->SetRenderTarget(0, pTemporarySurface);
- }
- else
- {
+ }
+ } else {
hr = m_pD3DDev->SetRenderTarget(0, m_pRenderTarget);
}
@@ -693,40 +667,43 @@ HRESULT CDX9RenderingEngine::InitResizers(float bicubicA)
// Check whether the resizer pixel shaders must be initialized
bool bInitRequired = false;
- if (bicubicA)
- {
- for (int i = 0; i < 4; i++)
- {
- if (!m_pResizerPixelShaders[i])
+ if (bicubicA) {
+ for (int i = 0; i < 4; i++) {
+ if (!m_pResizerPixelShaders[i]) {
bInitRequired = true;
+ }
}
- if (m_BicubicA != bicubicA)
+ if (m_BicubicA != bicubicA) {
bInitRequired = true;
- }
- else
- {
- if (!m_pResizerPixelShaders[0])
+ }
+ } else {
+ if (!m_pResizerPixelShaders[0]) {
bInitRequired = true;
+ }
}
- if (!bInitRequired)
+ if (!bInitRequired) {
return S_OK;
+ }
// Initialize the resizer pixel shaders
m_BicubicA = bicubicA;
- for (int i = 0; i < countof(m_pResizerPixelShaders); i++)
+ for (int i = 0; i < countof(m_pResizerPixelShaders); i++) {
m_pResizerPixelShaders[i] = NULL;
+ }
- if (m_Caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
+ if (m_Caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) {
return E_FAIL;
+ }
LPCSTR pProfile = m_Caps.PixelShaderVersion >= D3DPS_VERSION(3, 0) ? "ps_3_0" : "ps_2_0";
CStringA str;
- if (!LoadResource(IDF_SHADER_RESIZER, str, _T("FILE")))
+ if (!LoadResource(IDF_SHADER_RESIZER, str, _T("FILE"))) {
return E_FAIL;
+ }
CStringA A;
A.Format("(%f)", bicubicA);
@@ -736,13 +713,11 @@ HRESULT CDX9RenderingEngine::InitResizers(float bicubicA)
ASSERT(countof(pEntries) == countof(m_pResizerPixelShaders));
- for (int i = 0; i < countof(pEntries); i++)
- {
+ for (int i = 0; i < countof(pEntries); i++) {
CString ErrorMessage;
CString DissAssembly;
hr = m_pPSC->CompileShader(str, pEntries[i], pProfile, 0, &m_pResizerPixelShaders[i], &DissAssembly, &ErrorMessage);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
TRACE("%ws", ErrorMessage.GetString());
ASSERT (0);
return hr;
@@ -777,8 +752,9 @@ HRESULT CDX9RenderingEngine::TextureResize(IDirect3DTexture9* pTexture, Vector d
HRESULT hr;
D3DSURFACE_DESC desc;
- if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
float w = (float)desc.Width;
float h = (float)desc.Height;
@@ -786,8 +762,7 @@ HRESULT CDX9RenderingEngine::TextureResize(IDirect3DTexture9* pTexture, Vector d
float dx2 = 1.0/w;
float dy2 = 1.0/h;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{dst[0].x, dst[0].y, dst[0].z, 1.0f/dst[0].z, srcRect.left * dx2, srcRect.top * dy2},
{dst[1].x, dst[1].y, dst[1].z, 1.0f/dst[1].z, srcRect.right * dx2, srcRect.top * dy2},
{dst[2].x, dst[2].y, dst[2].z, 1.0f/dst[2].z, srcRect.left * dx2, srcRect.bottom * dy2},
@@ -808,8 +783,9 @@ HRESULT CDX9RenderingEngine::TextureResizeBilinear(IDirect3DTexture9* pTexture,
HRESULT hr;
D3DSURFACE_DESC desc;
- if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
// make const to give compiler a chance of optimising, also float faster than double and converted to float to sent to PS anyway
const float dx = 1.0f/(float)desc.Width;
@@ -819,8 +795,7 @@ HRESULT CDX9RenderingEngine::TextureResizeBilinear(IDirect3DTexture9* pTexture,
const float ty0 = srcRect.top;
const float ty1 = srcRect.bottom;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{dst[0].x, dst[0].y, dst[0].z, 1.0f/dst[0].z, tx0, ty0},
{dst[1].x, dst[1].y, dst[1].z, 1.0f/dst[1].z, tx1, ty0},
{dst[2].x, dst[2].y, dst[2].z, 1.0f/dst[2].z, tx0, ty1},
@@ -846,8 +821,9 @@ HRESULT CDX9RenderingEngine::TextureResizeBicubic1pass(IDirect3DTexture9* pTextu
HRESULT hr;
D3DSURFACE_DESC desc;
- if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
// make const to give compiler a chance of optimising, also float faster than double and converted to float to sent to PS anyway
const float dx = 1.0f/(float)desc.Width;
@@ -857,8 +833,7 @@ HRESULT CDX9RenderingEngine::TextureResizeBicubic1pass(IDirect3DTexture9* pTextu
const float ty0 = srcRect.top;
const float ty1 = srcRect.bottom;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{dst[0].x, dst[0].y, dst[0].z, 1.0f/dst[0].z, tx0, ty0},
{dst[1].x, dst[1].y, dst[1].z, 1.0f/dst[1].z, tx1, ty0},
{dst[2].x, dst[2].y, dst[2].z, 1.0f/dst[2].z, tx0, ty1},
@@ -1015,31 +990,30 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
bool bInitRequired = false;
if ((m_bFullFloatingPointProcessing != bFullFloatingPointProcessing) ||
- (m_bColorManagement != bColorManagement))
- {
+ (m_bColorManagement != bColorManagement)) {
bInitRequired = true;
}
- if (m_bColorManagement && bColorManagement)
- {
+ if (m_bColorManagement && bColorManagement) {
if ((m_InputVideoSystem != inputVideoSystem) ||
- (m_RenderingIntent != renderingIntent) ||
- (m_AmbientLight != ambientLight))
- {
+ (m_RenderingIntent != renderingIntent) ||
+ (m_AmbientLight != ambientLight)) {
bInitRequired = true;
}
}
- if (!bInitRequired)
+ if (!bInitRequired) {
return S_OK;
+ }
// Cleanup
CleanupFinalPass();
// Check whether the final pass is supported by the hardware
m_bFinalPass = data->m_bFP16Support;
- if (!m_bFinalPass)
+ if (!m_bFinalPass) {
return S_OK;
+ }
// Update the settings
m_bFullFloatingPointProcessing = bFullFloatingPointProcessing;
@@ -1052,8 +1026,9 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
m_bFinalPass = bFullFloatingPointProcessing || bColorManagement ||
(m_bForceInputHighColorResolution && !m_bHighColorResolution);
- if (!m_bFinalPass)
+ if (!m_bFinalPass) {
return S_OK;
+ }
// Create the dither texture
hr = m_pD3DDev->CreateTexture(DITHER_MATRIX_SIZE, DITHER_MATRIX_SIZE,
@@ -1064,54 +1039,47 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
&m_pDitherTexture,
NULL);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
CleanupFinalPass();
return hr;
}
D3DLOCKED_RECT lockedRect;
hr = m_pDitherTexture->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
CleanupFinalPass();
return hr;
}
char* outputRowIterator = static_cast<char*>(lockedRect.pBits);
- for (int y = 0; y < DITHER_MATRIX_SIZE; y++)
- {
+ for (int y = 0; y < DITHER_MATRIX_SIZE; y++) {
unsigned short* outputIterator = reinterpret_cast<unsigned short*>(outputRowIterator);
- for (int x = 0; x < DITHER_MATRIX_SIZE; x++)
- {
- for (int i = 0; i < 4; i++)
+ for (int x = 0; x < DITHER_MATRIX_SIZE; x++) {
+ for (int i = 0; i < 4; i++) {
*outputIterator++ = DITHER_MATRIX[y][x];
+ }
}
outputRowIterator += lockedRect.Pitch;
}
hr = m_pDitherTexture->UnlockRect(0);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
CleanupFinalPass();
return hr;
}
// Initialize the color management if necessary
- if (bColorManagement)
- {
+ if (bColorManagement) {
// Get the ICC profile path
TCHAR* iccProfilePath = 0;
HDC hDC = GetDC(m_hWnd);
- if (hDC != NULL)
- {
+ if (hDC != NULL) {
DWORD icmProfilePathSize = 0;
GetICMProfile(hDC, &icmProfilePathSize, NULL);
iccProfilePath = new TCHAR[icmProfilePathSize];
- if (!GetICMProfile(hDC, &icmProfilePathSize, iccProfilePath))
- {
+ if (!GetICMProfile(hDC, &icmProfilePathSize, iccProfilePath)) {
delete[] iccProfilePath;
iccProfilePath = 0;
}
@@ -1131,8 +1099,7 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
&m_pLut3DTexture,
NULL);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
delete[] iccProfilePath;
CleanupFinalPass();
return hr;
@@ -1141,8 +1108,7 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
float* lut3DFloat32 = new float[m_Lut3DEntryCount * 3];
hr = CreateIccProfileLut(iccProfilePath, lut3DFloat32);
delete[] iccProfilePath;
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
delete[] lut3DFloat32;
CleanupFinalPass();
return hr;
@@ -1158,8 +1124,7 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
D3DLOCKED_BOX lockedBox;
hr = m_pLut3DTexture->LockBox(0, &lockedBox, NULL, D3DLOCK_DISCARD);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
delete[] lut3DFloat16;
CleanupFinalPass();
return hr;
@@ -1167,19 +1132,17 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
D3DXFLOAT16* lut3DFloat16Iterator = lut3DFloat16;
char* outputSliceIterator = static_cast<char*>(lockedBox.pBits);
- for (int b = 0; b < m_Lut3DSize; b++)
- {
+ for (int b = 0; b < m_Lut3DSize; b++) {
char* outputRowIterator = outputSliceIterator;
- for (int g = 0; g < m_Lut3DSize; g++)
- {
+ for (int g = 0; g < m_Lut3DSize; g++) {
D3DXFLOAT16* outputIterator = reinterpret_cast<D3DXFLOAT16*>(outputRowIterator);
- for (int r = 0; r < m_Lut3DSize; r++)
- {
+ for (int r = 0; r < m_Lut3DSize; r++) {
// R, G, B
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
*outputIterator++ = *lut3DFloat16Iterator++;
+ }
// A
*outputIterator++ = oneFloat16;
@@ -1193,16 +1156,14 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
hr = m_pLut3DTexture->UnlockBox(0);
delete[] lut3DFloat16;
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
CleanupFinalPass();
return hr;
}
}
// Compile the final pixel shader
- if (m_Caps.PixelShaderVersion < D3DPS_VERSION(2, 0))
- {
+ if (m_Caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) {
CleanupFinalPass();
return E_FAIL;
}
@@ -1210,17 +1171,17 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
LPCSTR pProfile = m_Caps.PixelShaderVersion >= D3DPS_VERSION(3, 0) ? "ps_3_0" : "ps_2_0";
CStringA shaderSourceCode;
- if (!LoadResource(IDF_SHADER_FINAL, shaderSourceCode, _T("FILE")))
- {
+ if (!LoadResource(IDF_SHADER_FINAL, shaderSourceCode, _T("FILE"))) {
CleanupFinalPass();
return E_FAIL;
}
int quantization;
- if (m_bHighColorResolution && (m_DisplayType == D3DFMT_A2R10G10B10 || m_DisplayType == D3DFMT_A2B10G10R10))
- quantization = 1023; // 10-bit
- else
- quantization = 255; // 8-bit
+ if (m_bHighColorResolution && (m_DisplayType == D3DFMT_A2R10G10B10 || m_DisplayType == D3DFMT_A2B10G10R10)) {
+ quantization = 1023; // 10-bit
+ } else {
+ quantization = 255; // 8-bit
+ }
CStringA quantizationString;
quantizationString.Format("%d.0f", quantization);
@@ -1230,8 +1191,7 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
lut3DEnabledString.Format("%d", static_cast<int>(bColorManagement));
shaderSourceCode.Replace("_LUT3D_ENABLED_VALUE_", lut3DEnabledString);
- if (bColorManagement)
- {
+ if (bColorManagement) {
CStringA lut3DSizeString;
lut3DSizeString.Format("%d.0f", m_Lut3DSize);
shaderSourceCode.Replace("_LUT3D_SIZE_VALUE_", lut3DSizeString);
@@ -1240,8 +1200,7 @@ HRESULT CDX9RenderingEngine::InitFinalPass()
CString ErrorMessage;
CString DissAssembly;
hr = m_pPSC->CompileShader(shaderSourceCode, "main", pProfile, 0, &m_pFinalPixelShader, &DissAssembly, &ErrorMessage);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
TRACE("%ws", ErrorMessage.GetString());
ASSERT (0);
CleanupFinalPass();
@@ -1264,74 +1223,69 @@ HRESULT CDX9RenderingEngine::CreateIccProfileLut(TCHAR* profilePath, float* lut3
// Get the input video system
VideoSystem videoSystem;
- if (m_InputVideoSystem == VIDEO_SYSTEM_UNKNOWN)
- {
+ if (m_InputVideoSystem == VIDEO_SYSTEM_UNKNOWN) {
static const int ntscSizes[][2] = {{720, 480}, {720, 486}, {704, 480}};
static const int palSizes[][2] = {{720, 576}, {704, 576}};
videoSystem = VIDEO_SYSTEM_HDTV; // default
- for (int i = 0; i < countof(ntscSizes); i++)
- {
- if (m_NativeVideoSize.cx == ntscSizes[i][0] && m_NativeVideoSize.cy == ntscSizes[i][1])
+ for (int i = 0; i < countof(ntscSizes); i++) {
+ if (m_NativeVideoSize.cx == ntscSizes[i][0] && m_NativeVideoSize.cy == ntscSizes[i][1]) {
videoSystem = VIDEO_SYSTEM_SDTV_NTSC;
+ }
}
- for (int i = 0; i < countof(palSizes); i++)
- {
- if (m_NativeVideoSize.cx == palSizes[i][0] && m_NativeVideoSize.cy == palSizes[i][1])
+ for (int i = 0; i < countof(palSizes); i++) {
+ if (m_NativeVideoSize.cx == palSizes[i][0] && m_NativeVideoSize.cy == palSizes[i][1]) {
videoSystem = VIDEO_SYSTEM_SDTV_PAL;
+ }
}
- }
- else
- {
+ } else {
videoSystem = m_InputVideoSystem;
}
// Get the gamma
double gamma;
- switch (m_AmbientLight)
- {
- case AMBIENT_LIGHT_BRIGHT:
- gamma = 2.2;
- break;
+ switch (m_AmbientLight) {
+ case AMBIENT_LIGHT_BRIGHT:
+ gamma = 2.2;
+ break;
- case AMBIENT_LIGHT_DIM:
- gamma = 2.35;
- break;
+ case AMBIENT_LIGHT_DIM:
+ gamma = 2.35;
+ break;
- case AMBIENT_LIGHT_DARK:
- gamma = 2.4;
- break;
+ case AMBIENT_LIGHT_DARK:
+ gamma = 2.4;
+ break;
- default:
- return E_FAIL;
+ default:
+ return E_FAIL;
}
// Get the rendering intent
cmsUInt32Number intent;
- switch (m_RenderingIntent)
- {
- case COLOR_RENDERING_INTENT_PERCEPTUAL:
- intent = INTENT_PERCEPTUAL;
- break;
+ switch (m_RenderingIntent) {
+ case COLOR_RENDERING_INTENT_PERCEPTUAL:
+ intent = INTENT_PERCEPTUAL;
+ break;
- case COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC:
- intent = INTENT_RELATIVE_COLORIMETRIC;
- break;
+ case COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC:
+ intent = INTENT_RELATIVE_COLORIMETRIC;
+ break;
- case COLOR_RENDERING_INTENT_SATURATION:
- intent = INTENT_SATURATION;
- break;
+ case COLOR_RENDERING_INTENT_SATURATION:
+ intent = INTENT_SATURATION;
+ break;
- case COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC:
- intent = INTENT_ABSOLUTE_COLORIMETRIC;
- break;
+ case COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC:
+ intent = INTENT_ABSOLUTE_COLORIMETRIC;
+ break;
- default:
- return E_FAIL;
+ default:
+ return E_FAIL;
}
// Set the input white point. It's D65 in all cases.
@@ -1344,40 +1298,39 @@ HRESULT CDX9RenderingEngine::CreateIccProfileLut(TCHAR* profilePath, float* lut3
// Set the input primaries
cmsCIExyYTRIPLE primaries;
- switch (videoSystem)
- {
- case VIDEO_SYSTEM_HDTV:
- // Rec. 709
- primaries.Red.x = 0.64;
- primaries.Red.y = 0.33;
- primaries.Green.x = 0.30;
- primaries.Green.y = 0.60;
- primaries.Blue.x = 0.15;
- primaries.Blue.y = 0.06;
- break;
-
- case VIDEO_SYSTEM_SDTV_NTSC:
- // SMPTE-C
- primaries.Red.x = 0.630;
- primaries.Red.y = 0.340;
- primaries.Green.x = 0.310;
- primaries.Green.y = 0.595;
- primaries.Blue.x = 0.155;
- primaries.Blue.y = 0.070;
- break;
-
- case VIDEO_SYSTEM_SDTV_PAL:
- // PAL/SECAM
- primaries.Red.x = 0.64;
- primaries.Red.y = 0.33;
- primaries.Green.x = 0.29;
- primaries.Green.y = 0.60;
- primaries.Blue.x = 0.15;
- primaries.Blue.y = 0.06;
- break;
-
- default:
- return E_FAIL;
+ switch (videoSystem) {
+ case VIDEO_SYSTEM_HDTV:
+ // Rec. 709
+ primaries.Red.x = 0.64;
+ primaries.Red.y = 0.33;
+ primaries.Green.x = 0.30;
+ primaries.Green.y = 0.60;
+ primaries.Blue.x = 0.15;
+ primaries.Blue.y = 0.06;
+ break;
+
+ case VIDEO_SYSTEM_SDTV_NTSC:
+ // SMPTE-C
+ primaries.Red.x = 0.630;
+ primaries.Red.y = 0.340;
+ primaries.Green.x = 0.310;
+ primaries.Green.y = 0.595;
+ primaries.Blue.x = 0.155;
+ primaries.Blue.y = 0.070;
+ break;
+
+ case VIDEO_SYSTEM_SDTV_PAL:
+ // PAL/SECAM
+ primaries.Red.x = 0.64;
+ primaries.Red.y = 0.33;
+ primaries.Green.x = 0.29;
+ primaries.Green.y = 0.60;
+ primaries.Blue.x = 0.15;
+ primaries.Blue.y = 0.06;
+ break;
+
+ default:
+ return E_FAIL;
}
primaries.Red.Y = 1.0;
@@ -1389,39 +1342,37 @@ HRESULT CDX9RenderingEngine::CreateIccProfileLut(TCHAR* profilePath, float* lut3
cmsToneCurve* transferFunction = cmsBuildGamma(0, gamma);
cmsToneCurve* transferFunctionRGB[3];
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
transferFunctionRGB[i] = transferFunction;
+ }
// Create the input profile
cmsHPROFILE hInputProfile = cmsCreateRGBProfile(&whitePoint, &primaries, transferFunctionRGB);
cmsFreeToneCurve(transferFunction);
- if (hInputProfile == NULL)
+ if (hInputProfile == NULL) {
return E_FAIL;
+ }
// Open the output profile
cmsHPROFILE hOutputProfile;
FILE* outputProfileStream;
- if (profilePath != 0)
- {
- if (_wfopen_s(&outputProfileStream, T2W(profilePath), L"rb") != 0)
- {
+ if (profilePath != 0) {
+ if (_wfopen_s(&outputProfileStream, T2W(profilePath), L"rb") != 0) {
cmsCloseProfile(hInputProfile);
return E_FAIL;
}
hOutputProfile = cmsOpenProfileFromStream(outputProfileStream, "r");
- }
- else
- {
+ } else {
hOutputProfile = cmsCreate_sRGBProfile();
}
- if (hOutputProfile == NULL)
- {
- if (profilePath != 0)
+ if (hOutputProfile == NULL) {
+ if (profilePath != 0) {
fclose(outputProfileStream);
+ }
cmsCloseProfile(hInputProfile);
return E_FAIL;
@@ -1432,13 +1383,15 @@ HRESULT CDX9RenderingEngine::CreateIccProfileLut(TCHAR* profilePath, float* lut3
cmsCloseProfile(hOutputProfile);
- if (profilePath != 0)
+ if (profilePath != 0) {
fclose(outputProfileStream);
+ }
cmsCloseProfile(hInputProfile);
- if (hTransform == NULL)
+ if (hTransform == NULL) {
return E_FAIL;
+ }
// Create the 3D LUT input
unsigned short* lut3DOutput = new unsigned short[m_Lut3DEntryCount * 3];
@@ -1446,12 +1399,9 @@ HRESULT CDX9RenderingEngine::CreateIccProfileLut(TCHAR* profilePath, float* lut3
unsigned short* lut3DInputIterator = lut3DInput;
- for (int b = 0; b < m_Lut3DSize; b++)
- {
- for (int g = 0; g < m_Lut3DSize; g++)
- {
- for (int r = 0; r < m_Lut3DSize; r++)
- {
+ for (int b = 0; b < m_Lut3DSize; b++) {
+ for (int g = 0; g < m_Lut3DSize; g++) {
+ for (int r = 0; r < m_Lut3DSize; r++) {
*lut3DInputIterator++ = r * 65535 / (m_Lut3DSize - 1);
*lut3DInputIterator++ = g * 65535 / (m_Lut3DSize - 1);
*lut3DInputIterator++ = b * 65535 / (m_Lut3DSize - 1);
@@ -1463,8 +1413,9 @@ HRESULT CDX9RenderingEngine::CreateIccProfileLut(TCHAR* profilePath, float* lut3
cmsDoTransform(hTransform, lut3DInput, lut3DOutput, m_Lut3DEntryCount);
// Convert the output to floating point
- for (int i = 0; i < m_Lut3DEntryCount * 3; i++)
+ for (int i = 0; i < m_Lut3DEntryCount * 3; i++) {
lut3D[i] = static_cast<float>(lut3DOutput[i]) * (1.0f / 65535.0f);
+ }
// Cleanup
delete[] lut3DOutput;
@@ -1479,22 +1430,21 @@ HRESULT CDX9RenderingEngine::FinalPass(IDirect3DTexture9* pTexture)
HRESULT hr;
D3DSURFACE_DESC desc;
- if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
float w = (float)desc.Width;
float h = (float)desc.Height;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{0, 0, 0.5f, 2.0f, 0, 0},
{w, 0, 0.5f, 2.0f, 1, 0},
{0, h, 0.5f, 2.0f, 0, 1},
{w, h, 0.5f, 2.0f, 1, 1},
};
- for(int i = 0; i < countof(v); i++)
- {
+ for(int i = 0; i < countof(v); i++) {
v[i].x -= 0.5;
v[i].y -= 0.5;
}
@@ -1514,8 +1464,7 @@ HRESULT CDX9RenderingEngine::FinalPass(IDirect3DTexture9* pTexture)
hr = m_pD3DDev->SetTexture(1, m_pDitherTexture);
- if (m_bColorManagement)
- {
+ if (m_bColorManagement) {
hr = m_pD3DDev->SetSamplerState(2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
hr = m_pD3DDev->SetSamplerState(2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
hr = m_pD3DDev->SetSamplerState(2, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
@@ -1535,8 +1484,9 @@ HRESULT CDX9RenderingEngine::FinalPass(IDirect3DTexture9* pTexture)
hr = m_pD3DDev->SetTexture(1, NULL);
- if (m_bColorManagement)
+ if (m_bColorManagement) {
hr = m_pD3DDev->SetTexture(2, NULL);
+ }
return hr;
}
@@ -1546,22 +1496,21 @@ HRESULT CDX9RenderingEngine::TextureCopy(IDirect3DTexture9* pTexture)
HRESULT hr;
D3DSURFACE_DESC desc;
- if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if (!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
float w = (float)desc.Width;
float h = (float)desc.Height;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{0, 0, 0.5f, 2.0f, 0, 0},
{w, 0, 0.5f, 2.0f, 1, 0},
{0, h, 0.5f, 2.0f, 0, 1},
{w, h, 0.5f, 2.0f, 1, 1},
};
- for (int i = 0; i < countof(v); i++)
- {
+ for (int i = 0; i < countof(v); i++) {
v[i].x -= 0.5;
v[i].y -= 0.5;
}
@@ -1575,38 +1524,34 @@ bool CDX9RenderingEngine::ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, C
{
D3DSURFACE_DESC d3dsd;
ZeroMemory(&d3dsd, sizeof(d3dsd));
- if (FAILED(pSurface->GetDesc(&d3dsd)))
+ if (FAILED(pSurface->GetDesc(&d3dsd))) {
return(false);
+ }
int w = d3dsd.Width, h = d3dsd.Height;
int sw = s.Width(), sh = s.Height();
int dw = d.Width(), dh = d.Height();
if (d.left >= w || d.right < 0 || d.top >= h || d.bottom < 0
- || sw <= 0 || sh <= 0 || dw <= 0 || dh <= 0)
- {
+ || sw <= 0 || sh <= 0 || dw <= 0 || dh <= 0) {
s.SetRectEmpty();
d.SetRectEmpty();
return(true);
}
- if (d.right > w)
- {
+ if (d.right > w) {
s.right -= (d.right-w)*sw/dw;
d.right = w;
}
- if (d.bottom > h)
- {
+ if (d.bottom > h) {
s.bottom -= (d.bottom-h)*sh/dh;
d.bottom = h;
}
- if (d.left < 0)
- {
+ if (d.left < 0) {
s.left += (0-d.left)*sw/dw;
d.left = 0;
}
- if (d.top < 0)
- {
+ if (d.top < 0) {
s.top += (0-d.top)*sh/dh;
d.top = 0;
}
@@ -1616,20 +1561,19 @@ bool CDX9RenderingEngine::ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, C
HRESULT CDX9RenderingEngine::DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_Rect)
{
- if (!m_pD3DDev)
+ if (!m_pD3DDev) {
return E_POINTER;
+ }
DWORD Color = D3DCOLOR_ARGB(_Alpha, GetRValue(_Color), GetGValue(_Color), GetBValue(_Color));
- MYD3DVERTEX<0> v[] =
- {
+ MYD3DVERTEX<0> v[] = {
{float(_Rect.left), float(_Rect.top), 0.5f, 2.0f, Color},
{float(_Rect.right), float(_Rect.top), 0.5f, 2.0f, Color},
{float(_Rect.left), float(_Rect.bottom), 0.5f, 2.0f, Color},
{float(_Rect.right), float(_Rect.bottom), 0.5f, 2.0f, Color},
};
- for (int i = 0; i < countof(v); i++)
- {
+ for (int i = 0; i < countof(v); i++) {
v[i].x -= 0.5;
v[i].y -= 0.5;
}
@@ -1661,8 +1605,9 @@ HRESULT CDX9RenderingEngine::DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_
HRESULT CDX9RenderingEngine::AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture)
{
- if(!pSrc || !pDst)
+ if(!pSrc || !pDst) {
return E_POINTER;
+ }
CRect src(*pSrc), dst(*pDst);
@@ -1670,19 +1615,18 @@ HRESULT CDX9RenderingEngine::AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9*
D3DSURFACE_DESC d3dsd;
ZeroMemory(&d3dsd, sizeof(d3dsd));
- if(FAILED(pTexture->GetLevelDesc(0, &d3dsd)) /*|| d3dsd.Type != D3DRTYPE_TEXTURE*/)
+ if(FAILED(pTexture->GetLevelDesc(0, &d3dsd)) /*|| d3dsd.Type != D3DRTYPE_TEXTURE*/) {
return E_FAIL;
+ }
float w = (float)d3dsd.Width;
float h = (float)d3dsd.Height;
- struct
- {
+ struct {
float x, y, z, rhw;
float tu, tv;
}
- pVertices[] =
- {
+ pVertices[] = {
{(float)dst.left, (float)dst.top, 0.5f, 2.0f, (float)src.left / w, (float)src.top / h},
{(float)dst.right, (float)dst.top, 0.5f, 2.0f, (float)src.right / w, (float)src.top / h},
{(float)dst.left, (float)dst.bottom, 0.5f, 2.0f, (float)src.left / w, (float)src.bottom / h},
@@ -1753,20 +1697,21 @@ HRESULT CDX9RenderingEngine::AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9*
HRESULT CDX9RenderingEngine::SetCustomPixelShader(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace)
{
CAtlList<CExternalPixelShader> *pPixelShaders;
- if (bScreenSpace)
+ if (bScreenSpace) {
pPixelShaders = &m_pCustomScreenSpacePixelShaders;
- else
+ } else {
pPixelShaders = &m_pCustomPixelShaders;
+ }
- if (!pSrcData && !pTarget)
- {
+ if (!pSrcData && !pTarget) {
pPixelShaders->RemoveAll();
m_pD3DDev->SetPixelShader(NULL);
return S_OK;
}
- if (!pSrcData || !pTarget)
+ if (!pSrcData || !pTarget) {
return E_INVALIDARG;
+ }
CExternalPixelShader Shader;
Shader.m_SourceData = pSrcData;
@@ -1775,8 +1720,9 @@ HRESULT CDX9RenderingEngine::SetCustomPixelShader(LPCSTR pSrcData, LPCSTR pTarge
CComPtr<IDirect3DPixelShader9> pPixelShader;
HRESULT hr = Shader.Compile(m_pPSC);
- if (FAILED(hr))
+ if (FAILED(hr)) {
return hr;
+ }
pPixelShaders->AddTail(Shader);
diff --git a/src/filters/renderer/VideoRenderers/DX9RenderingEngine.h b/src/filters/renderer/VideoRenderers/DX9RenderingEngine.h
index d2afd3cf4..f90a03a81 100644
--- a/src/filters/renderer/VideoRenderers/DX9RenderingEngine.h
+++ b/src/filters/renderer/VideoRenderers/DX9RenderingEngine.h
@@ -32,152 +32,151 @@
namespace DSObjects
{
-class CDX9RenderingEngine
- : public CSubPicAllocatorPresenterImpl
-{
-protected:
- enum RenderingPath
+ class CDX9RenderingEngine
+ : public CSubPicAllocatorPresenterImpl
{
- RENDERING_PATH_STRETCHRECT,
- RENDERING_PATH_DRAW,
- };
+ protected:
+ enum RenderingPath {
+ RENDERING_PATH_STRETCHRECT,
+ RENDERING_PATH_DRAW,
+ };
- static const int MAX_VIDEO_SURFACES = 60;
+ static const int MAX_VIDEO_SURFACES = 60;
- // Variables initialized/managed by the allocator-presenter!
- CComPtr<IDirect3D9> m_pD3D;
- CComPtr<IDirect3D9Ex> m_pD3DEx;
- CComPtr<IDirect3DDevice9> m_pD3DDev;
- CComPtr<IDirect3DDevice9Ex> m_pD3DDevEx;
- UINT m_CurrentAdapter;
- D3DCAPS9 m_Caps;
- D3DFORMAT m_BackbufferType;
- D3DFORMAT m_DisplayType;
- CSize m_ScreenSize;
- int m_nNbDXSurface; // Total number of DX Surfaces
- int m_nCurSurface; // Surface currently displayed
+ // Variables initialized/managed by the allocator-presenter!
+ CComPtr<IDirect3D9> m_pD3D;
+ CComPtr<IDirect3D9Ex> m_pD3DEx;
+ CComPtr<IDirect3DDevice9> m_pD3DDev;
+ CComPtr<IDirect3DDevice9Ex> m_pD3DDevEx;
+ UINT m_CurrentAdapter;
+ D3DCAPS9 m_Caps;
+ D3DFORMAT m_BackbufferType;
+ D3DFORMAT m_DisplayType;
+ CSize m_ScreenSize;
+ int m_nNbDXSurface; // Total number of DX Surfaces
+ int m_nCurSurface; // Surface currently displayed
- bool m_bHighColorResolution;
- bool m_bForceInputHighColorResolution;
+ bool m_bHighColorResolution;
+ bool m_bForceInputHighColorResolution;
- // Variables initialized/managed by this class but can be accessed by the allocator-presenter
- bool m_bD3DX;
- RenderingPath m_RenderingPath;
- D3DFORMAT m_SurfaceType;
- CComPtr<IDirect3DTexture9> m_pVideoTexture[MAX_VIDEO_SURFACES];
- CComPtr<IDirect3DSurface9> m_pVideoSurface[MAX_VIDEO_SURFACES];
+ // Variables initialized/managed by this class but can be accessed by the allocator-presenter
+ bool m_bD3DX;
+ RenderingPath m_RenderingPath;
+ D3DFORMAT m_SurfaceType;
+ CComPtr<IDirect3DTexture9> m_pVideoTexture[MAX_VIDEO_SURFACES];
+ CComPtr<IDirect3DSurface9> m_pVideoSurface[MAX_VIDEO_SURFACES];
- bool m_bFullFloatingPointProcessing;
- bool m_bColorManagement;
+ bool m_bFullFloatingPointProcessing;
+ bool m_bColorManagement;
- CDX9RenderingEngine(HWND hWnd, HRESULT& hr, CString *_pError);
+ CDX9RenderingEngine(HWND hWnd, HRESULT& hr, CString *_pError);
- void InitRenderingEngine();
- void CleanupRenderingEngine();
+ void InitRenderingEngine();
+ void CleanupRenderingEngine();
- HRESULT CreateVideoSurfaces(D3DFORMAT format);
- void FreeVideoSurfaces();
+ HRESULT CreateVideoSurfaces(D3DFORMAT format);
+ void FreeVideoSurfaces();
- HRESULT RenderVideo(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect);
+ HRESULT RenderVideo(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect);
- HRESULT DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_Rect);
- HRESULT AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture);
+ HRESULT DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_Rect);
+ HRESULT AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture);
- HRESULT SetCustomPixelShader(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace);
+ HRESULT SetCustomPixelShader(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace);
-private:
- class CExternalPixelShader
- {
- public:
- CComPtr<IDirect3DPixelShader9> m_pPixelShader;
- CStringA m_SourceData;
- CStringA m_SourceTarget;
- HRESULT Compile(CPixelShaderCompiler *pCompiler)
+ private:
+ class CExternalPixelShader
{
- HRESULT hr = pCompiler->CompileShader(m_SourceData, "main", m_SourceTarget, 0, &m_pPixelShader);
- if(FAILED(hr))
- return hr;
-
- return S_OK;
- }
+ public:
+ CComPtr<IDirect3DPixelShader9> m_pPixelShader;
+ CStringA m_SourceData;
+ CStringA m_SourceTarget;
+ HRESULT Compile(CPixelShaderCompiler *pCompiler) {
+ HRESULT hr = pCompiler->CompileShader(m_SourceData, "main", m_SourceTarget, 0, &m_pPixelShader);
+ if(FAILED(hr)) {
+ return hr;
+ }
+
+ return S_OK;
+ }
+ };
+
+ // D3DX functions
+ typedef D3DXFLOAT16* (WINAPI* D3DXFloat32To16ArrayPtr)(
+ D3DXFLOAT16 *pOut,
+ CONST FLOAT *pIn,
+ UINT n);
+
+
+ CAutoPtr<CPixelShaderCompiler> m_pPSC;
+
+ // Settings
+ VideoSystem m_InputVideoSystem;
+ AmbientLight m_AmbientLight;
+ ColorRenderingIntent m_RenderingIntent;
+
+ // Custom pixel shaders
+ CAtlList<CExternalPixelShader> m_pCustomPixelShaders;
+ CComPtr<IDirect3DTexture9> m_pTemporaryVideoTextures[2];
+
+ // Screen space pipeline
+ int m_ScreenSpacePassCount;
+ int m_ScreenSpacePassSrc;
+ int m_ScreenSpacePassDest;
+ CSize m_TemporaryScreenSpaceTextureSize;
+ CComPtr<IDirect3DTexture9> m_pTemporaryScreenSpaceTextures[2];
+ IDirect3DSurface9* m_pRenderTarget;
+
+ // Resizers
+ float m_BicubicA;
+ CComPtr<IDirect3DPixelShader9> m_pResizerPixelShaders[4]; // bl, bc1, bc2_1, bc2_2
+
+ // Final pass
+ bool m_bFinalPass;
+ int m_Lut3DSize;
+ int m_Lut3DEntryCount;
+ CComPtr<IDirect3DVolumeTexture9> m_pLut3DTexture;
+ CComPtr<IDirect3DTexture9> m_pDitherTexture;
+ CComPtr<IDirect3DPixelShader9> m_pFinalPixelShader;
+
+ // Custom screen space pixel shaders
+ CAtlList<CExternalPixelShader> m_pCustomScreenSpacePixelShaders;
+
+ // StetchRect rendering path
+ D3DTEXTUREFILTERTYPE m_StretchRectFilter;
+
+ // D3DX function pointers
+ D3DXFloat32To16ArrayPtr m_pD3DXFloat32To16Array;
+
+
+ // Video rendering paths
+ HRESULT RenderVideoDrawPath(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect);
+ HRESULT RenderVideoStretchRectPath(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect);
+
+ // Custom pixel shaders
+ HRESULT InitTemporaryVideoTextures(int count);
+
+ // Screen space pipeline
+ HRESULT InitScreenSpacePipeline(int passCount, IDirect3DSurface9* pRenderTarget);
+ HRESULT InitTemporaryScreenSpaceTextures(int count);
+ HRESULT BeginScreenSpacePass();
+
+ // Resizers
+ HRESULT InitResizers(float bicubicA);
+ HRESULT TextureResize(IDirect3DTexture9* pTexture, Vector dst[4], D3DTEXTUREFILTERTYPE filter, const CRect &srcRect);
+ HRESULT TextureResizeBilinear(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &srcRect);
+ HRESULT TextureResizeBicubic1pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &srcRect);
+ //HRESULT TextureResizeBicubic2pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &srcRect);
+
+ // Final pass
+ HRESULT InitFinalPass();
+ void CleanupFinalPass();
+ HRESULT CreateIccProfileLut(TCHAR* profilePath, float* lut3D);
+ HRESULT FinalPass(IDirect3DTexture9* pTexture);
+
+ HRESULT TextureCopy(IDirect3DTexture9* pTexture);
+ bool ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, CRect& d);
};
- // D3DX functions
- typedef D3DXFLOAT16* (WINAPI* D3DXFloat32To16ArrayPtr)(
- D3DXFLOAT16 *pOut,
- CONST FLOAT *pIn,
- UINT n);
-
-
- CAutoPtr<CPixelShaderCompiler> m_pPSC;
-
- // Settings
- VideoSystem m_InputVideoSystem;
- AmbientLight m_AmbientLight;
- ColorRenderingIntent m_RenderingIntent;
-
- // Custom pixel shaders
- CAtlList<CExternalPixelShader> m_pCustomPixelShaders;
- CComPtr<IDirect3DTexture9> m_pTemporaryVideoTextures[2];
-
- // Screen space pipeline
- int m_ScreenSpacePassCount;
- int m_ScreenSpacePassSrc;
- int m_ScreenSpacePassDest;
- CSize m_TemporaryScreenSpaceTextureSize;
- CComPtr<IDirect3DTexture9> m_pTemporaryScreenSpaceTextures[2];
- IDirect3DSurface9* m_pRenderTarget;
-
- // Resizers
- float m_BicubicA;
- CComPtr<IDirect3DPixelShader9> m_pResizerPixelShaders[4]; // bl, bc1, bc2_1, bc2_2
-
- // Final pass
- bool m_bFinalPass;
- int m_Lut3DSize;
- int m_Lut3DEntryCount;
- CComPtr<IDirect3DVolumeTexture9> m_pLut3DTexture;
- CComPtr<IDirect3DTexture9> m_pDitherTexture;
- CComPtr<IDirect3DPixelShader9> m_pFinalPixelShader;
-
- // Custom screen space pixel shaders
- CAtlList<CExternalPixelShader> m_pCustomScreenSpacePixelShaders;
-
- // StetchRect rendering path
- D3DTEXTUREFILTERTYPE m_StretchRectFilter;
-
- // D3DX function pointers
- D3DXFloat32To16ArrayPtr m_pD3DXFloat32To16Array;
-
-
- // Video rendering paths
- HRESULT RenderVideoDrawPath(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect);
- HRESULT RenderVideoStretchRectPath(IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& destRect);
-
- // Custom pixel shaders
- HRESULT InitTemporaryVideoTextures(int count);
-
- // Screen space pipeline
- HRESULT InitScreenSpacePipeline(int passCount, IDirect3DSurface9* pRenderTarget);
- HRESULT InitTemporaryScreenSpaceTextures(int count);
- HRESULT BeginScreenSpacePass();
-
- // Resizers
- HRESULT InitResizers(float bicubicA);
- HRESULT TextureResize(IDirect3DTexture9* pTexture, Vector dst[4], D3DTEXTUREFILTERTYPE filter, const CRect &srcRect);
- HRESULT TextureResizeBilinear(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &srcRect);
- HRESULT TextureResizeBicubic1pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &srcRect);
- //HRESULT TextureResizeBicubic2pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &srcRect);
-
- // Final pass
- HRESULT InitFinalPass();
- void CleanupFinalPass();
- HRESULT CreateIccProfileLut(TCHAR* profilePath, float* lut3D);
- HRESULT FinalPass(IDirect3DTexture9* pTexture);
-
- HRESULT TextureCopy(IDirect3DTexture9* pTexture);
- bool ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, CRect& d);
-};
-
}
diff --git a/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp
index f106c0e36..20e4dbb18 100644
--- a/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.cpp
@@ -37,8 +37,7 @@ CDXRAllocatorPresenter::CDXRAllocatorPresenter(HWND hWnd, HRESULT& hr, CString &
: CSubPicAllocatorPresenterImpl(hWnd, hr, &_Error)
, m_ScreenSize(0, 0)
{
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
_Error += L"ISubPicAllocatorPresenterImpl failed\n";
return;
}
@@ -48,8 +47,7 @@ CDXRAllocatorPresenter::CDXRAllocatorPresenter(HWND hWnd, HRESULT& hr, CString &
CDXRAllocatorPresenter::~CDXRAllocatorPresenter()
{
- if(m_pSRCB)
- {
+ if(m_pSRCB) {
// nasty, but we have to let it know about our death somehow
((CSubRenderCallback*)(ISubRenderCallback*)m_pSRCB)->SetDXRAP(NULL);
}
@@ -75,10 +73,10 @@ STDMETHODIMP CDXRAllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, vo
return GetInterface((IVMRWindowlessControl*)this, ppv);
*/
- if(riid != IID_IUnknown && m_pDXR)
- {
- if(SUCCEEDED(m_pDXR->QueryInterface(riid, ppv)))
+ if(riid != IID_IUnknown && m_pDXR) {
+ if(SUCCEEDED(m_pDXR->QueryInterface(riid, ppv))) {
return S_OK;
+ }
}
return __super::NonDelegatingQueryInterface(riid, ppv);
@@ -89,50 +87,47 @@ HRESULT CDXRAllocatorPresenter::SetDevice(IDirect3DDevice9* pD3DDev)
CheckPointer(pD3DDev, E_POINTER);
CSize size;
- switch(GetRenderersSettings().nSPCMaxRes)
- {
- case 0:
- default:
- size = m_ScreenSize;
- break;
- case 1:
- size.SetSize(1024, 768);
- break;
- case 2:
- size.SetSize(800, 600);
- break;
- case 3:
- size.SetSize(640, 480);
- break;
- case 4:
- size.SetSize(512, 384);
- break;
- case 5:
- size.SetSize(384, 288);
- break;
- case 6:
- size.SetSize(2560, 1600);
- break;
- case 7:
- size.SetSize(1920, 1080);
- break;
- case 8:
- size.SetSize(1320, 900);
- break;
- case 9:
- size.SetSize(1280, 720);
- break;
- }
-
- if(m_pAllocator)
- {
- m_pAllocator->ChangeDevice(pD3DDev);
+ switch(GetRenderersSettings().nSPCMaxRes) {
+ case 0:
+ default:
+ size = m_ScreenSize;
+ break;
+ case 1:
+ size.SetSize(1024, 768);
+ break;
+ case 2:
+ size.SetSize(800, 600);
+ break;
+ case 3:
+ size.SetSize(640, 480);
+ break;
+ case 4:
+ size.SetSize(512, 384);
+ break;
+ case 5:
+ size.SetSize(384, 288);
+ break;
+ case 6:
+ size.SetSize(2560, 1600);
+ break;
+ case 7:
+ size.SetSize(1920, 1080);
+ break;
+ case 8:
+ size.SetSize(1320, 900);
+ break;
+ case 9:
+ size.SetSize(1280, 720);
+ break;
}
- else
- {
+
+ if(m_pAllocator) {
+ m_pAllocator->ChangeDevice(pD3DDev);
+ } else {
m_pAllocator = DNew CDX9SubPicAllocator(pD3DDev, size, GetRenderersSettings().fSPCPow2Tex);
- if(!m_pAllocator)
+ if(!m_pAllocator) {
return E_FAIL;
+ }
}
HRESULT hr = S_OK;
@@ -140,10 +135,13 @@ HRESULT CDXRAllocatorPresenter::SetDevice(IDirect3DDevice9* pD3DDev)
m_pSubPicQueue = GetRenderersSettings().nSPCSize > 0
? (ISubPicQueue*)DNew CSubPicQueue(GetRenderersSettings().nSPCSize, !GetRenderersSettings().fSPCAllowAnimationWhenBuffering, m_pAllocator, &hr)
: (ISubPicQueue*)DNew CSubPicQueueNoThread(m_pAllocator, &hr);
- if(!m_pSubPicQueue || FAILED(hr))
+ if(!m_pSubPicQueue || FAILED(hr)) {
return E_FAIL;
+ }
- if(m_SubPicProvider) m_pSubPicQueue->SetSubPicProvider(m_SubPicProvider);
+ if(m_SubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(m_SubPicProvider);
+ }
return S_OK;
}
@@ -154,7 +152,9 @@ HRESULT CDXRAllocatorPresenter::Render(
{
__super::SetPosition(CRect(0, 0, width, height), CRect(left, top, right, bottom)); // needed? should be already set by the player
SetTime(rtStart);
- if(atpf > 0 && m_pSubPicQueue) m_pSubPicQueue->SetFPS(10000000.0 / atpf);
+ if(atpf > 0 && m_pSubPicQueue) {
+ m_pSubPicQueue->SetFPS(10000000.0 / atpf);
+ }
AlphaBltSubPic(CSize(width, height));
return S_OK;
}
@@ -165,20 +165,22 @@ STDMETHODIMP CDXRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
{
CheckPointer(ppRenderer, E_POINTER);
- if(m_pDXR) return E_UNEXPECTED;
+ if(m_pDXR) {
+ return E_UNEXPECTED;
+ }
m_pDXR.CoCreateInstance(CLSID_DXR, GetOwner());
- if(!m_pDXR) return E_FAIL;
+ if(!m_pDXR) {
+ return E_FAIL;
+ }
CComQIPtr<ISubRender> pSR = m_pDXR;
- if(!pSR)
- {
+ if(!pSR) {
m_pDXR = NULL;
return E_FAIL;
}
m_pSRCB = DNew CSubRenderCallback(this);
- if(FAILED(pSR->SetCallback(m_pSRCB)))
- {
+ if(FAILED(pSR->SetCallback(m_pSRCB))) {
m_pDXR = NULL;
return E_FAIL;
}
@@ -187,22 +189,21 @@ STDMETHODIMP CDXRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
MONITORINFO mi;
mi.cbSize = sizeof(MONITORINFO);
- if (GetMonitorInfo(MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST), &mi))
+ if (GetMonitorInfo(MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST), &mi)) {
m_ScreenSize.SetSize(mi.rcMonitor.right-mi.rcMonitor.left, mi.rcMonitor.bottom-mi.rcMonitor.top);
+ }
return S_OK;
}
STDMETHODIMP_(void) CDXRAllocatorPresenter::SetPosition(RECT w, RECT v)
{
- if(CComQIPtr<IBasicVideo> pBV = m_pDXR)
- {
+ if(CComQIPtr<IBasicVideo> pBV = m_pDXR) {
pBV->SetDefaultSourcePosition();
pBV->SetDestinationPosition(v.left, v.top, v.right - v.left, v.bottom - v.top);
}
- if(CComQIPtr<IVideoWindow> pVW = m_pDXR)
- {
+ if(CComQIPtr<IVideoWindow> pVW = m_pDXR) {
pVW->SetWindowPosition(w.left, w.top, w.right - w.left, w.bottom - w.top);
}
}
@@ -211,15 +212,14 @@ STDMETHODIMP_(SIZE) CDXRAllocatorPresenter::GetVideoSize(bool fCorrectAR)
{
SIZE size = {0, 0};
- if(!fCorrectAR)
- {
- if(CComQIPtr<IBasicVideo> pBV = m_pDXR)
+ if(!fCorrectAR) {
+ if(CComQIPtr<IBasicVideo> pBV = m_pDXR) {
pBV->GetVideoSize(&size.cx, &size.cy);
- }
- else
- {
- if(CComQIPtr<IBasicVideo2> pBV2 = m_pDXR)
+ }
+ } else {
+ if(CComQIPtr<IBasicVideo2> pBV2 = m_pDXR) {
pBV2->GetPreferredAspectRatio(&size.cx, &size.cy);
+ }
}
return size;
@@ -233,8 +233,9 @@ STDMETHODIMP_(bool) CDXRAllocatorPresenter::Paint(bool fAll)
STDMETHODIMP CDXRAllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
{
HRESULT hr = E_NOTIMPL;
- if(CComQIPtr<IBasicVideo> pBV = m_pDXR)
+ if(CComQIPtr<IBasicVideo> pBV = m_pDXR) {
hr = pBV->GetCurrentImage((long*)size, (long*)lpDib);
+ }
return hr;
}
diff --git a/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.h b/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.h
index f5c79c9d0..65d5e263e 100644
--- a/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/DXRAllocatorPresenter.h
@@ -28,79 +28,73 @@
namespace DSObjects
{
-class CDXRAllocatorPresenter
- : public CSubPicAllocatorPresenterImpl
-{
- class CSubRenderCallback : public CUnknown, public ISubRenderCallback, public CCritSec
+ class CDXRAllocatorPresenter
+ : public CSubPicAllocatorPresenterImpl
{
- CDXRAllocatorPresenter* m_pDXRAP;
+ class CSubRenderCallback : public CUnknown, public ISubRenderCallback, public CCritSec
+ {
+ CDXRAllocatorPresenter* m_pDXRAP;
+
+ public:
+ CSubRenderCallback(CDXRAllocatorPresenter* pDXRAP)
+ : CUnknown(_T("CSubRender"), NULL)
+ , m_pDXRAP(pDXRAP) {
+ }
+
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
+ return
+ QI(ISubRenderCallback)
+ __super::NonDelegatingQueryInterface(riid, ppv);
+ }
+
+ void SetDXRAP(CDXRAllocatorPresenter* pDXRAP) {
+ CAutoLock cAutoLock(this);
+ m_pDXRAP = pDXRAP;
+ }
+
+ // ISubRenderCallback
+
+ STDMETHODIMP SetDevice(IDirect3DDevice9* pD3DDev) {
+ CAutoLock cAutoLock(this);
+ return m_pDXRAP ? m_pDXRAP->SetDevice(pD3DDev) : E_UNEXPECTED;
+ }
+
+ STDMETHODIMP Render(REFERENCE_TIME rtStart, int left, int top, int right, int bottom, int width, int height) {
+ CAutoLock cAutoLock(this);
+ return m_pDXRAP ? m_pDXRAP->Render(rtStart, 0, 0, left, top, right, bottom, width, height) : E_UNEXPECTED;
+ }
+
+ // ISubRendererCallback2
+
+ STDMETHODIMP RenderEx(REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME AvgTimePerFrame, int left, int top, int right, int bottom, int width, int height) {
+ CAutoLock cAutoLock(this);
+ return m_pDXRAP ? m_pDXRAP->Render(rtStart, rtStop, AvgTimePerFrame, left, top, right, bottom, width, height) : E_UNEXPECTED;
+ }
+ };
+
+ CComPtr<IUnknown> m_pDXR;
+ CComPtr<ISubRenderCallback> m_pSRCB;
+ CSize m_ScreenSize;
public:
- CSubRenderCallback(CDXRAllocatorPresenter* pDXRAP)
- : CUnknown(_T("CSubRender"), NULL)
- , m_pDXRAP(pDXRAP)
- {
- }
+ CDXRAllocatorPresenter(HWND hWnd, HRESULT& hr, CString &_Error);
+ virtual ~CDXRAllocatorPresenter();
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
- return
- QI(ISubRenderCallback)
- __super::NonDelegatingQueryInterface(riid, ppv);
- }
-
- void SetDXRAP(CDXRAllocatorPresenter* pDXRAP)
- {
- CAutoLock cAutoLock(this);
- m_pDXRAP = pDXRAP;
- }
-
- // ISubRenderCallback
-
- STDMETHODIMP SetDevice(IDirect3DDevice9* pD3DDev)
- {
- CAutoLock cAutoLock(this);
- return m_pDXRAP ? m_pDXRAP->SetDevice(pD3DDev) : E_UNEXPECTED;
- }
-
- STDMETHODIMP Render(REFERENCE_TIME rtStart, int left, int top, int right, int bottom, int width, int height)
- {
- CAutoLock cAutoLock(this);
- return m_pDXRAP ? m_pDXRAP->Render(rtStart, 0, 0, left, top, right, bottom, width, height) : E_UNEXPECTED;
- }
-
- // ISubRendererCallback2
-
- STDMETHODIMP RenderEx(REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME AvgTimePerFrame, int left, int top, int right, int bottom, int width, int height)
- {
- CAutoLock cAutoLock(this);
- return m_pDXRAP ? m_pDXRAP->Render(rtStart, rtStop, AvgTimePerFrame, left, top, right, bottom, width, height) : E_UNEXPECTED;
- }
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ HRESULT SetDevice(IDirect3DDevice9* pD3DDev);
+ HRESULT Render(
+ REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME atpf,
+ int left, int top, int bottom, int right, int width, int height);
+
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(void) SetPosition(RECT w, RECT v);
+ STDMETHODIMP_(SIZE) GetVideoSize(bool fCorrectAR);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
+ STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
};
-
- CComPtr<IUnknown> m_pDXR;
- CComPtr<ISubRenderCallback> m_pSRCB;
- CSize m_ScreenSize;
-
-public:
- CDXRAllocatorPresenter(HWND hWnd, HRESULT& hr, CString &_Error);
- virtual ~CDXRAllocatorPresenter();
-
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- HRESULT SetDevice(IDirect3DDevice9* pD3DDev);
- HRESULT Render(
- REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME atpf,
- int left, int top, int bottom, int right, int width, int height);
-
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(void) SetPosition(RECT w, RECT v);
- STDMETHODIMP_(SIZE) GetVideoSize(bool fCorrectAR);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
- STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
-};
}
diff --git a/src/filters/renderer/VideoRenderers/Dither.cpp b/src/filters/renderer/VideoRenderers/Dither.cpp
index d7455a168..c6dd1c75d 100644
--- a/src/filters/renderer/VideoRenderers/Dither.cpp
+++ b/src/filters/renderer/VideoRenderers/Dither.cpp
@@ -23,8 +23,7 @@
#include "Dither.h"
// Dither matrix in 16-bit floating point format
-const unsigned short DITHER_MATRIX[DITHER_MATRIX_SIZE][DITHER_MATRIX_SIZE] =
-{
+const unsigned short DITHER_MATRIX[DITHER_MATRIX_SIZE][DITHER_MATRIX_SIZE] = {
0x2c90, 0x38f4, 0x3bba, 0x29e0, 0x35f4, 0x3230, 0x3bbc, 0x3924, 0x3a46, 0x3644, 0x39e2, 0x370c, 0x3444, 0x3b1a, 0x3140, 0x39d2,
0x385a, 0x3b24, 0x2c10, 0x38c6, 0x3808, 0x2780, 0x3bbe, 0x37f8, 0x350c, 0x3a6c, 0x3368, 0x3bc0, 0x3000, 0x3886, 0x31b0, 0x3554,
0x3a94, 0x3618, 0x3430, 0x3a34, 0x3834, 0x39fe, 0x2740, 0x3758, 0x3494, 0x3b7a, 0x2700, 0x3958, 0x3858, 0x3a24, 0x364c, 0x3bc2,
diff --git a/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp
index 631fa05ca..fd046d3a7 100644
--- a/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.cpp
@@ -33,8 +33,7 @@
#define TRACE_EVR
#endif
-typedef enum
-{
+typedef enum {
MSG_MIXERIN,
MSG_MIXEROUT
} EVR_STATS_MSG;
@@ -69,186 +68,190 @@ MFVideoArea MakeArea(float x, float y, DWORD width, DWORD height)
namespace DSObjects
{
-class COuterEVR
- : public CUnknown
- , public IVMRffdshow9
- , public IVMRMixerBitmap9
- , public IBaseFilter
-{
- CComPtr<IUnknown> m_pEVR;
- VMR9AlphaBitmap* m_pVMR9AlphaBitmap;
- CEVRAllocatorPresenter *m_pAllocatorPresenter;
+ class COuterEVR
+ : public CUnknown
+ , public IVMRffdshow9
+ , public IVMRMixerBitmap9
+ , public IBaseFilter
+ {
+ CComPtr<IUnknown> m_pEVR;
+ VMR9AlphaBitmap* m_pVMR9AlphaBitmap;
+ CEVRAllocatorPresenter *m_pAllocatorPresenter;
-public:
+ public:
- // IBaseFilter
- virtual HRESULT STDMETHODCALLTYPE EnumPins(__out IEnumPins **ppEnum)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->EnumPins(ppEnum);
- return E_NOTIMPL;
- }
+ // IBaseFilter
+ virtual HRESULT STDMETHODCALLTYPE EnumPins(__out IEnumPins **ppEnum) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->EnumPins(ppEnum);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, __out IPin **ppPin)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->FindPin(Id, ppPin);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, __out IPin **ppPin) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->FindPin(Id, ppPin);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE QueryFilterInfo(__out FILTER_INFO *pInfo)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->QueryFilterInfo(pInfo);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE QueryFilterInfo(__out FILTER_INFO *pInfo) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->QueryFilterInfo(pInfo);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE JoinFilterGraph(__in_opt IFilterGraph *pGraph, __in_opt LPCWSTR pName)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->JoinFilterGraph(pGraph, pName);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE JoinFilterGraph(__in_opt IFilterGraph *pGraph, __in_opt LPCWSTR pName) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->JoinFilterGraph(pGraph, pName);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE QueryVendorInfo(__out LPWSTR *pVendorInfo)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->QueryVendorInfo(pVendorInfo);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE QueryVendorInfo(__out LPWSTR *pVendorInfo) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->QueryVendorInfo(pVendorInfo);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE Stop( void)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->Stop();
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE Stop( void) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->Stop();
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE Pause( void)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->Pause();
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE Pause( void) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->Pause();
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE Run( REFERENCE_TIME tStart)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->Run(tStart);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE Run( REFERENCE_TIME tStart) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->Run(tStart);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE GetState( DWORD dwMilliSecsTimeout, __out FILTER_STATE *State);
+ virtual HRESULT STDMETHODCALLTYPE GetState( DWORD dwMilliSecsTimeout, __out FILTER_STATE *State);
- virtual HRESULT STDMETHODCALLTYPE SetSyncSource(__in_opt IReferenceClock *pClock)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->SetSyncSource(pClock);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE SetSyncSource(__in_opt IReferenceClock *pClock) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->SetSyncSource(pClock);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE GetSyncSource(__deref_out_opt IReferenceClock **pClock)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->GetSyncSource(pClock);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE GetSyncSource(__deref_out_opt IReferenceClock **pClock) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->GetSyncSource(pClock);
+ }
+ return E_NOTIMPL;
+ }
- virtual HRESULT STDMETHODCALLTYPE GetClassID(__RPC__out CLSID *pClassID)
- {
- CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
- m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
- return pEVRBase->GetClassID(pClassID);
- return E_NOTIMPL;
- }
+ virtual HRESULT STDMETHODCALLTYPE GetClassID(__RPC__out CLSID *pClassID) {
+ CComPtr<IBaseFilter> pEVRBase;
+ if (m_pEVR) {
+ m_pEVR->QueryInterface(&pEVRBase);
+ }
+ if (pEVRBase) {
+ return pEVRBase->GetClassID(pClassID);
+ }
+ return E_NOTIMPL;
+ }
- COuterEVR(const TCHAR* pName, LPUNKNOWN pUnk, HRESULT& hr, VMR9AlphaBitmap* pVMR9AlphaBitmap, CEVRAllocatorPresenter *pAllocatorPresenter) : CUnknown(pName, pUnk)
- {
- hr = m_pEVR.CoCreateInstance(CLSID_EnhancedVideoRenderer, GetOwner());
- m_pVMR9AlphaBitmap = pVMR9AlphaBitmap;
- m_pAllocatorPresenter = pAllocatorPresenter;
- }
+ COuterEVR(const TCHAR* pName, LPUNKNOWN pUnk, HRESULT& hr, VMR9AlphaBitmap* pVMR9AlphaBitmap, CEVRAllocatorPresenter *pAllocatorPresenter) : CUnknown(pName, pUnk) {
+ hr = m_pEVR.CoCreateInstance(CLSID_EnhancedVideoRenderer, GetOwner());
+ m_pVMR9AlphaBitmap = pVMR9AlphaBitmap;
+ m_pAllocatorPresenter = pAllocatorPresenter;
+ }
- ~COuterEVR();
+ ~COuterEVR();
- DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
- HRESULT hr;
+ DECLARE_IUNKNOWN;
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
+ HRESULT hr;
- if(riid == __uuidof(IVMRMixerBitmap9))
- {
- return GetInterface((IVMRMixerBitmap9*)this, ppv);
- }
- if (riid == __uuidof(IMediaFilter))
- {
- return GetInterface((IMediaFilter*)this, ppv);
- }
- if (riid == __uuidof(IPersist))
- {
- return GetInterface((IPersist*)this, ppv);
- }
- if (riid == __uuidof(IBaseFilter))
- {
- return GetInterface((IBaseFilter*)this, ppv);
- }
+ if(riid == __uuidof(IVMRMixerBitmap9)) {
+ return GetInterface((IVMRMixerBitmap9*)this, ppv);
+ }
+ if (riid == __uuidof(IMediaFilter)) {
+ return GetInterface((IMediaFilter*)this, ppv);
+ }
+ if (riid == __uuidof(IPersist)) {
+ return GetInterface((IPersist*)this, ppv);
+ }
+ if (riid == __uuidof(IBaseFilter)) {
+ return GetInterface((IBaseFilter*)this, ppv);
+ }
- hr = m_pEVR ? m_pEVR->QueryInterface(riid, ppv) : E_NOINTERFACE;
- if(m_pEVR && FAILED(hr))
- {
- if(riid == __uuidof(IVMRffdshow9)) // Support ffdshow queueing. We show ffdshow that this is patched Media Player Classic.
- return GetInterface((IVMRffdshow9*)this, ppv);
- }
+ hr = m_pEVR ? m_pEVR->QueryInterface(riid, ppv) : E_NOINTERFACE;
+ if(m_pEVR && FAILED(hr)) {
+ if(riid == __uuidof(IVMRffdshow9)) { // Support ffdshow queueing. We show ffdshow that this is patched Media Player Classic.
+ return GetInterface((IVMRffdshow9*)this, ppv);
+ }
+ }
- return SUCCEEDED(hr) ? hr : __super::NonDelegatingQueryInterface(riid, ppv);
- }
+ return SUCCEEDED(hr) ? hr : __super::NonDelegatingQueryInterface(riid, ppv);
+ }
- // IVMRffdshow9
- STDMETHODIMP support_ffdshow()
- {
- queue_ffdshow_support = true;
- return S_OK;
- }
+ // IVMRffdshow9
+ STDMETHODIMP support_ffdshow() {
+ queue_ffdshow_support = true;
+ return S_OK;
+ }
- // IVMRMixerBitmap9
- STDMETHODIMP GetAlphaBitmapParameters(VMR9AlphaBitmap* pBmpParms);
+ // IVMRMixerBitmap9
+ STDMETHODIMP GetAlphaBitmapParameters(VMR9AlphaBitmap* pBmpParms);
- STDMETHODIMP SetAlphaBitmap(const VMR9AlphaBitmap* pBmpParms);
+ STDMETHODIMP SetAlphaBitmap(const VMR9AlphaBitmap* pBmpParms);
- STDMETHODIMP UpdateAlphaBitmapParameters(const VMR9AlphaBitmap* pBmpParms);
-};
+ STDMETHODIMP UpdateAlphaBitmapParameters(const VMR9AlphaBitmap* pBmpParms);
+ };
}
using namespace DSObjects;
@@ -256,13 +259,16 @@ using namespace DSObjects;
HRESULT STDMETHODCALLTYPE COuterEVR::GetState( DWORD dwMilliSecsTimeout, __out FILTER_STATE *State)
{
HRESULT ReturnValue;
- if (m_pAllocatorPresenter->GetState(dwMilliSecsTimeout, State, ReturnValue))
+ if (m_pAllocatorPresenter->GetState(dwMilliSecsTimeout, State, ReturnValue)) {
return ReturnValue;
+ }
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->GetState(dwMilliSecsTimeout, State);
+ }
return E_NOTIMPL;
}
@@ -315,8 +321,7 @@ CEVRAllocatorPresenter::CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
m_ModeratedTimeLast = -1;
m_ModeratedClockLast = -1;
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
_Error += L"DX9AllocatorPresenter failed\n";
return;
}
@@ -331,16 +336,19 @@ CEVRAllocatorPresenter::CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
pfMFCreateVideoSampleFromSurface = hLib ? (PTR_MFCreateVideoSampleFromSurface) GetProcAddress (hLib, "MFCreateVideoSampleFromSurface") : NULL;
pfMFCreateVideoMediaType = hLib ? (PTR_MFCreateVideoMediaType) GetProcAddress (hLib, "MFCreateVideoMediaType") : NULL;
- if (!pfDXVA2CreateDirect3DDeviceManager9 || !pfMFCreateDXSurfaceBuffer || !pfMFCreateVideoSampleFromSurface || !pfMFCreateVideoMediaType)
- {
- if (!pfDXVA2CreateDirect3DDeviceManager9)
+ if (!pfDXVA2CreateDirect3DDeviceManager9 || !pfMFCreateDXSurfaceBuffer || !pfMFCreateVideoSampleFromSurface || !pfMFCreateVideoMediaType) {
+ if (!pfDXVA2CreateDirect3DDeviceManager9) {
_Error += L"Could not find DXVA2CreateDirect3DDeviceManager9 (dxva2.dll)\n";
- if (!pfMFCreateDXSurfaceBuffer)
+ }
+ if (!pfMFCreateDXSurfaceBuffer) {
_Error += L"Could not find MFCreateDXSurfaceBuffer (evr.dll)\n";
- if (!pfMFCreateVideoSampleFromSurface)
+ }
+ if (!pfMFCreateVideoSampleFromSurface) {
_Error += L"Could not find MFCreateVideoSampleFromSurface (evr.dll)\n";
- if (!pfMFCreateVideoMediaType)
+ }
+ if (!pfMFCreateVideoMediaType) {
_Error += L"Could not find MFCreateVideoMediaType (evr.dll)\n";
+ }
hr = E_FAIL;
return;
}
@@ -352,8 +360,7 @@ CEVRAllocatorPresenter::CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
(FARPROC &)pMFInitMediaTypeFromAMMediaType = GetProcAddress(hLib, "MFInitMediaTypeFromAMMediaType");
(FARPROC &)pMFInitAMMediaTypeFromMFMediaType = GetProcAddress(hLib, "MFInitAMMediaTypeFromMFMediaType");
- if (!pMFCreateMediaType || !pMFInitMediaTypeFromAMMediaType || !pMFInitAMMediaTypeFromMFMediaType)
- {
+ if (!pMFCreateMediaType || !pMFInitMediaTypeFromAMMediaType || !pMFInitAMMediaTypeFromMFMediaType) {
hr = E_FAIL;
return;
}
@@ -367,22 +374,19 @@ CEVRAllocatorPresenter::CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
// Init DXVA manager
hr = pfDXVA2CreateDirect3DDeviceManager9(&m_nResetToken, &m_pD3DManager);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
hr = m_pD3DManager->ResetDevice(m_pD3DDev, m_nResetToken);
- if (!SUCCEEDED (hr))
- {
+ if (!SUCCEEDED (hr)) {
_Error += L"m_pD3DManager->ResetDevice failed\n";
}
- }
- else
+ } else {
_Error += L"DXVA2CreateDirect3DDeviceManager9 failed\n";
+ }
CComPtr<IDirectXVideoDecoderService> pDecoderService;
HANDLE hDevice;
if (SUCCEEDED (m_pD3DManager->OpenDeviceHandle(&hDevice)) &&
- SUCCEEDED (m_pD3DManager->GetVideoService (hDevice, __uuidof(IDirectXVideoDecoderService), (void**)&pDecoderService)))
- {
+ SUCCEEDED (m_pD3DManager->GetVideoService (hDevice, __uuidof(IDirectXVideoDecoderService), (void**)&pDecoderService))) {
TRACE_EVR ("EVR: DXVA2 : device handle = 0x%08x", hDevice);
HookDirectXVideoDecoderService (pDecoderService);
@@ -391,10 +395,11 @@ CEVRAllocatorPresenter::CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRES
// Bufferize frame only with 3D texture!
- if (s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
+ if (s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
m_nNbDXSurface = max (min (s.iEvrBuffers, MAX_VIDEO_SURFACES), 4);
- else
+ } else {
m_nNbDXSurface = 1;
+ }
ResetStats();
m_nRenderState = Shutdown;
@@ -442,12 +447,9 @@ void CEVRAllocatorPresenter::ResetStats()
HRESULT CEVRAllocatorPresenter::CheckShutdown() const
{
- if (m_nRenderState == Shutdown)
- {
+ if (m_nRenderState == Shutdown) {
return MF_E_SHUTDOWN;
- }
- else
- {
+ } else {
return S_OK;
}
}
@@ -457,8 +459,7 @@ void CEVRAllocatorPresenter::StartWorkerThreads()
{
DWORD dwThreadId;
- if (m_nRenderState == Shutdown)
- {
+ if (m_nRenderState == Shutdown) {
m_hEvtQuit = CreateEvent (NULL, TRUE, FALSE, NULL);
m_hEvtFlush = CreateEvent (NULL, TRUE, FALSE, NULL);
@@ -474,27 +475,32 @@ void CEVRAllocatorPresenter::StartWorkerThreads()
void CEVRAllocatorPresenter::StopWorkerThreads()
{
- if (m_nRenderState != Shutdown)
- {
+ if (m_nRenderState != Shutdown) {
SetEvent (m_hEvtFlush);
m_bEvtFlush = true;
SetEvent (m_hEvtQuit);
m_bEvtQuit = true;
- if ((m_hThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hThread, 10000) == WAIT_TIMEOUT))
- {
+ if ((m_hThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hThread, 10000) == WAIT_TIMEOUT)) {
ASSERT (FALSE);
TerminateThread (m_hThread, 0xDEAD);
}
- if ((m_hGetMixerThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hGetMixerThread, 10000) == WAIT_TIMEOUT))
- {
+ if ((m_hGetMixerThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hGetMixerThread, 10000) == WAIT_TIMEOUT)) {
ASSERT (FALSE);
TerminateThread (m_hGetMixerThread, 0xDEAD);
}
- if (m_hThread != INVALID_HANDLE_VALUE) CloseHandle (m_hThread);
- if (m_hGetMixerThread != INVALID_HANDLE_VALUE) CloseHandle (m_hGetMixerThread);
- if (m_hEvtFlush != INVALID_HANDLE_VALUE) CloseHandle (m_hEvtFlush);
- if (m_hEvtQuit != INVALID_HANDLE_VALUE) CloseHandle (m_hEvtQuit);
+ if (m_hThread != INVALID_HANDLE_VALUE) {
+ CloseHandle (m_hThread);
+ }
+ if (m_hGetMixerThread != INVALID_HANDLE_VALUE) {
+ CloseHandle (m_hGetMixerThread);
+ }
+ if (m_hEvtFlush != INVALID_HANDLE_VALUE) {
+ CloseHandle (m_hEvtFlush);
+ }
+ if (m_hEvtQuit != INVALID_HANDLE_VALUE) {
+ CloseHandle (m_hEvtQuit);
+ }
m_bEvtFlush = false;
m_bEvtQuit = false;
@@ -514,8 +520,7 @@ STDMETHODIMP CEVRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
HRESULT hr = E_FAIL;
- do
- {
+ do {
CMacrovisionKicker* pMK = DNew CMacrovisionKicker(NAME("CMacrovisionKicker"), NULL);
CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)pMK;
@@ -525,7 +530,9 @@ STDMETHODIMP CEVRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
pMK->SetInner((IUnknown*)(INonDelegatingUnknown*)pOuterEVR);
CComQIPtr<IBaseFilter> pBF = pUnk;
- if (FAILED (hr)) break;
+ if (FAILED (hr)) {
+ break;
+ }
// Set EVR custom presenter
CComPtr<IMFVideoPresenter> pVP;
@@ -534,8 +541,12 @@ STDMETHODIMP CEVRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
hr = pMFGS->GetService (MR_VIDEO_RENDER_SERVICE, IID_IMFVideoRenderer, (void**)&pMFVR);
- if(SUCCEEDED(hr)) hr = QueryInterface (__uuidof(IMFVideoPresenter), (void**)&pVP);
- if(SUCCEEDED(hr)) hr = pMFVR->InitializeRenderer (NULL, pVP);
+ if(SUCCEEDED(hr)) {
+ hr = QueryInterface (__uuidof(IMFVideoPresenter), (void**)&pVP);
+ }
+ if(SUCCEEDED(hr)) {
+ hr = pMFVR->InitializeRenderer (NULL, pVP);
+ }
#if 1
CComPtr<IPin> pPin = GetFirstPin(pBF);
@@ -547,13 +558,13 @@ STDMETHODIMP CEVRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
m_fUseInternalTimer = false;
#endif
- if(FAILED(hr))
+ if(FAILED(hr)) {
*ppRenderer = NULL;
- else
+ } else {
*ppRenderer = pBF.Detach();
+ }
- }
- while (0);
+ } while (0);
return hr;
}
@@ -566,31 +577,33 @@ STDMETHODIMP_(bool) CEVRAllocatorPresenter::Paint(bool fAll)
STDMETHODIMP CEVRAllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
HRESULT hr;
- if(riid == __uuidof(IMFClockStateSink))
+ if(riid == __uuidof(IMFClockStateSink)) {
hr = GetInterface((IMFClockStateSink*)this, ppv);
- else if(riid == __uuidof(IMFVideoPresenter))
+ } else if(riid == __uuidof(IMFVideoPresenter)) {
hr = GetInterface((IMFVideoPresenter*)this, ppv);
- else if(riid == __uuidof(IMFTopologyServiceLookupClient))
+ } else if(riid == __uuidof(IMFTopologyServiceLookupClient)) {
hr = GetInterface((IMFTopologyServiceLookupClient*)this, ppv);
- else if(riid == __uuidof(IMFVideoDeviceID))
+ } else if(riid == __uuidof(IMFVideoDeviceID)) {
hr = GetInterface((IMFVideoDeviceID*)this, ppv);
- else if(riid == __uuidof(IMFGetService))
+ } else if(riid == __uuidof(IMFGetService)) {
hr = GetInterface((IMFGetService*)this, ppv);
- else if(riid == __uuidof(IMFAsyncCallback))
+ } else if(riid == __uuidof(IMFAsyncCallback)) {
hr = GetInterface((IMFAsyncCallback*)this, ppv);
- else if(riid == __uuidof(IMFVideoDisplayControl))
+ } else if(riid == __uuidof(IMFVideoDisplayControl)) {
hr = GetInterface((IMFVideoDisplayControl*)this, ppv);
- else if(riid == __uuidof(IEVRTrustedVideoPlugin))
+ } else if(riid == __uuidof(IEVRTrustedVideoPlugin)) {
hr = GetInterface((IEVRTrustedVideoPlugin*)this, ppv);
- else if(riid == IID_IQualProp)
+ } else if(riid == IID_IQualProp) {
hr = GetInterface((IQualProp*)this, ppv);
- else if(riid == __uuidof(IMFRateSupport))
+ } else if(riid == __uuidof(IMFRateSupport)) {
hr = GetInterface((IMFRateSupport*)this, ppv);
- else if(riid == __uuidof(IDirect3DDeviceManager9))
-// hr = GetInterface((IDirect3DDeviceManager9*)this, ppv);
+ } else if(riid == __uuidof(IDirect3DDeviceManager9))
+ // hr = GetInterface((IDirect3DDeviceManager9*)this, ppv);
+ {
hr = m_pD3DManager->QueryInterface (__uuidof(IDirect3DDeviceManager9), (void**) ppv);
- else
+ } else {
hr = __super::NonDelegatingQueryInterface(riid, ppv);
+ }
return hr;
}
@@ -621,8 +634,9 @@ STDMETHODIMP CEVRAllocatorPresenter::OnClockStop(MFTIME hnsSystemTime)
STDMETHODIMP CEVRAllocatorPresenter::OnClockPause(MFTIME hnsSystemTime)
{
TRACE_EVR ("EVR: OnClockPause hnsSystemTime = %I64d\n", hnsSystemTime);
- if (!m_bSignaledStarvation)
+ if (!m_bSignaledStarvation) {
m_nRenderState = Paused;
+ }
m_ModeratedTimeLast = -1;
m_ModeratedClockLast = -1;
return S_OK;
@@ -652,11 +666,9 @@ bool CEVRAllocatorPresenter::GetState( DWORD dwMilliSecsTimeout, FILTER_STATE *S
{
CAutoLock lock(&m_SampleQueueLock);
- if (m_bSignaledStarvation)
- {
+ if (m_bSignaledStarvation) {
int nSamples = max(m_nNbDXSurface / 2, 1);
- if ((m_ScheduledSamples.GetCount() < nSamples || m_LastSampleOffset < -m_rtTimePerFrame*2) && !g_bNoDuration)
- {
+ if ((m_ScheduledSamples.GetCount() < nSamples || m_LastSampleOffset < -m_rtTimePerFrame*2) && !g_bNoDuration) {
*State = (FILTER_STATE)Paused;
_ReturnValue = VFW_S_STATE_INTERMEDIATE;
return true;
@@ -721,8 +733,9 @@ STDMETHODIMP CEVRAllocatorPresenter::GetFastestRate(MFRATE_DIRECTION eDirection,
fMaxRate = GetMaxRate(fThin);
// For reverse playback, swap the sign.
- if (eDirection == MFRATE_REVERSE)
+ if (eDirection == MFRATE_REVERSE) {
fMaxRate = -fMaxRate;
+ }
*pflRate = fMaxRate;
@@ -746,23 +759,22 @@ STDMETHODIMP CEVRAllocatorPresenter::IsRateSupported(BOOL fThin, float flRate, f
// Find the maximum forward rate.
fMaxRate = GetMaxRate(fThin);
- if (fabsf(flRate) > fMaxRate)
- {
+ if (fabsf(flRate) > fMaxRate) {
// The (absolute) requested rate exceeds the maximum rate.
hr = MF_E_UNSUPPORTED_RATE;
// The nearest supported rate is fMaxRate.
fNearestRate = fMaxRate;
- if (flRate < 0)
- {
+ if (flRate < 0) {
// For reverse playback, swap the sign.
fNearestRate = -fNearestRate;
}
}
// Return the nearest supported rate if the caller requested it.
- if (pflNearestSupportedRate != NULL)
+ if (pflNearestSupportedRate != NULL) {
*pflNearestSupportedRate = fNearestRate;
+ }
return hr;
}
@@ -774,8 +786,7 @@ float CEVRAllocatorPresenter::GetMaxRate(BOOL bThin)
UINT32 fpsNumerator = 0, fpsDenominator = 0;
UINT MonitorRateHz = 0;
- if (!bThin && (m_pMediaType != NULL))
- {
+ if (!bThin && (m_pMediaType != NULL)) {
// Non-thinned: Use the frame rate and monitor refresh rate.
// Frame rate:
@@ -785,8 +796,7 @@ float CEVRAllocatorPresenter::GetMaxRate(BOOL bThin)
// Monitor refresh rate:
MonitorRateHz = m_RefreshRate; // D3DDISPLAYMODE
- if (fpsDenominator && fpsNumerator && MonitorRateHz)
- {
+ if (fpsDenominator && fpsNumerator && MonitorRateHz) {
// Max Rate = Refresh Rate / Frame Rate
fMaxRate = (float)MulDiv(
MonitorRateHz, fpsDenominator, fpsNumerator);
@@ -797,15 +807,13 @@ float CEVRAllocatorPresenter::GetMaxRate(BOOL bThin)
void CEVRAllocatorPresenter::CompleteFrameStep(bool bCancel)
{
- if (m_nStepCount > 0)
- {
- if (bCancel || (m_nStepCount == 1))
- {
+ if (m_nStepCount > 0) {
+ if (bCancel || (m_nStepCount == 1)) {
m_pSink->Notify(EC_STEP_COMPLETE, bCancel ? TRUE : FALSE, 0);
m_nStepCount = 0;
- }
- else
+ } else {
m_nStepCount--;
+ }
}
}
@@ -814,59 +822,61 @@ STDMETHODIMP CEVRAllocatorPresenter::ProcessMessage(MFVP_MESSAGE_TYPE eMessage,
{
HRESULT hr = S_OK;
- switch (eMessage)
- {
- case MFVP_MESSAGE_BEGINSTREAMING : // The EVR switched from stopped to paused. The presenter should allocate resources
- ResetStats();
- TRACE_EVR ("EVR: MFVP_MESSAGE_BEGINSTREAMING\n");
- break;
-
- case MFVP_MESSAGE_CANCELSTEP : // Cancels a frame step
- TRACE_EVR ("EVR: MFVP_MESSAGE_CANCELSTEP\n");
- CompleteFrameStep (true);
- break;
-
- case MFVP_MESSAGE_ENDOFSTREAM : // All input streams have ended.
- TRACE_EVR ("EVR: MFVP_MESSAGE_ENDOFSTREAM\n");
- m_bPendingMediaFinished = true;
- break;
-
- case MFVP_MESSAGE_ENDSTREAMING : // The EVR switched from running or paused to stopped. The presenter should free resources
- TRACE_EVR ("EVR: MFVP_MESSAGE_ENDSTREAMING\n");
- break;
-
- case MFVP_MESSAGE_FLUSH : // The presenter should discard any pending samples
- SetEvent(m_hEvtFlush);
- m_bEvtFlush = true;
- TRACE_EVR ("EVR: MFVP_MESSAGE_FLUSH\n");
- while (WaitForSingleObject(m_hEvtFlush, 1) == WAIT_OBJECT_0);
- break;
-
- case MFVP_MESSAGE_INVALIDATEMEDIATYPE : // The mixer's output format has changed. The EVR will initiate format negotiation, as described previously
- /*
- 1) The EVR sets the media type on the reference stream.
- 2) The EVR calls IMFVideoPresenter::ProcessMessage on the presenter with the MFVP_MESSAGE_INVALIDATEMEDIATYPE message.
- 3) The presenter sets the media type on the mixer's output stream.
- 4) The EVR sets the media type on the substreams.
- */
- m_bPendingRenegotiate = true;
- while (*((volatile bool *)&m_bPendingRenegotiate))
- Sleep(1);
- break;
-
- case MFVP_MESSAGE_PROCESSINPUTNOTIFY : // One input stream on the mixer has received a new sample
-// GetImageFromMixer();
- break;
-
- case MFVP_MESSAGE_STEP : // Requests a frame step.
- TRACE_EVR ("EVR: MFVP_MESSAGE_STEP\n");
- m_nStepCount = ulParam;
- hr = S_OK;
- break;
-
- default :
- ASSERT (FALSE);
- break;
+ switch (eMessage) {
+ case MFVP_MESSAGE_BEGINSTREAMING : // The EVR switched from stopped to paused. The presenter should allocate resources
+ ResetStats();
+ TRACE_EVR ("EVR: MFVP_MESSAGE_BEGINSTREAMING\n");
+ break;
+
+ case MFVP_MESSAGE_CANCELSTEP : // Cancels a frame step
+ TRACE_EVR ("EVR: MFVP_MESSAGE_CANCELSTEP\n");
+ CompleteFrameStep (true);
+ break;
+
+ case MFVP_MESSAGE_ENDOFSTREAM : // All input streams have ended.
+ TRACE_EVR ("EVR: MFVP_MESSAGE_ENDOFSTREAM\n");
+ m_bPendingMediaFinished = true;
+ break;
+
+ case MFVP_MESSAGE_ENDSTREAMING : // The EVR switched from running or paused to stopped. The presenter should free resources
+ TRACE_EVR ("EVR: MFVP_MESSAGE_ENDSTREAMING\n");
+ break;
+
+ case MFVP_MESSAGE_FLUSH : // The presenter should discard any pending samples
+ SetEvent(m_hEvtFlush);
+ m_bEvtFlush = true;
+ TRACE_EVR ("EVR: MFVP_MESSAGE_FLUSH\n");
+ while (WaitForSingleObject(m_hEvtFlush, 1) == WAIT_OBJECT_0) {
+ ;
+ }
+ break;
+
+ case MFVP_MESSAGE_INVALIDATEMEDIATYPE : // The mixer's output format has changed. The EVR will initiate format negotiation, as described previously
+ /*
+ 1) The EVR sets the media type on the reference stream.
+ 2) The EVR calls IMFVideoPresenter::ProcessMessage on the presenter with the MFVP_MESSAGE_INVALIDATEMEDIATYPE message.
+ 3) The presenter sets the media type on the mixer's output stream.
+ 4) The EVR sets the media type on the substreams.
+ */
+ m_bPendingRenegotiate = true;
+ while (*((volatile bool *)&m_bPendingRenegotiate)) {
+ Sleep(1);
+ }
+ break;
+
+ case MFVP_MESSAGE_PROCESSINPUTNOTIFY : // One input stream on the mixer has received a new sample
+ // GetImageFromMixer();
+ break;
+
+ case MFVP_MESSAGE_STEP : // Requests a frame step.
+ TRACE_EVR ("EVR: MFVP_MESSAGE_STEP\n");
+ m_nStepCount = ulParam;
+ hr = S_OK;
+ break;
+
+ default :
+ ASSERT (FALSE);
+ break;
}
return hr;
}
@@ -880,34 +890,36 @@ HRESULT CEVRAllocatorPresenter::IsMediaTypeSupported(IMFMediaType* pMixerType)
GUID MajorType;
hr = pMixerType->GetMajorType(&MajorType);
- if (SUCCEEDED(hr))
- {
- if (MajorType != MFMediaType_Video)
+ if (SUCCEEDED(hr)) {
+ if (MajorType != MFMediaType_Video) {
hr = MF_E_INVALIDMEDIATYPE;
+ }
}
// We support only progressive formats
MFVideoInterlaceMode InterlaceMode;
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = pMixerType->GetUINT32(MF_MT_INTERLACE_MODE, (UINT32*)&InterlaceMode);
+ }
- if (SUCCEEDED(hr))
- {
- if (InterlaceMode != MFVideoInterlace_Progressive)
+ if (SUCCEEDED(hr)) {
+ if (InterlaceMode != MFVideoInterlace_Progressive) {
hr = MF_E_INVALIDMEDIATYPE;
+ }
}
// Check whether we support the surface format
int Merit;
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = GetMediaTypeMerit(pMixerType, &Merit);
+ }
- if (SUCCEEDED(hr))
- {
- if (Merit == 0)
+ if (SUCCEEDED(hr)) {
+ if (Merit == 0) {
hr = MF_E_INVALIDMEDIATYPE;
+ }
}
return hr;
@@ -926,30 +938,25 @@ HRESULT CEVRAllocatorPresenter::CreateProposedOutputType(IMFMediaType* pMixerTyp
VideoFormat = (MFVIDEOFORMAT*)pAMMedia->pbFormat;
hr = pfMFCreateVideoMediaType (VideoFormat, &m_pMediaType);
- if (0)
- {
+ if (0) {
// This code doesn't work, use same method as VMR9 instead
- if (VideoFormat->videoInfo.FramesPerSecond.Numerator != 0)
- {
- switch (VideoFormat->videoInfo.InterlaceMode)
- {
- case MFVideoInterlace_Progressive:
- case MFVideoInterlace_MixedInterlaceOrProgressive:
- default:
- {
- m_rtTimePerFrame = (10000000I64*VideoFormat->videoInfo.FramesPerSecond.Denominator)/VideoFormat->videoInfo.FramesPerSecond.Numerator;
- m_bInterlaced = false;
- }
- break;
- case MFVideoInterlace_FieldSingleUpper:
- case MFVideoInterlace_FieldSingleLower:
- case MFVideoInterlace_FieldInterleavedUpperFirst:
- case MFVideoInterlace_FieldInterleavedLowerFirst:
- {
- m_rtTimePerFrame = (20000000I64*VideoFormat->videoInfo.FramesPerSecond.Denominator)/VideoFormat->videoInfo.FramesPerSecond.Numerator;
- m_bInterlaced = true;
- }
- break;
+ if (VideoFormat->videoInfo.FramesPerSecond.Numerator != 0) {
+ switch (VideoFormat->videoInfo.InterlaceMode) {
+ case MFVideoInterlace_Progressive:
+ case MFVideoInterlace_MixedInterlaceOrProgressive:
+ default: {
+ m_rtTimePerFrame = (10000000I64*VideoFormat->videoInfo.FramesPerSecond.Denominator)/VideoFormat->videoInfo.FramesPerSecond.Numerator;
+ m_bInterlaced = false;
+ }
+ break;
+ case MFVideoInterlace_FieldSingleUpper:
+ case MFVideoInterlace_FieldSingleLower:
+ case MFVideoInterlace_FieldInterleavedUpperFirst:
+ case MFVideoInterlace_FieldInterleavedLowerFirst: {
+ m_rtTimePerFrame = (20000000I64*VideoFormat->videoInfo.FramesPerSecond.Denominator)/VideoFormat->videoInfo.FramesPerSecond.Numerator;
+ m_bInterlaced = true;
+ }
+ break;
}
}
}
@@ -957,8 +964,7 @@ HRESULT CEVRAllocatorPresenter::CreateProposedOutputType(IMFMediaType* pMixerTyp
m_AspectRatio.cx = VideoFormat->videoInfo.PixelAspectRatio.Numerator;
m_AspectRatio.cy = VideoFormat->videoInfo.PixelAspectRatio.Denominator;
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
i64Size.HighPart = VideoFormat->videoInfo.dwWidth;
i64Size.LowPart = VideoFormat->videoInfo.dwHeight;
m_pMediaType->SetUINT64 (MF_MT_FRAME_SIZE, i64Size.QuadPart);
@@ -968,19 +974,21 @@ HRESULT CEVRAllocatorPresenter::CreateProposedOutputType(IMFMediaType* pMixerTyp
CRenderersSettings& s = GetRenderersSettings();
#if 1
- if (s.m_RenderSettings.iEVROutputRange == 1)
+ if (s.m_RenderSettings.iEVROutputRange == 1) {
m_pMediaType->SetUINT32 (MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_16_235);
- else
+ } else {
m_pMediaType->SetUINT32 (MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_0_255);
+ }
-// m_pMediaType->SetUINT32 (MF_MT_TRANSFER_FUNCTION, MFVideoTransFunc_10);
+ // m_pMediaType->SetUINT32 (MF_MT_TRANSFER_FUNCTION, MFVideoTransFunc_10);
#else
m_pMediaType->SetUINT32 (MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_0_255);
- if (s.iEVROutputRange == 1)
+ if (s.iEVROutputRange == 1) {
m_pMediaType->SetUINT32 (MF_MT_YUV_MATRIX, MFVideoTransferMatrix_BT601);
- else
+ } else {
m_pMediaType->SetUINT32 (MF_MT_YUV_MATRIX, MFVideoTransferMatrix_BT709);
+ }
#endif
@@ -1000,20 +1008,17 @@ HRESULT CEVRAllocatorPresenter::CreateProposedOutputType(IMFMediaType* pMixerTyp
bool bDoneSomething = true;
- if(m_AspectRatio.cx >= 1 && m_AspectRatio.cy >= 1) //if any of these is 0, it will stuck into a infinite loop
- {
- while (bDoneSomething)
- {
+ if(m_AspectRatio.cx >= 1 && m_AspectRatio.cy >= 1) { //if any of these is 0, it will stuck into a infinite loop
+ while (bDoneSomething) {
bDoneSomething = false;
INT MinNum = min(m_AspectRatio.cx, m_AspectRatio.cy);
INT i;
- for (i = 2; i < MinNum+1; ++i)
- {
- if (m_AspectRatio.cx%i == 0 && m_AspectRatio.cy%i ==0)
+ for (i = 2; i < MinNum+1; ++i) {
+ if (m_AspectRatio.cx%i == 0 && m_AspectRatio.cy%i ==0) {
break;
+ }
}
- if (i != MinNum + 1)
- {
+ if (i != MinNum + 1) {
m_AspectRatio.cx = m_AspectRatio.cx / i;
m_AspectRatio.cy = m_AspectRatio.cy / i;
bDoneSomething = true;
@@ -1037,8 +1042,7 @@ HRESULT CEVRAllocatorPresenter::SetMediaType(IMFMediaType* pType)
CheckHR (pType->GetRepresentation(FORMAT_VideoInfo2, (void**)&pAMMedia));
hr = InitializeDevice (pType);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
strTemp = GetMediaTypeName (pAMMedia->subtype);
strTemp.Replace (L"MEDIASUBTYPE_", L"");
m_strStatsMsg[MSG_MIXEROUT].Format (L"Mixer output : %s", strTemp);
@@ -1051,17 +1055,20 @@ HRESULT CEVRAllocatorPresenter::SetMediaType(IMFMediaType* pType)
HRESULT CEVRAllocatorPresenter::GetMediaTypeFourCC(IMFMediaType* pType, DWORD* pFourCC)
{
- if (pFourCC == NULL)
+ if (pFourCC == NULL) {
return E_POINTER;
+ }
HRESULT hr = S_OK;
GUID guidSubType = GUID_NULL;
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = pType->GetGUID(MF_MT_SUBTYPE, &guidSubType);
+ }
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
*pFourCC = guidSubType.Data1;
+ }
return hr;
}
@@ -1071,62 +1078,66 @@ HRESULT CEVRAllocatorPresenter::GetMediaTypeMerit(IMFMediaType* pType, int* pMer
D3DFORMAT Format;
HRESULT hr = GetMediaTypeFourCC(pType, (DWORD*)&Format);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// We only support RGB mixer output surface formats
- switch (Format)
- {
- case D3DFMT_A2R10G10B10:
- if (m_bHighColorResolution || m_bForceInputHighColorResolution || m_bFullFloatingPointProcessing)
- *pMerit = 950;
- else
- *pMerit = 650;
+ switch (Format) {
+ case D3DFMT_A2R10G10B10:
+ if (m_bHighColorResolution || m_bForceInputHighColorResolution || m_bFullFloatingPointProcessing) {
+ *pMerit = 950;
+ } else {
+ *pMerit = 650;
+ }
- break;
+ break;
- case D3DFMT_A2B10G10R10:
- if (m_bHighColorResolution || m_bForceInputHighColorResolution || m_bFullFloatingPointProcessing)
- *pMerit = 900;
- else
- *pMerit = 600;
+ case D3DFMT_A2B10G10R10:
+ if (m_bHighColorResolution || m_bForceInputHighColorResolution || m_bFullFloatingPointProcessing) {
+ *pMerit = 900;
+ } else {
+ *pMerit = 600;
+ }
- break;
+ break;
- case D3DFMT_X8R8G8B8:
- if (m_bForceInputHighColorResolution)
- *pMerit = 800;
- else
- *pMerit = 850;
+ case D3DFMT_X8R8G8B8:
+ if (m_bForceInputHighColorResolution) {
+ *pMerit = 800;
+ } else {
+ *pMerit = 850;
+ }
- break;
+ break;
- case D3DFMT_A8R8G8B8:
- if (m_bForceInputHighColorResolution)
- *pMerit = 850;
- else
- *pMerit = 800;
+ case D3DFMT_A8R8G8B8:
+ if (m_bForceInputHighColorResolution) {
+ *pMerit = 850;
+ } else {
+ *pMerit = 800;
+ }
- break;
+ break;
- case D3DFMT_X8B8G8R8:
- if (m_bForceInputHighColorResolution)
- *pMerit = 700;
- else
- *pMerit = 750;
+ case D3DFMT_X8B8G8R8:
+ if (m_bForceInputHighColorResolution) {
+ *pMerit = 700;
+ } else {
+ *pMerit = 750;
+ }
- break;
+ break;
- case D3DFMT_A8B8G8R8:
- if (m_bForceInputHighColorResolution)
- *pMerit = 750;
- else
- *pMerit = 700;
- break;
+ case D3DFMT_A8B8G8R8:
+ if (m_bForceInputHighColorResolution) {
+ *pMerit = 750;
+ } else {
+ *pMerit = 700;
+ }
+ break;
- default:
- // Unsupported format
- *pMerit = 0;
- break;
+ default:
+ // Unsupported format
+ *pMerit = 0;
+ break;
}
}
@@ -1149,8 +1160,7 @@ HRESULT CEVRAllocatorPresenter::RenegotiateMediaType()
CComPtr<IMFMediaType> pMixerType;
CComPtr<IMFMediaType> pType;
- if (!m_pMixer)
- {
+ if (!m_pMixer) {
return MF_E_INVALIDREQUEST;
}
@@ -1158,50 +1168,49 @@ HRESULT CEVRAllocatorPresenter::RenegotiateMediaType()
// Loop through all of the mixer's proposed output types.
DWORD iTypeIndex = 0;
- while ((hr != MF_E_NO_MORE_TYPES))
- {
+ while ((hr != MF_E_NO_MORE_TYPES)) {
pMixerType = NULL;
pType = NULL;
m_pMediaType = NULL;
// Step 1. Get the next media type supported by mixer.
hr = m_pMixer->GetOutputAvailableType(0, iTypeIndex++, &pMixerType);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
break;
}
// Step 2. Check if we support this media type.
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = IsMediaTypeSupported(pMixerType);
+ }
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = CreateProposedOutputType(pMixerType, &pType);
+ }
// Step 4. Check if the mixer will accept this media type.
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = m_pMixer->SetOutputType(0, pType, MFT_SET_TYPE_TEST_ONLY);
+ }
int Merit;
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = GetMediaTypeMerit(pType, &Merit);
+ }
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
int nTypes = ValidMixerTypes.GetCount();
int iInsertPos = 0;
- for (int i = 0; i < nTypes; ++i)
- {
+ for (int i = 0; i < nTypes; ++i) {
int ThisMerit;
GetMediaTypeMerit(ValidMixerTypes[i], &ThisMerit);
- if (Merit > ThisMerit)
- {
+ if (Merit > ThisMerit) {
iInsertPos = i;
break;
- }
- else
+ } else {
iInsertPos = i+1;
+ }
}
ValidMixerTypes.InsertAt(iInsertPos, pType);
@@ -1210,15 +1219,13 @@ HRESULT CEVRAllocatorPresenter::RenegotiateMediaType()
int nValidTypes = ValidMixerTypes.GetCount();
- for (int i = 0; i < nValidTypes; ++i)
- {
+ for (int i = 0; i < nValidTypes; ++i) {
// Step 3. Adjust the mixer's type to match our requirements.
pType = ValidMixerTypes[i];
TRACE_EVR("EVR: Valid mixer output type: %ws\n", GetMediaTypeFormatDesc(pType));
}
- for (int i = 0; i < nValidTypes; ++i)
- {
+ for (int i = 0; i < nValidTypes; ++i) {
// Step 3. Adjust the mixer's type to match our requirements.
pType = ValidMixerTypes[i];
@@ -1229,17 +1236,15 @@ HRESULT CEVRAllocatorPresenter::RenegotiateMediaType()
hr = SetMediaType(pType);
// Step 6. Set output media type on mixer.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = m_pMixer->SetOutputType(0, pType, 0);
// If something went wrong, clear the media type.
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
SetMediaType(NULL);
- }
- else
+ } else {
break;
+ }
}
}
@@ -1262,12 +1267,10 @@ bool CEVRAllocatorPresenter::GetImageFromMixer()
bool bDoneSomething = false;
- while (SUCCEEDED(hr))
- {
+ while (SUCCEEDED(hr)) {
CComPtr<IMFSample> pSample;
- if (FAILED (GetFreeSample (&pSample)))
- {
+ if (FAILED (GetFreeSample (&pSample))) {
m_bWaitingSample = true;
break;
}
@@ -1282,14 +1285,12 @@ bool CEVRAllocatorPresenter::GetImageFromMixer()
llClockAfter = GetRenderersData()->GetPerfCounter();
}
- if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT)
- {
+ if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) {
MoveToFreeList (pSample, false);
break;
}
- if (m_pSink)
- {
+ if (m_pSink) {
//CAutoLock autolock(this); We shouldn't need to lock here, m_pSink is thread safe
llMixerLatency = llClockAfter - llClockBefore;
m_pSink->Notify (EC_PROCESSING_LATENCY, (LONG_PTR)&llMixerLatency, 0);
@@ -1299,8 +1300,7 @@ bool CEVRAllocatorPresenter::GetImageFromMixer()
REFERENCE_TIME nsDuration;
pSample->GetSampleDuration (&nsDuration);
- if (GetRenderersData()->m_fTearingTest)
- {
+ if (GetRenderersData()->m_fTearingTest) {
RECT rcTearing;
rcTearing.left = m_nTearingPos;
@@ -1320,8 +1320,9 @@ bool CEVRAllocatorPresenter::GetImageFromMixer()
MoveToScheduledList (pSample, false);
bDoneSomething = true;
- if (m_rtTimePerFrame == 0)
+ if (m_rtTimePerFrame == 0) {
break;
+ }
}
return bDoneSomething;
@@ -1337,8 +1338,9 @@ STDMETHODIMP CEVRAllocatorPresenter::GetCurrentMediaType(__deref_out IMFVideoMe
CheckPointer (ppMediaType, E_POINTER);
CheckHR (CheckShutdown());
- if (m_pMediaType == NULL)
+ if (m_pMediaType == NULL) {
CheckHR(MF_E_NOT_INITIALIZED);
+ }
CheckHR(m_pMediaType->QueryInterface( __uuidof(IMFVideoMediaType), (void**)&ppMediaType));
@@ -1393,10 +1395,11 @@ STDMETHODIMP CEVRAllocatorPresenter::GetService (/* [in] */ __RPC__in REFGUID gu
/* [in] */ __RPC__in REFIID riid,
/* [iid_is][out] */ __RPC__deref_out_opt LPVOID *ppvObject)
{
- if (guidService == MR_VIDEO_RENDER_SERVICE)
+ if (guidService == MR_VIDEO_RENDER_SERVICE) {
return NonDelegatingQueryInterface (riid, ppvObject);
- else if (guidService == MR_VIDEO_ACCELERATION_SERVICE)
+ } else if (guidService == MR_VIDEO_ACCELERATION_SERVICE) {
return m_pD3DManager->QueryInterface (__uuidof(IDirect3DDeviceManager9), (void**) ppvObject);
+ }
return E_NOINTERFACE;
}
@@ -1417,13 +1420,11 @@ STDMETHODIMP CEVRAllocatorPresenter::Invoke ( /* [in] */ __RPC__in_opt IMFAsyn
// IMFVideoDisplayControl
STDMETHODIMP CEVRAllocatorPresenter::GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo)
{
- if (pszVideo)
- {
+ if (pszVideo) {
pszVideo->cx = m_NativeVideoSize.cx;
pszVideo->cy = m_NativeVideoSize.cy;
}
- if (pszARVideo)
- {
+ if (pszARVideo) {
pszARVideo->cx = m_NativeVideoSize.cx * m_AspectRatio.cx;
pszARVideo->cy = m_NativeVideoSize.cy * m_AspectRatio.cy;
}
@@ -1431,19 +1432,16 @@ STDMETHODIMP CEVRAllocatorPresenter::GetNativeVideoSize(SIZE *pszVideo, SIZE *ps
}
STDMETHODIMP CEVRAllocatorPresenter::GetIdealVideoSize(SIZE *pszMin, SIZE *pszMax)
{
- if (pszMin)
- {
+ if (pszMin) {
pszMin->cx = 1;
pszMin->cy = 1;
}
- if (pszMax)
- {
+ if (pszMax) {
D3DDISPLAYMODE d3ddm;
ZeroMemory(&d3ddm, sizeof(d3ddm));
- if(SUCCEEDED(m_pD3D->GetAdapterDisplayMode(GetAdapter(m_pD3D), &d3ddm)))
- {
+ if(SUCCEEDED(m_pD3D->GetAdapterDisplayMode(GetAdapter(m_pD3D), &d3ddm))) {
pszMax->cx = d3ddm.Width;
pszMax->cy = d3ddm.Height;
}
@@ -1458,16 +1456,16 @@ STDMETHODIMP CEVRAllocatorPresenter::SetVideoPosition(const MFVideoNormalizedRec
STDMETHODIMP CEVRAllocatorPresenter::GetVideoPosition(MFVideoNormalizedRect *pnrcSource, LPRECT prcDest)
{
// Always all source rectangle ?
- if (pnrcSource)
- {
+ if (pnrcSource) {
pnrcSource->left = 0.0;
pnrcSource->top = 0.0;
pnrcSource->right = 1.0;
pnrcSource->bottom = 1.0;
}
- if (prcDest)
- memcpy (prcDest, &m_VideoRect, sizeof(m_VideoRect));//GetClientRect (m_hWnd, prcDest);
+ if (prcDest) {
+ memcpy (prcDest, &m_VideoRect, sizeof(m_VideoRect)); //GetClientRect (m_hWnd, prcDest);
+ }
return S_OK;
}
@@ -1485,7 +1483,7 @@ STDMETHODIMP CEVRAllocatorPresenter::GetAspectRatioMode(DWORD *pdwAspectRatioMod
STDMETHODIMP CEVRAllocatorPresenter::SetVideoWindow(HWND hwndVideo)
{
ASSERT (m_hWnd == hwndVideo); // What if not ??
-// m_hWnd = hwndVideo;
+ // m_hWnd = hwndVideo;
return S_OK;
}
STDMETHODIMP CEVRAllocatorPresenter::GetVideoWindow(HWND *phwndVideo)
@@ -1596,15 +1594,12 @@ STDMETHODIMP CEVRAllocatorPresenter::GetVideoService(HANDLE hDevice, REFIID riid
{
HRESULT hr = m_pD3DManager->GetVideoService(hDevice, riid, ppService);
- if (riid == __uuidof(IDirectXVideoDecoderService))
- {
+ if (riid == __uuidof(IDirectXVideoDecoderService)) {
UINT nNbDecoder = 5;
GUID* pDecoderGuid;
IDirectXVideoDecoderService* pDXVAVideoDecoder = (IDirectXVideoDecoderService*) *ppService;
pDXVAVideoDecoder->GetDecoderDeviceGuids (&nNbDecoder, &pDecoderGuid);
- }
- else if (riid == __uuidof(IDirectXVideoProcessorService))
- {
+ } else if (riid == __uuidof(IDirectXVideoProcessorService)) {
IDirectXVideoProcessorService* pDXVAProcessor = (IDirectXVideoProcessorService*) *ppService;
UNUSED_ALWAYS(pDXVAProcessor);
}
@@ -1618,10 +1613,18 @@ STDMETHODIMP CEVRAllocatorPresenter::GetNativeVideoSize(LONG* lpWidth, LONG* lpH
// This function should be called...
ASSERT (FALSE);
- if(lpWidth) *lpWidth = m_NativeVideoSize.cx;
- if(lpHeight) *lpHeight = m_NativeVideoSize.cy;
- if(lpARWidth) *lpARWidth = m_AspectRatio.cx;
- if(lpARHeight) *lpARHeight = m_AspectRatio.cy;
+ if(lpWidth) {
+ *lpWidth = m_NativeVideoSize.cx;
+ }
+ if(lpHeight) {
+ *lpHeight = m_NativeVideoSize.cy;
+ }
+ if(lpARWidth) {
+ *lpARWidth = m_AspectRatio.cx;
+ }
+ if(lpARHeight) {
+ *lpARHeight = m_AspectRatio.cy;
+ }
return S_OK;
}
@@ -1642,30 +1645,27 @@ STDMETHODIMP CEVRAllocatorPresenter::InitializeDevice(IMFMediaType* pMediaType)
hr = MFGetAttributeSize(pMediaType, MF_MT_FRAME_SIZE, &Width, &Height);
D3DFORMAT Format;
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
m_NativeVideoSize = CSize(Width, Height);
hr = GetMediaTypeFourCC(pMediaType, (DWORD*)&Format);
}
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
if (m_bForceInputHighColorResolution)
// May crash or not work correctly!
+ {
hr = AllocSurfaces(D3DFMT_A2R10G10B10);
- else
+ } else {
hr = AllocSurfaces(Format);
+ }
}
- if (SUCCEEDED(hr))
- {
- for(int i = 0; i < m_nNbDXSurface; i++)
- {
+ if (SUCCEEDED(hr)) {
+ for(int i = 0; i < m_nNbDXSurface; i++) {
CComPtr<IMFSample> pMFSample;
hr = pfMFCreateVideoSampleFromSurface (m_pVideoSurface[i], &pMFSample);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
pMFSample->SetUINT32 (GUID_SURFACE_INDEX, i);
m_FreeSamples.AddTail (pMFSample);
}
@@ -1697,8 +1697,7 @@ DWORD WINAPI CEVRAllocatorPresenter::PresentThread(LPVOID lpParam)
void CEVRAllocatorPresenter::CheckWaitingSampleFromMixer()
{
- if (m_bWaitingSample)
- {
+ if (m_bWaitingSample) {
m_bWaitingSample = false;
//GetImageFromMixer(); // Do this in processing thread instead
}
@@ -1707,16 +1706,17 @@ void CEVRAllocatorPresenter::CheckWaitingSampleFromMixer()
bool ExtractInterlaced(const AM_MEDIA_TYPE* pmt)
{
- if (pmt->formattype==FORMAT_VideoInfo)
+ if (pmt->formattype==FORMAT_VideoInfo) {
return false;
- else if (pmt->formattype==FORMAT_VideoInfo2)
+ } else if (pmt->formattype==FORMAT_VideoInfo2) {
return (((VIDEOINFOHEADER2*)pmt->pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced) != 0;
- else if (pmt->formattype==FORMAT_MPEGVideo)
+ } else if (pmt->formattype==FORMAT_MPEGVideo) {
return false;
- else if (pmt->formattype==FORMAT_MPEG2Video)
+ } else if (pmt->formattype==FORMAT_MPEG2Video) {
return (((MPEG2VIDEOINFO*)pmt->pbFormat)->hdr.dwInterlaceFlags & AMINTERLACE_IsInterlaced) != 0;
- else
+ } else {
return false;
+ }
}
@@ -1731,68 +1731,63 @@ void CEVRAllocatorPresenter::GetMixerThread()
//DWORD dwTaskIndex = 0;
// Tell Vista Multimedia Class Scheduler we are a playback thretad (increase priority)
-// if (pfAvSetMmThreadCharacteristicsW)
-// hAvrt = pfAvSetMmThreadCharacteristicsW (L"Playback", &dwTaskIndex);
-// if (pfAvSetMmThreadPriority)
-// pfAvSetMmThreadPriority (hAvrt, AVRT_PRIORITY_HIGH /*AVRT_PRIORITY_CRITICAL*/);
+ // if (pfAvSetMmThreadCharacteristicsW)
+ // hAvrt = pfAvSetMmThreadCharacteristicsW (L"Playback", &dwTaskIndex);
+ // if (pfAvSetMmThreadPriority)
+ // pfAvSetMmThreadPriority (hAvrt, AVRT_PRIORITY_HIGH /*AVRT_PRIORITY_CRITICAL*/);
timeGetDevCaps(&tc, sizeof(TIMECAPS));
dwResolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
dwUser = timeBeginPeriod(dwResolution);
- while (!bQuit)
- {
+ while (!bQuit) {
DWORD dwObject = WaitForMultipleObjects (countof(hEvts), hEvts, FALSE, 1);
- switch (dwObject)
- {
- case WAIT_OBJECT_0 :
- bQuit = true;
- break;
- case WAIT_TIMEOUT :
- {
- bool bDoneSomething = false;
- {
- CAutoLock AutoLock(&m_ImageProcessingLock);
- bDoneSomething = GetImageFromMixer();
- }
- if (m_rtTimePerFrame == 0 && bDoneSomething)
- {
- //CAutoLock lock(this);
- //CAutoLock lock2(&m_ImageProcessingLock);
- //CAutoLock cRenderLock(&m_RenderLock);
-
- // Use the code from VMR9 to get the movie fps, as this method is reliable.
- CComPtr<IPin> pPin;
- CMediaType mt;
- if (
- SUCCEEDED (m_pOuterEVR->FindPin(L"EVR Input0", &pPin)) &&
- SUCCEEDED (pPin->ConnectionMediaType(&mt)) )
+ switch (dwObject) {
+ case WAIT_OBJECT_0 :
+ bQuit = true;
+ break;
+ case WAIT_TIMEOUT : {
+ bool bDoneSomething = false;
{
- ExtractAvgTimePerFrame (&mt, m_rtTimePerFrame);
+ CAutoLock AutoLock(&m_ImageProcessingLock);
+ bDoneSomething = GetImageFromMixer();
+ }
+ if (m_rtTimePerFrame == 0 && bDoneSomething) {
+ //CAutoLock lock(this);
+ //CAutoLock lock2(&m_ImageProcessingLock);
+ //CAutoLock cRenderLock(&m_RenderLock);
- m_bInterlaced = ExtractInterlaced(&mt);
+ // Use the code from VMR9 to get the movie fps, as this method is reliable.
+ CComPtr<IPin> pPin;
+ CMediaType mt;
+ if (
+ SUCCEEDED (m_pOuterEVR->FindPin(L"EVR Input0", &pPin)) &&
+ SUCCEEDED (pPin->ConnectionMediaType(&mt)) ) {
+ ExtractAvgTimePerFrame (&mt, m_rtTimePerFrame);
- }
- // If framerate not set by Video Decoder choose 23.97...
- if (m_rtTimePerFrame == 0)
- m_rtTimePerFrame = 417166;
+ m_bInterlaced = ExtractInterlaced(&mt);
+
+ }
+ // If framerate not set by Video Decoder choose 23.97...
+ if (m_rtTimePerFrame == 0) {
+ m_rtTimePerFrame = 417166;
+ }
+
+ // Update internal subtitle clock
+ if(m_fUseInternalTimer && m_pSubPicQueue) {
+ m_fps = (float)(10000000.0 / m_rtTimePerFrame);
+ m_pSubPicQueue->SetFPS(m_fps);
+ }
- // Update internal subtitle clock
- if(m_fUseInternalTimer && m_pSubPicQueue)
- {
- m_fps = (float)(10000000.0 / m_rtTimePerFrame);
- m_pSubPicQueue->SetFPS(m_fps);
}
}
-
- }
- break;
+ break;
}
}
timeEndPeriod (dwResolution);
-// if (pfAvRevertMmThreadCharacteristics) pfAvRevertMmThreadCharacteristics (hAvrt);
+ // if (pfAvRevertMmThreadCharacteristics) pfAvRevertMmThreadCharacteristics (hAvrt);
}
void ModerateFloat(double& Value, double Target, double& ValuePrim, double ChangeSpeed)
@@ -1812,20 +1807,19 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
MFCLOCK_STATE State;
m_pClock->GetState(0, &State);
- if (!(Characteristics & MFCLOCK_CHARACTERISTICS_FLAG_FREQUENCY_10MHZ))
- {
+ if (!(Characteristics & MFCLOCK_CHARACTERISTICS_FLAG_FREQUENCY_10MHZ)) {
MFCLOCK_PROPERTIES Props;
- if (m_pClock->GetProperties(&Props) == S_OK)
- llClockTime = (llClockTime * 10000000) / Props.qwClockFrequency; // Make 10 MHz
+ if (m_pClock->GetProperties(&Props) == S_OK) {
+ llClockTime = (llClockTime * 10000000) / Props.qwClockFrequency; // Make 10 MHz
+ }
}
LONGLONG llPerf = PerformanceCounter;
-// return llClockTime + (llPerf - nsCurrentTime);
+ // return llClockTime + (llPerf - nsCurrentTime);
double Target = llClockTime + (llPerf - nsCurrentTime) * m_ModeratedTimeSpeed;
bool bReset = false;
- if (m_ModeratedTimeLast < 0 || State != m_LastClockState || m_ModeratedClockLast < 0)
- {
+ if (m_ModeratedTimeLast < 0 || State != m_LastClockState || m_ModeratedClockLast < 0) {
bReset = true;
m_ModeratedTimeLast = llPerf;
m_ModeratedClockLast = llClockTime;
@@ -1842,46 +1836,43 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
#if 1
- if (bReset)
- {
+ if (bReset) {
m_ModeratedTimeSpeed = 1.0;
m_ModeratedTimeSpeedPrim = 0.0;
ZeroMemory(m_TimeChangeHistory, sizeof(m_TimeChangeHistory));
ZeroMemory(m_ClockChangeHistory, sizeof(m_ClockChangeHistory));
m_ClockTimeChangeHistoryPos = 0;
}
- if (TimeChange)
- {
+ if (TimeChange) {
int Pos = m_ClockTimeChangeHistoryPos % 100;
int nHistory = min(m_ClockTimeChangeHistoryPos, 100);
++m_ClockTimeChangeHistoryPos;
- if (nHistory > 50)
- {
+ if (nHistory > 50) {
int iLastPos = (Pos - (nHistory)) % 100;
- if (iLastPos < 0)
+ if (iLastPos < 0) {
iLastPos += 100;
+ }
double TimeChange = llPerf - m_TimeChangeHistory[iLastPos];
double ClockChange = llClockTime - m_ClockChangeHistory[iLastPos];
double ClockSpeedTarget = ClockChange / TimeChange;
double ChangeSpeed = 0.1;
- if (ClockSpeedTarget > m_ModeratedTimeSpeed)
- {
- if (ClockSpeedTarget / m_ModeratedTimeSpeed > 0.1)
+ if (ClockSpeedTarget > m_ModeratedTimeSpeed) {
+ if (ClockSpeedTarget / m_ModeratedTimeSpeed > 0.1) {
ChangeSpeed = 0.1;
- else
+ } else {
ChangeSpeed = 0.01;
- }
- else
- {
- if (m_ModeratedTimeSpeed / ClockSpeedTarget > 0.1)
+ }
+ } else {
+ if (m_ModeratedTimeSpeed / ClockSpeedTarget > 0.1) {
ChangeSpeed = 0.1;
- else
+ } else {
ChangeSpeed = 0.01;
+ }
}
ModerateFloat(m_ModeratedTimeSpeed, ClockSpeedTarget, m_ModeratedTimeSpeedPrim, ChangeSpeed);
-// m_ModeratedTimeSpeed = TimeChange / ClockChange;
+ // m_ModeratedTimeSpeed = TimeChange / ClockChange;
}
m_TimeChangeHistory[Pos] = llPerf;
m_ClockChangeHistory[Pos] = llClockTime;
@@ -1893,31 +1884,24 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
double Diff = Target - EstimateTime;
// > 5 ms just set it
- if ((fabs(Diff) > 50000.0 || bReset))
- {
+ if ((fabs(Diff) > 50000.0 || bReset)) {
-// TRACE_EVR("EVR: Reset clock at diff: %f ms\n", (m_ModeratedTime - Target) /10000.0);
- if (State == MFCLOCK_STATE_RUNNING)
- {
- if (bReset)
- {
+ // TRACE_EVR("EVR: Reset clock at diff: %f ms\n", (m_ModeratedTime - Target) /10000.0);
+ if (State == MFCLOCK_STATE_RUNNING) {
+ if (bReset) {
m_ModeratedTimeSpeed = 1.0;
m_ModeratedTimeSpeedPrim = 0.0;
m_ClockDiffCalc = 0;
m_ClockDiffPrim = 0;
m_ModeratedTime = Target;
m_ModeratedTimer = llPerf;
- }
- else
- {
+ } else {
EstimateTime = m_ModeratedTime + TimeChange * m_ModeratedTimeSpeed;
Diff = Target - EstimateTime;
m_ClockDiffCalc = Diff;
m_ClockDiffPrim = 0;
}
- }
- else
- {
+ } else {
m_ModeratedTimeSpeed = 0.0;
m_ModeratedTimeSpeedPrim = 0.0;
m_ClockDiffCalc = 0;
@@ -1938,8 +1922,7 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
int nModerate = 0;
double Change = 0;
- while (m_ModeratedTimer < llPerf - ModerateTime)
- {
+ while (m_ModeratedTimer < llPerf - ModerateTime) {
m_ModeratedTimer += ModerateTime;
m_ModeratedTime += double(ModerateTime) * m_ModeratedTimeSpeed;
@@ -1950,9 +1933,9 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
double TimeSpeedTarget;
double AbsDiff = fabs(Diff);
TimeSpeedTarget = 1.0 - (Diff / 1000000.0);
-// TimeSpeedTarget = m_ModeratedTimeSpeed - (Diff / 100000000000.0);
+ // TimeSpeedTarget = m_ModeratedTimeSpeed - (Diff / 100000000000.0);
//if (AbsDiff > 20000.0)
-// TimeSpeedTarget = 1.0 - (Diff / 1000000.0);
+ // TimeSpeedTarget = 1.0 - (Diff / 1000000.0);
/*else if (AbsDiff > 5000.0)
TimeSpeedTarget = 1.0 - (Diff / 100000000.0);
else
@@ -1963,8 +1946,9 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
++nModerate;
Change += m_ModeratedTimeSpeed - StartMod;
}
- if (nModerate)
+ if (nModerate) {
m_ModeratedTimeSpeedDiff = Change / nModerate;
+ }
double Ret = m_ModeratedTime + double(llPerf - m_ModeratedTimer) * m_ModeratedTimeSpeed;
double Diff = Target - Ret;
@@ -1983,44 +1967,45 @@ LONGLONG CEVRAllocatorPresenter::GetClockTime(LONGLONG PerformanceCounter)
void CEVRAllocatorPresenter::OnVBlankFinished(bool fAll, LONGLONG PerformanceCounter)
{
- if (!m_pCurrentDisplaydSample || !m_OrderedPaint || !fAll)
+ if (!m_pCurrentDisplaydSample || !m_OrderedPaint || !fAll) {
return;
+ }
LONGLONG llClockTime;
LONGLONG nsSampleTime;
LONGLONG SampleDuration = 0;
- if (!m_bSignaledStarvation)
- {
+ if (!m_bSignaledStarvation) {
llClockTime = GetClockTime(PerformanceCounter);
m_StarvationClock = llClockTime;
- }
- else
- {
+ } else {
llClockTime = m_StarvationClock;
}
- if (FAILED(m_pCurrentDisplaydSample->GetSampleDuration(&SampleDuration)))
+ if (FAILED(m_pCurrentDisplaydSample->GetSampleDuration(&SampleDuration))) {
SampleDuration = 0;
+ }
- if (FAILED(m_pCurrentDisplaydSample->GetSampleTime(&nsSampleTime)))
+ if (FAILED(m_pCurrentDisplaydSample->GetSampleTime(&nsSampleTime))) {
nsSampleTime = llClockTime;
+ }
LONGLONG TimePerFrame = m_rtTimePerFrame;
- if (!TimePerFrame)
+ if (!TimePerFrame) {
return;
- if (SampleDuration > 1)
+ }
+ if (SampleDuration > 1) {
TimePerFrame = SampleDuration;
+ }
{
m_nNextSyncOffset = (m_nNextSyncOffset+1) % NB_JITTER;
LONGLONG SyncOffset = nsSampleTime - llClockTime;
m_pllSyncOffset[m_nNextSyncOffset] = SyncOffset;
-// TRACE_EVR("EVR: SyncOffset(%d, %d): %8I64d %8I64d %8I64d \n", m_nCurSurface, m_VSyncMode, m_LastPredictedSync, -SyncOffset, m_LastPredictedSync - (-SyncOffset));
+ // TRACE_EVR("EVR: SyncOffset(%d, %d): %8I64d %8I64d %8I64d \n", m_nCurSurface, m_VSyncMode, m_LastPredictedSync, -SyncOffset, m_LastPredictedSync - (-SyncOffset));
m_MaxSyncOffset = MINLONG64;
m_MinSyncOffset = MAXLONG64;
LONGLONG AvrageSum = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
LONGLONG Offset = m_pllSyncOffset[i];
AvrageSum += Offset;
m_MaxSyncOffset = max(m_MaxSyncOffset, Offset);
@@ -2028,8 +2013,7 @@ void CEVRAllocatorPresenter::OnVBlankFinished(bool fAll, LONGLONG PerformanceCou
}
double MeanOffset = double(AvrageSum)/NB_JITTER;
double DeviationSum = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
double Deviation = double(m_pllSyncOffset[i]) - MeanOffset;
DeviationSum += Deviation*Deviation;
}
@@ -2053,13 +2037,11 @@ STDMETHODIMP_(bool) CEVRAllocatorPresenter::ResetDevice()
bool bResult = __super::ResetDevice();
- for(int i = 0; i < m_nNbDXSurface; i++)
- {
+ for(int i = 0; i < m_nNbDXSurface; i++) {
CComPtr<IMFSample> pMFSample;
HRESULT hr = pfMFCreateVideoSampleFromSurface (m_pVideoSurface[i], &pMFSample);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
pMFSample->SetUINT32 (GUID_SURFACE_INDEX, i);
m_FreeSamples.AddTail (pMFSample);
}
@@ -2082,12 +2064,12 @@ void CEVRAllocatorPresenter::RenderThread()
// Tell Vista Multimedia Class Scheduler we are a playback thretad (increase priority)
HANDLE hAvrt = 0;
- if (pfAvSetMmThreadCharacteristicsW)
- {
+ if (pfAvSetMmThreadCharacteristicsW) {
DWORD dwTaskIndex = 0;
hAvrt = pfAvSetMmThreadCharacteristicsW (L"Playback", &dwTaskIndex);
- if (pfAvSetMmThreadPriority)
+ if (pfAvSetMmThreadPriority) {
pfAvSetMmThreadPriority (hAvrt, AVRT_PRIORITY_HIGH /*AVRT_PRIORITY_CRITICAL*/);
+ }
}
timeGetDevCaps(&tc, sizeof(TIMECAPS));
@@ -2096,353 +2078,328 @@ void CEVRAllocatorPresenter::RenderThread()
CRenderersSettings& s = GetRenderersSettings();
int NextSleepTime = 1;
- while (!bQuit)
- {
+ while (!bQuit) {
LONGLONG llPerf = GetRenderersData()->GetPerfCounter();
UNUSED_ALWAYS(llPerf);
- if (!s.m_RenderSettings.iVMR9VSyncAccurate && NextSleepTime == 0)
+ if (!s.m_RenderSettings.iVMR9VSyncAccurate && NextSleepTime == 0) {
NextSleepTime = 1;
+ }
dwObject = WaitForMultipleObjects (countof(hEvts), hEvts, FALSE, max(NextSleepTime < 0 ? 1 : NextSleepTime, 0));
/* dwObject = WAIT_TIMEOUT;
if (m_bEvtFlush)
dwObject = WAIT_OBJECT_0 + 1;
else if (m_bEvtQuit)
dwObject = WAIT_OBJECT_0;*/
-// if (NextSleepTime)
-// TRACE_EVR("EVR: Sleep: %7.3f\n", double(GetRenderersData()->GetPerfCounter()-llPerf) / 10000.0);
- if (NextSleepTime > 1)
+ // if (NextSleepTime)
+ // TRACE_EVR("EVR: Sleep: %7.3f\n", double(GetRenderersData()->GetPerfCounter()-llPerf) / 10000.0);
+ if (NextSleepTime > 1) {
NextSleepTime = 0;
- else if (NextSleepTime == 0)
+ } else if (NextSleepTime == 0) {
NextSleepTime = -1;
- switch (dwObject)
- {
- case WAIT_OBJECT_0 :
- bQuit = true;
- break;
- case WAIT_OBJECT_0 + 1 :
- // Flush pending samples!
- FlushSamples();
- m_bEvtFlush = false;
- ResetEvent(m_hEvtFlush);
- TRACE_EVR ("EVR: Flush done!\n");
- break;
-
- case WAIT_TIMEOUT :
-
- if (m_LastSetOutputRange != -1 && m_LastSetOutputRange != s.m_RenderSettings.iEVROutputRange || m_bPendingRenegotiate)
- {
+ }
+ switch (dwObject) {
+ case WAIT_OBJECT_0 :
+ bQuit = true;
+ break;
+ case WAIT_OBJECT_0 + 1 :
+ // Flush pending samples!
FlushSamples();
- RenegotiateMediaType();
- m_bPendingRenegotiate = false;
- }
- if (m_bPendingResetDevice)
- SendResetRequest();
+ m_bEvtFlush = false;
+ ResetEvent(m_hEvtFlush);
+ TRACE_EVR ("EVR: Flush done!\n");
+ break;
- // Discard timer events if playback stop
-// if ((dwObject == WAIT_OBJECT_0 + 3) && (m_nRenderState != Started)) continue;
+ case WAIT_TIMEOUT :
-// TRACE_EVR ("EVR: RenderThread ==>> Waiting buffer\n");
+ if (m_LastSetOutputRange != -1 && m_LastSetOutputRange != s.m_RenderSettings.iEVROutputRange || m_bPendingRenegotiate) {
+ FlushSamples();
+ RenegotiateMediaType();
+ m_bPendingRenegotiate = false;
+ }
+ if (m_bPendingResetDevice) {
+ SendResetRequest();
+ }
-// if (WaitForMultipleObjects (countof(hEvtsBuff), hEvtsBuff, FALSE, INFINITE) == WAIT_OBJECT_0+2)
- {
- CComPtr<IMFSample> pMFSample;
- LONGLONG llPerf = GetRenderersData()->GetPerfCounter();
- UNUSED_ALWAYS(llPerf);
- int nSamplesLeft = 0;
- if (SUCCEEDED (GetScheduledSample(&pMFSample, nSamplesLeft)))
- {
-// pMFSample->GetUINT32 (GUID_SURFACE_INDEX, (UINT32*)&m_nCurSurface);
- m_pCurrentDisplaydSample = pMFSample;
+ // Discard timer events if playback stop
+ // if ((dwObject == WAIT_OBJECT_0 + 3) && (m_nRenderState != Started)) continue;
- bool bValidSampleTime = true;
- HRESULT hGetSampleTime = pMFSample->GetSampleTime (&nsSampleTime);
- if (hGetSampleTime != S_OK || nsSampleTime == 0)
- {
- bValidSampleTime = false;
- }
- // We assume that all samples have the same duration
- LONGLONG SampleDuration = 0;
- pMFSample->GetSampleDuration(&SampleDuration);
+ // TRACE_EVR ("EVR: RenderThread ==>> Waiting buffer\n");
-// TRACE_EVR ("EVR: RenderThread ==>> Presenting surface %d (%I64d)\n", m_nCurSurface, nsSampleTime);
+ // if (WaitForMultipleObjects (countof(hEvtsBuff), hEvtsBuff, FALSE, INFINITE) == WAIT_OBJECT_0+2)
+ {
+ CComPtr<IMFSample> pMFSample;
+ LONGLONG llPerf = GetRenderersData()->GetPerfCounter();
+ UNUSED_ALWAYS(llPerf);
+ int nSamplesLeft = 0;
+ if (SUCCEEDED (GetScheduledSample(&pMFSample, nSamplesLeft))) {
+ // pMFSample->GetUINT32 (GUID_SURFACE_INDEX, (UINT32*)&m_nCurSurface);
+ m_pCurrentDisplaydSample = pMFSample;
+
+ bool bValidSampleTime = true;
+ HRESULT hGetSampleTime = pMFSample->GetSampleTime (&nsSampleTime);
+ if (hGetSampleTime != S_OK || nsSampleTime == 0) {
+ bValidSampleTime = false;
+ }
+ // We assume that all samples have the same duration
+ LONGLONG SampleDuration = 0;
+ pMFSample->GetSampleDuration(&SampleDuration);
- bool bStepForward = false;
+ // TRACE_EVR ("EVR: RenderThread ==>> Presenting surface %d (%I64d)\n", m_nCurSurface, nsSampleTime);
- if (m_nStepCount < 0)
- {
- // Drop frame
- TRACE_EVR ("EVR: Dropped frame\n");
- m_pcFrames++;
- bStepForward = true;
- m_nStepCount = 0;
- }
- else if (m_nStepCount > 0)
- {
- pMFSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
- ++m_OrderedPaint;
- if (!g_bExternalSubtitleTime)
- __super::SetTime (g_tSegmentStart + nsSampleTime);
- Paint(true);
- m_nDroppedUpdate = 0;
- CompleteFrameStep (false);
- bStepForward = true;
- }
- else if ((m_nRenderState == Started))
- {
- LONGLONG CurrentCounter = GetRenderersData()->GetPerfCounter();
- // Calculate wake up timer
- if (!m_bSignaledStarvation)
- {
- llClockTime = GetClockTime(CurrentCounter);
- m_StarvationClock = llClockTime;
- }
- else
- {
- llClockTime = m_StarvationClock;
- }
+ bool bStepForward = false;
- if (!bValidSampleTime)
- {
- // Just play as fast as possible
+ if (m_nStepCount < 0) {
+ // Drop frame
+ TRACE_EVR ("EVR: Dropped frame\n");
+ m_pcFrames++;
bStepForward = true;
+ m_nStepCount = 0;
+ } else if (m_nStepCount > 0) {
pMFSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
++m_OrderedPaint;
- if (!g_bExternalSubtitleTime)
+ if (!g_bExternalSubtitleTime) {
__super::SetTime (g_tSegmentStart + nsSampleTime);
- Paint(true);
- }
- else
- {
- LONGLONG TimePerFrame = GetFrameTime() * 10000000.0;
- LONGLONG DrawTime = (m_PaintTime) * 0.9 - 20000.0; // 2 ms offset
- //if (!s.iVMR9VSync)
- DrawTime = 0;
-
- LONGLONG SyncOffset = 0;
- LONGLONG VSyncTime = 0;
- LONGLONG TimeToNextVSync = -1;
- bool bVSyncCorrection = false;
- double DetectedRefreshTime;
- double DetectedScanlinesPerFrame;
- double DetectedScanlineTime;
- int DetectedRefreshRatePos;
- {
- CAutoLock Lock(&m_RefreshRateLock);
- DetectedRefreshTime = m_DetectedRefreshTime;
- DetectedRefreshRatePos = m_DetectedRefreshRatePos;
- DetectedScanlinesPerFrame = m_DetectedScanlinesPerFrame;
- DetectedScanlineTime = m_DetectedScanlineTime;
}
-
- if (DetectedRefreshRatePos < 20 || !DetectedRefreshTime || !DetectedScanlinesPerFrame)
- {
- DetectedRefreshTime = 1.0/m_RefreshRate;
- DetectedScanlinesPerFrame = m_ScreenSize.cy;
- DetectedScanlineTime = DetectedRefreshTime / double(m_ScreenSize.cy);
+ Paint(true);
+ m_nDroppedUpdate = 0;
+ CompleteFrameStep (false);
+ bStepForward = true;
+ } else if ((m_nRenderState == Started)) {
+ LONGLONG CurrentCounter = GetRenderersData()->GetPerfCounter();
+ // Calculate wake up timer
+ if (!m_bSignaledStarvation) {
+ llClockTime = GetClockTime(CurrentCounter);
+ m_StarvationClock = llClockTime;
+ } else {
+ llClockTime = m_StarvationClock;
}
- if (s.m_RenderSettings.iVMR9VSync)
- {
- bVSyncCorrection = true;
- double TargetVSyncPos = GetVBlackPos();
- double RefreshLines = DetectedScanlinesPerFrame;
- double ScanlinesPerSecond = 1.0/DetectedScanlineTime;
- double CurrentVSyncPos = fmod(double(m_VBlankStartMeasure) + ScanlinesPerSecond * ((CurrentCounter - m_VBlankStartMeasureTime) / 10000000.0), RefreshLines);
- double LinesUntilVSync = 0;
- //TargetVSyncPos -= ScanlinesPerSecond * (DrawTime/10000000.0);
- //TargetVSyncPos -= 10;
- TargetVSyncPos = fmod(TargetVSyncPos, RefreshLines);
- if (TargetVSyncPos < 0)
- TargetVSyncPos += RefreshLines;
- if (TargetVSyncPos > CurrentVSyncPos)
- LinesUntilVSync = TargetVSyncPos - CurrentVSyncPos;
- else
- LinesUntilVSync = (RefreshLines - CurrentVSyncPos) + TargetVSyncPos;
- double TimeUntilVSync = LinesUntilVSync * DetectedScanlineTime;
- TimeToNextVSync = TimeUntilVSync * 10000000.0;
- VSyncTime = DetectedRefreshTime * 10000000.0;
-
- LONGLONG ClockTimeAtNextVSync = llClockTime + (TimeUntilVSync * 10000000.0) * m_ModeratedTimeSpeed;
-
- SyncOffset = (nsSampleTime - ClockTimeAtNextVSync);
-
-// if (SyncOffset < 0)
-// TRACE_EVR("EVR: SyncOffset(%d): %I64d %I64d %I64d\n", m_nCurSurface, SyncOffset, TimePerFrame, VSyncTime);
- }
- else
- SyncOffset = (nsSampleTime - llClockTime);
-
- //LONGLONG SyncOffset = nsSampleTime - llClockTime;
- TRACE_EVR ("EVR: SyncOffset: %I64d SampleFrame: %I64d ClockFrame: %I64d\n", SyncOffset, TimePerFrame!=0 ? nsSampleTime/TimePerFrame : 0, TimePerFrame!=0 ? llClockTime /TimePerFrame : 0);
- if (SampleDuration > 1 && !m_DetectedLock)
- TimePerFrame = SampleDuration;
-
- LONGLONG MinMargin;
- if (m_FrameTimeCorrection && 0)
- MinMargin = 15000.0;
- else
- MinMargin = 15000.0 + min(m_DetectedFrameTimeStdDev, 20000.0);
- LONGLONG TimePerFrameMargin = min(double(TimePerFrame)*0.11, max(double(TimePerFrame)*0.02, MinMargin));
- LONGLONG TimePerFrameMargin0 = TimePerFrameMargin/2;
- LONGLONG TimePerFrameMargin1 = 0;
-
- if (m_DetectedLock && TimePerFrame < VSyncTime)
- VSyncTime = TimePerFrame;
-
- if (m_VSyncMode == 1)
- TimePerFrameMargin1 = -TimePerFrameMargin;
- else if (m_VSyncMode == 2)
- TimePerFrameMargin1 = TimePerFrameMargin;
-
- m_LastSampleOffset = SyncOffset;
- m_bLastSampleOffsetValid = true;
-
- LONGLONG VSyncOffset0 = 0;
- bool bDoVSyncCorrection = false;
- if ((SyncOffset < -(TimePerFrame + TimePerFrameMargin0 - TimePerFrameMargin1)) && nSamplesLeft > 0) // Only drop if we have something else to display at once
- {
- // Drop frame
- TRACE_EVR ("EVR: Dropped frame\n");
- m_pcFrames++;
+ if (!bValidSampleTime) {
+ // Just play as fast as possible
bStepForward = true;
- ++m_nDroppedUpdate;
- NextSleepTime = 0;
-// VSyncOffset0 = (-SyncOffset) - VSyncTime;
- //VSyncOffset0 = (-SyncOffset) - VSyncTime + TimePerFrameMargin1;
- //m_LastPredictedSync = VSyncOffset0;
- bDoVSyncCorrection = false;
- }
- else if (SyncOffset < TimePerFrameMargin1)
- {
-
- if (bVSyncCorrection)
+ pMFSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
+ ++m_OrderedPaint;
+ if (!g_bExternalSubtitleTime) {
+ __super::SetTime (g_tSegmentStart + nsSampleTime);
+ }
+ Paint(true);
+ } else {
+ LONGLONG TimePerFrame = GetFrameTime() * 10000000.0;
+ LONGLONG DrawTime = (m_PaintTime) * 0.9 - 20000.0; // 2 ms offset
+ //if (!s.iVMR9VSync)
+ DrawTime = 0;
+
+ LONGLONG SyncOffset = 0;
+ LONGLONG VSyncTime = 0;
+ LONGLONG TimeToNextVSync = -1;
+ bool bVSyncCorrection = false;
+ double DetectedRefreshTime;
+ double DetectedScanlinesPerFrame;
+ double DetectedScanlineTime;
+ int DetectedRefreshRatePos;
{
-// VSyncOffset0 = -SyncOffset;
- VSyncOffset0 = -SyncOffset;
- bDoVSyncCorrection = true;
+ CAutoLock Lock(&m_RefreshRateLock);
+ DetectedRefreshTime = m_DetectedRefreshTime;
+ DetectedRefreshRatePos = m_DetectedRefreshRatePos;
+ DetectedScanlinesPerFrame = m_DetectedScanlinesPerFrame;
+ DetectedScanlineTime = m_DetectedScanlineTime;
}
- // Paint and prepare for next frame
- TRACE_EVR ("EVR: Normalframe\n");
- m_nDroppedUpdate = 0;
- bStepForward = true;
- pMFSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
- m_LastFrameDuration = nsSampleTime - m_LastSampleTime;
- m_LastSampleTime = nsSampleTime;
- m_LastPredictedSync = VSyncOffset0;
+ if (DetectedRefreshRatePos < 20 || !DetectedRefreshTime || !DetectedScanlinesPerFrame) {
+ DetectedRefreshTime = 1.0/m_RefreshRate;
+ DetectedScanlinesPerFrame = m_ScreenSize.cy;
+ DetectedScanlineTime = DetectedRefreshTime / double(m_ScreenSize.cy);
+ }
- ++m_OrderedPaint;
+ if (s.m_RenderSettings.iVMR9VSync) {
+ bVSyncCorrection = true;
+ double TargetVSyncPos = GetVBlackPos();
+ double RefreshLines = DetectedScanlinesPerFrame;
+ double ScanlinesPerSecond = 1.0/DetectedScanlineTime;
+ double CurrentVSyncPos = fmod(double(m_VBlankStartMeasure) + ScanlinesPerSecond * ((CurrentCounter - m_VBlankStartMeasureTime) / 10000000.0), RefreshLines);
+ double LinesUntilVSync = 0;
+ //TargetVSyncPos -= ScanlinesPerSecond * (DrawTime/10000000.0);
+ //TargetVSyncPos -= 10;
+ TargetVSyncPos = fmod(TargetVSyncPos, RefreshLines);
+ if (TargetVSyncPos < 0) {
+ TargetVSyncPos += RefreshLines;
+ }
+ if (TargetVSyncPos > CurrentVSyncPos) {
+ LinesUntilVSync = TargetVSyncPos - CurrentVSyncPos;
+ } else {
+ LinesUntilVSync = (RefreshLines - CurrentVSyncPos) + TargetVSyncPos;
+ }
+ double TimeUntilVSync = LinesUntilVSync * DetectedScanlineTime;
+ TimeToNextVSync = TimeUntilVSync * 10000000.0;
+ VSyncTime = DetectedRefreshTime * 10000000.0;
- if (!g_bExternalSubtitleTime)
- __super::SetTime (g_tSegmentStart + nsSampleTime);
- Paint(true);
- //m_pSink->Notify(EC_SCRUB_TIME, LODWORD(nsSampleTime), HIDWORD(nsSampleTime));
+ LONGLONG ClockTimeAtNextVSync = llClockTime + (TimeUntilVSync * 10000000.0) * m_ModeratedTimeSpeed;
- NextSleepTime = 0;
- m_pcFramesDrawn++;
- }
- else
- {
- if (TimeToNextVSync >= 0 && SyncOffset > 0)
- {
- NextSleepTime = ((TimeToNextVSync)/10000) - 2;
+ SyncOffset = (nsSampleTime - ClockTimeAtNextVSync);
+
+ // if (SyncOffset < 0)
+ // TRACE_EVR("EVR: SyncOffset(%d): %I64d %I64d %I64d\n", m_nCurSurface, SyncOffset, TimePerFrame, VSyncTime);
+ } else {
+ SyncOffset = (nsSampleTime - llClockTime);
}
- else
- NextSleepTime = ((SyncOffset)/10000) - 2;
- if (NextSleepTime > TimePerFrame)
- NextSleepTime = 1;
+ //LONGLONG SyncOffset = nsSampleTime - llClockTime;
+ TRACE_EVR ("EVR: SyncOffset: %I64d SampleFrame: %I64d ClockFrame: %I64d\n", SyncOffset, TimePerFrame!=0 ? nsSampleTime/TimePerFrame : 0, TimePerFrame!=0 ? llClockTime /TimePerFrame : 0);
+ if (SampleDuration > 1 && !m_DetectedLock) {
+ TimePerFrame = SampleDuration;
+ }
- if (NextSleepTime < 0)
- NextSleepTime = 0;
- NextSleepTime = 1;
- //TRACE_EVR ("EVR: Delay\n");
- }
+ LONGLONG MinMargin;
+ if (m_FrameTimeCorrection && 0) {
+ MinMargin = 15000.0;
+ } else {
+ MinMargin = 15000.0 + min(m_DetectedFrameTimeStdDev, 20000.0);
+ }
+ LONGLONG TimePerFrameMargin = min(double(TimePerFrame)*0.11, max(double(TimePerFrame)*0.02, MinMargin));
+ LONGLONG TimePerFrameMargin0 = TimePerFrameMargin/2;
+ LONGLONG TimePerFrameMargin1 = 0;
- if (bDoVSyncCorrection)
- {
- //LONGLONG VSyncOffset0 = (((SyncOffset) % VSyncTime) + VSyncTime) % VSyncTime;
- LONGLONG Margin = TimePerFrameMargin;
+ if (m_DetectedLock && TimePerFrame < VSyncTime) {
+ VSyncTime = TimePerFrame;
+ }
- LONGLONG VSyncOffsetMin = 30000000000000;
- LONGLONG VSyncOffsetMax = -30000000000000;
- for (int i = 0; i < 5; ++i)
- {
- VSyncOffsetMin = min(m_VSyncOffsetHistory[i], VSyncOffsetMin);
- VSyncOffsetMax = max(m_VSyncOffsetHistory[i], VSyncOffsetMax);
+ if (m_VSyncMode == 1) {
+ TimePerFrameMargin1 = -TimePerFrameMargin;
+ } else if (m_VSyncMode == 2) {
+ TimePerFrameMargin1 = TimePerFrameMargin;
}
- m_VSyncOffsetHistory[m_VSyncOffsetHistoryPos] = VSyncOffset0;
- m_VSyncOffsetHistoryPos = (m_VSyncOffsetHistoryPos + 1) % 5;
+ m_LastSampleOffset = SyncOffset;
+ m_bLastSampleOffsetValid = true;
+
+ LONGLONG VSyncOffset0 = 0;
+ bool bDoVSyncCorrection = false;
+ if ((SyncOffset < -(TimePerFrame + TimePerFrameMargin0 - TimePerFrameMargin1)) && nSamplesLeft > 0) { // Only drop if we have something else to display at once
+ // Drop frame
+ TRACE_EVR ("EVR: Dropped frame\n");
+ m_pcFrames++;
+ bStepForward = true;
+ ++m_nDroppedUpdate;
+ NextSleepTime = 0;
+ // VSyncOffset0 = (-SyncOffset) - VSyncTime;
+ //VSyncOffset0 = (-SyncOffset) - VSyncTime + TimePerFrameMargin1;
+ //m_LastPredictedSync = VSyncOffset0;
+ bDoVSyncCorrection = false;
+ } else if (SyncOffset < TimePerFrameMargin1) {
+
+ if (bVSyncCorrection) {
+ // VSyncOffset0 = -SyncOffset;
+ VSyncOffset0 = -SyncOffset;
+ bDoVSyncCorrection = true;
+ }
-// LONGLONG VSyncTime2 = VSyncTime2 + (VSyncOffsetMax - VSyncOffsetMin);
- //VSyncOffsetMin; = (((VSyncOffsetMin) % VSyncTime) + VSyncTime) % VSyncTime;
- //VSyncOffsetMax = (((VSyncOffsetMax) % VSyncTime) + VSyncTime) % VSyncTime;
+ // Paint and prepare for next frame
+ TRACE_EVR ("EVR: Normalframe\n");
+ m_nDroppedUpdate = 0;
+ bStepForward = true;
+ pMFSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
+ m_LastFrameDuration = nsSampleTime - m_LastSampleTime;
+ m_LastSampleTime = nsSampleTime;
+ m_LastPredictedSync = VSyncOffset0;
-// TRACE_EVR("EVR: SyncOffset(%d, %d): %8I64d %8I64d %8I64d %8I64d\n", m_nCurSurface, m_VSyncMode,VSyncOffset0, VSyncOffsetMin, VSyncOffsetMax, VSyncOffsetMax - VSyncOffsetMin);
+ ++m_OrderedPaint;
- if (m_VSyncMode == 0)
- {
- // 23.976 in 60 Hz
- if (VSyncOffset0 < Margin && VSyncOffsetMax > (VSyncTime - Margin))
- {
- m_VSyncMode = 2;
+ if (!g_bExternalSubtitleTime) {
+ __super::SetTime (g_tSegmentStart + nsSampleTime);
}
- else if (VSyncOffset0 > (VSyncTime - Margin) && VSyncOffsetMin < Margin)
- {
- m_VSyncMode = 1;
+ Paint(true);
+ //m_pSink->Notify(EC_SCRUB_TIME, LODWORD(nsSampleTime), HIDWORD(nsSampleTime));
+
+ NextSleepTime = 0;
+ m_pcFramesDrawn++;
+ } else {
+ if (TimeToNextVSync >= 0 && SyncOffset > 0) {
+ NextSleepTime = ((TimeToNextVSync)/10000) - 2;
+ } else {
+ NextSleepTime = ((SyncOffset)/10000) - 2;
}
- }
- else if (m_VSyncMode == 2)
- {
- if (VSyncOffsetMin > (Margin))
- {
- m_VSyncMode = 0;
+
+ if (NextSleepTime > TimePerFrame) {
+ NextSleepTime = 1;
+ }
+
+ if (NextSleepTime < 0) {
+ NextSleepTime = 0;
}
+ NextSleepTime = 1;
+ //TRACE_EVR ("EVR: Delay\n");
}
- else if (m_VSyncMode == 1)
- {
- if (VSyncOffsetMax < (VSyncTime - Margin))
- {
- m_VSyncMode = 0;
+
+ if (bDoVSyncCorrection) {
+ //LONGLONG VSyncOffset0 = (((SyncOffset) % VSyncTime) + VSyncTime) % VSyncTime;
+ LONGLONG Margin = TimePerFrameMargin;
+
+ LONGLONG VSyncOffsetMin = 30000000000000;
+ LONGLONG VSyncOffsetMax = -30000000000000;
+ for (int i = 0; i < 5; ++i) {
+ VSyncOffsetMin = min(m_VSyncOffsetHistory[i], VSyncOffsetMin);
+ VSyncOffsetMax = max(m_VSyncOffsetHistory[i], VSyncOffsetMax);
+ }
+
+ m_VSyncOffsetHistory[m_VSyncOffsetHistoryPos] = VSyncOffset0;
+ m_VSyncOffsetHistoryPos = (m_VSyncOffsetHistoryPos + 1) % 5;
+
+ // LONGLONG VSyncTime2 = VSyncTime2 + (VSyncOffsetMax - VSyncOffsetMin);
+ //VSyncOffsetMin; = (((VSyncOffsetMin) % VSyncTime) + VSyncTime) % VSyncTime;
+ //VSyncOffsetMax = (((VSyncOffsetMax) % VSyncTime) + VSyncTime) % VSyncTime;
+
+ // TRACE_EVR("EVR: SyncOffset(%d, %d): %8I64d %8I64d %8I64d %8I64d\n", m_nCurSurface, m_VSyncMode,VSyncOffset0, VSyncOffsetMin, VSyncOffsetMax, VSyncOffsetMax - VSyncOffsetMin);
+
+ if (m_VSyncMode == 0) {
+ // 23.976 in 60 Hz
+ if (VSyncOffset0 < Margin && VSyncOffsetMax > (VSyncTime - Margin)) {
+ m_VSyncMode = 2;
+ } else if (VSyncOffset0 > (VSyncTime - Margin) && VSyncOffsetMin < Margin) {
+ m_VSyncMode = 1;
+ }
+ } else if (m_VSyncMode == 2) {
+ if (VSyncOffsetMin > (Margin)) {
+ m_VSyncMode = 0;
+ }
+ } else if (m_VSyncMode == 1) {
+ if (VSyncOffsetMax < (VSyncTime - Margin)) {
+ m_VSyncMode = 0;
+ }
}
}
- }
+ }
}
- }
- m_pCurrentDisplaydSample = NULL;
- if (bStepForward)
- {
- MoveToFreeList(pMFSample, true);
- CheckWaitingSampleFromMixer();
- m_MaxSampleDuration = max(SampleDuration, m_MaxSampleDuration);
- }
- else
- MoveToScheduledList(pMFSample, true);
- }
- else if (m_bLastSampleOffsetValid && m_LastSampleOffset < -10000000) // Only starve if we are 1 seconds behind
- {
- if (m_nRenderState == Started && !g_bNoDuration)
- {
- m_pSink->Notify(EC_STARVATION, 0, 0);
- m_bSignaledStarvation = true;
+ m_pCurrentDisplaydSample = NULL;
+ if (bStepForward) {
+ MoveToFreeList(pMFSample, true);
+ CheckWaitingSampleFromMixer();
+ m_MaxSampleDuration = max(SampleDuration, m_MaxSampleDuration);
+ } else {
+ MoveToScheduledList(pMFSample, true);
+ }
+ } else if (m_bLastSampleOffsetValid && m_LastSampleOffset < -10000000) { // Only starve if we are 1 seconds behind
+ if (m_nRenderState == Started && !g_bNoDuration) {
+ m_pSink->Notify(EC_STARVATION, 0, 0);
+ m_bSignaledStarvation = true;
+ }
}
+ //GetImageFromMixer();
}
- //GetImageFromMixer();
- }
-// else
-// {
-// TRACE_EVR ("EVR: RenderThread ==>> Flush before rendering frame!\n");
-// }
+ // else
+ // {
+ // TRACE_EVR ("EVR: RenderThread ==>> Flush before rendering frame!\n");
+ // }
- break;
+ break;
}
}
timeEndPeriod (dwResolution);
- if (pfAvRevertMmThreadCharacteristics) pfAvRevertMmThreadCharacteristics (hAvrt);
+ if (pfAvRevertMmThreadCharacteristics) {
+ pfAvRevertMmThreadCharacteristics (hAvrt);
+ }
}
void CEVRAllocatorPresenter::OnResetDevice()
@@ -2453,8 +2410,9 @@ void CEVRAllocatorPresenter::OnResetDevice()
hr = m_pD3DManager->ResetDevice(m_pD3DDev, m_nResetToken);
// Not necessary, but Microsoft documentation say Presenter should send this message...
- if (m_pSink)
+ if (m_pSink) {
m_pSink->Notify (EC_DISPLAY_CHANGED, 0, 0);
+ }
}
void CEVRAllocatorPresenter::RemoveAllSamples()
@@ -2474,13 +2432,12 @@ HRESULT CEVRAllocatorPresenter::GetFreeSample(IMFSample** ppSample)
CAutoLock lock(&m_SampleQueueLock);
HRESULT hr = S_OK;
- if (m_FreeSamples.GetCount() > 1) // <= Cannot use first free buffer (can be currently displayed)
- {
+ if (m_FreeSamples.GetCount() > 1) { // <= Cannot use first free buffer (can be currently displayed)
InterlockedIncrement (&m_nUsedBuffer);
*ppSample = m_FreeSamples.RemoveHead().Detach();
- }
- else
+ } else {
hr = MF_E_SAMPLEALLOCATOR_EMPTY;
+ }
return hr;
}
@@ -2492,13 +2449,12 @@ HRESULT CEVRAllocatorPresenter::GetScheduledSample(IMFSample** ppSample, int &_C
HRESULT hr = S_OK;
_Count = m_ScheduledSamples.GetCount();
- if (_Count > 0)
- {
+ if (_Count > 0) {
*ppSample = m_ScheduledSamples.RemoveHead().Detach();
--_Count;
- }
- else
+ } else {
hr = MF_E_SAMPLEALLOCATOR_EMPTY;
+ }
return hr;
}
@@ -2508,23 +2464,22 @@ void CEVRAllocatorPresenter::MoveToFreeList(IMFSample* pSample, bool bTail)
{
CAutoLock lock(&m_SampleQueueLock);
InterlockedDecrement (&m_nUsedBuffer);
- if (m_bPendingMediaFinished && m_nUsedBuffer == 0)
- {
+ if (m_bPendingMediaFinished && m_nUsedBuffer == 0) {
m_bPendingMediaFinished = false;
m_pSink->Notify (EC_COMPLETE, 0, 0);
}
- if (bTail)
+ if (bTail) {
m_FreeSamples.AddTail (pSample);
- else
+ } else {
m_FreeSamples.AddHead(pSample);
+ }
}
void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSorted)
{
- if (_bSorted)
- {
+ if (_bSorted) {
CAutoLock lock(&m_SampleQueueLock);
// Insert sorted
/* POSITION Iterator = m_ScheduledSamples.GetHeadPosition();
@@ -2546,18 +2501,17 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
}*/
m_ScheduledSamples.AddHead(pSample);
- }
- else
- {
+ } else {
CAutoLock lock(&m_SampleQueueLock);
CRenderersSettings& s = GetRenderersSettings();
double ForceFPS = 0.0;
-// double ForceFPS = 59.94;
-// double ForceFPS = 23.976;
- if (ForceFPS != 0.0)
+ // double ForceFPS = 59.94;
+ // double ForceFPS = 23.976;
+ if (ForceFPS != 0.0) {
m_rtTimePerFrame = 10000000.0 / ForceFPS;
+ }
LONGLONG Duration = m_rtTimePerFrame;
UNUSED_ALWAYS(Duration);
LONGLONG PrevTime = m_LastScheduledUncorrectedSampleTime;
@@ -2571,33 +2525,33 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
LONGLONG Diff2 = PrevTime - m_LastScheduledSampleTimeFP*10000000.0;
LONGLONG Diff = Time - PrevTime;
- if (PrevTime == -1)
+ if (PrevTime == -1) {
Diff = 0;
- if (Diff < 0)
+ }
+ if (Diff < 0) {
Diff = -Diff;
- if (Diff2 < 0)
+ }
+ if (Diff2 < 0) {
Diff2 = -Diff2;
- if (Diff < m_rtTimePerFrame*8 && m_rtTimePerFrame && Diff2 < m_rtTimePerFrame*8) // Detect seeking
- {
+ }
+ if (Diff < m_rtTimePerFrame*8 && m_rtTimePerFrame && Diff2 < m_rtTimePerFrame*8) { // Detect seeking
int iPos = (m_DetectedFrameTimePos++) % 60;
LONGLONG Diff = Time - PrevTime;
- if (PrevTime == -1)
+ if (PrevTime == -1) {
Diff = 0;
+ }
m_DetectedFrameTimeHistory[iPos] = Diff;
- if (m_DetectedFrameTimePos >= 10)
- {
+ if (m_DetectedFrameTimePos >= 10) {
int nFrames = min(m_DetectedFrameTimePos, 60);
LONGLONG DectedSum = 0;
- for (int i = 0; i < nFrames; ++i)
- {
+ for (int i = 0; i < nFrames; ++i) {
DectedSum += m_DetectedFrameTimeHistory[i];
}
double Average = double(DectedSum) / double(nFrames);
double DeviationSum = 0.0;
- for (int i = 0; i < nFrames; ++i)
- {
+ for (int i = 0; i < nFrames; ++i) {
double Deviation = m_DetectedFrameTimeHistory[i] - Average;
DeviationSum += Deviation*Deviation;
}
@@ -2613,10 +2567,8 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
static double AllowedValues[] = {60.0, 59.94, 50.0, 48.0, 47.952, 30.0, 29.97, 25.0, 24.0, 23.976};
int nAllowed = sizeof(AllowedValues) / sizeof(AllowedValues[0]);
- for (int i = 0; i < nAllowed; ++i)
- {
- if (fabs(1.0 - DetectedRate / AllowedValues[i]) < AllowedError)
- {
+ for (int i = 0; i < nAllowed; ++i) {
+ if (fabs(1.0 - DetectedRate / AllowedValues[i]) < AllowedError) {
DetectedRate = AllowedValues[i];
break;
}
@@ -2630,22 +2582,18 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
int m_Int;
- CAutoInt()
- {
+ CAutoInt() {
m_Int = 0;
}
- CAutoInt(int _Other)
- {
+ CAutoInt(int _Other) {
m_Int = _Other;
}
- operator int () const
- {
+ operator int () const {
return m_Int;
}
- CAutoInt &operator ++ ()
- {
+ CAutoInt &operator ++ () {
++m_Int;
return *this;
}
@@ -2654,37 +2602,31 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
CMap<double, double, CAutoInt, CAutoInt> Map;
- for (int i = 0; i < 500; ++i)
- {
+ for (int i = 0; i < 500; ++i) {
++Map[m_DetectedFrameTimeHistoryHistory[i]];
}
POSITION Pos = Map.GetStartPosition();
double BestVal = 0.0;
int BestNum = 5;
- while (Pos)
- {
+ while (Pos) {
double Key;
CAutoInt Value;
Map.GetNextAssoc(Pos, Key, Value);
- if (Value.m_Int > BestNum && Key != 0.0)
- {
+ if (Value.m_Int > BestNum && Key != 0.0) {
BestNum = Value.m_Int;
BestVal = Key;
}
}
m_DetectedLock = false;
- for (int i = 0; i < nAllowed; ++i)
- {
- if (BestVal == AllowedValues[i])
- {
+ for (int i = 0; i < nAllowed; ++i) {
+ if (BestVal == AllowedValues[i]) {
m_DetectedLock = true;
break;
}
}
- if (BestVal != 0.0)
- {
+ if (BestVal != 0.0) {
m_DetectedFrameRate = BestVal;
m_DetectedFrameTime = 1.0 / BestVal;
}
@@ -2692,18 +2634,17 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
LONGLONG PredictedNext = PrevTime + m_rtTimePerFrame;
LONGLONG PredictedDiff = PredictedNext - Time;
- if (PredictedDiff < 0)
+ if (PredictedDiff < 0) {
PredictedDiff = -PredictedDiff;
+ }
if (m_DetectedFrameTime != 0.0
//&& PredictedDiff > 15000
- && m_DetectedLock && s.m_RenderSettings.iEVREnableFrameTimeCorrection)
- {
+ && m_DetectedLock && s.m_RenderSettings.iEVREnableFrameTimeCorrection) {
double CurrentTime = Time / 10000000.0;
double LastTime = m_LastScheduledSampleTimeFP;
double PredictedTime = LastTime + m_DetectedFrameTime;
- if (fabs(PredictedTime - CurrentTime) > 0.0015) // 1.5 ms wrong, lets correct
- {
+ if (fabs(PredictedTime - CurrentTime) > 0.0015) { // 1.5 ms wrong, lets correct
CurrentTime = PredictedTime;
Time = CurrentTime * 10000000.0;
pSample->SetSampleTime(Time);
@@ -2712,15 +2653,12 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
m_FrameTimeCorrection = 30;
}
m_LastScheduledSampleTimeFP = CurrentTime;
- }
- else
+ } else {
m_LastScheduledSampleTimeFP = Time / 10000000.0;
- }
- else
- {
+ }
+ } else {
m_LastScheduledSampleTimeFP = Time / 10000000.0;
- if (Diff > m_rtTimePerFrame*8)
- {
+ if (Diff > m_rtTimePerFrame*8) {
// Seek
m_bSignaledStarvation = false;
m_DetectedFrameTimePos = 0;
@@ -2728,19 +2666,19 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
}
}
-// TRACE_EVR("EVR: Time: %f %f %f\n", Time / 10000000.0, SetDuration / 10000000.0, m_DetectedFrameRate);
- if (!m_bCorrectedFrameTime && m_FrameTimeCorrection)
+ // TRACE_EVR("EVR: Time: %f %f %f\n", Time / 10000000.0, SetDuration / 10000000.0, m_DetectedFrameRate);
+ if (!m_bCorrectedFrameTime && m_FrameTimeCorrection) {
--m_FrameTimeCorrection;
+ }
#if 0
- if (Time <= m_LastScheduledUncorrectedSampleTime && m_LastScheduledSampleTime >= 0)
+ if (Time <= m_LastScheduledUncorrectedSampleTime && m_LastScheduledSampleTime >= 0) {
PrevTime = m_LastScheduledSampleTime;
+ }
m_bCorrectedFrameTime = false;
- if (PrevTime != -1 && (Time >= PrevTime - ((Duration*20)/9) || Time == 0) || ForceFPS != 0.0)
- {
- if (Time - PrevTime > ((Duration*20)/9) && Time - PrevTime < Duration * 8 || Time == 0 || ((Time - PrevTime) < (Duration / 11)) || ForceFPS != 0.0)
- {
+ if (PrevTime != -1 && (Time >= PrevTime - ((Duration*20)/9) || Time == 0) || ForceFPS != 0.0) {
+ if (Time - PrevTime > ((Duration*20)/9) && Time - PrevTime < Duration * 8 || Time == 0 || ((Time - PrevTime) < (Duration / 11)) || ForceFPS != 0.0) {
// Error!!!!
Time = PrevTime + Duration;
pSample->SetSampleTime(Time);
@@ -2749,8 +2687,7 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
TRACE_EVR("EVR: Corrected invalid sample time\n");
}
}
- if (Time+Duration*10 < m_LastScheduledSampleTime)
- {
+ if (Time+Duration*10 < m_LastScheduledSampleTime) {
// Flush when repeating movie
FlushSamplesInternal();
}
@@ -2760,8 +2697,7 @@ void CEVRAllocatorPresenter::MoveToScheduledList(IMFSample* pSample, bool _bSort
static LONGLONG LastDuration = 0;
LONGLONG SetDuration = m_rtTimePerFrame;
pSample->GetSampleDuration(&SetDuration);
- if (SetDuration != LastDuration)
- {
+ if (SetDuration != LastDuration) {
TRACE_EVR("EVR: Old duration: %I64d New duration: %I64d\n", LastDuration, SetDuration);
}
LastDuration = SetDuration;
@@ -2786,8 +2722,7 @@ void CEVRAllocatorPresenter::FlushSamples()
void CEVRAllocatorPresenter::FlushSamplesInternal()
{
- while (m_ScheduledSamples.GetCount() > 0)
- {
+ while (m_ScheduledSamples.GetCount() > 0) {
CComPtr<IMFSample> pMFSample;
pMFSample = m_ScheduledSamples.RemoveHead();
diff --git a/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.h b/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.h
index c10634f2b..56d67639c 100644
--- a/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/EVRAllocatorPresenter.h
@@ -28,255 +28,254 @@
namespace DSObjects
{
-// dxva.dll
-typedef HRESULT (__stdcall *PTR_DXVA2CreateDirect3DDeviceManager9)(UINT* pResetToken, IDirect3DDeviceManager9** ppDeviceManager);
-
-// mf.dll
-typedef HRESULT (__stdcall *PTR_MFCreatePresentationClock)(IMFPresentationClock** ppPresentationClock);
-
-// evr.dll
-typedef HRESULT (__stdcall *PTR_MFCreateDXSurfaceBuffer)(REFIID riid, IUnknown* punkSurface, BOOL fBottomUpWhenLinear, IMFMediaBuffer** ppBuffer);
-typedef HRESULT (__stdcall *PTR_MFCreateVideoSampleFromSurface)(IUnknown* pUnkSurface, IMFSample** ppSample);
-typedef HRESULT (__stdcall *PTR_MFCreateVideoMediaType)(const MFVIDEOFORMAT* pVideoFormat, IMFVideoMediaType** ppIVideoMediaType);
-
-// AVRT.dll
-typedef HANDLE (__stdcall *PTR_AvSetMmThreadCharacteristicsW)(LPCWSTR TaskName, LPDWORD TaskIndex);
-typedef BOOL (__stdcall *PTR_AvSetMmThreadPriority)(HANDLE AvrtHandle, AVRT_PRIORITY Priority);
-typedef BOOL (__stdcall *PTR_AvRevertMmThreadCharacteristics)(HANDLE AvrtHandle);
-
-class COuterEVR;
-
-class CEVRAllocatorPresenter :
- public CDX9AllocatorPresenter,
- public IMFGetService,
- public IMFTopologyServiceLookupClient,
- public IMFVideoDeviceID,
- public IMFVideoPresenter,
- public IDirect3DDeviceManager9,
-
- public IMFAsyncCallback,
- public IQualProp,
- public IMFRateSupport,
- public IMFVideoDisplayControl,
- public IEVRTrustedVideoPlugin
-/* public IMFVideoPositionMapper, // Non mandatory EVR Presenter Interfaces (see later...)
-*/
-{
-public:
- CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
- ~CEVRAllocatorPresenter(void);
-
- DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
- STDMETHODIMP InitializeDevice(IMFMediaType* pMediaType);
- STDMETHODIMP_(bool) ResetDevice();
-
- // IMFClockStateSink
- STDMETHODIMP OnClockStart(/* [in] */ MFTIME hnsSystemTime, /* [in] */ LONGLONG llClockStartOffset);
- STDMETHODIMP STDMETHODCALLTYPE OnClockStop(/* [in] */ MFTIME hnsSystemTime);
- STDMETHODIMP STDMETHODCALLTYPE OnClockPause(/* [in] */ MFTIME hnsSystemTime);
- STDMETHODIMP STDMETHODCALLTYPE OnClockRestart(/* [in] */ MFTIME hnsSystemTime);
- STDMETHODIMP STDMETHODCALLTYPE OnClockSetRate(/* [in] */ MFTIME hnsSystemTime, /* [in] */ float flRate);
-
- // IBaseFilter delegate
- bool GetState( DWORD dwMilliSecsTimeout, FILTER_STATE *State, HRESULT &_ReturnValue);
-
- // IQualProp (EVR statistics window)
- STDMETHODIMP get_FramesDroppedInRenderer (int *pcFrames);
- STDMETHODIMP get_FramesDrawn (int *pcFramesDrawn);
- STDMETHODIMP get_AvgFrameRate (int *piAvgFrameRate);
- STDMETHODIMP get_Jitter (int *iJitter);
- STDMETHODIMP get_AvgSyncOffset (int *piAvg);
- STDMETHODIMP get_DevSyncOffset (int *piDev);
-
-
- // IMFRateSupport
- STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
- STDMETHODIMP GetFastestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
- STDMETHODIMP IsRateSupported(BOOL fThin, float flRate, float *pflNearestSupportedRate);
-
- float GetMaxRate(BOOL bThin);
-
-
- // IMFVideoPresenter
- STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
- STDMETHODIMP GetCurrentMediaType(__deref_out IMFVideoMediaType **ppMediaType);
-
- // IMFTopologyServiceLookupClient
- STDMETHODIMP InitServicePointers(/* [in] */ __in IMFTopologyServiceLookup *pLookup);
- STDMETHODIMP ReleaseServicePointers();
-
- // IMFVideoDeviceID
- STDMETHODIMP GetDeviceID(/* [out] */ __out IID *pDeviceID);
-
- // IMFGetService
- STDMETHODIMP GetService (/* [in] */ __RPC__in REFGUID guidService,
- /* [in] */ __RPC__in REFIID riid,
- /* [iid_is][out] */ __RPC__deref_out_opt LPVOID *ppvObject);
-
- // IMFAsyncCallback
- STDMETHODIMP GetParameters( /* [out] */ __RPC__out DWORD *pdwFlags, /* [out] */ __RPC__out DWORD *pdwQueue);
- STDMETHODIMP Invoke ( /* [in] */ __RPC__in_opt IMFAsyncResult *pAsyncResult);
-
- // IMFVideoDisplayControl
- STDMETHODIMP GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo);
- STDMETHODIMP GetIdealVideoSize(SIZE *pszMin, SIZE *pszMax);
- STDMETHODIMP SetVideoPosition(const MFVideoNormalizedRect *pnrcSource, const LPRECT prcDest);
- STDMETHODIMP GetVideoPosition(MFVideoNormalizedRect *pnrcSource, LPRECT prcDest);
- STDMETHODIMP SetAspectRatioMode(DWORD dwAspectRatioMode);
- STDMETHODIMP GetAspectRatioMode(DWORD *pdwAspectRatioMode);
- STDMETHODIMP SetVideoWindow(HWND hwndVideo);
- STDMETHODIMP GetVideoWindow(HWND *phwndVideo);
- STDMETHODIMP RepaintVideo( void);
- STDMETHODIMP GetCurrentImage(BITMAPINFOHEADER *pBih, BYTE **pDib, DWORD *pcbDib, LONGLONG *pTimeStamp);
- STDMETHODIMP SetBorderColor(COLORREF Clr);
- STDMETHODIMP GetBorderColor(COLORREF *pClr);
- STDMETHODIMP SetRenderingPrefs(DWORD dwRenderFlags);
- STDMETHODIMP GetRenderingPrefs(DWORD *pdwRenderFlags);
- STDMETHODIMP SetFullscreen(BOOL fFullscreen);
- STDMETHODIMP GetFullscreen(BOOL *pfFullscreen);
-
- // IEVRTrustedVideoPlugin
- STDMETHODIMP IsInTrustedVideoMode(BOOL *pYes);
- STDMETHODIMP CanConstrict(BOOL *pYes);
- STDMETHODIMP SetConstriction(DWORD dwKPix);
- STDMETHODIMP DisableImageExport(BOOL bDisable);
-
- // IDirect3DDeviceManager9
- STDMETHODIMP ResetDevice(IDirect3DDevice9 *pDevice,UINT resetToken);
- STDMETHODIMP OpenDeviceHandle(HANDLE *phDevice);
- STDMETHODIMP CloseDeviceHandle(HANDLE hDevice);
- STDMETHODIMP TestDevice(HANDLE hDevice);
- STDMETHODIMP LockDevice(HANDLE hDevice, IDirect3DDevice9 **ppDevice, BOOL fBlock);
- STDMETHODIMP UnlockDevice(HANDLE hDevice, BOOL fSaveState);
- STDMETHODIMP GetVideoService(HANDLE hDevice, REFIID riid, void **ppService);
-
-protected :
- void OnResetDevice();
- virtual void OnVBlankFinished(bool fAll, LONGLONG PerformanceCounter);
-
- double m_ModeratedTime;
- LONGLONG m_ModeratedTimeLast;
- LONGLONG m_ModeratedClockLast;
- LONGLONG m_ModeratedTimer;
- MFCLOCK_STATE m_LastClockState;
- LONGLONG GetClockTime(LONGLONG PerformanceCounter);
-
-private :
-
- typedef enum
+ // dxva.dll
+ typedef HRESULT (__stdcall *PTR_DXVA2CreateDirect3DDeviceManager9)(UINT* pResetToken, IDirect3DDeviceManager9** ppDeviceManager);
+
+ // mf.dll
+ typedef HRESULT (__stdcall *PTR_MFCreatePresentationClock)(IMFPresentationClock** ppPresentationClock);
+
+ // evr.dll
+ typedef HRESULT (__stdcall *PTR_MFCreateDXSurfaceBuffer)(REFIID riid, IUnknown* punkSurface, BOOL fBottomUpWhenLinear, IMFMediaBuffer** ppBuffer);
+ typedef HRESULT (__stdcall *PTR_MFCreateVideoSampleFromSurface)(IUnknown* pUnkSurface, IMFSample** ppSample);
+ typedef HRESULT (__stdcall *PTR_MFCreateVideoMediaType)(const MFVIDEOFORMAT* pVideoFormat, IMFVideoMediaType** ppIVideoMediaType);
+
+ // AVRT.dll
+ typedef HANDLE (__stdcall *PTR_AvSetMmThreadCharacteristicsW)(LPCWSTR TaskName, LPDWORD TaskIndex);
+ typedef BOOL (__stdcall *PTR_AvSetMmThreadPriority)(HANDLE AvrtHandle, AVRT_PRIORITY Priority);
+ typedef BOOL (__stdcall *PTR_AvRevertMmThreadCharacteristics)(HANDLE AvrtHandle);
+
+ class COuterEVR;
+
+ class CEVRAllocatorPresenter :
+ public CDX9AllocatorPresenter,
+ public IMFGetService,
+ public IMFTopologyServiceLookupClient,
+ public IMFVideoDeviceID,
+ public IMFVideoPresenter,
+ public IDirect3DDeviceManager9,
+
+ public IMFAsyncCallback,
+ public IQualProp,
+ public IMFRateSupport,
+ public IMFVideoDisplayControl,
+ public IEVRTrustedVideoPlugin
+ /* public IMFVideoPositionMapper, // Non mandatory EVR Presenter Interfaces (see later...)
+ */
{
- Started = State_Running,
- Stopped = State_Stopped,
- Paused = State_Paused,
- Shutdown = State_Running + 1
- } RENDER_STATE;
-
- COuterEVR* m_pOuterEVR;
- CComPtr<IMFClock> m_pClock;
- CComPtr<IDirect3DDeviceManager9> m_pD3DManager;
- CComPtr<IMFTransform> m_pMixer;
- CComPtr<IMediaEventSink> m_pSink;
- CComPtr<IMFVideoMediaType> m_pMediaType;
- MFVideoAspectRatioMode m_dwVideoAspectRatioMode;
- MFVideoRenderPrefs m_dwVideoRenderPrefs;
- COLORREF m_BorderColor;
-
-
- HANDLE m_hEvtQuit; // Stop rendering thread event
- bool m_bEvtQuit;
- HANDLE m_hEvtFlush; // Discard all buffers
- bool m_bEvtFlush;
-
- bool m_fUseInternalTimer;
- int32 m_LastSetOutputRange;
- bool m_bPendingRenegotiate;
- bool m_bPendingMediaFinished;
-
- HANDLE m_hThread;
- HANDLE m_hGetMixerThread;
- RENDER_STATE m_nRenderState;
-
- CCritSec m_SampleQueueLock;
- CCritSec m_ImageProcessingLock;
-
- CInterfaceList<IMFSample, &IID_IMFSample> m_FreeSamples;
- CInterfaceList<IMFSample, &IID_IMFSample> m_ScheduledSamples;
- IMFSample * m_pCurrentDisplaydSample;
- bool m_bWaitingSample;
- bool m_bLastSampleOffsetValid;
- LONGLONG m_LastScheduledSampleTime;
- double m_LastScheduledSampleTimeFP;
- LONGLONG m_LastScheduledUncorrectedSampleTime;
- LONGLONG m_MaxSampleDuration;
- LONGLONG m_LastSampleOffset;
- LONGLONG m_VSyncOffsetHistory[5];
- LONGLONG m_LastPredictedSync;
- int m_VSyncOffsetHistoryPos;
-
- UINT m_nResetToken;
- int m_nStepCount;
-
- bool m_bSignaledStarvation;
- LONGLONG m_StarvationClock;
-
- // Stats variable for IQualProp
- UINT m_pcFrames;
- UINT m_nDroppedUpdate;
- UINT m_pcFramesDrawn; // Retrieves the number of frames drawn since streaming started
- UINT m_piAvg;
- UINT m_piDev;
-
-
- void GetMixerThread();
- static DWORD WINAPI GetMixerThreadStatic(LPVOID lpParam);
-
- bool GetImageFromMixer();
- void RenderThread();
- static DWORD WINAPI PresentThread(LPVOID lpParam);
- void ResetStats();
- void StartWorkerThreads();
- void StopWorkerThreads();
- HRESULT CheckShutdown() const;
- void CompleteFrameStep(bool bCancel);
- void CheckWaitingSampleFromMixer();
-
- void RemoveAllSamples();
- HRESULT GetFreeSample(IMFSample** ppSample);
- HRESULT GetScheduledSample(IMFSample** ppSample, int &_Count);
- void MoveToFreeList(IMFSample* pSample, bool bTail);
- void MoveToScheduledList(IMFSample* pSample, bool _bSorted);
- void FlushSamples();
- void FlushSamplesInternal();
-
- // === Media type negotiation functions
- HRESULT RenegotiateMediaType();
- HRESULT IsMediaTypeSupported(IMFMediaType* pMixerType);
- HRESULT CreateProposedOutputType(IMFMediaType* pMixerType, IMFMediaType** pType);
- HRESULT SetMediaType(IMFMediaType* pType);
- HRESULT GetMediaTypeFourCC(IMFMediaType* pType, DWORD* pFourCC);
- HRESULT GetMediaTypeMerit(IMFMediaType* pType, int *pMerit);
- LPCTSTR GetMediaTypeFormatDesc(IMFMediaType* pMediaType);
-
- // === Functions pointers on Vista / .Net3 specifics library
- PTR_DXVA2CreateDirect3DDeviceManager9 pfDXVA2CreateDirect3DDeviceManager9;
- PTR_MFCreateDXSurfaceBuffer pfMFCreateDXSurfaceBuffer;
- PTR_MFCreateVideoSampleFromSurface pfMFCreateVideoSampleFromSurface;
- PTR_MFCreateVideoMediaType pfMFCreateVideoMediaType;
+ public:
+ CEVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+ ~CEVRAllocatorPresenter(void);
+
+ DECLARE_IUNKNOWN;
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
+ STDMETHODIMP InitializeDevice(IMFMediaType* pMediaType);
+ STDMETHODIMP_(bool) ResetDevice();
+
+ // IMFClockStateSink
+ STDMETHODIMP OnClockStart(/* [in] */ MFTIME hnsSystemTime, /* [in] */ LONGLONG llClockStartOffset);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockStop(/* [in] */ MFTIME hnsSystemTime);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockPause(/* [in] */ MFTIME hnsSystemTime);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockRestart(/* [in] */ MFTIME hnsSystemTime);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockSetRate(/* [in] */ MFTIME hnsSystemTime, /* [in] */ float flRate);
+
+ // IBaseFilter delegate
+ bool GetState( DWORD dwMilliSecsTimeout, FILTER_STATE *State, HRESULT &_ReturnValue);
+
+ // IQualProp (EVR statistics window)
+ STDMETHODIMP get_FramesDroppedInRenderer (int *pcFrames);
+ STDMETHODIMP get_FramesDrawn (int *pcFramesDrawn);
+ STDMETHODIMP get_AvgFrameRate (int *piAvgFrameRate);
+ STDMETHODIMP get_Jitter (int *iJitter);
+ STDMETHODIMP get_AvgSyncOffset (int *piAvg);
+ STDMETHODIMP get_DevSyncOffset (int *piDev);
+
+
+ // IMFRateSupport
+ STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
+ STDMETHODIMP GetFastestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
+ STDMETHODIMP IsRateSupported(BOOL fThin, float flRate, float *pflNearestSupportedRate);
+
+ float GetMaxRate(BOOL bThin);
+
+
+ // IMFVideoPresenter
+ STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
+ STDMETHODIMP GetCurrentMediaType(__deref_out IMFVideoMediaType **ppMediaType);
+
+ // IMFTopologyServiceLookupClient
+ STDMETHODIMP InitServicePointers(/* [in] */ __in IMFTopologyServiceLookup *pLookup);
+ STDMETHODIMP ReleaseServicePointers();
+
+ // IMFVideoDeviceID
+ STDMETHODIMP GetDeviceID(/* [out] */ __out IID *pDeviceID);
+
+ // IMFGetService
+ STDMETHODIMP GetService (/* [in] */ __RPC__in REFGUID guidService,
+ /* [in] */ __RPC__in REFIID riid,
+ /* [iid_is][out] */ __RPC__deref_out_opt LPVOID *ppvObject);
+
+ // IMFAsyncCallback
+ STDMETHODIMP GetParameters( /* [out] */ __RPC__out DWORD *pdwFlags, /* [out] */ __RPC__out DWORD *pdwQueue);
+ STDMETHODIMP Invoke ( /* [in] */ __RPC__in_opt IMFAsyncResult *pAsyncResult);
+
+ // IMFVideoDisplayControl
+ STDMETHODIMP GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo);
+ STDMETHODIMP GetIdealVideoSize(SIZE *pszMin, SIZE *pszMax);
+ STDMETHODIMP SetVideoPosition(const MFVideoNormalizedRect *pnrcSource, const LPRECT prcDest);
+ STDMETHODIMP GetVideoPosition(MFVideoNormalizedRect *pnrcSource, LPRECT prcDest);
+ STDMETHODIMP SetAspectRatioMode(DWORD dwAspectRatioMode);
+ STDMETHODIMP GetAspectRatioMode(DWORD *pdwAspectRatioMode);
+ STDMETHODIMP SetVideoWindow(HWND hwndVideo);
+ STDMETHODIMP GetVideoWindow(HWND *phwndVideo);
+ STDMETHODIMP RepaintVideo( void);
+ STDMETHODIMP GetCurrentImage(BITMAPINFOHEADER *pBih, BYTE **pDib, DWORD *pcbDib, LONGLONG *pTimeStamp);
+ STDMETHODIMP SetBorderColor(COLORREF Clr);
+ STDMETHODIMP GetBorderColor(COLORREF *pClr);
+ STDMETHODIMP SetRenderingPrefs(DWORD dwRenderFlags);
+ STDMETHODIMP GetRenderingPrefs(DWORD *pdwRenderFlags);
+ STDMETHODIMP SetFullscreen(BOOL fFullscreen);
+ STDMETHODIMP GetFullscreen(BOOL *pfFullscreen);
+
+ // IEVRTrustedVideoPlugin
+ STDMETHODIMP IsInTrustedVideoMode(BOOL *pYes);
+ STDMETHODIMP CanConstrict(BOOL *pYes);
+ STDMETHODIMP SetConstriction(DWORD dwKPix);
+ STDMETHODIMP DisableImageExport(BOOL bDisable);
+
+ // IDirect3DDeviceManager9
+ STDMETHODIMP ResetDevice(IDirect3DDevice9 *pDevice,UINT resetToken);
+ STDMETHODIMP OpenDeviceHandle(HANDLE *phDevice);
+ STDMETHODIMP CloseDeviceHandle(HANDLE hDevice);
+ STDMETHODIMP TestDevice(HANDLE hDevice);
+ STDMETHODIMP LockDevice(HANDLE hDevice, IDirect3DDevice9 **ppDevice, BOOL fBlock);
+ STDMETHODIMP UnlockDevice(HANDLE hDevice, BOOL fSaveState);
+ STDMETHODIMP GetVideoService(HANDLE hDevice, REFIID riid, void **ppService);
+
+ protected :
+ void OnResetDevice();
+ virtual void OnVBlankFinished(bool fAll, LONGLONG PerformanceCounter);
+
+ double m_ModeratedTime;
+ LONGLONG m_ModeratedTimeLast;
+ LONGLONG m_ModeratedClockLast;
+ LONGLONG m_ModeratedTimer;
+ MFCLOCK_STATE m_LastClockState;
+ LONGLONG GetClockTime(LONGLONG PerformanceCounter);
+
+ private :
+
+ typedef enum {
+ Started = State_Running,
+ Stopped = State_Stopped,
+ Paused = State_Paused,
+ Shutdown = State_Running + 1
+ } RENDER_STATE;
+
+ COuterEVR* m_pOuterEVR;
+ CComPtr<IMFClock> m_pClock;
+ CComPtr<IDirect3DDeviceManager9> m_pD3DManager;
+ CComPtr<IMFTransform> m_pMixer;
+ CComPtr<IMediaEventSink> m_pSink;
+ CComPtr<IMFVideoMediaType> m_pMediaType;
+ MFVideoAspectRatioMode m_dwVideoAspectRatioMode;
+ MFVideoRenderPrefs m_dwVideoRenderPrefs;
+ COLORREF m_BorderColor;
+
+
+ HANDLE m_hEvtQuit; // Stop rendering thread event
+ bool m_bEvtQuit;
+ HANDLE m_hEvtFlush; // Discard all buffers
+ bool m_bEvtFlush;
+
+ bool m_fUseInternalTimer;
+ int32 m_LastSetOutputRange;
+ bool m_bPendingRenegotiate;
+ bool m_bPendingMediaFinished;
+
+ HANDLE m_hThread;
+ HANDLE m_hGetMixerThread;
+ RENDER_STATE m_nRenderState;
+
+ CCritSec m_SampleQueueLock;
+ CCritSec m_ImageProcessingLock;
+
+ CInterfaceList<IMFSample, &IID_IMFSample> m_FreeSamples;
+ CInterfaceList<IMFSample, &IID_IMFSample> m_ScheduledSamples;
+ IMFSample * m_pCurrentDisplaydSample;
+ bool m_bWaitingSample;
+ bool m_bLastSampleOffsetValid;
+ LONGLONG m_LastScheduledSampleTime;
+ double m_LastScheduledSampleTimeFP;
+ LONGLONG m_LastScheduledUncorrectedSampleTime;
+ LONGLONG m_MaxSampleDuration;
+ LONGLONG m_LastSampleOffset;
+ LONGLONG m_VSyncOffsetHistory[5];
+ LONGLONG m_LastPredictedSync;
+ int m_VSyncOffsetHistoryPos;
+
+ UINT m_nResetToken;
+ int m_nStepCount;
+
+ bool m_bSignaledStarvation;
+ LONGLONG m_StarvationClock;
+
+ // Stats variable for IQualProp
+ UINT m_pcFrames;
+ UINT m_nDroppedUpdate;
+ UINT m_pcFramesDrawn; // Retrieves the number of frames drawn since streaming started
+ UINT m_piAvg;
+ UINT m_piDev;
+
+
+ void GetMixerThread();
+ static DWORD WINAPI GetMixerThreadStatic(LPVOID lpParam);
+
+ bool GetImageFromMixer();
+ void RenderThread();
+ static DWORD WINAPI PresentThread(LPVOID lpParam);
+ void ResetStats();
+ void StartWorkerThreads();
+ void StopWorkerThreads();
+ HRESULT CheckShutdown() const;
+ void CompleteFrameStep(bool bCancel);
+ void CheckWaitingSampleFromMixer();
+
+ void RemoveAllSamples();
+ HRESULT GetFreeSample(IMFSample** ppSample);
+ HRESULT GetScheduledSample(IMFSample** ppSample, int &_Count);
+ void MoveToFreeList(IMFSample* pSample, bool bTail);
+ void MoveToScheduledList(IMFSample* pSample, bool _bSorted);
+ void FlushSamples();
+ void FlushSamplesInternal();
+
+ // === Media type negotiation functions
+ HRESULT RenegotiateMediaType();
+ HRESULT IsMediaTypeSupported(IMFMediaType* pMixerType);
+ HRESULT CreateProposedOutputType(IMFMediaType* pMixerType, IMFMediaType** pType);
+ HRESULT SetMediaType(IMFMediaType* pType);
+ HRESULT GetMediaTypeFourCC(IMFMediaType* pType, DWORD* pFourCC);
+ HRESULT GetMediaTypeMerit(IMFMediaType* pType, int *pMerit);
+ LPCTSTR GetMediaTypeFormatDesc(IMFMediaType* pMediaType);
+
+ // === Functions pointers on Vista / .Net3 specifics library
+ PTR_DXVA2CreateDirect3DDeviceManager9 pfDXVA2CreateDirect3DDeviceManager9;
+ PTR_MFCreateDXSurfaceBuffer pfMFCreateDXSurfaceBuffer;
+ PTR_MFCreateVideoSampleFromSurface pfMFCreateVideoSampleFromSurface;
+ PTR_MFCreateVideoMediaType pfMFCreateVideoMediaType;
#if 0
- HRESULT (__stdcall *pMFCreateMediaType)(__deref_out IMFMediaType** ppMFType);
- HRESULT (__stdcall *pMFInitMediaTypeFromAMMediaType)(__in IMFMediaType *pMFType, __in const AM_MEDIA_TYPE *pAMType);
- HRESULT (__stdcall *pMFInitAMMediaTypeFromMFMediaType)(__in IMFMediaType *pMFType, __in GUID guidFormatBlockType, __inout AM_MEDIA_TYPE *pAMType);
+ HRESULT (__stdcall *pMFCreateMediaType)(__deref_out IMFMediaType** ppMFType);
+ HRESULT (__stdcall *pMFInitMediaTypeFromAMMediaType)(__in IMFMediaType *pMFType, __in const AM_MEDIA_TYPE *pAMType);
+ HRESULT (__stdcall *pMFInitAMMediaTypeFromMFMediaType)(__in IMFMediaType *pMFType, __in GUID guidFormatBlockType, __inout AM_MEDIA_TYPE *pAMType);
#endif
- PTR_AvSetMmThreadCharacteristicsW pfAvSetMmThreadCharacteristicsW;
- PTR_AvSetMmThreadPriority pfAvSetMmThreadPriority;
- PTR_AvRevertMmThreadCharacteristics pfAvRevertMmThreadCharacteristics;
-};
+ PTR_AvSetMmThreadCharacteristicsW pfAvSetMmThreadCharacteristicsW;
+ PTR_AvSetMmThreadPriority pfAvSetMmThreadPriority;
+ PTR_AvRevertMmThreadCharacteristics pfAvRevertMmThreadCharacteristics;
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/IPinHook.cpp b/src/filters/renderer/VideoRenderers/IPinHook.cpp
index c7a8caaed..e1420fd6e 100644
--- a/src/filters/renderer/VideoRenderers/IPinHook.cpp
+++ b/src/filters/renderer/VideoRenderers/IPinHook.cpp
@@ -79,14 +79,12 @@ const DXVA2_DECODER DXVA2Decoder[] =
};
*/
-typedef struct
-{
+typedef struct {
const int Format;
const LPCTSTR Description;
} D3DFORMAT_TYPE;
-const D3DFORMAT_TYPE D3DFormatType[] =
-{
+const D3DFORMAT_TYPE D3DFormatType[] = {
{ D3DFMT_UNKNOWN , _T("D3DFMT_UNKNOWN ") },
{ D3DFMT_R8G8B8 , _T("D3DFMT_R8G8B8 ") },
{ D3DFMT_A8R8G8B8 , _T("D3DFMT_A8R8G8B8 ") },
@@ -156,10 +154,10 @@ LPCTSTR GetDXVAVersion()
LPCTSTR FindD3DFormat(const D3DFORMAT Format)
{
- for (int i=0; i<countof(D3DFormatType); i++)
- {
- if (Format == D3DFormatType[i].Format)
+ for (int i=0; i<countof(D3DFormatType); i++) {
+ if (Format == D3DFormatType[i].Format) {
return D3DFormatType[i].Description;
+ }
}
return D3DFormatType[0].Description;
@@ -179,8 +177,9 @@ static HRESULT ( STDMETHODCALLTYPE *ReceiveOrg )( IMemInputPinC * This, IMediaSa
static HRESULT STDMETHODCALLTYPE ReceiveMineI(IMemInputPinC * This, IMediaSample *pSample)
{
REFERENCE_TIME rtStart, rtStop;
- if(pSample && SUCCEEDED(pSample->GetTime(&rtStart, &rtStop)))
+ if(pSample && SUCCEEDED(pSample->GetTime(&rtStart, &rtStop))) {
g_tSampleStart = rtStart;
+ }
return ReceiveOrg(This, pSample);
}
@@ -188,8 +187,7 @@ static HRESULT STDMETHODCALLTYPE ReceiveMine(IMemInputPinC * This, IMediaSample
{
// Support ffdshow queueing.
// To avoid black out on pause, we have to lock g_ffdshowReceive to synchronize with CMainFrame::OnPlayPause.
- if(queue_ffdshow_support)
- {
+ if(queue_ffdshow_support) {
CAutoLock lck(&g_ffdshowReceive);
return ReceiveMineI(This,pSample);
}
@@ -203,16 +201,17 @@ void UnhookNewSegmentAndReceive()
DWORD flOldProtect = 0;
// Casimir666 : unhook previous VTables
- if (g_pPinCVtbl && g_pMemInputPinCVtbl)
- {
+ if (g_pPinCVtbl && g_pMemInputPinCVtbl) {
res = VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (g_pPinCVtbl->NewSegment == NewSegmentMine)
+ if (g_pPinCVtbl->NewSegment == NewSegmentMine) {
g_pPinCVtbl->NewSegment = NewSegmentOrg;
+ }
res = VirtualProtect(g_pPinCVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
res = VirtualProtect(g_pMemInputPinCVtbl, sizeof(IMemInputPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (g_pMemInputPinCVtbl->Receive == ReceiveMine)
+ if (g_pMemInputPinCVtbl->Receive == ReceiveMine) {
g_pMemInputPinCVtbl->Receive = ReceiveOrg;
+ }
res = VirtualProtect(g_pMemInputPinCVtbl, sizeof(IMemInputPinCVtbl), flOldProtect, &flOldProtect);
g_pPinCVtbl = NULL;
@@ -224,8 +223,9 @@ void UnhookNewSegmentAndReceive()
bool HookNewSegmentAndReceive(IPinC* pPinC, IMemInputPinC* pMemInputPinC)
{
- if(!pPinC || !pMemInputPinC || (GetVersion()&0x80000000))
+ if(!pPinC || !pMemInputPinC || (GetVersion()&0x80000000)) {
return false;
+ }
g_tSegmentStart = 0;
g_tSampleStart = 0;
@@ -237,13 +237,17 @@ bool HookNewSegmentAndReceive(IPinC* pPinC, IMemInputPinC* pMemInputPinC)
// Casimir666 : change sizeof(IPinC) to sizeof(IPinCVtbl) to fix crash with EVR hack on Vista!
res = VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if(NewSegmentOrg == NULL) NewSegmentOrg = pPinC->lpVtbl->NewSegment;
+ if(NewSegmentOrg == NULL) {
+ NewSegmentOrg = pPinC->lpVtbl->NewSegment;
+ }
pPinC->lpVtbl->NewSegment = NewSegmentMine;
res = VirtualProtect(pPinC->lpVtbl, sizeof(IPinCVtbl), flOldProtect, &flOldProtect);
// Casimir666 : change sizeof(IMemInputPinC) to sizeof(IMemInputPinCVtbl) to fix crash with EVR hack on Vista!
res = VirtualProtect(pMemInputPinC->lpVtbl, sizeof(IMemInputPinCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if(ReceiveOrg == NULL) ReceiveOrg = pMemInputPinC->lpVtbl->Receive;
+ if(ReceiveOrg == NULL) {
+ ReceiveOrg = pMemInputPinC->lpVtbl->Receive;
+ }
pMemInputPinC->lpVtbl->Receive = ReceiveMine;
res = VirtualProtect(pMemInputPinC->lpVtbl, sizeof(IMemInputPinCVtbl), flOldProtect, &flOldProtect);
@@ -278,12 +282,10 @@ static void LOG_TOFILE(LPCTSTR FileName, LPCTSTR fmt, ...)
va_list args;
va_start(args, fmt);
int nCount = _vsctprintf(fmt, args) + 1;
- if(TCHAR* buff = DNew TCHAR[nCount])
- {
+ if(TCHAR* buff = DNew TCHAR[nCount]) {
FILE* f;
_vstprintf_s(buff, nCount, fmt, args);
- if(_tfopen_s(&f, FileName, _T("at")) == 0)
- {
+ if(_tfopen_s(&f, FileName, _T("at")) == 0) {
fseek(f, 0, 2);
_ftprintf(f, _T("%s\n"), buff);
fclose(f);
@@ -298,12 +300,11 @@ static void LOG(LPCTSTR fmt, ...)
{
va_list args;
va_start(args, fmt);
-// int nCount = _vsctprintf(fmt, args) + 1;
+ // int nCount = _vsctprintf(fmt, args) + 1;
TCHAR buff[3000];
FILE* f;
_vstprintf_s(buff, countof(buff), fmt, args);
- if(_tfopen_s(&f, LOG_FILE, _T("at")) == 0)
- {
+ if(_tfopen_s(&f, LOG_FILE, _T("at")) == 0) {
fseek(f, 0, 2);
_ftprintf(f, _T("%s\n"), buff);
fclose(f);
@@ -313,8 +314,7 @@ static void LOG(LPCTSTR fmt, ...)
}
static void LOGPF(LPCTSTR prefix, const DDPIXELFORMAT* p, int n)
{
- for(int i = 0; i < n; i++)
- {
+ for(int i = 0; i < n; i++) {
LOG(_T("%s[%d].dwSize = %d"), prefix, i, p[i].dwSize);
LOG(_T("%s[%d].dwFlags = %08x"), prefix, i, p[i].dwFlags);
LOG(_T("%s[%d].dwFourCC = %4.4hs"), prefix, i, &p[i].dwFourCC);
@@ -328,8 +328,7 @@ static void LOGPF(LPCTSTR prefix, const DDPIXELFORMAT* p, int n)
static void LOGUDI(LPCTSTR prefix, const AMVAUncompDataInfo* p, int n)
{
- for(int i = 0; i < n; i++)
- {
+ for(int i = 0; i < n; i++) {
LOG(_T("%s[%d].dwUncompWidth = %d"), prefix, i, p[i].dwUncompWidth);
LOG(_T("%s[%d].dwUncompHeight = %d"), prefix, i, p[i].dwUncompHeight);
@@ -346,8 +345,7 @@ static void LogDXVA_PicParams_H264 (DXVA_PicParams_H264* pPic)
int i;
static bool bFirstParam = true;
- if (bFirstParam)
- {
+ if (bFirstParam) {
LOG_TOFILE (_T("picture.log"), _T("RefPicFlag,wFrameWidthInMbsMinus1,wFrameHeightInMbsMinus1,CurrPic.Index7Bits,num_ref_frames,wBitFields,bit_depth_luma_minus8,bit_depth_chroma_minus8,Reserved16Bits,StatusReportFeedbackNumber,RFL.Index7Bits[0],") \
_T("RFL.Index7Bits[1],RFL.Index7Bits[2],RFL.Index7Bits[3],RFL.Index7Bits[4],RFL.Index7Bits[5],") \
_T("RFL.Index7Bits[6],RFL.Index7Bits[7],RFL.Index7Bits[8],RFL.Index7Bits[9],RFL.Index7Bits[10],") \
@@ -367,8 +365,8 @@ static void LogDXVA_PicParams_H264 (DXVA_PicParams_H264* pPic)
strRes.AppendFormat(_T("%d,"), pPic->wFrameHeightInMbsMinus1);
// DXVA_PicEntry_H264 CurrPic)); /* flag is bot field flag */
-// strRes.AppendFormat(_T("%d,"), pPic->CurrPic.AssociatedFlag);
-// strRes.AppendFormat(_T("%d,"), pPic->CurrPic.bPicEntry);
+ // strRes.AppendFormat(_T("%d,"), pPic->CurrPic.AssociatedFlag);
+ // strRes.AppendFormat(_T("%d,"), pPic->CurrPic.bPicEntry);
strRes.AppendFormat(_T("%d,"), pPic->CurrPic.Index7Bits);
@@ -380,18 +378,18 @@ static void LogDXVA_PicParams_H264 (DXVA_PicParams_H264* pPic)
strRes.AppendFormat(_T("%d,"), pPic->Reserved16Bits);
strRes.AppendFormat(_T("%d,"), pPic->StatusReportFeedbackNumber);
- for (i =0; i<16; i++)
- {
-// strRes.AppendFormat(_T("%d,"), pPic->RefFrameList[i].AssociatedFlag);
-// strRes.AppendFormat(_T("%d,"), pPic->RefFrameList[i].bPicEntry);
+ for (i =0; i<16; i++) {
+ // strRes.AppendFormat(_T("%d,"), pPic->RefFrameList[i].AssociatedFlag);
+ // strRes.AppendFormat(_T("%d,"), pPic->RefFrameList[i].bPicEntry);
strRes.AppendFormat(_T("%d,"), pPic->RefFrameList[i].Index7Bits);
}
strRes.AppendFormat(_T("%d, %d,"), pPic->CurrFieldOrderCnt[0], pPic->CurrFieldOrderCnt[1]);
- for (int i=0; i<16; i++)
+ for (int i=0; i<16; i++) {
strRes.AppendFormat(_T("%d, %d,"), pPic->FieldOrderCntList[i][0], pPic->FieldOrderCntList[i][1]);
-// strRes.AppendFormat(_T("%d,"), pPic->FieldOrderCntList[16][2]);
+ }
+ // strRes.AppendFormat(_T("%d,"), pPic->FieldOrderCntList[16][2]);
strRes.AppendFormat(_T("%d,"), pPic->pic_init_qs_minus26);
strRes.AppendFormat(_T("%d,"), pPic->chroma_qp_index_offset); /* also used for QScb */
@@ -404,10 +402,11 @@ static void LogDXVA_PicParams_H264 (DXVA_PicParams_H264* pPic)
strRes.AppendFormat(_T("%d,"), pPic->num_ref_idx_l1_active_minus1);
strRes.AppendFormat(_T("%d,"), pPic->Reserved8BitsA);
- for (int i=0; i<16; i++)
+ for (int i=0; i<16; i++) {
strRes.AppendFormat(_T("%d,"), pPic->FrameNumList[i]);
+ }
-// strRes.AppendFormat(_T("%d,"), pPic->FrameNumList[16]);
+ // strRes.AppendFormat(_T("%d,"), pPic->FrameNumList[16]);
strRes.AppendFormat(_T("%d,"), pPic->UsedForReferenceFlags);
strRes.AppendFormat(_T("%d,"), pPic->NonExistingFrameFlags);
strRes.AppendFormat(_T("%d,"), pPic->frame_num);
@@ -431,16 +430,16 @@ static void LogDXVA_PicParams_H264 (DXVA_PicParams_H264* pPic)
//for (int i=0; i<810; i++)
// strRes.AppendFormat(_T("%d,"), pPic->SliceGroupMap[i]);
-// strRes.AppendFormat(_T("%d,"), pPic->SliceGroupMap[810]);
+ // strRes.AppendFormat(_T("%d,"), pPic->SliceGroupMap[810]);
// SABOTAGE !!!
-//for (int i=0; i<16; i++)
-//{
-// pPic->FieldOrderCntList[i][0] = pPic->FieldOrderCntList[i][1] = 0;
-// pPic->RefFrameList[i].AssociatedFlag = 1;
-// pPic->RefFrameList[i].bPicEntry = 255;
-// pPic->RefFrameList[i].Index7Bits = 127;
-//}
+ //for (int i=0; i<16; i++)
+ //{
+ // pPic->FieldOrderCntList[i][0] = pPic->FieldOrderCntList[i][1] = 0;
+ // pPic->RefFrameList[i].AssociatedFlag = 1;
+ // pPic->RefFrameList[i].bPicEntry = 255;
+ // pPic->RefFrameList[i].Index7Bits = 127;
+ //}
// === Dump PicParams!
//static FILE* hPict = NULL;
@@ -458,16 +457,14 @@ static void LogH264SliceShort (DXVA_Slice_H264_Short* pSlice, int nCount)
CString strRes;
static bool bFirstSlice = true;
- if (bFirstSlice)
- {
+ if (bFirstSlice) {
strRes = _T("nCnt, BSNALunitDataLocation, SliceBytesInBuffer, wBadSliceChopping");
LOG_TOFILE (_T("sliceshort.log"), strRes);
strRes = "";
bFirstSlice = false;
}
- for (int i=0; i<nCount; i++)
- {
+ for (int i=0; i<nCount; i++) {
strRes.AppendFormat(_T("%d,"), i);
strRes.AppendFormat(_T("%d,"), pSlice[i].BSNALunitDataLocation);
strRes.AppendFormat(_T("%d,"), pSlice[i].SliceBytesInBuffer);
@@ -483,8 +480,7 @@ static void LogSliceInfo (DXVA_SliceInfo* pSlice, int nCount)
CString strRes;
static bool bFirstSlice = true;
- if (bFirstSlice)
- {
+ if (bFirstSlice) {
strRes = _T("nCnt, wHorizontalPosition, wVerticalPosition, dwSliceBitsInBuffer,dwSliceDataLocation, bStartCodeBitOffset, bReservedBits, wMBbitOffset, wNumberMBsInSlice, wQuantizerScaleCode, wBadSliceChopping");
LOG_TOFILE (_T("sliceshort.log"), strRes);
@@ -492,8 +488,7 @@ static void LogSliceInfo (DXVA_SliceInfo* pSlice, int nCount)
bFirstSlice = false;
}
- for (int i=0; i<nCount; i++)
- {
+ for (int i=0; i<nCount; i++) {
strRes.AppendFormat(_T("%d,"), i);
strRes.AppendFormat(_T("%d,"), pSlice[i].wHorizontalPosition);
strRes.AppendFormat(_T("%d,"), pSlice[i].wVerticalPosition);
@@ -516,32 +511,25 @@ static void LogH264SliceLong (DXVA_Slice_H264_Long* pSlice, int nCount)
static bool bFirstSlice = true;
CString strRes;
- if (bFirstSlice)
- {
+ if (bFirstSlice) {
strRes = _T("nCnt, BSNALunitDataLocation, SliceBytesInBuffer, wBadSliceChopping,") \
_T("first_mb_in_slice, NumMbsForSlice, BitOffsetToSliceData, slice_type,luma_log2_weight_denom,chroma_log2_weight_denom,") \
_T("num_ref_idx_l0_active_minus1,num_ref_idx_l1_active_minus1,slice_alpha_c0_offset_div2,slice_beta_offset_div2,") \
_T("Reserved8Bits,slice_qs_delta,slice_qp_delta,redundant_pic_cnt,direct_spatial_mv_pred_flag,cabac_init_idc,") \
_T("disable_deblocking_filter_idc,slice_id,");
- for (int i=0; i<2; i++) /* L0 & L1 */
- {
- for (int j=0; j<32; j++)
- {
+ for (int i=0; i<2; i++) { /* L0 & L1 */
+ for (int j=0; j<32; j++) {
strRes.AppendFormat(_T("R[%d][%d].AssociatedFlag,"), i, j);
strRes.AppendFormat(_T("R[%d][%d].bPicEntry,"), i, j);
strRes.AppendFormat(_T("R[%d][%d].Index7Bits,"), i, j);
}
}
- for (int a=0; a<2; a++) /* L0 & L1; Y, Cb, Cr */
- {
- for (int b=0; b<32; b++)
- {
- for (int c=0; c<3; c++)
- {
- for (int d=0; d<2; d++)
- {
+ for (int a=0; a<2; a++) { /* L0 & L1; Y, Cb, Cr */
+ for (int b=0; b<32; b++) {
+ for (int c=0; c<3; c++) {
+ for (int d=0; d<2; d++) {
strRes.AppendFormat(_T("W[%d][%d][%d][%d],"), a,b,c,d);
}
}
@@ -554,8 +542,7 @@ static void LogH264SliceLong (DXVA_Slice_H264_Long* pSlice, int nCount)
}
bFirstSlice = false;
- for (int i=0; i<nCount; i++)
- {
+ for (int i=0; i<nCount; i++) {
strRes.AppendFormat(_T("%d,"), i);
strRes.AppendFormat(_T("%d,"), pSlice[i].BSNALunitDataLocation);
strRes.AppendFormat(_T("%d,"), pSlice[i].SliceBytesInBuffer);
@@ -584,24 +571,18 @@ static void LogH264SliceLong (DXVA_Slice_H264_Long* pSlice, int nCount)
strRes.AppendFormat(_T("%d,"), pSlice[i].disable_deblocking_filter_idc);
strRes.AppendFormat(_T("%d,"), pSlice[i].slice_id);
- for (int a=0; a<2; a++) /* L0 & L1 */
- {
- for (int b=0; b<32; b++)
- {
+ for (int a=0; a<2; a++) { /* L0 & L1 */
+ for (int b=0; b<32; b++) {
strRes.AppendFormat(_T("%d,"), pSlice[i].RefPicList[a][b].AssociatedFlag);
strRes.AppendFormat(_T("%d,"), pSlice[i].RefPicList[a][b].bPicEntry);
strRes.AppendFormat(_T("%d,"), pSlice[i].RefPicList[a][b].Index7Bits);
}
}
- for (int a=0; a<2; a++) /* L0 & L1; Y, Cb, Cr */
- {
- for (int b=0; b<32; b++)
- {
- for (int c=0; c<3; c++)
- {
- for (int d=0; d<2; d++)
- {
+ for (int a=0; a<2; a++) { /* L0 & L1; Y, Cb, Cr */
+ for (int b=0; b<32; b++) {
+ for (int c=0; c<3; c++) {
+ for (int d=0; d<2; d++) {
strRes.AppendFormat(_T("%d,"), pSlice[i].Weights[a][b][c][d]);
}
}
@@ -618,8 +599,9 @@ static void LogDXVA_PictureParameters (DXVA_PictureParameters* pPic)
static bool bFirstPictureParam = true;
CString strRes;
- if (bFirstPictureParam)
+ if (bFirstPictureParam) {
LOG_TOFILE (_T("picture.log"), _T("wDecodedPictureIndex,wDeblockedPictureIndex,wForwardRefPictureIndex,wBackwardRefPictureIndex,wPicWidthInMBminus1,wPicHeightInMBminus1,bMacroblockWidthMinus1,bMacroblockHeightMinus1,bBlockWidthMinus1,bBlockHeightMinus1,bBPPminus1,bPicStructure,bSecondField,bPicIntra,bPicBackwardPrediction,bBidirectionalAveragingMode,bMVprecisionAndChromaRelation,bChromaFormat,bPicScanFixed,bPicScanMethod,bPicReadbackRequests,bRcontrol,bPicSpatialResid8,bPicOverflowBlocks,bPicExtrapolation,bPicDeblocked,bPicDeblockConfined,bPic4MVallowed,bPicOBMC,bPicBinPB,bMV_RPS,bReservedBits,wBitstreamFcodes,wBitstreamPCEelements,bBitstreamConcealmentNeed,bBitstreamConcealmentMethod"));
+ }
bFirstPictureParam = false;
strRes.Format (_T("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"),
@@ -668,27 +650,28 @@ void LogDXVA_Bitstream(BYTE* pBuffer, int nSize)
CString strRes;
static bool bFirstBitstream = true;
- if (bFirstBitstream)
+ if (bFirstBitstream) {
LOG_TOFILE (_T("bitstream.log"), _T("Size,Start, Stop"));
+ }
bFirstBitstream = false;
strRes.Format (_T("%d, -"), nSize);
- for (int i=0; i<20; i++)
- {
- if (i < nSize)
+ for (int i=0; i<20; i++) {
+ if (i < nSize) {
strRes.AppendFormat (_T(" %02x"), pBuffer[i]);
- else
+ } else {
strRes.Append(_T(" --"));
+ }
}
strRes.Append (_T(", -"), nSize);
- for (int i=0; i<20; i++)
- {
- if (nSize-i >= 0)
+ for (int i=0; i<20; i++) {
+ if (nSize-i >= 0) {
strRes.AppendFormat (_T(" %02x"), pBuffer[i]);
- else
+ } else {
strRes.Append(_T(" --"));
+ }
}
LOG_TOFILE (_T("bitstream.log"), strRes);
@@ -710,8 +693,7 @@ static HRESULT STDMETHODCALLTYPE GetVideoAcceleratorGUIDsMine(IAMVideoAccelerato
{
LOG(_T("\nGetVideoAcceleratorGUIDs"));
- if(pdwNumGuidsSupported)
- {
+ if(pdwNumGuidsSupported) {
LOG(_T("[in] *pdwNumGuidsSupported = %d"), *pdwNumGuidsSupported);
}
@@ -719,14 +701,11 @@ static HRESULT STDMETHODCALLTYPE GetVideoAcceleratorGUIDsMine(IAMVideoAccelerato
LOG(_T("hr = %08x"), hr);
- if(pdwNumGuidsSupported)
- {
+ if(pdwNumGuidsSupported) {
LOG(_T("[out] *pdwNumGuidsSupported = %d"), *pdwNumGuidsSupported);
- if(pGuidsSupported)
- {
- for(DWORD i = 0; i < *pdwNumGuidsSupported; i++)
- {
+ if(pGuidsSupported) {
+ for(DWORD i = 0; i < *pdwNumGuidsSupported; i++) {
LOG(_T("[out] pGuidsSupported[%d] = %s"), i, CStringFromGUID(pGuidsSupported[i]));
}
}
@@ -739,13 +718,11 @@ static HRESULT STDMETHODCALLTYPE GetUncompFormatsSupportedMine(IAMVideoAccelerat
{
LOG(_T("\nGetUncompFormatsSupported"));
- if(pGuid)
- {
+ if(pGuid) {
LOG(_T("[in] *pGuid = %s"), CStringFromGUID(*pGuid));
}
- if(pdwNumFormatsSupported)
- {
+ if(pdwNumFormatsSupported) {
LOG(_T("[in] *pdwNumFormatsSupported = %d"), *pdwNumFormatsSupported);
}
@@ -753,12 +730,10 @@ static HRESULT STDMETHODCALLTYPE GetUncompFormatsSupportedMine(IAMVideoAccelerat
LOG(_T("hr = %08x"), hr);
- if(pdwNumFormatsSupported)
- {
+ if(pdwNumFormatsSupported) {
LOG(_T("[out] *pdwNumFormatsSupported = %d"), *pdwNumFormatsSupported);
- if(pFormatsSupported)
- {
+ if(pFormatsSupported) {
LOGPF(_T("[out] pFormatsSupported"), pFormatsSupported, *pdwNumFormatsSupported);
}
}
@@ -781,14 +756,12 @@ static HRESULT STDMETHODCALLTYPE GetCompBufferInfoMine(IAMVideoAcceleratorC * Th
{
LOG(_T("\nGetCompBufferInfo"));
- if(pGuid)
- {
+ if(pGuid) {
g_guidDXVADecoder = *pGuid;
g_nDXVAVersion = 1;
LOG(_T("[in] *pGuid = %s"), CStringFromGUID(*pGuid));
- if(pdwNumTypesCompBuffers)
- {
+ if(pdwNumTypesCompBuffers) {
LOG(_T("[in] *pdwNumTypesCompBuffers = %d"), *pdwNumTypesCompBuffers);
}
}
@@ -825,16 +798,14 @@ static HRESULT STDMETHODCALLTYPE BeginFrameMine(IAMVideoAcceleratorC * This, con
{
LOG(_T("\nBeginFrame"));
- if(amvaBeginFrameInfo)
- {
+ if(amvaBeginFrameInfo) {
LOG(_T("[in] amvaBeginFrameInfo->dwDestSurfaceIndex = %08x"), amvaBeginFrameInfo->dwDestSurfaceIndex);
LOG(_T("[in] amvaBeginFrameInfo->pInputData = %08x"), amvaBeginFrameInfo->pInputData);
LOG(_T("[in] amvaBeginFrameInfo->dwSizeInputData = %08x"), amvaBeginFrameInfo->dwSizeInputData);
LOG(_T("[in] amvaBeginFrameInfo->pOutputData = %08x"), amvaBeginFrameInfo->pOutputData);
LOG(_T("[in] amvaBeginFrameInfo->dwSizeOutputData = %08x"), amvaBeginFrameInfo->dwSizeOutputData);
}
- if(amvaBeginFrameInfo && (amvaBeginFrameInfo->dwSizeInputData == 4))
- {
+ if(amvaBeginFrameInfo && (amvaBeginFrameInfo->dwSizeInputData == 4)) {
LOG(_T("[in] amvaBeginFrameInfo->pInputData => dwDestSurfaceIndex = %ld "),
((DWORD*)amvaBeginFrameInfo->pInputData)[0]);
}
@@ -851,8 +822,7 @@ static HRESULT STDMETHODCALLTYPE EndFrameMine(IAMVideoAcceleratorC * This, const
{
LOG(_T("\nEndFrame"));
- if(pEndFrameInfo)
- {
+ if(pEndFrameInfo) {
LOG(_T("[in] pEndFrameInfo->dwSizeMiscData = %08x"), pEndFrameInfo->dwSizeMiscData);
LOG(_T("[in] pEndFrameInfo->pMiscData = %08x"), pEndFrameInfo->pMiscData);
@@ -912,14 +882,11 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
#ifdef _DEBUG
LOG(_T("\nExecute"));
LOG(_T("[in] dwFunction = %08x"), dwFunction);
- if(lpPrivateInputData)
- {
- if (dwFunction == 0x01000000)
- {
+ if(lpPrivateInputData) {
+ if (dwFunction == 0x01000000) {
DXVA_BufferDescription* pBuffDesc = (DXVA_BufferDescription*)lpPrivateInputData;
- for (DWORD i=0; i<dwNumBuffers; i++)
- {
+ for (DWORD i=0; i<dwNumBuffers; i++) {
LOG(_T("[in] lpPrivateInputData, buffer description %d"), i);
LOG(_T(" pBuffDesc->dwTypeIndex = %d"), pBuffDesc[i].dwTypeIndex);
LOG(_T(" pBuffDesc->dwBufferIndex = %d"), pBuffDesc[i].dwBufferIndex);
@@ -932,9 +899,7 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
LOG(_T(" pBuffDesc->dwNumMBsInBuffer = %d"), pBuffDesc[i].dwNumMBsInBuffer);
LOG(_T(" pBuffDesc->dwReservedBits = %d"), pBuffDesc[i].dwReservedBits);
}
- }
- else if ((dwFunction == 0xfffff101) || (dwFunction == 0xfffff501))
- {
+ } else if ((dwFunction == 0xfffff101) || (dwFunction == 0xfffff501)) {
DXVA_ConfigPictureDecode* ConfigRequested = (DXVA_ConfigPictureDecode*)lpPrivateInputData;
LOG(_T("[in] lpPrivateInputData, config requested"));
LOG(_T(" pBuffDesc->dwTypeIndex = %d"), ConfigRequested->bConfig4GroupedCoefs);
@@ -953,8 +918,7 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
LOG(_T(" ConfigRequested->guidConfigBitstreamEncryption = %s"), CStringFromGUID (ConfigRequested->guidConfigBitstreamEncryption));
LOG(_T(" ConfigRequested->guidConfigMBcontrolEncryption = %s"), CStringFromGUID (ConfigRequested->guidConfigMBcontrolEncryption));
LOG(_T(" ConfigRequested->guidConfigResidDiffEncryption = %s"), CStringFromGUID (ConfigRequested->guidConfigResidDiffEncryption));
- }
- else
+ } else
LOG(_T("[in] lpPrivateInputData = %02x %02x %02x %02x ..."),
((BYTE*)lpPrivateInputData)[0],
((BYTE*)lpPrivateInputData)[1],
@@ -965,10 +929,8 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
LOG(_T("[in] lpPrivateOutputData = %08x"), lpPrivateOutputData);
LOG(_T("[in] cbPrivateOutputData = %08x"), cbPrivateOutputData);
LOG(_T("[in] dwNumBuffers = %08x"), dwNumBuffers);
- if(pamvaBufferInfo)
- {
- for (DWORD i=0; i<dwNumBuffers; i++)
- {
+ if(pamvaBufferInfo) {
+ for (DWORD i=0; i<dwNumBuffers; i++) {
LOG(_T("[in] pamvaBufferInfo, buffer description %d"), i);
LOG(_T("[in] pamvaBufferInfo->dwTypeIndex = %08x"), pamvaBufferInfo[i].dwTypeIndex);
LOG(_T("[in] pamvaBufferInfo->dwBufferIndex = %08x"), pamvaBufferInfo[i].dwBufferIndex);
@@ -978,27 +940,21 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
}
- for (DWORD i=0; i<dwNumBuffers; i++)
- {
- if (pamvaBufferInfo[i].dwTypeIndex == DXVA_PICTURE_DECODE_BUFFER)
- {
- if (g_guidDXVADecoder == DXVA2_ModeH264_E || g_guidDXVADecoder == DXVA_Intel_H264_ClearVideo)
+ for (DWORD i=0; i<dwNumBuffers; i++) {
+ if (pamvaBufferInfo[i].dwTypeIndex == DXVA_PICTURE_DECODE_BUFFER) {
+ if (g_guidDXVADecoder == DXVA2_ModeH264_E || g_guidDXVADecoder == DXVA_Intel_H264_ClearVideo) {
LogDXVA_PicParams_H264 ((DXVA_PicParams_H264*)g_ppBuffer[pamvaBufferInfo[i].dwTypeIndex]);
- else if (g_guidDXVADecoder == DXVA2_ModeVC1_D)
+ } else if (g_guidDXVADecoder == DXVA2_ModeVC1_D) {
LogDXVA_PictureParameters((DXVA_PictureParameters*)g_ppBuffer[pamvaBufferInfo[i].dwTypeIndex]);
- }
- else if (pamvaBufferInfo[i].dwTypeIndex == DXVA_SLICE_CONTROL_BUFFER && (pamvaBufferInfo[i].dwDataSize % sizeof(DXVA_Slice_H264_Short)) == 0)
- {
- for (WORD j=0; j<pamvaBufferInfo[i].dwDataSize / sizeof(DXVA_Slice_H264_Short); j++)
- {
+ }
+ } else if (pamvaBufferInfo[i].dwTypeIndex == DXVA_SLICE_CONTROL_BUFFER && (pamvaBufferInfo[i].dwDataSize % sizeof(DXVA_Slice_H264_Short)) == 0) {
+ for (WORD j=0; j<pamvaBufferInfo[i].dwDataSize / sizeof(DXVA_Slice_H264_Short); j++) {
DXVA_Slice_H264_Short* pSlice = &(((DXVA_Slice_H264_Short*)g_ppBuffer[pamvaBufferInfo[i].dwTypeIndex])[j]);
LOG(_T(" - BSNALunitDataLocation %d"), pSlice->BSNALunitDataLocation);
LOG(_T(" - SliceBytesInBuffer %d"), pSlice->SliceBytesInBuffer);
LOG(_T(" - wBadSliceChopping %d"), pSlice->wBadSliceChopping);
}
- }
- else if (pamvaBufferInfo[i].dwTypeIndex == DXVA_BITSTREAM_DATA_BUFFER)
- {
+ } else if (pamvaBufferInfo[i].dwTypeIndex == DXVA_BITSTREAM_DATA_BUFFER) {
LogDXVA_Bitstream(g_ppBuffer[pamvaBufferInfo[i].dwTypeIndex], pamvaBufferInfo[i].dwDataSize);
#if defined(LOG_BITSTREAM) && defined(_DEBUG)
@@ -1006,8 +962,7 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
static int nNb = 1;
sprintf (strFile, "BitStream%d.bin", nNb++);
FILE* hFile = fopen (strFile, "wb");
- if (hFile)
- {
+ if (hFile) {
fwrite (g_ppBuffer[pamvaBufferInfo[i].dwTypeIndex],
1,
pamvaBufferInfo[i].dwDataSize,
@@ -1023,8 +978,7 @@ static HRESULT STDMETHODCALLTYPE ExecuteMine(IAMVideoAcceleratorC* This, DWORD d
LOG(_T("hr = %08x"), hr);
- if(lpPrivateOutputData && (dwFunction == 0x01000000))
- {
+ if(lpPrivateOutputData && (dwFunction == 0x01000000)) {
LOG(_T("[out] *lpPrivateOutputData : Result = %08x"), ((DWORD*)lpPrivateOutputData)[0]);
}
@@ -1060,18 +1014,42 @@ void HookAMVideoAccelerator(IAMVideoAcceleratorC* pAMVideoAcceleratorC)
g_guidDXVADecoder = GUID_NULL;
g_nDXVAVersion = 0;
- if(GetVideoAcceleratorGUIDsOrg == NULL) GetVideoAcceleratorGUIDsOrg = pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs;
- if(GetUncompFormatsSupportedOrg == NULL) GetUncompFormatsSupportedOrg = pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported;
- if(GetInternalMemInfoOrg == NULL) GetInternalMemInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalMemInfo;
- if(GetCompBufferInfoOrg == NULL) GetCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetCompBufferInfo;
- if(GetInternalCompBufferInfoOrg == NULL) GetInternalCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalCompBufferInfo;
- if(BeginFrameOrg == NULL) BeginFrameOrg = pAMVideoAcceleratorC->lpVtbl->BeginFrame;
- if(EndFrameOrg == NULL) EndFrameOrg = pAMVideoAcceleratorC->lpVtbl->EndFrame;
- if(GetBufferOrg == NULL) GetBufferOrg = pAMVideoAcceleratorC->lpVtbl->GetBuffer;
- if(ReleaseBufferOrg == NULL) ReleaseBufferOrg = pAMVideoAcceleratorC->lpVtbl->ReleaseBuffer;
- if(ExecuteOrg == NULL) ExecuteOrg = pAMVideoAcceleratorC->lpVtbl->Execute;
- if(QueryRenderStatusOrg == NULL) QueryRenderStatusOrg = pAMVideoAcceleratorC->lpVtbl->QueryRenderStatus;
- if(DisplayFrameOrg == NULL) DisplayFrameOrg = pAMVideoAcceleratorC->lpVtbl->DisplayFrame;
+ if(GetVideoAcceleratorGUIDsOrg == NULL) {
+ GetVideoAcceleratorGUIDsOrg = pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs;
+ }
+ if(GetUncompFormatsSupportedOrg == NULL) {
+ GetUncompFormatsSupportedOrg = pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported;
+ }
+ if(GetInternalMemInfoOrg == NULL) {
+ GetInternalMemInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalMemInfo;
+ }
+ if(GetCompBufferInfoOrg == NULL) {
+ GetCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetCompBufferInfo;
+ }
+ if(GetInternalCompBufferInfoOrg == NULL) {
+ GetInternalCompBufferInfoOrg = pAMVideoAcceleratorC->lpVtbl->GetInternalCompBufferInfo;
+ }
+ if(BeginFrameOrg == NULL) {
+ BeginFrameOrg = pAMVideoAcceleratorC->lpVtbl->BeginFrame;
+ }
+ if(EndFrameOrg == NULL) {
+ EndFrameOrg = pAMVideoAcceleratorC->lpVtbl->EndFrame;
+ }
+ if(GetBufferOrg == NULL) {
+ GetBufferOrg = pAMVideoAcceleratorC->lpVtbl->GetBuffer;
+ }
+ if(ReleaseBufferOrg == NULL) {
+ ReleaseBufferOrg = pAMVideoAcceleratorC->lpVtbl->ReleaseBuffer;
+ }
+ if(ExecuteOrg == NULL) {
+ ExecuteOrg = pAMVideoAcceleratorC->lpVtbl->Execute;
+ }
+ if(QueryRenderStatusOrg == NULL) {
+ QueryRenderStatusOrg = pAMVideoAcceleratorC->lpVtbl->QueryRenderStatus;
+ }
+ if(DisplayFrameOrg == NULL) {
+ DisplayFrameOrg = pAMVideoAcceleratorC->lpVtbl->DisplayFrame;
+ }
pAMVideoAcceleratorC->lpVtbl->GetVideoAcceleratorGUIDs = GetVideoAcceleratorGUIDsMine;
pAMVideoAcceleratorC->lpVtbl->GetUncompFormatsSupported = GetUncompFormatsSupportedMine;
@@ -1125,81 +1103,70 @@ private :
UINT m_ppBufferLen[MAX_BUFFER_TYPE];
public :
- CFakeDirectXVideoDecoder(LPUNKNOWN pUnk, IDirectXVideoDecoder* pDec) : CUnknown(_T("Fake DXVA2 Dec"), pUnk)
- {
+ CFakeDirectXVideoDecoder(LPUNKNOWN pUnk, IDirectXVideoDecoder* pDec) : CUnknown(_T("Fake DXVA2 Dec"), pUnk) {
m_pDec.Attach (pDec);
memset (m_ppBuffer, 0, sizeof(m_ppBuffer));
}
- ~CFakeDirectXVideoDecoder()
- {
+ ~CFakeDirectXVideoDecoder() {
LOG(_T("CFakeDirectXVideoDecoder destroyed !\n"));
}
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
- if(riid == __uuidof(IDirectXVideoDecoder))
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
+ if(riid == __uuidof(IDirectXVideoDecoder)) {
return GetInterface((IDirectXVideoDecoder*)this, ppv);
- else
+ } else {
return __super::NonDelegatingQueryInterface(riid, ppv);
+ }
}
- virtual HRESULT STDMETHODCALLTYPE GetVideoDecoderService(IDirectXVideoDecoderService **ppService)
- {
+ virtual HRESULT STDMETHODCALLTYPE GetVideoDecoderService(IDirectXVideoDecoderService **ppService) {
HRESULT hr = m_pDec->GetVideoDecoderService (ppService);
LOG(_T("IDirectXVideoDecoder::GetVideoDecoderService hr = %08x\n"), hr);
return hr;
}
- virtual HRESULT STDMETHODCALLTYPE GetCreationParameters(GUID *pDeviceGuid, DXVA2_VideoDesc *pVideoDesc, DXVA2_ConfigPictureDecode *pConfig, IDirect3DSurface9 ***pDecoderRenderTargets, UINT *pNumSurfaces)
- {
+ virtual HRESULT STDMETHODCALLTYPE GetCreationParameters(GUID *pDeviceGuid, DXVA2_VideoDesc *pVideoDesc, DXVA2_ConfigPictureDecode *pConfig, IDirect3DSurface9 ***pDecoderRenderTargets, UINT *pNumSurfaces) {
HRESULT hr = m_pDec->GetCreationParameters(pDeviceGuid, pVideoDesc, pConfig, pDecoderRenderTargets, pNumSurfaces);
LOG(_T("IDirectXVideoDecoder::GetCreationParameters hr = %08x\n"), hr);
return hr;
}
- virtual HRESULT STDMETHODCALLTYPE GetBuffer(UINT BufferType, void **ppBuffer, UINT *pBufferSize)
- {
+ virtual HRESULT STDMETHODCALLTYPE GetBuffer(UINT BufferType, void **ppBuffer, UINT *pBufferSize) {
HRESULT hr = m_pDec->GetBuffer(BufferType, ppBuffer, pBufferSize);
- if (BufferType < MAX_BUFFER_TYPE)
- {
+ if (BufferType < MAX_BUFFER_TYPE) {
m_ppBuffer[BufferType] = (BYTE*)*ppBuffer;
m_ppBufferLen[BufferType] = *pBufferSize;
}
-// LOG(_T("IDirectXVideoDecoder::GetBuffer Type = %d, hr = %08x"), BufferType, hr);
+ // LOG(_T("IDirectXVideoDecoder::GetBuffer Type = %d, hr = %08x"), BufferType, hr);
return hr;
}
- virtual HRESULT STDMETHODCALLTYPE ReleaseBuffer(UINT BufferType)
- {
+ virtual HRESULT STDMETHODCALLTYPE ReleaseBuffer(UINT BufferType) {
HRESULT hr = m_pDec->ReleaseBuffer (BufferType);
-// LOG(_T("IDirectXVideoDecoder::ReleaseBuffer Type = %d, hr = %08x"), BufferType, hr);
+ // LOG(_T("IDirectXVideoDecoder::ReleaseBuffer Type = %d, hr = %08x"), BufferType, hr);
return hr;
}
- virtual HRESULT STDMETHODCALLTYPE BeginFrame(IDirect3DSurface9 *pRenderTarget, void *pvPVPData)
- {
+ virtual HRESULT STDMETHODCALLTYPE BeginFrame(IDirect3DSurface9 *pRenderTarget, void *pvPVPData) {
HRESULT hr = m_pDec->BeginFrame (pRenderTarget, pvPVPData);
LOG(_T("IDirectXVideoDecoder::BeginFrame pRenderTarget = %08x, hr = %08x"), pRenderTarget, hr);
return hr;
}
- virtual HRESULT STDMETHODCALLTYPE EndFrame(HANDLE *pHandleComplete)
- {
+ virtual HRESULT STDMETHODCALLTYPE EndFrame(HANDLE *pHandleComplete) {
HRESULT hr = m_pDec->EndFrame (pHandleComplete);
LOG(_T("IDirectXVideoDecoder::EndFrame Handle=0x%08x hr = %08x\n"), pHandleComplete, hr);
return hr;
}
- virtual HRESULT STDMETHODCALLTYPE Execute(const DXVA2_DecodeExecuteParams *pExecuteParams)
- {
- for (DWORD i=0; i<pExecuteParams->NumCompBuffers; i++)
- {
+ virtual HRESULT STDMETHODCALLTYPE Execute(const DXVA2_DecodeExecuteParams *pExecuteParams) {
+ for (DWORD i=0; i<pExecuteParams->NumCompBuffers; i++) {
CString strBuffer;
LogDecodeBufferDesc (&pExecuteParams->pCompressedBuffers[i]);
@@ -1214,35 +1181,27 @@ public :
LOG (strBuffer);*/
- if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_PictureParametersBufferType)
- {
- if (g_guidDXVADecoder == DXVA2_ModeH264_E || g_guidDXVADecoder == DXVA_Intel_H264_ClearVideo)
+ if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_PictureParametersBufferType) {
+ if (g_guidDXVADecoder == DXVA2_ModeH264_E || g_guidDXVADecoder == DXVA_Intel_H264_ClearVideo) {
LogDXVA_PicParams_H264 ((DXVA_PicParams_H264*)m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType]);
- else if (g_guidDXVADecoder == DXVA2_ModeVC1_D || g_guidDXVADecoder == DXVA2_ModeMPEG2_VLD)
+ } else if (g_guidDXVADecoder == DXVA2_ModeVC1_D || g_guidDXVADecoder == DXVA2_ModeMPEG2_VLD) {
LogDXVA_PictureParameters((DXVA_PictureParameters*)m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType]);
+ }
}
#if defined(_DEBUG)
- if (g_guidDXVADecoder == DXVA2_ModeH264_E || g_guidDXVADecoder == DXVA_Intel_H264_ClearVideo)
- {
- if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_SliceControlBufferType)
- {
- if (pExecuteParams->pCompressedBuffers[i].DataSize % sizeof(DXVA_Slice_H264_Long) == 0)
- {
+ if (g_guidDXVADecoder == DXVA2_ModeH264_E || g_guidDXVADecoder == DXVA_Intel_H264_ClearVideo) {
+ if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_SliceControlBufferType) {
+ if (pExecuteParams->pCompressedBuffers[i].DataSize % sizeof(DXVA_Slice_H264_Long) == 0) {
DXVA_Slice_H264_Long* pSlice = (DXVA_Slice_H264_Long*)m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType];
LogH264SliceLong (pSlice, pExecuteParams->pCompressedBuffers[i].DataSize / sizeof(DXVA_Slice_H264_Long));
- }
- else if (pExecuteParams->pCompressedBuffers[i].DataSize % sizeof(DXVA_Slice_H264_Short) == 0)
- {
+ } else if (pExecuteParams->pCompressedBuffers[i].DataSize % sizeof(DXVA_Slice_H264_Short) == 0) {
DXVA_Slice_H264_Short* pSlice = (DXVA_Slice_H264_Short*)m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType];
LogH264SliceShort (pSlice, pExecuteParams->pCompressedBuffers[i].DataSize / sizeof(DXVA_Slice_H264_Short));
}
}
- }
- else if (g_guidDXVADecoder == DXVA2_ModeMPEG2_VLD)
- {
- if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_SliceControlBufferType)
- {
+ } else if (g_guidDXVADecoder == DXVA2_ModeMPEG2_VLD) {
+ if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_SliceControlBufferType) {
DXVA_SliceInfo* pSlice = (DXVA_SliceInfo*)m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType];
LogSliceInfo (pSlice, pExecuteParams->pCompressedBuffers[i].DataSize / sizeof(DXVA_SliceInfo));
}
@@ -1250,14 +1209,12 @@ public :
#endif
#if defined(LOG_MATRIX) && defined(_DEBUG)
- if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_InverseQuantizationMatrixBufferType)
- {
+ if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_InverseQuantizationMatrixBufferType) {
char strFile[_MAX_PATH];
static int nNb = 1;
sprintf (strFile, "Matrix%d.bin", nNb++);
FILE* hFile = fopen (strFile, "wb");
- if (hFile)
- {
+ if (hFile) {
fwrite (m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType],
1,
pExecuteParams->pCompressedBuffers[i].DataSize,
@@ -1268,16 +1225,14 @@ public :
#endif
#if defined(_DEBUG)
- if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_BitStreamDateBufferType)
- {
+ if (pExecuteParams->pCompressedBuffers[i].CompressedBufferType == DXVA2_BitStreamDateBufferType) {
LogDXVA_Bitstream(m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType], pExecuteParams->pCompressedBuffers[i].DataSize);
#if defined(LOG_BITSTREAM)
char strFile[_MAX_PATH];
static int nNb = 1;
sprintf (strFile, "BitStream%d.bin", nNb++);
FILE* hFile = fopen (strFile, "wb");
- if (hFile)
- {
+ if (hFile) {
fwrite (m_ppBuffer[pExecuteParams->pCompressedBuffers[i].CompressedBufferType],
1,
pExecuteParams->pCompressedBuffers[i].DataSize,
@@ -1298,16 +1253,16 @@ public :
pExecuteParams->pExtensionData->PrivateInputDataSize,
pExecuteParams->pExtensionData->PrivateOutputDataSize,
hr);
- else
+ else {
LOG(_T("IDirectXVideoDecoder::Execute %d buffer, hr = %08x"), pExecuteParams->NumCompBuffers, hr);
+ }
return hr;
}
};
interface IDirectXVideoDecoderServiceC;
-struct IDirectXVideoDecoderServiceCVtbl
-{
+struct IDirectXVideoDecoderServiceCVtbl {
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )( IDirectXVideoDecoderServiceC* pThis, /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppvObject );
ULONG ( STDMETHODCALLTYPE *AddRef )(IDirectXVideoDecoderServiceC* pThis);
@@ -1345,8 +1300,7 @@ struct IDirectXVideoDecoderServiceCVtbl
END_INTERFACE
};
-interface IDirectXVideoDecoderServiceC
-{
+interface IDirectXVideoDecoderServiceC {
CONST_VTBL struct IDirectXVideoDecoderServiceCVtbl *lpVtbl;
};
@@ -1399,11 +1353,9 @@ static void LogVideoCardCaps(IDirectXVideoDecoderService* pDecoderService)
GUID* pDecoderGuids = NULL;
hr = pDecoderService->GetDecoderDeviceGuids(&cDecoderGuids, &pDecoderGuids);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Look for the decoder GUIDs we want.
- for (UINT iGuid = 0; iGuid < cDecoderGuids; iGuid++)
- {
+ for (UINT iGuid = 0; iGuid < cDecoderGuids; iGuid++) {
LOG (_T("=== New mode : %s"), GetDXVAMode (&pDecoderGuids[iGuid]));
// Find a configuration that we support.
@@ -1415,11 +1367,9 @@ static void LogVideoCardCaps(IDirectXVideoDecoderService* pDecoderService)
hr = pDecoderService->GetDecoderRenderTargets(pDecoderGuids[iGuid], &cFormats, &pFormats);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Look for a format that matches our output format.
- for (UINT iFormat = 0; iFormat < cFormats; iFormat++)
- {
+ for (UINT iFormat = 0; iFormat < cFormats; iFormat++) {
LOG (_T("Direct 3D format : %s"), FindD3DFormat(pFormats[iFormat]));
// Fill in the video description. Set the width, height, format, and frame rate.
memset(&m_VideoDesc, 0, sizeof(m_VideoDesc));
@@ -1430,12 +1380,10 @@ static void LogVideoCardCaps(IDirectXVideoDecoderService* pDecoderService)
// Get the available configurations.
hr = pDecoderService->GetDecoderConfigurations(pDecoderGuids[iGuid], &m_VideoDesc, NULL, &cConfigurations, &pConfig);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Find a supported configuration.
- for (UINT iConfig = 0; iConfig < cConfigurations; iConfig++)
- {
+ for (UINT iConfig = 0; iConfig < cConfigurations; iConfig++) {
LogDXVA2Config (&pConfig[iConfig]);
}
@@ -1459,8 +1407,8 @@ static HRESULT STDMETHODCALLTYPE CreateVideoDecoderMine(
__in UINT NumRenderTargets,
__deref_out IDirectXVideoDecoder** ppDecode)
{
-// DebugBreak();
-// ((DXVA2_VideoDesc*)pVideoDesc)->Format = (D3DFORMAT)0x3231564E;
+ // DebugBreak();
+ // ((DXVA2_VideoDesc*)pVideoDesc)->Format = (D3DFORMAT)0x3231564E;
g_guidDXVADecoder = Guid;
g_nDXVAVersion = 2;
@@ -1473,22 +1421,21 @@ static HRESULT STDMETHODCALLTYPE CreateVideoDecoderMine(
HRESULT hr = CreateVideoDecoderOrg(pThis, Guid, pVideoDesc, pConfig, ppDecoderRenderTargets, NumRenderTargets, ppDecode);
- if (FAILED (hr))
+ if (FAILED (hr)) {
g_guidDXVADecoder = GUID_NULL;
- else
- {
+ } else {
#ifdef _DEBUG
if ((Guid == DXVA2_ModeH264_E) ||
(Guid == DXVA2_ModeVC1_D) ||
(Guid == DXVA_Intel_H264_ClearVideo) ||
- (Guid == DXVA2_ModeMPEG2_VLD))
- {
+ (Guid == DXVA2_ModeMPEG2_VLD)) {
*ppDecode = DNew CFakeDirectXVideoDecoder (NULL, *ppDecode);
(*ppDecode)->AddRef();
}
- for (DWORD i=0; i<NumRenderTargets; i++)
+ for (DWORD i=0; i<NumRenderTargets; i++) {
LOG(_T(" - Surf %d : %08x"), i, ppDecoderRenderTargets[i]);
+ }
#endif
}
@@ -1519,7 +1466,7 @@ static HRESULT STDMETHODCALLTYPE GetDecoderConfigurationsMine (IDirectXVideoDeco
HRESULT hr = GetDecoderConfigurationsOrg(pThis, Guid, pVideoDesc, pReserved, pCount, ppConfigs);
// Force LongSlice decoding !
-// memcpy (&(*ppConfigs)[1], &(*ppConfigs)[0], sizeof(DXVA2_ConfigPictureDecode));
+ // memcpy (&(*ppConfigs)[1], &(*ppConfigs)[0], sizeof(DXVA2_ConfigPictureDecode));
return hr;
}
@@ -1532,15 +1479,16 @@ void HookDirectXVideoDecoderService(void* pIDirectXVideoDecoderService)
DWORD flOldProtect = 0;
// Casimir666 : unhook previous VTables
- if (g_pIDirectXVideoDecoderServiceCVtbl)
- {
+ if (g_pIDirectXVideoDecoderServiceCVtbl) {
res = VirtualProtect(g_pIDirectXVideoDecoderServiceCVtbl, sizeof(g_pIDirectXVideoDecoderServiceCVtbl), PAGE_WRITECOPY, &flOldProtect);
- if (g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder == CreateVideoDecoderMine)
+ if (g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder == CreateVideoDecoderMine) {
g_pIDirectXVideoDecoderServiceCVtbl->CreateVideoDecoder = CreateVideoDecoderOrg;
+ }
#ifdef _DEBUG
- if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations == GetDecoderConfigurationsMine)
+ if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations == GetDecoderConfigurationsMine) {
g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderConfigurations = GetDecoderConfigurationsOrg;
+ }
//if (g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderDeviceGuids == GetDecoderDeviceGuidsMine)
// g_pIDirectXVideoDecoderServiceCVtbl->GetDecoderDeviceGuids = GetDecoderDeviceGuidsOrg;
@@ -1562,8 +1510,7 @@ void HookDirectXVideoDecoderService(void* pIDirectXVideoDecoderService)
::DeleteFile (_T("slicelong.log"));
#endif
- if (pIDirectXVideoDecoderService)
- {
+ if (pIDirectXVideoDecoderService) {
res = VirtualProtect(pIDirectXVideoDecoderServiceC->lpVtbl, sizeof(IDirectXVideoDecoderServiceCVtbl), PAGE_WRITECOPY, &flOldProtect);
CreateVideoDecoderOrg = pIDirectXVideoDecoderServiceC->lpVtbl->CreateVideoDecoder;
diff --git a/src/filters/renderer/VideoRenderers/IPinHook.h b/src/filters/renderer/VideoRenderers/IPinHook.h
index fb919f57e..406a4efcb 100644
--- a/src/filters/renderer/VideoRenderers/IPinHook.h
+++ b/src/filters/renderer/VideoRenderers/IPinHook.h
@@ -25,8 +25,7 @@
interface IPinC;
-typedef struct IPinCVtbl
-{
+typedef struct IPinCVtbl {
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )( IPinC * This, /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppvObject );
ULONG ( STDMETHODCALLTYPE *AddRef )( IPinC * This );
@@ -49,15 +48,13 @@ typedef struct IPinCVtbl
END_INTERFACE
} IPinCVtbl;
-interface IPinC
-{
+interface IPinC {
CONST_VTBL struct IPinCVtbl *lpVtbl;
};
interface IMemInputPinC;
-typedef struct IMemInputPinCVtbl
-{
+typedef struct IMemInputPinCVtbl {
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )( IPinC * This, /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppvObject );
ULONG ( STDMETHODCALLTYPE *AddRef )( IPinC * This );
@@ -71,8 +68,7 @@ typedef struct IMemInputPinCVtbl
END_INTERFACE
} IMemInputPinCVtbl;
-interface IMemInputPinC
-{
+interface IMemInputPinC {
CONST_VTBL struct IMemInputPinCVtbl *lpVtbl;
};
@@ -86,8 +82,7 @@ extern REFERENCE_TIME g_tSegmentStart, g_tSampleStart, g_rtTimePerFrame;
interface IAMVideoAcceleratorC;
-typedef struct IAMVideoAcceleratorCVtbl
-{
+typedef struct IAMVideoAcceleratorCVtbl {
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
@@ -175,8 +170,7 @@ typedef struct IAMVideoAcceleratorCVtbl
END_INTERFACE
} IAMVideoAcceleratorCVtbl;
-interface IAMVideoAcceleratorC
-{
+interface IAMVideoAcceleratorC {
CONST_VTBL struct IAMVideoAcceleratorCVtbl *lpVtbl;
};
diff --git a/src/filters/renderer/VideoRenderers/IQTVideoSurface.h b/src/filters/renderer/VideoRenderers/IQTVideoSurface.h
index aeb2b8ad8..e6a186ce8 100644
--- a/src/filters/renderer/VideoRenderers/IQTVideoSurface.h
+++ b/src/filters/renderer/VideoRenderers/IQTVideoSurface.h
@@ -29,8 +29,7 @@
interface __declspec(uuid("A6AE36F7-A6F2-4157-AF54-6599857E4E20"))
IQTVideoSurface :
-public IUnknown
-{
+public IUnknown {
STDMETHOD (BeginBlt) (const BITMAP& bm) PURE;
STDMETHOD (DoBlt) (const BITMAP& bm) PURE;
};
diff --git a/src/filters/renderer/VideoRenderers/MacrovisionKicker.cpp b/src/filters/renderer/VideoRenderers/MacrovisionKicker.cpp
index 68bf107b5..4fd82c1f4 100644
--- a/src/filters/renderer/VideoRenderers/MacrovisionKicker.cpp
+++ b/src/filters/renderer/VideoRenderers/MacrovisionKicker.cpp
@@ -45,10 +45,12 @@ void CMacrovisionKicker::SetInner(IUnknown* pUnk)
STDMETHODIMP CMacrovisionKicker::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- if(riid == __uuidof(IUnknown))
+ if(riid == __uuidof(IUnknown)) {
return __super::NonDelegatingQueryInterface(riid, ppv);
- if(riid == __uuidof(IKsPropertySet) && CComQIPtr<IKsPropertySet>(m_pInner))
+ }
+ if(riid == __uuidof(IKsPropertySet) && CComQIPtr<IKsPropertySet>(m_pInner)) {
return GetInterface((IKsPropertySet*)this, ppv);
+ }
HRESULT hr = m_pInner ? m_pInner->QueryInterface(riid, ppv) : E_NOINTERFACE;
@@ -59,11 +61,9 @@ STDMETHODIMP CMacrovisionKicker::NonDelegatingQueryInterface(REFIID riid, void**
STDMETHODIMP CMacrovisionKicker::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength)
{
- if(CComQIPtr<IKsPropertySet> pKsPS = m_pInner)
- {
+ if(CComQIPtr<IKsPropertySet> pKsPS = m_pInner) {
if(PropSet == AM_KSPROPSETID_CopyProt && Id == AM_PROPERTY_COPY_MACROVISION
- /*&& DataLength == 4 && *(DWORD*)pPropertyData*/)
- {
+ /*&& DataLength == 4 && *(DWORD*)pPropertyData*/) {
TRACE(_T("Oops, no-no-no, no macrovision please\n"));
return S_OK;
}
@@ -76,8 +76,7 @@ STDMETHODIMP CMacrovisionKicker::Set(REFGUID PropSet, ULONG Id, LPVOID pInstance
STDMETHODIMP CMacrovisionKicker::Get(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength, ULONG* pBytesReturned)
{
- if(CComQIPtr<IKsPropertySet> pKsPS = m_pInner)
- {
+ if(CComQIPtr<IKsPropertySet> pKsPS = m_pInner) {
return pKsPS->Get(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength, pBytesReturned);
}
@@ -86,8 +85,7 @@ STDMETHODIMP CMacrovisionKicker::Get(REFGUID PropSet, ULONG Id, LPVOID pInstance
STDMETHODIMP CMacrovisionKicker::QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport)
{
- if(CComQIPtr<IKsPropertySet> pKsPS = m_pInner)
- {
+ if(CComQIPtr<IKsPropertySet> pKsPS = m_pInner) {
return pKsPS->QuerySupported(PropSet, Id, pTypeSupport);
}
diff --git a/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp b/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp
index 97b02fe56..b8813b4ea 100644
--- a/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp
+++ b/src/filters/renderer/VideoRenderers/PixelShaderCompiler.cpp
@@ -35,20 +35,15 @@ CPixelShaderCompiler::CPixelShaderCompiler(IDirect3DDevice9* pD3DDev, bool fStay
HINSTANCE hDll;
hDll = GetRenderersData()->GetD3X9Dll();
- if(hDll)
- {
+ if(hDll) {
m_pD3DXCompileShader = (D3DXCompileShaderPtr)GetProcAddress(hDll, "D3DXCompileShader");
m_pD3DXDisassembleShader = (D3DXDisassembleShaderPtr)GetProcAddress(hDll, "D3DXDisassembleShader");
}
- if(!fStaySilent)
- {
- if(!hDll)
- {
+ if(!fStaySilent) {
+ if(!hDll) {
AfxMessageBox(ResStr(IDS_PIXELSHADERCOMPILER_0), MB_OK);
- }
- else if(!m_pD3DXCompileShader || !m_pD3DXDisassembleShader)
- {
+ } else if(!m_pD3DXCompileShader || !m_pD3DXDisassembleShader) {
AfxMessageBox(ResStr(IDS_PIXELSHADERCOMPILER_1), MB_OK);
}
}
@@ -67,22 +62,20 @@ HRESULT CPixelShaderCompiler::CompileShader(
CString* disasm,
CString* errmsg)
{
- if(!m_pD3DXCompileShader || !m_pD3DXDisassembleShader)
+ if(!m_pD3DXCompileShader || !m_pD3DXDisassembleShader) {
return E_FAIL;
+ }
HRESULT hr;
CComPtr<ID3DXBuffer> pShader, pDisAsm, pErrorMsgs;
hr = m_pD3DXCompileShader(pSrcData, strlen(pSrcData), NULL, NULL, pFunctionName, pProfile, Flags, &pShader, &pErrorMsgs, NULL);
- if(FAILED(hr))
- {
- if(errmsg)
- {
+ if(FAILED(hr)) {
+ if(errmsg) {
CStringA msg = "Unexpected compiler error";
- if(pErrorMsgs)
- {
+ if(pErrorMsgs) {
int len = pErrorMsgs->GetBufferSize();
memcpy(msg.GetBufferSetLength(len), pErrorMsgs->GetBufferPointer(), len);
}
@@ -93,17 +86,21 @@ HRESULT CPixelShaderCompiler::CompileShader(
return hr;
}
- if(ppPixelShader)
- {
- if(!m_pD3DDev) return E_FAIL;
+ if(ppPixelShader) {
+ if(!m_pD3DDev) {
+ return E_FAIL;
+ }
hr = m_pD3DDev->CreatePixelShader((DWORD*)pShader->GetBufferPointer(), ppPixelShader);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
}
- if(disasm)
- {
+ if(disasm) {
hr = m_pD3DXDisassembleShader((DWORD*)pShader->GetBufferPointer(), FALSE, NULL, &pDisAsm);
- if(SUCCEEDED(hr) && pDisAsm) *disasm = CStringA((const char*)pDisAsm->GetBufferPointer());
+ if(SUCCEEDED(hr) && pDisAsm) {
+ *disasm = CStringA((const char*)pDisAsm->GetBufferPointer());
+ }
}
return S_OK;
diff --git a/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp
index dc2e562d3..de1099997 100644
--- a/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.cpp
@@ -65,7 +65,9 @@ HRESULT CQT7AllocatorPresenter::AllocSurfaces()
ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
HRESULT hr = m_pDD->CreateSurface(&ddsd, &m_pVideoSurfaceOff, NULL);
- if(FAILED(hr)) return E_FAIL;
+ if(FAILED(hr)) {
+ return E_FAIL;
+ }
DDBLTFX fx;
INITDDSTRUCT(fx);
@@ -95,33 +97,34 @@ STDMETHODIMP CQT7AllocatorPresenter::BeginBlt(const BITMAP& bm)
m_NativeVideoSize = m_AspectRatio = CSize(bm.bmWidth, abs(bm.bmHeight));
HRESULT hr;
- if(FAILED(hr = AllocSurfaces()))
+ if(FAILED(hr = AllocSurfaces())) {
return hr;
+ }
return S_OK;
}
STDMETHODIMP CQT7AllocatorPresenter::DoBlt(const BITMAP& bm)
{
- if(!m_pVideoSurface || !m_pVideoSurfaceOff)
+ if(!m_pVideoSurface || !m_pVideoSurfaceOff) {
return E_FAIL;
+ }
bool fOk = false;
DDSURFACEDESC2 ddsd;
INITDDSTRUCT(ddsd);
- if(FAILED(m_pVideoSurfaceOff->GetSurfaceDesc(&ddsd)))
+ if(FAILED(m_pVideoSurfaceOff->GetSurfaceDesc(&ddsd))) {
return E_FAIL;
+ }
UINT w = (UINT)bm.bmWidth;
UINT h = abs(bm.bmHeight);
int bpp = bm.bmBitsPixel;
- if((bpp == 16 || bpp == 24 || bpp == 32) && w == ddsd.dwWidth && h == ddsd.dwHeight)
- {
+ if((bpp == 16 || bpp == 24 || bpp == 32) && w == ddsd.dwWidth && h == ddsd.dwHeight) {
INITDDSTRUCT(ddsd);
- if(SUCCEEDED(m_pVideoSurfaceOff->Lock(NULL, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->Lock(NULL, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL))) {
BitBltFromRGBToRGB(
w, h,
(BYTE*)ddsd.lpSurface, ddsd.lPitch, ddsd.ddpfPixelFormat.dwRGBBitCount,
@@ -131,16 +134,14 @@ STDMETHODIMP CQT7AllocatorPresenter::DoBlt(const BITMAP& bm)
}
}
- if(!fOk)
- {
+ if(!fOk) {
DDBLTFX fx;
INITDDSTRUCT(fx);
fx.dwFillColor = 0;
m_pVideoSurfaceOff->Blt(NULL, NULL, NULL, DDBLT_WAIT|DDBLT_COLORFILL, &fx);
HDC hDC;
- if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC))) {
CString str;
str.Format(_T("Sorry, this format is not supported"));
diff --git a/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.h
index fba500aaf..27c7bd9b9 100644
--- a/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/QT7AllocatorPresenter.h
@@ -29,25 +29,25 @@
namespace DSObjects
{
-class CQT7AllocatorPresenter
- : public CDX7AllocatorPresenter
- , public IQTVideoSurface
-{
- CComPtr<IDirectDrawSurface7> m_pVideoSurfaceOff;
-
-protected:
- HRESULT AllocSurfaces();
- void DeleteSurfaces();
-
-public:
- CQT7AllocatorPresenter(HWND hWnd, HRESULT& hr);
-
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- // IQTVideoSurface
- STDMETHODIMP BeginBlt(const BITMAP& bm);
- STDMETHODIMP DoBlt(const BITMAP& bm);
-};
+ class CQT7AllocatorPresenter
+ : public CDX7AllocatorPresenter
+ , public IQTVideoSurface
+ {
+ CComPtr<IDirectDrawSurface7> m_pVideoSurfaceOff;
+
+ protected:
+ HRESULT AllocSurfaces();
+ void DeleteSurfaces();
+
+ public:
+ CQT7AllocatorPresenter(HWND hWnd, HRESULT& hr);
+
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ // IQTVideoSurface
+ STDMETHODIMP BeginBlt(const BITMAP& bm);
+ STDMETHODIMP DoBlt(const BITMAP& bm);
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp
index b3ff0f058..ff6fe0f8f 100644
--- a/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.cpp
@@ -51,8 +51,9 @@ HRESULT CQT9AllocatorPresenter::AllocSurfaces()
if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(
m_NativeVideoSize.cx, m_NativeVideoSize.cy, D3DFMT_X8R8G8B8,
- D3DPOOL_DEFAULT, &m_pVideoSurfaceOff, NULL)))
+ D3DPOOL_DEFAULT, &m_pVideoSurfaceOff, NULL))) {
return hr;
+ }
return __super::AllocSurfaces();
}
@@ -72,21 +73,25 @@ STDMETHODIMP CQT9AllocatorPresenter::BeginBlt(const BITMAP& bm)
CAutoLock cRenderLock(&m_RenderLock);
DeleteSurfaces();
m_NativeVideoSize = m_AspectRatio = CSize(bm.bmWidth, abs(bm.bmHeight));
- if(FAILED(AllocSurfaces())) return E_FAIL;
+ if(FAILED(AllocSurfaces())) {
+ return E_FAIL;
+ }
return S_OK;
}
STDMETHODIMP CQT9AllocatorPresenter::DoBlt(const BITMAP& bm)
{
- if(!m_pVideoSurface || !m_pVideoSurfaceOff)
+ if(!m_pVideoSurface || !m_pVideoSurfaceOff) {
return E_FAIL;
+ }
bool fOk = false;
D3DSURFACE_DESC d3dsd;
ZeroMemory(&d3dsd, sizeof(d3dsd));
- if(FAILED(m_pVideoSurfaceOff->GetDesc(&d3dsd)))
+ if(FAILED(m_pVideoSurfaceOff->GetDesc(&d3dsd))) {
return E_FAIL;
+ }
UINT w = (UINT)bm.bmWidth;
UINT h = abs(bm.bmHeight);
@@ -95,11 +100,9 @@ STDMETHODIMP CQT9AllocatorPresenter::DoBlt(const BITMAP& bm)
d3dsd.Format == D3DFMT_R8G8B8 || d3dsd.Format == D3DFMT_X8R8G8B8 || d3dsd.Format == D3DFMT_A8R8G8B8 ? 32 :
d3dsd.Format == D3DFMT_R5G6B5 ? 16 : 0;
- if((bpp == 16 || bpp == 24 || bpp == 32) && w == d3dsd.Width && h == d3dsd.Height)
- {
+ if((bpp == 16 || bpp == 24 || bpp == 32) && w == d3dsd.Width && h == d3dsd.Height) {
D3DLOCKED_RECT r;
- if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, NULL, 0)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, NULL, 0))) {
BitBltFromRGBToRGB(
w, h,
(BYTE*)r.pBits, r.Pitch, dbpp,
@@ -109,13 +112,11 @@ STDMETHODIMP CQT9AllocatorPresenter::DoBlt(const BITMAP& bm)
}
}
- if(!fOk)
- {
+ if(!fOk) {
m_pD3DDev->ColorFill(m_pVideoSurfaceOff, NULL, 0);
HDC hDC;
- if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC))) {
CString str;
str.Format(_T("Sorry, this color format is not supported"));
diff --git a/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.h
index 8fca8b2bc..033a2260f 100644
--- a/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/QT9AllocatorPresenter.h
@@ -27,24 +27,24 @@
namespace DSObjects
{
-class CQT9AllocatorPresenter
- : public CDX9AllocatorPresenter
- , public IQTVideoSurface
-{
- CComPtr<IDirect3DSurface9> m_pVideoSurfaceOff;
+ class CQT9AllocatorPresenter
+ : public CDX9AllocatorPresenter
+ , public IQTVideoSurface
+ {
+ CComPtr<IDirect3DSurface9> m_pVideoSurfaceOff;
-protected:
- HRESULT AllocSurfaces();
- void DeleteSurfaces();
+ protected:
+ HRESULT AllocSurfaces();
+ void DeleteSurfaces();
-public:
- CQT9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+ public:
+ CQT9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // IQTVideoSurface
- STDMETHODIMP BeginBlt(const BITMAP& bm);
- STDMETHODIMP DoBlt(const BITMAP& bm);
-};
+ // IQTVideoSurface
+ STDMETHODIMP BeginBlt(const BITMAP& bm);
+ STDMETHODIMP DoBlt(const BITMAP& bm);
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp
index c441d5331..6833d6510 100644
--- a/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.cpp
@@ -68,7 +68,9 @@ HRESULT CRM7AllocatorPresenter::AllocSurfaces()
ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF;
HRESULT hr = m_pDD->CreateSurface(&ddsd, &m_pVideoSurfaceOff, NULL);
- if(FAILED(hr)) return E_FAIL;
+ if(FAILED(hr)) {
+ return E_FAIL;
+ }
INITDDSTRUCT(fx);
fx.dwFillColor = 0;
@@ -86,11 +88,11 @@ HRESULT CRM7AllocatorPresenter::AllocSurfaces()
hr = m_pDD->CreateSurface(&ddsd, &m_pVideoSurfaceYUY2, NULL);
- if(FAILED(m_pVideoSurfaceOff->Blt(NULL, m_pVideoSurfaceYUY2, NULL, DDBLT_WAIT, NULL)))
+ if(FAILED(m_pVideoSurfaceOff->Blt(NULL, m_pVideoSurfaceYUY2, NULL, DDBLT_WAIT, NULL))) {
m_pVideoSurfaceYUY2 = NULL;
+ }
- if(m_pVideoSurfaceYUY2)
- {
+ if(m_pVideoSurfaceYUY2) {
INITDDSTRUCT(fx);
fx.dwFillColor = 0x80108010;
m_pVideoSurfaceYUY2->Blt(NULL, NULL, NULL, DDBLT_WAIT|DDBLT_COLORFILL, &fx);
@@ -113,20 +115,21 @@ void CRM7AllocatorPresenter::DeleteSurfaces()
STDMETHODIMP CRM7AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader* pBitmapInfo, REF(PNxRect) inDestRect, REF(PNxRect) inSrcRect)
{
- if(!m_pVideoSurface || !m_pVideoSurfaceOff)
+ if(!m_pVideoSurface || !m_pVideoSurfaceOff) {
return E_FAIL;
+ }
bool fRGB = false;
bool fYUY2 = false;
CRect src((RECT*)&inSrcRect), dst((RECT*)&inDestRect), src2(CPoint(0,0), src.Size());
- if(src.Width() > dst.Width() || src.Height() > dst.Height())
+ if(src.Width() > dst.Width() || src.Height() > dst.Height()) {
return E_FAIL;
+ }
DDSURFACEDESC2 ddsd;
- if(pBitmapInfo->biCompression == '024I')
- {
+ if(pBitmapInfo->biCompression == '024I') {
DWORD pitch = pBitmapInfo->biWidth;
DWORD size = pitch*abs(pBitmapInfo->biHeight);
@@ -134,29 +137,22 @@ STDMETHODIMP CRM7AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
BYTE* u = pImageData + size + src.top*(pitch/2) + src.left/2;
BYTE* v = pImageData + size + size/4 + src.top*(pitch/2) + src.left/2;
- if(m_pVideoSurfaceYUY2)
- {
+ if(m_pVideoSurfaceYUY2) {
INITDDSTRUCT(ddsd);
- if(SUCCEEDED(m_pVideoSurfaceYUY2->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceYUY2->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL))) {
BitBltFromI420ToYUY2(src.Width(), src.Height(), (BYTE*)ddsd.lpSurface, ddsd.lPitch, y, u, v, pitch);
m_pVideoSurfaceYUY2->Unlock(src2);
fYUY2 = true;
}
- }
- else
- {
+ } else {
INITDDSTRUCT(ddsd);
- if(SUCCEEDED(m_pVideoSurfaceOff->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL))) {
BitBltFromI420ToRGB(src.Width(), src.Height(), (BYTE*)ddsd.lpSurface, ddsd.lPitch, ddsd.ddpfPixelFormat.dwRGBBitCount, y, u, v, pitch);
m_pVideoSurfaceOff->Unlock(src2);
fRGB = true;
}
}
- }
- else if(pBitmapInfo->biCompression == '2YUY')
- {
+ } else if(pBitmapInfo->biCompression == '2YUY') {
DWORD w = pBitmapInfo->biWidth;
DWORD h = abs(pBitmapInfo->biHeight);
DWORD pitch = pBitmapInfo->biWidth*2;
@@ -165,30 +161,23 @@ STDMETHODIMP CRM7AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
BYTE* yvyu = pImageData + src.top*pitch + src.left*2;
- if(m_pVideoSurfaceYUY2)
- {
+ if(m_pVideoSurfaceYUY2) {
INITDDSTRUCT(ddsd);
- if(SUCCEEDED(m_pVideoSurfaceYUY2->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceYUY2->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL))) {
BitBltFromYUY2ToYUY2(src.Width(), src.Height(), (BYTE*)ddsd.lpSurface, ddsd.lPitch, yvyu, pitch);
m_pVideoSurfaceYUY2->Unlock(src2);
fYUY2 = true;
}
- }
- else
- {
+ } else {
INITDDSTRUCT(ddsd);
- if(SUCCEEDED(m_pVideoSurfaceOff->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL))) {
BitBltFromYUY2ToRGB(src.Width(), src.Height(), (BYTE*)ddsd.lpSurface, ddsd.lPitch, ddsd.ddpfPixelFormat.dwRGBBitCount, yvyu, pitch);
m_pVideoSurfaceOff->Unlock(src2);
fRGB = true;
}
}
- }
- else if(pBitmapInfo->biCompression == 0 || pBitmapInfo->biCompression == 3
- || pBitmapInfo->biCompression == 'BGRA')
- {
+ } else if(pBitmapInfo->biCompression == 0 || pBitmapInfo->biCompression == 3
+ || pBitmapInfo->biCompression == 'BGRA') {
DWORD w = pBitmapInfo->biWidth;
DWORD h = abs(pBitmapInfo->biHeight);
DWORD pitch = pBitmapInfo->biWidth*pBitmapInfo->biBitCount>>3;
@@ -198,11 +187,9 @@ STDMETHODIMP CRM7AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
BYTE* rgb = pImageData + src.top*pitch + src.left*(pBitmapInfo->biBitCount>>3);
INITDDSTRUCT(ddsd);
- if(SUCCEEDED(m_pVideoSurfaceOff->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->Lock(src2, &ddsd, DDLOCK_WAIT|DDLOCK_SURFACEMEMORYPTR|DDLOCK_WRITEONLY, NULL))) {
BYTE* lpSurface = (BYTE*)ddsd.lpSurface;
- if(pBitmapInfo->biHeight > 0)
- {
+ if(pBitmapInfo->biHeight > 0) {
lpSurface += ddsd.lPitch*(src.Height()-1);
ddsd.lPitch = -ddsd.lPitch;
}
@@ -212,16 +199,14 @@ STDMETHODIMP CRM7AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
}
}
- if(!fRGB && !fYUY2)
- {
+ if(!fRGB && !fYUY2) {
DDBLTFX fx;
INITDDSTRUCT(fx);
fx.dwFillColor = 0;
m_pVideoSurfaceOff->Blt(NULL, NULL, NULL, DDBLT_WAIT|DDBLT_COLORFILL, &fx);
HDC hDC;
- if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC))) {
CString str;
str.Format(_T("Sorry, this format is not supported"));
@@ -238,10 +223,12 @@ STDMETHODIMP CRM7AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
HRESULT hr;
- if(fRGB)
+ if(fRGB) {
hr = m_pVideoSurface->Blt(dst, m_pVideoSurfaceOff, src2, DDBLT_WAIT, NULL);
- if(fYUY2)
+ }
+ if(fYUY2) {
hr = m_pVideoSurface->Blt(dst, m_pVideoSurfaceYUY2, src2, DDBLT_WAIT, NULL);
+ }
Paint(true);
@@ -253,7 +240,9 @@ STDMETHODIMP CRM7AllocatorPresenter::BeginOptimizedBlt(RMABitmapInfoHeader* pBit
CAutoLock cAutoLock(this);
DeleteSurfaces();
m_NativeVideoSize = m_AspectRatio = CSize(pBitmapInfo->biWidth, abs(pBitmapInfo->biHeight));
- if(FAILED(AllocSurfaces())) return E_FAIL;
+ if(FAILED(AllocSurfaces())) {
+ return E_FAIL;
+ }
return PNR_NOTIMPL;
}
diff --git a/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.h
index 6eb927351..3676e4448 100644
--- a/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/RM7AllocatorPresenter.h
@@ -32,33 +32,33 @@
namespace DSObjects
{
-class CRM7AllocatorPresenter
- : public CDX7AllocatorPresenter
- , public IRMAVideoSurface
-{
- CComPtr<IDirectDrawSurface7> m_pVideoSurfaceOff;
- CComPtr<IDirectDrawSurface7> m_pVideoSurfaceYUY2;
+ class CRM7AllocatorPresenter
+ : public CDX7AllocatorPresenter
+ , public IRMAVideoSurface
+ {
+ CComPtr<IDirectDrawSurface7> m_pVideoSurfaceOff;
+ CComPtr<IDirectDrawSurface7> m_pVideoSurfaceYUY2;
- RMABitmapInfoHeader m_bitmapInfo;
- RMABitmapInfoHeader m_lastBitmapInfo;
+ RMABitmapInfoHeader m_bitmapInfo;
+ RMABitmapInfoHeader m_lastBitmapInfo;
-protected:
- HRESULT AllocSurfaces();
- void DeleteSurfaces();
+ protected:
+ HRESULT AllocSurfaces();
+ void DeleteSurfaces();
-public:
- CRM7AllocatorPresenter(HWND hWnd, HRESULT& hr);
+ public:
+ CRM7AllocatorPresenter(HWND hWnd, HRESULT& hr);
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // IRMAVideoSurface
- STDMETHODIMP Blt(UCHAR* pImageData, RMABitmapInfoHeader* pBitmapInfo, REF(PNxRect) inDestRect, REF(PNxRect) inSrcRect);
- STDMETHODIMP BeginOptimizedBlt(RMABitmapInfoHeader* pBitmapInfo);
- STDMETHODIMP OptimizedBlt(UCHAR* pImageBits, REF(PNxRect) rDestRect, REF(PNxRect) rSrcRect);
- STDMETHODIMP EndOptimizedBlt();
- STDMETHODIMP GetOptimizedFormat(REF(RMA_COMPRESSION_TYPE) ulType);
- STDMETHODIMP GetPreferredFormat(REF(RMA_COMPRESSION_TYPE) ulType);
-};
+ // IRMAVideoSurface
+ STDMETHODIMP Blt(UCHAR* pImageData, RMABitmapInfoHeader* pBitmapInfo, REF(PNxRect) inDestRect, REF(PNxRect) inSrcRect);
+ STDMETHODIMP BeginOptimizedBlt(RMABitmapInfoHeader* pBitmapInfo);
+ STDMETHODIMP OptimizedBlt(UCHAR* pImageBits, REF(PNxRect) rDestRect, REF(PNxRect) rSrcRect);
+ STDMETHODIMP EndOptimizedBlt();
+ STDMETHODIMP GetOptimizedFormat(REF(RMA_COMPRESSION_TYPE) ulType);
+ STDMETHODIMP GetPreferredFormat(REF(RMA_COMPRESSION_TYPE) ulType);
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp
index c965a0284..eb344cdc5 100644
--- a/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.cpp
@@ -55,18 +55,19 @@ HRESULT CRM9AllocatorPresenter::AllocSurfaces()
if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(
m_NativeVideoSize.cx, m_NativeVideoSize.cy, D3DFMT_X8R8G8B8,
- D3DPOOL_DEFAULT, &m_pVideoSurfaceOff, NULL)))
+ D3DPOOL_DEFAULT, &m_pVideoSurfaceOff, NULL))) {
return hr;
+ }
m_pD3DDev->ColorFill(m_pVideoSurfaceOff, NULL, 0);
if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(
m_NativeVideoSize.cx, m_NativeVideoSize.cy, D3DFMT_YUY2,
- D3DPOOL_DEFAULT, &m_pVideoSurfaceYUY2, NULL)))
+ D3DPOOL_DEFAULT, &m_pVideoSurfaceYUY2, NULL))) {
m_pVideoSurfaceYUY2 = NULL;
+ }
- if(m_pVideoSurfaceYUY2)
- {
+ if(m_pVideoSurfaceYUY2) {
m_pD3DDev->ColorFill(m_pVideoSurfaceOff, NULL, 0x80108010);
}
@@ -86,27 +87,29 @@ void CRM9AllocatorPresenter::DeleteSurfaces()
STDMETHODIMP CRM9AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader* pBitmapInfo, REF(PNxRect) inDestRect, REF(PNxRect) inSrcRect)
{
- if(!m_pVideoSurface || !m_pVideoSurfaceOff)
+ if(!m_pVideoSurface || !m_pVideoSurfaceOff) {
return E_FAIL;
+ }
bool fRGB = false;
bool fYUY2 = false;
CRect src((RECT*)&inSrcRect), dst((RECT*)&inDestRect), src2(CPoint(0,0), src.Size());
- if(src.Width() > dst.Width() || src.Height() > dst.Height())
+ if(src.Width() > dst.Width() || src.Height() > dst.Height()) {
return E_FAIL;
+ }
D3DSURFACE_DESC d3dsd;
ZeroMemory(&d3dsd, sizeof(d3dsd));
- if(FAILED(m_pVideoSurfaceOff->GetDesc(&d3dsd)))
+ if(FAILED(m_pVideoSurfaceOff->GetDesc(&d3dsd))) {
return E_FAIL;
+ }
int dbpp =
d3dsd.Format == D3DFMT_R8G8B8 || d3dsd.Format == D3DFMT_X8R8G8B8 || d3dsd.Format == D3DFMT_A8R8G8B8 ? 32 :
d3dsd.Format == D3DFMT_R5G6B5 ? 16 : 0;
- if(pBitmapInfo->biCompression == '024I')
- {
+ if(pBitmapInfo->biCompression == '024I') {
DWORD pitch = pBitmapInfo->biWidth;
DWORD size = pitch*abs(pBitmapInfo->biHeight);
@@ -114,29 +117,22 @@ STDMETHODIMP CRM9AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
BYTE* u = pImageData + size + src.top*(pitch/2) + src.left/2;
BYTE* v = pImageData + size + size/4 + src.top*(pitch/2) + src.left/2;
- if(m_pVideoSurfaceYUY2)
- {
+ if(m_pVideoSurfaceYUY2) {
D3DLOCKED_RECT r;
- if(SUCCEEDED(m_pVideoSurfaceYUY2->LockRect(&r, src2, 0)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceYUY2->LockRect(&r, src2, 0))) {
BitBltFromI420ToYUY2(src.Width(), src.Height(), (BYTE*)r.pBits, r.Pitch, y, u, v, pitch);
m_pVideoSurfaceYUY2->UnlockRect();
fYUY2 = true;
}
- }
- else
- {
+ } else {
D3DLOCKED_RECT r;
- if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, src2, 0)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, src2, 0))) {
BitBltFromI420ToRGB(src.Width(), src.Height(), (BYTE*)r.pBits, r.Pitch, dbpp, y, u, v, pitch);
m_pVideoSurfaceOff->UnlockRect();
fRGB = true;
}
}
- }
- else if(pBitmapInfo->biCompression == '2YUY')
- {
+ } else if(pBitmapInfo->biCompression == '2YUY') {
DWORD w = pBitmapInfo->biWidth;
DWORD h = abs(pBitmapInfo->biHeight);
DWORD pitch = pBitmapInfo->biWidth*2;
@@ -145,30 +141,23 @@ STDMETHODIMP CRM9AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
BYTE* yvyu = pImageData + src.top*pitch + src.left*2;
- if(m_pVideoSurfaceYUY2)
- {
+ if(m_pVideoSurfaceYUY2) {
D3DLOCKED_RECT r;
- if(SUCCEEDED(m_pVideoSurfaceYUY2->LockRect(&r, src2, 0)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceYUY2->LockRect(&r, src2, 0))) {
BitBltFromYUY2ToYUY2(src.Width(), src.Height(), (BYTE*)r.pBits, r.Pitch, yvyu, pitch);
m_pVideoSurfaceYUY2->UnlockRect();
fYUY2 = true;
}
- }
- else
- {
+ } else {
D3DLOCKED_RECT r;
- if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, src2, 0)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, src2, 0))) {
BitBltFromYUY2ToRGB(src.Width(), src.Height(), (BYTE*)r.pBits, r.Pitch, dbpp, yvyu, pitch);
m_pVideoSurfaceOff->UnlockRect();
fRGB = true;
}
}
- }
- else if(pBitmapInfo->biCompression == 0 || pBitmapInfo->biCompression == 3
- || pBitmapInfo->biCompression == 'BGRA')
- {
+ } else if(pBitmapInfo->biCompression == 0 || pBitmapInfo->biCompression == 3
+ || pBitmapInfo->biCompression == 'BGRA') {
DWORD w = pBitmapInfo->biWidth;
DWORD h = abs(pBitmapInfo->biHeight);
DWORD pitch = pBitmapInfo->biWidth*pBitmapInfo->biBitCount>>3;
@@ -178,11 +167,9 @@ STDMETHODIMP CRM9AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
BYTE* rgb = pImageData + src.top*pitch + src.left*(pBitmapInfo->biBitCount>>3);
D3DLOCKED_RECT r;
- if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, src2, 0)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->LockRect(&r, src2, 0))) {
BYTE* pBits = (BYTE*)r.pBits;
- if(pBitmapInfo->biHeight > 0)
- {
+ if(pBitmapInfo->biHeight > 0) {
pBits += r.Pitch*(src.Height()-1);
r.Pitch = -r.Pitch;
}
@@ -192,13 +179,11 @@ STDMETHODIMP CRM9AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
}
}
- if(!fRGB && !fYUY2)
- {
+ if(!fRGB && !fYUY2) {
m_pD3DDev->ColorFill(m_pVideoSurfaceOff, NULL, 0);
HDC hDC;
- if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC)))
- {
+ if(SUCCEEDED(m_pVideoSurfaceOff->GetDC(&hDC))) {
CString str;
str.Format(_T("Sorry, this format is not supported"));
@@ -214,10 +199,12 @@ STDMETHODIMP CRM9AllocatorPresenter::Blt(UCHAR* pImageData, RMABitmapInfoHeader*
HRESULT hr;
- if(fRGB)
+ if(fRGB) {
hr = m_pD3DDev->StretchRect(m_pVideoSurfaceOff, src2, m_pVideoSurface[m_nCurSurface], dst, D3DTEXF_NONE);
- if(fYUY2)
+ }
+ if(fYUY2) {
hr = m_pD3DDev->StretchRect(m_pVideoSurfaceYUY2, src2, m_pVideoSurface[m_nCurSurface], dst, D3DTEXF_NONE);
+ }
Paint(true);
@@ -230,7 +217,9 @@ STDMETHODIMP CRM9AllocatorPresenter::BeginOptimizedBlt(RMABitmapInfoHeader* pBit
CAutoLock cRenderLock(&m_RenderLock);
DeleteSurfaces();
m_NativeVideoSize = m_AspectRatio = CSize(pBitmapInfo->biWidth, abs(pBitmapInfo->biHeight));
- if(FAILED(AllocSurfaces())) return E_FAIL;
+ if(FAILED(AllocSurfaces())) {
+ return E_FAIL;
+ }
return PNR_NOTIMPL;
}
diff --git a/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.h
index b42429c57..77b9ac2dc 100644
--- a/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/RM9AllocatorPresenter.h
@@ -31,32 +31,32 @@
namespace DSObjects
{
-class CRM9AllocatorPresenter
- : public CDX9AllocatorPresenter
- , public IRMAVideoSurface
-{
- CComPtr<IDirect3DSurface9> m_pVideoSurfaceOff;
- CComPtr<IDirect3DSurface9> m_pVideoSurfaceYUY2;
-
- RMABitmapInfoHeader m_bitmapInfo;
- RMABitmapInfoHeader m_lastBitmapInfo;
-
-protected:
- HRESULT AllocSurfaces();
- void DeleteSurfaces();
-
-public:
- CRM9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
-
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- // IRMAVideoSurface
- STDMETHODIMP Blt(UCHAR* pImageData, RMABitmapInfoHeader* pBitmapInfo, REF(PNxRect) inDestRect, REF(PNxRect) inSrcRect);
- STDMETHODIMP BeginOptimizedBlt(RMABitmapInfoHeader* pBitmapInfo);
- STDMETHODIMP OptimizedBlt(UCHAR* pImageBits, REF(PNxRect) rDestRect, REF(PNxRect) rSrcRect);
- STDMETHODIMP EndOptimizedBlt();
- STDMETHODIMP GetOptimizedFormat(REF(RMA_COMPRESSION_TYPE) ulType);
- STDMETHODIMP GetPreferredFormat(REF(RMA_COMPRESSION_TYPE) ulType);
-};
+ class CRM9AllocatorPresenter
+ : public CDX9AllocatorPresenter
+ , public IRMAVideoSurface
+ {
+ CComPtr<IDirect3DSurface9> m_pVideoSurfaceOff;
+ CComPtr<IDirect3DSurface9> m_pVideoSurfaceYUY2;
+
+ RMABitmapInfoHeader m_bitmapInfo;
+ RMABitmapInfoHeader m_lastBitmapInfo;
+
+ protected:
+ HRESULT AllocSurfaces();
+ void DeleteSurfaces();
+
+ public:
+ CRM9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ // IRMAVideoSurface
+ STDMETHODIMP Blt(UCHAR* pImageData, RMABitmapInfoHeader* pBitmapInfo, REF(PNxRect) inDestRect, REF(PNxRect) inSrcRect);
+ STDMETHODIMP BeginOptimizedBlt(RMABitmapInfoHeader* pBitmapInfo);
+ STDMETHODIMP OptimizedBlt(UCHAR* pImageBits, REF(PNxRect) rDestRect, REF(PNxRect) rSrcRect);
+ STDMETHODIMP EndOptimizedBlt();
+ STDMETHODIMP GetOptimizedFormat(REF(RMA_COMPRESSION_TYPE) ulType);
+ STDMETHODIMP GetPreferredFormat(REF(RMA_COMPRESSION_TYPE) ulType);
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/RenderersSettings.cpp b/src/filters/renderer/VideoRenderers/RenderersSettings.cpp
index 274a60fc1..068b6620f 100644
--- a/src/filters/renderer/VideoRenderers/RenderersSettings.cpp
+++ b/src/filters/renderer/VideoRenderers/RenderersSettings.cpp
@@ -119,13 +119,10 @@ LONGLONG CRenderersData::GetPerfCounter()
LARGE_INTEGER llPerfFrequency;
QueryPerformanceFrequency (&llPerfFrequency);
- if (llPerfFrequency.QuadPart != 0)
- {
+ if (llPerfFrequency.QuadPart != 0) {
QueryPerformanceCounter (&i64Ticks100ns);
return llMulDiv (i64Ticks100ns.QuadPart, 10000000, llPerfFrequency.QuadPart, 0);
- }
- else
- {
+ } else {
// ms to 100ns units
return timeGetTime() * 10000;
}
@@ -133,32 +130,24 @@ LONGLONG CRenderersData::GetPerfCounter()
HINSTANCE CRenderersData::GetD3X9Dll()
{
- if (m_hD3DX9Dll == NULL)
- {
+ if (m_hD3DX9Dll == NULL) {
int min_ver = D3DX_SDK_VERSION;
int max_ver = D3DX_SDK_VERSION;
m_nDXSdkRelease = 0;
- if(D3DX_SDK_VERSION >= 42)
- {
+ if(D3DX_SDK_VERSION >= 42) {
// August 2009 SDK (v42) is not compatible with older versions
min_ver = 42;
- }
- else
- {
- if(D3DX_SDK_VERSION > 33)
- {
+ } else {
+ if(D3DX_SDK_VERSION > 33) {
// versions between 34 and 41 have no known compatibility issues
min_ver = 34;
- }
- else
- {
+ } else {
// The minimum version that supports the functionality required by MPC is 24
min_ver = 24;
- if(D3DX_SDK_VERSION == 33)
- {
+ if(D3DX_SDK_VERSION == 33) {
// The April 2007 SDK (v33) should not be used (crash sometimes during shader compilation)
max_ver = 32;
}
@@ -166,12 +155,10 @@ HINSTANCE CRenderersData::GetD3X9Dll()
}
// load latest compatible version of the DLL that is available
- for (int i=max_ver; i>=min_ver; i--)
- {
+ for (int i=max_ver; i>=min_ver; i--) {
m_strD3DX9Version.Format(_T("d3dx9_%d.dll"), i);
m_hD3DX9Dll = LoadLibrary (m_strD3DX9Version);
- if (m_hD3DX9Dll)
- {
+ if (m_hD3DX9Dll) {
m_nDXSdkRelease = i;
break;
}
diff --git a/src/filters/renderer/VideoRenderers/RenderersSettings.h b/src/filters/renderer/VideoRenderers/RenderersSettings.h
index 75dde7747..e5b19f015 100644
--- a/src/filters/renderer/VideoRenderers/RenderersSettings.h
+++ b/src/filters/renderer/VideoRenderers/RenderersSettings.h
@@ -23,52 +23,45 @@
#pragma once
-enum
-{
+enum {
WM_REARRANGERENDERLESS = WM_APP+1,
WM_RESET_DEVICE,
};
#define WM_MYMOUSELAST WM_XBUTTONDBLCLK
-enum
-{
+enum {
VIDRNDT_RM_DEFAULT,
VIDRNDT_RM_DX7,
VIDRNDT_RM_DX9,
};
-enum
-{
+enum {
VIDRNDT_QT_DEFAULT,
VIDRNDT_QT_DX7,
VIDRNDT_QT_DX9,
};
-enum
-{
+enum {
VIDRNDT_AP_SURFACE,
VIDRNDT_AP_TEXTURE2D,
VIDRNDT_AP_TEXTURE3D,
};
-enum VideoSystem
-{
+enum VideoSystem {
VIDEO_SYSTEM_UNKNOWN,
VIDEO_SYSTEM_HDTV,
VIDEO_SYSTEM_SDTV_NTSC,
VIDEO_SYSTEM_SDTV_PAL,
};
-enum AmbientLight
-{
+enum AmbientLight {
AMBIENT_LIGHT_BRIGHT,
AMBIENT_LIGHT_DIM,
AMBIENT_LIGHT_DARK,
};
-enum ColorRenderingIntent
-{
+enum ColorRenderingIntent {
COLOR_RENDERING_INTENT_PERCEPTUAL,
COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
COLOR_RENDERING_INTENT_SATURATION,
@@ -84,8 +77,7 @@ public:
class CRendererSettingsShared
{
public:
- CRendererSettingsShared()
- {
+ CRendererSettingsShared() {
SetDefault();
}
bool fVMR9AlterativeVSync;
@@ -124,8 +116,7 @@ public:
bool iEVREnableFrameTimeCorrection;
int iEVROutputRange;
- CRendererSettingsEVR()
- {
+ CRendererSettingsEVR() {
SetDefault();
}
void SetDefault();
@@ -171,8 +162,7 @@ public:
LONGLONG GetPerfCounter();
HINSTANCE GetD3X9Dll();
- int GetDXSdkRelease()
- {
+ int GetDXSdkRelease() {
return m_nDXSdkRelease;
};
};
diff --git a/src/filters/renderer/VideoRenderers/SyncAllocatorPresenter.h b/src/filters/renderer/VideoRenderers/SyncAllocatorPresenter.h
index f1c52707b..62ff11e70 100644
--- a/src/filters/renderer/VideoRenderers/SyncAllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/SyncAllocatorPresenter.h
@@ -28,8 +28,7 @@ DEFINE_GUID(CLSID_SyncAllocatorPresenter, 0xf9f62627, 0xe3ef, 0x4a2e, 0xb6, 0xc9
interface __declspec(uuid("F891C2A9-1DFF-45e0-9129-30C0990C5A9F"))
ISyncClockAdviser :
-public IUnknown
-{
+public IUnknown {
STDMETHOD (AdviseSyncClock)(ISyncClock* sC) PURE;
};
diff --git a/src/filters/renderer/VideoRenderers/SyncRenderer.cpp b/src/filters/renderer/VideoRenderers/SyncRenderer.cpp
index 7d6a09d31..9a1a35eab 100644
--- a/src/filters/renderer/VideoRenderers/SyncRenderer.cpp
+++ b/src/filters/renderer/VideoRenderers/SyncRenderer.cpp
@@ -94,8 +94,7 @@ CBaseAP::CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error):
m_llEstVBlankTime(0),
m_CurrentAdapter(0)
{
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
_Error += L"ISubPicAllocatorPresenterImpl failed\n";
return;
}
@@ -106,15 +105,12 @@ CBaseAP::CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error):
m_pD3DXCreateFont = NULL;
m_pD3DXCreateSprite = NULL;
hDll = GetRenderersData()->GetD3X9Dll();
- if(hDll)
- {
+ if(hDll) {
(FARPROC &)m_pD3DXLoadSurfaceFromMemory = GetProcAddress(hDll, "D3DXLoadSurfaceFromMemory");
(FARPROC &)m_pD3DXCreateLine = GetProcAddress(hDll, "D3DXCreateLine");
(FARPROC &)m_pD3DXCreateFont = GetProcAddress(hDll, "D3DXCreateFontW");
(FARPROC &)m_pD3DXCreateSprite = GetProcAddress(hDll, "D3DXCreateSprite");
- }
- else
- {
+ } else {
_Error += L"The installed DirectX End-User Runtime is outdated. Please download and install the ";
_Error += DIRECTX_SDK_DATE;
_Error += L" release or newer in order for MPC-HC to function properly.\n";
@@ -123,8 +119,7 @@ CBaseAP::CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error):
m_pDwmIsCompositionEnabled = NULL;
m_pDwmEnableComposition = NULL;
m_hDWMAPI = LoadLibrary(L"dwmapi.dll");
- if (m_hDWMAPI)
- {
+ if (m_hDWMAPI) {
(FARPROC &)m_pDwmIsCompositionEnabled = GetProcAddress(m_hDWMAPI, "DwmIsCompositionEnabled");
(FARPROC &)m_pDwmEnableComposition = GetProcAddress(m_hDWMAPI, "DwmEnableComposition");
}
@@ -132,42 +127,39 @@ CBaseAP::CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error):
m_pDirect3DCreate9Ex = NULL;
m_hD3D9 = LoadLibrary(L"d3d9.dll");
#ifndef DISABLE_USING_D3D9EX
- if (m_hD3D9)
+ if (m_hD3D9) {
(FARPROC &)m_pDirect3DCreate9Ex = GetProcAddress(m_hD3D9, "Direct3DCreate9Ex");
+ }
#endif
- if (m_pDirect3DCreate9Ex)
- {
+ if (m_pDirect3DCreate9Ex) {
_tprintf(_T("m_pDirect3DCreate9Ex\n"));
m_pDirect3DCreate9Ex(D3D_SDK_VERSION, &m_pD3DEx);
- if(!m_pD3DEx)
- {
+ if(!m_pD3DEx) {
m_pDirect3DCreate9Ex(D3D9b_SDK_VERSION, &m_pD3DEx);
}
}
- if(!m_pD3DEx)
- {
+ if(!m_pD3DEx) {
m_pD3D.Attach(Direct3DCreate9(D3D_SDK_VERSION));
- if(!m_pD3D)
- {
+ if(!m_pD3D) {
m_pD3D.Attach(Direct3DCreate9(D3D9b_SDK_VERSION));
}
- if(m_pD3D)
+ if(m_pD3D) {
_tprintf(_T("m_pDirect3DCreate9\n"));
- }
- else
+ }
+ } else {
m_pD3D = m_pD3DEx;
+ }
ZeroMemory(&m_VMR9AlphaBitmap, sizeof(m_VMR9AlphaBitmap));
CRenderersSettings& s = GetRenderersSettings();
- if (s.m_RenderSettings.iVMRDisableDesktopComposition)
- {
+ if (s.m_RenderSettings.iVMRDisableDesktopComposition) {
m_bDesktopCompositionDisabled = true;
- if (m_pDwmEnableComposition) m_pDwmEnableComposition(0);
- }
- else
- {
+ if (m_pDwmEnableComposition) {
+ m_pDwmEnableComposition(0);
+ }
+ } else {
m_bDesktopCompositionDisabled = false;
}
@@ -179,11 +171,11 @@ CBaseAP::CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error):
CBaseAP::~CBaseAP()
{
- if (m_bDesktopCompositionDisabled)
- {
+ if (m_bDesktopCompositionDisabled) {
m_bDesktopCompositionDisabled = false;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(1);
+ }
}
m_pFont = NULL;
@@ -193,19 +185,16 @@ CBaseAP::~CBaseAP()
m_pPSC.Free();
m_pD3D = NULL;
m_pD3DEx = NULL;
- if (m_hDWMAPI)
- {
+ if (m_hDWMAPI) {
FreeLibrary(m_hDWMAPI);
m_hDWMAPI = NULL;
}
- if (m_hD3D9)
- {
+ if (m_hD3D9) {
FreeLibrary(m_hD3D9);
m_hD3D9 = NULL;
}
m_pAudioStats = NULL;
- if (m_pGenlock)
- {
+ if (m_pGenlock) {
delete m_pGenlock;
m_pGenlock = NULL;
}
@@ -216,19 +205,16 @@ void CBaseAP::AdjustQuad(MYD3DVERTEX<texcoords>* v, double dx, double dy)
{
double offset = 0.5;
- for(int i = 0; i < 4; i++)
- {
+ for(int i = 0; i < 4; i++) {
v[i].x -= offset;
v[i].y -= offset;
- for(int j = 0; j < max(texcoords-1, 1); j++)
- {
+ for(int j = 0; j < max(texcoords-1, 1); j++) {
v[i].t[j].u -= offset*dx;
v[i].t[j].v -= offset*dy;
}
- if(texcoords > 1)
- {
+ if(texcoords > 1) {
v[i].t[texcoords-1].u -= offset;
v[i].t[texcoords-1].v -= offset;
}
@@ -238,37 +224,38 @@ void CBaseAP::AdjustQuad(MYD3DVERTEX<texcoords>* v, double dx, double dy)
template<int texcoords>
HRESULT CBaseAP::TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[4], D3DTEXTUREFILTERTYPE filter = D3DTEXF_LINEAR)
{
- if(!pD3DDev) return E_POINTER;
+ if(!pD3DDev) {
+ return E_POINTER;
+ }
DWORD FVF = 0;
- switch(texcoords)
- {
- case 1:
- FVF = D3DFVF_TEX1;
- break;
- case 2:
- FVF = D3DFVF_TEX2;
- break;
- case 3:
- FVF = D3DFVF_TEX3;
- break;
- case 4:
- FVF = D3DFVF_TEX4;
- break;
- case 5:
- FVF = D3DFVF_TEX5;
- break;
- case 6:
- FVF = D3DFVF_TEX6;
- break;
- case 7:
- FVF = D3DFVF_TEX7;
- break;
- case 8:
- FVF = D3DFVF_TEX8;
- break;
- default:
- return E_FAIL;
+ switch(texcoords) {
+ case 1:
+ FVF = D3DFVF_TEX1;
+ break;
+ case 2:
+ FVF = D3DFVF_TEX2;
+ break;
+ case 3:
+ FVF = D3DFVF_TEX3;
+ break;
+ case 4:
+ FVF = D3DFVF_TEX4;
+ break;
+ case 5:
+ FVF = D3DFVF_TEX5;
+ break;
+ case 6:
+ FVF = D3DFVF_TEX6;
+ break;
+ case 7:
+ FVF = D3DFVF_TEX7;
+ break;
+ case 8:
+ FVF = D3DFVF_TEX8;
+ break;
+ default:
+ return E_FAIL;
}
HRESULT hr;
@@ -281,8 +268,7 @@ HRESULT CBaseAP::TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[
hr = pD3DDev->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
hr = pD3DDev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_RED);
- for(int i = 0; i < texcoords; i++)
- {
+ for(int i = 0; i < texcoords; i++) {
hr = pD3DDev->SetSamplerState(i, D3DSAMP_MAGFILTER, filter);
hr = pD3DDev->SetSamplerState(i, D3DSAMP_MINFILTER, filter);
hr = pD3DDev->SetSamplerState(i, D3DSAMP_MIPFILTER, filter);
@@ -298,8 +284,7 @@ HRESULT CBaseAP::TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[
v[3] = tmp;
hr = pD3DDev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, v, sizeof(v[0]));
- for(int i = 0; i < texcoords; i++)
- {
+ for(int i = 0; i < texcoords; i++) {
pD3DDev->SetTexture(i, NULL);
}
@@ -308,7 +293,9 @@ HRESULT CBaseAP::TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[
HRESULT CBaseAP::DrawRectBase(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<0> v[4])
{
- if(!pD3DDev) return E_POINTER;
+ if(!pD3DDev) {
+ return E_POINTER;
+ }
HRESULT hr = pD3DDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
hr = pD3DDev->SetRenderState(D3DRS_LIGHTING, FALSE);
@@ -371,24 +358,20 @@ bool CBaseAP::SettingsNeedResetDevice()
CRenderersSettings::CRendererSettingsEVR & Current = m_LastRendererSettings;
bool bRet = false;
- if (!m_bIsFullscreen)
- {
- if (Current.iVMRDisableDesktopComposition)
- {
- if (!m_bDesktopCompositionDisabled)
- {
+ if (!m_bIsFullscreen) {
+ if (Current.iVMRDisableDesktopComposition) {
+ if (!m_bDesktopCompositionDisabled) {
m_bDesktopCompositionDisabled = true;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(0);
+ }
}
- }
- else
- {
- if (m_bDesktopCompositionDisabled)
- {
+ } else {
+ if (m_bDesktopCompositionDisabled) {
m_bDesktopCompositionDisabled = false;
- if (m_pDwmEnableComposition)
+ if (m_pDwmEnableComposition) {
m_pDwmEnableComposition(1);
+ }
}
}
}
@@ -418,20 +401,17 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
m_pResizerPixelShader[3] = 0;
POSITION pos = m_pPixelShadersScreenSpace.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CExternalPixelShader &Shader = m_pPixelShadersScreenSpace.GetNext(pos);
Shader.m_pPixelShader = NULL;
}
pos = m_pPixelShaders.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CExternalPixelShader &Shader = m_pPixelShaders.GetNext(pos);
Shader.m_pPixelShader = NULL;
}
- if(!m_pD3D)
- {
+ if(!m_pD3D) {
_Error += L"Failed to create Direct3D device\n";
return E_UNEXPECTED;
}
@@ -439,15 +419,13 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
D3DDISPLAYMODE d3ddm;
ZeroMemory(&d3ddm, sizeof(d3ddm));
m_CurrentAdapter = GetAdapter(m_pD3D);
- if(FAILED(m_pD3D->GetAdapterDisplayMode(m_CurrentAdapter, &d3ddm)))
- {
+ if(FAILED(m_pD3D->GetAdapterDisplayMode(m_CurrentAdapter, &d3ddm))) {
_Error += L"Can not retrieve display mode data\n";
return E_UNEXPECTED;
}
if FAILED(m_pD3D->GetDeviceCaps(m_CurrentAdapter, D3DDEVTYPE_HAL, &m_caps))
- if ((m_caps.Caps & D3DCAPS_READ_SCANLINE) == 0)
- {
+ if ((m_caps.Caps & D3DCAPS_READ_SCANLINE) == 0) {
_Error += L"Video card does not have scanline access. Display synchronization is not possible.\n";
return E_UNEXPECTED;
}
@@ -458,12 +436,13 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
m_pGenlock->SetDisplayResolution(d3ddm.Width, d3ddm.Height);
BOOL bCompositionEnabled = false;
- if (m_pDwmIsCompositionEnabled) m_pDwmIsCompositionEnabled(&bCompositionEnabled);
+ if (m_pDwmIsCompositionEnabled) {
+ m_pDwmIsCompositionEnabled(&bCompositionEnabled);
+ }
m_bCompositionEnabled = bCompositionEnabled != 0;
ZeroMemory(&pp, sizeof(pp));
- if (m_bIsFullscreen) // Exclusive mode fullscreen
- {
+ if (m_bIsFullscreen) { // Exclusive mode fullscreen
pp.Windowed = FALSE;
pp.BackBufferWidth = d3ddm.Width;
pp.BackBufferHeight = d3ddm.Height;
@@ -474,22 +453,20 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
pp.Flags = D3DPRESENTFLAG_VIDEO;
m_bHighColorResolution = s.m_RenderSettings.iEVRHighColorResolution;
- if (m_bHighColorResolution)
- {
- if(FAILED(m_pD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DFMT_A2R10G10B10, false)))
- {
+ if (m_bHighColorResolution) {
+ if(FAILED(m_pD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DFMT_A2R10G10B10, false))) {
m_strStatsMsg[MSG_ERROR].Format (L"10 bit RGB is not supported by this graphics device in this resolution.");
m_bHighColorResolution = false;
}
}
- if (m_bHighColorResolution)
+ if (m_bHighColorResolution) {
pp.BackBufferFormat = D3DFMT_A2R10G10B10;
- else
+ } else {
pp.BackBufferFormat = d3ddm.Format;
+ }
- if (m_pD3DEx)
- {
+ if (m_pD3DEx) {
D3DDISPLAYMODEEX DisplayMode;
ZeroMemory(&DisplayMode, sizeof(DisplayMode));
DisplayMode.Size = sizeof(DisplayMode);
@@ -499,36 +476,28 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
pp.FullScreen_RefreshRateInHz = DisplayMode.RefreshRate;
if FAILED(hr = m_pD3DEx->CreateDeviceEx(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
- D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED|D3DCREATE_ENABLE_PRESENTSTATS,
- &pp, &DisplayMode, &m_pD3DDevEx))
- {
+ D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED|D3DCREATE_ENABLE_PRESENTSTATS,
+ &pp, &DisplayMode, &m_pD3DDevEx)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
}
- if (m_pD3DDevEx)
- {
+ if (m_pD3DDevEx) {
m_pD3DDev = m_pD3DDevEx;
m_BackbufferType = pp.BackBufferFormat;
m_DisplayType = DisplayMode.Format;
}
- }
- else
- {
- if FAILED(hr = m_pD3D->CreateDevice(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED, &pp, &m_pD3DDev))
- {
+ } else {
+ if FAILED(hr = m_pD3D->CreateDevice(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED, &pp, &m_pD3DDev)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
}
_tprintf(_T("Created full-screen device\n"));
- if (m_pD3DDev)
- {
+ if (m_pD3DDev) {
m_BackbufferType = pp.BackBufferFormat;
m_DisplayType = d3ddm.Format;
}
}
- }
- else // Windowed
- {
+ } else { // Windowed
pp.Windowed = TRUE;
pp.hDeviceWindow = m_hWnd;
pp.SwapEffect = D3DSWAPEFFECT_COPY;
@@ -539,46 +508,37 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
m_BackbufferType = d3ddm.Format;
m_DisplayType = d3ddm.Format;
m_bHighColorResolution = s.m_RenderSettings.iEVRHighColorResolution;
- if (m_bHighColorResolution)
- {
- if(FAILED(m_pD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DFMT_A2R10G10B10, false)))
- {
+ if (m_bHighColorResolution) {
+ if(FAILED(m_pD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, D3DFMT_A2R10G10B10, false))) {
m_strStatsMsg[MSG_ERROR].Format (L"10 bit RGB is not supported by this graphics device in this resolution.");
m_bHighColorResolution = false;
}
}
- if (m_bHighColorResolution)
- {
+ if (m_bHighColorResolution) {
m_BackbufferType = D3DFMT_A2R10G10B10;
pp.BackBufferFormat = D3DFMT_A2R10G10B10;
}
- if (bCompositionEnabled)
- {
+ if (bCompositionEnabled) {
// Desktop composition presents the whole desktop
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- }
- else
- {
+ } else {
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
- if (m_pD3DEx)
- {
+ if (m_pD3DEx) {
if FAILED(hr = m_pD3DEx->CreateDeviceEx(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
- D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED|D3DCREATE_ENABLE_PRESENTSTATS,
- &pp, NULL, &m_pD3DDevEx))
- {
+ D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED|D3DCREATE_ENABLE_PRESENTSTATS,
+ &pp, NULL, &m_pD3DDevEx)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
}
- if (m_pD3DDevEx) m_pD3DDev = m_pD3DDevEx;
- }
- else
- {
+ if (m_pD3DDevEx) {
+ m_pD3DDev = m_pD3DDevEx;
+ }
+ } else {
if FAILED(hr = m_pD3D->CreateDevice(m_CurrentAdapter, D3DDEVTYPE_HAL, m_hWnd,
- D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED,
- &pp, &m_pD3DDev))
- {
+ D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_FPU_PRESERVE|D3DCREATE_MULTITHREADED,
+ &pp, &m_pD3DDev)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
}
@@ -586,13 +546,11 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
}
}
- while(hr == D3DERR_DEVICELOST)
- {
+ while(hr == D3DERR_DEVICELOST) {
TRACE("D3DERR_DEVICELOST. Trying to Reset.\n");
hr = m_pD3DDev->TestCooperativeLevel();
}
- if (hr == D3DERR_DEVICENOTRESET)
- {
+ if (hr == D3DERR_DEVICENOTRESET) {
TRACE("D3DERR_DEVICENOTRESET\n");
hr = m_pD3DDev->Reset(&pp);
}
@@ -600,64 +558,59 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
TRACE("CreateDevice: %d\n", (LONG)hr);
ASSERT (SUCCEEDED (hr));
- if (m_pD3DDevEx)
- {
+ if (m_pD3DDevEx) {
m_pD3DDevEx->SetGPUThreadPriority(7);
}
m_pPSC.Attach(DNew CPixelShaderCompiler(m_pD3DDev, true));
m_filter = D3DTEXF_NONE;
- if(m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MINFLINEAR && m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR)
+ if(m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MINFLINEAR && m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR) {
m_filter = D3DTEXF_LINEAR;
+ }
m_bicubicA = 0;
CSize size;
- switch(GetRenderersSettings().nSPCMaxRes)
- {
- case 0:
- default:
- size = m_ScreenSize;
- break;
- case 1:
- size.SetSize(1024, 768);
- break;
- case 2:
- size.SetSize(800, 600);
- break;
- case 3:
- size.SetSize(640, 480);
- break;
- case 4:
- size.SetSize(512, 384);
- break;
- case 5:
- size.SetSize(384, 288);
- break;
- case 6:
- size.SetSize(2560, 1600);
- break;
- case 7:
- size.SetSize(1920, 1080);
- break;
- case 8:
- size.SetSize(1320, 900);
- break;
- case 9:
- size.SetSize(1280, 720);
- break;
- }
-
- if(m_pAllocator)
- {
- m_pAllocator->ChangeDevice(m_pD3DDev);
+ switch(GetRenderersSettings().nSPCMaxRes) {
+ case 0:
+ default:
+ size = m_ScreenSize;
+ break;
+ case 1:
+ size.SetSize(1024, 768);
+ break;
+ case 2:
+ size.SetSize(800, 600);
+ break;
+ case 3:
+ size.SetSize(640, 480);
+ break;
+ case 4:
+ size.SetSize(512, 384);
+ break;
+ case 5:
+ size.SetSize(384, 288);
+ break;
+ case 6:
+ size.SetSize(2560, 1600);
+ break;
+ case 7:
+ size.SetSize(1920, 1080);
+ break;
+ case 8:
+ size.SetSize(1320, 900);
+ break;
+ case 9:
+ size.SetSize(1280, 720);
+ break;
}
- else
- {
+
+ if(m_pAllocator) {
+ m_pAllocator->ChangeDevice(m_pD3DDev);
+ } else {
m_pAllocator = DNew CDX9SubPicAllocator(m_pD3DDev, size, GetRenderersSettings().fSPCPow2Tex);
- if(!m_pAllocator)
- {
+ if(!m_pAllocator) {
_Error += L"CDX9SubPicAllocator failed\n";
return E_FAIL;
}
@@ -666,8 +619,7 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
hr = S_OK;
CComPtr<ISubPicProvider> pSubPicProvider;
- if(m_pSubPicQueue)
- {
+ if(m_pSubPicQueue) {
_tprintf(_T("m_pSubPicQueue != NULL\n"));
m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
}
@@ -676,16 +628,16 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
m_pSubPicQueue = GetRenderersSettings().nSPCSize > 0
? (ISubPicQueue*)DNew CSubPicQueue(GetRenderersSettings().nSPCSize, !GetRenderersSettings().fSPCAllowAnimationWhenBuffering, m_pAllocator, &hr)
: (ISubPicQueue*)DNew CSubPicQueueNoThread(m_pAllocator, &hr);
- if(!m_pSubPicQueue || FAILED(hr))
- {
+ if(!m_pSubPicQueue || FAILED(hr)) {
_Error += L"m_pSubPicQueue failed\n";
return E_FAIL;
}
- if(pSubPicProvider) m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ if(pSubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ }
- if (m_pD3DXCreateFont)
- {
+ if (m_pD3DXCreateFont) {
int MinSize = 1600;
int CurrentSize = min(m_ScreenSize.cx, MinSize);
double Scale = double(CurrentSize) / double(MinSize);
@@ -693,8 +645,12 @@ HRESULT CBaseAP::CreateDXDevice(CString &_Error)
m_pD3DXCreateFont(m_pD3DDev, -24.0*Scale, -11.0*Scale, CurrentSize < 800 ? FW_NORMAL : FW_BOLD, 0, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FIXED_PITCH | FF_DONTCARE, L"Lucida Console", &m_pFont);
}
- if (m_pD3DXCreateSprite) m_pD3DXCreateSprite(m_pD3DDev, &m_pSprite);
- if (m_pD3DXCreateLine) m_pD3DXCreateLine (m_pD3DDev, &m_pLine);
+ if (m_pD3DXCreateSprite) {
+ m_pD3DXCreateSprite(m_pD3DDev, &m_pSprite);
+ }
+ if (m_pD3DXCreateLine) {
+ m_pD3DXCreateLine (m_pD3DDev, &m_pLine);
+ }
m_LastAdapterCheck = GetRenderersData()->GetPerfCounter();
return S_OK;
}
@@ -706,7 +662,9 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
HRESULT hr = E_FAIL;
hr = m_pD3DDev->TestCooperativeLevel();
- if ((hr != D3DERR_DEVICENOTRESET) && (hr != D3D_OK)) return hr;
+ if ((hr != D3DERR_DEVICENOTRESET) && (hr != D3D_OK)) {
+ return hr;
+ }
CComPtr<IEnumPins> rendererInputEnum;
vector<CComPtr<IPin>> decoderOutput;
@@ -716,30 +674,26 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
bool disconnected = FALSE;
// Disconnect all pins to release video memory resources
- if (m_pD3DDev)
- {
+ if (m_pD3DDev) {
ZeroMemory(&filterInfo, sizeof(filterInfo));
m_pOuterEVR->QueryFilterInfo(&filterInfo); // This addref's the pGraph member
- if (SUCCEEDED(m_pOuterEVR->EnumPins(&rendererInputEnum)))
- {
+ if (SUCCEEDED(m_pOuterEVR->EnumPins(&rendererInputEnum))) {
CComPtr<IPin> input;
CComPtr<IPin> output;
- while (hr = rendererInputEnum->Next(1, &input.p, 0), hr == S_OK) // Must have .p here
- {
+ while (hr = rendererInputEnum->Next(1, &input.p, 0), hr == S_OK) { // Must have .p here
_tprintf(_T("Pin found\n"));
input->ConnectedTo(&output.p);
- if (output != NULL)
- {
+ if (output != NULL) {
rendererInput.push_back(input);
decoderOutput.push_back(output);
}
input.Release();
output.Release();
}
+ } else {
+ return hr;
}
- else return hr;
- for (DWORD i = 0; i < decoderOutput.size(); i++)
- {
+ for (DWORD i = 0; i < decoderOutput.size(); i++) {
_tprintf(_T("Disconnecting pin\n"));
filterInfo.pGraph->Disconnect(decoderOutput.at(i).p);
filterInfo.pGraph->Disconnect(rendererInput.at(i).p);
@@ -761,22 +715,19 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
m_pResizerPixelShader[3] = 0;
POSITION pos = m_pPixelShadersScreenSpace.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CExternalPixelShader &Shader = m_pPixelShadersScreenSpace.GetNext(pos);
Shader.m_pPixelShader = NULL;
}
pos = m_pPixelShaders.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CExternalPixelShader &Shader = m_pPixelShaders.GetNext(pos);
Shader.m_pPixelShader = NULL;
}
D3DDISPLAYMODE d3ddm;
ZeroMemory(&d3ddm, sizeof(d3ddm));
- if(FAILED(m_pD3D->GetAdapterDisplayMode(GetAdapter(m_pD3D), &d3ddm)))
- {
+ if(FAILED(m_pD3D->GetAdapterDisplayMode(GetAdapter(m_pD3D), &d3ddm))) {
_Error += L"Can not retrieve display mode data\n";
return E_UNEXPECTED;
}
@@ -790,20 +741,21 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
ZeroMemory(&pp, sizeof(pp));
BOOL bCompositionEnabled = false;
- if (m_pDwmIsCompositionEnabled) m_pDwmIsCompositionEnabled(&bCompositionEnabled);
+ if (m_pDwmIsCompositionEnabled) {
+ m_pDwmIsCompositionEnabled(&bCompositionEnabled);
+ }
m_bCompositionEnabled = bCompositionEnabled != 0;
m_bHighColorResolution = s.m_RenderSettings.iEVRHighColorResolution;
- if (m_bIsFullscreen) // Exclusive mode fullscreen
- {
+ if (m_bIsFullscreen) { // Exclusive mode fullscreen
pp.BackBufferWidth = d3ddm.Width;
pp.BackBufferHeight = d3ddm.Height;
- if (m_bHighColorResolution)
+ if (m_bHighColorResolution) {
pp.BackBufferFormat = D3DFMT_A2R10G10B10;
- else
+ } else {
pp.BackBufferFormat = d3ddm.Format;
- if(FAILED(m_pD3DEx->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pp.BackBufferFormat, pp.BackBufferFormat, false)))
- {
+ }
+ if(FAILED(m_pD3DEx->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pp.BackBufferFormat, pp.BackBufferFormat, false))) {
_Error += L"10 bit RGB is not supported by this graphics device in exclusive mode fullscreen.\n";
return hr;
}
@@ -811,89 +763,66 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
D3DDISPLAYMODEEX DisplayMode;
ZeroMemory(&DisplayMode, sizeof(DisplayMode));
DisplayMode.Size = sizeof(DisplayMode);
- if (m_pD3DDevEx)
- {
+ if (m_pD3DDevEx) {
m_pD3DEx->GetAdapterDisplayModeEx(GetAdapter(m_pD3DEx), &DisplayMode, NULL);
DisplayMode.Format = pp.BackBufferFormat;
pp.FullScreen_RefreshRateInHz = DisplayMode.RefreshRate;
- if FAILED(m_pD3DDevEx->Reset(&pp))
- {
+ if FAILED(m_pD3DDevEx->Reset(&pp)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
}
- }
- else if (m_pD3DDev)
- {
- if FAILED(m_pD3DDev->Reset(&pp))
- {
+ } else if (m_pD3DDev) {
+ if FAILED(m_pD3DDev->Reset(&pp)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
}
- }
- else
- {
+ } else {
_Error += L"No device.\n";
return hr;
}
m_BackbufferType = pp.BackBufferFormat;
m_DisplayType = d3ddm.Format;
- }
- else // Windowed
- {
+ } else { // Windowed
pp.BackBufferWidth = d3ddm.Width;
pp.BackBufferHeight = d3ddm.Height;
m_BackbufferType = d3ddm.Format;
m_DisplayType = d3ddm.Format;
- if (m_bHighColorResolution)
- {
+ if (m_bHighColorResolution) {
m_BackbufferType = D3DFMT_A2R10G10B10;
pp.BackBufferFormat = D3DFMT_A2R10G10B10;
}
- if(FAILED(m_pD3DEx->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pp.BackBufferFormat, pp.BackBufferFormat, false)))
- {
+ if(FAILED(m_pD3DEx->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pp.BackBufferFormat, pp.BackBufferFormat, false))) {
_Error += L"10 bit RGB is not supported by this graphics device in windowed mode.\n";
return hr;
}
- if (bCompositionEnabled)
- {
+ if (bCompositionEnabled) {
// Desktop composition presents the whole desktop
pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
- }
- else
- {
+ } else {
pp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
if (m_pD3DDevEx)
- if FAILED(m_pD3DDevEx->Reset(&pp))
- {
+ if FAILED(m_pD3DDevEx->Reset(&pp)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
- }
- else if (m_pD3DDev)
- if FAILED(m_pD3DDevEx->Reset(&pp))
- {
+ } else if (m_pD3DDev)
+ if FAILED(m_pD3DDevEx->Reset(&pp)) {
_Error += GetWindowsErrorMessage(hr, m_hD3D9);
return hr;
- }
- else
- {
+ } else {
_Error += L"No device.\n";
return hr;
}
}
- if (disconnected)
- {
- for (DWORD i = 0; i < decoderOutput.size(); i++)
- {
- if (FAILED(filterInfo.pGraph->ConnectDirect(decoderOutput.at(i).p, rendererInput.at(i).p, NULL)))
- {
+ if (disconnected) {
+ for (DWORD i = 0; i < decoderOutput.size(); i++) {
+ if (FAILED(filterInfo.pGraph->ConnectDirect(decoderOutput.at(i).p, rendererInput.at(i).p, NULL))) {
return hr;
}
}
- if (filterInfo.pGraph != NULL)
- {
+ if (filterInfo.pGraph != NULL) {
filterInfo.pGraph->Release();
}
}
@@ -902,58 +831,56 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
m_filter = D3DTEXF_NONE;
if((m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MINFLINEAR)
- && (m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR))
+ && (m_caps.StretchRectFilterCaps&D3DPTFILTERCAPS_MAGFLINEAR)) {
m_filter = D3DTEXF_LINEAR;
+ }
m_bicubicA = 0;
CComPtr<ISubPicProvider> pSubPicProvider;
- if(m_pSubPicQueue) m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
+ if(m_pSubPicQueue) {
+ m_pSubPicQueue->GetSubPicProvider(&pSubPicProvider);
+ }
CSize size;
- switch(GetRenderersSettings().nSPCMaxRes)
- {
- case 0:
- default:
- size = m_ScreenSize;
- break;
- case 1:
- size.SetSize(1024, 768);
- break;
- case 2:
- size.SetSize(800, 600);
- break;
- case 3:
- size.SetSize(640, 480);
- break;
- case 4:
- size.SetSize(512, 384);
- break;
- case 5:
- size.SetSize(384, 288);
- break;
- case 6:
- size.SetSize(2560, 1600);
- break;
- case 7:
- size.SetSize(1920, 1080);
- break;
- case 8:
- size.SetSize(1320, 900);
- break;
- case 9:
- size.SetSize(1280, 720);
- break;
- }
-
- if(m_pAllocator)
- {
- m_pAllocator->ChangeDevice(m_pD3DDev);
+ switch(GetRenderersSettings().nSPCMaxRes) {
+ case 0:
+ default:
+ size = m_ScreenSize;
+ break;
+ case 1:
+ size.SetSize(1024, 768);
+ break;
+ case 2:
+ size.SetSize(800, 600);
+ break;
+ case 3:
+ size.SetSize(640, 480);
+ break;
+ case 4:
+ size.SetSize(512, 384);
+ break;
+ case 5:
+ size.SetSize(384, 288);
+ break;
+ case 6:
+ size.SetSize(2560, 1600);
+ break;
+ case 7:
+ size.SetSize(1920, 1080);
+ break;
+ case 8:
+ size.SetSize(1320, 900);
+ break;
+ case 9:
+ size.SetSize(1280, 720);
+ break;
}
- else
- {
+
+ if(m_pAllocator) {
+ m_pAllocator->ChangeDevice(m_pD3DDev);
+ } else {
m_pAllocator = DNew CDX9SubPicAllocator(m_pD3DDev, size, GetRenderersSettings().fSPCPow2Tex);
- if(!m_pAllocator)
- {
+ if(!m_pAllocator) {
_Error += L"CDX9SubPicAllocator failed\n";
return E_FAIL;
@@ -964,18 +891,18 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
m_pSubPicQueue = GetRenderersSettings().nSPCSize > 0
? (ISubPicQueue*)DNew CSubPicQueue(GetRenderersSettings().nSPCSize, !GetRenderersSettings().fSPCAllowAnimationWhenBuffering, m_pAllocator, &hr)
: (ISubPicQueue*)DNew CSubPicQueueNoThread(m_pAllocator, &hr);
- if(!m_pSubPicQueue || FAILED(hr))
- {
+ if(!m_pSubPicQueue || FAILED(hr)) {
_Error += L"m_pSubPicQueue failed\n";
return E_FAIL;
}
- if(pSubPicProvider) m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ if(pSubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
+ }
m_pFont = NULL;
- if (m_pD3DXCreateFont)
- {
+ if (m_pD3DXCreateFont) {
int MinSize = 1600;
int CurrentSize = min(m_ScreenSize.cx, MinSize);
double Scale = double(CurrentSize) / double(MinSize);
@@ -984,9 +911,13 @@ HRESULT CBaseAP::ResetDXDevice(CString &_Error)
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FIXED_PITCH | FF_DONTCARE, L"Lucida Console", &m_pFont);
}
m_pSprite = NULL;
- if (m_pD3DXCreateSprite) m_pD3DXCreateSprite(m_pD3DDev, &m_pSprite);
+ if (m_pD3DXCreateSprite) {
+ m_pD3DXCreateSprite(m_pD3DDev, &m_pSprite);
+ }
m_pLine = NULL;
- if (m_pD3DXCreateLine) m_pD3DXCreateLine (m_pD3DDev, &m_pLine);
+ if (m_pD3DXCreateLine) {
+ m_pD3DXCreateLine (m_pD3DDev, &m_pLine);
+ }
return S_OK;
}
@@ -997,8 +928,7 @@ HRESULT CBaseAP::AllocSurfaces(D3DFORMAT Format)
CRenderersSettings& s = GetRenderersSettings();
- for(int i = 0; i < m_nDXSurface+2; i++)
- {
+ for(int i = 0; i < m_nDXSurface+2; i++) {
m_pVideoTexture[i] = NULL;
m_pVideoSurface[i] = NULL;
}
@@ -1008,31 +938,28 @@ HRESULT CBaseAP::AllocSurfaces(D3DFORMAT Format)
m_SurfaceType = Format;
HRESULT hr;
- if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
- {
+ if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D || s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
int nTexturesNeeded = s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D ? m_nDXSurface+2 : 1;
- for(int i = 0; i < nTexturesNeeded; i++)
- {
+ for(int i = 0; i < nTexturesNeeded; i++) {
if(FAILED(hr = m_pD3DDev->CreateTexture(
- m_NativeVideoSize.cx, m_NativeVideoSize.cy, 1, D3DUSAGE_RENDERTARGET, Format, D3DPOOL_DEFAULT, &m_pVideoTexture[i], NULL)))
+ m_NativeVideoSize.cx, m_NativeVideoSize.cy, 1, D3DUSAGE_RENDERTARGET, Format, D3DPOOL_DEFAULT, &m_pVideoTexture[i], NULL))) {
return hr;
+ }
- if(FAILED(hr = m_pVideoTexture[i]->GetSurfaceLevel(0, &m_pVideoSurface[i])))
+ if(FAILED(hr = m_pVideoTexture[i]->GetSurfaceLevel(0, &m_pVideoSurface[i]))) {
return hr;
+ }
}
- if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D)
- {
- for(int i = 0; i < m_nDXSurface+2; i++)
- {
+ if(s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE2D) {
+ for(int i = 0; i < m_nDXSurface+2; i++) {
m_pVideoTexture[i] = NULL;
}
}
- }
- else
- {
- if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(m_NativeVideoSize.cx, m_NativeVideoSize.cy, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_pVideoSurface[m_nCurSurface], NULL)))
+ } else {
+ if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(m_NativeVideoSize.cx, m_NativeVideoSize.cy, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &m_pVideoSurface[m_nCurSurface], NULL))) {
return hr;
+ }
}
hr = m_pD3DDev->ColorFill(m_pVideoSurface[m_nCurSurface], NULL, 0);
@@ -1044,8 +971,7 @@ void CBaseAP::DeleteSurfaces()
CAutoLock cAutoLock(this);
CAutoLock cRenderLock(&m_allocatorLock);
- for(int i = 0; i < m_nDXSurface+2; i++)
- {
+ for(int i = 0; i < m_nDXSurface+2; i++) {
m_pVideoTexture[i] = NULL;
m_pVideoSurface[i] = NULL;
}
@@ -1053,15 +979,20 @@ void CBaseAP::DeleteSurfaces()
UINT CBaseAP::GetAdapter(IDirect3D9* pD3D)
{
- if(m_hWnd == NULL || pD3D == NULL) return D3DADAPTER_DEFAULT;
+ if(m_hWnd == NULL || pD3D == NULL) {
+ return D3DADAPTER_DEFAULT;
+ }
HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
- if(hMonitor == NULL) return D3DADAPTER_DEFAULT;
+ if(hMonitor == NULL) {
+ return D3DADAPTER_DEFAULT;
+ }
- for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp)
- {
+ for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp) {
HMONITOR hAdpMon = pD3D->GetAdapterMonitor(adp);
- if(hAdpMon == hMonitor) return adp;
+ if(hAdpMon == hMonitor) {
+ return adp;
+ }
}
return D3DADAPTER_DEFAULT;
}
@@ -1077,37 +1008,33 @@ bool CBaseAP::ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, CRect& d)
{
D3DSURFACE_DESC d3dsd;
ZeroMemory(&d3dsd, sizeof(d3dsd));
- if(FAILED(pSurface->GetDesc(&d3dsd)))
+ if(FAILED(pSurface->GetDesc(&d3dsd))) {
return(false);
+ }
int w = d3dsd.Width, h = d3dsd.Height;
int sw = s.Width(), sh = s.Height();
int dw = d.Width(), dh = d.Height();
if(d.left >= w || d.right < 0 || d.top >= h || d.bottom < 0
- || sw <= 0 || sh <= 0 || dw <= 0 || dh <= 0)
- {
+ || sw <= 0 || sh <= 0 || dw <= 0 || dh <= 0) {
s.SetRectEmpty();
d.SetRectEmpty();
return(true);
}
- if(d.right > w)
- {
+ if(d.right > w) {
s.right -= (d.right-w)*sw/dw;
d.right = w;
}
- if(d.bottom > h)
- {
+ if(d.bottom > h) {
s.bottom -= (d.bottom-h)*sh/dh;
d.bottom = h;
}
- if(d.left < 0)
- {
+ if(d.left < 0) {
s.left += (0-d.left)*sw/dw;
d.left = 0;
}
- if(d.top < 0)
- {
+ if(d.top < 0) {
s.top += (0-d.top)*sh/dh;
d.top = 0;
}
@@ -1117,57 +1044,65 @@ bool CBaseAP::ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, CRect& d)
HRESULT CBaseAP::InitResizers(float bicubicA, bool bNeedScreenSizeTexture)
{
HRESULT hr;
- do
- {
- if (bicubicA)
- {
- if (!m_pResizerPixelShader[0])
+ do {
+ if (bicubicA) {
+ if (!m_pResizerPixelShader[0]) {
break;
- if (!m_pResizerPixelShader[1])
+ }
+ if (!m_pResizerPixelShader[1]) {
break;
- if (!m_pResizerPixelShader[2])
+ }
+ if (!m_pResizerPixelShader[2]) {
break;
- if (!m_pResizerPixelShader[3])
+ }
+ if (!m_pResizerPixelShader[3]) {
break;
- if (m_bicubicA != bicubicA)
+ }
+ if (m_bicubicA != bicubicA) {
break;
- if (!m_pScreenSizeTemporaryTexture[0])
+ }
+ if (!m_pScreenSizeTemporaryTexture[0]) {
break;
- if (bNeedScreenSizeTexture)
- {
- if (!m_pScreenSizeTemporaryTexture[1])
+ }
+ if (bNeedScreenSizeTexture) {
+ if (!m_pScreenSizeTemporaryTexture[1]) {
break;
+ }
}
- }
- else
- {
- if (!m_pResizerPixelShader[0])
+ } else {
+ if (!m_pResizerPixelShader[0]) {
break;
- if (bNeedScreenSizeTexture)
- {
- if (!m_pScreenSizeTemporaryTexture[0])
+ }
+ if (bNeedScreenSizeTexture) {
+ if (!m_pScreenSizeTemporaryTexture[0]) {
break;
- if (!m_pScreenSizeTemporaryTexture[1])
+ }
+ if (!m_pScreenSizeTemporaryTexture[1]) {
break;
+ }
}
}
return S_OK;
- }
- while (0);
+ } while (0);
m_bicubicA = bicubicA;
m_pScreenSizeTemporaryTexture[0] = NULL;
m_pScreenSizeTemporaryTexture[1] = NULL;
- for(int i = 0; i < countof(m_pResizerPixelShader); i++)
+ for(int i = 0; i < countof(m_pResizerPixelShader); i++) {
m_pResizerPixelShader[i] = NULL;
+ }
- if(m_caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) return E_FAIL;
+ if(m_caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) {
+ return E_FAIL;
+ }
LPCSTR pProfile = m_caps.PixelShaderVersion >= D3DPS_VERSION(3, 0) ? "ps_3_0" : "ps_2_0";
CStringA str;
- if(!LoadResource(IDF_SHADER_RESIZER, str, _T("FILE"))) return E_FAIL;
+ if(!LoadResource(IDF_SHADER_RESIZER, str, _T("FILE"))) {
+ return E_FAIL;
+ }
CStringA A;
A.Format("(%f)", bicubicA);
@@ -1176,34 +1111,28 @@ HRESULT CBaseAP::InitResizers(float bicubicA, bool bNeedScreenSizeTexture)
LPCSTR pEntries[] = {"main_bilinear", "main_bicubic1pass", "main_bicubic2pass_pass1", "main_bicubic2pass_pass2"};
ASSERT(countof(pEntries) == countof(m_pResizerPixelShader));
- for(int i = 0; i < countof(pEntries); i++)
- {
+ for(int i = 0; i < countof(pEntries); i++) {
CString ErrorMessage;
CString DissAssembly;
hr = m_pPSC->CompileShader(str, pEntries[i], pProfile, 0, &m_pResizerPixelShader[i], &DissAssembly, &ErrorMessage);
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
TRACE("%ws", ErrorMessage.GetString());
ASSERT (0);
return hr;
}
}
- if(m_bicubicA || bNeedScreenSizeTexture)
- {
+ if(m_bicubicA || bNeedScreenSizeTexture) {
if(FAILED(m_pD3DDev->CreateTexture(
min(m_ScreenSize.cx, (int)m_caps.MaxTextureWidth), min(max(m_ScreenSize.cy, m_NativeVideoSize.cy), (int)m_caps.MaxTextureHeight), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
- D3DPOOL_DEFAULT, &m_pScreenSizeTemporaryTexture[0], NULL)))
- {
+ D3DPOOL_DEFAULT, &m_pScreenSizeTemporaryTexture[0], NULL))) {
ASSERT(0);
m_pScreenSizeTemporaryTexture[0] = NULL; // will do 1 pass then
}
}
- if(m_bicubicA || bNeedScreenSizeTexture)
- {
+ if(m_bicubicA || bNeedScreenSizeTexture) {
if(FAILED(m_pD3DDev->CreateTexture(
min(m_ScreenSize.cx, (int)m_caps.MaxTextureWidth), min(max(m_ScreenSize.cy, m_NativeVideoSize.cy), (int)m_caps.MaxTextureHeight), 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
- D3DPOOL_DEFAULT, &m_pScreenSizeTemporaryTexture[1], NULL)))
- {
+ D3DPOOL_DEFAULT, &m_pScreenSizeTemporaryTexture[1], NULL))) {
ASSERT(0);
m_pScreenSizeTemporaryTexture[1] = NULL; // will do 1 pass then
}
@@ -1216,20 +1145,19 @@ HRESULT CBaseAP::TextureCopy(IDirect3DTexture9* pTexture)
HRESULT hr;
D3DSURFACE_DESC desc;
- if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
float w = (float)desc.Width;
float h = (float)desc.Height;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{0, 0, 0.5f, 2.0f, 0, 0},
{w, 0, 0.5f, 2.0f, 1, 0},
{0, h, 0.5f, 2.0f, 0, 1},
{w, h, 0.5f, 2.0f, 1, 1},
};
- for(int i = 0; i < countof(v); i++)
- {
+ for(int i = 0; i < countof(v); i++) {
v[i].x -= 0.5;
v[i].y -= 0.5;
}
@@ -1240,15 +1168,13 @@ HRESULT CBaseAP::TextureCopy(IDirect3DTexture9* pTexture)
HRESULT CBaseAP::DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_Rect)
{
DWORD Color = D3DCOLOR_ARGB(_Alpha, GetRValue(_Color), GetGValue(_Color), GetBValue(_Color));
- MYD3DVERTEX<0> v[] =
- {
+ MYD3DVERTEX<0> v[] = {
{float(_Rect.left), float(_Rect.top), 0.5f, 2.0f, Color},
{float(_Rect.right), float(_Rect.top), 0.5f, 2.0f, Color},
{float(_Rect.left), float(_Rect.bottom), 0.5f, 2.0f, Color},
{float(_Rect.right), float(_Rect.bottom), 0.5f, 2.0f, Color},
};
- for(int i = 0; i < countof(v); i++)
- {
+ for(int i = 0; i < countof(v); i++) {
v[i].x -= 0.5;
v[i].y -= 0.5;
}
@@ -1260,8 +1186,9 @@ HRESULT CBaseAP::TextureResize(IDirect3DTexture9* pTexture, Vector dst[4], D3DTE
HRESULT hr;
D3DSURFACE_DESC desc;
- if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
float w = (float)desc.Width;
float h = (float)desc.Height;
@@ -1269,8 +1196,7 @@ HRESULT CBaseAP::TextureResize(IDirect3DTexture9* pTexture, Vector dst[4], D3DTE
float dx2 = 1.0/w;
float dy2 = 1.0/h;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{dst[0].x, dst[0].y, dst[0].z, 1.0f/dst[0].z, SrcRect.left * dx2, SrcRect.top * dy2},
{dst[1].x, dst[1].y, dst[1].z, 1.0f/dst[1].z, SrcRect.right * dx2, SrcRect.top * dy2},
{dst[2].x, dst[2].y, dst[2].z, 1.0f/dst[2].z, SrcRect.left * dx2, SrcRect.bottom * dy2},
@@ -1288,8 +1214,9 @@ HRESULT CBaseAP::TextureResizeBilinear(IDirect3DTexture9* pTexture, Vector dst[4
HRESULT hr;
D3DSURFACE_DESC desc;
- if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
float w = (float)desc.Width;
float h = (float)desc.Height;
@@ -1299,8 +1226,7 @@ HRESULT CBaseAP::TextureResizeBilinear(IDirect3DTexture9* pTexture, Vector dst[4
float ty0 = SrcRect.top;
float ty1 = SrcRect.bottom;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{dst[0].x, dst[0].y, dst[0].z, 1.0f/dst[0].z, tx0, ty0},
{dst[1].x, dst[1].y, dst[1].z, 1.0f/dst[1].z, tx1, ty0},
{dst[2].x, dst[2].y, dst[2].z, 1.0f/dst[2].z, tx0, ty1},
@@ -1321,8 +1247,9 @@ HRESULT CBaseAP::TextureResizeBicubic1pass(IDirect3DTexture9* pTexture, Vector d
HRESULT hr;
D3DSURFACE_DESC desc;
- if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc)))
+ if(!pTexture || FAILED(pTexture->GetLevelDesc(0, &desc))) {
return E_FAIL;
+ }
double w = (double)desc.Width;
double h = (double)desc.Height;
@@ -1332,8 +1259,7 @@ HRESULT CBaseAP::TextureResizeBicubic1pass(IDirect3DTexture9* pTexture, Vector d
float ty0 = SrcRect.top;
float ty1 = SrcRect.bottom;
- MYD3DVERTEX<1> v[] =
- {
+ MYD3DVERTEX<1> v[] = {
{dst[0].x, dst[0].y, dst[0].z, 1.0f/dst[0].z, tx0, ty0},
{dst[1].x, dst[1].y, dst[1].z, 1.0f/dst[1].z, tx1, ty0},
{dst[2].x, dst[2].y, dst[2].z, 1.0f/dst[2].z, tx0, ty1},
@@ -1436,30 +1362,29 @@ HRESULT CBaseAP::TextureResizeBicubic2pass(IDirect3DTexture9* pTexture, Vector d
HRESULT CBaseAP::AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture)
{
- if(!pSrc || !pDst)
+ if(!pSrc || !pDst) {
return E_POINTER;
+ }
CRect src(*pSrc), dst(*pDst);
HRESULT hr;
- do
- {
+ do {
D3DSURFACE_DESC d3dsd;
ZeroMemory(&d3dsd, sizeof(d3dsd));
- if(FAILED(pTexture->GetLevelDesc(0, &d3dsd)) /*|| d3dsd.Type != D3DRTYPE_TEXTURE*/)
+ if(FAILED(pTexture->GetLevelDesc(0, &d3dsd)) /*|| d3dsd.Type != D3DRTYPE_TEXTURE*/) {
break;
+ }
float w = (float)d3dsd.Width;
float h = (float)d3dsd.Height;
- struct
- {
+ struct {
float x, y, z, rhw;
float tu, tv;
}
- pVertices[] =
- {
+ pVertices[] = {
{(float)dst.left, (float)dst.top, 0.5f, 2.0f, (float)src.left / w, (float)src.top / h},
{(float)dst.right, (float)dst.top, 0.5f, 2.0f, (float)src.right / w, (float)src.top / h},
{(float)dst.left, (float)dst.bottom, 0.5f, 2.0f, (float)src.left / w, (float)src.bottom / h},
@@ -1503,8 +1428,7 @@ HRESULT CBaseAP::AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture)
m_pD3DDev->SetRenderState(D3DRS_DESTBLEND, db);
return S_OK;
- }
- while(0);
+ } while(0);
return E_FAIL;
}
@@ -1515,13 +1439,13 @@ void CBaseAP::SyncStats(LONGLONG syncTime)
LONGLONG jitter = syncTime - m_llLastSyncTime;
m_pllJitter[m_nNextJitter] = jitter;
double syncDeviation = ((double)m_pllJitter[m_nNextJitter] - m_fJitterMean) / 10000.0;
- if (abs(syncDeviation) > (GetDisplayCycle() / 2))
+ if (abs(syncDeviation) > (GetDisplayCycle() / 2)) {
m_uSyncGlitches++;
+ }
LONGLONG llJitterSum = 0;
LONGLONG llJitterSumAvg = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
LONGLONG Jitter = m_pllJitter[i];
llJitterSum += Jitter;
llJitterSumAvg += Jitter;
@@ -1529,8 +1453,7 @@ void CBaseAP::SyncStats(LONGLONG syncTime)
m_fJitterMean = double(llJitterSumAvg) / NB_JITTER;
double DeviationSum = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
LONGLONG DevInt = m_pllJitter[i] - m_fJitterMean;
double Deviation = DevInt;
DeviationSum += Deviation*Deviation;
@@ -1550,8 +1473,7 @@ void CBaseAP::SyncOffsetStats(LONGLONG syncOffset)
m_pllSyncOffset[m_nNextSyncOffset] = syncOffset;
LONGLONG AvrageSum = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
LONGLONG Offset = m_pllSyncOffset[i];
AvrageSum += Offset;
m_MaxSyncOffset = max(m_MaxSyncOffset, Offset);
@@ -1559,8 +1481,7 @@ void CBaseAP::SyncOffsetStats(LONGLONG syncOffset)
}
double MeanOffset = double(AvrageSum)/NB_JITTER;
double DeviationSum = 0;
- for (int i=0; i<NB_JITTER; i++)
- {
+ for (int i=0; i<NB_JITTER; i++) {
double Deviation = double(m_pllSyncOffset[i]) - MeanOffset;
DeviationSum += Deviation*Deviation;
}
@@ -1574,20 +1495,20 @@ void CBaseAP::UpdateAlphaBitmap()
{
m_VMR9AlphaBitmapData.Free();
- if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0)
- {
+ if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0) {
HBITMAP hBitmap = (HBITMAP)GetCurrentObject (m_VMR9AlphaBitmap.hdc, OBJ_BITMAP);
- if (!hBitmap)
+ if (!hBitmap) {
return;
+ }
DIBSECTION info = {0};
- if (!::GetObject(hBitmap, sizeof( DIBSECTION ), &info ))
+ if (!::GetObject(hBitmap, sizeof( DIBSECTION ), &info )) {
return;
+ }
m_VMR9AlphaBitmapRect = CRect(0, 0, info.dsBm.bmWidth, info.dsBm.bmHeight);
m_VMR9AlphaBitmapWidthBytes = info.dsBm.bmWidthBytes;
- if (m_VMR9AlphaBitmapData.Allocate(info.dsBm.bmWidthBytes * info.dsBm.bmHeight))
- {
+ if (m_VMR9AlphaBitmapData.Allocate(info.dsBm.bmWidthBytes * info.dsBm.bmHeight)) {
memcpy((BYTE *)m_VMR9AlphaBitmapData, info.dsBm.bmBits, info.dsBm.bmWidthBytes * info.dsBm.bmHeight);
}
}
@@ -1596,8 +1517,7 @@ void CBaseAP::UpdateAlphaBitmap()
// Present a sample (frame) using DirectX.
STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
{
- if (m_bPendingResetDevice)
- {
+ if (m_bPendingResetDevice) {
SendResetRequest();
return false;
}
@@ -1617,7 +1537,9 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
// reference clock. The wiggles are not seen with the perfcounter-based reference clock of the sync to video option.
m_pD3DDev->GetRasterStatus(0, &rasterStatus);
m_uScanLineEnteringPaint = rasterStatus.ScanLine;
- if (m_pRefClock) m_pRefClock->GetTime(&llCurRefTime);
+ if (m_pRefClock) {
+ m_pRefClock->GetTime(&llCurRefTime);
+ }
int dScanLines = max((int)m_ScreenSize.cy - m_uScanLineEnteringPaint, 0);
dSyncOffset = dScanLines * m_dDetectedScanlineTime; // ms
llSyncOffset = REFERENCE_TIME(10000.0 * dSyncOffset); // Reference time units (100 ns)
@@ -1625,8 +1547,7 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
if(m_WindowRect.right <= m_WindowRect.left || m_WindowRect.bottom <= m_WindowRect.top
|| m_NativeVideoSize.cx <= 0 || m_NativeVideoSize.cy <= 0
- || !m_pVideoSurface)
- {
+ || !m_pVideoSurface) {
return(false);
}
@@ -1641,29 +1562,27 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
m_pD3DDev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
m_pD3DDev->SetRenderTarget(0, pBackBuffer);
hr = m_pD3DDev->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0);
- if(!rDstVid.IsRectEmpty())
- {
- if(m_pVideoTexture[m_nCurSurface])
- {
+ if(!rDstVid.IsRectEmpty()) {
+ if(m_pVideoTexture[m_nCurSurface]) {
CComPtr<IDirect3DTexture9> pVideoTexture = m_pVideoTexture[m_nCurSurface];
- if(m_pVideoTexture[m_nDXSurface] && m_pVideoTexture[m_nDXSurface+1] && !m_pPixelShaders.IsEmpty())
- {
+ if(m_pVideoTexture[m_nDXSurface] && m_pVideoTexture[m_nDXSurface+1] && !m_pPixelShaders.IsEmpty()) {
static __int64 counter = 0;
static long start = clock();
long stop = clock();
long diff = stop - start;
- if(diff >= 10*60*CLOCKS_PER_SEC) start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ if(diff >= 10*60*CLOCKS_PER_SEC) {
+ start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ }
int src = m_nCurSurface, dst = m_nDXSurface;
D3DSURFACE_DESC desc;
m_pVideoTexture[src]->GetLevelDesc(0, &desc);
- float fConstData[][4] =
- {
+ float fConstData[][4] = {
{(float)desc.Width, (float)desc.Height, (float)(counter++), (float)diff / CLOCKS_PER_SEC},
{1.0f / desc.Width, 1.0f / desc.Height, 0, 0},
};
@@ -1674,19 +1593,21 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
hr = m_pD3DDev->GetRenderTarget(0, &pRT);
POSITION pos = m_pPixelShaders.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
pVideoTexture = m_pVideoTexture[dst];
hr = m_pD3DDev->SetRenderTarget(0, m_pVideoSurface[dst]);
CExternalPixelShader &Shader = m_pPixelShaders.GetNext(pos);
- if (!Shader.m_pPixelShader)
+ if (!Shader.m_pPixelShader) {
Shader.Compile(m_pPSC);
+ }
hr = m_pD3DDev->SetPixelShader(Shader.m_pPixelShader);
TextureCopy(m_pVideoTexture[src]);
src = dst;
- if(++dst >= m_nDXSurface+2) dst = m_nDXSurface;
+ if(++dst >= m_nDXSurface+2) {
+ dst = m_nDXSurface;
+ }
}
hr = m_pD3DDev->SetRenderTarget(0, pRT);
@@ -1700,73 +1621,68 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
float A = 0;
- switch(iDX9Resizer)
- {
- case 3:
- A = -0.60f;
- break;
- case 4:
- A = -0.751f;
- break; // FIXME : 0.75 crash recent D3D, or eat CPU
- case 5:
- A = -1.00f;
- break;
+ switch(iDX9Resizer) {
+ case 3:
+ A = -0.60f;
+ break;
+ case 4:
+ A = -0.751f;
+ break; // FIXME : 0.75 crash recent D3D, or eat CPU
+ case 5:
+ A = -1.00f;
+ break;
}
bool bScreenSpacePixelShaders = !m_pPixelShadersScreenSpace.IsEmpty();
hr = InitResizers(A, bScreenSpacePixelShaders);
- if (!m_pScreenSizeTemporaryTexture[0] || !m_pScreenSizeTemporaryTexture[1])
+ if (!m_pScreenSizeTemporaryTexture[0] || !m_pScreenSizeTemporaryTexture[1]) {
bScreenSpacePixelShaders = false;
+ }
- if (bScreenSpacePixelShaders)
- {
+ if (bScreenSpacePixelShaders) {
CComPtr<IDirect3DSurface9> pRT;
hr = m_pScreenSizeTemporaryTexture[1]->GetSurfaceLevel(0, &pRT);
- if (hr != S_OK)
+ if (hr != S_OK) {
bScreenSpacePixelShaders = false;
- if (bScreenSpacePixelShaders)
- {
+ }
+ if (bScreenSpacePixelShaders) {
hr = m_pD3DDev->SetRenderTarget(0, pRT);
- if (hr != S_OK)
+ if (hr != S_OK) {
bScreenSpacePixelShaders = false;
+ }
hr = m_pD3DDev->Clear(0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0);
}
}
- if(rSrcVid.Size() != rDstVid.Size())
- {
- if(iDX9Resizer == 0 || iDX9Resizer == 1)
- {
+ if(rSrcVid.Size() != rDstVid.Size()) {
+ if(iDX9Resizer == 0 || iDX9Resizer == 1) {
D3DTEXTUREFILTERTYPE Filter = iDX9Resizer == 0 ? D3DTEXF_POINT : D3DTEXF_LINEAR;
hr = TextureResize(pVideoTexture, dst, Filter, rSrcVid);
- }
- else if(iDX9Resizer == 2)
- {
+ } else if(iDX9Resizer == 2) {
hr = TextureResizeBilinear(pVideoTexture, dst, rSrcVid);
- }
- else if(iDX9Resizer >= 3)
- {
+ } else if(iDX9Resizer >= 3) {
hr = TextureResizeBicubic2pass(pVideoTexture, dst, rSrcVid);
}
+ } else {
+ hr = TextureResize(pVideoTexture, dst, D3DTEXF_POINT, rSrcVid);
}
- else hr = TextureResize(pVideoTexture, dst, D3DTEXF_POINT, rSrcVid);
- if (bScreenSpacePixelShaders)
- {
+ if (bScreenSpacePixelShaders) {
static __int64 counter = 555;
static long start = clock() + 333;
long stop = clock() + 333;
long diff = stop - start;
- if(diff >= 10*60*CLOCKS_PER_SEC) start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ if(diff >= 10*60*CLOCKS_PER_SEC) {
+ start = stop; // reset after 10 min (ps float has its limits in both range and accuracy)
+ }
D3DSURFACE_DESC desc;
m_pScreenSizeTemporaryTexture[0]->GetLevelDesc(0, &desc);
- float fConstData[][4] =
- {
+ float fConstData[][4] = {
{(float)desc.Width, (float)desc.Height, (float)(counter++), (float)diff / CLOCKS_PER_SEC},
{1.0f / desc.Width, 1.0f / desc.Height, 0, 0},
};
@@ -1776,22 +1692,19 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
int src = 1, dst = 0;
POSITION pos = m_pPixelShadersScreenSpace.GetHeadPosition();
- while(pos)
- {
- if (m_pPixelShadersScreenSpace.GetTailPosition() == pos)
- {
+ while(pos) {
+ if (m_pPixelShadersScreenSpace.GetTailPosition() == pos) {
m_pD3DDev->SetRenderTarget(0, pBackBuffer);
- }
- else
- {
+ } else {
CComPtr<IDirect3DSurface9> pRT;
hr = m_pScreenSizeTemporaryTexture[dst]->GetSurfaceLevel(0, &pRT);
m_pD3DDev->SetRenderTarget(0, pRT);
}
CExternalPixelShader &Shader = m_pPixelShadersScreenSpace.GetNext(pos);
- if (!Shader.m_pPixelShader)
+ if (!Shader.m_pPixelShader) {
Shader.Compile(m_pPSC);
+ }
hr = m_pD3DDev->SetPixelShader(Shader.m_pPixelShader);
TextureCopy(m_pScreenSizeTemporaryTexture[src]);
@@ -1800,11 +1713,8 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
hr = m_pD3DDev->SetPixelShader(NULL);
}
- }
- else
- {
- if(pBackBuffer)
- {
+ } else {
+ if(pBackBuffer) {
ClipToSurface(pBackBuffer, rSrcVid, rDstVid);
// rSrcVid has to be aligned on mod2 for yuy2->rgb conversion with StretchRect
rSrcVid.left &= ~1;
@@ -1812,31 +1722,28 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
rSrcVid.top &= ~1;
rSrcVid.bottom &= ~1;
hr = m_pD3DDev->StretchRect(m_pVideoSurface[m_nCurSurface], rSrcVid, pBackBuffer, rDstVid, m_filter);
- if(FAILED(hr)) return false;
+ if(FAILED(hr)) {
+ return false;
+ }
}
}
}
AlphaBltSubPic(rSrcPri.Size());
- if (m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_UPDATE)
- {
+ if (m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_UPDATE) {
CAutoLock BitMapLock(&m_VMR9AlphaBitmapLock);
CRect rcSrc (m_VMR9AlphaBitmap.rSrc);
m_pOSDTexture = NULL;
m_pOSDSurface = NULL;
- if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0 && (BYTE *)m_VMR9AlphaBitmapData)
- {
+ if ((m_VMR9AlphaBitmap.dwFlags & VMRBITMAP_DISABLE) == 0 && (BYTE *)m_VMR9AlphaBitmapData) {
if( (m_pD3DXLoadSurfaceFromMemory != NULL) &&
SUCCEEDED(hr = m_pD3DDev->CreateTexture(rcSrc.Width(), rcSrc.Height(), 1,
D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
- D3DPOOL_DEFAULT, &m_pOSDTexture, NULL)) )
- {
- if (SUCCEEDED (hr = m_pOSDTexture->GetSurfaceLevel(0, &m_pOSDSurface)))
- {
+ D3DPOOL_DEFAULT, &m_pOSDTexture, NULL)) ) {
+ if (SUCCEEDED (hr = m_pOSDTexture->GetSurfaceLevel(0, &m_pOSDSurface))) {
hr = m_pD3DXLoadSurfaceFromMemory (m_pOSDSurface, NULL, NULL, (BYTE *)m_VMR9AlphaBitmapData, D3DFMT_A8R8G8B8, m_VMR9AlphaBitmapWidthBytes,
NULL, &m_VMR9AlphaBitmapRect, D3DX_FILTER_NONE, m_VMR9AlphaBitmap.clrSrcKey);
}
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
m_pOSDTexture = NULL;
m_pOSDSurface = NULL;
}
@@ -1844,111 +1751,123 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
}
m_VMR9AlphaBitmap.dwFlags ^= VMRBITMAP_UPDATE;
}
- if (pApp->m_fDisplayStats) DrawStats();
- if (m_pOSDTexture) AlphaBlt(rSrcPri, rDstPri, m_pOSDTexture);
+ if (pApp->m_fDisplayStats) {
+ DrawStats();
+ }
+ if (m_pOSDTexture) {
+ AlphaBlt(rSrcPri, rDstPri, m_pOSDTexture);
+ }
m_pD3DDev->EndScene();
- if (m_pD3DDevEx)
- {
- if (m_bIsFullscreen)
+ if (m_pD3DDevEx) {
+ if (m_bIsFullscreen) {
hr = m_pD3DDevEx->PresentEx(NULL, NULL, NULL, NULL, NULL);
- else
+ } else {
hr = m_pD3DDevEx->PresentEx(rSrcPri, rDstPri, NULL, NULL, NULL);
- }
- else
- {
- if (m_bIsFullscreen)
+ }
+ } else {
+ if (m_bIsFullscreen) {
hr = m_pD3DDev->Present(NULL, NULL, NULL, NULL);
- else
+ } else {
hr = m_pD3DDev->Present(rSrcPri, rDstPri, NULL, NULL);
+ }
+ }
+ if(FAILED(hr)) {
+ _tprintf(_T("Device lost or something\n"));
}
- if(FAILED(hr)) _tprintf(_T("Device lost or something\n"));
// Calculate timing statistics
- if (m_pRefClock) m_pRefClock->GetTime(&llCurRefTime); // To check if we called Present too late to hit the right vsync
+ if (m_pRefClock) {
+ m_pRefClock->GetTime(&llCurRefTime); // To check if we called Present too late to hit the right vsync
+ }
m_llEstVBlankTime = max(m_llEstVBlankTime, llCurRefTime); // Sometimes the real value is larger than the estimated value (but never smaller)
- if (pApp->m_fDisplayStats < 3) // Partial on-screen statistics
- SyncStats(m_llEstVBlankTime); // Max of estimate and real. Sometimes Present may actually return immediately so we need the estimate as a lower bound
- if (pApp->m_fDisplayStats == 1) // Full on-screen statistics
- SyncOffsetStats(-llSyncOffset); // Minus because we want time to flow downward in the graph in DrawStats
+ if (pApp->m_fDisplayStats < 3) { // Partial on-screen statistics
+ SyncStats(m_llEstVBlankTime); // Max of estimate and real. Sometimes Present may actually return immediately so we need the estimate as a lower bound
+ }
+ if (pApp->m_fDisplayStats == 1) { // Full on-screen statistics
+ SyncOffsetStats(-llSyncOffset); // Minus because we want time to flow downward in the graph in DrawStats
+ }
// Adjust sync
double frameCycle = (double)((m_llSampleTime - m_llLastSampleTime) / 10000.0);
- if (frameCycle < 0) frameCycle = 0.0; // Happens when searching.
+ if (frameCycle < 0) {
+ frameCycle = 0.0; // Happens when searching.
+ }
- if (s.m_RenderSettings.bSynchronizeVideo) m_pGenlock->ControlClock(dSyncOffset, frameCycle);
- else if (s.m_RenderSettings.bSynchronizeDisplay) m_pGenlock->ControlDisplay(dSyncOffset, frameCycle);
- else m_pGenlock->UpdateStats(dSyncOffset, frameCycle); // No sync or sync to nearest neighbor
+ if (s.m_RenderSettings.bSynchronizeVideo) {
+ m_pGenlock->ControlClock(dSyncOffset, frameCycle);
+ } else if (s.m_RenderSettings.bSynchronizeDisplay) {
+ m_pGenlock->ControlDisplay(dSyncOffset, frameCycle);
+ } else {
+ m_pGenlock->UpdateStats(dSyncOffset, frameCycle); // No sync or sync to nearest neighbor
+ }
m_dFrameCycle = m_pGenlock->frameCycleAvg;
- if (m_dFrameCycle > 0.0) m_fps = 1000.0 / m_dFrameCycle;
+ if (m_dFrameCycle > 0.0) {
+ m_fps = 1000.0 / m_dFrameCycle;
+ }
m_dCycleDifference = GetCycleDifference();
- if (abs(m_dCycleDifference) < 0.05) // If less than 5% speed difference
+ if (abs(m_dCycleDifference) < 0.05) { // If less than 5% speed difference
m_bSnapToVSync = true;
- else
+ } else {
m_bSnapToVSync = false;
+ }
// Check how well audio is matching rate (if at all)
DWORD tmp;
- if (m_pAudioStats != NULL)
- {
+ if (m_pAudioStats != NULL) {
m_pAudioStats->GetStatParam(AM_AUDREND_STAT_PARAM_SLAVE_ACCUMERROR, &m_lAudioLag, &tmp);
m_lAudioLagMin = min((long)m_lAudioLag, m_lAudioLagMin);
m_lAudioLagMax = max((long)m_lAudioLag, m_lAudioLagMax);
m_pAudioStats->GetStatParam(AM_AUDREND_STAT_PARAM_SLAVE_MODE, &m_lAudioSlaveMode, &tmp);
}
- if (pApp->m_bResetStats)
- {
+ if (pApp->m_bResetStats) {
ResetStats();
pApp->m_bResetStats = false;
}
bool fResetDevice = m_bPendingResetDevice;
- if(hr == D3DERR_DEVICELOST && m_pD3DDev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET || hr == S_PRESENT_MODE_CHANGED)
+ if(hr == D3DERR_DEVICELOST && m_pD3DDev->TestCooperativeLevel() == D3DERR_DEVICENOTRESET || hr == S_PRESENT_MODE_CHANGED) {
fResetDevice = true;
- if (SettingsNeedResetDevice())
+ }
+ if (SettingsNeedResetDevice()) {
fResetDevice = true;
+ }
BOOL bCompositionEnabled = false;
- if (m_pDwmIsCompositionEnabled) m_pDwmIsCompositionEnabled(&bCompositionEnabled);
- if ((bCompositionEnabled != 0) != m_bCompositionEnabled)
- {
- if (m_bIsFullscreen)
- {
+ if (m_pDwmIsCompositionEnabled) {
+ m_pDwmIsCompositionEnabled(&bCompositionEnabled);
+ }
+ if ((bCompositionEnabled != 0) != m_bCompositionEnabled) {
+ if (m_bIsFullscreen) {
m_bCompositionEnabled = (bCompositionEnabled != 0);
- }
- else
+ } else {
fResetDevice = true;
+ }
}
- if(s.fResetDevice)
- {
+ if(s.fResetDevice) {
LONGLONG time = GetRenderersData()->GetPerfCounter();
- if (time > m_LastAdapterCheck + 20000000) // check every 2 sec.
- {
+ if (time > m_LastAdapterCheck + 20000000) { // check every 2 sec.
m_LastAdapterCheck = time;
#ifdef _DEBUG
D3DDEVICE_CREATION_PARAMETERS Parameters;
- if(SUCCEEDED(m_pD3DDev->GetCreationParameters(&Parameters)))
- {
+ if(SUCCEEDED(m_pD3DDev->GetCreationParameters(&Parameters))) {
ASSERT(Parameters.AdapterOrdinal == m_CurrentAdapter);
}
#endif
- if(m_CurrentAdapter != GetAdapter(m_pD3D))
- {
+ if(m_CurrentAdapter != GetAdapter(m_pD3D)) {
fResetDevice = true;
}
#ifdef _DEBUG
- else
- {
+ else {
ASSERT(m_pD3D->GetAdapterMonitor(m_CurrentAdapter) == m_pD3D->GetAdapterMonitor(GetAdapter(m_pD3D)));
}
#endif
}
}
- if(fResetDevice)
- {
+ if(fResetDevice) {
m_bPendingResetDevice = true;
SendResetRequest();
}
@@ -1957,8 +1876,7 @@ STDMETHODIMP_(bool) CBaseAP::Paint(bool fAll)
void CBaseAP::SendResetRequest()
{
- if (!m_bDeviceResetRequested)
- {
+ if (!m_bDeviceResetRequested) {
m_bDeviceResetRequested = true;
AfxGetApp()->m_pMainWnd->PostMessage(WM_RESET_DEVICE);
}
@@ -1969,8 +1887,7 @@ STDMETHODIMP_(bool) CBaseAP::ResetDevice()
DeleteSurfaces();
HRESULT hr;
CString Error;
- if(FAILED(hr = CreateDXDevice(Error)) || FAILED(hr = AllocSurfaces()))
- {
+ if(FAILED(hr = CreateDXDevice(Error)) || FAILED(hr = AllocSurfaces())) {
m_bDeviceResetRequested = false;
return false;
}
@@ -1984,39 +1901,50 @@ STDMETHODIMP_(bool) CBaseAP::ResetDevice()
void CBaseAP::DrawText(const RECT &rc, const CString &strText, int _Priority)
{
- if (_Priority < 1) return;
+ if (_Priority < 1) {
+ return;
+ }
int Quality = 1;
D3DXCOLOR Color1(1.0f, 0.2f, 0.2f, 1.0f );
D3DXCOLOR Color0(0.0f, 0.0f, 0.0f, 1.0f );
RECT Rect1 = rc;
RECT Rect2 = rc;
- if (Quality == 1)
+ if (Quality == 1) {
OffsetRect(&Rect2 , 2, 2);
- else
+ } else {
OffsetRect(&Rect2 , -1, -1);
- if (Quality > 0)
+ }
+ if (Quality > 0) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 1, 0);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 1, 0);
- if (Quality > 2)
+ if (Quality > 2) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 0, 1);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 0, 1);
- if (Quality > 1)
+ if (Quality > 1) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , -1, 0);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText( m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , -1, 0);
- if (Quality > 2)
+ if (Quality > 2) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
OffsetRect (&Rect2 , 0, -1);
- if (Quality > 3)
+ if (Quality > 3) {
m_pFont->DrawText(m_pSprite, strText, -1, &Rect2, DT_NOCLIP, Color0);
+ }
m_pFont->DrawText( m_pSprite, strText, -1, &Rect1, DT_NOCLIP, Color1);
}
@@ -2030,8 +1958,7 @@ void CBaseAP::DrawStats()
RECT rc = {20, 20, 520, 520 };
// pApp->m_fDisplayStats = 1 for full stats, 2 for little less, 3 for basic, 0 for no stats
- if (m_pFont && m_pSprite)
- {
+ if (m_pFont && m_pSprite) {
m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);
CString strText;
int TextHeight = 25.0*m_TextScale + 0.5;
@@ -2040,8 +1967,7 @@ void CBaseAP::DrawStats()
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- if (pApp->m_fDisplayStats == 1)
- {
+ if (pApp->m_fDisplayStats == 1) {
strText.Format(L"Frame cycle: %.3f ms [%.3f ms, %.3f ms] | Frame rate: %.3f fps", m_dFrameCycle, m_pGenlock->minFrameCycle, m_pGenlock->maxFrameCycle, m_fps);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2062,32 +1988,27 @@ void CBaseAP::DrawStats()
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- if (m_pGenlock->powerstripTimingExists)
- {
+ if (m_pGenlock->powerstripTimingExists) {
strText.Format(L"Display cycle from Powerstrip: %.3f ms | Display refresh rate from Powerstrip: %.3f Hz", 1000.0 / m_pGenlock->curDisplayFreq, m_pGenlock->curDisplayFreq);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
}
- if ((m_caps.Caps & D3DCAPS_READ_SCANLINE) == 0)
- {
+ if ((m_caps.Caps & D3DCAPS_READ_SCANLINE) == 0) {
strText.Format(L"Graphics device does not support scan line access. No sync is possible");
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
}
#ifdef _DEBUG
- if (m_pD3DDevEx)
- {
+ if (m_pD3DDevEx) {
CComPtr<IDirect3DSwapChain9> pSC;
HRESULT hr = m_pD3DDevEx->GetSwapChain(0, &pSC);
CComQIPtr<IDirect3DSwapChain9Ex> pSCEx = pSC;
- if (pSCEx)
- {
+ if (pSCEx) {
D3DPRESENTSTATS stats;
hr = pSCEx->GetPresentStats(&stats);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
strText.Format(L"Graphics device present stats:");
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2104,9 +2025,7 @@ void CBaseAP::DrawStats()
stats.SyncQPCTime.QuadPart / Freq.QuadPart, stats.SyncGPUTime.QuadPart / Freq.QuadPart);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- }
- else
- {
+ } else {
strText.Format(L"Graphics device does not support present stats");
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2123,16 +2042,12 @@ void CBaseAP::DrawStats()
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- if (s.m_RenderSettings.bSynchronizeDisplay || s.m_RenderSettings.bSynchronizeVideo)
- {
- if (s.m_RenderSettings.bSynchronizeDisplay && !m_pGenlock->PowerstripRunning())
- {
+ if (s.m_RenderSettings.bSynchronizeDisplay || s.m_RenderSettings.bSynchronizeVideo) {
+ if (s.m_RenderSettings.bSynchronizeDisplay && !m_pGenlock->PowerstripRunning()) {
strText.Format(L"PowerStrip is not running. No display sync is possible.");
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- }
- else
- {
+ } else {
strText.Format(L"Sync adjustment: %d | # of adjustments: %d", m_pGenlock->adjDelta, (m_pGenlock->clockAdjustmentsMade + m_pGenlock->displayAdjustmentsMade) / 2);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2144,8 +2059,7 @@ void CBaseAP::DrawStats()
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- if (pApp->m_fDisplayStats < 3)
- {
+ if (pApp->m_fDisplayStats < 3) {
strText.Format(L"# of sync glitches: %d", m_uSyncGlitches);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2155,10 +2069,8 @@ void CBaseAP::DrawStats()
OffsetRect(&rc, 0, TextHeight);
}
- if (pApp->m_fDisplayStats == 1)
- {
- if (m_pAudioStats && s.m_RenderSettings.bSynchronizeVideo)
- {
+ if (pApp->m_fDisplayStats == 1) {
+ if (m_pAudioStats && s.m_RenderSettings.bSynchronizeVideo) {
strText.Format(L"Audio lag: %3d ms [%d ms, %d ms] | %s", m_lAudioLag, m_lAudioLagMin, m_lAudioLagMax, (m_lAudioSlaveMode == 4) ? _T("Audio renderer is matching rate (for analog sound output)") : _T("Audio renderer is not matching rate"));
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2167,8 +2079,7 @@ void CBaseAP::DrawStats()
strText.Format(L"Sample waiting time: %d ms", m_lNextSampleWait);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- if (s.m_RenderSettings.bSynchronizeNearest)
- {
+ if (s.m_RenderSettings.bSynchronizeNearest) {
strText.Format(L"Sample paint time correction: %2d ms | Hysteresis: %d", m_lShiftToNearest, m_llHysteresis /10000);
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2180,22 +2091,29 @@ void CBaseAP::DrawStats()
strText.Format(L"Settings: ");
- if (m_bIsFullscreen)
+ if (m_bIsFullscreen) {
strText += "D3DFS ";
- if (s.m_RenderSettings.iVMRDisableDesktopComposition)
+ }
+ if (s.m_RenderSettings.iVMRDisableDesktopComposition) {
strText += "DisDC ";
- if (s.m_RenderSettings.bSynchronizeVideo)
+ }
+ if (s.m_RenderSettings.bSynchronizeVideo) {
strText += "SyncVideo ";
- if (s.m_RenderSettings.bSynchronizeDisplay)
+ }
+ if (s.m_RenderSettings.bSynchronizeDisplay) {
strText += "SyncDisplay ";
- if (s.m_RenderSettings.bSynchronizeNearest)
+ }
+ if (s.m_RenderSettings.bSynchronizeNearest) {
strText += "SyncNearest ";
- if (m_bHighColorResolution)
+ }
+ if (m_bHighColorResolution) {
strText += "10 bit ";
- if (s.m_RenderSettings.iEVROutputRange == 0)
+ }
+ if (s.m_RenderSettings.iEVROutputRange == 0) {
strText += "0-255 ";
- else if (s.m_RenderSettings.iEVROutputRange == 1)
+ } else if (s.m_RenderSettings.iEVROutputRange == 1) {
strText += "16-235 ";
+ }
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
@@ -2208,10 +2126,8 @@ void CBaseAP::DrawStats()
DrawText(rc, strText, 1);
OffsetRect(&rc, 0, TextHeight);
- for (int i=0; i<6; i++)
- {
- if (m_strStatsMsg[i][0])
- {
+ for (int i=0; i<6; i++) {
+ if (m_strStatsMsg[i][0]) {
DrawText(rc, m_strStatsMsg[i], 1);
OffsetRect(&rc, 0, TextHeight);
}
@@ -2221,8 +2137,7 @@ void CBaseAP::DrawStats()
m_pSprite->End();
}
- if (m_pLine && (pApp->m_fDisplayStats < 3))
- {
+ if (m_pLine && (pApp->m_fDisplayStats < 3)) {
D3DXVECTOR2 Points[NB_JITTER];
int nIndex;
@@ -2237,8 +2152,7 @@ void CBaseAP::DrawStats()
m_pLine->SetAntialias(1);
m_pLine->Begin();
- for (int i = 0; i <= DrawHeight; i += 5)
- {
+ for (int i = 0; i <= DrawHeight; i += 5) {
Points[0].x = (FLOAT)StartX;
Points[0].y = (FLOAT)(StartY + i);
Points[1].x = (FLOAT)(StartX + ((i + 25) % 25 ? 50 : 625));
@@ -2246,8 +2160,7 @@ void CBaseAP::DrawStats()
m_pLine->Draw(Points, 2, D3DCOLOR_XRGB(100, 100, 255));
}
- for (int i = 0; i < DrawWidth; i += 125) // Every 25:th sample
- {
+ for (int i = 0; i < DrawWidth; i += 125) { // Every 25:th sample
Points[0].x = (FLOAT)(StartX + i);
Points[0].y = (FLOAT)(StartY + DrawHeight / 2);
Points[1].x = (FLOAT)(StartX + i);
@@ -2255,24 +2168,23 @@ void CBaseAP::DrawStats()
m_pLine->Draw(Points, 2, D3DCOLOR_XRGB(100, 100, 255));
}
- for (int i = 0; i < NB_JITTER; i++)
- {
+ for (int i = 0; i < NB_JITTER; i++) {
nIndex = (m_nNextJitter + 1 + i) % NB_JITTER;
- if (nIndex < 0)
+ if (nIndex < 0) {
nIndex += NB_JITTER;
+ }
double Jitter = m_pllJitter[nIndex] - m_fJitterMean;
Points[i].x = (FLOAT)(StartX + (i * 5));
Points[i].y = (FLOAT)(StartY + (Jitter / 2000.0 + 125.0));
}
m_pLine->Draw(Points, NB_JITTER, D3DCOLOR_XRGB(255, 100, 100));
- if (pApp->m_fDisplayStats == 1) // Full on-screen statistics
- {
- for (int i = 0; i < NB_JITTER; i++)
- {
+ if (pApp->m_fDisplayStats == 1) { // Full on-screen statistics
+ for (int i = 0; i < NB_JITTER; i++) {
nIndex = (m_nNextSyncOffset + 1 + i) % NB_JITTER;
- if (nIndex < 0)
+ if (nIndex < 0) {
nIndex += NB_JITTER;
+ }
Points[i].x = (FLOAT)(StartX + (i * 5));
Points[i].y = (FLOAT)(StartY + ((m_pllSyncOffset[nIndex]) / 2000 + 125));
}
@@ -2284,14 +2196,20 @@ void CBaseAP::DrawStats()
double CBaseAP::GetRefreshRate()
{
- if (m_pGenlock->powerstripTimingExists) return m_pGenlock->curDisplayFreq;
- else return (double)m_uD3DRefreshRate;
+ if (m_pGenlock->powerstripTimingExists) {
+ return m_pGenlock->curDisplayFreq;
+ } else {
+ return (double)m_uD3DRefreshRate;
+ }
}
double CBaseAP::GetDisplayCycle()
{
- if (m_pGenlock->powerstripTimingExists) return 1000.0 / m_pGenlock->curDisplayFreq;
- else return (double)m_dD3DRefreshCycle;
+ if (m_pGenlock->powerstripTimingExists) {
+ return 1000.0 / m_pGenlock->curDisplayFreq;
+ } else {
+ return (double)m_dD3DRefreshCycle;
+ }
}
double CBaseAP::GetCycleDifference()
@@ -2299,16 +2217,13 @@ double CBaseAP::GetCycleDifference()
double dBaseDisplayCycle = GetDisplayCycle();
UINT i;
double minDiff = 1.0;
- if (dBaseDisplayCycle == 0.0 || m_dFrameCycle == 0.0)
+ if (dBaseDisplayCycle == 0.0 || m_dFrameCycle == 0.0) {
return 1.0;
- else
- {
- for (i = 1; i <= 8; i++) // Try a lot of multiples of the display frequency
- {
+ } else {
+ for (i = 1; i <= 8; i++) { // Try a lot of multiples of the display frequency
double dDisplayCycle = i * dBaseDisplayCycle;
double diff = (dDisplayCycle - m_dFrameCycle) / m_dFrameCycle;
- if (abs(diff) < abs(minDiff))
- {
+ if (abs(diff) < abs(minDiff)) {
minDiff = diff;
m_dOptimumDisplayCycle = dDisplayCycle;
}
@@ -2319,13 +2234,16 @@ double CBaseAP::GetCycleDifference()
void CBaseAP::EstimateRefreshTimings()
{
- if (m_pD3DDev)
- {
+ if (m_pD3DDev) {
CRenderersData *pApp = GetRenderersData();
D3DRASTER_STATUS rasterStatus;
m_pD3DDev->GetRasterStatus(0, &rasterStatus);
- while (rasterStatus.ScanLine != 0) m_pD3DDev->GetRasterStatus(0, &rasterStatus);
- while (rasterStatus.ScanLine == 0) m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ while (rasterStatus.ScanLine != 0) {
+ m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ }
+ while (rasterStatus.ScanLine == 0) {
+ m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ }
m_pD3DDev->GetRasterStatus(0, &rasterStatus);
LONGLONG startTime = pApp->GetPerfCounter();
UINT startLine = rasterStatus.ScanLine;
@@ -2334,32 +2252,35 @@ void CBaseAP::EstimateRefreshTimings()
UINT endLine = 0;
UINT line = 0;
bool done = false;
- while (!done) // Estimate time for one scan line
- {
+ while (!done) { // Estimate time for one scan line
m_pD3DDev->GetRasterStatus(0, &rasterStatus);
line = rasterStatus.ScanLine;
time = pApp->GetPerfCounter();
- if (line > 0)
- {
+ if (line > 0) {
endLine = line;
endTime = time;
- }
- else
+ } else {
done = true;
+ }
}
m_dDetectedScanlineTime = (double)(endTime - startTime) / (double)((endLine - startLine) * 10000.0);
// Estimate the display refresh rate from the vsyncs
m_pD3DDev->GetRasterStatus(0, &rasterStatus);
- while (rasterStatus.ScanLine != 0) m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ while (rasterStatus.ScanLine != 0) {
+ m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ }
// Now we're at the start of a vsync
startTime = pApp->GetPerfCounter();
UINT i;
- for (i = 1; i <= 50; i++)
- {
+ for (i = 1; i <= 50; i++) {
m_pD3DDev->GetRasterStatus(0, &rasterStatus);
- while (rasterStatus.ScanLine == 0) m_pD3DDev->GetRasterStatus(0, &rasterStatus);
- while (rasterStatus.ScanLine != 0) m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ while (rasterStatus.ScanLine == 0) {
+ m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ }
+ while (rasterStatus.ScanLine != 0) {
+ m_pD3DDev->GetRasterStatus(0, &rasterStatus);
+ }
// Now we're at the next vsync
}
endTime = pApp->GetPerfCounter();
@@ -2369,16 +2290,17 @@ void CBaseAP::EstimateRefreshTimings()
bool CBaseAP::ExtractInterlaced(const AM_MEDIA_TYPE* pmt)
{
- if (pmt->formattype==FORMAT_VideoInfo)
+ if (pmt->formattype==FORMAT_VideoInfo) {
return false;
- else if (pmt->formattype==FORMAT_VideoInfo2)
+ } else if (pmt->formattype==FORMAT_VideoInfo2) {
return (((VIDEOINFOHEADER2*)pmt->pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced) != 0;
- else if (pmt->formattype==FORMAT_MPEGVideo)
+ } else if (pmt->formattype==FORMAT_MPEGVideo) {
return false;
- else if (pmt->formattype==FORMAT_MPEG2Video)
+ } else if (pmt->formattype==FORMAT_MPEG2Video) {
return (((MPEG2VIDEOINFO*)pmt->pbFormat)->hdr.dwInterlaceFlags & AMINTERLACE_IsInterlaced) != 0;
- else
+ } else {
return false;
+ }
}
STDMETHODIMP CBaseAP::GetDIB(BYTE* lpDib, DWORD* size)
@@ -2392,23 +2314,24 @@ STDMETHODIMP CBaseAP::GetDIB(BYTE* lpDib, DWORD* size)
m_pVideoSurface[m_nCurSurface]->GetDesc(&desc);
DWORD required = sizeof(BITMAPINFOHEADER) + (desc.Width * desc.Height * 32 >> 3);
- if(!lpDib)
- {
+ if(!lpDib) {
*size = required;
return S_OK;
}
- if(*size < required) return E_OUTOFMEMORY;
+ if(*size < required) {
+ return E_OUTOFMEMORY;
+ }
*size = required;
CComPtr<IDirect3DSurface9> pSurface = m_pVideoSurface[m_nCurSurface];
D3DLOCKED_RECT r;
- if(FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY)))
- {
+ if(FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY))) {
pSurface = NULL;
if(FAILED(hr = m_pD3DDev->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &pSurface, NULL))
|| FAILED(hr = m_pD3DDev->GetRenderTargetData(m_pVideoSurface[m_nCurSurface], pSurface))
- || FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY)))
+ || FAILED(hr = pSurface->LockRect(&r, NULL, D3DLOCK_READONLY))) {
return hr;
+ }
}
BITMAPINFOHEADER* bih = (BITMAPINFOHEADER*)lpDib;
@@ -2440,20 +2363,21 @@ STDMETHODIMP CBaseAP::SetPixelShader2(LPCSTR pSrcData, LPCSTR pTarget, bool bScr
CAutoLock cRenderLock(&m_allocatorLock);
CAtlList<CExternalPixelShader> *pPixelShaders;
- if (bScreenSpace)
+ if (bScreenSpace) {
pPixelShaders = &m_pPixelShadersScreenSpace;
- else
+ } else {
pPixelShaders = &m_pPixelShaders;
+ }
- if(!pSrcData && !pTarget)
- {
+ if(!pSrcData && !pTarget) {
pPixelShaders->RemoveAll();
m_pD3DDev->SetPixelShader(NULL);
return S_OK;
}
- if(!pSrcData || !pTarget)
+ if(!pSrcData || !pTarget) {
return E_INVALIDARG;
+ }
CExternalPixelShader Shader;
Shader.m_SourceData = pSrcData;
@@ -2462,8 +2386,9 @@ STDMETHODIMP CBaseAP::SetPixelShader2(LPCSTR pSrcData, LPCSTR pTarget, bool bScr
CComPtr<IDirect3DPixelShader9> pPixelShader;
HRESULT hr = Shader.Compile(m_pPSC);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
pPixelShaders->AddTail(Shader);
Paint(true);
@@ -2485,8 +2410,7 @@ CSyncAP::CSyncAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error): CBa
m_bEvtQuit = 0;
m_bEvtFlush = 0;
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
_Error += L"SyncAP failed\n";
return;
}
@@ -2501,16 +2425,19 @@ CSyncAP::CSyncAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error): CBa
pfMFCreateVideoSampleFromSurface = hLib ? (PTR_MFCreateVideoSampleFromSurface)GetProcAddress (hLib, "MFCreateVideoSampleFromSurface") : NULL;
pfMFCreateVideoMediaType = hLib ? (PTR_MFCreateVideoMediaType)GetProcAddress (hLib, "MFCreateVideoMediaType") : NULL;
- if (!pfDXVA2CreateDirect3DDeviceManager9 || !pfMFCreateDXSurfaceBuffer || !pfMFCreateVideoSampleFromSurface || !pfMFCreateVideoMediaType)
- {
- if (!pfDXVA2CreateDirect3DDeviceManager9)
+ if (!pfDXVA2CreateDirect3DDeviceManager9 || !pfMFCreateDXSurfaceBuffer || !pfMFCreateVideoSampleFromSurface || !pfMFCreateVideoMediaType) {
+ if (!pfDXVA2CreateDirect3DDeviceManager9) {
_Error += L"Could not find DXVA2CreateDirect3DDeviceManager9 (dxva2.dll)\n";
- if (!pfMFCreateDXSurfaceBuffer)
+ }
+ if (!pfMFCreateDXSurfaceBuffer) {
_Error += L"Could not find MFCreateDXSurfaceBuffer (evr.dll)\n";
- if (!pfMFCreateVideoSampleFromSurface)
+ }
+ if (!pfMFCreateVideoSampleFromSurface) {
_Error += L"Could not find MFCreateVideoSampleFromSurface (evr.dll)\n";
- if (!pfMFCreateVideoMediaType)
+ }
+ if (!pfMFCreateVideoMediaType) {
_Error += L"Could not find MFCreateVideoMediaType (evr.dll)\n";
+ }
hr = E_FAIL;
return;
}
@@ -2523,31 +2450,29 @@ CSyncAP::CSyncAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error): CBa
// Init DXVA manager
hr = pfDXVA2CreateDirect3DDeviceManager9(&m_nResetToken, &m_pD3DManager);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
hr = m_pD3DManager->ResetDevice(m_pD3DDev, m_nResetToken);
- if (!SUCCEEDED (hr))
- {
+ if (!SUCCEEDED (hr)) {
_Error += L"m_pD3DManager->ResetDevice failed\n";
}
- }
- else
+ } else {
_Error += L"DXVA2CreateDirect3DDeviceManager9 failed\n";
+ }
CComPtr<IDirectXVideoDecoderService> pDecoderService;
HANDLE hDevice;
if (SUCCEEDED (m_pD3DManager->OpenDeviceHandle(&hDevice)) &&
- SUCCEEDED (m_pD3DManager->GetVideoService (hDevice, __uuidof(IDirectXVideoDecoderService), (void**)&pDecoderService)))
- {
+ SUCCEEDED (m_pD3DManager->GetVideoService (hDevice, __uuidof(IDirectXVideoDecoderService), (void**)&pDecoderService))) {
HookDirectXVideoDecoderService (pDecoderService);
m_pD3DManager->CloseDeviceHandle (hDevice);
}
// Bufferize frame only with 3D texture
- if (s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D)
+ if (s.iAPSurfaceUsage == VIDRNDT_AP_TEXTURE3D) {
m_nDXSurface = max(min (s.iEvrBuffers, MAX_PICTURE_SLOTS-2), 4);
- else
+ } else {
m_nDXSurface = 1;
+ }
m_nRenderState = Shutdown;
m_bStepping = false;
@@ -2575,15 +2500,17 @@ CSyncAP::~CSyncAP(void)
HRESULT CSyncAP::CheckShutdown() const
{
- if (m_nRenderState == Shutdown) return MF_E_SHUTDOWN;
- else return S_OK;
+ if (m_nRenderState == Shutdown) {
+ return MF_E_SHUTDOWN;
+ } else {
+ return S_OK;
+ }
}
void CSyncAP::StartWorkerThreads()
{
DWORD dwThreadId;
- if (m_nRenderState == Shutdown)
- {
+ if (m_nRenderState == Shutdown) {
m_hEvtQuit = CreateEvent(NULL, TRUE, FALSE, NULL);
m_hEvtFlush = CreateEvent(NULL, TRUE, FALSE, NULL);
m_hEvtSkip = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -2597,30 +2524,37 @@ void CSyncAP::StartWorkerThreads()
void CSyncAP::StopWorkerThreads()
{
- if (m_nRenderState != Shutdown)
- {
+ if (m_nRenderState != Shutdown) {
SetEvent(m_hEvtFlush);
m_bEvtFlush = true;
SetEvent(m_hEvtQuit);
m_bEvtQuit = true;
SetEvent(m_hEvtSkip);
m_bEvtSkip = true;
- if ((m_hRenderThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hRenderThread, 10000) == WAIT_TIMEOUT))
- {
+ if ((m_hRenderThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hRenderThread, 10000) == WAIT_TIMEOUT)) {
ASSERT (FALSE);
TerminateThread (m_hRenderThread, 0xDEAD);
}
- if (m_hRenderThread != INVALID_HANDLE_VALUE) CloseHandle (m_hRenderThread);
- if ((m_hMixerThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hMixerThread, 10000) == WAIT_TIMEOUT))
- {
+ if (m_hRenderThread != INVALID_HANDLE_VALUE) {
+ CloseHandle (m_hRenderThread);
+ }
+ if ((m_hMixerThread != INVALID_HANDLE_VALUE) && (WaitForSingleObject (m_hMixerThread, 10000) == WAIT_TIMEOUT)) {
ASSERT (FALSE);
TerminateThread (m_hMixerThread, 0xDEAD);
}
- if (m_hMixerThread != INVALID_HANDLE_VALUE) CloseHandle (m_hMixerThread);
+ if (m_hMixerThread != INVALID_HANDLE_VALUE) {
+ CloseHandle (m_hMixerThread);
+ }
- if (m_hEvtFlush != INVALID_HANDLE_VALUE) CloseHandle(m_hEvtFlush);
- if (m_hEvtQuit != INVALID_HANDLE_VALUE) CloseHandle(m_hEvtQuit);
- if (m_hEvtSkip != INVALID_HANDLE_VALUE) CloseHandle(m_hEvtSkip);
+ if (m_hEvtFlush != INVALID_HANDLE_VALUE) {
+ CloseHandle(m_hEvtFlush);
+ }
+ if (m_hEvtQuit != INVALID_HANDLE_VALUE) {
+ CloseHandle(m_hEvtQuit);
+ }
+ if (m_hEvtSkip != INVALID_HANDLE_VALUE) {
+ CloseHandle(m_hEvtSkip);
+ }
m_bEvtFlush = false;
m_bEvtQuit = false;
@@ -2635,8 +2569,7 @@ STDMETHODIMP CSyncAP::CreateRenderer(IUnknown** ppRenderer)
*ppRenderer = NULL;
HRESULT hr = E_FAIL;
- do
- {
+ do {
CMacrovisionKicker* pMK = DNew CMacrovisionKicker(NAME("CMacrovisionKicker"), NULL);
CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)pMK;
@@ -2646,7 +2579,9 @@ STDMETHODIMP CSyncAP::CreateRenderer(IUnknown** ppRenderer)
pMK->SetInner((IUnknown*)(INonDelegatingUnknown*)pOuterEVR);
CComQIPtr<IBaseFilter> pBF = pUnk;
- if (FAILED(hr)) break;
+ if (FAILED(hr)) {
+ break;
+ }
// Set EVR custom presenter
CComPtr<IMFVideoPresenter> pVP;
@@ -2655,19 +2590,23 @@ STDMETHODIMP CSyncAP::CreateRenderer(IUnknown** ppRenderer)
hr = pMFGS->GetService (MR_VIDEO_RENDER_SERVICE, IID_IMFVideoRenderer, (void**)&pMFVR);
- if(SUCCEEDED(hr)) hr = QueryInterface(__uuidof(IMFVideoPresenter), (void**)&pVP);
- if(SUCCEEDED(hr)) hr = pMFVR->InitializeRenderer(NULL, pVP);
+ if(SUCCEEDED(hr)) {
+ hr = QueryInterface(__uuidof(IMFVideoPresenter), (void**)&pVP);
+ }
+ if(SUCCEEDED(hr)) {
+ hr = pMFVR->InitializeRenderer(NULL, pVP);
+ }
CComPtr<IPin> pPin = GetFirstPin(pBF);
CComQIPtr<IMemInputPin> pMemInputPin = pPin;
m_bUseInternalTimer = HookNewSegmentAndReceive((IPinC*)(IPin*)pPin, (IMemInputPinC*)(IMemInputPin*)pMemInputPin);
- if(FAILED(hr))
+ if(FAILED(hr)) {
*ppRenderer = NULL;
- else
+ } else {
*ppRenderer = pBF.Detach();
- }
- while (0);
+ }
+ } while (0);
return hr;
}
@@ -2680,32 +2619,33 @@ STDMETHODIMP_(bool) CSyncAP::Paint(bool fAll)
STDMETHODIMP CSyncAP::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
HRESULT hr;
- if(riid == __uuidof(IMFClockStateSink))
+ if(riid == __uuidof(IMFClockStateSink)) {
hr = GetInterface((IMFClockStateSink*)this, ppv);
- else if(riid == __uuidof(IMFVideoPresenter))
+ } else if(riid == __uuidof(IMFVideoPresenter)) {
hr = GetInterface((IMFVideoPresenter*)this, ppv);
- else if(riid == __uuidof(IMFTopologyServiceLookupClient))
+ } else if(riid == __uuidof(IMFTopologyServiceLookupClient)) {
hr = GetInterface((IMFTopologyServiceLookupClient*)this, ppv);
- else if(riid == __uuidof(IMFVideoDeviceID))
+ } else if(riid == __uuidof(IMFVideoDeviceID)) {
hr = GetInterface((IMFVideoDeviceID*)this, ppv);
- else if(riid == __uuidof(IMFGetService))
+ } else if(riid == __uuidof(IMFGetService)) {
hr = GetInterface((IMFGetService*)this, ppv);
- else if(riid == __uuidof(IMFAsyncCallback))
+ } else if(riid == __uuidof(IMFAsyncCallback)) {
hr = GetInterface((IMFAsyncCallback*)this, ppv);
- else if(riid == __uuidof(IMFVideoDisplayControl))
+ } else if(riid == __uuidof(IMFVideoDisplayControl)) {
hr = GetInterface((IMFVideoDisplayControl*)this, ppv);
- else if(riid == __uuidof(IEVRTrustedVideoPlugin))
+ } else if(riid == __uuidof(IEVRTrustedVideoPlugin)) {
hr = GetInterface((IEVRTrustedVideoPlugin*)this, ppv);
- else if(riid == IID_IQualProp)
+ } else if(riid == IID_IQualProp) {
hr = GetInterface((IQualProp*)this, ppv);
- else if(riid == __uuidof(IMFRateSupport))
+ } else if(riid == __uuidof(IMFRateSupport)) {
hr = GetInterface((IMFRateSupport*)this, ppv);
- else if(riid == __uuidof(IDirect3DDeviceManager9))
+ } else if(riid == __uuidof(IDirect3DDeviceManager9)) {
hr = m_pD3DManager->QueryInterface (__uuidof(IDirect3DDeviceManager9), (void**) ppv);
- else if(riid == __uuidof(ISyncClockAdviser))
+ } else if(riid == __uuidof(ISyncClockAdviser)) {
hr = GetInterface((ISyncClockAdviser*)this, ppv);
- else
+ } else {
hr = __super::NonDelegatingQueryInterface(riid, ppv);
+ }
return hr;
}
@@ -2744,20 +2684,19 @@ STDMETHODIMP CSyncAP::OnClockSetRate(MFTIME hnsSystemTime, float flRate)
bool CSyncAP::GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *State, HRESULT &_ReturnValue)
{
CAutoLock lock(&m_SampleQueueLock);
- switch(m_nRenderState)
- {
- case Started:
- *State = State_Running;
- break;
- case Paused:
- *State = State_Paused;
- break;
- case Stopped:
- *State = State_Stopped;
- break;
- default:
- *State = State_Stopped;
- _ReturnValue = E_FAIL;
+ switch(m_nRenderState) {
+ case Started:
+ *State = State_Running;
+ break;
+ case Paused:
+ *State = State_Paused;
+ break;
+ case Stopped:
+ *State = State_Stopped;
+ break;
+ default:
+ *State = State_Stopped;
+ _ReturnValue = E_FAIL;
}
_ReturnValue = S_OK;
return true;
@@ -2816,8 +2755,9 @@ STDMETHODIMP CSyncAP::GetFastestRate(MFRATE_DIRECTION eDirection, BOOL fThin, fl
fMaxRate = GetMaxRate(fThin);
// For reverse playback, swap the sign.
- if (eDirection == MFRATE_REVERSE)
+ if (eDirection == MFRATE_REVERSE) {
fMaxRate = -fMaxRate;
+ }
*pflRate = fMaxRate;
return hr;
@@ -2838,21 +2778,21 @@ STDMETHODIMP CSyncAP::IsRateSupported(BOOL fThin, float flRate, float *pflNeares
// Find the maximum forward rate.
fMaxRate = GetMaxRate(fThin);
- if (fabsf(flRate) > fMaxRate)
- {
+ if (fabsf(flRate) > fMaxRate) {
// The (absolute) requested rate exceeds the maximum rate.
hr = MF_E_UNSUPPORTED_RATE;
// The nearest supported rate is fMaxRate.
fNearestRate = fMaxRate;
- if (flRate < 0)
- {
+ if (flRate < 0) {
// For reverse playback, swap the sign.
fNearestRate = -fNearestRate;
}
}
// Return the nearest supported rate if the caller requested it.
- if (pflNearestSupportedRate != NULL) *pflNearestSupportedRate = fNearestRate;
+ if (pflNearestSupportedRate != NULL) {
+ *pflNearestSupportedRate = fNearestRate;
+ }
return hr;
}
@@ -2862,8 +2802,7 @@ float CSyncAP::GetMaxRate(BOOL bThin)
UINT32 fpsNumerator = 0, fpsDenominator = 0;
UINT MonitorRateHz = 0;
- if (!bThin && (m_pMediaType != NULL))
- {
+ if (!bThin && (m_pMediaType != NULL)) {
// Non-thinned: Use the frame rate and monitor refresh rate.
// Frame rate:
@@ -2873,8 +2812,7 @@ float CSyncAP::GetMaxRate(BOOL bThin)
// Monitor refresh rate:
MonitorRateHz = m_uD3DRefreshRate; // D3DDISPLAYMODE
- if (fpsDenominator && fpsNumerator && MonitorRateHz)
- {
+ if (fpsDenominator && fpsNumerator && MonitorRateHz) {
// Max Rate = Refresh Rate / Frame Rate
fMaxRate = (float)MulDiv(MonitorRateHz, fpsDenominator, fpsNumerator);
}
@@ -2884,15 +2822,13 @@ float CSyncAP::GetMaxRate(BOOL bThin)
void CSyncAP::CompleteFrameStep(bool bCancel)
{
- if (m_nStepCount > 0)
- {
- if (bCancel || (m_nStepCount == 1))
- {
+ if (m_nStepCount > 0) {
+ if (bCancel || (m_nStepCount == 1)) {
m_pSink->Notify(EC_STEP_COMPLETE, bCancel ? TRUE : FALSE, 0);
m_nStepCount = 0;
- }
- else
+ } else {
m_nStepCount--;
+ }
}
}
@@ -2901,51 +2837,54 @@ STDMETHODIMP CSyncAP::ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulPar
{
HRESULT hr = S_OK;
- switch (eMessage)
- {
- case MFVP_MESSAGE_BEGINSTREAMING:
- hr = BeginStreaming();
- m_llHysteresis = 0;
- m_lShiftToNearest = 0;
- m_bStepping = false;
- break;
-
- case MFVP_MESSAGE_CANCELSTEP:
- m_bStepping = false;
- CompleteFrameStep(true);
- break;
-
- case MFVP_MESSAGE_ENDOFSTREAM:
- m_bPendingMediaFinished = true;
- break;
-
- case MFVP_MESSAGE_ENDSTREAMING:
- m_pGenlock->ResetTiming();
- m_pRefClock = NULL;
- break;
-
- case MFVP_MESSAGE_FLUSH:
- SetEvent(m_hEvtFlush);
- m_bEvtFlush = true;
- while (WaitForSingleObject(m_hEvtFlush, 1) == WAIT_OBJECT_0);
- break;
+ switch (eMessage) {
+ case MFVP_MESSAGE_BEGINSTREAMING:
+ hr = BeginStreaming();
+ m_llHysteresis = 0;
+ m_lShiftToNearest = 0;
+ m_bStepping = false;
+ break;
- case MFVP_MESSAGE_INVALIDATEMEDIATYPE:
- m_bPendingRenegotiate = true;
- while (*((volatile bool *)&m_bPendingRenegotiate)) Sleep(1);
- break;
+ case MFVP_MESSAGE_CANCELSTEP:
+ m_bStepping = false;
+ CompleteFrameStep(true);
+ break;
- case MFVP_MESSAGE_PROCESSINPUTNOTIFY:
- break;
+ case MFVP_MESSAGE_ENDOFSTREAM:
+ m_bPendingMediaFinished = true;
+ break;
+
+ case MFVP_MESSAGE_ENDSTREAMING:
+ m_pGenlock->ResetTiming();
+ m_pRefClock = NULL;
+ break;
+
+ case MFVP_MESSAGE_FLUSH:
+ SetEvent(m_hEvtFlush);
+ m_bEvtFlush = true;
+ while (WaitForSingleObject(m_hEvtFlush, 1) == WAIT_OBJECT_0) {
+ ;
+ }
+ break;
- case MFVP_MESSAGE_STEP:
- m_nStepCount = ulParam;
- m_bStepping = true;
- break;
+ case MFVP_MESSAGE_INVALIDATEMEDIATYPE:
+ m_bPendingRenegotiate = true;
+ while (*((volatile bool *)&m_bPendingRenegotiate)) {
+ Sleep(1);
+ }
+ break;
+
+ case MFVP_MESSAGE_PROCESSINPUTNOTIFY:
+ break;
- default :
- ASSERT(FALSE);
- break;
+ case MFVP_MESSAGE_STEP:
+ m_nStepCount = ulParam;
+ m_bStepping = true;
+ break;
+
+ default :
+ ASSERT(FALSE);
+ break;
}
return hr;
}
@@ -2959,7 +2898,9 @@ HRESULT CSyncAP::IsMediaTypeSupported(IMFMediaType* pMixerType)
CheckHR (pMixerType->GetRepresentation(FORMAT_VideoInfo2, (void**)&pAMMedia));
CheckHR (pMixerType->GetUINT32 (MF_MT_INTERLACE_MODE, &nInterlaceMode));
- if ( (pAMMedia->majortype != MEDIATYPE_Video)) hr = MF_E_INVALIDMEDIATYPE;
+ if ( (pAMMedia->majortype != MEDIATYPE_Video)) {
+ hr = MF_E_INVALIDMEDIATYPE;
+ }
pMixerType->FreeRepresentation(FORMAT_VideoInfo2, (void*)pAMMedia);
return hr;
}
@@ -2979,18 +2920,18 @@ HRESULT CSyncAP::CreateProposedOutputType(IMFMediaType* pMixerType, IMFMediaType
m_AspectRatio.cx = VideoFormat->videoInfo.PixelAspectRatio.Numerator;
m_AspectRatio.cy = VideoFormat->videoInfo.PixelAspectRatio.Denominator;
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
i64Size.HighPart = VideoFormat->videoInfo.dwWidth;
i64Size.LowPart = VideoFormat->videoInfo.dwHeight;
m_pMediaType->SetUINT64(MF_MT_FRAME_SIZE, i64Size.QuadPart);
m_pMediaType->SetUINT32(MF_MT_PAN_SCAN_ENABLED, 0);
CRenderersSettings& s = GetRenderersSettings();
- if (s.m_RenderSettings.iEVROutputRange == 1)
+ if (s.m_RenderSettings.iEVROutputRange == 1) {
m_pMediaType->SetUINT32(MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_16_235);
- else
+ } else {
m_pMediaType->SetUINT32(MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_0_255);
+ }
m_LastSetOutputRange = s.m_RenderSettings.iEVROutputRange;
i64Size.HighPart = m_AspectRatio.cx;
@@ -3006,20 +2947,17 @@ HRESULT CSyncAP::CreateProposedOutputType(IMFMediaType* pMixerType, IMFMediaType
bool bDoneSomething = true;
- if(m_AspectRatio.cx >= 1 && m_AspectRatio.cy >= 1)
- {
- while (bDoneSomething)
- {
+ if(m_AspectRatio.cx >= 1 && m_AspectRatio.cy >= 1) {
+ while (bDoneSomething) {
bDoneSomething = false;
INT MinNum = min(m_AspectRatio.cx, m_AspectRatio.cy);
INT i;
- for (i = 2; i < MinNum+1; ++i)
- {
- if (m_AspectRatio.cx%i == 0 && m_AspectRatio.cy%i ==0)
+ for (i = 2; i < MinNum+1; ++i) {
+ if (m_AspectRatio.cx%i == 0 && m_AspectRatio.cy%i ==0) {
break;
+ }
}
- if (i != MinNum + 1)
- {
+ if (i != MinNum + 1) {
m_AspectRatio.cx = m_AspectRatio.cx / i;
m_AspectRatio.cy = m_AspectRatio.cy / i;
bDoneSomething = true;
@@ -3043,8 +2981,7 @@ HRESULT CSyncAP::SetMediaType(IMFMediaType* pType)
CheckHR(pType->GetRepresentation(FORMAT_VideoInfo2, (void**)&pAMMedia));
hr = InitializeDevice(pAMMedia);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
strTemp = GetMediaTypeName(pAMMedia->subtype);
strTemp.Replace(L"MEDIASUBTYPE_", L"");
m_strStatsMsg[MSG_MIXEROUT].Format (L"Mixer output: %s", strTemp);
@@ -3055,8 +2992,7 @@ HRESULT CSyncAP::SetMediaType(IMFMediaType* pType)
return hr;
}
-typedef struct
-{
+typedef struct {
const int Format;
const LPCTSTR Description;
} D3DFORMAT_TYPE;
@@ -3071,30 +3007,29 @@ LONGLONG CSyncAP::GetMediaTypeMerit(IMFMediaType *pMediaType)
VideoFormat = (MFVIDEOFORMAT*)pAMMedia->pbFormat;
LONGLONG Merit = 0;
- switch (VideoFormat->surfaceInfo.Format)
- {
- case FCC('NV12'):
- Merit = 90000000;
- break;
- case FCC('YV12'):
- Merit = 80000000;
- break;
- case FCC('YUY2'):
- Merit = 70000000;
- break;
- case FCC('UYVY'):
- Merit = 60000000;
- break;
-
- case D3DFMT_X8R8G8B8: // Never opt for RGB
- case D3DFMT_A8R8G8B8:
- case D3DFMT_R8G8B8:
- case D3DFMT_R5G6B5:
- Merit = 0;
- break;
- default:
- Merit = 1000;
- break;
+ switch (VideoFormat->surfaceInfo.Format) {
+ case FCC('NV12'):
+ Merit = 90000000;
+ break;
+ case FCC('YV12'):
+ Merit = 80000000;
+ break;
+ case FCC('YUY2'):
+ Merit = 70000000;
+ break;
+ case FCC('UYVY'):
+ Merit = 60000000;
+ break;
+
+ case D3DFMT_X8R8G8B8: // Never opt for RGB
+ case D3DFMT_A8R8G8B8:
+ case D3DFMT_R8G8B8:
+ case D3DFMT_R5G6B5:
+ Merit = 0;
+ break;
+ default:
+ Merit = 1000;
+ break;
}
pMediaType->FreeRepresentation(FORMAT_MFVideoFormat, (void*)pAMMedia);
return Merit;
@@ -3107,72 +3042,68 @@ HRESULT CSyncAP::RenegotiateMediaType()
CComPtr<IMFMediaType> pMixerType;
CComPtr<IMFMediaType> pType;
- if (!m_pMixer) return MF_E_INVALIDREQUEST;
+ if (!m_pMixer) {
+ return MF_E_INVALIDREQUEST;
+ }
CInterfaceArray<IMFMediaType> ValidMixerTypes;
// Loop through all of the mixer's proposed output types.
DWORD iTypeIndex = 0;
- while ((hr != MF_E_NO_MORE_TYPES))
- {
+ while ((hr != MF_E_NO_MORE_TYPES)) {
pMixerType = NULL;
pType = NULL;
m_pMediaType = NULL;
// Step 1. Get the next media type supported by mixer.
hr = m_pMixer->GetOutputAvailableType(0, iTypeIndex++, &pMixerType);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
break;
}
// Step 2. Check if we support this media type.
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = IsMediaTypeSupported(pMixerType);
- if (SUCCEEDED(hr))
+ }
+ if (SUCCEEDED(hr)) {
hr = CreateProposedOutputType(pMixerType, &pType);
+ }
// Step 4. Check if the mixer will accept this media type.
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr)) {
hr = m_pMixer->SetOutputType(0, pType, MFT_SET_TYPE_TEST_ONLY);
- if (SUCCEEDED(hr))
- {
+ }
+ if (SUCCEEDED(hr)) {
LONGLONG Merit = GetMediaTypeMerit(pType);
int nTypes = ValidMixerTypes.GetCount();
int iInsertPos = 0;
- for (int i = 0; i < nTypes; ++i)
- {
+ for (int i = 0; i < nTypes; ++i) {
LONGLONG ThisMerit = GetMediaTypeMerit(ValidMixerTypes[i]);
- if (Merit > ThisMerit)
- {
+ if (Merit > ThisMerit) {
iInsertPos = i;
break;
- }
- else
+ } else {
iInsertPos = i+1;
+ }
}
ValidMixerTypes.InsertAt(iInsertPos, pType);
}
}
int nValidTypes = ValidMixerTypes.GetCount();
- for (int i = 0; i < nValidTypes; ++i)
- {
+ for (int i = 0; i < nValidTypes; ++i) {
pType = ValidMixerTypes[i];
}
- for (int i = 0; i < nValidTypes; ++i)
- {
+ for (int i = 0; i < nValidTypes; ++i) {
pType = ValidMixerTypes[i];
hr = SetMediaType(pType);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = m_pMixer->SetOutputType(0, pType, 0);
// If something went wrong, clear the media type.
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
SetMediaType(NULL);
- }
- else
+ } else {
break;
+ }
}
}
@@ -3193,12 +3124,10 @@ bool CSyncAP::GetSampleFromMixer()
UINT dwSurface;
bool newSample = false;
- while(SUCCEEDED(hr)) // Get as many frames as there are and that we have samples for
- {
+ while(SUCCEEDED(hr)) { // Get as many frames as there are and that we have samples for
CComPtr<IMFSample> pSample;
CComPtr<IMFSample> pNewSample;
- if (FAILED(GetFreeSample(&pSample))) // All samples are taken for the moment. Better luck next time
- {
+ if (FAILED(GetFreeSample(&pSample))) { // All samples are taken for the moment. Better luck next time
break;
}
@@ -3211,21 +3140,18 @@ bool CSyncAP::GetSampleFromMixer()
llClockAfter = GetRenderersData()->GetPerfCounter();
}
- if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) // There are no samples left in the mixer
- {
+ if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT) { // There are no samples left in the mixer
MoveToFreeList(pSample, false);
break;
}
- if (m_pSink)
- {
+ if (m_pSink) {
llMixerLatency = llClockAfter - llClockBefore;
m_pSink->Notify (EC_PROCESSING_LATENCY, (LONG_PTR)&llMixerLatency, 0);
}
newSample = true;
- if (GetRenderersData()->m_fTearingTest)
- {
+ if (GetRenderersData()->m_fTearingTest) {
RECT rcTearing;
rcTearing.left = m_nTearingPos;
@@ -3251,8 +3177,9 @@ STDMETHODIMP CSyncAP::GetCurrentMediaType(__deref_out IMFVideoMediaType **ppMed
CheckPointer(ppMediaType, E_POINTER);
CheckHR(CheckShutdown());
- if (m_pMediaType == NULL)
+ if (m_pMediaType == NULL) {
CheckHR(MF_E_NOT_INITIALIZED);
+ }
CheckHR(m_pMediaType->QueryInterface(__uuidof(IMFVideoMediaType), (void**)&ppMediaType));
return hr;
@@ -3290,10 +3217,11 @@ STDMETHODIMP CSyncAP::GetDeviceID( __out IID *pDeviceID)
// IMFGetService
STDMETHODIMP CSyncAP::GetService( __RPC__in REFGUID guidService, __RPC__in REFIID riid, __RPC__deref_out_opt LPVOID *ppvObject)
{
- if (guidService == MR_VIDEO_RENDER_SERVICE)
+ if (guidService == MR_VIDEO_RENDER_SERVICE) {
return NonDelegatingQueryInterface (riid, ppvObject);
- else if (guidService == MR_VIDEO_ACCELERATION_SERVICE)
+ } else if (guidService == MR_VIDEO_ACCELERATION_SERVICE) {
return m_pD3DManager->QueryInterface (__uuidof(IDirect3DDeviceManager9), (void**) ppvObject);
+ }
return E_NOINTERFACE;
}
@@ -3313,13 +3241,11 @@ STDMETHODIMP CSyncAP::Invoke( __RPC__in_opt IMFAsyncResult *pAsyncResult)
// IMFVideoDisplayControl
STDMETHODIMP CSyncAP::GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo)
{
- if (pszVideo)
- {
+ if (pszVideo) {
pszVideo->cx = m_NativeVideoSize.cx;
pszVideo->cy = m_NativeVideoSize.cy;
}
- if (pszARVideo)
- {
+ if (pszARVideo) {
pszARVideo->cx = m_NativeVideoSize.cx * m_AspectRatio.cx;
pszARVideo->cy = m_NativeVideoSize.cy * m_AspectRatio.cy;
}
@@ -3328,19 +3254,16 @@ STDMETHODIMP CSyncAP::GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo)
STDMETHODIMP CSyncAP::GetIdealVideoSize(SIZE *pszMin, SIZE *pszMax)
{
- if (pszMin)
- {
+ if (pszMin) {
pszMin->cx = 1;
pszMin->cy = 1;
}
- if (pszMax)
- {
+ if (pszMax) {
D3DDISPLAYMODE d3ddm;
ZeroMemory(&d3ddm, sizeof(d3ddm));
- if(SUCCEEDED(m_pD3D->GetAdapterDisplayMode(GetAdapter(m_pD3D), &d3ddm)))
- {
+ if(SUCCEEDED(m_pD3D->GetAdapterDisplayMode(GetAdapter(m_pD3D), &d3ddm))) {
pszMax->cx = d3ddm.Width;
pszMax->cy = d3ddm.Height;
}
@@ -3353,15 +3276,15 @@ STDMETHODIMP CSyncAP::SetVideoPosition(const MFVideoNormalizedRect *pnrcSource,
}
STDMETHODIMP CSyncAP::GetVideoPosition(MFVideoNormalizedRect *pnrcSource, LPRECT prcDest)
{
- if (pnrcSource)
- {
+ if (pnrcSource) {
pnrcSource->left = 0.0;
pnrcSource->top = 0.0;
pnrcSource->right = 1.0;
pnrcSource->bottom = 1.0;
}
- if (prcDest)
- memcpy (prcDest, &m_VideoRect, sizeof(m_VideoRect));//GetClientRect (m_hWnd, prcDest);
+ if (prcDest) {
+ memcpy (prcDest, &m_VideoRect, sizeof(m_VideoRect)); //GetClientRect (m_hWnd, prcDest);
+ }
return S_OK;
}
STDMETHODIMP CSyncAP::SetAspectRatioMode(DWORD dwAspectRatioMode)
@@ -3495,15 +3418,12 @@ STDMETHODIMP CSyncAP::GetVideoService(HANDLE hDevice, REFIID riid, void **ppServ
{
HRESULT hr = m_pD3DManager->GetVideoService(hDevice, riid, ppService);
- if (riid == __uuidof(IDirectXVideoDecoderService))
- {
+ if (riid == __uuidof(IDirectXVideoDecoderService)) {
UINT nNbDecoder = 5;
GUID* pDecoderGuid;
IDirectXVideoDecoderService* pDXVAVideoDecoder = (IDirectXVideoDecoderService*) *ppService;
pDXVAVideoDecoder->GetDecoderDeviceGuids (&nNbDecoder, &pDecoderGuid);
- }
- else if (riid == __uuidof(IDirectXVideoProcessorService))
- {
+ } else if (riid == __uuidof(IDirectXVideoProcessorService)) {
IDirectXVideoProcessorService* pDXVAProcessor = (IDirectXVideoProcessorService*) *ppService;
UNUSED_ALWAYS(pDXVAProcessor);
}
@@ -3516,10 +3436,18 @@ STDMETHODIMP CSyncAP::GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lp
// This function should be called...
ASSERT (FALSE);
- if(lpWidth) *lpWidth = m_NativeVideoSize.cx;
- if(lpHeight) *lpHeight = m_NativeVideoSize.cy;
- if(lpARWidth) *lpARWidth = m_AspectRatio.cx;
- if(lpARHeight) *lpARHeight = m_AspectRatio.cy;
+ if(lpWidth) {
+ *lpWidth = m_NativeVideoSize.cx;
+ }
+ if(lpHeight) {
+ *lpHeight = m_NativeVideoSize.cy;
+ }
+ if(lpARWidth) {
+ *lpARWidth = m_AspectRatio.cx;
+ }
+ if(lpARHeight) {
+ *lpARHeight = m_AspectRatio.cy;
+ }
return S_OK;
}
@@ -3538,17 +3466,16 @@ STDMETHODIMP CSyncAP::InitializeDevice(AM_MEDIA_TYPE* pMediaType)
int h = abs(vih2->bmiHeader.biHeight);
m_NativeVideoSize = CSize(w, h);
- if (m_bHighColorResolution)
+ if (m_bHighColorResolution) {
hr = AllocSurfaces(D3DFMT_A2R10G10B10);
- else
+ } else {
hr = AllocSurfaces(D3DFMT_X8R8G8B8);
+ }
- for(int i = 0; i < m_nDXSurface; i++)
- {
+ for(int i = 0; i < m_nDXSurface; i++) {
CComPtr<IMFSample> pMFSample;
hr = pfMFCreateVideoSampleFromSurface(m_pVideoSurface[i], &pMFSample);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
pMFSample->SetUINT32(GUID_SURFACE_INDEX, i);
m_FreeSamples.AddTail (pMFSample);
}
@@ -3577,27 +3504,23 @@ void CSyncAP::MixerThread()
dwResolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
dwUser = timeBeginPeriod(dwResolution);
- while (!bQuit)
- {
+ while (!bQuit) {
DWORD dwObject = WaitForMultipleObjects (countof(hEvts), hEvts, FALSE, 1);
- switch (dwObject)
- {
- case WAIT_OBJECT_0 :
- bQuit = true;
- break;
- case WAIT_TIMEOUT :
- {
- bool bNewSample = false;
- {
- CAutoLock AutoLock(&m_ImageProcessingLock);
- bNewSample = GetSampleFromMixer();
- }
- if(m_bUseInternalTimer && m_pSubPicQueue)
- {
- m_pSubPicQueue->SetFPS(m_fps);
+ switch (dwObject) {
+ case WAIT_OBJECT_0 :
+ bQuit = true;
+ break;
+ case WAIT_TIMEOUT : {
+ bool bNewSample = false;
+ {
+ CAutoLock AutoLock(&m_ImageProcessingLock);
+ bNewSample = GetSampleFromMixer();
+ }
+ if(m_bUseInternalTimer && m_pSubPicQueue) {
+ m_pSubPicQueue->SetFPS(m_fps);
+ }
}
- }
- break;
+ break;
}
}
timeEndPeriod (dwResolution);
@@ -3627,11 +3550,12 @@ void CSyncAP::RenderThread()
// Tell Vista Multimedia Class Scheduler we are doing threaded playback (increase priority)
HANDLE hAvrt = 0;
- if (pfAvSetMmThreadCharacteristicsW)
- {
+ if (pfAvSetMmThreadCharacteristicsW) {
DWORD dwTaskIndex = 0;
hAvrt = pfAvSetMmThreadCharacteristicsW (L"Playback", &dwTaskIndex);
- if (pfAvSetMmThreadPriority) pfAvSetMmThreadPriority (hAvrt, AVRT_PRIORITY_HIGH);
+ if (pfAvSetMmThreadPriority) {
+ pfAvSetMmThreadPriority (hAvrt, AVRT_PRIORITY_HIGH);
+ }
}
// Set timer resolution
@@ -3640,8 +3564,7 @@ void CSyncAP::RenderThread()
dwUser = timeBeginPeriod(dwResolution);
pNewSample = NULL;
- while (!bQuit)
- {
+ while (!bQuit) {
m_lNextSampleWait = 1; // Default value for running this loop
nSamplesLeft = 0;
bool stepForward = false;
@@ -3652,47 +3575,38 @@ void CSyncAP::RenderThread()
CRenderersSettings& s = GetRenderersSettings();
dTargetSyncOffset = s.m_RenderSettings.fTargetSyncOffset;
- if ((m_nRenderState == Started || !m_bPrerolled) && !pNewSample) // If either streaming or the pre-roll sample and no sample yet fetched
- {
- if (SUCCEEDED(GetScheduledSample(&pNewSample, nSamplesLeft))) // Get the next sample
- {
+ if ((m_nRenderState == Started || !m_bPrerolled) && !pNewSample) { // If either streaming or the pre-roll sample and no sample yet fetched
+ if (SUCCEEDED(GetScheduledSample(&pNewSample, nSamplesLeft))) { // Get the next sample
m_llLastSampleTime = m_llSampleTime;
- if (!m_bPrerolled)
- {
+ if (!m_bPrerolled) {
m_bPrerolled = true; // m_bPrerolled is a ticket to show one (1) frame immediately
m_lNextSampleWait = 0; // Present immediately
- }
- else if (SUCCEEDED(pNewSample->GetSampleTime(&m_llSampleTime))) // Get zero-based sample due time
- {
- if (m_llLastSampleTime == m_llSampleTime) // In the rare case there are duplicate frames in the movie. There really shouldn't be but it happens.
- {
+ } else if (SUCCEEDED(pNewSample->GetSampleTime(&m_llSampleTime))) { // Get zero-based sample due time
+ if (m_llLastSampleTime == m_llSampleTime) { // In the rare case there are duplicate frames in the movie. There really shouldn't be but it happens.
MoveToFreeList(pNewSample, true);
pNewSample = NULL;
m_lNextSampleWait = 0;
- }
- else
- {
+ } else {
m_pClock->GetCorrelatedTime(0, &llRefClockTime, &llSystemTime); // Get zero-based reference clock time. llSystemTime is not used for anything here
m_lNextSampleWait = (LONG)((m_llSampleTime - llRefClockTime) / 10000); // Time left until sample is due, in ms
- if (m_bStepping)
- {
+ if (m_bStepping) {
m_lNextSampleWait = 0;
- }
- else if (s.m_RenderSettings.bSynchronizeNearest) // Present at the closest "safe" occasion at dTargetSyncOffset ms before vsync to avoid tearing
- {
- if (m_lNextSampleWait < -lDisplayCycle) // We have to allow slightly negative numbers at this stage. Otherwise we get "choking" when frame rate > refresh rate
- {
+ } else if (s.m_RenderSettings.bSynchronizeNearest) { // Present at the closest "safe" occasion at dTargetSyncOffset ms before vsync to avoid tearing
+ if (m_lNextSampleWait < -lDisplayCycle) { // We have to allow slightly negative numbers at this stage. Otherwise we get "choking" when frame rate > refresh rate
SetEvent(m_hEvtSkip);
m_bEvtSkip = true;
}
REFERENCE_TIME rtRefClockTimeNow;
- if (m_pRefClock) m_pRefClock->GetTime(&rtRefClockTimeNow); // Reference clock time now
+ if (m_pRefClock) {
+ m_pRefClock->GetTime(&rtRefClockTimeNow); // Reference clock time now
+ }
LONG lLastVsyncTime = (LONG)((m_llEstVBlankTime - rtRefClockTimeNow) / 10000); // Last vsync time relative to now
- if (abs(lLastVsyncTime) > lDisplayCycle) lLastVsyncTime = - lDisplayCycle; // To even out glitches in the beginning
+ if (abs(lLastVsyncTime) > lDisplayCycle) {
+ lLastVsyncTime = - lDisplayCycle; // To even out glitches in the beginning
+ }
LONGLONG llNextSampleWait = (LONGLONG)(((double)lLastVsyncTime + GetDisplayCycle() - dTargetSyncOffset) * 10000); // Time from now util next safe time to Paint()
- while ((llRefClockTime + llNextSampleWait) < (m_llSampleTime + m_llHysteresis)) // While the proposed time is in the past of sample presentation time
- {
+ while ((llRefClockTime + llNextSampleWait) < (m_llSampleTime + m_llHysteresis)) { // While the proposed time is in the past of sample presentation time
llNextSampleWait = llNextSampleWait + (LONGLONG)(GetDisplayCycle() * 10000); // Try the next possible time, one display cycle ahead
}
m_lNextSampleWait = (LONG)(llNextSampleWait / 10000);
@@ -3702,8 +3616,7 @@ void CSyncAP::RenderThread()
// If m_lShiftToNearest is pushed a whole cycle into the future, then we are getting more frames
// than we can chew and we need to throw one away. We don't want to wait many cycles and skip many
// frames.
- if (m_lShiftToNearest > (lDisplayCycle + 1))
- {
+ if (m_lShiftToNearest > (lDisplayCycle + 1)) {
SetEvent(m_hEvtSkip);
m_bEvtSkip = true;
}
@@ -3711,36 +3624,36 @@ void CSyncAP::RenderThread()
// We need to add a hysteresis to the control of the timing adjustment to avoid judder when
// presentation time is close to vsync and the renderer couldn't otherwise make up its mind
// whether to present before the vsync or after. That kind of indecisiveness leads to judder.
- if (m_bSnapToVSync)
- {
+ if (m_bSnapToVSync) {
- if ((m_lShiftToNearestPrev - m_lShiftToNearest) > lDisplayCycle2) // If a step down in the m_lShiftToNearest function. Display slower than video.
- {
+ if ((m_lShiftToNearestPrev - m_lShiftToNearest) > lDisplayCycle2) { // If a step down in the m_lShiftToNearest function. Display slower than video.
m_bVideoSlowerThanDisplay = false;
m_llHysteresis = -(LONGLONG)(10000 * lDisplayCycle4);
- }
- else if ((m_lShiftToNearest - m_lShiftToNearestPrev) > lDisplayCycle2) // If a step up
- {
+ } else if ((m_lShiftToNearest - m_lShiftToNearestPrev) > lDisplayCycle2) { // If a step up
m_bVideoSlowerThanDisplay = true;
m_llHysteresis = (LONGLONG)(10000 * lDisplayCycle4);
+ } else if ((m_lShiftToNearest < (3 * lDisplayCycle4)) && (m_lShiftToNearest > lDisplayCycle4)) {
+ m_llHysteresis = 0; // Reset when between 1/4 and 3/4 of the way either way
}
- else if ((m_lShiftToNearest < (3 * lDisplayCycle4)) && (m_lShiftToNearest > lDisplayCycle4))
- m_llHysteresis = 0; // Reset when between 1/4 and 3/4 of the way either way
- if ((m_lShiftToNearest < lDisplayCycle2) && (m_llHysteresis > 0)) m_llHysteresis = 0; // Should never really be in this territory.
- if (m_lShiftToNearest < 0) m_llHysteresis = 0; // A glitch might get us to a sticky state where both these numbers are negative.
- if ((m_lShiftToNearest > lDisplayCycle2) && (m_llHysteresis < 0)) m_llHysteresis = 0;
+ if ((m_lShiftToNearest < lDisplayCycle2) && (m_llHysteresis > 0)) {
+ m_llHysteresis = 0; // Should never really be in this territory.
+ }
+ if (m_lShiftToNearest < 0) {
+ m_llHysteresis = 0; // A glitch might get us to a sticky state where both these numbers are negative.
+ }
+ if ((m_lShiftToNearest > lDisplayCycle2) && (m_llHysteresis < 0)) {
+ m_llHysteresis = 0;
+ }
}
}
- if (m_lNextSampleWait < 0) // Skip late or duplicate sample.
- {
+ if (m_lNextSampleWait < 0) { // Skip late or duplicate sample.
SetEvent(m_hEvtSkip);
m_bEvtSkip = true;
}
- if (m_lNextSampleWait > 1000)
- {
+ if (m_lNextSampleWait > 1000) {
m_lNextSampleWait = 1000; // So as to avoid full a full stop when sample is far in the future (shouldn't really happen).
}
}
@@ -3749,86 +3662,86 @@ void CSyncAP::RenderThread()
}
// Wait for the next presentation time (m_lNextSampleWait) or some other event.
dwObject = WaitForMultipleObjects(countof(hEvts), hEvts, FALSE, (DWORD)m_lNextSampleWait);
- switch (dwObject)
- {
- case WAIT_OBJECT_0: // Quit
- bQuit = true;
- break;
-
- case WAIT_OBJECT_0 + 1: // Flush
- if (pNewSample) MoveToFreeList(pNewSample, true);
- pNewSample = NULL;
- FlushSamples();
- m_bEvtFlush = false;
- ResetEvent(m_hEvtFlush);
- m_bPrerolled = false;
- m_lShiftToNearest = 0;
- stepForward = true;
- break;
-
- case WAIT_OBJECT_0 + 2: // Skip sample
- m_pcFramesDropped++;
- m_llSampleTime = m_llLastSampleTime; // This sample will never be shown
- m_bEvtSkip = false;
- ResetEvent(m_hEvtSkip);
- stepForward = true;
- break;
+ switch (dwObject) {
+ case WAIT_OBJECT_0: // Quit
+ bQuit = true;
+ break;
- case WAIT_TIMEOUT: // Time to show the sample or something
- if (m_LastSetOutputRange != -1 && m_LastSetOutputRange != s.m_RenderSettings.iEVROutputRange || m_bPendingRenegotiate)
- {
- if (pNewSample) MoveToFreeList(pNewSample, true);
+ case WAIT_OBJECT_0 + 1: // Flush
+ if (pNewSample) {
+ MoveToFreeList(pNewSample, true);
+ }
pNewSample = NULL;
FlushSamples();
- RenegotiateMediaType();
- m_bPendingRenegotiate = false;
- }
+ m_bEvtFlush = false;
+ ResetEvent(m_hEvtFlush);
+ m_bPrerolled = false;
+ m_lShiftToNearest = 0;
+ stepForward = true;
+ break;
- if (m_bPendingResetDevice)
- {
- if (pNewSample)
- MoveToFreeList(pNewSample, true);
- pNewSample = NULL;
- SendResetRequest();
- }
- else if (m_nStepCount < 0)
- {
- m_nStepCount = 0;
+ case WAIT_OBJECT_0 + 2: // Skip sample
m_pcFramesDropped++;
+ m_llSampleTime = m_llLastSampleTime; // This sample will never be shown
+ m_bEvtSkip = false;
+ ResetEvent(m_hEvtSkip);
stepForward = true;
- }
- else if (pNewSample && (m_nStepCount > 0))
- {
- pNewSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
- if (!g_bExternalSubtitleTime) __super::SetTime (g_tSegmentStart + m_llSampleTime);
- Paint(true);
- CompleteFrameStep(false);
- m_pcFramesDrawn++;
- stepForward = true;
- }
- else if (pNewSample && !m_bStepping) // When a stepped frame is shown, a new one is fetched that we don't want to show here while stepping
- {
- pNewSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32*)&m_nCurSurface);
- if (!g_bExternalSubtitleTime) __super::SetTime (g_tSegmentStart + m_llSampleTime);
- Paint(true);
- m_pcFramesDrawn++;
- stepForward = true;
- }
- break;
+ break;
+
+ case WAIT_TIMEOUT: // Time to show the sample or something
+ if (m_LastSetOutputRange != -1 && m_LastSetOutputRange != s.m_RenderSettings.iEVROutputRange || m_bPendingRenegotiate) {
+ if (pNewSample) {
+ MoveToFreeList(pNewSample, true);
+ }
+ pNewSample = NULL;
+ FlushSamples();
+ RenegotiateMediaType();
+ m_bPendingRenegotiate = false;
+ }
+
+ if (m_bPendingResetDevice) {
+ if (pNewSample) {
+ MoveToFreeList(pNewSample, true);
+ }
+ pNewSample = NULL;
+ SendResetRequest();
+ } else if (m_nStepCount < 0) {
+ m_nStepCount = 0;
+ m_pcFramesDropped++;
+ stepForward = true;
+ } else if (pNewSample && (m_nStepCount > 0)) {
+ pNewSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32 *)&m_nCurSurface);
+ if (!g_bExternalSubtitleTime) {
+ __super::SetTime (g_tSegmentStart + m_llSampleTime);
+ }
+ Paint(true);
+ CompleteFrameStep(false);
+ m_pcFramesDrawn++;
+ stepForward = true;
+ } else if (pNewSample && !m_bStepping) { // When a stepped frame is shown, a new one is fetched that we don't want to show here while stepping
+ pNewSample->GetUINT32(GUID_SURFACE_INDEX, (UINT32*)&m_nCurSurface);
+ if (!g_bExternalSubtitleTime) {
+ __super::SetTime (g_tSegmentStart + m_llSampleTime);
+ }
+ Paint(true);
+ m_pcFramesDrawn++;
+ stepForward = true;
+ }
+ break;
} // switch
- if (pNewSample && stepForward)
- {
+ if (pNewSample && stepForward) {
MoveToFreeList(pNewSample, true);
pNewSample = NULL;
}
} // while
- if (pNewSample)
- {
+ if (pNewSample) {
MoveToFreeList(pNewSample, true);
pNewSample = NULL;
}
timeEndPeriod (dwResolution);
- if (pfAvRevertMmThreadCharacteristics) pfAvRevertMmThreadCharacteristics(hAvrt);
+ if (pfAvRevertMmThreadCharacteristics) {
+ pfAvRevertMmThreadCharacteristics(hAvrt);
+ }
}
STDMETHODIMP_(bool) CSyncAP::ResetDevice()
@@ -3840,12 +3753,10 @@ STDMETHODIMP_(bool) CSyncAP::ResetDevice()
bool bResult = __super::ResetDevice();
- for(int i = 0; i < m_nDXSurface; i++)
- {
+ for(int i = 0; i < m_nDXSurface; i++) {
CComPtr<IMFSample> pMFSample;
HRESULT hr = pfMFCreateVideoSampleFromSurface (m_pVideoSurface[i], &pMFSample);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
pMFSample->SetUINT32(GUID_SURFACE_INDEX, i);
m_FreeSamples.AddTail(pMFSample);
}
@@ -3859,9 +3770,13 @@ void CSyncAP::OnResetDevice()
TRACE("--> CSyncAP::OnResetDevice on thread: %d\n", GetCurrentThreadId());
HRESULT hr;
hr = m_pD3DManager->ResetDevice(m_pD3DDev, m_nResetToken);
- if (m_pSink) m_pSink->Notify(EC_DISPLAY_CHANGED, 0, 0);
+ if (m_pSink) {
+ m_pSink->Notify(EC_DISPLAY_CHANGED, 0, 0);
+ }
CSize videoSize = GetVisibleVideoSize();
- if (m_pSink) m_pSink->Notify(EC_VIDEO_SIZE_CHANGED, MAKELPARAM(videoSize.cx, videoSize.cy), 0);
+ if (m_pSink) {
+ m_pSink->Notify(EC_VIDEO_SIZE_CHANGED, MAKELPARAM(videoSize.cx, videoSize.cy), 0);
+ }
}
void CSyncAP::RemoveAllSamples()
@@ -3878,13 +3793,12 @@ HRESULT CSyncAP::GetFreeSample(IMFSample** ppSample)
CAutoLock lock(&m_SampleQueueLock);
HRESULT hr = S_OK;
- if (m_FreeSamples.GetCount() > 1) // Cannot use first free buffer (can be currently displayed)
- {
+ if (m_FreeSamples.GetCount() > 1) { // Cannot use first free buffer (can be currently displayed)
InterlockedIncrement(&m_nUsedBuffer);
*ppSample = m_FreeSamples.RemoveHead().Detach();
- }
- else
+ } else {
hr = MF_E_SAMPLEALLOCATOR_EMPTY;
+ }
return hr;
}
@@ -3895,13 +3809,12 @@ HRESULT CSyncAP::GetScheduledSample(IMFSample** ppSample, int &_Count)
HRESULT hr = S_OK;
_Count = m_ScheduledSamples.GetCount();
- if (_Count > 0)
- {
+ if (_Count > 0) {
*ppSample = m_ScheduledSamples.RemoveHead().Detach();
--_Count;
- }
- else
+ } else {
hr = MF_E_SAMPLEALLOCATOR_EMPTY;
+ }
return hr;
}
@@ -3910,26 +3823,23 @@ void CSyncAP::MoveToFreeList(IMFSample* pSample, bool bTail)
{
CAutoLock lock(&m_SampleQueueLock);
InterlockedDecrement(&m_nUsedBuffer);
- if (m_bPendingMediaFinished && m_nUsedBuffer == 0)
- {
+ if (m_bPendingMediaFinished && m_nUsedBuffer == 0) {
m_bPendingMediaFinished = false;
m_pSink->Notify(EC_COMPLETE, 0, 0);
}
- if (bTail)
+ if (bTail) {
m_FreeSamples.AddTail(pSample);
- else
+ } else {
m_FreeSamples.AddHead(pSample);
+ }
}
void CSyncAP::MoveToScheduledList(IMFSample* pSample, bool _bSorted)
{
- if (_bSorted)
- {
+ if (_bSorted) {
CAutoLock lock(&m_SampleQueueLock);
m_ScheduledSamples.AddHead(pSample);
- }
- else
- {
+ } else {
CAutoLock lock(&m_SampleQueueLock);
m_ScheduledSamples.AddTail(pSample);
}
@@ -3945,8 +3855,7 @@ void CSyncAP::FlushSamples()
void CSyncAP::FlushSamplesInternal()
{
m_bPrerolled = false;
- while (m_ScheduledSamples.GetCount() > 0)
- {
+ while (m_ScheduledSamples.GetCount() > 0) {
CComPtr<IMFSample> pMFSample;
pMFSample = m_ScheduledSamples.RemoveHead();
MoveToFreeList(pMFSample, true);
@@ -3970,42 +3879,41 @@ HRESULT CSyncAP::BeginStreaming()
pEVR->QueryFilterInfo(&filterInfo); // This addref's the pGraph member
BeginEnumFilters(filterInfo.pGraph, pEF, pBF)
- if(CComQIPtr<IAMAudioRendererStats> pAS = pBF)
- {
+ if(CComQIPtr<IAMAudioRendererStats> pAS = pBF) {
m_pAudioStats = pAS;
};
EndEnumFilters
pEVR->GetSyncSource(&m_pRefClock);
- if (filterInfo.pGraph) filterInfo.pGraph->Release();
+ if (filterInfo.pGraph) {
+ filterInfo.pGraph->Release();
+ }
m_pGenlock->SetMonitor(GetAdapter(m_pD3D));
m_pGenlock->GetTiming();
ResetStats();
EstimateRefreshTimings();
- if (m_dFrameCycle > 0.0) m_dCycleDifference = GetCycleDifference(); // Might have moved to another display
+ if (m_dFrameCycle > 0.0) {
+ m_dCycleDifference = GetCycleDifference(); // Might have moved to another display
+ }
return S_OK;
}
HRESULT CreateSyncRenderer(const CLSID& clsid, HWND hWnd, bool bFullscreen, ISubPicAllocatorPresenter** ppAP)
{
HRESULT hr = E_FAIL;
- if (clsid == CLSID_SyncAllocatorPresenter)
- {
+ if (clsid == CLSID_SyncAllocatorPresenter) {
CString Error;
*ppAP = DNew CSyncAP(hWnd, bFullscreen, hr, Error);
(*ppAP)->AddRef();
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
Error += L"\n";
Error += GetWindowsErrorMessage(hr, NULL);
MessageBox(hWnd, Error, L"Error creating EVR Sync", MB_OK | MB_ICONERROR);
(*ppAP)->Release();
*ppAP = NULL;
- }
- else if (!Error.IsEmpty())
- {
+ } else if (!Error.IsEmpty()) {
MessageBox(hWnd, Error, L"Warning creating EVR Sync", MB_OK|MB_ICONWARNING);
}
}
@@ -4027,120 +3935,144 @@ HRESULT STDMETHODCALLTYPE CSyncRenderer::GetState(DWORD dwMilliSecsTimeout, __ou
{
HRESULT ReturnValue;
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->GetState(dwMilliSecsTimeout, State);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::EnumPins(__out IEnumPins **ppEnum)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->EnumPins(ppEnum);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::FindPin(LPCWSTR Id, __out IPin **ppPin)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->FindPin(Id, ppPin);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::QueryFilterInfo(__out FILTER_INFO *pInfo)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->QueryFilterInfo(pInfo);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::JoinFilterGraph(__in_opt IFilterGraph *pGraph, __in_opt LPCWSTR pName)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->JoinFilterGraph(pGraph, pName);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::QueryVendorInfo(__out LPWSTR *pVendorInfo)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->QueryVendorInfo(pVendorInfo);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::Stop( void)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->Stop();
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::Pause(void)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->Pause();
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::Run(REFERENCE_TIME tStart)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->Run(tStart);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::SetSyncSource(__in_opt IReferenceClock *pClock)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->SetSyncSource(pClock);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::GetSyncSource(__deref_out_opt IReferenceClock **pClock)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->GetSyncSource(pClock);
+ }
return E_NOTIMPL;
}
STDMETHODIMP CSyncRenderer::GetClassID(__RPC__out CLSID *pClassID)
{
CComPtr<IBaseFilter> pEVRBase;
- if (m_pEVR)
+ if (m_pEVR) {
m_pEVR->QueryInterface(&pEVRBase);
- if (pEVRBase)
+ }
+ if (pEVRBase) {
return pEVRBase->GetClassID(pClassID);
+ }
return E_NOTIMPL;
}
@@ -4182,32 +4114,29 @@ STDMETHODIMP CSyncRenderer::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
HRESULT hr;
- if(riid == __uuidof(IVMRMixerBitmap9))
+ if(riid == __uuidof(IVMRMixerBitmap9)) {
return GetInterface((IVMRMixerBitmap9*)this, ppv);
+ }
- if (riid == __uuidof(IBaseFilter))
- {
+ if (riid == __uuidof(IBaseFilter)) {
return GetInterface((IBaseFilter*)this, ppv);
}
- if (riid == __uuidof(IMediaFilter))
- {
+ if (riid == __uuidof(IMediaFilter)) {
return GetInterface((IMediaFilter*)this, ppv);
}
- if (riid == __uuidof(IPersist))
- {
+ if (riid == __uuidof(IPersist)) {
return GetInterface((IPersist*)this, ppv);
}
- if (riid == __uuidof(IBaseFilter))
- {
+ if (riid == __uuidof(IBaseFilter)) {
return GetInterface((IBaseFilter*)this, ppv);
}
hr = m_pEVR ? m_pEVR->QueryInterface(riid, ppv) : E_NOINTERFACE;
- if(m_pEVR && FAILED(hr))
- {
- if(riid == __uuidof(IVMRffdshow9)) // Support ffdshow queueing. We show ffdshow that this is patched Media Player Classic.
+ if(m_pEVR && FAILED(hr)) {
+ if(riid == __uuidof(IVMRffdshow9)) { // Support ffdshow queueing. We show ffdshow that this is patched Media Player Classic.
return GetInterface((IVMRffdshow9*)this, ppv);
+ }
}
return SUCCEEDED(hr) ? hr : __super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -4239,13 +4168,11 @@ CGenlock::CGenlock(DOUBLE target, DOUBLE limit, INT lineD, INT colD, DOUBLE cloc
CGenlock::~CGenlock()
{
ResetTiming();
- if(syncOffsetFifo != NULL)
- {
+ if(syncOffsetFifo != NULL) {
delete syncOffsetFifo;
syncOffsetFifo = NULL;
}
- if(frameCycleFifo != NULL)
- {
+ if(frameCycleFifo != NULL) {
delete frameCycleFifo;
frameCycleFifo = NULL;
}
@@ -4255,8 +4182,11 @@ CGenlock::~CGenlock()
BOOL CGenlock::PowerstripRunning()
{
psWnd = FindWindow(_T("TPShidden"), NULL);
- if (!psWnd) return FALSE; // Powerstrip is not running
- else return TRUE;
+ if (!psWnd) {
+ return FALSE; // Powerstrip is not running
+ } else {
+ return TRUE;
+ }
}
// Get the display timing parameters through PowerStrip (if running).
@@ -4271,15 +4201,15 @@ HRESULT CGenlock::GetTiming()
TCHAR tmpStr[MAX_LOADSTRING];
CAutoLock lock(&csGenlockLock);
- if (!PowerstripRunning()) return E_FAIL;
+ if (!PowerstripRunning()) {
+ return E_FAIL;
+ }
getTiming = static_cast<ATOM>(SendMessage(psWnd, UM_GETTIMING, wParam, lParam));
GlobalGetAtomName(getTiming, savedTiming, MAX_LOADSTRING);
- while (params < TIMING_PARAM_CNT)
- {
- while (savedTiming[i] != ',' && savedTiming[i] != '\0')
- {
+ while (params < TIMING_PARAM_CNT) {
+ while (savedTiming[i] != ',' && savedTiming[i] != '\0') {
tmpStr[j++] = savedTiming[i];
tmpStr[j] = '\0';
i++;
@@ -4357,10 +4287,11 @@ HRESULT CGenlock::ResetTiming()
LRESULT ret;
CAutoLock lock(&csGenlockLock);
- if (!PowerstripRunning()) return E_FAIL;
+ if (!PowerstripRunning()) {
+ return E_FAIL;
+ }
- if (displayAdjustmentsMade > 0)
- {
+ if (displayAdjustmentsMade > 0) {
setTiming = GlobalAddAtom(cruise);
lParam = setTiming;
ret = SendMessage(psWnd, UM_SETCUSTOMTIMINGFAST, wParam, lParam);
@@ -4375,8 +4306,11 @@ HRESULT CGenlock::ResetTiming()
HRESULT CGenlock::ResetClock()
{
adjDelta = 0;
- if (syncClock == NULL) return E_FAIL;
- else return syncClock->AdjustClock(1.0);
+ if (syncClock == NULL) {
+ return E_FAIL;
+ } else {
+ return syncClock->AdjustClock(1.0);
+ }
}
HRESULT CGenlock::SetTargetSyncOffset(DOUBLE targetD)
@@ -4414,8 +4348,12 @@ HRESULT CGenlock::SetDisplayResolution(UINT columns, UINT lines)
HRESULT CGenlock::AdviseSyncClock(ISyncClock* sC)
{
- if (!sC) return E_FAIL;
- if (syncClock) syncClock = NULL; // Release any outstanding references if this is called repeatedly
+ if (!sC) {
+ return E_FAIL;
+ }
+ if (syncClock) {
+ syncClock = NULL; // Release any outstanding references if this is called repeatedly
+ }
syncClock = sC;
return S_OK;
}
@@ -4460,7 +4398,9 @@ HRESULT CGenlock::ControlDisplay(double syncOffset, double frameCycle)
minFrameCycle = min(minFrameCycle, frameCycle);
maxFrameCycle = max(maxFrameCycle, frameCycle);
- if (!PowerstripRunning() || !powerstripTimingExists) return E_FAIL;
+ if (!PowerstripRunning() || !powerstripTimingExists) {
+ return E_FAIL;
+ }
// Adjust as seldom as possible by checking the current controlState before changing it.
if ((syncOffsetAvg > highSyncOffset) && (adjDelta != 1))
// Speed up display refresh rate by subtracting pixels from the image.
@@ -4472,11 +4412,9 @@ HRESULT CGenlock::ControlDisplay(double syncOffset, double frameCycle)
SendMessage(psWnd, UM_SETCUSTOMTIMINGFAST, wParam, lParam);
GlobalDeleteAtom(setTiming);
displayAdjustmentsMade++;
- }
- else
+ } else
// Slow down display refresh rate by adding pixels to the image.
- if ((syncOffsetAvg < lowSyncOffset) && (adjDelta != -1))
- {
+ if ((syncOffsetAvg < lowSyncOffset) && (adjDelta != -1)) {
adjDelta = -1;
curDisplayFreq = displayFreqSlower;
setTiming = GlobalAddAtom(slower);
@@ -4484,11 +4422,9 @@ HRESULT CGenlock::ControlDisplay(double syncOffset, double frameCycle)
SendMessage(psWnd, UM_SETCUSTOMTIMINGFAST, wParam, lParam);
GlobalDeleteAtom(setTiming);
displayAdjustmentsMade++;
- }
- else
+ } else
// Cruise.
- if ((syncOffsetAvg < targetSyncOffset) && (adjDelta == 1))
- {
+ if ((syncOffsetAvg < targetSyncOffset) && (adjDelta == 1)) {
adjDelta = 0;
curDisplayFreq = displayFreqCruise;
setTiming = GlobalAddAtom(cruise);
@@ -4496,9 +4432,7 @@ HRESULT CGenlock::ControlDisplay(double syncOffset, double frameCycle)
SendMessage(psWnd, UM_SETCUSTOMTIMINGFAST, wParam, lParam);
GlobalDeleteAtom(setTiming);
displayAdjustmentsMade++;
- }
- else if ((syncOffsetAvg > targetSyncOffset) && (adjDelta == -1))
- {
+ } else if ((syncOffsetAvg > targetSyncOffset) && (adjDelta == -1)) {
adjDelta = 0;
curDisplayFreq = displayFreqCruise;
setTiming = GlobalAddAtom(cruise);
@@ -4526,7 +4460,9 @@ HRESULT CGenlock::ControlClock(double syncOffset, double frameCycle)
minFrameCycle = min(minFrameCycle, frameCycle);
maxFrameCycle = max(maxFrameCycle, frameCycle);
- if (!syncClock) return E_FAIL;
+ if (!syncClock) {
+ return E_FAIL;
+ }
// Adjust as seldom as possible by checking the current controlState before changing it.
if ((syncOffsetAvg > highSyncOffset) && (adjDelta != 1))
// Slow down video stream.
@@ -4534,25 +4470,19 @@ HRESULT CGenlock::ControlClock(double syncOffset, double frameCycle)
adjDelta = 1;
syncClock->AdjustClock(1.0 - cycleDelta); // Makes the clock move slower by providing smaller increments
clockAdjustmentsMade++;
- }
- else
+ } else
// Speed up video stream.
- if ((syncOffsetAvg < lowSyncOffset) && (adjDelta != -1))
- {
+ if ((syncOffsetAvg < lowSyncOffset) && (adjDelta != -1)) {
adjDelta = -1;
syncClock->AdjustClock(1.0 + cycleDelta);
clockAdjustmentsMade++;
- }
- else
+ } else
// Cruise.
- if ((syncOffsetAvg < targetSyncOffset) && (adjDelta == 1))
- {
+ if ((syncOffsetAvg < targetSyncOffset) && (adjDelta == 1)) {
adjDelta = 0;
syncClock->AdjustClock(1.0);
clockAdjustmentsMade++;
- }
- else if ((syncOffsetAvg > targetSyncOffset) && (adjDelta == -1))
- {
+ } else if ((syncOffsetAvg > targetSyncOffset) && (adjDelta == -1)) {
adjDelta = 0;
syncClock->AdjustClock(1.0);
clockAdjustmentsMade++;
diff --git a/src/filters/renderer/VideoRenderers/SyncRenderer.h b/src/filters/renderer/VideoRenderers/SyncRenderer.h
index ec19f8dbb..8e9f87c79 100644
--- a/src/filters/renderer/VideoRenderers/SyncRenderer.h
+++ b/src/filters/renderer/VideoRenderers/SyncRenderer.h
@@ -76,615 +76,609 @@ static const GUID GUID_SURFACE_INDEX = { 0x30c8e9f6, 0x415, 0x4b81, { 0xa3, 0x15
namespace GothSync
{
-typedef enum
-{
- MSG_MIXERIN,
- MSG_MIXEROUT,
- MSG_ERROR
-} EVR_STATS_MSG;
+ typedef enum {
+ MSG_MIXERIN,
+ MSG_MIXEROUT,
+ MSG_ERROR
+ } EVR_STATS_MSG;
#pragma pack(push, 1)
-template<int texcoords>
-struct MYD3DVERTEX
-{
- float x, y, z, rhw;
- struct
- {
- float u, v;
- } t[texcoords];
-};
+ template<int texcoords>
+ struct MYD3DVERTEX {
+ float x, y, z, rhw;
+ struct {
+ float u, v;
+ } t[texcoords];
+ };
-template<>
-struct MYD3DVERTEX<0>
-{
- float x, y, z, rhw;
- DWORD Diffuse;
-};
+ template<>
+ struct MYD3DVERTEX<0> {
+ float x, y, z, rhw;
+ DWORD Diffuse;
+ };
#pragma pack(pop)
-class CGenlock;
-class CSyncRenderer;
+ class CGenlock;
+ class CSyncRenderer;
-// Base allocator-presenter
-class CBaseAP:
- public CSubPicAllocatorPresenterImpl
-{
-protected:
- CRenderersSettings::CRendererSettingsEVR m_LastRendererSettings;
-
- HMODULE m_hDWMAPI;
- HRESULT (__stdcall * m_pDwmIsCompositionEnabled)(__out BOOL* pfEnabled);
- HRESULT (__stdcall * m_pDwmEnableComposition)(UINT uCompositionAction);
- HMODULE m_hD3D9;
- HRESULT (__stdcall * m_pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex**);
-
- CCritSec m_allocatorLock;
- CComPtr<IDirect3D9Ex> m_pD3DEx;
- CComPtr<IDirect3D9> m_pD3D;
- CComPtr<IDirect3DDevice9Ex> m_pD3DDevEx;
- CComPtr<IDirect3DDevice9> m_pD3DDev;
-
- CComPtr<IDirect3DTexture9> m_pVideoTexture[MAX_PICTURE_SLOTS];
- CComPtr<IDirect3DSurface9> m_pVideoSurface[MAX_PICTURE_SLOTS];
- CComPtr<IDirect3DTexture9> m_pOSDTexture;
- CComPtr<IDirect3DSurface9> m_pOSDSurface;
- CComPtr<ID3DXLine> m_pLine;
- CComPtr<ID3DXFont> m_pFont;
- CComPtr<ID3DXSprite> m_pSprite;
- CSyncRenderer *m_pOuterEVR;
-
- class CExternalPixelShader
+ // Base allocator-presenter
+ class CBaseAP:
+ public CSubPicAllocatorPresenterImpl
{
- public:
- CComPtr<IDirect3DPixelShader9> m_pPixelShader;
- CStringA m_SourceData;
- CStringA m_SourceTarget;
- HRESULT Compile(CPixelShaderCompiler *pCompiler)
+ protected:
+ CRenderersSettings::CRendererSettingsEVR m_LastRendererSettings;
+
+ HMODULE m_hDWMAPI;
+ HRESULT (__stdcall * m_pDwmIsCompositionEnabled)(__out BOOL* pfEnabled);
+ HRESULT (__stdcall * m_pDwmEnableComposition)(UINT uCompositionAction);
+ HMODULE m_hD3D9;
+ HRESULT (__stdcall * m_pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex**);
+
+ CCritSec m_allocatorLock;
+ CComPtr<IDirect3D9Ex> m_pD3DEx;
+ CComPtr<IDirect3D9> m_pD3D;
+ CComPtr<IDirect3DDevice9Ex> m_pD3DDevEx;
+ CComPtr<IDirect3DDevice9> m_pD3DDev;
+
+ CComPtr<IDirect3DTexture9> m_pVideoTexture[MAX_PICTURE_SLOTS];
+ CComPtr<IDirect3DSurface9> m_pVideoSurface[MAX_PICTURE_SLOTS];
+ CComPtr<IDirect3DTexture9> m_pOSDTexture;
+ CComPtr<IDirect3DSurface9> m_pOSDSurface;
+ CComPtr<ID3DXLine> m_pLine;
+ CComPtr<ID3DXFont> m_pFont;
+ CComPtr<ID3DXSprite> m_pSprite;
+ CSyncRenderer *m_pOuterEVR;
+
+ class CExternalPixelShader
{
- HRESULT hr = pCompiler->CompileShader(m_SourceData, "main", m_SourceTarget, 0, &m_pPixelShader);
- if(FAILED(hr)) return hr;
- return S_OK;
- }
+ public:
+ CComPtr<IDirect3DPixelShader9> m_pPixelShader;
+ CStringA m_SourceData;
+ CStringA m_SourceTarget;
+ HRESULT Compile(CPixelShaderCompiler *pCompiler) {
+ HRESULT hr = pCompiler->CompileShader(m_SourceData, "main", m_SourceTarget, 0, &m_pPixelShader);
+ if(FAILED(hr)) {
+ return hr;
+ }
+ return S_OK;
+ }
+ };
+
+ CAutoPtr<CPixelShaderCompiler> m_pPSC;
+ CAtlList<CExternalPixelShader> m_pPixelShaders;
+ CAtlList<CExternalPixelShader> m_pPixelShadersScreenSpace;
+ CComPtr<IDirect3DPixelShader9> m_pResizerPixelShader[4]; // bl, bc1, bc2_1, bc2_2
+ CComPtr<IDirect3DTexture9> m_pScreenSizeTemporaryTexture[2];
+
+ D3DFORMAT m_SurfaceType;
+ D3DFORMAT m_BackbufferType;
+ D3DFORMAT m_DisplayType;
+ D3DTEXTUREFILTERTYPE m_filter;
+ D3DCAPS9 m_caps;
+ D3DPRESENT_PARAMETERS pp;
+
+ bool SettingsNeedResetDevice();
+ void SendResetRequest();
+ virtual HRESULT CreateDXDevice(CString &_Error);
+ virtual HRESULT ResetDXDevice(CString &_Error);
+ virtual HRESULT AllocSurfaces(D3DFORMAT Format = D3DFMT_A8R8G8B8);
+ virtual void DeleteSurfaces();
+
+ HANDLE m_hEvtQuit; // Stop rendering thread event
+ LONGLONG m_LastAdapterCheck;
+ UINT m_CurrentAdapter;
+ UINT GetAdapter(IDirect3D9 *pD3D);
+
+ float m_bicubicA;
+ HRESULT InitResizers(float bicubicA, bool bNeedScreenSizeTexture);
+
+ // Functions to trace timing performance
+ void SyncStats(LONGLONG syncTime);
+ void SyncOffsetStats(LONGLONG syncOffset);
+ void DrawText(const RECT &rc, const CString &strText, int _Priority);
+ void DrawStats();
+
+ template<int texcoords>
+ void AdjustQuad(MYD3DVERTEX<texcoords>* v, double dx, double dy);
+ template<int texcoords>
+ HRESULT TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[4], D3DTEXTUREFILTERTYPE filter);
+ MFOffset GetOffset(float v);
+ MFVideoArea GetArea(float x, float y, DWORD width, DWORD height);
+ bool ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, CRect& d);
+
+ HRESULT DrawRectBase(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<0> v[4]);
+ HRESULT DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_Rect);
+ HRESULT TextureCopy(IDirect3DTexture9* pTexture);
+ HRESULT TextureResize(IDirect3DTexture9* pTexture, Vector dst[4], D3DTEXTUREFILTERTYPE filter, const CRect &SrcRect);
+ HRESULT TextureResizeBilinear(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &SrcRect);
+ HRESULT TextureResizeBicubic1pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &SrcRect);
+ HRESULT TextureResizeBicubic2pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &SrcRect);
+
+ typedef HRESULT (WINAPI * D3DXLoadSurfaceFromMemoryPtr)(
+ LPDIRECT3DSURFACE9 pDestSurface,
+ CONST PALETTEENTRY* pDestPalette,
+ CONST RECT* pDestRect,
+ LPCVOID pSrcMemory,
+ D3DFORMAT SrcFormat,
+ UINT SrcPitch,
+ CONST PALETTEENTRY* pSrcPalette,
+ CONST RECT* pSrcRect,
+ DWORD Filter,
+ D3DCOLOR ColorKey);
+
+ typedef HRESULT (WINAPI* D3DXCreateLinePtr)
+ (LPDIRECT3DDEVICE9 pDevice,
+ LPD3DXLINE* ppLine);
+
+ typedef HRESULT (WINAPI* D3DXCreateFontPtr)(
+ LPDIRECT3DDEVICE9 pDevice,
+ int Height,
+ UINT Width,
+ UINT Weight,
+ UINT MipLevels,
+ bool Italic,
+ DWORD CharSet,
+ DWORD OutputPrecision,
+ DWORD Quality,
+ DWORD PitchAndFamily,
+ LPCWSTR pFaceName,
+ LPD3DXFONT* ppFont);
+
+ HRESULT AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture);
+
+ virtual void OnResetDevice() {};
+
+ int m_nTearingPos;
+ VMR9AlphaBitmap m_VMR9AlphaBitmap;
+ CAutoVectorPtr<BYTE> m_VMR9AlphaBitmapData;
+ CRect m_VMR9AlphaBitmapRect;
+ int m_VMR9AlphaBitmapWidthBytes;
+
+ D3DXLoadSurfaceFromMemoryPtr m_pD3DXLoadSurfaceFromMemory;
+ D3DXCreateLinePtr m_pD3DXCreateLine;
+ D3DXCreateFontPtr m_pD3DXCreateFont;
+ HRESULT (__stdcall *m_pD3DXCreateSprite)(LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE * ppSprite);
+
+ int m_nDXSurface; // Total number of DX Surfaces
+ int m_nVMR9Surfaces;
+ int m_iVMR9Surface;
+ int m_nCurSurface; // Surface currently displayed
+ long m_nUsedBuffer;
+
+ LONG m_lNextSampleWait; // Waiting time for next sample in EVR
+ bool m_bSnapToVSync; // True if framerate is low enough so that snap to vsync makes sense
+
+ UINT m_uScanLineEnteringPaint; // The active scan line when entering Paint()
+ REFERENCE_TIME m_llEstVBlankTime; // Next vblank start time in reference clock "coordinates"
+
+ double m_fAvrFps; // Estimate the true FPS as given by the distance between vsyncs when a frame has been presented
+ double m_fJitterStdDev; // VSync estimate std dev
+ double m_fJitterMean; // Mean time between two syncpulses when a frame has been presented (i.e. when Paint() has been called
+
+ double m_fSyncOffsetAvr; // Mean time between the call of Paint() and vsync. To avoid tearing this should be several ms at least
+ double m_fSyncOffsetStdDev; // The std dev of the above
+
+ bool m_bHighColorResolution;
+ bool m_bCompositionEnabled;
+ bool m_bDesktopCompositionDisabled;
+ bool m_bIsFullscreen;
+ bool m_bNeedCheckSample;
+ DWORD m_dMainThreadId;
+
+ CSize m_ScreenSize;
+
+ // Display and frame rates and cycles
+ double m_dDetectedScanlineTime; // Time for one (horizontal) scan line. Extracted at stream start and used to calculate vsync time
+ UINT m_uD3DRefreshRate; // As got when creating the d3d device
+ double m_dD3DRefreshCycle; // Display refresh cycle ms
+ double m_dEstRefreshCycle; // As estimated from scan lines
+ double m_dFrameCycle; // Average sample time, extracted from the samples themselves
+ // double m_fps is defined in ISubPic.h
+ double m_dOptimumDisplayCycle; // The display cycle that is closest to the frame rate. A multiple of the actual display cycle
+ double m_dCycleDifference; // Difference in video and display cycle time relative to the video cycle time
+
+ UINT m_pcFramesDropped;
+ UINT m_pcFramesDuplicated;
+ UINT m_pcFramesDrawn;
+
+ LONGLONG m_pllJitter [NB_JITTER]; // Vertical sync time stats
+ LONGLONG m_pllSyncOffset [NB_JITTER]; // Sync offset time stats
+ int m_nNextJitter;
+ int m_nNextSyncOffset;
+ LONGLONG m_JitterStdDev;
+
+ LONGLONG m_llLastSyncTime;
+
+ LONGLONG m_MaxJitter;
+ LONGLONG m_MinJitter;
+ LONGLONG m_MaxSyncOffset;
+ LONGLONG m_MinSyncOffset;
+ UINT m_uSyncGlitches;
+
+ LONGLONG m_llSampleTime, m_llLastSampleTime; // Present time for the current sample
+ LONG m_lSampleLatency, m_lLastSampleLatency; // Time between intended and actual presentation time
+ LONG m_lMinSampleLatency, m_lLastMinSampleLatency;
+ LONGLONG m_llHysteresis;
+ LONG m_lHysteresis;
+ LONG m_lShiftToNearest, m_lShiftToNearestPrev;
+ bool m_bVideoSlowerThanDisplay;
+
+ int m_bInterlaced;
+ double m_TextScale;
+ CString m_strStatsMsg[10];
+
+ CGenlock *m_pGenlock; // The video - display synchronizer class
+ CComPtr<IReferenceClock> m_pRefClock; // The reference clock. Used in Paint()
+ CComPtr<IAMAudioRendererStats> m_pAudioStats; // Audio statistics from audio renderer. To check so that audio is in sync
+ DWORD m_lAudioLag; // Time difference between audio and video when the audio renderer is matching rate to the external reference clock
+ long m_lAudioLagMin, m_lAudioLagMax; // The accumulated difference between the audio renderer and the master clock
+ DWORD m_lAudioSlaveMode; // To check whether the audio renderer matches rate with SyncClock (returns the value 4 if it does)
+
+ double GetRefreshRate(); // Get the best estimate of the display refresh rate in Hz
+ double GetDisplayCycle(); // Get the best estimate of the display cycle time in milliseconds
+ double GetCycleDifference(); // Get the difference in video and display cycle times.
+ void EstimateRefreshTimings(); // Estimate the times for one scan line and one frame respectively from the actual refresh data
+ bool ExtractInterlaced(const AM_MEDIA_TYPE* pmt);
+
+ public:
+ CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+ ~CBaseAP();
+
+ CCritSec m_VMR9AlphaBitmapLock;
+ void UpdateAlphaBitmap();
+ void ResetStats();
+
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
+ STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
+ STDMETHODIMP SetPixelShader2(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace);
+ STDMETHODIMP_(bool) ResetDevice();
};
- CAutoPtr<CPixelShaderCompiler> m_pPSC;
- CAtlList<CExternalPixelShader> m_pPixelShaders;
- CAtlList<CExternalPixelShader> m_pPixelShadersScreenSpace;
- CComPtr<IDirect3DPixelShader9> m_pResizerPixelShader[4]; // bl, bc1, bc2_1, bc2_2
- CComPtr<IDirect3DTexture9> m_pScreenSizeTemporaryTexture[2];
-
- D3DFORMAT m_SurfaceType;
- D3DFORMAT m_BackbufferType;
- D3DFORMAT m_DisplayType;
- D3DTEXTUREFILTERTYPE m_filter;
- D3DCAPS9 m_caps;
- D3DPRESENT_PARAMETERS pp;
-
- bool SettingsNeedResetDevice();
- void SendResetRequest();
- virtual HRESULT CreateDXDevice(CString &_Error);
- virtual HRESULT ResetDXDevice(CString &_Error);
- virtual HRESULT AllocSurfaces(D3DFORMAT Format = D3DFMT_A8R8G8B8);
- virtual void DeleteSurfaces();
-
- HANDLE m_hEvtQuit; // Stop rendering thread event
- LONGLONG m_LastAdapterCheck;
- UINT m_CurrentAdapter;
- UINT GetAdapter(IDirect3D9 *pD3D);
-
- float m_bicubicA;
- HRESULT InitResizers(float bicubicA, bool bNeedScreenSizeTexture);
-
- // Functions to trace timing performance
- void SyncStats(LONGLONG syncTime);
- void SyncOffsetStats(LONGLONG syncOffset);
- void DrawText(const RECT &rc, const CString &strText, int _Priority);
- void DrawStats();
+ class CSyncAP:
+ public CBaseAP,
+ public IMFGetService,
+ public IMFTopologyServiceLookupClient,
+ public IMFVideoDeviceID,
+ public IMFVideoPresenter,
+ public IDirect3DDeviceManager9,
+ public IMFAsyncCallback,
+ public IQualProp,
+ public IMFRateSupport,
+ public IMFVideoDisplayControl,
+ public IEVRTrustedVideoPlugin,
+ public ISyncClockAdviser
- template<int texcoords>
- void AdjustQuad(MYD3DVERTEX<texcoords>* v, double dx, double dy);
- template<int texcoords>
- HRESULT TextureBlt(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<texcoords> v[4], D3DTEXTUREFILTERTYPE filter);
- MFOffset GetOffset(float v);
- MFVideoArea GetArea(float x, float y, DWORD width, DWORD height);
- bool ClipToSurface(IDirect3DSurface9* pSurface, CRect& s, CRect& d);
-
- HRESULT DrawRectBase(IDirect3DDevice9* pD3DDev, MYD3DVERTEX<0> v[4]);
- HRESULT DrawRect(DWORD _Color, DWORD _Alpha, const CRect &_Rect);
- HRESULT TextureCopy(IDirect3DTexture9* pTexture);
- HRESULT TextureResize(IDirect3DTexture9* pTexture, Vector dst[4], D3DTEXTUREFILTERTYPE filter, const CRect &SrcRect);
- HRESULT TextureResizeBilinear(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &SrcRect);
- HRESULT TextureResizeBicubic1pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &SrcRect);
- HRESULT TextureResizeBicubic2pass(IDirect3DTexture9* pTexture, Vector dst[4], const CRect &SrcRect);
-
- typedef HRESULT (WINAPI * D3DXLoadSurfaceFromMemoryPtr)(
- LPDIRECT3DSURFACE9 pDestSurface,
- CONST PALETTEENTRY* pDestPalette,
- CONST RECT* pDestRect,
- LPCVOID pSrcMemory,
- D3DFORMAT SrcFormat,
- UINT SrcPitch,
- CONST PALETTEENTRY* pSrcPalette,
- CONST RECT* pSrcRect,
- DWORD Filter,
- D3DCOLOR ColorKey);
-
- typedef HRESULT (WINAPI* D3DXCreateLinePtr)
- (LPDIRECT3DDEVICE9 pDevice,
- LPD3DXLINE* ppLine);
-
- typedef HRESULT (WINAPI* D3DXCreateFontPtr)(
- LPDIRECT3DDEVICE9 pDevice,
- int Height,
- UINT Width,
- UINT Weight,
- UINT MipLevels,
- bool Italic,
- DWORD CharSet,
- DWORD OutputPrecision,
- DWORD Quality,
- DWORD PitchAndFamily,
- LPCWSTR pFaceName,
- LPD3DXFONT* ppFont);
-
- HRESULT AlphaBlt(RECT* pSrc, RECT* pDst, IDirect3DTexture9* pTexture);
-
- virtual void OnResetDevice() {};
-
- int m_nTearingPos;
- VMR9AlphaBitmap m_VMR9AlphaBitmap;
- CAutoVectorPtr<BYTE> m_VMR9AlphaBitmapData;
- CRect m_VMR9AlphaBitmapRect;
- int m_VMR9AlphaBitmapWidthBytes;
-
- D3DXLoadSurfaceFromMemoryPtr m_pD3DXLoadSurfaceFromMemory;
- D3DXCreateLinePtr m_pD3DXCreateLine;
- D3DXCreateFontPtr m_pD3DXCreateFont;
- HRESULT (__stdcall *m_pD3DXCreateSprite)(LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE * ppSprite);
-
- int m_nDXSurface; // Total number of DX Surfaces
- int m_nVMR9Surfaces;
- int m_iVMR9Surface;
- int m_nCurSurface; // Surface currently displayed
- long m_nUsedBuffer;
-
- LONG m_lNextSampleWait; // Waiting time for next sample in EVR
- bool m_bSnapToVSync; // True if framerate is low enough so that snap to vsync makes sense
-
- UINT m_uScanLineEnteringPaint; // The active scan line when entering Paint()
- REFERENCE_TIME m_llEstVBlankTime; // Next vblank start time in reference clock "coordinates"
-
- double m_fAvrFps; // Estimate the true FPS as given by the distance between vsyncs when a frame has been presented
- double m_fJitterStdDev; // VSync estimate std dev
- double m_fJitterMean; // Mean time between two syncpulses when a frame has been presented (i.e. when Paint() has been called
-
- double m_fSyncOffsetAvr; // Mean time between the call of Paint() and vsync. To avoid tearing this should be several ms at least
- double m_fSyncOffsetStdDev; // The std dev of the above
-
- bool m_bHighColorResolution;
- bool m_bCompositionEnabled;
- bool m_bDesktopCompositionDisabled;
- bool m_bIsFullscreen;
- bool m_bNeedCheckSample;
- DWORD m_dMainThreadId;
-
- CSize m_ScreenSize;
-
- // Display and frame rates and cycles
- double m_dDetectedScanlineTime; // Time for one (horizontal) scan line. Extracted at stream start and used to calculate vsync time
- UINT m_uD3DRefreshRate; // As got when creating the d3d device
- double m_dD3DRefreshCycle; // Display refresh cycle ms
- double m_dEstRefreshCycle; // As estimated from scan lines
- double m_dFrameCycle; // Average sample time, extracted from the samples themselves
- // double m_fps is defined in ISubPic.h
- double m_dOptimumDisplayCycle; // The display cycle that is closest to the frame rate. A multiple of the actual display cycle
- double m_dCycleDifference; // Difference in video and display cycle time relative to the video cycle time
-
- UINT m_pcFramesDropped;
- UINT m_pcFramesDuplicated;
- UINT m_pcFramesDrawn;
-
- LONGLONG m_pllJitter [NB_JITTER]; // Vertical sync time stats
- LONGLONG m_pllSyncOffset [NB_JITTER]; // Sync offset time stats
- int m_nNextJitter;
- int m_nNextSyncOffset;
- LONGLONG m_JitterStdDev;
-
- LONGLONG m_llLastSyncTime;
-
- LONGLONG m_MaxJitter;
- LONGLONG m_MinJitter;
- LONGLONG m_MaxSyncOffset;
- LONGLONG m_MinSyncOffset;
- UINT m_uSyncGlitches;
-
- LONGLONG m_llSampleTime, m_llLastSampleTime; // Present time for the current sample
- LONG m_lSampleLatency, m_lLastSampleLatency; // Time between intended and actual presentation time
- LONG m_lMinSampleLatency, m_lLastMinSampleLatency;
- LONGLONG m_llHysteresis;
- LONG m_lHysteresis;
- LONG m_lShiftToNearest, m_lShiftToNearestPrev;
- bool m_bVideoSlowerThanDisplay;
-
- int m_bInterlaced;
- double m_TextScale;
- CString m_strStatsMsg[10];
-
- CGenlock *m_pGenlock; // The video - display synchronizer class
- CComPtr<IReferenceClock> m_pRefClock; // The reference clock. Used in Paint()
- CComPtr<IAMAudioRendererStats> m_pAudioStats; // Audio statistics from audio renderer. To check so that audio is in sync
- DWORD m_lAudioLag; // Time difference between audio and video when the audio renderer is matching rate to the external reference clock
- long m_lAudioLagMin, m_lAudioLagMax; // The accumulated difference between the audio renderer and the master clock
- DWORD m_lAudioSlaveMode; // To check whether the audio renderer matches rate with SyncClock (returns the value 4 if it does)
-
- double GetRefreshRate(); // Get the best estimate of the display refresh rate in Hz
- double GetDisplayCycle(); // Get the best estimate of the display cycle time in milliseconds
- double GetCycleDifference(); // Get the difference in video and display cycle times.
- void EstimateRefreshTimings(); // Estimate the times for one scan line and one frame respectively from the actual refresh data
- bool ExtractInterlaced(const AM_MEDIA_TYPE* pmt);
-
-public:
- CBaseAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
- ~CBaseAP();
-
- CCritSec m_VMR9AlphaBitmapLock;
- void UpdateAlphaBitmap();
- void ResetStats();
-
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
- STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
- STDMETHODIMP SetPixelShader2(LPCSTR pSrcData, LPCSTR pTarget, bool bScreenSpace);
- STDMETHODIMP_(bool) ResetDevice();
-};
-
-class CSyncAP:
- public CBaseAP,
- public IMFGetService,
- public IMFTopologyServiceLookupClient,
- public IMFVideoDeviceID,
- public IMFVideoPresenter,
- public IDirect3DDeviceManager9,
- public IMFAsyncCallback,
- public IQualProp,
- public IMFRateSupport,
- public IMFVideoDisplayControl,
- public IEVRTrustedVideoPlugin,
- public ISyncClockAdviser
+ {
+ public:
+ CSyncAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+ ~CSyncAP(void);
+
+ DECLARE_IUNKNOWN;
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
+ STDMETHODIMP InitializeDevice(AM_MEDIA_TYPE* pMediaType);
+ STDMETHODIMP_(bool) ResetDevice();
+
+ // IMFClockStateSink
+ STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockStop(MFTIME hnsSystemTime);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockPause(MFTIME hnsSystemTime);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockRestart(MFTIME hnsSystemTime);
+ STDMETHODIMP STDMETHODCALLTYPE OnClockSetRate(MFTIME hnsSystemTime, float flRate);
+
+ // IBaseFilter delegate
+ bool GetState( DWORD dwMilliSecsTimeout, FILTER_STATE *State, HRESULT &_ReturnValue);
+
+ // IQualProp (EVR statistics window). These are incompletely implemented currently
+ STDMETHODIMP get_FramesDroppedInRenderer(int *pcFrames);
+ STDMETHODIMP get_FramesDrawn(int *pcFramesDrawn);
+ STDMETHODIMP get_AvgFrameRate(int *piAvgFrameRate);
+ STDMETHODIMP get_Jitter(int *iJitter);
+ STDMETHODIMP get_AvgSyncOffset(int *piAvg);
+ STDMETHODIMP get_DevSyncOffset(int *piDev);
+
+ // IMFRateSupport
+ STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
+ STDMETHODIMP GetFastestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
+ STDMETHODIMP IsRateSupported(BOOL fThin, float flRate, float *pflNearestSupportedRate);
+ float GetMaxRate(BOOL bThin);
+
+ // IMFVideoPresenter
+ STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
+ STDMETHODIMP GetCurrentMediaType(__deref_out IMFVideoMediaType **ppMediaType);
+
+ // IMFTopologyServiceLookupClient
+ STDMETHODIMP InitServicePointers(__in IMFTopologyServiceLookup *pLookup);
+ STDMETHODIMP ReleaseServicePointers();
+
+ // IMFVideoDeviceID
+ STDMETHODIMP GetDeviceID(__out IID *pDeviceID);
+
+ // IMFGetService
+ STDMETHODIMP GetService (__RPC__in REFGUID guidService, __RPC__in REFIID riid, __RPC__deref_out_opt LPVOID *ppvObject);
+
+ // IMFAsyncCallback
+ STDMETHODIMP GetParameters(__RPC__out DWORD *pdwFlags, /* [out] */ __RPC__out DWORD *pdwQueue);
+ STDMETHODIMP Invoke(__RPC__in_opt IMFAsyncResult *pAsyncResult);
+
+ // IMFVideoDisplayControl
+ STDMETHODIMP GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo);
+ STDMETHODIMP GetIdealVideoSize(SIZE *pszMin, SIZE *pszMax);
+ STDMETHODIMP SetVideoPosition(const MFVideoNormalizedRect *pnrcSource, const LPRECT prcDest);
+ STDMETHODIMP GetVideoPosition(MFVideoNormalizedRect *pnrcSource, LPRECT prcDest);
+ STDMETHODIMP SetAspectRatioMode(DWORD dwAspectRatioMode);
+ STDMETHODIMP GetAspectRatioMode(DWORD *pdwAspectRatioMode);
+ STDMETHODIMP SetVideoWindow(HWND hwndVideo);
+ STDMETHODIMP GetVideoWindow(HWND *phwndVideo);
+ STDMETHODIMP RepaintVideo( void);
+ STDMETHODIMP GetCurrentImage(BITMAPINFOHEADER *pBih, BYTE **pDib, DWORD *pcbDib, LONGLONG *pTimeStamp);
+ STDMETHODIMP SetBorderColor(COLORREF Clr);
+ STDMETHODIMP GetBorderColor(COLORREF *pClr);
+ STDMETHODIMP SetRenderingPrefs(DWORD dwRenderFlags);
+ STDMETHODIMP GetRenderingPrefs(DWORD *pdwRenderFlags);
+ STDMETHODIMP SetFullscreen(BOOL fFullscreen);
+ STDMETHODIMP GetFullscreen(BOOL *pfFullscreen);
+
+ // IEVRTrustedVideoPlugin
+ STDMETHODIMP IsInTrustedVideoMode(BOOL *pYes);
+ STDMETHODIMP CanConstrict(BOOL *pYes);
+ STDMETHODIMP SetConstriction(DWORD dwKPix);
+ STDMETHODIMP DisableImageExport(BOOL bDisable);
+
+ // IDirect3DDeviceManager9
+ STDMETHODIMP ResetDevice(IDirect3DDevice9 *pDevice,UINT resetToken);
+ STDMETHODIMP OpenDeviceHandle(HANDLE *phDevice);
+ STDMETHODIMP CloseDeviceHandle(HANDLE hDevice);
+ STDMETHODIMP TestDevice(HANDLE hDevice);
+ STDMETHODIMP LockDevice(HANDLE hDevice, IDirect3DDevice9 **ppDevice, BOOL fBlock);
+ STDMETHODIMP UnlockDevice(HANDLE hDevice, BOOL fSaveState);
+ STDMETHODIMP GetVideoService(HANDLE hDevice, REFIID riid, void **ppService);
+
+ protected:
+ void OnResetDevice();
+ MFCLOCK_STATE m_LastClockState;
-{
-public:
- CSyncAP(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
- ~CSyncAP(void);
-
- DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
- STDMETHODIMP InitializeDevice(AM_MEDIA_TYPE* pMediaType);
- STDMETHODIMP_(bool) ResetDevice();
-
- // IMFClockStateSink
- STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset);
- STDMETHODIMP STDMETHODCALLTYPE OnClockStop(MFTIME hnsSystemTime);
- STDMETHODIMP STDMETHODCALLTYPE OnClockPause(MFTIME hnsSystemTime);
- STDMETHODIMP STDMETHODCALLTYPE OnClockRestart(MFTIME hnsSystemTime);
- STDMETHODIMP STDMETHODCALLTYPE OnClockSetRate(MFTIME hnsSystemTime, float flRate);
-
- // IBaseFilter delegate
- bool GetState( DWORD dwMilliSecsTimeout, FILTER_STATE *State, HRESULT &_ReturnValue);
-
- // IQualProp (EVR statistics window). These are incompletely implemented currently
- STDMETHODIMP get_FramesDroppedInRenderer(int *pcFrames);
- STDMETHODIMP get_FramesDrawn(int *pcFramesDrawn);
- STDMETHODIMP get_AvgFrameRate(int *piAvgFrameRate);
- STDMETHODIMP get_Jitter(int *iJitter);
- STDMETHODIMP get_AvgSyncOffset(int *piAvg);
- STDMETHODIMP get_DevSyncOffset(int *piDev);
-
- // IMFRateSupport
- STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
- STDMETHODIMP GetFastestRate(MFRATE_DIRECTION eDirection, BOOL fThin, float *pflRate);
- STDMETHODIMP IsRateSupported(BOOL fThin, float flRate, float *pflNearestSupportedRate);
- float GetMaxRate(BOOL bThin);
-
- // IMFVideoPresenter
- STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
- STDMETHODIMP GetCurrentMediaType(__deref_out IMFVideoMediaType **ppMediaType);
-
- // IMFTopologyServiceLookupClient
- STDMETHODIMP InitServicePointers(__in IMFTopologyServiceLookup *pLookup);
- STDMETHODIMP ReleaseServicePointers();
-
- // IMFVideoDeviceID
- STDMETHODIMP GetDeviceID(__out IID *pDeviceID);
-
- // IMFGetService
- STDMETHODIMP GetService (__RPC__in REFGUID guidService, __RPC__in REFIID riid, __RPC__deref_out_opt LPVOID *ppvObject);
-
- // IMFAsyncCallback
- STDMETHODIMP GetParameters(__RPC__out DWORD *pdwFlags, /* [out] */ __RPC__out DWORD *pdwQueue);
- STDMETHODIMP Invoke(__RPC__in_opt IMFAsyncResult *pAsyncResult);
-
- // IMFVideoDisplayControl
- STDMETHODIMP GetNativeVideoSize(SIZE *pszVideo, SIZE *pszARVideo);
- STDMETHODIMP GetIdealVideoSize(SIZE *pszMin, SIZE *pszMax);
- STDMETHODIMP SetVideoPosition(const MFVideoNormalizedRect *pnrcSource, const LPRECT prcDest);
- STDMETHODIMP GetVideoPosition(MFVideoNormalizedRect *pnrcSource, LPRECT prcDest);
- STDMETHODIMP SetAspectRatioMode(DWORD dwAspectRatioMode);
- STDMETHODIMP GetAspectRatioMode(DWORD *pdwAspectRatioMode);
- STDMETHODIMP SetVideoWindow(HWND hwndVideo);
- STDMETHODIMP GetVideoWindow(HWND *phwndVideo);
- STDMETHODIMP RepaintVideo( void);
- STDMETHODIMP GetCurrentImage(BITMAPINFOHEADER *pBih, BYTE **pDib, DWORD *pcbDib, LONGLONG *pTimeStamp);
- STDMETHODIMP SetBorderColor(COLORREF Clr);
- STDMETHODIMP GetBorderColor(COLORREF *pClr);
- STDMETHODIMP SetRenderingPrefs(DWORD dwRenderFlags);
- STDMETHODIMP GetRenderingPrefs(DWORD *pdwRenderFlags);
- STDMETHODIMP SetFullscreen(BOOL fFullscreen);
- STDMETHODIMP GetFullscreen(BOOL *pfFullscreen);
-
- // IEVRTrustedVideoPlugin
- STDMETHODIMP IsInTrustedVideoMode(BOOL *pYes);
- STDMETHODIMP CanConstrict(BOOL *pYes);
- STDMETHODIMP SetConstriction(DWORD dwKPix);
- STDMETHODIMP DisableImageExport(BOOL bDisable);
-
- // IDirect3DDeviceManager9
- STDMETHODIMP ResetDevice(IDirect3DDevice9 *pDevice,UINT resetToken);
- STDMETHODIMP OpenDeviceHandle(HANDLE *phDevice);
- STDMETHODIMP CloseDeviceHandle(HANDLE hDevice);
- STDMETHODIMP TestDevice(HANDLE hDevice);
- STDMETHODIMP LockDevice(HANDLE hDevice, IDirect3DDevice9 **ppDevice, BOOL fBlock);
- STDMETHODIMP UnlockDevice(HANDLE hDevice, BOOL fSaveState);
- STDMETHODIMP GetVideoService(HANDLE hDevice, REFIID riid, void **ppService);
-
-protected:
- void OnResetDevice();
- MFCLOCK_STATE m_LastClockState;
-
-private:
- // dxva.dll
- typedef HRESULT (__stdcall *PTR_DXVA2CreateDirect3DDeviceManager9)(UINT* pResetToken, IDirect3DDeviceManager9** ppDeviceManager);
- // mf.dll
- typedef HRESULT (__stdcall *PTR_MFCreatePresentationClock)(IMFPresentationClock** ppPresentationClock);
- // evr.dll
- typedef HRESULT (__stdcall *PTR_MFCreateDXSurfaceBuffer)(REFIID riid, IUnknown* punkSurface, BOOL fBottomUpWhenLinear, IMFMediaBuffer** ppBuffer);
- typedef HRESULT (__stdcall *PTR_MFCreateVideoSampleFromSurface)(IUnknown* pUnkSurface, IMFSample** ppSample);
- typedef HRESULT (__stdcall *PTR_MFCreateVideoMediaType)(const MFVIDEOFORMAT* pVideoFormat, IMFVideoMediaType** ppIVideoMediaType);
- // avrt.dll
- typedef HANDLE (__stdcall *PTR_AvSetMmThreadCharacteristicsW)(LPCWSTR TaskName, LPDWORD TaskIndex);
- typedef BOOL (__stdcall *PTR_AvSetMmThreadPriority)(HANDLE AvrtHandle, AVRT_PRIORITY Priority);
- typedef BOOL (__stdcall *PTR_AvRevertMmThreadCharacteristics)(HANDLE AvrtHandle);
-
- typedef enum
+ private:
+ // dxva.dll
+ typedef HRESULT (__stdcall *PTR_DXVA2CreateDirect3DDeviceManager9)(UINT* pResetToken, IDirect3DDeviceManager9** ppDeviceManager);
+ // mf.dll
+ typedef HRESULT (__stdcall *PTR_MFCreatePresentationClock)(IMFPresentationClock** ppPresentationClock);
+ // evr.dll
+ typedef HRESULT (__stdcall *PTR_MFCreateDXSurfaceBuffer)(REFIID riid, IUnknown* punkSurface, BOOL fBottomUpWhenLinear, IMFMediaBuffer** ppBuffer);
+ typedef HRESULT (__stdcall *PTR_MFCreateVideoSampleFromSurface)(IUnknown* pUnkSurface, IMFSample** ppSample);
+ typedef HRESULT (__stdcall *PTR_MFCreateVideoMediaType)(const MFVIDEOFORMAT* pVideoFormat, IMFVideoMediaType** ppIVideoMediaType);
+ // avrt.dll
+ typedef HANDLE (__stdcall *PTR_AvSetMmThreadCharacteristicsW)(LPCWSTR TaskName, LPDWORD TaskIndex);
+ typedef BOOL (__stdcall *PTR_AvSetMmThreadPriority)(HANDLE AvrtHandle, AVRT_PRIORITY Priority);
+ typedef BOOL (__stdcall *PTR_AvRevertMmThreadCharacteristics)(HANDLE AvrtHandle);
+
+ typedef enum {
+ Started = State_Running,
+ Stopped = State_Stopped,
+ Paused = State_Paused,
+ Shutdown = State_Running + 1
+ } RENDER_STATE;
+
+ CComPtr<IMFClock> m_pClock;
+ CComPtr<IDirect3DDeviceManager9> m_pD3DManager;
+ CComPtr<IMFTransform> m_pMixer;
+ CComPtr<IMediaEventSink> m_pSink;
+ CComPtr<IMFVideoMediaType> m_pMediaType;
+ MFVideoAspectRatioMode m_dwVideoAspectRatioMode;
+ MFVideoRenderPrefs m_dwVideoRenderPrefs;
+ COLORREF m_BorderColor;
+
+ HANDLE m_hEvtQuit; // Stop rendering thread event
+ bool m_bEvtQuit;
+ HANDLE m_hEvtFlush; // Discard all buffers
+ bool m_bEvtFlush;
+ HANDLE m_hEvtSkip; // Skip frame
+ bool m_bEvtSkip;
+
+ bool m_bUseInternalTimer;
+ int32 m_LastSetOutputRange;
+ bool m_bPendingRenegotiate;
+ bool m_bPendingMediaFinished;
+ bool m_bPrerolled; // true if first sample has been displayed.
+
+ HANDLE m_hRenderThread;
+ HANDLE m_hMixerThread;
+ RENDER_STATE m_nRenderState;
+ bool m_bStepping;
+
+ CCritSec m_SampleQueueLock;
+ CCritSec m_ImageProcessingLock;
+
+ CInterfaceList<IMFSample, &IID_IMFSample> m_FreeSamples;
+ CInterfaceList<IMFSample, &IID_IMFSample> m_ScheduledSamples;
+ IMFSample *m_pCurrentDisplaydSample;
+ UINT m_nResetToken;
+ int m_nStepCount;
+
+ bool GetSampleFromMixer();
+ void MixerThread();
+ static DWORD WINAPI MixerThreadStatic(LPVOID lpParam);
+ void RenderThread();
+ static DWORD WINAPI RenderThreadStatic(LPVOID lpParam);
+
+ void StartWorkerThreads();
+ void StopWorkerThreads();
+ HRESULT CheckShutdown() const;
+ void CompleteFrameStep(bool bCancel);
+
+ void RemoveAllSamples();
+ STDMETHODIMP AdviseSyncClock(ISyncClock* sC);
+ HRESULT BeginStreaming();
+ HRESULT GetFreeSample(IMFSample** ppSample);
+ HRESULT GetScheduledSample(IMFSample** ppSample, int &_Count);
+ void MoveToFreeList(IMFSample* pSample, bool bTail);
+ void MoveToScheduledList(IMFSample* pSample, bool _bSorted);
+ void FlushSamples();
+ void FlushSamplesInternal();
+
+ LONGLONG GetMediaTypeMerit(IMFMediaType *pMediaType);
+ HRESULT RenegotiateMediaType();
+ HRESULT IsMediaTypeSupported(IMFMediaType* pMixerType);
+ HRESULT CreateProposedOutputType(IMFMediaType* pMixerType, IMFMediaType** pType);
+ HRESULT SetMediaType(IMFMediaType* pType);
+
+ // Functions pointers for Vista/.NET3 specific library
+ PTR_DXVA2CreateDirect3DDeviceManager9 pfDXVA2CreateDirect3DDeviceManager9;
+ PTR_MFCreateDXSurfaceBuffer pfMFCreateDXSurfaceBuffer;
+ PTR_MFCreateVideoSampleFromSurface pfMFCreateVideoSampleFromSurface;
+ PTR_MFCreateVideoMediaType pfMFCreateVideoMediaType;
+
+ PTR_AvSetMmThreadCharacteristicsW pfAvSetMmThreadCharacteristicsW;
+ PTR_AvSetMmThreadPriority pfAvSetMmThreadPriority;
+ PTR_AvRevertMmThreadCharacteristics pfAvRevertMmThreadCharacteristics;
+ };
+
+ class CSyncRenderer:
+ public CUnknown,
+ public IVMRffdshow9,
+ public IVMRMixerBitmap9,
+ public IBaseFilter
{
- Started = State_Running,
- Stopped = State_Stopped,
- Paused = State_Paused,
- Shutdown = State_Running + 1
- } RENDER_STATE;
-
- CComPtr<IMFClock> m_pClock;
- CComPtr<IDirect3DDeviceManager9> m_pD3DManager;
- CComPtr<IMFTransform> m_pMixer;
- CComPtr<IMediaEventSink> m_pSink;
- CComPtr<IMFVideoMediaType> m_pMediaType;
- MFVideoAspectRatioMode m_dwVideoAspectRatioMode;
- MFVideoRenderPrefs m_dwVideoRenderPrefs;
- COLORREF m_BorderColor;
-
- HANDLE m_hEvtQuit; // Stop rendering thread event
- bool m_bEvtQuit;
- HANDLE m_hEvtFlush; // Discard all buffers
- bool m_bEvtFlush;
- HANDLE m_hEvtSkip; // Skip frame
- bool m_bEvtSkip;
-
- bool m_bUseInternalTimer;
- int32 m_LastSetOutputRange;
- bool m_bPendingRenegotiate;
- bool m_bPendingMediaFinished;
- bool m_bPrerolled; // true if first sample has been displayed.
-
- HANDLE m_hRenderThread;
- HANDLE m_hMixerThread;
- RENDER_STATE m_nRenderState;
- bool m_bStepping;
-
- CCritSec m_SampleQueueLock;
- CCritSec m_ImageProcessingLock;
-
- CInterfaceList<IMFSample, &IID_IMFSample> m_FreeSamples;
- CInterfaceList<IMFSample, &IID_IMFSample> m_ScheduledSamples;
- IMFSample *m_pCurrentDisplaydSample;
- UINT m_nResetToken;
- int m_nStepCount;
-
- bool GetSampleFromMixer();
- void MixerThread();
- static DWORD WINAPI MixerThreadStatic(LPVOID lpParam);
- void RenderThread();
- static DWORD WINAPI RenderThreadStatic(LPVOID lpParam);
-
- void StartWorkerThreads();
- void StopWorkerThreads();
- HRESULT CheckShutdown() const;
- void CompleteFrameStep(bool bCancel);
-
- void RemoveAllSamples();
- STDMETHODIMP AdviseSyncClock(ISyncClock* sC);
- HRESULT BeginStreaming();
- HRESULT GetFreeSample(IMFSample** ppSample);
- HRESULT GetScheduledSample(IMFSample** ppSample, int &_Count);
- void MoveToFreeList(IMFSample* pSample, bool bTail);
- void MoveToScheduledList(IMFSample* pSample, bool _bSorted);
- void FlushSamples();
- void FlushSamplesInternal();
-
- LONGLONG GetMediaTypeMerit(IMFMediaType *pMediaType);
- HRESULT RenegotiateMediaType();
- HRESULT IsMediaTypeSupported(IMFMediaType* pMixerType);
- HRESULT CreateProposedOutputType(IMFMediaType* pMixerType, IMFMediaType** pType);
- HRESULT SetMediaType(IMFMediaType* pType);
-
- // Functions pointers for Vista/.NET3 specific library
- PTR_DXVA2CreateDirect3DDeviceManager9 pfDXVA2CreateDirect3DDeviceManager9;
- PTR_MFCreateDXSurfaceBuffer pfMFCreateDXSurfaceBuffer;
- PTR_MFCreateVideoSampleFromSurface pfMFCreateVideoSampleFromSurface;
- PTR_MFCreateVideoMediaType pfMFCreateVideoMediaType;
-
- PTR_AvSetMmThreadCharacteristicsW pfAvSetMmThreadCharacteristicsW;
- PTR_AvSetMmThreadPriority pfAvSetMmThreadPriority;
- PTR_AvRevertMmThreadCharacteristics pfAvRevertMmThreadCharacteristics;
-};
-
-class CSyncRenderer:
- public CUnknown,
- public IVMRffdshow9,
- public IVMRMixerBitmap9,
- public IBaseFilter
-{
- CComPtr<IUnknown> m_pEVR;
- VMR9AlphaBitmap *m_pVMR9AlphaBitmap;
- CSyncAP *m_pAllocatorPresenter;
-
-public:
- CSyncRenderer(const TCHAR* pName, LPUNKNOWN pUnk, HRESULT& hr, VMR9AlphaBitmap* pVMR9AlphaBitmap, CSyncAP *pAllocatorPresenter);
- ~CSyncRenderer();
-
- // IBaseFilter
- virtual HRESULT STDMETHODCALLTYPE EnumPins(__out IEnumPins **ppEnum);
- virtual HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, __out IPin **ppPin);
- virtual HRESULT STDMETHODCALLTYPE QueryFilterInfo(__out FILTER_INFO *pInfo);
- virtual HRESULT STDMETHODCALLTYPE JoinFilterGraph(__in_opt IFilterGraph *pGraph, __in_opt LPCWSTR pName);
- virtual HRESULT STDMETHODCALLTYPE QueryVendorInfo(__out LPWSTR *pVendorInfo);
- virtual HRESULT STDMETHODCALLTYPE Stop(void);
- virtual HRESULT STDMETHODCALLTYPE Pause(void);
- virtual HRESULT STDMETHODCALLTYPE Run(REFERENCE_TIME tStart);
- virtual HRESULT STDMETHODCALLTYPE GetState(DWORD dwMilliSecsTimeout, __out FILTER_STATE *State);
- virtual HRESULT STDMETHODCALLTYPE SetSyncSource(__in_opt IReferenceClock *pClock);
- virtual HRESULT STDMETHODCALLTYPE GetSyncSource(__deref_out_opt IReferenceClock **pClock);
- virtual HRESULT STDMETHODCALLTYPE GetClassID(__RPC__out CLSID *pClassID);
-
- // IVMRffdshow9
- virtual HRESULT STDMETHODCALLTYPE support_ffdshow();
-
- // IVMRMixerBitmap9
- STDMETHODIMP GetAlphaBitmapParameters(VMR9AlphaBitmap* pBmpParms);
- STDMETHODIMP SetAlphaBitmap(const VMR9AlphaBitmap* pBmpParms);
- STDMETHODIMP UpdateAlphaBitmapParameters(const VMR9AlphaBitmap* pBmpParms);
-
- DECLARE_IUNKNOWN;
- virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface(REFIID riid, void** ppvObject);
-};
-
-class CGenlock
-{
-public:
- class MovingAverage
+ CComPtr<IUnknown> m_pEVR;
+ VMR9AlphaBitmap *m_pVMR9AlphaBitmap;
+ CSyncAP *m_pAllocatorPresenter;
+
+ public:
+ CSyncRenderer(const TCHAR* pName, LPUNKNOWN pUnk, HRESULT& hr, VMR9AlphaBitmap* pVMR9AlphaBitmap, CSyncAP *pAllocatorPresenter);
+ ~CSyncRenderer();
+
+ // IBaseFilter
+ virtual HRESULT STDMETHODCALLTYPE EnumPins(__out IEnumPins **ppEnum);
+ virtual HRESULT STDMETHODCALLTYPE FindPin(LPCWSTR Id, __out IPin **ppPin);
+ virtual HRESULT STDMETHODCALLTYPE QueryFilterInfo(__out FILTER_INFO *pInfo);
+ virtual HRESULT STDMETHODCALLTYPE JoinFilterGraph(__in_opt IFilterGraph *pGraph, __in_opt LPCWSTR pName);
+ virtual HRESULT STDMETHODCALLTYPE QueryVendorInfo(__out LPWSTR *pVendorInfo);
+ virtual HRESULT STDMETHODCALLTYPE Stop(void);
+ virtual HRESULT STDMETHODCALLTYPE Pause(void);
+ virtual HRESULT STDMETHODCALLTYPE Run(REFERENCE_TIME tStart);
+ virtual HRESULT STDMETHODCALLTYPE GetState(DWORD dwMilliSecsTimeout, __out FILTER_STATE *State);
+ virtual HRESULT STDMETHODCALLTYPE SetSyncSource(__in_opt IReferenceClock *pClock);
+ virtual HRESULT STDMETHODCALLTYPE GetSyncSource(__deref_out_opt IReferenceClock **pClock);
+ virtual HRESULT STDMETHODCALLTYPE GetClassID(__RPC__out CLSID *pClassID);
+
+ // IVMRffdshow9
+ virtual HRESULT STDMETHODCALLTYPE support_ffdshow();
+
+ // IVMRMixerBitmap9
+ STDMETHODIMP GetAlphaBitmapParameters(VMR9AlphaBitmap* pBmpParms);
+ STDMETHODIMP SetAlphaBitmap(const VMR9AlphaBitmap* pBmpParms);
+ STDMETHODIMP UpdateAlphaBitmapParameters(const VMR9AlphaBitmap* pBmpParms);
+
+ DECLARE_IUNKNOWN;
+ virtual HRESULT STDMETHODCALLTYPE NonDelegatingQueryInterface(REFIID riid, void** ppvObject);
+ };
+
+ class CGenlock
{
public:
- MovingAverage(INT size):
- fifoSize(size),
- oldestSample(0),
- sum(0)
+ class MovingAverage
{
- if (fifoSize > MAX_FIFO_SIZE)
- {
- fifoSize = MAX_FIFO_SIZE;
+ public:
+ MovingAverage(INT size):
+ fifoSize(size),
+ oldestSample(0),
+ sum(0) {
+ if (fifoSize > MAX_FIFO_SIZE) {
+ fifoSize = MAX_FIFO_SIZE;
+ }
+ for (INT i = 0; i < MAX_FIFO_SIZE; i++) {
+ fifo[i] = 0;
+ }
}
- for (INT i = 0; i < MAX_FIFO_SIZE; i++)
- fifo[i] = 0;
- }
- ~MovingAverage()
- {
- }
+ ~MovingAverage() {
+ }
- double Average(double sample)
- {
- sum = sum + sample - fifo[oldestSample];
- fifo[oldestSample] = sample;
- oldestSample++;
- if (oldestSample == fifoSize)
- oldestSample = 0;
- return sum / fifoSize;
- }
+ double Average(double sample) {
+ sum = sum + sample - fifo[oldestSample];
+ fifo[oldestSample] = sample;
+ oldestSample++;
+ if (oldestSample == fifoSize) {
+ oldestSample = 0;
+ }
+ return sum / fifoSize;
+ }
+
+ private:
+ INT fifoSize;
+ double fifo[MAX_FIFO_SIZE];
+ INT oldestSample;
+ double sum;
+ };
+
+ CGenlock(DOUBLE target, DOUBLE limit, INT rowD, INT colD, DOUBLE clockD, UINT mon);
+ ~CGenlock();
+
+ BOOL PowerstripRunning(); // TRUE if PowerStrip is running
+ HRESULT GetTiming(); // Get the string representing the display's current timing parameters
+ HRESULT ResetTiming(); // Reset timing to what was last registered by GetTiming()
+ HRESULT ResetClock(); // Reset reference clock speed to nominal
+ HRESULT SetTargetSyncOffset(DOUBLE targetD);
+ HRESULT GetTargetSyncOffset(DOUBLE *targetD);
+ HRESULT SetControlLimit(DOUBLE cL);
+ HRESULT GetControlLimit(DOUBLE *cL);
+ HRESULT SetDisplayResolution(UINT columns, UINT lines);
+ HRESULT AdviseSyncClock(ISyncClock* sC);
+ HRESULT SetMonitor(UINT mon); // Set the number of the monitor to synchronize
+ HRESULT ResetStats(); // Reset timing statistics
+
+ HRESULT ControlDisplay(double syncOffset, double frameCycle); // Adjust the frequency of the display if needed
+ HRESULT ControlClock(double syncOffset, double frameCycle); // Adjust the frequency of the clock if needed
+ HRESULT UpdateStats(double syncOffset, double frameCycle); // Don't adjust anything, just update the syncOffset stats
+
+ BOOL powerstripTimingExists; // TRUE if display timing has been got through Powerstrip
+ BOOL liveSource; // TRUE if live source -> display sync is the only option
+ INT adjDelta; // -1 for display slower in relation to video, 0 for keep, 1 for faster
+ INT lineDelta; // The number of rows added or subtracted when adjusting display fps
+ INT columnDelta; // The number of colums added or subtracted when adjusting display fps
+ DOUBLE cycleDelta; // Adjustment factor for cycle time as fraction of nominal value
+ UINT displayAdjustmentsMade; // The number of adjustments made to display refresh rate
+ UINT clockAdjustmentsMade; // The number of adjustments made to clock frequency
+
+ UINT totalLines, totalColumns; // Including the porches and sync widths
+ UINT visibleLines, visibleColumns; // The nominal resolution
+ MovingAverage *syncOffsetFifo;
+ MovingAverage *frameCycleFifo;
+ DOUBLE minSyncOffset, maxSyncOffset;
+ DOUBLE syncOffsetAvg; // Average of the above
+ DOUBLE minFrameCycle, maxFrameCycle;
+ DOUBLE frameCycleAvg;
+
+ UINT pixelClock; // In pixels/s
+ DOUBLE displayFreqCruise; // Nominal display frequency in frames/s
+ DOUBLE displayFreqSlower;
+ DOUBLE displayFreqFaster;
+ DOUBLE curDisplayFreq; // Current (adjusted) display frequency
+ DOUBLE controlLimit; // How much the sync offset is allowed to drift from target sync offset
+ WPARAM monitor; // The monitor to be controlled. 0-based.
+ CComPtr<ISyncClock> syncClock; // Interface to an adjustable reference clock
private:
- INT fifoSize;
- double fifo[MAX_FIFO_SIZE];
- INT oldestSample;
- double sum;
+ HWND psWnd; // PowerStrip window
+ const static INT TIMING_PARAM_CNT = 10;
+ const static INT MAX_LOADSTRING = 100;
+ UINT displayTiming[TIMING_PARAM_CNT]; // Display timing parameters
+ UINT displayTimingSave[TIMING_PARAM_CNT]; // So that we can reset the display at exit
+ TCHAR faster[MAX_LOADSTRING]; // String corresponding to faster display frequency
+ TCHAR cruise[MAX_LOADSTRING]; // String corresponding to nominal display frequency
+ TCHAR slower[MAX_LOADSTRING]; // String corresponding to slower display frequency
+ TCHAR savedTiming[MAX_LOADSTRING]; // String version of saved timing (to be restored upon exit)
+ DOUBLE lowSyncOffset; // The closest we want to let the scheduled render time to get to the next vsync. In % of the frame time
+ DOUBLE targetSyncOffset; // Where we want the scheduled render time to be in relation to the next vsync
+ DOUBLE highSyncOffset; // The furthers we want to let the scheduled render time to get to the next vsync
+ CCritSec csGenlockLock;
};
-
- CGenlock(DOUBLE target, DOUBLE limit, INT rowD, INT colD, DOUBLE clockD, UINT mon);
- ~CGenlock();
-
- BOOL PowerstripRunning(); // TRUE if PowerStrip is running
- HRESULT GetTiming(); // Get the string representing the display's current timing parameters
- HRESULT ResetTiming(); // Reset timing to what was last registered by GetTiming()
- HRESULT ResetClock(); // Reset reference clock speed to nominal
- HRESULT SetTargetSyncOffset(DOUBLE targetD);
- HRESULT GetTargetSyncOffset(DOUBLE *targetD);
- HRESULT SetControlLimit(DOUBLE cL);
- HRESULT GetControlLimit(DOUBLE *cL);
- HRESULT SetDisplayResolution(UINT columns, UINT lines);
- HRESULT AdviseSyncClock(ISyncClock* sC);
- HRESULT SetMonitor(UINT mon); // Set the number of the monitor to synchronize
- HRESULT ResetStats(); // Reset timing statistics
-
- HRESULT ControlDisplay(double syncOffset, double frameCycle); // Adjust the frequency of the display if needed
- HRESULT ControlClock(double syncOffset, double frameCycle); // Adjust the frequency of the clock if needed
- HRESULT UpdateStats(double syncOffset, double frameCycle); // Don't adjust anything, just update the syncOffset stats
-
- BOOL powerstripTimingExists; // TRUE if display timing has been got through Powerstrip
- BOOL liveSource; // TRUE if live source -> display sync is the only option
- INT adjDelta; // -1 for display slower in relation to video, 0 for keep, 1 for faster
- INT lineDelta; // The number of rows added or subtracted when adjusting display fps
- INT columnDelta; // The number of colums added or subtracted when adjusting display fps
- DOUBLE cycleDelta; // Adjustment factor for cycle time as fraction of nominal value
- UINT displayAdjustmentsMade; // The number of adjustments made to display refresh rate
- UINT clockAdjustmentsMade; // The number of adjustments made to clock frequency
-
- UINT totalLines, totalColumns; // Including the porches and sync widths
- UINT visibleLines, visibleColumns; // The nominal resolution
- MovingAverage *syncOffsetFifo;
- MovingAverage *frameCycleFifo;
- DOUBLE minSyncOffset, maxSyncOffset;
- DOUBLE syncOffsetAvg; // Average of the above
- DOUBLE minFrameCycle, maxFrameCycle;
- DOUBLE frameCycleAvg;
-
- UINT pixelClock; // In pixels/s
- DOUBLE displayFreqCruise; // Nominal display frequency in frames/s
- DOUBLE displayFreqSlower;
- DOUBLE displayFreqFaster;
- DOUBLE curDisplayFreq; // Current (adjusted) display frequency
- DOUBLE controlLimit; // How much the sync offset is allowed to drift from target sync offset
- WPARAM monitor; // The monitor to be controlled. 0-based.
- CComPtr<ISyncClock> syncClock; // Interface to an adjustable reference clock
-
-private:
- HWND psWnd; // PowerStrip window
- const static INT TIMING_PARAM_CNT = 10;
- const static INT MAX_LOADSTRING = 100;
- UINT displayTiming[TIMING_PARAM_CNT]; // Display timing parameters
- UINT displayTimingSave[TIMING_PARAM_CNT]; // So that we can reset the display at exit
- TCHAR faster[MAX_LOADSTRING]; // String corresponding to faster display frequency
- TCHAR cruise[MAX_LOADSTRING]; // String corresponding to nominal display frequency
- TCHAR slower[MAX_LOADSTRING]; // String corresponding to slower display frequency
- TCHAR savedTiming[MAX_LOADSTRING]; // String version of saved timing (to be restored upon exit)
- DOUBLE lowSyncOffset; // The closest we want to let the scheduled render time to get to the next vsync. In % of the frame time
- DOUBLE targetSyncOffset; // Where we want the scheduled render time to be in relation to the next vsync
- DOUBLE highSyncOffset; // The furthers we want to let the scheduled render time to get to the next vsync
- CCritSec csGenlockLock;
-};
}
diff --git a/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.cpp
index b8afdadd3..8a503e17d 100644
--- a/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.cpp
@@ -42,11 +42,11 @@ CVMR7AllocatorPresenter::CVMR7AllocatorPresenter(HWND hWnd, HRESULT& hr)
: CDX7AllocatorPresenter(hWnd, hr)
, m_fUseInternalTimer(false)
{
- if(FAILED(hr))
+ if(FAILED(hr)) {
return;
+ }
- if(FAILED(hr = m_pSA.CoCreateInstance(CLSID_AllocPresenter)))
- {
+ if(FAILED(hr = m_pSA.CoCreateInstance(CLSID_AllocPresenter))) {
hr = E_FAIL;
return;
}
@@ -66,13 +66,15 @@ STDMETHODIMP CVMR7AllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, v
HRESULT CVMR7AllocatorPresenter::CreateDevice()
{
HRESULT hr = __super::CreateDevice();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
- if(m_pIVMRSurfAllocNotify)
- {
+ if(m_pIVMRSurfAllocNotify) {
HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
- if(FAILED(hr = m_pIVMRSurfAllocNotify->ChangeDDrawDevice(m_pDD, hMonitor)))
- return hr; //return(false);
+ if(FAILED(hr = m_pIVMRSurfAllocNotify->ChangeDDrawDevice(m_pDD, hMonitor))) {
+ return hr; //return(false);
+ }
}
return hr;
@@ -97,27 +99,31 @@ STDMETHODIMP CVMR7AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
HRESULT hr;
- do
- {
+ do {
CComPtr<IBaseFilter> pBF;
- if(FAILED(hr = pBF.CoCreateInstance(CLSID_VideoMixingRenderer)))
+ if(FAILED(hr = pBF.CoCreateInstance(CLSID_VideoMixingRenderer))) {
break;
+ }
CComQIPtr<IVMRFilterConfig> pConfig = pBF;
- if(!pConfig)
+ if(!pConfig) {
break;
+ }
- if(FAILED(hr = pConfig->SetRenderingMode(VMRMode_Renderless)))
+ if(FAILED(hr = pConfig->SetRenderingMode(VMRMode_Renderless))) {
break;
+ }
CComQIPtr<IVMRSurfaceAllocatorNotify> pSAN = pBF;
- if(!pSAN)
+ if(!pSAN) {
break;
+ }
if(FAILED(hr = pSAN->AdviseSurfaceAllocator(MY_USER_ID, static_cast<IVMRSurfaceAllocator*>(this)))
- || FAILED(hr = AdviseNotify(pSAN)))
+ || FAILED(hr = AdviseNotify(pSAN))) {
break;
+ }
CComPtr<IPin> pPin = GetFirstPin(pBF);
CComQIPtr<IMemInputPin> pMemInputPin = pPin;
@@ -126,8 +132,7 @@ STDMETHODIMP CVMR7AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
*ppRenderer = (IUnknown*)pBF.Detach();
return S_OK;
- }
- while(0);
+ } while(0);
return E_FAIL;
}
@@ -135,18 +140,20 @@ STDMETHODIMP CVMR7AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
STDMETHODIMP_(void) CVMR7AllocatorPresenter::SetTime(REFERENCE_TIME rtNow)
{
__super::SetTime(rtNow);
-// m_fUseInternalTimer = false;
+ // m_fUseInternalTimer = false;
}
// IVMRSurfaceAllocator
STDMETHODIMP CVMR7AllocatorPresenter::AllocateSurface(DWORD_PTR dwUserID, VMRALLOCATIONINFO* lpAllocInfo, DWORD* lpdwBuffer, LPDIRECTDRAWSURFACE7* lplpSurface)
{
- if(!lpAllocInfo || !lpdwBuffer || !lplpSurface)
+ if(!lpAllocInfo || !lpdwBuffer || !lplpSurface) {
return E_POINTER;
+ }
- if(!m_pIVMRSurfAllocNotify)
+ if(!m_pIVMRSurfAllocNotify) {
return E_FAIL;
+ }
HRESULT hr;
@@ -157,24 +164,28 @@ STDMETHODIMP CVMR7AllocatorPresenter::AllocateSurface(DWORD_PTR dwUserID, VMRALL
// then that might stall for about 30 seconds because of some unknown buggy code
// behind <ddraw surface>->Release()
- if(lpAllocInfo->lpHdr->biBitCount < 16)
+ if(lpAllocInfo->lpHdr->biBitCount < 16) {
return E_FAIL;
+ }
hr = m_pSA->AllocateSurface(dwUserID, lpAllocInfo, lpdwBuffer, lplpSurface);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
m_NativeVideoSize = CSize(abs(lpAllocInfo->lpHdr->biWidth), abs(lpAllocInfo->lpHdr->biHeight));
m_AspectRatio = m_NativeVideoSize;
int arx = lpAllocInfo->szAspectRatio.cx, ary = lpAllocInfo->szAspectRatio.cy;
- if(arx > 0 && ary > 0) m_AspectRatio.SetSize(arx, ary);
+ if(arx > 0 && ary > 0) {
+ m_AspectRatio.SetSize(arx, ary);
+ }
- if(FAILED(hr = AllocSurfaces()))
+ if(FAILED(hr = AllocSurfaces())) {
return hr;
+ }
// test if the colorspace is acceptable
- if(FAILED(hr = m_pVideoSurface->Blt(NULL, *lplpSurface, NULL, DDBLT_WAIT, NULL)))
- {
+ if(FAILED(hr = m_pVideoSurface->Blt(NULL, *lplpSurface, NULL, DDBLT_WAIT, NULL))) {
DeleteSurfaces();
return hr;
}
@@ -197,8 +208,9 @@ STDMETHODIMP CVMR7AllocatorPresenter::PrepareSurface(DWORD_PTR dwUserID, IDirect
{
SetThreadName((DWORD)-1, "CVMR7AllocatorPresenter");
- if(!lpSurface)
+ if(!lpSurface) {
return E_POINTER;
+ }
// FIXME: sometimes the msmpeg4/divx3/wmv decoder wants to reuse our
// surface (expects it to point to the same mem every time), and to avoid
@@ -217,8 +229,9 @@ STDMETHODIMP CVMR7AllocatorPresenter::AdviseNotify(IVMRSurfaceAllocatorNotify* l
HRESULT hr;
HMONITOR hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
- if(FAILED(hr = m_pIVMRSurfAllocNotify->SetDDrawDevice(m_pDD, hMonitor)))
+ if(FAILED(hr = m_pIVMRSurfAllocNotify->SetDDrawDevice(m_pDD, hMonitor))) {
return hr;
+ }
return m_pSA->AdviseNotify(lpIVMRSurfAllocNotify);
}
@@ -227,8 +240,7 @@ STDMETHODIMP CVMR7AllocatorPresenter::AdviseNotify(IVMRSurfaceAllocatorNotify* l
STDMETHODIMP CVMR7AllocatorPresenter::StartPresenting(DWORD_PTR dwUserID)
{
- if (!m_bPendingResetDevice)
- {
+ if (!m_bPendingResetDevice) {
ASSERT(m_pD3DDev);
}
@@ -244,25 +256,24 @@ STDMETHODIMP CVMR7AllocatorPresenter::StopPresenting(DWORD_PTR dwUserID)
STDMETHODIMP CVMR7AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMRPRESENTATIONINFO* lpPresInfo)
{
- if(!lpPresInfo || !lpPresInfo->lpSurf)
+ if(!lpPresInfo || !lpPresInfo->lpSurf) {
return E_POINTER;
+ }
CAutoLock cAutoLock(this);
- if (!m_bPendingResetDevice)
+ if (!m_bPendingResetDevice) {
m_pVideoSurface->Blt(NULL, lpPresInfo->lpSurf, NULL, DDBLT_WAIT, NULL);
+ }
- if(lpPresInfo->rtEnd > lpPresInfo->rtStart)
- {
+ if(lpPresInfo->rtEnd > lpPresInfo->rtStart) {
REFERENCE_TIME rtTimePerFrame = lpPresInfo->rtEnd - lpPresInfo->rtStart;
m_fps = 10000000.0 / rtTimePerFrame;
- if(m_pSubPicQueue)
- {
+ if(m_pSubPicQueue) {
m_pSubPicQueue->SetFPS(m_fps);
- if(m_fUseInternalTimer && !g_bExternalSubtitleTime)
- {
+ if(m_fUseInternalTimer && !g_bExternalSubtitleTime) {
__super::SetTime(g_tSegmentStart + g_tSampleStart);
}
}
@@ -270,9 +281,10 @@ STDMETHODIMP CVMR7AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMRPRESEN
CSize VideoSize = m_NativeVideoSize;
int arx = lpPresInfo->szAspectRatio.cx, ary = lpPresInfo->szAspectRatio.cy;
- if(arx > 0 && ary > 0) VideoSize.cx = VideoSize.cy*arx/ary;
- if(VideoSize != GetVideoSize())
- {
+ if(arx > 0 && ary > 0) {
+ VideoSize.cx = VideoSize.cy*arx/ary;
+ }
+ if(VideoSize != GetVideoSize()) {
m_AspectRatio.SetSize(arx, ary);
AfxGetApp()->m_pMainWnd->PostMessage(WM_REARRANGERENDERLESS);
}
@@ -293,10 +305,18 @@ STDMETHODIMP CVMR7AllocatorPresenter::GetNativeVideoSize(LONG* lpWidth, LONG* lp
CSize vs = m_NativeVideoSize, ar = m_AspectRatio;
// DVD Nav. bug workaround fix
vs.cx = vs.cy * ar.cx / ar.cy;
- if(lpWidth) *lpWidth = vs.cx;
- if(lpHeight) *lpHeight = vs.cy;
- if(lpARWidth) *lpARWidth = ar.cx;
- if(lpARHeight) *lpARHeight = ar.cy;
+ if(lpWidth) {
+ *lpWidth = vs.cx;
+ }
+ if(lpHeight) {
+ *lpHeight = vs.cy;
+ }
+ if(lpARWidth) {
+ *lpARWidth = ar.cx;
+ }
+ if(lpARHeight) {
+ *lpARHeight = ar.cy;
+ }
return S_OK;
}
@@ -324,7 +344,9 @@ STDMETHODIMP CVMR7AllocatorPresenter::GetVideoPosition(LPRECT lpSRCRect, LPRECT
STDMETHODIMP CVMR7AllocatorPresenter::GetAspectRatioMode(DWORD* lpAspectRatioMode)
{
- if(lpAspectRatioMode) *lpAspectRatioMode = AM_ARMODE_STRETCHED;
+ if(lpAspectRatioMode) {
+ *lpAspectRatioMode = AM_ARMODE_STRETCHED;
+ }
return S_OK;
}
@@ -355,7 +377,9 @@ STDMETHODIMP CVMR7AllocatorPresenter::SetBorderColor(COLORREF Clr)
STDMETHODIMP CVMR7AllocatorPresenter::GetBorderColor(COLORREF* lpClr)
{
- if(lpClr) *lpClr = 0;
+ if(lpClr) {
+ *lpClr = 0;
+ }
return S_OK;
}
diff --git a/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.h
index c3b1708d1..04d8eca6b 100644
--- a/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/VMR7AllocatorPresenter.h
@@ -28,57 +28,57 @@
namespace DSObjects
{
-class CVMR7AllocatorPresenter
- : public CDX7AllocatorPresenter
- , public IVMRSurfaceAllocator
- , public IVMRImagePresenter
- , public IVMRWindowlessControl
-{
- CComPtr<IVMRSurfaceAllocatorNotify> m_pIVMRSurfAllocNotify;
- CComPtr<IVMRSurfaceAllocator> m_pSA;
+ class CVMR7AllocatorPresenter
+ : public CDX7AllocatorPresenter
+ , public IVMRSurfaceAllocator
+ , public IVMRImagePresenter
+ , public IVMRWindowlessControl
+ {
+ CComPtr<IVMRSurfaceAllocatorNotify> m_pIVMRSurfAllocNotify;
+ CComPtr<IVMRSurfaceAllocator> m_pSA;
- HRESULT CreateDevice();
- void DeleteSurfaces();
+ HRESULT CreateDevice();
+ void DeleteSurfaces();
- bool m_fUseInternalTimer;
+ bool m_fUseInternalTimer;
-public:
- CVMR7AllocatorPresenter(HWND hWnd, HRESULT& hr);
+ public:
+ CVMR7AllocatorPresenter(HWND hWnd, HRESULT& hr);
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(void) SetTime(REFERENCE_TIME rtNow);
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(void) SetTime(REFERENCE_TIME rtNow);
- // IVMRSurfaceAllocator
- STDMETHODIMP AllocateSurface(DWORD_PTR dwUserID, VMRALLOCATIONINFO* lpAllocInfo, DWORD* lpdwBuffer, LPDIRECTDRAWSURFACE7* lplpSurface);
- STDMETHODIMP FreeSurface(DWORD_PTR dwUserID);
- STDMETHODIMP PrepareSurface(DWORD_PTR dwUserID, IDirectDrawSurface7* lpSurface, DWORD dwSurfaceFlags);
- STDMETHODIMP AdviseNotify(IVMRSurfaceAllocatorNotify* lpIVMRSurfAllocNotify);
+ // IVMRSurfaceAllocator
+ STDMETHODIMP AllocateSurface(DWORD_PTR dwUserID, VMRALLOCATIONINFO* lpAllocInfo, DWORD* lpdwBuffer, LPDIRECTDRAWSURFACE7* lplpSurface);
+ STDMETHODIMP FreeSurface(DWORD_PTR dwUserID);
+ STDMETHODIMP PrepareSurface(DWORD_PTR dwUserID, IDirectDrawSurface7* lpSurface, DWORD dwSurfaceFlags);
+ STDMETHODIMP AdviseNotify(IVMRSurfaceAllocatorNotify* lpIVMRSurfAllocNotify);
- // IVMRImagePresenter
- STDMETHODIMP StartPresenting(DWORD_PTR dwUserID);
- STDMETHODIMP StopPresenting(DWORD_PTR dwUserID);
- STDMETHODIMP PresentImage(DWORD_PTR dwUserID, VMRPRESENTATIONINFO* lpPresInfo);
+ // IVMRImagePresenter
+ STDMETHODIMP StartPresenting(DWORD_PTR dwUserID);
+ STDMETHODIMP StopPresenting(DWORD_PTR dwUserID);
+ STDMETHODIMP PresentImage(DWORD_PTR dwUserID, VMRPRESENTATIONINFO* lpPresInfo);
- // IVMRWindowlessControl
- STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
- STDMETHODIMP GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
- STDMETHODIMP GetMaxIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
- STDMETHODIMP SetVideoPosition(const LPRECT lpSRCRect, const LPRECT lpDSTRect);
- STDMETHODIMP GetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect);
- STDMETHODIMP GetAspectRatioMode(DWORD* lpAspectRatioMode);
- STDMETHODIMP SetAspectRatioMode(DWORD AspectRatioMode);
- STDMETHODIMP SetVideoClippingWindow(HWND hwnd);
- STDMETHODIMP RepaintVideo(HWND hwnd, HDC hdc);
- STDMETHODIMP DisplayModeChanged();
- STDMETHODIMP GetCurrentImage(BYTE** lpDib);
- STDMETHODIMP SetBorderColor(COLORREF Clr);
- STDMETHODIMP GetBorderColor(COLORREF* lpClr);
- STDMETHODIMP SetColorKey(COLORREF Clr);
- STDMETHODIMP GetColorKey(COLORREF* lpClr);
-};
+ // IVMRWindowlessControl
+ STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
+ STDMETHODIMP GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
+ STDMETHODIMP GetMaxIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
+ STDMETHODIMP SetVideoPosition(const LPRECT lpSRCRect, const LPRECT lpDSTRect);
+ STDMETHODIMP GetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect);
+ STDMETHODIMP GetAspectRatioMode(DWORD* lpAspectRatioMode);
+ STDMETHODIMP SetAspectRatioMode(DWORD AspectRatioMode);
+ STDMETHODIMP SetVideoClippingWindow(HWND hwnd);
+ STDMETHODIMP RepaintVideo(HWND hwnd, HDC hdc);
+ STDMETHODIMP DisplayModeChanged();
+ STDMETHODIMP GetCurrentImage(BYTE** lpDib);
+ STDMETHODIMP SetBorderColor(COLORREF Clr);
+ STDMETHODIMP GetBorderColor(COLORREF* lpClr);
+ STDMETHODIMP SetColorKey(COLORREF Clr);
+ STDMETHODIMP GetColorKey(COLORREF* lpClr);
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.cpp
index 33f780b1c..4b0691b52 100644
--- a/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.cpp
@@ -29,544 +29,442 @@
namespace DSObjects
{
-class COuterVMR9
- : public CUnknown
- , public IVideoWindow
- , public IBasicVideo2
- , public IVMRWindowlessControl
- , public IVMRffdshow9
- , public IVMRMixerBitmap9
-{
- CComPtr<IUnknown> m_pVMR;
- VMR9AlphaBitmap* m_pVMR9AlphaBitmap;
- CDX9AllocatorPresenter *m_pAllocatorPresenter;
+ class COuterVMR9
+ : public CUnknown
+ , public IVideoWindow
+ , public IBasicVideo2
+ , public IVMRWindowlessControl
+ , public IVMRffdshow9
+ , public IVMRMixerBitmap9
+ {
+ CComPtr<IUnknown> m_pVMR;
+ VMR9AlphaBitmap* m_pVMR9AlphaBitmap;
+ CDX9AllocatorPresenter *m_pAllocatorPresenter;
+
+ public:
+
+ COuterVMR9(const TCHAR* pName, LPUNKNOWN pUnk, VMR9AlphaBitmap* pVMR9AlphaBitmap, CDX9AllocatorPresenter *_pAllocatorPresenter) : CUnknown(pName, pUnk) {
+ m_pVMR.CoCreateInstance(CLSID_VideoMixingRenderer9, GetOwner());
+ m_pVMR9AlphaBitmap = pVMR9AlphaBitmap;
+ m_pAllocatorPresenter = _pAllocatorPresenter;
+ }
-public:
+ ~COuterVMR9() {
+ m_pVMR = NULL;
+ }
- COuterVMR9(const TCHAR* pName, LPUNKNOWN pUnk, VMR9AlphaBitmap* pVMR9AlphaBitmap, CDX9AllocatorPresenter *_pAllocatorPresenter) : CUnknown(pName, pUnk)
- {
- m_pVMR.CoCreateInstance(CLSID_VideoMixingRenderer9, GetOwner());
- m_pVMR9AlphaBitmap = pVMR9AlphaBitmap;
- m_pAllocatorPresenter = _pAllocatorPresenter;
- }
+ DECLARE_IUNKNOWN;
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
+ HRESULT hr;
- ~COuterVMR9()
- {
- m_pVMR = NULL;
- }
+ // Casimir666 : in renderless mode, do the inlaying in place of VMR
+ if(riid == __uuidof(IVMRMixerBitmap9)) {
+ return GetInterface((IVMRMixerBitmap9*)this, ppv);
+ }
- DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
- HRESULT hr;
-
- // Casimir666 : in renderless mode, do the inlaying in place of VMR
- if(riid == __uuidof(IVMRMixerBitmap9))
- return GetInterface((IVMRMixerBitmap9*)this, ppv);
-
- hr = m_pVMR ? m_pVMR->QueryInterface(riid, ppv) : E_NOINTERFACE;
- if(m_pVMR && FAILED(hr))
- {
- if(riid == __uuidof(IVideoWindow))
- return GetInterface((IVideoWindow*)this, ppv);
- if(riid == __uuidof(IBasicVideo))
- return GetInterface((IBasicVideo*)this, ppv);
- if(riid == __uuidof(IBasicVideo2))
- return GetInterface((IBasicVideo2*)this, ppv);
- if(riid == __uuidof(IVMRffdshow9)) // Support ffdshow queueing. We show ffdshow that this is patched Media Player Classic.
- return GetInterface((IVMRffdshow9*)this, ppv);
- /* if(riid == __uuidof(IVMRWindowlessControl))
- return GetInterface((IVMRWindowlessControl*)this, ppv);
- */
+ hr = m_pVMR ? m_pVMR->QueryInterface(riid, ppv) : E_NOINTERFACE;
+ if(m_pVMR && FAILED(hr)) {
+ if(riid == __uuidof(IVideoWindow)) {
+ return GetInterface((IVideoWindow*)this, ppv);
+ }
+ if(riid == __uuidof(IBasicVideo)) {
+ return GetInterface((IBasicVideo*)this, ppv);
+ }
+ if(riid == __uuidof(IBasicVideo2)) {
+ return GetInterface((IBasicVideo2*)this, ppv);
+ }
+ if(riid == __uuidof(IVMRffdshow9)) { // Support ffdshow queueing. We show ffdshow that this is patched Media Player Classic.
+ return GetInterface((IVMRffdshow9*)this, ppv);
+ }
+ /* if(riid == __uuidof(IVMRWindowlessControl))
+ return GetInterface((IVMRWindowlessControl*)this, ppv);
+ */
+ }
+
+ return SUCCEEDED(hr) ? hr : __super::NonDelegatingQueryInterface(riid, ppv);
}
- return SUCCEEDED(hr) ? hr : __super::NonDelegatingQueryInterface(riid, ppv);
- }
+ // IVMRWindowlessControl
- // IVMRWindowlessControl
+ STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ return pWC9->GetNativeVideoSize(lpWidth, lpHeight, lpARWidth, lpARHeight);
+ }
- STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- return pWC9->GetNativeVideoSize(lpWidth, lpHeight, lpARWidth, lpARHeight);
+ return E_NOTIMPL;
}
-
- return E_NOTIMPL;
- }
- STDMETHODIMP GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetMaxIdealVideoSize(LONG* lpWidth, LONG* lpHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetVideoPosition(const LPRECT lpSRCRect, const LPRECT lpDSTRect)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- return pWC9->GetVideoPosition(lpSRCRect, lpDSTRect);
+ STDMETHODIMP GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight) {
+ return E_NOTIMPL;
}
+ STDMETHODIMP GetMaxIdealVideoSize(LONG* lpWidth, LONG* lpHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetVideoPosition(const LPRECT lpSRCRect, const LPRECT lpDSTRect) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ return pWC9->GetVideoPosition(lpSRCRect, lpDSTRect);
+ }
- return E_NOTIMPL;
- }
- STDMETHODIMP GetAspectRatioMode(DWORD* lpAspectRatioMode)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- *lpAspectRatioMode = VMR_ARMODE_NONE;
- return S_OK;
+ return E_NOTIMPL;
}
+ STDMETHODIMP GetAspectRatioMode(DWORD* lpAspectRatioMode) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ *lpAspectRatioMode = VMR_ARMODE_NONE;
+ return S_OK;
+ }
- return E_NOTIMPL;
- }
- STDMETHODIMP SetAspectRatioMode(DWORD AspectRatioMode)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetVideoClippingWindow(HWND hwnd)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP RepaintVideo(HWND hwnd, HDC hdc)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP DisplayModeChanged()
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetCurrentImage(BYTE** lpDib)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetBorderColor(COLORREF Clr)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetBorderColor(COLORREF* lpClr)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetColorKey(COLORREF Clr)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetColorKey(COLORREF* lpClr)
- {
- return E_NOTIMPL;
- }
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetAspectRatioMode(DWORD AspectRatioMode) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetVideoClippingWindow(HWND hwnd) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP RepaintVideo(HWND hwnd, HDC hdc) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP DisplayModeChanged() {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetCurrentImage(BYTE** lpDib) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetBorderColor(COLORREF Clr) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetBorderColor(COLORREF* lpClr) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetColorKey(COLORREF Clr) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetColorKey(COLORREF* lpClr) {
+ return E_NOTIMPL;
+ }
- // IVideoWindow
- STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Caption(BSTR strCaption)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Caption(BSTR* strCaption)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_WindowStyle(long WindowStyle)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_WindowStyle(long* WindowStyle)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_WindowStyleEx(long WindowStyleEx)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_WindowStyleEx(long* WindowStyleEx)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_AutoShow(long AutoShow)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_AutoShow(long* AutoShow)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_WindowState(long WindowState)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_WindowState(long* WindowState)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_BackgroundPalette(long BackgroundPalette)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_BackgroundPalette(long* pBackgroundPalette)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Visible(long Visible)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Visible(long* pVisible)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Left(long Left)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Left(long* pLeft)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Width(long Width)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Width(long* pWidth)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- CRect s, d;
- HRESULT hr = pWC9->GetVideoPosition(&s, &d);
- *pWidth = d.Width();
- return hr;
+ // IVideoWindow
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Caption(BSTR strCaption) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Caption(BSTR* strCaption) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_WindowStyle(long WindowStyle) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_WindowStyle(long* WindowStyle) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_WindowStyleEx(long WindowStyleEx) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_WindowStyleEx(long* WindowStyleEx) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_AutoShow(long AutoShow) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_AutoShow(long* AutoShow) {
+ return E_NOTIMPL;
}
+ STDMETHODIMP put_WindowState(long WindowState) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_WindowState(long* WindowState) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_BackgroundPalette(long BackgroundPalette) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_BackgroundPalette(long* pBackgroundPalette) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Visible(long Visible) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Visible(long* pVisible) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Left(long Left) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Left(long* pLeft) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Width(long Width) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Width(long* pWidth) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ CRect s, d;
+ HRESULT hr = pWC9->GetVideoPosition(&s, &d);
+ *pWidth = d.Width();
+ return hr;
+ }
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Top(long Top)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Top(long* pTop)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Height(long Height)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Height(long* pHeight)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- CRect s, d;
- HRESULT hr = pWC9->GetVideoPosition(&s, &d);
- *pHeight = d.Height();
- return hr;
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Top(long Top) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Top(long* pTop) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Height(long Height) {
+ return E_NOTIMPL;
}
+ STDMETHODIMP get_Height(long* pHeight) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ CRect s, d;
+ HRESULT hr = pWC9->GetVideoPosition(&s, &d);
+ *pHeight = d.Height();
+ return hr;
+ }
- return E_NOTIMPL;
- }
- STDMETHODIMP put_Owner(OAHWND Owner)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_Owner(OAHWND* Owner)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_MessageDrain(OAHWND Drain)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_MessageDrain(OAHWND* Drain)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_BorderColor(long* Color)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_BorderColor(long Color)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_FullScreenMode(long* FullScreenMode)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_FullScreenMode(long FullScreenMode)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetWindowForeground(long Focus)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP NotifyOwnerMessage(OAHWND hwnd, long uMsg, LONG_PTR wParam, LONG_PTR lParam)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetWindowPosition(long Left, long Top, long Width, long Height)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetWindowPosition(long* pLeft, long* pTop, long* pWidth, long* pHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetMinIdealImageSize(long* pWidth, long* pHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetMaxIdealImageSize(long* pWidth, long* pHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetRestorePosition(long* pLeft, long* pTop, long* pWidth, long* pHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP HideCursor(long HideCursor)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP IsCursorHidden(long* CursorHidden)
- {
- return E_NOTIMPL;
- }
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_Owner(OAHWND Owner) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Owner(OAHWND* Owner) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_MessageDrain(OAHWND Drain) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MessageDrain(OAHWND* Drain) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_BorderColor(long* Color) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_BorderColor(long Color) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_FullScreenMode(long* FullScreenMode) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_FullScreenMode(long FullScreenMode) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetWindowForeground(long Focus) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP NotifyOwnerMessage(OAHWND hwnd, long uMsg, LONG_PTR wParam, LONG_PTR lParam) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetWindowPosition(long Left, long Top, long Width, long Height) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetWindowPosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetMinIdealImageSize(long* pWidth, long* pHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetMaxIdealImageSize(long* pWidth, long* pHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetRestorePosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP HideCursor(long HideCursor) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP IsCursorHidden(long* CursorHidden) {
+ return E_NOTIMPL;
+ }
- // IBasicVideo2
- STDMETHODIMP get_AvgTimePerFrame(REFTIME* pAvgTimePerFrame)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_BitRate(long* pBitRate)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_BitErrorRate(long* pBitErrorRate)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_VideoWidth(long* pVideoWidth)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_VideoHeight(long* pVideoHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_SourceLeft(long SourceLeft)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_SourceLeft(long* pSourceLeft)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_SourceWidth(long SourceWidth)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_SourceWidth(long* pSourceWidth)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_SourceTop(long SourceTop)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_SourceTop(long* pSourceTop)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_SourceHeight(long SourceHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_SourceHeight(long* pSourceHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_DestinationLeft(long DestinationLeft)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_DestinationLeft(long* pDestinationLeft)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_DestinationWidth(long DestinationWidth)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_DestinationWidth(long* pDestinationWidth)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_DestinationTop(long DestinationTop)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_DestinationTop(long* pDestinationTop)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP put_DestinationHeight(long DestinationHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP get_DestinationHeight(long* pDestinationHeight)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetSourcePosition(long Left, long Top, long Width, long Height)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetSourcePosition(long* pLeft, long* pTop, long* pWidth, long* pHeight)
- {
- // DVD Nav. bug workaround fix
- {
- *pLeft = *pTop = 0;
- return GetVideoSize(pWidth, pHeight);
- }
- /*
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- CRect s, d;
- HRESULT hr = pWC9->GetVideoPosition(&s, &d);
- *pLeft = s.left;
- *pTop = s.top;
- *pWidth = s.Width();
- *pHeight = s.Height();
- return hr;
+ // IBasicVideo2
+ STDMETHODIMP get_AvgTimePerFrame(REFTIME* pAvgTimePerFrame) {
+ return E_NOTIMPL;
}
- return E_NOTIMPL;
- */
- }
- STDMETHODIMP SetDefaultSourcePosition()
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP SetDestinationPosition(long Left, long Top, long Width, long Height)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetDestinationPosition(long* pLeft, long* pTop, long* pWidth, long* pHeight)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
+ STDMETHODIMP get_BitRate(long* pBitRate) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_BitErrorRate(long* pBitErrorRate) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_VideoWidth(long* pVideoWidth) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_VideoHeight(long* pVideoHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_SourceLeft(long SourceLeft) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_SourceLeft(long* pSourceLeft) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_SourceWidth(long SourceWidth) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_SourceWidth(long* pSourceWidth) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_SourceTop(long SourceTop) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_SourceTop(long* pSourceTop) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_SourceHeight(long SourceHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_SourceHeight(long* pSourceHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_DestinationLeft(long DestinationLeft) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_DestinationLeft(long* pDestinationLeft) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_DestinationWidth(long DestinationWidth) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_DestinationWidth(long* pDestinationWidth) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_DestinationTop(long DestinationTop) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_DestinationTop(long* pDestinationTop) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_DestinationHeight(long DestinationHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_DestinationHeight(long* pDestinationHeight) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetSourcePosition(long Left, long Top, long Width, long Height) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetSourcePosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {
+ // DVD Nav. bug workaround fix
+ {
+ *pLeft = *pTop = 0;
+ return GetVideoSize(pWidth, pHeight);
+ }
+ /*
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
+ {
CRect s, d;
HRESULT hr = pWC9->GetVideoPosition(&s, &d);
- *pLeft = d.left;
- *pTop = d.top;
- *pWidth = d.Width();
- *pHeight = d.Height();
+ *pLeft = s.left;
+ *pTop = s.top;
+ *pWidth = s.Width();
+ *pHeight = s.Height();
return hr;
+ }
+ return E_NOTIMPL;
+ */
}
-
- return E_NOTIMPL;
- }
- STDMETHODIMP SetDefaultDestinationPosition()
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetVideoSize(long* pWidth, long* pHeight)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- LONG aw, ah;
- // return pWC9->GetNativeVideoSize(pWidth, pHeight, &aw, &ah);
- // DVD Nav. bug workaround fix
- HRESULT hr = pWC9->GetNativeVideoSize(pWidth, pHeight, &aw, &ah);
- *pWidth = *pHeight * aw / ah;
- return hr;
+ STDMETHODIMP SetDefaultSourcePosition() {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetDestinationPosition(long Left, long Top, long Width, long Height) {
+ return E_NOTIMPL;
}
+ STDMETHODIMP GetDestinationPosition(long* pLeft, long* pTop, long* pWidth, long* pHeight) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ CRect s, d;
+ HRESULT hr = pWC9->GetVideoPosition(&s, &d);
+ *pLeft = d.left;
+ *pTop = d.top;
+ *pWidth = d.Width();
+ *pHeight = d.Height();
+ return hr;
+ }
- return E_NOTIMPL;
- }
- // IVMRffdshow9
- STDMETHODIMP support_ffdshow()
- {
- queue_ffdshow_support = true;
- return S_OK;
- }
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP SetDefaultDestinationPosition() {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetVideoSize(long* pWidth, long* pHeight) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ LONG aw, ah;
+ // return pWC9->GetNativeVideoSize(pWidth, pHeight, &aw, &ah);
+ // DVD Nav. bug workaround fix
+ HRESULT hr = pWC9->GetNativeVideoSize(pWidth, pHeight, &aw, &ah);
+ *pWidth = *pHeight * aw / ah;
+ return hr;
+ }
- STDMETHODIMP GetVideoPaletteEntries(long StartIndex, long Entries, long* pRetrieved, long* pPalette)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP GetCurrentImage(long* pBufferSize, long* pDIBImage)
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP IsUsingDefaultSource()
- {
- return E_NOTIMPL;
- }
- STDMETHODIMP IsUsingDefaultDestination()
- {
- return E_NOTIMPL;
- }
+ return E_NOTIMPL;
+ }
+ // IVMRffdshow9
+ STDMETHODIMP support_ffdshow() {
+ queue_ffdshow_support = true;
+ return S_OK;
+ }
- STDMETHODIMP GetPreferredAspectRatio(long* plAspectX, long* plAspectY)
- {
- if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR)
- {
- LONG w, h;
- return pWC9->GetNativeVideoSize(&w, &h, plAspectX, plAspectY);
+ STDMETHODIMP GetVideoPaletteEntries(long StartIndex, long Entries, long* pRetrieved, long* pPalette) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetCurrentImage(long* pBufferSize, long* pDIBImage) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP IsUsingDefaultSource() {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP IsUsingDefaultDestination() {
+ return E_NOTIMPL;
}
- return E_NOTIMPL;
- }
+ STDMETHODIMP GetPreferredAspectRatio(long* plAspectX, long* plAspectY) {
+ if(CComQIPtr<IVMRWindowlessControl9> pWC9 = m_pVMR) {
+ LONG w, h;
+ return pWC9->GetNativeVideoSize(&w, &h, plAspectX, plAspectY);
+ }
- // IVMRMixerBitmap9
- STDMETHODIMP GetAlphaBitmapParameters(VMR9AlphaBitmap* pBmpParms)
- {
- CheckPointer(pBmpParms, E_POINTER);
- CAutoLock BitMapLock(&m_pAllocatorPresenter->m_VMR9AlphaBitmapLock);
- memcpy (pBmpParms, m_pVMR9AlphaBitmap, sizeof(VMR9AlphaBitmap));
- return S_OK;
- }
+ return E_NOTIMPL;
+ }
- STDMETHODIMP SetAlphaBitmap(const VMR9AlphaBitmap* pBmpParms)
- {
- CheckPointer(pBmpParms, E_POINTER);
- CAutoLock BitMapLock(&m_pAllocatorPresenter->m_VMR9AlphaBitmapLock);
- memcpy (m_pVMR9AlphaBitmap, pBmpParms, sizeof(VMR9AlphaBitmap));
- m_pVMR9AlphaBitmap->dwFlags |= VMRBITMAP_UPDATE;
- m_pAllocatorPresenter->UpdateAlphaBitmap();
- return S_OK;
- }
+ // IVMRMixerBitmap9
+ STDMETHODIMP GetAlphaBitmapParameters(VMR9AlphaBitmap* pBmpParms) {
+ CheckPointer(pBmpParms, E_POINTER);
+ CAutoLock BitMapLock(&m_pAllocatorPresenter->m_VMR9AlphaBitmapLock);
+ memcpy (pBmpParms, m_pVMR9AlphaBitmap, sizeof(VMR9AlphaBitmap));
+ return S_OK;
+ }
- STDMETHODIMP UpdateAlphaBitmapParameters(const VMR9AlphaBitmap* pBmpParms)
- {
- CheckPointer(pBmpParms, E_POINTER);
- CAutoLock BitMapLock(&m_pAllocatorPresenter->m_VMR9AlphaBitmapLock);
- memcpy (m_pVMR9AlphaBitmap, pBmpParms, sizeof(VMR9AlphaBitmap));
- m_pVMR9AlphaBitmap->dwFlags |= VMRBITMAP_UPDATE;
- m_pAllocatorPresenter->UpdateAlphaBitmap();
- return S_OK;
- }
-};
+ STDMETHODIMP SetAlphaBitmap(const VMR9AlphaBitmap* pBmpParms) {
+ CheckPointer(pBmpParms, E_POINTER);
+ CAutoLock BitMapLock(&m_pAllocatorPresenter->m_VMR9AlphaBitmapLock);
+ memcpy (m_pVMR9AlphaBitmap, pBmpParms, sizeof(VMR9AlphaBitmap));
+ m_pVMR9AlphaBitmap->dwFlags |= VMRBITMAP_UPDATE;
+ m_pAllocatorPresenter->UpdateAlphaBitmap();
+ return S_OK;
+ }
+
+ STDMETHODIMP UpdateAlphaBitmapParameters(const VMR9AlphaBitmap* pBmpParms) {
+ CheckPointer(pBmpParms, E_POINTER);
+ CAutoLock BitMapLock(&m_pAllocatorPresenter->m_VMR9AlphaBitmapLock);
+ memcpy (m_pVMR9AlphaBitmap, pBmpParms, sizeof(VMR9AlphaBitmap));
+ m_pVMR9AlphaBitmap->dwFlags |= VMRBITMAP_UPDATE;
+ m_pAllocatorPresenter->UpdateAlphaBitmap();
+ return S_OK;
+ }
+ };
}
using namespace DSObjects;
@@ -598,14 +496,13 @@ STDMETHODIMP CVMR9AllocatorPresenter::NonDelegatingQueryInterface(REFIID riid, v
HRESULT CVMR9AllocatorPresenter::CreateDevice(CString &_Error)
{
HRESULT hr = __super::CreateDevice(_Error);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
- if(m_pIVMRSurfAllocNotify)
- {
+ if(m_pIVMRSurfAllocNotify) {
HMONITOR hMonitor = m_pD3D->GetAdapterMonitor(m_CurrentAdapter);
- if(FAILED(hr = m_pIVMRSurfAllocNotify->ChangeD3DDevice(m_pD3DDev, hMonitor)))
- {
+ if(FAILED(hr = m_pIVMRSurfAllocNotify->ChangeD3DDevice(m_pD3DDev, hMonitor))) {
_Error += L"m_pIVMRSurfAllocNotify->ChangeD3DDevice failed";
return hr; //return(false);
}
@@ -632,8 +529,7 @@ STDMETHODIMP CVMR9AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
HRESULT hr;
- do
- {
+ do {
CMacrovisionKicker* pMK = DNew CMacrovisionKicker(NAME("CMacrovisionKicker"), NULL);
CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)pMK;
@@ -647,30 +543,30 @@ STDMETHODIMP CVMR9AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
CComQIPtr<IMemInputPin> pMemInputPin = pPin;
m_fUseInternalTimer = HookNewSegmentAndReceive((IPinC*)(IPin*)pPin, (IMemInputPinC*)(IMemInputPin*)pMemInputPin);
- if(CComQIPtr<IAMVideoAccelerator> pAMVA = pPin)
+ if(CComQIPtr<IAMVideoAccelerator> pAMVA = pPin) {
HookAMVideoAccelerator((IAMVideoAcceleratorC*)(IAMVideoAccelerator*)pAMVA);
+ }
CComQIPtr<IVMRFilterConfig9> pConfig = pBF;
- if(!pConfig)
+ if(!pConfig) {
break;
+ }
CRenderersSettings& s = GetRenderersSettings();
- if(s.fVMR9MixerMode)
- {
- if(FAILED(hr = pConfig->SetNumberOfStreams(1)))
+ if(s.fVMR9MixerMode) {
+ if(FAILED(hr = pConfig->SetNumberOfStreams(1))) {
break;
+ }
- if(CComQIPtr<IVMRMixerControl9> pMC = pBF)
- {
+ if(CComQIPtr<IVMRMixerControl9> pMC = pBF) {
DWORD dwPrefs;
pMC->GetMixingPrefs(&dwPrefs);
// See http://msdn.microsoft.com/en-us/library/dd390928(VS.85).aspx
dwPrefs |= MixerPref9_NonSquareMixing;
dwPrefs |= MixerPref9_NoDecimation;
- if(s.fVMR9MixerYUV && !IsVistaOrAbove())
- {
+ if(s.fVMR9MixerYUV && !IsVistaOrAbove()) {
dwPrefs &= ~MixerPref9_RenderTargetMask;
dwPrefs |= MixerPref9_RenderTargetYUV;
}
@@ -678,22 +574,24 @@ STDMETHODIMP CVMR9AllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
}
}
- if(FAILED(hr = pConfig->SetRenderingMode(VMR9Mode_Renderless)))
+ if(FAILED(hr = pConfig->SetRenderingMode(VMR9Mode_Renderless))) {
break;
+ }
CComQIPtr<IVMRSurfaceAllocatorNotify9> pSAN = pBF;
- if(!pSAN)
+ if(!pSAN) {
break;
+ }
if(FAILED(hr = pSAN->AdviseSurfaceAllocator(MY_USER_ID, static_cast<IVMRSurfaceAllocator9*>(this)))
- || FAILED(hr = AdviseNotify(pSAN)))
+ || FAILED(hr = AdviseNotify(pSAN))) {
break;
+ }
*ppRenderer = (IUnknown*)pBF.Detach();
return S_OK;
- }
- while(0);
+ } while(0);
return E_FAIL;
}
@@ -711,27 +609,29 @@ STDMETHODIMP CVMR9AllocatorPresenter::InitializeDevice(DWORD_PTR dwUserID, VMR9A
CAutoLock lock(this);
CAutoLock cRenderLock(&m_RenderLock);
- if(!lpAllocInfo || !lpNumBuffers)
+ if(!lpAllocInfo || !lpNumBuffers) {
return E_POINTER;
+ }
- if(!m_pIVMRSurfAllocNotify)
+ if(!m_pIVMRSurfAllocNotify) {
return E_FAIL;
+ }
if((GetAsyncKeyState(VK_CONTROL)&0x80000000))
- if(lpAllocInfo->Format == '21VY' || lpAllocInfo->Format == '024I')
+ if(lpAllocInfo->Format == '21VY' || lpAllocInfo->Format == '024I') {
return E_FAIL;
+ }
DeleteSurfaces();
int nOriginal = *lpNumBuffers;
- if (*lpNumBuffers == 1)
- {
+ if (*lpNumBuffers == 1) {
*lpNumBuffers = 4;
m_nVMR9Surfaces = 4;
- }
- else
+ } else {
m_nVMR9Surfaces = 0;
+ }
m_pSurfaces.SetCount(*lpNumBuffers);
int w = lpAllocInfo->dwWidth;
@@ -739,11 +639,14 @@ STDMETHODIMP CVMR9AllocatorPresenter::InitializeDevice(DWORD_PTR dwUserID, VMR9A
HRESULT hr;
- if(lpAllocInfo->dwFlags & VMR9AllocFlag_3DRenderTarget)
+ if(lpAllocInfo->dwFlags & VMR9AllocFlag_3DRenderTarget) {
lpAllocInfo->dwFlags |= VMR9AllocFlag_TextureSurface;
+ }
hr = m_pIVMRSurfAllocNotify->AllocateSurfaceHelper(lpAllocInfo, lpNumBuffers, &m_pSurfaces[0]);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
m_pSurfaces.SetCount(*lpNumBuffers);
@@ -752,23 +655,21 @@ STDMETHODIMP CVMR9AllocatorPresenter::InitializeDevice(DWORD_PTR dwUserID, VMR9A
CSize VideoSize = GetVisibleVideoSize();
int arx = lpAllocInfo->szAspectRatio.cx;
int ary = lpAllocInfo->szAspectRatio.cy;
- if(arx > 0 && ary > 0)
- {
+ if(arx > 0 && ary > 0) {
arx = arx / ((float) m_NativeVideoSize.cx / VideoSize.cx);
ary = ary / ((float) m_NativeVideoSize.cy / VideoSize.cy);
m_AspectRatio.SetSize(arx, ary);
- }
- else
+ } else {
m_AspectRatio = VideoSize;
+ }
- if(FAILED(hr = AllocSurfaces()))
+ if(FAILED(hr = AllocSurfaces())) {
return hr;
+ }
- if(!(lpAllocInfo->dwFlags & VMR9AllocFlag_TextureSurface))
- {
+ if(!(lpAllocInfo->dwFlags & VMR9AllocFlag_TextureSurface)) {
// test if the colorspace is acceptable
- if(FAILED(hr = m_pD3DDev->StretchRect(m_pSurfaces[0], NULL, m_pVideoSurface[m_nCurSurface], NULL, D3DTEXF_NONE)))
- {
+ if(FAILED(hr = m_pD3DDev->StretchRect(m_pSurfaces[0], NULL, m_pVideoSurface[m_nCurSurface], NULL, D3DTEXF_NONE))) {
DeleteSurfaces();
return E_FAIL;
}
@@ -776,8 +677,9 @@ STDMETHODIMP CVMR9AllocatorPresenter::InitializeDevice(DWORD_PTR dwUserID, VMR9A
hr = m_pD3DDev->ColorFill(m_pVideoSurface[m_nCurSurface], NULL, 0);
- if (m_nVMR9Surfaces && m_nVMR9Surfaces != (int)*lpNumBuffers)
+ if (m_nVMR9Surfaces && m_nVMR9Surfaces != (int)*lpNumBuffers) {
m_nVMR9Surfaces = *lpNumBuffers;
+ }
*lpNumBuffers = min(nOriginal, *lpNumBuffers);
m_iVMR9Surface = 0;
@@ -791,22 +693,21 @@ STDMETHODIMP CVMR9AllocatorPresenter::TerminateDevice(DWORD_PTR dwUserID)
STDMETHODIMP CVMR9AllocatorPresenter::GetSurface(DWORD_PTR dwUserID, DWORD SurfaceIndex, DWORD SurfaceFlags, IDirect3DSurface9** lplpSurface)
{
- if(!lplpSurface)
+ if(!lplpSurface) {
return E_POINTER;
+ }
- if(SurfaceIndex >= m_pSurfaces.GetCount())
+ if(SurfaceIndex >= m_pSurfaces.GetCount()) {
return E_FAIL;
+ }
CAutoLock cRenderLock(&m_RenderLock);
- if (m_nVMR9Surfaces)
- {
+ if (m_nVMR9Surfaces) {
++m_iVMR9Surface;
m_iVMR9Surface = m_iVMR9Surface % m_nVMR9Surfaces;
(*lplpSurface = m_pSurfaces[m_iVMR9Surface + SurfaceIndex])->AddRef();
- }
- else
- {
+ } else {
m_iVMR9Surface = SurfaceIndex;
(*lplpSurface = m_pSurfaces[SurfaceIndex])->AddRef();
}
@@ -823,8 +724,9 @@ STDMETHODIMP CVMR9AllocatorPresenter::AdviseNotify(IVMRSurfaceAllocatorNotify9*
HRESULT hr;
HMONITOR hMonitor = m_pD3D->GetAdapterMonitor(GetAdapter(m_pD3D));
- if(FAILED(hr = m_pIVMRSurfAllocNotify->SetD3DDevice(m_pD3DDev, hMonitor)))
+ if(FAILED(hr = m_pIVMRSurfAllocNotify->SetD3DDevice(m_pD3DDev, hMonitor))) {
return hr;
+ }
return S_OK;
}
@@ -833,8 +735,7 @@ STDMETHODIMP CVMR9AllocatorPresenter::AdviseNotify(IVMRSurfaceAllocatorNotify9*
STDMETHODIMP CVMR9AllocatorPresenter::StartPresenting(DWORD_PTR dwUserID)
{
- if (!m_bPendingResetDevice)
- {
+ if (!m_bPendingResetDevice) {
ASSERT(m_pD3DDev);
}
@@ -855,8 +756,7 @@ STDMETHODIMP CVMR9AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMR9Prese
SetThreadName((DWORD)-1, "CVMR9AllocatorPresenter");
CheckPointer(m_pIVMRSurfAllocNotify, E_UNEXPECTED);
- if (m_rtTimePerFrame == 0 || m_bNeedCheckSample)
- {
+ if (m_rtTimePerFrame == 0 || m_bNeedCheckSample) {
m_bNeedCheckSample = false;
CComPtr<IBaseFilter> pVMR9;
CComPtr<IPin> pPin;
@@ -864,74 +764,74 @@ STDMETHODIMP CVMR9AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMR9Prese
if (SUCCEEDED (m_pIVMRSurfAllocNotify->QueryInterface (__uuidof(IBaseFilter), (void**)&pVMR9)) &&
SUCCEEDED (pVMR9->FindPin(L"VMR Input0", &pPin)) &&
- SUCCEEDED (pPin->ConnectionMediaType(&mt)) )
- {
+ SUCCEEDED (pPin->ConnectionMediaType(&mt)) ) {
ExtractAvgTimePerFrame (&mt, m_rtTimePerFrame);
CSize NativeVideoSize = m_NativeVideoSize;
CSize AspectRatio = m_AspectRatio;
- if (mt.formattype==FORMAT_VideoInfo || mt.formattype==FORMAT_MPEGVideo)
- {
+ if (mt.formattype==FORMAT_VideoInfo || mt.formattype==FORMAT_MPEGVideo) {
VIDEOINFOHEADER *vh = (VIDEOINFOHEADER*)mt.pbFormat;
NativeVideoSize = CSize(vh->bmiHeader.biWidth, abs(vh->bmiHeader.biHeight));
- if (vh->rcTarget.right - vh->rcTarget.left > 0)
+ if (vh->rcTarget.right - vh->rcTarget.left > 0) {
NativeVideoSize.cx = vh->rcTarget.right - vh->rcTarget.left;
- else if (vh->rcSource.right - vh->rcSource.left > 0)
+ } else if (vh->rcSource.right - vh->rcSource.left > 0) {
NativeVideoSize.cx = vh->rcSource.right - vh->rcSource.left;
+ }
- if (vh->rcTarget.bottom - vh->rcTarget.top > 0)
+ if (vh->rcTarget.bottom - vh->rcTarget.top > 0) {
NativeVideoSize.cy = vh->rcTarget.bottom - vh->rcTarget.top;
- else if (vh->rcSource.bottom - vh->rcSource.top > 0)
+ } else if (vh->rcSource.bottom - vh->rcSource.top > 0) {
NativeVideoSize.cy = vh->rcSource.bottom - vh->rcSource.top;
- }
- else if (mt.formattype==FORMAT_VideoInfo2 || mt.formattype==FORMAT_MPEG2Video)
- {
+ }
+ } else if (mt.formattype==FORMAT_VideoInfo2 || mt.formattype==FORMAT_MPEG2Video) {
VIDEOINFOHEADER2 *vh = (VIDEOINFOHEADER2*)mt.pbFormat;
- if (vh->dwPictAspectRatioX && vh->dwPictAspectRatioY)
+ if (vh->dwPictAspectRatioX && vh->dwPictAspectRatioY) {
AspectRatio = CSize(vh->dwPictAspectRatioX, vh->dwPictAspectRatioY);
+ }
NativeVideoSize = CSize(vh->bmiHeader.biWidth, abs(vh->bmiHeader.biHeight));
- if (vh->rcTarget.right - vh->rcTarget.left > 0)
+ if (vh->rcTarget.right - vh->rcTarget.left > 0) {
NativeVideoSize.cx = vh->rcTarget.right - vh->rcTarget.left;
- else if (vh->rcSource.right - vh->rcSource.left > 0)
+ } else if (vh->rcSource.right - vh->rcSource.left > 0) {
NativeVideoSize.cx = vh->rcSource.right - vh->rcSource.left;
+ }
- if (vh->rcTarget.bottom - vh->rcTarget.top > 0)
+ if (vh->rcTarget.bottom - vh->rcTarget.top > 0) {
NativeVideoSize.cy = vh->rcTarget.bottom - vh->rcTarget.top;
- else if (vh->rcSource.bottom - vh->rcSource.top > 0)
+ } else if (vh->rcSource.bottom - vh->rcSource.top > 0) {
NativeVideoSize.cy = vh->rcSource.bottom - vh->rcSource.top;
+ }
}
- if (m_NativeVideoSize != NativeVideoSize || m_AspectRatio != AspectRatio)
- {
+ if (m_NativeVideoSize != NativeVideoSize || m_AspectRatio != AspectRatio) {
m_NativeVideoSize = NativeVideoSize;
m_AspectRatio = AspectRatio;
AfxGetApp()->m_pMainWnd->PostMessage(WM_REARRANGERENDERLESS);
}
}
// If framerate not set by Video Decoder choose 23.97...
- if (m_rtTimePerFrame == 0) m_rtTimePerFrame = 417166;
+ if (m_rtTimePerFrame == 0) {
+ m_rtTimePerFrame = 417166;
+ }
m_fps = 10000000.0 / m_rtTimePerFrame;
}
HRESULT hr;
- if(!lpPresInfo || !lpPresInfo->lpSurf)
+ if(!lpPresInfo || !lpPresInfo->lpSurf) {
return E_POINTER;
+ }
CAutoLock cAutoLock(this);
CAutoLock cRenderLock(&m_RenderLock);
- if(lpPresInfo->rtEnd > lpPresInfo->rtStart)
- {
- if(m_pSubPicQueue)
- {
+ if(lpPresInfo->rtEnd > lpPresInfo->rtStart) {
+ if(m_pSubPicQueue) {
m_pSubPicQueue->SetFPS(m_fps);
- if(m_fUseInternalTimer && !g_bExternalSubtitleTime)
- {
+ if(m_fUseInternalTimer && !g_bExternalSubtitleTime) {
__super::SetTime(g_tSegmentStart + g_tSampleStart);
}
}
@@ -940,37 +840,31 @@ STDMETHODIMP CVMR9AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMR9Prese
CSize VideoSize = GetVisibleVideoSize();
int arx = lpPresInfo->szAspectRatio.cx;
int ary = lpPresInfo->szAspectRatio.cy;
- if(arx > 0 && ary > 0)
- {
+ if(arx > 0 && ary > 0) {
arx = arx / ((float) m_NativeVideoSize.cx / VideoSize.cx);
ary = ary / ((float) m_NativeVideoSize.cy / VideoSize.cy);
VideoSize.cx = VideoSize.cy*arx/ary;
}
- if(VideoSize != GetVideoSize())
- {
+ if(VideoSize != GetVideoSize()) {
m_AspectRatio.SetSize(arx, ary);
AfxGetApp()->m_pMainWnd->PostMessage(WM_REARRANGERENDERLESS);
}
- if (!m_bPendingResetDevice)
- {
+ if (!m_bPendingResetDevice) {
CComPtr<IDirect3DTexture9> pTexture;
lpPresInfo->lpSurf->GetContainer(IID_IDirect3DTexture9, (void**)&pTexture);
- if(pTexture)
- {
+ if(pTexture) {
m_pVideoSurface[m_nCurSurface] = lpPresInfo->lpSurf;
- if(m_pVideoTexture[m_nCurSurface])
+ if(m_pVideoTexture[m_nCurSurface]) {
m_pVideoTexture[m_nCurSurface] = pTexture;
- }
- else
- {
+ }
+ } else {
hr = m_pD3DDev->StretchRect(lpPresInfo->lpSurf, NULL, m_pVideoSurface[m_nCurSurface], NULL, D3DTEXF_NONE);
}
// Tear test bars
- if (GetRenderersData()->m_fTearingTest)
- {
+ if (GetRenderersData()->m_fTearingTest) {
RECT rcTearing;
rcTearing.left = m_nTearingPos;
@@ -1000,10 +894,18 @@ STDMETHODIMP CVMR9AllocatorPresenter::PresentImage(DWORD_PTR dwUserID, VMR9Prese
STDMETHODIMP CVMR9AllocatorPresenter::GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight)
{
- if(lpWidth) *lpWidth = m_NativeVideoSize.cx;
- if(lpHeight) *lpHeight = m_NativeVideoSize.cy;
- if(lpARWidth) *lpARWidth = m_AspectRatio.cx;
- if(lpARHeight) *lpARHeight = m_AspectRatio.cy;
+ if(lpWidth) {
+ *lpWidth = m_NativeVideoSize.cx;
+ }
+ if(lpHeight) {
+ *lpHeight = m_NativeVideoSize.cy;
+ }
+ if(lpARWidth) {
+ *lpARWidth = m_AspectRatio.cx;
+ }
+ if(lpARHeight) {
+ *lpARHeight = m_AspectRatio.cy;
+ }
return S_OK;
}
STDMETHODIMP CVMR9AllocatorPresenter::GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight)
@@ -1026,7 +928,9 @@ STDMETHODIMP CVMR9AllocatorPresenter::GetVideoPosition(LPRECT lpSRCRect, LPRECT
}
STDMETHODIMP CVMR9AllocatorPresenter::GetAspectRatioMode(DWORD* lpAspectRatioMode)
{
- if(lpAspectRatioMode) *lpAspectRatioMode = AM_ARMODE_STRETCHED;
+ if(lpAspectRatioMode) {
+ *lpAspectRatioMode = AM_ARMODE_STRETCHED;
+ }
return S_OK;
}
STDMETHODIMP CVMR9AllocatorPresenter::SetAspectRatioMode(DWORD AspectRatioMode)
@@ -1055,6 +959,8 @@ STDMETHODIMP CVMR9AllocatorPresenter::SetBorderColor(COLORREF Clr)
}
STDMETHODIMP CVMR9AllocatorPresenter::GetBorderColor(COLORREF* lpClr)
{
- if(lpClr) *lpClr = 0;
+ if(lpClr) {
+ *lpClr = 0;
+ }
return S_OK;
}
diff --git a/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.h b/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.h
index 95fed2830..0ef6cf3ed 100644
--- a/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/VMR9AllocatorPresenter.h
@@ -26,56 +26,56 @@
namespace DSObjects
{
-class CVMR9AllocatorPresenter
- : public CDX9AllocatorPresenter
- , public IVMRSurfaceAllocator9
- , public IVMRImagePresenter9
- , public IVMRWindowlessControl9
-{
-protected:
- CComPtr<IVMRSurfaceAllocatorNotify9> m_pIVMRSurfAllocNotify;
- CInterfaceArray<IDirect3DSurface9> m_pSurfaces;
+ class CVMR9AllocatorPresenter
+ : public CDX9AllocatorPresenter
+ , public IVMRSurfaceAllocator9
+ , public IVMRImagePresenter9
+ , public IVMRWindowlessControl9
+ {
+ protected:
+ CComPtr<IVMRSurfaceAllocatorNotify9> m_pIVMRSurfAllocNotify;
+ CInterfaceArray<IDirect3DSurface9> m_pSurfaces;
- HRESULT CreateDevice(CString &_Error);
- void DeleteSurfaces();
+ HRESULT CreateDevice(CString &_Error);
+ void DeleteSurfaces();
- bool m_fUseInternalTimer;
- REFERENCE_TIME m_rtPrevStart;
+ bool m_fUseInternalTimer;
+ REFERENCE_TIME m_rtPrevStart;
-public:
- CVMR9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+ public:
+ CVMR9AllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(void) SetTime(REFERENCE_TIME rtNow);
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(void) SetTime(REFERENCE_TIME rtNow);
- // IVMRSurfaceAllocator9
- STDMETHODIMP InitializeDevice(DWORD_PTR dwUserID, VMR9AllocationInfo* lpAllocInfo, DWORD* lpNumBuffers);
- STDMETHODIMP TerminateDevice(DWORD_PTR dwID);
- STDMETHODIMP GetSurface(DWORD_PTR dwUserID, DWORD SurfaceIndex, DWORD SurfaceFlags, IDirect3DSurface9** lplpSurface);
- STDMETHODIMP AdviseNotify(IVMRSurfaceAllocatorNotify9* lpIVMRSurfAllocNotify);
+ // IVMRSurfaceAllocator9
+ STDMETHODIMP InitializeDevice(DWORD_PTR dwUserID, VMR9AllocationInfo* lpAllocInfo, DWORD* lpNumBuffers);
+ STDMETHODIMP TerminateDevice(DWORD_PTR dwID);
+ STDMETHODIMP GetSurface(DWORD_PTR dwUserID, DWORD SurfaceIndex, DWORD SurfaceFlags, IDirect3DSurface9** lplpSurface);
+ STDMETHODIMP AdviseNotify(IVMRSurfaceAllocatorNotify9* lpIVMRSurfAllocNotify);
- // IVMRImagePresenter9
- STDMETHODIMP StartPresenting(DWORD_PTR dwUserID);
- STDMETHODIMP StopPresenting(DWORD_PTR dwUserID);
- STDMETHODIMP PresentImage(DWORD_PTR dwUserID, VMR9PresentationInfo* lpPresInfo);
+ // IVMRImagePresenter9
+ STDMETHODIMP StartPresenting(DWORD_PTR dwUserID);
+ STDMETHODIMP StopPresenting(DWORD_PTR dwUserID);
+ STDMETHODIMP PresentImage(DWORD_PTR dwUserID, VMR9PresentationInfo* lpPresInfo);
- // IVMRWindowlessControl9
- STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
- STDMETHODIMP GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
- STDMETHODIMP GetMaxIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
- STDMETHODIMP SetVideoPosition(const LPRECT lpSRCRect, const LPRECT lpDSTRect);
- STDMETHODIMP GetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect);
- STDMETHODIMP GetAspectRatioMode(DWORD* lpAspectRatioMode);
- STDMETHODIMP SetAspectRatioMode(DWORD AspectRatioMode);
- STDMETHODIMP SetVideoClippingWindow(HWND hwnd);
- STDMETHODIMP RepaintVideo(HWND hwnd, HDC hdc);
- STDMETHODIMP DisplayModeChanged();
- STDMETHODIMP GetCurrentImage(BYTE** lpDib);
- STDMETHODIMP SetBorderColor(COLORREF Clr);
- STDMETHODIMP GetBorderColor(COLORREF* lpClr);
-};
+ // IVMRWindowlessControl9
+ STDMETHODIMP GetNativeVideoSize(LONG* lpWidth, LONG* lpHeight, LONG* lpARWidth, LONG* lpARHeight);
+ STDMETHODIMP GetMinIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
+ STDMETHODIMP GetMaxIdealVideoSize(LONG* lpWidth, LONG* lpHeight);
+ STDMETHODIMP SetVideoPosition(const LPRECT lpSRCRect, const LPRECT lpDSTRect);
+ STDMETHODIMP GetVideoPosition(LPRECT lpSRCRect, LPRECT lpDSTRect);
+ STDMETHODIMP GetAspectRatioMode(DWORD* lpAspectRatioMode);
+ STDMETHODIMP SetAspectRatioMode(DWORD AspectRatioMode);
+ STDMETHODIMP SetVideoClippingWindow(HWND hwnd);
+ STDMETHODIMP RepaintVideo(HWND hwnd, HDC hdc);
+ STDMETHODIMP DisplayModeChanged();
+ STDMETHODIMP GetCurrentImage(BYTE** lpDib);
+ STDMETHODIMP SetBorderColor(COLORREF Clr);
+ STDMETHODIMP GetBorderColor(COLORREF* lpClr);
+ };
}
diff --git a/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp b/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp
index 4169317fb..dd49f718a 100644
--- a/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp
+++ b/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.cpp
@@ -32,8 +32,7 @@ using namespace DSObjects;
interface __declspec(uuid("51FA8F61-1444-4597-996E-7495405753E6"))
IMadVRFullscreen :
-public IUnknown
-{
+public IUnknown {
STDMETHOD(ActivateFullscreenMode)(void) = 0;
};
@@ -46,8 +45,7 @@ CmadVRAllocatorPresenter::CmadVRAllocatorPresenter(HWND hWnd, bool bFullscreen,
, m_ScreenSize(0, 0)
, m_bIsFullscreen(bFullscreen)
{
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
_Error += L"ISubPicAllocatorPresenterImpl failed\n";
return;
}
@@ -57,8 +55,7 @@ CmadVRAllocatorPresenter::CmadVRAllocatorPresenter(HWND hWnd, bool bFullscreen,
CmadVRAllocatorPresenter::~CmadVRAllocatorPresenter()
{
- if(m_pSRCB)
- {
+ if(m_pSRCB) {
// nasty, but we have to let it know about our death somehow
((CSubRenderCallback*)(ISubRenderCallback*)m_pSRCB)->SetDXRAP(NULL);
}
@@ -84,10 +81,10 @@ STDMETHODIMP CmadVRAllocatorPresenter::NonDelegatingQueryInterface(REFIID riid,
return GetInterface((IVMRWindowlessControl*)this, ppv);
*/
- if(riid != IID_IUnknown && m_pDXR)
- {
- if(SUCCEEDED(m_pDXR->QueryInterface(riid, ppv)))
+ if(riid != IID_IUnknown && m_pDXR) {
+ if(SUCCEEDED(m_pDXR->QueryInterface(riid, ppv))) {
return S_OK;
+ }
}
return __super::NonDelegatingQueryInterface(riid, ppv);
@@ -98,50 +95,47 @@ HRESULT CmadVRAllocatorPresenter::SetDevice(IDirect3DDevice9* pD3DDev)
CheckPointer(pD3DDev, E_POINTER);
CSize size;
- switch(GetRenderersSettings().nSPCMaxRes)
- {
- case 0:
- default:
- size = m_ScreenSize;
- break;
- case 1:
- size.SetSize(1024, 768);
- break;
- case 2:
- size.SetSize(800, 600);
- break;
- case 3:
- size.SetSize(640, 480);
- break;
- case 4:
- size.SetSize(512, 384);
- break;
- case 5:
- size.SetSize(384, 288);
- break;
- case 6:
- size.SetSize(2560, 1600);
- break;
- case 7:
- size.SetSize(1920, 1080);
- break;
- case 8:
- size.SetSize(1320, 900);
- break;
- case 9:
- size.SetSize(1280, 720);
- break;
+ switch(GetRenderersSettings().nSPCMaxRes) {
+ case 0:
+ default:
+ size = m_ScreenSize;
+ break;
+ case 1:
+ size.SetSize(1024, 768);
+ break;
+ case 2:
+ size.SetSize(800, 600);
+ break;
+ case 3:
+ size.SetSize(640, 480);
+ break;
+ case 4:
+ size.SetSize(512, 384);
+ break;
+ case 5:
+ size.SetSize(384, 288);
+ break;
+ case 6:
+ size.SetSize(2560, 1600);
+ break;
+ case 7:
+ size.SetSize(1920, 1080);
+ break;
+ case 8:
+ size.SetSize(1320, 900);
+ break;
+ case 9:
+ size.SetSize(1280, 720);
+ break;
}
- if(m_pAllocator)
- {
+ if(m_pAllocator) {
m_pAllocator->ChangeDevice(pD3DDev);
- }
- else
- {
+ } else {
m_pAllocator = DNew CDX9SubPicAllocator(pD3DDev, size, GetRenderersSettings().fSPCPow2Tex);
- if(!m_pAllocator)
+ if(!m_pAllocator) {
return E_FAIL;
+ }
}
HRESULT hr = S_OK;
@@ -149,10 +143,13 @@ HRESULT CmadVRAllocatorPresenter::SetDevice(IDirect3DDevice9* pD3DDev)
m_pSubPicQueue = GetRenderersSettings().nSPCSize > 0
? (ISubPicQueue*)DNew CSubPicQueue(GetRenderersSettings().nSPCSize, !GetRenderersSettings().fSPCAllowAnimationWhenBuffering, m_pAllocator, &hr)
: (ISubPicQueue*)DNew CSubPicQueueNoThread(m_pAllocator, &hr);
- if(!m_pSubPicQueue || FAILED(hr))
+ if(!m_pSubPicQueue || FAILED(hr)) {
return E_FAIL;
+ }
- if(m_SubPicProvider) m_pSubPicQueue->SetSubPicProvider(m_SubPicProvider);
+ if(m_SubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(m_SubPicProvider);
+ }
return S_OK;
}
@@ -163,7 +160,9 @@ HRESULT CmadVRAllocatorPresenter::Render(
{
__super::SetPosition(CRect(0, 0, width, height), CRect(left, top, right, bottom)); // needed? should be already set by the player
SetTime(rtStart);
- if(atpf > 0 && m_pSubPicQueue) m_pSubPicQueue->SetFPS(10000000.0 / atpf);
+ if(atpf > 0 && m_pSubPicQueue) {
+ m_pSubPicQueue->SetFPS(10000000.0 / atpf);
+ }
AlphaBltSubPic(CSize(width, height));
return S_OK;
}
@@ -174,27 +173,29 @@ STDMETHODIMP CmadVRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
{
CheckPointer(ppRenderer, E_POINTER);
- if(m_pDXR) return E_UNEXPECTED;
+ if(m_pDXR) {
+ return E_UNEXPECTED;
+ }
m_pDXR.CoCreateInstance(CLSID_madVR, GetOwner());
- if(!m_pDXR) return E_FAIL;
+ if(!m_pDXR) {
+ return E_FAIL;
+ }
- if (m_bIsFullscreen)
- {
+ if (m_bIsFullscreen) {
CComQIPtr<IMadVRFullscreen> pVRF = m_pDXR;
- if (pVRF != NULL)
+ if (pVRF != NULL) {
pVRF->ActivateFullscreenMode();
+ }
}
CComQIPtr<ISubRender> pSR = m_pDXR;
- if(!pSR)
- {
+ if(!pSR) {
m_pDXR = NULL;
return E_FAIL;
}
m_pSRCB = DNew CSubRenderCallback(this);
- if(FAILED(pSR->SetCallback(m_pSRCB)))
- {
+ if(FAILED(pSR->SetCallback(m_pSRCB))) {
m_pDXR = NULL;
return E_FAIL;
}
@@ -203,22 +204,21 @@ STDMETHODIMP CmadVRAllocatorPresenter::CreateRenderer(IUnknown** ppRenderer)
MONITORINFO mi;
mi.cbSize = sizeof(MONITORINFO);
- if (GetMonitorInfo(MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST), &mi))
+ if (GetMonitorInfo(MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST), &mi)) {
m_ScreenSize.SetSize(mi.rcMonitor.right-mi.rcMonitor.left, mi.rcMonitor.bottom-mi.rcMonitor.top);
+ }
return S_OK;
}
STDMETHODIMP_(void) CmadVRAllocatorPresenter::SetPosition(RECT w, RECT v)
{
- if(CComQIPtr<IBasicVideo> pBV = m_pDXR)
- {
+ if(CComQIPtr<IBasicVideo> pBV = m_pDXR) {
pBV->SetDefaultSourcePosition();
pBV->SetDestinationPosition(v.left, v.top, v.right - v.left, v.bottom - v.top);
}
- if(CComQIPtr<IVideoWindow> pVW = m_pDXR)
- {
+ if(CComQIPtr<IVideoWindow> pVW = m_pDXR) {
pVW->SetWindowPosition(w.left, w.top, w.right - w.left, w.bottom - w.top);
}
}
@@ -227,15 +227,14 @@ STDMETHODIMP_(SIZE) CmadVRAllocatorPresenter::GetVideoSize(bool fCorrectAR)
{
SIZE size = {0, 0};
- if(!fCorrectAR)
- {
- if(CComQIPtr<IBasicVideo> pBV = m_pDXR)
+ if(!fCorrectAR) {
+ if(CComQIPtr<IBasicVideo> pBV = m_pDXR) {
pBV->GetVideoSize(&size.cx, &size.cy);
- }
- else
- {
- if(CComQIPtr<IBasicVideo2> pBV2 = m_pDXR)
+ }
+ } else {
+ if(CComQIPtr<IBasicVideo2> pBV2 = m_pDXR) {
pBV2->GetPreferredAspectRatio(&size.cx, &size.cy);
+ }
}
return size;
@@ -249,8 +248,9 @@ STDMETHODIMP_(bool) CmadVRAllocatorPresenter::Paint(bool fAll)
STDMETHODIMP CmadVRAllocatorPresenter::GetDIB(BYTE* lpDib, DWORD* size)
{
HRESULT hr = E_NOTIMPL;
- if(CComQIPtr<IBasicVideo> pBV = m_pDXR)
+ if(CComQIPtr<IBasicVideo> pBV = m_pDXR) {
hr = pBV->GetCurrentImage((long*)size, (long*)lpDib);
+ }
return hr;
}
diff --git a/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.h b/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.h
index 540974c98..a8c763324 100644
--- a/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.h
+++ b/src/filters/renderer/VideoRenderers/madVRAllocatorPresenter.h
@@ -28,80 +28,74 @@
namespace DSObjects
{
-class CmadVRAllocatorPresenter
- : public CSubPicAllocatorPresenterImpl
-{
- class CSubRenderCallback : public CUnknown, public ISubRenderCallback, public CCritSec
+ class CmadVRAllocatorPresenter
+ : public CSubPicAllocatorPresenterImpl
{
- CmadVRAllocatorPresenter* m_pDXRAP;
+ class CSubRenderCallback : public CUnknown, public ISubRenderCallback, public CCritSec
+ {
+ CmadVRAllocatorPresenter* m_pDXRAP;
+
+ public:
+ CSubRenderCallback(CmadVRAllocatorPresenter* pDXRAP)
+ : CUnknown(_T("CSubRender"), NULL)
+ , m_pDXRAP(pDXRAP) {
+ }
+
+ DECLARE_IUNKNOWN
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
+ return
+ QI(ISubRenderCallback)
+ __super::NonDelegatingQueryInterface(riid, ppv);
+ }
+
+ void SetDXRAP(CmadVRAllocatorPresenter* pDXRAP) {
+ CAutoLock cAutoLock(this);
+ m_pDXRAP = pDXRAP;
+ }
+
+ // ISubRenderCallback
+
+ STDMETHODIMP SetDevice(IDirect3DDevice9* pD3DDev) {
+ CAutoLock cAutoLock(this);
+ return m_pDXRAP ? m_pDXRAP->SetDevice(pD3DDev) : E_UNEXPECTED;
+ }
+
+ STDMETHODIMP Render(REFERENCE_TIME rtStart, int left, int top, int right, int bottom, int width, int height) {
+ CAutoLock cAutoLock(this);
+ return m_pDXRAP ? m_pDXRAP->Render(rtStart, 0, 0, left, top, right, bottom, width, height) : E_UNEXPECTED;
+ }
+
+ // ISubRendererCallback2
+
+ STDMETHODIMP RenderEx(REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME AvgTimePerFrame, int left, int top, int right, int bottom, int width, int height) {
+ CAutoLock cAutoLock(this);
+ return m_pDXRAP ? m_pDXRAP->Render(rtStart, rtStop, AvgTimePerFrame, left, top, right, bottom, width, height) : E_UNEXPECTED;
+ }
+ };
+
+ CComPtr<IUnknown> m_pDXR;
+ CComPtr<ISubRenderCallback> m_pSRCB;
+ CSize m_ScreenSize;
+ bool m_bIsFullscreen;
public:
- CSubRenderCallback(CmadVRAllocatorPresenter* pDXRAP)
- : CUnknown(_T("CSubRender"), NULL)
- , m_pDXRAP(pDXRAP)
- {
- }
+ CmadVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
+ virtual ~CmadVRAllocatorPresenter();
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
- return
- QI(ISubRenderCallback)
- __super::NonDelegatingQueryInterface(riid, ppv);
- }
-
- void SetDXRAP(CmadVRAllocatorPresenter* pDXRAP)
- {
- CAutoLock cAutoLock(this);
- m_pDXRAP = pDXRAP;
- }
-
- // ISubRenderCallback
-
- STDMETHODIMP SetDevice(IDirect3DDevice9* pD3DDev)
- {
- CAutoLock cAutoLock(this);
- return m_pDXRAP ? m_pDXRAP->SetDevice(pD3DDev) : E_UNEXPECTED;
- }
-
- STDMETHODIMP Render(REFERENCE_TIME rtStart, int left, int top, int right, int bottom, int width, int height)
- {
- CAutoLock cAutoLock(this);
- return m_pDXRAP ? m_pDXRAP->Render(rtStart, 0, 0, left, top, right, bottom, width, height) : E_UNEXPECTED;
- }
-
- // ISubRendererCallback2
-
- STDMETHODIMP RenderEx(REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME AvgTimePerFrame, int left, int top, int right, int bottom, int width, int height)
- {
- CAutoLock cAutoLock(this);
- return m_pDXRAP ? m_pDXRAP->Render(rtStart, rtStop, AvgTimePerFrame, left, top, right, bottom, width, height) : E_UNEXPECTED;
- }
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ HRESULT SetDevice(IDirect3DDevice9* pD3DDev);
+ HRESULT Render(
+ REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME atpf,
+ int left, int top, int bottom, int right, int width, int height);
+
+ // ISubPicAllocatorPresenter
+ STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
+ STDMETHODIMP_(void) SetPosition(RECT w, RECT v);
+ STDMETHODIMP_(SIZE) GetVideoSize(bool fCorrectAR);
+ STDMETHODIMP_(bool) Paint(bool fAll);
+ STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
+ STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
};
-
- CComPtr<IUnknown> m_pDXR;
- CComPtr<ISubRenderCallback> m_pSRCB;
- CSize m_ScreenSize;
- bool m_bIsFullscreen;
-
-public:
- CmadVRAllocatorPresenter(HWND hWnd, bool bFullscreen, HRESULT& hr, CString &_Error);
- virtual ~CmadVRAllocatorPresenter();
-
- DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- HRESULT SetDevice(IDirect3DDevice9* pD3DDev);
- HRESULT Render(
- REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, REFERENCE_TIME atpf,
- int left, int top, int bottom, int right, int width, int height);
-
- // ISubPicAllocatorPresenter
- STDMETHODIMP CreateRenderer(IUnknown** ppRenderer);
- STDMETHODIMP_(void) SetPosition(RECT w, RECT v);
- STDMETHODIMP_(SIZE) GetVideoSize(bool fCorrectAR);
- STDMETHODIMP_(bool) Paint(bool fAll);
- STDMETHODIMP GetDIB(BYTE* lpDib, DWORD* size);
- STDMETHODIMP SetPixelShader(LPCSTR pSrcData, LPCSTR pTarget);
-};
}
diff --git a/src/filters/source/BaseSource/BaseSource.cpp b/src/filters/source/BaseSource/BaseSource.cpp
index 3c42d2732..1c26cb6ba 100644
--- a/src/filters/source/BaseSource/BaseSource.cpp
+++ b/src/filters/source/BaseSource/BaseSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -31,7 +31,7 @@
// CBaseStream
//
-CBaseStream::CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr)
+CBaseStream::CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr)
: CSourceStream(name, phr, pParent, L"Output")
, CSourceSeeking(name, (IPin*)this, phr, &m_cSharedState)
, m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
@@ -50,21 +50,20 @@ CBaseStream::~CBaseStream()
STDMETHODIMP CBaseStream::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv)
- : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
+ : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
void CBaseStream::UpdateFromSeek()
{
- if(ThreadExists())
- {
+ if(ThreadExists()) {
// next time around the loop, the worker thread will
// pick up the position change.
// We need to flush all the existing data - we must do that here
// as our thread will probably be blocked in GetBuffer otherwise
-
+
m_bFlushing = TRUE;
DeliverBeginFlush();
@@ -73,7 +72,7 @@ void CBaseStream::UpdateFromSeek()
// complete the flush
DeliverEndFlush();
- m_bFlushing = FALSE;
+ m_bFlushing = FALSE;
// restart
Run();
@@ -82,8 +81,9 @@ void CBaseStream::UpdateFromSeek()
HRESULT CBaseStream::SetRate(double dRate)
{
- if(dRate <= 0)
+ if(dRate <= 0) {
return E_INVALIDARG;
+ }
{
CAutoLock lock(CSourceSeeking::m_pLock);
@@ -97,45 +97,46 @@ HRESULT CBaseStream::SetRate(double dRate)
HRESULT CBaseStream::OnThreadStartPlay()
{
- m_bDiscontinuity = TRUE;
- return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
+ m_bDiscontinuity = TRUE;
+ return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
}
HRESULT CBaseStream::ChangeStart()
{
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
m_rtSampleTime = 0;
m_rtPosition = m_rtStart;
- }
+ }
- UpdateFromSeek();
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CBaseStream::ChangeStop()
{
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- if(m_rtPosition < m_rtStop)
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ if(m_rtPosition < m_rtStop) {
return S_OK;
- }
+ }
+ }
- // We're already past the new stop time -- better flush the graph.
- UpdateFromSeek();
+ // We're already past the new stop time -- better flush the graph.
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CBaseStream::OnThreadCreate()
{
- CAutoLock cAutoLockShared(&m_cSharedState);
+ CAutoLock cAutoLockShared(&m_cSharedState);
- m_rtSampleTime = 0;
- m_rtPosition = m_rtStart;
+ m_rtSampleTime = 0;
+ m_rtPosition = m_rtStart;
- return CSourceStream::OnThreadCreate();
+ return CSourceStream::OnThreadCreate();
}
HRESULT CBaseStream::FillBuffer(IMediaSample* pSample)
@@ -145,36 +146,39 @@ HRESULT CBaseStream::FillBuffer(IMediaSample* pSample)
{
CAutoLock cAutoLockShared(&m_cSharedState);
- if(m_rtPosition >= m_rtStop)
+ if(m_rtPosition >= m_rtStop) {
return S_FALSE;
+ }
BYTE* pOut = NULL;
- if(FAILED(hr = pSample->GetPointer(&pOut)) || !pOut)
+ if(FAILED(hr = pSample->GetPointer(&pOut)) || !pOut) {
return S_FALSE;
+ }
int nFrame = m_rtPosition / m_AvgTimePerFrame; // (int)(1.0 * m_rtPosition / m_AvgTimePerFrame + 0.5);
long len = pSample->GetSize();
hr = FillBuffer(pSample, nFrame, pOut, len);
- if(hr != S_OK) return hr;
+ if(hr != S_OK) {
+ return hr;
+ }
pSample->SetActualDataLength(len);
REFERENCE_TIME rtStart, rtStop;
- // The sample times are modified by the current rate.
- rtStart = static_cast<REFERENCE_TIME>(m_rtSampleTime / m_dRateSeeking);
- rtStop = rtStart + static_cast<int>(m_AvgTimePerFrame / m_dRateSeeking);
+ // The sample times are modified by the current rate.
+ rtStart = static_cast<REFERENCE_TIME>(m_rtSampleTime / m_dRateSeeking);
+ rtStop = rtStart + static_cast<int>(m_AvgTimePerFrame / m_dRateSeeking);
pSample->SetTime(&rtStart, &rtStop);
- m_rtSampleTime += m_AvgTimePerFrame;
- m_rtPosition += m_AvgTimePerFrame;
+ m_rtSampleTime += m_AvgTimePerFrame;
+ m_rtPosition += m_AvgTimePerFrame;
}
pSample->SetSyncPoint(TRUE);
- if(m_bDiscontinuity)
- {
+ if(m_bDiscontinuity) {
pSample->SetDiscontinuity(TRUE);
m_bDiscontinuity = FALSE;
}
diff --git a/src/filters/source/BaseSource/BaseSource.h b/src/filters/source/BaseSource/BaseSource.h
index b305defdc..fea572b3c 100644
--- a/src/filters/source/BaseSource/BaseSource.h
+++ b/src/filters/source/BaseSource/BaseSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -34,17 +34,17 @@ protected:
public:
CBaseSource(TCHAR* name, LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
- : CSource(name, lpunk, clsid)
- {
- if(phr) *phr = S_OK;
+ : CSource(name, lpunk, clsid) {
+ if(phr) {
+ *phr = S_OK;
+ }
}
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv)
- {
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv) {
CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
QI(IAMFilterMiscFlags)
__super::NonDelegatingQueryInterface(riid, ppv);
@@ -52,33 +52,37 @@ public:
// IFileSourceFilter
- STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
- {
+ STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt) {
// TODO: destroy any already existing pins and create new, now we are just going die nicely instead of doing it :)
- if(GetPinCount() > 0)
+ if(GetPinCount() > 0) {
return VFW_E_ALREADY_CONNECTED;
+ }
HRESULT hr = S_OK;
- if(!(DNew TStream(pszFileName, this, &hr)))
+ if(!(DNew TStream(pszFileName, this, &hr))) {
return E_OUTOFMEMORY;
+ }
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
m_fn = pszFileName;
return S_OK;
}
- STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
- {
+ STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt) {
size_t nCount;
- if(!ppszFileName) return E_POINTER;
-
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
+
nCount = m_fn.GetLength()+1;
*ppszFileName = (LPOLESTR)CoTaskMemAlloc(nCount*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy_s(*ppszFileName, nCount, m_fn);
@@ -87,13 +91,12 @@ public:
// IAMFilterMiscFlags
- STDMETHODIMP_(ULONG) GetMiscFlags()
- {
+ STDMETHODIMP_(ULONG) GetMiscFlags() {
return AM_FILTER_MISC_FLAGS_IS_SOURCE;
}
};
-class CBaseStream
+class CBaseStream
: public CSourceStream
, public CSourceSeeking
{
@@ -113,18 +116,20 @@ private:
STDMETHODIMP SetRate(double dRate);
HRESULT ChangeStart();
- HRESULT ChangeStop();
- HRESULT ChangeRate() {return S_OK;}
+ HRESULT ChangeStop();
+ HRESULT ChangeRate() {
+ return S_OK;
+ }
public:
- CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr);
+ CBaseStream(TCHAR* name, CSource* pParent, HRESULT* phr);
virtual ~CBaseStream();
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- HRESULT FillBuffer(IMediaSample* pSample);
+ HRESULT FillBuffer(IMediaSample* pSample);
- virtual HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/) = 0;
+ virtual HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/) = 0;
STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
diff --git a/src/filters/source/BaseSource/stdafx.cpp b/src/filters/source/BaseSource/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/source/BaseSource/stdafx.cpp
+++ b/src/filters/source/BaseSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/BaseSource/stdafx.h b/src/filters/source/BaseSource/stdafx.h
index 4811c9499..eb1a0a29e 100644
--- a/src/filters/source/BaseSource/stdafx.h
+++ b/src/filters/source/BaseSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/D2VSource/D2VSource.cpp b/src/filters/source/D2VSource/D2VSource.cpp
index 1745e381d..ec59fad28 100644
--- a/src/filters/source/D2VSource/D2VSource.cpp
+++ b/src/filters/source/D2VSource/D2VSource.cpp
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,23 +24,19 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_YUY2}
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CD2VSource), L"MPC - D2VSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CD2VSource>, NULL, &sudFilter[0]}
};
@@ -49,15 +45,15 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
_T("0"), _T("0,18,,4456443241564950726F6A65637446696C65")); // "DVD2AVIProjectFile"
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"),
_T("Source Filter"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".d2v"),
+ _T("Media Type\\Extensions"), _T(".d2v"),
_T("Source Filter"), _T("{47CE0591-C4D5-4b41-BED7-28F59AD76228}"));
return AMovieDllRegisterServer2(TRUE);
@@ -84,7 +80,9 @@ CFilterApp theApp;
CD2VSource::CD2VSource(LPUNKNOWN lpunk, HRESULT* phr)
: CBaseSource<CD2VStream>(NAME("CD2VSource"), lpunk, phr, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CD2VSource::~CD2VSource()
@@ -95,35 +93,40 @@ CD2VSource::~CD2VSource()
// CD2VStream
//
-CD2VStream::CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr)
+CD2VStream::CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr)
: CBaseStream(NAME("D2VSourceStream"), pParent, phr)
, m_pFrameBuffer(NULL)
{
CAutoLock cAutoLock(&m_cSharedState);
m_pDecoder.Attach(DNew CMPEG2Dec());
- if(!m_pDecoder)
- {
- if(phr) *phr = E_OUTOFMEMORY;
+ if(!m_pDecoder) {
+ if(phr) {
+ *phr = E_OUTOFMEMORY;
+ }
return;
}
- if(!m_pDecoder->Open(CString(fn), CMPEG2Dec::YUY2))
- {
- if(phr) *phr = E_FAIL;
+ if(!m_pDecoder->Open(CString(fn), CMPEG2Dec::YUY2)) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
- if(!m_pFrameBuffer.Allocate(m_pDecoder->Clip_Width*m_pDecoder->Clip_Height*4))
- {
- if(phr) *phr = E_OUTOFMEMORY;
+ if(!m_pFrameBuffer.Allocate(m_pDecoder->Clip_Width*m_pDecoder->Clip_Height*4)) {
+ if(phr) {
+ *phr = E_OUTOFMEMORY;
+ }
return;
}
m_AvgTimePerFrame = 10000000000i64/m_pDecoder->VF_FrameRate;
m_rtDuration = m_rtStop = m_AvgTimePerFrame*m_pDecoder->VF_FrameLimit;
- if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ if(phr) {
+ *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ }
}
CD2VStream::~CD2VStream()
@@ -133,37 +136,42 @@ CD2VStream::~CD2VStream()
HRESULT CD2VStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
-// CAutoLock cAutoLock(m_pFilter->pStateLock());
+ // CAutoLock cAutoLock(m_pFilter->pStateLock());
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
int w, h, bpp;
- if(!GetDim(w, h, bpp))
+ if(!GetDim(w, h, bpp)) {
return E_FAIL;
+ }
pProperties->cBuffers = 1;
pProperties->cbBuffer = w*h*bpp>>3;
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CD2VStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len)
{
- if(!m_pDecoder)
+ if(!m_pDecoder) {
return S_FALSE;
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
SetMediaType(&mt);
@@ -171,8 +179,9 @@ HRESULT CD2VStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, lo
}
int w, h, bpp;
- if(!GetDim(w, h, bpp))
+ if(!GetDim(w, h, bpp)) {
return S_FALSE;
+ }
BYTE* pIn = m_pFrameBuffer;
@@ -183,10 +192,9 @@ HRESULT CD2VStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, lo
m_pDecoder->Decode(pIn, (unsigned long)(nFrame), pitchIn);
- for(int y = 0, p = min(pitchIn, pitchOut);
- y < h;
- y++, pIn += pitchIn, pOut += pitchOut)
- {
+ for(int y = 0, p = min(pitchIn, pitchOut);
+ y < h;
+ y++, pIn += pitchIn, pOut += pitchOut) {
memcpy(pOut, pIn, p);
}
@@ -197,15 +205,19 @@ HRESULT CD2VStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, lo
HRESULT CD2VStream::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pFilter->pStateLock());
+ CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
- pmt->SetType(&MEDIATYPE_Video);
- pmt->SetSubtype(&MEDIASUBTYPE_YUY2);
- pmt->SetFormatType(&FORMAT_VideoInfo);
- pmt->SetTemporalCompression(FALSE);
+ pmt->SetType(&MEDIATYPE_Video);
+ pmt->SetSubtype(&MEDIASUBTYPE_YUY2);
+ pmt->SetFormatType(&FORMAT_VideoInfo);
+ pmt->SetTemporalCompression(FALSE);
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
memset(vih, 0, sizeof(VIDEOINFOHEADER));
@@ -220,17 +232,17 @@ HRESULT CD2VStream::GetMediaType(int iPosition, CMediaType* pmt)
pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
- return NOERROR;
+ return NOERROR;
}
HRESULT CD2VStream::SetMediaType(const CMediaType* pmt)
{
- if(m_pDecoder)
- {
- if(pmt->subtype == MEDIASUBTYPE_YUY2)
+ if(m_pDecoder) {
+ if(pmt->subtype == MEDIASUBTYPE_YUY2) {
m_pDecoder->m_dstFormat = CMPEG2Dec::YUY2;
- else
+ } else {
return E_FAIL;
+ }
}
return CSourceStream::SetMediaType(pmt);
@@ -239,20 +251,19 @@ HRESULT CD2VStream::SetMediaType(const CMediaType* pmt)
HRESULT CD2VStream::CheckMediaType(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Video
- && pmt->subtype == MEDIASUBTYPE_YUY2
- && pmt->formattype == FORMAT_VideoInfo
- ? S_OK
- : E_INVALIDARG;
+ && pmt->subtype == MEDIASUBTYPE_YUY2
+ && pmt->formattype == FORMAT_VideoInfo
+ ? S_OK
+ : E_INVALIDARG;
}
STDMETHODIMP CD2VStream::Notify(IBaseFilter* pSender, Quality q)
{
- if(q.Late > 0 && q.Late < 100000000)
- {
+ if(q.Late > 0 && q.Late < 100000000) {
CAutoLock cAutoLockShared(&m_cSharedState);
- m_rtSampleTime += (q.Late/m_AvgTimePerFrame)*m_AvgTimePerFrame;
- m_rtPosition += (q.Late/m_AvgTimePerFrame)*m_AvgTimePerFrame;
+ m_rtSampleTime += (q.Late/m_AvgTimePerFrame)*m_AvgTimePerFrame;
+ m_rtPosition += (q.Late/m_AvgTimePerFrame)*m_AvgTimePerFrame;
}
return S_OK;
@@ -262,20 +273,15 @@ STDMETHODIMP CD2VStream::Notify(IBaseFilter* pSender, Quality q)
bool CD2VStream::GetDim(int& w, int& h, int& bpp)
{
- if(m_mt.formattype == FORMAT_VideoInfo)
- {
+ if(m_mt.formattype == FORMAT_VideoInfo) {
w = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biWidth;
h = abs(((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biHeight);
bpp = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
+ } else if(m_mt.formattype == FORMAT_VideoInfo2) {
w = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biWidth;
h = abs(((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biHeight);
bpp = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else
- {
+ } else {
return(false);
}
diff --git a/src/filters/source/D2VSource/D2VSource.h b/src/filters/source/D2VSource/D2VSource.h
index d36f05956..6d38f3936 100644
--- a/src/filters/source/D2VSource/D2VSource.h
+++ b/src/filters/source/D2VSource/D2VSource.h
@@ -1,16 +1,16 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,7 +24,7 @@
class CD2VStream;
class __declspec(uuid("47CE0591-C4D5-4b41-BED7-28F59AD76228"))
-CD2VSource : public CBaseSource<CD2VStream>
+ CD2VSource : public CBaseSource<CD2VStream>
{
public:
CD2VSource(LPUNKNOWN lpunk, HRESULT* phr);
@@ -42,15 +42,15 @@ private:
bool GetDim(int& w, int& h, int& bpp);
public:
- CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr);
+ CD2VStream(const WCHAR* fn, CSource* pParent, HRESULT* phr);
virtual ~CD2VStream();
- HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/);
+ HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len /*in+out*/);
- HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT CheckMediaType(const CMediaType* pMediaType);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- HRESULT SetMediaType(const CMediaType* pmt);
+ HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT CheckMediaType(const CMediaType* pMediaType);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ HRESULT SetMediaType(const CMediaType* pmt);
STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
diff --git a/src/filters/source/DTSAC3Source/DTSAC3Source.cpp b/src/filters/source/DTSAC3Source/DTSAC3Source.cpp
index ea2c58ba2..98e61db08 100644
--- a/src/filters/source/DTSAC3Source/DTSAC3Source.cpp
+++ b/src/filters/source/DTSAC3Source/DTSAC3Source.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -30,21 +30,18 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_DTS},
{&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_DTS},
{&MEDIATYPE_Audio, &MEDIASUBTYPE_DOLBY_AC3},
{&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_DOLBY_AC3},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
#ifdef DDPLUS_ONLY
{&__uuidof(CDTSAC3Source), L"MPC - DD+ Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin}
#else
@@ -52,8 +49,7 @@ const AMOVIESETUP_FILTER sudFilter[] =
#endif
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDTSAC3Source>, NULL, &sudFilter[0]}
};
@@ -62,36 +58,36 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
_T("0"), _T("0,4,,7FFE8001"));
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
_T("1"), _T("0,2,,0B77"));
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
_T("2"), _T("0,2,,770B"));
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"),
_T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
#ifndef DDPLUS_ONLY
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".dts"),
+ _T("Media Type\\Extensions"), _T(".dts"),
_T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ac3"),
+ _T("Media Type\\Extensions"), _T(".ac3"),
_T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
#endif
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ddp"),
+ _T("Media Type\\Extensions"), _T(".ddp"),
_T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ec3"),
+ _T("Media Type\\Extensions"), _T(".ec3"),
_T("Source Filter"), _T("{B4A7BE85-551D-4594-BDC7-832B09185041}"));
return AMovieDllRegisterServer2(TRUE);
@@ -131,7 +127,7 @@ CDTSAC3Source::~CDTSAC3Source()
// CDTSAC3Stream
-CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
+CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
: CBaseStream(NAME("CDTSAC3Stream"), pParent, phr)
, m_nFileOffset(0)
{
@@ -143,25 +139,28 @@ CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
CString fn(wfn);
- if(!m_file.Open(fn, CFile::modeRead|CFile::shareDenyNone))
- {
- if(phr) *phr = E_FAIL;
+ if(!m_file.Open(fn, CFile::modeRead|CFile::shareDenyNone)) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
DWORD id = 0;
if(m_file.Read(&id, sizeof(id)) != sizeof(id)
- || id != 0x0180FE7F && (WORD)id != 0x0b77 && (WORD)id != 0x770b)
- {
- if(phr) *phr = E_FAIL;
+ || id != 0x0180FE7F && (WORD)id != 0x0b77 && (WORD)id != 0x770b) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
- if(id == 0x0180FE7F)
- {
+ if(id == 0x0180FE7F) {
#ifdef DDPLUS_ONLY
-//Temporary patch to disable DTS source
- if(phr) *phr = E_FAIL;
+ //Temporary patch to disable DTS source
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
#endif
BYTE buff[8];
@@ -181,8 +180,7 @@ CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
UNUSED_ALWAYS(npcmsampleblocks);
UNUSED_ALWAYS(audiochannelarrangement);
- int freqtbl[] =
- {
+ int freqtbl[] = {
0,8000,16000,32000,
0,0,
11025,22050,44100,
@@ -191,8 +189,7 @@ CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
0,0
};
- int bitratetbl[] =
- {
+ int bitratetbl[] = {
32000,56000,64000,96000,112000,128000,192000,224000,
256000,320000,384000,448000,512000,576000,640000,754500,
960000,1024000,1152000,1280000,1344000,1408000,1411200,1472000,
@@ -203,50 +200,50 @@ CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
m_nSamplesPerSec = freqtbl[freq];
m_nAvgBytesPerSec = (bitratetbl[transbitrate] + 4) / 8;
-// m_nBytesPerFrame = m_nAvgBytesPerSec*10.656063618290258449304174950298/1000 + 0.5;
+ // m_nBytesPerFrame = m_nAvgBytesPerSec*10.656063618290258449304174950298/1000 + 0.5;
m_nBytesPerFrame = framebytes*DTS_MAGIC_NUMBER;
- if (framebytes == 2012)
- {
+ if (framebytes == 2012) {
// DTS and DTS-HD tracks from HD DVD and Blu-Ray sources have framesizes of 2012 bytes
// but if we handle them mathematically "correctly", audio sync will slowly drift away
// we have to handle them as if they had 2013 bytes
m_AvgTimePerFrame = 10000000i64 * (2013*DTS_MAGIC_NUMBER) * 8 / bitratetbl[transbitrate];
- }
- else
+ } else {
m_AvgTimePerFrame = 10000000i64 * m_nBytesPerFrame * 8 / bitratetbl[transbitrate];
+ }
m_subtype = MEDIASUBTYPE_DTS;
m_wFormatTag = WAVE_FORMAT_DVD_DTS;
m_streamid = 0x88;
- }
- else
- {
+ } else {
BYTE info, info1, bsid;
- if((BYTE)id == 0x77) m_file.Seek(1, CFile::current); // LE
+ if((BYTE)id == 0x77) {
+ m_file.Seek(1, CFile::current); // LE
+ }
m_file.Read(&info, 1);
m_file.Read(&info1, 1);
bsid = (info1>>3);
- if(bsid>=0 && bsid<=8) //AC3
- {
+ if(bsid>=0 && bsid<=8) { //AC3
#ifdef DDPLUS_ONLY
-//Temporary patch to disable AC3 source
- if(phr) *phr = E_FAIL;
+ //Temporary patch to disable AC3 source
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
#endif
BYTE freq = info>>6;
BYTE bitrate = info&0x3f;
- if(bitrate >= 38)
- {
- if(phr) *phr = E_FAIL;
+ if(bitrate >= 38) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
int freqtbl[] = {48000,44100,32000,48000};
- int bitratetbl[] =
- {
+ int bitratetbl[] = {
32000,32000,40000,40000,48000,48000,56000,56000,64000,64000,
80000,80000,96000,96000,112000,112000,128000,128000,160000,160000,
192000,192000,224000,224000,256000,256000,320000,320000,384000,384000,
@@ -259,18 +256,15 @@ CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
m_nAvgBytesPerSec = (bitratetbl[bitrate] + 4) / 8;
m_nBytesPerFrame = m_nAvgBytesPerSec*32/1000*AC3_MAGIC_NUMBER;
m_AvgTimePerFrame = 10000000i64 * m_nBytesPerFrame * 8 / bitratetbl[bitrate];
-
+
m_subtype = MEDIASUBTYPE_DOLBY_AC3;
m_wFormatTag = WAVE_FORMAT_DOLBY_AC3;
m_streamid = 0x80;
- }
- else if(bsid>=11 && bsid <=16) //DD+
- {
+ } else if(bsid>=11 && bsid <=16) { //DD+
BYTE fscod = info>>6;
BYTE numblkscod = (info&0x30)>>4;
- if(fscod == 3)
- {
+ if(fscod == 3) {
fscod = numblkscod+3;
numblkscod = 3;
}
@@ -284,10 +278,10 @@ CDTSAC3Stream::CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
m_subtype = MEDIASUBTYPE_DOLBY_AC3;
m_wFormatTag = WAVE_FORMAT_DOLBY_AC3;
m_streamid = 0xC0;
- }
- else
- {
- if(phr) *phr = E_FAIL;
+ } else {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
@@ -303,21 +297,25 @@ CDTSAC3Stream::~CDTSAC3Stream()
HRESULT CDTSAC3Stream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
pProperties->cBuffers = 1;
pProperties->cbBuffer = m_nBytesPerFrame+35;
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CDTSAC3Stream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len)
@@ -328,10 +326,8 @@ HRESULT CDTSAC3Stream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut,
const GUID* subtype = &m_mt.subtype;
UNUSED_ALWAYS(subtype);
- if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- {
- BYTE PESHeader[] =
- {
+ if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK) {
+ BYTE PESHeader[] = {
0x00,0x00,0x01,0xBA, // PES id
0x44,0x00,0x04,0x00,0x04,0x01, // SCR (0)
0x01,0x89,0xC3,0xF8, // mux rate (1260000 bytes/sec, 22bits), marker (2bits), reserved (~0, 5bits), stuffing (0, 3bits)
@@ -343,10 +339,8 @@ HRESULT CDTSAC3Stream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut,
majortype = &MEDIATYPE_MPEG2_PES;
}
- if(*majortype == MEDIATYPE_MPEG2_PES)
- {
- BYTE Private1Header[] =
- {
+ if(*majortype == MEDIATYPE_MPEG2_PES) {
+ BYTE Private1Header[] = {
0x00,0x00,0x01,0xBD, // private stream 1 id
(m_nBytesPerFrame+15)>>8,(m_nBytesPerFrame+15)&255, // packet length
0x81,0x80, // marker, original, PTS - flags
@@ -363,10 +357,11 @@ HRESULT CDTSAC3Stream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut,
majortype = &MEDIATYPE_Audio;
}
- if(*majortype == MEDIATYPE_Audio)
- {
+ if(*majortype == MEDIATYPE_Audio) {
m_file.Seek(m_nFileOffset + nFrame*m_nBytesPerFrame, CFile::begin);
- if(m_file.Read(pOut, m_nBytesPerFrame) < m_nBytesPerFrame) return S_FALSE;
+ if(m_file.Read(pOut, m_nBytesPerFrame) < m_nBytesPerFrame) {
+ return S_FALSE;
+ }
pOut += m_nBytesPerFrame;
}
@@ -378,43 +373,42 @@ HRESULT CDTSAC3Stream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut,
bool CDTSAC3Stream::CheckDTS(const CMediaType* pmt)
{
return (pmt->majortype == MEDIATYPE_Audio
- || pmt->majortype == MEDIATYPE_MPEG2_PES
+ || pmt->majortype == MEDIATYPE_MPEG2_PES
|| pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- && pmt->subtype == MEDIASUBTYPE_DTS;
-// return pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_DTS;
+ && pmt->subtype == MEDIASUBTYPE_DTS;
+ // return pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_DTS;
}
bool CDTSAC3Stream::CheckWAVEDTS(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_WAVE_DTS
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS;
+ && pmt->subtype == MEDIASUBTYPE_WAVE_DTS
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS;
}
bool CDTSAC3Stream::CheckAC3(const CMediaType* pmt)
{
return (pmt->majortype == MEDIATYPE_Audio
- || pmt->majortype == MEDIATYPE_MPEG2_PES
+ || pmt->majortype == MEDIATYPE_MPEG2_PES
|| pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
-// return pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
+ && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
+ // return pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
}
bool CDTSAC3Stream::CheckWAVEAC3(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3;
+ && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3;
}
HRESULT CDTSAC3Stream::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pFilter->pStateLock());
+ CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition >= 0 && iPosition < 5)
- {
+ if(iPosition >= 0 && iPosition < 5) {
pmt->subtype = m_subtype;
pmt->formattype = FORMAT_WaveFormatEx;
WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
@@ -425,29 +419,26 @@ HRESULT CDTSAC3Stream::GetMediaType(int iPosition, CMediaType* pmt)
wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
wfe->nChannels = 6;
- switch(iPosition)
- {
- case 0:
- pmt->majortype = MEDIATYPE_Audio;
- break;
- case 1:
- pmt->ResetFormatBuffer();
- pmt->formattype = FORMAT_None;
- case 2:
- pmt->majortype = MEDIATYPE_MPEG2_PES;
- break;
- case 3:
- pmt->ResetFormatBuffer();
- pmt->formattype = FORMAT_None;
- case 4:
- pmt->majortype = MEDIATYPE_DVD_ENCRYPTED_PACK;
- break;
- default:
- return E_INVALIDARG;
+ switch(iPosition) {
+ case 0:
+ pmt->majortype = MEDIATYPE_Audio;
+ break;
+ case 1:
+ pmt->ResetFormatBuffer();
+ pmt->formattype = FORMAT_None;
+ case 2:
+ pmt->majortype = MEDIATYPE_MPEG2_PES;
+ break;
+ case 3:
+ pmt->ResetFormatBuffer();
+ pmt->formattype = FORMAT_None;
+ case 4:
+ pmt->majortype = MEDIATYPE_DVD_ENCRYPTED_PACK;
+ break;
+ default:
+ return E_INVALIDARG;
}
- }
- else if(iPosition == 5)
- {
+ } else if(iPosition == 5) {
pmt->majortype = MEDIATYPE_Audio;
pmt->subtype = FOURCCMap(m_wFormatTag);
pmt->formattype = FORMAT_WaveFormatEx;
@@ -459,13 +450,11 @@ HRESULT CDTSAC3Stream::GetMediaType(int iPosition, CMediaType* pmt)
wfe->nAvgBytesPerSec = m_nAvgBytesPerSec;
wfe->nChannels = 2;
wfe->nBlockAlign = 1;
- }
- else
- {
+ } else {
return VFW_S_NO_MORE_ITEMS;
}
- pmt->SetTemporalCompression(FALSE);
+ pmt->SetTemporalCompression(FALSE);
return S_OK;
}
@@ -473,7 +462,7 @@ HRESULT CDTSAC3Stream::GetMediaType(int iPosition, CMediaType* pmt)
HRESULT CDTSAC3Stream::CheckMediaType(const CMediaType* pmt)
{
return CheckDTS(pmt) || CheckWAVEDTS(pmt)
- || CheckAC3(pmt) || CheckWAVEAC3(pmt)
- ? S_OK
- : E_INVALIDARG;
+ || CheckAC3(pmt) || CheckWAVEAC3(pmt)
+ ? S_OK
+ : E_INVALIDARG;
}
diff --git a/src/filters/source/DTSAC3Source/DTSAC3Source.h b/src/filters/source/DTSAC3Source/DTSAC3Source.h
index 5f0b1a976..75593e8f4 100644
--- a/src/filters/source/DTSAC3Source/DTSAC3Source.h
+++ b/src/filters/source/DTSAC3Source/DTSAC3Source.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,7 +27,7 @@
class CDTSAC3Stream;
class __declspec(uuid("B4A7BE85-551D-4594-BDC7-832B09185041"))
-CDTSAC3Source : public CBaseSource<CDTSAC3Stream>
+ CDTSAC3Source : public CBaseSource<CDTSAC3Stream>
{
public:
CDTSAC3Source(LPUNKNOWN lpunk, HRESULT* phr);
@@ -48,12 +48,12 @@ class CDTSAC3Stream : public CBaseStream
bool CheckWAVEAC3(const CMediaType* pmt);
public:
- CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr);
+ CDTSAC3Stream(const WCHAR* wfn, CSource* pParent, HRESULT* phr);
virtual ~CDTSAC3Stream();
- HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len);
-
+ HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len);
+
HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT CheckMediaType(const CMediaType* pMediaType);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ HRESULT CheckMediaType(const CMediaType* pMediaType);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
};
diff --git a/src/filters/source/DTSAC3Source/stdafx.cpp b/src/filters/source/DTSAC3Source/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/source/DTSAC3Source/stdafx.cpp
+++ b/src/filters/source/DTSAC3Source/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/DTSAC3Source/stdafx.h b/src/filters/source/DTSAC3Source/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/source/DTSAC3Source/stdafx.h
+++ b/src/filters/source/DTSAC3Source/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/FLICSource/FLICSource.cpp b/src/filters/source/FLICSource/FLICSource.cpp
index 696103f59..16e92a992 100644
--- a/src/filters/source/FLICSource/FLICSource.cpp
+++ b/src/filters/source/FLICSource/FLICSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,23 +25,19 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_RGB32},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CFLICSource), L"MPC - FLICSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFLICSource>, NULL, &sudFilter[0]}
};
@@ -50,23 +46,23 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
- _T("0"), _T("4,2,,11AF"));
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
+ _T("0"), _T("4,2,,11AF"));
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
_T("1"), _T("4,2,,12AF"));
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"),
_T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".fli"),
+ _T("Media Type\\Extensions"), _T(".fli"),
_T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".flc"),
+ _T("Media Type\\Extensions"), _T(".flc"),
_T("Source Filter"), _T("{17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4}"));
return AMovieDllRegisterServer2(TRUE);
@@ -102,9 +98,9 @@ CFLICSource::~CFLICSource()
STDMETHODIMP CFLICSource::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
QI(IAMFilterMiscFlags)
__super::NonDelegatingQueryInterface(riid, ppv);
@@ -112,17 +108,20 @@ STDMETHODIMP CFLICSource::NonDelegatingQueryInterface(REFIID riid, void** ppv)
// IFileSourceFilter
-STDMETHODIMP CFLICSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CFLICSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(GetPinCount() > 0)
+ if(GetPinCount() > 0) {
return VFW_E_ALREADY_CONNECTED;
+ }
HRESULT hr = S_OK;
- if(!(DNew CFLICStream(pszFileName, this, &hr)))
+ if(!(DNew CFLICStream(pszFileName, this, &hr))) {
return E_OUTOFMEMORY;
+ }
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
m_fn = pszFileName;
@@ -131,11 +130,14 @@ STDMETHODIMP CFLICSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
STDMETHODIMP CFLICSource::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
+
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -151,7 +153,7 @@ ULONG CFLICSource::GetMiscFlags()
// CFLICStream
-CFLICStream::CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr)
+CFLICStream::CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr)
: CSourceStream(NAME("FLICStream"), phr, pParent, L"Output")
, CSourceSeeking(NAME("FLICStream"), (IPin*)this, phr, &m_cSharedState)
, m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
@@ -160,98 +162,106 @@ CFLICStream::CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr)
CString fn(wfn);
- if(!m_flic.Open(fn, CFile::modeRead|CFile::shareDenyNone))
- {
- if(phr) *phr = E_FAIL;
+ if(!m_flic.Open(fn, CFile::modeRead|CFile::shareDenyNone)) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
if(m_flic.Read(&m_hdr, sizeof(m_hdr)) != sizeof(m_hdr)
- || (m_hdr.id != 0xaf11 && m_hdr.id != 0xaf12)
- || m_hdr.bpp != 8)
- {
- if(phr) *phr = E_FAIL;
+ || (m_hdr.id != 0xaf11 && m_hdr.id != 0xaf12)
+ || m_hdr.bpp != 8) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
m_AvgTimePerFrame = (m_hdr.id == 0xaf11)
- ? 10000000i64 * max(m_hdr.ticks, 1) / 70
- : 10000000i64 * max(m_hdr.ticks, 1) / 1000;
+ ? 10000000i64 * max(m_hdr.ticks, 1) / 70
+ : 10000000i64 * max(m_hdr.ticks, 1) / 1000;
// not tested (lack of test files)
{
__int64 pos = m_flic.GetPosition();
FLIC_PREFIX fp;
- if(m_flic.Read(&fp, sizeof(fp)) != sizeof(fp) || fp.id != 0xf100)
+ if(m_flic.Read(&fp, sizeof(fp)) != sizeof(fp) || fp.id != 0xf100) {
m_flic.Seek(pos, CFile::begin);
- else
+ } else {
m_flic.Seek(pos + fp.size, CFile::begin);
+ }
}
- do
- {
+ do {
FLIC_FRAME_ENTRY ffe;
- if(m_flic.Read(&ffe.hdr, sizeof(ffe.hdr)) != sizeof(ffe.hdr) || ffe.hdr.id != 0xf1fa)
+ if(m_flic.Read(&ffe.hdr, sizeof(ffe.hdr)) != sizeof(ffe.hdr) || ffe.hdr.id != 0xf1fa) {
break;
+ }
ffe.pos = m_flic.GetPosition();
ffe.fKeyframe = (m_frames.GetCount() == 0);
int chunk = 0;
- while(chunk < ffe.hdr.chunks)
- {
+ while(chunk < ffe.hdr.chunks) {
FLIC_CHUNK fc;
- if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc))
+ if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc)) {
break;
-/*
- switch(fc.type)
- {
- case FLIC_COLOR: _colorchunk(); break;
- case FLIC_256_COLOR: _color256chunk(); break;
- case FLIC_BRUN: _brunchunk(); break;
- case FLIC_LC: _lcchunk(); break;
- case FLIC_DELTA: _deltachunk(); break;
- case FLIC_BLACK: _blackchunk(); break;
- case FLIC_COPY: _copychunk(); break;
- case FLIC_MINI: break;
- default: break;
}
-*/
- ffe.fKeyframe =
+ /*
+ switch(fc.type)
+ {
+ case FLIC_COLOR: _colorchunk(); break;
+ case FLIC_256_COLOR: _color256chunk(); break;
+ case FLIC_BRUN: _brunchunk(); break;
+ case FLIC_LC: _lcchunk(); break;
+ case FLIC_DELTA: _deltachunk(); break;
+ case FLIC_BLACK: _blackchunk(); break;
+ case FLIC_COPY: _copychunk(); break;
+ case FLIC_MINI: break;
+ default: break;
+ }
+ */
+ ffe.fKeyframe =
(/*fc.type == FLIC_256_COLOR
|| fc.type == FLIC_64_COLOR
- ||*/ fc.type == FLIC_BRUN
- || fc.type == FLIC_BLACK
- || fc.type == FLIC_COPY);
+ ||*/ fc.type == FLIC_BRUN
+ || fc.type == FLIC_BLACK
+ || fc.type == FLIC_COPY);
ULONGLONG pos = m_flic.GetPosition() + fc.size - sizeof(fc);
- if(m_flic.Seek(pos, CFile::begin) != pos)
+ if(m_flic.Seek(pos, CFile::begin) != pos) {
break;
+ }
chunk++;
}
- if(chunk < ffe.hdr.chunks)
+ if(chunk < ffe.hdr.chunks) {
break;
+ }
ULONGLONG pos = ffe.pos + ffe.hdr.size - sizeof(ffe.hdr);
- if(m_flic.Seek(pos, CFile::begin) != pos)
+ if(m_flic.Seek(pos, CFile::begin) != pos) {
break;
+ }
m_frames.Add(ffe);
- }
- while(1);
+ } while(1);
m_nLastFrameNum = -1;
memset(m_pPalette, 0, sizeof(m_pPalette));
m_nBufferSize = m_hdr.x*m_hdr.y*32>>3;
- if(!m_pFrameBuffer.Allocate(m_nBufferSize))
- {
- if(phr) *phr = E_OUTOFMEMORY;
+ if(!m_pFrameBuffer.Allocate(m_nBufferSize)) {
+ if(phr) {
+ *phr = E_OUTOFMEMORY;
+ }
return;
}
m_rtDuration = m_rtStop = m_AvgTimePerFrame*m_frames.GetCount();
- if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ if(phr) {
+ *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ }
}
CFLICStream::~CFLICStream()
@@ -261,21 +271,20 @@ CFLICStream::~CFLICStream()
STDMETHODIMP CFLICStream::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv) //GetInterface((IMediaSeeking*)this, ppv)
- : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
+ : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
void CFLICStream::UpdateFromSeek()
{
- if(ThreadExists())
- {
+ if(ThreadExists()) {
// next time around the loop, the worker thread will
// pick up the position change.
// We need to flush all the existing data - we must do that here
// as our thread will probably be blocked in GetBuffer otherwise
-
+
m_bFlushing = TRUE;
DeliverBeginFlush();
@@ -284,7 +293,7 @@ void CFLICStream::UpdateFromSeek()
// complete the flush
DeliverEndFlush();
- m_bFlushing = FALSE;
+ m_bFlushing = FALSE;
// restart
Run();
@@ -293,8 +302,9 @@ void CFLICStream::UpdateFromSeek()
HRESULT CFLICStream::SetRate(double dRate)
{
- if(dRate <= 0)
+ if(dRate <= 0) {
return E_INVALIDARG;
+ }
{
CAutoLock lock(CSourceSeeking::m_pLock);
@@ -308,65 +318,70 @@ HRESULT CFLICStream::SetRate(double dRate)
HRESULT CFLICStream::OnThreadStartPlay()
{
- m_bDiscontinuity = TRUE;
- return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
+ m_bDiscontinuity = TRUE;
+ return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
}
HRESULT CFLICStream::ChangeStart()
{
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
m_rtSampleTime = 0;
m_rtPosition = m_rtStart;
- }
+ }
- UpdateFromSeek();
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CFLICStream::ChangeStop()
{
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- if(m_rtPosition < m_rtStop)
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ if(m_rtPosition < m_rtStop) {
return S_OK;
- }
+ }
+ }
- // We're already past the new stop time -- better flush the graph.
- UpdateFromSeek();
+ // We're already past the new stop time -- better flush the graph.
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CFLICStream::OnThreadCreate()
{
- CAutoLock cAutoLockShared(&m_cSharedState);
- m_rtSampleTime = 0;
- m_rtPosition = m_rtStart;
+ CAutoLock cAutoLockShared(&m_cSharedState);
+ m_rtSampleTime = 0;
+ m_rtPosition = m_rtStart;
- return CSourceStream::OnThreadCreate();
+ return CSourceStream::OnThreadCreate();
}
HRESULT CFLICStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
-// CAutoLock cAutoLock(m_pFilter->pStateLock());
+ // CAutoLock cAutoLock(m_pFilter->pStateLock());
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
pProperties->cBuffers = 1;
pProperties->cbBuffer = m_nBufferSize;
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
@@ -376,17 +391,18 @@ HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
{
CAutoLock cAutoLockShared(&m_cSharedState);
- if(m_rtPosition >= m_rtStop)
+ if(m_rtPosition >= m_rtStop) {
return S_FALSE;
+ }
BYTE* pDataIn = m_pFrameBuffer;
BYTE* pDataOut = NULL;
- if(!pDataIn || FAILED(hr = pSample->GetPointer(&pDataOut)) || !pDataOut)
+ if(!pDataIn || FAILED(hr = pSample->GetPointer(&pDataOut)) || !pDataOut) {
return S_FALSE;
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
SetMediaType(&mt);
@@ -394,20 +410,15 @@ HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
}
int w, h, bpp;
- if(m_mt.formattype == FORMAT_VideoInfo)
- {
+ if(m_mt.formattype == FORMAT_VideoInfo) {
w = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biWidth;
h = abs(((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biHeight);
bpp = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
+ } else if(m_mt.formattype == FORMAT_VideoInfo2) {
w = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biWidth;
h = abs(((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biHeight);
bpp = ((VIDEOINFOHEADER2*)m_mt.pbFormat)->bmiHeader.biBitCount;
- }
- else
- {
+ } else {
return S_FALSE;
}
@@ -419,36 +430,37 @@ HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
{
SeekToNearestKeyFrame(nFrame);
- while(m_nLastFrameNum < nFrame && !m_bFlushing)
+ while(m_nLastFrameNum < nFrame && !m_bFlushing) {
ExtractFrame(++m_nLastFrameNum);
+ }
- for(int y = 0, p = min(pitchIn, pitchOut);
- y < h;
- y++, pDataIn += pitchIn, pDataOut += pitchOut)
- {
+ for(int y = 0, p = min(pitchIn, pitchOut);
+ y < h;
+ y++, pDataIn += pitchIn, pDataOut += pitchOut) {
BYTE* src = pDataIn;
BYTE* end = src + p;
DWORD* dst = (DWORD*)pDataOut;
- while(src < end) *dst++ = m_pPalette[*src++];
+ while(src < end) {
+ *dst++ = m_pPalette[*src++];
+ }
}
}
pSample->SetActualDataLength(pitchOut*h);
REFERENCE_TIME rtStart, rtStop;
- // The sample times are modified by the current rate.
- rtStart = static_cast<REFERENCE_TIME>(m_rtSampleTime / m_dRateSeeking);
- rtStop = rtStart + static_cast<int>(m_AvgTimePerFrame / m_dRateSeeking);
- pSample->SetTime(&rtStart, &rtStop);
+ // The sample times are modified by the current rate.
+ rtStart = static_cast<REFERENCE_TIME>(m_rtSampleTime / m_dRateSeeking);
+ rtStop = rtStart + static_cast<int>(m_AvgTimePerFrame / m_dRateSeeking);
+ pSample->SetTime(&rtStart, &rtStop);
- m_rtSampleTime += m_AvgTimePerFrame;
- m_rtPosition += m_AvgTimePerFrame;
+ m_rtSampleTime += m_AvgTimePerFrame;
+ m_rtPosition += m_AvgTimePerFrame;
}
pSample->SetSyncPoint(TRUE);
- if(m_bDiscontinuity)
- {
+ if(m_bDiscontinuity) {
pSample->SetDiscontinuity(TRUE);
m_bDiscontinuity = FALSE;
}
@@ -458,15 +470,19 @@ HRESULT CFLICStream::FillBuffer(IMediaSample* pSample)
HRESULT CFLICStream::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pFilter->pStateLock());
+ CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
- pmt->SetType(&MEDIATYPE_Video);
- pmt->SetSubtype(&MEDIASUBTYPE_RGB32);
- pmt->SetFormatType(&FORMAT_VideoInfo);
- pmt->SetTemporalCompression(TRUE);
+ pmt->SetType(&MEDIATYPE_Video);
+ pmt->SetSubtype(&MEDIASUBTYPE_RGB32);
+ pmt->SetFormatType(&FORMAT_VideoInfo);
+ pmt->SetTemporalCompression(TRUE);
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
memset(vih, 0, sizeof(VIDEOINFOHEADER));
@@ -481,7 +497,7 @@ HRESULT CFLICStream::GetMediaType(int iPosition, CMediaType* pmt)
pmt->SetSampleSize(vih->bmiHeader.biSizeImage);
- return NOERROR;
+ return NOERROR;
}
HRESULT CFLICStream::CheckConnect(IPin* pPin)
@@ -492,8 +508,10 @@ HRESULT CFLICStream::CheckConnect(IPin* pPin)
HRESULT CFLICStream::CheckMediaType(const CMediaType* pmt)
{
if(pmt->majortype == MEDIATYPE_Video
- && pmt->subtype == MEDIASUBTYPE_RGB32
- && pmt->formattype == FORMAT_VideoInfo) return S_OK;
+ && pmt->subtype == MEDIASUBTYPE_RGB32
+ && pmt->formattype == FORMAT_VideoInfo) {
+ return S_OK;
+ }
return E_INVALIDARG;
}
@@ -507,17 +525,19 @@ STDMETHODIMP CFLICStream::Notify(IBaseFilter* pSender, Quality q)
void CFLICStream::SeekToNearestKeyFrame(int nFrame)
{
- if(m_nLastFrameNum == nFrame)
+ if(m_nLastFrameNum == nFrame) {
return;
+ }
- if(m_nLastFrameNum > nFrame)
+ if(m_nLastFrameNum > nFrame) {
m_nLastFrameNum = -1;
+ }
- for(int i = m_nLastFrameNum+1, j = min(m_frames.GetCount(), nFrame); i < j; i++)
- {
+ for(int i = m_nLastFrameNum+1, j = min(m_frames.GetCount(), nFrame); i < j; i++) {
FLIC_FRAME_ENTRY& ffe = m_frames[i];
- if(ffe.fKeyframe)
+ if(ffe.fKeyframe) {
m_nLastFrameNum = i-1;
+ }
}
}
@@ -531,35 +551,55 @@ void CFLICStream::ExtractFrame(int nFrame)
m_flic.Seek(ffe.pos, CFile::begin);
int chunk = 0;
- while(chunk < ffe.hdr.chunks)
- {
+ while(chunk < ffe.hdr.chunks) {
FLIC_CHUNK fc;
- if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc))
+ if(m_flic.Read(&fc, sizeof(fc)) != sizeof(fc)) {
break;
+ }
ULONGLONG next = m_flic.GetPosition() + fc.size - sizeof(fc);
- switch(fc.type)
- {
- case FLIC_64_COLOR: fNewPalette = _colorchunk(true); break;
- case FLIC_256_COLOR: fNewPalette = _colorchunk(false); break;
- case FLIC_BRUN: _brunchunk(); fNewFrame = true; break;
- case FLIC_LC: _lcchunk(); break;
- case FLIC_DELTA: _deltachunk(); break;
- case FLIC_BLACK: _blackchunk(); fNewFrame = true; break;
- case FLIC_COPY: _copychunk(); fNewFrame = true; break;
- case FLIC_MINI: break;
- default: break;
+ switch(fc.type) {
+ case FLIC_64_COLOR:
+ fNewPalette = _colorchunk(true);
+ break;
+ case FLIC_256_COLOR:
+ fNewPalette = _colorchunk(false);
+ break;
+ case FLIC_BRUN:
+ _brunchunk();
+ fNewFrame = true;
+ break;
+ case FLIC_LC:
+ _lcchunk();
+ break;
+ case FLIC_DELTA:
+ _deltachunk();
+ break;
+ case FLIC_BLACK:
+ _blackchunk();
+ fNewFrame = true;
+ break;
+ case FLIC_COPY:
+ _copychunk();
+ fNewFrame = true;
+ break;
+ case FLIC_MINI:
+ break;
+ default:
+ break;
}
- if(m_flic.Seek(next, CFile::begin) != next)
+ if(m_flic.Seek(next, CFile::begin) != next) {
break;
+ }
chunk++;
}
- if(chunk < ffe.hdr.chunks)
+ if(chunk < ffe.hdr.chunks) {
ASSERT(0);
+ }
ffe.fKeyframe = (fNewPalette && fNewFrame);
}
@@ -583,8 +623,7 @@ bool CFLICStream::_colorchunk(bool f64)
WORD packets;
m_flic.Read(&packets, sizeof(packets));
- while(packets--)
- {
+ while(packets--) {
BYTE skip2;
m_flic.Read(&skip2, sizeof(skip2));
skip += skip2;
@@ -593,15 +632,14 @@ bool CFLICStream::_colorchunk(bool f64)
m_flic.Read(&count, sizeof(count));
int len = (count == 0 ? (256-skip) : count);
- while(len-- > 0)
- {
+ while(len-- > 0) {
BYTE r, g, b;
m_flic.Read(&r, sizeof(r));
m_flic.Read(&g, sizeof(g));
m_flic.Read(&b, sizeof(b));
- m_pPalette[skip++] = f64
- ? ((r << 18)&0xff0000) | ((g << 10)&0xff00) | ((b << 2)&0xff)
- : ((r << 16)&0xff0000) | ((g << 8)&0xff00) | ((b << 0)&0xff);
+ m_pPalette[skip++] = f64
+ ? ((r << 18)&0xff0000) | ((g << 10)&0xff00) | ((b << 2)&0xff)
+ : ((r << 16)&0xff0000) | ((g << 8)&0xff00) | ((b << 0)&0xff);
nColorsUpdated++;
}
}
@@ -614,27 +652,22 @@ void CFLICStream::_brunchunk()
BYTE* tmp = m_pFrameBuffer;
int lines = m_hdr.y;
- while(lines--)
- {
+ while(lines--) {
BYTE packets;
m_flic.Read(&packets, sizeof(packets));
-
+
BYTE* ptr = tmp;
- while(ptr < tmp + m_hdr.x)
- {
+ while(ptr < tmp + m_hdr.x) {
signed char count;
m_flic.Read(&count, sizeof(count));
- if(count >= 0)
- {
+ if(count >= 0) {
BYTE c;
m_flic.Read(&c, sizeof(c));
memset(ptr, c, count);
ptr += count;
- }
- else
- {
+ } else {
m_flic.Read(ptr, -count);
ptr += -count;
}
@@ -654,15 +687,13 @@ void CFLICStream::_lcchunk()
WORD lines;
m_flic.Read(&lines, sizeof(lines));
- while(lines--)
- {
+ while(lines--) {
BYTE* ptr = tmp;
BYTE packets;
m_flic.Read(&packets, sizeof(packets));
- while(packets--)
- {
+ while(packets--) {
BYTE skip;
m_flic.Read(&skip, sizeof(skip));
@@ -671,13 +702,10 @@ void CFLICStream::_lcchunk()
signed char count;
m_flic.Read(&count, sizeof(count));
- if(count >= 0)
- {
+ if(count >= 0) {
m_flic.Read(ptr, count);
ptr += count;
- }
- else
- {
+ } else {
BYTE c;
m_flic.Read(&c, sizeof(c));
memset(ptr, c, -count);
@@ -696,31 +724,23 @@ void CFLICStream::_deltachunk()
WORD lines;
m_flic.Read(&lines, sizeof(lines));
- while(lines--)
- {
+ while(lines--) {
signed short packets;
m_flic.Read(&packets, sizeof(packets));
- if(packets < 0)
- {
- if(packets&0x4000)
- {
+ if(packets < 0) {
+ if(packets&0x4000) {
tmp += -packets * m_hdr.x;
lines++;
- }
- else
- {
+ } else {
signed char count;
m_flic.Read(&count, sizeof(count));
tmp[m_hdr.x-1] = (BYTE)packets;
}
- }
- else
- {
+ } else {
BYTE* ptr = tmp;
- while(packets--)
- {
+ while(packets--) {
BYTE skip;
m_flic.Read(&skip, sizeof(skip));
@@ -729,22 +749,19 @@ void CFLICStream::_deltachunk()
signed char count;
m_flic.Read(&count, sizeof(count));
- if(count >= 0)
- {
+ if(count >= 0) {
// Fix vulnerability : http://www.team509.com/modules.php?name=News&file=article&sid=38
- if ((count << 1) + (long)(ptr - m_pFrameBuffer) < m_nBufferSize)
+ if ((count << 1) + (long)(ptr - m_pFrameBuffer) < m_nBufferSize) {
m_flic.Read(ptr, count << 1);
- else
+ } else {
ASSERT(FALSE);
+ }
ptr += count << 1;
- }
- else
- {
+ } else {
WORD c;
m_flic.Read(&c, sizeof(c));
count = -count;
- while(count-- > 0)
- {
+ while(count-- > 0) {
*ptr++ = c>>8;
*ptr++ = c&0xff;
}
diff --git a/src/filters/source/FLICSource/FLICSource.h b/src/filters/source/FLICSource/FLICSource.h
index 5038fb0a6..6df23ec7e 100644
--- a/src/filters/source/FLICSource/FLICSource.h
+++ b/src/filters/source/FLICSource/FLICSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,8 +24,7 @@
#include <atlcoll.h>
#pragma pack(push, 1)
-enum
-{
+enum {
FLIC_256_COLOR = 4,
FLIC_DELTA = 7,
FLIC_64_COLOR = 11,
@@ -35,9 +34,8 @@ enum
FLIC_COPY = 16,
FLIC_MINI = 18
};
-
-struct FLIC
-{
+
+struct FLIC {
DWORD size;
WORD id; // 0xaf11 or 0xaf12
WORD frames, x, y, bpp;
@@ -46,38 +44,34 @@ struct FLIC
BYTE reserved[102];
};
-struct FLIC_PREFIX
-{
+struct FLIC_PREFIX {
DWORD size;
WORD id; // 0xf100
WORD chunks;
BYTE reserved[8];
};
-struct FLIC_FRAME
-{
+struct FLIC_FRAME {
DWORD size;
WORD id; // 0xf1fa
WORD chunks;
BYTE reserved[8];
};
-struct FLIC_CHUNK
-{
+struct FLIC_CHUNK {
DWORD size;
WORD type;
};
#pragma pack(pop)
-struct FLIC_FRAME_ENTRY
-{
+struct FLIC_FRAME_ENTRY {
__int64 pos;
bool fKeyframe;
FLIC_FRAME hdr;
};
class __declspec(uuid("17DB5CF6-39BB-4d5b-B0AA-BEBA44673AD4"))
-CFLICSource
+ CFLICSource
: public CSource
, public IFileSourceFilter
, public IAMFilterMiscFlags
@@ -89,7 +83,7 @@ public:
virtual ~CFLICSource();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
@@ -99,7 +93,7 @@ public:
STDMETHODIMP_(ULONG) GetMiscFlags();
};
-class CFLICStream
+class CFLICStream
: public CSourceStream
, public CSourceSeeking
{
@@ -121,8 +115,10 @@ class CFLICStream
STDMETHODIMP SetRate(double dRate);
HRESULT ChangeStart();
- HRESULT ChangeStop();
- HRESULT ChangeRate() {return S_OK;}
+ HRESULT ChangeStop();
+ HRESULT ChangeRate() {
+ return S_OK;
+ }
private:
int m_nLastFrameNum;
@@ -140,17 +136,17 @@ private:
void _deltachunk();
public:
- CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr);
+ CFLICStream(const WCHAR* wfn, CFLICSource* pParent, HRESULT* phr);
virtual ~CFLICStream();
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT FillBuffer(IMediaSample* pSample);
+ HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT FillBuffer(IMediaSample* pSample);
HRESULT CheckConnect(IPin* pPin);
- HRESULT CheckMediaType(const CMediaType* pMediaType);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
-
+ HRESULT CheckMediaType(const CMediaType* pMediaType);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+
STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
diff --git a/src/filters/source/FLICSource/stdafx.cpp b/src/filters/source/FLICSource/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/source/FLICSource/stdafx.cpp
+++ b/src/filters/source/FLICSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/FLICSource/stdafx.h b/src/filters/source/FLICSource/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/source/FLICSource/stdafx.h
+++ b/src/filters/source/FLICSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/FlacSource/FlacSource.cpp b/src/filters/source/FlacSource/FlacSource.cpp
index ab887a244..ea18dabc2 100644
--- a/src/filters/source/FlacSource/FlacSource.cpp
+++ b/src/filters/source/FlacSource/FlacSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -33,23 +33,19 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_FLAC_FRAMED}
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CFlacSource), L"MPC - Flac Source", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFlacSource>, NULL, &sudFilter[0]}
};
@@ -58,15 +54,15 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
_T("0"), _T("0,4,,664C6143"));
SetRegKeyValue(
- _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
+ _T("Media Type\\{e436eb83-524f-11ce-9f53-0020af0ba770}"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"),
_T("Source Filter"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".flac"),
+ _T("Media Type\\Extensions"), _T(".flac"),
_T("Source Filter"), _T("{1930D8FF-4739-4e42-9199-3B2EDEAA3BF2}"));
return AMovieDllRegisterServer2(TRUE);
@@ -113,7 +109,7 @@ CFlacSource::~CFlacSource()
// CFlacStream
-CFlacStream::CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
+CFlacStream::CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
: CBaseStream(NAME("CFlacStream"), pParent, phr)
, m_bIsEOF (false)
{
@@ -122,42 +118,44 @@ CFlacStream::CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr)
CFileException ex;
HRESULT hr = E_FAIL;
- do
- {
- if(!m_file.Open(fn, CFile::modeRead|CFile::shareDenyNone, &ex))
- {
+ do {
+ if(!m_file.Open(fn, CFile::modeRead|CFile::shareDenyNone, &ex)) {
hr = AmHresultFromWin32 (ex.m_lOsError);
break;
}
m_pDecoder = FLAC__stream_decoder_new();
- if (!m_pDecoder) break;
-
- if (FLAC__STREAM_DECODER_INIT_STATUS_OK != FLAC__stream_decoder_init_stream (_DECODER_,
- StreamDecoderRead,
- StreamDecoderSeek,
- StreamDecoderTell,
- StreamDecoderLength,
- StreamDecoderEof,
- StreamDecoderWrite,
- StreamDecoderMetadata,
- StreamDecoderError,
- this))
- {
+ if (!m_pDecoder) {
+ break;
+ }
+
+ if (FLAC__STREAM_DECODER_INIT_STATUS_OK != FLAC__stream_decoder_init_stream (_DECODER_,
+ StreamDecoderRead,
+ StreamDecoderSeek,
+ StreamDecoderTell,
+ StreamDecoderLength,
+ StreamDecoderEof,
+ StreamDecoderWrite,
+ StreamDecoderMetadata,
+ StreamDecoderError,
+ this)) {
break;
}
if (!FLAC__stream_decoder_process_until_end_of_metadata (_DECODER_) ||
- !FLAC__stream_decoder_seek_absolute (_DECODER_, 0))
+ !FLAC__stream_decoder_seek_absolute (_DECODER_, 0)) {
break;
+ }
FLAC__stream_decoder_get_decode_position(_DECODER_, &m_llOffset);
hr = S_OK;
} while (false);
- if(phr) *phr = hr;
+ if(phr) {
+ *phr = hr;
+ }
}
CFlacStream::~CFlacStream()
@@ -167,21 +165,25 @@ CFlacStream::~CFlacStream()
HRESULT CFlacStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
pProperties->cBuffers = 1;
pProperties->cbBuffer = m_nMaxFrameSize;
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CFlacStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len)
@@ -189,22 +191,24 @@ HRESULT CFlacStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, l
FLAC__uint64 llCurPos;
FLAC__uint64 llNextPos;
- if (m_bDiscontinuity)
- {
+ if (m_bDiscontinuity) {
FLAC__stream_decoder_seek_absolute (_DECODER_, (m_rtPosition * m_i64TotalNumSamples) / m_rtDuration);
}
FLAC__stream_decoder_get_decode_position(_DECODER_, &llCurPos);
-
+
FLAC__stream_decoder_skip_single_frame (_DECODER_);
- if (m_bIsEOF)
+ if (m_bIsEOF) {
return S_FALSE;
+ }
FLAC__stream_decoder_get_decode_position(_DECODER_, &llNextPos);
FLAC__uint64 llCurFile = m_file.GetPosition();
len = llNextPos - llCurPos;
ASSERT (len > 0);
- if (len <= 0) return S_FALSE;
+ if (len <= 0) {
+ return S_FALSE;
+ }
m_file.Seek (llCurPos, CFile::begin);
m_file.Read (pOut, len);
@@ -219,10 +223,9 @@ HRESULT CFlacStream::FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, l
HRESULT CFlacStream::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pFilter->pStateLock());
+ CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition == 0)
- {
+ if(iPosition == 0) {
pmt->majortype = MEDIATYPE_Audio;
pmt->subtype = MEDIASUBTYPE_FLAC_FRAMED;
pmt->formattype = FORMAT_WaveFormatEx;
@@ -235,13 +238,11 @@ HRESULT CFlacStream::GetMediaType(int iPosition, CMediaType* pmt)
wfe->nChannels = m_nChannels;
wfe->nBlockAlign = 1;
wfe->wBitsPerSample = m_wBitsPerSample;
- }
- else
- {
+ } else {
return VFW_S_NO_MORE_ITEMS;
}
- pmt->SetTemporalCompression(FALSE);
+ pmt->SetTemporalCompression(FALSE);
return S_OK;
}
@@ -249,12 +250,13 @@ HRESULT CFlacStream::GetMediaType(int iPosition, CMediaType* pmt)
HRESULT CFlacStream::CheckMediaType(const CMediaType* pmt)
{
if ( pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_FLAC_FRAMED
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_FLAC)
+ && pmt->subtype == MEDIASUBTYPE_FLAC_FRAMED
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_FLAC) {
return S_OK;
- else
+ } else {
return E_INVALIDARG;
+ }
}
@@ -267,7 +269,7 @@ void CFlacStream::UpdateFromMetadata (void* pBuffer)
m_nChannels = pMetadata->data.stream_info.channels;
m_wBitsPerSample = pMetadata->data.stream_info.bits_per_sample;
m_i64TotalNumSamples = pMetadata->data.stream_info.total_samples;
- m_nAvgBytesPerSec = (m_nChannels * (m_wBitsPerSample >> 3)) * m_nSamplesPerSec;
+ m_nAvgBytesPerSec = (m_nChannels * (m_wBitsPerSample >> 3)) * m_nSamplesPerSec;
// === Init members from base classes
GetFileSizeEx (m_file.m_hFile, (LARGE_INTEGER*)&m_llFileSize);
@@ -282,9 +284,9 @@ FLAC__StreamDecoderReadStatus StreamDecoderRead(const FLAC__StreamDecoder *decod
CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
UINT nRead;
- nRead = pThis->GetFile()->Read (buffer, *bytes);
- pThis->m_bIsEOF = (nRead != *bytes);
- *bytes = nRead;
+ nRead = pThis->GetFile()->Read (buffer, *bytes);
+ pThis->m_bIsEOF = (nRead != *bytes);
+ *bytes = nRead;
return (*bytes == 0) ? FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM : FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
@@ -292,7 +294,7 @@ FLAC__StreamDecoderReadStatus StreamDecoderRead(const FLAC__StreamDecoder *decod
FLAC__StreamDecoderSeekStatus StreamDecoderSeek(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
-
+
pThis->m_bIsEOF = false;
pThis->GetFile()->Seek (absolute_byte_offset, CFile::begin);
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
@@ -310,10 +312,9 @@ FLAC__StreamDecoderLengthStatus StreamDecoderLength(const FLAC__StreamDecoder *d
CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
CFile* pFile = pThis->GetFile();
- if (pFile == NULL)
+ if (pFile == NULL) {
return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
- else
- {
+ } else {
*stream_length = pFile->GetLength();
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}
@@ -344,6 +345,7 @@ void StreamDecoderMetadata(const FLAC__StreamDecoder *decoder, const FLAC__Strea
{
CFlacStream* pThis = static_cast<CFlacStream*> (client_data);
- if (pThis)
+ if (pThis) {
pThis->UpdateFromMetadata ((void*)metadata);
+ }
}
diff --git a/src/filters/source/FlacSource/FlacSource.h b/src/filters/source/FlacSource/FlacSource.h
index 9b486bd77..06add98e1 100644
--- a/src/filters/source/FlacSource/FlacSource.h
+++ b/src/filters/source/FlacSource/FlacSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,7 +27,7 @@
class CFlacStream;
class __declspec(uuid("1930D8FF-4739-4e42-9199-3B2EDEAA3BF2"))
-CFlacSource : public CBaseSource<CFlacStream>
+ CFlacSource : public CBaseSource<CFlacStream>
{
public:
CFlacSource(LPUNKNOWN lpunk, HRESULT* phr);
@@ -50,20 +50,22 @@ class CFlacStream : public CBaseStream
int m_nAvgBytesPerSec;
ULONGLONG m_llOffset; // Position of first frame in file
- ULONGLONG m_llFileSize; // Size of the file
+ ULONGLONG m_llFileSize; // Size of the file
public:
- CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr);
+ CFlacStream(const WCHAR* wfn, CSource* pParent, HRESULT* phr);
virtual ~CFlacStream();
- HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len);
-
+ HRESULT FillBuffer(IMediaSample* pSample, int nFrame, BYTE* pOut, long& len);
+
HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT CheckMediaType(const CMediaType* pMediaType);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ HRESULT CheckMediaType(const CMediaType* pMediaType);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
void UpdateFromMetadata (void* pBuffer);
- inline CFile* GetFile() { return &m_file; };
+ inline CFile* GetFile() {
+ return &m_file;
+ };
bool m_bIsEOF;
};
diff --git a/src/filters/source/FlacSource/stdafx.cpp b/src/filters/source/FlacSource/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/source/FlacSource/stdafx.cpp
+++ b/src/filters/source/FlacSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/FlacSource/stdafx.h b/src/filters/source/FlacSource/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/source/FlacSource/stdafx.h
+++ b/src/filters/source/FlacSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/ShoutcastSource/ShoutcastSource.cpp b/src/filters/source/ShoutcastSource/ShoutcastSource.cpp
index 5e5654e66..13a9ca345 100644
--- a/src/filters/source/ShoutcastSource/ShoutcastSource.cpp
+++ b/src/filters/source/ShoutcastSource/ShoutcastSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -31,25 +31,21 @@
#define AVGBUFFERLENGTH 30000000i64
#define MAXBUFFERLENGTH 100000000i64
-static const DWORD s_bitrate[2][16] =
-{
+static const DWORD s_bitrate[2][16] = {
{1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0},
{1,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0}
};
-static const DWORD s_freq[4][4] =
-{
+static const DWORD s_freq[4][4] = {
{11025,12000,8000,0},
{0,0,0,0},
{22050,24000,16000,0},
{44100,48000,32000,0}
};
-static const BYTE s_channels[4] =
-{
+static const BYTE s_channels[4] = {
2,2,2,1 // stereo, joint stereo, dual, mono
};
-typedef struct
-{
+typedef struct {
WORD sync;
BYTE version;
BYTE layer;
@@ -58,11 +54,11 @@ typedef struct
BYTE channels;
DWORD framesize;
- bool ExtractHeader(CSocket& socket)
- {
+ bool ExtractHeader(CSocket& socket) {
BYTE buff[4];
- if(4 != socket.Receive(buff, 4, MSG_PEEK))
+ if(4 != socket.Receive(buff, 4, MSG_PEEK)) {
return(false);
+ }
sync = (buff[0]<<4)|(buff[1]>>4)|1;
version = (buff[1]>>3)&3;
@@ -79,23 +75,19 @@ typedef struct
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_MP3},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CShoutcastSource), L"MPC - ShoutcastSource", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CShoutcastSource>, NULL, &sudFilter[0]}
};
@@ -116,18 +108,18 @@ STDAPI DllUnregisterServer()
class CShoutcastSourceApp : public CFilterApp
{
public:
- BOOL InitInstance()
- {
- if(!__super::InitInstance()) return FALSE;
-/*
- if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
- {
- AfxMessageBox(_T("AfxWinInit failed!"));
+ BOOL InitInstance() {
+ if(!__super::InitInstance()) {
return FALSE;
}
-*/
- if(!AfxSocketInit(NULL))
- {
+ /*
+ if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
+ {
+ AfxMessageBox(_T("AfxWinInit failed!"));
+ return FALSE;
+ }
+ */
+ if(!AfxSocketInit(NULL)) {
AfxMessageBox(_T("AfxSocketInit failed!"));
return FALSE;
}
@@ -158,9 +150,9 @@ CShoutcastSource::~CShoutcastSource()
STDMETHODIMP CShoutcastSource::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
QI(IAMFilterMiscFlags)
QI(IAMOpenProgress)
@@ -170,15 +162,17 @@ STDMETHODIMP CShoutcastSource::NonDelegatingQueryInterface(REFIID riid, void** p
// IFileSourceFilter
-STDMETHODIMP CShoutcastSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CShoutcastSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(GetPinCount() > 0)
+ if(GetPinCount() > 0) {
return VFW_E_ALREADY_CONNECTED;
+ }
HRESULT hr = E_OUTOFMEMORY;
- if(!(DNew CShoutcastStream(pszFileName, this, &hr)) || FAILED(hr))
+ if(!(DNew CShoutcastStream(pszFileName, this, &hr)) || FAILED(hr)) {
return hr;
+ }
m_fn = pszFileName;
@@ -187,11 +181,14 @@ STDMETHODIMP CShoutcastSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE*
STDMETHODIMP CShoutcastSource::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
+
*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR));
- if(!(*ppszFileName))
+ if(!(*ppszFileName)) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -209,10 +206,13 @@ ULONG CShoutcastSource::GetMiscFlags()
STDMETHODIMP CShoutcastSource::QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent)
{
- if(m_iPins == 1)
- {
- if(pllTotal) *pllTotal = 100;
- if(pllCurrent) *pllCurrent = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetBufferFullness();
+ if(m_iPins == 1) {
+ if(pllTotal) {
+ *pllTotal = 100;
+ }
+ if(pllCurrent) {
+ *pllCurrent = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetBufferFullness();
+ }
return S_OK;
}
@@ -230,8 +230,7 @@ STDMETHODIMP CShoutcastSource::get_Title(BSTR* pbstrTitle)
{
CheckPointer(pbstrTitle, E_POINTER);
- if(m_iPins == 1)
- {
+ if(m_iPins == 1) {
*pbstrTitle = (static_cast<CShoutcastStream*>(m_paStreams[0]))->GetTitle().AllocSysString();
return S_OK;
}
@@ -250,40 +249,41 @@ CShoutcastStream::CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent,
*phr = S_OK;
CString fn(wfn);
- if(fn.Find(_T("://")) < 0) fn = _T("http://") + fn;
+ if(fn.Find(_T("://")) < 0) {
+ fn = _T("http://") + fn;
+ }
#if defined(REGISTER_FILTER) && defined(DEBUG)
-//fn = _T("http://localhost:8000/");
-//fn = _T("http://64.236.34.141/stream/1005");
-//fn = _T("http://218.145.30.106:11000"); // 128kbps korean
-//fn = _T("http://65.206.46.110:8020"); // 96kbps
-//fn = _T("http://64.236.34.72:80/stream/1003");
-fn = _T("http://64.236.34.72:80/stream/1011");
-//fn = _T("http://218.145.30.106:11000");
-//fn = _T("http://radio.sluchaj.com:8000/radio.ogg"); // ogg
-// http://www.oddsock.org/icecast2yp/ // more ogg via icecast2
+ //fn = _T("http://localhost:8000/");
+ //fn = _T("http://64.236.34.141/stream/1005");
+ //fn = _T("http://218.145.30.106:11000"); // 128kbps korean
+ //fn = _T("http://65.206.46.110:8020"); // 96kbps
+ //fn = _T("http://64.236.34.72:80/stream/1003");
+ fn = _T("http://64.236.34.72:80/stream/1011");
+ //fn = _T("http://218.145.30.106:11000");
+ //fn = _T("http://radio.sluchaj.com:8000/radio.ogg"); // ogg
+ // http://www.oddsock.org/icecast2yp/ // more ogg via icecast2
#endif
- if(!m_url.CrackUrl(fn))
- {
+ if(!m_url.CrackUrl(fn)) {
*phr = E_FAIL;
return;
}
- if(m_url.GetUrlPathLength() == 0)
+ if(m_url.GetUrlPathLength() == 0) {
m_url.SetUrlPath(_T("/"));
+ }
- if(m_url.GetPortNumber() == ATL_URL_INVALID_PORT_NUMBER)
+ if(m_url.GetPortNumber() == ATL_URL_INVALID_PORT_NUMBER) {
m_url.SetPortNumber(ATL_URL_DEFAULT_HTTP_PORT);
+ }
- if(m_url.GetScheme() != ATL_URL_SCHEME_HTTP)
- {
+ if(m_url.GetScheme() != ATL_URL_SCHEME_HTTP) {
*phr = E_FAIL;
return;
}
- if(!m_socket.Create() || !m_socket.Connect(m_url))
- {
+ if(!m_socket.Create() || !m_socket.Connect(m_url)) {
*phr = E_FAIL;
return;
}
@@ -304,8 +304,12 @@ void CShoutcastStream::EmptyBuffer()
LONGLONG CShoutcastStream::GetBufferFullness()
{
CAutoLock cAutoLock(&m_queue);
- if(!m_fBuffering) return 100;
- if(m_queue.IsEmpty()) return 0;
+ if(!m_fBuffering) {
+ return 100;
+ }
+ if(m_queue.IsEmpty()) {
+ return 0;
+ }
LONGLONG ret = 100i64*(m_queue.GetTail().rtStart - m_queue.GetHead().rtStart) / AVGBUFFERLENGTH;
return(min(ret, 100));
}
@@ -318,21 +322,25 @@ CString CShoutcastStream::GetTitle()
HRESULT CShoutcastStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
pProperties->cBuffers = BUFFERS;
pProperties->cbBuffer = MAXFRAMESIZE;
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CShoutcastStream::FillBuffer(IMediaSample* pSample)
@@ -340,31 +348,33 @@ HRESULT CShoutcastStream::FillBuffer(IMediaSample* pSample)
HRESULT hr;
BYTE* pData = NULL;
- if(FAILED(hr = pSample->GetPointer(&pData)) || !pData)
+ if(FAILED(hr = pSample->GetPointer(&pData)) || !pData) {
return S_FALSE;
+ }
- do
- {
+ do {
// do we have to refill our buffer?
{
CAutoLock cAutoLock(&m_queue);
- if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - MINBUFFERLENGTH)
- break; // nope, that's great
+ if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - MINBUFFERLENGTH) {
+ break; // nope, that's great
+ }
}
TRACE(_T("START BUFFERING\n"));
m_fBuffering = true;
- while(1)
- {
- if(fExitThread) // playback stopped?
+ while(1) {
+ if(fExitThread) { // playback stopped?
return S_FALSE;
+ }
Sleep(50);
CAutoLock cAutoLock(&m_queue);
- if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - AVGBUFFERLENGTH)
- break; // this is enough
+ if(!m_queue.IsEmpty() && m_queue.GetHead().rtStart < m_queue.GetTail().rtStart - AVGBUFFERLENGTH) {
+ break; // this is enough
+ }
}
pSample->SetDiscontinuity(TRUE);
@@ -376,14 +386,12 @@ HRESULT CShoutcastStream::FillBuffer(IMediaSample* pSample)
TRACE(_T("END BUFFERING\n"));
m_fBuffering = false;
- }
- while(false);
+ } while(false);
{
CAutoLock cAutoLock(&m_queue);
ASSERT(!m_queue.IsEmpty());
- if(!m_queue.IsEmpty())
- {
+ if(!m_queue.IsEmpty()) {
mp3frame f = m_queue.RemoveHead();
DWORD len = min(pSample->GetSize(), f.len);
memcpy(pData, f.pData, len);
@@ -400,14 +408,18 @@ HRESULT CShoutcastStream::FillBuffer(IMediaSample* pSample)
HRESULT CShoutcastStream::GetMediaType(int iPosition, CMediaType* pmt)
{
- CAutoLock cAutoLock(m_pFilter->pStateLock());
+ CAutoLock cAutoLock(m_pFilter->pStateLock());
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
- pmt->SetType(&MEDIATYPE_Audio);
- pmt->SetSubtype(&MEDIASUBTYPE_MP3);
- pmt->SetFormatType(&FORMAT_WaveFormatEx);
+ pmt->SetType(&MEDIATYPE_Audio);
+ pmt->SetSubtype(&MEDIASUBTYPE_MP3);
+ pmt->SetFormatType(&FORMAT_WaveFormatEx);
WAVEFORMATEX* wfe = (WAVEFORMATEX*)pmt->AllocFormatBuffer(sizeof(WAVEFORMATEX));
memset(wfe, 0, sizeof(WAVEFORMATEX));
@@ -418,14 +430,16 @@ HRESULT CShoutcastStream::GetMediaType(int iPosition, CMediaType* pmt)
wfe->nBlockAlign = 1;
wfe->wBitsPerSample = 0;
- return NOERROR;
+ return NOERROR;
}
HRESULT CShoutcastStream::CheckMediaType(const CMediaType* pmt)
{
if(pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_MP3
- && pmt->formattype == FORMAT_WaveFormatEx) return S_OK;
+ && pmt->subtype == MEDIASUBTYPE_MP3
+ && pmt->formattype == FORMAT_WaveFormatEx) {
+ return S_OK;
+ }
return E_INVALIDARG;
}
@@ -445,26 +459,28 @@ UINT CShoutcastStream::SocketThreadProc()
CAutoVectorPtr<BYTE> pData;
if(!m_socket.Create() || !m_socket.Connect(m_url)
- || !pData.Allocate(max(m_socket.m_metaint, MAXFRAMESIZE)))
- {
- m_socket.Close();
+ || !pData.Allocate(max(m_socket.m_metaint, MAXFRAMESIZE))) {
+ m_socket.Close();
return 1;
}
REFERENCE_TIME m_rtSampleTime = 0;
-
- while(!fExitThread)
- {
+
+ while(!fExitThread) {
int len = MAXFRAMESIZE;
len = m_socket.Receive(pData, len);
- if(len <= 0) break;
+ if(len <= 0) {
+ break;
+ }
mp3frame f(len);
memcpy(f.pData, pData, len);
f.rtStop = (f.rtStart = m_rtSampleTime) + (10000000i64 * len * 8/m_socket.m_bitrate);
m_rtSampleTime = f.rtStop;
f.title = m_socket.m_title;
- if(f.title.IsEmpty()) f.title = m_socket.m_url;
+ if(f.title.IsEmpty()) {
+ f.title = m_socket.m_url;
+ }
CAutoLock cAutoLock(&m_queue);
m_queue.AddTail(f);
@@ -481,7 +497,9 @@ HRESULT CShoutcastStream::OnThreadCreate()
fExitThread = true;
m_hSocketThread = AfxBeginThread(::SocketThreadProc, this)->m_hThread;
- while(fExitThread) Sleep(10);
+ while(fExitThread) {
+ Sleep(10);
+ }
return NOERROR;
}
@@ -489,7 +507,7 @@ HRESULT CShoutcastStream::OnThreadCreate()
HRESULT CShoutcastStream::OnThreadDestroy()
{
EmptyBuffer();
-
+
fExitThread = true;
m_socket.CancelBlockingCall();
WaitForSingleObject(m_hSocketThread, (DWORD)-1);
@@ -507,81 +525,84 @@ HRESULT CShoutcastStream::Inactive()
int CShoutcastStream::CShoutcastSocket::Receive(void* lpBuf, int nBufLen, int nFlags)
{
- if(nFlags&MSG_PEEK)
+ if(nFlags&MSG_PEEK) {
return __super::Receive(lpBuf, nBufLen, nFlags);
+ }
- if(m_metaint > 0 && m_nBytesRead + nBufLen > m_metaint)
+ if(m_metaint > 0 && m_nBytesRead + nBufLen > m_metaint) {
nBufLen = m_metaint - m_nBytesRead;
+ }
int len = __super::Receive(lpBuf, nBufLen, nFlags);
- if(len <= 0) return len;
+ if(len <= 0) {
+ return len;
+ }
- if((m_nBytesRead += len) == m_metaint)
- {
+ if((m_nBytesRead += len) == m_metaint) {
m_nBytesRead = 0;
static BYTE buff[255*16], b = 0;
memset(buff, 0, sizeof(buff));
- if(1 == __super::Receive(&b, 1) && b && b*16 == __super::Receive(buff, b*16))
- {
+ if(1 == __super::Receive(&b, 1) && b && b*16 == __super::Receive(buff, b*16)) {
CStringA str = (LPCSTR)buff;
-
+
TRACE(_T("Metainfo: %s\n"), CString(str));
CStringA title("StreamTitle='"), url("StreamUrl='");
-
+
int i = str.Find(title);
- if(i >= 0)
- {
+ if(i >= 0) {
i += title.GetLength();
int j = str.Find('\'', i);
- if(j > i) m_title = str.Mid(i, j - i);
- }
- else
- {
+ if(j > i) {
+ m_title = str.Mid(i, j - i);
+ }
+ } else {
TRACE(_T("!!!!!!!!!Missing StreamTitle!!!!!!!!!\n"));
}
i = str.Find(url);
- if(i >= 0)
- {
+ if(i >= 0) {
i += url.GetLength();
int j = str.Find('\'', i);
- if(j > i) m_url = str.Mid(i, j - i);
+ if(j > i) {
+ m_url = str.Mid(i, j - i);
+ }
}
}
- }
- else if(m_metaint > 0)
- {
+ } else if(m_metaint > 0) {
char* p = (char*)lpBuf;
char* p0 = p;
char* pend = p + len - 13;
- for(; p < pend; p++)
- {
- if(strncmp(p, "StreamTitle='", 13))
+ for(; p < pend; p++) {
+ if(strncmp(p, "StreamTitle='", 13)) {
continue;
+ }
-TRACE(_T("!!!!!!!!!StreamTitle found inside mp3 data!!!!!!!!! offset=%d\n"), p - p0);
-TRACE(_T("resyncing...\n"));
- while(p-- > p0)
- {
- if((BYTE)*p >= 0x20)
+ TRACE(_T("!!!!!!!!!StreamTitle found inside mp3 data!!!!!!!!! offset=%d\n"), p - p0);
+ TRACE(_T("resyncing...\n"));
+ while(p-- > p0) {
+ if((BYTE)*p >= 0x20) {
continue;
+ }
-TRACE(_T("found possible length byte: %d, skipping %d bytes\n"), *p, 1 + *p*16);
+ TRACE(_T("found possible length byte: %d, skipping %d bytes\n"), *p, 1 + *p*16);
p += 1 + *p*16;
len = (p0 + len) - p;
-TRACE(_T("returning the remaining bytes in the packet: %d\n"), len);
- if(len <= 0)
- {
-TRACE(_T("nothing to return, reading a bit more in\n"));
- if(len < 0) __super::Receive(lpBuf, -len, nFlags);
+ TRACE(_T("returning the remaining bytes in the packet: %d\n"), len);
+ if(len <= 0) {
+ TRACE(_T("nothing to return, reading a bit more in\n"));
+ if(len < 0) {
+ __super::Receive(lpBuf, -len, nFlags);
+ }
int len = __super::Receive(lpBuf, nBufLen, nFlags);
- if(len <= 0) return len;
+ if(len <= 0) {
+ return len;
+ }
}
-
- m_nBytesRead = len;
+
+ m_nBytesRead = len;
memcpy(lpBuf, p, len);
break;
@@ -596,8 +617,9 @@ TRACE(_T("nothing to return, reading a bit more in\n"));
bool CShoutcastStream::CShoutcastSocket::Connect(CUrl& url)
{
- if(!__super::Connect(url.GetHostName(), url.GetPortNumber()))
+ if(!__super::Connect(url.GetHostName(), url.GetPortNumber())) {
return(false);
+ }
CStringA str;
str.Format(
@@ -613,8 +635,7 @@ bool CShoutcastStream::CShoutcastSocket::Connect(CUrl& url)
bool fTryAgain = false;
int metaint = 0;
- do
- {
+ do {
int len = Send((BYTE*)(LPCSTR)str, str.GetLength());
UNUSED_ALWAYS(len);
@@ -624,21 +645,22 @@ bool CShoutcastStream::CShoutcastSocket::Connect(CUrl& url)
str.Empty();
BYTE cur = 0, prev = 0;
- while(Receive(&cur, 1) == 1 && cur && !(cur == '\n' && prev == '\n'))
- {
- if(cur == '\r')
+ while(Receive(&cur, 1) == 1 && cur && !(cur == '\n' && prev == '\n')) {
+ if(cur == '\r') {
continue;
+ }
- if(cur == '\n')
- {
+ if(cur == '\n') {
str.MakeLower();
- if(str.Find("icy 200 ok") >= 0) fOK = true;
- else if(1 == sscanf(str, "icy-br:%d", &m_bitrate)) m_bitrate *= 1000;
- else if(1 == sscanf(str, "icy-metaint:%d", &metaint)) metaint = metaint;
+ if(str.Find("icy 200 ok") >= 0) {
+ fOK = true;
+ } else if(1 == sscanf(str, "icy-br:%d", &m_bitrate)) {
+ m_bitrate *= 1000;
+ } else if(1 == sscanf(str, "icy-metaint:%d", &metaint)) {
+ metaint = metaint;
+ }
str.Empty();
- }
- else
- {
+ } else {
str += cur;
}
@@ -646,8 +668,7 @@ bool CShoutcastStream::CShoutcastSocket::Connect(CUrl& url)
cur = 0;
}
- if(!fOK && GetLastError() == WSAECONNRESET && !fTryAgain)
- {
+ if(!fOK && GetLastError() == WSAECONNRESET && !fTryAgain) {
str.Format(
"GET %s HTTP/1.0\r\n"
"Icy-MetaData:1\r\n"
@@ -657,15 +678,15 @@ bool CShoutcastStream::CShoutcastSocket::Connect(CUrl& url)
"\r\n", CStringA(url.GetUrlPath()), CStringA(url.GetHostName()));
fTryAgain = true;
- }
- else
- {
+ } else {
fTryAgain = false;
}
- }
- while(fTryAgain);
+ } while(fTryAgain);
- if(!fOK || m_bitrate == 0) {Close(); return(false);}
+ if(!fOK || m_bitrate == 0) {
+ Close();
+ return(false);
+ }
m_metaint = metaint;
m_nBytesRead = 0;
@@ -679,12 +700,12 @@ bool CShoutcastStream::CShoutcastSocket::FindSync()
m_channels = (DWORD)-1;
BYTE b;
- for(int i = MAXFRAMESIZE; i > 0; i--, Receive(&b, 1))
- {
+ for(int i = MAXFRAMESIZE; i > 0; i--, Receive(&b, 1)) {
mp3hdr h;
- if(h.ExtractHeader(*this) && m_bitrate == h.bitrate)
- {
- if(h.bitrate > 1) m_bitrate = h.bitrate;
+ if(h.ExtractHeader(*this) && m_bitrate == h.bitrate) {
+ if(h.bitrate > 1) {
+ m_bitrate = h.bitrate;
+ }
m_freq = h.freq;
m_channels = h.channels;
return(true);
diff --git a/src/filters/source/ShoutcastSource/ShoutcastSource.h b/src/filters/source/ShoutcastSource/ShoutcastSource.h
index 2c6a9e752..3e873955c 100644
--- a/src/filters/source/ShoutcastSource/ShoutcastSource.h
+++ b/src/filters/source/ShoutcastSource/ShoutcastSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -28,7 +28,7 @@
#include <qnetwork.h>
class __declspec(uuid("68F540E9-766F-44d2-AB07-E26CC6D27A79"))
-CShoutcastSource
+ CShoutcastSource
: public CSource
, public IFileSourceFilter
, public IAMFilterMiscFlags
@@ -42,7 +42,7 @@ public:
virtual ~CShoutcastSource();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
@@ -52,27 +52,59 @@ public:
STDMETHODIMP_(ULONG) GetMiscFlags();
// IAMOpenProgress
- STDMETHODIMP QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent);
- STDMETHODIMP AbortOperation();
+ STDMETHODIMP QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent);
+ STDMETHODIMP AbortOperation();
// IAMMediaContent
- STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;}
- STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {return E_NOTIMPL;}
- STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {return E_NOTIMPL;}
- STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {return E_NOTIMPL;}
- STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName) {return E_NOTIMPL;}
+ STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName) {
+ return E_NOTIMPL;
+ }
STDMETHODIMP get_Title(BSTR* pbstrTitle);
- STDMETHODIMP get_Rating(BSTR* pbstrRating) {return E_NOTIMPL;}
- STDMETHODIMP get_Description(BSTR* pbstrDescription) {return E_NOTIMPL;}
- STDMETHODIMP get_Copyright(BSTR* pbstrCopyright) {return E_NOTIMPL;}
- STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {return E_NOTIMPL;}
- STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {return E_NOTIMPL;}
- STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {return E_NOTIMPL;}
+ STDMETHODIMP get_Rating(BSTR* pbstrRating) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Description(BSTR* pbstrDescription) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_Copyright(BSTR* pbstrCopyright) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {
+ return E_NOTIMPL;
+ }
};
class CShoutcastStream : public CSourceStream
@@ -84,13 +116,19 @@ class CShoutcastStream : public CSourceStream
BYTE* pData;
REFERENCE_TIME rtStart, rtStop;
CString title;
- mp3frame(DWORD len = 0) {this->len = len; pData = len ? DNew BYTE[len] : NULL; rtStart = rtStop = 0;}
- mp3frame(const mp3frame& f) {*this = f;}
- ~mp3frame() {delete pData;}
- mp3frame& operator = (const mp3frame& f)
- {
- if(this != &f)
- {
+ mp3frame(DWORD len = 0) {
+ this->len = len;
+ pData = len ? DNew BYTE[len] : NULL;
+ rtStart = rtStop = 0;
+ }
+ mp3frame(const mp3frame& f) {
+ *this = f;
+ }
+ ~mp3frame() {
+ delete pData;
+ }
+ mp3frame& operator = (const mp3frame& f) {
+ if(this != &f) {
len = f.len;
pData = f.pData;
rtStart = f.rtStart;
@@ -109,7 +147,9 @@ class CShoutcastStream : public CSourceStream
DWORD m_nBytesRead;
public:
- CShoutcastSocket() {m_metaint = m_bitrate = m_freq = m_channels = 0;}
+ CShoutcastSocket() {
+ m_metaint = m_bitrate = m_freq = m_channels = 0;
+ }
int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
DWORD m_metaint, m_bitrate, m_freq, m_channels;
@@ -126,7 +166,7 @@ class CShoutcastStream : public CSourceStream
CString m_title;
public:
- CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent, HRESULT* phr);
+ CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent, HRESULT* phr);
virtual ~CShoutcastStream();
bool fExitThread;
@@ -136,15 +176,17 @@ public:
LONGLONG GetBufferFullness();
CString GetTitle();
- HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT FillBuffer(IMediaSample* pSample);
- HRESULT CheckMediaType(const CMediaType* pMediaType);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT FillBuffer(IMediaSample* pSample);
+ HRESULT CheckMediaType(const CMediaType* pMediaType);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- STDMETHODIMP Notify(IBaseFilter* pSender, Quality q) {return E_NOTIMPL;}
+ STDMETHODIMP Notify(IBaseFilter* pSender, Quality q) {
+ return E_NOTIMPL;
+ }
- HRESULT OnThreadCreate();
- HRESULT OnThreadDestroy();
+ HRESULT OnThreadCreate();
+ HRESULT OnThreadDestroy();
HRESULT Inactive();
- HRESULT Pause();
+ HRESULT Pause();
};
diff --git a/src/filters/source/ShoutcastSource/stdafx.cpp b/src/filters/source/ShoutcastSource/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/source/ShoutcastSource/stdafx.cpp
+++ b/src/filters/source/ShoutcastSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/ShoutcastSource/stdafx.h b/src/filters/source/ShoutcastSource/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/source/ShoutcastSource/stdafx.h
+++ b/src/filters/source/ShoutcastSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/SubtitleSource/SubtitleSource.cpp b/src/filters/source/SubtitleSource/SubtitleSource.cpp
index b470268a9..8bd54eb70 100644
--- a/src/filters/source/SubtitleSource/SubtitleSource.cpp
+++ b/src/filters/source/SubtitleSource/SubtitleSource.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -32,20 +32,17 @@ static int _ATPF = 400000;
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Subtitle, &MEDIASUBTYPE_NULL},
{&MEDIATYPE_Text, &MEDIASUBTYPE_NULL},
{&MEDIATYPE_Video, &MEDIASUBTYPE_RGB32},
};
-const AMOVIESETUP_PIN sudOpPin[] =
-{
+const AMOVIESETUP_PIN sudOpPin[] = {
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut},
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CSubtitleSourceASCII), L"MPC - SubtitleSource (S_TEXT/ASCII)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
{&__uuidof(CSubtitleSourceUTF8), L"MPC - SubtitleSource (S_TEXT/UTF8)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
{&__uuidof(CSubtitleSourceSSA), L"MPC - SubtitleSource (S_TEXT/SSA)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
@@ -55,13 +52,12 @@ const AMOVIESETUP_FILTER sudFilter[] =
{&__uuidof(CSubtitleSourceARGB), L"MPC - SubtitleSource (ARGB)", MERIT_NORMAL, countof(sudOpPin), sudOpPin, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CSubtitleSourceASCII>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CSubtitleSourceUTF8>, NULL, &sudFilter[1]},
{sudFilter[2].strName, sudFilter[2].clsID, CreateInstance<CSubtitleSourceSSA>, NULL, &sudFilter[2]},
{sudFilter[3].strName, sudFilter[3].clsID, CreateInstance<CSubtitleSourceASS>, NULL, &sudFilter[3]},
-// {sudFilter[4].strName, sudFilter[4].clsID, CreateInstance<CSubtitleSourceUSF>, NULL, &sudFilter[4]},
+ // {sudFilter[4].strName, sudFilter[4].clsID, CreateInstance<CSubtitleSourceUSF>, NULL, &sudFilter[4]},
{sudFilter[5].strName, sudFilter[5].clsID, CreateInstance<CSubtitleSourcePreview>, NULL, &sudFilter[5]},
{sudFilter[6].strName, sudFilter[6].clsID, CreateInstance<CSubtitleSourceARGB>, NULL, &sudFilter[6]},
};
@@ -70,37 +66,37 @@ int g_cTemplates = countof(g_Templates);
STDAPI DllRegisterServer()
{
-/*
- CString clsid = CStringFromGUID(__uuidof(CSubtitleSourcePreview));
+ /*
+ CString clsid = CStringFromGUID(__uuidof(CSubtitleSourcePreview));
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".sub"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".sub"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".srt"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".srt"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".smi"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".smi"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ssa"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ssa"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".ass"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".ass"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".xss"),
- _T("Source Filter"), clsid);
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".xss"),
+ _T("Source Filter"), clsid);
- SetRegKeyValue(
- _T("Media Type\\Extensions"), _T(".usf"),
- _T("Source Filter"), clsid);
-*/
+ SetRegKeyValue(
+ _T("Media Type\\Extensions"), _T(".usf"),
+ _T("Source Filter"), clsid);
+ */
return AMovieDllRegisterServer2(TRUE);
}
@@ -113,7 +109,7 @@ STDAPI DllUnregisterServer()
DeleteRegKey(_T("Media Type\\Extensions"), _T(".ass"));
DeleteRegKey(_T("Media Type\\Extensions"), _T(".xss"));
DeleteRegKey(_T("Media Type\\Extensions"), _T(".usf"));
-/**/
+ /**/
return AMovieDllRegisterServer2(FALSE);
}
@@ -122,14 +118,17 @@ STDAPI DllUnregisterServer()
class CSubtitleSourceApp : public CFilterApp
{
public:
- BOOL InitInstance()
- {
- if(!__super::InitInstance()) return FALSE;
+ BOOL InitInstance() {
+ if(!__super::InitInstance()) {
+ return FALSE;
+ }
_WIDTH = GetProfileInt(_T("SubtitleSource"), _T("w"), 640);
_HEIGHT = GetProfileInt(_T("SubtitleSource"), _T("h"), 480);
_ATPF = GetProfileInt(_T("SubtitleSource"), _T("atpf"), 400000);
- if(_ATPF <= 0) _ATPF = 400000;
+ if(_ATPF <= 0) {
+ _ATPF = 400000;
+ }
WriteProfileInt(_T("SubtitleSource"), _T("w"), _WIDTH);
WriteProfileInt(_T("SubtitleSource"), _T("h"), _HEIGHT);
WriteProfileInt(_T("SubtitleSource"), _T("atpf"), _ATPF);
@@ -157,9 +156,9 @@ CSubtitleSource::~CSubtitleSource()
STDMETHODIMP CSubtitleSource::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
- return
+ return
QI(IFileSourceFilter)
QI(IAMFilterMiscFlags)
__super::NonDelegatingQueryInterface(riid, ppv);
@@ -167,17 +166,20 @@ STDMETHODIMP CSubtitleSource::NonDelegatingQueryInterface(REFIID riid, void** pp
// IFileSourceFilter
-STDMETHODIMP CSubtitleSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
+STDMETHODIMP CSubtitleSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt)
{
- if(GetPinCount() > 0)
+ if(GetPinCount() > 0) {
return VFW_E_ALREADY_CONNECTED;
+ }
HRESULT hr = S_OK;
- if(!(DNew CSubtitleStream(pszFileName, this, &hr)))
+ if(!(DNew CSubtitleStream(pszFileName, this, &hr))) {
return E_OUTOFMEMORY;
+ }
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
m_fn = pszFileName;
@@ -186,10 +188,13 @@ STDMETHODIMP CSubtitleSource::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* p
STDMETHODIMP CSubtitleSource::GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt)
{
- if(!ppszFileName) return E_POINTER;
-
- if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR))))
+ if(!ppszFileName) {
+ return E_POINTER;
+ }
+
+ if(!(*ppszFileName = (LPOLESTR)CoTaskMemAlloc((m_fn.GetLength()+1)*sizeof(WCHAR)))) {
return E_OUTOFMEMORY;
+ }
wcscpy(*ppszFileName, m_fn);
@@ -207,7 +212,7 @@ ULONG CSubtitleSource::GetMiscFlags()
// CSubtitleStream
//
-CSubtitleStream::CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr)
+CSubtitleStream::CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr)
: CSourceStream(NAME("SubtitleStream"), phr, pParent, L"Output")
, CSourceSeeking(NAME("SubtitleStream"), (IPin*)this, phr, &m_cSharedState)
, m_bDiscontinuity(FALSE), m_bFlushing(FALSE)
@@ -218,9 +223,10 @@ CSubtitleStream::CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRE
CString fn(wfn);
- if(!m_rts.Open(fn, DEFAULT_CHARSET))
- {
- if(phr) *phr = E_FAIL;
+ if(!m_rts.Open(fn, DEFAULT_CHARSET)) {
+ if(phr) {
+ *phr = E_FAIL;
+ }
return;
}
@@ -229,12 +235,15 @@ CSubtitleStream::CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRE
m_rts.Sort();
m_rtDuration = 0;
- for(int i = 0, cnt = m_rts.GetCount(); i < cnt; i++)
+ for(int i = 0, cnt = m_rts.GetCount(); i < cnt; i++) {
m_rtDuration = max(m_rtDuration, 10000i64*m_rts[i].end);
+ }
m_rtStop = m_rtDuration;
- if(phr) *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ if(phr) {
+ *phr = m_rtDuration > 0 ? S_OK : E_FAIL;
+ }
}
CSubtitleStream::~CSubtitleStream()
@@ -244,21 +253,20 @@ CSubtitleStream::~CSubtitleStream()
STDMETHODIMP CSubtitleStream::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
+ CheckPointer(ppv, E_POINTER);
return (riid == IID_IMediaSeeking) ? CSourceSeeking::NonDelegatingQueryInterface(riid, ppv) //GetInterface((IMediaSeeking*)this, ppv)
- : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
+ : CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
void CSubtitleStream::UpdateFromSeek()
{
- if(ThreadExists())
- {
+ if(ThreadExists()) {
// next time around the loop, the worker thread will
// pick up the position change.
// We need to flush all the existing data - we must do that here
// as our thread will probably be blocked in GetBuffer otherwise
-
+
m_bFlushing = TRUE;
DeliverBeginFlush();
@@ -267,7 +275,7 @@ void CSubtitleStream::UpdateFromSeek()
// complete the flush
DeliverEndFlush();
- m_bFlushing = FALSE;
+ m_bFlushing = FALSE;
// restart
Run();
@@ -276,8 +284,9 @@ void CSubtitleStream::UpdateFromSeek()
HRESULT CSubtitleStream::SetRate(double dRate)
{
- if(dRate <= 0)
+ if(dRate <= 0) {
return E_INVALIDARG;
+ }
{
CAutoLock lock(CSourceSeeking::m_pLock);
@@ -291,106 +300,107 @@ HRESULT CSubtitleStream::SetRate(double dRate)
HRESULT CSubtitleStream::OnThreadStartPlay()
{
- m_bDiscontinuity = TRUE;
- return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
+ m_bDiscontinuity = TRUE;
+ return DeliverNewSegment(m_rtStart, m_rtStop, m_dRateSeeking);
}
HRESULT CSubtitleStream::ChangeStart()
{
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
OnThreadCreate();
-/*
- if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
- {
- m_nPosition = (int)(m_rtStart/10000)*1/1000;
- }
- else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
- {
- int m_nSegments = 0;
- if(!m_rts.SearchSubs((int)(m_rtStart/10000), 25, &m_nPosition, &m_nSegments))
- m_nPosition = m_nSegments;
- }
- else
- {
- m_nPosition = m_rts.SearchSub((int)(m_rtStart/10000), 25);
- if(m_nPosition < 0) m_nPosition = 0;
- else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) m_nPosition++;
- }
-*/ }
+ /*
+ if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
+ {
+ m_nPosition = (int)(m_rtStart/10000)*1/1000;
+ }
+ else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
+ {
+ int m_nSegments = 0;
+ if(!m_rts.SearchSubs((int)(m_rtStart/10000), 25, &m_nPosition, &m_nSegments))
+ m_nPosition = m_nSegments;
+ }
+ else
+ {
+ m_nPosition = m_rts.SearchSub((int)(m_rtStart/10000), 25);
+ if(m_nPosition < 0) m_nPosition = 0;
+ else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) m_nPosition++;
+ }
+ */
+ }
- UpdateFromSeek();
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CSubtitleStream::ChangeStop()
{
-/*
- {
- CAutoLock lock(CSourceSeeking::m_pLock);
- if(m_rtPosition < m_rtStop)
- return S_OK;
- }
-*/
- // We're already past the new stop time -- better flush the graph.
- UpdateFromSeek();
+ /*
+ {
+ CAutoLock lock(CSourceSeeking::m_pLock);
+ if(m_rtPosition < m_rtStop)
+ return S_OK;
+ }
+ */
+ // We're already past the new stop time -- better flush the graph.
+ UpdateFromSeek();
- return S_OK;
+ return S_OK;
}
HRESULT CSubtitleStream::OnThreadCreate()
{
- CAutoLock cAutoLockShared(&m_cSharedState);
+ CAutoLock cAutoLockShared(&m_cSharedState);
- if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
- {
+ if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32) {
m_nPosition = m_rtStart/_ATPF;
- }
- else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32) {
int m_nSegments = 0;
- if(!m_rts.SearchSubs((int)(m_rtStart/10000), 10000000/_ATPF, &m_nPosition, &m_nSegments))
+ if(!m_rts.SearchSubs((int)(m_rtStart/10000), 10000000/_ATPF, &m_nPosition, &m_nSegments)) {
m_nPosition = m_nSegments;
- }
- else
- {
+ }
+ } else {
m_nPosition = m_rts.SearchSub((int)(m_rtStart/10000), 25);
- if(m_nPosition < 0) m_nPosition = 0;
- else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) m_nPosition++;
+ if(m_nPosition < 0) {
+ m_nPosition = 0;
+ } else if(m_rts[m_nPosition].end <= (int)(m_rtStart/10000)) {
+ m_nPosition++;
+ }
}
- return CSourceStream::OnThreadCreate();
+ return CSourceStream::OnThreadCreate();
}
HRESULT CSubtitleStream::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
-// CAutoLock cAutoLock(m_pFilter->pStateLock());
+ // CAutoLock cAutoLock(m_pFilter->pStateLock());
- ASSERT(pAlloc);
- ASSERT(pProperties);
+ ASSERT(pAlloc);
+ ASSERT(pProperties);
- HRESULT hr = NOERROR;
+ HRESULT hr = NOERROR;
- if(m_mt.majortype == MEDIATYPE_Video)
- {
+ if(m_mt.majortype == MEDIATYPE_Video) {
pProperties->cBuffers = 2;
pProperties->cbBuffer = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader.biSizeImage;
- }
- else
- {
+ } else {
pProperties->cBuffers = 1;
pProperties->cbBuffer = 0x10000;
}
- ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ ALLOCATOR_PROPERTIES Actual;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
- ASSERT(Actual.cBuffers == pProperties->cBuffers);
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
+ ASSERT(Actual.cBuffers == pProperties->cBuffers);
- return NOERROR;
+ return NOERROR;
}
HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
@@ -401,12 +411,12 @@ HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
CAutoLock cAutoLockShared(&m_cSharedState);
BYTE* pData = NULL;
- if(FAILED(hr = pSample->GetPointer(&pData)) || !pData)
+ if(FAILED(hr = pSample->GetPointer(&pData)) || !pData) {
return S_FALSE;
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
SetMediaType(&mt);
DeleteMediaType(pmt);
@@ -415,12 +425,12 @@ HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
int len = 0;
REFERENCE_TIME rtStart, rtStop;
- if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32)
- {
+ if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_ARGB32) {
rtStart = (REFERENCE_TIME)((m_nPosition*_ATPF - m_rtStart) / m_dRateSeeking);
rtStop = (REFERENCE_TIME)(((m_nPosition+1)*_ATPF - m_rtStart) / m_dRateSeeking);
- if(m_rtStart+rtStart >= m_rtDuration)
+ if(m_rtStart+rtStart >= m_rtDuration) {
return S_FALSE;
+ }
BITMAPINFOHEADER& bmi = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader;
@@ -433,23 +443,24 @@ HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
len = spd.h*spd.pitch;
- for(int y = 0; y < spd.h; y++)
+ for(int y = 0; y < spd.h; y++) {
memsetd((DWORD*)(pData + spd.pitch*y), 0xff000000, spd.w*4);
+ }
RECT bbox;
m_rts.Render(spd, m_nPosition*_ATPF, 10000000.0/_ATPF, bbox);
- for(int y = 0; y < spd.h; y++)
- {
+ for(int y = 0; y < spd.h; y++) {
DWORD* p = (DWORD*)(pData + spd.pitch*y);
- for(int x = 0; x < spd.w; x++, p++)
+ for(int x = 0; x < spd.w; x++, p++) {
*p = (0xff000000-(*p&0xff000000))|(*p&0xffffff);
+ }
}
- }
- else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Video && m_mt.subtype == MEDIASUBTYPE_RGB32) {
const STSSegment* stss = m_rts.GetSegment(m_nPosition);
- if(!stss) return S_FALSE;
+ if(!stss) {
+ return S_FALSE;
+ }
BITMAPINFOHEADER& bmi = ((VIDEOINFOHEADER*)m_mt.pbFormat)->bmiHeader;
@@ -462,13 +473,15 @@ HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
len = spd.h*spd.pitch;
- for(int y = 0; y < spd.h; y++)
- {
+ for(int y = 0; y < spd.h; y++) {
DWORD c1 = 0xff606060, c2 = 0xffa0a0a0;
- if(y&32) c1 ^= c2, c2 ^= c1, c1 ^= c2;
+ if(y&32) {
+ c1 ^= c2, c2 ^= c1, c1 ^= c2;
+ }
DWORD* p = (DWORD*)(pData + spd.pitch*y);
- for(int x = 0; x < spd.w; x+=32, p+=32)
+ for(int x = 0; x < spd.w; x+=32, p+=32) {
memsetd(p, (x&32) ? c1 : c2, min(spd.w-x,32)*4);
+ }
}
RECT bbox;
@@ -476,40 +489,33 @@ HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
rtStart = (REFERENCE_TIME)((10000i64*stss->start - m_rtStart) / m_dRateSeeking);
rtStop = (REFERENCE_TIME)((10000i64*stss->end - m_rtStart) / m_dRateSeeking);
- }
- else
- {
- if(m_nPosition >= m_rts.GetCount())
+ } else {
+ if(m_nPosition >= m_rts.GetCount()) {
return S_FALSE;
+ }
STSEntry& stse = m_rts[m_nPosition];
- if(stse.start >= m_rtStop/10000)
+ if(stse.start >= m_rtStop/10000) {
return S_FALSE;
+ }
- if(m_mt.majortype == MEDIATYPE_Subtitle && m_mt.subtype == MEDIASUBTYPE_UTF8)
- {
+ if(m_mt.majortype == MEDIATYPE_Subtitle && m_mt.subtype == MEDIASUBTYPE_UTF8) {
CStringA str = UTF16To8(m_rts.GetStrW(m_nPosition, false));
memcpy((char*)pData, str, len = str.GetLength());
- }
- else if(m_mt.majortype == MEDIATYPE_Subtitle && (m_mt.subtype == MEDIASUBTYPE_SSA || m_mt.subtype == MEDIASUBTYPE_ASS))
- {
+ } else if(m_mt.majortype == MEDIATYPE_Subtitle && (m_mt.subtype == MEDIASUBTYPE_SSA || m_mt.subtype == MEDIASUBTYPE_ASS)) {
CStringW line;
- line.Format(L"%d,%d,%s,%s,%d,%d,%d,%s,%s",
- stse.readorder, stse.layer, CStringW(stse.style), CStringW(stse.actor),
- stse.marginRect.left, stse.marginRect.right, (stse.marginRect.top+stse.marginRect.bottom)/2,
- CStringW(stse.effect), m_rts.GetStrW(m_nPosition, true));
+ line.Format(L"%d,%d,%s,%s,%d,%d,%d,%s,%s",
+ stse.readorder, stse.layer, CStringW(stse.style), CStringW(stse.actor),
+ stse.marginRect.left, stse.marginRect.right, (stse.marginRect.top+stse.marginRect.bottom)/2,
+ CStringW(stse.effect), m_rts.GetStrW(m_nPosition, true));
CStringA str = UTF16To8(line);
memcpy((char*)pData, str, len = str.GetLength());
- }
- else if(m_mt.majortype == MEDIATYPE_Text && m_mt.subtype == MEDIASUBTYPE_NULL)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Text && m_mt.subtype == MEDIASUBTYPE_NULL) {
CStringA str = m_rts.GetStrA(m_nPosition, false);
memcpy((char*)pData, str, len = str.GetLength());
- }
- else
- {
+ } else {
return S_FALSE;
}
@@ -525,8 +531,7 @@ HRESULT CSubtitleStream::FillBuffer(IMediaSample* pSample)
pSample->SetSyncPoint(TRUE);
- if(m_bDiscontinuity)
- {
+ if(m_bDiscontinuity) {
pSample->SetDiscontinuity(TRUE);
m_bDiscontinuity = FALSE;
}
@@ -541,17 +546,16 @@ HRESULT CSubtitleStream::GetMediaType(CMediaType* pmt)
HRESULT CSubtitleStream::CheckMediaType(const CMediaType* pmt)
{
- CAutoLock lock(m_pFilter->pStateLock());
+ CAutoLock lock(m_pFilter->pStateLock());
- CMediaType mt;
- GetMediaType(&mt);
+ CMediaType mt;
+ GetMediaType(&mt);
- if(mt.majortype == pmt->majortype && mt.subtype == pmt->subtype)
- {
- return NOERROR;
- }
+ if(mt.majortype == pmt->majortype && mt.subtype == pmt->subtype) {
+ return NOERROR;
+ }
- return E_FAIL;
+ return E_FAIL;
}
STDMETHODIMP CSubtitleStream::Notify(IBaseFilter* pSender, Quality q)
@@ -570,7 +574,7 @@ CSubtitleSourceASCII::CSubtitleSourceASCII(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourceASCII::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Text);
@@ -578,7 +582,7 @@ HRESULT CSubtitleSourceASCII::GetMediaType(CMediaType* pmt)
pmt->SetFormatType(&FORMAT_None);
pmt->ResetFormatBuffer();
- return NOERROR;
+ return NOERROR;
}
//
@@ -592,7 +596,7 @@ CSubtitleSourceUTF8::CSubtitleSourceUTF8(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourceUTF8::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Subtitle);
@@ -602,7 +606,7 @@ HRESULT CSubtitleSourceUTF8::GetMediaType(CMediaType* pmt)
memset(psi, 0, pmt->FormatLength());
strcpy(psi->IsoLang, "eng");
- return NOERROR;
+ return NOERROR;
}
//
@@ -616,7 +620,7 @@ CSubtitleSourceSSA::CSubtitleSourceSSA(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourceSSA::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Subtitle);
@@ -629,15 +633,17 @@ HRESULT CSubtitleSourceSSA::GetMediaType(CMediaType* pmt)
CFile f;
TCHAR path[_MAX_PATH], fn[_MAX_PATH];
- if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn))
+ if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn)) {
return E_FAIL;
+ }
_tremove(fn);
_tcscat(fn, _T(".ssa"));
- if(!sts.SaveAs(fn, EXTSSA, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead))
+ if(!sts.SaveAs(fn, EXTSSA, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead)) {
return E_FAIL;
+ }
int len = (int)f.GetLength()-3;
f.Seek(3, CFile::begin);
@@ -651,7 +657,7 @@ HRESULT CSubtitleSourceSSA::GetMediaType(CMediaType* pmt)
_tremove(fn);
- return NOERROR;
+ return NOERROR;
}
//
@@ -665,7 +671,7 @@ CSubtitleSourceASS::CSubtitleSourceASS(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourceASS::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Subtitle);
@@ -678,15 +684,17 @@ HRESULT CSubtitleSourceASS::GetMediaType(CMediaType* pmt)
CFile f;
TCHAR path[_MAX_PATH], fn[_MAX_PATH];
- if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn))
+ if(!GetTempPath(MAX_PATH, path) || !GetTempFileName(path, _T("mpc_sts"), 0, fn)) {
return E_FAIL;
+ }
_tremove(fn);
_tcscat(fn, _T(".ass"));
- if(!sts.SaveAs(fn, EXTASS, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead))
+ if(!sts.SaveAs(fn, EXTASS, -1, CTextFile::UTF8) || !f.Open(fn, CFile::modeRead)) {
return E_FAIL;
+ }
int len = (int)f.GetLength();
@@ -699,7 +707,7 @@ HRESULT CSubtitleSourceASS::GetMediaType(CMediaType* pmt)
_tremove(fn);
- return NOERROR;
+ return NOERROR;
}
//
@@ -713,7 +721,7 @@ CSubtitleSourceUSF::CSubtitleSourceUSF(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourceUSF::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Subtitle);
@@ -724,7 +732,7 @@ HRESULT CSubtitleSourceUSF::GetMediaType(CMediaType* pmt)
strcpy(psi->IsoLang, "eng");
// TODO: ...
- return NOERROR;
+ return NOERROR;
}
//
@@ -738,7 +746,7 @@ CSubtitleSourcePreview::CSubtitleSourcePreview(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourcePreview::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Video);
@@ -754,7 +762,7 @@ HRESULT CSubtitleSourcePreview::GetMediaType(CMediaType* pmt)
pvih->bmiHeader.biPlanes = 1;
pvih->bmiHeader.biSizeImage = pvih->bmiHeader.biWidth*abs(pvih->bmiHeader.biHeight)*pvih->bmiHeader.biBitCount>>3;
- return NOERROR;
+ return NOERROR;
}
//
@@ -768,7 +776,7 @@ CSubtitleSourceARGB::CSubtitleSourceARGB(LPUNKNOWN lpunk, HRESULT* phr)
HRESULT CSubtitleSourceARGB::GetMediaType(CMediaType* pmt)
{
- CAutoLock cAutoLock(pStateLock());
+ CAutoLock cAutoLock(pStateLock());
pmt->InitMediaType();
pmt->SetType(&MEDIATYPE_Video);
@@ -785,5 +793,5 @@ HRESULT CSubtitleSourceARGB::GetMediaType(CMediaType* pmt)
pvih->bmiHeader.biPlanes = 1;
pvih->bmiHeader.biSizeImage = pvih->bmiHeader.biWidth*abs(pvih->bmiHeader.biHeight)*pvih->bmiHeader.biBitCount>>3;
- return NOERROR;
+ return NOERROR;
}
diff --git a/src/filters/source/SubtitleSource/SubtitleSource.h b/src/filters/source/SubtitleSource/SubtitleSource.h
index 459db7b6a..071a13e4a 100644
--- a/src/filters/source/SubtitleSource/SubtitleSource.h
+++ b/src/filters/source/SubtitleSource/SubtitleSource.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -37,7 +37,7 @@ public:
virtual ~CSubtitleSource();
DECLARE_IUNKNOWN;
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
@@ -46,10 +46,10 @@ public:
// IAMFilterMiscFlags
STDMETHODIMP_(ULONG) GetMiscFlags();
- virtual HRESULT GetMediaType(CMediaType* pmt) = 0;
+ virtual HRESULT GetMediaType(CMediaType* pmt) = 0;
};
-class CSubtitleStream
+class CSubtitleStream
: public CSourceStream
, public CSourceSeeking
{
@@ -66,28 +66,30 @@ class CSubtitleStream
STDMETHODIMP SetRate(double dRate);
HRESULT ChangeStart();
- HRESULT ChangeStop();
- HRESULT ChangeRate() {return S_OK;}
+ HRESULT ChangeStop();
+ HRESULT ChangeRate() {
+ return S_OK;
+ }
protected:
CRenderedTextSubtitle m_rts;
public:
- CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr);
+ CSubtitleStream(const WCHAR* wfn, CSubtitleSource* pParent, HRESULT* phr);
virtual ~CSubtitleStream();
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT FillBuffer(IMediaSample* pSample);
- HRESULT GetMediaType(CMediaType* pmt);
+ HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT FillBuffer(IMediaSample* pSample);
+ HRESULT GetMediaType(CMediaType* pmt);
HRESULT CheckMediaType(const CMediaType* pmt);
STDMETHODIMP Notify(IBaseFilter* pSender, Quality q);
};
class __declspec(uuid("E44CA3B5-A0FF-41A0-AF16-42429B1095EA"))
-CSubtitleSourceASCII : public CSubtitleSource
+ CSubtitleSourceASCII : public CSubtitleSource
{
public:
CSubtitleSourceASCII(LPUNKNOWN lpunk, HRESULT* phr);
@@ -96,7 +98,7 @@ public:
};
class __declspec(uuid("87864E0F-7073-4E39-B802-143DE0ED4964"))
-CSubtitleSourceUTF8 : public CSubtitleSource
+ CSubtitleSourceUTF8 : public CSubtitleSource
{
public:
CSubtitleSourceUTF8(LPUNKNOWN lpunk, HRESULT* phr);
@@ -105,7 +107,7 @@ public:
};
class __declspec(uuid("18316B1A-5877-4CC4-85FD-EDE65CD489EC"))
-CSubtitleSourceSSA : public CSubtitleSource
+ CSubtitleSourceSSA : public CSubtitleSource
{
public:
CSubtitleSourceSSA(LPUNKNOWN lpunk, HRESULT* phr);
@@ -114,7 +116,7 @@ public:
};
class __declspec(uuid("416782BC-1D87-48C0-8F65-F113A5CB8E15"))
-CSubtitleSourceASS : public CSubtitleSource
+ CSubtitleSourceASS : public CSubtitleSource
{
public:
CSubtitleSourceASS(LPUNKNOWN lpunk, HRESULT* phr);
@@ -123,7 +125,7 @@ public:
};
class __declspec(uuid("D7215AFC-DFE6-483B-9AF3-6BBECFF14CF4"))
-CSubtitleSourceUSF : public CSubtitleSource
+ CSubtitleSourceUSF : public CSubtitleSource
{
public:
CSubtitleSourceUSF(LPUNKNOWN lpunk, HRESULT* phr);
@@ -132,7 +134,7 @@ public:
};
class __declspec(uuid("932E75D4-BBD4-4A0F-9071-6728FBDC4C98"))
-CSubtitleSourcePreview : public CSubtitleSource
+ CSubtitleSourcePreview : public CSubtitleSource
{
public:
CSubtitleSourcePreview(LPUNKNOWN lpunk, HRESULT* phr);
@@ -141,7 +143,7 @@ public:
};
class __declspec(uuid("CF0D7280-527D-415E-BA02-56017484D73E"))
-CSubtitleSourceARGB : public CSubtitleSource
+ CSubtitleSourceARGB : public CSubtitleSource
{
public:
CSubtitleSourceARGB(LPUNKNOWN lpunk, HRESULT* phr);
diff --git a/src/filters/source/SubtitleSource/stdafx.cpp b/src/filters/source/SubtitleSource/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/source/SubtitleSource/stdafx.cpp
+++ b/src/filters/source/SubtitleSource/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/source/SubtitleSource/stdafx.h b/src/filters/source/SubtitleSource/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/source/SubtitleSource/stdafx.h
+++ b/src/filters/source/SubtitleSource/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/switcher/AudioSwitcher/Audio.cpp b/src/filters/switcher/AudioSwitcher/Audio.cpp
index 055c01668..a163816c1 100644
--- a/src/filters/switcher/AudioSwitcher/Audio.cpp
+++ b/src/filters/switcher/AudioSwitcher/Audio.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,7 +24,8 @@
#include "stdafx.h"
#include "Audio.h"
-static long audio_pointsample_8(void *dst, void *src, long accum, long samp_frac, long cnt) {
+static long audio_pointsample_8(void *dst, void *src, long accum, long samp_frac, long cnt)
+{
unsigned char *d = (unsigned char *)dst;
unsigned char *s = (unsigned char *)src;
@@ -36,7 +37,8 @@ static long audio_pointsample_8(void *dst, void *src, long accum, long samp_frac
return accum;
}
-static long audio_pointsample_16(void *dst, void *src, long accum, long samp_frac, long cnt) {
+static long audio_pointsample_16(void *dst, void *src, long accum, long samp_frac, long cnt)
+{
unsigned short *d = (unsigned short *)dst;
unsigned short *s = (unsigned short *)src;
@@ -48,7 +50,8 @@ static long audio_pointsample_16(void *dst, void *src, long accum, long samp_fra
return accum;
}
-static long audio_pointsample_32(void *dst, void *src, long accum, long samp_frac, long cnt) {
+static long audio_pointsample_32(void *dst, void *src, long accum, long samp_frac, long cnt)
+{
unsigned long *d = (unsigned long *)dst;
unsigned long *s = (unsigned long *)src;
@@ -60,7 +63,8 @@ static long audio_pointsample_32(void *dst, void *src, long accum, long samp_fra
return accum;
}
-static long audio_downsample_mono8(void *dst, void *src, long *filter_bank, int filter_width, long accum, long samp_frac, long cnt) {
+static long audio_downsample_mono8(void *dst, void *src, long *filter_bank, int filter_width, long accum, long samp_frac, long cnt)
+{
unsigned char *d = (unsigned char *)dst;
unsigned char *s = (unsigned char *)src;
@@ -77,12 +81,13 @@ static long audio_downsample_mono8(void *dst, void *src, long *filter_bank, int
sum += *fb_ptr++ * (int)*s_ptr++;
} while(--w);
- if (sum < 0)
+ if (sum < 0) {
*d++ = 0;
- else if (sum > 0x3fffff)
+ } else if (sum > 0x3fffff) {
*d++ = 0xff;
- else
+ } else {
*d++ = ((sum + 0x2000)>>14);
+ }
accum += samp_frac;
} while(--cnt);
@@ -90,7 +95,8 @@ static long audio_downsample_mono8(void *dst, void *src, long *filter_bank, int
return accum;
}
-static long audio_downsample_mono16(void *dst, void *src, long *filter_bank, int filter_width, long accum, long samp_frac, long cnt) {
+static long audio_downsample_mono16(void *dst, void *src, long *filter_bank, int filter_width, long accum, long samp_frac, long cnt)
+{
signed short *d = (signed short *)dst;
signed short *s = (signed short *)src;
@@ -107,12 +113,13 @@ static long audio_downsample_mono16(void *dst, void *src, long *filter_bank, int
sum += *fb_ptr++ * (int)*s_ptr++;
} while(--w);
- if (sum < -0x20000000)
+ if (sum < -0x20000000) {
*d++ = -0x8000;
- else if (sum > 0x1fffffff)
+ } else if (sum > 0x1fffffff) {
*d++ = 0x7fff;
- else
+ } else {
*d++ = ((sum + 0x2000)>>14);
+ }
accum += samp_frac;
} while(--cnt);
@@ -121,11 +128,13 @@ static long audio_downsample_mono16(void *dst, void *src, long *filter_bank, int
}
-static int permute_index(int a, int b) {
+static int permute_index(int a, int b)
+{
return (b-(a>>8)-1) + (a&255)*b;
}
-static void make_downsample_filter(long *filter_bank, int filter_width, long samp_frac) {
+static void make_downsample_filter(long *filter_bank, int filter_width, long samp_frac)
+{
int i, j, v;
double filt_max;
double filtwidth_frac;
@@ -140,29 +149,32 @@ static void make_downsample_filter(long *filter_bank, int filter_width, long sam
int y = 0;
double d = i / filtwidth_frac;
- if (d<1.0)
+ if (d<1.0) {
y = (int)(0.5 + filt_max*(1.0 - d));
+ }
filter_bank[permute_index(128*filter_width + i, filter_width)]
- = filter_bank[permute_index(128*filter_width - i, filter_width)]
- = y;
+ = filter_bank[permute_index(128*filter_width - i, filter_width)]
+ = y;
}
// Normalize the filter to correct for integer roundoff errors
for(i=0; i<256*filter_width; i+=filter_width) {
v=0;
- for(j=0; j<filter_width; j++)
+ for(j=0; j<filter_width; j++) {
v += filter_bank[i+j];
+ }
-// _RPT2(0,"error[%02x] = %04x\n", i/filter_width, 0x4000 - v);
+ // _RPT2(0,"error[%02x] = %04x\n", i/filter_width, 0x4000 - v);
v = (0x4000 - v)/filter_width;
- for(j=0; j<filter_width; j++)
+ for(j=0; j<filter_width; j++) {
filter_bank[i+j] += v;
+ }
}
-// _CrtCheckMemory();
+ // _CrtCheckMemory();
}
AudioStreamResampler::AudioStreamResampler(int bps, long org_rate, long new_rate, bool fHighQuality)
@@ -171,22 +183,17 @@ AudioStreamResampler::AudioStreamResampler(int bps, long org_rate, long new_rate
this->bps = bps;
- if(bps == 1)
- {
+ if(bps == 1) {
ptsampleRout = audio_pointsample_8;
dnsampleRout = audio_downsample_mono8;
- }
- else if(bps >= 2)
- {
+ } else if(bps >= 2) {
ptsampleRout = audio_pointsample_16;
dnsampleRout = audio_downsample_mono16;
- }
- else
- {
+ } else {
return;
}
-// org_rate > new_rate!
+ // org_rate > new_rate!
samp_frac = MulDiv(org_rate, 0x80000, new_rate);
holdover = 0;
@@ -196,17 +203,14 @@ AudioStreamResampler::AudioStreamResampler(int bps, long org_rate, long new_rate
// If this is a high-quality downsample, allocate memory for the filter bank
- if(fHighQuality)
- {
- if(samp_frac>0x80000)
- {
+ if(fHighQuality) {
+ if(samp_frac>0x80000) {
// HQ downsample: allocate filter bank
filter_width = ((samp_frac + 0x7ffff)>>19)<<1 <<1;
filter_bank = DNew long[filter_width * 256];
- if(!filter_bank)
- {
+ if(!filter_bank) {
filter_width = 1;
return;
}
@@ -236,8 +240,7 @@ long AudioStreamResampler::Downsample(void* input, long samplesin, void* output,
//
// We need (n/2) points to the left and (n/2-1) points to the right.
- while(samplesin > 0 && samplesout > 0)
- {
+ while(samplesin > 0 && samplesout > 0) {
long srcSamples, dstSamples;
int nhold;
@@ -251,13 +254,16 @@ long AudioStreamResampler::Downsample(void* input, long samplesin, void* output,
// Don't exceed the buffer (BUFFER_SIZE - holdover).
- if(srcSamples > BUFFER_SIZE - holdover)
+ if(srcSamples > BUFFER_SIZE - holdover) {
srcSamples = BUFFER_SIZE - holdover;
+ }
// Read into buffer.
srcSamples = min(srcSamples, samplesin);
- if(!srcSamples) break;
+ if(!srcSamples) {
+ break;
+ }
memcpy((char*)cbuffer + holdover*bps, (char*)input, srcSamples*bps);
input = (void *)((char *)input + srcSamples*bps);
@@ -269,15 +275,16 @@ long AudioStreamResampler::Downsample(void* input, long samplesin, void* output,
dstSamples = (((__int64)(srcSamples+holdover-filter_width)<<19) + 0x7ffff - accum) / samp_frac + 1;
- if(dstSamples > samplesout)
+ if(dstSamples > samplesout) {
dstSamples = samplesout;
+ }
- if(dstSamples >= 1)
- {
- if(filter_bank)
+ if(dstSamples >= 1) {
+ if(filter_bank) {
accum = dnsampleRout(output, cbuffer, filter_bank, filter_width, accum, samp_frac, dstSamples);
- else
+ } else {
accum = ptsampleRout(output, cbuffer, accum, samp_frac, dstSamples);
+ }
output = (void *)((char *)output + bps * dstSamples);
lActualSamples += dstSamples;
@@ -297,16 +304,17 @@ long AudioStreamResampler::Downsample(void* input, long samplesin, void* output,
nhold = - (accum>>19);
-// _ASSERT(nhold<=(filter_width/2));
+ // _ASSERT(nhold<=(filter_width/2));
if (nhold>0) {
memmove(cbuffer, (char *)cbuffer+bps*(srcSamples+holdover-nhold), bps*nhold);
holdover = nhold;
accum += nhold<<19;
- } else
+ } else {
holdover = 0;
+ }
-// _ASSERT(accum>=0);
+ // _ASSERT(accum>=0);
}
int Bytes = lActualSamples * bps;
diff --git a/src/filters/switcher/AudioSwitcher/Audio.h b/src/filters/switcher/AudioSwitcher/Audio.h
index df032796f..5cb098ed0 100644
--- a/src/filters/switcher/AudioSwitcher/Audio.h
+++ b/src/filters/switcher/AudioSwitcher/Audio.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -29,7 +29,7 @@
typedef long (*AudioPointSampler)(void *, void *, long, long, long);
typedef long (*AudioDownSampler)(void *, void *, long *, int, long, long, long);
-class AudioStreamResampler
+class AudioStreamResampler
{
private:
AudioPointSampler ptsampleRout;
diff --git a/src/filters/switcher/AudioSwitcher/AudioSwitcher.cpp b/src/filters/switcher/AudioSwitcher/AudioSwitcher.cpp
index d49e6f4c2..db50246d1 100644
--- a/src/filters/switcher/AudioSwitcher/AudioSwitcher.cpp
+++ b/src/filters/switcher/AudioSwitcher/AudioSwitcher.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -37,30 +37,25 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_NULL}
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_NULL}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CAudioSwitcherFilter), L"MPC - AudioSwitcher", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CAudioSwitcherFilter>, NULL, &sudFilter[0]}
+CFactoryTemplate g_Templates[] = {
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CAudioSwitcherFilter>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
@@ -99,10 +94,12 @@ CAudioSwitcherFilter::CAudioSwitcherFilter(LPUNKNOWN lpunk, HRESULT* phr)
{
memset(m_pSpeakerToChannelMap, 0, sizeof(m_pSpeakerToChannelMap));
- if(phr)
- {
- if(FAILED(*phr)) return;
- else *phr = S_OK;
+ if(phr) {
+ if(FAILED(*phr)) {
+ return;
+ } else {
+ *phr = S_OK;
+ }
}
}
@@ -116,9 +113,10 @@ STDMETHODIMP CAudioSwitcherFilter::NonDelegatingQueryInterface(REFIID riid, void
HRESULT CAudioSwitcherFilter::CheckMediaType(const CMediaType* pmt)
{
if(pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->nChannels > 2
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag != WAVE_FORMAT_EXTENSIBLE)
- return VFW_E_INVALIDMEDIATYPE; // stupid iviaudio tries to fool us
+ && ((WAVEFORMATEX*)pmt->pbFormat)->nChannels > 2
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
+ return VFW_E_INVALIDMEDIATYPE; // stupid iviaudio tries to fool us
+ }
return (pmt->majortype == MEDIATYPE_Audio
&& pmt->formattype == FORMAT_WaveFormatEx
@@ -130,38 +128,37 @@ HRESULT CAudioSwitcherFilter::CheckMediaType(const CMediaType* pmt)
|| ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_IEEE_FLOAT
|| ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3_SPDIF
|| ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_EXTENSIBLE))
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
-template<class T, class U, int Umin, int Umax>
+template<class T, class U, int Umin, int Umax>
__forceinline void mix(DWORD mask, int ch, int bps, BYTE* src, BYTE* dst)
{
U sum = 0;
- for(int i = 0, j = ch; i < j; i++)
- {
- if(mask & (1<<i))
- {
+ for(int i = 0, j = ch; i < j; i++) {
+ if(mask & (1<<i)) {
sum += *(T*)&src[bps*i];
}
}
- if(sum < Umin) sum = Umin;
- else if(sum > Umax) sum = Umax;
-
+ if(sum < Umin) {
+ sum = Umin;
+ } else if(sum > Umax) {
+ sum = Umax;
+ }
+
*(T*)dst = (T)sum;
}
-template<>
+template<>
__forceinline void mix<int, INT64, (-1<<24), (+1<<24)-1>(DWORD mask, int ch, int bps, BYTE* src, BYTE* dst)
{
INT64 sum = 0;
- for(int i = 0, j = ch; i < j; i++)
- {
- if(mask & (1<<i))
- {
+ for(int i = 0, j = ch; i < j; i++) {
+ if(mask & (1<<i)) {
int tmp;
memcpy((BYTE*)&tmp+1, &src[bps*i], 3);
sum += tmp >> 8;
@@ -173,31 +170,30 @@ __forceinline void mix<int, INT64, (-1<<24), (+1<<24)-1>(DWORD mask, int ch, int
memcpy(dst, (BYTE*)&sum, 3);
}
-template<class T, class U, int Umin, int Umax>
+template<class T, class U, int Umin, int Umax>
__forceinline void mix4(DWORD mask, BYTE* src, BYTE* dst)
{
U sum = 0;
int bps = sizeof T;
- if(mask & (1<<0))
- {
+ if(mask & (1<<0)) {
sum += *(T*)&src[bps*0];
}
- if(mask & (1<<1))
- {
+ if(mask & (1<<1)) {
sum += *(T*)&src[bps*1];
}
- if(mask & (1<<2))
- {
+ if(mask & (1<<2)) {
sum += *(T*)&src[bps*2];
}
- if(mask & (1<<3))
- {
+ if(mask & (1<<3)) {
sum += *(T*)&src[bps*3];
}
- if(sum < Umin) sum = Umin;
- else if(sum > Umax) sum = Umax;
+ if(sum < Umin) {
+ sum = Umin;
+ } else if(sum > Umax) {
+ sum = Umax;
+ }
*(T*)dst = (T)sum;
}
@@ -205,11 +201,17 @@ __forceinline void mix4(DWORD mask, BYTE* src, BYTE* dst)
template<class T>
T clamp(double s, T smin, T smax)
{
- if(s < -1) s = -1;
- else if(s > 1) s = 1;
+ if(s < -1) {
+ s = -1;
+ } else if(s > 1) {
+ s = 1;
+ }
T t = (T)(s * smax);
- if(t < smin) t = smin;
- else if(t > smax) t = smax;
+ if(t < smin) {
+ t = smin;
+ } else if(t > smax) {
+ t = smax;
+ }
return t;
}
@@ -217,8 +219,9 @@ HRESULT CAudioSwitcherFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
{
CStreamSwitcherInputPin* pInPin = GetInputPin();
CStreamSwitcherOutputPin* pOutPin = GetOutputPin();
- if(!pInPin || !pOutPin)
+ if(!pInPin || !pOutPin) {
return __super::Transform(pIn, pOut);
+ }
WAVEFORMATEX* wfe = (WAVEFORMATEX*)pInPin->CurrentMediaType().pbFormat;
WAVEFORMATEX* wfeout = (WAVEFORMATEX*)pOutPin->CurrentMediaType().pbFormat;
@@ -230,17 +233,14 @@ HRESULT CAudioSwitcherFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
int lenout = (UINT64)len * wfeout->nSamplesPerSec / wfe->nSamplesPerSec;
REFERENCE_TIME rtStart, rtStop;
- if(SUCCEEDED(pIn->GetTime(&rtStart, &rtStop)))
- {
+ if(SUCCEEDED(pIn->GetTime(&rtStart, &rtStop))) {
rtStart += m_rtAudioTimeShift;
rtStop += m_rtAudioTimeShift;
pOut->SetTime(&rtStart, &rtStop);
m_rtNextStart = rtStart;
m_rtNextStop = rtStop;
- }
- else
- {
+ } else {
pOut->SetTime(&m_rtNextStart, &m_rtNextStop);
}
@@ -249,34 +249,41 @@ HRESULT CAudioSwitcherFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
m_rtNextStart += rtDur;
m_rtNextStop += rtDur;
- if(pIn->IsDiscontinuity() == S_OK)
- {
+ if(pIn->IsDiscontinuity() == S_OK) {
m_sample_max = 0.1f;
}
WORD tag = wfe->wFormatTag;
bool fPCM = tag == WAVE_FORMAT_PCM || tag == WAVE_FORMAT_EXTENSIBLE && wfex->SubFormat == KSDATAFORMAT_SUBTYPE_PCM;
bool fFloat = tag == WAVE_FORMAT_IEEE_FLOAT || tag == WAVE_FORMAT_EXTENSIBLE && wfex->SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
- if(!fPCM && !fFloat) return __super::Transform(pIn, pOut);
+ if(!fPCM && !fFloat) {
+ return __super::Transform(pIn, pOut);
+ }
BYTE* pDataIn = NULL;
BYTE* pDataOut = NULL;
HRESULT hr;
- if(FAILED(hr = pIn->GetPointer(&pDataIn))) return hr;
- if(FAILED(hr = pOut->GetPointer(&pDataOut))) return hr;
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
+ return hr;
+ }
+ if(FAILED(hr = pOut->GetPointer(&pDataOut))) {
+ return hr;
+ }
- if(!pDataIn || !pDataOut || len < 0 || lenout < 0) return S_FALSE;
+ if(!pDataIn || !pDataOut || len < 0 || lenout < 0) {
+ return S_FALSE;
+ }
// len = 0 doesn't mean it's failed, return S_OK otherwise might screw the sound
- if(len == 0) {pOut->SetActualDataLength(0); return S_OK;}
+ if(len == 0) {
+ pOut->SetActualDataLength(0);
+ return S_OK;
+ }
- if(m_fCustomChannelMapping)
- {
+ if(m_fCustomChannelMapping) {
size_t channelsCount = m_chs[wfe->nChannels-1].GetCount();
- if(channelsCount > 0 && wfeout->nChannels <= channelsCount)
- {
- for(int i = 0; i < wfeout->nChannels; i++)
- {
+ if(channelsCount > 0 && wfeout->nChannels <= channelsCount) {
+ for(int i = 0; i < wfeout->nChannels; i++) {
DWORD mask = m_chs[wfe->nChannels-1][i].Channel;
BYTE* src = pDataIn;
@@ -285,147 +292,144 @@ HRESULT CAudioSwitcherFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
int srcstep = bps*wfe->nChannels;
int dststep = bps*wfeout->nChannels;
int channels = min(18, wfe->nChannels);
- if(fPCM && wfe->wBitsPerSample == 8)
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ if(fPCM && wfe->wBitsPerSample == 8) {
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix<unsigned char, INT64, 0, UCHAR_MAX>(mask, channels, bps, src, dst);
}
- }
- else if(fPCM && wfe->wBitsPerSample == 16)
- {
- if (wfe->nChannels != 4 || wfeout->nChannels != 4)
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ } else if(fPCM && wfe->wBitsPerSample == 16) {
+ if (wfe->nChannels != 4 || wfeout->nChannels != 4) {
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix<short, INT64, SHRT_MIN, SHRT_MAX>(mask, channels, bps, src, dst);
}
- }
- else // most popular channels count
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ } else { // most popular channels count
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix4<short, INT64, SHRT_MIN, SHRT_MAX>(mask, src, dst);
}
}
- }
- else if(fPCM && wfe->wBitsPerSample == 24)
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ } else if(fPCM && wfe->wBitsPerSample == 24) {
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix<int, INT64, (-1<<24), (+1<<24)-1>(mask, channels, bps, src, dst);
}
- }
- else if(fPCM && wfe->wBitsPerSample == 32)
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ } else if(fPCM && wfe->wBitsPerSample == 32) {
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix<int, __int64, INT_MIN, INT_MAX>(mask, channels, bps, src, dst);
}
- }
- else if(fFloat && wfe->wBitsPerSample == 32)
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ } else if(fFloat && wfe->wBitsPerSample == 32) {
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix<float, double, -1, 1>(mask, channels, bps, src, dst);
}
- }
- else if(fFloat && wfe->wBitsPerSample == 64)
- {
- for(int k = 0; k < len; k++, src += srcstep, dst += dststep)
- {
+ } else if(fFloat && wfe->wBitsPerSample == 64) {
+ for(int k = 0; k < len; k++, src += srcstep, dst += dststep) {
mix<double, double, -1, 1>(mask, channels, bps, src, dst);
}
}
}
- }
- else
- {
+ } else {
BYTE* pDataOut = NULL;
HRESULT hr;
- if(FAILED(hr = pOut->GetPointer(&pDataOut)) || !pDataOut) return hr;
+ if(FAILED(hr = pOut->GetPointer(&pDataOut)) || !pDataOut) {
+ return hr;
+ }
memset(pDataOut, 0, pOut->GetSize());
}
- }
- else
- {
+ } else {
HRESULT hr;
- if(S_OK != (hr = __super::Transform(pIn, pOut)))
+ if(S_OK != (hr = __super::Transform(pIn, pOut))) {
return hr;
+ }
}
if(m_fDownSampleTo441
- && wfe->nSamplesPerSec > 44100 && wfeout->nSamplesPerSec == 44100
- && wfe->wBitsPerSample <= 16 && fPCM)
- {
- if(BYTE* buff = DNew BYTE[len*bps])
- {
- for(int ch = 0; ch < wfeout->nChannels; ch++)
- {
+ && wfe->nSamplesPerSec > 44100 && wfeout->nSamplesPerSec == 44100
+ && wfe->wBitsPerSample <= 16 && fPCM) {
+ if(BYTE* buff = DNew BYTE[len*bps]) {
+ for(int ch = 0; ch < wfeout->nChannels; ch++) {
memset(buff, 0, len*bps);
- for(int i = 0; i < len; i++)
+ for(int i = 0; i < len; i++) {
memcpy(buff + i*bps, (char*)pDataOut + (ch + i*wfeout->nChannels)*bps, bps);
+ }
m_pResamplers[ch]->Downsample(buff, len, buff, lenout);
- for(int i = 0; i < lenout; i++)
+ for(int i = 0; i < lenout; i++) {
memcpy((char*)pDataOut + (ch + i*wfeout->nChannels)*bps, buff + i*bps, bps);
+ }
}
delete [] buff;
}
}
- if(m_fNormalize || m_boost_mul > 1)
- {
+ if(m_fNormalize || m_boost_mul > 1) {
int samples = lenout*wfeout->nChannels;
- if(double* buff = DNew double[samples])
- {
- for(int i = 0; i < samples; i++)
- {
- if(fPCM && wfe->wBitsPerSample == 8) buff[i] = (double)((BYTE*)pDataOut)[i] / UCHAR_MAX;
- else if(fPCM && wfe->wBitsPerSample == 16) buff[i] = (double)((short*)pDataOut)[i] / SHRT_MAX;
- else if(fPCM && wfe->wBitsPerSample == 24) {int tmp; memcpy(((BYTE*)&tmp)+1, &pDataOut[i*3], 3); buff[i] = (float)(tmp >> 8) / ((1<<23)-1);}
- else if(fPCM && wfe->wBitsPerSample == 32) buff[i] = (double)((int*)pDataOut)[i] / INT_MAX;
- else if(fFloat && wfe->wBitsPerSample == 32) buff[i] = (double)((float*)pDataOut)[i];
- else if(fFloat && wfe->wBitsPerSample == 64) buff[i] = ((double*)pDataOut)[i];
+ if(double* buff = DNew double[samples]) {
+ for(int i = 0; i < samples; i++) {
+ if(fPCM && wfe->wBitsPerSample == 8) {
+ buff[i] = (double)((BYTE*)pDataOut)[i] / UCHAR_MAX;
+ } else if(fPCM && wfe->wBitsPerSample == 16) {
+ buff[i] = (double)((short*)pDataOut)[i] / SHRT_MAX;
+ } else if(fPCM && wfe->wBitsPerSample == 24) {
+ int tmp;
+ memcpy(((BYTE*)&tmp)+1, &pDataOut[i*3], 3);
+ buff[i] = (float)(tmp >> 8) / ((1<<23)-1);
+ } else if(fPCM && wfe->wBitsPerSample == 32) {
+ buff[i] = (double)((int*)pDataOut)[i] / INT_MAX;
+ } else if(fFloat && wfe->wBitsPerSample == 32) {
+ buff[i] = (double)((float*)pDataOut)[i];
+ } else if(fFloat && wfe->wBitsPerSample == 64) {
+ buff[i] = ((double*)pDataOut)[i];
+ }
}
double sample_mul = 1;
- if(m_fNormalize)
- {
- for(int i = 0; i < samples; i++)
- {
+ if(m_fNormalize) {
+ for(int i = 0; i < samples; i++) {
double s = buff[i];
- if(s < 0) s = -s;
- if(s > 1) s = 1;
- if(m_sample_max < s) m_sample_max = s;
+ if(s < 0) {
+ s = -s;
+ }
+ if(s > 1) {
+ s = 1;
+ }
+ if(m_sample_max < s) {
+ m_sample_max = s;
+ }
}
sample_mul = 1.0f / m_sample_max;
- if(m_fNormalizeRecover) m_sample_max -= 1.0*rtDur/200000000; // -5%/sec
- if(m_sample_max < 0.1) m_sample_max = 0.1;
+ if(m_fNormalizeRecover) {
+ m_sample_max -= 1.0*rtDur/200000000; // -5%/sec
+ }
+ if(m_sample_max < 0.1) {
+ m_sample_max = 0.1;
+ }
}
- if(m_boost_mul > 1)
- {
+ if(m_boost_mul > 1) {
sample_mul *= m_boost_mul;
}
- for(int i = 0; i < samples; i++)
- {
+ for(int i = 0; i < samples; i++) {
double s = buff[i] * sample_mul;
- if(fPCM && wfe->wBitsPerSample == 8) ((BYTE*)pDataOut)[i] = clamp<BYTE>(s, 0, UCHAR_MAX);
- else if(fPCM && wfe->wBitsPerSample == 16) ((short*)pDataOut)[i] = clamp<short>(s, SHRT_MIN, SHRT_MAX);
- else if(fPCM && wfe->wBitsPerSample == 24) {int tmp = clamp<int>(s, -1<<23, (1<<23)-1); memcpy(&pDataOut[i*3], &tmp, 3);}
- else if(fPCM && wfe->wBitsPerSample == 32) ((int*)pDataOut)[i] = clamp<int>(s, INT_MIN, INT_MAX);
- else if(fFloat && wfe->wBitsPerSample == 32) ((float*)pDataOut)[i] = clamp<float>(s, -1, +1);
- else if(fFloat && wfe->wBitsPerSample == 64) ((double*)pDataOut)[i] = clamp<double>(s, -1, +1);
+ if(fPCM && wfe->wBitsPerSample == 8) {
+ ((BYTE*)pDataOut)[i] = clamp<BYTE>(s, 0, UCHAR_MAX);
+ } else if(fPCM && wfe->wBitsPerSample == 16) {
+ ((short*)pDataOut)[i] = clamp<short>(s, SHRT_MIN, SHRT_MAX);
+ } else if(fPCM && wfe->wBitsPerSample == 24) {
+ int tmp = clamp<int>(s, -1<<23, (1<<23)-1);
+ memcpy(&pDataOut[i*3], &tmp, 3);
+ } else if(fPCM && wfe->wBitsPerSample == 32) {
+ ((int*)pDataOut)[i] = clamp<int>(s, INT_MIN, INT_MAX);
+ } else if(fFloat && wfe->wBitsPerSample == 32) {
+ ((float*)pDataOut)[i] = clamp<float>(s, -1, +1);
+ } else if(fFloat && wfe->wBitsPerSample == 64) {
+ ((double*)pDataOut)[i] = clamp<double>(s, -1, +1);
+ }
}
delete buff;
@@ -441,41 +445,39 @@ CMediaType CAudioSwitcherFilter::CreateNewOutputMediaType(CMediaType mt, long& c
{
CStreamSwitcherInputPin* pInPin = GetInputPin();
CStreamSwitcherOutputPin* pOutPin = GetOutputPin();
- if(!pInPin || !pOutPin || ((WAVEFORMATEX*)mt.pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3_SPDIF)
+ if(!pInPin || !pOutPin || ((WAVEFORMATEX*)mt.pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3_SPDIF) {
return __super::CreateNewOutputMediaType(mt, cbBuffer);
+ }
WAVEFORMATEX* wfe = (WAVEFORMATEX*)pInPin->CurrentMediaType().pbFormat;
- if(m_fCustomChannelMapping)
- {
+ if(m_fCustomChannelMapping) {
m_chs[wfe->nChannels-1].RemoveAll();
DWORD mask = DWORD((__int64(1)<<wfe->nChannels)-1);
- for(int i = 0; i < 18; i++)
- {
- if(m_pSpeakerToChannelMap[wfe->nChannels-1][i]&mask)
- {
+ for(int i = 0; i < 18; i++) {
+ if(m_pSpeakerToChannelMap[wfe->nChannels-1][i]&mask) {
ChMap cm = {1<<i, m_pSpeakerToChannelMap[wfe->nChannels-1][i]};
m_chs[wfe->nChannels-1].Add(cm);
}
}
- if(m_chs[wfe->nChannels-1].GetCount() > 0)
- {
+ if(m_chs[wfe->nChannels-1].GetCount() > 0) {
mt.ReallocFormatBuffer(sizeof(WAVEFORMATEXTENSIBLE));
WAVEFORMATEXTENSIBLE* wfex = (WAVEFORMATEXTENSIBLE*)mt.pbFormat;
wfex->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX);
wfex->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wfex->Samples.wValidBitsPerSample = wfe->wBitsPerSample;
- wfex->SubFormat =
+ wfex->SubFormat =
wfe->wFormatTag == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM :
wfe->wFormatTag == WAVE_FORMAT_IEEE_FLOAT ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT :
wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? ((WAVEFORMATEXTENSIBLE*)wfe)->SubFormat :
KSDATAFORMAT_SUBTYPE_PCM; // can't happen
wfex->dwChannelMask = 0;
- for(int i = 0; i < m_chs[wfe->nChannels-1].GetCount(); i++)
+ for(int i = 0; i < m_chs[wfe->nChannels-1].GetCount(); i++) {
wfex->dwChannelMask |= m_chs[wfe->nChannels-1][i].Speaker;
+ }
wfex->Format.nChannels = (WORD)m_chs[wfe->nChannels-1].GetCount();
wfex->Format.nBlockAlign = wfex->Format.nChannels*wfex->Format.wBitsPerSample>>3;
@@ -485,10 +487,8 @@ CMediaType CAudioSwitcherFilter::CreateNewOutputMediaType(CMediaType mt, long& c
WAVEFORMATEX* wfeout = (WAVEFORMATEX*)mt.pbFormat;
- if(m_fDownSampleTo441)
- {
- if(wfeout->nSamplesPerSec > 44100 && wfeout->wBitsPerSample <= 16)
- {
+ if(m_fDownSampleTo441) {
+ if(wfeout->nSamplesPerSec > 44100 && wfeout->wBitsPerSample <= 16) {
wfeout->nSamplesPerSec = 44100;
wfeout->nAvgBytesPerSec = wfeout->nBlockAlign*wfeout->nSamplesPerSec;
}
@@ -499,8 +499,8 @@ CMediaType CAudioSwitcherFilter::CreateNewOutputMediaType(CMediaType mt, long& c
int lenout = len * wfeout->nSamplesPerSec / wfe->nSamplesPerSec;
cbBuffer = lenout*bps*wfeout->nChannels;
-// mt.lSampleSize = (ULONG)max(mt.lSampleSize, wfe->nAvgBytesPerSec * rtLen / 10000000i64);
-// mt.lSampleSize = (mt.lSampleSize + (wfe->nBlockAlign-1)) & ~(wfe->nBlockAlign-1);
+ // mt.lSampleSize = (ULONG)max(mt.lSampleSize, wfe->nAvgBytesPerSec * rtLen / 10000000i64);
+ // mt.lSampleSize = (mt.lSampleSize + (wfe->nBlockAlign-1)) & ~(wfe->nBlockAlign-1);
return mt;
}
@@ -511,8 +511,7 @@ void CAudioSwitcherFilter::OnNewOutputMediaType(const CMediaType& mtIn, const CM
const WAVEFORMATEX* wfeout = (WAVEFORMATEX*)mtOut.pbFormat;
m_pResamplers.RemoveAll();
- for(int i = 0; i < wfeout->nChannels; i++)
- {
+ for(int i = 0; i < wfeout->nChannels; i++) {
CAutoPtr<AudioStreamResampler> pResampler;
pResampler.Attach(DNew AudioStreamResampler(wfeout->wBitsPerSample>>3, wfe->nSamplesPerSec, wfeout->nSamplesPerSec, true));
m_pResamplers.Add(pResampler);
@@ -540,24 +539,23 @@ HRESULT CAudioSwitcherFilter::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE
STDMETHODIMP CAudioSwitcherFilter::GetInputSpeakerConfig(DWORD* pdwChannelMask)
{
- if(!pdwChannelMask)
+ if(!pdwChannelMask) {
return E_POINTER;
+ }
*pdwChannelMask = 0;
CStreamSwitcherInputPin* pInPin = GetInputPin();
- if(!pInPin || !pInPin->IsConnected())
+ if(!pInPin || !pInPin->IsConnected()) {
return E_UNEXPECTED;
+ }
WAVEFORMATEX* wfe = (WAVEFORMATEX*)pInPin->CurrentMediaType().pbFormat;
- if(wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
- {
+ if(wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
WAVEFORMATEXTENSIBLE* wfex = (WAVEFORMATEXTENSIBLE*)wfe;
*pdwChannelMask = wfex->dwChannelMask;
- }
- else
- {
+ } else {
*pdwChannelMask = 0/*wfe->nChannels == 1 ? 4 : wfe->nChannels == 2 ? 3 : 0*/;
}
@@ -566,7 +564,9 @@ STDMETHODIMP CAudioSwitcherFilter::GetInputSpeakerConfig(DWORD* pdwChannelMask)
STDMETHODIMP CAudioSwitcherFilter::GetSpeakerConfig(bool* pfCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18])
{
- if(pfCustomChannelMapping) *pfCustomChannelMapping = m_fCustomChannelMapping;
+ if(pfCustomChannelMapping) {
+ *pfCustomChannelMapping = m_fCustomChannelMapping;
+ }
memcpy(pSpeakerToChannelMap, m_pSpeakerToChannelMap, sizeof(m_pSpeakerToChannelMap));
return S_OK;
@@ -575,10 +575,9 @@ STDMETHODIMP CAudioSwitcherFilter::GetSpeakerConfig(bool* pfCustomChannelMapping
STDMETHODIMP CAudioSwitcherFilter::SetSpeakerConfig(bool fCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18])
{
if(m_State == State_Stopped || m_fCustomChannelMapping != fCustomChannelMapping
- || memcmp(m_pSpeakerToChannelMap, pSpeakerToChannelMap, sizeof(m_pSpeakerToChannelMap)))
- {
+ || memcmp(m_pSpeakerToChannelMap, pSpeakerToChannelMap, sizeof(m_pSpeakerToChannelMap))) {
PauseGraph;
-
+
CStreamSwitcherInputPin* pInput = GetInputPin();
SelectInput(NULL);
@@ -607,8 +606,7 @@ STDMETHODIMP_(bool) CAudioSwitcherFilter::IsDownSamplingTo441Enabled()
STDMETHODIMP CAudioSwitcherFilter::EnableDownSamplingTo441(bool fEnable)
{
- if(m_fDownSampleTo441 != fEnable)
- {
+ if(m_fDownSampleTo441 != fEnable) {
PauseGraph;
m_fDownSampleTo441 = fEnable;
ResumeGraph;
@@ -638,7 +636,9 @@ STDMETHODIMP CAudioSwitcherFilter::GetNormalizeBoost(bool& fNormalize, bool& fNo
STDMETHODIMP CAudioSwitcherFilter::SetNormalizeBoost(bool fNormalize, bool fNormalizeRecover, float boost_dB)
{
- if(m_fNormalize != fNormalize) m_sample_max = 0.1f;
+ if(m_fNormalize != fNormalize) {
+ m_sample_max = 0.1f;
+ }
m_fNormalize = fNormalize;
m_fNormalizeRecover = fNormalizeRecover;
m_boost_mul = pow(10.0f, boost_dB/20);
@@ -650,6 +650,8 @@ STDMETHODIMP CAudioSwitcherFilter::SetNormalizeBoost(bool fNormalize, bool fNorm
STDMETHODIMP CAudioSwitcherFilter::Enable(long lIndex, DWORD dwFlags)
{
HRESULT hr = __super::Enable(lIndex, dwFlags);
- if(S_OK == hr) m_sample_max = 0.1f;
+ if(S_OK == hr) {
+ m_sample_max = 0.1f;
+ }
return hr;
}
diff --git a/src/filters/switcher/AudioSwitcher/AudioSwitcher.h b/src/filters/switcher/AudioSwitcher/AudioSwitcher.h
index 8f2779149..b54037d06 100644
--- a/src/filters/switcher/AudioSwitcher/AudioSwitcher.h
+++ b/src/filters/switcher/AudioSwitcher/AudioSwitcher.h
@@ -21,12 +21,12 @@
#include "StreamSwitcher.h"
interface __declspec(uuid("CEDB2890-53AE-4231-91A3-B0AAFCD1DBDE"))
-IAudioSwitcherFilter : public IUnknown
-{
+IAudioSwitcherFilter :
+public IUnknown {
STDMETHOD(GetInputSpeakerConfig) (DWORD* pdwChannelMask) = 0;
- STDMETHOD(GetSpeakerConfig) (bool* pfCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]) = 0;
- STDMETHOD(SetSpeakerConfig) (bool fCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]) = 0;
- STDMETHOD_(int, GetNumberOfInputChannels) () = 0;
+ STDMETHOD(GetSpeakerConfig) (bool* pfCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]) = 0;
+ STDMETHOD(SetSpeakerConfig) (bool fCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]) = 0;
+ STDMETHOD_(int, GetNumberOfInputChannels) () = 0;
STDMETHOD_(bool, IsDownSamplingTo441Enabled) () = 0;
STDMETHOD(EnableDownSamplingTo441) (bool fEnable) = 0;
STDMETHOD_(REFERENCE_TIME, GetAudioTimeShift) () = 0;
@@ -38,9 +38,11 @@ IAudioSwitcherFilter : public IUnknown
class AudioStreamResampler;
class __declspec(uuid("18C16B08-6497-420e-AD14-22D21C2CEAB7"))
-CAudioSwitcherFilter : public CStreamSwitcherFilter, public IAudioSwitcherFilter
+ CAudioSwitcherFilter : public CStreamSwitcherFilter, public IAudioSwitcherFilter
{
- typedef struct {DWORD Speaker, Channel;} ChMap;
+ typedef struct {
+ DWORD Speaker, Channel;
+ } ChMap;
CAtlArray<ChMap> m_chs[18];
bool m_fCustomChannelMapping;
@@ -58,7 +60,7 @@ public:
CAudioSwitcherFilter(LPUNKNOWN lpunk, HRESULT* phr);
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT CheckMediaType(const CMediaType* pmt);
HRESULT Transform(IMediaSample* pIn, IMediaSample* pOut);
@@ -70,9 +72,9 @@ public:
// IAudioSwitcherFilter
STDMETHODIMP GetInputSpeakerConfig(DWORD* pdwChannelMask);
- STDMETHODIMP GetSpeakerConfig(bool* pfCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]);
- STDMETHODIMP SetSpeakerConfig(bool fCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]);
- STDMETHODIMP_(int) GetNumberOfInputChannels();
+ STDMETHODIMP GetSpeakerConfig(bool* pfCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]);
+ STDMETHODIMP SetSpeakerConfig(bool fCustomChannelMapping, DWORD pSpeakerToChannelMap[18][18]);
+ STDMETHODIMP_(int) GetNumberOfInputChannels();
STDMETHODIMP_(bool) IsDownSamplingTo441Enabled();
STDMETHODIMP EnableDownSamplingTo441(bool fEnable);
STDMETHODIMP_(REFERENCE_TIME) GetAudioTimeShift();
diff --git a/src/filters/switcher/AudioSwitcher/StreamSwitcher.cpp b/src/filters/switcher/AudioSwitcher/StreamSwitcher.cpp
index 7a75a2768..8b62ada0a 100644
--- a/src/filters/switcher/AudioSwitcher/StreamSwitcher.cpp
+++ b/src/filters/switcher/AudioSwitcher/StreamSwitcher.cpp
@@ -45,10 +45,10 @@ CStreamSwitcherPassThru::CStreamSwitcherPassThru(LPUNKNOWN pUnk, HRESULT* phr, C
STDMETHODIMP CStreamSwitcherPassThru::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
- CheckPointer(ppv, E_POINTER);
- *ppv = NULL;
+ CheckPointer(ppv, E_POINTER);
+ *ppv = NULL;
- return
+ return
QI(IMediaSeeking)
CMediaPosition::NonDelegatingQueryInterface(riid, ppv);
}
@@ -56,17 +56,19 @@ STDMETHODIMP CStreamSwitcherPassThru::NonDelegatingQueryInterface(REFIID riid, v
template<class T>
HRESULT GetPeer(CStreamSwitcherFilter* pFilter, T** ppT)
{
- *ppT = NULL;
+ *ppT = NULL;
CBasePin* pPin = pFilter->GetInputPin();
- if(!pPin) return E_NOTIMPL;
+ if(!pPin) {
+ return E_NOTIMPL;
+ }
- CComPtr<IPin> pConnected;
- if(FAILED(pPin->ConnectedTo(&pConnected)))
+ CComPtr<IPin> pConnected;
+ if(FAILED(pPin->ConnectedTo(&pConnected))) {
return E_NOTIMPL;
+ }
- if(CComQIPtr<T> pT = pConnected)
- {
+ if(CComQIPtr<T> pT = pConnected) {
*ppT = pT.Detach();
return S_OK;
}
@@ -78,12 +80,12 @@ HRESULT GetPeer(CStreamSwitcherFilter* pFilter, T** ppT)
CComPtr<IMediaSeeking> pMS; \
if(FAILED(GetPeer(m_pFilter, &pMS))) return E_NOTIMPL; \
return pMS->##call; \
-
+
#define CallPeer(call) \
CComPtr<IMediaPosition> pMP; \
if(FAILED(GetPeer(m_pFilter, &pMP))) return E_NOTIMPL; \
return pMP->##call; \
-
+
#define CallPeerSeekingAll(call) \
HRESULT hr = E_NOTIMPL; \
POSITION pos = m_pFilter->m_pInputs.GetHeadPosition(); \
@@ -101,7 +103,7 @@ HRESULT GetPeer(CStreamSwitcherFilter* pFilter, T** ppT)
} \
} \
return hr; \
-
+
#define CallPeerAll(call) \
HRESULT hr = E_NOTIMPL; \
POSITION pos = m_pFilter->m_pInputs.GetHeadPosition(); \
@@ -119,71 +121,131 @@ HRESULT GetPeer(CStreamSwitcherFilter* pFilter, T** ppT)
} \
} \
return hr; \
-
+
// IMediaSeeking
STDMETHODIMP CStreamSwitcherPassThru::GetCapabilities(DWORD* pCaps)
- {CallPeerSeeking(GetCapabilities(pCaps));}
+{
+ CallPeerSeeking(GetCapabilities(pCaps));
+}
STDMETHODIMP CStreamSwitcherPassThru::CheckCapabilities(DWORD* pCaps)
- {CallPeerSeeking(CheckCapabilities(pCaps));}
+{
+ CallPeerSeeking(CheckCapabilities(pCaps));
+}
STDMETHODIMP CStreamSwitcherPassThru::IsFormatSupported(const GUID* pFormat)
- {CallPeerSeeking(IsFormatSupported(pFormat));}
+{
+ CallPeerSeeking(IsFormatSupported(pFormat));
+}
STDMETHODIMP CStreamSwitcherPassThru::QueryPreferredFormat(GUID* pFormat)
- {CallPeerSeeking(QueryPreferredFormat(pFormat));}
+{
+ CallPeerSeeking(QueryPreferredFormat(pFormat));
+}
STDMETHODIMP CStreamSwitcherPassThru::SetTimeFormat(const GUID* pFormat)
- {CallPeerSeeking(SetTimeFormat(pFormat));}
+{
+ CallPeerSeeking(SetTimeFormat(pFormat));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetTimeFormat(GUID* pFormat)
- {CallPeerSeeking(GetTimeFormat(pFormat));}
+{
+ CallPeerSeeking(GetTimeFormat(pFormat));
+}
STDMETHODIMP CStreamSwitcherPassThru::IsUsingTimeFormat(const GUID* pFormat)
- {CallPeerSeeking(IsUsingTimeFormat(pFormat));}
+{
+ CallPeerSeeking(IsUsingTimeFormat(pFormat));
+}
STDMETHODIMP CStreamSwitcherPassThru::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
- {CallPeerSeeking(ConvertTimeFormat(pTarget, pTargetFormat, Source, pSourceFormat));}
+{
+ CallPeerSeeking(ConvertTimeFormat(pTarget, pTargetFormat, Source, pSourceFormat));
+}
STDMETHODIMP CStreamSwitcherPassThru::SetPositions(LONGLONG* pCurrent, DWORD CurrentFlags, LONGLONG* pStop, DWORD StopFlags)
- {CallPeerSeekingAll(SetPositions(pCurrent, CurrentFlags, pStop, StopFlags));}
+{
+ CallPeerSeekingAll(SetPositions(pCurrent, CurrentFlags, pStop, StopFlags));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
- {CallPeerSeeking(GetPositions(pCurrent, pStop));}
+{
+ CallPeerSeeking(GetPositions(pCurrent, pStop));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetCurrentPosition(LONGLONG* pCurrent)
- {CallPeerSeeking(GetCurrentPosition(pCurrent));}
+{
+ CallPeerSeeking(GetCurrentPosition(pCurrent));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetStopPosition(LONGLONG* pStop)
- {CallPeerSeeking(GetStopPosition(pStop));}
+{
+ CallPeerSeeking(GetStopPosition(pStop));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetDuration(LONGLONG* pDuration)
- {CallPeerSeeking(GetDuration(pDuration));}
+{
+ CallPeerSeeking(GetDuration(pDuration));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetPreroll(LONGLONG* pllPreroll)
- {CallPeerSeeking(GetPreroll(pllPreroll));}
+{
+ CallPeerSeeking(GetPreroll(pllPreroll));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
- {CallPeerSeeking(GetAvailable(pEarliest, pLatest));}
+{
+ CallPeerSeeking(GetAvailable(pEarliest, pLatest));
+}
STDMETHODIMP CStreamSwitcherPassThru::GetRate(double* pdRate)
- {CallPeerSeeking(GetRate(pdRate));}
+{
+ CallPeerSeeking(GetRate(pdRate));
+}
STDMETHODIMP CStreamSwitcherPassThru::SetRate(double dRate)
- {if(0.0 == dRate) return E_INVALIDARG;
- CallPeerSeekingAll(SetRate(dRate));}
+{
+ if(0.0 == dRate) {
+ return E_INVALIDARG;
+ }
+ CallPeerSeekingAll(SetRate(dRate));
+}
// IMediaPosition
STDMETHODIMP CStreamSwitcherPassThru::get_Duration(REFTIME* plength)
- {CallPeer(get_Duration(plength));}
+{
+ CallPeer(get_Duration(plength));
+}
STDMETHODIMP CStreamSwitcherPassThru::get_CurrentPosition(REFTIME* pllTime)
- {CallPeer(get_CurrentPosition(pllTime));}
+{
+ CallPeer(get_CurrentPosition(pllTime));
+}
STDMETHODIMP CStreamSwitcherPassThru::put_CurrentPosition(REFTIME llTime)
- {CallPeerAll(put_CurrentPosition(llTime));}
+{
+ CallPeerAll(put_CurrentPosition(llTime));
+}
STDMETHODIMP CStreamSwitcherPassThru::get_StopTime(REFTIME* pllTime)
- {CallPeer(get_StopTime(pllTime));}
+{
+ CallPeer(get_StopTime(pllTime));
+}
STDMETHODIMP CStreamSwitcherPassThru::put_StopTime(REFTIME llTime)
- {CallPeerAll(put_StopTime(llTime));}
+{
+ CallPeerAll(put_StopTime(llTime));
+}
STDMETHODIMP CStreamSwitcherPassThru::get_PrerollTime(REFTIME * pllTime)
- {CallPeer(get_PrerollTime(pllTime));}
+{
+ CallPeer(get_PrerollTime(pllTime));
+}
STDMETHODIMP CStreamSwitcherPassThru::put_PrerollTime(REFTIME llTime)
- {CallPeerAll(put_PrerollTime(llTime));}
+{
+ CallPeerAll(put_PrerollTime(llTime));
+}
STDMETHODIMP CStreamSwitcherPassThru::get_Rate(double* pdRate)
- {CallPeer(get_Rate(pdRate));}
+{
+ CallPeer(get_Rate(pdRate));
+}
STDMETHODIMP CStreamSwitcherPassThru::put_Rate(double dRate)
- {if(0.0 == dRate) return E_INVALIDARG;
- CallPeerAll(put_Rate(dRate));}
+{
+ if(0.0 == dRate) {
+ return E_INVALIDARG;
+ }
+ CallPeerAll(put_Rate(dRate));
+}
STDMETHODIMP CStreamSwitcherPassThru::CanSeekForward(LONG* pCanSeekForward)
- {CallPeer(CanSeekForward(pCanSeekForward));}
-STDMETHODIMP CStreamSwitcherPassThru::CanSeekBackward(LONG* pCanSeekBackward)
- {CallPeer(CanSeekBackward(pCanSeekBackward));}
+{
+ CallPeer(CanSeekForward(pCanSeekForward));
+}
+STDMETHODIMP CStreamSwitcherPassThru::CanSeekBackward(LONG* pCanSeekBackward)
+{
+ CallPeer(CanSeekBackward(pCanSeekBackward));
+}
//
// CStreamSwitcherAllocator
@@ -201,7 +263,7 @@ CStreamSwitcherAllocator::CStreamSwitcherAllocator(CStreamSwitcherInputPin* pPin
#ifdef DEBUG
CStreamSwitcherAllocator::~CStreamSwitcherAllocator()
{
- ASSERT(m_bCommitted == FALSE);
+ ASSERT(m_bCommitted == FALSE);
}
#endif
@@ -216,49 +278,59 @@ STDMETHODIMP_(ULONG) CStreamSwitcherAllocator::NonDelegatingRelease()
}
STDMETHODIMP CStreamSwitcherAllocator::GetBuffer(
- IMediaSample** ppBuffer,
- REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime,
+ IMediaSample** ppBuffer,
+ REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime,
DWORD dwFlags)
{
HRESULT hr = VFW_E_NOT_COMMITTED;
- if(!m_bCommitted)
- return hr;
-/*
-TRACE(_T("CStreamSwitcherAllocator::GetBuffer m_pPin->m_evBlock.Wait() + %x\n"), this);
- m_pPin->m_evBlock.Wait();
-TRACE(_T("CStreamSwitcherAllocator::GetBuffer m_pPin->m_evBlock.Wait() - %x\n"), this);
-*/
- if(m_fMediaTypeChanged)
- {
- if(!m_pPin || !m_pPin->m_pFilter)
+ if(!m_bCommitted) {
+ return hr;
+ }
+ /*
+ TRACE(_T("CStreamSwitcherAllocator::GetBuffer m_pPin->m_evBlock.Wait() + %x\n"), this);
+ m_pPin->m_evBlock.Wait();
+ TRACE(_T("CStreamSwitcherAllocator::GetBuffer m_pPin->m_evBlock.Wait() - %x\n"), this);
+ */
+ if(m_fMediaTypeChanged) {
+ if(!m_pPin || !m_pPin->m_pFilter) {
return hr;
+ }
CStreamSwitcherOutputPin* pOut = (static_cast<CStreamSwitcherFilter*>(m_pPin->m_pFilter))->GetOutputPin();
- if(!pOut || !pOut->CurrentAllocator())
+ if(!pOut || !pOut->CurrentAllocator()) {
return hr;
+ }
ALLOCATOR_PROPERTIES Properties, Actual;
- if(FAILED(pOut->CurrentAllocator()->GetProperties(&Actual)))
+ if(FAILED(pOut->CurrentAllocator()->GetProperties(&Actual))) {
return hr;
- if(FAILED(GetProperties(&Properties)))
+ }
+ if(FAILED(GetProperties(&Properties))) {
return hr;
+ }
- if(!m_bCommitted || Properties.cbBuffer < Actual.cbBuffer)
- {
+ if(!m_bCommitted || Properties.cbBuffer < Actual.cbBuffer) {
Properties.cbBuffer = Actual.cbBuffer;
- if(FAILED(Decommit())) return hr;
- if(FAILED(SetProperties(&Properties, &Actual))) return hr;
- if(FAILED(Commit())) return hr;
+ if(FAILED(Decommit())) {
+ return hr;
+ }
+ if(FAILED(SetProperties(&Properties, &Actual))) {
+ return hr;
+ }
+ if(FAILED(Commit())) {
+ return hr;
+ }
ASSERT(Actual.cbBuffer >= Properties.cbBuffer);
- if(Actual.cbBuffer < Properties.cbBuffer) return hr;
+ if(Actual.cbBuffer < Properties.cbBuffer) {
+ return hr;
+ }
}
}
hr = CMemAllocator::GetBuffer(ppBuffer, pStartTime, pEndTime, dwFlags);
- if(m_fMediaTypeChanged && SUCCEEDED(hr))
- {
+ if(m_fMediaTypeChanged && SUCCEEDED(hr)) {
(*ppBuffer)->SetMediaType(&m_mt);
m_fMediaTypeChanged = false;
}
@@ -278,7 +350,7 @@ void CStreamSwitcherAllocator::NotifyMediaType(const CMediaType& mt)
//
CStreamSwitcherInputPin::CStreamSwitcherInputPin(CStreamSwitcherFilter* pFilter, HRESULT* phr, LPCWSTR pName)
- : CBaseInputPin(NAME("CStreamSwitcherInputPin"), pFilter, &pFilter->m_csState, phr, pName)
+ : CBaseInputPin(NAME("CStreamSwitcherInputPin"), pFilter, &pFilter->m_csState, phr, pName)
, m_Allocator(this, phr)
, m_bSampleSkipped(FALSE)
, m_bQualityChanged(FALSE)
@@ -291,7 +363,7 @@ CStreamSwitcherInputPin::CStreamSwitcherInputPin(CStreamSwitcherFilter* pFilter,
}
class __declspec(uuid("138130AF-A79B-45D5-B4AA-87697457BA87"))
-NeroAudioDecoder {};
+ NeroAudioDecoder {};
STDMETHODIMP CStreamSwitcherInputPin::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
@@ -310,7 +382,9 @@ STDMETHODIMP CStreamSwitcherInputPin::DynamicQueryAccept(const AM_MEDIA_TYPE* pm
STDMETHODIMP CStreamSwitcherInputPin::NotifyEndOfStream(HANDLE hNotifyEvent)
{
- if(m_hNotifyEvent) SetEvent(m_hNotifyEvent);
+ if(m_hNotifyEvent) {
+ SetEvent(m_hNotifyEvent);
+ }
m_hNotifyEvent = hNotifyEvent;
return S_OK;
}
@@ -335,7 +409,7 @@ STDMETHODIMP_(bool) CStreamSwitcherInputPin::IsActive()
return(this == (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetInputPin());
}
-//
+//
HRESULT CStreamSwitcherInputPin::QueryAcceptDownstream(const AM_MEDIA_TYPE* pmt)
{
@@ -343,12 +417,12 @@ HRESULT CStreamSwitcherInputPin::QueryAcceptDownstream(const AM_MEDIA_TYPE* pmt)
CStreamSwitcherOutputPin* pOut = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetOutputPin();
- if(pOut && pOut->IsConnected())
- {
- if(CComPtr<IPinConnection> pPC = pOut->CurrentPinConnection())
- {
+ if(pOut && pOut->IsConnected()) {
+ if(CComPtr<IPinConnection> pPC = pOut->CurrentPinConnection()) {
hr = pPC->DynamicQueryAccept(pmt);
- if(hr == S_OK) return S_OK;
+ if(hr == S_OK) {
+ return S_OK;
+ }
}
hr = pOut->GetConnected()->QueryAccept(pmt);
@@ -359,71 +433,78 @@ HRESULT CStreamSwitcherInputPin::QueryAcceptDownstream(const AM_MEDIA_TYPE* pmt)
void CStreamSwitcherInputPin::Block(bool fBlock)
{
- if(fBlock) m_evBlock.Reset();
- else m_evBlock.Set();
+ if(fBlock) {
+ m_evBlock.Reset();
+ } else {
+ m_evBlock.Set();
+ }
}
HRESULT CStreamSwitcherInputPin::InitializeOutputSample(IMediaSample* pInSample, IMediaSample** ppOutSample)
{
- if(!pInSample || !ppOutSample)
+ if(!pInSample || !ppOutSample) {
return E_POINTER;
+ }
CStreamSwitcherOutputPin* pOut = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetOutputPin();
ASSERT(pOut->GetConnected());
- CComPtr<IMediaSample> pOutSample;
+ CComPtr<IMediaSample> pOutSample;
DWORD dwFlags = m_bSampleSkipped ? AM_GBF_PREVFRAMESKIPPED : 0;
- if(!(m_SampleProps.dwSampleFlags & AM_SAMPLE_SPLICEPOINT))
+ if(!(m_SampleProps.dwSampleFlags & AM_SAMPLE_SPLICEPOINT)) {
dwFlags |= AM_GBF_NOTASYNCPOINT;
+ }
HRESULT hr = pOut->GetDeliveryBuffer(&pOutSample
- , m_SampleProps.dwSampleFlags & AM_SAMPLE_TIMEVALID ? &m_SampleProps.tStart : NULL
- , m_SampleProps.dwSampleFlags & AM_SAMPLE_STOPVALID ? &m_SampleProps.tStop : NULL
- , dwFlags);
+ , m_SampleProps.dwSampleFlags & AM_SAMPLE_TIMEVALID ? &m_SampleProps.tStart : NULL
+ , m_SampleProps.dwSampleFlags & AM_SAMPLE_STOPVALID ? &m_SampleProps.tStop : NULL
+ , dwFlags);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
- if(!pOutSample)
+ if(!pOutSample) {
return E_FAIL;
+ }
- if(CComQIPtr<IMediaSample2> pOutSample2 = pOutSample)
- {
- AM_SAMPLE2_PROPERTIES OutProps;
+ if(CComQIPtr<IMediaSample2> pOutSample2 = pOutSample) {
+ AM_SAMPLE2_PROPERTIES OutProps;
EXECUTE_ASSERT(SUCCEEDED(pOutSample2->GetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, tStart), (PBYTE)&OutProps)));
- OutProps.dwTypeSpecificFlags = m_SampleProps.dwTypeSpecificFlags;
- OutProps.dwSampleFlags =
- (OutProps.dwSampleFlags & AM_SAMPLE_TYPECHANGED) |
- (m_SampleProps.dwSampleFlags & ~AM_SAMPLE_TYPECHANGED);
+ OutProps.dwTypeSpecificFlags = m_SampleProps.dwTypeSpecificFlags;
+ OutProps.dwSampleFlags =
+ (OutProps.dwSampleFlags & AM_SAMPLE_TYPECHANGED) |
+ (m_SampleProps.dwSampleFlags & ~AM_SAMPLE_TYPECHANGED);
- OutProps.tStart = m_SampleProps.tStart;
- OutProps.tStop = m_SampleProps.tStop;
- OutProps.cbData = FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, dwStreamId);
+ OutProps.tStart = m_SampleProps.tStart;
+ OutProps.tStop = m_SampleProps.tStop;
+ OutProps.cbData = FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, dwStreamId);
- hr = pOutSample2->SetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, dwStreamId), (PBYTE)&OutProps);
- if(m_SampleProps.dwSampleFlags & AM_SAMPLE_DATADISCONTINUITY)
+ hr = pOutSample2->SetProperties(FIELD_OFFSET(AM_SAMPLE2_PROPERTIES, dwStreamId), (PBYTE)&OutProps);
+ if(m_SampleProps.dwSampleFlags & AM_SAMPLE_DATADISCONTINUITY) {
m_bSampleSkipped = FALSE;
- }
- else
- {
- if(m_SampleProps.dwSampleFlags & AM_SAMPLE_TIMEVALID)
+ }
+ } else {
+ if(m_SampleProps.dwSampleFlags & AM_SAMPLE_TIMEVALID) {
pOutSample->SetTime(&m_SampleProps.tStart, &m_SampleProps.tStop);
+ }
- if(m_SampleProps.dwSampleFlags & AM_SAMPLE_SPLICEPOINT)
+ if(m_SampleProps.dwSampleFlags & AM_SAMPLE_SPLICEPOINT) {
pOutSample->SetSyncPoint(TRUE);
+ }
- if(m_SampleProps.dwSampleFlags & AM_SAMPLE_DATADISCONTINUITY)
- {
+ if(m_SampleProps.dwSampleFlags & AM_SAMPLE_DATADISCONTINUITY) {
pOutSample->SetDiscontinuity(TRUE);
- m_bSampleSkipped = FALSE;
- }
+ m_bSampleSkipped = FALSE;
+ }
LONGLONG MediaStart, MediaEnd;
- if(pInSample->GetMediaTime(&MediaStart, &MediaEnd) == NOERROR)
+ if(pInSample->GetMediaTime(&MediaStart, &MediaEnd) == NOERROR) {
pOutSample->SetMediaTime(&MediaStart, &MediaEnd);
- }
+ }
+ }
*ppOutSample = pOutSample.Detach();
@@ -437,21 +518,23 @@ HRESULT CStreamSwitcherInputPin::CheckMediaType(const CMediaType* pmt)
return (static_cast<CStreamSwitcherFilter*>(m_pFilter))->CheckMediaType(pmt);
}
-// virtual
+// virtual
HRESULT CStreamSwitcherInputPin::CheckConnect(IPin* pPin)
{
- return (IPin*)(static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetOutputPin() == pPin
- ? E_FAIL
- : __super::CheckConnect(pPin);
+ return (IPin*)(static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetOutputPin() == pPin
+ ? E_FAIL
+ : __super::CheckConnect(pPin);
}
HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin)
{
HRESULT hr = __super::CompleteConnect(pReceivePin);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
- (static_cast<CStreamSwitcherFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this, pReceivePin);
+ (static_cast<CStreamSwitcherFilter*>(m_pFilter))->CompleteConnect(PINDIR_INPUT, this, pReceivePin);
m_fCanBlock = false;
bool fForkedSomewhere = false;
@@ -459,49 +542,52 @@ HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin)
CStringW fileName;
CStringW pinName;
- IPin* pPin = (IPin*)this;
+ IPin* pPin = (IPin*)this;
IBaseFilter* pBF = (IBaseFilter*)m_pFilter;
pPin = GetUpStreamPin(pBF, pPin);
- if (pPin)
+ if (pPin) {
pBF = GetFilterFromPin(pPin);
- while(pPin && pBF)
- {
- if(IsSplitter(pBF))
- {
+ }
+ while(pPin && pBF) {
+ if(IsSplitter(pBF)) {
pinName = GetPinName(pPin);
}
CLSID clsid = GetCLSID(pBF);
- if(clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter)
+ if(clsid == CLSID_AviSplitter || clsid == CLSID_OggSplitter) {
m_fCanBlock = true;
+ }
int nIn, nOut, nInC, nOutC;
CountPins(pBF, nIn, nOut, nInC, nOutC);
fForkedSomewhere = fForkedSomewhere || nIn > 1 || nOut > 1;
- if(CComQIPtr<IFileSourceFilter> pFSF = pBF)
- {
+ if(CComQIPtr<IFileSourceFilter> pFSF = pBF) {
WCHAR* pszName = NULL;
AM_MEDIA_TYPE mt;
- if(SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName)
- {
+ if(SUCCEEDED(pFSF->GetCurFile(&pszName, &mt)) && pszName) {
fileName = pszName;
CoTaskMemFree(pszName);
fileName.Replace('\\', '/');
CStringW fn = fileName.Mid(fileName.ReverseFind('/')+1);
- if(!fn.IsEmpty()) fileName = fn;
+ if(!fn.IsEmpty()) {
+ fileName = fn;
+ }
// Haali & LAVFSplitter return only one "Audio" pin name, cause CMainFrame::OnInitMenuPopup lookup find the wrong popmenu,
// add space at the end to prevent this, internal filter never return "Audio" only.
- if(!pinName.IsEmpty()) fileName = pinName + L" ";
+ if(!pinName.IsEmpty()) {
+ fileName = pinName + L" ";
+ }
WCHAR* pName = DNew WCHAR[fileName.GetLength()+1];
- if(pName)
- {
+ if(pName) {
wcscpy(pName, fileName);
- if(m_pName) delete [] m_pName;
+ if(m_pName) {
+ delete [] m_pName;
+ }
m_pName = pName;
}
}
@@ -512,12 +598,14 @@ HRESULT CStreamSwitcherInputPin::CompleteConnect(IPin* pReceivePin)
pPin = GetFirstPin(pBF);
pPin = GetUpStreamPin(pBF, pPin);
- if (pPin)
+ if (pPin) {
pBF = GetFilterFromPin(pPin);
+ }
}
- if(!fForkedSomewhere)
+ if(!fForkedSomewhere) {
m_fCanBlock = true;
+ }
m_hNotifyEvent = NULL;
@@ -543,7 +631,9 @@ HRESULT CStreamSwitcherInputPin::Inactive()
STDMETHODIMP CStreamSwitcherInputPin::QueryAccept(const AM_MEDIA_TYPE* pmt)
{
HRESULT hr = __super::QueryAccept(pmt);
- if(S_OK != hr) return hr;
+ if(S_OK != hr) {
+ return hr;
+ }
return QueryAcceptDownstream(pmt);
}
@@ -551,39 +641,43 @@ STDMETHODIMP CStreamSwitcherInputPin::QueryAccept(const AM_MEDIA_TYPE* pmt)
STDMETHODIMP CStreamSwitcherInputPin::ReceiveConnection(IPin* pConnector, const AM_MEDIA_TYPE* pmt)
{
// FIXME: this locked up once
-// CAutoLock cAutoLock(&((CStreamSwitcherFilter*)m_pFilter)->m_csReceive);
+ // CAutoLock cAutoLock(&((CStreamSwitcherFilter*)m_pFilter)->m_csReceive);
HRESULT hr;
- if(S_OK != (hr = QueryAcceptDownstream(pmt)))
+ if(S_OK != (hr = QueryAcceptDownstream(pmt))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(m_Connected && m_Connected != pConnector)
- return VFW_E_ALREADY_CONNECTED;
+ if(m_Connected && m_Connected != pConnector) {
+ return VFW_E_ALREADY_CONNECTED;
+ }
- if(m_Connected)
+ if(m_Connected) {
m_Connected->Release(), m_Connected = NULL;
+ }
return SUCCEEDED(__super::ReceiveConnection(pConnector, pmt)) ? S_OK : E_FAIL;
}
STDMETHODIMP CStreamSwitcherInputPin::GetAllocator(IMemAllocator** ppAllocator)
{
- CheckPointer(ppAllocator, E_POINTER);
+ CheckPointer(ppAllocator, E_POINTER);
- if(m_pAllocator == NULL)
- {
- (m_pAllocator = &m_Allocator)->AddRef();
- }
+ if(m_pAllocator == NULL) {
+ (m_pAllocator = &m_Allocator)->AddRef();
+ }
- (*ppAllocator = m_pAllocator)->AddRef();
+ (*ppAllocator = m_pAllocator)->AddRef();
- return NOERROR;
+ return NOERROR;
}
STDMETHODIMP CStreamSwitcherInputPin::NotifyAllocator(IMemAllocator* pAllocator, BOOL bReadOnly)
{
HRESULT hr = __super::NotifyAllocator(pAllocator, bReadOnly);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
m_bUsingOwnAllocator = (pAllocator == (IMemAllocator*)&m_Allocator);
@@ -592,18 +686,20 @@ STDMETHODIMP CStreamSwitcherInputPin::NotifyAllocator(IMemAllocator* pAllocator,
STDMETHODIMP CStreamSwitcherInputPin::BeginFlush()
{
- CAutoLock cAutoLock(&(static_cast<CStreamSwitcherFilter*>(m_pFilter))->m_csState);
+ CAutoLock cAutoLock(&(static_cast<CStreamSwitcherFilter*>(m_pFilter))->m_csState);
HRESULT hr;
CStreamSwitcherFilter* pSSF = static_cast<CStreamSwitcherFilter*>(m_pFilter);
CStreamSwitcherOutputPin* pOut = pSSF->GetOutputPin();
- if(!IsConnected() || !pOut || !pOut->IsConnected())
+ if(!IsConnected() || !pOut || !pOut->IsConnected()) {
return VFW_E_NOT_CONNECTED;
+ }
- if(FAILED(hr = __super::BeginFlush()))
+ if(FAILED(hr = __super::BeginFlush())) {
return hr;
+ }
return IsActive() ? pSSF->DeliverBeginFlush() : Block(false), S_OK;
}
@@ -617,27 +713,29 @@ STDMETHODIMP CStreamSwitcherInputPin::EndFlush()
CStreamSwitcherFilter* pSSF = static_cast<CStreamSwitcherFilter*>(m_pFilter);
CStreamSwitcherOutputPin* pOut = pSSF->GetOutputPin();
- if(!IsConnected() || !pOut || !pOut->IsConnected())
+ if(!IsConnected() || !pOut || !pOut->IsConnected()) {
return VFW_E_NOT_CONNECTED;
+ }
- if(FAILED(hr = __super::EndFlush()))
+ if(FAILED(hr = __super::EndFlush())) {
return hr;
+ }
return IsActive() ? pSSF->DeliverEndFlush() : Block(true), S_OK;
}
STDMETHODIMP CStreamSwitcherInputPin::EndOfStream()
{
- CAutoLock cAutoLock(&m_csReceive);
+ CAutoLock cAutoLock(&m_csReceive);
CStreamSwitcherFilter* pSSF = static_cast<CStreamSwitcherFilter*>(m_pFilter);
CStreamSwitcherOutputPin* pOut = pSSF->GetOutputPin();
- if(!IsConnected() || !pOut || !pOut->IsConnected())
+ if(!IsConnected() || !pOut || !pOut->IsConnected()) {
return VFW_E_NOT_CONNECTED;
+ }
- if(m_hNotifyEvent)
- {
+ if(m_hNotifyEvent) {
SetEvent(m_hNotifyEvent), m_hNotifyEvent = NULL;
return S_OK;
}
@@ -650,45 +748,46 @@ STDMETHODIMP CStreamSwitcherInputPin::EndOfStream()
STDMETHODIMP CStreamSwitcherInputPin::Receive(IMediaSample* pSample)
{
AM_MEDIA_TYPE* pmt = NULL;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) {
const CMediaType mt(*pmt);
DeleteMediaType(pmt), pmt = NULL;
SetMediaType(&mt);
}
- // DAMN!!!!!! this doesn't work if the stream we are blocking
- // shares the same thread with another stream, mpeg splitters
- // are usually like that. Our nicely built up multithreaded
+ // DAMN!!!!!! this doesn't work if the stream we are blocking
+ // shares the same thread with another stream, mpeg splitters
+ // are usually like that. Our nicely built up multithreaded
// strategy is useless because of this, ARRRRRRGHHHHHH.
#ifdef BLOCKSTREAM
- if(m_fCanBlock)
+ if(m_fCanBlock) {
m_evBlock.Wait();
+ }
#endif
- if(!IsActive())
- {
+ if(!IsActive()) {
#ifdef BLOCKSTREAM
- if(m_fCanBlock)
+ if(m_fCanBlock) {
return S_FALSE;
+ }
#endif
TRACE(_T("&^$#@ : a stupid fix for this stupid problem\n"));
-//Sleep(32);
+ //Sleep(32);
return E_FAIL; // a stupid fix for this stupid problem
}
- CAutoLock cAutoLock(&m_csReceive);
+ CAutoLock cAutoLock(&m_csReceive);
CStreamSwitcherOutputPin* pOut = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetOutputPin();
ASSERT(pOut->GetConnected());
HRESULT hr = __super::Receive(pSample);
- if(S_OK != hr) return hr;
+ if(S_OK != hr) {
+ return hr;
+ }
- if(m_SampleProps.dwStreamId != AM_STREAM_MEDIA)
- {
+ if(m_SampleProps.dwStreamId != AM_STREAM_MEDIA) {
return pOut->Deliver(pSample);
}
@@ -699,8 +798,7 @@ STDMETHODIMP CStreamSwitcherInputPin::Receive(IMediaSample* pSample)
hr = pOut->CurrentAllocator()->GetProperties(&actual);
REFERENCE_TIME rtStart = 0, rtStop = 0;
- if(S_OK == pSample->GetTime(&rtStart, &rtStop))
- {
+ if(S_OK == pSample->GetTime(&rtStart, &rtStop)) {
//
}
@@ -711,35 +809,34 @@ STDMETHODIMP CStreamSwitcherInputPin::Receive(IMediaSample* pSample)
bool fTypeChanged = false;
- if(mtOut != pOut->CurrentMediaType() || cbBuffer > actual.cbBuffer)
- {
+ if(mtOut != pOut->CurrentMediaType() || cbBuffer > actual.cbBuffer) {
fTypeChanged = true;
m_SampleProps.dwSampleFlags |= AM_SAMPLE_TYPECHANGED/*|AM_SAMPLE_DATADISCONTINUITY|AM_SAMPLE_TIMEDISCONTINUITY*/;
-/*
- if(CComQIPtr<IPinConnection> pPC = pOut->CurrentPinConnection())
- {
- HANDLE hEOS = CreateEvent(NULL, FALSE, FALSE, NULL);
- hr = pPC->NotifyEndOfStream(hEOS);
- hr = pOut->DeliverEndOfStream();
- WaitForSingleObject(hEOS, 3000);
- CloseHandle(hEOS);
- hr = pOut->DeliverBeginFlush();
- hr = pOut->DeliverEndFlush();
- }
-*/
+ /*
+ if(CComQIPtr<IPinConnection> pPC = pOut->CurrentPinConnection())
+ {
+ HANDLE hEOS = CreateEvent(NULL, FALSE, FALSE, NULL);
+ hr = pPC->NotifyEndOfStream(hEOS);
+ hr = pOut->DeliverEndOfStream();
+ WaitForSingleObject(hEOS, 3000);
+ CloseHandle(hEOS);
+ hr = pOut->DeliverBeginFlush();
+ hr = pOut->DeliverEndFlush();
+ }
+ */
- if(props.cBuffers < 8 && mtOut.majortype == MEDIATYPE_Audio)
+ if(props.cBuffers < 8 && mtOut.majortype == MEDIATYPE_Audio) {
props.cBuffers = 8;
+ }
props.cbBuffer = cbBuffer;
if(actual.cbAlign != props.cbAlign
- || actual.cbPrefix != props.cbPrefix
- || actual.cBuffers < props.cBuffers
- || actual.cbBuffer < props.cbBuffer)
- {
+ || actual.cbPrefix != props.cbPrefix
+ || actual.cBuffers < props.cBuffers
+ || actual.cbBuffer < props.cbBuffer) {
hr = pOut->DeliverBeginFlush();
hr = pOut->DeliverEndFlush();
hr = pOut->CurrentAllocator()->Decommit();
@@ -749,20 +846,19 @@ STDMETHODIMP CStreamSwitcherInputPin::Receive(IMediaSample* pSample)
}
CComPtr<IMediaSample> pOutSample;
- if(FAILED(InitializeOutputSample(pSample, &pOutSample)))
+ if(FAILED(InitializeOutputSample(pSample, &pOutSample))) {
return E_FAIL;
+ }
pmt = NULL;
- if(SUCCEEDED(pOutSample->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pOutSample->GetMediaType(&pmt)) && pmt) {
const CMediaType mt(*pmt);
DeleteMediaType(pmt), pmt = NULL;
// TODO
ASSERT(0);
}
- if(fTypeChanged)
- {
+ if(fTypeChanged) {
pOut->SetMediaType(&mtOut);
(static_cast<CStreamSwitcherFilter*>(m_pFilter))->OnNewOutputMediaType(m_mt, mtOut);
pOutSample->SetMediaType(&mtOut);
@@ -774,25 +870,21 @@ STDMETHODIMP CStreamSwitcherInputPin::Receive(IMediaSample* pSample)
//
- if(S_OK == hr)
- {
+ if(S_OK == hr) {
hr = pOut->Deliver(pOutSample);
- m_bSampleSkipped = FALSE;
-/*
- if(FAILED(hr))
- {
- ASSERT(0);
- }
-*/
- }
- else if(S_FALSE == hr)
- {
+ m_bSampleSkipped = FALSE;
+ /*
+ if(FAILED(hr))
+ {
+ ASSERT(0);
+ }
+ */
+ } else if(S_FALSE == hr) {
hr = S_OK;
pOutSample = NULL;
m_bSampleSkipped = TRUE;
-
- if(!m_bQualityChanged)
- {
+
+ if(!m_bQualityChanged) {
m_pFilter->NotifyEvent(EC_QUALITY_CHANGE, 0, 0);
m_bQualityChanged = TRUE;
}
@@ -803,16 +895,18 @@ STDMETHODIMP CStreamSwitcherInputPin::Receive(IMediaSample* pSample)
STDMETHODIMP CStreamSwitcherInputPin::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
{
- if(!IsConnected())
+ if(!IsConnected()) {
return S_OK;
+ }
CAutoLock cAutoLock(&m_csReceive);
CStreamSwitcherFilter* pSSF = static_cast<CStreamSwitcherFilter*>(m_pFilter);
CStreamSwitcherOutputPin* pOut = pSSF->GetOutputPin();
- if(!pOut || !pOut->IsConnected())
+ if(!pOut || !pOut->IsConnected()) {
return VFW_E_NOT_CONNECTED;
+ }
return pSSF->DeliverNewSegment(tStart, tStop, dRate);
}
@@ -824,35 +918,37 @@ STDMETHODIMP CStreamSwitcherInputPin::NewSegment(REFERENCE_TIME tStart, REFERENC
CStreamSwitcherOutputPin::CStreamSwitcherOutputPin(CStreamSwitcherFilter* pFilter, HRESULT* phr)
: CBaseOutputPin(NAME("CStreamSwitcherOutputPin"), pFilter, &pFilter->m_csState, phr, L"Out")
{
-// m_bCanReconnectWhenActive = TRUE;
+ // m_bCanReconnectWhenActive = TRUE;
}
STDMETHODIMP CStreamSwitcherOutputPin::NonDelegatingQueryInterface(REFIID riid, void **ppv)
{
- CheckPointer(ppv,E_POINTER);
- ValidateReadWritePtr(ppv, sizeof(PVOID));
- *ppv = NULL;
+ CheckPointer(ppv,E_POINTER);
+ ValidateReadWritePtr(ppv, sizeof(PVOID));
+ *ppv = NULL;
- if(riid == IID_IMediaPosition || riid == IID_IMediaSeeking)
- {
- if(m_pStreamSwitcherPassThru == NULL)
- {
+ if(riid == IID_IMediaPosition || riid == IID_IMediaSeeking) {
+ if(m_pStreamSwitcherPassThru == NULL) {
HRESULT hr = S_OK;
m_pStreamSwitcherPassThru = (IUnknown*)(INonDelegatingUnknown*)
- DNew CStreamSwitcherPassThru(GetOwner(), &hr, static_cast<CStreamSwitcherFilter*>(m_pFilter));
+ DNew CStreamSwitcherPassThru(GetOwner(), &hr, static_cast<CStreamSwitcherFilter*>(m_pFilter));
- if(!m_pStreamSwitcherPassThru) return E_OUTOFMEMORY;
- if(FAILED(hr)) return hr;
- }
+ if(!m_pStreamSwitcherPassThru) {
+ return E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ return hr;
+ }
+ }
- return m_pStreamSwitcherPassThru->QueryInterface(riid, ppv);
- }
-/*
- else if(riid == IID_IStreamBuilder)
- {
- return GetInterface((IStreamBuilder*)this, ppv);
+ return m_pStreamSwitcherPassThru->QueryInterface(riid, ppv);
}
-*/
+ /*
+ else if(riid == IID_IStreamBuilder)
+ {
+ return GetInterface((IStreamBuilder*)this, ppv);
+ }
+ */
return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv);
}
@@ -862,15 +958,12 @@ HRESULT CStreamSwitcherOutputPin::QueryAcceptUpstream(const AM_MEDIA_TYPE* pmt)
CStreamSwitcherInputPin* pIn = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetInputPin();
- if(pIn && pIn->IsConnected() && (pIn->IsUsingOwnAllocator() || pIn->CurrentMediaType() == *pmt))
- {
- if(CComQIPtr<IPin> pPinTo = pIn->GetConnected())
- {
- if(S_OK != (hr = pPinTo->QueryAccept(pmt)))
+ if(pIn && pIn->IsConnected() && (pIn->IsUsingOwnAllocator() || pIn->CurrentMediaType() == *pmt)) {
+ if(CComQIPtr<IPin> pPinTo = pIn->GetConnected()) {
+ if(S_OK != (hr = pPinTo->QueryAccept(pmt))) {
return VFW_E_TYPE_NOT_ACCEPTED;
- }
- else
- {
+ }
+ } else {
return E_FAIL;
}
}
@@ -883,44 +976,51 @@ HRESULT CStreamSwitcherOutputPin::QueryAcceptUpstream(const AM_MEDIA_TYPE* pmt)
HRESULT CStreamSwitcherOutputPin::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
CStreamSwitcherInputPin* pIn = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetInputPin();
- if(!pIn || !pIn->IsConnected()) return E_UNEXPECTED;
+ if(!pIn || !pIn->IsConnected()) {
+ return E_UNEXPECTED;
+ }
CComPtr<IMemAllocator> pAllocatorIn;
pIn->GetAllocator(&pAllocatorIn);
- if(!pAllocatorIn) return E_UNEXPECTED;
+ if(!pAllocatorIn) {
+ return E_UNEXPECTED;
+ }
HRESULT hr;
- if(FAILED(hr = pAllocatorIn->GetProperties(pProperties)))
+ if(FAILED(hr = pAllocatorIn->GetProperties(pProperties))) {
return hr;
+ }
- if(pProperties->cBuffers < 8 && pIn->CurrentMediaType().majortype == MEDIATYPE_Audio)
+ if(pProperties->cBuffers < 8 && pIn->CurrentMediaType().majortype == MEDIATYPE_Audio) {
pProperties->cBuffers = 8;
+ }
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR);
+ ? E_FAIL
+ : NOERROR);
}
// virtual
class __declspec(uuid("AEFA5024-215A-4FC7-97A4-1043C86FD0B8"))
-MatrixMixer {};
+ MatrixMixer {};
HRESULT CStreamSwitcherOutputPin::CheckConnect(IPin* pPin)
{
CComPtr<IBaseFilter> pBF = GetFilterFromPin(pPin);
- return
+ return
IsAudioWaveRenderer(pBF) || GetCLSID(pBF) == __uuidof(MatrixMixer)
- ? __super::CheckConnect(pPin)
+ ? __super::CheckConnect(pPin)
: E_FAIL;
-// return CComQIPtr<IPinConnection>(pPin) ? CBaseOutputPin::CheckConnect(pPin) : E_NOINTERFACE;
-// return CBaseOutputPin::CheckConnect(pPin);
+ // return CComQIPtr<IPinConnection>(pPin) ? CBaseOutputPin::CheckConnect(pPin) : E_NOINTERFACE;
+ // return CBaseOutputPin::CheckConnect(pPin);
}
HRESULT CStreamSwitcherOutputPin::BreakConnect()
@@ -943,27 +1043,32 @@ HRESULT CStreamSwitcherOutputPin::CheckMediaType(const CMediaType* pmt)
HRESULT CStreamSwitcherOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
{
CStreamSwitcherInputPin* pIn = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetInputPin();
- if(!pIn || !pIn->IsConnected()) return E_UNEXPECTED;
+ if(!pIn || !pIn->IsConnected()) {
+ return E_UNEXPECTED;
+ }
CComPtr<IEnumMediaTypes> pEM;
- if(FAILED(pIn->GetConnected()->EnumMediaTypes(&pEM)))
+ if(FAILED(pIn->GetConnected()->EnumMediaTypes(&pEM))) {
return VFW_S_NO_MORE_ITEMS;
+ }
- if(iPosition > 0 && FAILED(pEM->Skip(iPosition)))
+ if(iPosition > 0 && FAILED(pEM->Skip(iPosition))) {
return VFW_S_NO_MORE_ITEMS;
+ }
AM_MEDIA_TYPE* tmp = NULL;
- if(S_OK != pEM->Next(1, &tmp, NULL) || !tmp)
+ if(S_OK != pEM->Next(1, &tmp, NULL) || !tmp) {
return VFW_S_NO_MORE_ITEMS;
+ }
CopyMediaType(pmt, tmp);
DeleteMediaType(tmp);
-/*
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ /*
+ if(iPosition < 0) return E_INVALIDARG;
+ if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
- CopyMediaType(pmt, &pIn->CurrentMediaType());
-*/
+ CopyMediaType(pmt, &pIn->CurrentMediaType());
+ */
return S_OK;
}
@@ -972,7 +1077,9 @@ HRESULT CStreamSwitcherOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
STDMETHODIMP CStreamSwitcherOutputPin::QueryAccept(const AM_MEDIA_TYPE* pmt)
{
HRESULT hr = __super::QueryAccept(pmt);
- if(S_OK != hr) return hr;
+ if(S_OK != hr) {
+ return hr;
+ }
return QueryAcceptUpstream(pmt);
}
@@ -982,8 +1089,10 @@ STDMETHODIMP CStreamSwitcherOutputPin::QueryAccept(const AM_MEDIA_TYPE* pmt)
STDMETHODIMP CStreamSwitcherOutputPin::Notify(IBaseFilter* pSender, Quality q)
{
CStreamSwitcherInputPin* pIn = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetInputPin();
- if(!pIn || !pIn->IsConnected()) return VFW_E_NOT_CONNECTED;
- return pIn->PassNotify(q);
+ if(!pIn || !pIn->IsConnected()) {
+ return VFW_E_NOT_CONNECTED;
+ }
+ return pIn->PassNotify(q);
}
// IStreamBuilder
@@ -992,13 +1101,11 @@ STDMETHODIMP CStreamSwitcherOutputPin::Render(IPin* ppinOut, IGraphBuilder* pGra
{
CComPtr<IBaseFilter> pBF;
pBF.CoCreateInstance(CLSID_DSoundRender);
- if(!pBF || FAILED(pGraph->AddFilter(pBF, L"Default DirectSound Device")))
- {
+ if(!pBF || FAILED(pGraph->AddFilter(pBF, L"Default DirectSound Device"))) {
return E_FAIL;
}
- if(FAILED(pGraph->ConnectDirect(ppinOut, GetFirstDisconnectedPin(pBF, PINDIR_INPUT), NULL)))
- {
+ if(FAILED(pGraph->ConnectDirect(ppinOut, GetFirstDisconnectedPin(pBF, PINDIR_INPUT), NULL))) {
pGraph->RemoveFilter(pBF);
return E_FAIL;
}
@@ -1015,36 +1122,42 @@ STDMETHODIMP CStreamSwitcherOutputPin::Backout(IPin* ppinOut, IGraphBuilder* pGr
// CStreamSwitcherFilter
//
-CStreamSwitcherFilter::CStreamSwitcherFilter(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
+CStreamSwitcherFilter::CStreamSwitcherFilter(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid)
: CBaseFilter(NAME("CStreamSwitcherFilter"), lpunk, &m_csState, clsid)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
HRESULT hr = S_OK;
- do
- {
+ do {
CAutoPtr<CStreamSwitcherInputPin> pInput;
CAutoPtr<CStreamSwitcherOutputPin> pOutput;
hr = S_OK;
- pInput.Attach(DNew CStreamSwitcherInputPin(this, &hr, L"Channel 1"));
- if(!pInput || FAILED(hr)) break;
+ pInput.Attach(DNew CStreamSwitcherInputPin(this, &hr, L"Channel 1"));
+ if(!pInput || FAILED(hr)) {
+ break;
+ }
hr = S_OK;
pOutput.Attach(DNew CStreamSwitcherOutputPin(this, &hr));
- if(!pOutput || FAILED(hr)) break;
+ if(!pOutput || FAILED(hr)) {
+ break;
+ }
CAutoLock cAutoLock(&m_csPins);
-
+
m_pInputs.AddHead(m_pInput = pInput.Detach());
m_pOutput = pOutput.Detach();
return;
- }
- while(false);
+ } while(false);
- if(phr) *phr = E_FAIL;
+ if(phr) {
+ *phr = E_FAIL;
+ }
}
CStreamSwitcherFilter::~CStreamSwitcherFilter()
@@ -1052,7 +1165,9 @@ CStreamSwitcherFilter::~CStreamSwitcherFilter()
CAutoLock cAutoLock(&m_csPins);
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos) delete m_pInputs.GetNext(pos);
+ while(pos) {
+ delete m_pInputs.GetNext(pos);
+ }
m_pInputs.RemoveAll();
m_pInput = NULL;
@@ -1080,9 +1195,13 @@ CBasePin* CStreamSwitcherFilter::GetPin(int n)
{
CAutoLock cAutoLock(&m_csPins);
- if(n < 0 || n >= GetPinCount()) return NULL;
- else if(n == 0) return m_pOutput;
- else return m_pInputs.GetAt(m_pInputs.FindIndex(n-1));
+ if(n < 0 || n >= GetPinCount()) {
+ return NULL;
+ } else if(n == 0) {
+ return m_pOutput;
+ } else {
+ return m_pInputs.GetAt(m_pInputs.FindIndex(n-1));
+ }
}
int CStreamSwitcherFilter::GetConnectedInputPinCount()
@@ -1092,10 +1211,10 @@ int CStreamSwitcherFilter::GetConnectedInputPinCount()
int nConnected = 0;
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
- if(m_pInputs.GetNext(pos)->IsConnected())
+ while(pos) {
+ if(m_pInputs.GetNext(pos)->IsConnected()) {
nConnected++;
+ }
}
return(nConnected);
@@ -1103,15 +1222,14 @@ int CStreamSwitcherFilter::GetConnectedInputPinCount()
CStreamSwitcherInputPin* CStreamSwitcherFilter::GetConnectedInputPin(int n)
{
- if(n >= 0)
- {
+ if(n >= 0) {
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CStreamSwitcherInputPin* pPin = m_pInputs.GetNext(pos);
- if(pPin->IsConnected())
- {
- if(n == 0) return(pPin);
+ if(pPin->IsConnected()) {
+ if(n == 0) {
+ return(pPin);
+ }
n--;
}
}
@@ -1134,26 +1252,22 @@ CStreamSwitcherOutputPin* CStreamSwitcherFilter::GetOutputPin()
HRESULT CStreamSwitcherFilter::CompleteConnect(PIN_DIRECTION dir, CBasePin* pPin, IPin* pReceivePin)
{
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
CAutoLock cAutoLock(&m_csPins);
int nConnected = GetConnectedInputPinCount();
- if(nConnected == 1)
- {
+ if(nConnected == 1) {
m_pInput = static_cast<CStreamSwitcherInputPin*>(pPin);
}
- if((size_t)nConnected == m_pInputs.GetCount())
- {
+ if((size_t)nConnected == m_pInputs.GetCount()) {
CStringW name;
name.Format(L"Channel %d", ++m_PinVersion);
HRESULT hr = S_OK;
CStreamSwitcherInputPin* pPin = DNew CStreamSwitcherInputPin(this, &hr, name);
- if(!pPin || FAILED(hr))
- {
+ if(!pPin || FAILED(hr)) {
delete pPin;
return E_FAIL;
}
@@ -1173,8 +1287,7 @@ void CStreamSwitcherFilter::SelectInput(CStreamSwitcherInputPin* pInput)
// release blocked GetBuffer in our own allocator & block all Receive
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CStreamSwitcherInputPin* pPin = m_pInputs.GetNext(pos);
pPin->Block(false);
// a few Receive calls can arrive here, but since m_pInput == NULL neighter of them gets delivered
@@ -1182,13 +1295,14 @@ void CStreamSwitcherFilter::SelectInput(CStreamSwitcherInputPin* pInput)
}
// this will let waiting GetBuffer() calls go on inside our Receive()
- if(m_pOutput)
- {
+ if(m_pOutput) {
m_pOutput->DeliverBeginFlush();
m_pOutput->DeliverEndFlush();
}
- if(!pInput) return;
+ if(!pInput) {
+ return;
+ }
// set new input
m_pInput = pInput;
@@ -1205,13 +1319,19 @@ HRESULT CStreamSwitcherFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
BYTE* pDataOut = NULL;
HRESULT hr;
- if(FAILED(hr = pIn->GetPointer(&pDataIn))) return hr;
- if(FAILED(hr = pOut->GetPointer(&pDataOut))) return hr;
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
+ return hr;
+ }
+ if(FAILED(hr = pOut->GetPointer(&pDataOut))) {
+ return hr;
+ }
long len = pIn->GetActualDataLength();
long size = pOut->GetSize();
- if(!pDataIn || !pDataOut /*|| len > size || len <= 0*/) return S_FALSE; // FIXME
+ if(!pDataIn || !pDataOut /*|| len > size || len <= 0*/) {
+ return S_FALSE; // FIXME
+ }
memcpy(pDataOut, pDataIn, min(len, size));
pOut->SetActualDataLength(min(len, size));
@@ -1248,7 +1368,9 @@ HRESULT CStreamSwitcherFilter::DeliverNewSegment(REFERENCE_TIME tStart, REFERENC
STDMETHODIMP CStreamSwitcherFilter::Count(DWORD* pcStreams)
{
- if(!pcStreams) return E_POINTER;
+ if(!pcStreams) {
+ return E_POINTER;
+ }
CAutoLock cAutoLock(&m_csPins);
@@ -1262,45 +1384,56 @@ STDMETHODIMP CStreamSwitcherFilter::Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWOR
CAutoLock cAutoLock(&m_csPins);
CBasePin* pPin = GetConnectedInputPin(lIndex);
- if(!pPin) return E_INVALIDARG;
+ if(!pPin) {
+ return E_INVALIDARG;
+ }
- if(ppmt)
+ if(ppmt) {
*ppmt = CreateMediaType(&m_pOutput->CurrentMediaType());
+ }
- if(pdwFlags)
+ if(pdwFlags) {
*pdwFlags = (m_pInput == pPin) ? AMSTREAMSELECTINFO_EXCLUSIVE : 0;
+ }
- if(plcid)
+ if(plcid) {
*plcid = 0;
+ }
- if(pdwGroup)
+ if(pdwGroup) {
*pdwGroup = 0;
+ }
- if(ppszName)
- {
+ if(ppszName) {
*ppszName = (WCHAR*)CoTaskMemAlloc((wcslen(pPin->Name())+1)*sizeof(WCHAR));
- if(*ppszName)
+ if(*ppszName) {
wcscpy(*ppszName, pPin->Name());
+ }
}
- if(ppObject)
+ if(ppObject) {
*ppObject = NULL;
+ }
- if(ppUnk)
+ if(ppUnk) {
*ppUnk = NULL;
+ }
return S_OK;
}
STDMETHODIMP CStreamSwitcherFilter::Enable(long lIndex, DWORD dwFlags)
{
- if(dwFlags != AMSTREAMSELECTENABLE_ENABLE)
+ if(dwFlags != AMSTREAMSELECTENABLE_ENABLE) {
return E_NOTIMPL;
+ }
PauseGraph;
CStreamSwitcherInputPin* pNewInput = GetConnectedInputPin(lIndex);
- if(!pNewInput) return E_INVALIDARG;
+ if(!pNewInput) {
+ return E_INVALIDARG;
+ }
SelectInput(pNewInput);
diff --git a/src/filters/switcher/AudioSwitcher/StreamSwitcher.h b/src/filters/switcher/AudioSwitcher/StreamSwitcher.h
index be5a6fc32..714524b64 100644
--- a/src/filters/switcher/AudioSwitcher/StreamSwitcher.h
+++ b/src/filters/switcher/AudioSwitcher/StreamSwitcher.h
@@ -32,14 +32,14 @@
CComQIPtr<IMediaSeeking> _pMS((IUnknown*)(INonDelegatingUnknown*)m_pGraph); \
LONGLONG _rtNow = 0; \
if(_pMS) _hr = _pMS->GetCurrentPosition(&_rtNow); \
-
+
#define ResumeGraph \
if(SUCCEEDED(_hr) && _pMS && _fs != State_Stopped) \
_hr = _pMS->SetPositions(&_rtNow, AM_SEEKING_AbsolutePositioning, NULL, AM_SEEKING_NoPositioning); \
\
if(_fs == State_Running && _pMS) \
_pMC->Run(); \
-
+
class CStreamSwitcherFilter;
class CStreamSwitcherPassThru : public IMediaSeeking, public CMediaPosition
@@ -48,42 +48,42 @@ protected:
CStreamSwitcherFilter* m_pFilter;
public:
- CStreamSwitcherPassThru(LPUNKNOWN, HRESULT* phr, CStreamSwitcherFilter* pFilter);
+ CStreamSwitcherPassThru(LPUNKNOWN, HRESULT* phr, CStreamSwitcherFilter* pFilter);
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- // IMediaSeeking methods
- STDMETHODIMP GetCapabilities(DWORD* pCapabilities);
- STDMETHODIMP CheckCapabilities(DWORD* pCapabilities);
- STDMETHODIMP SetTimeFormat(const GUID* pFormat);
- STDMETHODIMP GetTimeFormat(GUID* pFormat);
- STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat);
- STDMETHODIMP IsFormatSupported(const GUID* pFormat);
- STDMETHODIMP QueryPreferredFormat(GUID* pFormat);
- STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat);
- STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD CurrentFlags, LONGLONG* pStop, DWORD StopFlags);
- STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop);
- STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent);
- STDMETHODIMP GetStopPosition(LONGLONG* pStop);
- STDMETHODIMP SetRate(double dRate);
- STDMETHODIMP GetRate(double* pdRate);
- STDMETHODIMP GetDuration(LONGLONG* pDuration);
- STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest);
- STDMETHODIMP GetPreroll(LONGLONG* pllPreroll);
-
- // IMediaPosition properties
- STDMETHODIMP get_Duration(REFTIME* plength);
- STDMETHODIMP put_CurrentPosition(REFTIME llTime);
- STDMETHODIMP get_StopTime(REFTIME* pllTime);
- STDMETHODIMP put_StopTime(REFTIME llTime);
- STDMETHODIMP get_PrerollTime(REFTIME* pllTime);
- STDMETHODIMP put_PrerollTime(REFTIME llTime);
- STDMETHODIMP get_Rate(double* pdRate);
- STDMETHODIMP put_Rate(double dRate);
- STDMETHODIMP get_CurrentPosition(REFTIME* pllTime);
- STDMETHODIMP CanSeekForward(LONG* pCanSeekForward);
- STDMETHODIMP CanSeekBackward(LONG* pCanSeekBackward);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ // IMediaSeeking methods
+ STDMETHODIMP GetCapabilities(DWORD* pCapabilities);
+ STDMETHODIMP CheckCapabilities(DWORD* pCapabilities);
+ STDMETHODIMP SetTimeFormat(const GUID* pFormat);
+ STDMETHODIMP GetTimeFormat(GUID* pFormat);
+ STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat);
+ STDMETHODIMP IsFormatSupported(const GUID* pFormat);
+ STDMETHODIMP QueryPreferredFormat(GUID* pFormat);
+ STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat);
+ STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD CurrentFlags, LONGLONG* pStop, DWORD StopFlags);
+ STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop);
+ STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent);
+ STDMETHODIMP GetStopPosition(LONGLONG* pStop);
+ STDMETHODIMP SetRate(double dRate);
+ STDMETHODIMP GetRate(double* pdRate);
+ STDMETHODIMP GetDuration(LONGLONG* pDuration);
+ STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest);
+ STDMETHODIMP GetPreroll(LONGLONG* pllPreroll);
+
+ // IMediaPosition properties
+ STDMETHODIMP get_Duration(REFTIME* plength);
+ STDMETHODIMP put_CurrentPosition(REFTIME llTime);
+ STDMETHODIMP get_StopTime(REFTIME* pllTime);
+ STDMETHODIMP put_StopTime(REFTIME llTime);
+ STDMETHODIMP get_PrerollTime(REFTIME* pllTime);
+ STDMETHODIMP put_PrerollTime(REFTIME llTime);
+ STDMETHODIMP get_Rate(double* pdRate);
+ STDMETHODIMP put_Rate(double dRate);
+ STDMETHODIMP get_CurrentPosition(REFTIME* pllTime);
+ STDMETHODIMP CanSeekForward(LONG* pCanSeekForward);
+ STDMETHODIMP CanSeekBackward(LONG* pCanSeekBackward);
};
class CStreamSwitcherInputPin;
@@ -91,9 +91,9 @@ class CStreamSwitcherInputPin;
class CStreamSwitcherAllocator : public CMemAllocator
{
protected:
- CStreamSwitcherInputPin* m_pPin;
+ CStreamSwitcherInputPin* m_pPin;
- CMediaType m_mt;
+ CMediaType m_mt;
bool m_fMediaTypeChanged;
public:
@@ -106,16 +106,16 @@ public:
STDMETHODIMP_(ULONG) NonDelegatingRelease();
STDMETHODIMP GetBuffer(
- IMediaSample** ppBuffer,
- REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime,
+ IMediaSample** ppBuffer,
+ REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime,
DWORD dwFlags);
void NotifyMediaType(const CMediaType& mt);
};
interface __declspec(uuid("DA395FA3-4A3E-4D85-805E-0BEFF53D4BCD"))
-IStreamSwitcherInputPin : public IUnknown
-{
+IStreamSwitcherInputPin :
+public IUnknown {
STDMETHOD_(bool, IsActive)() = 0;
};
@@ -141,15 +141,21 @@ class CStreamSwitcherInputPin : public CBaseInputPin, public IPinConnection, pub
HANDLE m_hNotifyEvent;
public:
- CStreamSwitcherInputPin(CStreamSwitcherFilter* pFilter, HRESULT* phr, LPCWSTR pName);
+ CStreamSwitcherInputPin(CStreamSwitcherFilter* pFilter, HRESULT* phr, LPCWSTR pName);
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
- CMediaType& CurrentMediaType() {return m_mt;}
- IMemAllocator* CurrentAllocator() {return m_pAllocator;}
+ CMediaType& CurrentMediaType() {
+ return m_mt;
+ }
+ IMemAllocator* CurrentAllocator() {
+ return m_pAllocator;
+ }
- bool IsUsingOwnAllocator() {return m_bUsingOwnAllocator == TRUE;}
+ bool IsUsingOwnAllocator() {
+ return m_bUsingOwnAllocator == TRUE;
+ }
void Block(bool fBlock);
@@ -168,11 +174,11 @@ public:
STDMETHODIMP GetAllocator(IMemAllocator** ppAllocator);
STDMETHODIMP NotifyAllocator(IMemAllocator* pAllocator, BOOL bReadOnly);
STDMETHODIMP BeginFlush();
- STDMETHODIMP EndFlush();
+ STDMETHODIMP EndFlush();
STDMETHODIMP EndOfStream();
// IMemInputPin
- STDMETHODIMP Receive(IMediaSample* pSample);
+ STDMETHODIMP Receive(IMediaSample* pSample);
STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
// IPinConnection
@@ -193,14 +199,20 @@ class CStreamSwitcherOutputPin : public CBaseOutputPin, public IStreamBuilder
HRESULT QueryAcceptUpstream(const AM_MEDIA_TYPE* pmt);
public:
- CStreamSwitcherOutputPin(CStreamSwitcherFilter* pFilter, HRESULT* phr);
+ CStreamSwitcherOutputPin(CStreamSwitcherFilter* pFilter, HRESULT* phr);
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
-
- CMediaType& CurrentMediaType() {return m_mt;}
- IMemAllocator* CurrentAllocator() {return m_pAllocator;}
- IPinConnection* CurrentPinConnection() {return m_pPinConnection;}
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+
+ CMediaType& CurrentMediaType() {
+ return m_mt;
+ }
+ IMemAllocator* CurrentAllocator() {
+ return m_pAllocator;
+ }
+ IPinConnection* CurrentPinConnection() {
+ return m_pPinConnection;
+ }
// pure virtual
HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
@@ -246,7 +258,7 @@ public:
virtual ~CStreamSwitcherFilter();
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
int GetPinCount();
CBasePin* GetPin(int n);
@@ -257,7 +269,9 @@ public:
CStreamSwitcherOutputPin* GetOutputPin();
bool m_fResetOutputMediaType;
- void ResetOutputMediaType() {m_fResetOutputMediaType = true;}
+ void ResetOutputMediaType() {
+ m_fResetOutputMediaType = true;
+ }
// override these
virtual HRESULT CheckMediaType(const CMediaType* pmt) = 0;
@@ -266,14 +280,14 @@ public:
virtual void OnNewOutputMediaType(const CMediaType& mtIn, const CMediaType& mtOut) {}
// and maybe these
- virtual HRESULT DeliverEndOfStream();
- virtual HRESULT DeliverBeginFlush();
- virtual HRESULT DeliverEndFlush();
- virtual HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ virtual HRESULT DeliverEndOfStream();
+ virtual HRESULT DeliverBeginFlush();
+ virtual HRESULT DeliverEndFlush();
+ virtual HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
// IAMStreamSelect
- STDMETHODIMP Count(DWORD* pcStreams);
- STDMETHODIMP Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD* pdwFlags, LCID* plcid, DWORD* pdwGroup, WCHAR** ppszName, IUnknown** ppObject, IUnknown** ppUnk);
- STDMETHODIMP Enable(long lIndex, DWORD dwFlags);
+ STDMETHODIMP Count(DWORD* pcStreams);
+ STDMETHODIMP Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD* pdwFlags, LCID* plcid, DWORD* pdwGroup, WCHAR** ppszName, IUnknown** ppObject, IUnknown** ppUnk);
+ STDMETHODIMP Enable(long lIndex, DWORD dwFlags);
};
diff --git a/src/filters/switcher/AudioSwitcher/stdafx.cpp b/src/filters/switcher/AudioSwitcher/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/switcher/AudioSwitcher/stdafx.cpp
+++ b/src/filters/switcher/AudioSwitcher/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/switcher/AudioSwitcher/stdafx.h b/src/filters/switcher/AudioSwitcher/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/switcher/AudioSwitcher/stdafx.h
+++ b/src/filters/switcher/AudioSwitcher/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.cpp b/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.cpp
index 412e860c6..24394dd83 100644
--- a/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.cpp
+++ b/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -29,31 +29,26 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_WAVE_DOLBY_AC3},
{&MEDIATYPE_Audio, &MEDIASUBTYPE_WAVE_DTS},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CAVI2AC3Filter), L"MPC - AVI<->AC3/DTS", MERIT_NORMAL, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CAVI2AC3Filter>, NULL, &sudFilter[0]}
+CFactoryTemplate g_Templates[] = {
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CAVI2AC3Filter>, NULL, &sudFilter[0]}
};
int g_cTemplates = countof(g_Templates);
@@ -79,9 +74,11 @@ CFilterApp theApp;
//
CAVI2AC3Filter::CAVI2AC3Filter(LPUNKNOWN lpunk, HRESULT* phr)
- : CTransformFilter(NAME("CAVI2AC3Filter"), lpunk, __uuidof(this))
+ : CTransformFilter(NAME("CAVI2AC3Filter"), lpunk, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CAVI2AC3Filter::~CAVI2AC3Filter()
@@ -93,77 +90,76 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
HRESULT hr;
BYTE* pIn = NULL;
- if(FAILED(hr = pSample->GetPointer(&pIn))) return hr;
+ if(FAILED(hr = pSample->GetPointer(&pIn))) {
+ return hr;
+ }
BYTE* pInOrg = pIn;
long len = pSample->GetActualDataLength();
- if(len <= 0) return S_FALSE;
+ if(len <= 0) {
+ return S_FALSE;
+ }
BYTE* pOut = NULL;
- if(FAILED(hr = pOutSample->GetPointer(&pOut))) return hr;
+ if(FAILED(hr = pOutSample->GetPointer(&pOut))) {
+ return hr;
+ }
BYTE* pOutOrg = pOut;
int size = pOutSample->GetSize();
if((CheckAC3(&m_pInput->CurrentMediaType()) || CheckDTS(&m_pInput->CurrentMediaType()))
- && (CheckWAVEAC3(&m_pOutput->CurrentMediaType()) || CheckWAVEDTS(&m_pOutput->CurrentMediaType())))
- {
- if(*(DWORD*)pIn == 0xBA010000)
- {
+ && (CheckWAVEAC3(&m_pOutput->CurrentMediaType()) || CheckWAVEDTS(&m_pOutput->CurrentMediaType()))) {
+ if(*(DWORD*)pIn == 0xBA010000) {
pIn += 14;
}
- if(*(DWORD*)pIn == 0xBD010000)
- {
+ if(*(DWORD*)pIn == 0xBD010000) {
pIn += 8 + 1 + pIn[8] + 1 + 3;
}
len -= (pInOrg - pIn);
- if(size < len) return E_FAIL;
+ if(size < len) {
+ return E_FAIL;
+ }
memcpy(pOut, pIn, len);
pOut += len;
- }
- else if((CheckWAVEAC3(&m_pInput->CurrentMediaType()) || CheckWAVEDTS(&m_pInput->CurrentMediaType()))
- && (CheckAC3(&m_pOutput->CurrentMediaType()) || CheckDTS(&m_pOutput->CurrentMediaType())))
- {
+ } else if((CheckWAVEAC3(&m_pInput->CurrentMediaType()) || CheckWAVEDTS(&m_pInput->CurrentMediaType()))
+ && (CheckAC3(&m_pOutput->CurrentMediaType()) || CheckDTS(&m_pOutput->CurrentMediaType()))) {
if((m_pOutput->CurrentMediaType().majortype == MEDIATYPE_DVD_ENCRYPTED_PACK
- || m_pOutput->CurrentMediaType().majortype == MEDIATYPE_MPEG2_PES)
- && (len + 12 + 3) >= 0x10000) // damn, this can happen if the interleave time is too big
- {
+ || m_pOutput->CurrentMediaType().majortype == MEDIATYPE_MPEG2_PES)
+ && (len + 12 + 3) >= 0x10000) { // damn, this can happen if the interleave time is too big
REFERENCE_TIME rtStart = 0, rtStop = 1;
bool fHasTime = (S_OK == pSample->GetTime(&rtStart, &rtStop));
bool fDiscontinuity = (S_OK == pOutSample->IsDiscontinuity());
int pos = 0;
- while(pos < len)
- {
+ while(pos < len) {
int curlen = min(len - pos, 2013);
pos += 2013;
CComPtr<IMediaSample> pOutSample;
hr = InitializeOutputSample(pSample, &pOutSample);
- if(fDiscontinuity)
- {
- if(fHasTime)
- {
+ if(fDiscontinuity) {
+ if(fHasTime) {
rtStop = rtStart + (rtStop - rtStart) * curlen / len;
pOutSample->SetTime(&rtStart, &rtStop);
}
fDiscontinuity = false;
- }
- else
- {
+ } else {
pOutSample->SetTime(NULL, NULL);
pOutSample->SetDiscontinuity(FALSE);
}
BYTE* pOut = NULL;
- if(FAILED(hr = pOutSample->GetPointer(&pOut))) return hr;
+ if(FAILED(hr = pOutSample->GetPointer(&pOut))) {
+ return hr;
+ }
BYTE* pOutOrg = pOut;
int size = pOutSample->GetSize();
@@ -171,12 +167,12 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
const GUID* majortype = &m_pOutput->CurrentMediaType().majortype;
const GUID* subtype = &m_pOutput->CurrentMediaType().subtype;
- if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- {
- if(size < curlen + 32 + 3) return E_FAIL;
+ if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK) {
+ if(size < curlen + 32 + 3) {
+ return E_FAIL;
+ }
- BYTE PESHeader[] =
- {
+ BYTE PESHeader[] = {
0x00,0x00,0x01,0xBA, // PES id
0x44,0x00,0x04,0x00,0x04,0x01, // SCR (0)
0x01,0x89,0xC3,0xF8, // mux rate (1260000 bytes/sec, 22bits), marker (2bits), reserved (~0, 5bits), stuffing (0, 3bits)
@@ -188,12 +184,12 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
majortype = &MEDIATYPE_MPEG2_PES;
}
- if(*majortype == MEDIATYPE_MPEG2_PES)
- {
- if(size < curlen + 20 + 3) return E_FAIL;
+ if(*majortype == MEDIATYPE_MPEG2_PES) {
+ if(size < curlen + 20 + 3) {
+ return E_FAIL;
+ }
- BYTE Private1Header[] =
- {
+ BYTE Private1Header[] = {
0x00,0x00,0x01,0xBD, // private stream 1 id
0x07,0xEC, // packet length (TODO: modify it later)
0x81,0x80, // marker, original, PTS - flags
@@ -209,30 +205,22 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
Private1Header[4] = (packetlen>>8)&0xff;
Private1Header[5] = packetlen&0xff;
- if(*subtype == MEDIASUBTYPE_DTS)
- {
+ if(*subtype == MEDIASUBTYPE_DTS) {
Private1Header[17] += 8;
}
- if(*subtype == MEDIASUBTYPE_DOLBY_AC3)
- {
- for(int i = 0; i < curlen; i++)
- {
- if(*(DWORD*)&pIn[i] == 0x770B)
- {
+ if(*subtype == MEDIASUBTYPE_DOLBY_AC3) {
+ for(int i = 0; i < curlen; i++) {
+ if(*(DWORD*)&pIn[i] == 0x770B) {
i++;
Private1Header[19] = (i>>8)&0xff;
Private1Header[20] = i&0xff;
break;
}
}
- }
- else if(*subtype == MEDIASUBTYPE_DTS)
- {
- for(int i = 0; i < curlen; i++)
- {
- if(*(DWORD*)&pIn[i] == 0x0180FE7F)
- {
+ } else if(*subtype == MEDIASUBTYPE_DTS) {
+ for(int i = 0; i < curlen; i++) {
+ if(*(DWORD*)&pIn[i] == 0x0180FE7F) {
i++;
Private1Header[19] = (i>>8)&0xff;
Private1Header[20] = i&0xff;
@@ -247,9 +235,10 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
majortype = &MEDIATYPE_Audio;
}
- if(*majortype == MEDIATYPE_Audio)
- {
- if(size < curlen) return E_FAIL;
+ if(*majortype == MEDIATYPE_Audio) {
+ if(size < curlen) {
+ return E_FAIL;
+ }
memcpy(pOut, pIn, curlen);
pIn += curlen;
pOut += curlen;
@@ -261,18 +250,16 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
}
return S_FALSE;
- }
- else // phew, we can do the easier way
- {
+ } else { // phew, we can do the easier way
const GUID* majortype = &m_pOutput->CurrentMediaType().majortype;
const GUID* subtype = &m_pOutput->CurrentMediaType().subtype;
- if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- {
- if(size < len + 32 + 3) return E_FAIL;
+ if(*majortype == MEDIATYPE_DVD_ENCRYPTED_PACK) {
+ if(size < len + 32 + 3) {
+ return E_FAIL;
+ }
- BYTE PESHeader[] =
- {
+ BYTE PESHeader[] = {
0x00,0x00,0x01,0xBA, // PES id
0x44,0x00,0x04,0x00,0x04,0x01, // SCR (0)
0x01,0x89,0xC3,0xF8, // mux rate (1260000 bytes/sec, 22bits), marker (2bits), reserved (~0, 5bits), stuffing (0, 3bits)
@@ -284,12 +271,12 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
majortype = &MEDIATYPE_MPEG2_PES;
}
- if(*majortype == MEDIATYPE_MPEG2_PES)
- {
- if(size < len + 20 + 3) return E_FAIL;
+ if(*majortype == MEDIATYPE_MPEG2_PES) {
+ if(size < len + 20 + 3) {
+ return E_FAIL;
+ }
- BYTE Private1Header[] =
- {
+ BYTE Private1Header[] = {
0x00,0x00,0x01,0xBD, // private stream 1 id
0x07,0xEC, // packet length (TODO: modify it later)
0x81,0x80, // marker, original, PTS - flags
@@ -305,8 +292,7 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
Private1Header[4] = (packetlen>>8)&0xff;
Private1Header[5] = packetlen&0xff;
- if(*subtype == MEDIASUBTYPE_DTS)
- {
+ if(*subtype == MEDIASUBTYPE_DTS) {
Private1Header[17] += 8;
}
@@ -316,18 +302,17 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
majortype = &MEDIATYPE_Audio;
}
- if(*majortype == MEDIATYPE_Audio)
- {
- if(size < len) return E_FAIL;
+ if(*majortype == MEDIATYPE_Audio) {
+ if(size < len) {
+ return E_FAIL;
+ }
memcpy(pOut, pIn, len);
pIn += len;
pOut += len;
}
}
- }
- else
- {
+ } else {
return E_FAIL;
}
@@ -339,33 +324,33 @@ HRESULT CAVI2AC3Filter::Transform(IMediaSample* pSample, IMediaSample* pOutSampl
bool CAVI2AC3Filter::CheckAC3(const CMediaType* pmt)
{
return (pmt->majortype == MEDIATYPE_Audio
- || pmt->majortype == MEDIATYPE_MPEG2_PES
+ || pmt->majortype == MEDIATYPE_MPEG2_PES
|| pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
+ && pmt->subtype == MEDIASUBTYPE_DOLBY_AC3;
}
bool CAVI2AC3Filter::CheckDTS(const CMediaType* pmt)
{
return (pmt->majortype == MEDIATYPE_Audio
- || pmt->majortype == MEDIATYPE_MPEG2_PES
+ || pmt->majortype == MEDIATYPE_MPEG2_PES
|| pmt->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK)
- && pmt->subtype == MEDIASUBTYPE_DTS;
+ && pmt->subtype == MEDIASUBTYPE_DTS;
}
bool CAVI2AC3Filter::CheckWAVEAC3(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3;
+ && pmt->subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3;
}
bool CAVI2AC3Filter::CheckWAVEDTS(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Audio
- && pmt->subtype == MEDIASUBTYPE_WAVE_DTS
- && pmt->formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS;
+ && pmt->subtype == MEDIASUBTYPE_WAVE_DTS
+ && pmt->formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS;
}
HRESULT CAVI2AC3Filter::CheckInputType(const CMediaType* mtIn)
@@ -373,28 +358,32 @@ HRESULT CAVI2AC3Filter::CheckInputType(const CMediaType* mtIn)
bool fWaveFormatEx = !!(mtIn->formattype == FORMAT_WaveFormatEx);
return CheckAC3(mtIn) && fWaveFormatEx || CheckDTS(mtIn) && fWaveFormatEx
- || CheckWAVEAC3(mtIn) || CheckWAVEDTS(mtIn)
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ || CheckWAVEAC3(mtIn) || CheckWAVEDTS(mtIn)
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CAVI2AC3Filter::CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut)
{
return CheckAC3(mtIn) && CheckWAVEAC3(mtOut)
- || CheckWAVEAC3(mtIn) && CheckAC3(mtOut)
- || CheckDTS(mtIn) && CheckWAVEDTS(mtOut)
- || CheckWAVEDTS(mtIn) && CheckDTS(mtOut)
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ || CheckWAVEAC3(mtIn) && CheckAC3(mtOut)
+ || CheckDTS(mtIn) && CheckWAVEDTS(mtOut)
+ || CheckWAVEDTS(mtIn) && CheckDTS(mtOut)
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CAVI2AC3Filter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
CComPtr<IMemAllocator> pAllocatorIn;
m_pInput->GetAllocator(&pAllocatorIn);
- if(!pAllocatorIn) return E_UNEXPECTED;
+ if(!pAllocatorIn) {
+ return E_UNEXPECTED;
+ }
pAllocatorIn->GetProperties(pProperties);
@@ -405,26 +394,32 @@ HRESULT CAVI2AC3Filter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PR
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
- return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR);
+ return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
+ ? E_FAIL
+ : NOERROR);
}
HRESULT CAVI2AC3Filter::GetMediaType(int iPosition, CMediaType* pMediaType)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
const GUID& majortype = m_pInput->CurrentMediaType().majortype;
const GUID& subtype = m_pInput->CurrentMediaType().subtype;
UNUSED_ALWAYS(majortype);
-
- if(CheckAC3(&m_pInput->CurrentMediaType()) || CheckDTS(&m_pInput->CurrentMediaType()))
- {
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+
+ if(CheckAC3(&m_pInput->CurrentMediaType()) || CheckDTS(&m_pInput->CurrentMediaType())) {
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pMediaType->majortype = MEDIATYPE_Audio;
@@ -438,44 +433,38 @@ HRESULT CAVI2AC3Filter::GetMediaType(int iPosition, CMediaType* pMediaType)
wfe->nChannels = 2;
wfe->nBlockAlign = 1;
- if(subtype == MEDIASUBTYPE_DOLBY_AC3)
- {
+ if(subtype == MEDIASUBTYPE_DOLBY_AC3) {
pMediaType->subtype = MEDIASUBTYPE_WAVE_DOLBY_AC3;
wfe->wFormatTag = WAVE_FORMAT_DOLBY_AC3;
- }
- else if(subtype == MEDIASUBTYPE_DTS)
- {
+ } else if(subtype == MEDIASUBTYPE_DTS) {
pMediaType->subtype = MEDIASUBTYPE_WAVE_DTS;
wfe->wFormatTag = WAVE_FORMAT_DVD_DTS;
+ } else {
+ return E_INVALIDARG;
}
- else
- {
+ } else if(CheckWAVEAC3(&m_pInput->CurrentMediaType()) || CheckWAVEDTS(&m_pInput->CurrentMediaType())) {
+ if(iPosition < 0) {
return E_INVALIDARG;
}
- }
- else if(CheckWAVEAC3(&m_pInput->CurrentMediaType()) || CheckWAVEDTS(&m_pInput->CurrentMediaType()))
- {
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 4) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition > 4) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
- if(subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3)
- {
+ if(subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3) {
pMediaType->subtype = MEDIASUBTYPE_DOLBY_AC3;
pMediaType->formattype = FORMAT_WaveFormatEx;
DOLBYAC3WAVEFORMAT* wfe = (DOLBYAC3WAVEFORMAT*)pMediaType->AllocFormatBuffer(sizeof(DOLBYAC3WAVEFORMAT));
memset(wfe, 0, sizeof(DOLBYAC3WAVEFORMAT));
- // unfortunately we can't tell what we are going to get in transform,
- // so we just set the most common values and hope that the ac3 decoder
+ // unfortunately we can't tell what we are going to get in transform,
+ // so we just set the most common values and hope that the ac3 decoder
// is flexible enough (it is usually :) to find out these from the bitstream
wfe->wfx.cbSize = sizeof(DOLBYAC3WAVEFORMAT) - sizeof(WAVEFORMATEX);
wfe->wfx.wFormatTag = WAVE_FORMAT_DOLBY_AC3;
wfe->wfx.nSamplesPerSec = 48000;
wfe->wfx.nChannels = 6;
wfe->bBigEndian = TRUE;
- }
- else if(subtype == MEDIASUBTYPE_WAVE_DTS)
- {
+ } else if(subtype == MEDIASUBTYPE_WAVE_DTS) {
pMediaType->subtype = MEDIASUBTYPE_DTS;
pMediaType->formattype = FORMAT_WaveFormatEx;
@@ -486,35 +475,30 @@ HRESULT CAVI2AC3Filter::GetMediaType(int iPosition, CMediaType* pMediaType)
wfe->wFormatTag = WAVE_FORMAT_PCM;
wfe->nSamplesPerSec = 48000;
wfe->nChannels = 6;
- }
- else
- {
+ } else {
return E_INVALIDARG;
}
- switch(iPosition)
- {
- case 0:
- pMediaType->majortype = MEDIATYPE_Audio;
- break;
- case 1:
- pMediaType->ResetFormatBuffer();
- pMediaType->formattype = FORMAT_None;
- case 2:
- pMediaType->majortype = MEDIATYPE_MPEG2_PES;
- break;
- case 3:
- pMediaType->ResetFormatBuffer();
- pMediaType->formattype = FORMAT_None;
- case 4:
- pMediaType->majortype = MEDIATYPE_DVD_ENCRYPTED_PACK;
- break;
- default:
- return E_INVALIDARG;
+ switch(iPosition) {
+ case 0:
+ pMediaType->majortype = MEDIATYPE_Audio;
+ break;
+ case 1:
+ pMediaType->ResetFormatBuffer();
+ pMediaType->formattype = FORMAT_None;
+ case 2:
+ pMediaType->majortype = MEDIATYPE_MPEG2_PES;
+ break;
+ case 3:
+ pMediaType->ResetFormatBuffer();
+ pMediaType->formattype = FORMAT_None;
+ case 4:
+ pMediaType->majortype = MEDIATYPE_DVD_ENCRYPTED_PACK;
+ break;
+ default:
+ return E_INVALIDARG;
}
- }
- else
- {
+ } else {
return VFW_S_NO_MORE_ITEMS;
}
diff --git a/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.h b/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.h
index c199bfa90..f178ef616 100644
--- a/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.h
+++ b/src/filters/transform/AVI2AC3Filter/AVI2AC3Filter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -32,14 +32,13 @@
*/
-typedef struct tagDOLBYAC3WAVEFORMAT
-{
- WAVEFORMATEX wfx;
- BYTE bBigEndian; // TRUE = Big Endian, FALSE little endian
- BYTE bsid;
- BYTE lfeon;
- BYTE copyrightb;
- BYTE nAuxBitsCode; // Aux bits per frame
+typedef struct tagDOLBYAC3WAVEFORMAT {
+ WAVEFORMATEX wfx;
+ BYTE bBigEndian; // TRUE = Big Endian, FALSE little endian
+ BYTE bsid;
+ BYTE lfeon;
+ BYTE copyrightb;
+ BYTE nAuxBitsCode; // Aux bits per frame
} DOLBYAC3WAVEFORMAT;
//
@@ -47,7 +46,7 @@ typedef struct tagDOLBYAC3WAVEFORMAT
//
class __declspec(uuid("93230DD0-7B3C-4efb-AFBB-DC380FEC9E6B"))
-CAVI2AC3Filter : public CTransformFilter
+ CAVI2AC3Filter : public CTransformFilter
{
bool CheckAC3(const CMediaType* pmt);
bool CheckDTS(const CMediaType* pmt);
diff --git a/src/filters/transform/AVI2AC3Filter/stdafx.cpp b/src/filters/transform/AVI2AC3Filter/stdafx.cpp
index 2d8565418..9508867df 100644
--- a/src/filters/transform/AVI2AC3Filter/stdafx.cpp
+++ b/src/filters/transform/AVI2AC3Filter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/AVI2AC3Filter/stdafx.h b/src/filters/transform/AVI2AC3Filter/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/transform/AVI2AC3Filter/stdafx.h
+++ b/src/filters/transform/AVI2AC3Filter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/BaseVideoFilter/BaseVideoFilter.cpp b/src/filters/transform/BaseVideoFilter/BaseVideoFilter.cpp
index a75457d82..e4d902bac 100644
--- a/src/filters/transform/BaseVideoFilter/BaseVideoFilter.cpp
+++ b/src/filters/transform/BaseVideoFilter/BaseVideoFilter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -33,19 +33,30 @@
//
bool f_need_set_aspect;
-CBaseVideoFilter::CBaseVideoFilter(TCHAR* pName, LPUNKNOWN lpunk, HRESULT* phr, REFCLSID clsid, long cBuffers)
+CBaseVideoFilter::CBaseVideoFilter(TCHAR* pName, LPUNKNOWN lpunk, HRESULT* phr, REFCLSID clsid, long cBuffers)
: CTransformFilter(pName, lpunk, clsid)
, m_cBuffers(cBuffers)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pInput = DNew CBaseVideoInputPin(NAME("CBaseVideoInputPin"), this, phr, L"Video");
- if(!m_pInput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!m_pInput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
m_pOutput = DNew CBaseVideoOutputPin(NAME("CBaseVideoOutputPin"), this, phr, L"Output");
- if(!m_pOutput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) {delete m_pInput, m_pInput = NULL; return;}
+ if(!m_pOutput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ delete m_pInput, m_pInput = NULL;
+ return;
+ }
m_wout = m_win = m_w = 0;
m_hout = m_hin = m_h = 0;
@@ -73,10 +84,11 @@ int CBaseVideoFilter::GetPinCount()
CBasePin* CBaseVideoFilter::GetPin(int n)
{
- switch(n)
- {
- case 0: return m_pInput;
- case 1: return m_pOutput;
+ switch(n) {
+ case 0:
+ return m_pInput;
+ case 1:
+ return m_pOutput;
}
return NULL;
}
@@ -92,20 +104,21 @@ HRESULT CBaseVideoFilter::Receive(IMediaSample* pIn)
HRESULT hr;
- AM_SAMPLE2_PROPERTIES* const pProps = m_pInput->SampleProps();
- if(pProps->dwStreamId != AM_STREAM_MEDIA)
+ AM_SAMPLE2_PROPERTIES* const pProps = m_pInput->SampleProps();
+ if(pProps->dwStreamId != AM_STREAM_MEDIA) {
return m_pOutput->Deliver(pIn);
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
m_pInput->SetMediaType(&mt);
DeleteMediaType(pmt);
}
- if(FAILED(hr = Transform(pIn)))
+ if(FAILED(hr = Transform(pIn))) {
return hr;
+ }
return S_OK;
}
@@ -116,15 +129,16 @@ HRESULT CBaseVideoFilter::GetDeliveryBuffer(int w, int h, IMediaSample** ppOut)
HRESULT hr;
- if(FAILED(hr = ReconnectOutput(w, h)))
+ if(FAILED(hr = ReconnectOutput(w, h))) {
return hr;
+ }
- if(FAILED(hr = m_pOutput->GetDeliveryBuffer(ppOut, NULL, NULL, 0)))
+ if(FAILED(hr = m_pOutput->GetDeliveryBuffer(ppOut, NULL, NULL, 0))) {
return hr;
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED((*ppOut)->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED((*ppOut)->GetMediaType(&pmt)) && pmt) {
CMediaType mt = *pmt;
m_pOutput->SetMediaType(&mt);
DeleteMediaType(pmt);
@@ -135,8 +149,9 @@ HRESULT CBaseVideoFilter::GetDeliveryBuffer(int w, int h, IMediaSample** ppOut)
// FIXME: hell knows why but without this the overlay mixer starts very skippy
// (don't enable this for other renderers, the old for example will go crazy if you do)
- if(GetCLSID(m_pOutput->GetConnected()) == CLSID_OverlayMixer)
+ if(GetCLSID(m_pOutput->GetConnected()) == CLSID_OverlayMixer) {
(*ppOut)->SetDiscontinuity(TRUE);
+ }
return S_OK;
}
@@ -146,12 +161,10 @@ HRESULT CBaseVideoFilter::ReconnectOutput(int w, int h, bool bSendSample, int re
CMediaType& mt = m_pOutput->CurrentMediaType();
bool m_update_aspect = false;
- if(f_need_set_aspect)
- {
+ if(f_need_set_aspect) {
int wout = 0, hout = 0, arxout = 0, aryout = 0;
ExtractDim(&mt, wout, hout, arxout, aryout);
- if(arxout != m_arx || aryout != m_ary)
- {
+ if(arxout != m_arx || aryout != m_ary) {
CString debug_s;
debug_s.Format(_T("\nCBaseVideoFilter::ReconnectOutput; wout = %d, hout = %d, current = %dx%d, set = %dx%d\n"), wout, hout, arxout, aryout, m_arx, m_ary);
TRACE(debug_s);
@@ -163,8 +176,7 @@ HRESULT CBaseVideoFilter::ReconnectOutput(int w, int h, bool bSendSample, int re
int h_org = m_h;
bool fForceReconnection = false;
- if(w != m_w || h != m_h)
- {
+ if(w != m_w || h != m_h) {
fForceReconnection = true;
m_w = w;
m_h = h;
@@ -172,52 +184,39 @@ HRESULT CBaseVideoFilter::ReconnectOutput(int w, int h, bool bSendSample, int re
HRESULT hr = S_OK;
- if(m_update_aspect || fForceReconnection || m_w != m_wout || m_h != m_hout || m_arx != m_arxout || m_ary != m_aryout)
- {
- if(GetCLSID(m_pOutput->GetConnected()) == CLSID_VideoRenderer)
- {
+ if(m_update_aspect || fForceReconnection || m_w != m_wout || m_h != m_hout || m_arx != m_arxout || m_ary != m_aryout) {
+ if(GetCLSID(m_pOutput->GetConnected()) == CLSID_VideoRenderer) {
NotifyEvent(EC_ERRORABORT, 0, 0);
return E_FAIL;
}
BITMAPINFOHEADER* bmi = NULL;
- if(mt.formattype == FORMAT_VideoInfo)
- {
+ if(mt.formattype == FORMAT_VideoInfo) {
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)mt.Format();
- if (realWidth != -1 && realHeight != -1)
- {
+ if (realWidth != -1 && realHeight != -1) {
SetRect(&vih->rcSource, 0, 0, realWidth, realHeight);
SetRect(&vih->rcTarget, 0, 0, realWidth, realHeight);
- }
- else
- {
+ } else {
SetRect(&vih->rcSource, 0, 0, m_w, m_h);
SetRect(&vih->rcTarget, 0, 0, m_w, m_h);
}
bmi = &vih->bmiHeader;
bmi->biXPelsPerMeter = m_w * m_ary;
bmi->biYPelsPerMeter = m_h * m_arx;
- }
- else if(mt.formattype == FORMAT_VideoInfo2)
- {
+ } else if(mt.formattype == FORMAT_VideoInfo2) {
VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)mt.Format();
- if (realWidth != -1 && realHeight != -1)
- {
+ if (realWidth != -1 && realHeight != -1) {
SetRect(&vih->rcSource, 0, 0, realWidth, realHeight);
SetRect(&vih->rcTarget, 0, 0, realWidth, realHeight);
- }
- else
- {
+ } else {
SetRect(&vih->rcSource, 0, 0, m_w, m_h);
SetRect(&vih->rcTarget, 0, 0, m_w, m_h);
}
bmi = &vih->bmiHeader;
vih->dwPictAspectRatioX = m_arx;
vih->dwPictAspectRatioY = m_ary;
- }
- else
- {
+ } else {
return E_FAIL; //should never be here? prevent null pointer refs for bmi
}
@@ -229,27 +228,19 @@ HRESULT CBaseVideoFilter::ReconnectOutput(int w, int h, bool bSendSample, int re
ASSERT(SUCCEEDED(hr)); // should better not fail, after all "mt" is the current media type, just with a different resolution
HRESULT hr1 = 0, hr2 = 0;
CComPtr<IMediaSample> pOut;
- if(SUCCEEDED(hr1 = m_pOutput->GetConnected()->ReceiveConnection(m_pOutput, &mt)))
- {
- if (bSendSample)
- {
- if (SUCCEEDED(hr2 = m_pOutput->GetDeliveryBuffer(&pOut, NULL, NULL, 0)))
- {
+ if(SUCCEEDED(hr1 = m_pOutput->GetConnected()->ReceiveConnection(m_pOutput, &mt))) {
+ if (bSendSample) {
+ if (SUCCEEDED(hr2 = m_pOutput->GetDeliveryBuffer(&pOut, NULL, NULL, 0))) {
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pOut->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pOut->GetMediaType(&pmt)) && pmt) {
CMediaType mt = *pmt;
m_pOutput->SetMediaType(&mt);
DeleteMediaType(pmt);
- }
- else // stupid overlay mixer won't let us know the new pitch...
- {
+ } else { // stupid overlay mixer won't let us know the new pitch...
long size = pOut->GetSize();
bmi->biWidth = size / bmi->biHeight * 8 / bmi->biBitCount;
}
- }
- else
- {
+ } else {
m_w = w_org;
m_h = h_org;
return E_FAIL;
@@ -285,20 +276,19 @@ HRESULT CBaseVideoFilter::CopyBuffer(BYTE* pOut, BYTE** ppIn, int w, int h, int
int pitchOut = 0;
- if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS)
- {
+ if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS) {
pitchOut = bihOut.biWidth*bihOut.biBitCount>>3;
- if(bihOut.biHeight > 0)
- {
+ if(bihOut.biHeight > 0) {
pOut += pitchOut*(h-1);
pitchOut = -pitchOut;
- if(h < 0) h = -h;
+ if(h < 0) {
+ h = -h;
+ }
}
}
- if(h < 0)
- {
+ if(h < 0) {
h = -h;
ppIn[0] += pitchIn*(h-1);
ppIn[1] += (pitchIn>>1)*((h>>1)-1);
@@ -306,79 +296,70 @@ HRESULT CBaseVideoFilter::CopyBuffer(BYTE* pOut, BYTE** ppIn, int w, int h, int
pitchIn = -pitchIn;
}
- if(subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV || subtype == MEDIASUBTYPE_YV12)
- {
+ if(subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV || subtype == MEDIASUBTYPE_YV12) {
BYTE* pIn = ppIn[0];
BYTE* pInU = ppIn[1];
BYTE* pInV = ppIn[2];
- if(subtype == MEDIASUBTYPE_YV12) {BYTE* tmp = pInU; pInU = pInV; pInV = tmp;}
+ if(subtype == MEDIASUBTYPE_YV12) {
+ BYTE* tmp = pInU;
+ pInU = pInV;
+ pInV = tmp;
+ }
BYTE* pOutU = pOut + bihOut.biWidth*h;
BYTE* pOutV = pOut + bihOut.biWidth*h*5/4;
- if(bihOut.biCompression == '21VY') {BYTE* tmp = pOutU; pOutU = pOutV; pOutV = tmp;}
+ if(bihOut.biCompression == '21VY') {
+ BYTE* tmp = pOutU;
+ pOutU = pOutV;
+ pOutV = tmp;
+ }
ASSERT(w <= abs(pitchIn));
- if(bihOut.biCompression == '2YUY')
- {
- if (!fInterlaced)
+ if(bihOut.biCompression == '2YUY') {
+ if (!fInterlaced) {
BitBltFromI420ToYUY2(w, h, pOut, bihOut.biWidth*2, pIn, pInU, pInV, pitchIn);
- else
+ } else {
BitBltFromI420ToYUY2Interlaced(w, h, pOut, bihOut.biWidth*2, pIn, pInU, pInV, pitchIn);
- }
- else if(bihOut.biCompression == '024I' || bihOut.biCompression == 'VUYI' || bihOut.biCompression == '21VY')
- {
+ }
+ } else if(bihOut.biCompression == '024I' || bihOut.biCompression == 'VUYI' || bihOut.biCompression == '21VY') {
BitBltFromI420ToI420(w, h, pOut, pOutU, pOutV, bihOut.biWidth, pIn, pInU, pInV, pitchIn);
- }
- else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS)
- {
- if(!BitBltFromI420ToRGB(w, h, pOut, pitchOut, bihOut.biBitCount, pIn, pInU, pInV, pitchIn))
- {
- for(DWORD y = 0; y < h; y++, pOut += pitchOut)
+ } else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS) {
+ if(!BitBltFromI420ToRGB(w, h, pOut, pitchOut, bihOut.biBitCount, pIn, pInU, pInV, pitchIn)) {
+ for(DWORD y = 0; y < h; y++, pOut += pitchOut) {
memset(pOut, 0, pitchOut);
+ }
}
}
- }
- else if(subtype == MEDIASUBTYPE_YUY2)
- {
- if(bihOut.biCompression == '2YUY')
- {
+ } else if(subtype == MEDIASUBTYPE_YUY2) {
+ if(bihOut.biCompression == '2YUY') {
BitBltFromYUY2ToYUY2(w, h, pOut, bihOut.biWidth*2, ppIn[0], pitchIn);
- }
- else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS)
- {
- if(!BitBltFromYUY2ToRGB(w, h, pOut, pitchOut, bihOut.biBitCount, ppIn[0], pitchIn))
- {
- for(DWORD y = 0; y < h; y++, pOut += pitchOut)
+ } else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS) {
+ if(!BitBltFromYUY2ToRGB(w, h, pOut, pitchOut, bihOut.biBitCount, ppIn[0], pitchIn)) {
+ for(DWORD y = 0; y < h; y++, pOut += pitchOut) {
memset(pOut, 0, pitchOut);
+ }
}
}
- }
- else if(subtype == MEDIASUBTYPE_ARGB32 || subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_RGB24 || subtype == MEDIASUBTYPE_RGB565)
- {
- int sbpp =
+ } else if(subtype == MEDIASUBTYPE_ARGB32 || subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_RGB24 || subtype == MEDIASUBTYPE_RGB565) {
+ int sbpp =
subtype == MEDIASUBTYPE_ARGB32 || subtype == MEDIASUBTYPE_RGB32 ? 32 :
subtype == MEDIASUBTYPE_RGB24 ? 24 :
subtype == MEDIASUBTYPE_RGB565 ? 16 : 0;
- if(bihOut.biCompression == '2YUY')
- {
+ if(bihOut.biCompression == '2YUY') {
// TODO
// BitBltFromRGBToYUY2();
- }
- else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS)
- {
- if(!BitBltFromRGBToRGB(w, h, pOut, pitchOut, bihOut.biBitCount, ppIn[0], pitchIn, sbpp))
- {
- for(DWORD y = 0; y < h; y++, pOut += pitchOut)
+ } else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS) {
+ if(!BitBltFromRGBToRGB(w, h, pOut, pitchOut, bihOut.biBitCount, ppIn[0], pitchIn, sbpp)) {
+ for(DWORD y = 0; y < h; y++, pOut += pitchOut) {
memset(pOut, 0, pitchOut);
+ }
}
}
- }
- else
- {
+ } else {
return VFW_E_TYPE_NOT_ACCEPTED;
}
@@ -390,63 +371,62 @@ HRESULT CBaseVideoFilter::CheckInputType(const CMediaType* mtIn)
BITMAPINFOHEADER bih;
ExtractBIH(mtIn, &bih);
- return mtIn->majortype == MEDIATYPE_Video
- && (mtIn->subtype == MEDIASUBTYPE_YV12
- || mtIn->subtype == MEDIASUBTYPE_I420
- || mtIn->subtype == MEDIASUBTYPE_IYUV
- || mtIn->subtype == MEDIASUBTYPE_YUY2
- || mtIn->subtype == MEDIASUBTYPE_ARGB32
- || mtIn->subtype == MEDIASUBTYPE_RGB32
- || mtIn->subtype == MEDIASUBTYPE_RGB24
- || mtIn->subtype == MEDIASUBTYPE_RGB565)
- && (mtIn->formattype == FORMAT_VideoInfo
- || mtIn->formattype == FORMAT_VideoInfo2)
- && bih.biHeight > 0
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ return mtIn->majortype == MEDIATYPE_Video
+ && (mtIn->subtype == MEDIASUBTYPE_YV12
+ || mtIn->subtype == MEDIASUBTYPE_I420
+ || mtIn->subtype == MEDIASUBTYPE_IYUV
+ || mtIn->subtype == MEDIASUBTYPE_YUY2
+ || mtIn->subtype == MEDIASUBTYPE_ARGB32
+ || mtIn->subtype == MEDIASUBTYPE_RGB32
+ || mtIn->subtype == MEDIASUBTYPE_RGB24
+ || mtIn->subtype == MEDIASUBTYPE_RGB565)
+ && (mtIn->formattype == FORMAT_VideoInfo
+ || mtIn->formattype == FORMAT_VideoInfo2)
+ && bih.biHeight > 0
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CBaseVideoFilter::CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut)
{
- if(FAILED(CheckInputType(mtIn)) || mtOut->majortype != MEDIATYPE_Video)
+ if(FAILED(CheckInputType(mtIn)) || mtOut->majortype != MEDIATYPE_Video) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if(mtIn->majortype == MEDIATYPE_Video
- && (mtIn->subtype == MEDIASUBTYPE_YV12
- || mtIn->subtype == MEDIASUBTYPE_I420
- || mtIn->subtype == MEDIASUBTYPE_IYUV))
- {
+ if(mtIn->majortype == MEDIATYPE_Video
+ && (mtIn->subtype == MEDIASUBTYPE_YV12
+ || mtIn->subtype == MEDIASUBTYPE_I420
+ || mtIn->subtype == MEDIASUBTYPE_IYUV)) {
if(mtOut->subtype != MEDIASUBTYPE_YV12
- && mtOut->subtype != MEDIASUBTYPE_I420
- && mtOut->subtype != MEDIASUBTYPE_IYUV
- && mtOut->subtype != MEDIASUBTYPE_YUY2
- && mtOut->subtype != MEDIASUBTYPE_ARGB32
- && mtOut->subtype != MEDIASUBTYPE_RGB32
- && mtOut->subtype != MEDIASUBTYPE_RGB24
- && mtOut->subtype != MEDIASUBTYPE_RGB565)
+ && mtOut->subtype != MEDIASUBTYPE_I420
+ && mtOut->subtype != MEDIASUBTYPE_IYUV
+ && mtOut->subtype != MEDIASUBTYPE_YUY2
+ && mtOut->subtype != MEDIASUBTYPE_ARGB32
+ && mtOut->subtype != MEDIASUBTYPE_RGB32
+ && mtOut->subtype != MEDIASUBTYPE_RGB24
+ && mtOut->subtype != MEDIASUBTYPE_RGB565) {
return VFW_E_TYPE_NOT_ACCEPTED;
- }
- else if(mtIn->majortype == MEDIATYPE_Video
- && (mtIn->subtype == MEDIASUBTYPE_YUY2))
- {
+ }
+ } else if(mtIn->majortype == MEDIATYPE_Video
+ && (mtIn->subtype == MEDIASUBTYPE_YUY2)) {
if(mtOut->subtype != MEDIASUBTYPE_YUY2
- && mtOut->subtype != MEDIASUBTYPE_ARGB32
- && mtOut->subtype != MEDIASUBTYPE_RGB32
- && mtOut->subtype != MEDIASUBTYPE_RGB24
- && mtOut->subtype != MEDIASUBTYPE_RGB565)
+ && mtOut->subtype != MEDIASUBTYPE_ARGB32
+ && mtOut->subtype != MEDIASUBTYPE_RGB32
+ && mtOut->subtype != MEDIASUBTYPE_RGB24
+ && mtOut->subtype != MEDIASUBTYPE_RGB565) {
return VFW_E_TYPE_NOT_ACCEPTED;
- }
- else if(mtIn->majortype == MEDIATYPE_Video
- && (mtIn->subtype == MEDIASUBTYPE_ARGB32
- || mtIn->subtype == MEDIASUBTYPE_RGB32
- || mtIn->subtype == MEDIASUBTYPE_RGB24
- || mtIn->subtype == MEDIASUBTYPE_RGB565))
- {
+ }
+ } else if(mtIn->majortype == MEDIATYPE_Video
+ && (mtIn->subtype == MEDIASUBTYPE_ARGB32
+ || mtIn->subtype == MEDIASUBTYPE_RGB32
+ || mtIn->subtype == MEDIASUBTYPE_RGB24
+ || mtIn->subtype == MEDIASUBTYPE_RGB565)) {
if(mtOut->subtype != MEDIASUBTYPE_ARGB32
- && mtOut->subtype != MEDIASUBTYPE_RGB32
- && mtOut->subtype != MEDIASUBTYPE_RGB24
- && mtOut->subtype != MEDIASUBTYPE_RGB565)
+ && mtOut->subtype != MEDIASUBTYPE_RGB32
+ && mtOut->subtype != MEDIASUBTYPE_RGB24
+ && mtOut->subtype != MEDIASUBTYPE_RGB565) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
return S_OK;
@@ -456,15 +436,17 @@ HRESULT CBaseVideoFilter::CheckOutputType(const CMediaType& mtOut)
{
int wout = 0, hout = 0, arxout = 0, aryout = 0;
return ExtractDim(&mtOut, wout, hout, arxout, aryout)
- && m_h == abs((int)hout)
- && mtOut.subtype != MEDIASUBTYPE_ARGB32
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ && m_h == abs((int)hout)
+ && mtOut.subtype != MEDIASUBTYPE_ARGB32
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CBaseVideoFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
BITMAPINFOHEADER bih;
ExtractBIH(&m_pOutput->CurrentMediaType(), &bih);
@@ -479,17 +461,17 @@ HRESULT CBaseVideoFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
- return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR;
+ return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
+ ? E_FAIL
+ : NOERROR;
}
-VIDEO_OUTPUT_FORMATS DefaultFormats[] =
-{
+VIDEO_OUTPUT_FORMATS DefaultFormats[] = {
{&MEDIASUBTYPE_YV12, 3, 12, '21VY'},
{&MEDIASUBTYPE_I420, 3, 12, '024I'},
{&MEDIASUBTYPE_IYUV, 3, 12, 'VUYI'},
@@ -518,7 +500,9 @@ HRESULT CBaseVideoFilter::GetMediaType(int iPosition, CMediaType* pmt)
VIDEO_OUTPUT_FORMATS* fmts;
int nFormatCount;
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
// this will make sure we won't connect to the old renderer in dvd mode
@@ -527,16 +511,22 @@ HRESULT CBaseVideoFilter::GetMediaType(int iPosition, CMediaType* pmt)
bool fFoundDVDNavigator = false;
CComPtr<IBaseFilter> pBF = this;
CComPtr<IPin> pPin = m_pInput;
- for(; !fFoundDVDNavigator && (pBF = GetUpStreamFilter(pBF, pPin)); pPin = GetFirstPin(pBF))
- fFoundDVDNavigator = GetCLSID(pBF) == CLSID_DVDNavigator;
+ for(; !fFoundDVDNavigator && (pBF = GetUpStreamFilter(pBF, pPin)); pPin = GetFirstPin(pBF)) {
+ fFoundDVDNavigator = GetCLSID(pBF) == CLSID_DVDNavigator;
+ }
- if(fFoundDVDNavigator || m_pInput->CurrentMediaType().formattype == FORMAT_VideoInfo2)
+ if(fFoundDVDNavigator || m_pInput->CurrentMediaType().formattype == FORMAT_VideoInfo2) {
iPosition = iPosition*2;
+ }
//
GetOutputFormats (nFormatCount, &fmts);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition >= 2*nFormatCount) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition >= 2*nFormatCount) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->majortype = MEDIATYPE_Video;
pmt->subtype = *fmts[iPosition/2].subtype;
@@ -556,24 +546,23 @@ HRESULT CBaseVideoFilter::GetMediaType(int iPosition, CMediaType* pmt)
bihOut.biCompression = fmts[iPosition/2].biCompression;
bihOut.biSizeImage = w*h*bihOut.biBitCount>>3;
- if(iPosition&1)
- {
+ if(iPosition&1) {
pmt->formattype = FORMAT_VideoInfo;
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
memset(vih, 0, sizeof(VIDEOINFOHEADER));
vih->bmiHeader = bihOut;
vih->bmiHeader.biXPelsPerMeter = vih->bmiHeader.biWidth * ary;
vih->bmiHeader.biYPelsPerMeter = vih->bmiHeader.biHeight * arx;
- }
- else
- {
+ } else {
pmt->formattype = FORMAT_VideoInfo2;
VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER2));
memset(vih, 0, sizeof(VIDEOINFOHEADER2));
vih->bmiHeader = bihOut;
vih->dwPictAspectRatioX = arx;
vih->dwPictAspectRatioY = ary;
- if(IsVideoInterlaced()) vih->dwInterlaceFlags = AMINTERLACE_IsInterlaced | AMINTERLACE_DisplayModeBobOrWeave;
+ if(IsVideoInterlaced()) {
+ vih->dwInterlaceFlags = AMINTERLACE_IsInterlaced | AMINTERLACE_DisplayModeBobOrWeave;
+ }
}
CMediaType& mt = m_pInput->CurrentMediaType();
@@ -590,29 +579,27 @@ HRESULT CBaseVideoFilter::GetMediaType(int iPosition, CMediaType* pmt)
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->Format();
VIDEOINFOHEADER* vihInput = (VIDEOINFOHEADER*)pmtInput.Format();
- if (vih && vihInput && (vihInput->rcSource.right != 0) && (vihInput->rcSource.bottom != 0))
- {
+ if (vih && vihInput && (vihInput->rcSource.right != 0) && (vihInput->rcSource.bottom != 0)) {
vih->rcSource = vihInput->rcSource;
vih->rcTarget = vihInput->rcTarget;
- }
- else
- {
+ } else {
vih->rcSource.right = vih->rcTarget.right = m_win;
vih->rcSource.bottom = vih->rcTarget.bottom = m_hin;
}
- if (RealWidth != -1 && vih->rcSource.right > RealWidth)
+ if (RealWidth != -1 && vih->rcSource.right > RealWidth) {
vih->rcSource.right = RealWidth;
- if (RealHeight != -1 && vih->rcSource.bottom > RealHeight)
+ }
+ if (RealHeight != -1 && vih->rcSource.bottom > RealHeight) {
vih->rcSource.bottom = RealHeight;
+ }
return S_OK;
}
HRESULT CBaseVideoFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt)
{
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
m_w = m_h = m_arx = m_ary = 0;
ExtractDim(pmt, m_w, m_h, m_arx, m_ary);
m_win = m_w;
@@ -629,14 +616,13 @@ HRESULT CBaseVideoFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt)
a = b % tmp;
b = tmp;
}
- if(b) m_arx /= b, m_ary /= b;
- }
- else if(dir == PINDIR_OUTPUT)
- {
+ if(b) {
+ m_arx /= b, m_ary /= b;
+ }
+ } else if(dir == PINDIR_OUTPUT) {
int wout = 0, hout = 0, arxout = 0, aryout = 0;
ExtractDim(pmt, wout, hout, arxout, aryout);
- if(m_w == wout && m_h == hout && m_arx == arxout && m_ary == aryout)
- {
+ if(m_w == wout && m_h == hout && m_arx == arxout && m_ary == aryout) {
m_wout = wout;
m_hout = hout;
m_arxout = arxout;
@@ -650,11 +636,13 @@ HRESULT CBaseVideoFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt)
//
// CBaseVideoInputAllocator
//
-
+
CBaseVideoInputAllocator::CBaseVideoInputAllocator(HRESULT* phr)
: CMemAllocator(NAME("CBaseVideoInputAllocator"), NULL, phr)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
void CBaseVideoInputAllocator::SetMediaType(const CMediaType& mt)
@@ -664,13 +652,13 @@ void CBaseVideoInputAllocator::SetMediaType(const CMediaType& mt)
STDMETHODIMP CBaseVideoInputAllocator::GetBuffer(IMediaSample** ppBuffer, REFERENCE_TIME* pStartTime, REFERENCE_TIME* pEndTime, DWORD dwFlags)
{
- if(!m_bCommitted)
- return VFW_E_NOT_COMMITTED;
+ if(!m_bCommitted) {
+ return VFW_E_NOT_COMMITTED;
+ }
HRESULT hr = __super::GetBuffer(ppBuffer, pStartTime, pEndTime, dwFlags);
- if(SUCCEEDED(hr) && m_mt.majortype != GUID_NULL)
- {
+ if(SUCCEEDED(hr) && m_mt.majortype != GUID_NULL) {
(*ppBuffer)->SetMediaType(&m_mt);
m_mt.majortype = GUID_NULL;
}
@@ -682,7 +670,7 @@ STDMETHODIMP CBaseVideoInputAllocator::GetBuffer(IMediaSample** ppBuffer, REFERE
// CBaseVideoInputPin
//
-CBaseVideoInputPin::CBaseVideoInputPin(TCHAR* pObjectName, CBaseVideoFilter* pFilter, HRESULT* phr, LPCWSTR pName)
+CBaseVideoInputPin::CBaseVideoInputPin(TCHAR* pObjectName, CBaseVideoFilter* pFilter, HRESULT* phr, LPCWSTR pName)
: CTransformInputPin(pObjectName, pFilter, phr, pName)
, m_pAllocator(NULL)
{
@@ -695,54 +683,57 @@ CBaseVideoInputPin::~CBaseVideoInputPin()
STDMETHODIMP CBaseVideoInputPin::GetAllocator(IMemAllocator** ppAllocator)
{
- CheckPointer(ppAllocator, E_POINTER);
+ CheckPointer(ppAllocator, E_POINTER);
- if(m_pAllocator == NULL)
- {
+ if(m_pAllocator == NULL) {
HRESULT hr = S_OK;
- m_pAllocator = DNew CBaseVideoInputAllocator(&hr);
- m_pAllocator->AddRef();
- }
+ m_pAllocator = DNew CBaseVideoInputAllocator(&hr);
+ m_pAllocator->AddRef();
+ }
- (*ppAllocator = m_pAllocator)->AddRef();
+ (*ppAllocator = m_pAllocator)->AddRef();
- return S_OK;
-}
+ return S_OK;
+}
STDMETHODIMP CBaseVideoInputPin::ReceiveConnection(IPin* pConnector, const AM_MEDIA_TYPE* pmt)
{
CAutoLock cObjectLock(m_pLock);
- if(m_Connected)
- {
+ if(m_Connected) {
CMediaType mt(*pmt);
- if(FAILED(CheckMediaType(&mt)))
+ if(FAILED(CheckMediaType(&mt))) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
ALLOCATOR_PROPERTIES props, actual;
CComPtr<IMemAllocator> pMemAllocator;
if(FAILED(GetAllocator(&pMemAllocator))
- || FAILED(pMemAllocator->Decommit())
- || FAILED(pMemAllocator->GetProperties(&props)))
+ || FAILED(pMemAllocator->Decommit())
+ || FAILED(pMemAllocator->GetProperties(&props))) {
return E_FAIL;
+ }
BITMAPINFOHEADER bih;
- if(ExtractBIH(pmt, &bih) && bih.biSizeImage)
+ if(ExtractBIH(pmt, &bih) && bih.biSizeImage) {
props.cbBuffer = bih.biSizeImage;
+ }
if(FAILED(pMemAllocator->SetProperties(&props, &actual))
- || FAILED(pMemAllocator->Commit())
- || props.cbBuffer != actual.cbBuffer)
+ || FAILED(pMemAllocator->Commit())
+ || props.cbBuffer != actual.cbBuffer) {
return E_FAIL;
+ }
- if(m_pAllocator)
+ if(m_pAllocator) {
m_pAllocator->SetMediaType(mt);
+ }
return SetMediaType(&mt) == S_OK
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
return __super::ReceiveConnection(pConnector, pmt);
@@ -759,10 +750,11 @@ CBaseVideoOutputPin::CBaseVideoOutputPin(TCHAR* pObjectName, CBaseVideoFilter* p
HRESULT CBaseVideoOutputPin::CheckMediaType(const CMediaType* mtOut)
{
- if(IsConnected())
- {
+ if(IsConnected()) {
HRESULT hr = (static_cast<CBaseVideoFilter*>(m_pFilter))->CheckOutputType(*mtOut);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
}
return __super::CheckMediaType(mtOut);
diff --git a/src/filters/transform/BaseVideoFilter/BaseVideoFilter.h b/src/filters/transform/BaseVideoFilter/BaseVideoFilter.h
index 37ffdc049..cc5eccbb2 100644
--- a/src/filters/transform/BaseVideoFilter/BaseVideoFilter.h
+++ b/src/filters/transform/BaseVideoFilter/BaseVideoFilter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -22,8 +22,7 @@
#pragma once
-typedef struct
-{
+typedef struct {
const GUID* subtype;
WORD biPlanes;
WORD biBitCount;
@@ -33,7 +32,7 @@ typedef struct
class CBaseVideoFilter : public CTransformFilter
{
private:
- HRESULT Receive(IMediaSample* pIn);
+ HRESULT Receive(IMediaSample* pIn);
// these are private for a reason, don't bother them
int m_win, m_hin, m_arxin, m_aryin;
@@ -52,7 +51,9 @@ protected:
virtual void GetOutputSize(int& w, int& h, int& arx, int& ary, int &RealWidth, int &RealHeight) {}
virtual HRESULT Transform(IMediaSample* pIn) = 0;
- virtual bool IsVideoInterlaced() {return false;}
+ virtual bool IsVideoInterlaced() {
+ return false;
+ }
virtual void GetOutputFormats (int& nNumber, VIDEO_OUTPUT_FORMATS** ppFormats);
public:
@@ -63,11 +64,11 @@ public:
int GetPinCount();
CBasePin* GetPin(int n);
- HRESULT CheckInputType(const CMediaType* mtIn);
+ HRESULT CheckInputType(const CMediaType* mtIn);
HRESULT CheckOutputType(const CMediaType& mtOut);
- HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
- HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
+ HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
+ HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
HRESULT SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt);
void SetAspect(CSize aspect);
@@ -100,5 +101,5 @@ class CBaseVideoOutputPin : public CTransformOutputPin
public:
CBaseVideoOutputPin(TCHAR* pObjectName, CBaseVideoFilter* pFilter, HRESULT* phr, LPCWSTR pName);
- HRESULT CheckMediaType(const CMediaType* mtOut);
+ HRESULT CheckMediaType(const CMediaType* mtOut);
};
diff --git a/src/filters/transform/BaseVideoFilter/stdafx.cpp b/src/filters/transform/BaseVideoFilter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/transform/BaseVideoFilter/stdafx.cpp
+++ b/src/filters/transform/BaseVideoFilter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/BaseVideoFilter/stdafx.h b/src/filters/transform/BaseVideoFilter/stdafx.h
index e0d4538b1..79bb9cc0d 100644
--- a/src/filters/transform/BaseVideoFilter/stdafx.h
+++ b/src/filters/transform/BaseVideoFilter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/BufferFilter/BufferFilter.cpp b/src/filters/transform/BufferFilter/BufferFilter.cpp
index e79e3b2a8..51f021b8a 100644
--- a/src/filters/transform/BufferFilter/BufferFilter.cpp
+++ b/src/filters/transform/BufferFilter/BufferFilter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -25,29 +25,24 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_NULL, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_NULL, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CBufferFilter), L"MPC - Buffer Filter", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CBufferFilter>, NULL, &sudFilter[0]}
};
@@ -73,25 +68,34 @@ CFilterApp theApp;
// CBufferFilter
//
-CBufferFilter::CBufferFilter(LPUNKNOWN lpunk, HRESULT* phr)
+CBufferFilter::CBufferFilter(LPUNKNOWN lpunk, HRESULT* phr)
: CTransformFilter(NAME("CBufferFilter"), lpunk, __uuidof(this))
, m_nSamplesToBuffer(2)
{
HRESULT hr = S_OK;
- do
- {
+ do {
m_pInput = DNew CTransformInputPin(NAME("Transform input pin"), this, &hr, L"In");
- if(!m_pInput) hr = E_OUTOFMEMORY;
- if(FAILED(hr)) break;
+ if(!m_pInput) {
+ hr = E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ break;
+ }
m_pOutput = DNew CBufferFilterOutputPin(this, &hr);
- if(!m_pOutput) hr = E_OUTOFMEMORY;
- if(FAILED(hr)) {delete m_pInput, m_pInput = NULL; break;}
- }
- while(false);
+ if(!m_pOutput) {
+ hr = E_OUTOFMEMORY;
+ }
+ if(FAILED(hr)) {
+ delete m_pInput, m_pInput = NULL;
+ break;
+ }
+ } while(false);
- if(phr) *phr = hr;
+ if(phr) {
+ *phr = hr;
+ }
}
CBufferFilter::~CBufferFilter()
@@ -109,11 +113,13 @@ STDMETHODIMP CBufferFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
STDMETHODIMP CBufferFilter::SetBuffers(int nBuffers)
{
- if(!m_pOutput)
+ if(!m_pOutput) {
return E_FAIL;
+ }
- if(m_pOutput->IsConnected()) // TODO: allow "on-the-fly" changes
+ if(m_pOutput->IsConnected()) { // TODO: allow "on-the-fly" changes
return VFW_E_ALREADY_CONNECTED;
+ }
m_nSamplesToBuffer = nBuffers;
@@ -143,8 +149,9 @@ HRESULT CBufferFilter::Receive(IMediaSample* pSample)
{
/* Check for other streams and pass them on */
AM_SAMPLE2_PROPERTIES* const pProps = m_pInput->SampleProps();
- if(pProps->dwStreamId != AM_STREAM_MEDIA)
+ if(pProps->dwStreamId != AM_STREAM_MEDIA) {
return m_pOutput->Deliver(pSample);
+ }
HRESULT hr;
ASSERT(pSample);
@@ -155,8 +162,9 @@ HRESULT CBufferFilter::Receive(IMediaSample* pSample)
// Set up the output sample
hr = InitializeOutputSample(pSample, &pOutSample);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
// Start timing the transform (if PERF is defined)
MSR_START(m_idTransform);
@@ -170,16 +178,14 @@ HRESULT CBufferFilter::Receive(IMediaSample* pSample)
if(FAILED(hr)) {
DbgLog((LOG_TRACE,1,TEXT("Error from transform")));
- }
- else {
+ } else {
// the Transform() function can return S_FALSE to indicate that the
// sample should not be delivered; we only deliver the sample if it's
// really S_OK (same as NOERROR, of course.)
if(hr == NOERROR) {
hr = m_pOutput->Deliver(pOutSample);
m_bSampleSkipped = FALSE; // last thing no longer dropped
- }
- else {
+ } else {
// S_FALSE returned from Transform is a PRIVATE agreement
// We should return NOERROR from Receive() in this cause because returning S_FALSE
// from Receive() means that this is the end of the stream and no more data should
@@ -218,10 +224,12 @@ HRESULT CBufferFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
long len = pIn->GetActualDataLength();
long size = pOut->GetSize();
- if(!pDataIn || !pDataOut || len > size || len <= 0) return S_FALSE;
+ if(!pDataIn || !pDataOut || len > size || len <= 0) {
+ return S_FALSE;
+ }
memcpy(pDataOut, pDataIn, min(len, size));
-
+
pOut->SetActualDataLength(min(len, size));
return S_OK;
@@ -239,11 +247,15 @@ HRESULT CBufferFilter::CheckTransform(const CMediaType* mtIn, const CMediaType*
HRESULT CBufferFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
CComPtr<IMemAllocator> pAllocatorIn;
m_pInput->GetAllocator(&pAllocatorIn);
- if(!pAllocatorIn) return E_UNEXPECTED;
+ if(!pAllocatorIn) {
+ return E_UNEXPECTED;
+ }
pAllocatorIn->GetProperties(pProperties);
@@ -251,21 +263,28 @@ HRESULT CBufferFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PRO
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
- return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR);
+ return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
+ ? E_FAIL
+ : NOERROR);
}
HRESULT CBufferFilter::GetMediaType(int iPosition, CMediaType* pMediaType)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
// TODO: offer all input types from upstream and allow reconnection at least in stopped state
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
CopyMediaType(pMediaType, &m_pInput->CurrentMediaType());
@@ -275,10 +294,10 @@ HRESULT CBufferFilter::GetMediaType(int iPosition, CMediaType* pMediaType)
HRESULT CBufferFilter::StopStreaming()
{
CBufferFilterOutputPin* pPin = static_cast<CBufferFilterOutputPin*>(m_pOutput);
- if(m_pInput && pPin && pPin->m_pOutputQueue)
- {
- while(!m_pInput->IsFlushing() && pPin->m_pOutputQueue->GetQueueCount() > 0)
+ if(m_pInput && pPin && pPin->m_pOutputQueue) {
+ while(!m_pInput->IsFlushing() && pPin->m_pOutputQueue->GetQueueCount() > 0) {
Sleep(50);
+ }
}
return __super::StopStreaming();
@@ -297,15 +316,15 @@ HRESULT CBufferFilterOutputPin::Active()
{
CAutoLock lock_it(m_pLock);
- if(m_Connected && !m_pOutputQueue)
- {
+ if(m_Connected && !m_pOutputQueue) {
HRESULT hr = NOERROR;
m_pOutputQueue.Attach(DNew CBufferFilterOutputQueue(m_Connected, &hr));
- if(!m_pOutputQueue) hr = E_OUTOFMEMORY;
+ if(!m_pOutputQueue) {
+ hr = E_OUTOFMEMORY;
+ }
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
m_pOutputQueue.Free();
return hr;
}
@@ -323,7 +342,9 @@ HRESULT CBufferFilterOutputPin::Inactive()
HRESULT CBufferFilterOutputPin::Deliver(IMediaSample* pMediaSample)
{
- if(!m_pOutputQueue) return NOERROR;
+ if(!m_pOutputQueue) {
+ return NOERROR;
+ }
pMediaSample->AddRef();
return m_pOutputQueue->Receive(pMediaSample);
}
@@ -332,7 +353,7 @@ HRESULT CBufferFilterOutputPin::Deliver(IMediaSample* pMediaSample)
if(!m_pOutputQueue) return NOERROR; \
m_pOutputQueue->##call; \
return NOERROR; \
-
+
HRESULT CBufferFilterOutputPin::DeliverEndOfStream()
{
CallQueue(EOS());
diff --git a/src/filters/transform/BufferFilter/BufferFilter.h b/src/filters/transform/BufferFilter/BufferFilter.h
index 7bba2767f..f95bb02bb 100644
--- a/src/filters/transform/BufferFilter/BufferFilter.h
+++ b/src/filters/transform/BufferFilter/BufferFilter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,8 +24,8 @@
#include <atlbase.h>
interface __declspec(uuid("63EF0035-3FFE-4c41-9230-4346E028BE20"))
-IBufferFilter : public IUnknown
-{
+IBufferFilter :
+public IUnknown {
STDMETHOD(SetBuffers) (int nBuffers) = 0;
STDMETHOD_(int, GetBuffers) () = 0;
STDMETHOD_(int, GetFreeBuffers) () = 0;
@@ -33,7 +33,7 @@ IBufferFilter : public IUnknown
};
class __declspec(uuid("DA2B3D77-2F29-4fd2-AC99-DEE4A8A13BF0"))
-CBufferFilter : public CTransformFilter, public IBufferFilter
+ CBufferFilter : public CTransformFilter, public IBufferFilter
{
int m_nSamplesToBuffer;
@@ -42,7 +42,7 @@ public:
virtual ~CBufferFilter();
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IBufferFilter
STDMETHODIMP SetBuffers(int nBuffers);
@@ -52,10 +52,10 @@ public:
HRESULT Receive(IMediaSample* pSample);
HRESULT Transform(IMediaSample* pIn, IMediaSample* pOut);
- HRESULT CheckInputType(const CMediaType* mtIn);
- HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
- HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
+ HRESULT CheckInputType(const CMediaType* mtIn);
+ HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
+ HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
HRESULT StopStreaming();
};
@@ -65,22 +65,19 @@ class CBufferFilterOutputPin : public CTransformOutputPin
{
public:
CBufferFilterOutputQueue(IPin* pInputPin, HRESULT* phr,
- DWORD dwPriority = THREAD_PRIORITY_NORMAL,
- BOOL bAuto = FALSE, BOOL bQueue = TRUE,
- LONG lBatchSize = 1, BOOL bBatchExact = FALSE,
- LONG lListSize = DEFAULTCACHE,
- bool bFlushingOpt = false)
- : COutputQueue(pInputPin, phr, bAuto, bQueue, lBatchSize, bBatchExact, lListSize, dwPriority, bFlushingOpt)
- {
+ DWORD dwPriority = THREAD_PRIORITY_NORMAL,
+ BOOL bAuto = FALSE, BOOL bQueue = TRUE,
+ LONG lBatchSize = 1, BOOL bBatchExact = FALSE,
+ LONG lListSize = DEFAULTCACHE,
+ bool bFlushingOpt = false)
+ : COutputQueue(pInputPin, phr, bAuto, bQueue, lBatchSize, bBatchExact, lListSize, dwPriority, bFlushingOpt) {
}
- int GetQueueCount()
- {
+ int GetQueueCount() {
return m_List ? m_List->GetCount() : -1;
}
- bool SetPriority(DWORD dwPriority)
- {
+ bool SetPriority(DWORD dwPriority) {
return m_hThread ? !!::SetThreadPriority(m_hThread, dwPriority) : false;
}
};
@@ -91,11 +88,11 @@ public:
CAutoPtr<CBufferFilterOutputQueue> m_pOutputQueue;
HRESULT Active();
- HRESULT Inactive();
+ HRESULT Inactive();
HRESULT Deliver(IMediaSample* pMediaSample);
- HRESULT DeliverEndOfStream();
- HRESULT DeliverBeginFlush();
+ HRESULT DeliverEndOfStream();
+ HRESULT DeliverBeginFlush();
HRESULT DeliverEndFlush();
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
};
diff --git a/src/filters/transform/BufferFilter/stdafx.cpp b/src/filters/transform/BufferFilter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/transform/BufferFilter/stdafx.cpp
+++ b/src/filters/transform/BufferFilter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/BufferFilter/stdafx.h b/src/filters/transform/BufferFilter/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/transform/BufferFilter/stdafx.h
+++ b/src/filters/transform/BufferFilter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/DeCSSFilter/DeCSSFilter.cpp b/src/filters/transform/DeCSSFilter/DeCSSFilter.cpp
index 0ee407ed1..511d32613 100644
--- a/src/filters/transform/DeCSSFilter/DeCSSFilter.cpp
+++ b/src/filters/transform/DeCSSFilter/DeCSSFilter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,31 +27,26 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_MPEG2_PACK, &MEDIASUBTYPE_NULL},
{&MEDIATYPE_MPEG2_PES, &MEDIASUBTYPE_NULL},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CDeCSSFilter), L"MPC - DeCSSFilter", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDeCSSFilter>, NULL, &sudFilter[0]},
+CFactoryTemplate g_Templates[] = {
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDeCSSFilter>, NULL, &sudFilter[0]},
};
int g_cTemplates = countof(g_Templates);
@@ -79,44 +74,54 @@ CFilterApp theApp;
class CKsPSInputPin : public CDeCSSInputPin
{
public:
- CKsPSInputPin(TCHAR* pObjectName, CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName)
- : CDeCSSInputPin(pObjectName, pFilter, phr, pName)
- {
+ CKsPSInputPin(TCHAR* pObjectName, CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName)
+ : CDeCSSInputPin(pObjectName, pFilter, phr, pName) {
}
// IKsPropertySet
- STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength)
- {
- if(CComQIPtr<IKsPropertySet> pKsPS = (static_cast<CDeCSSFilter*>(m_pFilter))->m_pOutput->GetConnected())
+ STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength) {
+ if(CComQIPtr<IKsPropertySet> pKsPS = (static_cast<CDeCSSFilter*>(m_pFilter))->m_pOutput->GetConnected()) {
return pKsPS->Set(PropSet, Id, InstanceData, InstanceLength, PropertyData, DataLength);
+ }
return E_NOTIMPL;
}
- STDMETHODIMP Get(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength, ULONG* pBytesReturned)
- {
- if(CComQIPtr<IKsPropertySet> pKsPS = (static_cast<CDeCSSFilter*>(m_pFilter))->m_pOutput->GetConnected())
+ STDMETHODIMP Get(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength, ULONG* pBytesReturned) {
+ if(CComQIPtr<IKsPropertySet> pKsPS = (static_cast<CDeCSSFilter*>(m_pFilter))->m_pOutput->GetConnected()) {
return pKsPS->Get(PropSet, Id, InstanceData, InstanceLength, PropertyData, DataLength, pBytesReturned);
+ }
return E_NOTIMPL;
}
- STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport)
- {
- if(CComQIPtr<IKsPropertySet> pKsPS = (static_cast<CDeCSSFilter*>(m_pFilter))->m_pOutput->GetConnected())
+ STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport) {
+ if(CComQIPtr<IKsPropertySet> pKsPS = (static_cast<CDeCSSFilter*>(m_pFilter))->m_pOutput->GetConnected()) {
return pKsPS->QuerySupported(PropSet, Id, pTypeSupport);
+ }
return E_NOTIMPL;
}
};
-CDeCSSFilter::CDeCSSFilter(LPUNKNOWN lpunk, HRESULT* phr)
+CDeCSSFilter::CDeCSSFilter(LPUNKNOWN lpunk, HRESULT* phr)
: CTransformFilter(NAME("CDeCSSFilter"), lpunk, __uuidof(this))
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pInput = DNew CKsPSInputPin(NAME("CKsPSInputPin"), this, phr, L"In");
- if(!m_pInput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!m_pInput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
m_pOutput = DNew CTransformOutputPin(NAME("CTransformOutputPin"), this, phr, L"Out");
- if(!m_pOutput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) {delete m_pInput, m_pInput = NULL; return;}
+ if(!m_pOutput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ delete m_pInput, m_pInput = NULL;
+ return;
+ }
}
CDeCSSFilter::~CDeCSSFilter()
@@ -126,8 +131,7 @@ CDeCSSFilter::~CDeCSSFilter()
HRESULT CDeCSSFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
{
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt) {
CMediaType mt = *pmt;
m_pInput->SetMediaType(&mt);
mt.majortype = m_pOutput->CurrentMediaType().majortype;
@@ -145,30 +149,38 @@ HRESULT CDeCSSFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
long len = pIn->GetActualDataLength();
long size = pOut->GetSize();
- if(len == 0 || pDataIn == NULL) // format changes do not carry any data
- {
+ if(len == 0 || pDataIn == NULL) { // format changes do not carry any data
pOut->SetActualDataLength(0);
return S_OK;
}
- if(m_pOutput->CurrentMediaType().majortype == MEDIATYPE_MPEG2_PES)
- {
- if(*(DWORD*)pDataIn == 0xBA010000)
- {
- len -= 14; pDataIn += 14;
- if(int stuffing = (pDataIn[-1]&7)) {len -= stuffing; pDataIn += stuffing;}
+ if(m_pOutput->CurrentMediaType().majortype == MEDIATYPE_MPEG2_PES) {
+ if(*(DWORD*)pDataIn == 0xBA010000) {
+ len -= 14;
+ pDataIn += 14;
+ if(int stuffing = (pDataIn[-1]&7)) {
+ len -= stuffing;
+ pDataIn += stuffing;
+ }
+ }
+ if(len <= 0) {
+ return S_FALSE;
}
- if(len <= 0) return S_FALSE;
- if(*(DWORD*)pDataIn == 0xBB010000)
- {
- len -= 4; pDataIn += 4;
+ if(*(DWORD*)pDataIn == 0xBB010000) {
+ len -= 4;
+ pDataIn += 4;
int hdrlen = ((pDataIn[0]<<8)|pDataIn[1]) + 2;
- len -= hdrlen; pDataIn += hdrlen;
+ len -= hdrlen;
+ pDataIn += hdrlen;
+ }
+ if(len <= 0) {
+ return S_FALSE;
}
- if(len <= 0) return S_FALSE;
}
- if(!pDataIn || !pDataOut || len > size || len < 0) return S_FALSE;
+ if(!pDataIn || !pDataOut || len > size || len < 0) {
+ return S_FALSE;
+ }
memcpy(pDataOut, pDataIn, min(len, size));
pOut->SetActualDataLength(min(len, size));
@@ -179,21 +191,23 @@ HRESULT CDeCSSFilter::Transform(IMediaSample* pIn, IMediaSample* pOut)
HRESULT CDeCSSFilter::CheckInputType(const CMediaType* mtIn)
{
return mtIn->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CDeCSSFilter::CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut)
{
return SUCCEEDED(CheckInputType(mtIn))
- && mtOut->majortype == MEDIATYPE_MPEG2_PACK || mtOut->majortype == MEDIATYPE_MPEG2_PES
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ && mtOut->majortype == MEDIATYPE_MPEG2_PACK || mtOut->majortype == MEDIATYPE_MPEG2_PES
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CDeCSSFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
pProperties->cbAlign = 1;
pProperties->cBuffers = 1;
@@ -202,24 +216,35 @@ HRESULT CDeCSSFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROP
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
- return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR);
+ return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
+ ? E_FAIL
+ : NOERROR);
}
HRESULT CDeCSSFilter::GetMediaType(int iPosition, CMediaType* pmt)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 1) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 1) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
CopyMediaType(pmt, &m_pInput->CurrentMediaType());
- if(iPosition == 0) pmt->majortype = MEDIATYPE_MPEG2_PACK;
- if(iPosition == 1) pmt->majortype = MEDIATYPE_MPEG2_PES;
+ if(iPosition == 0) {
+ pmt->majortype = MEDIATYPE_MPEG2_PACK;
+ }
+ if(iPosition == 1) {
+ pmt->majortype = MEDIATYPE_MPEG2_PES;
+ }
return S_OK;
}
diff --git a/src/filters/transform/DeCSSFilter/DeCSSFilter.h b/src/filters/transform/DeCSSFilter/DeCSSFilter.h
index 37c1aa0d0..58fbf1f2d 100644
--- a/src/filters/transform/DeCSSFilter/DeCSSFilter.h
+++ b/src/filters/transform/DeCSSFilter/DeCSSFilter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -22,7 +22,7 @@
#pragma once
class __declspec(uuid("7B3BD419-FE03-4820-BE94-A22A4F844895"))
-CDeCSSFilter : public CTransformFilter
+ CDeCSSFilter : public CTransformFilter
{
friend class CKsPSInputPin;
@@ -30,10 +30,10 @@ public:
CDeCSSFilter(LPUNKNOWN lpunk, HRESULT* phr);
virtual ~CDeCSSFilter();
- HRESULT Transform(IMediaSample* pIn, IMediaSample* pOut);
- HRESULT CheckInputType(const CMediaType* mtIn);
- HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
- HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
- HRESULT GetMediaType(int iPosition, CMediaType* pmt);
+ HRESULT Transform(IMediaSample* pIn, IMediaSample* pOut);
+ HRESULT CheckInputType(const CMediaType* mtIn);
+ HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
+ HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT GetMediaType(int iPosition, CMediaType* pmt);
};
diff --git a/src/filters/transform/DeCSSFilter/stdafx.cpp b/src/filters/transform/DeCSSFilter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/transform/DeCSSFilter/stdafx.cpp
+++ b/src/filters/transform/DeCSSFilter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/DeCSSFilter/stdafx.h b/src/filters/transform/DeCSSFilter/stdafx.h
index 62d50a36b..d1c3768d8 100644
--- a/src/filters/transform/DeCSSFilter/stdafx.h
+++ b/src/filters/transform/DeCSSFilter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/MPCVideoDec/DXVADecoder.cpp b/src/filters/transform/MPCVideoDec/DXVADecoder.cpp
index 771fbc212..374080e74 100644
--- a/src/filters/transform/MPCVideoDec/DXVADecoder.cpp
+++ b/src/filters/transform/MPCVideoDec/DXVADecoder.cpp
@@ -98,8 +98,9 @@ void CDXVADecoder::AllocExecuteParams (int nSize)
{
m_ExecuteParams.pCompressedBuffers = DNew DXVA2_DecodeBufferDesc[nSize];
- for (int i=0; i<nSize; i++)
+ for (int i=0; i<nSize; i++) {
memset (&m_ExecuteParams.pCompressedBuffers[i], 0, sizeof(DXVA2_DecodeBufferDesc));
+ }
}
void CDXVADecoder::SetExtraData (BYTE* pDataIn, UINT nSize)
@@ -117,8 +118,7 @@ void CDXVADecoder::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSize)
void CDXVADecoder::Flush()
{
TRACE ("CDXVADecoder::Flush\n");
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
m_pPictureStore[i].bRefPicture = false;
m_pPictureStore[i].bInUse = false;
m_pPictureStore[i].bDisplayed = false;
@@ -139,8 +139,7 @@ HRESULT CDXVADecoder::ConfigureDXVA1()
HRESULT hr = S_FALSE;
DXVA_ConfigPictureDecode ConfigRequested;
- if (m_pAMVideoAccelerator)
- {
+ if (m_pAMVideoAccelerator) {
memset (&ConfigRequested, 0, sizeof(ConfigRequested));
ConfigRequested.guidConfigBitstreamEncryption = DXVA_NoEncrypt;
ConfigRequested.guidConfigMBcontrolEncryption = DXVA_NoEncrypt;
@@ -167,13 +166,12 @@ HRESULT CDXVADecoder::ConfigureDXVA1()
m_DXVA2Config.ConfigSpecificIDCT = m_DXVA1Config.bConfigSpecificIDCT;
m_DXVA2Config.Config4GroupedCoefs = m_DXVA1Config.bConfig4GroupedCoefs;
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
writeDXVA_QueryOrReplyFunc (&m_DXVA1Config.dwFunction, DXVA_QUERYORREPLYFUNCFLAG_DECODER_LOCK_QUERY, DXVA_PICTURE_DECODING_FUNCTION);
hr = m_pAMVideoAccelerator->Execute (m_DXVA1Config.dwFunction, &m_DXVA1Config, sizeof(DXVA_ConfigPictureDecode), &ConfigRequested, sizeof(DXVA_ConfigPictureDecode), 0, NULL);
// TODO : check config!
-// ASSERT (ConfigRequested.bConfigBitstreamRaw == 2);
+ // ASSERT (ConfigRequested.bConfigBitstreamRaw == 2);
AMVAUncompDataInfo DataInfo;
DWORD dwNum = COMP_BUFFER_COUNT;
@@ -190,14 +188,15 @@ CDXVADecoder* CDXVADecoder::CreateDecoder (CMPCVideoDecFilter* pFilter, IAMVideo
{
CDXVADecoder* pDecoder = NULL;
- if ((*guidDecoder == DXVA2_ModeH264_E) || (*guidDecoder == DXVA2_ModeH264_F) || (*guidDecoder == DXVA_Intel_H264_ClearVideo))
+ if ((*guidDecoder == DXVA2_ModeH264_E) || (*guidDecoder == DXVA2_ModeH264_F) || (*guidDecoder == DXVA_Intel_H264_ClearVideo)) {
pDecoder = DNew CDXVADecoderH264 (pFilter, pAMVideoAccelerator, H264_VLD, nPicEntryNumber);
- else if (*guidDecoder == DXVA2_ModeVC1_D || *guidDecoder == DXVA_Intel_VC1_ClearVideo)
+ } else if (*guidDecoder == DXVA2_ModeVC1_D || *guidDecoder == DXVA_Intel_VC1_ClearVideo) {
pDecoder = DNew CDXVADecoderVC1 (pFilter, pAMVideoAccelerator, VC1_VLD, nPicEntryNumber);
- else if (*guidDecoder == DXVA2_ModeMPEG2_VLD)
+ } else if (*guidDecoder == DXVA2_ModeMPEG2_VLD) {
pDecoder = DNew CDXVADecoderMpeg2 (pFilter, pAMVideoAccelerator, MPEG2_VLD, nPicEntryNumber);
- else
- ASSERT (FALSE); // Unknown decoder !!
+ } else {
+ ASSERT (FALSE); // Unknown decoder !!
+ }
return pDecoder;
}
@@ -207,14 +206,15 @@ CDXVADecoder* CDXVADecoder::CreateDecoder (CMPCVideoDecFilter* pFilter, IDirectX
{
CDXVADecoder* pDecoder = NULL;
- if ((*guidDecoder == DXVA2_ModeH264_E) || (*guidDecoder == DXVA2_ModeH264_F) || (*guidDecoder == DXVA_Intel_H264_ClearVideo))
+ if ((*guidDecoder == DXVA2_ModeH264_E) || (*guidDecoder == DXVA2_ModeH264_F) || (*guidDecoder == DXVA_Intel_H264_ClearVideo)) {
pDecoder = DNew CDXVADecoderH264 (pFilter, pDirectXVideoDec, H264_VLD, nPicEntryNumber, pDXVA2Config);
- else if (*guidDecoder == DXVA2_ModeVC1_D || *guidDecoder == DXVA_Intel_VC1_ClearVideo)
+ } else if (*guidDecoder == DXVA2_ModeVC1_D || *guidDecoder == DXVA_Intel_VC1_ClearVideo) {
pDecoder = DNew CDXVADecoderVC1 (pFilter, pDirectXVideoDec, VC1_VLD, nPicEntryNumber, pDXVA2Config);
- else if (*guidDecoder == DXVA2_ModeMPEG2_VLD)
+ } else if (*guidDecoder == DXVA2_ModeMPEG2_VLD) {
pDecoder = DNew CDXVADecoderMpeg2 (pFilter, pDirectXVideoDec, MPEG2_VLD, nPicEntryNumber, pDXVA2Config);
- else
- ASSERT (FALSE); // Unknown decoder !!
+ } else {
+ ASSERT (FALSE); // Unknown decoder !!
+ }
return pDecoder;
}
@@ -230,60 +230,61 @@ HRESULT CDXVADecoder::AddExecuteBuffer (DWORD CompressedBufferType, UINT nSize,
//if (CompressedBufferType != DXVA2_PictureParametersBufferType && CompressedBufferType != DXVA2_InverseQuantizationMatrixBufferType)
// dwNumMBs = FFGetMBNumber (m_pFilter->GetAVCtx());
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- DWORD dwTypeIndex;
- LONG lStride;
- dwTypeIndex = GetDXVA1CompressedType (CompressedBufferType);
-
-// TRACE ("Fill : %d - %d\n", dwTypeIndex, m_dwBufferIndex);
- hr = m_pAMVideoAccelerator->GetBuffer(dwTypeIndex, m_dwBufferIndex, FALSE, (void**)&pDXVABuffer, &lStride);
- ASSERT (SUCCEEDED (hr));
-
- if (SUCCEEDED (hr))
- {
- if (CompressedBufferType == DXVA2_BitStreamDateBufferType)
- CopyBitstream (pDXVABuffer, (BYTE*)pBuffer, nSize);
- else
- memcpy (pDXVABuffer, (BYTE*)pBuffer, nSize);
- m_DXVA1BufferInfo[m_dwNumBuffersInfo].dwTypeIndex = dwTypeIndex;
- m_DXVA1BufferInfo[m_dwNumBuffersInfo].dwBufferIndex = m_dwBufferIndex;
- m_DXVA1BufferInfo[m_dwNumBuffersInfo].dwDataSize = nSize;
-
- m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwTypeIndex = dwTypeIndex;
- m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwBufferIndex = m_dwBufferIndex;
- m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwDataSize = nSize;
- m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwNumMBsInBuffer = dwNumMBs;
-
- m_dwNumBuffersInfo++;
- }
- break;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ DWORD dwTypeIndex;
+ LONG lStride;
+ dwTypeIndex = GetDXVA1CompressedType (CompressedBufferType);
- case ENGINE_DXVA2 :
- UINT nDXVASize;
- hr = m_pDirectXVideoDec->GetBuffer (CompressedBufferType, (void**)&pDXVABuffer, &nDXVASize);
- ASSERT (nSize <= nDXVASize);
+ // TRACE ("Fill : %d - %d\n", dwTypeIndex, m_dwBufferIndex);
+ hr = m_pAMVideoAccelerator->GetBuffer(dwTypeIndex, m_dwBufferIndex, FALSE, (void**)&pDXVABuffer, &lStride);
+ ASSERT (SUCCEEDED (hr));
- if (SUCCEEDED (hr) && (nSize <= nDXVASize))
- {
- if (CompressedBufferType == DXVA2_BitStreamDateBufferType)
- CopyBitstream (pDXVABuffer, (BYTE*)pBuffer, nSize);
- else
- memcpy (pDXVABuffer, (BYTE*)pBuffer, nSize);
+ if (SUCCEEDED (hr)) {
+ if (CompressedBufferType == DXVA2_BitStreamDateBufferType) {
+ CopyBitstream (pDXVABuffer, (BYTE*)pBuffer, nSize);
+ } else {
+ memcpy (pDXVABuffer, (BYTE*)pBuffer, nSize);
+ }
+ m_DXVA1BufferInfo[m_dwNumBuffersInfo].dwTypeIndex = dwTypeIndex;
+ m_DXVA1BufferInfo[m_dwNumBuffersInfo].dwBufferIndex = m_dwBufferIndex;
+ m_DXVA1BufferInfo[m_dwNumBuffersInfo].dwDataSize = nSize;
+
+ m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwTypeIndex = dwTypeIndex;
+ m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwBufferIndex = m_dwBufferIndex;
+ m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwDataSize = nSize;
+ m_DXVA1BufferDesc[m_dwNumBuffersInfo].dwNumMBsInBuffer = dwNumMBs;
+
+ m_dwNumBuffersInfo++;
+ }
+ break;
- m_ExecuteParams.pCompressedBuffers[m_ExecuteParams.NumCompBuffers].CompressedBufferType = CompressedBufferType;
- m_ExecuteParams.pCompressedBuffers[m_ExecuteParams.NumCompBuffers].DataSize = nSize;
- m_ExecuteParams.pCompressedBuffers[m_ExecuteParams.NumCompBuffers].NumMBsInBuffer = dwNumMBs;
- m_ExecuteParams.NumCompBuffers++;
+ case ENGINE_DXVA2 :
+ UINT nDXVASize;
+ hr = m_pDirectXVideoDec->GetBuffer (CompressedBufferType, (void**)&pDXVABuffer, &nDXVASize);
+ ASSERT (nSize <= nDXVASize);
+
+ if (SUCCEEDED (hr) && (nSize <= nDXVASize)) {
+ if (CompressedBufferType == DXVA2_BitStreamDateBufferType) {
+ CopyBitstream (pDXVABuffer, (BYTE*)pBuffer, nSize);
+ } else {
+ memcpy (pDXVABuffer, (BYTE*)pBuffer, nSize);
+ }
+
+ m_ExecuteParams.pCompressedBuffers[m_ExecuteParams.NumCompBuffers].CompressedBufferType = CompressedBufferType;
+ m_ExecuteParams.pCompressedBuffers[m_ExecuteParams.NumCompBuffers].DataSize = nSize;
+ m_ExecuteParams.pCompressedBuffers[m_ExecuteParams.NumCompBuffers].NumMBsInBuffer = dwNumMBs;
+ m_ExecuteParams.NumCompBuffers++;
- }
- break;
- default :
- ASSERT (FALSE);
- break;
+ }
+ break;
+ default :
+ ASSERT (FALSE);
+ break;
+ }
+ if (pRealSize) {
+ *pRealSize = nSize;
}
- if (pRealSize) *pRealSize = nSize;
return hr;
}
@@ -295,15 +296,13 @@ HRESULT CDXVADecoder::GetDeliveryBuffer(REFERENCE_TIME rtStart, REFERENCE_TIME r
CComPtr<IMediaSample> pNewSample;
// Change aspect ratio for DXVA2
- if (m_nEngine == ENGINE_DXVA2)
- {
+ if (m_nEngine == ENGINE_DXVA2) {
m_pFilter->UpdateAspectRatio();
m_pFilter->ReconnectOutput(m_pFilter->PictWidthRounded(), m_pFilter->PictHeightRounded(), true, m_pFilter->PictWidth(), m_pFilter->PictHeight());
}
hr = m_pFilter->GetOutputPin()->GetDeliveryBuffer(&pNewSample, 0, 0, 0);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
pNewSample->SetTime(&rtStart, &rtStop);
pNewSample->SetMediaTime(NULL, NULL);
*ppSampleToDeliver = pNewSample.Detach();
@@ -315,43 +314,40 @@ HRESULT CDXVADecoder::Execute()
{
HRESULT hr = E_INVALIDARG;
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- DWORD dwFunction;
- HRESULT hr2;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ DWORD dwFunction;
+ HRESULT hr2;
-// writeDXVA_QueryOrReplyFunc (&dwFunction, DXVA_QUERYORREPLYFUNCFLAG_DECODER_LOCK_QUERY, DXVA_PICTURE_DECODING_FUNCTION);
-// hr = m_pAMVideoAccelerator->Execute (dwFunction, &m_DXVA1Config, sizeof(DXVA_ConfigPictureDecode), NULL, 0, m_dwNumBuffersInfo, m_DXVA1BufferInfo);
+ // writeDXVA_QueryOrReplyFunc (&dwFunction, DXVA_QUERYORREPLYFUNCFLAG_DECODER_LOCK_QUERY, DXVA_PICTURE_DECODING_FUNCTION);
+ // hr = m_pAMVideoAccelerator->Execute (dwFunction, &m_DXVA1Config, sizeof(DXVA_ConfigPictureDecode), NULL, 0, m_dwNumBuffersInfo, m_DXVA1BufferInfo);
- DWORD dwResult;
- dwFunction = 0x01000000;
- hr = m_pAMVideoAccelerator->Execute (dwFunction, m_DXVA1BufferDesc, sizeof(DXVA_BufferDescription)*m_dwNumBuffersInfo,&dwResult, sizeof(dwResult), m_dwNumBuffersInfo, m_DXVA1BufferInfo);
- ASSERT (SUCCEEDED (hr));
+ DWORD dwResult;
+ dwFunction = 0x01000000;
+ hr = m_pAMVideoAccelerator->Execute (dwFunction, m_DXVA1BufferDesc, sizeof(DXVA_BufferDescription)*m_dwNumBuffersInfo,&dwResult, sizeof(dwResult), m_dwNumBuffersInfo, m_DXVA1BufferInfo);
+ ASSERT (SUCCEEDED (hr));
- for (DWORD i=0; i<m_dwNumBuffersInfo; i++)
- {
- hr2 = m_pAMVideoAccelerator->ReleaseBuffer (m_DXVA1BufferInfo[i].dwTypeIndex, m_DXVA1BufferInfo[i].dwBufferIndex);
- ASSERT (SUCCEEDED (hr2));
- }
+ for (DWORD i=0; i<m_dwNumBuffersInfo; i++) {
+ hr2 = m_pAMVideoAccelerator->ReleaseBuffer (m_DXVA1BufferInfo[i].dwTypeIndex, m_DXVA1BufferInfo[i].dwBufferIndex);
+ ASSERT (SUCCEEDED (hr2));
+ }
- m_dwNumBuffersInfo = 0;
- break;
+ m_dwNumBuffersInfo = 0;
+ break;
- case ENGINE_DXVA2 :
+ case ENGINE_DXVA2 :
- for (DWORD i=0; i<m_ExecuteParams.NumCompBuffers; i++)
- {
- hr2 = m_pDirectXVideoDec->ReleaseBuffer (m_ExecuteParams.pCompressedBuffers[i].CompressedBufferType);
- ASSERT (SUCCEEDED (hr2));
- }
+ for (DWORD i=0; i<m_ExecuteParams.NumCompBuffers; i++) {
+ hr2 = m_pDirectXVideoDec->ReleaseBuffer (m_ExecuteParams.pCompressedBuffers[i].CompressedBufferType);
+ ASSERT (SUCCEEDED (hr2));
+ }
- hr = m_pDirectXVideoDec->Execute(&m_ExecuteParams);
- m_ExecuteParams.NumCompBuffers = 0;
- break;
- default :
- ASSERT (FALSE);
- break;
+ hr = m_pDirectXVideoDec->Execute(&m_ExecuteParams);
+ m_ExecuteParams.NumCompBuffers = 0;
+ break;
+ default :
+ ASSERT (FALSE);
+ break;
}
return hr;
@@ -364,24 +360,23 @@ HRESULT CDXVADecoder::QueryStatus(PVOID LPDXVAStatus, UINT nSize)
DXVA2_DecodeExtensionData ExtensionData;
DWORD dwFunction = 0x07000000;
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- hr = m_pAMVideoAccelerator->Execute (dwFunction, NULL, 0, LPDXVAStatus, nSize, 0, NULL);
- break;
-
- case ENGINE_DXVA2 :
- memset (&ExecuteParams, 0, sizeof(ExecuteParams));
- memset (&ExtensionData, 0, sizeof(ExtensionData));
- ExecuteParams.pExtensionData = &ExtensionData;
- ExtensionData.pPrivateOutputData = LPDXVAStatus;
- ExtensionData.PrivateOutputDataSize = nSize;
- ExtensionData.Function = 7;
- hr = m_pDirectXVideoDec->Execute(&ExecuteParams);
- break;
- default :
- ASSERT (FALSE);
- break;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ hr = m_pAMVideoAccelerator->Execute (dwFunction, NULL, 0, LPDXVAStatus, nSize, 0, NULL);
+ break;
+
+ case ENGINE_DXVA2 :
+ memset (&ExecuteParams, 0, sizeof(ExecuteParams));
+ memset (&ExtensionData, 0, sizeof(ExtensionData));
+ ExecuteParams.pExtensionData = &ExtensionData;
+ ExtensionData.pPrivateOutputData = LPDXVAStatus;
+ ExtensionData.PrivateOutputDataSize = nSize;
+ ExtensionData.Function = 7;
+ hr = m_pDirectXVideoDec->Execute(&ExecuteParams);
+ break;
+ default :
+ ASSERT (FALSE);
+ break;
}
return hr;
@@ -389,21 +384,19 @@ HRESULT CDXVADecoder::QueryStatus(PVOID LPDXVAStatus, UINT nSize)
DWORD CDXVADecoder::GetDXVA1CompressedType (DWORD dwDXVA2CompressedType)
{
- if (dwDXVA2CompressedType <= DXVA2_BitStreamDateBufferType)
+ if (dwDXVA2CompressedType <= DXVA2_BitStreamDateBufferType) {
return dwDXVA2CompressedType + 1;
- else
- {
- switch (dwDXVA2CompressedType)
- {
- case DXVA2_MotionVectorBuffer :
- return DXVA_MOTION_VECTOR_BUFFER;
- break;
- case DXVA2_FilmGrainBuffer :
- return DXVA_FILM_GRAIN_BUFFER;
- break;
- default :
- ASSERT (FALSE);
- return DXVA_COMPBUFFER_TYPE_THAT_IS_NOT_USED;
+ } else {
+ switch (dwDXVA2CompressedType) {
+ case DXVA2_MotionVectorBuffer :
+ return DXVA_MOTION_VECTOR_BUFFER;
+ break;
+ case DXVA2_FilmGrainBuffer :
+ return DXVA_FILM_GRAIN_BUFFER;
+ break;
+ default :
+ ASSERT (FALSE);
+ return DXVA_COMPBUFFER_TYPE_THAT_IS_NOT_USED;
}
}
}
@@ -425,47 +418,47 @@ HRESULT CDXVADecoder::BeginFrame(int nSurfaceIndex, IMediaSample* pSampleToDeliv
HRESULT hr = E_INVALIDARG;
int nTry = 0;
- for (int i=0; i<20; i++)
- {
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- AMVABeginFrameInfo BeginFrameInfo;
+ for (int i=0; i<20; i++) {
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ AMVABeginFrameInfo BeginFrameInfo;
- BeginFrameInfo.dwDestSurfaceIndex = nSurfaceIndex;
- BeginFrameInfo.dwSizeInputData = sizeof(nSurfaceIndex);
- BeginFrameInfo.pInputData = &nSurfaceIndex;
- BeginFrameInfo.dwSizeOutputData = 0;
- BeginFrameInfo.pOutputData = NULL;
+ BeginFrameInfo.dwDestSurfaceIndex = nSurfaceIndex;
+ BeginFrameInfo.dwSizeInputData = sizeof(nSurfaceIndex);
+ BeginFrameInfo.pInputData = &nSurfaceIndex;
+ BeginFrameInfo.dwSizeOutputData = 0;
+ BeginFrameInfo.pOutputData = NULL;
- DO_DXVA_PENDING_LOOP (m_pAMVideoAccelerator->BeginFrame(&BeginFrameInfo));
+ DO_DXVA_PENDING_LOOP (m_pAMVideoAccelerator->BeginFrame(&BeginFrameInfo));
- ASSERT (SUCCEEDED (hr));
- // TRACE ("BeginFrame %d\n",nSurfaceIndex);
- if (SUCCEEDED (hr))
- hr = FindFreeDXVA1Buffer ((DWORD)-1, m_dwBufferIndex);
- break;
+ ASSERT (SUCCEEDED (hr));
+ // TRACE ("BeginFrame %d\n",nSurfaceIndex);
+ if (SUCCEEDED (hr)) {
+ hr = FindFreeDXVA1Buffer ((DWORD)-1, m_dwBufferIndex);
+ }
+ break;
- case ENGINE_DXVA2 :
- {
- CComQIPtr<IMFGetService> pSampleService;
- CComPtr<IDirect3DSurface9> pDecoderRenderTarget;
- pSampleService = pSampleToDeliver;
- if (pSampleService)
- {
- hr = pSampleService->GetService (MR_BUFFER_SERVICE, __uuidof(IDirect3DSurface9), (void**) &pDecoderRenderTarget);
- if (SUCCEEDED (hr))
- DO_DXVA_PENDING_LOOP (m_pDirectXVideoDec->BeginFrame(pDecoderRenderTarget, NULL));
+ case ENGINE_DXVA2 : {
+ CComQIPtr<IMFGetService> pSampleService;
+ CComPtr<IDirect3DSurface9> pDecoderRenderTarget;
+ pSampleService = pSampleToDeliver;
+ if (pSampleService) {
+ hr = pSampleService->GetService (MR_BUFFER_SERVICE, __uuidof(IDirect3DSurface9), (void**) &pDecoderRenderTarget);
+ if (SUCCEEDED (hr)) {
+ DO_DXVA_PENDING_LOOP (m_pDirectXVideoDec->BeginFrame(pDecoderRenderTarget, NULL));
+ }
+ }
}
- }
- break;
- default :
- ASSERT (FALSE);
break;
+ default :
+ ASSERT (FALSE);
+ break;
}
// For slow accelerator wait a little...
- if (SUCCEEDED (hr)) break;
+ if (SUCCEEDED (hr)) {
+ break;
+ }
Sleep(1);
}
@@ -478,24 +471,23 @@ HRESULT CDXVADecoder::EndFrame(int nSurfaceIndex)
HRESULT hr = E_INVALIDARG;
DWORD dwDummy = nSurfaceIndex;
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- AMVAEndFrameInfo EndFrameInfo;
-
- EndFrameInfo.dwSizeMiscData = sizeof (dwDummy); // TODO : usefull ??
- EndFrameInfo.pMiscData = &dwDummy;
- hr = m_pAMVideoAccelerator->EndFrame(&EndFrameInfo);
-// TRACE ("EndFrame %d\n",nSurfaceIndex);
- ASSERT (SUCCEEDED (hr));
- break;
-
- case ENGINE_DXVA2 :
- hr = m_pDirectXVideoDec->EndFrame(NULL);
- break;
- default :
- ASSERT (FALSE);
- break;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ AMVAEndFrameInfo EndFrameInfo;
+
+ EndFrameInfo.dwSizeMiscData = sizeof (dwDummy); // TODO : usefull ??
+ EndFrameInfo.pMiscData = &dwDummy;
+ hr = m_pAMVideoAccelerator->EndFrame(&EndFrameInfo);
+ // TRACE ("EndFrame %d\n",nSurfaceIndex);
+ ASSERT (SUCCEEDED (hr));
+ break;
+
+ case ENGINE_DXVA2 :
+ hr = m_pDirectXVideoDec->EndFrame(NULL);
+ break;
+ default :
+ ASSERT (FALSE);
+ break;
}
return hr;
@@ -506,8 +498,7 @@ bool CDXVADecoder::AddToStore (int nSurfaceIndex, IMediaSample* pSample, bool bR
REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, bool bIsField,
FF_FIELD_TYPE nFieldType, FF_SLICE_TYPE nSliceType, int nCodecSpecific)
{
- if (bIsField && (m_nFieldSurface == -1))
- {
+ if (bIsField && (m_nFieldSurface == -1)) {
m_nFieldSurface = nSurfaceIndex;
m_pFieldSample = pSample;
m_pPictureStore[nSurfaceIndex].n1FieldType = nFieldType;
@@ -515,9 +506,7 @@ bool CDXVADecoder::AddToStore (int nSurfaceIndex, IMediaSample* pSample, bool bR
m_pPictureStore[nSurfaceIndex].rtStop = rtStop;
m_pPictureStore[nSurfaceIndex].nCodecSpecific = nCodecSpecific;
return false;
- }
- else
- {
+ } else {
//TRACE ("Add Stor: %10I64d - %10I64d Ind = %d Codec=%d\n", rtStart, rtStop, nSurfaceIndex, nCodecSpecific);
ASSERT (m_pPictureStore[nSurfaceIndex].pSample == NULL);
ASSERT (!m_pPictureStore[nSurfaceIndex].bInUse);
@@ -529,8 +518,7 @@ bool CDXVADecoder::AddToStore (int nSurfaceIndex, IMediaSample* pSample, bool bR
m_pPictureStore[nSurfaceIndex].pSample = pSample;
m_pPictureStore[nSurfaceIndex].nSliceType = nSliceType;
- if (!bIsField)
- {
+ if (!bIsField) {
m_pPictureStore[nSurfaceIndex].rtStart = rtStart;
m_pPictureStore[nSurfaceIndex].rtStop = rtStop;
m_pPictureStore[nSurfaceIndex].n1FieldType = nFieldType;
@@ -555,8 +543,9 @@ void CDXVADecoder::RemoveRefFrame (int nSurfaceIndex)
ASSERT ((nSurfaceIndex < m_nPicEntryNumber) && m_pPictureStore[nSurfaceIndex].bInUse);
m_pPictureStore[nSurfaceIndex].bRefPicture = false;
- if (m_pPictureStore[nSurfaceIndex].bDisplayed)
+ if (m_pPictureStore[nSurfaceIndex].bDisplayed) {
FreePictureSlot (nSurfaceIndex);
+ }
}
@@ -566,14 +555,11 @@ int CDXVADecoder::FindOldestFrame()
int nPos = -1;
// TODO : find better solution...
- if (m_nWaitingPics > m_nMaxWaiting)
- {
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
+ if (m_nWaitingPics > m_nMaxWaiting) {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
if (!m_pPictureStore[i].bDisplayed &&
- m_pPictureStore[i].bInUse &&
- (m_pPictureStore[i].rtStart < rtMin))
- {
+ m_pPictureStore[i].bInUse &&
+ (m_pPictureStore[i].rtStart < rtMin)) {
rtMin = m_pPictureStore[i].rtStart;
nPos = i;
}
@@ -584,36 +570,33 @@ int CDXVADecoder::FindOldestFrame()
void CDXVADecoder::SetTypeSpecificFlags(PICTURE_STORE* pPicture, IMediaSample* pMS)
{
- if(CComQIPtr<IMediaSample2> pMS2 = pMS)
- {
+ if(CComQIPtr<IMediaSample2> pMS2 = pMS) {
AM_SAMPLE2_PROPERTIES props;
- if(SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props)))
- {
+ if(SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props))) {
props.dwTypeSpecificFlags &= ~0x7f;
- if(pPicture->n1FieldType == PICT_FRAME)
+ if(pPicture->n1FieldType == PICT_FRAME) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_WEAVE;
- else
- {
- if(pPicture->n1FieldType == PICT_TOP_FIELD)
+ } else {
+ if(pPicture->n1FieldType == PICT_TOP_FIELD) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_FIELD1FIRST;
+ }
//if(m_fb.flags & PIC_FLAG_REPEAT_FIRST_FIELD)
// props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_REPEAT_FIELD;
}
- switch (pPicture->nSliceType)
- {
- case I_TYPE :
- case SI_TYPE :
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_I_SAMPLE;
- break;
- case P_TYPE :
- case SP_TYPE :
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_P_SAMPLE;
- break;
- default :
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_B_SAMPLE;
- break;
+ switch (pPicture->nSliceType) {
+ case I_TYPE :
+ case SI_TYPE :
+ props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_I_SAMPLE;
+ break;
+ case P_TYPE :
+ case SP_TYPE :
+ props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_P_SAMPLE;
+ break;
+ default :
+ props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_B_SAMPLE;
+ break;
}
pMS2->SetProperties(sizeof(props), (BYTE*)&props);
@@ -630,24 +613,23 @@ HRESULT CDXVADecoder::DisplayNextFrame()
int nPicIndex;
nPicIndex = FindOldestFrame();
- if (nPicIndex != -1)
- {
- if (m_pPictureStore[nPicIndex].rtStart >= 0)
- {
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- // For DXVA1, query a media sample at the last time (only one in the allocator)
- hr = GetDeliveryBuffer (m_pPictureStore[nPicIndex].rtStart, m_pPictureStore[nPicIndex].rtStop, &pSampleToDeliver);
- SetTypeSpecificFlags(&m_pPictureStore[nPicIndex], pSampleToDeliver);
- if (SUCCEEDED (hr)) hr = m_pAMVideoAccelerator->DisplayFrame(nPicIndex, pSampleToDeliver);
- break;
- case ENGINE_DXVA2 :
- // For DXVA2 media sample is in the picture store
- m_pPictureStore[nPicIndex].pSample->SetTime (&m_pPictureStore[nPicIndex].rtStart, &m_pPictureStore[nPicIndex].rtStop);
- SetTypeSpecificFlags(&m_pPictureStore[nPicIndex], m_pPictureStore[nPicIndex].pSample);
- hr = m_pFilter->GetOutputPin()->Deliver(m_pPictureStore[nPicIndex].pSample);
- break;
+ if (nPicIndex != -1) {
+ if (m_pPictureStore[nPicIndex].rtStart >= 0) {
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ // For DXVA1, query a media sample at the last time (only one in the allocator)
+ hr = GetDeliveryBuffer (m_pPictureStore[nPicIndex].rtStart, m_pPictureStore[nPicIndex].rtStop, &pSampleToDeliver);
+ SetTypeSpecificFlags(&m_pPictureStore[nPicIndex], pSampleToDeliver);
+ if (SUCCEEDED (hr)) {
+ hr = m_pAMVideoAccelerator->DisplayFrame(nPicIndex, pSampleToDeliver);
+ }
+ break;
+ case ENGINE_DXVA2 :
+ // For DXVA2 media sample is in the picture store
+ m_pPictureStore[nPicIndex].pSample->SetTime (&m_pPictureStore[nPicIndex].rtStart, &m_pPictureStore[nPicIndex].rtStop);
+ SetTypeSpecificFlags(&m_pPictureStore[nPicIndex], m_pPictureStore[nPicIndex].pSample);
+ hr = m_pFilter->GetOutputPin()->Deliver(m_pPictureStore[nPicIndex].pSample);
+ break;
}
@@ -665,8 +647,9 @@ HRESULT CDXVADecoder::DisplayNextFrame()
}
m_pPictureStore[nPicIndex].bDisplayed = true;
- if (!m_pPictureStore[nPicIndex].bRefPicture)
+ if (!m_pPictureStore[nPicIndex].bRefPicture) {
FreePictureSlot (nPicIndex);
+ }
}
return hr;
@@ -678,48 +661,42 @@ HRESULT CDXVADecoder::GetFreeSurfaceIndex(int& nSurfaceIndex, IMediaSample** ppS
int nPos = -1;
DWORD dwMinDisplay = MAXDWORD;
- if (m_nFieldSurface != -1)
- {
+ if (m_nFieldSurface != -1) {
nSurfaceIndex = m_nFieldSurface;
*ppSampleToDeliver = m_pFieldSample.Detach();
return S_FALSE;
}
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
- if (!m_pPictureStore[i].bInUse && m_pPictureStore[i].dwDisplayCount < dwMinDisplay)
- {
- dwMinDisplay = m_pPictureStore[i].dwDisplayCount;
- nPos = i;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ for (int i=0; i<m_nPicEntryNumber; i++) {
+ if (!m_pPictureStore[i].bInUse && m_pPictureStore[i].dwDisplayCount < dwMinDisplay) {
+ dwMinDisplay = m_pPictureStore[i].dwDisplayCount;
+ nPos = i;
+ }
}
- }
- if (nPos != -1)
- {
- nSurfaceIndex = nPos;
- return S_OK;
- }
+ if (nPos != -1) {
+ nSurfaceIndex = nPos;
+ return S_OK;
+ }
- // Ho ho...
- ASSERT (FALSE);
- Flush();
- break;
- case ENGINE_DXVA2 :
- CComPtr<IMediaSample> pNewSample;
- CComQIPtr<IMPCDXVA2Sample> pMPCDXVA2Sample;
- // TODO : test IDirect3DDeviceManager9::TestDevice !!!
-// TRACE ("==> Try get buffer...\n");
- if (SUCCEEDED (hr = GetDeliveryBuffer(rtStart, rtStop, &pNewSample)))
- {
- pMPCDXVA2Sample = pNewSample;
- nSurfaceIndex = pMPCDXVA2Sample ? pMPCDXVA2Sample->GetDXSurfaceId() : 0;
- *ppSampleToDeliver = pNewSample.Detach();
-// TRACE ("GetFreeSurfaceIndex : %d\n", nSurfaceIndex);
- }
- break;
+ // Ho ho...
+ ASSERT (FALSE);
+ Flush();
+ break;
+ case ENGINE_DXVA2 :
+ CComPtr<IMediaSample> pNewSample;
+ CComQIPtr<IMPCDXVA2Sample> pMPCDXVA2Sample;
+ // TODO : test IDirect3DDeviceManager9::TestDevice !!!
+ // TRACE ("==> Try get buffer...\n");
+ if (SUCCEEDED (hr = GetDeliveryBuffer(rtStart, rtStop, &pNewSample))) {
+ pMPCDXVA2Sample = pNewSample;
+ nSurfaceIndex = pMPCDXVA2Sample ? pMPCDXVA2Sample->GetDXSurfaceId() : 0;
+ *ppSampleToDeliver = pNewSample.Detach();
+ // TRACE ("GetFreeSurfaceIndex : %d\n", nSurfaceIndex);
+ }
+ break;
}
return hr;
@@ -728,7 +705,7 @@ HRESULT CDXVADecoder::GetFreeSurfaceIndex(int& nSurfaceIndex, IMediaSample** ppS
void CDXVADecoder::FreePictureSlot (int nSurfaceIndex)
{
-// TRACE ("Free : %d\n", nSurfaceIndex);
+ // TRACE ("Free : %d\n", nSurfaceIndex);
m_pPictureStore[nSurfaceIndex].dwDisplayCount = m_dwDisplayCount++;
m_pPictureStore[nSurfaceIndex].bInUse = false;
m_pPictureStore[nSurfaceIndex].bDisplayed = false;
@@ -740,12 +717,11 @@ void CDXVADecoder::FreePictureSlot (int nSurfaceIndex)
BYTE CDXVADecoder::GetConfigResidDiffAccelerator()
{
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- return m_DXVA1Config.bConfigResidDiffAccelerator;
- case ENGINE_DXVA2 :
- return m_DXVA2Config.ConfigResidDiffAccelerator;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ return m_DXVA1Config.bConfigResidDiffAccelerator;
+ case ENGINE_DXVA2 :
+ return m_DXVA2Config.ConfigResidDiffAccelerator;
}
return 0;
}
@@ -753,12 +729,11 @@ BYTE CDXVADecoder::GetConfigResidDiffAccelerator()
BYTE CDXVADecoder::GetConfigIntraResidUnsigned()
{
- switch (m_nEngine)
- {
- case ENGINE_DXVA1 :
- return m_DXVA1Config.bConfigIntraResidUnsigned;
- case ENGINE_DXVA2 :
- return m_DXVA2Config.ConfigIntraResidUnsigned;
+ switch (m_nEngine) {
+ case ENGINE_DXVA1 :
+ return m_DXVA1Config.bConfigIntraResidUnsigned;
+ case ENGINE_DXVA2 :
+ return m_DXVA2Config.ConfigIntraResidUnsigned;
}
return 0;
}
diff --git a/src/filters/transform/MPCVideoDec/DXVADecoder.h b/src/filters/transform/MPCVideoDec/DXVADecoder.h
index a8c92154b..6c776454e 100644
--- a/src/filters/transform/MPCVideoDec/DXVADecoder.h
+++ b/src/filters/transform/MPCVideoDec/DXVADecoder.h
@@ -26,28 +26,24 @@
#include <dxva2api.h>
#include <videoacc.h>
-typedef enum
-{
+typedef enum {
ENGINE_DXVA1,
ENGINE_DXVA2
} DXVA_ENGINE;
-typedef enum
-{
+typedef enum {
H264_VLD,
VC1_VLD,
MPEG2_VLD
} DXVAMode;
-typedef enum
-{
+typedef enum {
PICT_TOP_FIELD = 1,
PICT_BOTTOM_FIELD = 2,
PICT_FRAME = 3
} FF_FIELD_TYPE;
-typedef enum
-{
+typedef enum {
I_TYPE = 1, ///< Intra
P_TYPE = 2, ///< Predicted
B_TYPE = 3, ///< Bi-dir predicted
@@ -57,8 +53,7 @@ typedef enum
BI_TYPE = 7
} FF_SLICE_TYPE;
-typedef struct
-{
+typedef struct {
bool bRefPicture; // True if reference picture
bool bInUse; // Slot in use
bool bDisplayed; // True if picture have been presented
diff --git a/src/filters/transform/MPCVideoDec/DXVADecoderH264.cpp b/src/filters/transform/MPCVideoDec/DXVADecoderH264.cpp
index 612168526..d75e7f310 100644
--- a/src/filters/transform/MPCVideoDec/DXVADecoderH264.cpp
+++ b/src/filters/transform/MPCVideoDec/DXVADecoderH264.cpp
@@ -60,18 +60,18 @@ void CDXVADecoderH264::Init()
memset (&m_pSliceShort, 0, sizeof (DXVA_Slice_H264_Short)*MAX_SLICES);
m_DXVAPicParams.MbsConsecutiveFlag = 1;
- if(m_pFilter->GetPCIVendor() == PCIV_Intel)
+ if(m_pFilter->GetPCIVendor() == PCIV_Intel) {
m_DXVAPicParams.Reserved16Bits = 0x534c;
- else
+ } else {
m_DXVAPicParams.Reserved16Bits = 0;
+ }
m_DXVAPicParams.ContinuationFlag = 1;
m_DXVAPicParams.Reserved8BitsA = 0;
m_DXVAPicParams.Reserved8BitsB = 0;
m_DXVAPicParams.MinLumaBipredSize8x8Flag = 1; // Improve accelerator performances
m_DXVAPicParams.StatusReportFeedbackNumber = 0; // Use to report status
- for (int i =0; i<16; i++)
- {
+ for (int i =0; i<16; i++) {
m_DXVAPicParams.RefFrameList[i].AssociatedFlag = 1;
m_DXVAPicParams.RefFrameList[i].bPicEntry = 255;
m_DXVAPicParams.RefFrameList[i].Index7Bits = 127;
@@ -81,13 +81,12 @@ void CDXVADecoderH264::Init()
m_nNALLength = 4;
m_nMaxSlices = 0;
- switch (GetMode())
- {
- case H264_VLD :
- AllocExecuteParams (3);
- break;
- default :
- ASSERT(FALSE);
+ switch (GetMode()) {
+ case H264_VLD :
+ AllocExecuteParams (3);
+ break;
+ default :
+ ASSERT(FALSE);
}
}
@@ -103,67 +102,62 @@ void CDXVADecoderH264::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSi
#if 0
// Test to place Nal on multiple of 128 bytes (seems to be not necessary)
- if(!m_bUseLongSlice)
- {
- while (Nalu.ReadNext())
- {
- switch (Nalu.GetType())
- {
- case NALU_TYPE_SLICE:
- case NALU_TYPE_IDR:
- // For AVC1, put startcode 0x000001
- pDXVABuffer[0]=pDXVABuffer[1]=0;
- pDXVABuffer[2]=1;
-
- // Copy NALU
- memcpy (pDXVABuffer+3, Nalu.GetDataBuffer(), Nalu.GetDataLength());
-
- // Complete with zero padding (buffer size should be a multiple of 128)
- nDummy = 128 - ((Nalu.GetDataLength()+3) %128);
- pDXVABuffer += Nalu.GetDataLength() + 3;
- memset (pDXVABuffer, 0, nDummy);
- pDXVABuffer += nDummy;
-
- // Update slice control buffer
- nDxvaNalLength = Nalu.GetDataLength()+3+nDummy;
- m_pSliceShort[nSlices].BSNALunitDataLocation = nSize;
- m_pSliceShort[nSlices].SliceBytesInBuffer = nDxvaNalLength;
-
- nSize += nDxvaNalLength;
- nSlices++;
- break;
+ if(!m_bUseLongSlice) {
+ while (Nalu.ReadNext()) {
+ switch (Nalu.GetType()) {
+ case NALU_TYPE_SLICE:
+ case NALU_TYPE_IDR:
+ // For AVC1, put startcode 0x000001
+ pDXVABuffer[0]=pDXVABuffer[1]=0;
+ pDXVABuffer[2]=1;
+
+ // Copy NALU
+ memcpy (pDXVABuffer+3, Nalu.GetDataBuffer(), Nalu.GetDataLength());
+
+ // Complete with zero padding (buffer size should be a multiple of 128)
+ nDummy = 128 - ((Nalu.GetDataLength()+3) %128);
+ pDXVABuffer += Nalu.GetDataLength() + 3;
+ memset (pDXVABuffer, 0, nDummy);
+ pDXVABuffer += nDummy;
+
+ // Update slice control buffer
+ nDxvaNalLength = Nalu.GetDataLength()+3+nDummy;
+ m_pSliceShort[nSlices].BSNALunitDataLocation = nSize;
+ m_pSliceShort[nSlices].SliceBytesInBuffer = nDxvaNalLength;
+
+ nSize += nDxvaNalLength;
+ nSlices++;
+ break;
}
}
- }
- else
+ } else
#endif
{
- while (Nalu.ReadNext())
- {
- switch (Nalu.GetType())
- {
- case NALU_TYPE_SLICE:
- case NALU_TYPE_IDR:
- // Skip the NALU if the data length is below 0
- if(Nalu.GetDataLength() < 0)
+ while (Nalu.ReadNext()) {
+ switch (Nalu.GetType()) {
+ case NALU_TYPE_SLICE:
+ case NALU_TYPE_IDR:
+ // Skip the NALU if the data length is below 0
+ if(Nalu.GetDataLength() < 0) {
+ break;
+ }
+
+ // For AVC1, put startcode 0x000001
+ pDXVABuffer[0]=pDXVABuffer[1]=0;
+ pDXVABuffer[2]=1;
+
+ // Copy NALU
+ memcpy (pDXVABuffer+3, Nalu.GetDataBuffer(), Nalu.GetDataLength());
+
+ // Update slice control buffer
+ nDxvaNalLength = Nalu.GetDataLength()+3;
+ m_pSliceShort[nSlices].BSNALunitDataLocation = nSize;
+ m_pSliceShort[nSlices].SliceBytesInBuffer = nDxvaNalLength;
+
+ nSize += nDxvaNalLength;
+ pDXVABuffer += nDxvaNalLength;
+ nSlices++;
break;
-
- // For AVC1, put startcode 0x000001
- pDXVABuffer[0]=pDXVABuffer[1]=0;
- pDXVABuffer[2]=1;
-
- // Copy NALU
- memcpy (pDXVABuffer+3, Nalu.GetDataBuffer(), Nalu.GetDataLength());
-
- // Update slice control buffer
- nDxvaNalLength = Nalu.GetDataLength()+3;
- m_pSliceShort[nSlices].BSNALunitDataLocation = nSize;
- m_pSliceShort[nSlices].SliceBytesInBuffer = nDxvaNalLength;
-
- nSize += nDxvaNalLength;
- pDXVABuffer += nDxvaNalLength;
- nSlices++;
- break;
}
}
@@ -204,39 +198,43 @@ HRESULT CDXVADecoderH264::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
Nalu.SetBuffer (pDataIn, nSize, m_nNALLength);
FFH264DecodeBuffer (m_pFilter->GetAVCtx(), pDataIn, nSize, &nFramePOC, &nOutPOC, &rtOutStart);
- while (Nalu.ReadNext())
- {
- switch (Nalu.GetType())
- {
- case NALU_TYPE_SLICE:
- case NALU_TYPE_IDR:
- if(m_bUseLongSlice)
- {
- m_pSliceLong[nSlices].BSNALunitDataLocation = nNalOffset;
- m_pSliceLong[nSlices].SliceBytesInBuffer = Nalu.GetDataLength()+3; //.GetRoundedDataLength();
- m_pSliceLong[nSlices].slice_id = nSlices;
- FF264UpdateRefFrameSliceLong(&m_DXVAPicParams, &m_pSliceLong[nSlices], m_pFilter->GetAVCtx());
-
- if (nSlices>0)
- m_pSliceLong[nSlices-1].NumMbsForSlice = m_pSliceLong[nSlices].NumMbsForSlice = m_pSliceLong[nSlices].first_mb_in_slice - m_pSliceLong[nSlices-1].first_mb_in_slice;
- }
- nSlices++;
- nNalOffset += (UINT)(Nalu.GetDataLength() + 3);
- if (nSlices > MAX_SLICES) break;
- break;
+ while (Nalu.ReadNext()) {
+ switch (Nalu.GetType()) {
+ case NALU_TYPE_SLICE:
+ case NALU_TYPE_IDR:
+ if(m_bUseLongSlice) {
+ m_pSliceLong[nSlices].BSNALunitDataLocation = nNalOffset;
+ m_pSliceLong[nSlices].SliceBytesInBuffer = Nalu.GetDataLength()+3; //.GetRoundedDataLength();
+ m_pSliceLong[nSlices].slice_id = nSlices;
+ FF264UpdateRefFrameSliceLong(&m_DXVAPicParams, &m_pSliceLong[nSlices], m_pFilter->GetAVCtx());
+
+ if (nSlices>0) {
+ m_pSliceLong[nSlices-1].NumMbsForSlice = m_pSliceLong[nSlices].NumMbsForSlice = m_pSliceLong[nSlices].first_mb_in_slice - m_pSliceLong[nSlices-1].first_mb_in_slice;
+ }
+ }
+ nSlices++;
+ nNalOffset += (UINT)(Nalu.GetDataLength() + 3);
+ if (nSlices > MAX_SLICES) {
+ break;
+ }
+ break;
}
}
- if (nSlices == 0) return S_FALSE;
+ if (nSlices == 0) {
+ return S_FALSE;
+ }
m_nMaxWaiting = min (max (m_DXVAPicParams.num_ref_frames, 3), 8);
// If parsing fail (probably no PPS/SPS), continue anyway it may arrived later (happen on truncated streams)
- if (FAILED (FFH264BuildPicParams (&m_DXVAPicParams, &m_DXVAScalingMatrix, &nFieldType, &nSliceType, m_pFilter->GetAVCtx(), m_pFilter->GetPCIVendor())))
+ if (FAILED (FFH264BuildPicParams (&m_DXVAPicParams, &m_DXVAScalingMatrix, &nFieldType, &nSliceType, m_pFilter->GetAVCtx(), m_pFilter->GetPCIVendor()))) {
return S_FALSE;
+ }
// Wait I frame after a flush
- if (m_bFlushed && !m_DXVAPicParams.IntraPicFlag)
+ if (m_bFlushed && !m_DXVAPicParams.IntraPicFlag) {
return S_FALSE;
+ }
CHECK_HR (GetFreeSurfaceIndex (nSurfaceIndex, &pSampleToDeliver, rtStart, rtStop));
@@ -246,7 +244,7 @@ HRESULT CDXVADecoderH264::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
m_DXVAPicParams.StatusReportFeedbackNumber++;
-// TRACE("CDXVADecoderH264 : Decode frame %u\n", m_DXVAPicParams.StatusReportFeedbackNumber);
+ // TRACE("CDXVADecoderH264 : Decode frame %u\n", m_DXVAPicParams.StatusReportFeedbackNumber);
// Send picture parameters
CHECK_HR (AddExecuteBuffer (DXVA2_PictureParametersBufferType, sizeof(m_DXVAPicParams), &m_DXVAPicParams));
@@ -255,12 +253,9 @@ HRESULT CDXVADecoderH264::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
// Add bitstream, slice control and quantization matrix
CHECK_HR (AddExecuteBuffer (DXVA2_BitStreamDateBufferType, nSize, pDataIn, &nSize));
- if (m_bUseLongSlice)
- {
+ if (m_bUseLongSlice) {
CHECK_HR(AddExecuteBuffer(DXVA2_SliceControlBufferType, sizeof(DXVA_Slice_H264_Long)*nSlices, m_pSliceLong));
- }
- else
- {
+ } else {
CHECK_HR (AddExecuteBuffer (DXVA2_SliceControlBufferType, sizeof (DXVA_Slice_H264_Short)*nSlices, m_pSliceShort));
}
@@ -272,7 +267,7 @@ HRESULT CDXVADecoderH264::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
CHECK_HR (EndFrame(nSurfaceIndex));
#ifdef _DEBUG
-// DisplayStatus();
+ // DisplayStatus();
#endif
bool bAdded = AddToStore (nSurfaceIndex, pSampleToDeliver, m_DXVAPicParams.RefPicFlag, rtStart, rtStop,
@@ -282,12 +277,10 @@ HRESULT CDXVADecoderH264::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
FFH264UpdateRefFramesList (&m_DXVAPicParams, m_pFilter->GetAVCtx());
ClearUnusedRefFrames();
- if (bAdded)
- {
+ if (bAdded) {
hr = DisplayNextFrame();
- if (nOutPOC != INT_MIN)
- {
+ if (nOutPOC != INT_MIN) {
m_nOutPOC = nOutPOC;
m_rtOutStart = rtOutStart;
}
@@ -299,10 +292,8 @@ HRESULT CDXVADecoderH264::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
void CDXVADecoderH264::RemoveUndisplayedFrame(int nPOC)
{
// Find frame with given POC, and free the slot
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
- if (m_pPictureStore[i].bInUse && m_pPictureStore[i].nCodecSpecific == nPOC)
- {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
+ if (m_pPictureStore[i].bInUse && m_pPictureStore[i].nCodecSpecific == nPOC) {
m_pPictureStore[i].bDisplayed = true;
RemoveRefFrame (i);
return;
@@ -313,11 +304,11 @@ void CDXVADecoderH264::RemoveUndisplayedFrame(int nPOC)
void CDXVADecoderH264::ClearUnusedRefFrames()
{
// Remove old reference frames (not anymore a short or long ref frame)
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
if (m_pPictureStore[i].bRefPicture && m_pPictureStore[i].bDisplayed)
- if (!FFH264IsRefFrameInUse (i, m_pFilter->GetAVCtx()))
+ if (!FFH264IsRefFrameInUse (i, m_pFilter->GetAVCtx())) {
RemoveRefFrame (i);
+ }
}
}
@@ -334,10 +325,8 @@ void CDXVADecoderH264::ClearRefFramesList()
{
int i;
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
- if (m_pPictureStore[i].bInUse)
- {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
+ if (m_pPictureStore[i].bInUse) {
m_pPictureStore[i].bDisplayed = true;
RemoveRefFrame (i);
}
@@ -369,22 +358,17 @@ int CDXVADecoderH264::FindOldestFrame()
int nPos = -1;
REFERENCE_TIME rtPos = _I64_MAX;
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
- if (m_pPictureStore[i].bInUse && !m_pPictureStore[i].bDisplayed)
- {
- if (m_pPictureStore[i].nCodecSpecific == m_nOutPOC && m_pPictureStore[i].rtStart < rtPos)
- {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
+ if (m_pPictureStore[i].bInUse && !m_pPictureStore[i].bDisplayed) {
+ if (m_pPictureStore[i].nCodecSpecific == m_nOutPOC && m_pPictureStore[i].rtStart < rtPos) {
nPos = i;
rtPos = m_pPictureStore[i].rtStart;
}
}
}
- if (nPos != -1)
- {
- if (m_rtOutStart == _I64_MIN)
- {
+ if (nPos != -1) {
+ if (m_rtOutStart == _I64_MIN) {
// If start time not set (no PTS for example), guess presentation time!
m_rtOutStart = m_rtLastFrameDisplayed;
}
diff --git a/src/filters/transform/MPCVideoDec/DXVADecoderMpeg2.cpp b/src/filters/transform/MPCVideoDec/DXVADecoderMpeg2.cpp
index 3012ae884..af5e4d9a6 100644
--- a/src/filters/transform/MPCVideoDec/DXVADecoderMpeg2.cpp
+++ b/src/filters/transform/MPCVideoDec/DXVADecoderMpeg2.cpp
@@ -67,13 +67,12 @@ void CDXVADecoderMpeg2::Init()
m_wRefPictureIndex[1] = NO_REF_FRAME;
m_nSliceCount = 0;
- switch (GetMode())
- {
- case MPEG2_VLD :
- AllocExecuteParams (4);
- break;
- default :
- ASSERT(FALSE);
+ switch (GetMode()) {
+ case MPEG2_VLD :
+ AllocExecuteParams (4);
+ break;
+ default :
+ ASSERT(FALSE);
}
}
@@ -90,12 +89,12 @@ HRESULT CDXVADecoderMpeg2::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIM
m_pFilter->GetFrame(), &m_nNextCodecIndex, &nFieldType, &nSliceType, pDataIn, nSize);
// Wait I frame after a flush
- if (m_bFlushed && ! m_PictureParams.bPicIntra)
+ if (m_bFlushed && ! m_PictureParams.bPicIntra) {
return S_FALSE;
+ }
hr = GetFreeSurfaceIndex (nSurfaceIndex, &pSampleToDeliver, rtStart, rtStop);
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
ASSERT (hr == VFW_E_NOT_COMMITTED); // Normal when stop playing
return hr;
}
@@ -134,9 +133,10 @@ void CDXVADecoderMpeg2::UpdatePictureParams(int nSurfaceIndex)
m_PictureParams.wDecodedPictureIndex = nSurfaceIndex;
// Manage reference picture list
- if (!m_PictureParams.bPicBackwardPrediction)
- {
- if (m_wRefPictureIndex[0] != NO_REF_FRAME) RemoveRefFrame (m_wRefPictureIndex[0]);
+ if (!m_PictureParams.bPicBackwardPrediction) {
+ if (m_wRefPictureIndex[0] != NO_REF_FRAME) {
+ RemoveRefFrame (m_wRefPictureIndex[0]);
+ }
m_wRefPictureIndex[0] = m_wRefPictureIndex[1];
m_wRefPictureIndex[1] = nSurfaceIndex;
}
@@ -144,34 +144,37 @@ void CDXVADecoderMpeg2::UpdatePictureParams(int nSurfaceIndex)
m_PictureParams.wBackwardRefPictureIndex = (m_PictureParams.bPicBackwardPrediction == 1) ? m_wRefPictureIndex[1] : NO_REF_FRAME;
// Shall be 0 if bConfigResidDiffHost is 0 or if BPP > 8
- if (cpd->ConfigResidDiffHost == 0 || m_PictureParams.bBPPminus1 > 7)
+ if (cpd->ConfigResidDiffHost == 0 || m_PictureParams.bBPPminus1 > 7) {
m_PictureParams.bPicSpatialResid8 = 0;
- else
- {
+ } else {
if (m_PictureParams.bBPPminus1 == 7 && m_PictureParams.bPicIntra && cpd->ConfigResidDiffHost)
// Shall be 1 if BPP is 8 and bPicIntra is 1 and bConfigResidDiffHost is 1
+ {
m_PictureParams.bPicSpatialResid8 = 1;
- else
+ } else
// Shall be 1 if bConfigSpatialResid8 is 1
+ {
m_PictureParams.bPicSpatialResid8 = cpd->ConfigSpatialResid8;
+ }
}
// Shall be 0 if bConfigResidDiffHost is 0 or if bConfigSpatialResid8 is 0 or if BPP > 8
- if (cpd->ConfigResidDiffHost == 0 || cpd->ConfigSpatialResid8 == 0 || m_PictureParams.bBPPminus1 > 7)
+ if (cpd->ConfigResidDiffHost == 0 || cpd->ConfigSpatialResid8 == 0 || m_PictureParams.bBPPminus1 > 7) {
m_PictureParams.bPicOverflowBlocks = 0;
+ }
// Shall be 1 if bConfigHostInverseScan is 1 or if bConfigResidDiffAccelerator is 0.
- if (cpd->ConfigHostInverseScan == 1 || cpd->ConfigResidDiffAccelerator == 0)
- {
+ if (cpd->ConfigHostInverseScan == 1 || cpd->ConfigResidDiffAccelerator == 0) {
m_PictureParams.bPicScanFixed = 1;
- if (cpd->ConfigHostInverseScan != 0)
- m_PictureParams.bPicScanMethod = 3; // 11 = Arbitrary scan with absolute coefficient address.
- else if (FFGetAlternateScan(m_pFilter->GetAVCtx()))
- m_PictureParams.bPicScanMethod = 1; // 00 = Zig-zag scan (MPEG-2 Figure 7-2)
- else
- m_PictureParams.bPicScanMethod = 0; // 01 = Alternate-vertical (MPEG-2 Figure 7-3),
+ if (cpd->ConfigHostInverseScan != 0) {
+ m_PictureParams.bPicScanMethod = 3; // 11 = Arbitrary scan with absolute coefficient address.
+ } else if (FFGetAlternateScan(m_pFilter->GetAVCtx())) {
+ m_PictureParams.bPicScanMethod = 1; // 00 = Zig-zag scan (MPEG-2 Figure 7-2)
+ } else {
+ m_PictureParams.bPicScanMethod = 0; // 01 = Alternate-vertical (MPEG-2 Figure 7-3),
+ }
}
}
@@ -184,12 +187,13 @@ void CDXVADecoderMpeg2::SetExtraData (BYTE* pDataIn, UINT nSize)
void CDXVADecoderMpeg2::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSize)
{
- while (*((DWORD*)pBuffer) != 0x01010000)
- {
+ while (*((DWORD*)pBuffer) != 0x01010000) {
pBuffer++;
nSize--;
- if (nSize <= 0) return;
+ if (nSize <= 0) {
+ return;
+ }
}
memcpy (pDXVABuffer, pBuffer, nSize);
@@ -200,8 +204,12 @@ void CDXVADecoderMpeg2::Flush()
{
m_nNextCodecIndex = INT_MIN;
- if (m_wRefPictureIndex[0] != NO_REF_FRAME) RemoveRefFrame (m_wRefPictureIndex[0]);
- if (m_wRefPictureIndex[1] != NO_REF_FRAME) RemoveRefFrame (m_wRefPictureIndex[1]);
+ if (m_wRefPictureIndex[0] != NO_REF_FRAME) {
+ RemoveRefFrame (m_wRefPictureIndex[0]);
+ }
+ if (m_wRefPictureIndex[1] != NO_REF_FRAME) {
+ RemoveRefFrame (m_wRefPictureIndex[1]);
+ }
m_wRefPictureIndex[0] = NO_REF_FRAME;
m_wRefPictureIndex[1] = NO_REF_FRAME;
@@ -214,19 +222,18 @@ int CDXVADecoderMpeg2::FindOldestFrame()
{
int nPos = -1;
- for (int i=0; i<m_nPicEntryNumber; i++)
- {
+ for (int i=0; i<m_nPicEntryNumber; i++) {
if (!m_pPictureStore[i].bDisplayed &&
- m_pPictureStore[i].bInUse &&
- (m_pPictureStore[i].nCodecSpecific == m_nNextCodecIndex))
- {
+ m_pPictureStore[i].bInUse &&
+ (m_pPictureStore[i].nCodecSpecific == m_nNextCodecIndex)) {
m_nNextCodecIndex = INT_MIN;
nPos = i;
}
}
- if (nPos != -1)
+ if (nPos != -1) {
m_pFilter->UpdateFrameTime(m_pPictureStore[nPos].rtStart, m_pPictureStore[nPos].rtStop);
+ }
return nPos;
}
diff --git a/src/filters/transform/MPCVideoDec/DXVADecoderVC1.cpp b/src/filters/transform/MPCVideoDec/DXVADecoderVC1.cpp
index 2d55d0e84..212d18b6c 100644
--- a/src/filters/transform/MPCVideoDec/DXVADecoderVC1.cpp
+++ b/src/filters/transform/MPCVideoDec/DXVADecoderVC1.cpp
@@ -72,13 +72,12 @@ void CDXVADecoderVC1::Init()
m_wRefPictureIndex[0] = NO_REF_FRAME;
m_wRefPictureIndex[1] = NO_REF_FRAME;
- switch (GetMode())
- {
- case VC1_VLD :
- AllocExecuteParams (3);
- break;
- default :
- ASSERT(FALSE);
+ switch (GetMode()) {
+ case VC1_VLD :
+ AllocExecuteParams (3);
+ break;
+ default :
+ ASSERT(FALSE);
}
}
@@ -92,16 +91,17 @@ HRESULT CDXVADecoderVC1::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
int nSliceType;
FFVC1UpdatePictureParam (&m_PictureParams, m_pFilter->GetAVCtx(), &nFieldType, &nSliceType, pDataIn, nSize);
- if (FFIsSkipped (m_pFilter->GetAVCtx()))
+ if (FFIsSkipped (m_pFilter->GetAVCtx())) {
return S_OK;
+ }
// Wait I frame after a flush
- if (m_bFlushed && ! m_PictureParams.bPicIntra)
+ if (m_bFlushed && ! m_PictureParams.bPicIntra) {
return S_FALSE;
+ }
hr = GetFreeSurfaceIndex (nSurfaceIndex, &pSampleToDeliver, rtStart, rtStop);
- if (FAILED (hr))
- {
+ if (FAILED (hr)) {
ASSERT (hr == VFW_E_NOT_COMMITTED); // Normal when stop playing
return hr;
}
@@ -114,9 +114,10 @@ HRESULT CDXVADecoderVC1::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
m_PictureParams.wDeblockedPictureIndex = m_PictureParams.wDecodedPictureIndex;
// Manage reference picture list
- if (!m_PictureParams.bPicBackwardPrediction)
- {
- if (m_wRefPictureIndex[0] != NO_REF_FRAME) RemoveRefFrame (m_wRefPictureIndex[0]);
+ if (!m_PictureParams.bPicBackwardPrediction) {
+ if (m_wRefPictureIndex[0] != NO_REF_FRAME) {
+ RemoveRefFrame (m_wRefPictureIndex[0]);
+ }
m_wRefPictureIndex[0] = m_wRefPictureIndex[1];
m_wRefPictureIndex[1] = nSurfaceIndex;
}
@@ -133,7 +134,7 @@ HRESULT CDXVADecoderVC1::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
// Send picture params to accelerator
m_PictureParams.wDecodedPictureIndex = nSurfaceIndex;
CHECK_HR (AddExecuteBuffer (DXVA2_PictureParametersBufferType, sizeof(m_PictureParams), &m_PictureParams));
-// CHECK_HR (Execute());
+ // CHECK_HR (Execute());
// Send bitstream to accelerator
@@ -152,20 +153,16 @@ HRESULT CDXVADecoderVC1::DecodeFrame (BYTE* pDataIn, UINT nSize, REFERENCE_TIME
#endif
// Re-order B frames
- if (m_pFilter->IsReorderBFrame())
- {
- if (m_PictureParams.bPicBackwardPrediction == 1)
- {
+ if (m_pFilter->IsReorderBFrame()) {
+ if (m_PictureParams.bPicBackwardPrediction == 1) {
SwapRT (rtStart, m_rtStartDelayed);
SwapRT (rtStop, m_rtStopDelayed);
- }
- else
- {
+ } else {
// Save I or P reference time (swap later)
- if (!m_bFlushed)
- {
- if (m_nDelayedSurfaceIndex != -1)
+ if (!m_bFlushed) {
+ if (m_nDelayedSurfaceIndex != -1) {
UpdateStore (m_nDelayedSurfaceIndex, m_rtStartDelayed, m_rtStopDelayed);
+ }
m_rtStartDelayed = m_rtStopDelayed = _I64_MAX;
SwapRT (rtStart, m_rtStartDelayed);
SwapRT (rtStop, m_rtStopDelayed);
@@ -209,8 +206,8 @@ void CDXVADecoderVC1::SetExtraData (BYTE* pDataIn, UINT nSize)
// iWMV9 - i9IRU - iOHIT - iINSO - iWMVA - 0 - 0 - 0 | Section 3.2.5
m_PictureParams.bBidirectionalAveragingMode = (1 << 7) |
- (GetConfigIntraResidUnsigned() <<6) | // i9IRU
- (GetConfigResidDiffAccelerator() <<5); // iOHIT
+ (GetConfigIntraResidUnsigned() <<6) | // i9IRU
+ (GetConfigResidDiffAccelerator() <<5); // iOHIT
}
@@ -218,29 +215,20 @@ BYTE* CDXVADecoderVC1::FindNextStartCode(BYTE* pBuffer, UINT nSize, UINT& nPacke
{
BYTE* pStart = pBuffer;
BYTE bCode = 0;
- for (int i=0; i<nSize-4; i++)
- {
- if ( ((*((DWORD*)(pBuffer+i)) & 0x00FFFFFF) == 0x00010000) || (i >= nSize-5) )
- {
- if (bCode == 0)
- {
+ for (int i=0; i<nSize-4; i++) {
+ if ( ((*((DWORD*)(pBuffer+i)) & 0x00FFFFFF) == 0x00010000) || (i >= nSize-5) ) {
+ if (bCode == 0) {
bCode = pBuffer[i+3];
- if ((nSize == 5) && (bCode == 0x0D))
- {
+ if ((nSize == 5) && (bCode == 0x0D)) {
nPacketSize = nSize;
return pBuffer;
}
- }
- else
- {
- if (bCode == 0x0D)
- {
+ } else {
+ if (bCode == 0x0D) {
// Start code found!
nPacketSize = i - (pStart - pBuffer) + (i >= nSize-5 ? 5 : 1);
return pStart;
- }
- else
- {
+ } else {
// Other stuff, ignore it
pStart = pBuffer + i;
bCode = pBuffer[i+3];
@@ -257,8 +245,7 @@ void CDXVADecoderVC1::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSiz
{
int nDummy;
- if ( (*((DWORD*)pBuffer) & 0x00FFFFFF) != 0x00010000)
- {
+ if ( (*((DWORD*)pBuffer) & 0x00FFFFFF) != 0x00010000) {
// Some splitter have remove startcode (Haali)
pDXVABuffer[0]=pDXVABuffer[1]=0;
pDXVABuffer[2]=1;
@@ -267,15 +254,12 @@ void CDXVADecoderVC1::CopyBitstream(BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSiz
// Copy bitstream buffer, with zero padding (buffer is rounded to multiple of 128)
memcpy (pDXVABuffer, (BYTE*)pBuffer, nSize);
nSize +=4;
- }
- else
- {
+ } else {
BYTE* pStart;
UINT nPacketSize;
pStart = FindNextStartCode (pBuffer, nSize, nPacketSize);
- if (pStart)
- {
+ if (pStart) {
// Startcode already present
memcpy (pDXVABuffer, (BYTE*)pStart, nPacketSize);
nSize = nPacketSize;
@@ -295,8 +279,12 @@ void CDXVADecoderVC1::Flush()
m_rtStartDelayed = _I64_MAX;
m_rtStopDelayed = _I64_MAX;
- if (m_wRefPictureIndex[0] != NO_REF_FRAME) RemoveRefFrame (m_wRefPictureIndex[0]);
- if (m_wRefPictureIndex[1] != NO_REF_FRAME) RemoveRefFrame (m_wRefPictureIndex[1]);
+ if (m_wRefPictureIndex[0] != NO_REF_FRAME) {
+ RemoveRefFrame (m_wRefPictureIndex[0]);
+ }
+ if (m_wRefPictureIndex[1] != NO_REF_FRAME) {
+ RemoveRefFrame (m_wRefPictureIndex[1]);
+ }
m_wRefPictureIndex[0] = NO_REF_FRAME;
m_wRefPictureIndex[1] = NO_REF_FRAME;
@@ -311,8 +299,7 @@ HRESULT CDXVADecoderVC1::DisplayStatus()
memset (&Status, 0, sizeof(Status));
- if (SUCCEEDED (hr = CDXVADecoder::QueryStatus(&Status, sizeof(Status))))
- {
+ if (SUCCEEDED (hr = CDXVADecoder::QueryStatus(&Status, sizeof(Status)))) {
Status.StatusReportFeedbackNumber = 0x00FF & Status.StatusReportFeedbackNumber;
TRACE_VC1 ("CDXVADecoderVC1 : Status for the frame %u : bBufType = %u, bStatus = %u, wNumMbsAffected = %u\n",
diff --git a/src/filters/transform/MPCVideoDec/DXVADecoderVC1.h b/src/filters/transform/MPCVideoDec/DXVADecoderVC1.h
index d08a6ffea..6c2e1873c 100644
--- a/src/filters/transform/MPCVideoDec/DXVADecoderVC1.h
+++ b/src/filters/transform/MPCVideoDec/DXVADecoderVC1.h
@@ -39,38 +39,33 @@ public:
virtual void CopyBitstream (BYTE* pDXVABuffer, BYTE* pBuffer, UINT& nSize);
virtual void Flush();
- typedef enum
- {
+ typedef enum {
VC1_PS_TOP_FIELD = 1,
VC1_PS_BOTTOM_FIELD = 2,
VC1_PS_PROGRESSIVE = 3
};
- typedef enum
- {
+ typedef enum {
VC1_CHROMA_420 = 1,
VC1_CHROMA_422 = 2,
VC1_CHROMA_444 = 3
} VC1_CHROMA_FORMAT;
- typedef enum
- {
+ typedef enum {
VC1_CR_BICUBIC_QUARTER_CHROMA = 4,
VC1_CR_BICUBIC_HALF_CHROMA = 5,
VC1_CR_BILINEAR_QUARTER_CHROMA = 12,
VC1_CR_BILINEAR_HALF_CHROMA = 13,
};
- typedef enum
- {
+ typedef enum {
VC1_SCAN_ZIGZAG = 0,
VC1_SCAN_ALTERNATE_VERTICAL = 1,
VC1_SCAN_ALTERNATE_HORIZONTAL = 2,
VC1_SCAN_ARBITRARY = 3 // Use when bConfigHostInverseScan = 1
} VC1_PIC_SCAN_METHOD;
- typedef enum // Values for bPicDeblockConfined when bConfigBitstreamRaw = 1
- {
+ typedef enum { // Values for bPicDeblockConfined when bConfigBitstreamRaw = 1
VC1_EXTENDED_DMV = 0x0001,
VC1_PSF = 0x0002,
VC1_REFPICFLAG = 0x0004,
@@ -81,8 +76,7 @@ public:
VC1_POSTPROCFLAG = 0x0080
} VC1_DEBLOCK_CONFINED;
- typedef enum // Values for bPicSpatialResid8
- {
+ typedef enum { // Values for bPicSpatialResid8
VC1_VSTRANSFORM = 0x0001,
VC1_DQUANT = 0x0002,
VC1_EXTENDED_MV = 0x0004,
diff --git a/src/filters/transform/MPCVideoDec/FfmpegContext.c b/src/filters/transform/MPCVideoDec/FfmpegContext.c
index 596f0973d..08566ca83 100644
--- a/src/filters/transform/MPCVideoDec/FfmpegContext.c
+++ b/src/filters/transform/MPCVideoDec/FfmpegContext.c
@@ -42,15 +42,15 @@ int av_h264_decode_frame(struct AVCodecContext* avctx, int* nOutPOC, int64_t* rt
int av_vc1_decode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size);
void av_init_packet(AVPacket *pkt);
-const byte ZZ_SCAN[16] =
-{ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
+const byte ZZ_SCAN[16] = {
+ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
};
-const byte ZZ_SCAN8[64] =
-{ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
+const byte ZZ_SCAN8[64] = {
+ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
};
// FIXME : remove duplicate declaration with ffmpeg ??
@@ -75,16 +75,16 @@ BOOL IsVistaOrAbove()
static BOOL result = FALSE;
OSVERSIONINFO osver;
- if (!checked)
- {
+ if (!checked) {
checked = TRUE;
osver.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
if (GetVersionEx( &osver ) &&
- osver.dwPlatformId == VER_PLATFORM_WIN32_NT &&
- (osver.dwMajorVersion >= 6 ) )
+ osver.dwPlatformId == VER_PLATFORM_WIN32_NT &&
+ (osver.dwMajorVersion >= 6 ) ) {
result = TRUE;
+ }
}
return result;
@@ -103,16 +103,15 @@ inline MpegEncContext* GetMpegEncContext(struct AVCodecContext* pAVCtx)
Mpeg1Context* s1;
MpegEncContext* s = NULL;
- switch (pAVCtx->codec_id)
- {
- case CODEC_ID_VC1 :
- case CODEC_ID_H264 :
- s = (MpegEncContext*) pAVCtx->priv_data;
- break;
- case CODEC_ID_MPEG2VIDEO:
- s1 = (Mpeg1Context*)pAVCtx->priv_data;
- s = (MpegEncContext*)&s1->mpeg_enc_ctx;
- break;
+ switch (pAVCtx->codec_id) {
+ case CODEC_ID_VC1 :
+ case CODEC_ID_H264 :
+ s = (MpegEncContext*) pAVCtx->priv_data;
+ break;
+ case CODEC_ID_MPEG2VIDEO:
+ s1 = (Mpeg1Context*)pAVCtx->priv_data;
+ s = (MpegEncContext*)&s1->mpeg_enc_ctx;
+ break;
}
return s;
}
@@ -120,38 +119,29 @@ inline MpegEncContext* GetMpegEncContext(struct AVCodecContext* pAVCtx)
void FFH264DecodeBuffer (struct AVCodecContext* pAVCtx, BYTE* pBuffer, UINT nSize, int* pFramePOC, int* pOutPOC, REFERENCE_TIME* pOutrtStart)
{
- if (pBuffer != NULL)
- {
+ if (pBuffer != NULL) {
H264Context* h = (H264Context*) pAVCtx->priv_data;
av_h264_decode_frame (pAVCtx, pOutPOC, pOutrtStart, pBuffer, nSize);
- if (h->s.current_picture_ptr != NULL && pFramePOC) *pFramePOC = h->s.current_picture_ptr->field_poc[0];
+ if (h->s.current_picture_ptr != NULL && pFramePOC) {
+ *pFramePOC = h->s.current_picture_ptr->field_poc[0];
+ }
}
}
// returns TRUE if version is equal to or higher than A.B.C.D, returns FALSE otherwise
BOOL DriverVersionCheck(LARGE_INTEGER VideoDriverVersion, int A, int B, int C, int D)
{
- if (HIWORD(VideoDriverVersion.HighPart) > A)
- {
+ if (HIWORD(VideoDriverVersion.HighPart) > A) {
return TRUE;
- }
- else if (HIWORD(VideoDriverVersion.HighPart) == A)
- {
- if (LOWORD(VideoDriverVersion.HighPart) > B)
- {
+ } else if (HIWORD(VideoDriverVersion.HighPart) == A) {
+ if (LOWORD(VideoDriverVersion.HighPart) > B) {
return TRUE;
- }
- else if (LOWORD(VideoDriverVersion.HighPart) == B)
- {
- if (HIWORD(VideoDriverVersion.LowPart) > C)
- {
+ } else if (LOWORD(VideoDriverVersion.HighPart) == B) {
+ if (HIWORD(VideoDriverVersion.LowPart) > C) {
return TRUE;
- }
- else if (HIWORD(VideoDriverVersion.LowPart) == C)
- {
- if (LOWORD(VideoDriverVersion.LowPart) >= D)
- {
+ } else if (HIWORD(VideoDriverVersion.LowPart) == C) {
+ if (LOWORD(VideoDriverVersion.LowPart) >= D) {
return TRUE;
}
}
@@ -173,61 +163,45 @@ int FFH264CheckCompatibility(int nWidth, int nHeight, struct AVCodecContext* pAV
int max_ref_frames = 0;
int max_ref_frames_dpb41 = min(11, 8388608/(nWidth * nHeight) );
- if (pBuffer != NULL)
- {
+ if (pBuffer != NULL) {
av_h264_decode_frame (pAVCtx, NULL, NULL, pBuffer, nSize);
}
cur_sps = pContext->sps_buffers[0];
cur_pps = pContext->pps_buffers[0];
- if (cur_sps != NULL)
- {
+ if (cur_sps != NULL) {
video_is_level51 = cur_sps->level_idc >= 51 ? 1 : 0;
profile_higher_than_high = (cur_sps->profile_idc > 100);
max_ref_frames = max_ref_frames_dpb41; // default value is calculate
- if (nPCIVendor == PCIV_nVidia)
- {
+ if (nPCIVendor == PCIV_nVidia) {
// nVidia cards support level 5.1 since drivers v6.14.11.7800 for XP and drivers v7.15.11.7800 for Vista/7
- if (IsVistaOrAbove())
- {
- if (DriverVersionCheck(VideoDriverVersion, 7, 15, 11, 7800))
- {
+ if (IsVistaOrAbove()) {
+ if (DriverVersionCheck(VideoDriverVersion, 7, 15, 11, 7800)) {
no_level51_support = 0;
// max ref frames is 16 for HD and 11 otherwise
if(nWidth >= 1280) {
max_ref_frames = 16;
- }
- else
- {
+ } else {
max_ref_frames = 11;
}
}
- }
- else
- {
- if (DriverVersionCheck(VideoDriverVersion, 6, 14, 11, 7800))
- {
+ } else {
+ if (DriverVersionCheck(VideoDriverVersion, 6, 14, 11, 7800)) {
no_level51_support = 0;
// max ref frames is 14
max_ref_frames = 14;
}
}
- }
- else if (nPCIVendor == PCIV_S3_Graphics)
- {
+ } else if (nPCIVendor == PCIV_S3_Graphics) {
no_level51_support = 0;
- }
- else if (nPCIVendor == PCIV_ATI)
- {
+ } else if (nPCIVendor == PCIV_ATI) {
// HD4xxx and HD5xxx ATI cards support level 5.1 since drivers v8.14.1.6105 (Catalyst 10.4)
- if((nPCIDevice >> 8 == 0x68) || (nPCIDevice >> 8 == 0x94))
- {
- if (DriverVersionCheck(VideoDriverVersion, 8, 14, 1, 6105))
- {
+ if((nPCIDevice >> 8 == 0x68) || (nPCIDevice >> 8 == 0x94)) {
+ if (DriverVersionCheck(VideoDriverVersion, 8, 14, 1, 6105)) {
no_level51_support = 0;
max_ref_frames = 16;
}
@@ -235,8 +209,7 @@ int FFH264CheckCompatibility(int nWidth, int nHeight, struct AVCodecContext* pAV
}
// Check maximum allowed number reference frames
- if (cur_sps->ref_frame_count > max_ref_frames)
- {
+ if (cur_sps->ref_frame_count > max_ref_frames) {
too_much_ref_frames = 1;
}
}
@@ -249,37 +222,38 @@ void CopyScalingMatrix(DXVA_Qmatrix_H264* pDest, DXVA_Qmatrix_H264* pSource, int
{
int i,j;
- switch (nPCIVendor)
- {
- case PCIV_ATI :
- // The ATI way
- memcpy (pDest, pSource, sizeof (DXVA_Qmatrix_H264));
- break;
-
- default :
- // The nVidia way (and other manufacturers compliant with specifications....)
- for (i=0; i<6; i++)
- for (j=0; j<16; j++)
- pDest->bScalingLists4x4[i][j] = pSource->bScalingLists4x4[i][ZZ_SCAN[j]];
-
- for (i=0; i<2; i++)
- for (j=0; j<64; j++)
- pDest->bScalingLists8x8[i][j] = pSource->bScalingLists8x8[i][ZZ_SCAN8[j]];
- break;
+ switch (nPCIVendor) {
+ case PCIV_ATI :
+ // The ATI way
+ memcpy (pDest, pSource, sizeof (DXVA_Qmatrix_H264));
+ break;
+
+ default :
+ // The nVidia way (and other manufacturers compliant with specifications....)
+ for (i=0; i<6; i++)
+ for (j=0; j<16; j++) {
+ pDest->bScalingLists4x4[i][j] = pSource->bScalingLists4x4[i][ZZ_SCAN[j]];
+ }
+
+ for (i=0; i<2; i++)
+ for (j=0; j<64; j++) {
+ pDest->bScalingLists8x8[i][j] = pSource->bScalingLists8x8[i][ZZ_SCAN8[j]];
+ }
+ break;
}
}
USHORT FFH264FindRefFrameIndex(USHORT num_frame, DXVA_PicParams_H264* pDXVAPicParams)
{
int i;
- for (i=0; i<pDXVAPicParams->num_ref_frames; i++)
- {
- if (pDXVAPicParams->FrameNumList[i] == num_frame)
+ for (i=0; i<pDXVAPicParams->num_ref_frames; i++) {
+ if (pDXVAPicParams->FrameNumList[i] == num_frame) {
return pDXVAPicParams->RefFrameList[i].Index7Bits;
+ }
}
#ifdef _DEBUG
-// DebugBreak(); // Ref frame not found !
+ // DebugBreak(); // Ref frame not found !
#endif
return 127;
@@ -299,34 +273,33 @@ HRESULT FFH264BuildPicParams (DXVA_PicParams_H264* pDXVAPicParams, DXVA_Qmatrix_
cur_sps = &h->sps;
cur_pps = &h->pps;
- if (cur_sps && cur_pps)
- {
+ if (cur_sps && cur_pps) {
*nFieldType = h->s.picture_structure;
- if (h->sps.pic_struct_present_flag)
- {
- switch (h->sei_pic_struct)
- {
- case SEI_PIC_STRUCT_TOP_FIELD:
- case SEI_PIC_STRUCT_TOP_BOTTOM:
- case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
- *nFieldType = PICT_TOP_FIELD;
- break;
- case SEI_PIC_STRUCT_BOTTOM_FIELD:
- case SEI_PIC_STRUCT_BOTTOM_TOP:
- case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
- *nFieldType = PICT_BOTTOM_FIELD;
- break;
- case SEI_PIC_STRUCT_FRAME_DOUBLING:
- case SEI_PIC_STRUCT_FRAME_TRIPLING:
- case SEI_PIC_STRUCT_FRAME:
- *nFieldType = PICT_FRAME;
- break;
+ if (h->sps.pic_struct_present_flag) {
+ switch (h->sei_pic_struct) {
+ case SEI_PIC_STRUCT_TOP_FIELD:
+ case SEI_PIC_STRUCT_TOP_BOTTOM:
+ case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
+ *nFieldType = PICT_TOP_FIELD;
+ break;
+ case SEI_PIC_STRUCT_BOTTOM_FIELD:
+ case SEI_PIC_STRUCT_BOTTOM_TOP:
+ case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
+ *nFieldType = PICT_BOTTOM_FIELD;
+ break;
+ case SEI_PIC_STRUCT_FRAME_DOUBLING:
+ case SEI_PIC_STRUCT_FRAME_TRIPLING:
+ case SEI_PIC_STRUCT_FRAME:
+ *nFieldType = PICT_FRAME;
+ break;
}
}
*nSliceType = h->slice_type;
- if (cur_sps->mb_width==0 || cur_sps->mb_height==0) return VFW_E_INVALID_FILE_FORMAT;
+ if (cur_sps->mb_width==0 || cur_sps->mb_height==0) {
+ return VFW_E_INVALID_FILE_FORMAT;
+ }
pDXVAPicParams->wFrameWidthInMbsMinus1 = cur_sps->mb_width - 1; // pic_width_in_mbs_minus1;
pDXVAPicParams->wFrameHeightInMbsMinus1 = cur_sps->mb_height * (2 - cur_sps->frame_mbs_only_flag) - 1; // pic_height_in_map_units_minus1;
pDXVAPicParams->num_ref_frames = cur_sps->ref_frame_count; // num_ref_frames;
@@ -346,16 +319,16 @@ HRESULT FFH264BuildPicParams (DXVA_PicParams_H264* pDXVAPicParams, DXVA_Qmatrix_
pDXVAPicParams->bit_depth_luma_minus8 = cur_sps->bit_depth_luma - 8; // bit_depth_luma_minus8
pDXVAPicParams->bit_depth_chroma_minus8 = cur_sps->bit_depth_chroma - 8; // bit_depth_chroma_minus8
- // pDXVAPicParams->StatusReportFeedbackNumber = SET IN DecodeFrame;
+ // pDXVAPicParams->StatusReportFeedbackNumber = SET IN DecodeFrame;
- // pDXVAPicParams->CurrFieldOrderCnt = SET IN UpdateRefFramesList;
- // pDXVAPicParams->FieldOrderCntList = SET IN UpdateRefFramesList;
- // pDXVAPicParams->FrameNumList = SET IN UpdateRefFramesList;
- // pDXVAPicParams->UsedForReferenceFlags = SET IN UpdateRefFramesList;
- // pDXVAPicParams->NonExistingFrameFlags
+ // pDXVAPicParams->CurrFieldOrderCnt = SET IN UpdateRefFramesList;
+ // pDXVAPicParams->FieldOrderCntList = SET IN UpdateRefFramesList;
+ // pDXVAPicParams->FrameNumList = SET IN UpdateRefFramesList;
+ // pDXVAPicParams->UsedForReferenceFlags = SET IN UpdateRefFramesList;
+ // pDXVAPicParams->NonExistingFrameFlags
pDXVAPicParams->frame_num = h->frame_num;
- // pDXVAPicParams->SliceGroupMap
+ // pDXVAPicParams->SliceGroupMap
pDXVAPicParams->log2_max_frame_num_minus4 = cur_sps->log2_max_frame_num - 4; // log2_max_frame_num_minus4;
@@ -378,25 +351,19 @@ HRESULT FFH264BuildPicParams (DXVA_PicParams_H264* pDXVAPicParams, DXVA_Qmatrix_
pDXVAPicParams->pic_init_qp_minus26 = cur_pps->init_qp - 26;
pDXVAPicParams->pic_init_qs_minus26 = cur_pps->init_qs - 26;
- if (field_pic_flag)
- {
+ if (field_pic_flag) {
pDXVAPicParams->CurrPic.AssociatedFlag = (h->s.picture_structure == PICT_BOTTOM_FIELD);
- if (pDXVAPicParams->CurrPic.AssociatedFlag)
- {
+ if (pDXVAPicParams->CurrPic.AssociatedFlag) {
// Bottom field
pDXVAPicParams->CurrFieldOrderCnt[0] = 0;
pDXVAPicParams->CurrFieldOrderCnt[1] = h->poc_lsb + h->poc_msb;
- }
- else
- {
+ } else {
// Top field
pDXVAPicParams->CurrFieldOrderCnt[0] = h->poc_lsb + h->poc_msb;
pDXVAPicParams->CurrFieldOrderCnt[1] = 0;
}
- }
- else
- {
+ } else {
pDXVAPicParams->CurrPic.AssociatedFlag = 0;
pDXVAPicParams->CurrFieldOrderCnt[0] = h->poc_lsb + h->poc_msb;
pDXVAPicParams->CurrFieldOrderCnt[1] = h->poc_lsb + h->poc_msb;
@@ -416,8 +383,9 @@ void FFH264SetCurrentPicture (int nIndex, DXVA_PicParams_H264* pDXVAPicParams, s
pDXVAPicParams->CurrPic.Index7Bits = nIndex;
- if (h->s.current_picture_ptr)
+ if (h->s.current_picture_ptr) {
h->s.current_picture_ptr->opaque = (void*)nIndex;
+ }
}
@@ -429,51 +397,40 @@ void FFH264UpdateRefFramesList (DXVA_PicParams_H264* pDXVAPicParams, struct AVCo
Picture* pic;
UCHAR AssociatedFlag;
- for(i=0; i<16; i++)
- {
- if (i < h->short_ref_count)
- {
+ for(i=0; i<16; i++) {
+ if (i < h->short_ref_count) {
// Short list reference frames
pic = h->short_ref[h->short_ref_count - i - 1];
AssociatedFlag = pic->long_ref != 0;
- }
- else if (i >= h->short_ref_count && i < h->long_ref_count)
- {
+ } else if (i >= h->short_ref_count && i < h->long_ref_count) {
// Long list reference frames
pic = h->short_ref[h->short_ref_count + h->long_ref_count - i - 1];
AssociatedFlag = 1;
- }
- else
+ } else {
pic = NULL;
+ }
- if (pic != NULL)
- {
+ if (pic != NULL) {
pDXVAPicParams->FrameNumList[i] = pic->long_ref ? pic->pic_id : pic->frame_num;
- if (pic->field_poc[0] != INT_MAX)
- {
+ if (pic->field_poc[0] != INT_MAX) {
pDXVAPicParams->FieldOrderCntList[i][0] = pic->field_poc [0];
nUsedForReferenceFlags |= 1<<(i*2);
- }
- else
+ } else {
pDXVAPicParams->FieldOrderCntList[i][0] = 0;
+ }
- if (pic->field_poc[1] != INT_MAX)
- {
+ if (pic->field_poc[1] != INT_MAX) {
pDXVAPicParams->FieldOrderCntList[i][1] = pic->field_poc [1];
nUsedForReferenceFlags |= 2<<(i*2);
- }
- else
- {
+ } else {
pDXVAPicParams->FieldOrderCntList[i][1] = 0;
}
pDXVAPicParams->RefFrameList[i].AssociatedFlag = AssociatedFlag;
pDXVAPicParams->RefFrameList[i].Index7Bits = (UCHAR)pic->opaque;
- }
- else
- {
+ } else {
pDXVAPicParams->FrameNumList[i] = 0;
pDXVAPicParams->FieldOrderCntList[i][0] = 0;
pDXVAPicParams->FieldOrderCntList[i][1] = 0;
@@ -490,16 +447,16 @@ BOOL FFH264IsRefFrameInUse (int nFrameNum, struct AVCodecContext* pAVCtx)
H264Context* h = (H264Context*) pAVCtx->priv_data;
int i;
- for (i=0; i<h->short_ref_count; i++)
- {
- if ((int)h->short_ref[i]->opaque == nFrameNum)
+ for (i=0; i<h->short_ref_count; i++) {
+ if ((int)h->short_ref[i]->opaque == nFrameNum) {
return TRUE;
+ }
}
- for (i=0; i<h->long_ref_count; i++)
- {
- if ((int)h->long_ref[i]->opaque == nFrameNum)
+ for (i=0; i<h->long_ref_count; i++) {
+ if ((int)h->long_ref[i]->opaque == nFrameNum) {
return TRUE;
+ }
}
return FALSE;
@@ -513,8 +470,8 @@ void FF264UpdateRefFrameSliceLong(DXVA_PicParams_H264* pDXVAPicParams, DXVA_Slic
HRESULT hr = E_FAIL;
unsigned int i;
- for(i=0; i<32; i++)
- { pSlice->RefPicList[0][i].AssociatedFlag = 1;
+ for(i=0; i<32; i++) {
+ pSlice->RefPicList[0][i].AssociatedFlag = 1;
pSlice->RefPicList[0][i].bPicEntry = 255;
pSlice->RefPicList[0][i].Index7Bits = 127;
pSlice->RefPicList[1][i].AssociatedFlag = 1;
@@ -522,56 +479,54 @@ void FF264UpdateRefFrameSliceLong(DXVA_PicParams_H264* pDXVAPicParams, DXVA_Slic
pSlice->RefPicList[1][i].Index7Bits = 127;
}
- if(h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE)
- {
+ if(h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) {
if(h->ref_count[0] > 0) {
for(i=0; i < h->ref_count[0]; i++) {
pSlice->RefPicList[0][i].Index7Bits = FFH264FindRefFrameIndex (h->ref_list[0][i].frame_num, pDXVAPicParams);
pSlice->RefPicList[0][i].AssociatedFlag = 0;
if((h->s.picture_structure != PICT_FRAME)) {
if((h->sei_pic_struct == SEI_PIC_STRUCT_BOTTOM_FIELD) ||
- (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM) ||
- (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)) {
+ (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM) ||
+ (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)) {
pSlice->RefPicList[0][i].AssociatedFlag = 1;
}
}
}
}
- }
- else
+ } else {
pSlice->num_ref_idx_l0_active_minus1 = 0;
+ }
- if(h->slice_type == FF_B_TYPE || h->slice_type == FF_S_TYPE || h->slice_type == FF_BI_TYPE)
- {
+ if(h->slice_type == FF_B_TYPE || h->slice_type == FF_S_TYPE || h->slice_type == FF_BI_TYPE) {
if(h->ref_count[1] > 0) {
for(i=0; i < h->ref_count[1]; i++) {
pSlice->RefPicList[1][i].Index7Bits = FFH264FindRefFrameIndex (h->ref_list[1][i].frame_num, pDXVAPicParams);
pSlice->RefPicList[1][i].AssociatedFlag = 0;
if((h->s.picture_structure != PICT_FRAME)) {
if((h->sei_pic_struct == SEI_PIC_STRUCT_BOTTOM_FIELD) ||
- (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM) ||
- (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)) {
+ (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM) ||
+ (h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP)) {
pSlice->RefPicList[1][i].AssociatedFlag = 1;
}
}
}
}
- }
- else
+ } else {
pSlice->num_ref_idx_l1_active_minus1 = 0;
+ }
- if(h->slice_type == FF_I_TYPE || h->slice_type == FF_SI_TYPE)
- {
- for(i = 0; i<16; i++)
+ if(h->slice_type == FF_I_TYPE || h->slice_type == FF_SI_TYPE) {
+ for(i = 0; i<16; i++) {
pSlice->RefPicList[0][i].bPicEntry = 0xff;
+ }
}
if(h->slice_type == FF_P_TYPE || h->slice_type == FF_I_TYPE ||
- h->slice_type ==FF_SP_TYPE || h->slice_type == FF_SI_TYPE)
- {
- for(i = 0; i < 16; i++)
- pSlice->RefPicList[1][i].bPicEntry = 0xff;
+ h->slice_type ==FF_SP_TYPE || h->slice_type == FF_SI_TYPE) {
+ for(i = 0; i < 16; i++) {
+ pSlice->RefPicList[1][i].bPicEntry = 0xff;
+ }
}
}
@@ -585,16 +540,16 @@ HRESULT FFVC1UpdatePictureParam (DXVA_PictureParameters* pPicParams, struct AVCo
{
VC1Context* vc1 = (VC1Context*) pAVCtx->priv_data;
- if (pBuffer)
- {
+ if (pBuffer) {
av_vc1_decode_frame (pAVCtx, pBuffer, nSize);
}
// WARNING : vc1->interlace is not reliable (always set for progressive video on HD-DVD material)
- if (vc1->fcm == 0)
+ if (vc1->fcm == 0) {
*nFieldType = PICT_FRAME;
- else // fcm : 2 or 3 frame or field interlaced
+ } else { // fcm : 2 or 3 frame or field interlaced
*nFieldType = (vc1->tff ? PICT_TOP_FIELD : PICT_BOTTOM_FIELD);
+ }
pPicParams->bPicIntra = (vc1->s.pict_type == FF_I_TYPE);
pPicParams->bPicBackwardPrediction = (vc1->s.pict_type == FF_B_TYPE);
@@ -602,8 +557,8 @@ HRESULT FFVC1UpdatePictureParam (DXVA_PictureParameters* pPicParams, struct AVCo
// Init Init Init Todo
// iWMV9 - i9IRU - iOHIT - iINSO - iWMVA - 0 - 0 - 0 | Section 3.2.5
pPicParams->bBidirectionalAveragingMode = (pPicParams->bBidirectionalAveragingMode & 0xE0) | // init in SetExtraData
- ((vc1->lumshift!=0 || vc1->lumscale!=32) ? 0x10 : 0)| // iINSO
- ((vc1->profile == PROFILE_ADVANCED) <<3 ); // iWMVA
+ ((vc1->lumshift!=0 || vc1->lumscale!=32) ? 0x10 : 0)| // iINSO
+ ((vc1->profile == PROFILE_ADVANCED) <<3 ); // iWMVA
// Section 3.2.20.3
pPicParams->bPicSpatialResid8 = (vc1->panscanflag << 7) | (vc1->refdist_flag << 6) |
@@ -637,9 +592,9 @@ HRESULT FFVC1UpdatePictureParam (DXVA_PictureParameters* pPicParams, struct AVCo
// TODO : not finish...
pPicParams->bMVprecisionAndChromaRelation = ((vc1->mv_mode == MV_PMODE_1MV_HPEL_BILIN) << 3) | // 0 for non-bilinear luma motion, 1 for bilinear
- (1 << 2) | // 0 for WMV8, 1 for WMV9 motion
- (0 << 1) | // 1 for WMV8 quarter sample luma motion
- (0); // 0 for quarter sample chroma motion, 1 for half sample chroma
+ (1 << 2) | // 0 for WMV8, 1 for WMV9 motion
+ (0 << 1) | // 1 for WMV8 quarter sample luma motion
+ (0); // 0 for quarter sample chroma motion, 1 for half sample chroma
// Cf §7.1.1.25 in VC1 specification, §3.2.14.3 in DXVA spec
pPicParams->bRcontrol = vc1->rnd;
@@ -660,11 +615,10 @@ HRESULT FFMpeg2DecodeFrame (DXVA_PictureParameters* pPicParams, DXVA_QmatrixData
int got_picture = 0;
Mpeg1Context* s1 = (Mpeg1Context*)pAVCtx->priv_data;
MpegEncContext* s = (MpegEncContext*)&s1->mpeg_enc_ctx;
- AVPacket avpkt;
+ AVPacket avpkt;
- if (pBuffer)
- {
- av_init_packet(&avpkt);
+ if (pBuffer) {
+ av_init_packet(&avpkt);
avpkt.data = pBuffer;
avpkt.size = nSize;
// HACK for CorePNG to decode as normal PNG by default
@@ -718,13 +672,13 @@ HRESULT FFMpeg2DecodeFrame (DXVA_PictureParameters* pPicParams, DXVA_QmatrixData
// pPicParams->bReservedBits; // ??
pPicParams->wBitstreamFcodes = (s->mpeg_f_code[0][0]<<12) | (s->mpeg_f_code[0][1]<<8) |
- (s->mpeg_f_code[1][0]<<4) | (s->mpeg_f_code[1][1]);
+ (s->mpeg_f_code[1][0]<<4) | (s->mpeg_f_code[1][1]);
pPicParams->wBitstreamPCEelements = (s->intra_dc_precision<<14) | (s->picture_structure<<12) |
- (s->top_field_first<<11) | (s->frame_pred_frame_dct<<10)|
- (s->concealment_motion_vectors<<9) | (s->q_scale_type<<8)|
- (s->intra_vlc_format<<7) | (s->alternate_scan<<6)|
- (s->repeat_first_field<<5) | (s->chroma_420_type<<4)|
- (s->progressive_frame<<3);
+ (s->top_field_first<<11) | (s->frame_pred_frame_dct<<10)|
+ (s->concealment_motion_vectors<<9) | (s->q_scale_type<<8)|
+ (s->intra_vlc_format<<7) | (s->alternate_scan<<6)|
+ (s->repeat_first_field<<5) | (s->chroma_420_type<<4)|
+ (s->progressive_frame<<3);
// TODO : could be interesting to parameter concealment method?
// pPicParams->bBitstreamConcealmentNeed;
@@ -734,16 +688,16 @@ HRESULT FFMpeg2DecodeFrame (DXVA_PictureParameters* pPicParams, DXVA_QmatrixData
pQMatrixData->bNewQmatrix[1] = 1;
pQMatrixData->bNewQmatrix[2] = 1;
pQMatrixData->bNewQmatrix[3] = 1;
- for (i=0; i<64; i++) // intra Y, inter Y, intra chroma, inter chroma
- {
+ for (i=0; i<64; i++) { // intra Y, inter Y, intra chroma, inter chroma
pQMatrixData->Qmatrix[0][i] = s->intra_matrix[ZZ_SCAN8[i]];
pQMatrixData->Qmatrix[1][i] = s->inter_matrix[ZZ_SCAN8[i]];
pQMatrixData->Qmatrix[2][i] = s->chroma_intra_matrix[ZZ_SCAN8[i]];
pQMatrixData->Qmatrix[3][i] = s->chroma_inter_matrix[ZZ_SCAN8[i]];
}
- if (got_picture)
+ if (got_picture) {
*nNextCodecIndex = pFrame->coded_picture_number;
+ }
return S_OK;
}
@@ -764,18 +718,16 @@ int FFIsSkipped(struct AVCodecContext* pAVCtx)
int FFIsInterlaced(struct AVCodecContext* pAVCtx, int nHeight)
{
- if (pAVCtx->codec_id == CODEC_ID_H264)
- {
+ if (pAVCtx->codec_id == CODEC_ID_H264) {
H264Context* h = (H264Context*) pAVCtx->priv_data;
SPS* cur_sps = h->sps_buffers[0];
- if (cur_sps && !cur_sps->frame_mbs_only_flag)
+ if (cur_sps && !cur_sps->frame_mbs_only_flag) {
return 1;
- else
+ } else {
return 0;
- }
- else if (pAVCtx->codec_id == CODEC_ID_VC1)
- {
+ }
+ } else if (pAVCtx->codec_id == CODEC_ID_VC1) {
VC1Context* vc1 = (VC1Context*) pAVCtx->priv_data;
return vc1->interlace;
}
@@ -785,25 +737,24 @@ int FFIsInterlaced(struct AVCodecContext* pAVCtx, int nHeight)
void FFSetThreadNumber(struct AVCodecContext* pAVCtx, int nThreadCount)
{
- if (pAVCtx->thread_count > 1)
- {
+ if (pAVCtx->thread_count > 1) {
avcodec_thread_free (pAVCtx);
pAVCtx->thread_count = 1;
}
- if (nThreadCount > 1)
+ if (nThreadCount > 1) {
avcodec_thread_init(pAVCtx, nThreadCount);
+ }
}
BOOL FFSoftwareCheckCompatibility(struct AVCodecContext* pAVCtx)
{
- if (pAVCtx->codec_id == CODEC_ID_VC1)
- {
+ if (pAVCtx->codec_id == CODEC_ID_VC1) {
VC1Context* vc1 = (VC1Context*) pAVCtx->priv_data;
return !vc1->interlace;
- }
- else
+ } else {
return TRUE;
+ }
}
diff --git a/src/filters/transform/MPCVideoDec/FfmpegContext.h b/src/filters/transform/MPCVideoDec/FfmpegContext.h
index 958b9a16d..1477d329b 100644
--- a/src/filters/transform/MPCVideoDec/FfmpegContext.h
+++ b/src/filters/transform/MPCVideoDec/FfmpegContext.h
@@ -27,8 +27,7 @@
struct AVCodecContext;
struct AVFrame;
-enum PCI_Vendors
-{
+enum PCI_Vendors {
PCIV_ATI = 0x1002,
PCIV_nVidia = 0x10DE,
PCIV_Intel = 0x8086,
diff --git a/src/filters/transform/MPCVideoDec/H264QuantizationMatrix.h b/src/filters/transform/MPCVideoDec/H264QuantizationMatrix.h
index b05941919..011363214 100644
--- a/src/filters/transform/MPCVideoDec/H264QuantizationMatrix.h
+++ b/src/filters/transform/MPCVideoDec/H264QuantizationMatrix.h
@@ -22,8 +22,7 @@
#pragma once
-typedef enum
-{
+typedef enum {
Flat16,
JVTMatrix,
QMatrix,
@@ -31,59 +30,64 @@ typedef enum
} QMatrixH264Type;
-const byte ZZ_SCAN[16] =
-{ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
+const byte ZZ_SCAN[16] = {
+ 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
};
-const byte ZZ_SCAN8[64] =
-{ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
+const byte ZZ_SCAN8[64] = {
+ 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
};
-const DXVA_Qmatrix_H264 g_QMatrixH264[] =
-{
+const DXVA_Qmatrix_H264 g_QMatrixH264[] = {
// 1) #flat 16
{
{
// INTRA4X4_LUMA =
- { 16,16,16,16,
+ {
+ 16,16,16,16,
16,16,16,16,
16,16,16,16,
16,16,16,16
},
// INTRA4X4_CHROMAU =
- { 16,16,16,16,
+ {
+ 16,16,16,16,
16,16,16,16,
16,16,16,16,
16,16,16,16
},
// INTRA4X4_CHROMAV =
- { 16,16,16,16,
+ {
+ 16,16,16,16,
16,16,16,16,
16,16,16,16,
16,16,16,16
},
// INTER4X4_LUMA =
- { 16,16,16,16,
+ {
+ 16,16,16,16,
16,16,16,16,
16,16,16,16,
16,16,16,16
},
// INTER4X4_CHROMAU =
- { 16,16,16,16,
+ {
+ 16,16,16,16,
16,16,16,16,
16,16,16,16,
16,16,16,16
},
// INTER4X4_CHROMAV =
- { 16,16,16,16,
+ {
+ 16,16,16,16,
16,16,16,16,
16,16,16,16,
16,16,16,16
@@ -91,7 +95,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
{
// INTRA8X8_LUMA =
- { 16,16,16,16,16,16,16,16,
+ {
+ 16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
@@ -102,7 +107,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
// INTER8X8_LUMA =
- { 16,16,16,16,16,16,16,16,
+ {
+ 16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,
@@ -117,42 +123,48 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
{
{
// INTRA4X4_LUMA
- { 6,13,20,28,
+ {
+ 6,13,20,28,
13,20,28,32,
20,28,32,37,
28,32,37,42
},
// INTRA4X4_CHROMAU
- { 6,13,20,28,
+ {
+ 6,13,20,28,
13,20,28,32,
20,28,32,37,
28,32,37,42
},
// INTRA4X4_CHROMAV
- { 6,13,20,28,
+ {
+ 6,13,20,28,
13,20,28,32,
20,28,32,37,
28,32,37,42
},
// INTER4X4_LUMA
- { 10,14,20,24,
+ {
+ 10,14,20,24,
14,20,24,27,
20,24,27,30,
24,27,30,34
},
// INTER4X4_CHROMAU
- { 10,14,20,24,
+ {
+ 10,14,20,24,
14,20,24,27,
20,24,27,30,
24,27,30,34
},
// INTER4X4_CHROMAV
- { 10,14,20,24,
+ {
+ 10,14,20,24,
14,20,24,27,
20,24,27,30,
24,27,30,34
@@ -160,7 +172,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
{
// INTRA8X8_LUMA
- { 6,10,13,16,18,23,25,27,
+ {
+ 6,10,13,16,18,23,25,27,
10,11,16,18,23,25,27,29,
13,16,18,23,25,27,29,31,
16,18,23,25,27,29,31,33,
@@ -171,7 +184,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
// INTER8X8_LUMA
- { 9,13,15,17,19,21,22,24,
+ {
+ 9,13,15,17,19,21,22,24,
13,13,17,19,21,22,24,25,
15,17,19,21,22,24,25,27,
17,19,21,22,24,25,27,28,
@@ -187,42 +201,48 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
{
{
// INTRA4X4_LUMA =
- { 6,12,19,26,
+ {
+ 6,12,19,26,
12,19,26,31,
19,26,31,35,
26,31,35,39
},
// INTRA4X4_CHROMAU =
- { 6,12,19,26,
+ {
+ 6,12,19,26,
12,19,26,31,
19,26,31,35,
26,31,35,39
},
// INTRA4X4_CHROMAV =
- { 6,12,19,26,
+ {
+ 6,12,19,26,
12,19,26,31,
19,26,31,35,
26,31,35,39
},
// INTER4X4_LUMA =
- { 9,13,18,21,
+ {
+ 9,13,18,21,
13,18,21,24,
18,21,24,27,
21,24,27,30
},
// INTER4X4_CHROMAU =
- { 9,13,18,21,
+ {
+ 9,13,18,21,
13,18,21,24,
18,21,24,27,
21,24,27,30
},
// INTER4X4_CHROMAV =
- { 9,13,18,21,
+ {
+ 9,13,18,21,
13,18,21,24,
18,21,24,27,
21,24,27,30
@@ -230,7 +250,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
{
// INTRA8X8_LUMA =
- { 6,10,13,16,19,24,26,28,
+ {
+ 6,10,13,16,19,24,26,28,
10,12,16,19,24,26,28,31,
13,16,19,24,26,28,31,33,
16,19,24,26,28,31,33,35,
@@ -241,7 +262,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
// INTER8X8_LUMA =
- { 9,12,14,16,18,19,21,22,
+ {
+ 9,12,14,16,18,19,21,22,
12,13,16,18,19,21,22,24,
14,16,18,19,21,22,24,25,
16,18,19,21,22,24,25,27,
@@ -257,42 +279,48 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
{
{
// INTRA4X4_LUMA =
- { 7,16,22,24,
+ {
+ 7,16,22,24,
16,22,24,28,
18,22,27,33,
22,24,32,47
},
// INTRA4X4_CHROMAU =
- { 7,16,22,24,
+ {
+ 7,16,22,24,
16,22,24,28,
18,22,27,33,
22,24,32,47
},
// INTRA4X4_CHROMAV =
- { 7,16,22,24,
+ {
+ 7,16,22,24,
16,22,24,28,
18,22,27,33,
22,24,32,47
},
// INTER4X4_LUMA =
- { 13,15,17,18,
+ {
+ 13,15,17,18,
15,17,18,20,
17,18,21,22,
18,20,22,25
},
// INTER4X4_CHROMAU =
- { 13,15,17,18,
+ {
+ 13,15,17,18,
15,17,18,20,
17,18,21,22,
18,20,22,25
},
// INTER4X4_CHROMAV =
- { 13,15,17,18,
+ {
+ 13,15,17,18,
15,17,18,20,
17,18,21,22,
18,20,22,25
@@ -300,7 +328,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
{
// INTRA8X8_LUMA =
- { 7,13,16,18,22,22,24,28,
+ {
+ 7,13,16,18,22,22,24,28,
13,13,18,20,22,24,28,31,
16,18,22,22,24,28,28,32,
18,18,22,22,24,28,31,33,
@@ -311,7 +340,8 @@ const DXVA_Qmatrix_H264 g_QMatrixH264[] =
},
// INTER8X8_LUMA =
- { 13,14,15,16,17,17,18,19,
+ {
+ 13,14,15,16,17,17,18,19,
14,15,16,17,17,18,19,20,
15,16,17,17,18,19,20,21,
16,17,17,18,19,20,21,22,
diff --git a/src/filters/transform/MPCVideoDec/IMPCVideoDecFilter.h b/src/filters/transform/MPCVideoDec/IMPCVideoDecFilter.h
index 45b204c33..dfd8ad5ec 100644
--- a/src/filters/transform/MPCVideoDec/IMPCVideoDecFilter.h
+++ b/src/filters/transform/MPCVideoDec/IMPCVideoDecFilter.h
@@ -24,8 +24,7 @@
#pragma once
// Internal codec list (use to enable/disable codec in standalone mode)
-typedef enum
-{
+typedef enum {
MPCVD_H264 = 1,
MPCVD_VC1 = MPCVD_H264<<1,
MPCVD_XVID = MPCVD_VC1<<1,
@@ -45,8 +44,7 @@ typedef enum
interface __declspec(uuid("CDC3B5B3-A8B0-4c70-A805-9FC80CDEF262"))
IMPCVideoDecFilter :
-public IUnknown
-{
+public IUnknown {
STDMETHOD(Apply()) = 0;
STDMETHOD(SetThreadNumber(int nValue)) = 0;
diff --git a/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.cpp b/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.cpp
index ce310b302..b8c5891d2 100644
--- a/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.cpp
+++ b/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.cpp
@@ -37,29 +37,25 @@
#include <moreuuids.h>
-typedef struct
-{
+typedef struct {
const CLSID* clsMinorType;
const enum CodecID nFFCodec;
const int fourcc;
} FFMPEG_CODECS;
-const FFMPEG_CODECS ffCodecs[] =
-{
+const FFMPEG_CODECS ffCodecs[] = {
// AMVA
{ &MEDIASUBTYPE_IMA_AMV, CODEC_ID_ADPCM_IMA_AMV, MAKEFOURCC('A','M','V','A') },
};
-const AMOVIESETUP_MEDIATYPE CMPCAudioDecFilter::sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE CMPCAudioDecFilter::sudPinTypesIn[] = {
{ &MEDIATYPE_Audio, &MEDIASUBTYPE_IMA_AMV },
};
const int CMPCAudioDecFilter::sudPinTypesInCount = countof(CMPCAudioDecFilter::sudPinTypesIn);
-const AMOVIESETUP_MEDIATYPE CMPCAudioDecFilter::sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE CMPCAudioDecFilter::sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_PCM}
};
const int CMPCAudioDecFilter::sudPinTypesOutCount = countof(CMPCAudioDecFilter::sudPinTypesOut);
@@ -68,10 +64,16 @@ const int CMPCAudioDecFilter::sudPinTypesOutCount = countof(CMPCAudioDecFilter::
CMPCAudioDecFilter::CMPCAudioDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
: CTransformFilter(NAME("CMPCAudioDecFilter"), lpunk, __uuidof(this))
{
- if(!(m_pInput = new CTransformInputPin(NAME("CAudioDecInputPin"), this, phr, L"In"))) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!(m_pInput = new CTransformInputPin(NAME("CAudioDecInputPin"), this, phr, L"In"))) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
- if(!(m_pOutput = new CTransformOutputPin(NAME("CAudioDecOutputPin"), this, phr, L"Out"))) *phr = E_OUTOFMEMORY;
+ if(!(m_pOutput = new CTransformOutputPin(NAME("CAudioDecOutputPin"), this, phr, L"Out"))) {
+ *phr = E_OUTOFMEMORY;
+ }
if(FAILED(*phr)) {
delete m_pInput, m_pInput = NULL;
return;
@@ -97,12 +99,13 @@ CMPCAudioDecFilter::~CMPCAudioDecFilter(void)
void CMPCAudioDecFilter::Cleanup()
{
- if (m_pAVCtx)
- {
+ if (m_pAVCtx) {
avcodec_thread_free (m_pAVCtx);
av_free(m_pAVCtx);
}
- if (m_pFrame) av_free(m_pFrame);
+ if (m_pFrame) {
+ av_free(m_pFrame);
+ }
m_pAVCodec = NULL;
m_pAVCtx = NULL;
@@ -124,9 +127,9 @@ void CMPCAudioDecFilter::LogLibAVCodec(void* par,int level,const char *fmt,va_li
STDMETHODIMP CMPCAudioDecFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
return
-// QI(IMPCVideoDecFilter)
-// QI(ISpecifyPropertyPages)
-// QI(ISpecifyPropertyPages2)
+ // QI(IMPCVideoDecFilter)
+ // QI(ISpecifyPropertyPages)
+ // QI(ISpecifyPropertyPages2)
__super::NonDelegatingQueryInterface(riid, ppv);
}
@@ -146,11 +149,11 @@ HRESULT CMPCAudioDecFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATO
HRESULT CMPCAudioDecFilter::CheckInputType(const CMediaType* mtIn)
{
- for (int i=0; i<sizeof(sudPinTypesIn)/sizeof(AMOVIESETUP_MEDIATYPE); i++)
- {
+ for (int i=0; i<sizeof(sudPinTypesIn)/sizeof(AMOVIESETUP_MEDIATYPE); i++) {
if ((mtIn->majortype == *sudPinTypesIn[i].clsMajorType) &&
- (mtIn->subtype == *sudPinTypesIn[i].clsMinorType))
+ (mtIn->subtype == *sudPinTypesIn[i].clsMinorType)) {
return S_OK;
+ }
}
return VFW_E_TYPE_NOT_ACCEPTED;
@@ -158,10 +161,16 @@ HRESULT CMPCAudioDecFilter::CheckInputType(const CMediaType* mtIn)
HRESULT CMPCAudioDecFilter::GetMediaType(int iPosition, CMediaType* pmt)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
CMediaType mt = m_pInput->CurrentMediaType();
const GUID& subtype = mt.subtype;
@@ -178,7 +187,7 @@ HRESULT CMPCAudioDecFilter::GetMediaType(int iPosition, CMediaType* pmt)
//}
//else
//{
- *pmt = CreateMediaType(GetSampleFormat(), wfe->nSamplesPerSec, min(2, wfe->nChannels));
+ *pmt = CreateMediaType(GetSampleFormat(), wfe->nSamplesPerSec, min(2, wfe->nChannels));
//}
return S_OK;
@@ -193,12 +202,10 @@ HRESULT CMPCAudioDecFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pRece
{
int nNewCodec;
- if (direction == PINDIR_OUTPUT)
- {
+ if (direction == PINDIR_OUTPUT) {
CMediaType& mt = m_pInput->CurrentMediaType();
nNewCodec = FindCodec(&mt);
- if ((direction == PINDIR_OUTPUT) && (nNewCodec != -1) && (nNewCodec != m_nCodecNb))
- {
+ if ((direction == PINDIR_OUTPUT) && (nNewCodec != -1) && (nNewCodec != m_nCodecNb)) {
WAVEFORMATEX* wfex = (WAVEFORMATEX*) mt.pbFormat;
Cleanup();
@@ -256,8 +263,9 @@ HRESULT CMPCAudioDecFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pRece
}
*/
- if (avcodec_open(m_pAVCtx, m_pAVCodec)<0)
+ if (avcodec_open(m_pAVCtx, m_pAVCodec)<0) {
return VFW_E_INVALIDMEDIATYPE;
+ }
}
}
@@ -321,15 +329,16 @@ HRESULT CMPCAudioDecFilter::Transform(IMediaSample* pIn)
int CMPCAudioDecFilter::FindCodec(const CMediaType* mtIn)
{
for (int i=0; i<countof(ffCodecs); i++)
- if (mtIn->subtype == *ffCodecs[i].clsMinorType)
+ if (mtIn->subtype == *ffCodecs[i].clsMinorType) {
return i;
+ }
return -1;
}
STDMETHODIMP_(SampleFormat) CMPCAudioDecFilter::GetSampleFormat()
{
-// CAutoLock cAutoLock(&m_csProps);
+ // CAutoLock cAutoLock(&m_csProps);
return m_iSampleFormat;
}
@@ -347,26 +356,25 @@ CMediaType CMPCAudioDecFilter::CreateMediaType(SampleFormat sf, DWORD nSamplesPe
wfe->wFormatTag = (WORD)mt.subtype.Data1;
wfe->nChannels = nChannels;
wfe->nSamplesPerSec = nSamplesPerSec;
- switch(sf)
- {
- default:
- case SAMPLE_FMT_S16:
- wfe->wBitsPerSample = 16;
- break;
- case SAMPLE_FMT_S32:
- case SAMPLE_FMT_FLT:
- wfe->wBitsPerSample = 32;
- break;
+ switch(sf) {
+ default:
+ case SAMPLE_FMT_S16:
+ wfe->wBitsPerSample = 16;
+ break;
+ case SAMPLE_FMT_S32:
+ case SAMPLE_FMT_FLT:
+ wfe->wBitsPerSample = 32;
+ break;
}
wfe->nBlockAlign = wfe->nChannels*wfe->wBitsPerSample/8;
wfe->nAvgBytesPerSec = wfe->nSamplesPerSec*wfe->nBlockAlign;
// FIXME: 32 bit only seems to work with WAVE_FORMAT_EXTENSIBLE
- if(dwChannelMask == 0 && (sf == SAMPLE_FMT_S32))
+ if(dwChannelMask == 0 && (sf == SAMPLE_FMT_S32)) {
dwChannelMask = nChannels == 2 ? (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT) : SPEAKER_FRONT_CENTER;
+ }
- if(dwChannelMask)
- {
+ if(dwChannelMask) {
wfex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wfex.Format.cbSize = sizeof(wfex) - sizeof(wfex.Format);
wfex.dwChannelMask = dwChannelMask;
diff --git a/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.h b/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.h
index 938870ae1..ea1737c6c 100644
--- a/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.h
+++ b/src/filters/transform/MPCVideoDec/MPCAudioDecFilter.h
@@ -49,7 +49,7 @@ public:
HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
-// HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
+ // HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
HRESULT CMPCAudioDecFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pReceivePin);
STDMETHODIMP_(SampleFormat) GetSampleFormat();
diff --git a/src/filters/transform/MPCVideoDec/MPCFfmpegDec.cpp b/src/filters/transform/MPCVideoDec/MPCFfmpegDec.cpp
index 41ab0c7af..bbfd7beee 100644
--- a/src/filters/transform/MPCVideoDec/MPCFfmpegDec.cpp
+++ b/src/filters/transform/MPCVideoDec/MPCFfmpegDec.cpp
@@ -29,21 +29,18 @@
// Workaround: graphedit crashes when a filter exposes more than 115 input MediaTypes!
-const AMOVIESETUP_PIN sudpPinsVideoDec[] =
-{
+const AMOVIESETUP_PIN sudpPinsVideoDec[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, CMPCVideoDecFilter::sudPinTypesInCount > 115 ? 115 : CMPCVideoDecFilter::sudPinTypesInCount, CMPCVideoDecFilter::sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, CMPCVideoDecFilter::sudPinTypesOutCount, CMPCVideoDecFilter::sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilters[] =
-{
+const AMOVIESETUP_FILTER sudFilters[] = {
{&__uuidof(CMPCVideoDecFilter), L"MPC - Video decoder", /*MERIT_DO_NOT_USE*/0x40000001, countof(sudpPinsVideoDec), sudpPinsVideoDec, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilters[0].strName, &__uuidof(CMPCVideoDecFilter), CreateInstance<CMPCVideoDecFilter>, NULL, &sudFilters[0]},
{L"CMPCVideoDecPropertyPage", &__uuidof(CMPCVideoDecSettingsWnd), CreateInstance<CInternalPropertyPageTempl<CMPCVideoDecSettingsWnd> >},
{L"CMPCVideoDecPropertyPage2", &__uuidof(CMPCVideoDecCodecWnd), CreateInstance<CInternalPropertyPageTempl<CMPCVideoDecCodecWnd> >},
diff --git a/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.cpp b/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.cpp
index 1832b7802..27932d76a 100644
--- a/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.cpp
+++ b/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.cpp
@@ -52,35 +52,34 @@ extern "C"
#define ROUND_FRAMERATE(var,FrameRate) if (labs ((long)(var - FrameRate)) < FrameRate*1/100) var = FrameRate;
-typedef struct
-{
+typedef struct {
const int PicEntryNumber;
const UINT PreferedConfigBitstream;
const GUID* Decoder[MAX_SUPPORTED_MODE];
const WORD RestrictedMode[MAX_SUPPORTED_MODE];
} DXVA_PARAMS;
-typedef struct
-{
+typedef struct {
const CLSID* clsMinorType;
const enum CodecID nFFCodec;
const int fourcc;
const DXVA_PARAMS* DXVAModes;
- int DXVAModeCount()
- {
- if (!DXVAModes) return 0;
- for (int i=0; i<MAX_SUPPORTED_MODE; i++)
- {
- if (DXVAModes->Decoder[i] == &GUID_NULL) return i;
+ int DXVAModeCount() {
+ if (!DXVAModes) {
+ return 0;
+ }
+ for (int i=0; i<MAX_SUPPORTED_MODE; i++) {
+ if (DXVAModes->Decoder[i] == &GUID_NULL) {
+ return i;
+ }
}
return MAX_SUPPORTED_MODE;
}
} FFMPEG_CODECS;
-typedef enum
-{
+typedef enum {
ffYCbCr_RGB_coeff_ITUR_BT601 = 0,
ffYCbCr_RGB_coeff_ITUR_BT709 = 1,
ffYCbCr_RGB_coeff_SMPTE240M = 2,
@@ -105,8 +104,7 @@ struct TYCbCr2RGB_coeffs {
int cspOptionsBlackCutoff,
int cspOptionsChromaCutoff,
double cspOptionsRGB_WhiteLevel,
- double cspOptionsRGB_BlackLevel)
- {
+ double cspOptionsRGB_BlackLevel) {
if (cspOptionsIturBt == ffYCbCr_RGB_coeff_ITUR_BT601) {
Kr = 0.299;
Kg = 0.587;
@@ -139,8 +137,7 @@ struct TYCbCr2RGB_coeffs {
// DXVA modes supported for Mpeg2
-DXVA_PARAMS DXVA_Mpeg2 =
-{
+DXVA_PARAMS DXVA_Mpeg2 = {
9, // PicEntryNumber
1, // PreferedConfigBitstream
{ &DXVA2_ModeMPEG2_VLD, &GUID_NULL },
@@ -148,16 +145,14 @@ DXVA_PARAMS DXVA_Mpeg2 =
};
// DXVA modes supported for H264
-DXVA_PARAMS DXVA_H264 =
-{
+DXVA_PARAMS DXVA_H264 = {
16, // PicEntryNumber
2, // PreferedConfigBitstream
{ &DXVA2_ModeH264_E, &DXVA2_ModeH264_F, &DXVA_Intel_H264_ClearVideo, &GUID_NULL },
{ DXVA_RESTRICTED_MODE_H264_E, 0}
};
-DXVA_PARAMS DXVA_H264_VISTA =
-{
+DXVA_PARAMS DXVA_H264_VISTA = {
22, // PicEntryNumber
2, // PreferedConfigBitstream
{ &DXVA2_ModeH264_E, &DXVA2_ModeH264_F, &DXVA_Intel_H264_ClearVideo, &GUID_NULL },
@@ -165,16 +160,14 @@ DXVA_PARAMS DXVA_H264_VISTA =
};
// DXVA modes supported for VC1
-DXVA_PARAMS DXVA_VC1 =
-{
+DXVA_PARAMS DXVA_VC1 = {
14, // PicEntryNumber
1, // PreferedConfigBitstream
{ &DXVA2_ModeVC1_D, &GUID_NULL },
{ DXVA_RESTRICTED_MODE_VC1_D, 0}
};
-FFMPEG_CODECS ffCodecs[] =
-{
+FFMPEG_CODECS ffCodecs[] = {
#if HAS_FFMPEG_VIDEO_DECODERS
// Flash video
{ &MEDIASUBTYPE_FLV1, CODEC_ID_FLV1, MAKEFOURCC('F','L','V','1'), NULL },
@@ -348,8 +341,7 @@ FFMPEG_CODECS ffCodecs[] =
};
/* Important: the order should be exactly the same as in ffCodecs[] */
-const AMOVIESETUP_MEDIATYPE CMPCVideoDecFilter::sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE CMPCVideoDecFilter::sudPinTypesIn[] = {
#if HAS_FFMPEG_VIDEO_DECODERS
// Flash video
{ &MEDIATYPE_Video, &MEDIASUBTYPE_FLV1 },
@@ -530,8 +522,7 @@ bool* CMPCVideoDecFilter::FFmpegFilters = NULL;
bool* CMPCVideoDecFilter::DXVAFilters = NULL;
bool CMPCVideoDecFilter::m_ref_frame_count_check_skip = false;
-const AMOVIESETUP_MEDIATYPE CMPCVideoDecFilter::sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE CMPCVideoDecFilter::sudPinTypesOut[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_NV12},
{&MEDIATYPE_Video, &MEDIASUBTYPE_NV24}
};
@@ -545,8 +536,7 @@ BOOL CALLBACK EnumFindProcessWnd (HWND hwnd, LPARAM lParam)
GetWindowThreadProcessId (hwnd, &procid);
GetClassName (hwnd, WindowClass, countof(WindowClass));
- if (procid == GetCurrentProcessId() && _tcscmp (WindowClass, _T("MediaPlayerClassicW")) == 0)
- {
+ if (procid == GetCurrentProcessId() && _tcscmp (WindowClass, _T("MediaPlayerClassicW")) == 0) {
HWND* pWnd = (HWND*) lParam;
*pWnd = hwnd;
return FALSE;
@@ -559,20 +549,25 @@ CMPCVideoDecFilter::CMPCVideoDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
{
HWND hWnd = NULL;
- if(IsVistaOrAbove())
- {
- for (int i=0; i<countof(ffCodecs); i++)
- {
- if(ffCodecs[i].nFFCodec == CODEC_ID_H264)
+ if(IsVistaOrAbove()) {
+ for (int i=0; i<countof(ffCodecs); i++) {
+ if(ffCodecs[i].nFFCodec == CODEC_ID_H264) {
ffCodecs[i].DXVAModes = &DXVA_H264_VISTA;
+ }
}
}
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
- if (m_pOutput) delete m_pOutput;
+ if (m_pOutput) {
+ delete m_pOutput;
+ }
m_pOutput = DNew CVideoDecOutputPin(NAME("CVideoDecOutputPin"), this, phr, L"Output");
- if(!m_pOutput) *phr = E_OUTOFMEMORY;
+ if(!m_pOutput) {
+ *phr = E_OUTOFMEMORY;
+ }
m_pCpuId = DNew CCpuId();
m_pAVCodec = NULL;
@@ -618,20 +613,37 @@ CMPCVideoDecFilter::CMPCVideoDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
m_sar.SetSize(1,1);
CRegKey key;
- if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Video Decoder"), KEY_READ))
- {
+ if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Video Decoder"), KEY_READ)) {
DWORD dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ThreadNumber"), dw)) m_nThreadNumber = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DiscardMode"), dw)) m_nDiscardMode = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ErrorRecognition"), dw)) m_nErrorRecognition = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("IDCTAlgo"), dw)) m_nIDCTAlgo = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ActiveCodecs"), dw)) m_nActiveCodecs = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ARMode"), dw)) m_nARMode = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DXVACheckCompatibility"), dw)) m_nDXVACheckCompatibility = dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DisableDXVA_SD"), dw)) m_nDXVA_SD = dw;
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ThreadNumber"), dw)) {
+ m_nThreadNumber = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DiscardMode"), dw)) {
+ m_nDiscardMode = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ErrorRecognition"), dw)) {
+ m_nErrorRecognition = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("IDCTAlgo"), dw)) {
+ m_nIDCTAlgo = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ActiveCodecs"), dw)) {
+ m_nActiveCodecs = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ARMode"), dw)) {
+ m_nARMode = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DXVACheckCompatibility"), dw)) {
+ m_nDXVACheckCompatibility = dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DisableDXVA_SD"), dw)) {
+ m_nDXVA_SD = dw;
+ }
}
- if(m_nDXVACheckCompatibility > 3) m_nDXVACheckCompatibility = 1; // skip level check by default
+ if(m_nDXVACheckCompatibility > 3) {
+ m_nDXVACheckCompatibility = 1; // skip level check by default
+ }
ff_avcodec_default_get_buffer = avcodec_default_get_buffer;
ff_avcodec_default_release_buffer = avcodec_default_release_buffer;
@@ -649,23 +661,28 @@ CMPCVideoDecFilter::CMPCVideoDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
int nCodecs = countof(ffCodecs);
int nPinTypes = countof(sudPinTypesIn);
ASSERT (nCodecs == nPinTypes);
- for (int i=0; i<nPinTypes; i++)
+ for (int i=0; i<nPinTypes; i++) {
ASSERT (ffCodecs[i].clsMinorType == sudPinTypesIn[i].clsMinorType);
+ }
#endif
}
UINT CMPCVideoDecFilter::GetAdapter(IDirect3D9* pD3D, HWND hWnd)
{
- if(hWnd == NULL || pD3D == NULL)
+ if(hWnd == NULL || pD3D == NULL) {
return D3DADAPTER_DEFAULT;
+ }
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
- if(hMonitor == NULL) return D3DADAPTER_DEFAULT;
+ if(hMonitor == NULL) {
+ return D3DADAPTER_DEFAULT;
+ }
- for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp)
- {
+ for(UINT adp = 0, num_adp = pD3D->GetAdapterCount(); adp < num_adp; ++adp) {
HMONITOR hAdpMon = pD3D->GetAdapterMonitor(adp);
- if(hAdpMon == hMonitor) return adp;
+ if(hAdpMon == hMonitor) {
+ return adp;
+ }
}
return D3DADAPTER_DEFAULT;
@@ -680,11 +697,9 @@ void CMPCVideoDecFilter::DetectVideoCard(HWND hWnd)
m_VideoDriverVersion.LowPart = 0;
pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);
- if (pD3D9)
- {
+ if (pD3D9) {
D3DADAPTER_IDENTIFIER9 adapterIdentifier;
- if (pD3D9->GetAdapterIdentifier(GetAdapter(pD3D9, hWnd), 0, &adapterIdentifier) == S_OK)
- {
+ if (pD3D9->GetAdapterIdentifier(GetAdapter(pD3D9, hWnd), 0, &adapterIdentifier) == S_OK) {
m_nPCIVendor = adapterIdentifier.VendorId;
m_nPCIDevice = adapterIdentifier.DeviceId;
m_VideoDriverVersion = adapterIdentifier.DriverVersion;
@@ -712,15 +727,12 @@ bool CMPCVideoDecFilter::IsVideoInterlaced()
void CMPCVideoDecFilter::UpdateFrameTime (REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop)
{
- if (rtStart == _I64_MIN)
- {
+ if (rtStart == _I64_MIN) {
// If reference time has not been set by splitter, extrapolate start time
// from last known start time already delivered
rtStart = m_rtLastStart + m_rtAvrTimePerFrame*m_nCountEstimated;
m_nCountEstimated++;
- }
- else
- {
+ } else {
// Known start time, set as new reference
m_rtLastStart = rtStart;
m_nCountEstimated = 1;
@@ -738,13 +750,10 @@ void CMPCVideoDecFilter::GetOutputSize(int& w, int& h, int& arx, int& ary, int &
w = PictWidthRounded();
h = PictHeightRounded();
#else
- if (m_nDXVAMode == MODE_SOFTWARE)
- {
+ if (m_nDXVAMode == MODE_SOFTWARE) {
w = m_nWidth;
h = m_nHeight;
- }
- else
- {
+ } else {
// DXVA surface are multiple of 16 pixels!
w = PictWidthRounded();
h = PictHeightRounded();
@@ -778,111 +787,105 @@ int CMPCVideoDecFilter::PictHeightRounded()
int CMPCVideoDecFilter::FindCodec(const CMediaType* mtIn)
{
for (int i=0; i<countof(ffCodecs); i++)
- if (mtIn->subtype == *ffCodecs[i].clsMinorType)
- {
+ if (mtIn->subtype == *ffCodecs[i].clsMinorType) {
#ifndef REGISTER_FILTER
- switch (ffCodecs[i].nFFCodec)
- {
- case CODEC_ID_H264 :
- #if INTERNAL_DECODER_H264_DXVA
- m_bUseDXVA = DXVAFilters && DXVAFilters[TRA_DXVA_H264];
- #else
- m_bUseDXVA = false;
- #endif
- #if INTERNAL_DECODER_H264
- m_bUseFFmpeg = FFmpegFilters && FFmpegFilters[FFM_H264];
- #else
- m_bUseFFmpeg = false;
- #endif
- break;
- case CODEC_ID_VC1 :
- #if INTERNAL_DECODER_VC1_DXVA
- m_bUseDXVA = DXVAFilters && DXVAFilters[TRA_DXVA_VC1];
- #else
- m_bUseDXVA = false;
- #endif
- #if INTERNAL_DECODER_VC1
- m_bUseFFmpeg = FFmpegFilters && FFmpegFilters[FFM_VC1];
- #else
- m_bUseFFmpeg = false;
- #endif
- break;
- case CODEC_ID_MPEG2VIDEO :
- #if INTERNAL_DECODER_MPEG2_DXVA
- m_bUseDXVA = true;
- #endif
- m_bUseFFmpeg = false; // No Mpeg2 software support with ffmpeg!
- break;
- default :
- m_bUseDXVA = false;
+ switch (ffCodecs[i].nFFCodec) {
+ case CODEC_ID_H264 :
+#if INTERNAL_DECODER_H264_DXVA
+ m_bUseDXVA = DXVAFilters && DXVAFilters[TRA_DXVA_H264];
+#else
+ m_bUseDXVA = false;
+#endif
+#if INTERNAL_DECODER_H264
+ m_bUseFFmpeg = FFmpegFilters && FFmpegFilters[FFM_H264];
+#else
+ m_bUseFFmpeg = false;
+#endif
+ break;
+ case CODEC_ID_VC1 :
+#if INTERNAL_DECODER_VC1_DXVA
+ m_bUseDXVA = DXVAFilters && DXVAFilters[TRA_DXVA_VC1];
+#else
+ m_bUseDXVA = false;
+#endif
+#if INTERNAL_DECODER_VC1
+ m_bUseFFmpeg = FFmpegFilters && FFmpegFilters[FFM_VC1];
+#else
+ m_bUseFFmpeg = false;
+#endif
+ break;
+ case CODEC_ID_MPEG2VIDEO :
+#if INTERNAL_DECODER_MPEG2_DXVA
+ m_bUseDXVA = true;
+#endif
+ m_bUseFFmpeg = false; // No Mpeg2 software support with ffmpeg!
+ break;
+ default :
+ m_bUseDXVA = false;
}
return ((m_bUseDXVA || m_bUseFFmpeg) ? i : -1);
#else
bool bCodecActivated = false;
- switch (ffCodecs[i].nFFCodec)
- {
- case CODEC_ID_FLV1 :
- case CODEC_ID_VP6F :
- bCodecActivated = (m_nActiveCodecs & MPCVD_FLASH) != 0;
- break;
- case CODEC_ID_MPEG4 :
- if ((*ffCodecs[i].clsMinorType == MEDIASUBTYPE_XVID) ||
- (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_xvid) ||
- (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_XVIX) ||
- (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_xvix) )
- {
- bCodecActivated = (m_nActiveCodecs & MPCVD_XVID) != 0;
- }
- else if ((*ffCodecs[i].clsMinorType == MEDIASUBTYPE_DX50) ||
- (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_dx50) ||
- (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_DIVX) ||
- (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_divx) )
- {
- bCodecActivated = (m_nActiveCodecs & MPCVD_DIVX) != 0;
- }
- break;
- case CODEC_ID_WMV1 :
- case CODEC_ID_WMV2 :
- case CODEC_ID_WMV3 :
- bCodecActivated = (m_nActiveCodecs & MPCVD_WMV) != 0;
- break;
- case CODEC_ID_MSMPEG4V3 :
- case CODEC_ID_MSMPEG4V2 :
- case CODEC_ID_MSMPEG4V1 :
- bCodecActivated = (m_nActiveCodecs & MPCVD_MSMPEG4) != 0;
- break;
- case CODEC_ID_H264 :
- m_bUseDXVA = (m_nActiveCodecs & MPCVD_H264_DXVA) != 0;
- m_bUseFFmpeg = (m_nActiveCodecs & MPCVD_H264) != 0;
- bCodecActivated = m_bUseDXVA || m_bUseFFmpeg;
- break;
- case CODEC_ID_SVQ3 :
- case CODEC_ID_SVQ1 :
- bCodecActivated = (m_nActiveCodecs & MPCVD_SVQ3) != 0;
- break;
- case CODEC_ID_H263 :
- bCodecActivated = (m_nActiveCodecs & MPCVD_H263) != 0;
- break;
- case CODEC_ID_THEORA :
- bCodecActivated = (m_nActiveCodecs & MPCVD_THEORA) != 0;
- break;
- case CODEC_ID_VC1 :
- m_bUseDXVA = (m_nActiveCodecs & MPCVD_VC1_DXVA) != 0;
- m_bUseFFmpeg = (m_nActiveCodecs & MPCVD_VC1) != 0;
- bCodecActivated = m_bUseDXVA || m_bUseFFmpeg;
- break;
- case CODEC_ID_AMV :
- bCodecActivated = (m_nActiveCodecs & MPCVD_AMVV) != 0;
- break;
- case CODEC_ID_VP5 :
- case CODEC_ID_VP6 :
- case CODEC_ID_VP6A :
- bCodecActivated = (m_nActiveCodecs & MPCVD_VP6) != 0;
- break;
- case CODEC_ID_VP8 :
- bCodecActivated = (m_nActiveCodecs & MPCVD_VP8) != 0;
- break;
+ switch (ffCodecs[i].nFFCodec) {
+ case CODEC_ID_FLV1 :
+ case CODEC_ID_VP6F :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_FLASH) != 0;
+ break;
+ case CODEC_ID_MPEG4 :
+ if ((*ffCodecs[i].clsMinorType == MEDIASUBTYPE_XVID) ||
+ (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_xvid) ||
+ (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_XVIX) ||
+ (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_xvix) ) {
+ bCodecActivated = (m_nActiveCodecs & MPCVD_XVID) != 0;
+ } else if ((*ffCodecs[i].clsMinorType == MEDIASUBTYPE_DX50) ||
+ (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_dx50) ||
+ (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_DIVX) ||
+ (*ffCodecs[i].clsMinorType == MEDIASUBTYPE_divx) ) {
+ bCodecActivated = (m_nActiveCodecs & MPCVD_DIVX) != 0;
+ }
+ break;
+ case CODEC_ID_WMV1 :
+ case CODEC_ID_WMV2 :
+ case CODEC_ID_WMV3 :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_WMV) != 0;
+ break;
+ case CODEC_ID_MSMPEG4V3 :
+ case CODEC_ID_MSMPEG4V2 :
+ case CODEC_ID_MSMPEG4V1 :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_MSMPEG4) != 0;
+ break;
+ case CODEC_ID_H264 :
+ m_bUseDXVA = (m_nActiveCodecs & MPCVD_H264_DXVA) != 0;
+ m_bUseFFmpeg = (m_nActiveCodecs & MPCVD_H264) != 0;
+ bCodecActivated = m_bUseDXVA || m_bUseFFmpeg;
+ break;
+ case CODEC_ID_SVQ3 :
+ case CODEC_ID_SVQ1 :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_SVQ3) != 0;
+ break;
+ case CODEC_ID_H263 :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_H263) != 0;
+ break;
+ case CODEC_ID_THEORA :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_THEORA) != 0;
+ break;
+ case CODEC_ID_VC1 :
+ m_bUseDXVA = (m_nActiveCodecs & MPCVD_VC1_DXVA) != 0;
+ m_bUseFFmpeg = (m_nActiveCodecs & MPCVD_VC1) != 0;
+ bCodecActivated = m_bUseDXVA || m_bUseFFmpeg;
+ break;
+ case CODEC_ID_AMV :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_AMVV) != 0;
+ break;
+ case CODEC_ID_VP5 :
+ case CODEC_ID_VP6 :
+ case CODEC_ID_VP6A :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_VP6) != 0;
+ break;
+ case CODEC_ID_VP8 :
+ bCodecActivated = (m_nActiveCodecs & MPCVD_VP8) != 0;
+ break;
}
return (bCodecActivated ? i : -1);
#endif
@@ -896,26 +899,38 @@ void CMPCVideoDecFilter::Cleanup()
SAFE_DELETE (m_pDXVADecoder);
// Release FFMpeg
- if (m_pAVCtx)
- {
- if (m_pAVCtx->intra_matrix) free(m_pAVCtx->intra_matrix);
- if (m_pAVCtx->inter_matrix) free(m_pAVCtx->inter_matrix);
- if (m_pAVCtx->extradata) free((unsigned char*)m_pAVCtx->extradata);
- if (m_pFFBuffer) free(m_pFFBuffer);
+ if (m_pAVCtx) {
+ if (m_pAVCtx->intra_matrix) {
+ free(m_pAVCtx->intra_matrix);
+ }
+ if (m_pAVCtx->inter_matrix) {
+ free(m_pAVCtx->inter_matrix);
+ }
+ if (m_pAVCtx->extradata) {
+ free((unsigned char*)m_pAVCtx->extradata);
+ }
+ if (m_pFFBuffer) {
+ free(m_pFFBuffer);
+ }
- if (m_pAVCtx->slice_offset) av_free(m_pAVCtx->slice_offset);
- if (m_pAVCtx->codec) avcodec_close(m_pAVCtx);
+ if (m_pAVCtx->slice_offset) {
+ av_free(m_pAVCtx->slice_offset);
+ }
+ if (m_pAVCtx->codec) {
+ avcodec_close(m_pAVCtx);
+ }
// Free thread resource if necessary
FFSetThreadNumber (m_pAVCtx, 0);
av_free(m_pAVCtx);
}
- if (m_pFrame) av_free(m_pFrame);
+ if (m_pFrame) {
+ av_free(m_pFrame);
+ }
#if HAS_FFMPEG_VIDEO_DECODERS
- if (m_pSwsContext)
- {
+ if (m_pSwsContext) {
sws_freeContext(m_pSwsContext);
m_pSwsContext = NULL;
}
@@ -932,8 +947,7 @@ void CMPCVideoDecFilter::Cleanup()
SAFE_DELETE_ARRAY (m_pVideoOutputFormat);
// Release DXVA ressources
- if (m_hDevice != INVALID_HANDLE_VALUE)
- {
+ if (m_hDevice != INVALID_HANDLE_VALUE) {
m_pDeviceManager->CloseDeviceHandle(m_hDevice);
m_hDevice = INVALID_HANDLE_VALUE;
}
@@ -946,16 +960,15 @@ void CMPCVideoDecFilter::Cleanup()
void CMPCVideoDecFilter::CalcAvgTimePerFrame()
{
CMediaType &mt = m_pInput->CurrentMediaType();
- if (mt.formattype==FORMAT_VideoInfo)
+ if (mt.formattype==FORMAT_VideoInfo) {
m_rtAvrTimePerFrame = ((VIDEOINFOHEADER*)mt.pbFormat)->AvgTimePerFrame;
- else if (mt.formattype==FORMAT_VideoInfo2)
+ } else if (mt.formattype==FORMAT_VideoInfo2) {
m_rtAvrTimePerFrame = ((VIDEOINFOHEADER2*)mt.pbFormat)->AvgTimePerFrame;
- else if (mt.formattype==FORMAT_MPEGVideo)
+ } else if (mt.formattype==FORMAT_MPEGVideo) {
m_rtAvrTimePerFrame = ((MPEG1VIDEOINFO*)mt.pbFormat)->hdr.AvgTimePerFrame;
- else if (mt.formattype==FORMAT_MPEG2Video)
+ } else if (mt.formattype==FORMAT_MPEG2Video) {
m_rtAvrTimePerFrame = ((MPEG2VIDEOINFO*)mt.pbFormat)->hdr.AvgTimePerFrame;
- else
- {
+ } else {
ASSERT (FALSE);
m_rtAvrTimePerFrame = 1;
}
@@ -975,7 +988,7 @@ void CMPCVideoDecFilter::LogLibAVCodec(void* par,int level,const char *fmt,va_li
void CMPCVideoDecFilter::OnGetBuffer(AVFrame *pic)
{
// Callback from FFMpeg to store Ref Time in frame (needed to have correct rtStart after avcodec_decode_video calls)
-// pic->rtStart = m_rtStart;
+ // pic->rtStart = m_rtStart;
}
STDMETHODIMP CMPCVideoDecFilter::NonDelegatingQueryInterface(REFIID riid, void** ppv)
@@ -992,11 +1005,11 @@ STDMETHODIMP CMPCVideoDecFilter::NonDelegatingQueryInterface(REFIID riid, void**
HRESULT CMPCVideoDecFilter::CheckInputType(const CMediaType* mtIn)
{
- for (int i=0; i<sizeof(sudPinTypesIn)/sizeof(AMOVIESETUP_MEDIATYPE); i++)
- {
+ for (int i=0; i<sizeof(sudPinTypesIn)/sizeof(AMOVIESETUP_MEDIATYPE); i++) {
if ((mtIn->majortype == *sudPinTypesIn[i].clsMajorType) &&
- (mtIn->subtype == *sudPinTypesIn[i].clsMinorType))
+ (mtIn->subtype == *sudPinTypesIn[i].clsMinorType)) {
return S_OK;
+ }
}
return VFW_E_TYPE_NOT_ACCEPTED;
@@ -1013,13 +1026,13 @@ HRESULT CMPCVideoDecFilter::SetMediaType(PIN_DIRECTION direction,const CMediaTyp
{
int nNewCodec;
- if (direction == PINDIR_INPUT)
- {
+ if (direction == PINDIR_INPUT) {
nNewCodec = FindCodec(pmt);
- if (nNewCodec == -1) return VFW_E_TYPE_NOT_ACCEPTED;
+ if (nNewCodec == -1) {
+ return VFW_E_TYPE_NOT_ACCEPTED;
+ }
- if (nNewCodec != m_nCodecNb)
- {
+ if (nNewCodec != m_nCodecNb) {
m_nCodecNb = nNewCodec;
m_bReorderBFrame = true;
@@ -1029,45 +1042,36 @@ HRESULT CMPCVideoDecFilter::SetMediaType(PIN_DIRECTION direction,const CMediaTyp
m_pAVCtx = avcodec_alloc_context();
CheckPointer (m_pAVCtx, E_POINTER);
- if ((m_nThreadNumber > 1) && IsMultiThreadSupported (ffCodecs[m_nCodecNb].nFFCodec))
+ if ((m_nThreadNumber > 1) && IsMultiThreadSupported (ffCodecs[m_nCodecNb].nFFCodec)) {
FFSetThreadNumber(m_pAVCtx, m_nThreadNumber);
+ }
m_pFrame = avcodec_alloc_frame();
CheckPointer (m_pFrame, E_POINTER);
- if(pmt->formattype == FORMAT_VideoInfo)
- {
+ if(pmt->formattype == FORMAT_VideoInfo) {
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->pbFormat;
m_pAVCtx->width = vih->bmiHeader.biWidth;
m_pAVCtx->height = abs(vih->bmiHeader.biHeight);
m_pAVCtx->codec_tag = vih->bmiHeader.biCompression;
- }
- else if(pmt->formattype == FORMAT_VideoInfo2)
- {
+ } else if(pmt->formattype == FORMAT_VideoInfo2) {
VIDEOINFOHEADER2* vih2 = (VIDEOINFOHEADER2*)pmt->pbFormat;
m_pAVCtx->width = vih2->bmiHeader.biWidth;
m_pAVCtx->height = abs(vih2->bmiHeader.biHeight);
m_pAVCtx->codec_tag = vih2->bmiHeader.biCompression;
- }
- else if(pmt->formattype == FORMAT_MPEGVideo)
- {
+ } else if(pmt->formattype == FORMAT_MPEGVideo) {
MPEG1VIDEOINFO* mpgv = (MPEG1VIDEOINFO*)pmt->pbFormat;
m_pAVCtx->width = mpgv->hdr.bmiHeader.biWidth;
m_pAVCtx->height = abs(mpgv->hdr.bmiHeader.biHeight);
m_pAVCtx->codec_tag = mpgv->hdr.bmiHeader.biCompression;
- }
- else if(pmt->formattype == FORMAT_MPEG2Video)
- {
+ } else if(pmt->formattype == FORMAT_MPEG2Video) {
MPEG2VIDEOINFO* mpg2v = (MPEG2VIDEOINFO*)pmt->pbFormat;
m_pAVCtx->width = mpg2v->hdr.bmiHeader.biWidth;
m_pAVCtx->height = abs(mpg2v->hdr.bmiHeader.biHeight);
m_pAVCtx->codec_tag = mpg2v->hdr.bmiHeader.biCompression;
- if (mpg2v->hdr.bmiHeader.biCompression == NULL)
- {
+ if (mpg2v->hdr.bmiHeader.biCompression == NULL) {
m_pAVCtx->codec_tag = pmt->subtype.Data1;
- }
- else if ( (m_pAVCtx->codec_tag == MAKEFOURCC('a','v','c','1')) || (m_pAVCtx->codec_tag == MAKEFOURCC('A','V','C','1')))
- {
+ } else if ( (m_pAVCtx->codec_tag == MAKEFOURCC('a','v','c','1')) || (m_pAVCtx->codec_tag == MAKEFOURCC('A','V','C','1'))) {
m_pAVCtx->nal_length_size = mpg2v->dwFlags;
m_bReorderBFrame = false;
}
@@ -1087,9 +1091,9 @@ HRESULT CMPCVideoDecFilter::SetMediaType(PIN_DIRECTION direction,const CMediaTyp
m_pAVCtx->postgain = 1.0f;
m_pAVCtx->debug_mv = 0;
- #ifdef _DEBUG
+#ifdef _DEBUG
//m_pAVCtx->debug = FF_DEBUG_PICT_INFO | FF_DEBUG_STARTCODE | FF_DEBUG_PTS;
- #endif
+#endif
m_pAVCtx->opaque = this;
m_pAVCtx->get_buffer = get_buffer;
@@ -1098,53 +1102,52 @@ HRESULT CMPCVideoDecFilter::SetMediaType(PIN_DIRECTION direction,const CMediaTyp
ConnectTo (m_pAVCtx);
CalcAvgTimePerFrame();
- if (avcodec_open(m_pAVCtx, m_pAVCodec)<0)
+ if (avcodec_open(m_pAVCtx, m_pAVCodec)<0) {
return VFW_E_INVALIDMEDIATYPE;
+ }
- switch (ffCodecs[m_nCodecNb].nFFCodec)
- {
- case CODEC_ID_H264 :
- if((m_nDXVA_SD) && (PictWidthRounded() < 1280))
- {
- m_bDXVACompatible = false;
- }
- else
- {
- if(m_nDXVACheckCompatibility != 3)
- {
- // non-zero value indicates that an incompatibility was detected
- int nCompat = FFH264CheckCompatibility (PictWidthRounded(), PictHeightRounded(), m_pAVCtx, (BYTE*)m_pAVCtx->extradata, m_pAVCtx->extradata_size, m_nPCIVendor, m_nPCIDevice, m_VideoDriverVersion);
-
- if(nCompat > 0)
- {
- switch(m_nDXVACheckCompatibility)
- {
- case 0 :
- // full check
- m_bDXVACompatible = false;
- break;
- case 1 :
- // skip level check
- if(nCompat != DXVA_UNSUPPORTED_LEVEL) m_bDXVACompatible = false;
- break;
- case 2 :
- // skip reference frame check
- if(nCompat != DXVA_TOO_MANY_REF_FRAMES) m_bDXVACompatible = false;
- break;
+ switch (ffCodecs[m_nCodecNb].nFFCodec) {
+ case CODEC_ID_H264 :
+ if((m_nDXVA_SD) && (PictWidthRounded() < 1280)) {
+ m_bDXVACompatible = false;
+ } else {
+ if(m_nDXVACheckCompatibility != 3) {
+ // non-zero value indicates that an incompatibility was detected
+ int nCompat = FFH264CheckCompatibility (PictWidthRounded(), PictHeightRounded(), m_pAVCtx, (BYTE*)m_pAVCtx->extradata, m_pAVCtx->extradata_size, m_nPCIVendor, m_nPCIDevice, m_VideoDriverVersion);
+
+ if(nCompat > 0) {
+ switch(m_nDXVACheckCompatibility) {
+ case 0 :
+ // full check
+ m_bDXVACompatible = false;
+ break;
+ case 1 :
+ // skip level check
+ if(nCompat != DXVA_UNSUPPORTED_LEVEL) {
+ m_bDXVACompatible = false;
+ }
+ break;
+ case 2 :
+ // skip reference frame check
+ if(nCompat != DXVA_TOO_MANY_REF_FRAMES) {
+ m_bDXVACompatible = false;
+ }
+ break;
+ }
}
}
}
- }
- break;
- case CODEC_ID_MPEG2VIDEO :
- // DSP is disable for DXVA decoding (to keep default idct_permutation)
- m_pAVCtx->dsp_mask ^= AV_CPU_FLAG_FORCE;
- break;
+ break;
+ case CODEC_ID_MPEG2VIDEO :
+ // DSP is disable for DXVA decoding (to keep default idct_permutation)
+ m_pAVCtx->dsp_mask ^= AV_CPU_FLAG_FORCE;
+ break;
}
// Force single thread for DXVA !
- if (IsDXVASupported())
+ if (IsDXVASupported()) {
FFSetThreadNumber(m_pAVCtx, 1);
+ }
BuildDXVAOutputFormat();
}
@@ -1154,16 +1157,14 @@ HRESULT CMPCVideoDecFilter::SetMediaType(PIN_DIRECTION direction,const CMediaTyp
}
-VIDEO_OUTPUT_FORMATS DXVAFormats[] =
-{
+VIDEO_OUTPUT_FORMATS DXVAFormats[] = {
{&MEDIASUBTYPE_NV12, 1, 12, 'avxd'}, // DXVA2
{&MEDIASUBTYPE_NV12, 1, 12, 'AVXD'},
{&MEDIASUBTYPE_NV12, 1, 12, 'AVxD'},
{&MEDIASUBTYPE_NV12, 1, 12, 'AvXD'}
};
-VIDEO_OUTPUT_FORMATS SoftwareFormats[] =
-{
+VIDEO_OUTPUT_FORMATS SoftwareFormats[] = {
{&MEDIASUBTYPE_YV12, 3, 12, '21VY'},
{&MEDIASUBTYPE_YUY2, 1, 16, '2YUY'}, // Software
{&MEDIASUBTYPE_I420, 3, 12, '024I'},
@@ -1200,11 +1201,9 @@ void CMPCVideoDecFilter::BuildDXVAOutputFormat()
m_pVideoOutputFormat = DNew VIDEO_OUTPUT_FORMATS[m_nVideoOutputCount];
- if (IsDXVASupported())
- {
+ if (IsDXVASupported()) {
// Dynamic DXVA media types for DXVA1
- for (nPos=0; nPos<ffCodecs[m_nCodecNb].DXVAModeCount(); nPos++)
- {
+ for (nPos=0; nPos<ffCodecs[m_nCodecNb].DXVAModeCount(); nPos++) {
m_pVideoOutputFormat[nPos].subtype = ffCodecs[m_nCodecNb].DXVAModes->Decoder[nPos];
m_pVideoOutputFormat[nPos].biCompression = 'avxd';
m_pVideoOutputFormat[nPos].biBitCount = 12;
@@ -1217,17 +1216,19 @@ void CMPCVideoDecFilter::BuildDXVAOutputFormat()
}
// Software rendering
- if (m_bUseFFmpeg)
+ if (m_bUseFFmpeg) {
memcpy (&m_pVideoOutputFormat[nPos], SoftwareFormats, sizeof(SoftwareFormats));
+ }
}
int CMPCVideoDecFilter::GetPicEntryNumber()
{
- if (IsDXVASupported())
+ if (IsDXVASupported()) {
return ffCodecs[m_nCodecNb].DXVAModes->PicEntryNumber;
- else
+ } else {
return 0;
+ }
}
@@ -1244,44 +1245,32 @@ void CMPCVideoDecFilter::AllocExtradata(AVCodecContext* pAVCtx, const CMediaType
const BYTE* data = NULL;
unsigned int size = 0;
- if (pmt->formattype==FORMAT_VideoInfo)
- {
+ if (pmt->formattype==FORMAT_VideoInfo) {
size = pmt->cbFormat-sizeof(VIDEOINFOHEADER);
data = size?pmt->pbFormat+sizeof(VIDEOINFOHEADER):NULL;
- }
- else if (pmt->formattype==FORMAT_VideoInfo2)
- {
+ } else if (pmt->formattype==FORMAT_VideoInfo2) {
size = pmt->cbFormat-sizeof(VIDEOINFOHEADER2);
data = size?pmt->pbFormat+sizeof(VIDEOINFOHEADER2):NULL;
- }
- else if (pmt->formattype==FORMAT_MPEGVideo)
- {
+ } else if (pmt->formattype==FORMAT_MPEGVideo) {
MPEG1VIDEOINFO* mpeg1info = (MPEG1VIDEOINFO*)pmt->pbFormat;
- if (mpeg1info->cbSequenceHeader)
- {
+ if (mpeg1info->cbSequenceHeader) {
size = mpeg1info->cbSequenceHeader;
data = mpeg1info->bSequenceHeader;
}
- }
- else if (pmt->formattype==FORMAT_MPEG2Video)
- {
+ } else if (pmt->formattype==FORMAT_MPEG2Video) {
MPEG2VIDEOINFO* mpeg2info = (MPEG2VIDEOINFO*)pmt->pbFormat;
- if (mpeg2info->cbSequenceHeader)
- {
+ if (mpeg2info->cbSequenceHeader) {
size = mpeg2info->cbSequenceHeader;
data = (const uint8_t*)mpeg2info->dwSequenceHeader;
}
- }
- else if (pmt->formattype==FORMAT_VorbisFormat2)
- {
+ } else if (pmt->formattype==FORMAT_VorbisFormat2) {
const VORBISFORMAT2 *vf2=(const VORBISFORMAT2*)pmt->pbFormat;
UNUSED_ALWAYS(vf2);
size=pmt->cbFormat-sizeof(VORBISFORMAT2);
data=size?pmt->pbFormat+sizeof(VORBISFORMAT2):NULL;
}
- if (size)
- {
+ if (size) {
pAVCtx->extradata_size = size;
pAVCtx->extradata = (const unsigned char*)calloc(1,size+FF_INPUT_BUFFER_PADDING_SIZE);
memcpy((void*)pAVCtx->extradata, data, size);
@@ -1293,31 +1282,31 @@ HRESULT CMPCVideoDecFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pRece
{
LOG(_T("CMPCVideoDecFilter::CompleteConnect"));
- if (direction==PINDIR_INPUT && m_pOutput->IsConnected())
- {
+ if (direction==PINDIR_INPUT && m_pOutput->IsConnected()) {
ReconnectOutput (m_nWidth, m_nHeight);
- }
- else if (direction==PINDIR_OUTPUT)
- {
- if (IsDXVASupported())
- {
- if (m_nDXVAMode == MODE_DXVA1)
+ } else if (direction==PINDIR_OUTPUT) {
+ if (IsDXVASupported()) {
+ if (m_nDXVAMode == MODE_DXVA1) {
m_pDXVADecoder->ConfigureDXVA1();
- else if (SUCCEEDED (ConfigureDXVA2 (pReceivePin)) && SUCCEEDED (SetEVRForDXVA2 (pReceivePin)) )
+ } else if (SUCCEEDED (ConfigureDXVA2 (pReceivePin)) && SUCCEEDED (SetEVRForDXVA2 (pReceivePin)) ) {
m_nDXVAMode = MODE_DXVA2;
+ }
}
- if (m_nDXVAMode == MODE_SOFTWARE && !FFSoftwareCheckCompatibility(m_pAVCtx))
+ if (m_nDXVAMode == MODE_SOFTWARE && !FFSoftwareCheckCompatibility(m_pAVCtx)) {
return VFW_E_INVALIDMEDIATYPE;
+ }
CLSID ClsidSourceFilter = GetCLSID(m_pInput->GetConnected());
- if((ClsidSourceFilter == __uuidof(CMpegSourceFilter)) || (ClsidSourceFilter == __uuidof(CMpegSplitterFilter)))
+ if((ClsidSourceFilter == __uuidof(CMpegSourceFilter)) || (ClsidSourceFilter == __uuidof(CMpegSplitterFilter))) {
m_bReorderBFrame = false;
+ }
}
// Cannot use YUY2 if horizontal or vertical resolution is not even
if ( ((m_pOutput->CurrentMediaType().subtype == MEDIASUBTYPE_NV12) && (m_nDXVAMode == MODE_SOFTWARE)) ||
- ((m_pOutput->CurrentMediaType().subtype == MEDIASUBTYPE_YUY2) && (m_pAVCtx->width&1 || m_pAVCtx->height&1)) )
+ ((m_pOutput->CurrentMediaType().subtype == MEDIASUBTYPE_YUY2) && (m_pAVCtx->width&1 || m_pAVCtx->height&1)) ) {
return VFW_E_INVALIDMEDIATYPE;
+ }
return __super::CompleteConnect (direction, pReceivePin);
}
@@ -1325,24 +1314,26 @@ HRESULT CMPCVideoDecFilter::CompleteConnect(PIN_DIRECTION direction, IPin* pRece
HRESULT CMPCVideoDecFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if (UseDXVA2())
- {
+ if (UseDXVA2()) {
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
pProperties->cBuffers = GetPicEntryNumber();
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
? E_FAIL
: NOERROR;
- }
- else
+ } else {
return __super::DecideBufferSize (pAllocator, pProperties);
+ }
}
@@ -1356,19 +1347,20 @@ HRESULT CMPCVideoDecFilter::NewSegment(REFERENCE_TIME rtStart, REFERENCE_TIME rt
ResetBuffer();
- if (m_pAVCtx)
+ if (m_pAVCtx) {
avcodec_flush_buffers (m_pAVCtx);
+ }
- if (m_pDXVADecoder)
+ if (m_pDXVADecoder) {
m_pDXVADecoder->Flush();
+ }
return __super::NewSegment (rtStart, rtStop, dRate);
}
HRESULT CMPCVideoDecFilter::BreakConnect(PIN_DIRECTION dir)
{
- if (dir == PINDIR_INPUT)
- {
+ if (dir == PINDIR_INPUT) {
Cleanup();
}
@@ -1377,34 +1369,31 @@ HRESULT CMPCVideoDecFilter::BreakConnect(PIN_DIRECTION dir)
void CMPCVideoDecFilter::SetTypeSpecificFlags(IMediaSample* pMS)
{
- if(CComQIPtr<IMediaSample2> pMS2 = pMS)
- {
+ if(CComQIPtr<IMediaSample2> pMS2 = pMS) {
AM_SAMPLE2_PROPERTIES props;
- if(SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props)))
- {
+ if(SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props))) {
props.dwTypeSpecificFlags &= ~0x7f;
- if(!m_pFrame->interlaced_frame)
+ if(!m_pFrame->interlaced_frame) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_WEAVE;
- else
- {
- if(m_pFrame->top_field_first)
+ } else {
+ if(m_pFrame->top_field_first) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_FIELD1FIRST;
+ }
}
- switch (m_pFrame->pict_type)
- {
- case FF_I_TYPE :
- case FF_SI_TYPE :
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_I_SAMPLE;
- break;
- case FF_P_TYPE :
- case FF_SP_TYPE :
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_P_SAMPLE;
- break;
- default :
- props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_B_SAMPLE;
- break;
+ switch (m_pFrame->pict_type) {
+ case FF_I_TYPE :
+ case FF_SI_TYPE :
+ props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_I_SAMPLE;
+ break;
+ case FF_P_TYPE :
+ case FF_SP_TYPE :
+ props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_P_SAMPLE;
+ break;
+ default :
+ props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_B_SAMPLE;
+ break;
}
pMS2->SetProperties(sizeof(props), (BYTE*)&props);
@@ -1415,11 +1404,12 @@ void CMPCVideoDecFilter::SetTypeSpecificFlags(IMediaSample* pMS)
#if HAS_FFMPEG_VIDEO_DECODERS
int CMPCVideoDecFilter::GetCspFromMediaType(GUID& subtype)
{
- if (subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV || subtype == MEDIASUBTYPE_YV12)
+ if (subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV || subtype == MEDIASUBTYPE_YV12) {
return FF_CSP_420P|FF_CSP_FLAGS_YUV_ADJ;
- else if (subtype == MEDIASUBTYPE_YUY2)
+ } else if (subtype == MEDIASUBTYPE_YUY2) {
return FF_CSP_YUY2;
-// else if (subtype == MEDIASUBTYPE_ARGB32 || subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_RGB24 || subtype == MEDIASUBTYPE_RGB565)
+ }
+ // else if (subtype == MEDIASUBTYPE_ARGB32 || subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_RGB24 || subtype == MEDIASUBTYPE_RGB565)
ASSERT (FALSE);
return FF_CSP_NULL;
@@ -1428,15 +1418,18 @@ int CMPCVideoDecFilter::GetCspFromMediaType(GUID& subtype)
void CMPCVideoDecFilter::InitSwscale()
{
- if (m_pSwsContext == NULL)
- {
+ if (m_pSwsContext == NULL) {
TYCbCr2RGB_coeffs coeffs(ffYCbCr_RGB_coeff_ITUR_BT601,0, 235, 16, 255.0, 0.0);
int32_t swscaleTable[7];
SwsParams params;
memset(&params,0,sizeof(params));
- if (m_pAVCtx->dsp_mask & CCpuId::MPC_MM_MMX) params.cpu |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2;
- if (m_pAVCtx->dsp_mask & CCpuId::MPC_MM_3DNOW) params.cpu |= SWS_CPU_CAPS_3DNOW;
+ if (m_pAVCtx->dsp_mask & CCpuId::MPC_MM_MMX) {
+ params.cpu |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2;
+ }
+ if (m_pAVCtx->dsp_mask & CCpuId::MPC_MM_3DNOW) {
+ params.cpu |= SWS_CPU_CAPS_3DNOW;
+ }
params.methodLuma.method=params.methodChroma.method=SWS_POINT;
@@ -1487,10 +1480,8 @@ HRESULT CMPCVideoDecFilter::SoftwareDecode(IMediaSample* pIn, BYTE* pDataIn, int
AVPacket avpkt;
av_init_packet(&avpkt);
- while (nSize > 0)
- {
- if (nSize+FF_INPUT_BUFFER_PADDING_SIZE > m_nFFBufferSize)
- {
+ while (nSize > 0) {
+ if (nSize+FF_INPUT_BUFFER_PADDING_SIZE > m_nFFBufferSize) {
m_nFFBufferSize = nSize+FF_INPUT_BUFFER_PADDING_SIZE;
m_pFFBuffer = (BYTE*)realloc(m_pFFBuffer, m_nFFBufferSize);
}
@@ -1509,15 +1500,20 @@ HRESULT CMPCVideoDecFilter::SoftwareDecode(IMediaSample* pIn, BYTE* pDataIn, int
avpkt.flags = AV_PKT_FLAG_KEY;
used_bytes = avcodec_decode_video2 (m_pAVCtx, m_pFrame, &got_picture, &avpkt);
- if (!got_picture || !m_pFrame->data[0]) return S_OK;
- if(pIn->IsPreroll() == S_OK || rtStart < 0) return S_OK;
+ if (!got_picture || !m_pFrame->data[0]) {
+ return S_OK;
+ }
+ if(pIn->IsPreroll() == S_OK || rtStart < 0) {
+ return S_OK;
+ }
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
UpdateAspectRatio();
- if(FAILED(hr = GetDeliveryBuffer(m_pAVCtx->width, m_pAVCtx->height, &pOut)) || FAILED(hr = pOut->GetPointer(&pDataOut)))
+ if(FAILED(hr = GetDeliveryBuffer(m_pAVCtx->width, m_pAVCtx->height, &pOut)) || FAILED(hr = pOut->GetPointer(&pDataOut))) {
return hr;
+ }
rtStart = m_pFrame->reordered_opaque;
rtStop = m_pFrame->reordered_opaque + m_rtAvrTimePerFrame;
@@ -1527,34 +1523,37 @@ HRESULT CMPCVideoDecFilter::SoftwareDecode(IMediaSample* pIn, BYTE* pDataIn, int
pOut->SetMediaTime(NULL, NULL);
#if HAS_FFMPEG_VIDEO_DECODERS
- if (m_pSwsContext == NULL) InitSwscale();
+ if (m_pSwsContext == NULL) {
+ InitSwscale();
+ }
// TODO : quick and dirty patch to fix convertion to YUY2 with swscale
- if (m_nOutCsp == FF_CSP_YUY2)
+ if (m_nOutCsp == FF_CSP_YUY2) {
CopyBuffer(pDataOut, m_pFrame->data, m_pAVCtx->width, m_pAVCtx->height, m_pFrame->linesize[0], MEDIASUBTYPE_I420, false);
+ }
- else if (m_pSwsContext != NULL)
- {
+ else if (m_pSwsContext != NULL) {
uint8_t* dst[4];
stride_t srcStride[4];
stride_t dstStride[4];
const TcspInfo *outcspInfo=csp_getInfo(m_nOutCsp);
- for (int i=0; i<4; i++)
- {
+ for (int i=0; i<4; i++) {
srcStride[i]=(stride_t)m_pFrame->linesize[i];
dstStride[i]=m_pOutSize.cx>>outcspInfo->shiftX[i];
- if (i==0)
+ if (i==0) {
dst[i]=pDataOut;
- else
+ } else {
dst[i]=dst[i-1]+dstStride[i-1]*(m_pOutSize.cy>>outcspInfo->shiftY[i-1]);
+ }
}
int nTempCsp = m_nOutCsp;
- if(outcspInfo->id==FF_CSP_420P)
+ if(outcspInfo->id==FF_CSP_420P) {
csp_yuv_adj_to_plane(nTempCsp,outcspInfo,odd2even(m_pOutSize.cy),(unsigned char**)dst,dstStride);
- else
+ } else {
csp_yuv_adj_to_plane(nTempCsp,outcspInfo,m_pAVCtx->height,(unsigned char**)dst,dstStride);
+ }
sws_scale_ordered (m_pSwsContext, m_pFrame->data, srcStride, 0, m_pAVCtx->height, dst, dstStride);
}
@@ -1667,24 +1666,17 @@ bool CMPCVideoDecFilter::FindPicture(int nIndex, int nStartCode)
{
DWORD dw = 0;
- for (int i=0; i<m_nFFBufferPos-nIndex; i++)
- {
+ for (int i=0; i<m_nFFBufferPos-nIndex; i++) {
dw = (dw<<8) + m_pFFBuffer[i+nIndex];
- if (i >= 4)
- {
- if (m_nFFPicEnd == INT_MIN)
- {
+ if (i >= 4) {
+ if (m_nFFPicEnd == INT_MIN) {
if ( (dw & 0xffffff00) == 0x00000100 &&
- (dw & 0x000000FF) == (DWORD)nStartCode )
- {
+ (dw & 0x000000FF) == (DWORD)nStartCode ) {
m_nFFPicEnd = i+nIndex-3;
}
- }
- else
- {
+ } else {
if ( (dw & 0xffffff00) == 0x00000100 &&
- ( (dw & 0x000000FF) == (DWORD)nStartCode || (dw & 0x000000FF) == 0xB3 ))
- {
+ ( (dw & 0x000000FF) == (DWORD)nStartCode || (dw & 0x000000FF) == 0xB3 )) {
m_nFFPicEnd = i+nIndex-3;
return true;
}
@@ -1702,8 +1694,7 @@ void CMPCVideoDecFilter::ResetBuffer()
m_nFFBufferPos = 0;
m_nFFPicEnd = INT_MIN;
- for (int i=0; i<MAX_BUFF_TIME; i++)
- {
+ for (int i=0; i<MAX_BUFF_TIME; i++) {
m_FFBufferTime[i].nBuffPos = INT_MIN;
m_FFBufferTime[i].rtStart = _I64_MIN;
m_FFBufferTime[i].rtStop = _I64_MIN;
@@ -1712,10 +1703,8 @@ void CMPCVideoDecFilter::ResetBuffer()
void CMPCVideoDecFilter::PushBufferTime(int nPos, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop)
{
- for (int i=0; i<MAX_BUFF_TIME; i++)
- {
- if (m_FFBufferTime[i].nBuffPos == INT_MIN)
- {
+ for (int i=0; i<MAX_BUFF_TIME; i++) {
+ if (m_FFBufferTime[i].nBuffPos == INT_MIN) {
m_FFBufferTime[i].nBuffPos = nPos;
m_FFBufferTime[i].rtStart = rtStart;
m_FFBufferTime[i].rtStop = rtStop;
@@ -1730,10 +1719,8 @@ void CMPCVideoDecFilter::PopBufferTime(int nPos)
int i = 0;
// Shift buffer time list
- while (i<MAX_BUFF_TIME && m_FFBufferTime[i].nBuffPos!=INT_MIN)
- {
- if (m_FFBufferTime[i].nBuffPos >= nPos)
- {
+ while (i<MAX_BUFF_TIME && m_FFBufferTime[i].nBuffPos!=INT_MIN) {
+ if (m_FFBufferTime[i].nBuffPos >= nPos) {
m_FFBufferTime[nDestPos].nBuffPos = m_FFBufferTime[i].nBuffPos - nPos;
m_FFBufferTime[nDestPos].rtStart = m_FFBufferTime[i].rtStart;
m_FFBufferTime[nDestPos].rtStop = m_FFBufferTime[i].rtStop;
@@ -1743,8 +1730,7 @@ void CMPCVideoDecFilter::PopBufferTime(int nPos)
}
// Free unused slots
- for (i=nDestPos; i<MAX_BUFF_TIME; i++)
- {
+ for (i=nDestPos; i<MAX_BUFF_TIME; i++) {
m_FFBufferTime[i].nBuffPos = INT_MIN;
m_FFBufferTime[i].rtStart = _I64_MIN;
m_FFBufferTime[i].rtStop = _I64_MIN;
@@ -1753,11 +1739,11 @@ void CMPCVideoDecFilter::PopBufferTime(int nPos)
bool CMPCVideoDecFilter::AppendBuffer (BYTE* pDataIn, int nSize, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop)
{
- if (rtStart != _I64_MIN)
+ if (rtStart != _I64_MIN) {
PushBufferTime (m_nFFBufferPos, rtStart, rtStop);
+ }
- if (m_nFFBufferPos+nSize+FF_INPUT_BUFFER_PADDING_SIZE > m_nFFBufferSize)
- {
+ if (m_nFFBufferPos+nSize+FF_INPUT_BUFFER_PADDING_SIZE > m_nFFBufferSize) {
m_nFFBufferSize = m_nFFBufferPos+nSize+FF_INPUT_BUFFER_PADDING_SIZE;
m_pFFBuffer = (BYTE*)realloc(m_pFFBuffer, m_nFFBufferSize);
}
@@ -1792,8 +1778,9 @@ HRESULT CMPCVideoDecFilter::Transform(IMediaSample* pIn)
REFERENCE_TIME rtStart = _I64_MIN;
REFERENCE_TIME rtStop = _I64_MIN;
- if(FAILED(hr = pIn->GetPointer(&pDataIn)))
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
return hr;
+ }
nSize = pIn->GetActualDataLength();
pIn->GetTime(&rtStart, &rtStop);
@@ -1818,23 +1805,23 @@ HRESULT CMPCVideoDecFilter::Transform(IMediaSample* pIn)
// m_nCountEstimated++;
// rtStart = rtStop = m_rtLastStart + m_nCountEstimated*m_rtAvrTimePerFrame;
//}
- if (rtStop <= rtStart && rtStop != _I64_MIN)
+ if (rtStop <= rtStart && rtStop != _I64_MIN) {
rtStop = rtStart + m_rtAvrTimePerFrame;
+ }
m_pAVCtx->reordered_opaque = rtStart;
m_pAVCtx->reordered_opaque2 = rtStop;
- if (m_pAVCtx->has_b_frames)
- {
+ if (m_pAVCtx->has_b_frames) {
m_BFrames[m_nPosB].rtStart = rtStart;
m_BFrames[m_nPosB].rtStop = rtStop;
m_nPosB = 1-m_nPosB;
}
-// m_rtStart = rtStart;
+ // m_rtStart = rtStart;
-// DumpBuffer (pDataIn, nSize);
-// TRACE ("Receive : %10I64d - %10I64d (%10I64d) Size=%d\n", rtStart, rtStop, rtStop - rtStart, nSize);
+ // DumpBuffer (pDataIn, nSize);
+ // TRACE ("Receive : %10I64d - %10I64d (%10I64d) Size=%d\n", rtStart, rtStop, rtStop - rtStart, nSize);
//char strMsg[300];
//FILE* hFile = fopen ("d:\\receive.txt", "at");
@@ -1847,49 +1834,42 @@ HRESULT CMPCVideoDecFilter::Transform(IMediaSample* pIn)
//fwrite (pDataIn, nSize, 1, hFile);
//fclose (hFile);
- switch (m_nDXVAMode)
- {
- case MODE_SOFTWARE :
- hr = SoftwareDecode (pIn, pDataIn, nSize, rtStart, rtStop);
- break;
- case MODE_DXVA1 :
- case MODE_DXVA2 :
- CheckPointer (m_pDXVADecoder, E_UNEXPECTED);
- UpdateAspectRatio();
+ switch (m_nDXVAMode) {
+ case MODE_SOFTWARE :
+ hr = SoftwareDecode (pIn, pDataIn, nSize, rtStart, rtStop);
+ break;
+ case MODE_DXVA1 :
+ case MODE_DXVA2 :
+ CheckPointer (m_pDXVADecoder, E_UNEXPECTED);
+ UpdateAspectRatio();
+
+ // Change aspect ratio for DXVA1
+ if ((m_nDXVAMode == MODE_DXVA1) &&
+ ReconnectOutput(PictWidthRounded(), PictHeightRounded(), true, PictWidth(), PictHeight()) == S_OK) {
+ m_pDXVADecoder->ConfigureDXVA1();
+ }
- // Change aspect ratio for DXVA1
- if ((m_nDXVAMode == MODE_DXVA1) &&
- ReconnectOutput(PictWidthRounded(), PictHeightRounded(), true, PictWidth(), PictHeight()) == S_OK)
- {
- m_pDXVADecoder->ConfigureDXVA1();
- }
+ if (m_pAVCtx->codec_id == CODEC_ID_MPEG2VIDEO) {
+ AppendBuffer (pDataIn, nSize, rtStart, rtStop);
+ hr = S_OK;
- if (m_pAVCtx->codec_id == CODEC_ID_MPEG2VIDEO)
- {
- AppendBuffer (pDataIn, nSize, rtStart, rtStop);
- hr = S_OK;
-
- while (FindPicture (max (m_nFFBufferPos-nSize-4, 0), 0x00))
- {
- if (m_FFBufferTime[0].nBuffPos != INT_MIN && m_FFBufferTime[0].nBuffPos < m_nFFPicEnd)
- {
- rtStart = m_FFBufferTime[0].rtStart;
- rtStop = m_FFBufferTime[0].rtStop;
+ while (FindPicture (max (m_nFFBufferPos-nSize-4, 0), 0x00)) {
+ if (m_FFBufferTime[0].nBuffPos != INT_MIN && m_FFBufferTime[0].nBuffPos < m_nFFPicEnd) {
+ rtStart = m_FFBufferTime[0].rtStart;
+ rtStop = m_FFBufferTime[0].rtStop;
+ } else {
+ rtStart = rtStop = _I64_MIN;
+ }
+ hr = m_pDXVADecoder->DecodeFrame (m_pFFBuffer, m_nFFPicEnd, rtStart, rtStop);
+ ShrinkBuffer();
}
- else
- rtStart = rtStop = _I64_MIN;
- hr = m_pDXVADecoder->DecodeFrame (m_pFFBuffer, m_nFFPicEnd, rtStart, rtStop);
- ShrinkBuffer();
+ } else {
+ hr = m_pDXVADecoder->DecodeFrame (pDataIn, nSize, rtStart, rtStop);
}
- }
- else
- {
- hr = m_pDXVADecoder->DecodeFrame (pDataIn, nSize, rtStart, rtStop);
- }
- break;
- default :
- ASSERT (FALSE);
- hr = E_UNEXPECTED;
+ break;
+ default :
+ ASSERT (FALSE);
+ hr = E_UNEXPECTED;
}
return hr;
@@ -1898,15 +1878,15 @@ HRESULT CMPCVideoDecFilter::Transform(IMediaSample* pIn)
void CMPCVideoDecFilter::UpdateAspectRatio()
{
- if(((m_nARMode) && (m_pAVCtx)) && ((m_pAVCtx->sample_aspect_ratio.num>0) && (m_pAVCtx->sample_aspect_ratio.den>0)))
- {
+ if(((m_nARMode) && (m_pAVCtx)) && ((m_pAVCtx->sample_aspect_ratio.num>0) && (m_pAVCtx->sample_aspect_ratio.den>0))) {
CSize SAR(m_pAVCtx->sample_aspect_ratio.num, m_pAVCtx->sample_aspect_ratio.den);
- if(m_sar != SAR)
- {
+ if(m_sar != SAR) {
m_sar = SAR;
CSize aspect(m_nWidth * SAR.cx, m_nHeight * SAR.cy);
int lnko = LNKO(aspect.cx, aspect.cy);
- if(lnko > 1) aspect.cx /= lnko, aspect.cy /= lnko;
+ if(lnko > 1) {
+ aspect.cx /= lnko, aspect.cy /= lnko;
+ }
SetAspect(aspect);
}
}
@@ -1915,8 +1895,7 @@ void CMPCVideoDecFilter::UpdateAspectRatio()
void CMPCVideoDecFilter::ReorderBFrames(REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop)
{
// Re-order B-frames if needed
- if (m_pAVCtx->has_b_frames && m_bReorderBFrame)
- {
+ if (m_pAVCtx->has_b_frames && m_bReorderBFrame) {
rtStart = m_BFrames [m_nPosB].rtStart;
rtStop = m_BFrames [m_nPosB].rtStop;
}
@@ -1933,14 +1912,13 @@ void CMPCVideoDecFilter::FillInVideoDescription(DXVA2_VideoDesc *pDesc)
BOOL CMPCVideoDecFilter::IsSupportedDecoderMode(const GUID& mode)
{
- if (IsDXVASupported())
- {
- for (int i=0; i<MAX_SUPPORTED_MODE; i++)
- {
- if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == GUID_NULL)
+ if (IsDXVASupported()) {
+ for (int i=0; i<MAX_SUPPORTED_MODE; i++) {
+ if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == GUID_NULL) {
break;
- else if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == mode)
+ } else if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == mode) {
return true;
+ }
}
}
@@ -1959,9 +1937,9 @@ BOOL CMPCVideoDecFilter::IsSupportedDecoderConfig(const D3DFORMAT nD3DFormat, co
}
HRESULT CMPCVideoDecFilter::FindDXVA2DecoderConfiguration(IDirectXVideoDecoderService *pDecoderService,
- const GUID& guidDecoder,
- DXVA2_ConfigPictureDecode *pSelectedConfig,
- BOOL *pbFoundDXVA2Configuration)
+ const GUID& guidDecoder,
+ DXVA2_ConfigPictureDecode *pSelectedConfig,
+ BOOL *pbFoundDXVA2Configuration)
{
HRESULT hr = S_OK;
UINT cFormats = 0;
@@ -1975,11 +1953,9 @@ HRESULT CMPCVideoDecFilter::FindDXVA2DecoderConfiguration(IDirectXVideoDecoderSe
hr = pDecoderService->GetDecoderRenderTargets(guidDecoder, &cFormats, &pFormats);
LOG (_T("GetDecoderRenderTargets => %d"), cFormats);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Look for a format that matches our output format.
- for (UINT iFormat = 0; iFormat < cFormats; iFormat++)
- {
+ for (UINT iFormat = 0; iFormat < cFormats; iFormat++) {
LOG (_T("Try to negociate => 0x%08x"), pFormats[iFormat]);
// Fill in the video description. Set the width, height, format, and frame rate.
@@ -1989,24 +1965,22 @@ HRESULT CMPCVideoDecFilter::FindDXVA2DecoderConfiguration(IDirectXVideoDecoderSe
// Get the available configurations.
hr = pDecoderService->GetDecoderConfigurations(guidDecoder, &m_VideoDesc, NULL, &cConfigurations, &pConfig);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
continue;
}
// Find a supported configuration.
- for (UINT iConfig = 0; iConfig < cConfigurations; iConfig++)
- {
- if (IsSupportedDecoderConfig(pFormats[iFormat], pConfig[iConfig], bIsPrefered))
- {
+ for (UINT iConfig = 0; iConfig < cConfigurations; iConfig++) {
+ if (IsSupportedDecoderConfig(pFormats[iFormat], pConfig[iConfig], bIsPrefered)) {
// This configuration is good.
- if (bIsPrefered || !*pbFoundDXVA2Configuration)
- {
+ if (bIsPrefered || !*pbFoundDXVA2Configuration) {
*pbFoundDXVA2Configuration = TRUE;
*pSelectedConfig = pConfig[iConfig];
}
- if (bIsPrefered) break;
+ if (bIsPrefered) {
+ break;
+ }
}
}
@@ -2041,70 +2015,61 @@ HRESULT CMPCVideoDecFilter::ConfigureDXVA2(IPin *pPin)
hr = pPin->QueryInterface(__uuidof(IMFGetService), (void**)&pGetService);
// Get the Direct3D device manager.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = pGetService->GetService(
- MR_VIDEO_ACCELERATION_SERVICE,
- __uuidof(IDirect3DDeviceManager9),
- (void**)&pDeviceManager);
+ MR_VIDEO_ACCELERATION_SERVICE,
+ __uuidof(IDirect3DDeviceManager9),
+ (void**)&pDeviceManager);
}
// Open a new device handle.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = pDeviceManager->OpenDeviceHandle(&hDevice);
}
// Get the video decoder service.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = pDeviceManager->GetVideoService(
- hDevice,
- __uuidof(IDirectXVideoDecoderService),
- (void**)&pDecoderService);
+ hDevice,
+ __uuidof(IDirectXVideoDecoderService),
+ (void**)&pDecoderService);
}
// Get the decoder GUIDs.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = pDecoderService->GetDecoderDeviceGuids(&cDecoderGuids, &pDecoderGuids);
}
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Look for the decoder GUIDs we want.
- for (UINT iGuid = 0; iGuid < cDecoderGuids; iGuid++)
- {
+ for (UINT iGuid = 0; iGuid < cDecoderGuids; iGuid++) {
// Do we support this mode?
- if (!IsSupportedDecoderMode(pDecoderGuids[iGuid]))
- {
+ if (!IsSupportedDecoderMode(pDecoderGuids[iGuid])) {
continue;
}
// Find a configuration that we support.
hr = FindDXVA2DecoderConfiguration(pDecoderService, pDecoderGuids[iGuid], &config, &bFoundDXVA2Configuration);
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
break;
}
- if (bFoundDXVA2Configuration)
- {
+ if (bFoundDXVA2Configuration) {
// Found a good configuration. Save the GUID.
guidDecoder = pDecoderGuids[iGuid];
}
}
}
- if (pDecoderGuids) CoTaskMemFree(pDecoderGuids);
- if (!bFoundDXVA2Configuration)
- {
+ if (pDecoderGuids) {
+ CoTaskMemFree(pDecoderGuids);
+ }
+ if (!bFoundDXVA2Configuration) {
hr = E_FAIL; // Unable to find a configuration.
}
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Store the things we will need later.
m_pDeviceManager = pDeviceManager;
m_pDecoderService = pDecoderService;
@@ -2114,10 +2079,8 @@ HRESULT CMPCVideoDecFilter::ConfigureDXVA2(IPin *pPin)
m_hDevice = hDevice;
}
- if (FAILED(hr))
- {
- if (hDevice != INVALID_HANDLE_VALUE)
- {
+ if (FAILED(hr)) {
+ if (hDevice != INVALID_HANDLE_VALUE) {
pDeviceManager->CloseDeviceHandle(hDevice);
}
}
@@ -2138,37 +2101,32 @@ HRESULT CMPCVideoDecFilter::SetEVRForDXVA2(IPin *pPin)
hr = pPin->QueryInterface(__uuidof(IMFGetService), (void**)&pGetService);
// Get the IDirectXVideoMemoryConfiguration interface.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = pGetService->GetService(
- MR_VIDEO_ACCELERATION_SERVICE,
- __uuidof(IDirectXVideoMemoryConfiguration),
- (void**)&pVideoConfig);
+ MR_VIDEO_ACCELERATION_SERVICE,
+ __uuidof(IDirectXVideoMemoryConfiguration),
+ (void**)&pVideoConfig);
- if (SUCCEEDED (pGetService->GetService(MR_VIDEO_RENDER_SERVICE, __uuidof(IMFVideoDisplayControl), (void**)&pVdc)))
- {
+ if (SUCCEEDED (pGetService->GetService(MR_VIDEO_RENDER_SERVICE, __uuidof(IMFVideoDisplayControl), (void**)&pVdc))) {
HWND hWnd;
- if (SUCCEEDED (pVdc->GetVideoWindow(&hWnd)))
- {
+ if (SUCCEEDED (pVdc->GetVideoWindow(&hWnd))) {
DetectVideoCard(hWnd);
}
}
}
// Notify the EVR.
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
DXVA2_SurfaceType surfaceType;
- for (DWORD iTypeIndex = 0; ; iTypeIndex++)
- {
+ for (DWORD iTypeIndex = 0; ; iTypeIndex++) {
hr = pVideoConfig->GetAvailableSurfaceTypeByIndex(iTypeIndex, &surfaceType);
- if (FAILED(hr))
+ if (FAILED(hr)) {
break;
+ }
- if (surfaceType == DXVA2_SurfaceType_DecoderRenderTarget)
- {
+ if (surfaceType == DXVA2_SurfaceType_DecoderRenderTarget) {
hr = pVideoConfig->SetSurfaceType(DXVA2_SurfaceType_DecoderRenderTarget);
break;
}
@@ -2186,17 +2144,19 @@ HRESULT CMPCVideoDecFilter::CreateDXVA2Decoder(UINT nNumRenderTargets, IDirect3D
m_pDecoderRenderTarget = NULL;
- if (m_pDXVADecoder) m_pDXVADecoder->SetDirectXVideoDec (NULL);
+ if (m_pDXVADecoder) {
+ m_pDXVADecoder->SetDirectXVideoDec (NULL);
+ }
hr = m_pDecoderService->CreateVideoDecoder (m_DXVADecoderGUID, &m_VideoDesc, &m_DXVA2Config,
- pDecoderRenderTargets, nNumRenderTargets, &pDirectXVideoDec);
+ pDecoderRenderTargets, nNumRenderTargets, &pDirectXVideoDec);
- if (SUCCEEDED (hr))
- {
- if (!m_pDXVADecoder)
- {
+ if (SUCCEEDED (hr)) {
+ if (!m_pDXVADecoder) {
m_pDXVADecoder = CDXVADecoder::CreateDecoder (this, pDirectXVideoDec, &m_DXVADecoderGUID, GetPicEntryNumber(), &m_DXVA2Config);
- if (m_pDXVADecoder) m_pDXVADecoder->SetExtraData ((BYTE*)m_pAVCtx->extradata, m_pAVCtx->extradata_size);
+ if (m_pDXVADecoder) {
+ m_pDXVADecoder->SetExtraData ((BYTE*)m_pAVCtx->extradata, m_pAVCtx->extradata_size);
+ }
}
m_pDXVADecoder->SetDirectXVideoDec (pDirectXVideoDec);
@@ -2214,18 +2174,14 @@ HRESULT CMPCVideoDecFilter::FindDXVA1DecoderConfiguration(IAMVideoAccelerator* p
pAMVideoAccelerator->GetUncompFormatsSupported (guidDecoder, &dwFormats, NULL);
- if (dwFormats > 0)
- {
+ if (dwFormats > 0) {
// Find the valid render target formats for this decoder GUID.
pPixelFormats = DNew DDPIXELFORMAT[dwFormats];
hr = pAMVideoAccelerator->GetUncompFormatsSupported (guidDecoder, &dwFormats, pPixelFormats);
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Look for a format that matches our output format.
- for (DWORD iFormat = 0; iFormat < dwFormats; iFormat++)
- {
- if (pPixelFormats[iFormat].dwFourCC == MAKEFOURCC ('N', 'V', '1', '2'))
- {
+ for (DWORD iFormat = 0; iFormat < dwFormats; iFormat++) {
+ if (pPixelFormats[iFormat].dwFourCC == MAKEFOURCC ('N', 'V', '1', '2')) {
memcpy (pPixelFormat, &pPixelFormats[iFormat], sizeof(DDPIXELFORMAT));
SAFE_DELETE_ARRAY(pPixelFormats)
return S_OK;
@@ -2242,11 +2198,11 @@ HRESULT CMPCVideoDecFilter::FindDXVA1DecoderConfiguration(IAMVideoAccelerator* p
HRESULT CMPCVideoDecFilter::CheckDXVA1Decoder(const GUID *pGuid)
{
- if (m_nCodecNb != -1)
- {
+ if (m_nCodecNb != -1) {
for (int i=0; i<MAX_SUPPORTED_MODE; i++)
- if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == *pGuid)
+ if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == *pGuid) {
return S_OK;
+ }
}
return E_INVALIDARG;
@@ -2260,11 +2216,11 @@ void CMPCVideoDecFilter::SetDXVA1Params(const GUID* pGuid, DDPIXELFORMAT* pPixel
WORD CMPCVideoDecFilter::GetDXVA1RestrictedMode()
{
- if (m_nCodecNb != -1)
- {
+ if (m_nCodecNb != -1) {
for (int i=0; i<MAX_SUPPORTED_MODE; i++)
- if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == m_DXVADecoderGUID)
+ if (*ffCodecs[m_nCodecNb].DXVAModes->Decoder[i] == m_DXVADecoderGUID) {
return ffCodecs[m_nCodecNb].DXVAModes->RestrictedMode [i];
+ }
}
return DXVA_RESTRICTED_MODE_UNRESTRICTED;
@@ -2272,16 +2228,21 @@ WORD CMPCVideoDecFilter::GetDXVA1RestrictedMode()
HRESULT CMPCVideoDecFilter::CreateDXVA1Decoder(IAMVideoAccelerator* pAMVideoAccelerator, const GUID* pDecoderGuid, DWORD dwSurfaceCount)
{
- if (m_pDXVADecoder && m_DXVADecoderGUID == *pDecoderGuid)
+ if (m_pDXVADecoder && m_DXVADecoderGUID == *pDecoderGuid) {
return S_OK;
+ }
SAFE_DELETE (m_pDXVADecoder);
- if (!m_bUseDXVA) return E_FAIL;
+ if (!m_bUseDXVA) {
+ return E_FAIL;
+ }
m_nDXVAMode = MODE_DXVA1;
m_DXVADecoderGUID = *pDecoderGuid;
m_pDXVADecoder = CDXVADecoder::CreateDecoder (this, pAMVideoAccelerator, &m_DXVADecoderGUID, dwSurfaceCount);
- if (m_pDXVADecoder) m_pDXVADecoder->SetExtraData ((BYTE*)m_pAVCtx->extradata, m_pAVCtx->extradata_size);
+ if (m_pDXVADecoder) {
+ m_pDXVADecoder->SetExtraData ((BYTE*)m_pAVCtx->extradata, m_pAVCtx->extradata_size);
+ }
return S_OK;
}
@@ -2302,7 +2263,9 @@ STDMETHODIMP CMPCVideoDecFilter::GetPages(CAUUID* pPages)
pPages->pElems = (GUID*)CoTaskMemAlloc(sizeof(GUID) * pPages->cElems);
pPages->pElems[0] = __uuidof(CMPCVideoDecSettingsWnd);
- if (pPages->cElems>1) pPages->pElems[1] = __uuidof(CMPCVideoDecCodecWnd);
+ if (pPages->cElems>1) {
+ pPages->pElems[1] = __uuidof(CMPCVideoDecCodecWnd);
+ }
return S_OK;
}
@@ -2311,16 +2274,15 @@ STDMETHODIMP CMPCVideoDecFilter::CreatePage(const GUID& guid, IPropertyPage** pp
{
CheckPointer(ppPage, E_POINTER);
- if(*ppPage != NULL) return E_INVALIDARG;
+ if(*ppPage != NULL) {
+ return E_INVALIDARG;
+ }
HRESULT hr;
- if(guid == __uuidof(CMPCVideoDecSettingsWnd))
- {
+ if(guid == __uuidof(CMPCVideoDecSettingsWnd)) {
(*ppPage = DNew CInternalPropertyPageTempl<CMPCVideoDecSettingsWnd>(NULL, &hr))->AddRef();
- }
- else if(guid == __uuidof(CMPCVideoDecCodecWnd))
- {
+ } else if(guid == __uuidof(CMPCVideoDecCodecWnd)) {
(*ppPage = DNew CInternalPropertyPageTempl<CMPCVideoDecCodecWnd>(NULL, &hr))->AddRef();
}
@@ -2332,8 +2294,7 @@ STDMETHODIMP CMPCVideoDecFilter::CreatePage(const GUID& guid, IPropertyPage** pp
STDMETHODIMP CMPCVideoDecFilter::Apply()
{
CRegKey key;
- if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Video Decoder")))
- {
+ if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPC Video Decoder"))) {
key.SetDWORDValue(_T("ThreadNumber"), m_nThreadNumber);
key.SetDWORDValue(_T("DiscardMode"), m_nDiscardMode);
key.SetDWORDValue(_T("ErrorRecognition"), m_nErrorRecognition);
@@ -2392,10 +2353,11 @@ STDMETHODIMP_(int) CMPCVideoDecFilter::GetIDCTAlgo()
}
STDMETHODIMP_(GUID*) CMPCVideoDecFilter::GetDXVADecoderGuid()
{
- if (m_pGraph == NULL)
+ if (m_pGraph == NULL) {
return NULL;
- else
+ } else {
return &m_DXVADecoderGUID;
+ }
}
STDMETHODIMP CMPCVideoDecFilter::SetActiveCodecs(MPC_VIDEO_CODEC nValue)
{
diff --git a/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.h b/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.h
index 7800a0e16..846a8cab2 100644
--- a/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.h
+++ b/src/filters/transform/MPCVideoDec/MPCVideoDecFilter.h
@@ -44,22 +44,19 @@ class CCpuId;
#define MAX_BUFF_TIME 20
-typedef enum
-{
+typedef enum {
MODE_SOFTWARE,
MODE_DXVA1,
MODE_DXVA2
} DXVA_MODE;
-typedef struct
-{
+typedef struct {
REFERENCE_TIME rtStart;
REFERENCE_TIME rtStop;
} B_FRAME;
-typedef struct
-{
+typedef struct {
REFERENCE_TIME rtStart;
REFERENCE_TIME rtStop;
int nBuffPos;
@@ -162,8 +159,8 @@ protected:
void SetTypeSpecificFlags(IMediaSample* pMS);
HRESULT SoftwareDecode(IMediaSample* pIn, BYTE* pDataIn, int nSize, REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
-//void FindStartCodeVC1 (BYTE** pDataIn, int& nSize);
-//void FindStartCodeH264 (BYTE** pDataIn, int& nSize);
+ //void FindStartCodeVC1 (BYTE** pDataIn, int& nSize);
+ //void FindStartCodeH264 (BYTE** pDataIn, int& nSize);
bool AppendBuffer (BYTE* pDataIn, int nSize, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop);
bool FindPicture(int nIndex, int nStartCode);
void ShrinkBuffer();
@@ -190,7 +187,9 @@ public:
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
virtual bool IsVideoInterlaced();
virtual void GetOutputSize(int& w, int& h, int& arx, int& ary, int &RealWidth, int &RealHeight);
- CTransformOutputPin* GetOutputPin() {return m_pOutput;}
+ CTransformOutputPin* GetOutputPin() {
+ return m_pOutput;
+ }
void UpdateFrameTime (REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
// === Overriden DirectShow functions
@@ -241,19 +240,37 @@ public:
int PictHeight();
int PictWidthRounded();
int PictHeightRounded();
- inline bool UseDXVA2() {return (m_nDXVAMode == MODE_DXVA2);};
- void FlushDXVADecoder() {if (m_pDXVADecoder) m_pDXVADecoder->Flush();}
- inline AVCodecContext* GetAVCtx() {return m_pAVCtx;};
- inline AVFrame* GetFrame() {return m_pFrame;}
+ inline bool UseDXVA2() {
+ return (m_nDXVAMode == MODE_DXVA2);
+ };
+ void FlushDXVADecoder() {
+ if (m_pDXVADecoder) {
+ m_pDXVADecoder->Flush();
+ }
+ }
+ inline AVCodecContext* GetAVCtx() {
+ return m_pAVCtx;
+ };
+ inline AVFrame* GetFrame() {
+ return m_pFrame;
+ }
bool IsDXVASupported();
- inline bool IsReorderBFrame() { return m_bReorderBFrame;};
- inline int GetPCIVendor() {return m_nPCIVendor;};
- inline REFERENCE_TIME GetAvrTimePerFrame() {return m_rtAvrTimePerFrame;};
+ inline bool IsReorderBFrame() {
+ return m_bReorderBFrame;
+ };
+ inline int GetPCIVendor() {
+ return m_nPCIVendor;
+ };
+ inline REFERENCE_TIME GetAvrTimePerFrame() {
+ return m_rtAvrTimePerFrame;
+ };
void UpdateAspectRatio();
void ReorderBFrames(REFERENCE_TIME& rtStart, REFERENCE_TIME& rtStop);
// === DXVA1 functions
- DDPIXELFORMAT* GetPixelFormat() {return &m_PixelFormat;}
+ DDPIXELFORMAT* GetPixelFormat() {
+ return &m_PixelFormat;
+ }
HRESULT FindDXVA1DecoderConfiguration(IAMVideoAccelerator* pAMVideoAccelerator, const GUID* guidDecoder, DDPIXELFORMAT* pPixelFormat);
HRESULT CheckDXVA1Decoder(const GUID *pGuid);
void SetDXVA1Params(const GUID* pGuid, DDPIXELFORMAT* pPixelFormat);
@@ -263,12 +280,14 @@ public:
// === DXVA2 functions
void FillInVideoDescription(DXVA2_VideoDesc *pDesc);
- DXVA2_ConfigPictureDecode* GetDXVA2Config() {return &m_DXVA2Config;};
+ DXVA2_ConfigPictureDecode* GetDXVA2Config() {
+ return &m_DXVA2Config;
+ };
HRESULT ConfigureDXVA2(IPin *pPin);
HRESULT SetEVRForDXVA2(IPin *pPin);
HRESULT FindDXVA2DecoderConfiguration(IDirectXVideoDecoderService *pDecoderService,
- const GUID& guidDecoder,
- DXVA2_ConfigPictureDecode *pSelectedConfig,
- BOOL *pbFoundDXVA2Configuration);
+ const GUID& guidDecoder,
+ DXVA2_ConfigPictureDecode *pSelectedConfig,
+ BOOL *pbFoundDXVA2Configuration);
HRESULT CreateDXVA2Decoder(UINT nNumRenderTargets, IDirect3DSurface9** pDecoderRenderTargets);
};
diff --git a/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.cpp b/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.cpp
index 81b74bbf7..11f7d613a 100644
--- a/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.cpp
+++ b/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.cpp
@@ -37,20 +37,21 @@
// CMPCVideoDecSettingsWnd
//
-int g_AVDiscard[] =
-{
+int g_AVDiscard[] = {
-16, ///< AVDISCARD_NONE discard nothing
- 0, ///< AVDISCARD_DEFAULT discard useless packets like 0 size packets in avi
- 8, ///< AVDISCARD_NONREF discard all non reference
- 16, ///< AVDISCARD_BIDIR discard all bidirectional frames
- 32, ///< AVDISCARD_NONKEY discard all frames except keyframes
- 48, ///< AVDISCARD_ALL discard all
+ 0, ///< AVDISCARD_DEFAULT discard useless packets like 0 size packets in avi
+ 8, ///< AVDISCARD_NONREF discard all non reference
+ 16, ///< AVDISCARD_BIDIR discard all bidirectional frames
+ 32, ///< AVDISCARD_NONKEY discard all frames except keyframes
+ 48, ///< AVDISCARD_ALL discard all
};
int FindDiscardIndex(int nValue)
{
for (int i=0; i<countof (g_AVDiscard); i++)
- if (g_AVDiscard[i] == nValue) return i;
+ if (g_AVDiscard[i] == nValue) {
+ return i;
+ }
return 1;
}
@@ -66,9 +67,13 @@ bool CMPCVideoDecSettingsWnd::OnConnect(const CInterfaceList<IUnknown, &IID_IUnk
m_pMDF.Release();
POSITION pos = pUnks.GetHeadPosition();
- while(pos && !(m_pMDF = pUnks.GetNext(pos)));
+ while(pos && !(m_pMDF = pUnks.GetNext(pos))) {
+ ;
+ }
- if(!m_pMDF) return false;
+ if(!m_pMDF) {
+ return false;
+ }
return true;
}
@@ -86,7 +91,7 @@ bool CMPCVideoDecSettingsWnd::OnActivate()
#if HAS_FFMPEG_VIDEO_DECODERS
m_grpFFMpeg.Create (ResStr (IDS_VDF_FFSETTINGS), WS_VISIBLE|WS_CHILD | BS_GROUPBOX, CRect (10, nPosY, 350, nPosY+150), this, (UINT)IDC_STATIC);
- #if INTERNAL_DECODER_H264
+#if INTERNAL_DECODER_H264
// Decoding threads
nPosY += VERTICAL_SPACING;
@@ -101,9 +106,9 @@ bool CMPCVideoDecSettingsWnd::OnActivate()
m_cbThreadNumber.AddString (_T("7"));
m_cbThreadNumber.AddString (_T("8"));
- #endif /* INTERNAL_DECODER_H264 */
+#endif /* INTERNAL_DECODER_H264 */
- #if INTERNAL_DECODER_H264
+#if INTERNAL_DECODER_H264
// H264 deblocking mode
nPosY += VERTICAL_SPACING;
@@ -116,7 +121,7 @@ bool CMPCVideoDecSettingsWnd::OnActivate()
m_cbDiscardMode.AddString (ResStr (IDS_VDF_DBLK_NONKFRM));
m_cbDiscardMode.AddString (ResStr (IDS_VDF_DBLK_ALL));
- #endif /* INTERNAL_DECODER_H264 */
+#endif /* INTERNAL_DECODER_H264 */
// Error recognition
nPosY += VERTICAL_SPACING;
@@ -172,27 +177,24 @@ bool CMPCVideoDecSettingsWnd::OnActivate()
DxvaGui = m_pMDF->GetDXVADecoderGuid();
- if (DxvaGui != NULL)
- {
+ if (DxvaGui != NULL) {
CString DXVAMode = GetDXVAMode (DxvaGui);
m_edtDXVAMode.SetWindowText (DXVAMode);
- }
- else
- {
+ } else {
m_txtDXVAMode.ShowWindow (SW_HIDE);
m_edtDXVAMode.ShowWindow (SW_HIDE);
}
- for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow())
+ for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
pWnd->SetFont(&m_font, FALSE);
+ }
- if (m_pMDF)
- {
+ if (m_pMDF) {
#if HAS_FFMPEG_VIDEO_DECODERS
- #if INTERNAL_DECODER_H264
+#if INTERNAL_DECODER_H264
m_cbThreadNumber.SetCurSel (m_pMDF->GetThreadNumber() - 1);
m_cbDiscardMode.SetCurSel (FindDiscardIndex (m_pMDF->GetDiscardMode()));
- #endif
+#endif
m_cbErrorRecognition.SetCurSel (m_pMDF->GetErrorRecognition()-1);
m_cbIDCTAlgo.SetCurSel (m_pMDF->GetIDCTAlgo());
@@ -214,13 +216,12 @@ bool CMPCVideoDecSettingsWnd::OnApply()
{
OnDeactivate();
- if(m_pMDF && m_cbDXVACompatibilityCheck.m_hWnd)
- {
+ if(m_pMDF && m_cbDXVACompatibilityCheck.m_hWnd) {
#if HAS_FFMPEG_VIDEO_DECODERS
- #if INTERNAL_DECODER_H264
+#if INTERNAL_DECODER_H264
m_pMDF->SetThreadNumber (m_cbThreadNumber.GetCurSel() + 1);
m_pMDF->SetDiscardMode (g_AVDiscard[m_cbDiscardMode.GetCurSel()]);
- #endif /* INTERNAL_DECODER_H264 */
+#endif /* INTERNAL_DECODER_H264 */
m_pMDF->SetErrorRecognition (m_cbErrorRecognition.GetCurSel()+1);
m_pMDF->SetIDCTAlgo (m_cbIDCTAlgo.GetCurSel());
@@ -257,9 +258,13 @@ bool CMPCVideoDecCodecWnd::OnConnect(const CInterfaceList<IUnknown, &IID_IUnknow
m_pMDF.Release();
POSITION pos = pUnks.GetHeadPosition();
- while(pos && !(m_pMDF = pUnks.GetNext(pos)));
+ while(pos && !(m_pMDF = pUnks.GetNext(pos))) {
+ ;
+ }
- if(!m_pMDF) return false;
+ if(!m_pMDF) {
+ return false;
+ }
return true;
}
@@ -320,8 +325,9 @@ bool CMPCVideoDecCodecWnd::OnActivate()
m_lstCodecs.SetCheck (nPos++, (nActiveCodecs & MPCVD_THEORA) != 0);
#endif
- for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow())
+ for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
pWnd->SetFont(&m_font, FALSE);
+ }
return true;
}
@@ -334,35 +340,64 @@ bool CMPCVideoDecCodecWnd::OnApply()
{
OnDeactivate();
- if(m_pMDF)
- {
+ if(m_pMDF) {
int nActiveCodecs = 0;
int nPos = 0;
#if INTERNAL_DECODER_H264_DXVA
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_H264_DXVA;
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_H264_DXVA;
+ }
#endif
#if INTERNAL_DECODER_H264
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_H264;
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_H264;
+ }
#endif
#if INTERNAL_DECODER_VC1_DXVA
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_VC1_DXVA;
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_VC1_DXVA;
+ }
#endif
#if INTERNAL_DECODER_VC1
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_VC1;
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_VC1;
+ }
#endif
#if HAS_FFMPEG_VIDEO_DECODERS
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_XVID;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_DIVX;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_MSMPEG4;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_FLASH;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_VP6;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_VP8;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_WMV;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_H263;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_SVQ3;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_AMVV;
- if (m_lstCodecs.GetCheck (nPos++)) nActiveCodecs |= MPCVD_THEORA;
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_XVID;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_DIVX;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_MSMPEG4;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_FLASH;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_VP6;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_VP8;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_WMV;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_H263;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_SVQ3;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_AMVV;
+ }
+ if (m_lstCodecs.GetCheck (nPos++)) {
+ nActiveCodecs |= MPCVD_THEORA;
+ }
#endif
m_pMDF->SetActiveCodecs ((MPC_VIDEO_CODEC)nActiveCodecs);
diff --git a/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.h b/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.h
index 289b206b9..a6b372002 100644
--- a/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.h
+++ b/src/filters/transform/MPCVideoDec/MPCVideoDecSettingsWnd.h
@@ -54,8 +54,7 @@ class __declspec(uuid("D5AA0389-D274-48e1-BF50-ACB05A56DDE0"))
CButton m_cbDXVA_SD;
- enum
- {
+ enum {
IDC_PP_THREAD_NUMBER = 10000,
IDC_PP_ENABLE_DEBLOCKING,
IDC_PP_DISCARD_MODE,
diff --git a/src/filters/transform/MPCVideoDec/TlibavcodecExt.cpp b/src/filters/transform/MPCVideoDec/TlibavcodecExt.cpp
index af7c78397..2ea37a49b 100644
--- a/src/filters/transform/MPCVideoDec/TlibavcodecExt.cpp
+++ b/src/filters/transform/MPCVideoDec/TlibavcodecExt.cpp
@@ -40,15 +40,17 @@ void TlibavcodecExt::ConnectTo(AVCodecContext *pAVCtx)
int TlibavcodecExt::get_buffer(AVCodecContext *c, AVFrame *pic)
{
int ret=c->opaque->ff_avcodec_default_get_buffer(c,pic);
- if (ret==0)
+ if (ret==0) {
c->opaque->OnGetBuffer(pic);
+ }
return ret;
}
int TlibavcodecExt::reget_buffer(AVCodecContext *c, AVFrame *pic)
{
int ret=c->opaque->ff_avcodec_default_reget_buffer(c,pic);
- if (ret==0)
+ if (ret==0) {
c->opaque->OnRegetBuffer(pic);
+ }
return ret;
}
void TlibavcodecExt::release_buffer(AVCodecContext *c, AVFrame *pic)
diff --git a/src/filters/transform/MPCVideoDec/TlibavcodecExt.h b/src/filters/transform/MPCVideoDec/TlibavcodecExt.h
index 7e7d5c051..37b7ccf8e 100644
--- a/src/filters/transform/MPCVideoDec/TlibavcodecExt.h
+++ b/src/filters/transform/MPCVideoDec/TlibavcodecExt.h
@@ -36,8 +36,7 @@ typedef void (*FUNC_AV_DEFAULT_RELEASE_BUFFER)(AVCodecContext *s, AVFrame *pic
typedef int (*FUNC_AV_DEFAULT_REGET_BUFFER)(AVCodecContext *s, AVFrame *pic);
-struct TlibavcodecExt
-{
+struct TlibavcodecExt {
protected:
static int get_buffer(AVCodecContext *s, AVFrame *pic);
static void release_buffer(AVCodecContext *s, AVFrame *pic);
diff --git a/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.cpp b/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.cpp
index 4cfcc495a..1d8579612 100644
--- a/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.cpp
+++ b/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.cpp
@@ -40,16 +40,12 @@ STDMETHODIMP CDXVA2Sample::QueryInterface(REFIID riid, __deref_out void **ppv)
CheckPointer(ppv,E_POINTER);
ValidateReadWritePtr(ppv,sizeof(PVOID));
- if (riid == __uuidof(IMFGetService))
- {
+ if (riid == __uuidof(IMFGetService)) {
return GetInterface((IMFGetService*) this, ppv);
}
- if (riid == __uuidof(IMPCDXVA2Sample))
- {
+ if (riid == __uuidof(IMPCDXVA2Sample)) {
return GetInterface((IMPCDXVA2Sample*) this, ppv);
- }
- else
- {
+ } else {
return CMediaSample::QueryInterface(riid, ppv);
}
}
@@ -70,16 +66,11 @@ STDMETHODIMP_(ULONG) CDXVA2Sample::Release()
// IMFGetService::GetService
STDMETHODIMP CDXVA2Sample::GetService(REFGUID guidService, REFIID riid, LPVOID *ppv)
{
- if (guidService != MR_BUFFER_SERVICE)
- {
+ if (guidService != MR_BUFFER_SERVICE) {
return MF_E_UNSUPPORTED_SERVICE;
- }
- else if (m_pSurface == NULL)
- {
+ } else if (m_pSurface == NULL) {
return E_NOINTERFACE;
- }
- else
- {
+ } else {
return m_pSurface->QueryInterface(riid, ppv);
}
}
@@ -131,8 +122,7 @@ HRESULT CVideoDecDXVAAllocator::Alloc()
hr = __super::Alloc();
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Free the old resources.
Free();
@@ -140,20 +130,16 @@ HRESULT CVideoDecDXVAAllocator::Alloc()
// Allocate a new array of pointers.
m_ppRTSurfaceArray = DNew IDirect3DSurface9*[m_lCount];
- if (m_ppRTSurfaceArray == NULL)
- {
+ if (m_ppRTSurfaceArray == NULL) {
hr = E_OUTOFMEMORY;
- }
- else
- {
+ } else {
ZeroMemory(m_ppRTSurfaceArray, sizeof(IDirect3DSurface9*) * m_lCount);
}
}
// Allocate the surfaces.
D3DFORMAT m_dwFormat = m_pVideoDecFilter->m_VideoDesc.Format;
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
hr = pDXVA2Service->CreateSurface(
m_pVideoDecFilter->PictWidthRounded(),
m_pVideoDecFilter->PictHeightRounded(),
@@ -167,19 +153,15 @@ HRESULT CVideoDecDXVAAllocator::Alloc()
);
}
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
// Important : create samples in reverse order !
- for (m_lAllocated = m_lCount-1; m_lAllocated >= 0; m_lAllocated--)
- {
+ for (m_lAllocated = m_lCount-1; m_lAllocated >= 0; m_lAllocated--) {
CDXVA2Sample *pSample = DNew CDXVA2Sample(this, &hr);
- if (pSample == NULL)
- {
+ if (pSample == NULL) {
hr = E_OUTOFMEMORY;
break;
}
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
break;
}
// Assign the Direct3D surface pointer and the index.
@@ -190,11 +172,12 @@ HRESULT CVideoDecDXVAAllocator::Alloc()
}
hr = m_pVideoDecFilter->CreateDXVA2Decoder (m_lCount, m_ppRTSurfaceArray);
- if (FAILED (hr)) Free();
+ if (FAILED (hr)) {
+ Free();
+ }
}
- if (SUCCEEDED(hr))
- {
+ if (SUCCEEDED(hr)) {
m_bChanged = FALSE;
}
return hr;
@@ -205,22 +188,19 @@ void CVideoDecDXVAAllocator::Free()
CMediaSample *pSample = NULL;
m_pVideoDecFilter->FlushDXVADecoder();
-// m_FreeSurface.RemoveAll();
- do
- {
+ // m_FreeSurface.RemoveAll();
+ do {
pSample = m_lFree.RemoveHead();
- if (pSample)
- {
+ if (pSample) {
delete pSample;
}
} while (pSample);
- if (m_ppRTSurfaceArray)
- {
- for (long i = 0; i < m_nSurfaceArrayCount; i++)
- {
- if (m_ppRTSurfaceArray[i] != NULL)
+ if (m_ppRTSurfaceArray) {
+ for (long i = 0; i < m_nSurfaceArrayCount; i++) {
+ if (m_ppRTSurfaceArray[i] != NULL) {
m_ppRTSurfaceArray[i]->Release();
+ }
}
delete [] m_ppRTSurfaceArray;
diff --git a/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.h b/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.h
index 0f20d4383..7b3206112 100644
--- a/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.h
+++ b/src/filters/transform/MPCVideoDec/VideoDecDXVAAllocator.h
@@ -33,8 +33,7 @@ class CVideoDecDXVAAllocator;
interface __declspec(uuid("AE7EC2A2-1913-4a80-8DD6-DF1497ABA494"))
IMPCDXVA2Sample :
-public IUnknown
-{
+public IUnknown {
STDMETHOD_(int, GetDXSurfaceId()) = 0;
};
@@ -80,13 +79,13 @@ public:
CVideoDecDXVAAllocator(CMPCVideoDecFilter* pVideoDecFilter, HRESULT* phr);
virtual ~CVideoDecDXVAAllocator();
-// STDMETHODIMP GetBuffer(__deref_out IMediaSample **ppBuffer, // Try for a circular buffer!
-// __in_opt REFERENCE_TIME * pStartTime,
-// __in_opt REFERENCE_TIME * pEndTime,
-// DWORD dwFlags);
-//
-// STDMETHODIMP ReleaseBuffer(IMediaSample *pBuffer);
-// CAtlList<int> m_FreeSurface;
+ // STDMETHODIMP GetBuffer(__deref_out IMediaSample **ppBuffer, // Try for a circular buffer!
+ // __in_opt REFERENCE_TIME * pStartTime,
+ // __in_opt REFERENCE_TIME * pEndTime,
+ // DWORD dwFlags);
+ //
+ // STDMETHODIMP ReleaseBuffer(IMediaSample *pBuffer);
+ // CAtlList<int> m_FreeSurface;
protected:
diff --git a/src/filters/transform/MPCVideoDec/VideoDecOutputPin.cpp b/src/filters/transform/MPCVideoDec/VideoDecOutputPin.cpp
index 06dbbbd4e..4fcc513dd 100644
--- a/src/filters/transform/MPCVideoDec/VideoDecOutputPin.cpp
+++ b/src/filters/transform/MPCVideoDec/VideoDecOutputPin.cpp
@@ -44,24 +44,21 @@ CVideoDecOutputPin::~CVideoDecOutputPin(void)
HRESULT CVideoDecOutputPin::InitAllocator(IMemAllocator **ppAlloc)
{
TRACE("CVideoDecOutputPin::InitAllocator");
- if (m_pVideoDecFilter->UseDXVA2())
- {
+ if (m_pVideoDecFilter->UseDXVA2()) {
HRESULT hr = S_FALSE;
m_pDXVA2Allocator = DNew CVideoDecDXVAAllocator(m_pVideoDecFilter, &hr);
- if (!m_pDXVA2Allocator)
- {
+ if (!m_pDXVA2Allocator) {
return E_OUTOFMEMORY;
}
- if (FAILED(hr))
- {
+ if (FAILED(hr)) {
delete m_pDXVA2Allocator;
return hr;
}
// Return the IMemAllocator interface.
return m_pDXVA2Allocator->QueryInterface(__uuidof(IMemAllocator), (void **)ppAlloc);
- }
- else
+ } else {
return __super::InitAllocator(ppAlloc);
+ }
}
STDMETHODIMP CVideoDecOutputPin::NonDelegatingQueryInterface(REFIID riid, void** ppv)
@@ -77,18 +74,15 @@ STDMETHODIMP CVideoDecOutputPin::GetUncompSurfacesInfo(const GUID *pGuid, LPAMVA
{
HRESULT hr = E_INVALIDARG;
- if (SUCCEEDED (m_pVideoDecFilter->CheckDXVA1Decoder (pGuid)))
- {
+ if (SUCCEEDED (m_pVideoDecFilter->CheckDXVA1Decoder (pGuid))) {
CComQIPtr<IAMVideoAccelerator> pAMVideoAccelerator = GetConnected();
- if (pAMVideoAccelerator)
- {
+ if (pAMVideoAccelerator) {
pUncompBufferInfo->dwMaxNumSurfaces = m_pVideoDecFilter->GetPicEntryNumber();
pUncompBufferInfo->dwMinNumSurfaces = m_pVideoDecFilter->GetPicEntryNumber();
hr = m_pVideoDecFilter->FindDXVA1DecoderConfiguration (pAMVideoAccelerator, pGuid, &pUncompBufferInfo->ddUncompPixelFormat);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
memcpy (&m_ddUncompPixelFormat, &pUncompBufferInfo->ddUncompPixelFormat, sizeof(DDPIXELFORMAT));
m_GuidDecoderDXVA1 = *pGuid;
}
@@ -112,19 +106,16 @@ STDMETHODIMP CVideoDecOutputPin::GetCreateVideoAcceleratorData(const GUID *pGuid
CComQIPtr<IAMVideoAccelerator> pAMVideoAccelerator = GetConnected();
DXVA_ConnectMode* pConnectMode;
- if (pAMVideoAccelerator)
- {
+ if (pAMVideoAccelerator) {
memcpy (&UncompInfo.ddUncompPixelFormat, &m_ddUncompPixelFormat, sizeof (DDPIXELFORMAT));
UncompInfo.dwUncompWidth = m_pVideoDecFilter->PictWidthRounded();
UncompInfo.dwUncompHeight = m_pVideoDecFilter->PictHeightRounded();
hr = pAMVideoAccelerator->GetCompBufferInfo(&m_GuidDecoderDXVA1, &UncompInfo, &dwNumTypesCompBuffers, CompInfo);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
hr = m_pVideoDecFilter->CreateDXVA1Decoder (pAMVideoAccelerator, pGuid, m_dwDXVA1SurfaceCount);
- if (SUCCEEDED (hr))
- {
+ if (SUCCEEDED (hr)) {
m_pVideoDecFilter->SetDXVA1Params (&m_GuidDecoderDXVA1, &m_ddUncompPixelFormat);
pConnectMode = (DXVA_ConnectMode*)CoTaskMemAlloc (sizeof(DXVA_ConnectMode));
diff --git a/src/filters/transform/MPCVideoDec/stdafx.cpp b/src/filters/transform/MPCVideoDec/stdafx.cpp
index 1734bc03d..5008ff8b5 100644
--- a/src/filters/transform/MPCVideoDec/stdafx.cpp
+++ b/src/filters/transform/MPCVideoDec/stdafx.cpp
@@ -31,11 +31,9 @@ void LOG(LPCTSTR fmt, ...)
{
va_list args;
va_start(args, fmt);
- if(TCHAR* buff = new TCHAR[_vsctprintf(fmt, args) + 1])
- {
+ if(TCHAR* buff = new TCHAR[_vsctprintf(fmt, args) + 1]) {
_vstprintf(buff, fmt, args);
- if(FILE* f = _tfopen(LOG_FILE, _T("at")))
- {
+ if(FILE* f = _tfopen(LOG_FILE, _T("at"))) {
fseek(f, 0, 2);
_ftprintf(f, _T("%s\n"), buff);
fclose(f);
diff --git a/src/filters/transform/MpaDecFilter/IMpaDecFilter.h b/src/filters/transform/MpaDecFilter/IMpaDecFilter.h
index 718755179..6c933d6bd 100644
--- a/src/filters/transform/MpaDecFilter/IMpaDecFilter.h
+++ b/src/filters/transform/MpaDecFilter/IMpaDecFilter.h
@@ -26,8 +26,7 @@
enum MPCSampleFormat {SF_PCM16, SF_PCM24, SF_PCM32, SF_FLOAT32};
enum {AAC_ASIS, AAC_STEREO};
-enum DolbyDigitalMode
-{
+enum DolbyDigitalMode {
DD_Unknown,
DD_AC3, // Standard AC3
DD_EAC3, // Dolby Digital +
@@ -38,8 +37,7 @@ enum DolbyDigitalMode
interface __declspec(uuid("2067C60F-752F-4EBD-B0B1-4CBC5E00741C"))
IMpaDecFilter :
-public IUnknown
-{
+public IUnknown {
enum enctype {ac3, dts, aac, etlast};
STDMETHOD(SetSampleFormat(MPCSampleFormat sf)) = 0;
diff --git a/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp b/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp
index e5c0e565f..eaf64c305 100644
--- a/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp
+++ b/src/filters/transform/MpaDecFilter/MpaDecFilter.cpp
@@ -43,8 +43,7 @@
#define EAC3_FRAME_TYPE_RESERVED 3
#define AC3_HEADER_SIZE 7
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_MP3},
{&MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1AudioPayload},
{&MEDIATYPE_Audio, &MEDIASUBTYPE_MPEG1Payload},
@@ -119,24 +118,20 @@ const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_PCM},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMpaDecFilter), L"MPC - MPA Decoder Filter", /*MERIT_DO_NOT_USE*/0x40000001, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, &__uuidof(CMpaDecFilter), CreateInstance<CMpaDecFilter>, NULL, &sudFilter[0]},
{L"CMpaDecPropertyPage", &__uuidof(CMpaDecSettingsWnd), CreateInstance<CInternalPropertyPageTempl<CMpaDecSettingsWnd> >},
};
@@ -168,14 +163,12 @@ CFilterApp theApp;
// lets see how we can map these things to dshow (oh the joy!)
#pragma warning(disable : 4245)
-static struct scmap_t
-{
+static struct scmap_t {
WORD nChannels;
BYTE ch[8];
DWORD dwChannelMask;
}
-s_scmap_ac3[2*11] =
-{
+s_scmap_ac3[2*11] = {
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // A52_CHANNEL
{1, {0,-1,-1,-1,-1,-1,-1,-1}, 0}, // A52_MONO
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // A52_STEREO
@@ -200,8 +193,7 @@ s_scmap_ac3[2*11] =
{2, {1, 0,-1,-1,-1,-1,-1,-1}, SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY}, // A52_CHANNEL2|A52_LFE
{3, {1, 2, 0,-1,-1,-1,-1,-1}, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_LOW_FREQUENCY}, // A52_DOLBY|A52_LFE
},
-s_scmap_dts[2*10] =
-{
+s_scmap_dts[2*10] = {
{1, {0,-1,-1,-1,-1,-1,-1,-1}, 0}, // DTS_MONO
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // DTS_CHANNEL
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // DTS_STEREO
@@ -224,8 +216,7 @@ s_scmap_dts[2*10] =
{5, {0, 1, 4, 2, 3,-1,-1,-1}, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT}, // DTS_2F2R|DTS_LFE
{6, {1, 2, 0, 5, 3, 4,-1,-1}, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT}, // DTS_3F2R|DTS_LFE
},
-s_scmap_vorbis[6] =
-{
+s_scmap_vorbis[6] = {
{1, {0,-1,-1,-1,-1,-1,-1,-1}, 0}, // 1F
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // 2F
{3, {0, 2, 1,-1,-1,-1,-1,-1}, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER}, // 2F1R
@@ -233,9 +224,8 @@ s_scmap_vorbis[6] =
{5, {0, 2, 1, 3, 4,-1,-1,-1}, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT}, // 3F2R
{6, {0, 2, 1, 5, 3, 4,-1,-1}, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT}, // 3F2R + LFE
},
-s_scmap_hdmv[] =
-{
-// FL FR FC LFe BL BR FLC FRC
+s_scmap_hdmv[] = {
+ // FL FR FC LFe BL BR FLC FRC
{0, {-1,-1,-1,-1,-1,-1,-1,-1 }, 0}, // INVALID
{1, { 0,-1,-1,-1,-1,-1,-1,-1 }, 0}, // Mono M1, 0
{0, {-1,-1,-1,-1,-1,-1,-1,-1 }, 0}, // INVALID
@@ -249,9 +239,8 @@ s_scmap_hdmv[] =
{8, { 0, 1, 2, 3, 6, 4, 5,-1 }, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT}, // 3/4 FL, FR, FC, BL, Bls, Brs, BR
{8, { 0, 1, 2, 7, 4, 5, 3, 6 }, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT},// 3/4+LFe FL, FR, FC, BL, Bls, Brs, BR, LFe
},
-m_scmap_default[] =
-{
-// FL FR FC LFe BL BR FLC FRC
+m_scmap_default[] = {
+ // FL FR FC LFe BL BR FLC FRC
{1, { 0,-1,-1,-1,-1,-1,-1,-1 }, 0}, // Mono M1, 0
{2, { 0, 1,-1,-1,-1,-1,-1,-1 }, 0}, // Stereo FL, FR
{3, { 0, 1, 2,-1,-1,-1,-1,-1 }, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER}, // 3/0 FL, FR, FC
@@ -261,9 +250,8 @@ m_scmap_default[] =
{7, { 0, 1, 2, 3, 4, 5, 6,-1 }, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT|SPEAKER_BACK_CENTER}, // 3/4 FL, FR, FC, BL, Bls, Brs, BR
{8, { 0, 1, 2, 3, 6, 7, 4, 5 }, SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT},// 3/4+LFe FL, FR, FC, BL, Bls, Brs, BR, LFe
},
-m_ffmpeg_ac3[] =
-{
-// FL FR FC LFe BL BR FLC FRC
+m_ffmpeg_ac3[] = {
+ // FL FR FC LFe BL BR FLC FRC
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // AC3_CHMODE_DUALMONO
{1, {0,-1,-1,-1,-1,-1,-1,-1}, 0}, // AC3_CHMODE_MONO
{2, {0, 1,-1,-1,-1,-1,-1,-1}, 0}, // AC3_CHMODE_STEREO
@@ -284,14 +272,22 @@ CMpaDecFilter::CMpaDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
, m_fNormalize(false)
, m_boost(1)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pInput = DNew CMpaDecInputPin(this, phr, L"In");
- if(!m_pInput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!m_pInput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
m_pOutput = DNew CTransformOutputPin(NAME("CTransformOutputPin"), this, phr, L"Out");
- if(!m_pOutput) *phr = E_OUTOFMEMORY;
+ if(!m_pOutput) {
+ *phr = E_OUTOFMEMORY;
+ }
if(FAILED(*phr)) {
delete m_pInput, m_pInput = NULL;
return;
@@ -320,25 +316,44 @@ CMpaDecFilter::CMpaDecFilter(LPUNKNOWN lpunk, HRESULT* phr)
#endif
CRegKey key;
- if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Audio Decoder"), KEY_READ))
- {
+ if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Audio Decoder"), KEY_READ)) {
DWORD dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("SampleFormat"), dw)) m_iSampleFormat = (MPCSampleFormat)dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Normalize"), dw)) m_fNormalize = !!dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Boost"), dw)) m_boost = *(float*)&dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Ac3SpeakerConfig"), dw)) m_iSpeakerConfig[ac3] = (int)dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DtsSpeakerConfig"), dw)) m_iSpeakerConfig[dts] = (int)dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("AacSpeakerConfig"), dw)) m_iSpeakerConfig[aac] = (int)dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Ac3DynamicRangeControl"), dw)) m_fDynamicRangeControl[ac3] = !!dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DtsDynamicRangeControl"), dw)) m_fDynamicRangeControl[dts] = !!dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("AacDynamicRangeControl"), dw)) m_fDynamicRangeControl[aac] = !!dw;
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("SampleFormat"), dw)) {
+ m_iSampleFormat = (MPCSampleFormat)dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Normalize"), dw)) {
+ m_fNormalize = !!dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Boost"), dw)) {
+ m_boost = *(float*)&dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Ac3SpeakerConfig"), dw)) {
+ m_iSpeakerConfig[ac3] = (int)dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DtsSpeakerConfig"), dw)) {
+ m_iSpeakerConfig[dts] = (int)dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("AacSpeakerConfig"), dw)) {
+ m_iSpeakerConfig[aac] = (int)dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Ac3DynamicRangeControl"), dw)) {
+ m_fDynamicRangeControl[ac3] = !!dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DtsDynamicRangeControl"), dw)) {
+ m_fDynamicRangeControl[dts] = !!dw;
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("AacDynamicRangeControl"), dw)) {
+ m_fDynamicRangeControl[aac] = !!dw;
+ }
}
}
CMpaDecFilter::~CMpaDecFilter()
{
#if defined(REGISTER_FILTER) | HAS_FFMPEG_AUDIO_DECODERS
- if (m_pFFBuffer) free(m_pFFBuffer);
+ if (m_pFFBuffer) {
+ free(m_pFFBuffer);
+ }
m_nFFBufferSize = 0;
#endif
@@ -395,12 +410,14 @@ HRESULT CMpaDecFilter::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, d
m_ps2_state.sync = false;
m_DolbyDigitalMode = DD_Unknown;
#if defined(REGISTER_FILTER) | HAS_FFMPEG_AUDIO_DECODERS
- if (m_pAVCtx)
+ if (m_pAVCtx) {
avcodec_flush_buffers (m_pAVCtx);
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
- if (m_flac.pDecoder)
+ if (m_flac.pDecoder) {
FLAC__stream_decoder_flush((FLAC__StreamDecoder*) m_flac.pDecoder);
+ }
#endif
return __super::NewSegment(tStart, tStop, dRate);
}
@@ -412,12 +429,12 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
HRESULT hr;
AM_SAMPLE2_PROPERTIES* const pProps = m_pInput->SampleProps();
- if(pProps->dwStreamId != AM_STREAM_MEDIA)
+ if(pProps->dwStreamId != AM_STREAM_MEDIA) {
return m_pOutput->Deliver(pIn);
+ }
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
m_pInput->SetMediaType(&mt);
DeleteMediaType(pmt);
@@ -433,7 +450,9 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
}
BYTE* pDataIn = NULL;
- if(FAILED(hr = pIn->GetPointer(&pDataIn))) return hr;
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
+ return hr;
+ }
long len = pIn->GetActualDataLength();
@@ -442,8 +461,7 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
REFERENCE_TIME rtStart = _I64_MIN, rtStop = _I64_MIN;
hr = pIn->GetTime(&rtStart, &rtStop);
- if(pIn->IsDiscontinuity() == S_OK)
- {
+ if(pIn->IsDiscontinuity() == S_OK) {
m_fDiscontinuity = true;
m_buff.RemoveAll();
m_sample_max = 0.1f;
@@ -458,13 +476,11 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
const GUID& subtype = m_pInput->CurrentMediaType().subtype;
BOOL bNoJitterControl = false;
- if(subtype == MEDIASUBTYPE_AMR || subtype == MEDIASUBTYPE_SAMR || subtype == MEDIASUBTYPE_SAWB)
- {
+ if(subtype == MEDIASUBTYPE_AMR || subtype == MEDIASUBTYPE_SAMR || subtype == MEDIASUBTYPE_SAWB) {
bNoJitterControl = true;
}
- if(SUCCEEDED(hr) && _abs64((m_rtStart - rtStart)) > 1000000i64 && !bNoJitterControl) // +-100ms jitter is allowed for now
- {
+ if(SUCCEEDED(hr) && _abs64((m_rtStart - rtStart)) > 1000000i64 && !bNoJitterControl) { // +-100ms jitter is allowed for now
m_buff.RemoveAll();
m_rtStart = rtStart;
}
@@ -475,51 +491,60 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
len += bufflen;
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AMR
- if(subtype == MEDIASUBTYPE_AMR || subtype == MEDIASUBTYPE_SAMR)
+ if(subtype == MEDIASUBTYPE_AMR || subtype == MEDIASUBTYPE_SAMR) {
hr = ProcessFFmpeg(CODEC_ID_AMR_NB);
- else if(subtype == MEDIASUBTYPE_SAWB)
+ } else if(subtype == MEDIASUBTYPE_SAWB) {
hr = ProcessFFmpeg(CODEC_ID_AMR_WB);
+ }
#else
if(0) {}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_LPCM
- else if(subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO)
+ else if(subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
hr = ProcessLPCM();
- else if(subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO)
+ } else if(subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO) {
hr = ProcessHdmvLPCM(pIn->IsSyncPoint());
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AC3
else if(subtype == MEDIASUBTYPE_DOLBY_AC3 ||
subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3 ||
subtype == MEDIASUBTYPE_DOLBY_DDPLUS ||
- subtype == MEDIASUBTYPE_DOLBY_TRUEHD)
+ subtype == MEDIASUBTYPE_DOLBY_TRUEHD) {
hr = ProcessAC3();
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_DTS
- else if(subtype == MEDIASUBTYPE_DTS || subtype == MEDIASUBTYPE_WAVE_DTS)
+ else if(subtype == MEDIASUBTYPE_DTS || subtype == MEDIASUBTYPE_WAVE_DTS) {
hr = ProcessDTS();
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AAC
- else if(subtype == MEDIASUBTYPE_AAC || subtype == MEDIASUBTYPE_MP4A || subtype == MEDIASUBTYPE_mp4a)
+ else if(subtype == MEDIASUBTYPE_AAC || subtype == MEDIASUBTYPE_MP4A || subtype == MEDIASUBTYPE_mp4a) {
hr = ProcessAAC();
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_PS2AUDIO
- else if(subtype == MEDIASUBTYPE_PS2_PCM)
+ else if(subtype == MEDIASUBTYPE_PS2_PCM) {
hr = ProcessPS2PCM();
- else if(subtype == MEDIASUBTYPE_PS2_ADPCM)
+ } else if(subtype == MEDIASUBTYPE_PS2_ADPCM) {
hr = ProcessPS2ADPCM();
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
- else if(subtype == MEDIASUBTYPE_Vorbis2)
+ else if(subtype == MEDIASUBTYPE_Vorbis2) {
hr = ProcessVorbis();
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
- else if(subtype == MEDIASUBTYPE_FLAC_FRAMED)
+ else if(subtype == MEDIASUBTYPE_FLAC_FRAMED) {
hr = ProcessFlac();
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_NELLYMOSER
- else if(subtype == MEDIASUBTYPE_NELLYMOSER)
+ else if(subtype == MEDIASUBTYPE_NELLYMOSER) {
hr = ProcessFFmpeg(CODEC_ID_NELLYMOSER);
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_PCM
else if(subtype == MEDIASUBTYPE_PCM_NONE ||
@@ -528,42 +553,36 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
return S_OK;
}
hr = ProcessPCMraw();
- }
- else if(subtype == MEDIASUBTYPE_PCM_TWOS) {
+ } else if(subtype == MEDIASUBTYPE_PCM_TWOS) {
if(m_buff.GetCount() < 960) {
return S_OK;
}
hr = ProcessPCMintBE();
- }
- else if(subtype == MEDIASUBTYPE_PCM_SOWT) {
+ } else if(subtype == MEDIASUBTYPE_PCM_SOWT) {
if(m_buff.GetCount() < 960) {
return S_OK;
}
hr = ProcessPCMintLE();
- }
- else if(subtype == MEDIASUBTYPE_PCM_IN24 ||
- subtype == MEDIASUBTYPE_PCM_IN32) {
+ } else if(subtype == MEDIASUBTYPE_PCM_IN24 ||
+ subtype == MEDIASUBTYPE_PCM_IN32) {
if(m_buff.GetCount() < 1920) {
return S_OK;
}
hr = ProcessPCMintBE();
- }
- else if(subtype == MEDIASUBTYPE_PCM_IN24_le ||
- subtype == MEDIASUBTYPE_PCM_IN32_le) {
+ } else if(subtype == MEDIASUBTYPE_PCM_IN24_le ||
+ subtype == MEDIASUBTYPE_PCM_IN32_le) {
if(m_buff.GetCount() < 1920) {
return S_OK;
}
hr = ProcessPCMintLE();
- }
- else if(subtype == MEDIASUBTYPE_PCM_FL32 ||
- subtype == MEDIASUBTYPE_PCM_FL64) {
+ } else if(subtype == MEDIASUBTYPE_PCM_FL32 ||
+ subtype == MEDIASUBTYPE_PCM_FL64) {
if(m_buff.GetCount() < 3840) {
return S_OK;
}
hr = ProcessPCMfloatBE();
- }
- else if(subtype == MEDIASUBTYPE_PCM_FL32_le ||
- subtype == MEDIASUBTYPE_PCM_FL64_le) {
+ } else if(subtype == MEDIASUBTYPE_PCM_FL32_le ||
+ subtype == MEDIASUBTYPE_PCM_FL64_le) {
if(m_buff.GetCount() < 3840) {
return S_OK;
}
@@ -571,12 +590,14 @@ HRESULT CMpaDecFilter::Receive(IMediaSample* pIn)
}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_IMA4
- else if(subtype == MEDIASUBTYPE_IMA4)
+ else if(subtype == MEDIASUBTYPE_IMA4) {
hr = ProcessFFmpeg(CODEC_ID_ADPCM_IMA_QT);
+ }
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_MPEGAUDIO
- else // if(.. the rest ..)
+ else { // if(.. the rest ..)
hr = ProcessMPA();
+ }
#endif
return hr;
@@ -587,8 +608,9 @@ HRESULT CMpaDecFilter::ProcessLPCM()
{
WAVEFORMATEX* wfein = (WAVEFORMATEX*)m_pInput->CurrentMediaType().Format();
- if (wfein->nChannels < 1 || wfein->nChannels > 8)
+ if (wfein->nChannels < 1 || wfein->nChannels > 8) {
return ERROR_NOT_SUPPORTED;
+ }
scmap_t* remap = &m_scmap_default [wfein->nChannels-1];
int nChannels = wfein->nChannels;
@@ -604,144 +626,122 @@ HRESULT CMpaDecFilter::ProcessLPCM()
float* pDataOut = pBuff.GetData();
- switch (wfein->wBitsPerSample)
- {
- case 16 :
- {
- long nSamples = len/(BytesPerDoubleChannelSample);
- int16 Temp[2][8];
- for (int i=0; i<nSamples; i++)
- {
- for(int j = 0; j < nChannels; j++)
- {
- uint16 All = *((uint16 *)pDataIn);
- pDataIn += 2;
- int16 Part1 = (All & 0xFF) << 8 | (All & 0xFF00) >> 8;
- Temp[0][j] = Part1;
- }
- for(int j = 0; j < nChannels; j++)
- {
- uint16 All = *((uint16 *)pDataIn);
- pDataIn += 2;
- int16 Part1 = (All & 0xFF) << 8 | (All & 0xFF00) >> 8;
- Temp[1][j] = Part1;
- }
+ switch (wfein->wBitsPerSample) {
+ case 16 : {
+ long nSamples = len/(BytesPerDoubleChannelSample);
+ int16 Temp[2][8];
+ for (int i=0; i<nSamples; i++) {
+ for(int j = 0; j < nChannels; j++) {
+ uint16 All = *((uint16 *)pDataIn);
+ pDataIn += 2;
+ int16 Part1 = (All & 0xFF) << 8 | (All & 0xFF00) >> 8;
+ Temp[0][j] = Part1;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ uint16 All = *((uint16 *)pDataIn);
+ pDataIn += 2;
+ int16 Part1 = (All & 0xFF) << 8 | (All & 0xFF00) >> 8;
+ Temp[1][j] = Part1;
+ }
- for(int j = 0; j < nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = float(Temp[0][nRemap]) / float(SHRT_MAX);
- ++pDataOut;
- }
- for(int j = 0; j < nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = float(Temp[1][nRemap]) / float(SHRT_MAX);
- ++pDataOut;
+ for(int j = 0; j < nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = float(Temp[0][nRemap]) / float(SHRT_MAX);
+ ++pDataOut;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = float(Temp[1][nRemap]) / float(SHRT_MAX);
+ ++pDataOut;
+ }
}
}
- }
- break;
+ break;
- case 24 :
- {
- long nSamples = len/(BytesPerDoubleChannelSample);
- int32 Temp[2][8];
- for (int i=0; i<nSamples; i++)
- {
- // Start by upper 16 bits
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint16 *)pDataIn);
- pDataIn += 2;
- uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
- Temp[0][j] = Part1;
- }
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint16 *)pDataIn);
- pDataIn += 2;
- uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
- Temp[1][j] = Part1;
- }
+ case 24 : {
+ long nSamples = len/(BytesPerDoubleChannelSample);
+ int32 Temp[2][8];
+ for (int i=0; i<nSamples; i++) {
+ // Start by upper 16 bits
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint16 *)pDataIn);
+ pDataIn += 2;
+ uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
+ Temp[0][j] = Part1;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint16 *)pDataIn);
+ pDataIn += 2;
+ uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
+ Temp[1][j] = Part1;
+ }
- // Continue with lower bits
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint8 *)pDataIn);
- pDataIn += 1;
- Temp[0][j] = int32(Temp[0][j] | (All << 8)) >> 8;
- }
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint8 *)pDataIn);
- pDataIn += 1;
- Temp[1][j] = int32(Temp[1][j] | (All << 8)) >> 8;
- }
+ // Continue with lower bits
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint8 *)pDataIn);
+ pDataIn += 1;
+ Temp[0][j] = int32(Temp[0][j] | (All << 8)) >> 8;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint8 *)pDataIn);
+ pDataIn += 1;
+ Temp[1][j] = int32(Temp[1][j] | (All << 8)) >> 8;
+ }
- // Convert into float
- for(int j = 0; j < nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = float(Temp[0][nRemap]) / float(1<<23);
- ++pDataOut;
- }
- for(int j = 0; j < nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = float(Temp[1][nRemap]) / float(1<<23);
- ++pDataOut;
+ // Convert into float
+ for(int j = 0; j < nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = float(Temp[0][nRemap]) / float(1<<23);
+ ++pDataOut;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = float(Temp[1][nRemap]) / float(1<<23);
+ ++pDataOut;
+ }
}
}
- }
- break;
- case 20 :
- {
- long nSamples = len/(BytesPerDoubleChannelSample);
- int32 Temp[2][8];
- for (int i=0; i<nSamples; i++)
- {
- // Start by upper 16 bits
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint16 *)pDataIn);
- pDataIn += 2;
- uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
- Temp[0][j] = Part1;
- }
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint16 *)pDataIn);
- pDataIn += 2;
- uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
- Temp[1][j] = Part1;
- }
+ break;
+ case 20 : {
+ long nSamples = len/(BytesPerDoubleChannelSample);
+ int32 Temp[2][8];
+ for (int i=0; i<nSamples; i++) {
+ // Start by upper 16 bits
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint16 *)pDataIn);
+ pDataIn += 2;
+ uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
+ Temp[0][j] = Part1;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint16 *)pDataIn);
+ pDataIn += 2;
+ uint32 Part1 = (All & 0xFF) << 24 | (All & 0xFF00) << 8;
+ Temp[1][j] = Part1;
+ }
- // Continue with lower bits
- for(int j = 0; j < nChannels; j++)
- {
- uint32 All = *((uint8 *)pDataIn);
- pDataIn += 1;
- Temp[0][j] = int32(Temp[0][j] | ((All&0xf0) << 8)) >> 8;
- Temp[1][j] = int32(Temp[1][j] | ((All&0x0f) << 12)) >> 8;
- }
+ // Continue with lower bits
+ for(int j = 0; j < nChannels; j++) {
+ uint32 All = *((uint8 *)pDataIn);
+ pDataIn += 1;
+ Temp[0][j] = int32(Temp[0][j] | ((All&0xf0) << 8)) >> 8;
+ Temp[1][j] = int32(Temp[1][j] | ((All&0x0f) << 12)) >> 8;
+ }
- // Convert into float
- for(int j = 0; j < nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = float(Temp[0][nRemap]) / float(1<<23);
- ++pDataOut;
- }
- for(int j = 0; j < nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = float(Temp[1][nRemap]) / float(1<<23);
- ++pDataOut;
+ // Convert into float
+ for(int j = 0; j < nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = float(Temp[0][nRemap]) / float(1<<23);
+ ++pDataOut;
+ }
+ for(int j = 0; j < nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = float(Temp[1][nRemap]) / float(1<<23);
+ ++pDataOut;
+ }
}
}
- }
- break;
+ break;
}
memmove(m_buff.GetData(), pDataIn, m_buff.GetCount() - len );
@@ -760,8 +760,7 @@ HRESULT CMpaDecFilter::ProcessHdmvLPCM(bool bAlignOldBuffer) // Blu ray LPCM
int BytesPerSample = wfein->nChannels*BytesPerChannelSample; // Beliyaal: Old calculation only worked if nChannel*bytespersample is power of 2
int oldlen = m_buff.GetCount();
int len = (oldlen / BytesPerSample) * BytesPerSample;
- if (bAlignOldBuffer)
- {
+ if (bAlignOldBuffer) {
m_buff.SetCount(len);
}
scmap_t* remap = &s_scmap_hdmv [wfein->channel_conf];
@@ -771,39 +770,34 @@ HRESULT CMpaDecFilter::ProcessHdmvLPCM(bool bAlignOldBuffer) // Blu ray LPCM
float* pDataOut = pBuff.GetData();
- switch (wfein->wBitsPerSample)
- {
- case 16 :
- for (int i=0; i<len/wfein->nChannels/2; i++)
- {
- for(int j = 0; j < wfein->nChannels; j++)
- {
- int nRemap = remap->ch[j];
- *pDataOut = (float)(short)((pDataIn[nRemap*2]<<8)|pDataIn[nRemap*2+1]) / SHRT_MAX;
- pDataOut++;
+ switch (wfein->wBitsPerSample) {
+ case 16 :
+ for (int i=0; i<len/wfein->nChannels/2; i++) {
+ for(int j = 0; j < wfein->nChannels; j++) {
+ int nRemap = remap->ch[j];
+ *pDataOut = (float)(short)((pDataIn[nRemap*2]<<8)|pDataIn[nRemap*2+1]) / SHRT_MAX;
+ pDataOut++;
+ }
+ pDataIn += wfein->nChannels*2;
}
- pDataIn += wfein->nChannels*2;
- }
- break;
+ break;
- case 24 :
- case 20 :
- long lSample;
+ case 24 :
+ case 20 :
+ long lSample;
- for (int i=0; i<len/wfein->nChannels/3; i++)
- {
- for(int j = 0; j < wfein->nChannels; j++)
- {
- BYTE nRemap = remap->ch[j];
+ for (int i=0; i<len/wfein->nChannels/3; i++) {
+ for(int j = 0; j < wfein->nChannels; j++) {
+ BYTE nRemap = remap->ch[j];
- lSample = (long)pDataIn[nRemap*3]<<24 | (long)pDataIn[nRemap*3+1]<<16 | (long)pDataIn[nRemap*3+2]<<8;
- *pDataOut = (float)(long)lSample / 0x80000000;
+ lSample = (long)pDataIn[nRemap*3]<<24 | (long)pDataIn[nRemap*3+1]<<16 | (long)pDataIn[nRemap*3+2]<<8;
+ *pDataOut = (float)(long)lSample / 0x80000000;
- pDataOut++;
+ pDataOut++;
+ }
+ pDataIn += wfein->nChannels*3;
}
- pDataIn += wfein->nChannels*3;
- }
- break;
+ break;
}
memmove(m_buff.GetData(), pDataIn, m_buff.GetCount() - len );
@@ -818,34 +812,30 @@ HRESULT CMpaDecFilter::ProcessA52(BYTE* p, int buffsize, int& size, bool& fEnoug
{
int flags, sample_rate, bit_rate;
- if((size = a52_syncinfo(p, &flags, &sample_rate, &bit_rate)) > 0)
- {
-// TRACE(_T("ac3: size=%d, flags=%08x, sample_rate=%d, bit_rate=%d\n"), size, flags, sample_rate, bit_rate);
+ if((size = a52_syncinfo(p, &flags, &sample_rate, &bit_rate)) > 0) {
+ // TRACE(_T("ac3: size=%d, flags=%08x, sample_rate=%d, bit_rate=%d\n"), size, flags, sample_rate, bit_rate);
fEnoughData = size <= buffsize;
- if(fEnoughData)
- {
+ if(fEnoughData) {
int iSpeakerConfig = GetSpeakerConfig(ac3);
- if(iSpeakerConfig < 0)
- {
+ if(iSpeakerConfig < 0) {
HRESULT hr;
- if(S_OK != (hr = Deliver(p, size, bit_rate, 0x0001)))
+ if(S_OK != (hr = Deliver(p, size, bit_rate, 0x0001))) {
return hr;
- }
- else
- {
+ }
+ } else {
flags = iSpeakerConfig&(A52_CHANNEL_MASK|A52_LFE);
flags |= A52_ADJUST_LEVEL;
sample_t level = 1, gain = 1, bias = 0;
level *= gain;
- if(a52_frame(m_a52_state, p, &flags, &level, bias) == 0)
- {
- if(GetDynamicRangeControl(ac3))
+ if(a52_frame(m_a52_state, p, &flags, &level, bias) == 0) {
+ if(GetDynamicRangeControl(ac3)) {
a52_dynrng(m_a52_state, NULL, NULL);
+ }
int scmapidx = min(flags&A52_CHANNEL_MASK, countof(s_scmap_ac3)/2);
scmap_t& scmap = s_scmap_ac3[scmapidx + ((flags&A52_LFE)?(countof(s_scmap_ac3)/2):0)];
@@ -856,25 +846,22 @@ HRESULT CMpaDecFilter::ProcessA52(BYTE* p, int buffsize, int& size, bool& fEnoug
int i = 0;
- for(; i < 6 && a52_block(m_a52_state) == 0; i++)
- {
+ for(; i < 6 && a52_block(m_a52_state) == 0; i++) {
sample_t* samples = a52_samples(m_a52_state);
- for(int j = 0; j < 256; j++, samples++)
- {
- for(int ch = 0; ch < scmap.nChannels; ch++)
- {
+ for(int j = 0; j < 256; j++, samples++) {
+ for(int ch = 0; ch < scmap.nChannels; ch++) {
ASSERT(scmap.ch[ch] != -1);
*p++ = (float)(*(samples + 256*scmap.ch[ch]) / level);
}
}
}
- if(i == 6)
- {
+ if(i == 6) {
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, sample_rate, scmap.nChannels, scmap.dwChannelMask)))
+ if(S_OK != (hr = Deliver(pBuff, sample_rate, scmap.nChannels, scmap.dwChannelMask))) {
return hr;
+ }
}
}
}
@@ -892,38 +879,33 @@ HRESULT CMpaDecFilter::ProcessAC3()
BYTE* base = p;
BYTE* end = p + m_buff.GetCount();
- while(end - p >= 7)
- {
+ while(end - p >= 7) {
int size = 0, flags, sample_rate, bit_rate;
- if((size = a52_syncinfo(p, &flags, &sample_rate, &bit_rate)) > 0)
- {
-// TRACE(_T("ac3: size=%d, flags=%08x, sample_rate=%d, bit_rate=%d\n"), size, flags, sample_rate, bit_rate);
+ if((size = a52_syncinfo(p, &flags, &sample_rate, &bit_rate)) > 0) {
+ // TRACE(_T("ac3: size=%d, flags=%08x, sample_rate=%d, bit_rate=%d\n"), size, flags, sample_rate, bit_rate);
bool fEnoughData = p + size <= end;
- if(fEnoughData)
- {
+ if(fEnoughData) {
int iSpeakerConfig = GetSpeakerConfig(ac3);
- if(iSpeakerConfig < 0)
- {
+ if(iSpeakerConfig < 0) {
HRESULT hr;
- if(S_OK != (hr = Deliver(p, size, bit_rate, 0x0001)))
+ if(S_OK != (hr = Deliver(p, size, bit_rate, 0x0001))) {
return hr;
- }
- else
- {
+ }
+ } else {
flags = iSpeakerConfig&(A52_CHANNEL_MASK|A52_LFE);
flags |= A52_ADJUST_LEVEL;
sample_t level = 1, gain = 1, bias = 0;
level *= gain;
- if(a52_frame(m_a52_state, p, &flags, &level, bias) == 0)
- {
- if(GetDynamicRangeControl(ac3))
+ if(a52_frame(m_a52_state, p, &flags, &level, bias) == 0) {
+ if(GetDynamicRangeControl(ac3)) {
a52_dynrng(m_a52_state, NULL, NULL);
+ }
int scmapidx = min(flags&A52_CHANNEL_MASK, countof(s_scmap_ac3)/2);
scmap_t& scmap = s_scmap_ac3[scmapidx + ((flags&A52_LFE)?(countof(s_scmap_ac3)/2):0)];
@@ -934,25 +916,22 @@ HRESULT CMpaDecFilter::ProcessAC3()
int i = 0;
- for(; i < 6 && a52_block(m_a52_state) == 0; i++)
- {
+ for(; i < 6 && a52_block(m_a52_state) == 0; i++) {
sample_t* samples = a52_samples(m_a52_state);
- for(int j = 0; j < 256; j++, samples++)
- {
- for(int ch = 0; ch < scmap.nChannels; ch++)
- {
+ for(int j = 0; j < 256; j++, samples++) {
+ for(int ch = 0; ch < scmap.nChannels; ch++) {
ASSERT(scmap.ch[ch] != -1);
*p++ = (float)(*(samples + 256*scmap.ch[ch]) / level);
}
}
}
- if(i == 6)
- {
+ if(i == 6) {
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, sample_rate, scmap.nChannels, scmap.dwChannelMask)))
+ if(S_OK != (hr = Deliver(pBuff, sample_rate, scmap.nChannels, scmap.dwChannelMask))) {
return hr;
+ }
}
}
}
@@ -964,11 +943,10 @@ HRESULT CMpaDecFilter::ProcessAC3()
end = base + (end - p);
p = base;
- if(!fEnoughData)
+ if(!fEnoughData) {
break;
- }
- else
- {
+ }
+ } else {
p++;
}
}
@@ -987,76 +965,70 @@ HRESULT CMpaDecFilter::ProcessAC3()
BYTE* base = p;
BYTE* end = p + m_buff.GetCount();
- while(end - p >= AC3_HEADER_SIZE)
- {
+ while(end - p >= AC3_HEADER_SIZE) {
int size = 0;
bool fEnoughData = true;
- if (m_DolbyDigitalMode != DD_TRUEHD && m_DolbyDigitalMode != DD_MLP && (*((__int16*)p) == 0x770b)) /* AC3-EAC3 syncword */
- {
+ if (m_DolbyDigitalMode != DD_TRUEHD && m_DolbyDigitalMode != DD_MLP && (*((__int16*)p) == 0x770b)) { /* AC3-EAC3 syncword */
BYTE bsid = p[5] >> 3;
- if ((m_DolbyDigitalMode != DD_EAC3) && bsid <= 12)
- {
+ if ((m_DolbyDigitalMode != DD_EAC3) && bsid <= 12) {
m_DolbyDigitalMode = DD_AC3;
- if (FAILED (hr = ProcessA52 (p, end-p, size, fEnoughData))) return hr;
- }
- else if (bsid <= 16)
- {
+ if (FAILED (hr = ProcessA52 (p, end-p, size, fEnoughData))) {
+ return hr;
+ }
+ } else if (bsid <= 16) {
DeliverFFmpeg(CODEC_ID_EAC3, p, end-p, size);
- if (size > 0)
+ if (size > 0) {
m_DolbyDigitalMode = DD_EAC3;
- }
- else
- {
+ }
+ } else {
p++;
continue;
}
- }
- else if ( (*((__int32*)(p+4)) == 0xba6f72f8) || // True HD major sync frame
- m_DolbyDigitalMode == DD_TRUEHD )
- {
+ } else if ( (*((__int32*)(p+4)) == 0xba6f72f8) || // True HD major sync frame
+ m_DolbyDigitalMode == DD_TRUEHD ) {
int nLenght = (((p[0]<<8) + p[1]) & 0x0FFF)*2;
m_DolbyDigitalMode = DD_TRUEHD;
- if (nLenght >= 4)
- {
+ if (nLenght >= 4) {
DeliverFFmpeg(CODEC_ID_TRUEHD, p, end-p, size);
- if (size<0) size = end-p;
+ if (size<0) {
+ size = end-p;
+ }
}
- }
- else if ( (*((__int32*)(p+4)) == 0xbb6f72f8) ||
- m_DolbyDigitalMode == DD_MLP ) // MLP
- {
+ } else if ( (*((__int32*)(p+4)) == 0xbb6f72f8) ||
+ m_DolbyDigitalMode == DD_MLP ) { // MLP
int nLenght = (((p[0]<<8) + p[1]) & 0x0FFF)*2;
m_DolbyDigitalMode = DD_MLP;
- if (nLenght >= 4)
- {
+ if (nLenght >= 4) {
DeliverFFmpeg(CODEC_ID_MLP, p, end-p, size);
- if (size<0) size = end-p;
+ if (size<0) {
+ size = end-p;
+ }
}
- }
- else
- {
+ } else {
p++;
continue;
}
// Update buffer position
- if (fEnoughData)
- {
+ if (fEnoughData) {
ASSERT (size <= end-p);
- if (size <= 0) break;
+ if (size <= 0) {
+ break;
+ }
p += size;
}
memmove(base, p, end - p);
end = base + (end - p);
p = base;
- if(!fEnoughData)
+ if(!fEnoughData) {
break;
+ }
}
m_buff.SetCount(end - p);
@@ -1077,7 +1049,9 @@ HRESULT CMpaDecFilter::ProcessFFmpeg(int nCodecId)
int size = 0;
hr = DeliverFFmpeg(nCodecId, p, end-p, size);
- if (size <= 0) return S_OK;
+ if (size <= 0) {
+ return S_OK;
+ }
p += size;
memmove(base, p, end - p);
end = base + (end - p);
@@ -1095,38 +1069,33 @@ HRESULT CMpaDecFilter::ProcessDTS()
BYTE* base = p;
BYTE* end = p + m_buff.GetCount();
- while(end - p >= 14)
- {
+ while(end - p >= 14) {
int size = 0, flags, sample_rate, bit_rate, frame_length;
- if((size = dts_syncinfo(m_dts_state, p, &flags, &sample_rate, &bit_rate, &frame_length)) > 0)
- {
-// TRACE(_T("dts: size=%d, flags=%08x, sample_rate=%d, bit_rate=%d, frame_length=%d\n"), size, flags, sample_rate, bit_rate, frame_length);
+ if((size = dts_syncinfo(m_dts_state, p, &flags, &sample_rate, &bit_rate, &frame_length)) > 0) {
+ // TRACE(_T("dts: size=%d, flags=%08x, sample_rate=%d, bit_rate=%d, frame_length=%d\n"), size, flags, sample_rate, bit_rate, frame_length);
bool fEnoughData = p + size <= end;
- if(fEnoughData)
- {
+ if(fEnoughData) {
int iSpeakerConfig = GetSpeakerConfig(dts);
- if(iSpeakerConfig < 0)
- {
+ if(iSpeakerConfig < 0) {
HRESULT hr;
- if(S_OK != (hr = Deliver(p, size, bit_rate, 0x000b)))
+ if(S_OK != (hr = Deliver(p, size, bit_rate, 0x000b))) {
return hr;
- }
- else
- {
+ }
+ } else {
flags = iSpeakerConfig&(DTS_CHANNEL_MASK|DTS_LFE);
flags |= DTS_ADJUST_LEVEL;
sample_t level = 1, gain = 1, bias = 0;
level *= gain;
- if(dts_frame(m_dts_state, p, &flags, &level, bias) == 0)
- {
- if(GetDynamicRangeControl(dts))
+ if(dts_frame(m_dts_state, p, &flags, &level, bias) == 0) {
+ if(GetDynamicRangeControl(dts)) {
dts_dynrng(m_dts_state, NULL, NULL);
+ }
int scmapidx = min(flags&DTS_CHANNEL_MASK, countof(s_scmap_dts)/2);
scmap_t& scmap = s_scmap_dts[scmapidx + ((flags&DTS_LFE)?(countof(s_scmap_dts)/2):0)];
@@ -1139,25 +1108,22 @@ HRESULT CMpaDecFilter::ProcessDTS()
int i = 0;
- for(; i < blocks && dts_block(m_dts_state) == 0; i++)
- {
+ for(; i < blocks && dts_block(m_dts_state) == 0; i++) {
sample_t* samples = dts_samples(m_dts_state);
- for(int j = 0; j < 256; j++, samples++)
- {
- for(int ch = 0; ch < scmap.nChannels; ch++)
- {
+ for(int j = 0; j < 256; j++, samples++) {
+ for(int ch = 0; ch < scmap.nChannels; ch++) {
ASSERT(scmap.ch[ch] != -1);
*p++ = (float)(*(samples + 256*scmap.ch[ch]) / level);
}
}
}
- if(i == blocks)
- {
+ if(i == blocks) {
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, sample_rate, scmap.nChannels, scmap.dwChannelMask)))
+ if(S_OK != (hr = Deliver(pBuff, sample_rate, scmap.nChannels, scmap.dwChannelMask))) {
return hr;
+ }
}
}
}
@@ -1169,11 +1135,10 @@ HRESULT CMpaDecFilter::ProcessDTS()
end = base + (end - p);
p = base;
- if(!fEnoughData)
+ if(!fEnoughData) {
break;
- }
- else
- {
+ }
+ } else {
p++;
}
}
@@ -1197,12 +1162,15 @@ HRESULT CMpaDecFilter::ProcessAAC()
float* src = (float*)NeAACDecDecode(m_aac_state.h, &info, m_buff.GetData(), m_buff.GetCount());
m_buff.RemoveAll();
//if(!src) return E_FAIL;
- if(info.error) m_aac_state.init(m_pInput->CurrentMediaType());
- if(!src || info.samples == 0) return S_OK;
+ if(info.error) {
+ m_aac_state.init(m_pInput->CurrentMediaType());
+ }
+ if(!src || info.samples == 0) {
+ return S_OK;
+ }
// HACK: bug in faad2 with mono sources?
- if(info.channels == 2 && info.channel_position[1] == UNKNOWN_CHANNEL)
- {
+ if(info.channels == 2 && info.channel_position[1] == UNKNOWN_CHANNEL) {
info.channel_position[0] = FRONT_CHANNEL_LEFT;
info.channel_position[1] = FRONT_CHANNEL_RIGHT;
}
@@ -1223,8 +1191,7 @@ HRESULT CMpaDecFilter::ProcessAAC()
chmask[LFE_CHANNEL] = SPEAKER_LOW_FREQUENCY;
DWORD dwChannelMask = 0;
- for(int i = 0; i < info.channels; i++)
- {
+ for(int i = 0; i < info.channels; i++) {
if(info.channel_position[i] == UNKNOWN_CHANNEL) {
ASSERT(0);
return E_FAIL;
@@ -1235,14 +1202,11 @@ HRESULT CMpaDecFilter::ProcessAAC()
int chmap[countof(info.channel_position)];
memset(chmap, 0, sizeof(chmap));
- for(int i = 0; i < info.channels; i++)
- {
+ for(int i = 0; i < info.channels; i++) {
unsigned int ch = 0, mask = chmask[info.channel_position[i]];
- for(int j = 0; j < 32; j++)
- {
- if(dwChannelMask & (1 << j))
- {
+ for(int j = 0; j < 32; j++) {
+ if(dwChannelMask & (1 << j)) {
if((1 << j) == mask) {
chmap[i] = ch;
break;
@@ -1252,15 +1216,19 @@ HRESULT CMpaDecFilter::ProcessAAC()
}
}
- if(info.channels <= 2) dwChannelMask = 0;
+ if(info.channels <= 2) {
+ dwChannelMask = 0;
+ }
for(int j = 0; j < info.samples; j += info.channels, dst += info.channels)
- for(int i = 0; i < info.channels; i++)
+ for(int i = 0; i < info.channels; i++) {
dst[chmap[i]] = *src++;
+ }
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, info.samplerate, info.channels, dwChannelMask)))
+ if(S_OK != (hr = Deliver(pBuff, info.samplerate, info.channels, dwChannelMask))) {
return hr;
+ }
return S_OK;
}
@@ -1276,20 +1244,20 @@ HRESULT CMpaDecFilter::ProcessPCMraw() //'raw '
float* f = pBuff.GetData();
switch(wfe->wBitsPerSample) {
- case 8: //unsigned 8-bit
- { BYTE* b = m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)(CHAR)(b[i] - 128) / 128;
+ case 8: { //unsigned 8-bit
+ BYTE* b = m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)(CHAR)(b[i] - 128) / 128;
+ }
}
- }
- break;
- case 16: //signed big-endian 16 bit
- { USHORT* d = (USHORT*)m_buff.GetData();//signed take as an unsigned to shift operations.
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)(SHORT)(d[i] << 8 | d[i] >> 8) / 32768;
+ break;
+ case 16: { //signed big-endian 16 bit
+ USHORT* d = (USHORT*)m_buff.GetData();//signed take as an unsigned to shift operations.
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)(SHORT)(d[i] << 8 | d[i] >> 8) / 32768;
+ }
}
- }
- break;
+ break;
}
HRESULT hr;
@@ -1311,39 +1279,39 @@ HRESULT CMpaDecFilter::ProcessPCMintBE() //'twos', big-endian 'in24' and 'in32'
float* f = pBuff.GetData();
switch(wfe->wBitsPerSample) {
- case 8: //signed 8-bit
- { CHAR* b = (CHAR*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)b[i] / 128;
+ case 8: { //signed 8-bit
+ CHAR* b = (CHAR*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)b[i] / 128;
+ }
}
- }
- break;
- case 16: //signed big-endian 16-bit
- { USHORT* d = (USHORT*)m_buff.GetData();//signed take as an unsigned to shift operations.
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)(SHORT)(d[i] << 8 | d[i] >> 8) / 32768;
+ break;
+ case 16: { //signed big-endian 16-bit
+ USHORT* d = (USHORT*)m_buff.GetData();//signed take as an unsigned to shift operations.
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)(SHORT)(d[i] << 8 | d[i] >> 8) / 32768;
+ }
}
- }
- break;
- case 24: //signed big-endian 24-bit
- { BYTE* b = (BYTE*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)(signed int)((unsigned int)b[3*i] << 24 |
- (unsigned int)b[3*i+1] << 16 |
- (unsigned int)b[3*i+2] << 8) / 2147483648;
+ break;
+ case 24: { //signed big-endian 24-bit
+ BYTE* b = (BYTE*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)(signed int)((unsigned int)b[3*i] << 24 |
+ (unsigned int)b[3*i+1] << 16 |
+ (unsigned int)b[3*i+2] << 8) / 2147483648;
+ }
}
- }
- break;
- case 32: //signed big-endian 32-bit
- { UINT* q = (UINT*)m_buff.GetData();//signed take as an unsigned to shift operations.
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)(INT)(q[i] >> 24 |
- (q[i] & 0x00ff0000) >> 8 |
- (q[i] & 0x0000ff00) << 8 |
- q[i] << 24) / 2147483648;
+ break;
+ case 32: { //signed big-endian 32-bit
+ UINT* q = (UINT*)m_buff.GetData();//signed take as an unsigned to shift operations.
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)(INT)(q[i] >> 24 |
+ (q[i] & 0x00ff0000) >> 8 |
+ (q[i] & 0x0000ff00) << 8 |
+ q[i] << 24) / 2147483648;
+ }
}
- }
- break;
+ break;
}
HRESULT hr;
@@ -1365,36 +1333,36 @@ HRESULT CMpaDecFilter::ProcessPCMintLE() //'sowt', little-endian 'in24' and 'in3
float* f = pBuff.GetData();
switch(wfe->wBitsPerSample) {
- case 8: //signed 8-bit
- { CHAR* b = (CHAR*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)b[i] / 128;
+ case 8: { //signed 8-bit
+ CHAR* b = (CHAR*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)b[i] / 128;
+ }
}
- }
- break;
- case 16: //signed little-endian 16-bit
- { SHORT* d = (SHORT*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)d[i] / 32768;
+ break;
+ case 16: { //signed little-endian 16-bit
+ SHORT* d = (SHORT*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)d[i] / 32768;
+ }
}
- }
- break;
- case 24: //signed little-endian 32-bit
- { BYTE* b = (BYTE*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)(signed int)((unsigned int)b[3*i] << 8 |
- (unsigned int)b[3*i+1] << 16 |
- (unsigned int)b[3*i+2] << 24) / 2147483648;
+ break;
+ case 24: { //signed little-endian 32-bit
+ BYTE* b = (BYTE*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)(signed int)((unsigned int)b[3*i] << 8 |
+ (unsigned int)b[3*i+1] << 16 |
+ (unsigned int)b[3*i+2] << 24) / 2147483648;
+ }
}
- }
- break;
- case 32: //signed little-endian 32-bit
- { INT* q = (INT*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)q[i] / 2147483648;
+ break;
+ case 32: { //signed little-endian 32-bit
+ INT* q = (INT*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)q[i] / 2147483648;
+ }
}
- }
- break;
+ break;
}
HRESULT hr;
@@ -1416,33 +1384,33 @@ HRESULT CMpaDecFilter::ProcessPCMfloatBE() //big-endian 'fl32' and 'fl64'
float* f = pBuff.GetData();
switch(wfe->wBitsPerSample) {
- case 32:
- { unsigned int* q = (unsigned int*)m_buff.GetData();
- unsigned int* vf = (unsigned int*)f;
- for(int i = 0; i < nSamples; i++) {
- vf[i] = q[i] >> 24 |
- (q[i] & 0x00ff0000) >> 8 |
- (q[i] & 0x0000ff00) << 8 |
- q[i] << 24;
- }
- }
- break;
- case 64:
- { unsigned __int64* q = (unsigned __int64*)m_buff.GetData();
- unsigned __int64 x;
- for(int i = 0; i < nSamples; i++) {
- x = q[i] >>56 |
- (q[i] & 0x00FF000000000000) >> 40 |
- (q[i] & 0x0000FF0000000000) >> 24 |
- (q[i] & 0x000000FF00000000) >> 8 |
- (q[i] & 0x00000000FF000000) << 8 |
- (q[i] & 0x0000000000FF0000) << 24 |
- (q[i] & 0x000000000000FF00) << 40 |
- q[i] << 56;
- f[i] = (float)*(double*)&x;
- }
- }
- break;
+ case 32: {
+ unsigned int* q = (unsigned int*)m_buff.GetData();
+ unsigned int* vf = (unsigned int*)f;
+ for(int i = 0; i < nSamples; i++) {
+ vf[i] = q[i] >> 24 |
+ (q[i] & 0x00ff0000) >> 8 |
+ (q[i] & 0x0000ff00) << 8 |
+ q[i] << 24;
+ }
+ }
+ break;
+ case 64: {
+ unsigned __int64* q = (unsigned __int64*)m_buff.GetData();
+ unsigned __int64 x;
+ for(int i = 0; i < nSamples; i++) {
+ x = q[i] >>56 |
+ (q[i] & 0x00FF000000000000) >> 40 |
+ (q[i] & 0x0000FF0000000000) >> 24 |
+ (q[i] & 0x000000FF00000000) >> 8 |
+ (q[i] & 0x00000000FF000000) << 8 |
+ (q[i] & 0x0000000000FF0000) << 24 |
+ (q[i] & 0x000000000000FF00) << 40 |
+ q[i] << 56;
+ f[i] = (float)*(double*)&x;
+ }
+ }
+ break;
}
HRESULT hr;
@@ -1464,20 +1432,20 @@ HRESULT CMpaDecFilter::ProcessPCMfloatLE() //little-endian 'fl32' and 'fl64'
float* f = pBuff.GetData();
switch(wfe->wBitsPerSample) {
- case 32:
- { float* q = (float*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = q[i];
+ case 32: {
+ float* q = (float*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = q[i];
+ }
}
- }
- break;
- case 64:
- { double* q = (double*)m_buff.GetData();
- for(int i = 0; i < nSamples; i++) {
- f[i] = (float)q[i];
+ break;
+ case 64: {
+ double* q = (double*)m_buff.GetData();
+ for(int i = 0; i < nSamples; i++) {
+ f[i] = (float)q[i];
+ }
}
- }
- break;
+ break;
}
HRESULT hr;
@@ -1504,38 +1472,32 @@ HRESULT CMpaDecFilter::ProcessPS2PCM()
pBuff.SetCount(samples*channels);
float* f = pBuff.GetData();
- while(end - p >= size)
- {
+ while(end - p >= size) {
DWORD* dw = (DWORD*)p;
- if(dw[0] == 'dhSS')
- {
+ if(dw[0] == 'dhSS') {
p += dw[1] + 8;
- }
- else if(dw[0] == 'dbSS')
- {
+ } else if(dw[0] == 'dbSS') {
p += 8;
m_ps2_state.sync = true;
- }
- else
- {
- if(m_ps2_state.sync)
- {
+ } else {
+ if(m_ps2_state.sync) {
short* s = (short*)p;
for(int i = 0; i < samples; i++)
- for(int j = 0; j < channels; j++)
+ for(int j = 0; j < channels; j++) {
f[i*channels+j] = (float)s[j*samples+i] / 32768;
- }
- else
- {
- for(int i = 0, j = samples*channels; i < j; i++)
+ }
+ } else {
+ for(int i = 0, j = samples*channels; i < j; i++) {
f[i] = 0;
+ }
}
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, wfe->nSamplesPerSec, wfe->nChannels)))
+ if(S_OK != (hr = Deliver(pBuff, wfe->nSamplesPerSec, wfe->nChannels))) {
return hr;
+ }
p += size;
@@ -1563,8 +1525,7 @@ static void decodeps2adpcm(ps2_state_t& s, int channel, BYTE* pin, double* pout)
}
// if(unk == 7) {ASSERT(0); return;} // ???
- static double s_tbl[] =
- {
+ static double s_tbl[] = {
0.0, 0.0, 0.9375, 0.0, 1.796875, -0.8125, 1.53125, -0.859375, 1.90625, -0.9375,
0.0, 0.0, -0.9375, 0.0, -1.796875, 0.8125, -1.53125, 0.859375 -1.90625, 0.9375
};
@@ -1573,8 +1534,7 @@ static void decodeps2adpcm(ps2_state_t& s, int channel, BYTE* pin, double* pout)
double& a = s.a[channel];
double& b = s.b[channel];
- for(int i = 0; i < 28; i++)
- {
+ for(int i = 0; i < 28; i++) {
short input = (short)(((pin[2+i/2] >> ((i&1) << 2)) & 0xf) << 12) >> shift;
double output = a * tbl[1] + b * tbl[0] + input;
@@ -1600,44 +1560,39 @@ HRESULT CMpaDecFilter::ProcessPS2ADPCM()
pBuff.SetCount(samples*channels);
float* f = pBuff.GetData();
- while(end - p >= size)
- {
+ while(end - p >= size) {
DWORD* dw = (DWORD*)p;
- if(dw[0] == 'dhSS')
- {
+ if(dw[0] == 'dhSS') {
p += dw[1] + 8;
- }
- else if(dw[0] == 'dbSS')
- {
+ } else if(dw[0] == 'dbSS') {
p += 8;
m_ps2_state.sync = true;
- }
- else
- {
- if(m_ps2_state.sync)
- {
+ } else {
+ if(m_ps2_state.sync) {
double* tmp = DNew double[samples*channels];
for(int channel = 0, j = 0, k = 0; channel < channels; channel++, j += wfe->dwInterleave)
- for(int i = 0; i < wfe->dwInterleave; i += 16, k += 28)
+ for(int i = 0; i < wfe->dwInterleave; i += 16, k += 28) {
decodeps2adpcm(m_ps2_state, channel, p + i + j, tmp + k);
+ }
for(int i = 0, k = 0; i < samples; i++)
- for(int j = 0; j < channels; j++, k++)
+ for(int j = 0; j < channels; j++, k++) {
f[k] = (float)tmp[j*samples+i];
+ }
delete [] tmp;
- }
- else
- {
- for(int i = 0, j = samples*channels; i < j; i++)
+ } else {
+ for(int i = 0, j = samples*channels; i < j; i++) {
f[i] = 0;
+ }
}
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, wfe->nSamplesPerSec, wfe->nChannels)))
+ if(S_OK != (hr = Deliver(pBuff, wfe->nSamplesPerSec, wfe->nChannels))) {
return hr;
+ }
p += size;
}
@@ -1655,11 +1610,13 @@ HRESULT CMpaDecFilter::ProcessPS2ADPCM()
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
HRESULT CMpaDecFilter::ProcessVorbis()
{
- if(m_vorbis.vi.channels < 1 || m_vorbis.vi.channels > 6)
+ if(m_vorbis.vi.channels < 1 || m_vorbis.vi.channels > 6) {
return E_FAIL;
+ }
- if(m_buff.IsEmpty())
+ if(m_buff.IsEmpty()) {
return S_OK;
+ }
HRESULT hr = S_OK;
@@ -1670,31 +1627,30 @@ HRESULT CMpaDecFilter::ProcessVorbis()
op.b_o_s = 0;
op.packetno = m_vorbis.packetno++;
- if(vorbis_synthesis(&m_vorbis.vb, &op) == 0)
- {
+ if(vorbis_synthesis(&m_vorbis.vb, &op) == 0) {
vorbis_synthesis_blockin(&m_vorbis.vd, &m_vorbis.vb);
int samples;
float** pcm;
- while((samples = vorbis_synthesis_pcmout(&m_vorbis.vd, &pcm)) > 0)
- {
+ while((samples = vorbis_synthesis_pcmout(&m_vorbis.vd, &pcm)) > 0) {
const scmap_t& scmap = s_scmap_vorbis[m_vorbis.vi.channels-1];
CAtlArray<float> pBuff;
pBuff.SetCount(samples * scmap.nChannels);
float* dst = pBuff.GetData();
- for(int j = 0, ch = scmap.nChannels; j < ch; j++)
- {
+ for(int j = 0, ch = scmap.nChannels; j < ch; j++) {
float* src = pcm[scmap.ch[j]];
- for(int i = 0; i < samples; i++)
+ for(int i = 0; i < samples; i++) {
dst[j + i*ch] = src[i];
+ }
// dst[j + i*ch] = (float)max(min(src[i], 1<<24), -1<<24) / (1<<24);
}
- if(S_OK != (hr = Deliver(pBuff, m_vorbis.vi.rate, scmap.nChannels, scmap.dwChannelMask)))
+ if(S_OK != (hr = Deliver(pBuff, m_vorbis.vi.rate, scmap.nChannels, scmap.dwChannelMask))) {
break;
+ }
vorbis_synthesis_read(&m_vorbis.vd, samples);
}
@@ -1708,8 +1664,11 @@ HRESULT CMpaDecFilter::ProcessVorbis()
static inline float fscale(mad_fixed_t sample)
{
- if(sample >= MAD_F_ONE) sample = MAD_F_ONE - 1;
- else if(sample < -MAD_F_ONE) sample = -MAD_F_ONE;
+ if(sample >= MAD_F_ONE) {
+ sample = MAD_F_ONE - 1;
+ } else if(sample < -MAD_F_ONE) {
+ sample = -MAD_F_ONE;
+ }
return (float)sample / (1 << MAD_F_FRACBITS);
}
@@ -1730,12 +1689,9 @@ HRESULT CMpaDecFilter::ProcessMPA()
{
mad_stream_buffer(&m_stream, m_buff.GetData(), m_buff.GetCount());
- while(1)
- {
- if(mad_frame_decode(&m_frame, &m_stream) == -1)
- {
- if(m_stream.error == MAD_ERROR_BUFLEN)
- {
+ while(1) {
+ if(mad_frame_decode(&m_frame, &m_stream) == -1) {
+ if(m_stream.error == MAD_ERROR_BUFLEN) {
memmove(m_buff.GetData(), m_stream.this_frame, m_stream.bufend - m_stream.this_frame);
m_buff.SetCount(m_stream.bufend - m_stream.this_frame);
break;
@@ -1747,8 +1703,7 @@ HRESULT CMpaDecFilter::ProcessMPA()
}
- if(!MAD_RECOVERABLE(m_stream.error))
- {
+ if(!MAD_RECOVERABLE(m_stream.error)) {
TRACE(_T("*m_stream.error == %d\n"), m_stream.error);
return E_FAIL;
}
@@ -1772,8 +1727,7 @@ HRESULT CMpaDecFilter::ProcessMPA()
mad_synth_frame(&m_synth, &m_frame);
WAVEFORMATEX* wfein = (WAVEFORMATEX*)m_pInput->CurrentMediaType().Format();
- if(wfein->nChannels != m_synth.pcm.channels || wfein->nSamplesPerSec != m_synth.pcm.samplerate)
- {
+ if(wfein->nChannels != m_synth.pcm.channels || wfein->nSamplesPerSec != m_synth.pcm.samplerate) {
TRACE(_T("MAD channels %d %d samplerate %d %d \n"),wfein->nChannels , m_synth.pcm.channels, wfein->nSamplesPerSec , m_synth.pcm.samplerate);
//Some time this does happened - need more testing ...
//continue;
@@ -1786,15 +1740,17 @@ HRESULT CMpaDecFilter::ProcessMPA()
pBuff.SetCount(m_synth.pcm.length*m_synth.pcm.channels);
float* pDataOut = pBuff.GetData();
- for(unsigned short i = 0; i < m_synth.pcm.length; i++)
- {
+ for(unsigned short i = 0; i < m_synth.pcm.length; i++) {
*pDataOut++ = fscale(*left_ch++);
- if(m_synth.pcm.channels == 2) *pDataOut++ = fscale(*right_ch++);
+ if(m_synth.pcm.channels == 2) {
+ *pDataOut++ = fscale(*right_ch++);
+ }
}
HRESULT hr;
- if(S_OK != (hr = Deliver(pBuff, m_synth.pcm.samplerate, m_synth.pcm.channels)))
+ if(S_OK != (hr = Deliver(pBuff, m_synth.pcm.samplerate, m_synth.pcm.channels))) {
return hr;
+ }
}
return S_OK;
@@ -1807,12 +1763,12 @@ HRESULT CMpaDecFilter::GetDeliveryBuffer(IMediaSample** pSample, BYTE** pData)
*pData = NULL;
if(FAILED(hr = m_pOutput->GetDeliveryBuffer(pSample, NULL, NULL, 0))
- || FAILED(hr = (*pSample)->GetPointer(pData)))
+ || FAILED(hr = (*pSample)->GetPointer(pData))) {
return hr;
+ }
AM_MEDIA_TYPE* pmt = NULL;
- if(SUCCEEDED((*pSample)->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED((*pSample)->GetMediaType(&pmt)) && pmt) {
CMediaType mt = *pmt;
m_pOutput->SetMediaType(&mt);
DeleteMediaType(pmt);
@@ -1833,23 +1789,25 @@ HRESULT CMpaDecFilter::Deliver(CAtlArray<float>& pBuff, DWORD nSamplesPerSec, WO
int nSamples = pBuff.GetCount()/wfe->nChannels;
- if(FAILED(hr = ReconnectOutput(nSamples, mt)))
+ if(FAILED(hr = ReconnectOutput(nSamples, mt))) {
return hr;
+ }
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
- if(FAILED(GetDeliveryBuffer(&pOut, &pDataOut)))
+ if(FAILED(GetDeliveryBuffer(&pOut, &pDataOut))) {
return E_FAIL;
+ }
REFERENCE_TIME rtDur = 10000000i64*nSamples/wfe->nSamplesPerSec;
REFERENCE_TIME rtStart = m_rtStart, rtStop = m_rtStart + rtDur;
m_rtStart += rtDur;
-//TRACE(_T("CMpaDecFilter: %I64d - %I64d\n"), rtStart/10000, rtStop/10000);
- if(rtStart < 0 /*200000*/ /* < 0, FIXME: 0 makes strange noises */)
+ //TRACE(_T("CMpaDecFilter: %I64d - %I64d\n"), rtStart/10000, rtStop/10000);
+ if(rtStart < 0 /*200000*/ /* < 0, FIXME: 0 makes strange noises */) {
return S_OK;
+ }
- if(hr == S_OK)
- {
+ if(hr == S_OK) {
m_pOutput->SetMediaType(&mt);
pOut->SetMediaType(&mt);
}
@@ -1872,13 +1830,15 @@ HRESULT CMpaDecFilter::Deliver(CAtlArray<float>& pBuff, DWORD nSamplesPerSec, WO
// TODO: move this into the audio switcher
float sample_mul = 1;
- if(m_fNormalize)
- {
- for(int i = 0, len = pBuff.GetCount(); i < len; i++)
- {
+ if(m_fNormalize) {
+ for(int i = 0, len = pBuff.GetCount(); i < len; i++) {
float f = *pDataIn++;
- if(f < 0) f = -f;
- if(m_sample_max < f) m_sample_max = f;
+ if(f < 0) {
+ f = -f;
+ }
+ if(m_sample_max < f) {
+ m_sample_max = f;
+ }
}
sample_mul = 1.0f / m_sample_max;
pDataIn = pBuff.GetData();
@@ -1887,45 +1847,48 @@ HRESULT CMpaDecFilter::Deliver(CAtlArray<float>& pBuff, DWORD nSamplesPerSec, WO
bool fBoost = m_boost > 1;
double boost = 1+log10(m_boost);
- for(int i = 0, len = pBuff.GetCount(); i < len; i++)
- {
+ for(int i = 0, len = pBuff.GetCount(); i < len; i++) {
float f = *pDataIn++;
// TODO: move this into the audio switcher
- if(m_fNormalize)
+ if(m_fNormalize) {
f *= sample_mul;
+ }
- if(fBoost)
+ if(fBoost) {
f *= boost;
+ }
- if(f < -1) f = -1;
- else if(f > 1) f = 1;
+ if(f < -1) {
+ f = -1;
+ } else if(f > 1) {
+ f = 1;
+ }
#define round(x) ((x) > 0 ? (x) + 0.5 : (x) - 0.5)
- switch(sf)
- {
- default:
- case SF_PCM16:
- *(short*)pDataOut = (short)round(f * SHRT_MAX);
- pDataOut += sizeof(short);
- break;
- case SF_PCM24:
- { DWORD i24 = (DWORD)(int)round(f * ((1<<23)-1));
- *pDataOut++ = (BYTE)(i24);
- *pDataOut++ = (BYTE)(i24>>8);
- *pDataOut++ = (BYTE)(i24>>16);
- }
- break;
- case SF_PCM32:
- *(int*)pDataOut = (int)round(f * INT_MAX);
- pDataOut += sizeof(int);
- break;
- case SF_FLOAT32:
- *(float*)pDataOut = f;
- pDataOut += sizeof(float);
+ switch(sf) {
+ default:
+ case SF_PCM16:
+ *(short*)pDataOut = (short)round(f * SHRT_MAX);
+ pDataOut += sizeof(short);
+ break;
+ case SF_PCM24: {
+ DWORD i24 = (DWORD)(int)round(f * ((1<<23)-1));
+ *pDataOut++ = (BYTE)(i24);
+ *pDataOut++ = (BYTE)(i24>>8);
+ *pDataOut++ = (BYTE)(i24>>16);
+ }
break;
+ case SF_PCM32:
+ *(int*)pDataOut = (int)round(f * INT_MAX);
+ pDataOut += sizeof(int);
+ break;
+ case SF_FLOAT32:
+ *(float*)pDataOut = f;
+ pDataOut += sizeof(float);
+ break;
}
}
@@ -1941,19 +1904,26 @@ HRESULT CMpaDecFilter::Deliver(BYTE* pBuff, int size, int bit_rate, BYTE type)
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
int length = 0;
- while(length < size+sizeof(WORD)*4) length += 0x800;
+ while(length < size+sizeof(WORD)*4) {
+ length += 0x800;
+ }
int size2 = 1i64 * wfe->nBlockAlign * wfe->nSamplesPerSec * size*8 / bit_rate;
- while(length < size2) length += 0x800;
- if(length > size2)
+ while(length < size2) {
+ length += 0x800;
+ }
+ if(length > size2) {
padded = true;
+ }
- if(FAILED(hr = ReconnectOutput(length / wfe->nBlockAlign, mt)))
+ if(FAILED(hr = ReconnectOutput(length / wfe->nBlockAlign, mt))) {
return hr;
+ }
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
- if(FAILED(GetDeliveryBuffer(&pOut, &pDataOut)))
+ if(FAILED(GetDeliveryBuffer(&pOut, &pDataOut))) {
return E_FAIL;
+ }
WORD* pDataOutW = (WORD*)pDataOut;
pDataOutW[0] = 0xf872;
@@ -1962,14 +1932,11 @@ HRESULT CMpaDecFilter::Deliver(BYTE* pBuff, int size, int bit_rate, BYTE type)
REFERENCE_TIME rtDur;
- if(!padded)
- {
+ if(!padded) {
rtDur = 10000000i64 * size*8 / bit_rate;
pDataOutW[3] = size*8;
_swab((char*)pBuff, (char*)&pDataOutW[4], size);
- }
- else
- {
+ } else {
const size_t blocks = (size + length - 1) / length;
rtDur = 10000000i64 * blocks * length*8 / bit_rate;
pDataOutW[3] = length*8;
@@ -1978,11 +1945,11 @@ HRESULT CMpaDecFilter::Deliver(BYTE* pBuff, int size, int bit_rate, BYTE type)
REFERENCE_TIME rtStart = m_rtStart, rtStop = m_rtStart + rtDur;
m_rtStart += rtDur;
- if(rtStart < 0)
+ if(rtStart < 0) {
return S_OK;
+ }
- if(hr == S_OK)
- {
+ if(hr == S_OK) {
m_pOutput->SetMediaType(&mt);
pOut->SetMediaType(&mt);
}
@@ -2005,35 +1972,37 @@ HRESULT CMpaDecFilter::ReconnectOutput(int nSamples, CMediaType& mt)
HRESULT hr;
CComQIPtr<IMemInputPin> pPin = m_pOutput->GetConnected();
- if(!pPin) return E_NOINTERFACE;
+ if(!pPin) {
+ return E_NOINTERFACE;
+ }
CComPtr<IMemAllocator> pAllocator;
- if(FAILED(hr = pPin->GetAllocator(&pAllocator)) || !pAllocator)
+ if(FAILED(hr = pPin->GetAllocator(&pAllocator)) || !pAllocator) {
return hr;
+ }
ALLOCATOR_PROPERTIES props, actual;
- if(FAILED(hr = pAllocator->GetProperties(&props)))
+ if(FAILED(hr = pAllocator->GetProperties(&props))) {
return hr;
+ }
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
long cbBuffer = nSamples * wfe->nBlockAlign;
- if(mt != m_pOutput->CurrentMediaType() || cbBuffer > props.cbBuffer)
- {
- if(cbBuffer > props.cbBuffer)
- {
+ if(mt != m_pOutput->CurrentMediaType() || cbBuffer > props.cbBuffer) {
+ if(cbBuffer > props.cbBuffer) {
props.cBuffers = 4;
props.cbBuffer = cbBuffer*3/2;
if(FAILED(hr = m_pOutput->DeliverBeginFlush())
- || FAILED(hr = m_pOutput->DeliverEndFlush())
- || FAILED(hr = pAllocator->Decommit())
- || FAILED(hr = pAllocator->SetProperties(&props, &actual))
- || FAILED(hr = pAllocator->Commit()))
+ || FAILED(hr = m_pOutput->DeliverEndFlush())
+ || FAILED(hr = pAllocator->Decommit())
+ || FAILED(hr = pAllocator->SetProperties(&props, &actual))
+ || FAILED(hr = pAllocator->Commit())) {
return hr;
+ }
- if(props.cBuffers > actual.cBuffers || props.cbBuffer > actual.cbBuffer)
- {
+ if(props.cBuffers > actual.cBuffers || props.cbBuffer > actual.cbBuffer) {
NotifyEvent(EC_ERRORABORT, hr, 0);
return E_FAIL;
}
@@ -2059,30 +2028,29 @@ CMediaType CMpaDecFilter::CreateMediaType(MPCSampleFormat sf, DWORD nSamplesPerS
wfe->wFormatTag = (WORD)mt.subtype.Data1;
wfe->nChannels = nChannels;
wfe->nSamplesPerSec = nSamplesPerSec;
- switch(sf)
- {
- default:
- case SF_PCM16:
- wfe->wBitsPerSample = 16;
- break;
- case SF_PCM24:
- wfe->wBitsPerSample = 24;
- break;
- case SF_PCM32:
- case SF_FLOAT32:
- wfe->wBitsPerSample = 32;
- break;
+ switch(sf) {
+ default:
+ case SF_PCM16:
+ wfe->wBitsPerSample = 16;
+ break;
+ case SF_PCM24:
+ wfe->wBitsPerSample = 24;
+ break;
+ case SF_PCM32:
+ case SF_FLOAT32:
+ wfe->wBitsPerSample = 32;
+ break;
}
wfe->nBlockAlign = wfe->nChannels*wfe->wBitsPerSample/8;
wfe->nAvgBytesPerSec = wfe->nSamplesPerSec*wfe->nBlockAlign;
mt.SetSampleSize (wfe->wBitsPerSample*wfe->nChannels/8);
// FIXME: 24/32 bit only seems to work with WAVE_FORMAT_EXTENSIBLE
- if(dwChannelMask == 0 && (sf == SF_PCM24 || sf == SF_PCM32))
+ if(dwChannelMask == 0 && (sf == SF_PCM24 || sf == SF_PCM32)) {
dwChannelMask = nChannels == 2 ? (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT) : SPEAKER_FRONT_CENTER;
+ }
- if(dwChannelMask)
- {
+ if(dwChannelMask) {
wfex.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
wfex.Format.cbSize = sizeof(wfex) - sizeof(wfex.Format);
wfex.dwChannelMask = dwChannelMask;
@@ -2105,14 +2073,12 @@ CMediaType CMpaDecFilter::CreateMediaTypeSPDIF()
HRESULT CMpaDecFilter::CheckInputType(const CMediaType* mtIn)
{
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_LPCM
- if(mtIn->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO)
- {
+ if(mtIn->subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mtIn->Format();
- if(wfe->nChannels < 1 || wfe->nChannels > 8 || (wfe->wBitsPerSample != 16 && wfe->wBitsPerSample != 20 && wfe->wBitsPerSample != 24))
+ if(wfe->nChannels < 1 || wfe->nChannels > 8 || (wfe->wBitsPerSample != 16 && wfe->wBitsPerSample != 20 && wfe->wBitsPerSample != 24)) {
return VFW_E_TYPE_NOT_ACCEPTED;
- }
- else if(mtIn->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO)
- {
+ }
+ } else if(mtIn->subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mtIn->Format();
UNUSED_ALWAYS(wfe);
return S_OK;
@@ -2121,46 +2087,45 @@ HRESULT CMpaDecFilter::CheckInputType(const CMediaType* mtIn)
if(0) {}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_PS2AUD
- else if(mtIn->subtype == MEDIASUBTYPE_PS2_ADPCM)
- {
+ else if(mtIn->subtype == MEDIASUBTYPE_PS2_ADPCM) {
WAVEFORMATEXPS2* wfe = (WAVEFORMATEXPS2*)mtIn->Format();
UNUSED_ALWAYS(wfe);
- if(wfe->dwInterleave & 0xf) // has to be a multiple of the block size (16 bytes)
+ if(wfe->dwInterleave & 0xf) { // has to be a multiple of the block size (16 bytes)
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
- else if(mtIn->subtype == MEDIASUBTYPE_Vorbis2)
- {
- if(!m_vorbis.init(*mtIn))
+ else if(mtIn->subtype == MEDIASUBTYPE_Vorbis2) {
+ if(!m_vorbis.init(*mtIn)) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
- else if(mtIn->subtype == MEDIASUBTYPE_FLAC_FRAMED)
- {
+ else if(mtIn->subtype == MEDIASUBTYPE_FLAC_FRAMED) {
return S_OK;
}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_NELLYMOSER
- else if(mtIn->subtype == MEDIASUBTYPE_NELLYMOSER)
- {
+ else if(mtIn->subtype == MEDIASUBTYPE_NELLYMOSER) {
return S_OK;
}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AAC
- else if(mtIn->subtype == MEDIASUBTYPE_AAC)
- {
+ else if(mtIn->subtype == MEDIASUBTYPE_AAC) {
// Reject invalid AAC stream on connection
- if (!m_aac_state.init(*mtIn)) return VFW_E_TYPE_NOT_ACCEPTED;
+ if (!m_aac_state.init(*mtIn)) {
+ return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
#endif
- for(int i = 0; i < countof(sudPinTypesIn); i++)
- {
+ for(int i = 0; i < countof(sudPinTypesIn); i++) {
if(*sudPinTypesIn[i].clsMajorType == mtIn->majortype
- && *sudPinTypesIn[i].clsMinorType == mtIn->subtype)
+ && *sudPinTypesIn[i].clsMinorType == mtIn->subtype) {
return S_OK;
+ }
}
return VFW_E_TYPE_NOT_ACCEPTED;
@@ -2177,7 +2142,9 @@ HRESULT CMpaDecFilter::CheckTransform(const CMediaType* mtIn, const CMediaType*
HRESULT CMpaDecFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
CMediaType& mt = m_pInput->CurrentMediaType();
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
@@ -2191,8 +2158,9 @@ HRESULT CMpaDecFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PRO
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
? E_FAIL
@@ -2201,36 +2169,41 @@ HRESULT CMpaDecFilter::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PRO
HRESULT CMpaDecFilter::GetMediaType(int iPosition, CMediaType* pmt)
{
- if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED;
+ if(m_pInput->IsConnected() == FALSE) {
+ return E_UNEXPECTED;
+ }
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
CMediaType mt = m_pInput->CurrentMediaType();
const GUID& subtype = mt.subtype;
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
- if (wfe == NULL) return E_INVALIDARG;
+ if (wfe == NULL) {
+ return E_INVALIDARG;
+ }
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AC3 | INTERNAL_DECODER_DTS
if(GetSpeakerConfig(ac3) < 0 && (subtype == MEDIASUBTYPE_DOLBY_AC3 ||
subtype == MEDIASUBTYPE_WAVE_DOLBY_AC3 ||
subtype == MEDIASUBTYPE_DOLBY_DDPLUS ||
subtype == MEDIASUBTYPE_DOLBY_TRUEHD)
- || GetSpeakerConfig(dts) < 0 && (subtype == MEDIASUBTYPE_DTS || subtype == MEDIASUBTYPE_WAVE_DTS))
- {
+ || GetSpeakerConfig(dts) < 0 && (subtype == MEDIASUBTYPE_DTS || subtype == MEDIASUBTYPE_WAVE_DTS)) {
*pmt = CreateMediaTypeSPDIF();
}
#else
if(0) {}
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
- else if(subtype == MEDIASUBTYPE_Vorbis2)
- {
+ else if(subtype == MEDIASUBTYPE_Vorbis2) {
*pmt = CreateMediaType(GetSampleFormat(), m_vorbis.vi.rate, m_vorbis.vi.channels);
}
#endif
- else
- {
+ else {
*pmt = CreateMediaType(GetSampleFormat(), wfe->nSamplesPerSec, min(2, wfe->nChannels));
}
@@ -2240,7 +2213,9 @@ HRESULT CMpaDecFilter::GetMediaType(int iPosition, CMediaType* pmt)
HRESULT CMpaDecFilter::StartStreaming()
{
HRESULT hr = __super::StartStreaming();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AC3
m_a52_state = a52_init(0);
@@ -2316,7 +2291,9 @@ STDMETHODIMP_(MPCSampleFormat) CMpaDecFilter::GetSampleFormat()
STDMETHODIMP CMpaDecFilter::SetNormalize(bool fNormalize)
{
CAutoLock cAutoLock(&m_csProps);
- if(m_fNormalize != fNormalize) m_sample_max = 0.1f;
+ if(m_fNormalize != fNormalize) {
+ m_sample_max = 0.1f;
+ }
m_fNormalize = fNormalize;
return S_OK;
}
@@ -2330,29 +2307,38 @@ STDMETHODIMP_(bool) CMpaDecFilter::GetNormalize()
STDMETHODIMP CMpaDecFilter::SetSpeakerConfig(enctype et, int sc)
{
CAutoLock cAutoLock(&m_csProps);
- if(et >= 0 && et < etlast) m_iSpeakerConfig[et] = sc;
+ if(et >= 0 && et < etlast) {
+ m_iSpeakerConfig[et] = sc;
+ }
return S_OK;
}
STDMETHODIMP_(int) CMpaDecFilter::GetSpeakerConfig(enctype et)
{
CAutoLock cAutoLock(&m_csProps);
- if(et >= 0 && et < etlast) return m_iSpeakerConfig[et];
+ if(et >= 0 && et < etlast) {
+ return m_iSpeakerConfig[et];
+ }
return -1;
}
STDMETHODIMP CMpaDecFilter::SetDynamicRangeControl(enctype et, bool fDRC)
{
CAutoLock cAutoLock(&m_csProps);
- if(et >= 0 && et < etlast) m_fDynamicRangeControl[et] = fDRC;
- else return E_INVALIDARG;
+ if(et >= 0 && et < etlast) {
+ m_fDynamicRangeControl[et] = fDRC;
+ } else {
+ return E_INVALIDARG;
+ }
return S_OK;
}
STDMETHODIMP_(bool) CMpaDecFilter::GetDynamicRangeControl(enctype et)
{
CAutoLock cAutoLock(&m_csProps);
- if(et >= 0 && et < etlast) return m_fDynamicRangeControl[et];
+ if(et >= 0 && et < etlast) {
+ return m_fDynamicRangeControl[et];
+ }
return false;
}
@@ -2379,8 +2365,7 @@ STDMETHODIMP CMpaDecFilter::SaveSettings()
{
CAutoLock cAutoLock(&m_csProps);
CRegKey key;
- if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Audio Decoder")))
- {
+ if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Audio Decoder"))) {
key.SetDWORDValue(_T("SampleFormat"), m_iSampleFormat);
key.SetDWORDValue(_T("Normalize"), m_fNormalize);
key.SetDWORDValue(_T("Boost"), *(DWORD*)&m_boost);
@@ -2411,12 +2396,13 @@ STDMETHODIMP CMpaDecFilter::CreatePage(const GUID& guid, IPropertyPage** ppPage)
{
CheckPointer(ppPage, E_POINTER);
- if(*ppPage != NULL) return E_INVALIDARG;
+ if(*ppPage != NULL) {
+ return E_INVALIDARG;
+ }
HRESULT hr;
- if(guid == __uuidof(CMpaDecSettingsWnd))
- {
+ if(guid == __uuidof(CMpaDecSettingsWnd)) {
(*ppPage = DNew CInternalPropertyPageTempl<CMpaDecSettingsWnd>(NULL, &hr))->AddRef();
}
@@ -2437,10 +2423,12 @@ CMpaDecInputPin::CMpaDecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR
// aac_state_t
//
-aac_state_t::aac_state_t() : h(NULL), freq(0), channels(0) {
+aac_state_t::aac_state_t() : h(NULL), freq(0), channels(0)
+{
open();
}
-aac_state_t::~aac_state_t() {
+aac_state_t::~aac_state_t()
+{
close();
}
@@ -2448,7 +2436,9 @@ bool aac_state_t::open()
{
close();
h = NeAACDecOpen();
- if(!h) return false;
+ if(!h) {
+ return false;
+ }
NeAACDecConfigurationPtr c = NeAACDecGetCurrentConfiguration(h);
c->outputFormat = FAAD_FMT_FLOAT;
NeAACDecSetConfiguration(h, c);
@@ -2457,16 +2447,19 @@ bool aac_state_t::open()
void aac_state_t::close()
{
- if(h) NeAACDecClose(h);
+ if(h) {
+ NeAACDecClose(h);
+ }
h = NULL;
}
bool aac_state_t::init(const CMediaType& mt)
{
if(mt.subtype != MEDIASUBTYPE_AAC
- && mt.subtype != MEDIASUBTYPE_MP4A
- && mt.subtype != MEDIASUBTYPE_mp4a)
- return true; // nothing to do
+ && mt.subtype != MEDIASUBTYPE_MP4A
+ && mt.subtype != MEDIASUBTYPE_mp4a) {
+ return true; // nothing to do
+ }
open();
const WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
@@ -2502,8 +2495,9 @@ void vorbis_state_t::clear()
bool vorbis_state_t::init(const CMediaType& mt)
{
- if(mt.subtype != MEDIASUBTYPE_Vorbis2)
- return true; // nothing to do
+ if(mt.subtype != MEDIASUBTYPE_Vorbis2) {
+ return true; // nothing to do
+ }
clear();
@@ -2521,8 +2515,9 @@ bool vorbis_state_t::init(const CMediaType& mt)
op.b_o_s = 1;
op.packetno = packetno++;
- if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0)
+ if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0) {
return false;
+ }
memset(&op, 0, sizeof(op));
op.packet = (fmt += vf->HeaderSize[0]);
@@ -2530,8 +2525,9 @@ bool vorbis_state_t::init(const CMediaType& mt)
op.b_o_s = 0;
op.packetno = packetno++;
- if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0)
+ if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0) {
return false;
+ }
memset(&op, 0, sizeof(op));
op.packet = (fmt += vf->HeaderSize[1]);
@@ -2539,19 +2535,23 @@ bool vorbis_state_t::init(const CMediaType& mt)
op.b_o_s = 0;
op.packetno = packetno++;
- if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0)
+ if(vorbis_synthesis_headerin(&vi, &vc, &op) < 0) {
return false;
+ }
postgain = 1.0;
- if(vorbis_comment_query_count(&vc, "LWING_GAIN"))
+ if(vorbis_comment_query_count(&vc, "LWING_GAIN")) {
postgain = atof(vorbis_comment_query(&vc, "LWING_GAIN", 0));
+ }
- if(vorbis_comment_query_count(&vc, "POSTGAIN"))
+ if(vorbis_comment_query_count(&vc, "POSTGAIN")) {
postgain = atof(vorbis_comment_query(&vc, "POSTGAIN", 0));
+ }
- if(vorbis_comment_query_count(&vc, "REPLAYGAIN_TRACK_GAIN"))
+ if(vorbis_comment_query_count(&vc, "REPLAYGAIN_TRACK_GAIN")) {
postgain = pow(10.0, atof(vorbis_comment_query(&vc, "REPLAYGAIN_TRACK_GAIN", 0)) / 20.0);
+ }
vorbis_synthesis_init(&vd, &vi);
vorbis_block_init(&vd, &vb);
@@ -2568,8 +2568,7 @@ void CMpaDecFilter::FlacFillBuffer(BYTE buffer[], size_t *bytes)
{
UINT nSize = min (*bytes, m_buff.GetCount());
- if (nSize > 0)
- {
+ if (nSize > 0) {
memcpy_s (buffer, *bytes, m_buff.GetData(), nSize);
memmove(m_buff.GetData(), m_buff.GetData() + nSize, m_buff.GetCount() - nSize);
m_buff.SetCount(m_buff.GetCount() - nSize);
@@ -2588,31 +2587,26 @@ void CMpaDecFilter::FlacDeliverBuffer (unsigned blocksize, const __int32 * cons
scmap_t& scmap = m_scmap_default[wfein->nChannels-1];
- switch (wfein->wBitsPerSample)
- {
- case 16 :
- for(unsigned i = 0; i < blocksize; i++)
- {
- for(int nChannel = 0; nChannel < wfein->nChannels; nChannel++)
- {
- FLAC__int16 nVal = (FLAC__int16)buffer[nChannel][i];
- *pDataOut = (float)nVal / SHRT_MAX;
- pDataOut++;
+ switch (wfein->wBitsPerSample) {
+ case 16 :
+ for(unsigned i = 0; i < blocksize; i++) {
+ for(int nChannel = 0; nChannel < wfein->nChannels; nChannel++) {
+ FLAC__int16 nVal = (FLAC__int16)buffer[nChannel][i];
+ *pDataOut = (float)nVal / SHRT_MAX;
+ pDataOut++;
+ }
}
- }
- break;
- case 20 :
- case 24 :
- for(unsigned i = 0; i < blocksize; i++)
- {
- for(int nChannel = 0; nChannel < wfein->nChannels; nChannel++)
- {
- FLAC__int32 nVal = (FLAC__int32)buffer[nChannel][i];
- *pDataOut = (float)nVal / INT24_MAX;
- pDataOut++;
+ break;
+ case 20 :
+ case 24 :
+ for(unsigned i = 0; i < blocksize; i++) {
+ for(int nChannel = 0; nChannel < wfein->nChannels; nChannel++) {
+ FLAC__int32 nVal = (FLAC__int32)buffer[nChannel][i];
+ *pDataOut = (float)nVal / INT24_MAX;
+ pDataOut++;
+ }
}
- }
- break;
+ break;
}
m_flac.hr = Deliver(pBuff, wfein->nSamplesPerSec, wfein->nChannels, scmap.dwChannelMask);
@@ -2648,11 +2642,9 @@ static void StreamDecoderMetadata(const FLAC__StreamDecoder *decoder, const FLAC
void CMpaDecFilter::FlacInitDecoder()
{
- if (!m_flac.pDecoder)
- {
+ if (!m_flac.pDecoder) {
m_flac.pDecoder = FLAC__stream_decoder_new();
- if (m_flac.pDecoder)
- {
+ if (m_flac.pDecoder) {
FLAC__stream_decoder_init_stream ((FLAC__StreamDecoder*)m_flac.pDecoder,
StreamDecoderRead,
NULL,
@@ -2664,9 +2656,7 @@ void CMpaDecFilter::FlacInitDecoder()
StreamDecoderError,
this);
}
- }
- else
- {
+ } else {
FLAC__stream_decoder_reset ((FLAC__StreamDecoder*)m_flac.pDecoder);
}
}
@@ -2674,8 +2664,7 @@ void CMpaDecFilter::FlacInitDecoder()
void CMpaDecFilter::flac_stream_finish()
{
- if (m_flac.pDecoder)
- {
+ if (m_flac.pDecoder) {
FLAC__stream_decoder_delete ((FLAC__StreamDecoder*)m_flac.pDecoder);
m_flac.pDecoder = NULL;
}
@@ -2697,93 +2686,86 @@ HRESULT CMpaDecFilter::DeliverFFmpeg(int nCodecId, BYTE* p, int buffsize, int& s
size = 0;
if (!m_pAVCtx || nCodecId != m_pAVCtx->codec_id)
- if (!InitFFmpeg (nCodecId)) return E_FAIL;
+ if (!InitFFmpeg (nCodecId)) {
+ return E_FAIL;
+ }
- while (buffsize > 0)
- {
+ while (buffsize > 0) {
BYTE* pParserData;
int nParserLength = AVCODEC_MAX_AUDIO_FRAME_SIZE;
int nPCMLength = AVCODEC_MAX_AUDIO_FRAME_SIZE;
int nRet;
- if (m_pAVCtx->codec_id != CODEC_ID_MLP)
- {
+ if (m_pAVCtx->codec_id != CODEC_ID_MLP) {
// Parse buffer
nRet = av_parser_parse( m_pParser, m_pAVCtx, (uint8_t**)&pParserData, &nParserLength,
(const uint8_t*)p, buffsize, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
- if (nRet<0 || (nRet==0 && nParserLength==0))
+ if (nRet<0 || (nRet==0 && nParserLength==0)) {
return S_OK;
+ }
buffsize -= nRet;
p += nRet;
size += nRet;
// Decode frame
- if (nParserLength > 0)
- {
+ if (nParserLength > 0) {
nRet = avcodec_decode_audio2(m_pAVCtx, (int16_t*)m_pPCMData, &nPCMLength, (const uint8_t*)pParserData, nParserLength);
- if (nRet<0 || (nRet==0 &&nPCMLength==0))
+ if (nRet<0 || (nRet==0 &&nPCMLength==0)) {
continue;
- }
- else
+ }
+ } else {
continue;
- }
- else
- {
+ }
+ } else {
// No parsing for MLP : decode only
nRet = avcodec_decode_audio2(m_pAVCtx, (int16_t*)m_pPCMData, &nPCMLength, (const uint8_t*)p, buffsize);
- if (nRet<0 || (nRet==0 && nParserLength==0))
+ if (nRet<0 || (nRet==0 && nParserLength==0)) {
return S_OK;
+ }
buffsize -= nRet;
p += nRet;
size += nRet;
}
- if (nPCMLength > 0)
- {
+ if (nPCMLength > 0) {
WAVEFORMATEX* wfein = (WAVEFORMATEX*)m_pInput->CurrentMediaType().Format();
CAtlArray<float> pBuff;
int nRemap;
float* pDataOut;
nRemap = FFGetChannelMap (m_pAVCtx);
- if (nRemap >=0)
- {
+ if (nRemap >=0) {
scmap_t& scmap = s_scmap_ac3[nRemap];
- switch (m_pAVCtx->sample_fmt)
- {
- case SAMPLE_FMT_S16 :
- pBuff.SetCount (nPCMLength / 2);
- pDataOut = pBuff.GetData();
-
- for (int i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++)
- {
- for(int ch=0; ch<m_pAVCtx->channels; ch++)
- {
- *pDataOut = (float)((int16_t*)m_pPCMData) [scmap.ch[ch]+i*m_pAVCtx->channels] / SHRT_MAX;
- pDataOut++;
+ switch (m_pAVCtx->sample_fmt) {
+ case SAMPLE_FMT_S16 :
+ pBuff.SetCount (nPCMLength / 2);
+ pDataOut = pBuff.GetData();
+
+ for (int i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++) {
+ for(int ch=0; ch<m_pAVCtx->channels; ch++) {
+ *pDataOut = (float)((int16_t*)m_pPCMData) [scmap.ch[ch]+i*m_pAVCtx->channels] / SHRT_MAX;
+ pDataOut++;
+ }
}
- }
- break;
+ break;
- case SAMPLE_FMT_S32 :
- pBuff.SetCount (nPCMLength / 4);
- pDataOut = pBuff.GetData();
+ case SAMPLE_FMT_S32 :
+ pBuff.SetCount (nPCMLength / 4);
+ pDataOut = pBuff.GetData();
- for (int i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++)
- {
- for(int ch=0; ch<m_pAVCtx->channels; ch++)
- {
- *pDataOut = (float)((int32_t*)m_pPCMData) [scmap.ch[ch]+i*m_pAVCtx->channels] / INT_MAX;
- pDataOut++;
+ for (int i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++) {
+ for(int ch=0; ch<m_pAVCtx->channels; ch++) {
+ *pDataOut = (float)((int32_t*)m_pPCMData) [scmap.ch[ch]+i*m_pAVCtx->channels] / INT_MAX;
+ pDataOut++;
+ }
}
- }
- break;
- default :
- ASSERT(FALSE);
- break;
+ break;
+ default :
+ ASSERT(FALSE);
+ break;
}
hr = Deliver(pBuff, m_pAVCtx->sample_rate, m_pAVCtx->channels, scmap.dwChannelMask);
}
@@ -2801,8 +2783,7 @@ HRESULT CMpaDecFilter::DeliverFFmpeg(int nCodecId, BYTE* p, int buffsize, int& s
HRESULT hr = S_OK;
int nPCMLength = 0;
if (!m_pAVCtx || nCodecId != m_pAVCtx->codec_id)
- if (!InitFFmpeg (nCodecId))
- {
+ if (!InitFFmpeg (nCodecId)) {
size = 0;
return E_FAIL;
}
@@ -2810,14 +2791,12 @@ HRESULT CMpaDecFilter::DeliverFFmpeg(int nCodecId, BYTE* p, int buffsize, int& s
CAtlArray<float> pBuffOut;
scmap_t* scmap = NULL;
- AVPacket avpkt;
- av_init_packet(&avpkt);
+ AVPacket avpkt;
+ av_init_packet(&avpkt);
- while (buffsize > 0)
- {
+ while (buffsize > 0) {
nPCMLength = AVCODEC_MAX_AUDIO_FRAME_SIZE;
- if (buffsize+FF_INPUT_BUFFER_PADDING_SIZE > m_nFFBufferSize)
- {
+ if (buffsize+FF_INPUT_BUFFER_PADDING_SIZE > m_nFFBufferSize) {
m_nFFBufferSize = buffsize+FF_INPUT_BUFFER_PADDING_SIZE;
m_pFFBuffer = (BYTE*)realloc(m_pFFBuffer, m_nFFBufferSize);
@@ -2846,60 +2825,52 @@ HRESULT CMpaDecFilter::DeliverFFmpeg(int nCodecId, BYTE* p, int buffsize, int& s
}
size += used_byte;//
- if ( nPCMLength>0)
- {
+ if ( nPCMLength>0) {
WAVEFORMATEX* wfein = (WAVEFORMATEX*)m_pInput->CurrentMediaType().Format();
CAtlArray<float> pBuff;
int nRemap;
float* pDataOut;
nRemap = FFGetChannelMap (m_pAVCtx);
- if (nRemap >=0)
- {
+ if (nRemap >=0) {
- switch (nCodecId)
- {
- case CODEC_ID_EAC3 :
- scmap = &m_ffmpeg_ac3[FFGetChannelMap(m_pAVCtx)];
- break;
- default :
- scmap = &m_scmap_default[m_pAVCtx->channels-1];
- break;
+ switch (nCodecId) {
+ case CODEC_ID_EAC3 :
+ scmap = &m_ffmpeg_ac3[FFGetChannelMap(m_pAVCtx)];
+ break;
+ default :
+ scmap = &m_scmap_default[m_pAVCtx->channels-1];
+ break;
}
- switch (m_pAVCtx->sample_fmt)
- {
- case SAMPLE_FMT_S16 :
- pBuff.SetCount (nPCMLength / 2);
- pDataOut = pBuff.GetData();
-
- for (size_t i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++)
- {
- for(int ch=0; ch<m_pAVCtx->channels; ch++)
- {
- *pDataOut = (float)((int16_t*)m_pPCMData) [scmap->ch[ch]+i*m_pAVCtx->channels] / SHRT_MAX;
- pDataOut++;
+ switch (m_pAVCtx->sample_fmt) {
+ case SAMPLE_FMT_S16 :
+ pBuff.SetCount (nPCMLength / 2);
+ pDataOut = pBuff.GetData();
+
+ for (size_t i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++) {
+ for(int ch=0; ch<m_pAVCtx->channels; ch++) {
+ *pDataOut = (float)((int16_t*)m_pPCMData) [scmap->ch[ch]+i*m_pAVCtx->channels] / SHRT_MAX;
+ pDataOut++;
+ }
}
- }
- break;
+ break;
- case SAMPLE_FMT_S32 :
- pBuff.SetCount (nPCMLength / 4);
- pDataOut = pBuff.GetData();
+ case SAMPLE_FMT_S32 :
+ pBuff.SetCount (nPCMLength / 4);
+ pDataOut = pBuff.GetData();
- for (size_t i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++)
- {
- for(int ch=0; ch<m_pAVCtx->channels; ch++)
- {
- *pDataOut = (float)((int32_t*)m_pPCMData) [scmap->ch[ch]+i*m_pAVCtx->channels] / INT_MAX;
- pDataOut++;
+ for (size_t i=0; i<pBuff.GetCount()/m_pAVCtx->channels; i++) {
+ for(int ch=0; ch<m_pAVCtx->channels; ch++) {
+ *pDataOut = (float)((int32_t*)m_pPCMData) [scmap->ch[ch]+i*m_pAVCtx->channels] / INT_MAX;
+ pDataOut++;
+ }
}
- }
- break;
- default :
- ASSERT(FALSE);
- break;
+ break;
+ default :
+ ASSERT(FALSE);
+ break;
}
if(pBuff.GetCount() > 0) {
@@ -2916,8 +2887,9 @@ HRESULT CMpaDecFilter::DeliverFFmpeg(int nCodecId, BYTE* p, int buffsize, int& s
buffsize -= used_byte;
pDataInBuff += used_byte;
}
- if(pBuffOut.GetCount() > 0 && scmap)
+ if(pBuffOut.GetCount() > 0 && scmap) {
hr = Deliver(pBuffOut, m_pAVCtx->sample_rate, scmap->nChannels, scmap->dwChannelMask);
+ }
return hr;
}
#endif
@@ -2933,13 +2905,13 @@ bool CMpaDecFilter::InitFFmpeg(int nCodecId)
av_log_set_callback(LogLibAVCodec);
#endif
- if (m_pAVCodec) ffmpeg_stream_finish();
+ if (m_pAVCodec) {
+ ffmpeg_stream_finish();
+ }
m_pAVCodec = avcodec_find_decoder((CodecID)nCodecId);
- if (m_pAVCodec)
- {
- if (nCodecId==CODEC_ID_AMR_NB || nCodecId== CODEC_ID_AMR_WB)
- {
+ if (m_pAVCodec) {
+ if (nCodecId==CODEC_ID_AMR_NB || nCodecId== CODEC_ID_AMR_WB) {
wfein->nChannels = 1;
wfein->nSamplesPerSec = 8000;
}
@@ -2955,14 +2927,15 @@ bool CMpaDecFilter::InitFFmpeg(int nCodecId)
m_pAVCtx->codec_id = (CodecID)nCodecId;
m_pParser = av_parser_init(nCodecId);
- if (avcodec_open(m_pAVCtx,m_pAVCodec)>=0)
- {
+ if (avcodec_open(m_pAVCtx,m_pAVCodec)>=0) {
m_pPCMData = (BYTE*)FF_aligned_malloc (AVCODEC_MAX_AUDIO_FRAME_SIZE+FF_INPUT_BUFFER_PADDING_SIZE, 64);
bRet = true;
}
}
- if (!bRet) ffmpeg_stream_finish();
+ if (!bRet) {
+ ffmpeg_stream_finish();
+ }
return bRet;
}
@@ -2977,20 +2950,20 @@ void CMpaDecFilter::LogLibAVCodec(void* par,int level,const char *fmt,va_list va
void CMpaDecFilter::ffmpeg_stream_finish()
{
m_pAVCodec = NULL;
- if (m_pAVCtx)
- {
+ if (m_pAVCtx) {
avcodec_close (m_pAVCtx);
av_free (m_pAVCtx);
m_pAVCtx = NULL;
}
- if (m_pParser)
- {
+ if (m_pParser) {
av_parser_close (m_pParser);
m_pParser = NULL;
}
- if (m_pPCMData) FF_aligned_free (m_pPCMData);
+ if (m_pPCMData) {
+ FF_aligned_free (m_pPCMData);
+ }
}
#pragma endregion
diff --git a/src/filters/transform/MpaDecFilter/MpaDecFilter.h b/src/filters/transform/MpaDecFilter/MpaDecFilter.h
index 16dc0c509..b26f98c82 100644
--- a/src/filters/transform/MpaDecFilter/MpaDecFilter.h
+++ b/src/filters/transform/MpaDecFilter/MpaDecFilter.h
@@ -38,8 +38,7 @@
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AAC
-struct aac_state_t
-{
+struct aac_state_t {
void* h; // NeAACDecHandle h;
DWORD freq;
BYTE channels;
@@ -52,8 +51,7 @@ struct aac_state_t
};
#endif
-struct ps2_state_t
-{
+struct ps2_state_t {
bool sync;
double a[2], b[2];
ps2_state_t() {
@@ -66,8 +64,7 @@ struct ps2_state_t
};
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
-struct vorbis_state_t
-{
+struct vorbis_state_t {
vorbis_info vi;
vorbis_comment vc;
vorbis_block vb;
@@ -84,8 +81,7 @@ struct vorbis_state_t
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
-struct flac_state_t
-{
+struct flac_state_t {
void* pDecoder;
HRESULT hr;
};
diff --git a/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.cpp b/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.cpp
index cf56cd629..cf5bc2a91 100644
--- a/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.cpp
+++ b/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.cpp
@@ -48,9 +48,13 @@ bool CMpaDecSettingsWnd::OnConnect(const CInterfaceList<IUnknown, &IID_IUnknown>
m_pMDF.Release();
POSITION pos = pUnks.GetHeadPosition();
- while(pos && !(m_pMDF = pUnks.GetNext(pos)));
+ while(pos && !(m_pMDF = pUnks.GetNext(pos))) {
+ ;
+ }
- if(!m_pMDF) return false;
+ if(!m_pMDF) {
+ return false;
+ }
m_outputformat = m_pMDF->GetSampleFormat();
m_ac3spkcfg = m_pMDF->GetSpeakerConfig(IMpaDecFilter::ac3);
@@ -70,18 +74,17 @@ void CMpaDecSettingsWnd::OnDisconnect()
LPCTSTR CMpaDecSettingsWnd::GetDolbyMode (DolbyDigitalMode ddmode)
{
- switch (ddmode)
- {
- case DD_AC3 :
- return _T(" (AC3)");
- case DD_EAC3 :
- return _T(" (Dolby Digital Plus)");
- case DD_TRUEHD :
- return _T(" (Dolby True HD)");
- case DD_MLP :
- return _T(" (MLP)");
- default :
- return _T("");
+ switch (ddmode) {
+ case DD_AC3 :
+ return _T(" (AC3)");
+ case DD_EAC3 :
+ return _T(" (Dolby Digital Plus)");
+ case DD_TRUEHD :
+ return _T(" (Dolby True HD)");
+ case DD_MLP :
+ return _T(" (MLP)");
+ default :
+ return _T("");
}
}
@@ -105,8 +108,9 @@ bool CMpaDecSettingsWnd::OnActivate()
m_outputformat_combo.SetCurSel(0);
for(int i = 0; i < m_outputformat_combo.GetCount(); i++)
- if((int)m_outputformat_combo.GetItemData(i) == m_outputformat)
+ if((int)m_outputformat_combo.GetItemData(i) == m_outputformat) {
m_outputformat_combo.SetCurSel(i);
+ }
p.y += 30;
@@ -130,8 +134,9 @@ bool CMpaDecSettingsWnd::OnActivate()
m_ac3spkcfg_combo.SetItemData(m_ac3spkcfg_combo.AddString(ResStr(IDS_MPA_CHANNEL_2)), A52_CHANNEL2);
for(int i = 0, sel = abs(m_ac3spkcfg) & A52_CHANNEL_MASK; i < m_ac3spkcfg_combo.GetCount(); i++)
- if((int)m_ac3spkcfg_combo.GetItemData(i) == sel)
+ if((int)m_ac3spkcfg_combo.GetItemData(i) == sel) {
m_ac3spkcfg_combo.SetCurSel(i);
+ }
m_ac3spkcfg_combo.GetWindowRect(r);
ScreenToClient(r);
@@ -139,8 +144,7 @@ bool CMpaDecSettingsWnd::OnActivate()
m_ac3lfe_check.Create(_T("LFE"), dwStyle|BS_AUTOCHECKBOX, CRect(CPoint(r.left, r.bottom + 3), CSize(50, m_fontheight)), this, IDC_PP_CHECK4);
m_ac3lfe_check.SetCheck(!!(abs(m_ac3spkcfg) & A52_LFE));
- for(int i = 0, h = max(20, m_fontheight)+1; i < countof(m_ac3spkcfg_radio); i++, p.y += h)
- {
+ for(int i = 0, h = max(20, m_fontheight)+1; i < countof(m_ac3spkcfg_radio); i++, p.y += h) {
static const TCHAR* labels[] = {m_strDecodeToSpeaker, _T("SPDIF")};
m_ac3spkcfg_radio[i].Create(labels[i], dwStyle|BS_AUTORADIOBUTTON|(i == 0 ? WS_GROUP : 0), CRect(p + CPoint(10, 0), CSize(140, h)), this, IDC_PP_RADIO1+i);
}
@@ -171,8 +175,9 @@ bool CMpaDecSettingsWnd::OnActivate()
m_dtsspkcfg_combo.SetItemData(m_dtsspkcfg_combo.AddString(ResStr(IDS_MPA_3F_2R)), DTS_3F2R);
for(int i = 0, sel = abs(m_dtsspkcfg) & DTS_CHANNEL_MASK; i < m_dtsspkcfg_combo.GetCount(); i++)
- if((int)m_dtsspkcfg_combo.GetItemData(i) == sel)
+ if((int)m_dtsspkcfg_combo.GetItemData(i) == sel) {
m_dtsspkcfg_combo.SetCurSel(i);
+ }
m_dtsspkcfg_combo.GetWindowRect(r);
ScreenToClient(r);
@@ -180,8 +185,7 @@ bool CMpaDecSettingsWnd::OnActivate()
m_dtslfe_check.Create(_T("LFE"), dwStyle|BS_AUTOCHECKBOX, CRect(CPoint(r.left, r.bottom + 3), CSize(50, m_fontheight)), this, IDC_PP_CHECK5);
m_dtslfe_check.SetCheck(!!(abs(m_dtsspkcfg) & DTS_LFE));
- for(int i = 0, h = max(20, m_fontheight)+1; i < countof(m_dtsspkcfg_radio); i++, p.y += h)
- {
+ for(int i = 0, h = max(20, m_fontheight)+1; i < countof(m_dtsspkcfg_radio); i++, p.y += h) {
static const TCHAR* labels[] = {m_strDecodeToSpeaker, _T("SPDIF")};
m_dtsspkcfg_radio[i].Create(labels[i], dwStyle|BS_AUTORADIOBUTTON|(i == 0 ? WS_GROUP : 0), CRect(p + CPoint(10, 0), CSize(140, h)), this, IDC_PP_RADIO3+i);
}
@@ -202,8 +206,9 @@ bool CMpaDecSettingsWnd::OnActivate()
m_aacdownmix_check.Create(ResStr(IDS_MPADECSETTINGSWND_12), dwStyle|BS_AUTOCHECKBOX, CRect(p + CPoint(10, 0), CSize(150, m_fontheight)), this, IDC_PP_CHECK3);
m_aacdownmix_check.SetCheck(m_aacdownmix);
- for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow())
+ for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
pWnd->SetFont(&m_font, FALSE);
+ }
return true;
}
@@ -212,12 +217,20 @@ void CMpaDecSettingsWnd::OnDeactivate()
{
m_outputformat = m_outputformat_combo.GetItemData(m_outputformat_combo.GetCurSel());
m_ac3spkcfg = m_ac3spkcfg_combo.GetItemData(m_ac3spkcfg_combo.GetCurSel());
- if(!!m_ac3lfe_check.GetCheck()) m_ac3spkcfg |= A52_LFE;
- if(IsDlgButtonChecked(IDC_PP_RADIO2)) m_ac3spkcfg = -m_ac3spkcfg;
+ if(!!m_ac3lfe_check.GetCheck()) {
+ m_ac3spkcfg |= A52_LFE;
+ }
+ if(IsDlgButtonChecked(IDC_PP_RADIO2)) {
+ m_ac3spkcfg = -m_ac3spkcfg;
+ }
m_ac3drc = !!m_ac3spkcfg_check.GetCheck();
m_dtsspkcfg = m_dtsspkcfg_combo.GetItemData(m_dtsspkcfg_combo.GetCurSel());
- if(!!m_dtslfe_check.GetCheck()) m_dtsspkcfg |= DTS_LFE;
- if(IsDlgButtonChecked(IDC_PP_RADIO4)) m_dtsspkcfg = -m_dtsspkcfg;
+ if(!!m_dtslfe_check.GetCheck()) {
+ m_dtsspkcfg |= DTS_LFE;
+ }
+ if(IsDlgButtonChecked(IDC_PP_RADIO4)) {
+ m_dtsspkcfg = -m_dtsspkcfg;
+ }
m_dtsdrc = !!m_dtsspkcfg_check.GetCheck();
m_aacdownmix = !!m_aacdownmix_check.GetCheck();
}
@@ -226,8 +239,7 @@ bool CMpaDecSettingsWnd::OnApply()
{
OnDeactivate();
- if(m_pMDF)
- {
+ if(m_pMDF) {
m_pMDF->SetSampleFormat((MPCSampleFormat)m_outputformat);
m_pMDF->SetSpeakerConfig(IMpaDecFilter::ac3, m_ac3spkcfg);
m_pMDF->SetDynamicRangeControl(IMpaDecFilter::ac3, m_ac3drc);
diff --git a/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.h b/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.h
index 143369335..7e1ab6b2c 100644
--- a/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.h
+++ b/src/filters/transform/MpaDecFilter/MpaDecSettingsWnd.h
@@ -40,8 +40,7 @@ class __declspec(uuid("24103041-884B-4772-B0D3-A600E7CBFEC7"))
bool m_aacdownmix;
DolbyDigitalMode m_ddmode;
- enum
- {
+ enum {
IDC_PP_RADIO1 = 10000,
IDC_PP_RADIO2,
IDC_PP_RADIO3,
diff --git a/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h b/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h
index a36174c94..054337be6 100644
--- a/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h
+++ b/src/filters/transform/Mpeg2DecFilter/IMpeg2DecFilter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -24,8 +24,8 @@
typedef enum {DIAuto, DIWeave, DIBlend, DIBob, DIFieldShift, DIELA} ditype;
interface __declspec(uuid("0ABEAA65-0317-47B9-AE1D-D9EA905AFD25"))
-IMpeg2DecFilter : public IUnknown
-{
+IMpeg2DecFilter :
+public IUnknown {
STDMETHOD(SetDeinterlaceMethod(ditype di)) = 0;
STDMETHOD_(ditype, GetDeinterlaceMethod()) = 0;
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp
index 75f777984..d2e74b47e 100644
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp
+++ b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -40,8 +40,7 @@
#ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_DVD_ENCRYPTED_PACK, &MEDIASUBTYPE_MPEG2_VIDEO},
{&MEDIATYPE_MPEG2_PACK, &MEDIASUBTYPE_MPEG2_VIDEO},
{&MEDIATYPE_MPEG2_PES, &MEDIASUBTYPE_MPEG2_VIDEO},
@@ -52,29 +51,25 @@ const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
#endif
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_IYUV},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
- {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
- {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
+const AMOVIESETUP_PIN sudpPins[] = {
+ {L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
+ {L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
- #ifdef MPEG2ONLY
+const AMOVIESETUP_FILTER sudFilter[] = {
+#ifdef MPEG2ONLY
{&__uuidof(CMpeg2DecFilter), L"MPC - MPEG-2 Video Decoder (Gabest)", 0x00600001, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
- #else
+#else
{&__uuidof(CMpeg2DecFilter), L"MPC - MPEG Video Decoder (Gabest)", 0x00600001, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
- #endif
+#endif
};
-CFactoryTemplate g_Templates[] =
-{
- {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMpeg2DecFilter>, NULL, &sudFilter[0]},
+CFactoryTemplate g_Templates[] = {
+ {sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMpeg2DecFilter>, NULL, &sudFilter[0]},
{L"CMpeg2DecPropertyPage", &__uuidof(CMpeg2DecSettingsWnd), CreateInstance<CInternalPropertyPageTempl<CMpeg2DecSettingsWnd> >},
};
@@ -95,48 +90,42 @@ STDAPI DllUnregisterServer()
#include <detours/detours.h>
BOOL (__stdcall * Real_IsDebuggerPresent)(void)
- = IsDebuggerPresent;
+= IsDebuggerPresent;
LONG (__stdcall * Real_ChangeDisplaySettingsExA)(LPCSTR a0,
- LPDEVMODEA a1,
- HWND a2,
- DWORD a3,
- LPVOID a4)
- = ChangeDisplaySettingsExA;
+ LPDEVMODEA a1,
+ HWND a2,
+ DWORD a3,
+ LPVOID a4)
+= ChangeDisplaySettingsExA;
LONG (__stdcall * Real_ChangeDisplaySettingsExW)(LPCWSTR a0,
- LPDEVMODEW a1,
- HWND a2,
- DWORD a3,
- LPVOID a4)
- = ChangeDisplaySettingsExW;
+ LPDEVMODEW a1,
+ HWND a2,
+ DWORD a3,
+ LPVOID a4)
+= ChangeDisplaySettingsExW;
BOOL WINAPI Mine_IsDebuggerPresent()
{
- TRACE(_T("Oops, somebody was trying to be naughty! (called IsDebuggerPresent)\n"));
+ TRACE(_T("Oops, somebody was trying to be naughty! (called IsDebuggerPresent)\n"));
return FALSE;
}
LONG WINAPI Mine_ChangeDisplaySettingsEx(LONG ret, DWORD dwFlags, LPVOID lParam)
{
- if(dwFlags&CDS_VIDEOPARAMETERS)
- {
+ if(dwFlags&CDS_VIDEOPARAMETERS) {
VIDEOPARAMETERS* vp = (VIDEOPARAMETERS*)lParam;
if(vp->Guid == GUIDFromCString(_T("{02C62061-1097-11d1-920F-00A024DF156E}"))
- && (vp->dwFlags&VP_FLAGS_COPYPROTECT))
- {
- if(vp->dwCommand == VP_COMMAND_GET)
- {
- if((vp->dwTVStandard&VP_TV_STANDARD_WIN_VGA) && vp->dwTVStandard != VP_TV_STANDARD_WIN_VGA)
- {
+ && (vp->dwFlags&VP_FLAGS_COPYPROTECT)) {
+ if(vp->dwCommand == VP_COMMAND_GET) {
+ if((vp->dwTVStandard&VP_TV_STANDARD_WIN_VGA) && vp->dwTVStandard != VP_TV_STANDARD_WIN_VGA) {
TRACE(_T("Ooops, tv-out enabled? macrovision checks suck..."));
vp->dwTVStandard = VP_TV_STANDARD_WIN_VGA;
}
- }
- else if(vp->dwCommand == VP_COMMAND_SET)
- {
+ } else if(vp->dwCommand == VP_COMMAND_SET) {
TRACE(_T("Ooops, as I already told ya, no need for any macrovision bs here"));
return 0;
}
@@ -161,11 +150,12 @@ LONG WINAPI Mine_ChangeDisplaySettingsExW(LPCWSTR lpszDeviceName, LPDEVMODEW lpD
class CMpeg2DecFilterApp : public CFilterApp
{
public:
- BOOL InitInstance()
- {
+ BOOL InitInstance() {
long lError;
- if(!__super::InitInstance()) return FALSE;
+ if(!__super::InitInstance()) {
+ return FALSE;
+ }
DetourRestoreAfterWith();
DetourTransactionBegin();
@@ -190,31 +180,45 @@ CMpeg2DecFilterApp theApp;
// CMpeg2DecFilter
//
-CMpeg2DecFilter::CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr)
+CMpeg2DecFilter::CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr)
: CBaseVideoFilter(NAME("CMpeg2DecFilter"), lpunk, phr, __uuidof(this), 1)
, m_fWaitForKeyFrame(true)
, m_fInitializedBuffer(true)
{
delete m_pInput;
-// delete m_pOutput;
+ // delete m_pOutput;
- if(FAILED(*phr)) return;
+ if(FAILED(*phr)) {
+ return;
+ }
m_pInput = DNew CMpeg2DecInputPin(this, phr, L"Video");
- if(!m_pInput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!m_pInput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
-// m_pOutput = DNew CMpeg2DecOutputPin(this, phr, L"Output");
-// if(!m_pOutput) *phr = E_OUTOFMEMORY;
-// if(FAILED(*phr)) return;
+ // m_pOutput = DNew CMpeg2DecOutputPin(this, phr, L"Output");
+ // if(!m_pOutput) *phr = E_OUTOFMEMORY;
+ // if(FAILED(*phr)) return;
m_pSubpicInput = DNew CSubpicInputPin(this, phr);
- if(!m_pSubpicInput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!m_pSubpicInput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
m_pClosedCaptionOutput = DNew CClosedCaptionOutputPin(this, m_pLock, phr);
- if(!m_pClosedCaptionOutput) *phr = E_OUTOFMEMORY;
- if(FAILED(*phr)) return;
+ if(!m_pClosedCaptionOutput) {
+ *phr = E_OUTOFMEMORY;
+ }
+ if(FAILED(*phr)) {
+ return;
+ }
SetDeinterlaceMethod(DIAuto);
SetBrightness(0.0f);
@@ -227,18 +231,35 @@ CMpeg2DecFilter::CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr)
EnableReadARFromStream(true);
CRegKey key;
- if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Video Decoder"), KEY_READ))
- {
+ if(ERROR_SUCCESS == key.Open(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Video Decoder"), KEY_READ)) {
DWORD dw;
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DeinterlaceMethod"), dw)) SetDeinterlaceMethod((ditype)dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Brightness"), dw)) SetBrightness(*(float*)&dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Contrast"), dw)) SetContrast(*(float*)&dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Hue"), dw)) SetHue(*(float*)&dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Saturation"), dw)) SetSaturation(*(float*)&dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ForcedSubtitles"), dw)) EnableForcedSubtitles(!!dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("PlanarYUV"), dw)) EnablePlanarYUV(!!dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Interlaced"), dw)) EnableInterlaced(!!dw);
- if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ReadARFromStream"), dw)) EnableReadARFromStream(!!dw);
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("DeinterlaceMethod"), dw)) {
+ SetDeinterlaceMethod((ditype)dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Brightness"), dw)) {
+ SetBrightness(*(float*)&dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Contrast"), dw)) {
+ SetContrast(*(float*)&dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Hue"), dw)) {
+ SetHue(*(float*)&dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Saturation"), dw)) {
+ SetSaturation(*(float*)&dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ForcedSubtitles"), dw)) {
+ EnableForcedSubtitles(!!dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("PlanarYUV"), dw)) {
+ EnablePlanarYUV(!!dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("Interlaced"), dw)) {
+ EnableInterlaced(!!dw);
+ }
+ if(ERROR_SUCCESS == key.QueryDWORDValue(_T("ReadARFromStream"), dw)) {
+ EnableReadARFromStream(!!dw);
+ }
}
m_rate.Rate = 10000;
@@ -250,8 +271,7 @@ CMpeg2DecFilter::CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr)
CMpeg2DecFilter::~CMpeg2DecFilter()
{
CRegKey key;
- if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Video Decoder")))
- {
+ if(ERROR_SUCCESS == key.Create(HKEY_CURRENT_USER, _T("Software\\Gabest\\Filters\\MPEG Video Decoder"))) {
key.SetDWORDValue(_T("DeinterlaceMethod"), m_ditype);
key.SetDWORDValue(_T("Brightness"), *(DWORD*)&m_bright);
key.SetDWORDValue(_T("Contrast"), *(DWORD*)&m_cont);
@@ -273,7 +293,7 @@ STDMETHODIMP CMpeg2DecFilter::NonDelegatingQueryInterface(REFIID riid, void** pp
QI(IMpeg2DecFilter)
QI(ISpecifyPropertyPages)
QI(ISpecifyPropertyPages2)
- __super::NonDelegatingQueryInterface(riid, ppv);
+ __super::NonDelegatingQueryInterface(riid, ppv);
}
int CMpeg2DecFilter::GetPinCount()
@@ -283,12 +303,15 @@ int CMpeg2DecFilter::GetPinCount()
CBasePin* CMpeg2DecFilter::GetPin(int n)
{
- switch(n)
- {
- case 0: return m_pInput;
- case 1: return m_pOutput;
- case 2: return m_pSubpicInput;
- case 3: return m_pClosedCaptionOutput;
+ switch(n) {
+ case 0:
+ return m_pInput;
+ case 1:
+ return m_pOutput;
+ case 2:
+ return m_pSubpicInput;
+ case 3:
+ return m_pClosedCaptionOutput;
}
return NULL;
}
@@ -323,11 +346,10 @@ HRESULT CMpeg2DecFilter::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop,
void CMpeg2DecFilter::InputTypeChanged()
{
CAutoLock cAutoLock(&m_csReceive);
-
+
TRACE(_T("ResetMpeg2Decoder()\n"));
- for(int i = 0; i < countof(m_dec->m_pictures); i++)
- {
+ for(int i = 0; i < countof(m_dec->m_pictures); i++) {
m_dec->m_pictures[i].rtStart = m_dec->m_pictures[i].rtStop = _I64_MIN+1;
m_dec->m_pictures[i].fDelivered = false;
m_dec->m_pictures[i].flags &= ~PIC_MASK_CODING_TYPE;
@@ -338,13 +360,10 @@ void CMpeg2DecFilter::InputTypeChanged()
BYTE* pSequenceHeader = NULL;
DWORD cbSequenceHeader = 0;
- if(mt.formattype == FORMAT_MPEGVideo)
- {
+ if(mt.formattype == FORMAT_MPEGVideo) {
pSequenceHeader = ((MPEG1VIDEOINFO*)mt.Format())->bSequenceHeader;
cbSequenceHeader = ((MPEG1VIDEOINFO*)mt.Format())->cbSequenceHeader;
- }
- else if(mt.formattype == FORMAT_MPEG2_VIDEO)
- {
+ } else if(mt.formattype == FORMAT_MPEG2_VIDEO) {
pSequenceHeader = (BYTE*)((MPEG2VIDEOINFO*)mt.Format())->dwSequenceHeader;
cbSequenceHeader = ((MPEG2VIDEOINFO*)mt.Format())->cbSequenceHeader;
}
@@ -369,17 +388,13 @@ void CMpeg2DecFilter::SetDeinterlaceMethod()
DWORD oldflags = m_fb.flags;
DWORD newflags = m_dec->m_info.m_display_picture->flags;
- if(!(seqflags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
- && !(oldflags & PIC_FLAG_REPEAT_FIRST_FIELD)
- && (newflags & PIC_FLAG_PROGRESSIVE_FRAME))
- {
- if(!m_fFilm && (newflags & PIC_FLAG_REPEAT_FIRST_FIELD))
- {
+ if(!(seqflags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
+ && !(oldflags & PIC_FLAG_REPEAT_FIRST_FIELD)
+ && (newflags & PIC_FLAG_PROGRESSIVE_FRAME)) {
+ if(!m_fFilm && (newflags & PIC_FLAG_REPEAT_FIRST_FIELD)) {
TRACE(_T("m_fFilm = true\n"));
m_fFilm = true;
- }
- else if(m_fFilm && !(newflags & PIC_FLAG_REPEAT_FIRST_FIELD))
- {
+ } else if(m_fFilm && !(newflags & PIC_FLAG_REPEAT_FIRST_FIELD)) {
TRACE(_T("m_fFilm = false\n"));
m_fFilm = false;
}
@@ -387,28 +402,26 @@ void CMpeg2DecFilter::SetDeinterlaceMethod()
const CMediaType& mt = m_pOutput->CurrentMediaType();
- if(mt.formattype == FORMAT_VideoInfo2 && (((VIDEOINFOHEADER2*)mt.pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced))
- {
+ if(mt.formattype == FORMAT_VideoInfo2 && (((VIDEOINFOHEADER2*)mt.pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced)) {
m_fb.di = DIWeave;
- }
- else
- {
+ } else {
m_fb.di = GetDeinterlaceMethod();
- if(m_fb.di == DIAuto || m_fb.di != DIWeave && m_fb.di != DIBlend && m_fb.di != DIBob && m_fb.di != DIFieldShift && m_fb.di != DIELA)
- {
- if(seqflags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
- m_fb.di = DIWeave; // hurray!
- else if(m_fFilm)
- m_fb.di = DIWeave; // we are lucky
- else if(!(m_fb.flags & PIC_FLAG_PROGRESSIVE_FRAME))
- m_fb.di = DIBlend; // ok, clear thing
- else
+ if(m_fb.di == DIAuto || m_fb.di != DIWeave && m_fb.di != DIBlend && m_fb.di != DIBob && m_fb.di != DIFieldShift && m_fb.di != DIELA) {
+ if(seqflags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) {
+ m_fb.di = DIWeave; // hurray!
+ } else if(m_fFilm) {
+ m_fb.di = DIWeave; // we are lucky
+ } else if(!(m_fb.flags & PIC_FLAG_PROGRESSIVE_FRAME)) {
+ m_fb.di = DIBlend; // ok, clear thing
+ } else
// big trouble here, the progressive_frame bit is not reliable :'(
- // frames without temporal field diffs can be only detected when ntsc
- // uses the repeat field flag (signaled with m_fFilm), if it's not set
+ // frames without temporal field diffs can be only detected when ntsc
+ // uses the repeat field flag (signaled with m_fFilm), if it's not set
// or we have pal then we might end up blending the fields unnecessarily...
+ {
m_fb.di = DIBlend;
+ }
}
}
@@ -417,32 +430,35 @@ void CMpeg2DecFilter::SetDeinterlaceMethod()
void CMpeg2DecFilter::SetTypeSpecificFlags(IMediaSample* pMS)
{
- if(CComQIPtr<IMediaSample2> pMS2 = pMS)
- {
+ if(CComQIPtr<IMediaSample2> pMS2 = pMS) {
AM_SAMPLE2_PROPERTIES props;
- if(SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props)))
- {
+ if(SUCCEEDED(pMS2->GetProperties(sizeof(props), (BYTE*)&props))) {
props.dwTypeSpecificFlags &= ~0x7f;
const CMediaType& mt = m_pOutput->CurrentMediaType();
- if(mt.formattype == FORMAT_VideoInfo2 && (((VIDEOINFOHEADER2*)mt.pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced))
- {
+ if(mt.formattype == FORMAT_VideoInfo2 && (((VIDEOINFOHEADER2*)mt.pbFormat)->dwInterlaceFlags & AMINTERLACE_IsInterlaced)) {
// props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_WEAVE;
- if(m_dec->m_info.m_sequence->flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
+ if(m_dec->m_info.m_sequence->flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_WEAVE;
+ }
- if(m_fb.flags & PIC_FLAG_TOP_FIELD_FIRST)
+ if(m_fb.flags & PIC_FLAG_TOP_FIELD_FIRST) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_FIELD1FIRST;
- if(m_fb.flags & PIC_FLAG_REPEAT_FIRST_FIELD)
+ }
+ if(m_fb.flags & PIC_FLAG_REPEAT_FIRST_FIELD) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_REPEAT_FIELD;
+ }
- if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I)
+ if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_I_SAMPLE;
- if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P)
+ }
+ if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_P_SAMPLE;
- if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B)
+ }
+ if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B) {
props.dwTypeSpecificFlags |= AM_VIDEO_FLAG_B_SAMPLE;
+ }
}
pMS2->SetProperties(sizeof(props), (BYTE*)&props);
@@ -455,58 +471,61 @@ HRESULT CMpeg2DecFilter::Transform(IMediaSample* pIn)
HRESULT hr;
BYTE* pDataIn = NULL;
- if(FAILED(hr = pIn->GetPointer(&pDataIn)))
+ if(FAILED(hr = pIn->GetPointer(&pDataIn))) {
return hr;
+ }
long len = pIn->GetActualDataLength();
(static_cast<CDeCSSInputPin*>(m_pInput))->StripPacket(pDataIn, len);
- if(pIn->IsDiscontinuity() == S_OK)
- {
+ if(pIn->IsDiscontinuity() == S_OK) {
InputTypeChanged();
}
REFERENCE_TIME rtStart = _I64_MIN, rtStop = _I64_MIN;
hr = pIn->GetTime(&rtStart, &rtStop);
- if(FAILED(hr)) rtStart = rtStop = _I64_MIN;
+ if(FAILED(hr)) {
+ rtStart = rtStop = _I64_MIN;
+ }
- while(len >= 0)
- {
+ while(len >= 0) {
mpeg2_state_t state = m_dec->mpeg2_parse();
#ifndef _WIN64
__asm emms; // this one is missing somewhere in the precompiled mmx obj files
#endif
- switch(state)
- {
- case STATE_BUFFER:
- if(len > 0) {m_dec->mpeg2_buffer(pDataIn, pDataIn + len); len = 0;}
- else len = -1;
- break;
- case STATE_INVALID:
- TRACE(_T("*** STATE_INVALID\n"));
- break;
- case STATE_GOP:
- m_pClosedCaptionOutput->Deliver(m_dec->m_info.m_user_data, m_dec->m_info.m_user_data_len);
- break;
- case STATE_SEQUENCE:
- m_AvgTimePerFrame = m_dec->m_info.m_sequence->frame_period
- ? 10i64 * m_dec->m_info.m_sequence->frame_period / 27
- : ((VIDEOINFOHEADER*)m_pInput->CurrentMediaType().Format())->AvgTimePerFrame;
- break;
- case STATE_PICTURE:
- m_dec->m_picture->rtStart = rtStart; rtStart = _I64_MIN;
- m_dec->m_picture->fDelivered = false;
- m_dec->mpeg2_skip(m_fDropFrames && (m_dec->m_picture->flags&PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B);
- break;
- case STATE_SLICE:
- case STATE_END:
- {
+ switch(state) {
+ case STATE_BUFFER:
+ if(len > 0) {
+ m_dec->mpeg2_buffer(pDataIn, pDataIn + len);
+ len = 0;
+ } else {
+ len = -1;
+ }
+ break;
+ case STATE_INVALID:
+ TRACE(_T("*** STATE_INVALID\n"));
+ break;
+ case STATE_GOP:
+ m_pClosedCaptionOutput->Deliver(m_dec->m_info.m_user_data, m_dec->m_info.m_user_data_len);
+ break;
+ case STATE_SEQUENCE:
+ m_AvgTimePerFrame = m_dec->m_info.m_sequence->frame_period
+ ? 10i64 * m_dec->m_info.m_sequence->frame_period / 27
+ : ((VIDEOINFOHEADER*)m_pInput->CurrentMediaType().Format())->AvgTimePerFrame;
+ break;
+ case STATE_PICTURE:
+ m_dec->m_picture->rtStart = rtStart;
+ rtStart = _I64_MIN;
+ m_dec->m_picture->fDelivered = false;
+ m_dec->mpeg2_skip(m_fDropFrames && (m_dec->m_picture->flags&PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B);
+ break;
+ case STATE_SLICE:
+ case STATE_END: {
mpeg2_picture_t* picture = m_dec->m_info.m_display_picture;
mpeg2_fbuf_t* fbuf = m_dec->m_info.m_display_fbuf;
- if(picture && !(picture->flags&PIC_FLAG_SKIP) && fbuf)
- {
+ if(picture && !(picture->flags&PIC_FLAG_SKIP) && fbuf) {
ASSERT(!picture->fDelivered);
picture->fDelivered = true;
@@ -517,8 +536,7 @@ HRESULT CMpeg2DecFilter::Transform(IMediaSample* pIn)
int h = m_dec->m_info.m_sequence->picture_height;
int pitch = (m_dec->m_info.m_sequence->width + 31) & ~31;
- if(m_fb.w != w || m_fb.h != h || m_fb.pitch != pitch)
- {
+ if(m_fb.w != w || m_fb.h != h || m_fb.pitch != pitch) {
m_fb.Alloc(w, h, pitch);
m_fInitializedBuffer = false;
}
@@ -526,7 +544,9 @@ HRESULT CMpeg2DecFilter::Transform(IMediaSample* pIn)
// start - end
m_fb.rtStart = picture->rtStart;
- if(m_fb.rtStart == _I64_MIN) m_fb.rtStart = m_fb.rtStop;
+ if(m_fb.rtStart == _I64_MIN) {
+ m_fb.rtStart = m_fb.rtStop;
+ }
m_fb.rtStop = m_fb.rtStart + m_AvgTimePerFrame * picture->nb_fields / (m_dec->m_info.m_display_picture_2nd ? 1 : 2);
REFERENCE_TIME rtStart = m_fb.rtStart;
@@ -540,19 +560,22 @@ HRESULT CMpeg2DecFilter::Transform(IMediaSample* pIn)
UpdateAspectRatio();
hr = DeliverFast();
- if(hr != S_OK)
+ if(hr != S_OK) {
hr = DeliverNormal();
- if(hr != S_OK)
+ }
+ if(hr != S_OK) {
return hr;
- if(hr == S_OK && !m_fWaitForKeyFrame)
+ }
+ if(hr == S_OK && !m_fWaitForKeyFrame) {
m_fInitializedBuffer = true;
+ }
}
}
break;
- default:
- break;
+ default:
+ break;
}
- }
+ }
return S_OK;
}
@@ -564,14 +587,15 @@ bool CMpeg2DecFilter::IsVideoInterlaced()
void CMpeg2DecFilter::UpdateAspectRatio()
{
- if(m_bReadARFromStream && (m_par.cx != m_dec->m_info.m_sequence->pixel_width || m_par.cy != m_dec->m_info.m_sequence->pixel_height))
- {
+ if(m_bReadARFromStream && (m_par.cx != m_dec->m_info.m_sequence->pixel_width || m_par.cy != m_dec->m_info.m_sequence->pixel_height)) {
m_par.cx = m_dec->m_info.m_sequence->pixel_width;
m_par.cy = m_dec->m_info.m_sequence->pixel_height;
CSize dar(m_dec->m_info.m_sequence->picture_width * m_par.cx,
- m_dec->m_info.m_sequence->picture_height * m_par.cy);
+ m_dec->m_info.m_sequence->picture_height * m_par.cy);
int lnko = LNKO(dar.cx, dar.cy);
- if(lnko > 1) dar.cx /= lnko, dar.cy /= lnko;
+ if(lnko > 1) {
+ dar.cx /= lnko, dar.cy /= lnko;
+ }
SetAspect(dar);
}
}
@@ -583,38 +607,46 @@ HRESULT CMpeg2DecFilter::DeliverFast()
CAutoLock cAutoLock(&m_csReceive);
mpeg2_fbuf_t* fbuf = m_dec->m_info.m_display_fbuf;
- if(!fbuf) return S_FALSE;
+ if(!fbuf) {
+ return S_FALSE;
+ }
{
- CAutoLock cAutoLock2(&m_csProps);
+ CAutoLock cAutoLock2(&m_csProps);
- if(GetCLSID(m_pInput->GetConnected()) == CLSID_DVDNavigator
- || m_pSubpicInput->HasAnythingToRender(m_fb.rtStart)
- || fabs(m_bright) > EPSILON || fabs(m_cont-1.0) > EPSILON
- || fabs(m_hue) > EPSILON || fabs(m_sat-1.0) > EPSILON)
- return S_FALSE;
+ if(GetCLSID(m_pInput->GetConnected()) == CLSID_DVDNavigator
+ || m_pSubpicInput->HasAnythingToRender(m_fb.rtStart)
+ || fabs(m_bright) > EPSILON || fabs(m_cont-1.0) > EPSILON
+ || fabs(m_hue) > EPSILON || fabs(m_sat-1.0) > EPSILON) {
+ return S_FALSE;
+ }
}
- if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I)
+ if((m_fb.flags & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
m_fWaitForKeyFrame = false;
+ }
- if(m_fb.rtStart < 0 || m_fWaitForKeyFrame)
+ if(m_fb.rtStart < 0 || m_fWaitForKeyFrame) {
return S_OK;
+ }
const CMediaType& mt = m_pOutput->CurrentMediaType();
-
- if(mt.subtype != MEDIASUBTYPE_I420 && mt.subtype != MEDIASUBTYPE_IYUV && mt.subtype != MEDIASUBTYPE_YV12)
+
+ if(mt.subtype != MEDIASUBTYPE_I420 && mt.subtype != MEDIASUBTYPE_IYUV && mt.subtype != MEDIASUBTYPE_YV12) {
return S_FALSE;
+ }
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
if(FAILED(hr = GetDeliveryBuffer(m_fb.w, m_fb.h, &pOut))
- || FAILED(hr = pOut->GetPointer(&pDataOut)))
+ || FAILED(hr = pOut->GetPointer(&pDataOut))) {
return hr;
+ }
- if(mt.subtype != MEDIASUBTYPE_I420 && mt.subtype != MEDIASUBTYPE_IYUV && mt.subtype != MEDIASUBTYPE_YV12)
+ if(mt.subtype != MEDIASUBTYPE_I420 && mt.subtype != MEDIASUBTYPE_IYUV && mt.subtype != MEDIASUBTYPE_YV12) {
return S_FALSE;
+ }
BITMAPINFOHEADER bihOut;
ExtractBIH(&mt, &bihOut);
@@ -628,36 +660,32 @@ HRESULT CMpeg2DecFilter::DeliverFast()
BYTE* u = y + dstpitch*h;
BYTE* v = y + dstpitch*h*5/4;
- if(bihOut.biCompression == '21VY') {BYTE* tmp = u; u = v; v = tmp;}
+ if(bihOut.biCompression == '21VY') {
+ BYTE* tmp = u;
+ u = v;
+ v = tmp;
+ }
- if(m_fb.di == DIWeave)
- {
+ if(m_fb.di == DIWeave) {
BitBltFromI420ToI420(w, h, y, u, v, dstpitch, fbuf->buf[0], fbuf->buf[1], fbuf->buf[2], srcpitch);
- }
- else if(m_fb.di == DIBlend)
- {
+ } else if(m_fb.di == DIBlend) {
DeinterlaceBlend(y, fbuf->buf[0], w, h, dstpitch, srcpitch);
DeinterlaceBlend(u, fbuf->buf[1], w/2, h/2, dstpitch/2, srcpitch/2);
DeinterlaceBlend(v, fbuf->buf[2], w/2, h/2, dstpitch/2, srcpitch/2);
- }
- else // TODO
- {
+ } else { // TODO
return S_FALSE;
}
- if(h == 1088)
- {
+ if(h == 1088) {
memset(y + dstpitch*(h-8), 0xff, dstpitch*8);
memset(u + dstpitch*(h-8)/4, 0x80, dstpitch*8/4);
memset(v + dstpitch*(h-8)/4, 0x80, dstpitch*8/4);
}
- if(CMpeg2DecInputPin* pPin = dynamic_cast<CMpeg2DecInputPin*>(m_pInput))
- {
+ if(CMpeg2DecInputPin* pPin = dynamic_cast<CMpeg2DecInputPin*>(m_pInput)) {
CAutoLock cAutoLock(&pPin->m_csRateLock);
- if(m_rate.Rate != pPin->m_ratechange.Rate)
- {
+ if(m_rate.Rate != pPin->m_ratechange.Rate) {
m_rate.Rate = pPin->m_ratechange.Rate;
m_rate.StartTime = m_fb.rtStart;
}
@@ -688,7 +716,9 @@ HRESULT CMpeg2DecFilter::DeliverNormal()
CAutoLock cAutoLock(&m_csReceive);
mpeg2_fbuf_t* fbuf = m_dec->m_info.m_display_fbuf;
- if(!fbuf) return S_FALSE;
+ if(!fbuf) {
+ return S_FALSE;
+ }
int w = m_fb.w;
int h = m_fb.h;
@@ -702,35 +732,26 @@ HRESULT CMpeg2DecFilter::DeliverNormal()
// deinterlace
- if(m_fb.di == DIWeave)
- {
+ if(m_fb.di == DIWeave) {
BitBltFromI420ToI420(w, h, m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], dpitch, fbuf->buf[0], fbuf->buf[1], fbuf->buf[2], spitch);
- }
- else if(m_fb.di == DIBlend)
- {
+ } else if(m_fb.di == DIBlend) {
DeinterlaceBlend(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch);
DeinterlaceBlend(m_fb.buf[1], fbuf->buf[1], w/2, h/2, dpitch/2, spitch/2);
DeinterlaceBlend(m_fb.buf[2], fbuf->buf[2], w/2, h/2, dpitch/2, spitch/2);
- }
- else if(m_fb.di == DIBob)
- {
+ } else if(m_fb.di == DIBob) {
DeinterlaceBob(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, tff);
DeinterlaceBob(m_fb.buf[1], fbuf->buf[1], w/2, h/2, dpitch/2, spitch/2, tff);
DeinterlaceBob(m_fb.buf[2], fbuf->buf[2], w/2, h/2, dpitch/2, spitch/2, tff);
m_fb.rtStart = rtStart;
m_fb.rtStop = (rtStart + rtStop) / 2;
- }
- else if(m_fb.di == DIFieldShift)
- {
+ } else if(m_fb.di == DIFieldShift) {
int soffset = tff ? 0 : spitch;
int doffset = tff ? 0 : dpitch;
BitBltFromRGBToRGB(w, h/2, m_fb.buf[0] + doffset, dpitch*2, 8, fbuf->buf[0] + soffset, spitch*2, 8);
BitBltFromRGBToRGB(w/2, h/4, m_fb.buf[1] + doffset/2, dpitch, 8, fbuf->buf[1] + soffset/2, spitch, 8);
BitBltFromRGBToRGB(w/2, h/4, m_fb.buf[2] + doffset/2, dpitch, 8, fbuf->buf[2] + soffset/2, spitch, 8);
- }
- else if(m_fb.di == DIELA)
- {
+ } else if(m_fb.di == DIELA) {
DeinterlaceELA(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, tff);
DeinterlaceELA(m_fb.buf[1], fbuf->buf[1], w/2, h/2, dpitch/2, spitch/2, tff);
DeinterlaceELA(m_fb.buf[2], fbuf->buf[2], w/2, h/2, dpitch/2, spitch/2, tff);
@@ -742,15 +763,14 @@ HRESULT CMpeg2DecFilter::DeliverNormal()
// deliver
- if (m_fb.di == DIWeave || m_fInitializedBuffer)
- {
+ if (m_fb.di == DIWeave || m_fInitializedBuffer) {
hr = Deliver(false);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
}
- if(m_fb.di == DIBob)
- {
+ if(m_fb.di == DIBob) {
DeinterlaceBob(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, !tff);
DeinterlaceBob(m_fb.buf[1], fbuf->buf[1], w/2, h/2, dpitch/2, spitch/2, !tff);
DeinterlaceBob(m_fb.buf[2], fbuf->buf[2], w/2, h/2, dpitch/2, spitch/2, !tff);
@@ -765,24 +785,21 @@ HRESULT CMpeg2DecFilter::DeliverNormal()
// deliver
hr = Deliver(false);
- }
- else if(m_fb.di == DIFieldShift)
- {
+ } else if(m_fb.di == DIFieldShift) {
int soffset = !tff ? 0 : spitch;
int doffset = !tff ? 0 : dpitch;
BitBltFromRGBToRGB(w, h/2, m_fb.buf[0] + doffset, dpitch*2, 8, fbuf->buf[0] + soffset, spitch*2, 8);
BitBltFromRGBToRGB(w/2, h/4, m_fb.buf[1] + doffset/2, dpitch, 8, fbuf->buf[1] + soffset/2, spitch, 8);
BitBltFromRGBToRGB(w/2, h/4, m_fb.buf[2] + doffset/2, dpitch, 8, fbuf->buf[2] + soffset/2, spitch, 8);
- }
- else if(m_fb.di == DIELA)
- {
+ } else if(m_fb.di == DIELA) {
DeinterlaceELA(m_fb.buf[0], fbuf->buf[0], w, h, dpitch, spitch, !tff);
DeinterlaceELA(m_fb.buf[1], fbuf->buf[1], w/2, h/2, dpitch/2, spitch/2, !tff);
DeinterlaceELA(m_fb.buf[2], fbuf->buf[2], w/2, h/2, dpitch/2, spitch/2, !tff);
}
- if (!m_fInitializedBuffer)
+ if (!m_fInitializedBuffer) {
hr = Deliver(false);
+ }
return hr;
}
@@ -792,22 +809,24 @@ HRESULT CMpeg2DecFilter::Deliver(bool fRepeatLast)
{
CAutoLock cAutoLock(&m_csReceive);
- if((m_fb.flags&PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I)
+ if((m_fb.flags&PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_I) {
m_fWaitForKeyFrame = false;
+ }
- if(m_fb.rtStart < 0 || m_fWaitForKeyFrame)
+ if(m_fb.rtStart < 0 || m_fWaitForKeyFrame) {
return S_OK;
+ }
HRESULT hr;
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
if(FAILED(hr = GetDeliveryBuffer(m_fb.w, m_fb.h, &pOut))
- || FAILED(hr = pOut->GetPointer(&pDataOut)))
+ || FAILED(hr = pOut->GetPointer(&pDataOut))) {
return hr;
+ }
- if(m_fb.h == 1088)
- {
+ if(m_fb.h == 1088) {
memset(m_fb.buf[0] + m_fb.w*(m_fb.h-8), 0xff, m_fb.pitch*8);
memset(m_fb.buf[1] + m_fb.w*(m_fb.h-8)/4, 0x80, m_fb.pitch*8/4);
memset(m_fb.buf[2] + m_fb.w*(m_fb.h-8)/4, 0x80, m_fb.pitch*8/4);
@@ -815,11 +834,10 @@ HRESULT CMpeg2DecFilter::Deliver(bool fRepeatLast)
BYTE** buf = &m_fb.buf[0];
- if(m_pSubpicInput->HasAnythingToRender(m_fb.rtStart))
- {
- BitBltFromI420ToI420(m_fb.w, m_fb.h,
- m_fb.buf[3], m_fb.buf[4], m_fb.buf[5], m_fb.pitch,
- m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], m_fb.pitch);
+ if(m_pSubpicInput->HasAnythingToRender(m_fb.rtStart)) {
+ BitBltFromI420ToI420(m_fb.w, m_fb.h,
+ m_fb.buf[3], m_fb.buf[4], m_fb.buf[5], m_fb.pitch,
+ m_fb.buf[0], m_fb.buf[1], m_fb.buf[2], m_fb.pitch);
buf = &m_fb.buf[3];
@@ -830,12 +848,10 @@ HRESULT CMpeg2DecFilter::Deliver(bool fRepeatLast)
//
- if(CMpeg2DecInputPin* pPin = dynamic_cast<CMpeg2DecInputPin*>(m_pInput))
- {
+ if(CMpeg2DecInputPin* pPin = dynamic_cast<CMpeg2DecInputPin*>(m_pInput)) {
CAutoLock cAutoLock(&pPin->m_csRateLock);
- if(m_rate.Rate != pPin->m_ratechange.Rate)
- {
+ if(m_rate.Rate != pPin->m_ratechange.Rate) {
m_rate.Rate = pPin->m_ratechange.Rate;
m_rate.StartTime = m_fb.rtStart;
}
@@ -865,29 +881,29 @@ HRESULT CMpeg2DecFilter::Deliver(bool fRepeatLast)
HRESULT CMpeg2DecFilter::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
{
- if(dir == PINDIR_OUTPUT)
- {
- if(GetCLSID(m_pInput->GetConnected()) == CLSID_DVDNavigator)
- {
+ if(dir == PINDIR_OUTPUT) {
+ if(GetCLSID(m_pInput->GetConnected()) == CLSID_DVDNavigator) {
// one of these needed for dynamic format changes
CLSID clsid = GetCLSID(pPin);
DWORD ver = 0;
- if(CComQIPtr<IFilterVersion> pFV = GetFilterFromPin(pPin))
+ if(CComQIPtr<IFilterVersion> pFV = GetFilterFromPin(pPin)) {
ver = pFV->GetFilterVersion();
+ }
if(clsid != CLSID_OverlayMixer
- /*&& clsid != CLSID_OverlayMixer2*/
- && clsid != CLSID_VideoMixingRenderer
- && clsid != CLSID_VideoMixingRenderer9
- && clsid != GUIDFromCString(_T("{FA10746C-9B63-4b6c-BC49-FC300EA5F256}")) // EVR
- && clsid != GUIDFromCString(_T("{04FE9017-F873-410E-871E-AB91661A4EF7}")) // ffdshow
- && (clsid != GUIDFromCString(_T("{93A22E7A-5091-45ef-BA61-6DA26156A5D0}")) || ver < 0x0234) // dvobsub
- && (clsid != GUIDFromCString(_T("{9852A670-F845-491b-9BE6-EBD841B8A613}")) || ver < 0x0234) // dvobsub auto
- && clsid != CLSID_madVR
- && clsid != CLSID_DXR) // Haali's video renderer
+ /*&& clsid != CLSID_OverlayMixer2*/
+ && clsid != CLSID_VideoMixingRenderer
+ && clsid != CLSID_VideoMixingRenderer9
+ && clsid != GUIDFromCString(_T("{FA10746C-9B63-4b6c-BC49-FC300EA5F256}")) // EVR
+ && clsid != GUIDFromCString(_T("{04FE9017-F873-410E-871E-AB91661A4EF7}")) // ffdshow
+ && (clsid != GUIDFromCString(_T("{93A22E7A-5091-45ef-BA61-6DA26156A5D0}")) || ver < 0x0234) // dvobsub
+ && (clsid != GUIDFromCString(_T("{9852A670-F845-491b-9BE6-EBD841B8A613}")) || ver < 0x0234) // dvobsub auto
+ && clsid != CLSID_madVR
+ && clsid != CLSID_DXR) { // Haali's video renderer
return E_FAIL;
+ }
}
}
@@ -896,11 +912,11 @@ HRESULT CMpeg2DecFilter::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
HRESULT CMpeg2DecFilter::CheckInputType(const CMediaType* mtIn)
{
- if(mtIn->formattype == FORMAT_MPEG2_VIDEO && mtIn->pbFormat)
- {
+ if(mtIn->formattype == FORMAT_MPEG2_VIDEO && mtIn->pbFormat) {
MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mtIn->pbFormat;
- if(vih->cbSequenceHeader > 0 && (vih->dwSequenceHeader[0] & 0x00ffffff) != 0x00010000)
+ if(vih->cbSequenceHeader > 0 && (vih->dwSequenceHeader[0] & 0x00ffffff) != 0x00010000) {
return VFW_E_TYPE_NOT_ACCEPTED;
+ }
}
return (mtIn->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK && mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO
@@ -909,20 +925,20 @@ HRESULT CMpeg2DecFilter::CheckInputType(const CMediaType* mtIn)
|| mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO
|| mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPEG1Packet
|| mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_MPEG1Payload)
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CMpeg2DecFilter::CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut)
{
- bool fPlanarYUV = mtOut->subtype == MEDIASUBTYPE_YV12
- || mtOut->subtype == MEDIASUBTYPE_I420
- || mtOut->subtype == MEDIASUBTYPE_IYUV;
+ bool fPlanarYUV = mtOut->subtype == MEDIASUBTYPE_YV12
+ || mtOut->subtype == MEDIASUBTYPE_I420
+ || mtOut->subtype == MEDIASUBTYPE_IYUV;
return SUCCEEDED(__super::CheckTransform(mtIn, mtOut))
- && (!fPlanarYUV || IsPlanarYUVEnabled())
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ && (!fPlanarYUV || IsPlanarYUVEnabled())
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
DWORD g_clock;
@@ -930,25 +946,29 @@ DWORD g_clock;
HRESULT CMpeg2DecFilter::StartStreaming()
{
HRESULT hr = __super::StartStreaming();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
m_dec.Attach(DNew CMpeg2Dec());
- if(!m_dec) return E_OUTOFMEMORY;
+ if(!m_dec) {
+ return E_OUTOFMEMORY;
+ }
InputTypeChanged();
-// g_clock = clock();
+ // g_clock = clock();
return S_OK;
}
HRESULT CMpeg2DecFilter::StopStreaming()
{
-/*
- CString str;
- str.Format(_T("%d"), clock()-g_clock);
- AfxMessageBox(str);
-*/
+ /*
+ CString str;
+ str.Format(_T("%d"), clock()-g_clock);
+ AfxMessageBox(str);
+ */
m_dec.Free();
return __super::StopStreaming();
@@ -956,10 +976,13 @@ HRESULT CMpeg2DecFilter::StopStreaming()
HRESULT CMpeg2DecFilter::AlterQuality(Quality q)
{
- if(q.Late > 100*10000i64) m_fDropFrames = true;
- else if(q.Late <= 0) m_fDropFrames = false;
+ if(q.Late > 100*10000i64) {
+ m_fDropFrames = true;
+ } else if(q.Late <= 0) {
+ m_fDropFrames = false;
+ }
-// TRACE(_T("CMpeg2DecFilter::AlterQuality: Type=%d, Proportion=%d, Late=%I64d, TimeStamp=%I64d\n"), q.Type, q.Proportion, q.Late, q.TimeStamp);
+ // TRACE(_T("CMpeg2DecFilter::AlterQuality: Type=%d, Proportion=%d, Late=%I64d, TimeStamp=%I64d\n"), q.Type, q.Proportion, q.Late, q.TimeStamp);
return S_OK;
}
@@ -980,12 +1003,13 @@ STDMETHODIMP CMpeg2DecFilter::CreatePage(const GUID& guid, IPropertyPage** ppPag
{
CheckPointer(ppPage, E_POINTER);
- if(*ppPage != NULL) return E_INVALIDARG;
+ if(*ppPage != NULL) {
+ return E_INVALIDARG;
+ }
HRESULT hr;
- if(guid == __uuidof(CMpeg2DecSettingsWnd))
- {
+ if(guid == __uuidof(CMpeg2DecSettingsWnd)) {
(*ppPage = DNew CInternalPropertyPageTempl<CMpeg2DecSettingsWnd>(NULL, &hr))->AddRef();
}
@@ -1012,11 +1036,10 @@ void CMpeg2DecFilter::CalcBrCont(BYTE* YTbl, float bright, float cont)
int Cont = (int)(cont * 512);
int Bright = (int)bright;
- for(int i = 0; i < 256; i++)
- {
+ for(int i = 0; i < 256; i++) {
int y = ((Cont * (i - 16)) >> 9) + Bright + 16;
YTbl[i] = min(max(y, 0), 255);
-// YTbl[i] = min(max(y, 16), 235);
+ // YTbl[i] = min(max(y, 16), 235);
}
}
@@ -1027,11 +1050,9 @@ void CMpeg2DecFilter::CalcHueSat(BYTE* UTbl, BYTE* VTbl, float hue, float sat)
int Sin = (int)(sin(Hue) * 4096);
int Cos = (int)(cos(Hue) * 4096);
- for(int y = 0; y < 256; y++)
- {
- for(int x = 0; x < 256; x++)
- {
- int u = x - 128;
+ for(int y = 0; y < 256; y++) {
+ for(int x = 0; x < 256; x++) {
+ int u = x - 128;
int v = y - 128;
int ux = (u * Cos + v * Sin) >> 12;
v = (v * Cos - u * Sin) >> 12;
@@ -1049,12 +1070,10 @@ void CMpeg2DecFilter::ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int
{
CAutoLock cAutoLock(&m_csProps);
- if(fabs(m_bright) > EPSILON || fabs(m_cont-1.0) > EPSILON)
- {
+ if(fabs(m_bright) > EPSILON || fabs(m_cont-1.0) > EPSILON) {
int size = pitch*h;
- if((g_cpuid.m_flags&CCpuID::sse2) && ((DWORD_PTR)srcy & 15) == 0)
- {
+ if((g_cpuid.m_flags&CCpuID::sse2) && ((DWORD_PTR)srcy & 15) == 0) {
short Cont = (short)(min(max(m_cont, 0) * 512, (1<<16)-1));
short Bright = (short)(m_bright + 16);
@@ -1064,8 +1083,7 @@ void CMpeg2DecFilter::ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int
__m128i _16 = _mm_set1_epi16(16);
__m128i _512 = _mm_set1_epi16(512);
- for(int i = 0, j = size>>4; i < j; i++)
- {
+ for(int i = 0, j = size>>4; i < j; i++) {
__m128i r = _mm_load_si128((__m128i*)&srcy[i*16]);
__m128i rl = _mm_unpacklo_epi8(r, zero);
@@ -1101,8 +1119,7 @@ void CMpeg2DecFilter::ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int
size &= 15;
}
- for(; size > 0; size--)
- {
+ for(; size > 0; size--) {
*srcy++ = m_YTbl[*srcy];
}
}
@@ -1111,10 +1128,8 @@ void CMpeg2DecFilter::ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int
w /= 2;
h /= 2;
- if(fabs(m_hue) > EPSILON || fabs(m_sat-1.0) > EPSILON)
- {
- for(int size = pitch*h; size > 0; size--)
- {
+ if(fabs(m_hue) > EPSILON || fabs(m_sat-1.0) > EPSILON) {
+ for(int size = pitch*h; size > 0; size--) {
WORD uv = (*srcv<<8)|*srcu;
*srcu++ = m_UTbl[uv];
*srcv++ = m_VTbl[uv];
@@ -1242,175 +1257,172 @@ CMpeg2DecInputPin::CMpeg2DecInputPin(CTransformFilter* pFilter, HRESULT* phr, LP
STDMETHODIMP CMpeg2DecInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength)
{
- if(PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/)
+ if(PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/) {
return __super::Set(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength);
+ }
if(PropSet == AM_KSPROPSETID_TSRateChange)
- switch(Id)
- {
- case AM_RATE_SimpleRateChange:
- {
- AM_SimpleRateChange* p = (AM_SimpleRateChange*)pPropertyData;
- if(!m_CorrectTS) return E_PROP_ID_UNSUPPORTED;
- CAutoLock cAutoLock(&m_csRateLock);
- m_ratechange = *p;
- DbgLog((LOG_TRACE, 0, _T("StartTime=%I64d, Rate=%d"), p->StartTime, p->Rate));
- }
- break;
- case AM_RATE_UseRateVersion:
- {
- WORD* p = (WORD*)pPropertyData;
- if(*p > 0x0101) return E_PROP_ID_UNSUPPORTED;
- }
- break;
- case AM_RATE_CorrectTS:
- {
- LONG* p = (LONG*)pPropertyData;
- m_CorrectTS = *p;
+ switch(Id) {
+ case AM_RATE_SimpleRateChange: {
+ AM_SimpleRateChange* p = (AM_SimpleRateChange*)pPropertyData;
+ if(!m_CorrectTS) {
+ return E_PROP_ID_UNSUPPORTED;
+ }
+ CAutoLock cAutoLock(&m_csRateLock);
+ m_ratechange = *p;
+ DbgLog((LOG_TRACE, 0, _T("StartTime=%I64d, Rate=%d"), p->StartTime, p->Rate));
+ }
+ break;
+ case AM_RATE_UseRateVersion: {
+ WORD* p = (WORD*)pPropertyData;
+ if(*p > 0x0101) {
+ return E_PROP_ID_UNSUPPORTED;
+ }
+ }
+ break;
+ case AM_RATE_CorrectTS: {
+ LONG* p = (LONG*)pPropertyData;
+ m_CorrectTS = *p;
+ }
+ break;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
}
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-/*
- if(PropSet == AM_KSPROPSETID_DVD_RateChange)
- switch(Id)
- {
- case AM_RATE_ChangeRate:
+ /*
+ if(PropSet == AM_KSPROPSETID_DVD_RateChange)
+ switch(Id)
{
- AM_DVD_ChangeRate* p = (AM_DVD_ChangeRate*)pPropertyData;
+ case AM_RATE_ChangeRate:
+ {
+ AM_DVD_ChangeRate* p = (AM_DVD_ChangeRate*)pPropertyData;
+ }
+ break;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
}
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-*/
+ */
return S_OK;
}
STDMETHODIMP CMpeg2DecInputPin::Get(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength, ULONG* pBytesReturned)
{
- if(PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/)
+ if(PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/) {
return __super::Get(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength, pBytesReturned);
+ }
if(PropSet == AM_KSPROPSETID_TSRateChange)
- switch(Id)
- {
- case AM_RATE_SimpleRateChange:
- {
- AM_SimpleRateChange* p = (AM_SimpleRateChange*)pPropertyData;
- UNUSED_ALWAYS(p);
- return E_PROP_ID_UNSUPPORTED;
- }
- break;
- case AM_RATE_MaxFullDataRate:
- {
- AM_MaxFullDataRate* p = (AM_MaxFullDataRate*)pPropertyData;
- UNUSED_ALWAYS(p);
- *p = 8*10000;
- *pBytesReturned = sizeof(AM_MaxFullDataRate);
- }
- break;
- case AM_RATE_QueryFullFrameRate:
- {
- AM_QueryRate* p = (AM_QueryRate*)pPropertyData;
- p->lMaxForwardFullFrame = 8*10000;
- p->lMaxReverseFullFrame = 8*10000;
- *pBytesReturned = sizeof(AM_QueryRate);
+ switch(Id) {
+ case AM_RATE_SimpleRateChange: {
+ AM_SimpleRateChange* p = (AM_SimpleRateChange*)pPropertyData;
+ UNUSED_ALWAYS(p);
+ return E_PROP_ID_UNSUPPORTED;
+ }
+ break;
+ case AM_RATE_MaxFullDataRate: {
+ AM_MaxFullDataRate* p = (AM_MaxFullDataRate*)pPropertyData;
+ UNUSED_ALWAYS(p);
+ *p = 8*10000;
+ *pBytesReturned = sizeof(AM_MaxFullDataRate);
+ }
+ break;
+ case AM_RATE_QueryFullFrameRate: {
+ AM_QueryRate* p = (AM_QueryRate*)pPropertyData;
+ p->lMaxForwardFullFrame = 8*10000;
+ p->lMaxReverseFullFrame = 8*10000;
+ *pBytesReturned = sizeof(AM_QueryRate);
+ }
+ break;
+ case AM_RATE_QueryLastRateSegPTS: {
+ REFERENCE_TIME* p = (REFERENCE_TIME*)pPropertyData;
+ return E_PROP_ID_UNSUPPORTED;
+ }
+ break;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
}
- break;
- case AM_RATE_QueryLastRateSegPTS:
+ /*
+ if(PropSet == AM_KSPROPSETID_DVD_RateChange)
+ switch(Id)
{
- REFERENCE_TIME* p = (REFERENCE_TIME*)pPropertyData;
+ case AM_RATE_FullDataRateMax:
+ {
+ AM_MaxFullDataRate* p = (AM_MaxFullDataRate*)pPropertyData;
+ }
+ break;
+ case AM_RATE_ReverseDecode:
+ {
+ LONG* p = (LONG*)pPropertyData;
+ }
+ break;
+ case AM_RATE_DecoderPosition:
+ {
+ AM_DVD_DecoderPosition* p = (AM_DVD_DecoderPosition*)pPropertyData;
+ }
+ break;
+ case AM_RATE_DecoderVersion:
+ {
+ LONG* p = (LONG*)pPropertyData;
+ }
+ break;
+ default:
return E_PROP_ID_UNSUPPORTED;
}
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-/*
- if(PropSet == AM_KSPROPSETID_DVD_RateChange)
- switch(Id)
- {
- case AM_RATE_FullDataRateMax:
- {
- AM_MaxFullDataRate* p = (AM_MaxFullDataRate*)pPropertyData;
- }
- break;
- case AM_RATE_ReverseDecode:
- {
- LONG* p = (LONG*)pPropertyData;
- }
- break;
- case AM_RATE_DecoderPosition:
- {
- AM_DVD_DecoderPosition* p = (AM_DVD_DecoderPosition*)pPropertyData;
- }
- break;
- case AM_RATE_DecoderVersion:
- {
- LONG* p = (LONG*)pPropertyData;
- }
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-*/
+ */
return S_OK;
}
STDMETHODIMP CMpeg2DecInputPin::QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport)
{
- if(PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/)
+ if(PropSet != AM_KSPROPSETID_TSRateChange /*&& PropSet != AM_KSPROPSETID_DVD_RateChange*/) {
return __super::QuerySupported(PropSet, Id, pTypeSupport);
+ }
if(PropSet == AM_KSPROPSETID_TSRateChange)
- switch(Id)
- {
- case AM_RATE_SimpleRateChange:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
- break;
- case AM_RATE_MaxFullDataRate:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_UseRateVersion:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_RATE_QueryFullFrameRate:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_QueryLastRateSegPTS:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_CorrectTS:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-/*
- if(PropSet == AM_KSPROPSETID_DVD_RateChange)
- switch(Id)
- {
- case AM_RATE_ChangeRate:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_RATE_FullDataRateMax:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_ReverseDecode:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_DecoderPosition:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- case AM_RATE_DecoderVersion:
- *pTypeSupport = KSPROPERTY_SUPPORT_GET;
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
- }
-*/
+ switch(Id) {
+ case AM_RATE_SimpleRateChange:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET | KSPROPERTY_SUPPORT_SET;
+ break;
+ case AM_RATE_MaxFullDataRate:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ case AM_RATE_UseRateVersion:
+ *pTypeSupport = KSPROPERTY_SUPPORT_SET;
+ break;
+ case AM_RATE_QueryFullFrameRate:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ case AM_RATE_QueryLastRateSegPTS:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ case AM_RATE_CorrectTS:
+ *pTypeSupport = KSPROPERTY_SUPPORT_SET;
+ break;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
+ }
+ /*
+ if(PropSet == AM_KSPROPSETID_DVD_RateChange)
+ switch(Id)
+ {
+ case AM_RATE_ChangeRate:
+ *pTypeSupport = KSPROPERTY_SUPPORT_SET;
+ break;
+ case AM_RATE_FullDataRateMax:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ case AM_RATE_ReverseDecode:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ case AM_RATE_DecoderPosition:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ case AM_RATE_DecoderVersion:
+ *pTypeSupport = KSPROPERTY_SUPPORT_GET;
+ break;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
+ }
+ */
return S_OK;
}
@@ -1429,15 +1441,15 @@ HRESULT CMpeg2DecOutputPin::Active()
// TODO
- if(m_Connected && !m_pOutputQueue)
- {
+ if(m_Connected && !m_pOutputQueue) {
HRESULT hr = NOERROR;
m_pOutputQueue.Attach(DNew COutputQueue(m_Connected, &hr));
- if(!m_pOutputQueue) hr = E_OUTOFMEMORY;
+ if(!m_pOutputQueue) {
+ hr = E_OUTOFMEMORY;
+ }
- if(FAILED(hr))
- {
+ if(FAILED(hr)) {
m_pOutputQueue.Free();
return hr;
}
@@ -1455,7 +1467,9 @@ HRESULT CMpeg2DecOutputPin::Inactive()
HRESULT CMpeg2DecOutputPin::Deliver(IMediaSample* pMediaSample)
{
- if(!m_pOutputQueue) return NOERROR;
+ if(!m_pOutputQueue) {
+ return NOERROR;
+ }
pMediaSample->AddRef();
return m_pOutputQueue->Receive(pMediaSample);
}
@@ -1464,7 +1478,7 @@ HRESULT CMpeg2DecOutputPin::Deliver(IMediaSample* pMediaSample)
if(!m_pOutputQueue) return NOERROR; \
m_pOutputQueue->##call; \
return NOERROR; \
-
+
HRESULT CMpeg2DecOutputPin::DeliverEndOfStream()
{
CallQueue(EOS());
@@ -1492,7 +1506,7 @@ HRESULT CMpeg2DecOutputPin::DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_T
#define PTS2RT(pts) (10000i64*pts/90)
-CSubpicInputPin::CSubpicInputPin(CTransformFilter* pFilter, HRESULT* phr)
+CSubpicInputPin::CSubpicInputPin(CTransformFilter* pFilter, HRESULT* phr)
: CMpeg2DecInputPin(pFilter, phr, L"SubPicture")
, m_spon(TRUE)
, m_fsppal(false)
@@ -1512,12 +1526,12 @@ HRESULT CSubpicInputPin::CheckMediaType(const CMediaType* mtIn)
return (mtIn->majortype == MEDIATYPE_DVD_ENCRYPTED_PACK
|| mtIn->majortype == MEDIATYPE_MPEG2_PACK
|| mtIn->majortype == MEDIATYPE_MPEG2_PES
- || mtIn->majortype == MEDIATYPE_Video)
- && (mtIn->subtype == MEDIASUBTYPE_DVD_SUBPICTURE
- || mtIn->subtype == MEDIASUBTYPE_CVD_SUBPICTURE
- || mtIn->subtype == MEDIASUBTYPE_SVCD_SUBPICTURE)
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ || mtIn->majortype == MEDIATYPE_Video)
+ && (mtIn->subtype == MEDIASUBTYPE_DVD_SUBPICTURE
+ || mtIn->subtype == MEDIASUBTYPE_CVD_SUBPICTURE
+ || mtIn->subtype == MEDIASUBTYPE_SVCD_SUBPICTURE)
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CSubpicInputPin::SetMediaType(const CMediaType* mtIn)
@@ -1527,16 +1541,18 @@ HRESULT CSubpicInputPin::SetMediaType(const CMediaType* mtIn)
bool CSubpicInputPin::HasAnythingToRender(REFERENCE_TIME rt)
{
- if(!IsConnected()) return(false);
+ if(!IsConnected()) {
+ return(false);
+ }
CAutoLock cAutoLock(&m_csReceive);
POSITION pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
spu* sp = m_sps.GetNext(pos);
- if(sp->m_rtStart <= rt && rt < sp->m_rtStop && (/*sp->m_psphli ||*/ sp->m_fForced || m_spon))
+ if(sp->m_rtStart <= rt && rt < sp->m_rtStop && (/*sp->m_psphli ||*/ sp->m_fForced || m_spon)) {
return(true);
+ }
}
return(false);
@@ -1550,20 +1566,21 @@ void CSubpicInputPin::RenderSubpics(REFERENCE_TIME rt, BYTE** yuv, int w, int h)
// remove no longer needed things first
pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
POSITION cur = pos;
spu* sp = m_sps.GetNext(pos);
- if(sp->m_rtStop <= rt) m_sps.RemoveAt(cur);
+ if(sp->m_rtStop <= rt) {
+ m_sps.RemoveAt(cur);
+ }
}
pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
spu* sp = m_sps.GetNext(pos);
- if(sp->m_rtStart <= rt && rt < sp->m_rtStop
- && (m_spon || sp->m_fForced && ((static_cast<CMpeg2DecFilter*>(m_pFilter))->IsForcedSubtitlesEnabled() || sp->m_psphli)))
+ if(sp->m_rtStart <= rt && rt < sp->m_rtStop
+ && (m_spon || sp->m_fForced && ((static_cast<CMpeg2DecFilter*>(m_pFilter))->IsForcedSubtitlesEnabled() || sp->m_psphli))) {
sp->Render(rt, yuv, w, h, m_sppal, m_fsppal);
+ }
}
}
@@ -1572,29 +1589,33 @@ HRESULT CSubpicInputPin::Transform(IMediaSample* pSample)
HRESULT hr;
AM_MEDIA_TYPE* pmt;
- if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt)
- {
+ if(SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) {
CMediaType mt(*pmt);
SetMediaType(&mt);
DeleteMediaType(pmt);
}
BYTE* pDataIn = NULL;
- if(FAILED(hr = pSample->GetPointer(&pDataIn))) return hr;
+ if(FAILED(hr = pSample->GetPointer(&pDataIn))) {
+ return hr;
+ }
long len = pSample->GetActualDataLength();
StripPacket(pDataIn, len);
- if(len <= 0) return S_FALSE;
+ if(len <= 0) {
+ return S_FALSE;
+ }
- if(m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE) {
pDataIn += 4;
len -= 4;
}
- if(len <= 0) return S_FALSE;
+ if(len <= 0) {
+ return S_FALSE;
+ }
CAutoLock cAutoLock(&m_csReceive);
@@ -1603,23 +1624,17 @@ HRESULT CSubpicInputPin::Transform(IMediaSample* pSample)
bool fRefresh = false;
- if(FAILED(hr))
- {
- if(!m_sps.IsEmpty())
- {
+ if(FAILED(hr)) {
+ if(!m_sps.IsEmpty()) {
spu* sp = m_sps.GetTail();
sp->SetCount(sp->GetCount() + len);
memcpy(sp->GetData() + sp->GetCount() - len, pDataIn, len);
}
- }
- else
- {
+ } else {
POSITION pos = m_sps.GetTailPosition();
- while(pos)
- {
+ while(pos) {
spu* sp = m_sps.GetPrev(pos);
- if(sp->m_rtStop == _I64_MAX)
- {
+ if(sp->m_rtStop == _I64_MAX) {
sp->m_rtStop = rtStart;
break;
}
@@ -1627,10 +1642,15 @@ HRESULT CSubpicInputPin::Transform(IMediaSample* pSample)
CAutoPtr<spu> p;
- if(m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE) p.Attach(DNew dvdspu());
- else if(m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE) p.Attach(DNew cvdspu());
- else if(m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE) p.Attach(DNew svcdspu());
- else return E_FAIL;
+ if(m_mt.subtype == MEDIASUBTYPE_DVD_SUBPICTURE) {
+ p.Attach(DNew dvdspu());
+ } else if(m_mt.subtype == MEDIASUBTYPE_CVD_SUBPICTURE) {
+ p.Attach(DNew cvdspu());
+ } else if(m_mt.subtype == MEDIASUBTYPE_SVCD_SUBPICTURE) {
+ p.Attach(DNew svcdspu());
+ } else {
+ return E_FAIL;
+ }
p->m_rtStart = rtStart;
p->m_rtStop = _I64_MAX;
@@ -1638,8 +1658,7 @@ HRESULT CSubpicInputPin::Transform(IMediaSample* pSample)
p->SetCount(len);
memcpy(p->GetData(), pDataIn, len);
- if(m_sphli && p->m_rtStart == PTS2RT(m_sphli->StartPTM))
- {
+ if(m_sphli && p->m_rtStart == PTS2RT(m_sphli->StartPTM)) {
p->m_psphli = m_sphli;
fRefresh = true;
}
@@ -1647,14 +1666,12 @@ HRESULT CSubpicInputPin::Transform(IMediaSample* pSample)
m_sps.AddTail(p);
}
- if(!m_sps.IsEmpty())
- {
+ if(!m_sps.IsEmpty()) {
m_sps.GetTail()->Parse();
}
- if(fRefresh)
- {
-// ((CMpeg2DecFilter*)m_pFilter)->Deliver(true);
+ if(fRefresh) {
+ // ((CMpeg2DecFilter*)m_pFilter)->Deliver(true);
}
return S_FALSE;
@@ -1671,15 +1688,14 @@ STDMETHODIMP CSubpicInputPin::EndFlush()
STDMETHODIMP CSubpicInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceData, ULONG InstanceLength, LPVOID pPropertyData, ULONG DataLength)
{
- if(PropSet != AM_KSPROPSETID_DvdSubPic)
+ if(PropSet != AM_KSPROPSETID_DvdSubPic) {
return __super::Set(PropSet, Id, pInstanceData, InstanceLength, pPropertyData, DataLength);
+ }
bool fRefresh = false;
- switch(Id)
- {
- case AM_PROPERTY_DVDSUBPIC_PALETTE:
- {
+ switch(Id) {
+ case AM_PROPERTY_DVDSUBPIC_PALETTE: {
CAutoLock cAutoLock(&m_csReceive);
AM_PROPERTY_SPPAL* pSPPAL = (AM_PROPERTY_SPPAL*)pPropertyData;
@@ -1689,22 +1705,18 @@ STDMETHODIMP CSubpicInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceDat
DbgLog((LOG_TRACE, 0, _T("new palette")));
}
break;
- case AM_PROPERTY_DVDSUBPIC_HLI:
- {
+ case AM_PROPERTY_DVDSUBPIC_HLI: {
CAutoLock cAutoLock(&m_csReceive);
AM_PROPERTY_SPHLI* pSPHLI = (AM_PROPERTY_SPHLI*)pPropertyData;
m_sphli.Free();
- if(pSPHLI->HLISS)
- {
+ if(pSPHLI->HLISS) {
POSITION pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
spu* sp = m_sps.GetNext(pos);
- if(sp->m_rtStart <= PTS2RT(pSPHLI->StartPTM) && PTS2RT(pSPHLI->StartPTM) < sp->m_rtStop)
- {
+ if(sp->m_rtStart <= PTS2RT(pSPHLI->StartPTM) && PTS2RT(pSPHLI->StartPTM) < sp->m_rtStop) {
fRefresh = true;
sp->m_psphli.Free();
sp->m_psphli.Attach(DNew AM_PROPERTY_SPHLI);
@@ -1712,17 +1724,13 @@ STDMETHODIMP CSubpicInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceDat
}
}
- if(!fRefresh) // save it for later, a subpic might be late for this hli
- {
+ if(!fRefresh) { // save it for later, a subpic might be late for this hli
m_sphli.Attach(DNew AM_PROPERTY_SPHLI);
memcpy((AM_PROPERTY_SPHLI*)m_sphli, pSPHLI, sizeof(AM_PROPERTY_SPHLI));
}
- }
- else
- {
+ } else {
POSITION pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
spu* sp = m_sps.GetNext(pos);
fRefresh |= !!sp->m_psphli;
sp->m_psphli.Free();
@@ -1730,25 +1738,23 @@ STDMETHODIMP CSubpicInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceDat
}
if(pSPHLI->HLISS)
- DbgLog((LOG_TRACE, 0, _T("hli: %I64d - %I64d, (%d,%d) - (%d,%d)"),
- PTS2RT(pSPHLI->StartPTM)/10000, PTS2RT(pSPHLI->EndPTM)/10000,
- pSPHLI->StartX, pSPHLI->StartY, pSPHLI->StopX, pSPHLI->StopY));
+ DbgLog((LOG_TRACE, 0, _T("hli: %I64d - %I64d, (%d,%d) - (%d,%d)"),
+ PTS2RT(pSPHLI->StartPTM)/10000, PTS2RT(pSPHLI->EndPTM)/10000,
+ pSPHLI->StartX, pSPHLI->StartY, pSPHLI->StopX, pSPHLI->StopY));
}
break;
- case AM_PROPERTY_DVDSUBPIC_COMPOSIT_ON:
- {
+ case AM_PROPERTY_DVDSUBPIC_COMPOSIT_ON: {
CAutoLock cAutoLock(&m_csReceive);
AM_PROPERTY_COMPOSIT_ON* pCompositOn = (AM_PROPERTY_COMPOSIT_ON*)pPropertyData;
m_spon = *pCompositOn;
}
break;
- default:
- return E_PROP_ID_UNSUPPORTED;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
}
- if(fRefresh)
- {
+ if(fRefresh) {
(static_cast<CMpeg2DecFilter*>(m_pFilter))->Deliver(true);
}
@@ -1757,24 +1763,24 @@ STDMETHODIMP CSubpicInputPin::Set(REFGUID PropSet, ULONG Id, LPVOID pInstanceDat
STDMETHODIMP CSubpicInputPin::QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport)
{
- if(PropSet != AM_KSPROPSETID_DvdSubPic)
+ if(PropSet != AM_KSPROPSETID_DvdSubPic) {
return __super::QuerySupported(PropSet, Id, pTypeSupport);
+ }
- switch(Id)
- {
- case AM_PROPERTY_DVDSUBPIC_PALETTE:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_PROPERTY_DVDSUBPIC_HLI:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- case AM_PROPERTY_DVDSUBPIC_COMPOSIT_ON:
- *pTypeSupport = KSPROPERTY_SUPPORT_SET;
- break;
- default:
- return E_PROP_ID_UNSUPPORTED;
+ switch(Id) {
+ case AM_PROPERTY_DVDSUBPIC_PALETTE:
+ *pTypeSupport = KSPROPERTY_SUPPORT_SET;
+ break;
+ case AM_PROPERTY_DVDSUBPIC_HLI:
+ *pTypeSupport = KSPROPERTY_SUPPORT_SET;
+ break;
+ case AM_PROPERTY_DVDSUBPIC_COMPOSIT_ON:
+ *pTypeSupport = KSPROPERTY_SUPPORT_SET;
+ break;
+ default:
+ return E_PROP_ID_UNSUPPORTED;
}
-
+
return S_OK;
}
@@ -1785,26 +1791,32 @@ static __inline BYTE GetNibble(BYTE* p, DWORD* offset, int& nField, int& fAligne
BYTE ret = (p[offset[nField]] >> (fAligned << 2)) & 0x0f;
offset[nField] += 1-fAligned;
fAligned = !fAligned;
- return ret;
+ return ret;
}
static __inline BYTE GetHalfNibble(BYTE* p, DWORD* offset, int& nField, int& n)
{
BYTE ret = (p[offset[nField]] >> (n << 1)) & 0x03;
- if(!n) offset[nField]++;
+ if(!n) {
+ offset[nField]++;
+ }
n = (n-1+4)&3;
- return ret;
+ return ret;
}
static __inline void DrawPixel(BYTE** yuv, CPoint pt, int pitch, AM_DVD_YUV& c)
{
- if(c.Reserved == 0) return;
+ if(c.Reserved == 0) {
+ return;
+ }
BYTE* p = &yuv[0][pt.y*pitch + pt.x];
-// *p = (*p*(15-contrast) + sppal[color].Y*contrast)>>4;
+ // *p = (*p*(15-contrast) + sppal[color].Y*contrast)>>4;
*p -= (*p - c.Y) * c.Reserved >> 4;
- if(pt.y&1) return; // since U/V is half res there is no need to overwrite the same line again
+ if(pt.y&1) {
+ return; // since U/V is half res there is no need to overwrite the same line again
+ }
pt.x = (pt.x + 1) / 2;
pt.y = (pt.y /*+ 1*/) / 2; // only paint the upper field always, don't round it
@@ -1813,11 +1825,11 @@ static __inline void DrawPixel(BYTE** yuv, CPoint pt, int pitch, AM_DVD_YUV& c)
// U/V is exchanged? wierd but looks true when comparing the outputted colors from other decoders
p = &yuv[1][pt.y*pitch + pt.x];
-// *p = (BYTE)(((((int)*p-0x80)*(15-contrast) + ((int)sppal[color].V-0x80)*contrast) >> 4) + 0x80);
+ // *p = (BYTE)(((((int)*p-0x80)*(15-contrast) + ((int)sppal[color].V-0x80)*contrast) >> 4) + 0x80);
*p -= (*p - c.V) * c.Reserved >> 4;
p = &yuv[2][pt.y*pitch + pt.x];
-// *p = (BYTE)(((((int)*p-0x80)*(15-contrast) + ((int)sppal[color].U-0x80)*contrast) >> 4) + 0x80);
+ // *p = (BYTE)(((((int)*p-0x80)*(15-contrast) + ((int)sppal[color].U-0x80)*contrast) >> 4) + 0x80);
*p -= (*p - c.U) * c.Reserved >> 4;
// Neighter of the blending formulas are accurate (">>4" should be "/15").
@@ -1827,23 +1839,32 @@ static __inline void DrawPixel(BYTE** yuv, CPoint pt, int pitch, AM_DVD_YUV& c)
static __inline void DrawPixels(BYTE** yuv, int pitch, CPoint pt, int len, AM_DVD_YUV& c, CRect& rc)
{
- if(pt.y < rc.top || pt.y >= rc.bottom) return;
- if(pt.x < rc.left) {len -= rc.left - pt.x; pt.x = rc.left;}
- if(pt.x + len > rc.right) len = rc.right - pt.x;
- if(len <= 0 || pt.x >= rc.right) return;
+ if(pt.y < rc.top || pt.y >= rc.bottom) {
+ return;
+ }
+ if(pt.x < rc.left) {
+ len -= rc.left - pt.x;
+ pt.x = rc.left;
+ }
+ if(pt.x + len > rc.right) {
+ len = rc.right - pt.x;
+ }
+ if(len <= 0 || pt.x >= rc.right) {
+ return;
+ }
- if(c.Reserved == 0)
- {
- if(rc.IsRectEmpty())
+ if(c.Reserved == 0) {
+ if(rc.IsRectEmpty()) {
return;
+ }
- if(pt.y < rc.top || pt.y >= rc.bottom
- || pt.x+len < rc.left || pt.x >= rc.right)
+ if(pt.y < rc.top || pt.y >= rc.bottom
+ || pt.x+len < rc.left || pt.x >= rc.right) {
return;
+ }
}
- while(len-- > 0)
- {
+ while(len-- > 0) {
DrawPixel(yuv, pt, pitch, c);
pt.x++;
}
@@ -1860,50 +1881,65 @@ bool CSubpicInputPin::dvdspu::Parse()
WORD packetsize = (p[0]<<8)|p[1];
WORD datasize = (p[2]<<8)|p[3];
- if(packetsize > GetCount() || datasize > packetsize)
+ if(packetsize > GetCount() || datasize > packetsize) {
return(false);
+ }
int i, next = datasize;
- #define GetWORD (p[i]<<8)|p[i+1]; i += 2
+#define GetWORD (p[i]<<8)|p[i+1]; i += 2
- do
- {
+ do {
i = next;
int pts = GetWORD;
next = GetWORD;
- if(next > packetsize || next < datasize)
+ if(next > packetsize || next < datasize) {
return(false);
+ }
REFERENCE_TIME rt = m_rtStart + 1024*PTS2RT(pts);
- for(bool fBreak = false; !fBreak; )
- {
+ for(bool fBreak = false; !fBreak; ) {
int len = 0;
- switch(p[i])
- {
- case 0x00: len = 0; break;
- case 0x01: len = 0; break;
- case 0x02: len = 0; break;
- case 0x03: len = 2; break;
- case 0x04: len = 2; break;
- case 0x05: len = 6; break;
- case 0x06: len = 4; break;
- case 0x07: len = 0; break; // TODO
- default: len = 0; break;
+ switch(p[i]) {
+ case 0x00:
+ len = 0;
+ break;
+ case 0x01:
+ len = 0;
+ break;
+ case 0x02:
+ len = 0;
+ break;
+ case 0x03:
+ len = 2;
+ break;
+ case 0x04:
+ len = 2;
+ break;
+ case 0x05:
+ len = 6;
+ break;
+ case 0x06:
+ len = 4;
+ break;
+ case 0x07:
+ len = 0;
+ break; // TODO
+ default:
+ len = 0;
+ break;
}
- if(i+len >= packetsize)
- {
+ if(i+len >= packetsize) {
TRACE(_T("Warning: Wrong subpicture parameter block ending\n"));
break;
}
- switch(p[i++])
- {
+ switch(p[i++]) {
case 0x00: // forced start displaying
m_fForced = true;
break;
@@ -1952,8 +1988,7 @@ bool CSubpicInputPin::dvdspu::Parse()
offset_t o = {rt, m_sphli};
m_offsets.AddTail(o); // is it always going to be sorted?
- }
- while(i <= next && i < packetsize);
+ } while(i <= next && i < packetsize);
return(true);
}
@@ -1970,18 +2005,17 @@ void CSubpicInputPin::dvdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h
CRect rcclip(0, 0, w, h);
rcclip &= rc;
- if(m_psphli)
- {
+ if(m_psphli) {
rcclip &= CRect(m_psphli->StartX, m_psphli->StartY, m_psphli->StopX, m_psphli->StopY);
sphli = *m_psphli;
- }
- else if(m_offsets.GetCount() > 1)
- {
+ } else if(m_offsets.GetCount() > 1) {
POSITION pos = m_offsets.GetTailPosition();
- while(pos)
- {
+ while(pos) {
const offset_t& o = m_offsets.GetPrev(pos);
- if(rt >= o.rt) {sphli = o.sphli; break;}
+ if(rt >= o.rt) {
+ sphli = o.sphli;
+ break;
+ }
}
}
@@ -2000,22 +2034,24 @@ void CSubpicInputPin::dvdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h
DWORD end[2] = {offset[1], (p[2]<<8)|p[3]};
- while((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1]))
- {
+ while((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1])) {
DWORD code;
if((code = GetNibble(p, offset, nField, fAligned)) >= 0x4
- || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x10
- || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x40
- || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x100)
- {
+ || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x10
+ || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x40
+ || (code = (code << 4) | GetNibble(p, offset, nField, fAligned)) >= 0x100) {
DrawPixels(yuv, w, pt, code >> 2, pal[code&3], rcclip);
- if((pt.x += code >> 2) < rc.right) continue;
+ if((pt.x += code >> 2) < rc.right) {
+ continue;
+ }
}
DrawPixels(yuv, w, pt, rc.right - pt.x, pal[code&3], rcclip);
- if(!fAligned) GetNibble(p, offset, nField, fAligned); // align to byte
+ if(!fAligned) {
+ GetNibble(p, offset, nField, fAligned); // align to byte
+ }
pt.x = rc.left;
pt.y++;
@@ -2032,58 +2068,63 @@ bool CSubpicInputPin::cvdspu::Parse()
WORD packetsize = (p[0]<<8)|p[1];
WORD datasize = (p[2]<<8)|p[3];
- if(packetsize > GetCount() || datasize > packetsize)
+ if(packetsize > GetCount() || datasize > packetsize) {
return(false);
+ }
p = GetData() + datasize;
- for(int i = datasize, j = packetsize-4; i <= j; i+=4, p+=4)
- {
- switch(p[0])
- {
- case 0x0c:
- break;
- case 0x04:
- m_rtStop = m_rtStart + 10000i64*((p[1]<<16)|(p[2]<<8)|p[3])/90;
- break;
- case 0x17:
- m_sphli.StartX = ((p[1]&0x0f)<<6) + (p[2]>>2);
- m_sphli.StartY = ((p[2]&0x03)<<8) + p[3];
- break;
- case 0x1f:
- m_sphli.StopX = ((p[1]&0x0f)<<6) + (p[2]>>2);
- m_sphli.StopY = ((p[2]&0x03)<<8) + p[3];
- break;
- case 0x24: case 0x25: case 0x26: case 0x27:
- m_sppal[0][p[0]-0x24].Y = p[1];
- m_sppal[0][p[0]-0x24].U = p[2];
- m_sppal[0][p[0]-0x24].V = p[3];
- break;
- case 0x2c: case 0x2d: case 0x2e: case 0x2f:
- m_sppal[1][p[0]-0x2c].Y = p[1];
- m_sppal[1][p[0]-0x2c].U = p[2];
- m_sppal[1][p[0]-0x2c].V = p[3];
- break;
- case 0x37:
- m_sppal[0][3].Reserved = p[2]>>4;
- m_sppal[0][2].Reserved = p[2]&0xf;
- m_sppal[0][1].Reserved = p[3]>>4;
- m_sppal[0][0].Reserved = p[3]&0xf;
- break;
- case 0x3f:
- m_sppal[1][3].Reserved = p[2]>>4;
- m_sppal[1][2].Reserved = p[2]&0xf;
- m_sppal[1][1].Reserved = p[3]>>4;
- m_sppal[1][0].Reserved = p[3]&0xf;
- break;
- case 0x47:
- m_offset[0] = (p[2]<<8)|p[3];
- break;
- case 0x4f:
- m_offset[1] = (p[2]<<8)|p[3];
- break;
- default:
- break;
+ for(int i = datasize, j = packetsize-4; i <= j; i+=4, p+=4) {
+ switch(p[0]) {
+ case 0x0c:
+ break;
+ case 0x04:
+ m_rtStop = m_rtStart + 10000i64*((p[1]<<16)|(p[2]<<8)|p[3])/90;
+ break;
+ case 0x17:
+ m_sphli.StartX = ((p[1]&0x0f)<<6) + (p[2]>>2);
+ m_sphli.StartY = ((p[2]&0x03)<<8) + p[3];
+ break;
+ case 0x1f:
+ m_sphli.StopX = ((p[1]&0x0f)<<6) + (p[2]>>2);
+ m_sphli.StopY = ((p[2]&0x03)<<8) + p[3];
+ break;
+ case 0x24:
+ case 0x25:
+ case 0x26:
+ case 0x27:
+ m_sppal[0][p[0]-0x24].Y = p[1];
+ m_sppal[0][p[0]-0x24].U = p[2];
+ m_sppal[0][p[0]-0x24].V = p[3];
+ break;
+ case 0x2c:
+ case 0x2d:
+ case 0x2e:
+ case 0x2f:
+ m_sppal[1][p[0]-0x2c].Y = p[1];
+ m_sppal[1][p[0]-0x2c].U = p[2];
+ m_sppal[1][p[0]-0x2c].V = p[3];
+ break;
+ case 0x37:
+ m_sppal[0][3].Reserved = p[2]>>4;
+ m_sppal[0][2].Reserved = p[2]&0xf;
+ m_sppal[0][1].Reserved = p[3]>>4;
+ m_sppal[0][0].Reserved = p[3]&0xf;
+ break;
+ case 0x3f:
+ m_sppal[1][3].Reserved = p[2]>>4;
+ m_sppal[1][2].Reserved = p[2]&0xf;
+ m_sppal[1][1].Reserved = p[3]>>4;
+ m_sppal[1][0].Reserved = p[3]&0xf;
+ break;
+ case 0x47:
+ m_offset[0] = (p[2]<<8)|p[3];
+ break;
+ case 0x4f:
+ m_offset[1] = (p[2]<<8)|p[3];
+ break;
+ default:
+ break;
}
}
@@ -2111,12 +2152,10 @@ void CSubpicInputPin::cvdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h
DWORD end[2] = {offset[1], (p[2]<<8)|p[3]};
- while((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1]))
- {
+ while((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1])) {
BYTE code;
- if((code = GetNibble(p, offset, nField, fAligned)) >= 0x4)
- {
+ if((code = GetNibble(p, offset, nField, fAligned)) >= 0x4) {
DrawPixels(yuv, w, pt, code >> 2, m_sppal[0][code&3], rcclip);
pt.x += code >> 2;
continue;
@@ -2125,7 +2164,9 @@ void CSubpicInputPin::cvdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int h
code = GetNibble(p, offset, nField, fAligned);
DrawPixels(yuv, w, pt, rc.right - pt.x, m_sppal[0][code&3], rcclip);
- if(!fAligned) GetNibble(p, offset, nField, fAligned); // align to byte
+ if(!fAligned) {
+ GetNibble(p, offset, nField, fAligned); // align to byte
+ }
pt.x = rc.left;
pt.y++;
@@ -2140,41 +2181,48 @@ bool CSubpicInputPin::svcdspu::Parse()
BYTE* p = GetData();
BYTE* p0 = p;
- if(GetCount() < 2)
+ if(GetCount() < 2) {
return(false);
+ }
- WORD packetsize = (p[0]<<8)|p[1]; p += 2;
+ WORD packetsize = (p[0]<<8)|p[1];
+ p += 2;
- if(packetsize > GetCount())
+ if(packetsize > GetCount()) {
return(false);
+ }
bool duration = !!(*p++&0x04);
*p++; // unknown
- if(duration)
- {
+ if(duration) {
m_rtStop = m_rtStart + 10000i64*((p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3])/90;
p += 4;
}
- m_sphli.StartX = m_sphli.StopX = (p[0]<<8)|p[1]; p += 2;
- m_sphli.StartY = m_sphli.StopY = (p[0]<<8)|p[1]; p += 2;
- m_sphli.StopX += (p[0]<<8)|p[1]; p += 2;
- m_sphli.StopY += (p[0]<<8)|p[1]; p += 2;
+ m_sphli.StartX = m_sphli.StopX = (p[0]<<8)|p[1];
+ p += 2;
+ m_sphli.StartY = m_sphli.StopY = (p[0]<<8)|p[1];
+ p += 2;
+ m_sphli.StopX += (p[0]<<8)|p[1];
+ p += 2;
+ m_sphli.StopY += (p[0]<<8)|p[1];
+ p += 2;
- for(int i = 0; i < 4; i++)
- {
+ for(int i = 0; i < 4; i++) {
m_sppal[i].Y = *p++;
m_sppal[i].U = *p++;
m_sppal[i].V = *p++;
m_sppal[i].Reserved = *p++ >> 4;
}
- if(*p++&0xc0)
- p += 4; // duration of the shift operation should be here, but it is untested
+ if(*p++&0xc0) {
+ p += 4; // duration of the shift operation should be here, but it is untested
+ }
- m_offset[1] = (p[0]<<8)|p[1]; p += 2;
+ m_offset[1] = (p[0]<<8)|p[1];
+ p += 2;
m_offset[0] = p - p0;
m_offset[1] += m_offset[0];
@@ -2203,16 +2251,18 @@ void CSubpicInputPin::svcdspu::Render(REFERENCE_TIME rt, BYTE** yuv, int w, int
DWORD end[2] = {offset[1], (p[2]<<8)|p[3]};
- while((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1]))
- {
+ while((nField == 0 && offset[0] < end[0]) || (nField == 1 && offset[1] < end[1])) {
BYTE code = GetHalfNibble(p, offset, nField, n);
BYTE repeat = 1 + (code == 0 ? GetHalfNibble(p, offset, nField, n) : 0);
DrawPixels(yuv, w, pt, repeat, m_sppal[code&3], rcclip);
- if((pt.x += repeat) < rc.right) continue;
+ if((pt.x += repeat) < rc.right) {
+ continue;
+ }
- while(n != 3)
- GetHalfNibble(p, offset, nField, n); // align to byte
+ while(n != 3) {
+ GetHalfNibble(p, offset, nField, n); // align to byte
+ }
pt.x = rc.left;
pt.y++;
@@ -2232,14 +2282,18 @@ CClosedCaptionOutputPin::CClosedCaptionOutputPin(CBaseFilter* pFilter, CCritSec*
HRESULT CClosedCaptionOutputPin::CheckMediaType(const CMediaType* mtOut)
{
return mtOut->majortype == MEDIATYPE_AUXLine21Data && mtOut->subtype == MEDIASUBTYPE_Line21_GOPPacket
- ? S_OK
- : VFW_E_TYPE_NOT_ACCEPTED;
+ ? S_OK
+ : VFW_E_TYPE_NOT_ACCEPTED;
}
HRESULT CClosedCaptionOutputPin::GetMediaType(int iPosition, CMediaType* pmt)
{
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->InitMediaType();
pmt->majortype = MEDIATYPE_AUXLine21Data;
@@ -2258,20 +2312,20 @@ HRESULT CClosedCaptionOutputPin::DecideBufferSize(IMemAllocator* pAllocator, ALL
HRESULT hr;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual)))
+ if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) {
return hr;
+ }
- return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
- ? E_FAIL
- : NOERROR;
+ return pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer
+ ? E_FAIL
+ : NOERROR;
}
HRESULT CClosedCaptionOutputPin::Deliver(const void* ptr, int len)
{
HRESULT hr = S_FALSE;
- if(len > 4 && ptr && *(DWORD*)ptr == 0xf8014343 && IsConnected())
- {
+ if(len > 4 && ptr && *(DWORD*)ptr == 0xf8014343 && IsConnected()) {
CComPtr<IMediaSample> pSample;
GetDeliveryBuffer(&pSample, NULL, NULL, 0);
BYTE* pData = NULL;
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h
index 829ec6fa3..a6d5f10d2 100644
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h
+++ b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecFilter.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -33,7 +33,7 @@ class CClosedCaptionOutputPin;
class CMpeg2Dec;
class __declspec(uuid("39F498AF-1A09-4275-B193-673B0BA3D478"))
-CMpeg2DecFilter
+ CMpeg2DecFilter
: public CBaseVideoFilter
, public IMpeg2DecFilter
, public ISpecifyPropertyPages2
@@ -48,39 +48,47 @@ CMpeg2DecFilter
bool m_fInitializedBuffer;
CSize m_par;
- struct framebuf
- {
+ struct framebuf {
int w, h, pitch;
BYTE* buf_base;
BYTE* buf[6];
REFERENCE_TIME rtStart, rtStop;
DWORD flags;
ditype di;
- framebuf()
- {
+ framebuf() {
w = h = pitch = 0;
buf_base = NULL;
memset(&buf, 0, sizeof(buf));
rtStart = rtStop = 0;
flags = 0;
}
- ~framebuf() {Free();}
- void Alloc(int w, int h, int pitch)
- {
- this->w = w; this->h = h; this->pitch = pitch;
+ ~framebuf() {
+ Free();
+ }
+ void Alloc(int w, int h, int pitch) {
+ this->w = w;
+ this->h = h;
+ this->pitch = pitch;
int size = pitch*h;
buf_base = (BYTE*)_aligned_malloc(size*3+6*32, 32);
BYTE* p = buf_base;
- buf[0] = p; p += (size + 31) & ~31;
- buf[3] = p; p += (size + 31) & ~31;
- buf[1] = p; p += (size/4 + 31) & ~31;
- buf[4] = p; p += (size/4 + 31) & ~31;
- buf[2] = p; p += (size/4 + 31) & ~31;
- buf[5] = p; p += (size/4 + 31) & ~31;
+ buf[0] = p;
+ p += (size + 31) & ~31;
+ buf[3] = p;
+ p += (size + 31) & ~31;
+ buf[1] = p;
+ p += (size/4 + 31) & ~31;
+ buf[4] = p;
+ p += (size/4 + 31) & ~31;
+ buf[2] = p;
+ p += (size/4 + 31) & ~31;
+ buf[5] = p;
+ p += (size/4 + 31) & ~31;
}
- void Free()
- {
- if(buf_base) _aligned_free(buf_base);
+ void Free() {
+ if(buf_base) {
+ _aligned_free(buf_base);
+ }
buf_base = NULL;
}
} m_fb;
@@ -102,7 +110,7 @@ public:
virtual ~CMpeg2DecFilter();
DECLARE_IUNKNOWN
- STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
+ STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT DeliverFast();
HRESULT DeliverNormal();
@@ -111,13 +119,13 @@ public:
int GetPinCount();
CBasePin* GetPin(int n);
- HRESULT EndOfStream();
+ HRESULT EndOfStream();
HRESULT BeginFlush();
HRESULT EndFlush();
- HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
HRESULT CheckConnect(PIN_DIRECTION dir, IPin* pPin);
- HRESULT CheckInputType(const CMediaType* mtIn);
+ HRESULT CheckInputType(const CMediaType* mtIn);
HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
HRESULT StartStreaming();
@@ -139,7 +147,7 @@ protected:
static void CalcBrCont(BYTE* YTbl, float bright, float cont);
static void CalcHueSat(BYTE* UTbl, BYTE* VTbl, float hue, float sat);
void ApplyBrContHueSat(BYTE* srcy, BYTE* srcu, BYTE* srcv, int w, int h, int pitch);
-
+
public:
// ISpecifyPropertyPages2
@@ -181,15 +189,15 @@ class CMpeg2DecInputPin : public CDeCSSInputPin
LONG m_CorrectTS;
public:
- CMpeg2DecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName);
+ CMpeg2DecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName);
CCritSec m_csRateLock;
AM_SimpleRateChange m_ratechange;
// IKsPropertySet
- STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength);
- STDMETHODIMP Get(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength, ULONG* pBytesReturned);
- STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport);
+ STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength);
+ STDMETHODIMP Get(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength, ULONG* pBytesReturned);
+ STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport);
};
class CMpeg2DecOutputPin : public CBaseVideoOutputPin
@@ -200,13 +208,13 @@ public:
CAutoPtr<COutputQueue> m_pOutputQueue;
HRESULT Active();
- HRESULT Inactive();
+ HRESULT Inactive();
HRESULT Deliver(IMediaSample* pMediaSample);
- HRESULT DeliverEndOfStream();
- HRESULT DeliverBeginFlush();
+ HRESULT DeliverEndOfStream();
+ HRESULT DeliverBeginFlush();
HRESULT DeliverEndFlush();
- HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
+ HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
};
class CSubpicInputPin : public CMpeg2DecInputPin
@@ -222,11 +230,15 @@ class CSubpicInputPin : public CMpeg2DecInputPin
{
public:
bool m_fForced;
- REFERENCE_TIME m_rtStart, m_rtStop;
+ REFERENCE_TIME m_rtStart, m_rtStop;
DWORD m_offset[2];
AM_PROPERTY_SPHLI m_sphli; // parsed
CAutoPtr<AM_PROPERTY_SPHLI> m_psphli; // for the menu (optional)
- spu() {memset(&m_sphli, 0, sizeof(m_sphli)); m_fForced = false; m_rtStart = m_rtStop = 0;}
+ spu() {
+ memset(&m_sphli, 0, sizeof(m_sphli));
+ m_fForced = false;
+ m_rtStart = m_rtStop = 0;
+ }
virtual ~spu() {}
virtual bool Parse() = 0;
virtual void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal) = 0;
@@ -235,7 +247,10 @@ class CSubpicInputPin : public CMpeg2DecInputPin
class dvdspu : public spu
{
public:
- struct offset_t {REFERENCE_TIME rt; AM_PROPERTY_SPHLI sphli;};
+ struct offset_t {
+ REFERENCE_TIME rt;
+ AM_PROPERTY_SPHLI sphli;
+ };
CAtlList<offset_t> m_offsets;
bool Parse();
void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal);
@@ -245,7 +260,9 @@ class CSubpicInputPin : public CMpeg2DecInputPin
{
public:
AM_DVD_YUV m_sppal[2][4];
- cvdspu() {memset(m_sppal, 0, sizeof(m_sppal));}
+ cvdspu() {
+ memset(m_sppal, 0, sizeof(m_sppal));
+ }
bool Parse();
void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal);
};
@@ -254,7 +271,9 @@ class CSubpicInputPin : public CMpeg2DecInputPin
{
public:
AM_DVD_YUV m_sppal[4];
- svcdspu() {memset(m_sppal, 0, sizeof(m_sppal));}
+ svcdspu() {
+ memset(m_sppal, 0, sizeof(m_sppal));
+ }
bool Parse();
void Render(REFERENCE_TIME rt, BYTE** p, int w, int h, AM_DVD_YUV* sppal, bool fsppal);
};
@@ -270,18 +289,24 @@ public:
bool HasAnythingToRender(REFERENCE_TIME rt);
void RenderSubpics(REFERENCE_TIME rt, BYTE** p, int w, int h);
- HRESULT CheckMediaType(const CMediaType* mtIn);
+ HRESULT CheckMediaType(const CMediaType* mtIn);
HRESULT SetMediaType(const CMediaType* mtIn);
// we shouldn't pass these to the filter from this pin
- STDMETHODIMP EndOfStream() {return S_OK;}
- STDMETHODIMP BeginFlush() {return S_OK;}
- STDMETHODIMP EndFlush();
- STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {return S_OK;}
+ STDMETHODIMP EndOfStream() {
+ return S_OK;
+ }
+ STDMETHODIMP BeginFlush() {
+ return S_OK;
+ }
+ STDMETHODIMP EndFlush();
+ STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate) {
+ return S_OK;
+ }
// IKsPropertySet
- STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength);
- STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport);
+ STDMETHODIMP Set(REFGUID PropSet, ULONG Id, LPVOID InstanceData, ULONG InstanceLength, LPVOID PropertyData, ULONG DataLength);
+ STDMETHODIMP QuerySupported(REFGUID PropSet, ULONG Id, ULONG* pTypeSupport);
};
class CClosedCaptionOutputPin : public CBaseOutputPin
@@ -289,11 +314,13 @@ class CClosedCaptionOutputPin : public CBaseOutputPin
public:
CClosedCaptionOutputPin(CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
- HRESULT CheckMediaType(const CMediaType* mtOut);
+ HRESULT CheckMediaType(const CMediaType* mtOut);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
- HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
+ HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
- CMediaType& CurrentMediaType() {return m_mt;}
+ CMediaType& CurrentMediaType() {
+ return m_mt;
+ }
HRESULT Deliver(const void* ptr, int len);
};
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp
index c8de3e7ea..4be2a2f54 100644
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp
+++ b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -51,9 +51,13 @@ bool CMpeg2DecSettingsWnd::OnConnect(const CInterfaceList<IUnknown, &IID_IUnknow
m_pM2DF.Release();
POSITION pos = pUnks.GetHeadPosition();
- while(pos && !(m_pM2DF = pUnks.GetNext(pos)));
-
- if(!m_pM2DF) return false;
+ while(pos && !(m_pM2DF = pUnks.GetNext(pos))) {
+ ;
+ }
+
+ if(!m_pM2DF) {
+ return false;
+ }
m_ditype = m_pM2DF->GetDeinterlaceMethod();
m_procamp[0] = m_pM2DF->GetBrightness();
@@ -107,15 +111,15 @@ bool CMpeg2DecSettingsWnd::OnActivate()
m_ditype_combo.SetItemData(m_ditype_combo.AddString(_T("ELA")), (DWORD)DIELA);
m_ditype_combo.SetCurSel(0);
for(int i = 0; i < m_ditype_combo.GetCount(); i++)
- if((int)m_ditype_combo.GetItemData(i) == m_ditype)
+ if((int)m_ditype_combo.GetItemData(i) == m_ditype) {
m_ditype_combo.SetCurSel(i);
+ }
m_ditype_combo.EnableWindow(!IsDlgButtonChecked(m_interlaced_check.GetDlgCtrlID()));
p.y += m_fontheight + 20;
- for(int i = 0, h = max(20, m_fontheight)+1; i < countof(m_procamp_slider); i++, p.y += h)
- {
+ for(int i = 0, h = max(20, m_fontheight)+1; i < countof(m_procamp_slider); i++, p.y += h) {
static const TCHAR* labels[] = {m_strBrightness, m_strContrast, m_strHue, m_strSaturation};
m_procamp_static[i].Create(labels[i], dwStyle, CRect(p, CSize(70, h)), this);
m_procamp_slider[i].Create(dwStyle, CRect(p + CPoint(80, 0), CSize(200, h)), this, IDC_PP_SLIDER1+i);
@@ -149,8 +153,9 @@ bool CMpeg2DecSettingsWnd::OnActivate()
ResStr(IDS_MPEG2DECSETTINGSWND_8),
dwStyle, CRect(p, CSize(320, m_fontheight * 4)), this);
- for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow())
+ for(CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) {
pWnd->SetFont(&m_font, FALSE);
+ }
return true;
}
@@ -172,8 +177,7 @@ bool CMpeg2DecSettingsWnd::OnApply()
{
OnDeactivate();
- if(m_pM2DF)
- {
+ if(m_pM2DF) {
m_pM2DF->SetDeinterlaceMethod(m_ditype);
m_pM2DF->SetBrightness(m_procamp[0]);
m_pM2DF->SetContrast(m_procamp[1]);
@@ -205,7 +209,7 @@ void CMpeg2DecSettingsWnd::UpdateProcampValues()
BEGIN_MESSAGE_MAP(CMpeg2DecSettingsWnd, CInternalPropertyPageWnd)
ON_BN_CLICKED(IDC_PP_BUTTON1, OnButtonProcampPc2Tv)
ON_BN_CLICKED(IDC_PP_BUTTON2, OnButtonProcampReset)
- ON_BN_CLICKED(IDC_PP_CHECK2, OnButtonInterlaced)
+ ON_BN_CLICKED(IDC_PP_CHECK2, OnButtonInterlaced)
ON_WM_HSCROLL()
END_MESSAGE_MAP()
diff --git a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h
index a358fdb8a..9a3e25939 100644
--- a/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h
+++ b/src/filters/transform/Mpeg2DecFilter/Mpeg2DecSettingsWnd.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -26,7 +26,7 @@
#include <afxcmn.h>
class __declspec(uuid("E5FB6957-65E6-491B-BB37-B25C9FE3BEA7"))
-CMpeg2DecSettingsWnd : public CInternalPropertyPageWnd
+ CMpeg2DecSettingsWnd : public CInternalPropertyPageWnd
{
CComQIPtr<IMpeg2DecFilter> m_pM2DF;
@@ -37,8 +37,7 @@ CMpeg2DecSettingsWnd : public CInternalPropertyPageWnd
bool m_forcedsubs;
bool m_readARFromStream;
- enum
- {
+ enum {
IDC_PP_COMBO1 = 10000,
IDC_PP_SLIDER1,
IDC_PP_SLIDER2,
@@ -69,15 +68,19 @@ CMpeg2DecSettingsWnd : public CInternalPropertyPageWnd
public:
CMpeg2DecSettingsWnd();
-
+
bool OnConnect(const CInterfaceList<IUnknown, &IID_IUnknown>& pUnks);
void OnDisconnect();
bool OnActivate();
void OnDeactivate();
bool OnApply();
- static LPCTSTR GetWindowTitle() {return _T("Settings");}
- static CSize GetWindowSize() {return CSize(320, 240);}
+ static LPCTSTR GetWindowTitle() {
+ return _T("Settings");
+ }
+ static CSize GetWindowSize() {
+ return CSize(320, 240);
+ }
DECLARE_MESSAGE_MAP()
diff --git a/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp b/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp
index 134707c76..7eab60218 100644
--- a/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp
+++ b/src/filters/transform/Mpeg2DecFilter/idct_sse2.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -47,276 +47,276 @@ static __align16(const short,M128_tg_2_16[8]) = {27146, 27146, 27146, 27146, 271
static __align16(const short,M128_tg_3_16[8]) = {-21746, -21746, -21746, -21746, -21746, -21746, -21746, -21746}; // tg * (2<<16) + 0.5
static __align16(const short,M128_cos_4_16[8]) = {-19195, -19195, -19195, -19195, -19195, -19195, -19195, -19195};// cos * (2<<16) + 0.5
-static __align16(const int16_t,M128_tab_i_04[])={16384, 21407, 16384, 8867, 16384, -8867, 16384, -21407, 16384, 8867, -16384, -21407, -16384, 21407, 16384, -8867, 22725, 19266, 19266, -4520, 12873, -22725, 4520, -12873, 12873, 4520, -22725, -12873, 4520, 19266, 19266, -22725};
-static __align16(const int16_t,M128_tab_i_17[])={22725, 29692, 22725, 12299, 22725, -12299, 22725, -29692, 22725, 12299, -22725, -29692, -22725, 29692, 22725, -12299, 31521, 26722, 26722, -6270, 17855, -31521, 6270, -17855, 17855, 6270, -31521, -17855, 6270, 26722, 26722, -31521};
-static __align16(const int16_t,M128_tab_i_26[])={21407, 27969, 21407, 11585, 21407, -11585, 21407, -27969, 21407, 11585, -21407, -27969, -21407, 27969, 21407, -11585, 29692, 25172, 25172, -5906, 16819, -29692, 5906, -16819, 16819, 5906, -29692, -16819, 5906, 25172, 25172, -29692};
-static __align16(const int16_t,M128_tab_i_35[])={19266, 25172, 19266, 10426, 19266, -10426, 19266, -25172, 19266, 10426, -19266, -25172, -19266, 25172, 19266, -10426, 26722, 22654, 22654, -5315, 15137, -26722, 5315, -15137, 15137, 5315, -26722, -15137, 5315, 22654, 22654, -26722};
+static __align16(const int16_t,M128_tab_i_04[])= {16384, 21407, 16384, 8867, 16384, -8867, 16384, -21407, 16384, 8867, -16384, -21407, -16384, 21407, 16384, -8867, 22725, 19266, 19266, -4520, 12873, -22725, 4520, -12873, 12873, 4520, -22725, -12873, 4520, 19266, 19266, -22725};
+static __align16(const int16_t,M128_tab_i_17[])= {22725, 29692, 22725, 12299, 22725, -12299, 22725, -29692, 22725, 12299, -22725, -29692, -22725, 29692, 22725, -12299, 31521, 26722, 26722, -6270, 17855, -31521, 6270, -17855, 17855, 6270, -31521, -17855, 6270, 26722, 26722, -31521};
+static __align16(const int16_t,M128_tab_i_26[])= {21407, 27969, 21407, 11585, 21407, -11585, 21407, -27969, 21407, 11585, -21407, -27969, -21407, 27969, 21407, -11585, 29692, 25172, 25172, -5906, 16819, -29692, 5906, -16819, 16819, 5906, -29692, -16819, 5906, 25172, 25172, -29692};
+static __align16(const int16_t,M128_tab_i_35[])= {19266, 25172, 19266, 10426, 19266, -10426, 19266, -25172, 19266, 10426, -19266, -25172, -19266, 25172, 19266, -10426, 26722, 22654, 22654, -5315, 15137, -26722, 5315, -15137, 15137, 5315, -26722, -15137, 5315, 22654, 22654, -26722};
static __forceinline void DCT_8_INV_ROW(const uint8_t * const ecx,const uint8_t * const esi,__m128i &xmm0,__m128i &xmm1,__m128i &xmm2,__m128i &xmm3,__m128i &xmm4,__m128i &xmm5,__m128i &xmm6,__m128i &xmm7)
{
- xmm0=_mm_shufflelo_epi16(xmm0, 0xD8 );
- xmm1=_mm_shuffle_epi32( xmm0, 0 );
- pmaddwd (xmm1, esi);
- xmm3=_mm_shuffle_epi32( xmm0, 0x55);
- xmm0=_mm_shufflehi_epi16( xmm0, 0xD8 );
- pmaddwd( xmm3, esi+32 );
- xmm2=_mm_shuffle_epi32( xmm0, 0xAA );
- xmm0=_mm_shuffle_epi32( xmm0, 0xFF );
- pmaddwd( xmm2, esi+16 );
- xmm4=_mm_shufflehi_epi16( xmm4, 0xD8 );
- paddd (xmm1, M128_round_inv_row);
- xmm4=_mm_shufflelo_epi16 (xmm4, 0xD8 );
- pmaddwd (xmm0, esi+48 );
- xmm5=_mm_shuffle_epi32( xmm4, 0 );
- xmm6=_mm_shuffle_epi32( xmm4, 0xAA );
- pmaddwd (xmm5, ecx );
- paddd (xmm1, xmm2 );
- movdqa (xmm2, xmm1 );
- xmm7=_mm_shuffle_epi32( xmm4, 0x55 );
- pmaddwd (xmm6, ecx+16 );
- paddd (xmm0, xmm3 );
- xmm4=_mm_shuffle_epi32( xmm4, 0xFF );
- psubd (xmm2, xmm0 );
- pmaddwd (xmm7, ecx+32 );
- paddd (xmm0, xmm1 );
- psrad (xmm2, 12 );
- paddd (xmm5, M128_round_inv_row);
- pmaddwd (xmm4, ecx+48 );
- paddd (xmm5, xmm6 );
- movdqa (xmm6, xmm5 );
- psrad (xmm0, 12 );
- xmm2=_mm_shuffle_epi32( xmm2, 0x1B );
- packssdw (xmm0, xmm2 );
- paddd (xmm4, xmm7 );
- psubd (xmm6, xmm4 );
- paddd (xmm4, xmm5 );
- psrad (xmm6, 12 );
- psrad (xmm4, 12 );
- xmm6=_mm_shuffle_epi32( xmm6, 0x1B );
- packssdw (xmm4, xmm6 );
+ xmm0=_mm_shufflelo_epi16(xmm0, 0xD8 );
+ xmm1=_mm_shuffle_epi32( xmm0, 0 );
+ pmaddwd (xmm1, esi);
+ xmm3=_mm_shuffle_epi32( xmm0, 0x55);
+ xmm0=_mm_shufflehi_epi16( xmm0, 0xD8 );
+ pmaddwd( xmm3, esi+32 );
+ xmm2=_mm_shuffle_epi32( xmm0, 0xAA );
+ xmm0=_mm_shuffle_epi32( xmm0, 0xFF );
+ pmaddwd( xmm2, esi+16 );
+ xmm4=_mm_shufflehi_epi16( xmm4, 0xD8 );
+ paddd (xmm1, M128_round_inv_row);
+ xmm4=_mm_shufflelo_epi16 (xmm4, 0xD8 );
+ pmaddwd (xmm0, esi+48 );
+ xmm5=_mm_shuffle_epi32( xmm4, 0 );
+ xmm6=_mm_shuffle_epi32( xmm4, 0xAA );
+ pmaddwd (xmm5, ecx );
+ paddd (xmm1, xmm2 );
+ movdqa (xmm2, xmm1 );
+ xmm7=_mm_shuffle_epi32( xmm4, 0x55 );
+ pmaddwd (xmm6, ecx+16 );
+ paddd (xmm0, xmm3 );
+ xmm4=_mm_shuffle_epi32( xmm4, 0xFF );
+ psubd (xmm2, xmm0 );
+ pmaddwd (xmm7, ecx+32 );
+ paddd (xmm0, xmm1 );
+ psrad (xmm2, 12 );
+ paddd (xmm5, M128_round_inv_row);
+ pmaddwd (xmm4, ecx+48 );
+ paddd (xmm5, xmm6 );
+ movdqa (xmm6, xmm5 );
+ psrad (xmm0, 12 );
+ xmm2=_mm_shuffle_epi32( xmm2, 0x1B );
+ packssdw (xmm0, xmm2 );
+ paddd (xmm4, xmm7 );
+ psubd (xmm6, xmm4 );
+ paddd (xmm4, xmm5 );
+ psrad (xmm6, 12 );
+ psrad (xmm4, 12 );
+ xmm6=_mm_shuffle_epi32( xmm6, 0x1B );
+ packssdw (xmm4, xmm6 );
}
static __forceinline void DCT_8_INV_COL_8(__m128i &src0,__m128i &src1,__m128i &src2,__m128i &src3,__m128i &src4,__m128i &src5,__m128i &src6,__m128i &src7,
- __m128i &xmm0,__m128i &xmm1,__m128i &xmm2,__m128i &xmm3,__m128i &xmm4,__m128i &xmm5,__m128i &xmm6,__m128i &xmm7)
+ __m128i &xmm0,__m128i &xmm1,__m128i &xmm2,__m128i &xmm3,__m128i &xmm4,__m128i &xmm5,__m128i &xmm6,__m128i &xmm7)
{
- movdqa( xmm1, M128_tg_3_16 );
- movdqa( xmm2, xmm0 );
- movdqa( xmm3, src3 );
- pmulhw( xmm0, xmm1 );
- pmulhw( xmm1, xmm3 );
- movdqa( xmm5, M128_tg_1_16 );
- movdqa( xmm6, xmm4 );
- pmulhw( xmm4, xmm5 );
- paddsw( xmm0, xmm2 );
- pmulhw( xmm5, src1 );
- paddsw( xmm1, xmm3 );
- movdqa( xmm7, src6 );
- paddsw( xmm0, xmm3 );
- movdqa( xmm3, M128_tg_2_16 );
- psubsw( xmm2, xmm1 );
- pmulhw( xmm7, xmm3 );
- movdqa( xmm1, xmm0 );
- pmulhw( xmm3, src2 );
- psubsw( xmm5, xmm6 );
- paddsw( xmm4, src1 );
- paddsw( xmm0, xmm4 );
- paddsw( xmm0, M128_one_corr );
- psubsw( xmm4, xmm1 );
- movdqa( xmm6, xmm5 );
- psubsw( xmm5, xmm2 );
- paddsw( xmm5, M128_one_corr );
- paddsw( xmm6, xmm2 );
- movdqa( src7, xmm0 );
- movdqa( xmm1, xmm4 );
- movdqa( xmm0, M128_cos_4_16 );
- paddsw( xmm4, xmm5 );
- movdqa( xmm2, M128_cos_4_16 );
- pmulhw( xmm2, xmm4 );
- movdqa( src3, xmm6 );
- psubsw( xmm1, xmm5 );
- paddsw( xmm7, src2 );
- psubsw( xmm3, src6 );
- movdqa( xmm6, src0 );
- pmulhw( xmm0, xmm1 );
- movdqa( xmm5, src4 );
- paddsw( xmm5, xmm6 );
- psubsw( xmm6, src4 );
- paddsw( xmm4, xmm2 );
- por ( xmm4, M128_one_corr );
- paddsw( xmm0, xmm1 );
- por ( xmm0, M128_one_corr );
- movdqa( xmm2, xmm5 );
- paddsw( xmm5, xmm7 );
- movdqa( xmm1, xmm6 );
- paddsw( xmm5, M128_round_inv_col );
- psubsw( xmm2, xmm7 );
- movdqa( xmm7, src7 );
- paddsw( xmm6, xmm3 );
- paddsw( xmm6, M128_round_inv_col );
- paddsw( xmm7, xmm5 );
- psraw ( xmm7, SHIFT_INV_COL );
- psubsw( xmm1, xmm3 );
- paddsw( xmm1, M128_round_inv_corr );
- movdqa( xmm3, xmm6 );
- paddsw( xmm2, M128_round_inv_corr );
- paddsw( xmm6, xmm4 );
- movdqa( src0,xmm7 );
- psraw (xmm6, SHIFT_INV_COL );
- movdqa( xmm7, xmm1 );
- paddsw( xmm1, xmm0 );
- movdqa( src1, xmm6 );
- psraw (xmm1, SHIFT_INV_COL );
- movdqa( xmm6, src3 );
- psubsw( xmm7, xmm0 );
- psraw (xmm7, SHIFT_INV_COL );
- movdqa( src2, xmm1 );
- psubsw( xmm5, src7 );
- psraw (xmm5, SHIFT_INV_COL );
- movdqa( src7, xmm5 );
- psubsw( xmm3, xmm4 );
- paddsw( xmm6, xmm2 );
- psubsw( xmm2, src3 );
- psraw (xmm6, SHIFT_INV_COL );
- psraw (xmm2, SHIFT_INV_COL );
- movdqa( src3, xmm6 );
- psraw (xmm3, SHIFT_INV_COL );
- movdqa( src4, xmm2 );
- movdqa( src5, xmm7 );
- movdqa( src6, xmm3 );
+ movdqa( xmm1, M128_tg_3_16 );
+ movdqa( xmm2, xmm0 );
+ movdqa( xmm3, src3 );
+ pmulhw( xmm0, xmm1 );
+ pmulhw( xmm1, xmm3 );
+ movdqa( xmm5, M128_tg_1_16 );
+ movdqa( xmm6, xmm4 );
+ pmulhw( xmm4, xmm5 );
+ paddsw( xmm0, xmm2 );
+ pmulhw( xmm5, src1 );
+ paddsw( xmm1, xmm3 );
+ movdqa( xmm7, src6 );
+ paddsw( xmm0, xmm3 );
+ movdqa( xmm3, M128_tg_2_16 );
+ psubsw( xmm2, xmm1 );
+ pmulhw( xmm7, xmm3 );
+ movdqa( xmm1, xmm0 );
+ pmulhw( xmm3, src2 );
+ psubsw( xmm5, xmm6 );
+ paddsw( xmm4, src1 );
+ paddsw( xmm0, xmm4 );
+ paddsw( xmm0, M128_one_corr );
+ psubsw( xmm4, xmm1 );
+ movdqa( xmm6, xmm5 );
+ psubsw( xmm5, xmm2 );
+ paddsw( xmm5, M128_one_corr );
+ paddsw( xmm6, xmm2 );
+ movdqa( src7, xmm0 );
+ movdqa( xmm1, xmm4 );
+ movdqa( xmm0, M128_cos_4_16 );
+ paddsw( xmm4, xmm5 );
+ movdqa( xmm2, M128_cos_4_16 );
+ pmulhw( xmm2, xmm4 );
+ movdqa( src3, xmm6 );
+ psubsw( xmm1, xmm5 );
+ paddsw( xmm7, src2 );
+ psubsw( xmm3, src6 );
+ movdqa( xmm6, src0 );
+ pmulhw( xmm0, xmm1 );
+ movdqa( xmm5, src4 );
+ paddsw( xmm5, xmm6 );
+ psubsw( xmm6, src4 );
+ paddsw( xmm4, xmm2 );
+ por ( xmm4, M128_one_corr );
+ paddsw( xmm0, xmm1 );
+ por ( xmm0, M128_one_corr );
+ movdqa( xmm2, xmm5 );
+ paddsw( xmm5, xmm7 );
+ movdqa( xmm1, xmm6 );
+ paddsw( xmm5, M128_round_inv_col );
+ psubsw( xmm2, xmm7 );
+ movdqa( xmm7, src7 );
+ paddsw( xmm6, xmm3 );
+ paddsw( xmm6, M128_round_inv_col );
+ paddsw( xmm7, xmm5 );
+ psraw ( xmm7, SHIFT_INV_COL );
+ psubsw( xmm1, xmm3 );
+ paddsw( xmm1, M128_round_inv_corr );
+ movdqa( xmm3, xmm6 );
+ paddsw( xmm2, M128_round_inv_corr );
+ paddsw( xmm6, xmm4 );
+ movdqa( src0,xmm7 );
+ psraw (xmm6, SHIFT_INV_COL );
+ movdqa( xmm7, xmm1 );
+ paddsw( xmm1, xmm0 );
+ movdqa( src1, xmm6 );
+ psraw (xmm1, SHIFT_INV_COL );
+ movdqa( xmm6, src3 );
+ psubsw( xmm7, xmm0 );
+ psraw (xmm7, SHIFT_INV_COL );
+ movdqa( src2, xmm1 );
+ psubsw( xmm5, src7 );
+ psraw (xmm5, SHIFT_INV_COL );
+ movdqa( src7, xmm5 );
+ psubsw( xmm3, xmm4 );
+ paddsw( xmm6, xmm2 );
+ psubsw( xmm2, src3 );
+ psraw (xmm6, SHIFT_INV_COL );
+ psraw (xmm2, SHIFT_INV_COL );
+ movdqa( src3, xmm6 );
+ psraw (xmm3, SHIFT_INV_COL );
+ movdqa( src4, xmm2 );
+ movdqa( src5, xmm7 );
+ movdqa( src6, xmm3 );
}
static __forceinline void idct_M128ASM(__m128i &src0,__m128i &src1,__m128i &src2,__m128i &src3,__m128i &src4,__m128i &src5,__m128i &src6,__m128i &src7)
{
-__m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7;
- movdqa (xmm0, src0);
- uint8_t *esi=(uint8_t*)M128_tab_i_04;
- movdqa (xmm4, src2);
- uint8_t *ecx=(uint8_t*)M128_tab_i_26;
- DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
- movdqa (src0, xmm0);
- movdqa (src2, xmm4);
+ __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7;
+ movdqa (xmm0, src0);
+ uint8_t *esi=(uint8_t*)M128_tab_i_04;
+ movdqa (xmm4, src2);
+ uint8_t *ecx=(uint8_t*)M128_tab_i_26;
+ DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
+ movdqa (src0, xmm0);
+ movdqa (src2, xmm4);
- movdqa (xmm0, src4);
- movdqa (xmm4, src6);
- DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
- movdqa (src4, xmm0);
- movdqa (src6, xmm4);
+ movdqa (xmm0, src4);
+ movdqa (xmm4, src6);
+ DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
+ movdqa (src4, xmm0);
+ movdqa (src6, xmm4);
- movdqa (xmm0, src3);
- esi=(uint8_t*)M128_tab_i_35;
- movdqa (xmm4, src1);
- ecx=(uint8_t*)M128_tab_i_17;
- DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
- movdqa (src3, xmm0);
- movdqa (src1, xmm4);
+ movdqa (xmm0, src3);
+ esi=(uint8_t*)M128_tab_i_35;
+ movdqa (xmm4, src1);
+ ecx=(uint8_t*)M128_tab_i_17;
+ DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
+ movdqa (src3, xmm0);
+ movdqa (src1, xmm4);
- movdqa (xmm0, src5);
- movdqa (xmm4, src7);
- DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
- DCT_8_INV_COL_8(src0,src1,src2,src3,src4,src5,src6,src7,
- xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
+ movdqa (xmm0, src5);
+ movdqa (xmm4, src7);
+ DCT_8_INV_ROW(ecx,esi,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
+ DCT_8_INV_COL_8(src0,src1,src2,src3,src4,src5,src6,src7,
+ xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7);
}
void mpeg2_idct_copy_sse2(int16_t* block, uint8_t* dest, const int stride)
{
- __m128i &src0=*(__m128i*)(block+0*16/2);
- __m128i &src1=*(__m128i*)(block+1*16/2);
- __m128i &src2=*(__m128i*)(block+2*16/2);
- __m128i &src3=*(__m128i*)(block+3*16/2);
- __m128i &src4=*(__m128i*)(block+4*16/2);
- __m128i &src5=*(__m128i*)(block+5*16/2);
- __m128i &src6=*(__m128i*)(block+6*16/2);
- __m128i &src7=*(__m128i*)(block+7*16/2);
- idct_M128ASM (src0,src1,src2,src3,src4,src5,src6,src7);
+ __m128i &src0=*(__m128i*)(block+0*16/2);
+ __m128i &src1=*(__m128i*)(block+1*16/2);
+ __m128i &src2=*(__m128i*)(block+2*16/2);
+ __m128i &src3=*(__m128i*)(block+3*16/2);
+ __m128i &src4=*(__m128i*)(block+4*16/2);
+ __m128i &src5=*(__m128i*)(block+5*16/2);
+ __m128i &src6=*(__m128i*)(block+6*16/2);
+ __m128i &src7=*(__m128i*)(block+7*16/2);
+ idct_M128ASM (src0,src1,src2,src3,src4,src5,src6,src7);
- __m128i zero = _mm_setzero_si128();
+ __m128i zero = _mm_setzero_si128();
- __m128i r0 = _mm_packus_epi16(_mm_load_si128(&src0), _mm_load_si128(&src1));
- __m128i r1 = _mm_packus_epi16(_mm_load_si128(&src2), _mm_load_si128(&src3));
- __m128i r2 = _mm_packus_epi16(_mm_load_si128(&src4), _mm_load_si128(&src5));
- __m128i r3 = _mm_packus_epi16(_mm_load_si128(&src6), _mm_load_si128(&src7));
+ __m128i r0 = _mm_packus_epi16(_mm_load_si128(&src0), _mm_load_si128(&src1));
+ __m128i r1 = _mm_packus_epi16(_mm_load_si128(&src2), _mm_load_si128(&src3));
+ __m128i r2 = _mm_packus_epi16(_mm_load_si128(&src4), _mm_load_si128(&src5));
+ __m128i r3 = _mm_packus_epi16(_mm_load_si128(&src6), _mm_load_si128(&src7));
- _mm_storel_pi((__m64*)&dest[0*stride], *(__m128*)&r0);
- _mm_storeh_pi((__m64*)&dest[1*stride], *(__m128*)&r0);
- _mm_storel_pi((__m64*)&dest[2*stride], *(__m128*)&r1);
- _mm_storeh_pi((__m64*)&dest[3*stride], *(__m128*)&r1);
- _mm_storel_pi((__m64*)&dest[4*stride], *(__m128*)&r2);
- _mm_storeh_pi((__m64*)&dest[5*stride], *(__m128*)&r2);
- _mm_storel_pi((__m64*)&dest[6*stride], *(__m128*)&r3);
- _mm_storeh_pi((__m64*)&dest[7*stride], *(__m128*)&r3);
+ _mm_storel_pi((__m64*)&dest[0*stride], *(__m128*)&r0);
+ _mm_storeh_pi((__m64*)&dest[1*stride], *(__m128*)&r0);
+ _mm_storel_pi((__m64*)&dest[2*stride], *(__m128*)&r1);
+ _mm_storeh_pi((__m64*)&dest[3*stride], *(__m128*)&r1);
+ _mm_storel_pi((__m64*)&dest[4*stride], *(__m128*)&r2);
+ _mm_storeh_pi((__m64*)&dest[5*stride], *(__m128*)&r2);
+ _mm_storel_pi((__m64*)&dest[6*stride], *(__m128*)&r3);
+ _mm_storeh_pi((__m64*)&dest[7*stride], *(__m128*)&r3);
- _mm_store_si128(&src0, zero);
- _mm_store_si128(&src1, zero);
- _mm_store_si128(&src2, zero);
- _mm_store_si128(&src3, zero);
- _mm_store_si128(&src4, zero);
- _mm_store_si128(&src5, zero);
- _mm_store_si128(&src6, zero);
- _mm_store_si128(&src7, zero);
+ _mm_store_si128(&src0, zero);
+ _mm_store_si128(&src1, zero);
+ _mm_store_si128(&src2, zero);
+ _mm_store_si128(&src3, zero);
+ _mm_store_si128(&src4, zero);
+ _mm_store_si128(&src5, zero);
+ _mm_store_si128(&src6, zero);
+ _mm_store_si128(&src7, zero);
}
void mpeg2_idct_add_sse2(int,int16_t* block, uint8_t* dest, const int stride)
{
- __m128i &src0=*(__m128i*)(block+0*16/2);
- __m128i &src1=*(__m128i*)(block+1*16/2);
- __m128i &src2=*(__m128i*)(block+2*16/2);
- __m128i &src3=*(__m128i*)(block+3*16/2);
- __m128i &src4=*(__m128i*)(block+4*16/2);
- __m128i &src5=*(__m128i*)(block+5*16/2);
- __m128i &src6=*(__m128i*)(block+6*16/2);
- __m128i &src7=*(__m128i*)(block+7*16/2);
- idct_M128ASM (src0,src1,src2,src3,src4,src5,src6,src7);
+ __m128i &src0=*(__m128i*)(block+0*16/2);
+ __m128i &src1=*(__m128i*)(block+1*16/2);
+ __m128i &src2=*(__m128i*)(block+2*16/2);
+ __m128i &src3=*(__m128i*)(block+3*16/2);
+ __m128i &src4=*(__m128i*)(block+4*16/2);
+ __m128i &src5=*(__m128i*)(block+5*16/2);
+ __m128i &src6=*(__m128i*)(block+6*16/2);
+ __m128i &src7=*(__m128i*)(block+7*16/2);
+ idct_M128ASM (src0,src1,src2,src3,src4,src5,src6,src7);
- __m128i zero = _mm_setzero_si128();
+ __m128i zero = _mm_setzero_si128();
- __m128i r0 = _mm_load_si128(&src0);
- __m128i r1 = _mm_load_si128(&src1);
- __m128i r2 = _mm_load_si128(&src2);
- __m128i r3 = _mm_load_si128(&src3);
- __m128i r4 = _mm_load_si128(&src4);
- __m128i r5 = _mm_load_si128(&src5);
- __m128i r6 = _mm_load_si128(&src6);
- __m128i r7 = _mm_load_si128(&src7);
+ __m128i r0 = _mm_load_si128(&src0);
+ __m128i r1 = _mm_load_si128(&src1);
+ __m128i r2 = _mm_load_si128(&src2);
+ __m128i r3 = _mm_load_si128(&src3);
+ __m128i r4 = _mm_load_si128(&src4);
+ __m128i r5 = _mm_load_si128(&src5);
+ __m128i r6 = _mm_load_si128(&src6);
+ __m128i r7 = _mm_load_si128(&src7);
- __m128 q0 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[0*stride]);
- __m128 q1 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[1*stride]);
- __m128 q2 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[2*stride]);
- __m128 q3 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[3*stride]);
- __m128 q4 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[4*stride]);
- __m128 q5 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[5*stride]);
- __m128 q6 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[6*stride]);
- __m128 q7 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[7*stride]);
+ __m128 q0 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[0*stride]);
+ __m128 q1 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[1*stride]);
+ __m128 q2 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[2*stride]);
+ __m128 q3 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[3*stride]);
+ __m128 q4 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[4*stride]);
+ __m128 q5 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[5*stride]);
+ __m128 q6 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[6*stride]);
+ __m128 q7 = _mm_loadl_pi(*(__m128*)&zero, (__m64*)&dest[7*stride]);
- r0 = _mm_adds_epi16(r0, _mm_unpacklo_epi8(*(__m128i*)&q0, zero));
- r1 = _mm_adds_epi16(r1, _mm_unpacklo_epi8(*(__m128i*)&q1, zero));
- r2 = _mm_adds_epi16(r2, _mm_unpacklo_epi8(*(__m128i*)&q2, zero));
- r3 = _mm_adds_epi16(r3, _mm_unpacklo_epi8(*(__m128i*)&q3, zero));
- r4 = _mm_adds_epi16(r4, _mm_unpacklo_epi8(*(__m128i*)&q4, zero));
- r5 = _mm_adds_epi16(r5, _mm_unpacklo_epi8(*(__m128i*)&q5, zero));
- r6 = _mm_adds_epi16(r6, _mm_unpacklo_epi8(*(__m128i*)&q6, zero));
- r7 = _mm_adds_epi16(r7, _mm_unpacklo_epi8(*(__m128i*)&q7, zero));
+ r0 = _mm_adds_epi16(r0, _mm_unpacklo_epi8(*(__m128i*)&q0, zero));
+ r1 = _mm_adds_epi16(r1, _mm_unpacklo_epi8(*(__m128i*)&q1, zero));
+ r2 = _mm_adds_epi16(r2, _mm_unpacklo_epi8(*(__m128i*)&q2, zero));
+ r3 = _mm_adds_epi16(r3, _mm_unpacklo_epi8(*(__m128i*)&q3, zero));
+ r4 = _mm_adds_epi16(r4, _mm_unpacklo_epi8(*(__m128i*)&q4, zero));
+ r5 = _mm_adds_epi16(r5, _mm_unpacklo_epi8(*(__m128i*)&q5, zero));
+ r6 = _mm_adds_epi16(r6, _mm_unpacklo_epi8(*(__m128i*)&q6, zero));
+ r7 = _mm_adds_epi16(r7, _mm_unpacklo_epi8(*(__m128i*)&q7, zero));
- r0 = _mm_packus_epi16(r0, r1);
- r1 = _mm_packus_epi16(r2, r3);
- r2 = _mm_packus_epi16(r4, r5);
- r3 = _mm_packus_epi16(r6, r7);
+ r0 = _mm_packus_epi16(r0, r1);
+ r1 = _mm_packus_epi16(r2, r3);
+ r2 = _mm_packus_epi16(r4, r5);
+ r3 = _mm_packus_epi16(r6, r7);
- _mm_storel_pi((__m64*)&dest[0*stride], *(__m128*)&r0);
- _mm_storeh_pi((__m64*)&dest[1*stride], *(__m128*)&r0);
- _mm_storel_pi((__m64*)&dest[2*stride], *(__m128*)&r1);
- _mm_storeh_pi((__m64*)&dest[3*stride], *(__m128*)&r1);
- _mm_storel_pi((__m64*)&dest[4*stride], *(__m128*)&r2);
- _mm_storeh_pi((__m64*)&dest[5*stride], *(__m128*)&r2);
- _mm_storel_pi((__m64*)&dest[6*stride], *(__m128*)&r3);
- _mm_storeh_pi((__m64*)&dest[7*stride], *(__m128*)&r3);
+ _mm_storel_pi((__m64*)&dest[0*stride], *(__m128*)&r0);
+ _mm_storeh_pi((__m64*)&dest[1*stride], *(__m128*)&r0);
+ _mm_storel_pi((__m64*)&dest[2*stride], *(__m128*)&r1);
+ _mm_storeh_pi((__m64*)&dest[3*stride], *(__m128*)&r1);
+ _mm_storel_pi((__m64*)&dest[4*stride], *(__m128*)&r2);
+ _mm_storeh_pi((__m64*)&dest[5*stride], *(__m128*)&r2);
+ _mm_storel_pi((__m64*)&dest[6*stride], *(__m128*)&r3);
+ _mm_storeh_pi((__m64*)&dest[7*stride], *(__m128*)&r3);
- _mm_store_si128(&src0, zero);
- _mm_store_si128(&src1, zero);
- _mm_store_si128(&src2, zero);
- _mm_store_si128(&src3, zero);
- _mm_store_si128(&src4, zero);
- _mm_store_si128(&src5, zero);
- _mm_store_si128(&src6, zero);
- _mm_store_si128(&src7, zero);
+ _mm_store_si128(&src0, zero);
+ _mm_store_si128(&src1, zero);
+ _mm_store_si128(&src2, zero);
+ _mm_store_si128(&src3, zero);
+ _mm_store_si128(&src4, zero);
+ _mm_store_si128(&src5, zero);
+ _mm_store_si128(&src6, zero);
+ _mm_store_si128(&src7, zero);
}
void mpeg2_idct_init_sse2()
diff --git a/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp b/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp
index 3d5061bd0..c71dad156 100644
--- a/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp
+++ b/src/filters/transform/Mpeg2DecFilter/mc_sse2.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -31,459 +31,452 @@ static const __m128i const_1_16_bytes=_mm_set1_epi16(1);
static void MC_put_o_16_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
{
- const int edi= eax+eax;
- const int ebx= edi+eax;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4){
- __m128i xmm0,xmm1,xmm2,xmm3;
- movdqu (xmm0, edx );
- movdqu (xmm1, edx+eax);
- movdqu (xmm2, edx+edi);
- movdqu (xmm3, edx+ebx);
- movdqa (ecx, xmm0 );
- movdqa (ecx+eax, xmm1 );
- movdqa (ecx+edi, xmm2 );
- movdqa (ecx+ebx, xmm3 );
- }
+ const int edi= eax+eax;
+ const int ebx= edi+eax;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ __m128i xmm0,xmm1,xmm2,xmm3;
+ movdqu (xmm0, edx );
+ movdqu (xmm1, edx+eax);
+ movdqu (xmm2, edx+edi);
+ movdqu (xmm3, edx+ebx);
+ movdqa (ecx, xmm0 );
+ movdqa (ecx+eax, xmm1 );
+ movdqa (ecx+edi, xmm2 );
+ movdqa (ecx+ebx, xmm3 );
+ }
}
static void MC_put_o_8_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
{
- const int edi= eax+eax;
- const int ebx= edi+eax;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4){
- __m128d xmm0,xmm1,xmm2,xmm3;
- movlpd (xmm0, edx);
- movlpd (xmm1, edx+eax);
- movlpd (xmm2, edx+edi);
- movlpd (xmm3, edx+ebx);
- movlpd (ecx, xmm0);
- movlpd (ecx+eax, xmm1 );
- movlpd (ecx+edi, xmm2);
- movlpd (ecx+ebx, xmm3 );
- }
+ const int edi= eax+eax;
+ const int ebx= edi+eax;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ __m128d xmm0,xmm1,xmm2,xmm3;
+ movlpd (xmm0, edx);
+ movlpd (xmm1, edx+eax);
+ movlpd (xmm2, edx+edi);
+ movlpd (xmm3, edx+ebx);
+ movlpd (ecx, xmm0);
+ movlpd (ecx+eax, xmm1 );
+ movlpd (ecx+edi, xmm2);
+ movlpd (ecx+ebx, xmm3 );
+ }
}
static void MC_put_x_16_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
{
- const int edi= eax+eax;
- const int ebx= edi+eax;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4){
- __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7;
- movdqu (xmm0, edx);
- movdqu (xmm1, edx+1);
- movdqu (xmm2, edx+eax);
- movdqu (xmm3, edx+eax+1);
- movdqu (xmm4, edx+edi);
- movdqu( xmm5, edx+edi+1);
- movdqu( xmm6, edx+ebx );
- movdqu( xmm7, edx+ebx+1 );
- pavgb (xmm0, xmm1);
- pavgb (xmm2, xmm3);
- pavgb (xmm4, xmm5);
- pavgb (xmm6, xmm7);
- movdqa (ecx, xmm0);
- movdqa (ecx+eax, xmm2);
- movdqa (ecx+edi, xmm4);
- movdqa (ecx+ebx, xmm6);
- }
+ const int edi= eax+eax;
+ const int ebx= edi+eax;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7;
+ movdqu (xmm0, edx);
+ movdqu (xmm1, edx+1);
+ movdqu (xmm2, edx+eax);
+ movdqu (xmm3, edx+eax+1);
+ movdqu (xmm4, edx+edi);
+ movdqu( xmm5, edx+edi+1);
+ movdqu( xmm6, edx+ebx );
+ movdqu( xmm7, edx+ebx+1 );
+ pavgb (xmm0, xmm1);
+ pavgb (xmm2, xmm3);
+ pavgb (xmm4, xmm5);
+ pavgb (xmm6, xmm7);
+ movdqa (ecx, xmm0);
+ movdqa (ecx+eax, xmm2);
+ movdqa (ecx+edi, xmm4);
+ movdqa (ecx+ebx, xmm6);
+ }
}
static void MC_put_x_8_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
{
- const int edi= eax+eax;
- const int ebx= edi+eax;
- __m128i xmm0,xmm1,xmm2,xmm3;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4){
- movlpd (xmm0, edx);
- movlpd (xmm1, edx+1);
- movhpd (xmm0, edx+eax);
- movhpd (xmm1, edx+eax+1);
- movlpd (xmm2, edx+edi);
- movlpd (xmm3, edx+edi+1);
- movhpd (xmm2, edx+ebx);
- movhpd (xmm3, edx+ebx+1);
- pavgb (xmm0, xmm1);
- pavgb (xmm2, xmm3);
- movlpd (ecx, xmm0);
- movhpd (ecx+eax, xmm0);
- movlpd (ecx+edi, xmm2);
- movhpd (ecx+ebx, xmm2);
- }
+ const int edi= eax+eax;
+ const int ebx= edi+eax;
+ __m128i xmm0,xmm1,xmm2,xmm3;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ movlpd (xmm0, edx);
+ movlpd (xmm1, edx+1);
+ movhpd (xmm0, edx+eax);
+ movhpd (xmm1, edx+eax+1);
+ movlpd (xmm2, edx+edi);
+ movlpd (xmm3, edx+edi+1);
+ movhpd (xmm2, edx+ebx);
+ movhpd (xmm3, edx+ebx+1);
+ pavgb (xmm0, xmm1);
+ pavgb (xmm2, xmm3);
+ movlpd (ecx, xmm0);
+ movhpd (ecx+eax, xmm0);
+ movlpd (ecx+edi, xmm2);
+ movhpd (ecx+ebx, xmm2);
+ }
}
static void MC_put_y_16_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
{
- const int edi= eax+eax;
- const int ebx= edi+eax;
- __m128i xmm0;
- movdqu (xmm0, edx);
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4){
- __m128i xmm1,xmm2,xmm3,xmm4;
- movdqu (xmm1, edx+eax);
- movdqu (xmm2, edx+edi );
- movdqu (xmm3, edx+ebx );
- movdqu (xmm4, edx+edi*2 );
- pavgb (xmm0, xmm1 );
- pavgb (xmm1, xmm2 );
- pavgb (xmm2, xmm3 );
- pavgb (xmm3, xmm4 );
- movdqa (ecx, xmm0 );
- movdqa (ecx+eax, xmm1 );
- movdqa (ecx+edi, xmm2 );
- movdqa (ecx+ebx, xmm3 );
- movdqa (xmm0, xmm4 );
- }
+ const int edi= eax+eax;
+ const int ebx= edi+eax;
+ __m128i xmm0;
+ movdqu (xmm0, edx);
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ __m128i xmm1,xmm2,xmm3,xmm4;
+ movdqu (xmm1, edx+eax);
+ movdqu (xmm2, edx+edi );
+ movdqu (xmm3, edx+ebx );
+ movdqu (xmm4, edx+edi*2 );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm1, xmm2 );
+ pavgb (xmm2, xmm3 );
+ pavgb (xmm3, xmm4 );
+ movdqa (ecx, xmm0 );
+ movdqa (ecx+eax, xmm1 );
+ movdqa (ecx+edi, xmm2 );
+ movdqa (ecx+ebx, xmm3 );
+ movdqa (xmm0, xmm4 );
+ }
}
static void MC_put_y_8_sse2(uint8_t* ecx, const uint8_t* edx, const int eax, int esi)
{
- const int edi= eax+eax;
- const int ebx= edi+eax;
- __m128i xmm0;
- movlpd (xmm0, edx);
+ const int edi= eax+eax;
+ const int ebx= edi+eax;
+ __m128i xmm0;
+ movlpd (xmm0, edx);
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4){
- __m128i xmm1,xmm2,xmm3,xmm4;
- movlpd (xmm1, edx+eax );
- movlpd (xmm2, edx+edi );
- movlpd (xmm3, edx+ebx );
- movlpd (xmm4, edx+edi*2 );
- pavgb (xmm0, xmm1 );
- pavgb (xmm1, xmm2);
- pavgb (xmm2, xmm3 );
- pavgb (xmm3, xmm4 );
- movlpd (ecx, xmm0 );
- movlpd (ecx+eax, xmm1 );
- movlpd (ecx+edi, xmm2 );
- movlpd (ecx+ebx, xmm3 );
- movdqa (xmm0, xmm4 );
- }
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ __m128i xmm1,xmm2,xmm3,xmm4;
+ movlpd (xmm1, edx+eax );
+ movlpd (xmm2, edx+edi );
+ movlpd (xmm3, edx+ebx );
+ movlpd (xmm4, edx+edi*2 );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm1, xmm2);
+ pavgb (xmm2, xmm3 );
+ pavgb (xmm3, xmm4 );
+ movlpd (ecx, xmm0 );
+ movlpd (ecx+eax, xmm1 );
+ movlpd (ecx+edi, xmm2 );
+ movlpd (ecx+ebx, xmm3 );
+ movdqa (xmm0, xmm4 );
+ }
}
static void MC_put_xy_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref ;
- uint8_t *ecx= dest;
- int eax= stride;
- int esi= height;
- int edi= eax+eax;
- __m128i xmm7,xmm0,xmm1,xmm4,xmm5,xmm2,xmm3;
- movdqa (xmm7, const_1_16_bytes );
- movdqu (xmm0, edx );
- movdqu (xmm1, edx+1 );
- for (;esi;edx+= edi,ecx+= edi,esi-= 2)
- {
- movdqu (xmm2, edx+eax );
- movdqu (xmm3, edx+eax+1 );
- movdqu (xmm4, edx+edi );
- movdqu (xmm5, edx+edi+1 );
- pavgb (xmm0, xmm1 );
- pavgb (xmm2, xmm3 );
- movdqa( xmm1, xmm5 );
- pavgb (xmm5, xmm4 );
- psubusb( xmm2, xmm7 );
- pavgb (xmm0, xmm2 );
- pavgb (xmm2, xmm5);
- movdqa (ecx, xmm0);
- movdqa (xmm0, xmm4);
- movdqa (ecx+eax, xmm2);
- }
+ const uint8_t *edx= ref ;
+ uint8_t *ecx= dest;
+ int eax= stride;
+ int esi= height;
+ int edi= eax+eax;
+ __m128i xmm7,xmm0,xmm1,xmm4,xmm5,xmm2,xmm3;
+ movdqa (xmm7, const_1_16_bytes );
+ movdqu (xmm0, edx );
+ movdqu (xmm1, edx+1 );
+ for (; esi; edx+= edi,ecx+= edi,esi-= 2) {
+ movdqu (xmm2, edx+eax );
+ movdqu (xmm3, edx+eax+1 );
+ movdqu (xmm4, edx+edi );
+ movdqu (xmm5, edx+edi+1 );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm2, xmm3 );
+ movdqa( xmm1, xmm5 );
+ pavgb (xmm5, xmm4 );
+ psubusb( xmm2, xmm7 );
+ pavgb (xmm0, xmm2 );
+ pavgb (xmm2, xmm5);
+ movdqa (ecx, xmm0);
+ movdqa (xmm0, xmm4);
+ movdqa (ecx+eax, xmm2);
+ }
}
static void MC_put_xy_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int eax= stride;
- int esi= height;
- int edi= eax+eax;
- __m128i xmm7,xmm0,xmm2,xmm1,xmm3,xmm4,xmm5;
- movdqa (xmm7, const_1_16_bytes);
- movlpd (xmm0, edx);
- movlpd (xmm1, edx+1);
- for (;esi;edx+= edi,ecx+= edi,esi-= 2)
- {
- movlpd (xmm2, edx+eax);
- movlpd (xmm3, edx+eax+1);
- movlpd (xmm4, edx+edi);
- movlpd (xmm5, edx+edi+1);
- pavgb (xmm0, xmm1 );
- pavgb (xmm2, xmm3 );
- movdqa( xmm1, xmm5 );
- pavgb (xmm5, xmm4 );
- psubusb( xmm2, xmm7 );
- pavgb (xmm0, xmm2 );
- pavgb (xmm2, xmm5);
- movlpd (ecx, xmm0);
- movdqa (xmm0, xmm4);
- movlpd (ecx+eax, xmm2);
- }
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int eax= stride;
+ int esi= height;
+ int edi= eax+eax;
+ __m128i xmm7,xmm0,xmm2,xmm1,xmm3,xmm4,xmm5;
+ movdqa (xmm7, const_1_16_bytes);
+ movlpd (xmm0, edx);
+ movlpd (xmm1, edx+1);
+ for (; esi; edx+= edi,ecx+= edi,esi-= 2) {
+ movlpd (xmm2, edx+eax);
+ movlpd (xmm3, edx+eax+1);
+ movlpd (xmm4, edx+edi);
+ movlpd (xmm5, edx+edi+1);
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm2, xmm3 );
+ movdqa( xmm1, xmm5 );
+ pavgb (xmm5, xmm4 );
+ psubusb( xmm2, xmm7 );
+ pavgb (xmm0, xmm2 );
+ pavgb (xmm2, xmm5);
+ movlpd (ecx, xmm0);
+ movdqa (xmm0, xmm4);
+ movlpd (ecx+eax, xmm2);
+ }
}
static void MC_avg_o_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- int ebx= edi+eax;
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ int ebx= edi+eax;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4)
- {
- __m128i xmm0,xmm1,xmm2,xmm3;
- movdqu (xmm0, edx);
- movdqu (xmm1, edx+eax );
- movdqu (xmm2, edx+edi);
- movdqu (xmm3, edx+ebx );
- pavgb (xmm0, ecx);
- pavgb (xmm1, ecx+eax);
- pavgb (xmm2, ecx+edi);
- pavgb (xmm3, ecx+ebx);
- movdqa (ecx, xmm0);
- movdqa (ecx+eax, xmm1 );
- movdqa (ecx+edi, xmm2);
- movdqa (ecx+ebx, xmm3 );
- }
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ __m128i xmm0,xmm1,xmm2,xmm3;
+ movdqu (xmm0, edx);
+ movdqu (xmm1, edx+eax );
+ movdqu (xmm2, edx+edi);
+ movdqu (xmm3, edx+ebx );
+ pavgb (xmm0, ecx);
+ pavgb (xmm1, ecx+eax);
+ pavgb (xmm2, ecx+edi);
+ pavgb (xmm3, ecx+ebx);
+ movdqa (ecx, xmm0);
+ movdqa (ecx+eax, xmm1 );
+ movdqa (ecx+edi, xmm2);
+ movdqa (ecx+ebx, xmm3 );
+ }
}
static void MC_avg_o_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- int ebx= edi+eax;
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ int ebx= edi+eax;
- __m128i xmm0,xmm1,xmm2,xmm3;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4)
- {
- movlpd (xmm0, edx);
- movhpd (xmm0, edx+eax );
- movlpd (xmm2, edx+edi);
- movhpd (xmm2, edx+ebx );
- movlpd (xmm1, ecx);
- movhpd (xmm1, ecx+eax);
- movlpd (xmm3, ecx+edi);
- movhpd (xmm3, ecx+ebx);
- pavgb (xmm0, xmm1);
- pavgb (xmm2, xmm3);
- movlpd (ecx, xmm0);
- movhpd (ecx+eax, xmm0);
- movlpd (ecx+edi, xmm2);
- movhpd (ecx+ebx, xmm2);
- }
+ __m128i xmm0,xmm1,xmm2,xmm3;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ movlpd (xmm0, edx);
+ movhpd (xmm0, edx+eax );
+ movlpd (xmm2, edx+edi);
+ movhpd (xmm2, edx+ebx );
+ movlpd (xmm1, ecx);
+ movhpd (xmm1, ecx+eax);
+ movlpd (xmm3, ecx+edi);
+ movhpd (xmm3, ecx+ebx);
+ pavgb (xmm0, xmm1);
+ pavgb (xmm2, xmm3);
+ movlpd (ecx, xmm0);
+ movhpd (ecx+eax, xmm0);
+ movlpd (ecx+edi, xmm2);
+ movhpd (ecx+ebx, xmm2);
+ }
}
static void MC_avg_x_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- int ebx= edi+eax;
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ int ebx= edi+eax;
- __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4)
- {
- movdqu (xmm0, edx);
- movdqu (xmm1, edx+1);
- movdqu (xmm2, edx+eax);
- movdqu (xmm3, edx+eax+1);
- movdqu (xmm4, edx+edi);
- movdqu (xmm5, edx+edi+1);
- movdqu (xmm6, edx+ebx);
- movdqu (xmm7, edx+ebx+1);
- pavgb (xmm0, xmm1);
- pavgb (xmm2, xmm3);
- pavgb (xmm4, xmm5);
- pavgb (xmm6, xmm7);
- pavgb (xmm0, ecx);
- pavgb (xmm2, ecx+eax);
- pavgb (xmm4, ecx+edi);
- pavgb (xmm6, ecx+ebx);
- movdqa (ecx, xmm0);
- movdqa (ecx+eax, xmm2);
- movdqa (ecx+edi, xmm4);
- movdqa (ecx+ebx, xmm6);
- }
+ __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5,xmm6,xmm7;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ movdqu (xmm0, edx);
+ movdqu (xmm1, edx+1);
+ movdqu (xmm2, edx+eax);
+ movdqu (xmm3, edx+eax+1);
+ movdqu (xmm4, edx+edi);
+ movdqu (xmm5, edx+edi+1);
+ movdqu (xmm6, edx+ebx);
+ movdqu (xmm7, edx+ebx+1);
+ pavgb (xmm0, xmm1);
+ pavgb (xmm2, xmm3);
+ pavgb (xmm4, xmm5);
+ pavgb (xmm6, xmm7);
+ pavgb (xmm0, ecx);
+ pavgb (xmm2, ecx+eax);
+ pavgb (xmm4, ecx+edi);
+ pavgb (xmm6, ecx+ebx);
+ movdqa (ecx, xmm0);
+ movdqa (ecx+eax, xmm2);
+ movdqa (ecx+edi, xmm4);
+ movdqa (ecx+ebx, xmm6);
+ }
}
static void MC_avg_x_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- int ebx= edi+eax;
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ int ebx= edi+eax;
- __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5;
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4)
- {
- movlpd (xmm0, edx);
- movlpd (xmm1, edx+1);
- movhpd (xmm0, edx+eax);
- movhpd (xmm1, edx+eax+1);
- movlpd (xmm2, edx+edi);
- movlpd (xmm3, edx+edi+1);
- movhpd (xmm2, edx+ebx);
- movhpd (xmm3, edx+ebx+1);
- movlpd (xmm4, ecx);
- movhpd (xmm4, ecx+eax);
- movlpd (xmm5, ecx+edi);
- movhpd (xmm5, ecx+ebx);
- pavgb (xmm0, xmm1);
- pavgb (xmm2, xmm3);
- pavgb (xmm0, xmm4);
- pavgb (xmm2, xmm5);
- movlpd (ecx, xmm0);
- movhpd (ecx+eax, xmm0);
- movlpd (ecx+edi, xmm2);
- movhpd (ecx+ebx, xmm2);
- }
+ __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5;
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ movlpd (xmm0, edx);
+ movlpd (xmm1, edx+1);
+ movhpd (xmm0, edx+eax);
+ movhpd (xmm1, edx+eax+1);
+ movlpd (xmm2, edx+edi);
+ movlpd (xmm3, edx+edi+1);
+ movhpd (xmm2, edx+ebx);
+ movhpd (xmm3, edx+ebx+1);
+ movlpd (xmm4, ecx);
+ movhpd (xmm4, ecx+eax);
+ movlpd (xmm5, ecx+edi);
+ movhpd (xmm5, ecx+ebx);
+ pavgb (xmm0, xmm1);
+ pavgb (xmm2, xmm3);
+ pavgb (xmm0, xmm4);
+ pavgb (xmm2, xmm5);
+ movlpd (ecx, xmm0);
+ movhpd (ecx+eax, xmm0);
+ movlpd (ecx+edi, xmm2);
+ movhpd (ecx+ebx, xmm2);
+ }
}
static void MC_avg_y_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- int ebx= edi+eax;
- __m128i xmm0,xmm1,xmm2,xmm3,xmm4;
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ int ebx= edi+eax;
+ __m128i xmm0,xmm1,xmm2,xmm3,xmm4;
- movdqu (xmm0,edx);
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4)
- {
- movdqu (xmm1, edx+eax );
- movdqu (xmm2, edx+edi );
- movdqu (xmm3, edx+ebx );
- movdqu (xmm4, edx+edi*2 );
- pavgb (xmm0, xmm1 );
- pavgb (xmm1, xmm2 );
- pavgb (xmm2, xmm3 );
- pavgb (xmm3, xmm4 );
- pavgb (xmm0, ecx);
- pavgb (xmm1, ecx+eax );
- pavgb (xmm2, ecx+edi);
- pavgb (xmm3, ecx+ebx );
- movdqa (ecx, xmm0 );
- movdqa (ecx+eax, xmm1 );
- movdqa (ecx+edi, xmm2 );
- movdqa (ecx+ebx, xmm3 );
- movdqa (xmm0, xmm4 );
- }
+ movdqu (xmm0,edx);
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ movdqu (xmm1, edx+eax );
+ movdqu (xmm2, edx+edi );
+ movdqu (xmm3, edx+ebx );
+ movdqu (xmm4, edx+edi*2 );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm1, xmm2 );
+ pavgb (xmm2, xmm3 );
+ pavgb (xmm3, xmm4 );
+ pavgb (xmm0, ecx);
+ pavgb (xmm1, ecx+eax );
+ pavgb (xmm2, ecx+edi);
+ pavgb (xmm3, ecx+ebx );
+ movdqa (ecx, xmm0 );
+ movdqa (ecx+eax, xmm1 );
+ movdqa (ecx+edi, xmm2 );
+ movdqa (ecx+ebx, xmm3 );
+ movdqa (xmm0, xmm4 );
+ }
}
static void MC_avg_y_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- int ebx= edi+eax;
- __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5;
- movhpd (xmm0, edx );
- movlpd (xmm0, edx+eax );
- for (;esi;edx+=edi*2,ecx+=edi*2,esi-=4)
- {
- movlhps (xmm1, xmm0);
- movlpd (xmm1, edx+edi );
- movlhps (xmm2, xmm1);
- movlpd (xmm2, edx+ebx );
- movlhps (xmm3, xmm2);
- movlpd (xmm3, edx+edi*2 );
- movhpd (xmm4, ecx );
- movlpd (xmm4, ecx+eax );
- movhpd (xmm5, ecx+edi );
- movlpd (xmm5, ecx+ebx );
- pavgb (xmm0, xmm1 );
- pavgb (xmm2, xmm3);
- pavgb (xmm0, xmm4);
- pavgb (xmm2, xmm5);
- movhpd (ecx, xmm0 );
- movlpd (ecx+eax, xmm0 );
- movhpd (ecx+edi, xmm2 );
- movlpd (ecx+ebx, xmm2);
- movdqa (xmm0, xmm3 );
- }
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ int ebx= edi+eax;
+ __m128i xmm0,xmm1,xmm2,xmm3,xmm4,xmm5;
+ movhpd (xmm0, edx );
+ movlpd (xmm0, edx+eax );
+ for (; esi; edx+=edi*2,ecx+=edi*2,esi-=4) {
+ movlhps (xmm1, xmm0);
+ movlpd (xmm1, edx+edi );
+ movlhps (xmm2, xmm1);
+ movlpd (xmm2, edx+ebx );
+ movlhps (xmm3, xmm2);
+ movlpd (xmm3, edx+edi*2 );
+ movhpd (xmm4, ecx );
+ movlpd (xmm4, ecx+eax );
+ movhpd (xmm5, ecx+edi );
+ movlpd (xmm5, ecx+ebx );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm2, xmm3);
+ pavgb (xmm0, xmm4);
+ pavgb (xmm2, xmm5);
+ movhpd (ecx, xmm0 );
+ movlpd (ecx+eax, xmm0 );
+ movhpd (ecx+edi, xmm2 );
+ movlpd (ecx+ebx, xmm2);
+ movdqa (xmm0, xmm3 );
+ }
}
static void MC_avg_xy_16_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- __m128i xmm7,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5;
- movdqa (xmm7, const_1_16_bytes );
- movdqu (xmm0, edx );
- movdqu (xmm1, edx+1 );
- for (;esi;edx+=edi,ecx+=edi,esi-=2)
- {
- movdqu (xmm2, edx+eax );
- movdqu (xmm3, edx+eax+1 );
- movdqu (xmm4, edx+edi );
- movdqu (xmm5, edx+edi+1 );
- pavgb (xmm0, xmm1 );
- pavgb (xmm2, xmm3 );
- movdqa (xmm1, xmm5 );
- pavgb (xmm5, xmm4 );
- psubusb (xmm2, xmm7 );
- pavgb (xmm0, xmm2 );
- pavgb (xmm2, xmm5);
- pavgb (xmm0, ecx );
- pavgb (xmm2, ecx+eax);
- movdqa (ecx, xmm0);
- movdqa (xmm0, xmm4);
- movdqa (ecx+eax, xmm2);
- }
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ __m128i xmm7,xmm0,xmm1,xmm2,xmm3,xmm4,xmm5;
+ movdqa (xmm7, const_1_16_bytes );
+ movdqu (xmm0, edx );
+ movdqu (xmm1, edx+1 );
+ for (; esi; edx+=edi,ecx+=edi,esi-=2) {
+ movdqu (xmm2, edx+eax );
+ movdqu (xmm3, edx+eax+1 );
+ movdqu (xmm4, edx+edi );
+ movdqu (xmm5, edx+edi+1 );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm2, xmm3 );
+ movdqa (xmm1, xmm5 );
+ pavgb (xmm5, xmm4 );
+ psubusb (xmm2, xmm7 );
+ pavgb (xmm0, xmm2 );
+ pavgb (xmm2, xmm5);
+ pavgb (xmm0, ecx );
+ pavgb (xmm2, ecx+eax);
+ movdqa (ecx, xmm0);
+ movdqa (xmm0, xmm4);
+ movdqa (ecx+eax, xmm2);
+ }
}
static void MC_avg_xy_8_sse2(uint8_t* dest, const uint8_t* ref, const int stride, int height)
{
- const uint8_t *edx= ref;
- uint8_t *ecx= dest;
- int esi= height;
- int eax= stride;
- int edi= eax+eax;
- __m128i xmm7,xmm0,xmm2,xmm1,xmm3,xmm4;
- movdqa (xmm7, const_1_16_bytes );
- movhpd (xmm0, edx );
- movlpd (xmm0, edx+eax );
- movhpd (xmm2, edx+1 );
- movlpd (xmm2, edx+eax+1 );
- for (;esi;edx+=edi,ecx+=edi,esi-=2)
- {
+ const uint8_t *edx= ref;
+ uint8_t *ecx= dest;
+ int esi= height;
+ int eax= stride;
+ int edi= eax+eax;
+ __m128i xmm7,xmm0,xmm2,xmm1,xmm3,xmm4;
+ movdqa (xmm7, const_1_16_bytes );
+ movhpd (xmm0, edx );
+ movlpd (xmm0, edx+eax );
+ movhpd (xmm2, edx+1 );
+ movlpd (xmm2, edx+eax+1 );
+ for (; esi; edx+=edi,ecx+=edi,esi-=2) {
- movhpd (xmm1, edx+eax );
- movlpd (xmm1, edx+edi );
- movhpd (xmm3, edx+eax+1 );
- movlpd (xmm3, edx+edi+1 );
- pavgb (xmm0, xmm1 );
- pavgb (xmm2, xmm3 );
- psubusb( xmm0, xmm7 );
- pavgb (xmm0, xmm2 );
- movhpd( xmm4, ecx);
- movlpd( xmm4, ecx+eax);
- pavgb (xmm0, xmm4 );
- movhpd (ecx, xmm0 );
- movlpd (ecx+eax, xmm0 );
- movdqa (xmm0, xmm1 );
- movdqa (xmm2, xmm3 );
- }
+ movhpd (xmm1, edx+eax );
+ movlpd (xmm1, edx+edi );
+ movhpd (xmm3, edx+eax+1 );
+ movlpd (xmm3, edx+edi+1 );
+ pavgb (xmm0, xmm1 );
+ pavgb (xmm2, xmm3 );
+ psubusb( xmm0, xmm7 );
+ pavgb (xmm0, xmm2 );
+ movhpd( xmm4, ecx);
+ movlpd( xmm4, ecx+eax);
+ pavgb (xmm0, xmm4 );
+ movhpd (ecx, xmm0 );
+ movlpd (ecx+eax, xmm0 );
+ movdqa (xmm0, xmm1 );
+ movdqa (xmm2, xmm3 );
+ }
}
-mpeg2_mc_t mpeg2_mc_sse2 =
-{
- {MC_put_o_16_sse2, MC_put_x_16_sse2, MC_put_y_16_sse2, MC_put_xy_16_sse2,
- MC_put_o_8_sse2, MC_put_x_8_sse2, MC_put_y_8_sse2, MC_put_xy_8_sse2},
- {MC_avg_o_16_sse2, MC_avg_x_16_sse2, MC_avg_y_16_sse2, MC_avg_xy_16_sse2,
- MC_avg_o_8_sse2, MC_avg_x_8_sse2, MC_avg_y_8_sse2, MC_avg_xy_8_sse2}
+mpeg2_mc_t mpeg2_mc_sse2 = {
+ {
+ MC_put_o_16_sse2, MC_put_x_16_sse2, MC_put_y_16_sse2, MC_put_xy_16_sse2,
+ MC_put_o_8_sse2, MC_put_x_8_sse2, MC_put_y_8_sse2, MC_put_xy_8_sse2
+ },
+ {
+ MC_avg_o_16_sse2, MC_avg_x_16_sse2, MC_avg_y_16_sse2, MC_avg_xy_16_sse2,
+ MC_avg_o_8_sse2, MC_avg_x_8_sse2, MC_avg_y_8_sse2, MC_avg_xy_8_sse2
+ }
};
diff --git a/src/filters/transform/Mpeg2DecFilter/stdafx.cpp b/src/filters/transform/Mpeg2DecFilter/stdafx.cpp
index 13934d005..bea3f980a 100644
--- a/src/filters/transform/Mpeg2DecFilter/stdafx.cpp
+++ b/src/filters/transform/Mpeg2DecFilter/stdafx.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/Mpeg2DecFilter/stdafx.h b/src/filters/transform/Mpeg2DecFilter/stdafx.h
index e1b753d82..2e566de2c 100644
--- a/src/filters/transform/Mpeg2DecFilter/stdafx.h
+++ b/src/filters/transform/Mpeg2DecFilter/stdafx.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
@@ -6,12 +6,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
- *
+ *
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/src/filters/transform/VSFilter/AvgLines.cpp b/src/filters/transform/VSFilter/AvgLines.cpp
index 19e80a305..2a0b89311 100644
--- a/src/filters/transform/VSFilter/AvgLines.cpp
+++ b/src/filters/transform/VSFilter/AvgLines.cpp
@@ -20,28 +20,26 @@
void AvgLines8(BYTE* dst, DWORD h, DWORD pitch)
{
- if(h <= 1)
+ if(h <= 1) {
return;
+ }
BYTE* s = dst;
BYTE* d = dst + (h-2)*pitch;
- for(; s < d; s += pitch*2)
- {
+ for(; s < d; s += pitch*2) {
BYTE* tmp = s;
#ifndef _WIN64
- if((g_cpuid.m_flags & CCpuID::sse2) && !((DWORD)tmp&0xf) && !((DWORD)pitch&0xf))
- {
- __asm
- {
+ if((g_cpuid.m_flags & CCpuID::sse2) && !((DWORD)tmp&0xf) && !((DWORD)pitch&0xf)) {
+ __asm {
mov esi, tmp
mov ebx, pitch
mov ecx, ebx
shr ecx, 4
-AvgLines8_sse2_loop:
+ AvgLines8_sse2_loop:
movdqa xmm0, [esi]
pavgb xmm0, [esi+ebx*2]
movdqa [esi+ebx], xmm0
@@ -53,15 +51,11 @@ AvgLines8_sse2_loop:
mov tmp, esi
}
- for(ptrdiff_t i = pitch&7; i--; tmp++)
- {
+ for(ptrdiff_t i = pitch&7; i--; tmp++) {
tmp[pitch] = (tmp[0] + tmp[pitch<<1] + 1) >> 1;
}
- }
- else if(g_cpuid.m_flags & CCpuID::mmx)
- {
- __asm
- {
+ } else if(g_cpuid.m_flags & CCpuID::mmx) {
+ __asm {
mov esi, tmp
mov ebx, pitch
@@ -69,7 +63,7 @@ AvgLines8_sse2_loop:
shr ecx, 3
pxor mm7, mm7
-AvgLines8_mmx_loop:
+ AvgLines8_mmx_loop:
movq mm0, [esi]
movq mm1, mm0
@@ -100,23 +94,19 @@ AvgLines8_mmx_loop:
mov tmp, esi
}
- for(ptrdiff_t i = pitch&7; i--; tmp++)
- {
+ for(ptrdiff_t i = pitch&7; i--; tmp++) {
tmp[pitch] = (tmp[0] + tmp[pitch<<1] + 1) >> 1;
}
- }
- else
+ } else
#endif
{
- for(ptrdiff_t i = pitch; i--; tmp++)
- {
+ for(ptrdiff_t i = pitch; i--; tmp++) {
tmp[pitch] = (tmp[0] + tmp[pitch<<1] + 1) >> 1;
}
}
}
- if(!(h&1) && h >= 2)
- {
+ if(!(h&1) && h >= 2) {
dst += (h-2)*pitch;
memcpy(dst + pitch, dst, pitch);
}
@@ -128,8 +118,9 @@ AvgLines8_mmx_loop:
void AvgLines555(BYTE* dst, DWORD h, DWORD pitch)
{
- if(h <= 1)
+ if(h <= 1) {
return;
+ }
unsigned __int64 __0x03e003e003e003e0 = 0x03e003e003e003e0;
unsigned __int64 __0x001f001f001f001f = 0x001f001f001f001f;
@@ -137,13 +128,11 @@ void AvgLines555(BYTE* dst, DWORD h, DWORD pitch)
BYTE* s = dst;
BYTE* d = dst + (h-2)*pitch;
- for(; s < d; s += pitch*2)
- {
+ for(; s < d; s += pitch*2) {
BYTE* tmp = s;
#ifndef _WIN64
- __asm
- {
+ __asm {
mov esi, tmp
mov ebx, pitch
@@ -153,7 +142,7 @@ void AvgLines555(BYTE* dst, DWORD h, DWORD pitch)
movq mm6, __0x03e003e003e003e0
movq mm7, __0x001f001f001f001f
-AvgLines555_loop:
+ AvgLines555_loop:
movq mm0, [esi]
movq mm1, mm0
movq mm2, mm0
@@ -196,8 +185,7 @@ AvgLines555_loop:
}
#endif
- for(ptrdiff_t i = (pitch&7)>>1; i--; tmp++)
- {
+ for(ptrdiff_t i = (pitch&7)>>1; i--; tmp++) {
tmp[pitch] =
((((*tmp&0x7c00) + (tmp[pitch<<1]&0x7c00)) >> 1)&0x7c00)|
((((*tmp&0x03e0) + (tmp[pitch<<1]&0x03e0)) >> 1)&0x03e0)|
@@ -205,8 +193,7 @@ AvgLines555_loop:
}
}
- if(!(h&1) && h >= 2)
- {
+ if(!(h&1) && h >= 2) {
dst += (h-2)*pitch;
memcpy(dst + pitch, dst, pitch);
}
@@ -218,8 +205,9 @@ AvgLines555_loop:
void AvgLines565(BYTE* dst, DWORD h, DWORD pitch)
{
- if(h <= 1)
+ if(h <= 1) {
return;
+ }
unsigned __int64 __0x07e007e007e007e0 = 0x07e007e007e007e0;
unsigned __int64 __0x001f001f001f001f = 0x001f001f001f001f;
@@ -227,13 +215,11 @@ void AvgLines565(BYTE* dst, DWORD h, DWORD pitch)
BYTE* s = dst;
BYTE* d = dst + (h-2)*pitch;
- for(; s < d; s += pitch*2)
- {
+ for(; s < d; s += pitch*2) {
WORD* tmp = (WORD*)s;
#ifndef _WIN64
- __asm
- {
+ __asm {
mov esi, tmp
mov ebx, pitch
@@ -243,7 +229,7 @@ void AvgLines565(BYTE* dst, DWORD h, DWORD pitch)
movq mm6, __0x07e007e007e007e0
movq mm7, __0x001f001f001f001f
-AvgLines565_loop:
+ AvgLines565_loop:
movq mm0, [esi]
movq mm1, mm0
movq mm2, mm0
@@ -285,8 +271,7 @@ AvgLines565_loop:
mov tmp, esi
}
#else
- for(ptrdiff_t wd=(pitch>>3); wd--; tmp++)
- {
+ for(ptrdiff_t wd=(pitch>>3); wd--; tmp++) {
tmp[0] =
((((*tmp&0xf800) + (tmp[pitch<<1]&0xf800)) >> 1)&0xf800)|
((((*tmp&0x07e0) + (tmp[pitch<<1]&0x07e0)) >> 1)&0x07e0)|
@@ -294,8 +279,7 @@ AvgLines565_loop:
}
#endif
- for(ptrdiff_t i = (pitch&7)>>1; i--; tmp++)
- {
+ for(ptrdiff_t i = (pitch&7)>>1; i--; tmp++) {
tmp[pitch] =
((((*tmp&0xf800) + (tmp[pitch<<1]&0xf800)) >> 1)&0xf800)|
((((*tmp&0x07e0) + (tmp[pitch<<1]&0x07e0)) >> 1)&0x07e0)|
@@ -303,8 +287,7 @@ AvgLines565_loop:
}
}
- if(!(h&1) && h >= 2)
- {
+ if(!(h&1) && h >= 2) {
dst += (h-2)*pitch;
memcpy(dst + pitch, dst, pitch);
}
diff --git a/src/filters/transform/VSFilter/Copy.cpp b/src/filters/transform/VSFilter/Copy.cpp
index 7c6e077ea..575b2103d 100644
--- a/src/filters/transform/VSFilter/Copy.cpp
+++ b/src/filters/transform/VSFilter/Copy.cpp
@@ -33,82 +33,62 @@ extern void ColorConvInit();
void BltLineRGB32(DWORD* d, BYTE* sub, int w, const GUID& subtype)
{
- if(subtype == MEDIASUBTYPE_YV12 || subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV)
- {
+ if(subtype == MEDIASUBTYPE_YV12 || subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV) {
BYTE* db = (BYTE*)d;
BYTE* dbtend = db + w;
- for(; db < dbtend; sub+=4, db++)
- {
- if(sub[3] < 0xff)
- {
+ for(; db < dbtend; sub+=4, db++) {
+ if(sub[3] < 0xff) {
int y = (c2y_yb[sub[0]] + c2y_yg[sub[1]] + c2y_yr[sub[2]] + 0x108000) >> 16;
*db = y; // w/o colors
}
}
- }
- else if(subtype == MEDIASUBTYPE_YUY2)
- {
+ } else if(subtype == MEDIASUBTYPE_YUY2) {
WORD* ds = (WORD*)d;
WORD* dstend = ds + w;
- for(; ds < dstend; sub+=4, ds++)
- {
- if(sub[3] < 0xff)
- {
+ for(; ds < dstend; sub+=4, ds++) {
+ if(sub[3] < 0xff) {
int y = (c2y_yb[sub[0]] + c2y_yg[sub[1]] + c2y_yr[sub[2]] + 0x108000) >> 16;
*ds = 0x8000|y; // w/o colors
}
}
- }
- else if(subtype == MEDIASUBTYPE_RGB555)
- {
+ } else if(subtype == MEDIASUBTYPE_RGB555) {
WORD* ds = (WORD*)d;
WORD* dstend = ds + w;
- for(; ds < dstend; sub+=4, ds++)
- {
- if(sub[3] < 0xff)
- {
+ for(; ds < dstend; sub+=4, ds++) {
+ if(sub[3] < 0xff) {
*ds = ((*((DWORD*)sub)>>9)&0x7c00)|((*((DWORD*)sub)>>6)&0x03e0)|((*((DWORD*)sub)>>3)&0x001f);
}
}
- }
- else if(subtype == MEDIASUBTYPE_RGB565)
- {
+ } else if(subtype == MEDIASUBTYPE_RGB565) {
WORD* ds = (WORD*)d;
WORD* dstend = ds + w;
- for(; ds < dstend; sub+=4, ds++)
- {
- if(sub[3] < 0xff)
- {
+ for(; ds < dstend; sub+=4, ds++) {
+ if(sub[3] < 0xff) {
*ds = ((*((DWORD*)sub)>>8)&0xf800)|((*((DWORD*)sub)>>5)&0x07e0)|((*((DWORD*)sub)>>3)&0x001f);
}
}
- }
- else if(subtype == MEDIASUBTYPE_RGB24)
- {
+ } else if(subtype == MEDIASUBTYPE_RGB24) {
BYTE* dt = (BYTE*)d;
BYTE* dstend = dt + w*3;
- for(; dt < dstend; sub+=4, dt+=3)
- {
- if(sub[3] < 0xff)
- {
+ for(; dt < dstend; sub+=4, dt+=3) {
+ if(sub[3] < 0xff) {
dt[0] = sub[0];
dt[1] = sub[1];
dt[2] = sub[2];
}
}
- }
- else if(subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_ARGB32)
- {
+ } else if(subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_ARGB32) {
DWORD* dstend = d + w;
- for(; d < dstend; sub+=4, d++)
- {
- if(sub[3] < 0xff) *d = *((DWORD*)sub)&0xffffff;
+ for(; d < dstend; sub+=4, d++) {
+ if(sub[3] < 0xff) {
+ *d = *((DWORD*)sub)&0xffffff;
+ }
}
}
}
@@ -119,7 +99,9 @@ HRESULT CDirectVobSubFilter::Copy(BYTE* pSub, BYTE* pIn, CSize sub, CSize in, in
int wSub = sub.cx, hSub = sub.cy, pitchSub = wSub*bpp>>3;
bool fScale2x = wIn*2 <= wSub;
- if(fScale2x) wIn <<= 1, hIn <<= 1;
+ if(fScale2x) {
+ wIn <<= 1, hIn <<= 1;
+ }
int left = ((wSub - wIn)>>1)&~1;
int mid = wIn;
@@ -136,32 +118,27 @@ HRESULT CDirectVobSubFilter::Copy(BYTE* pSub, BYTE* pIn, CSize sub, CSize in, in
j += (hSub - hIn) >> 1;
- for(; i < j; i++, pSub += pitchSub)
- {
+ for(; i < j; i++, pSub += pitchSub) {
memsetd(pSub, black, dpLeft+dpMid+dpRight);
}
j += hIn;
- if(hIn > hSub)
+ if(hIn > hSub) {
pIn += pitchIn * ((hIn - hSub) >> (fScale2x?2:1));
+ }
- if(fScale2x)
- {
+ if(fScale2x) {
Scale2x(subtype,
pSub + dpLeft, pitchSub, pIn, pitchIn,
in.cx, (min(j, hSub) - i) >> 1);
- for(ptrdiff_t k = min(j, hSub); i < k; i++, pIn += pitchIn, pSub += pitchSub)
- {
+ for(ptrdiff_t k = min(j, hSub); i < k; i++, pIn += pitchIn, pSub += pitchSub) {
memsetd(pSub, black, dpLeft);
memsetd(pSub + dpLeft+dpMid, black, dpRight);
}
- }
- else
- {
- for(ptrdiff_t k = min(j, hSub); i < k; i++, pIn += pitchIn, pSub += pitchSub)
- {
+ } else {
+ for(ptrdiff_t k = min(j, hSub); i < k; i++, pIn += pitchIn, pSub += pitchSub) {
memsetd(pSub, black, dpLeft);
memcpy(pSub + dpLeft, pIn, dpMid);
memsetd(pSub + dpLeft+dpMid, black, dpRight);
@@ -170,8 +147,7 @@ HRESULT CDirectVobSubFilter::Copy(BYTE* pSub, BYTE* pIn, CSize sub, CSize in, in
j = hSub;
- for(; i < j; i++, pSub += pitchSub)
- {
+ for(; i < j; i++, pSub += pitchSub) {
memsetd(pSub, black, dpLeft+dpMid+dpRight);
}
}
@@ -181,8 +157,9 @@ HRESULT CDirectVobSubFilter::Copy(BYTE* pSub, BYTE* pIn, CSize sub, CSize in, in
void CDirectVobSubFilter::PrintMessages(BYTE* pOut)
{
- if(!m_hdc || !m_hbm)
+ if(!m_hdc || !m_hbm) {
return;
+ }
ColorConvInit();
@@ -193,8 +170,7 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut)
CString msg, tmp;
- if(m_fOSD)
- {
+ if(m_fOSD) {
tmp.Format(_T("in: %dx%d %s\nout: %dx%d %s\n"),
m_w, m_h,
Subtype2String(m_pInput->CurrentMediaType().subtype),
@@ -211,16 +187,14 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut)
CAutoLock cAutoLock(&m_csQueueLock);
- if(m_pSubPicQueue)
- {
+ if(m_pSubPicQueue) {
int nSubPics = -1;
REFERENCE_TIME rtNow = -1, rtStart = -1, rtStop = -1;
m_pSubPicQueue->GetStats(nSubPics, rtNow, rtStart, rtStop);
tmp.Format(_T("queue stats: %I64d - %I64d [ms]\n"), rtStart/10000, rtStop/10000);
msg += tmp;
- for(ptrdiff_t i = 0; i < nSubPics; i++)
- {
+ for(ptrdiff_t i = 0; i < nSubPics; i++) {
m_pSubPicQueue->GetStats(i, rtStart, rtStop);
tmp.Format(_T("%d: %I64d - %I64d [ms]\n"), i, rtStart/10000, rtStop/10000);
msg += tmp;
@@ -229,7 +203,9 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut)
}
}
- if(msg.IsEmpty()) return;
+ if(msg.IsEmpty()) {
+ return;
+ }
HANDLE hOldBitmap = SelectObject(m_hdc, m_hbm);
HANDLE hOldFont = SelectObject(m_hdc, m_hfont);
@@ -253,14 +229,14 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut)
int pitchIn = bm.bmWidthBytes;
int pitchOut = bihOut.biWidth * bihOut.biBitCount >> 3;
- if(subtype == MEDIASUBTYPE_YV12 || subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV)
+ if(subtype == MEDIASUBTYPE_YV12 || subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV) {
pitchOut = bihOut.biWidth;
+ }
pitchIn = (pitchIn+3)&~3;
pitchOut = (pitchOut+3)&~3;
- if(bihOut.biHeight > 0 && bihOut.biCompression <= 3) // flip if the dst bitmap is flipped rgb (m_hbm is a top-down bitmap, not like the subpictures)
- {
+ if(bihOut.biHeight > 0 && bihOut.biCompression <= 3) { // flip if the dst bitmap is flipped rgb (m_hbm is a top-down bitmap, not like the subpictures)
pOut += pitchOut * (abs(bihOut.biHeight)-1);
pitchOut = -pitchOut;
}
@@ -268,8 +244,7 @@ void CDirectVobSubFilter::PrintMessages(BYTE* pOut)
pIn += pitchIn * r.top;
pOut += pitchOut * r.top;
- for(ptrdiff_t w = min(r.right, m_w), h = r.Height(); h--; pIn += pitchIn, pOut += pitchOut)
- {
+ for(ptrdiff_t w = min(r.right, m_w), h = r.Height(); h--; pIn += pitchIn, pOut += pitchOut) {
BltLineRGB32((DWORD*)pOut, pIn, w, subtype);
memsetd(pIn, 0xff000000, r.right*4);
}
diff --git a/src/filters/transform/VSFilter/DirectVobSub.cpp b/src/filters/transform/VSFilter/DirectVobSub.cpp
index 59d3a8ec1..8ae4bba69 100644
--- a/src/filters/transform/VSFilter/DirectVobSub.cpp
+++ b/src/filters/transform/VSFilter/DirectVobSub.cpp
@@ -53,10 +53,12 @@ CDirectVobSub::CDirectVobSub()
m_fMediaFPSEnabled = !!theApp.GetProfileInt(ResStr(IDS_R_TIMING), ResStr(IDS_RTM_MEDIAFPSENABLED), 0);
m_ePARCompensationType = static_cast<CSimpleTextSubtitle::EPARCompensationType>(theApp.GetProfileInt(ResStr(IDS_R_TEXT), ResStr(IDS_RT_AUTOPARCOMPENSATION), 0));
pData = NULL;
- if(theApp.GetProfileBinary(ResStr(IDS_R_TIMING), ResStr(IDS_RTM_MEDIAFPS), &pData, &nSize) && pData)
- {
- if(nSize != sizeof(m_MediaFPS)) m_MediaFPS = 25.0;
- else memcpy(&m_MediaFPS, pData, sizeof(m_MediaFPS));
+ if(theApp.GetProfileBinary(ResStr(IDS_R_TIMING), ResStr(IDS_RTM_MEDIAFPS), &pData, &nSize) && pData) {
+ if(nSize != sizeof(m_MediaFPS)) {
+ m_MediaFPS = 25.0;
+ } else {
+ memcpy(&m_MediaFPS, pData, sizeof(m_MediaFPS));
+ }
delete [] pData;
}
m_ZoomRect.left = m_ZoomRect.top = 0;
@@ -74,7 +76,9 @@ STDMETHODIMP CDirectVobSub::get_FileName(WCHAR* fn)
{
CAutoLock cAutoLock(&m_propsLock);
- if(!fn) return E_POINTER;
+ if(!fn) {
+ return E_POINTER;
+ }
#ifdef UNICODE
wcscpy(fn, m_FileName);
@@ -89,10 +93,14 @@ STDMETHODIMP CDirectVobSub::put_FileName(WCHAR* fn)
{
CAutoLock cAutoLock(&m_propsLock);
- if(!fn) return E_POINTER;
+ if(!fn) {
+ return E_POINTER;
+ }
CString tmp = fn;
- if(!m_FileName.Left(m_FileName.ReverseFind('.')+1).CompareNoCase(tmp.Left(tmp.ReverseFind('.')+1))) return S_FALSE;
+ if(!m_FileName.Left(m_FileName.ReverseFind('.')+1).CompareNoCase(tmp.Left(tmp.ReverseFind('.')+1))) {
+ return S_FALSE;
+ }
#ifdef UNICODE
m_FileName = fn;
@@ -130,13 +138,16 @@ STDMETHODIMP CDirectVobSub::put_SelectedLanguage(int iSelected)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_iSelectedLanguage == iSelected) return S_FALSE;
+ if(m_iSelectedLanguage == iSelected) {
+ return S_FALSE;
+ }
int nCount;
if(FAILED(get_LanguageCount(&nCount))
- || iSelected < 0
- || iSelected >= nCount)
+ || iSelected < 0
+ || iSelected >= nCount) {
return E_FAIL;
+ }
m_iSelectedLanguage = iSelected;
@@ -154,7 +165,9 @@ STDMETHODIMP CDirectVobSub::put_HideSubtitles(bool fHideSubtitles)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fHideSubtitles == fHideSubtitles) return S_FALSE;
+ if(m_fHideSubtitles == fHideSubtitles) {
+ return S_FALSE;
+ }
m_fHideSubtitles = fHideSubtitles;
@@ -172,7 +185,9 @@ STDMETHODIMP CDirectVobSub::put_PreBuffering(bool fDoPreBuffering)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fDoPreBuffering == fDoPreBuffering) return S_FALSE;
+ if(m_fDoPreBuffering == fDoPreBuffering) {
+ return S_FALSE;
+ }
m_fDoPreBuffering = fDoPreBuffering;
@@ -183,9 +198,15 @@ STDMETHODIMP CDirectVobSub::get_Placement(bool* fOverridePlacement, int* xperc,
{
CAutoLock cAutoLock(&m_propsLock);
- if(fOverridePlacement) *fOverridePlacement = m_fOverridePlacement;
- if(xperc) *xperc = m_PlacementXperc;
- if(yperc) *yperc = m_PlacementYperc;
+ if(fOverridePlacement) {
+ *fOverridePlacement = m_fOverridePlacement;
+ }
+ if(xperc) {
+ *xperc = m_PlacementXperc;
+ }
+ if(yperc) {
+ *yperc = m_PlacementYperc;
+ }
return S_OK;
}
@@ -194,7 +215,9 @@ STDMETHODIMP CDirectVobSub::put_Placement(bool fOverridePlacement, int xperc, in
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fOverridePlacement == fOverridePlacement && m_PlacementXperc == xperc && m_PlacementYperc == yperc) return S_FALSE;
+ if(m_fOverridePlacement == fOverridePlacement && m_PlacementXperc == xperc && m_PlacementYperc == yperc) {
+ return S_FALSE;
+ }
m_fOverridePlacement = fOverridePlacement;
m_PlacementXperc = xperc;
@@ -207,9 +230,15 @@ STDMETHODIMP CDirectVobSub::get_VobSubSettings(bool* fBuffer, bool* fOnlyShowFor
{
CAutoLock cAutoLock(&m_propsLock);
- if(fBuffer) *fBuffer = m_fBufferVobSub;
- if(fOnlyShowForcedSubs) *fOnlyShowForcedSubs = m_fOnlyShowForcedVobSubs;
- if(fPolygonize) *fPolygonize = m_fPolygonize;
+ if(fBuffer) {
+ *fBuffer = m_fBufferVobSub;
+ }
+ if(fOnlyShowForcedSubs) {
+ *fOnlyShowForcedSubs = m_fOnlyShowForcedVobSubs;
+ }
+ if(fPolygonize) {
+ *fPolygonize = m_fPolygonize;
+ }
return S_OK;
}
@@ -218,7 +247,9 @@ STDMETHODIMP CDirectVobSub::put_VobSubSettings(bool fBuffer, bool fOnlyShowForce
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fBufferVobSub == fBuffer && m_fOnlyShowForcedVobSubs == fOnlyShowForcedSubs && m_fPolygonize == fPolygonize) return S_FALSE;
+ if(m_fBufferVobSub == fBuffer && m_fOnlyShowForcedVobSubs == fOnlyShowForcedSubs && m_fPolygonize == fPolygonize) {
+ return S_FALSE;
+ }
m_fBufferVobSub = fBuffer;
m_fOnlyShowForcedVobSubs = fOnlyShowForcedSubs;
@@ -231,14 +262,14 @@ STDMETHODIMP CDirectVobSub::get_TextSettings(void* lf, int lflen, COLORREF* colo
{
CAutoLock cAutoLock(&m_propsLock);
- if(lf)
- {
- if(lflen == sizeof(LOGFONTA))
+ if(lf) {
+ if(lflen == sizeof(LOGFONTA)) {
strncpy_s(((LOGFONTA*)lf)->lfFaceName, LF_FACESIZE, CStringA(m_defStyle.fontName), _TRUNCATE);
- else if(lflen == sizeof(LOGFONTW))
+ } else if(lflen == sizeof(LOGFONTW)) {
wcsncpy_s(((LOGFONTW*)lf)->lfFaceName, LF_FACESIZE, CStringW(m_defStyle.fontName), _TRUNCATE);
- else
+ } else {
return E_INVALIDARG;
+ }
((LOGFONT*)lf)->lfCharSet = m_defStyle.charSet;
((LOGFONT*)lf)->lfItalic = m_defStyle.fItalic;
@@ -248,10 +279,18 @@ STDMETHODIMP CDirectVobSub::get_TextSettings(void* lf, int lflen, COLORREF* colo
((LOGFONT*)lf)->lfUnderline = m_defStyle.fUnderline;
}
- if(color) *color = m_defStyle.colors[0];
- if(fShadow) *fShadow = (m_defStyle.shadowDepthX!=0) || (m_defStyle.shadowDepthY!=0);
- if(fOutline) *fOutline = (m_defStyle.outlineWidthX+m_defStyle.outlineWidthY)>0;
- if(fAdvancedRenderer) *fAdvancedRenderer = m_fAdvancedRenderer;
+ if(color) {
+ *color = m_defStyle.colors[0];
+ }
+ if(fShadow) {
+ *fShadow = (m_defStyle.shadowDepthX!=0) || (m_defStyle.shadowDepthY!=0);
+ }
+ if(fOutline) {
+ *fOutline = (m_defStyle.outlineWidthX+m_defStyle.outlineWidthY)>0;
+ }
+ if(fAdvancedRenderer) {
+ *fAdvancedRenderer = m_fAdvancedRenderer;
+ }
return S_OK;
}
@@ -260,14 +299,14 @@ STDMETHODIMP CDirectVobSub::put_TextSettings(void* lf, int lflen, COLORREF color
{
CAutoLock cAutoLock(&m_propsLock);
- if(lf)
- {
- if(lflen == sizeof(LOGFONTA))
+ if(lf) {
+ if(lflen == sizeof(LOGFONTA)) {
m_defStyle.fontName = ((LOGFONTA*)lf)->lfFaceName;
- else if(lflen == sizeof(LOGFONTW))
+ } else if(lflen == sizeof(LOGFONTW)) {
m_defStyle.fontName = ((LOGFONTW*)lf)->lfFaceName;
- else
+ } else {
return E_INVALIDARG;
+ }
m_defStyle.charSet = ((LOGFONT*)lf)->lfCharSet;
m_defStyle.fItalic = !!((LOGFONT*)lf)->lfItalic;
@@ -276,8 +315,7 @@ STDMETHODIMP CDirectVobSub::put_TextSettings(void* lf, int lflen, COLORREF color
m_defStyle.fStrikeOut = !!((LOGFONT*)lf)->lfStrikeOut;
m_defStyle.fUnderline = !!((LOGFONT*)lf)->lfUnderline;
- if(m_defStyle.fontSize < 0)
- {
+ if(m_defStyle.fontSize < 0) {
HDC hdc = ::GetDC(0);
m_defStyle.fontSize = -m_defStyle.fontSize * 72 / GetDeviceCaps(hdc, LOGPIXELSY);
::ReleaseDC(0, hdc);
@@ -297,8 +335,12 @@ STDMETHODIMP CDirectVobSub::get_Flip(bool* fPicture, bool* fSubtitles)
{
CAutoLock cAutoLock(&m_propsLock);
- if(fPicture) *fPicture = m_fFlipPicture;
- if(fSubtitles) *fSubtitles = m_fFlipSubtitles;
+ if(fPicture) {
+ *fPicture = m_fFlipPicture;
+ }
+ if(fSubtitles) {
+ *fSubtitles = m_fFlipSubtitles;
+ }
return S_OK;
}
@@ -307,7 +349,9 @@ STDMETHODIMP CDirectVobSub::put_Flip(bool fPicture, bool fSubtitles)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fFlipPicture == fPicture && m_fFlipSubtitles == fSubtitles) return S_FALSE;
+ if(m_fFlipPicture == fPicture && m_fFlipSubtitles == fSubtitles) {
+ return S_FALSE;
+ }
m_fFlipPicture = fPicture;
m_fFlipSubtitles = fSubtitles;
@@ -326,7 +370,9 @@ STDMETHODIMP CDirectVobSub::put_OSD(bool fOSD)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fOSD == fOSD) return S_FALSE;
+ if(m_fOSD == fOSD) {
+ return S_FALSE;
+ }
m_fOSD = fOSD;
@@ -344,7 +390,9 @@ STDMETHODIMP CDirectVobSub::put_SaveFullPath(bool fSaveFullPath)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fSaveFullPath == fSaveFullPath) return S_FALSE;
+ if(m_fSaveFullPath == fSaveFullPath) {
+ return S_FALSE;
+ }
m_fSaveFullPath = fSaveFullPath;
@@ -355,9 +403,15 @@ STDMETHODIMP CDirectVobSub::get_SubtitleTiming(int* delay, int* speedmul, int* s
{
CAutoLock cAutoLock(&m_propsLock);
- if(delay) *delay = m_SubtitleDelay;
- if(speedmul) *speedmul = m_SubtitleSpeedMul;
- if(speeddiv) *speeddiv = m_SubtitleSpeedDiv;
+ if(delay) {
+ *delay = m_SubtitleDelay;
+ }
+ if(speedmul) {
+ *speedmul = m_SubtitleSpeedMul;
+ }
+ if(speeddiv) {
+ *speeddiv = m_SubtitleSpeedDiv;
+ }
return S_OK;
}
@@ -366,11 +420,15 @@ STDMETHODIMP CDirectVobSub::put_SubtitleTiming(int delay, int speedmul, int spee
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_SubtitleDelay == delay && m_SubtitleSpeedMul == speedmul && m_SubtitleSpeedDiv == speeddiv) return S_FALSE;
+ if(m_SubtitleDelay == delay && m_SubtitleSpeedMul == speedmul && m_SubtitleSpeedDiv == speeddiv) {
+ return S_FALSE;
+ }
m_SubtitleDelay = delay;
m_SubtitleSpeedMul = speedmul;
- if(speeddiv > 0) m_SubtitleSpeedDiv = speeddiv;
+ if(speeddiv > 0) {
+ m_SubtitleSpeedDiv = speeddiv;
+ }
return S_OK;
}
@@ -379,8 +437,12 @@ STDMETHODIMP CDirectVobSub::get_MediaFPS(bool* fEnabled, double* fps)
{
CAutoLock cAutoLock(&m_propsLock);
- if(fEnabled) *fEnabled = m_fMediaFPSEnabled;
- if(fps) *fps = m_MediaFPS;
+ if(fEnabled) {
+ *fEnabled = m_fMediaFPSEnabled;
+ }
+ if(fps) {
+ *fps = m_MediaFPS;
+ }
return S_OK;
}
@@ -389,10 +451,14 @@ STDMETHODIMP CDirectVobSub::put_MediaFPS(bool fEnabled, double fps)
{
CAutoLock cAutoLock(&m_propsLock);
- if(m_fMediaFPSEnabled == fEnabled && m_MediaFPS == fps) return S_FALSE;
+ if(m_fMediaFPSEnabled == fEnabled && m_MediaFPS == fps) {
+ return S_FALSE;
+ }
m_fMediaFPSEnabled = fEnabled;
- if(fps > 0) m_MediaFPS = fps;
+ if(fps > 0) {
+ m_MediaFPS = fps;
+ }
return S_OK;
}
@@ -401,7 +467,9 @@ STDMETHODIMP CDirectVobSub::get_ZoomRect(NORMALIZEDRECT* rect)
{
CAutoLock cAutoLock(&m_propsLock);
- if(!rect) return E_POINTER;
+ if(!rect) {
+ return E_POINTER;
+ }
*rect = m_ZoomRect;
@@ -412,9 +480,13 @@ STDMETHODIMP CDirectVobSub::put_ZoomRect(NORMALIZEDRECT* rect)
{
CAutoLock cAutoLock(&m_propsLock);
- if(!rect) return E_POINTER;
+ if(!rect) {
+ return E_POINTER;
+ }
- if(!memcmp(&m_ZoomRect, rect, sizeof(m_ZoomRect))) return S_FALSE;
+ if(!memcmp(&m_ZoomRect, rect, sizeof(m_ZoomRect))) {
+ return S_FALSE;
+ }
m_ZoomRect = *rect;
@@ -465,7 +537,9 @@ STDMETHODIMP CDirectVobSub::IsSubtitleReloaderLocked(bool* fLocked)
{
CAutoLock cAutoLock(&m_propsLock);
- if(!fLocked) return E_POINTER;
+ if(!fLocked) {
+ return E_POINTER;
+ }
bool fDisabled;
get_SubtitleReloader(&fDisabled);
@@ -479,11 +553,16 @@ STDMETHODIMP CDirectVobSub::LockSubtitleReloader(bool fLock)
{
CAutoLock cAutoLock(&m_propsLock);
- if(fLock) m_nReloaderDisableCount++;
- else m_nReloaderDisableCount--;
+ if(fLock) {
+ m_nReloaderDisableCount++;
+ } else {
+ m_nReloaderDisableCount--;
+ }
ASSERT(m_nReloaderDisableCount >= 0);
- if(m_nReloaderDisableCount < 0) m_nReloaderDisableCount = 0;
+ if(m_nReloaderDisableCount < 0) {
+ m_nReloaderDisableCount = 0;
+ }
return S_OK;
}
@@ -494,7 +573,9 @@ STDMETHODIMP CDirectVobSub::get_SubtitleReloader(bool* fDisabled)
CAutoLock cAutoLock(&m_propsLock);
- if(fDisabled) *fDisabled = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_DISABLERELOADER), 0);
+ if(fDisabled) {
+ *fDisabled = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_DISABLERELOADER), 0);
+ }
return S_OK;
}
@@ -507,7 +588,9 @@ STDMETHODIMP CDirectVobSub::put_SubtitleReloader(bool fDisable)
bool b;
get_SubtitleReloader(&b);
- if(b == fDisable) return S_FALSE;
+ if(b == fDisable) {
+ return S_FALSE;
+ }
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_DISABLERELOADER), fDisable);
@@ -520,11 +603,21 @@ STDMETHODIMP CDirectVobSub::get_ExtendPicture(int* horizontal, int* vertical, in
CAutoLock cAutoLock(&m_propsLock);
- if(horizontal) *horizontal = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_MOD32FIX), 0) & 1;
- if(vertical) *vertical = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EXTPIC), 0);
- if(resx2) *resx2 = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_RESX2), 2) & 3;
- if(resx2minw) *resx2minw = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_RESX2MINW), 384);
- if(resx2minh) *resx2minh = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_RESX2MINH), 288);
+ if(horizontal) {
+ *horizontal = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_MOD32FIX), 0) & 1;
+ }
+ if(vertical) {
+ *vertical = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EXTPIC), 0);
+ }
+ if(resx2) {
+ *resx2 = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_RESX2), 2) & 3;
+ }
+ if(resx2minw) {
+ *resx2minw = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_RESX2MINW), 384);
+ }
+ if(resx2minh) {
+ *resx2minh = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_RESX2MINH), 288);
+ }
return S_OK;
}
@@ -537,7 +630,9 @@ STDMETHODIMP CDirectVobSub::put_ExtendPicture(int horizontal, int vertical, int
int i[5];
get_ExtendPicture(i, i+1, i+2, i+3, i+4);
- if(i[0] == horizontal && i[1] == vertical && i[2] == resx2 && i[3] == resx2minw && i[4] == resx2minh) return S_FALSE;
+ if(i[0] == horizontal && i[1] == vertical && i[2] == resx2 && i[3] == resx2minw && i[4] == resx2minh) {
+ return S_FALSE;
+ }
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_MOD32FIX), horizontal & 1);
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EXTPIC), vertical);
@@ -554,10 +649,18 @@ STDMETHODIMP CDirectVobSub::get_LoadSettings(int* level, bool* fExternalLoad, bo
CAutoLock cAutoLock(&m_propsLock);
- if(level) *level = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_LOADLEVEL), 0) & 3;
- if(fExternalLoad) *fExternalLoad = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EXTERNALLOAD), 1);
- if(fWebLoad) *fWebLoad = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_WEBLOAD), 0);
- if(fEmbeddedLoad) *fEmbeddedLoad = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EMBEDDEDLOAD), 1);
+ if(level) {
+ *level = theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_LOADLEVEL), 0) & 3;
+ }
+ if(fExternalLoad) {
+ *fExternalLoad = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EXTERNALLOAD), 1);
+ }
+ if(fWebLoad) {
+ *fWebLoad = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_WEBLOAD), 0);
+ }
+ if(fEmbeddedLoad) {
+ *fEmbeddedLoad = !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EMBEDDEDLOAD), 1);
+ }
return S_OK;
}
@@ -571,7 +674,9 @@ STDMETHODIMP CDirectVobSub::put_LoadSettings(int level, bool fExternalLoad, bool
int i;
bool b[3];
get_LoadSettings(&i, b, b+1, b+2);
- if(i == level && b[0] == fExternalLoad && b[1] == fWebLoad && b[2] == fEmbeddedLoad) return S_FALSE;
+ if(i == level && b[0] == fExternalLoad && b[1] == fWebLoad && b[2] == fEmbeddedLoad) {
+ return S_FALSE;
+ }
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_LOADLEVEL), level & 3);
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_EXTERNALLOAD), fExternalLoad);
@@ -617,8 +722,9 @@ STDMETHODIMP CDirectVobSub::put_TextSettings(STSStyle* pDefStyle)
CAutoLock cAutoLock(&m_propsLock);
- if(!memcmp(&m_defStyle, pDefStyle, sizeof(m_defStyle)))
+ if(!memcmp(&m_defStyle, pDefStyle, sizeof(m_defStyle))) {
return S_FALSE;
+ }
m_defStyle = *pDefStyle;
diff --git a/src/filters/transform/VSFilter/DirectVobSub.h b/src/filters/transform/VSFilter/DirectVobSub.h
index 7f6edcba4..1c3917707 100644
--- a/src/filters/transform/VSFilter/DirectVobSub.h
+++ b/src/filters/transform/VSFilter/DirectVobSub.h
@@ -91,8 +91,12 @@ public:
STDMETHODIMP put_MediaFPS(bool fEnabled, double fps);
STDMETHODIMP get_ZoomRect(NORMALIZEDRECT* rect);
STDMETHODIMP put_ZoomRect(NORMALIZEDRECT* rect);
- STDMETHODIMP get_ColorFormat(int* iPosition) {return E_NOTIMPL;}
- STDMETHODIMP put_ColorFormat(int iPosition) {return E_NOTIMPL;}
+ STDMETHODIMP get_ColorFormat(int* iPosition) {
+ return E_NOTIMPL;
+ }
+ STDMETHODIMP put_ColorFormat(int iPosition) {
+ return E_NOTIMPL;
+ }
STDMETHODIMP UpdateRegistry();
diff --git a/src/filters/transform/VSFilter/DirectVobSubFilter.cpp b/src/filters/transform/VSFilter/DirectVobSubFilter.cpp
index 1d0726364..935e29b57 100644
--- a/src/filters/transform/VSFilter/DirectVobSubFilter.cpp
+++ b/src/filters/transform/VSFilter/DirectVobSubFilter.cpp
@@ -100,7 +100,9 @@ CDirectVobSubFilter::CDirectVobSubFilter(LPUNKNOWN punk, HRESULT* phr, const GUI
CDirectVobSubFilter::~CDirectVobSubFilter()
{
CAutoLock cAutoLock(&m_csQueueLock);
- if(m_pSubPicQueue) m_pSubPicQueue->Invalidate();
+ if(m_pSubPicQueue) {
+ m_pSubPicQueue->Invalidate();
+ }
m_pSubPicQueue = NULL;
if(m_hfont) {
@@ -116,8 +118,9 @@ CDirectVobSubFilter::~CDirectVobSubFilter()
m_hdc = 0;
}
- for(ptrdiff_t i = 0; i < m_pTextInput.GetCount(); i++)
+ for(ptrdiff_t i = 0; i < m_pTextInput.GetCount(); i++) {
delete m_pTextInput[i];
+ }
m_frd.EndThreadEvent.Set();
CAMThread::Close();
@@ -145,15 +148,17 @@ void CDirectVobSubFilter::GetOutputSize(int& w, int& h, int& arx, int& ary)
w = s.cx;
h = s.cy;
- if(w != os.cx)
- {
- while(arx < 100) arx *= 10, ary *= 10;
+ if(w != os.cx) {
+ while(arx < 100) {
+ arx *= 10, ary *= 10;
+ }
arx = arx * w / os.cx;
}
- if(h != os.cy)
- {
- while(ary < 100) arx *= 10, ary *= 10;
+ if(h != os.cy) {
+ while(ary < 100) {
+ arx *= 10, ary *= 10;
+ }
ary = ary * h / os.cy;
}
}
@@ -164,18 +169,17 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
REFERENCE_TIME rtStart, rtStop;
- if(SUCCEEDED(pIn->GetTime(&rtStart, &rtStop)))
- {
+ if(SUCCEEDED(pIn->GetTime(&rtStart, &rtStop))) {
double dRate = m_pInput->CurrentRate();
m_tPrev = m_pInput->CurrentStartTime() + dRate*rtStart;
REFERENCE_TIME rtAvgTimePerFrame = rtStop - rtStart;
- if(CComQIPtr<ISubClock2> pSC2 = m_pSubClock)
- {
+ if(CComQIPtr<ISubClock2> pSC2 = m_pSubClock) {
REFERENCE_TIME rt;
- if(S_OK == pSC2->GetAvgTimePerFrame(&rt))
+ if(S_OK == pSC2->GetAvgTimePerFrame(&rt)) {
rtAvgTimePerFrame = rt;
+ }
}
m_fps = 10000000.0/rtAvgTimePerFrame / dRate;
@@ -186,8 +190,7 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
{
CAutoLock cAutoLock(&m_csQueueLock);
- if(m_pSubPicQueue)
- {
+ if(m_pSubPicQueue) {
m_pSubPicQueue->SetTime(CalcCurrentTime());
m_pSubPicQueue->SetFPS(m_fps);
}
@@ -196,8 +199,9 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
//
BYTE* pDataIn = NULL;
- if(FAILED(pIn->GetPointer(&pDataIn)) || !pDataIn)
+ if(FAILED(pIn->GetPointer(&pDataIn)) || !pDataIn) {
return S_FALSE;
+ }
const CMediaType& mt = m_pInput->CurrentMediaType();
@@ -211,11 +215,11 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
CSize sub(m_w, m_h);
CSize in(bihIn.biWidth, bihIn.biHeight);
- if(FAILED(Copy((BYTE*)m_pTempPicBuff, pDataIn, sub, in, bpp, mt.subtype, black)))
+ if(FAILED(Copy((BYTE*)m_pTempPicBuff, pDataIn, sub, in, bpp, mt.subtype, black))) {
return E_FAIL;
+ }
- if(fYV12)
- {
+ if(fYV12) {
BYTE* pSubV = (BYTE*)m_pTempPicBuff + (sub.cx*bpp>>3)*sub.cy;
BYTE* pInV = pDataIn + (in.cx*bpp>>3)*in.cy;
sub.cx >>= 1;
@@ -224,10 +228,12 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
in.cy >>= 1;
BYTE* pSubU = pSubV + (sub.cx*bpp>>3)*sub.cy;
BYTE* pInU = pInV + (in.cx*bpp>>3)*in.cy;
- if(FAILED(Copy(pSubV, pInV, sub, in, bpp, mt.subtype, 0x80808080)))
+ if(FAILED(Copy(pSubV, pInV, sub, in, bpp, mt.subtype, 0x80808080))) {
return E_FAIL;
- if(FAILED(Copy(pSubU, pInU, sub, in, bpp, mt.subtype, 0x80808080)))
+ }
+ if(FAILED(Copy(pSubU, pInU, sub, in, bpp, mt.subtype, 0x80808080))) {
return E_FAIL;
+ }
}
//
@@ -237,8 +243,9 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
CComPtr<IMediaSample> pOut;
BYTE* pDataOut = NULL;
if(FAILED(hr = GetDeliveryBuffer(spd.w, spd.h, &pOut))
- || FAILED(hr = pOut->GetPointer(&pDataOut)))
+ || FAILED(hr = pOut->GetPointer(&pDataOut))) {
return hr;
+ }
pOut->SetTime(&rtStart, &rtStop);
pOut->SetMediaTime(NULL, NULL);
@@ -256,27 +263,32 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
bool fOutputFlipped = bihOut.biHeight >= 0 && bihOut.biCompression <= 3;
bool fFlip = fInputFlipped != fOutputFlipped;
- if(m_fFlipPicture) fFlip = !fFlip;
- if(m_fMSMpeg4Fix) fFlip = !fFlip;
+ if(m_fFlipPicture) {
+ fFlip = !fFlip;
+ }
+ if(m_fMSMpeg4Fix) {
+ fFlip = !fFlip;
+ }
bool fFlipSub = fOutputFlipped;
- if(m_fFlipSubtitles) fFlipSub = !fFlipSub;
+ if(m_fFlipSubtitles) {
+ fFlipSub = !fFlipSub;
+ }
//
{
CAutoLock cAutoLock(&m_csQueueLock);
- if(m_pSubPicQueue)
- {
+ if(m_pSubPicQueue) {
CComPtr<ISubPic> pSubPic;
- if(SUCCEEDED(m_pSubPicQueue->LookupSubPic(CalcCurrentTime(), pSubPic)) && pSubPic)
- {
+ if(SUCCEEDED(m_pSubPicQueue->LookupSubPic(CalcCurrentTime(), pSubPic)) && pSubPic) {
CRect r;
pSubPic->GetDirtyRect(r);
- if(fFlip ^ fFlipSub)
+ if(fFlip ^ fFlipSub) {
spd.h = -spd.h;
+ }
pSubPic->AlphaBlt(r, r, &spd);
}
@@ -294,13 +306,15 @@ HRESULT CDirectVobSubFilter::Transform(IMediaSample* pIn)
CBasePin* CDirectVobSubFilter::GetPin(int n)
{
- if(n < __super::GetPinCount())
+ if(n < __super::GetPinCount()) {
return __super::GetPin(n);
+ }
n -= __super::GetPinCount();
- if(n >= 0 && n < m_pTextInput.GetCount())
+ if(n >= 0 && n < m_pTextInput.GetCount()) {
return m_pTextInput[n];
+ }
n -= m_pTextInput.GetCount();
@@ -314,21 +328,17 @@ int CDirectVobSubFilter::GetPinCount()
HRESULT CDirectVobSubFilter::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pName)
{
- if(pGraph)
- {
+ if(pGraph) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
- if(!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_SEENDIVXWARNING), 0))
- {
+ if(!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_SEENDIVXWARNING), 0)) {
unsigned __int64 ver = GetFileVersion(_T("divx_c32.ax"));
- if(((ver >> 48)&0xffff) == 4 && ((ver >> 32)&0xffff) == 2)
- {
+ if(((ver >> 48)&0xffff) == 4 && ((ver >> 32)&0xffff) == 2) {
DWORD dwVersion = GetVersion();
DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
- if(dwVersion < 0x80000000 && dwWindowsMajorVersion >= 5)
- {
+ if(dwVersion < 0x80000000 && dwWindowsMajorVersion >= 5) {
AfxMessageBox(IDS_DIVX_WARNING);
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_SEENDIVXWARNING), 1);
}
@@ -336,20 +346,15 @@ HRESULT CDirectVobSubFilter::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pName
}
/*removeme*/
- if(!g_RegOK)
- {
+ if(!g_RegOK) {
DllRegisterServer();
g_RegOK = true;
}
- }
- else
- {
- if(m_hSystrayThread)
- {
+ } else {
+ if(m_hSystrayThread) {
SendMessage(m_tbid.hSystrayWnd, WM_CLOSE, 0, 0);
- if(WaitForSingleObject(m_hSystrayThread, 10000) != WAIT_OBJECT_0)
- {
+ if(WaitForSingleObject(m_hSystrayThread, 10000) != WAIT_OBJECT_0) {
DbgLog((LOG_TRACE, 0, _T("CALL THE AMBULANCE!!!")));
TerminateThread(m_hSystrayThread, (DWORD)-1);
}
@@ -366,13 +371,15 @@ STDMETHODIMP CDirectVobSubFilter::QueryFilterInfo(FILTER_INFO* pInfo)
CheckPointer(pInfo, E_POINTER);
ValidateReadWritePtr(pInfo, sizeof(FILTER_INFO));
- if(!get_Forced())
+ if(!get_Forced()) {
return __super::QueryFilterInfo(pInfo);
+ }
wcscpy(pInfo->achName, L"DirectVobSub (forced auto-loading version)");
pInfo->pGraph = m_pGraph;
- if(m_pGraph)
+ if(m_pGraph) {
m_pGraph->AddRef();
+ }
return S_OK;
}
@@ -382,10 +389,11 @@ STDMETHODIMP CDirectVobSubFilter::QueryFilterInfo(FILTER_INFO* pInfo)
HRESULT CDirectVobSubFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* pmt)
{
HRESULT hr = __super::SetMediaType(dir, pmt);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
CAutoLock cAutoLock(&m_csReceive);
REFERENCE_TIME atpf =
@@ -395,13 +403,12 @@ HRESULT CDirectVobSubFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* p
m_fps = atpf ? 10000000.0 / atpf : 25;
- if (pmt->formattype == FORMAT_VideoInfo2)
+ if (pmt->formattype == FORMAT_VideoInfo2) {
m_CurrentVIH2 = *(VIDEOINFOHEADER2*)pmt->Format();
+ }
InitSubPicQueue();
- }
- else if(dir == PINDIR_OUTPUT)
- {
+ } else if(dir == PINDIR_OUTPUT) {
}
@@ -410,11 +417,8 @@ HRESULT CDirectVobSubFilter::SetMediaType(PIN_DIRECTION dir, const CMediaType* p
HRESULT CDirectVobSubFilter::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
{
- if(dir == PINDIR_INPUT)
- {
- }
- else if(dir == PINDIR_OUTPUT)
- {
+ if(dir == PINDIR_INPUT) {
+ } else if(dir == PINDIR_OUTPUT) {
}
return __super::CheckConnect(dir, pPin);
@@ -422,24 +426,19 @@ HRESULT CDirectVobSubFilter::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
HRESULT CDirectVobSubFilter::CompleteConnect(PIN_DIRECTION dir, IPin* pReceivePin)
{
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
CComPtr<IBaseFilter> pFilter;
// needed when we have a decoder with a version number of 3.x
if(SUCCEEDED(m_pGraph->FindFilterByName(L"DivX MPEG-4 DVD Video Decompressor ", &pFilter))
- && (GetFileVersion(_T("divx_c32.ax")) >> 48) <= 4
- || SUCCEEDED(m_pGraph->FindFilterByName(L"Microcrap MPEG-4 Video Decompressor", &pFilter))
- || SUCCEEDED(m_pGraph->FindFilterByName(L"Microsoft MPEG-4 Video Decompressor", &pFilter))
- && (GetFileVersion(_T("mpg4ds32.ax")) >> 48) <= 3)
- {
+ && (GetFileVersion(_T("divx_c32.ax")) >> 48) <= 4
+ || SUCCEEDED(m_pGraph->FindFilterByName(L"Microcrap MPEG-4 Video Decompressor", &pFilter))
+ || SUCCEEDED(m_pGraph->FindFilterByName(L"Microsoft MPEG-4 Video Decompressor", &pFilter))
+ && (GetFileVersion(_T("mpg4ds32.ax")) >> 48) <= 3) {
m_fMSMpeg4Fix = true;
}
- }
- else if(dir == PINDIR_OUTPUT)
- {
- if(!m_hSystrayThread)
- {
+ } else if(dir == PINDIR_OUTPUT) {
+ if(!m_hSystrayThread) {
m_tbid.graph = m_pGraph;
m_tbid.dvs = static_cast<IDirectVobSub*>(this);
@@ -456,16 +455,12 @@ HRESULT CDirectVobSubFilter::CompleteConnect(PIN_DIRECTION dir, IPin* pReceivePi
HRESULT CDirectVobSubFilter::BreakConnect(PIN_DIRECTION dir)
{
- if(dir == PINDIR_INPUT)
- {
- if(m_pOutput->IsConnected())
- {
+ if(dir == PINDIR_INPUT) {
+ if(m_pOutput->IsConnected()) {
m_pOutput->GetConnected()->Disconnect();
m_pOutput->Disconnect();
}
- }
- else if(dir == PINDIR_OUTPUT)
- {
+ } else if(dir == PINDIR_OUTPUT) {
// not really needed, but may free up a little memory
CAutoLock cAutoLock(&m_csQueueLock);
m_pSubPicQueue = NULL;
@@ -526,13 +521,21 @@ void CDirectVobSubFilter::InitSubPicQueue()
ExtractBIH(&m_pInput->CurrentMediaType(), &bihIn);
m_spd.type = -1;
- if(subtype == MEDIASUBTYPE_YV12) m_spd.type = MSP_YV12;
- else if(subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV) m_spd.type = MSP_IYUV;
- else if(subtype == MEDIASUBTYPE_YUY2) m_spd.type = MSP_YUY2;
- else if(subtype == MEDIASUBTYPE_RGB32) m_spd.type = MSP_RGB32;
- else if(subtype == MEDIASUBTYPE_RGB24) m_spd.type = MSP_RGB24;
- else if(subtype == MEDIASUBTYPE_RGB565) m_spd.type = MSP_RGB16;
- else if(subtype == MEDIASUBTYPE_RGB555) m_spd.type = MSP_RGB15;
+ if(subtype == MEDIASUBTYPE_YV12) {
+ m_spd.type = MSP_YV12;
+ } else if(subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV) {
+ m_spd.type = MSP_IYUV;
+ } else if(subtype == MEDIASUBTYPE_YUY2) {
+ m_spd.type = MSP_YUY2;
+ } else if(subtype == MEDIASUBTYPE_RGB32) {
+ m_spd.type = MSP_RGB32;
+ } else if(subtype == MEDIASUBTYPE_RGB24) {
+ m_spd.type = MSP_RGB24;
+ } else if(subtype == MEDIASUBTYPE_RGB565) {
+ m_spd.type = MSP_RGB16;
+ } else if(subtype == MEDIASUBTYPE_RGB555) {
+ m_spd.type = MSP_RGB15;
+ }
m_spd.w = m_w;
m_spd.h = m_h;
m_spd.bpp = (m_spd.type == MSP_YV12 || m_spd.type == MSP_IYUV) ? 8 : bihIn.biBitCount;
@@ -542,7 +545,9 @@ void CDirectVobSubFilter::InitSubPicQueue()
CComPtr<ISubPicAllocator> pSubPicAllocator = new CMemSubPicAllocator(m_spd.type, CSize(m_w, m_h));
CSize video(bihIn.biWidth, bihIn.biHeight), window = video;
- if(AdjustFrameSize(window)) video += video;
+ if(AdjustFrameSize(window)) {
+ video += video;
+ }
ASSERT(window == CSize(m_w, m_h));
pSubPicAllocator->SetCurSize(window);
@@ -553,7 +558,9 @@ void CDirectVobSubFilter::InitSubPicQueue()
? (ISubPicQueue*)new CSubPicQueue(10, false, pSubPicAllocator, &hr)
: (ISubPicQueue*)new CSubPicQueueNoThread(pSubPicAllocator, &hr);
- if(FAILED(hr)) m_pSubPicQueue = NULL;
+ if(FAILED(hr)) {
+ m_pSubPicQueue = NULL;
+ }
UpdateSubtitle(false);
@@ -585,35 +592,40 @@ bool CDirectVobSubFilter::AdjustFrameSize(CSize& s)
bool fRet = (resx2 == 1) || (resx2 == 2 && s.cx*s.cy <= resx2minw*resx2minh);
- if(fRet)
- {
+ if(fRet) {
s.cx <<= 1;
s.cy <<= 1;
}
int h;
- switch(vertical&0x7f)
- {
- case 1:
- h = s.cx * 9 / 16;
- if(s.cy < h || !!(vertical&0x80)) s.cy = (h + 3) & ~3;
- break;
- case 2:
- h = s.cx * 3 / 4;
- if(s.cy < h || !!(vertical&0x80)) s.cy = (h + 3) & ~3;
- break;
- case 3:
- h = 480;
- if(s.cy < h || !!(vertical&0x80)) s.cy = (h + 3) & ~3;
- break;
- case 4:
- h = 576;
- if(s.cy < h || !!(vertical&0x80)) s.cy = (h + 3) & ~3;
- break;
- }
-
- if(horizontal == 1)
- {
+ switch(vertical&0x7f) {
+ case 1:
+ h = s.cx * 9 / 16;
+ if(s.cy < h || !!(vertical&0x80)) {
+ s.cy = (h + 3) & ~3;
+ }
+ break;
+ case 2:
+ h = s.cx * 3 / 4;
+ if(s.cy < h || !!(vertical&0x80)) {
+ s.cy = (h + 3) & ~3;
+ }
+ break;
+ case 3:
+ h = 480;
+ if(s.cy < h || !!(vertical&0x80)) {
+ s.cy = (h + 3) & ~3;
+ }
+ break;
+ case 4:
+ h = 576;
+ if(s.cy < h || !!(vertical&0x80)) {
+ s.cy = (h + 3) & ~3;
+ }
+ break;
+ }
+
+ if(horizontal == 1) {
s.cx = (s.cx + 31) & ~31;
s.cy = (s.cy + 1) & ~1;
}
@@ -623,13 +635,16 @@ bool CDirectVobSubFilter::AdjustFrameSize(CSize& s)
STDMETHODIMP CDirectVobSubFilter::Count(DWORD* pcStreams)
{
- if(!pcStreams) return E_POINTER;
+ if(!pcStreams) {
+ return E_POINTER;
+ }
*pcStreams = 0;
int nLangs = 0;
- if(SUCCEEDED(get_LanguageCount(&nLangs)))
+ if(SUCCEEDED(get_LanguageCount(&nLangs))) {
(*pcStreams) += nLangs;
+ }
(*pcStreams) += 2; // enable ... disable
@@ -647,26 +662,27 @@ int CDirectVobSubFilter::FindPreferedLanguage(bool fHideToo)
int nLangs;
get_LanguageCount(&nLangs);
- if(nLangs <= 0) return(0);
+ if(nLangs <= 0) {
+ return(0);
+ }
- for(ptrdiff_t i = 0; i < MAXPREFLANGS; i++)
- {
+ for(ptrdiff_t i = 0; i < MAXPREFLANGS; i++) {
CString tmp;
tmp.Format(IDS_RL_LANG, i);
CString lang = theApp.GetProfileString(ResStr(IDS_R_PREFLANGS), tmp);
- if(!lang.IsEmpty())
- {
- for(ptrdiff_t ret = 0; ret < nLangs; ret++)
- {
+ if(!lang.IsEmpty()) {
+ for(ptrdiff_t ret = 0; ret < nLangs; ret++) {
CString l;
WCHAR* pName = NULL;
get_LanguageName(ret, &pName);
l = pName;
CoTaskMemFree(pName);
- if(!l.CompareNoCase(lang)) return(ret);
+ if(!l.CompareNoCase(lang)) {
+ return(ret);
+ }
}
}
}
@@ -681,30 +697,28 @@ void CDirectVobSubFilter::UpdatePreferedLanguages(CString l)
CString langs[MAXPREFLANGS+1];
int i = 0, j = 0, k = -1;
- for(; i < MAXPREFLANGS; i++)
- {
+ for(; i < MAXPREFLANGS; i++) {
CString tmp;
tmp.Format(IDS_RL_LANG, i);
langs[j] = theApp.GetProfileString(ResStr(IDS_R_PREFLANGS), tmp);
- if(!langs[j].IsEmpty())
- {
- if(!langs[j].CompareNoCase(l)) k = j;
+ if(!langs[j].IsEmpty()) {
+ if(!langs[j].CompareNoCase(l)) {
+ k = j;
+ }
j++;
}
}
- if(k == -1)
- {
+ if(k == -1) {
langs[k = j] = l;
j++;
}
// move the selected to the top of the list
- while(k > 0)
- {
+ while(k > 0) {
CString tmp = langs[k];
langs[k] = langs[k-1];
langs[k-1] = tmp;
@@ -716,21 +730,20 @@ void CDirectVobSubFilter::UpdatePreferedLanguages(CString l)
CString hidesubs;
hidesubs.LoadString(IDS_M_HIDESUBTITLES);
- for(k = 1; k < j; k++)
- {
- if(!langs[k].CompareNoCase(hidesubs)) break;
+ for(k = 1; k < j; k++) {
+ if(!langs[k].CompareNoCase(hidesubs)) {
+ break;
+ }
}
- while(k < j-1)
- {
+ while(k < j-1) {
CString tmp = langs[k];
langs[k] = langs[k+1];
langs[k+1] = tmp;
k++;
}
- for(i = 0; i < j; i++)
- {
+ for(i = 0; i < j; i++) {
CString tmp;
tmp.Format(IDS_RL_LANG, i);
@@ -740,39 +753,35 @@ void CDirectVobSubFilter::UpdatePreferedLanguages(CString l)
STDMETHODIMP CDirectVobSubFilter::Enable(long lIndex, DWORD dwFlags)
{
- if(!(dwFlags & AMSTREAMSELECTENABLE_ENABLE))
+ if(!(dwFlags & AMSTREAMSELECTENABLE_ENABLE)) {
return E_NOTIMPL;
+ }
int nLangs = 0;
get_LanguageCount(&nLangs);
- if(!(lIndex >= 0 && lIndex < nLangs+2+2))
+ if(!(lIndex >= 0 && lIndex < nLangs+2+2)) {
return E_INVALIDARG;
+ }
int i = lIndex-1;
- 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
- {
+ 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
put_HideSubtitles(false);
- }
- else if(i >= 0 && i < nLangs)
- {
+ } else if(i >= 0 && i < nLangs) {
put_HideSubtitles(false);
put_SelectedLanguage(i);
WCHAR* pName = NULL;
- if(SUCCEEDED(get_LanguageName(i, &pName)))
- {
+ if(SUCCEEDED(get_LanguageName(i, &pName))) {
UpdatePreferedLanguages(CString(pName));
- if(pName) CoTaskMemFree(pName);
+ if(pName) {
+ CoTaskMemFree(pName);
+ }
}
- }
- else if(i == nLangs && !m_fLoading)
- {
+ } else if(i == nLangs && !m_fLoading) {
put_HideSubtitles(true);
- }
- else if((i == nLangs+1 || i == nLangs+2) && !m_fLoading)
- {
+ } else if((i == nLangs+1 || i == nLangs+2) && !m_fLoading) {
put_Flip(i == nLangs+2, m_fFlipSubtitles);
}
@@ -786,66 +795,83 @@ STDMETHODIMP CDirectVobSubFilter::Info(long lIndex, AM_MEDIA_TYPE** ppmt, DWORD*
int nLangs = 0;
get_LanguageCount(&nLangs);
- if(!(lIndex >= 0 && lIndex < nLangs+2+2))
+ if(!(lIndex >= 0 && lIndex < nLangs+2+2)) {
return E_INVALIDARG;
+ }
int i = lIndex-1;
- if(ppmt) *ppmt = CreateMediaType(&m_pInput->CurrentMediaType());
+ if(ppmt) {
+ *ppmt = CreateMediaType(&m_pInput->CurrentMediaType());
+ }
- if(pdwFlags)
- {
+ if(pdwFlags) {
*pdwFlags = 0;
if(i == -1 && !m_fHideSubtitles
- || i >= 0 && i < nLangs && i == m_iSelectedLanguage
- || i == nLangs && m_fHideSubtitles
- || i == nLangs+1 && !m_fFlipPicture
- || i == nLangs+2 && m_fFlipPicture)
- {
+ || i >= 0 && i < nLangs && i == m_iSelectedLanguage
+ || i == nLangs && m_fHideSubtitles
+ || i == nLangs+1 && !m_fFlipPicture
+ || i == nLangs+2 && m_fFlipPicture) {
*pdwFlags |= AMSTREAMSELECTINFO_ENABLED;
}
}
- if(plcid) *plcid = 0;
+ if(plcid) {
+ *plcid = 0;
+ }
- if(pdwGroup) *pdwGroup = 0x648E51;
+ if(pdwGroup) {
+ *pdwGroup = 0x648E51;
+ }
- if(ppszName)
- {
+ if(ppszName) {
*ppszName = NULL;
CStringW str;
- if(i == -1) str = ResStr(IDS_M_SHOWSUBTITLES);
- else if(i >= 0 && i < nLangs) get_LanguageName(i, ppszName);
- else if(i == nLangs) str = ResStr(IDS_M_HIDESUBTITLES);
- else if(i == nLangs+1) {
+ if(i == -1) {
+ str = ResStr(IDS_M_SHOWSUBTITLES);
+ } else if(i >= 0 && i < nLangs) {
+ get_LanguageName(i, ppszName);
+ } else if(i == nLangs) {
+ str = ResStr(IDS_M_HIDESUBTITLES);
+ } else if(i == nLangs+1) {
str = ResStr(IDS_M_ORIGINALPICTURE);
- if(pdwGroup) (*pdwGroup)++;
- }
- else if(i == nLangs+2) {
+ if(pdwGroup) {
+ (*pdwGroup)++;
+ }
+ } else if(i == nLangs+2) {
str = ResStr(IDS_M_FLIPPEDPICTURE);
- if(pdwGroup) (*pdwGroup)++;
+ if(pdwGroup) {
+ (*pdwGroup)++;
+ }
}
- if(!str.IsEmpty())
- {
+ if(!str.IsEmpty()) {
*ppszName = (WCHAR*)CoTaskMemAlloc((str.GetLength()+1)*sizeof(WCHAR));
- if(*ppszName == NULL) return S_FALSE;
+ if(*ppszName == NULL) {
+ return S_FALSE;
+ }
wcscpy(*ppszName, str);
}
}
- if(ppObject) *ppObject = NULL;
+ if(ppObject) {
+ *ppObject = NULL;
+ }
- if(ppUnk) *ppUnk = NULL;
+ if(ppUnk) {
+ *ppUnk = NULL;
+ }
return S_OK;
}
STDMETHODIMP CDirectVobSubFilter::GetClassID(CLSID* pClsid)
{
- if(pClsid == NULL) return E_POINTER;
+ if(pClsid == NULL) {
+ return E_POINTER;
+ }
*pClsid = m_clsid;
return NOERROR;
}
@@ -857,7 +883,9 @@ STDMETHODIMP CDirectVobSubFilter::GetPages(CAUUID* pPages)
pPages->cElems = 7;
pPages->pElems = (GUID*)CoTaskMemAlloc(sizeof(GUID)*pPages->cElems);
- if(pPages->pElems == NULL) return E_OUTOFMEMORY;
+ if(pPages->pElems == NULL) {
+ return E_OUTOFMEMORY;
+ }
int i = 0;
pPages->pElems[i++] = __uuidof(CDVSMainPPage);
@@ -877,8 +905,7 @@ STDMETHODIMP CDirectVobSubFilter::put_FileName(WCHAR* fn)
{
HRESULT hr = CDirectVobSub::put_FileName(fn);
- if(hr == S_OK && !Open())
- {
+ if(hr == S_OK && !Open()) {
m_FileName.Empty();
hr = E_FAIL;
}
@@ -890,13 +917,14 @@ STDMETHODIMP CDirectVobSubFilter::get_LanguageCount(int* nLangs)
{
HRESULT hr = CDirectVobSub::get_LanguageCount(nLangs);
- if(hr == NOERROR && nLangs)
- {
+ if(hr == NOERROR && nLangs) {
CAutoLock cAutolock(&m_csQueueLock);
*nLangs = 0;
POSITION pos = m_pSubStreams.GetHeadPosition();
- while(pos) (*nLangs) += m_pSubStreams.GetNext(pos)->GetStreamCount();
+ while(pos) {
+ (*nLangs) += m_pSubStreams.GetNext(pos)->GetStreamCount();
+ }
}
return hr;
@@ -906,10 +934,11 @@ STDMETHODIMP CDirectVobSubFilter::get_LanguageName(int iLanguage, WCHAR** ppName
{
HRESULT hr = CDirectVobSub::get_LanguageName(iLanguage, ppName);
- if(!ppName) return E_POINTER;
+ if(!ppName) {
+ return E_POINTER;
+ }
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
CAutoLock cAutolock(&m_csQueueLock);
hr = E_INVALIDARG;
@@ -917,12 +946,10 @@ STDMETHODIMP CDirectVobSubFilter::get_LanguageName(int iLanguage, WCHAR** ppName
int i = iLanguage;
POSITION pos = m_pSubStreams.GetHeadPosition();
- while(i >= 0 && pos)
- {
+ while(i >= 0 && pos) {
CComPtr<ISubStream> pSubStream = m_pSubStreams.GetNext(pos);
- if(i < pSubStream->GetStreamCount())
- {
+ if(i < pSubStream->GetStreamCount()) {
pSubStream->GetStreamInfo(i, ppName, NULL);
hr = NOERROR;
break;
@@ -939,8 +966,7 @@ STDMETHODIMP CDirectVobSubFilter::put_SelectedLanguage(int iSelected)
{
HRESULT hr = CDirectVobSub::put_SelectedLanguage(iSelected);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
UpdateSubtitle(false);
}
@@ -951,8 +977,7 @@ STDMETHODIMP CDirectVobSubFilter::put_HideSubtitles(bool fHideSubtitles)
{
HRESULT hr = CDirectVobSub::put_HideSubtitles(fHideSubtitles);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
UpdateSubtitle(false);
}
@@ -963,8 +988,7 @@ STDMETHODIMP CDirectVobSubFilter::put_PreBuffering(bool fDoPreBuffering)
{
HRESULT hr = CDirectVobSub::put_PreBuffering(fDoPreBuffering);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
InitSubPicQueue();
}
@@ -975,8 +999,7 @@ STDMETHODIMP CDirectVobSubFilter::put_Placement(bool fOverridePlacement, int xpe
{
HRESULT hr = CDirectVobSub::put_Placement(fOverridePlacement, xperc, yperc);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
UpdateSubtitle(true);
}
@@ -987,9 +1010,8 @@ STDMETHODIMP CDirectVobSubFilter::put_VobSubSettings(bool fBuffer, bool fOnlySho
{
HRESULT hr = CDirectVobSub::put_VobSubSettings(fBuffer, fOnlyShowForcedSubs, fReserved);
- if(hr == NOERROR)
- {
-// UpdateSubtitle(false);
+ if(hr == NOERROR) {
+ // UpdateSubtitle(false);
InvalidateSubtitle();
}
@@ -1000,9 +1022,8 @@ STDMETHODIMP CDirectVobSubFilter::put_TextSettings(void* lf, int lflen, COLORREF
{
HRESULT hr = CDirectVobSub::put_TextSettings(lf, lflen, color, fShadow, fOutline, fAdvancedRenderer);
- if(hr == NOERROR)
- {
-// UpdateSubtitle(true);
+ if(hr == NOERROR) {
+ // UpdateSubtitle(true);
InvalidateSubtitle();
}
@@ -1013,8 +1034,7 @@ STDMETHODIMP CDirectVobSubFilter::put_SubtitleTiming(int delay, int speedmul, in
{
HRESULT hr = CDirectVobSub::put_SubtitleTiming(delay, speedmul, speeddiv);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
InvalidateSubtitle();
}
@@ -1027,10 +1047,11 @@ STDMETHODIMP CDirectVobSubFilter::get_MediaFPS(bool* fEnabled, double* fps)
CComQIPtr<IMediaSeeking> pMS = m_pGraph;
double rate;
- if(pMS && SUCCEEDED(pMS->GetRate(&rate)))
- {
+ if(pMS && SUCCEEDED(pMS->GetRate(&rate))) {
m_MediaFPS = rate * m_fps;
- if(fps) *fps = m_MediaFPS;
+ if(fps) {
+ *fps = m_MediaFPS;
+ }
}
return hr;
@@ -1041,16 +1062,15 @@ STDMETHODIMP CDirectVobSubFilter::put_MediaFPS(bool fEnabled, double fps)
HRESULT hr = CDirectVobSub::put_MediaFPS(fEnabled, fps);
CComQIPtr<IMediaSeeking> pMS = m_pGraph;
- if(pMS)
- {
- if(hr == NOERROR)
- {
+ if(pMS) {
+ if(hr == NOERROR) {
hr = pMS->SetRate(m_fMediaFPSEnabled ? m_MediaFPS / m_fps : 1.0);
}
double dRate;
- if(SUCCEEDED(pMS->GetRate(&dRate)))
+ if(SUCCEEDED(pMS->GetRate(&dRate))) {
m_MediaFPS = dRate * m_fps;
+ }
}
return hr;
@@ -1072,8 +1092,7 @@ STDMETHODIMP CDirectVobSubFilter::put_TextSettings(STSStyle* pDefStyle)
{
HRESULT hr = CDirectVobSub::put_TextSettings(pDefStyle);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
UpdateSubtitle(true);
}
@@ -1084,8 +1103,7 @@ STDMETHODIMP CDirectVobSubFilter::put_AspectRatioSettings(CSimpleTextSubtitle::E
{
HRESULT hr = CDirectVobSub::put_AspectRatioSettings(ePARCompensationType);
- if(hr == NOERROR)
- {
+ if(hr == NOERROR) {
UpdateSubtitle(true);
}
@@ -1097,10 +1115,12 @@ STDMETHODIMP CDirectVobSubFilter::put_AspectRatioSettings(CSimpleTextSubtitle::E
STDMETHODIMP CDirectVobSubFilter::HasConfigDialog(int iSelected)
{
int nLangs;
- if(FAILED(get_LanguageCount(&nLangs))) return E_FAIL;
+ if(FAILED(get_LanguageCount(&nLangs))) {
+ return E_FAIL;
+ }
return E_FAIL;
// TODO: temporally disabled since we don't have a new textsub/vobsub editor dlg for dvs yet
-// return(nLangs >= 0 && iSelected < nLangs ? S_OK : E_FAIL);
+ // return(nLangs >= 0 && iSelected < nLangs ? S_OK : E_FAIL);
}
STDMETHODIMP CDirectVobSubFilter::ShowConfigDialog(int iSelected, HWND hWndParent)
@@ -1119,19 +1139,21 @@ CDirectVobSubFilter2::CDirectVobSubFilter2(LPUNKNOWN punk, HRESULT* phr, const G
HRESULT CDirectVobSubFilter2::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
{
CPinInfo pi;
- if(FAILED(pPin->QueryPinInfo(&pi))) return E_FAIL;
+ if(FAILED(pPin->QueryPinInfo(&pi))) {
+ return E_FAIL;
+ }
- if(CComQIPtr<IDirectVobSub>(pi.pFilter)) return E_FAIL;
+ if(CComQIPtr<IDirectVobSub>(pi.pFilter)) {
+ return E_FAIL;
+ }
- if(dir == PINDIR_INPUT)
- {
+ if(dir == PINDIR_INPUT) {
CFilterInfo fi;
if(SUCCEEDED(pi.pFilter->QueryFilterInfo(&fi))
- && !wcsnicmp(fi.achName, L"Overlay Mixer", 13))
+ && !wcsnicmp(fi.achName, L"Overlay Mixer", 13)) {
return(E_FAIL);
- }
- else
- {
+ }
+ } else {
}
return __super::CheckConnect(dir, pPin);
@@ -1139,12 +1161,11 @@ HRESULT CDirectVobSubFilter2::CheckConnect(PIN_DIRECTION dir, IPin* pPin)
HRESULT CDirectVobSubFilter2::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pName)
{
- if(pGraph)
- {
- BeginEnumFilters(pGraph, pEF, pBF)
- {
- if(pBF != (IBaseFilter*)this && CComQIPtr<IDirectVobSub>(pBF))
+ if(pGraph) {
+ BeginEnumFilters(pGraph, pEF, pBF) {
+ if(pBF != (IBaseFilter*)this && CComQIPtr<IDirectVobSub>(pBF)) {
return E_FAIL;
+ }
}
EndEnumFilters
@@ -1158,31 +1179,32 @@ HRESULT CDirectVobSubFilter2::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pNam
// This whole workaround is needed because the video stream will always be connected
// to the pre-added filters first, no matter how high merit we have.
- if(!get_Forced())
- {
- BeginEnumFilters(pGraph, pEF, pBF)
- {
- if(CComQIPtr<IDirectVobSub>(pBF))
+ if(!get_Forced()) {
+ BeginEnumFilters(pGraph, pEF, pBF) {
+ if(CComQIPtr<IDirectVobSub>(pBF)) {
continue;
+ }
CComPtr<IPin> pInPin = GetFirstPin(pBF, PINDIR_INPUT);
CComPtr<IPin> pOutPin = GetFirstPin(pBF, PINDIR_OUTPUT);
- if(!pInPin)
+ if(!pInPin) {
continue;
+ }
CComPtr<IPin> pPin;
if(pInPin && SUCCEEDED(pInPin->ConnectedTo(&pPin))
- || pOutPin && SUCCEEDED(pOutPin->ConnectedTo(&pPin)))
+ || pOutPin && SUCCEEDED(pOutPin->ConnectedTo(&pPin))) {
continue;
+ }
- if(pOutPin && GetFilterName(pBF) == _T("Overlay Mixer"))
+ if(pOutPin && GetFilterName(pBF) == _T("Overlay Mixer")) {
continue;
+ }
bool fVideoInputPin = false;
- do
- {
+ do {
BITMAPINFOHEADER bih = {sizeof(BITMAPINFOHEADER), 384, 288, 1, 16, '2YUY', 384*288*2, 0, 0, 0, 0};
CMediaType cmt;
@@ -1198,8 +1220,7 @@ HRESULT CDirectVobSubFilter2::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pNam
memcpy(&vih->bmiHeader, &bih, sizeof(bih));
vih->AvgTimePerFrame = 400000;
- if(SUCCEEDED(pInPin->QueryAccept(&cmt)))
- {
+ if(SUCCEEDED(pInPin->QueryAccept(&cmt))) {
fVideoInputPin = true;
break;
}
@@ -1211,19 +1232,15 @@ HRESULT CDirectVobSubFilter2::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pNam
vih2->dwPictAspectRatioX = 384;
vih2->dwPictAspectRatioY = 288;
- if(SUCCEEDED(pInPin->QueryAccept(&cmt)))
- {
+ if(SUCCEEDED(pInPin->QueryAccept(&cmt))) {
fVideoInputPin = true;
break;
}
- }
- while(false);
+ } while(false);
- if(fVideoInputPin)
- {
+ if(fVideoInputPin) {
CComPtr<IBaseFilter> pDVS;
- if(ShouldWeAutoload(pGraph) && SUCCEEDED(pDVS.CoCreateInstance(__uuidof(CDirectVobSubFilter2))))
- {
+ if(ShouldWeAutoload(pGraph) && SUCCEEDED(pDVS.CoCreateInstance(__uuidof(CDirectVobSubFilter2)))) {
CComQIPtr<IDirectVobSub2>(pDVS)->put_Forced(true);
CComQIPtr<IGraphConfig>(pGraph)->AddFilterToCache(pDVS);
}
@@ -1233,9 +1250,7 @@ HRESULT CDirectVobSubFilter2::JoinFilterGraph(IFilterGraph* pGraph, LPCWSTR pNam
}
EndEnumFilters
}
- }
- else
- {
+ } else {
}
return __super::JoinFilterGraph(pGraph, pName);
@@ -1245,9 +1260,13 @@ HRESULT CDirectVobSubFilter2::CheckInputType(const CMediaType* mtIn)
{
HRESULT hr = __super::CheckInputType(mtIn);
- if(FAILED(hr) || m_pInput->IsConnected()) return hr;
+ if(FAILED(hr) || m_pInput->IsConnected()) {
+ return hr;
+ }
- if(!ShouldWeAutoload(m_pGraph)) return VFW_E_TYPE_NOT_ACCEPTED;
+ if(!ShouldWeAutoload(m_pGraph)) {
+ return VFW_E_TYPE_NOT_ACCEPTED;
+ }
GetRidOfInternalScriptRenderer();
@@ -1256,8 +1275,7 @@ HRESULT CDirectVobSubFilter2::CheckInputType(const CMediaType* mtIn)
bool CDirectVobSubFilter2::ShouldWeAutoload(IFilterGraph* pGraph)
{
- TCHAR blacklistedapps[][32] =
- {
+ TCHAR blacklistedapps[][32] = {
_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)
_T("explorer."), // as some users reported thumbnail preview loads dvobsub, I've never experienced this yet...
_T("producer."), // this is real's producer
@@ -1266,54 +1284,54 @@ bool CDirectVobSubFilter2::ShouldWeAutoload(IFilterGraph* pGraph)
_T("GoogleDesktopCrawl."), // Google Desktop
};
- for(ptrdiff_t i = 0; i < countof(blacklistedapps); i++)
- {
- if(theApp.m_AppName.Find(blacklistedapps[i]) >= 0)
+ for(ptrdiff_t i = 0; i < countof(blacklistedapps); i++) {
+ if(theApp.m_AppName.Find(blacklistedapps[i]) >= 0) {
return(false);
+ }
}
int level;
bool m_fExternalLoad, m_fWebLoad, m_fEmbeddedLoad;
get_LoadSettings(&level, &m_fExternalLoad, &m_fWebLoad, &m_fEmbeddedLoad);
- if(level < 0 || level >= 2) return(false);
+ if(level < 0 || level >= 2) {
+ return(false);
+ }
bool fRet = false;
- if(level == 1)
+ if(level == 1) {
fRet = m_fExternalLoad = m_fWebLoad = m_fEmbeddedLoad = true;
+ }
// find text stream on known splitters
- if(!fRet && m_fEmbeddedLoad)
- {
+ if(!fRet && m_fEmbeddedLoad) {
CComPtr<IBaseFilter> pBF;
if((pBF = FindFilter(CLSID_OggSplitter, pGraph)) || (pBF = FindFilter(CLSID_AviSplitter, pGraph))
- || (pBF = FindFilter(L"{34293064-02F2-41D5-9D75-CC5967ACA1AB}", pGraph)) // matroska demux
- || (pBF = FindFilter(L"{0A68C3B5-9164-4a54-AFAF-995B2FF0E0D4}", pGraph)) // matroska source
- || (pBF = FindFilter(L"{149D2E01-C32E-4939-80F6-C07B81015A7A}", pGraph)) // matroska splitter
- || (pBF = FindFilter(L"{9AB95E90-1F37-427e-9B3D-257FB0CB25F7}", pGraph)) // Haali's matroska splitter (?)
- || (pBF = FindFilter(L"{55DA30FC-F16B-49fc-BAA5-AE59FC65F82D}", pGraph)) // Haali's matroska splitter
- || (pBF = FindFilter(L"{52B63861-DC93-11CE-A099-00AA00479A58}", pGraph)) // 3ivx splitter
- || (pBF = FindFilter(L"{6D3688CE-3E9D-42F4-92CA-8A11119D25CD}", pGraph)) // our ogg source
- || (pBF = FindFilter(L"{9FF48807-E133-40AA-826F-9B2959E5232D}", pGraph)) // our ogg splitter
- || (pBF = FindFilter(L"{803E8280-F3CE-4201-982C-8CD8FB512004}", pGraph)) // dsm source
- || (pBF = FindFilter(L"{0912B4DD-A30A-4568-B590-7179EBB420EC}", pGraph)) // dsm splitter
- || (pBF = FindFilter(L"{3CCC052E-BDEE-408a-BEA7-90914EF2964B}", pGraph)) // mp4 source
- || (pBF = FindFilter(L"{61F47056-E400-43d3-AF1E-AB7DFFD4C4AD}", pGraph))) // mp4 splitter
- {
- BeginEnumPins(pBF, pEP, pPin)
- {
- BeginEnumMediaTypes(pPin, pEM, pmt)
- {
- if(pmt->majortype == MEDIATYPE_Text || pmt->majortype == MEDIATYPE_Subtitle)
- {
+ || (pBF = FindFilter(L"{34293064-02F2-41D5-9D75-CC5967ACA1AB}", pGraph)) // matroska demux
+ || (pBF = FindFilter(L"{0A68C3B5-9164-4a54-AFAF-995B2FF0E0D4}", pGraph)) // matroska source
+ || (pBF = FindFilter(L"{149D2E01-C32E-4939-80F6-C07B81015A7A}", pGraph)) // matroska splitter
+ || (pBF = FindFilter(L"{9AB95E90-1F37-427e-9B3D-257FB0CB25F7}", pGraph)) // Haali's matroska splitter (?)
+ || (pBF = FindFilter(L"{55DA30FC-F16B-49fc-BAA5-AE59FC65F82D}", pGraph)) // Haali's matroska splitter
+ || (pBF = FindFilter(L"{52B63861-DC93-11CE-A099-00AA00479A58}", pGraph)) // 3ivx splitter
+ || (pBF = FindFilter(L"{6D3688CE-3E9D-42F4-92CA-8A11119D25CD}", pGraph)) // our ogg source
+ || (pBF = FindFilter(L"{9FF48807-E133-40AA-826F-9B2959E5232D}", pGraph)) // our ogg splitter
+ || (pBF = FindFilter(L"{803E8280-F3CE-4201-982C-8CD8FB512004}", pGraph)) // dsm source
+ || (pBF = FindFilter(L"{0912B4DD-A30A-4568-B590-7179EBB420EC}", pGraph)) // dsm splitter
+ || (pBF = FindFilter(L"{3CCC052E-BDEE-408a-BEA7-90914EF2964B}", pGraph)) // mp4 source
+ || (pBF = FindFilter(L"{61F47056-E400-43d3-AF1E-AB7DFFD4C4AD}", pGraph))) { // mp4 splitter
+ BeginEnumPins(pBF, pEP, pPin) {
+ BeginEnumMediaTypes(pPin, pEM, pmt) {
+ if(pmt->majortype == MEDIATYPE_Text || pmt->majortype == MEDIATYPE_Subtitle) {
fRet = true;
break;
}
}
EndEnumMediaTypes(pmt)
- if(fRet) break;
+ if(fRet) {
+ break;
+ }
}
EndEnumFilters
}
@@ -1323,13 +1341,12 @@ bool CDirectVobSubFilter2::ShouldWeAutoload(IFilterGraph* pGraph)
CStringW fn;
- BeginEnumFilters(pGraph, pEF, pBF)
- {
- if(CComQIPtr<IFileSourceFilter> pFSF = pBF)
- {
+ BeginEnumFilters(pGraph, pEF, pBF) {
+ if(CComQIPtr<IFileSourceFilter> pFSF = pBF) {
LPOLESTR fnw = NULL;
- if(!pFSF || FAILED(pFSF->GetCurFile(&fnw, NULL)) || !fnw)
+ if(!pFSF || FAILED(pFSF->GetCurFile(&fnw, NULL)) || !fnw) {
continue;
+ }
fn = CString(fnw);
CoTaskMemFree(fnw);
break;
@@ -1337,13 +1354,14 @@ bool CDirectVobSubFilter2::ShouldWeAutoload(IFilterGraph* pGraph)
}
EndEnumFilters
- if((m_fExternalLoad || m_fWebLoad) && (m_fWebLoad || !(wcsstr(fn, L"http://") || wcsstr(fn, L"mms://"))))
- {
+ if((m_fExternalLoad || m_fWebLoad) && (m_fWebLoad || !(wcsstr(fn, L"http://") || wcsstr(fn, L"mms://")))) {
bool fTemp = m_fHideSubtitles;
fRet = !fn.IsEmpty() && SUCCEEDED(put_FileName((LPWSTR)(LPCWSTR)fn))
|| SUCCEEDED(put_FileName(L"c:\\tmp.srt"))
|| fRet;
- if(fTemp) m_fHideSubtitles = true;
+ if(fTemp) {
+ m_fHideSubtitles = true;
+ }
}
return(fRet);
@@ -1351,16 +1369,13 @@ bool CDirectVobSubFilter2::ShouldWeAutoload(IFilterGraph* pGraph)
void CDirectVobSubFilter2::GetRidOfInternalScriptRenderer()
{
- while(CComPtr<IBaseFilter> pBF = FindFilter(L"{48025243-2D39-11CE-875D-00608CB78066}", m_pGraph))
- {
- BeginEnumPins(pBF, pEP, pPin)
- {
+ while(CComPtr<IBaseFilter> pBF = FindFilter(L"{48025243-2D39-11CE-875D-00608CB78066}", m_pGraph)) {
+ BeginEnumPins(pBF, pEP, pPin) {
PIN_DIRECTION dir;
CComPtr<IPin> pPinTo;
if(SUCCEEDED(pPin->QueryDirection(&dir)) && dir == PINDIR_INPUT
- && SUCCEEDED(pPin->ConnectedTo(&pPinTo)))
- {
+ && SUCCEEDED(pPin->ConnectedTo(&pPinTo))) {
m_pGraph->Disconnect(pPinTo);
m_pGraph->Disconnect(pPin);
m_pGraph->ConnectDirect(pPinTo, GetPin(2 + m_pTextInput.GetCount()-1), NULL);
@@ -1368,8 +1383,9 @@ void CDirectVobSubFilter2::GetRidOfInternalScriptRenderer()
}
EndEnumPins
- if(FAILED(m_pGraph->RemoveFilter(pBF)))
+ if(FAILED(m_pGraph->RemoveFilter(pBF))) {
break;
+ }
}
}
@@ -1387,68 +1403,63 @@ bool CDirectVobSubFilter::Open()
CAtlArray<CString> paths;
- for(ptrdiff_t i = 0; i < 10; i++)
- {
+ for(ptrdiff_t i = 0; i < 10; i++) {
CString tmp;
tmp.Format(IDS_RP_PATH, i);
CString path = theApp.GetProfileString(ResStr(IDS_R_DEFTEXTPATHES), tmp);
- if(!path.IsEmpty()) paths.Add(path);
+ if(!path.IsEmpty()) {
+ paths.Add(path);
+ }
}
CAtlArray<SubFile> ret;
GetSubFileNames(m_FileName, paths, ret);
- for(ptrdiff_t i = 0; i < ret.GetCount(); i++)
- {
- if(m_frd.files.Find(ret[i].fn))
+ for(ptrdiff_t i = 0; i < ret.GetCount(); i++) {
+ if(m_frd.files.Find(ret[i].fn)) {
continue;
+ }
CComPtr<ISubStream> pSubStream;
- if(!pSubStream)
- {
+ if(!pSubStream) {
CAutoPtr<CVobSubFile> pVSF(new CVobSubFile(&m_csSubLock));
- if(pVSF && pVSF->Open(ret[i].fn) && pVSF->GetStreamCount() > 0)
- {
+ if(pVSF && pVSF->Open(ret[i].fn) && pVSF->GetStreamCount() > 0) {
pSubStream = pVSF.Detach();
m_frd.files.AddTail(ret[i].fn.Left(ret[i].fn.GetLength()-4) + _T(".sub"));
}
}
- if(!pSubStream)
- {
+ if(!pSubStream) {
CAutoPtr<ssf::CRenderer> pSSF(new ssf::CRenderer(&m_csSubLock));
- if(pSSF && pSSF->Open(ret[i].fn) && pSSF->GetStreamCount() > 0)
- {
+ if(pSSF && pSSF->Open(ret[i].fn) && pSSF->GetStreamCount() > 0) {
pSubStream = pSSF.Detach();
}
}
- if(!pSubStream)
- {
+ if(!pSubStream) {
CAutoPtr<CRenderedTextSubtitle> pRTS(new CRenderedTextSubtitle(&m_csSubLock));
- if(pRTS && pRTS->Open(ret[i].fn, DEFAULT_CHARSET) && pRTS->GetStreamCount() > 0)
- {
+ if(pRTS && pRTS->Open(ret[i].fn, DEFAULT_CHARSET) && pRTS->GetStreamCount() > 0) {
pSubStream = pRTS.Detach();
m_frd.files.AddTail(ret[i].fn + _T(".style"));
}
}
- if(pSubStream)
- {
+ if(pSubStream) {
m_pSubStreams.AddTail(pSubStream);
m_frd.files.AddTail(ret[i].fn);
}
}
- for(ptrdiff_t i = 0; i < m_pTextInput.GetCount(); i++)
- {
- if(m_pTextInput[i]->IsConnected())
+ for(ptrdiff_t i = 0; i < m_pTextInput.GetCount(); i++) {
+ if(m_pTextInput[i]->IsConnected()) {
m_pSubStreams.AddTail(m_pTextInput[i]->GetSubStream());
+ }
}
- if(S_FALSE == put_SelectedLanguage(FindPreferedLanguage()))
- UpdateSubtitle(false); // make sure pSubPicProvider of our queue gets updated even if the stream number hasn't changed
+ if(S_FALSE == put_SelectedLanguage(FindPreferedLanguage())) {
+ UpdateSubtitle(false); // make sure pSubPicProvider of our queue gets updated even if the stream number hasn't changed
+ }
m_frd.RefreshEvent.Set();
@@ -1459,22 +1470,21 @@ void CDirectVobSubFilter::UpdateSubtitle(bool fApplyDefStyle)
{
CAutoLock cAutolock(&m_csQueueLock);
- if(!m_pSubPicQueue) return;
+ if(!m_pSubPicQueue) {
+ return;
+ }
InvalidateSubtitle();
CComPtr<ISubStream> pSubStream;
- if(!m_fHideSubtitles)
- {
+ if(!m_fHideSubtitles) {
int i = m_iSelectedLanguage;
- for(POSITION pos = m_pSubStreams.GetHeadPosition(); i >= 0 && pos; pSubStream = NULL)
- {
+ for(POSITION pos = m_pSubStreams.GetHeadPosition(); i >= 0 && pos; pSubStream = NULL) {
pSubStream = m_pSubStreams.GetNext(pos);
- if(i < pSubStream->GetStreamCount())
- {
+ if(i < pSubStream->GetStreamCount()) {
CAutoLock cAutoLock(&m_csSubLock);
pSubStream->SetStream(i);
break;
@@ -1491,43 +1501,33 @@ void CDirectVobSubFilter::SetSubtitle(ISubStream* pSubStream, bool fApplyDefStyl
{
CAutoLock cAutolock(&m_csQueueLock);
- if(pSubStream)
- {
+ if(pSubStream) {
CAutoLock cAutolock(&m_csSubLock);
CLSID clsid;
pSubStream->GetClassID(&clsid);
- if(clsid == __uuidof(CVobSubFile))
- {
+ if(clsid == __uuidof(CVobSubFile)) {
CVobSubSettings* pVSS = (CVobSubFile*)(ISubStream*)pSubStream;
- if(fApplyDefStyle)
- {
+ if(fApplyDefStyle) {
pVSS->SetAlignment(m_fOverridePlacement, m_PlacementXperc, m_PlacementYperc, 1, 1);
pVSS->m_fOnlyShowForcedSubs = m_fOnlyShowForcedVobSubs;
}
- }
- else if(clsid == __uuidof(CVobSubStream))
- {
+ } else if(clsid == __uuidof(CVobSubStream)) {
CVobSubSettings* pVSS = (CVobSubStream*)(ISubStream*)pSubStream;
- if(fApplyDefStyle)
- {
+ if(fApplyDefStyle) {
pVSS->SetAlignment(m_fOverridePlacement, m_PlacementXperc, m_PlacementYperc, 1, 1);
pVSS->m_fOnlyShowForcedSubs = m_fOnlyShowForcedVobSubs;
}
- }
- else if(clsid == __uuidof(CRenderedTextSubtitle))
- {
+ } else if(clsid == __uuidof(CRenderedTextSubtitle)) {
CRenderedTextSubtitle* pRTS = (CRenderedTextSubtitle*)(ISubStream*)pSubStream;
- if(fApplyDefStyle || pRTS->m_fUsingAutoGeneratedDefaultStyle)
- {
+ if(fApplyDefStyle || pRTS->m_fUsingAutoGeneratedDefaultStyle) {
STSStyle s = m_defStyle;
- if(m_fOverridePlacement)
- {
+ if(m_fOverridePlacement) {
s.scrAlignment = 2;
int w = pRTS->m_dstScreenSize.cx;
int h = pRTS->m_dstScreenSize.cy;
@@ -1541,14 +1541,11 @@ void CDirectVobSubFilter::SetSubtitle(ISubStream* pSubStream, bool fApplyDefStyl
}
pRTS->m_ePARCompensationType = m_ePARCompensationType;
- if (m_CurrentVIH2.dwPictAspectRatioX != 0 && m_CurrentVIH2.dwPictAspectRatioY != 0&& m_CurrentVIH2.bmiHeader.biWidth != 0 && m_CurrentVIH2.bmiHeader.biHeight != 0)
- {
+ if (m_CurrentVIH2.dwPictAspectRatioX != 0 && m_CurrentVIH2.dwPictAspectRatioY != 0&& m_CurrentVIH2.bmiHeader.biWidth != 0 && m_CurrentVIH2.bmiHeader.biHeight != 0) {
pRTS->m_dPARCompensation = ((double)abs(m_CurrentVIH2.bmiHeader.biWidth) / (double)abs(m_CurrentVIH2.bmiHeader.biHeight)) /
((double)abs((long)m_CurrentVIH2.dwPictAspectRatioX) / (double)abs((long)m_CurrentVIH2.dwPictAspectRatioY));
- }
- else
- {
+ } else {
pRTS->m_dPARCompensation = 1.00;
}
@@ -1556,17 +1553,14 @@ void CDirectVobSubFilter::SetSubtitle(ISubStream* pSubStream, bool fApplyDefStyl
}
}
- if(!fApplyDefStyle)
- {
+ if(!fApplyDefStyle) {
int i = 0;
POSITION pos = m_pSubStreams.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CComPtr<ISubStream> pSubStream2 = m_pSubStreams.GetNext(pos);
- if(pSubStream == pSubStream2)
- {
+ if(pSubStream == pSubStream2) {
m_iSelectedLanguage = i + pSubStream2->GetStream();
break;
}
@@ -1577,18 +1571,19 @@ void CDirectVobSubFilter::SetSubtitle(ISubStream* pSubStream, bool fApplyDefStyl
m_nSubtitleId = (DWORD_PTR)pSubStream;
- if(m_pSubPicQueue)
+ if(m_pSubPicQueue) {
m_pSubPicQueue->SetSubPicProvider(CComQIPtr<ISubPicProvider>(pSubStream));
+ }
}
void CDirectVobSubFilter::InvalidateSubtitle(REFERENCE_TIME rtInvalidate, DWORD_PTR nSubtitleId)
{
CAutoLock cAutolock(&m_csQueueLock);
- if(m_pSubPicQueue)
- {
- if(nSubtitleId == -1 || nSubtitleId == m_nSubtitleId)
+ if(m_pSubPicQueue) {
+ if(nSubtitleId == -1 || nSubtitleId == m_nSubtitleId) {
m_pSubPicQueue->Invalidate(rtInvalidate);
+ }
}
}
@@ -1599,14 +1594,17 @@ void CDirectVobSubFilter::AddSubStream(ISubStream* pSubStream)
CAutoLock cAutoLock(&m_csQueueLock);
POSITION pos = m_pSubStreams.Find(pSubStream);
- if(!pos) m_pSubStreams.AddTail(pSubStream);
+ if(!pos) {
+ m_pSubStreams.AddTail(pSubStream);
+ }
int len = m_pTextInput.GetCount();
for(ptrdiff_t i = 0; i < m_pTextInput.GetCount(); i++)
- if(m_pTextInput[i]->IsConnected()) len--;
+ if(m_pTextInput[i]->IsConnected()) {
+ len--;
+ }
- if(len == 0)
- {
+ if(len == 0) {
HRESULT hr = S_OK;
m_pTextInput.Add(new CTextInputPin(this, m_pLock, &m_csSubLock, &hr));
}
@@ -1617,21 +1615,28 @@ void CDirectVobSubFilter::RemoveSubStream(ISubStream* pSubStream)
CAutoLock cAutoLock(&m_csQueueLock);
POSITION pos = m_pSubStreams.Find(pSubStream);
- if(pos) m_pSubStreams.RemoveAt(pos);
+ if(pos) {
+ m_pSubStreams.RemoveAt(pos);
+ }
}
void CDirectVobSubFilter::Post_EC_OLE_EVENT(CString str, DWORD_PTR nSubtitleId)
{
- if(nSubtitleId != -1 && nSubtitleId != m_nSubtitleId)
+ if(nSubtitleId != -1 && nSubtitleId != m_nSubtitleId) {
return;
+ }
CComQIPtr<IMediaEventSink> pMES = m_pGraph;
- if(!pMES) return;
+ if(!pMES) {
+ return;
+ }
CComBSTR bstr1("Text"), bstr2(" ");
str.Trim();
- if(!str.IsEmpty()) bstr2 = CStringA(str);
+ if(!str.IsEmpty()) {
+ bstr2 = CStringA(str);
+ }
pMES->Notify(EC_OLE_EVENT, (LONG_PTR)bstr1.Detach(), (LONG_PTR)bstr2.Detach());
}
@@ -1642,8 +1647,7 @@ void CDirectVobSubFilter::SetupFRD(CStringArray& paths, CAtlArray<HANDLE>& handl
{
CAutoLock cAutolock(&m_csSubLock);
- for(ptrdiff_t i = 2; i < handles.GetCount(); i++)
- {
+ for(ptrdiff_t i = 2; i < handles.GetCount(); i++) {
FindCloseChangeNotification(handles[i]);
}
@@ -1656,30 +1660,32 @@ void CDirectVobSubFilter::SetupFRD(CStringArray& paths, CAtlArray<HANDLE>& handl
m_frd.mtime.SetCount(m_frd.files.GetCount());
POSITION pos = m_frd.files.GetHeadPosition();
- for(ptrdiff_t i = 0; pos; i++)
- {
+ for(ptrdiff_t i = 0; pos; i++) {
CString fn = m_frd.files.GetNext(pos);
CFileStatus status;
- if(CFileGetStatus(fn, status))
+ if(CFileGetStatus(fn, status)) {
m_frd.mtime[i] = status.m_mtime;
+ }
fn.Replace('\\', '/');
fn = fn.Left(fn.ReverseFind('/')+1);
bool fFound = false;
- for(ptrdiff_t j = 0; !fFound && j < paths.GetCount(); j++)
- {
- if(paths[j] == fn) fFound = true;
+ for(ptrdiff_t j = 0; !fFound && j < paths.GetCount(); j++) {
+ if(paths[j] == fn) {
+ fFound = true;
+ }
}
- if(!fFound)
- {
+ if(!fFound) {
paths.Add(fn);
HANDLE h = FindFirstChangeNotification(fn, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
- if(h != INVALID_HANDLE_VALUE) handles.Add(h);
+ if(h != INVALID_HANDLE_VALUE) {
+ handles.Add(h);
+ }
}
}
}
@@ -1693,47 +1699,39 @@ DWORD CDirectVobSubFilter::ThreadProc()
SetupFRD(paths, handles);
- while(1)
- {
+ while(1) {
DWORD idx = WaitForMultipleObjects(handles.GetCount(), handles.GetData(), FALSE, INFINITE);
- if(idx == (WAIT_OBJECT_0 + 0)) // m_frd.hEndThreadEvent
- {
+ if(idx == (WAIT_OBJECT_0 + 0)) { // m_frd.hEndThreadEvent
break;
}
- if(idx == (WAIT_OBJECT_0 + 1)) // m_frd.hRefreshEvent
- {
+ if(idx == (WAIT_OBJECT_0 + 1)) { // m_frd.hRefreshEvent
SetupFRD(paths, handles);
- }
- else if(idx >= (WAIT_OBJECT_0 + 2) && idx < (WAIT_OBJECT_0 + handles.GetCount()))
- {
+ } else if(idx >= (WAIT_OBJECT_0 + 2) && idx < (WAIT_OBJECT_0 + handles.GetCount())) {
bool fLocked = true;
IsSubtitleReloaderLocked(&fLocked);
- if(fLocked) continue;
+ if(fLocked) {
+ continue;
+ }
- if(FindNextChangeNotification(handles[idx - WAIT_OBJECT_0]) == FALSE)
+ if(FindNextChangeNotification(handles[idx - WAIT_OBJECT_0]) == FALSE) {
break;
+ }
int j = 0;
POSITION pos = m_frd.files.GetHeadPosition();
- for(ptrdiff_t i = 0; pos && j == 0; i++)
- {
+ for(ptrdiff_t i = 0; pos && j == 0; i++) {
CString fn = m_frd.files.GetNext(pos);
CFileStatus status;
- if(CFileGetStatus(fn, status) && m_frd.mtime[i] != status.m_mtime)
- {
- for(j = 0; j < 10; j++)
- {
- if(FILE* f = _tfopen(fn, _T("rb+")))
- {
+ if(CFileGetStatus(fn, status) && m_frd.mtime[i] != status.m_mtime) {
+ for(j = 0; j < 10; j++) {
+ if(FILE* f = _tfopen(fn, _T("rb+"))) {
fclose(f);
j = 0;
break;
- }
- else
- {
+ } else {
Sleep(100);
j++;
}
@@ -1741,36 +1739,28 @@ DWORD CDirectVobSubFilter::ThreadProc()
}
}
- if(j > 0)
- {
+ if(j > 0) {
SetupFRD(paths, handles);
- }
- else
- {
+ } else {
Sleep(500);
POSITION pos = m_frd.files.GetHeadPosition();
- for(ptrdiff_t i = 0; pos; i++)
- {
+ for(ptrdiff_t i = 0; pos; i++) {
CFileStatus status;
if(CFileGetStatus(m_frd.files.GetNext(pos), status)
- && m_frd.mtime[i] != status.m_mtime)
- {
+ && m_frd.mtime[i] != status.m_mtime) {
Open();
SetupFRD(paths, handles);
break;
}
}
}
- }
- else
- {
+ } else {
break;
}
}
- for(ptrdiff_t i = 2; i < handles.GetCount(); i++)
- {
+ for(ptrdiff_t i = 2; i < handles.GetCount(); i++) {
FindCloseChangeNotification(handles[i]);
}
diff --git a/src/filters/transform/VSFilter/DirectVobSubFilter.h b/src/filters/transform/VSFilter/DirectVobSubFilter.h
index 6552d5f17..82932bd2c 100644
--- a/src/filters/transform/VSFilter/DirectVobSubFilter.h
+++ b/src/filters/transform/VSFilter/DirectVobSubFilter.h
@@ -30,8 +30,7 @@
#include "../../../Subtitles/RTS.h"
#include "../../../Subtitles/SSF.h"
-typedef struct
-{
+typedef struct {
HWND hSystrayWnd;
IFilterGraph* graph;
IDirectVobSub* dvs;
diff --git a/src/filters/transform/VSFilter/DirectVobSubPropPage.cpp b/src/filters/transform/VSFilter/DirectVobSubPropPage.cpp
index 4b4713a64..79196273c 100644
--- a/src/filters/transform/VSFilter/DirectVobSubPropPage.cpp
+++ b/src/filters/transform/VSFilter/DirectVobSubPropPage.cpp
@@ -48,7 +48,9 @@ BOOL WINAPI MyGetDialogSize(int iResourceID, DLGPROC pDlgProc, LPARAM lParam, SI
pDlgProc,
lParam);
- if(hwnd == NULL) return FALSE;
+ if(hwnd == NULL) {
+ return FALSE;
+ }
RECT rc;
GetWindowRect(hwnd, &rc);
@@ -65,7 +67,9 @@ STDMETHODIMP CDVSBasePPage::GetPageInfo(LPPROPPAGEINFO pPageInfo)
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CString str;
- if(!str.LoadString(m_TitleId)) return E_FAIL;
+ if(!str.LoadString(m_TitleId)) {
+ return E_FAIL;
+ }
WCHAR wszTitle[STR_MAX_LENGTH];
#ifdef UNICODE
@@ -104,16 +108,20 @@ STDMETHODIMP CDVSBasePPage::Activate(HWND hwndParent, LPCRECT pRect, BOOL fModal
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CheckPointer(pRect,E_POINTER);
-/*
- // Return failure if SetObject has not been called.
- if (m_bObjectSet == FALSE) {
+ /*
+ // Return failure if SetObject has not been called.
+ if (m_bObjectSet == FALSE) {
+ return E_UNEXPECTED;
+ }
+ */
+ if(m_hwnd) {
return E_UNEXPECTED;
}
-*/
- if(m_hwnd) return E_UNEXPECTED;
m_hwnd = CreateDialogParam(AfxGetResourceHandle(), MAKEINTRESOURCE(m_DialogId), hwndParent, DialogProc, (LPARAM)this);
- if(m_hwnd == NULL) return E_OUTOFMEMORY;
+ if(m_hwnd == NULL) {
+ return E_OUTOFMEMORY;
+ }
OnActivate();
Move(pRect);
@@ -132,36 +140,34 @@ CDVSBasePPage::CDVSBasePPage(TCHAR* pName, LPUNKNOWN lpunk, int DialogId, int Ti
INT_PTR CDVSBasePPage::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- if(m_bIsInitialized)
- {
- m_bDirty = TRUE;
- if(m_pPageSite) m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
-
- switch(HIWORD(wParam))
- {
- case BN_CLICKED:
- case CBN_SELCHANGE:
- case EN_CHANGE:
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- if(!m_fDisableInstantUpdate
- && !(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_INSTANTUPDATE)
- && !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_INSTANTUPDATE), 1))
- OnApplyChanges();
- }
+ switch(uMsg) {
+ case WM_COMMAND: {
+ if(m_bIsInitialized) {
+ m_bDirty = TRUE;
+ if(m_pPageSite) {
+ m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
+ }
+
+ switch(HIWORD(wParam)) {
+ case BN_CLICKED:
+ case CBN_SELCHANGE:
+ case EN_CHANGE: {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+ if(!m_fDisableInstantUpdate
+ && !(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_INSTANTUPDATE)
+ && !!theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_INSTANTUPDATE), 1)) {
+ OnApplyChanges();
+ }
+ }
+ }
}
}
- }
- break;
-
- case WM_NCDESTROY:
- DetachControls();
break;
+
+ case WM_NCDESTROY:
+ DetachControls();
+ break;
}
return OnMessage(uMsg, wParam, lParam)
@@ -171,7 +177,9 @@ INT_PTR CDVSBasePPage::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
HRESULT CDVSBasePPage::OnConnect(IUnknown* pUnknown)
{
- if(!(m_pDirectVobSub = pUnknown)) return E_NOINTERFACE;
+ if(!(m_pDirectVobSub = pUnknown)) {
+ return E_NOINTERFACE;
+ }
m_pDirectVobSub->LockSubtitleReloader(true); // *
@@ -186,7 +194,9 @@ HRESULT CDVSBasePPage::OnConnect(IUnknown* pUnknown)
HRESULT CDVSBasePPage::OnDisconnect()
{
- if(m_pDirectVobSub == NULL) return E_UNEXPECTED;
+ if(m_pDirectVobSub == NULL) {
+ return E_UNEXPECTED;
+ }
m_pDirectVobSub->LockSubtitleReloader(false); // *
@@ -233,8 +243,7 @@ HRESULT CDVSBasePPage::OnApplyChanges()
AFX_MANAGE_STATE(AfxGetStaticModuleState());
- if(m_bIsInitialized)
- {
+ if(m_bIsInitialized) {
OnDeactivate();
UpdateObjectData(true);
m_pDirectVobSub->UpdateRegistry(); // *
@@ -251,13 +260,11 @@ void CDVSBasePPage::AttachControls()
AFX_MANAGE_STATE(AfxGetStaticModuleState());
POSITION pos = m_controls.GetStartPosition();
- while(pos)
- {
+ while(pos) {
UINT id;
CWnd* pControl;
m_controls.GetNextAssoc(pos, id, pControl);
- if(pControl)
- {
+ if(pControl) {
BOOL fRet = pControl->Attach(GetDlgItem(m_Dlg, id));
ASSERT(fRet);
}
@@ -268,17 +275,20 @@ void CDVSBasePPage::AttachControls()
void CDVSBasePPage::DetachControls()
{
- if(!m_fAttached) return;
+ if(!m_fAttached) {
+ return;
+ }
AFX_MANAGE_STATE(AfxGetStaticModuleState());
POSITION pos = m_controls.GetStartPosition();
- while(pos)
- {
+ while(pos) {
UINT id;
CWnd* pControl;
m_controls.GetNextAssoc(pos, id, pControl);
- if(pControl) pControl->Detach();
+ if(pControl) {
+ pControl->Detach();
+ }
}
m_fAttached = false;
@@ -313,9 +323,10 @@ CDVSMainPPage::~CDVSMainPPage()
void CDVSMainPPage::FreeLangs()
{
- if(m_nLangs > 0 && m_ppLangs)
- {
- for(ptrdiff_t i = 0; i < m_nLangs; i++) CoTaskMemFree(m_ppLangs[i]);
+ if(m_nLangs > 0 && m_ppLangs) {
+ for(ptrdiff_t i = 0; i < m_nLangs; i++) {
+ CoTaskMemFree(m_ppLangs[i]);
+ }
CoTaskMemFree(m_ppLangs);
m_nLangs = 0;
m_ppLangs = NULL;
@@ -330,52 +341,45 @@ void CDVSMainPPage::AllocLangs(int nLangs)
bool CDVSMainPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case BN_CLICKED:
- {
- if(LOWORD(wParam) == IDC_OPEN)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CFileDialog fd(TRUE, NULL, NULL,
- OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,
- _T(".idx .smi .sub .srt .psb .ssa .ass .usf .ssf|*.idx;*.smi;*.sub;*.srt;*.psb;*.ssa;*.ass;*.usf;*.ssf|")
- _T("All files (*.*)|*.*||"),
- CDialog::FromHandle(m_Dlg), 0);
-
- if(fd.DoModal() == IDOK)
- {
- m_fnedit.SetWindowText(fd.GetPathName());
- }
-
- return(true);
- }
- else if(LOWORD(wParam) == IDC_FONT)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- CStyleEditorDialog dlg(_T("Default"), &m_defStyle, CWnd::FromHandle(m_hwnd));
-
- if(dlg.DoModal() == IDOK)
- {
- m_defStyle = dlg.m_stss;
- CString str = m_defStyle.fontName;
- if(str.GetLength() > 18) str = str.Left(16).TrimRight() + _T("...");
- m_font.SetWindowText(str);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case BN_CLICKED: {
+ if(LOWORD(wParam) == IDC_OPEN) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+ CFileDialog fd(TRUE, NULL, NULL,
+ OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,
+ _T(".idx .smi .sub .srt .psb .ssa .ass .usf .ssf|*.idx;*.smi;*.sub;*.srt;*.psb;*.ssa;*.ass;*.usf;*.ssf|")
+ _T("All files (*.*)|*.*||"),
+ CDialog::FromHandle(m_Dlg), 0);
+
+ if(fd.DoModal() == IDOK) {
+ m_fnedit.SetWindowText(fd.GetPathName());
+ }
+
+ return(true);
+ } else if(LOWORD(wParam) == IDC_FONT) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+ CStyleEditorDialog dlg(_T("Default"), &m_defStyle, CWnd::FromHandle(m_hwnd));
+
+ if(dlg.DoModal() == IDOK) {
+ m_defStyle = dlg.m_stss;
+ CString str = m_defStyle.fontName;
+ if(str.GetLength() > 18) {
+ str = str.Left(16).TrimRight() + _T("...");
+ }
+ m_font.SetWindowText(str);
+ }
+
+ return(true);
+ }
}
-
- return(true);
+ break;
}
}
break;
- }
- }
- break;
}
return(false);
@@ -383,14 +387,14 @@ bool CDVSMainPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSMainPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
- if(m_pDirectVobSub->put_FileName(m_fn) == S_OK)
- {
+ if(fSave) {
+ if(m_pDirectVobSub->put_FileName(m_fn) == S_OK) {
int nLangs;
m_pDirectVobSub->get_LanguageCount(&nLangs);
AllocLangs(nLangs);
- for(ptrdiff_t i = 0; i < m_nLangs; i++) m_pDirectVobSub->get_LanguageName(i, &m_ppLangs[i]);
+ for(ptrdiff_t i = 0; i < m_nLangs; i++) {
+ m_pDirectVobSub->get_LanguageName(i, &m_ppLangs[i]);
+ }
m_pDirectVobSub->get_SelectedLanguage(&m_iSelectedLanguage);
}
@@ -399,14 +403,14 @@ void CDVSMainPPage::UpdateObjectData(bool fSave)
m_pDirectVobSub->put_VobSubSettings(true, m_fOnlyShowForcedVobSubs, false);
m_pDirectVobSub->put_TextSettings(&m_defStyle);
m_pDirectVobSub->put_AspectRatioSettings(&m_ePARCompensationType);
- }
- else
- {
+ } else {
m_pDirectVobSub->get_FileName(m_fn);
int nLangs;
m_pDirectVobSub->get_LanguageCount(&nLangs);
AllocLangs(nLangs);
- for(ptrdiff_t i = 0; i < m_nLangs; i++) m_pDirectVobSub->get_LanguageName(i, &m_ppLangs[i]);
+ for(ptrdiff_t i = 0; i < m_nLangs; i++) {
+ m_pDirectVobSub->get_LanguageName(i, &m_ppLangs[i]);
+ }
m_pDirectVobSub->get_SelectedLanguage(&m_iSelectedLanguage);
m_pDirectVobSub->get_Placement(&m_fOverridePlacement, &m_PlacementXperc, &m_PlacementYperc);
m_pDirectVobSub->get_VobSubSettings(NULL, &m_fOnlyShowForcedVobSubs, NULL);
@@ -417,8 +421,7 @@ void CDVSMainPPage::UpdateObjectData(bool fSave)
void CDVSMainPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
CString fn;
m_fnedit.GetWindowText(fn);
#ifdef UNICODE
@@ -431,13 +434,12 @@ void CDVSMainPPage::UpdateControlData(bool fSave)
m_PlacementXperc = m_subposx.GetPos();
m_PlacementYperc = m_subposy.GetPos();
m_fOnlyShowForcedVobSubs = !!m_forcedsubs.GetCheck();
- if (m_PARCombo.GetCurSel() != CB_ERR)
+ if (m_PARCombo.GetCurSel() != CB_ERR) {
m_ePARCompensationType = static_cast<CSimpleTextSubtitle::EPARCompensationType>(m_PARCombo.GetItemData(m_PARCombo.GetCurSel()));
- else
+ } else {
m_ePARCompensationType = CSimpleTextSubtitle::EPCTDisabled;
- }
- else
- {
+ }
+ } else {
m_fnedit.SetWindowText(CString(m_fn));
m_oplacement.SetCheck(m_fOverridePlacement);
m_subposx.SetRange(-20, 120);
@@ -450,29 +452,35 @@ void CDVSMainPPage::UpdateControlData(bool fSave)
m_forcedsubs.SetCheck(m_fOnlyShowForcedVobSubs);
m_langs.ResetContent();
m_langs.EnableWindow(m_nLangs > 0);
- for(ptrdiff_t i = 0; i < m_nLangs; i++) m_langs.AddString(CString(m_ppLangs[i]));
+ for(ptrdiff_t i = 0; i < m_nLangs; i++) {
+ m_langs.AddString(CString(m_ppLangs[i]));
+ }
m_langs.SetCurSel(m_iSelectedLanguage);
m_PARCombo.ResetContent();
m_PARCombo.InsertString(0, ResStr(IDS_RT_PAR_DISABLED));
m_PARCombo.SetItemData(0, CSimpleTextSubtitle::EPCTDisabled);
- if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTDisabled)
+ if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTDisabled) {
m_PARCombo.SetCurSel(0);
+ }
m_PARCombo.InsertString(1, ResStr(IDS_RT_PAR_DOWNSCALE));
m_PARCombo.SetItemData(1, CSimpleTextSubtitle::EPCTDownscale);
- if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTDownscale)
+ if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTDownscale) {
m_PARCombo.SetCurSel(1);
+ }
m_PARCombo.InsertString(2, ResStr(IDS_RT_PAR_UPSCALE));
m_PARCombo.SetItemData(2, CSimpleTextSubtitle::EPCTUpscale);
- if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTUpscale)
+ if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTUpscale) {
m_PARCombo.SetCurSel(2);
+ }
m_PARCombo.InsertString(3, ResStr(IDS_RT_PAR_ACCURATE_SIZE));
m_PARCombo.SetItemData(3, CSimpleTextSubtitle::EPCTAccurateSize);
- if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTAccurateSize)
+ if (m_ePARCompensationType == CSimpleTextSubtitle::EPCTAccurateSize) {
m_PARCombo.SetCurSel(3);
+ }
}
}
@@ -494,34 +502,27 @@ CDVSGeneralPPage::CDVSGeneralPPage(LPUNKNOWN pUnk, HRESULT* phr) :
bool CDVSGeneralPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case CBN_SELCHANGE:
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- if(LOWORD(wParam) == IDC_RESX2COMBO)
- {
- m_resx2w.EnableWindow(m_resx2.GetCurSel() == 2);
- m_resx2h.EnableWindow(m_resx2.GetCurSel() == 2);
- return(true);
- }
- else if(LOWORD(wParam) == IDC_LOADCOMBO)
- {
- m_extload.EnableWindow(m_load.GetCurSel() == 1);
- m_webload.EnableWindow(m_load.GetCurSel() == 1);
- m_embload.EnableWindow(m_load.GetCurSel() == 1);
- return(true);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case CBN_SELCHANGE: {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+ if(LOWORD(wParam) == IDC_RESX2COMBO) {
+ m_resx2w.EnableWindow(m_resx2.GetCurSel() == 2);
+ m_resx2h.EnableWindow(m_resx2.GetCurSel() == 2);
+ return(true);
+ } else if(LOWORD(wParam) == IDC_LOADCOMBO) {
+ m_extload.EnableWindow(m_load.GetCurSel() == 1);
+ m_webload.EnableWindow(m_load.GetCurSel() == 1);
+ m_embload.EnableWindow(m_load.GetCurSel() == 1);
+ return(true);
+ }
+ }
+ break;
}
}
break;
- }
- }
- break;
}
return(false);
@@ -529,13 +530,10 @@ bool CDVSGeneralPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSGeneralPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_pDirectVobSub->put_ExtendPicture(m_HorExt, m_VerExt, m_ResX2, m_ResX2minw, m_ResX2minh);
m_pDirectVobSub->put_LoadSettings(m_LoadLevel, m_fExternalLoad, m_fWebLoad, m_fEmbeddedLoad);
- }
- else
- {
+ } else {
m_pDirectVobSub->get_ExtendPicture(&m_HorExt, &m_VerExt, &m_ResX2, &m_ResX2minw, &m_ResX2minh);
m_pDirectVobSub->get_LoadSettings(&m_LoadLevel, &m_fExternalLoad, &m_fWebLoad, &m_fEmbeddedLoad);
}
@@ -543,20 +541,23 @@ void CDVSGeneralPPage::UpdateObjectData(bool fSave)
void CDVSGeneralPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
- if(m_verext.GetCurSel() >= 0) m_VerExt = m_verext.GetItemData(m_verext.GetCurSel());
+ if(fSave) {
+ if(m_verext.GetCurSel() >= 0) {
+ m_VerExt = m_verext.GetItemData(m_verext.GetCurSel());
+ }
m_HorExt = !!m_mod32fix.GetCheck();
- if(m_resx2.GetCurSel() >= 0) m_ResX2 = m_resx2.GetItemData(m_resx2.GetCurSel());
+ if(m_resx2.GetCurSel() >= 0) {
+ m_ResX2 = m_resx2.GetItemData(m_resx2.GetCurSel());
+ }
m_ResX2minw = m_resx2w.GetPos();
m_ResX2minh = m_resx2h.GetPos();
- if(m_load.GetCurSel() >= 0) m_LoadLevel = m_load.GetItemData(m_load.GetCurSel());
+ if(m_load.GetCurSel() >= 0) {
+ m_LoadLevel = m_load.GetItemData(m_load.GetCurSel());
+ }
m_fExternalLoad = !!m_extload.GetCheck();
m_fWebLoad = !!m_webload.GetCheck();
m_fEmbeddedLoad = !!m_embload.GetCheck();
- }
- else
- {
+ } else {
m_verext.ResetContent();
m_verext.AddString(ResStr(IDS_ORGHEIGHT));
m_verext.SetItemData(0, 0);
@@ -622,25 +623,20 @@ CDVSMiscPPage::CDVSMiscPPage(LPUNKNOWN pUnk, HRESULT* phr) :
bool CDVSMiscPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case BN_CLICKED:
- {
- if(LOWORD(wParam) == IDC_INSTANTUPDATE)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_INSTANTUPDATE), !!m_instupd.GetCheck());
- return(true);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case BN_CLICKED: {
+ if(LOWORD(wParam) == IDC_INSTANTUPDATE) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_INSTANTUPDATE), !!m_instupd.GetCheck());
+ return(true);
+ }
+ }
+ break;
}
}
break;
- }
- }
- break;
}
return(false);
@@ -648,17 +644,14 @@ bool CDVSMiscPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSMiscPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_pDirectVobSub->put_Flip(m_fFlipPicture, m_fFlipSubtitles);
m_pDirectVobSub->put_HideSubtitles(m_fHideSubtitles);
m_pDirectVobSub->put_OSD(m_fOSD);
m_pDirectVobSub->put_PreBuffering(m_fDoPreBuffering);
m_pDirectVobSub->put_SubtitleReloader(m_fReloaderDisabled);
m_pDirectVobSub->put_SaveFullPath(m_fSaveFullPath);
- }
- else
- {
+ } else {
m_pDirectVobSub->get_Flip(&m_fFlipPicture, &m_fFlipSubtitles);
m_pDirectVobSub->get_HideSubtitles(&m_fHideSubtitles);
m_pDirectVobSub->get_OSD(&m_fOSD);
@@ -670,8 +663,7 @@ void CDVSMiscPPage::UpdateObjectData(bool fSave)
void CDVSMiscPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_fFlipPicture = !!m_flippic.GetCheck();
m_fFlipSubtitles = !!m_flipsub.GetCheck();
m_fHideSubtitles = !!m_hidesub.GetCheck();
@@ -679,9 +671,7 @@ void CDVSMiscPPage::UpdateControlData(bool fSave)
m_fDoPreBuffering = !!m_prebuff.GetCheck();
m_fOSD = !!m_showosd.GetCheck();
m_fReloaderDisabled = !m_autoreload.GetCheck();
- }
- else
- {
+ } else {
m_flippic.SetCheck(m_fFlipPicture);
m_flipsub.SetCheck(m_fFlipSubtitles);
m_hidesub.SetCheck(m_fHideSubtitles);
@@ -707,25 +697,20 @@ CDVSTimingPPage::CDVSTimingPPage(LPUNKNOWN pUnk, HRESULT* phr) :
bool CDVSTimingPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case BN_CLICKED:
- {
- if(LOWORD(wParam) == IDC_MODFPS)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- m_fps.EnableWindow(!!m_modfps.GetCheck());
- return(true);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case BN_CLICKED: {
+ if(LOWORD(wParam) == IDC_MODFPS) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ m_fps.EnableWindow(!!m_modfps.GetCheck());
+ return(true);
+ }
+ }
+ break;
}
}
break;
- }
- }
- break;
}
return(false);
@@ -733,13 +718,10 @@ bool CDVSTimingPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSTimingPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_pDirectVobSub->put_SubtitleTiming(m_SubtitleDelay, m_SubtitleSpeedMul, m_SubtitleSpeedDiv);
m_pDirectVobSub->put_MediaFPS(m_fMediaFPSEnabled, m_MediaFPS);
- }
- else
- {
+ } else {
m_pDirectVobSub->get_SubtitleTiming(&m_SubtitleDelay, &m_SubtitleSpeedMul, &m_SubtitleSpeedDiv);
m_pDirectVobSub->get_MediaFPS(&m_fMediaFPSEnabled, &m_MediaFPS);
}
@@ -747,13 +729,14 @@ void CDVSTimingPPage::UpdateObjectData(bool fSave)
void CDVSTimingPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_fMediaFPSEnabled = !!m_modfps.GetCheck();
CString fpsstr;
m_fps.GetWindowText(fpsstr);
float fps;
- if(_stscanf(fpsstr, _T("%f"), &fps) == 1) m_MediaFPS = fps;
+ if(_stscanf(fpsstr, _T("%f"), &fps) == 1) {
+ m_MediaFPS = fps;
+ }
#if _MFC_VER >= 0x0700
m_SubtitleDelay = m_subdelay.GetPos32();
m_SubtitleSpeedMul = m_subspeedmul.GetPos32();
@@ -763,9 +746,7 @@ void CDVSTimingPPage::UpdateControlData(bool fSave)
m_SubtitleSpeedMul = SendMessage(GetDlgItem(m_Dlg, IDC_SPIN6), UDM_GETPOS32, 0, 0);
m_SubtitleSpeedDiv = SendMessage(GetDlgItem(m_Dlg, IDC_SPIN9), UDM_GETPOS32, 0, 0);
#endif
- }
- else
- {
+ } else {
m_modfps.SetCheck(m_fMediaFPSEnabled);
CString fpsstr;
fpsstr.Format(_T("%.4f"), m_MediaFPS);
@@ -796,40 +777,32 @@ CDVSAboutPPage::CDVSAboutPPage(LPUNKNOWN lpunk, HRESULT* phr) :
bool CDVSAboutPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_INITDIALOG:
- {
+ switch(uMsg) {
+ case WM_INITDIALOG: {
#ifdef _VSMOD
- SetDlgItemTextA( m_Dlg, IDC_VERSION, "DirectVobSub 2.40."MAKE_STR(MPC_VERSION_REV)"."MAKE_STR(MPC_VERSION_PATCH)" "MAKE_STR(VERSION_ARCH)", MOD\nCopyright 2001-2010 MPC-HC & VSFilterMod Teams" );
+ SetDlgItemTextA( m_Dlg, IDC_VERSION, "DirectVobSub 2.40."MAKE_STR(MPC_VERSION_REV)"."MAKE_STR(MPC_VERSION_PATCH)" "MAKE_STR(VERSION_ARCH)", MOD\nCopyright 2001-2010 MPC-HC & VSFilterMod Teams" );
#else
- SetDlgItemTextA( m_Dlg, IDC_VERSION, "DirectVobSub 2.40."MAKE_STR(MPC_VERSION_REV)"."MAKE_STR(MPC_VERSION_PATCH)" "MAKE_STR(VERSION_ARCH)"\nCopyright 2001-2010 MPC-HC Team" );
+ SetDlgItemTextA( m_Dlg, IDC_VERSION, "DirectVobSub 2.40."MAKE_STR(MPC_VERSION_REV)"."MAKE_STR(MPC_VERSION_PATCH)" "MAKE_STR(VERSION_ARCH)"\nCopyright 2001-2010 MPC-HC Team" );
#endif
- }
- break;
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case BN_CLICKED:
- {
- if(LOWORD(wParam) == IDC_HOMEPAGEBTN)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- ShellExecute(m_Dlg, _T("open"), ResStr(IDS_URL_HOMEPAGE), NULL, NULL, SW_SHOWNORMAL);
- return(true);
- }
- else if(LOWORD(wParam) == IDC_BUGREPORTBTN)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- ShellExecute(m_Dlg, _T("open"), ResStr(IDS_URL_EMAIL), NULL, NULL, SW_SHOWNORMAL);
- return(true);
- }
}
break;
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case BN_CLICKED: {
+ if(LOWORD(wParam) == IDC_HOMEPAGEBTN) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ ShellExecute(m_Dlg, _T("open"), ResStr(IDS_URL_HOMEPAGE), NULL, NULL, SW_SHOWNORMAL);
+ return(true);
+ } else if(LOWORD(wParam) == IDC_BUGREPORTBTN) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ ShellExecute(m_Dlg, _T("open"), ResStr(IDS_URL_EMAIL), NULL, NULL, SW_SHOWNORMAL);
+ return(true);
+ }
+ }
+ break;
+ }
}
- }
- break;
+ break;
}
return(false);
@@ -848,28 +821,23 @@ CDVSZoomPPage::CDVSZoomPPage(LPUNKNOWN pUnk, HRESULT* phr) :
bool CDVSZoomPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case EN_CHANGE:
- {
- if(LOWORD(wParam) == IDC_EDIT1 || LOWORD(wParam) == IDC_EDIT2
- || LOWORD(wParam) == IDC_EDIT7 || LOWORD(wParam) == IDC_EDIT8)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
- UpdateControlData(true);
- UpdateObjectData(true);
- return(true);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case EN_CHANGE: {
+ if(LOWORD(wParam) == IDC_EDIT1 || LOWORD(wParam) == IDC_EDIT2
+ || LOWORD(wParam) == IDC_EDIT7 || LOWORD(wParam) == IDC_EDIT8) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ UpdateControlData(true);
+ UpdateObjectData(true);
+ return(true);
+ }
+ }
+
+ break;
}
}
-
break;
- }
- }
- break;
}
return(false);
@@ -877,15 +845,12 @@ bool CDVSZoomPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSZoomPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_rect.left = 1.0f * (short)m_posx.GetPos() / 100;
m_rect.top = 1.0f * (short)m_posy.GetPos() / 100;
m_rect.right = m_rect.left + 1.0f * (short)m_scalex.GetPos() / 100;
m_rect.bottom = m_rect.top + 1.0f * (short)m_scaley.GetPos() / 100;
- }
- else
- {
+ } else {
m_posx.SetRange(-100, 100);
m_posx.SetPos((int)(m_rect.left*100));
m_posy.SetRange(-100, 100);
@@ -899,12 +864,9 @@ void CDVSZoomPPage::UpdateControlData(bool fSave)
void CDVSZoomPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_pDirectVobSub->put_ZoomRect(&m_rect);
- }
- else
- {
+ } else {
m_pDirectVobSub->get_ZoomRect(&m_rect);
}
}
@@ -925,77 +887,68 @@ CDVSColorPPage::CDVSColorPPage(LPUNKNOWN pUnk, HRESULT* phr) :
bool CDVSColorPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case LBN_DBLCLK:
- if((HWND)lParam == m_dynchglist.m_hWnd)
- {
- int old = -1;
- m_pDirectVobSub->get_ColorFormat(&old);
- if(FAILED(m_pDirectVobSub->put_ColorFormat(m_dynchglist.GetCurSel())))
- m_dynchglist.SetCurSel(old);
-
- return(true);
- }
- break;
-
- case BN_CLICKED:
- {
- switch(LOWORD(wParam))
- {
- case IDC_COLORCHANGE:
- {
- int old = -1;
- m_pDirectVobSub->get_ColorFormat(&old);
- if(FAILED(m_pDirectVobSub->put_ColorFormat(m_dynchglist.GetCurSel())))
- m_dynchglist.SetCurSel(old);
-
- return(true);
- }
- case IDC_COLORUP:
- {
- int sel = m_preflist.GetCurSel();
- if(sel > 0)
- {
- CString str;
- m_preflist.GetText(sel, str);
- int iPos = (int)m_preflist.GetItemData(sel);
- m_preflist.DeleteString(sel);
- sel--;
- m_preflist.InsertString(sel, str);
- m_preflist.SetItemData(sel, iPos);
- m_preflist.SetCurSel(sel);
- }
-
- return(true);
- }
- case IDC_COLORDOWN:
- {
- int sel = m_preflist.GetCurSel();
- if(sel >= 0 && sel < m_preflist.GetCount()-1)
- {
- CString str;
- m_preflist.GetText(sel, str);
- int iPos = (int)m_preflist.GetItemData(sel);
- m_preflist.DeleteString(sel);
- sel++;
- m_preflist.InsertString(sel, str);
- m_preflist.SetItemData(sel, iPos);
- m_preflist.SetCurSel(sel);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case LBN_DBLCLK:
+ if((HWND)lParam == m_dynchglist.m_hWnd) {
+ int old = -1;
+ m_pDirectVobSub->get_ColorFormat(&old);
+ if(FAILED(m_pDirectVobSub->put_ColorFormat(m_dynchglist.GetCurSel()))) {
+ m_dynchglist.SetCurSel(old);
+ }
+
+ return(true);
+ }
+ break;
+
+ case BN_CLICKED: {
+ switch(LOWORD(wParam)) {
+ case IDC_COLORCHANGE: {
+ int old = -1;
+ m_pDirectVobSub->get_ColorFormat(&old);
+ if(FAILED(m_pDirectVobSub->put_ColorFormat(m_dynchglist.GetCurSel()))) {
+ m_dynchglist.SetCurSel(old);
+ }
+
+ return(true);
+ }
+ case IDC_COLORUP: {
+ int sel = m_preflist.GetCurSel();
+ if(sel > 0) {
+ CString str;
+ m_preflist.GetText(sel, str);
+ int iPos = (int)m_preflist.GetItemData(sel);
+ m_preflist.DeleteString(sel);
+ sel--;
+ m_preflist.InsertString(sel, str);
+ m_preflist.SetItemData(sel, iPos);
+ m_preflist.SetCurSel(sel);
+ }
+
+ return(true);
+ }
+ case IDC_COLORDOWN: {
+ int sel = m_preflist.GetCurSel();
+ if(sel >= 0 && sel < m_preflist.GetCount()-1) {
+ CString str;
+ m_preflist.GetText(sel, str);
+ int iPos = (int)m_preflist.GetItemData(sel);
+ m_preflist.DeleteString(sel);
+ sel++;
+ m_preflist.InsertString(sel, str);
+ m_preflist.SetItemData(sel, iPos);
+ m_preflist.SetCurSel(sel);
+ }
+
+ return(true);
+ }
+ }
}
-
- return(true);
- }
+ break;
}
}
break;
- }
- }
- break;
}
return(false);
@@ -1003,35 +956,30 @@ bool CDVSColorPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSColorPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
- }
- else
- {
+ if(fSave) {
+ } else {
}
}
void CDVSColorPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
- if((UINT)m_preflist.GetCount() == VIHSIZE)
- {
+ if(fSave) {
+ if((UINT)m_preflist.GetCount() == VIHSIZE) {
BYTE* pData = new BYTE[VIHSIZE];
- for(ptrdiff_t i = 0; i < m_preflist.GetCount(); i++)
+ for(ptrdiff_t i = 0; i < m_preflist.GetCount(); i++) {
pData[i] = (BYTE)m_preflist.GetItemData(i);
+ }
theApp.WriteProfileBinary(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_COLORFORMATS), pData, VIHSIZE);
delete [] pData;
+ } else {
+ ASSERT(0);
}
- else ASSERT(0);
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_FORCERGB), !!m_forcergb.GetCheck());
- }
- else
- {
+ } else {
m_preflist.ResetContent();
m_dynchglist.ResetContent();
@@ -1039,19 +987,20 @@ void CDVSColorPPage::UpdateControlData(bool fSave)
UINT nSize;
if(!theApp.GetProfileBinary(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_COLORFORMATS), &pData, &nSize)
- || !pData || nSize != VIHSIZE)
- {
- if(pData) delete [] pData, pData = NULL;
+ || !pData || nSize != VIHSIZE) {
+ if(pData) {
+ delete [] pData, pData = NULL;
+ }
nSize = VIHSIZE;
pData = new BYTE[VIHSIZE];
- for(ptrdiff_t i = 0; i < VIHSIZE; i++) pData[i] = i;
+ for(ptrdiff_t i = 0; i < VIHSIZE; i++) {
+ pData[i] = i;
+ }
}
- if(pData)
- {
- for(ptrdiff_t i = 0; i < (int)nSize; i++)
- {
+ if(pData) {
+ for(ptrdiff_t i = 0; i < (int)nSize; i++) {
m_dynchglist.AddString(VIH2String(pData[i]));
m_dynchglist.SetItemData(i, pData[i]);
m_preflist.AddString(VIH2String(pData[i]));
@@ -1085,98 +1034,85 @@ CDVSPathsPPage::CDVSPathsPPage(LPUNKNOWN pUnk, HRESULT* phr) :
bool CDVSPathsPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uMsg)
- {
- case WM_COMMAND:
- {
- switch(HIWORD(wParam))
- {
- case LBN_SELCHANGE:
- if((HWND)lParam == m_pathlist.m_hWnd)
- {
- int i = m_pathlist.GetCurSel();
- m_remove.EnableWindow(i >= 3 ? TRUE : FALSE);
- if(i >= 0)
- {
- CString path;
- m_pathlist.GetText(i, path);
- m_path.SetWindowText(path);
- }
- return(true);
- }
- break;
-
- case LBN_SELCANCEL:
- if((HWND)lParam == m_pathlist.m_hWnd)
- {
- m_remove.EnableWindow(FALSE);
- return(true);
- }
- break;
-
- case BN_CLICKED:
- {
- switch(LOWORD(wParam))
- {
- case IDC_BROWSE:
- {
- TCHAR pathbuff[MAX_PATH];
-
- BROWSEINFO bi;
- bi.hwndOwner = m_Dlg;
- bi.pidlRoot = NULL;
- bi.pszDisplayName = pathbuff;
- bi.lpszTitle = _T("");
- bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_VALIDATE | BIF_USENEWUI;
- bi.lpfn = NULL;
- bi.lParam = 0;
- bi.iImage = 0;
-
- LPITEMIDLIST iil = SHBrowseForFolder(&bi);
- if(iil)
- {
- SHGetPathFromIDList(iil, pathbuff);
- m_path.SetWindowText(pathbuff);
- }
-
- return(true);
- }
- break;
-
- case IDC_REMOVE:
- {
- int i = m_pathlist.GetCurSel();
- if(i >= 0)
- {
- m_pathlist.DeleteString(i);
- i = min(i, m_pathlist.GetCount()-1);
- if(i >= 0 && m_pathlist.GetCount() > 0)
- {
- m_pathlist.SetCurSel(i);
+ switch(uMsg) {
+ case WM_COMMAND: {
+ switch(HIWORD(wParam)) {
+ case LBN_SELCHANGE:
+ if((HWND)lParam == m_pathlist.m_hWnd) {
+ int i = m_pathlist.GetCurSel();
m_remove.EnableWindow(i >= 3 ? TRUE : FALSE);
+ if(i >= 0) {
+ CString path;
+ m_pathlist.GetText(i, path);
+ m_path.SetWindowText(path);
+ }
+ return(true);
}
- }
-
- return(true);
- }
- break;
+ break;
- case IDC_ADD:
- {
- CString path;
- m_path.GetWindowText(path);
- if(!path.IsEmpty() && m_pathlist.FindString(-1, path) < 0)
- m_pathlist.AddString(path);
-
- return(true);
- }
- break;
+ case LBN_SELCANCEL:
+ if((HWND)lParam == m_pathlist.m_hWnd) {
+ m_remove.EnableWindow(FALSE);
+ return(true);
+ }
+ break;
+
+ case BN_CLICKED: {
+ switch(LOWORD(wParam)) {
+ case IDC_BROWSE: {
+ TCHAR pathbuff[MAX_PATH];
+
+ BROWSEINFO bi;
+ bi.hwndOwner = m_Dlg;
+ bi.pidlRoot = NULL;
+ bi.pszDisplayName = pathbuff;
+ bi.lpszTitle = _T("");
+ bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_VALIDATE | BIF_USENEWUI;
+ bi.lpfn = NULL;
+ bi.lParam = 0;
+ bi.iImage = 0;
+
+ LPITEMIDLIST iil = SHBrowseForFolder(&bi);
+ if(iil) {
+ SHGetPathFromIDList(iil, pathbuff);
+ m_path.SetWindowText(pathbuff);
+ }
+
+ return(true);
+ }
+ break;
+
+ case IDC_REMOVE: {
+ int i = m_pathlist.GetCurSel();
+ if(i >= 0) {
+ m_pathlist.DeleteString(i);
+ i = min(i, m_pathlist.GetCount()-1);
+ if(i >= 0 && m_pathlist.GetCount() > 0) {
+ m_pathlist.SetCurSel(i);
+ m_remove.EnableWindow(i >= 3 ? TRUE : FALSE);
+ }
+ }
+
+ return(true);
+ }
+ break;
+
+ case IDC_ADD: {
+ CString path;
+ m_path.GetWindowText(path);
+ if(!path.IsEmpty() && m_pathlist.FindString(-1, path) < 0) {
+ m_pathlist.AddString(path);
+ }
+
+ return(true);
+ }
+ break;
+ }
+ }
+ break;
}
}
break;
- }
- }
- break;
}
return(false);
@@ -1184,55 +1120,48 @@ bool CDVSPathsPPage::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
void CDVSPathsPPage::UpdateObjectData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
CString chk(_T("123456789")), path, tmp;
int i = 0;
- do
- {
+ do {
tmp.Format(ResStr(IDS_RP_PATH), i++);
path = theApp.GetProfileString(ResStr(IDS_R_DEFTEXTPATHES), tmp, chk);
- if(path != chk) theApp.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES), tmp, _T(""));
- }
- while(path != chk);
+ if(path != chk) {
+ theApp.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES), tmp, _T(""));
+ }
+ } while(path != chk);
- for(i = 0; i < m_paths.GetSize(); i++)
- {
+ for(i = 0; i < m_paths.GetSize(); i++) {
tmp.Format(ResStr(IDS_RP_PATH), i);
theApp.WriteProfileString(ResStr(IDS_R_DEFTEXTPATHES), tmp, m_paths[i]);
}
- }
- else
- {
+ } else {
CString chk(_T("123456789")), path, tmp;
int i = 0;
- do
- {
- if(!path.IsEmpty()) m_paths.Add(path);
+ do {
+ if(!path.IsEmpty()) {
+ m_paths.Add(path);
+ }
tmp.Format(ResStr(IDS_RP_PATH), i++);
path = theApp.GetProfileString(ResStr(IDS_R_DEFTEXTPATHES), tmp, chk);
- }
- while(path != chk);
+ } while(path != chk);
}
}
void CDVSPathsPPage::UpdateControlData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
m_paths.RemoveAll();
- for(ptrdiff_t i = 0; i < m_pathlist.GetCount(); i++)
- {
+ for(ptrdiff_t i = 0; i < m_pathlist.GetCount(); i++) {
CString path;
m_pathlist.GetText(i, path);
m_paths.Add(path);
}
- }
- else
- {
+ } else {
m_pathlist.ResetContent();
- for(ptrdiff_t i = 0; i < m_paths.GetSize(); i++)
+ for(ptrdiff_t i = 0; i < m_paths.GetSize(); i++) {
m_pathlist.AddString(m_paths[i]);
+ }
m_remove.EnableWindow(FALSE);
m_add.EnableWindow(TRUE);
diff --git a/src/filters/transform/VSFilter/IDirectVobSub.h b/src/filters/transform/VSFilter/IDirectVobSub.h
index b917f87c3..37fefc6d1 100644
--- a/src/filters/transform/VSFilter/IDirectVobSub.h
+++ b/src/filters/transform/VSFilter/IDirectVobSub.h
@@ -253,24 +253,21 @@ IDirectVobSub :
interface __declspec(uuid("FE6EC6A0-21CA-4970-9EF0-B296F7F38AF0"))
ISubClock :
- public IUnknown
- {
+ public IUnknown {
STDMETHOD(SetTime)(REFERENCE_TIME rt) PURE;
STDMETHOD_(REFERENCE_TIME, GetTime)() PURE;
};
interface __declspec(uuid("0665B760-FBC1-46C3-A35F-E471527C96A4"))
ISubClock2 :
- public ISubClock
- {
+ public ISubClock {
STDMETHOD(SetAvgTimePerFrame)(REFERENCE_TIME rt) PURE;
STDMETHOD(GetAvgTimePerFrame)(REFERENCE_TIME* prt) PURE; // return S_OK only if *prt was set and is valid
};
interface __declspec(uuid("AB52FC9C-2415-4dca-BC1C-8DCC2EAE8150"))
IDirectVobSub2 :
- public IDirectVobSub
- {
+ public IDirectVobSub {
STDMETHOD(AdviseSubClock) (THIS_
ISubClock* pSubClock
) PURE;
diff --git a/src/filters/transform/VSFilter/Scale2x.cpp b/src/filters/transform/VSFilter/Scale2x.cpp
index 71cf01f24..f05773520 100644
--- a/src/filters/transform/VSFilter/Scale2x.cpp
+++ b/src/filters/transform/VSFilter/Scale2x.cpp
@@ -37,13 +37,11 @@ void Scale2x_YV( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
BYTE* s2;
BYTE* d1;
- for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) // TODO: replace this mess with mmx code
- {
+ for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) { // TODO: replace this mess with mmx code
BYTE* stmp = s1 + spitch;
BYTE* dtmp = d1 + dpitch;
- for(BYTE* s3 = s1 + (w-1); s1 < s3; s1 += 1, d1 += 2)
- {
+ for(BYTE* s3 = s1 + (w-1); s1 < s3; s1 += 1, d1 += 2) {
d1[0] = s1[0];
d1[1] = (s1[0]+s1[1])>>1;
}
@@ -70,8 +68,7 @@ void Scale2x_YUY2_SSE2( BYTE* s1, BYTE* d1, int w )
__m128i mm4 = _mm_cvtsi64_si128(__0x00ff00ff00ff00ff);
__m128i mm5 = _mm_cvtsi64_si128(__0x00000000ffffffff);
__m128i mm6 = _mm_cvtsi64_si128(__0xffffffff00000000);
- for(BYTE* s3 = s1 + ((w>>1)-1)*4; s1 < s3; s1 += 4, d1 += 8)
- {
+ for(BYTE* s3 = s1 + ((w>>1)-1)*4; s1 < s3; s1 += 4, d1 += 8) {
__m128i mm0 = _mm_cvtsi64_si128(*(size_t*)s1); //movq mm0, [esi]
__m128i mm2 = _mm_move_epi64(mm0); //movq mm2, mm0
mm0 = _mm_and_si128(mm0, mm4); //pand mm0, mm4 // mm0 = 00y400y300y200y1
@@ -112,8 +109,7 @@ void Scale2x_YUY2_MMX( BYTE* s1, BYTE* d1, int w )
unsigned __int64 __0x00000000ffffffff = 0x00000000ffffffff;
unsigned __int64 __0x00ff00ff00ff00ff = 0x00ff00ff00ff00ff;
- __asm
- {
+ __asm {
mov esi, s1
mov edi, d1
@@ -124,7 +120,7 @@ void Scale2x_YUY2_MMX( BYTE* s1, BYTE* d1, int w )
movq mm4, __0x00ff00ff00ff00ff
movq mm5, __0x00000000ffffffff
movq mm6, __0xffffffff00000000
-row_loop1:
+ row_loop1:
movq mm0, [esi]
movq mm2, mm0
@@ -185,8 +181,7 @@ row_loop1:
void Scale2x_YUY2_c( BYTE* s1, BYTE* d1, int w )
{
- for(BYTE* s3 = s1 + ((w>>1)-1)*4; s1 < s3; s1 += 4, d1 += 8)
- {
+ for(BYTE* s3 = s1 + ((w>>1)-1)*4; s1 < s3; s1 += 4, d1 += 8) {
d1[0] = s1[0];
d1[1] = s1[1];
d1[2] = (s1[0]+s1[2])>>1;
@@ -229,8 +224,7 @@ void Scale2x_YUY2( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
BYTE* s2;
BYTE* d1;
- for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch)
- {
+ for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) {
// row0, 4 pixels: y1|u1|y2|v1|y3|u2|y4|v2
// ->
// row0, 8 pixels: y1|u1|(y1+y2)/2|v1|y2|(u1+u2)/2|(y2+y3)/2|(v1+v2)/2
@@ -254,13 +248,11 @@ void Scale2x_RGB555( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
BYTE* s2;
BYTE* d1;
- for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) // TODO: replace this mess with mmx code
- {
+ for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) { // TODO: replace this mess with mmx code
BYTE* stmp = s1 + spitch;
BYTE* dtmp = d1 + dpitch;
- for(BYTE* s3 = s1 + (w-1)*2; s1 < s3; s1 += 2, d1 += 4)
- {
+ for(BYTE* s3 = s1 + (w-1)*2; s1 < s3; s1 += 2, d1 += 4) {
*((WORD*)d1) = *((WORD*)s1);
*((WORD*)d1+1) =
((((*((WORD*)s1)&0x7c00) + (*((WORD*)s1+1)&0x7c00)) >> 1)&0x7c00)|
@@ -287,13 +279,11 @@ void Scale2x_RGB565( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
BYTE* s2;
BYTE* d1;
- for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) // TODO: replace this mess with mmx code
- {
+ for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) { // TODO: replace this mess with mmx code
BYTE* stmp = s1 + spitch;
BYTE* dtmp = d1 + dpitch;
- for(BYTE* s3 = s1 + (w-1)*2; s1 < s3; s1 += 2, d1 += 4)
- {
+ for(BYTE* s3 = s1 + (w-1)*2; s1 < s3; s1 += 2, d1 += 4) {
*((WORD*)d1) = *((WORD*)s1);
*((WORD*)d1+1) =
((((*((WORD*)s1)&0xf800) + (*((WORD*)s1+1)&0xf800)) >> 1)&0xf800)|
@@ -320,13 +310,11 @@ void Scale2x_RGB24( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
BYTE* s2;
BYTE* d1;
- for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) // TODO: replace this mess with mmx code
- {
+ for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) { // TODO: replace this mess with mmx code
BYTE* stmp = s1 + spitch;
BYTE* dtmp = d1 + dpitch;
- for(BYTE* s3 = s1 + (w-1)*3; s1 < s3; s1 += 3, d1 += 6)
- {
+ for(BYTE* s3 = s1 + (w-1)*3; s1 < s3; s1 += 3, d1 += 6) {
d1[0] = s1[0];
d1[1] = s1[1];
d1[2] = s1[2];
@@ -353,8 +341,7 @@ void Scale2x_RGB24( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
void Scale2x_XRGB32_SSE2( BYTE* s1, BYTE* d1, int w )
{
__m128i mm_zero = _mm_setzero_si128();//pxor mm0, mm0
- for(BYTE* s3 = s1 + (w-1)*4; s1 < s3; s1 += 4, d1 += 8)
- {
+ for(BYTE* s3 = s1 + (w-1)*4; s1 < s3; s1 += 4, d1 += 8) {
__m128i mm1 = _mm_cvtsi64_si128(*(size_t*)s1); //movq mm1, [esi]
__m128i mm2 = _mm_move_epi64(mm1); //movq mm2, mm1
@@ -379,8 +366,7 @@ void Scale2x_XRGB32_SSE2( BYTE* s1, BYTE* d1, int w )
#else
void Scale2x_XRGB32_MMX( BYTE* s1, BYTE* d1, int w )
{
- __asm
- {
+ __asm {
mov esi, s1
mov edi, d1
@@ -388,7 +374,7 @@ void Scale2x_XRGB32_MMX( BYTE* s1, BYTE* d1, int w )
dec ecx
pxor mm0, mm0
-row_loop3:
+ row_loop3:
movq mm1, [esi]
movq mm2, mm1
@@ -422,8 +408,7 @@ row_loop3:
void Scale2x_XRGB32_c( BYTE* s1, BYTE* d1, int w )
{
- for(BYTE* s3 = s1 + (w-1)*4; s1 < s3; s1 += 3, d1 += 6)
- {
+ for(BYTE* s3 = s1 + (w-1)*4; s1 < s3; s1 += 3, d1 += 6) {
d1[0] = s1[0];
d1[1] = s1[1];
d1[2] = s1[2];
@@ -456,8 +441,7 @@ void Scale2x_XRGB32( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
BYTE* s2;
BYTE* d1;
- for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch)
- {
+ for(s1 = s, s2 = s + h*spitch, d1 = d; s1 < s2; d1 += dpitch) {
scale_func(s1, d1, w);
s1 += spitch;
@@ -474,16 +458,17 @@ void Scale2x_XRGB32( int w, int h, BYTE* d, int dpitch, BYTE* s, int spitch )
/* ResX2 */
void Scale2x(const GUID& subtype, BYTE* d, int dpitch, BYTE* s, int spitch, int w, int h)
{
- if(subtype == MEDIASUBTYPE_YV12 || subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV)
+ if(subtype == MEDIASUBTYPE_YV12 || subtype == MEDIASUBTYPE_I420 || subtype == MEDIASUBTYPE_IYUV) {
Scale2x_YV(w, h, d, dpitch, s, spitch);
- else if(subtype == MEDIASUBTYPE_YUY2)
+ } else if(subtype == MEDIASUBTYPE_YUY2) {
Scale2x_YUY2(w, h, d, dpitch, s, spitch);
- else if(subtype == MEDIASUBTYPE_RGB555)
+ } else if(subtype == MEDIASUBTYPE_RGB555) {
Scale2x_RGB555(w, h, d, dpitch, s, spitch);
- else if(subtype == MEDIASUBTYPE_RGB565)
+ } else if(subtype == MEDIASUBTYPE_RGB565) {
Scale2x_RGB565(w, h, d, dpitch, s, spitch);
- else if(subtype == MEDIASUBTYPE_RGB24)
+ } else if(subtype == MEDIASUBTYPE_RGB24) {
Scale2x_RGB24(w, h, d, dpitch, s, spitch);
- else if(subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_ARGB32)
+ } else if(subtype == MEDIASUBTYPE_RGB32 || subtype == MEDIASUBTYPE_ARGB32) {
Scale2x_XRGB32(w, h, d, dpitch, s, spitch);
+ }
}
diff --git a/src/filters/transform/VSFilter/StyleEditorDialog.cpp b/src/filters/transform/VSFilter/StyleEditorDialog.cpp
index b31fa4b9c..0cd270f06 100644
--- a/src/filters/transform/VSFilter/StyleEditorDialog.cpp
+++ b/src/filters/transform/VSFilter/StyleEditorDialog.cpp
@@ -106,11 +106,12 @@ void CStyleEditorDialog::DoDataExchange(CDataExchange* pDX)
void CStyleEditorDialog::UpdateControlData(bool fSave)
{
- if(fSave)
- {
+ if(fSave) {
UpdateData();
- if(m_iCharset >= 0) m_stss.charSet = m_charset.GetItemData(m_iCharset);
+ if(m_iCharset >= 0) {
+ m_stss.charSet = m_charset.GetItemData(m_iCharset);
+ }
m_stss.fontSpacing = m_spacing;
m_stss.fontAngleZ = m_angle;
m_stss.fontScaleX = m_scalex;
@@ -123,24 +124,27 @@ void CStyleEditorDialog::UpdateControlData(bool fSave)
m_stss.scrAlignment = m_screenalignment+1;
m_stss.marginRect = m_margin;
- for(ptrdiff_t i = 0; i < 4; i++) m_stss.alpha[i] = 255-m_alpha[i];
- }
- else
- {
+ for(ptrdiff_t i = 0; i < 4; i++) {
+ m_stss.alpha[i] = 255-m_alpha[i];
+ }
+ } else {
m_font.SetWindowText(m_stss.fontName);
m_iCharset = -1;
- for(ptrdiff_t i = 0; i < CharSetLen; i++)
- {
+ for(ptrdiff_t i = 0; i < CharSetLen; i++) {
CString str;
str.Format(_T("%s (%d)"), CharSetNames[i], CharSetList[i]);
m_charset.AddString(str);
m_charset.SetItemData(i, CharSetList[i]);
- if(m_stss.charSet == CharSetList[i]) m_iCharset = i;
+ if(m_stss.charSet == CharSetList[i]) {
+ m_iCharset = i;
+ }
}
// TODO: allow floats in these edit boxes
m_spacing = m_stss.fontSpacing;
m_spacingspin.SetRange32(-10000, 10000);
- while(m_stss.fontAngleZ < 0) m_stss.fontAngleZ += 360;
+ while(m_stss.fontAngleZ < 0) {
+ m_stss.fontAngleZ += 360;
+ }
m_angle = fmod(m_stss.fontAngleZ, 360);
m_anglespin.SetRange32(0, 359);
m_scalex = m_stss.fontScaleX;
@@ -161,8 +165,7 @@ void CStyleEditorDialog::UpdateControlData(bool fSave)
m_margintopspin.SetRange32(-10000, 10000);
m_marginbottomspin.SetRange32(-10000, 10000);
- for(ptrdiff_t i = 0; i < 4; i++)
- {
+ for(ptrdiff_t i = 0; i < 4; i++) {
m_color[i].SetColorPtr(&m_stss.colors[i]);
m_alpha[i] = 255-m_stss.alpha[i];
m_alphasliders[i].SetRange(0, 255);
@@ -178,8 +181,7 @@ void CStyleEditorDialog::AskColor(int i)
{
CColorDialog dlg(m_stss.colors[i]);
dlg.m_cc.Flags |= CC_FULLOPEN;
- if(dlg.DoModal() == IDOK)
- {
+ if(dlg.DoModal() == IDOK) {
m_stss.colors[i] = dlg.m_cc.rgbResult;
m_color[i].Invalidate();
}
@@ -223,16 +225,15 @@ void CStyleEditorDialog::OnBnClickedButton1()
lf <<= m_stss;
CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT|CF_FORCEFONTEXIST|CF_SCALABLEONLY|CF_EFFECTS);
- if(dlg.DoModal() == IDOK)
- {
+ if(dlg.DoModal() == IDOK) {
CString str(lf.lfFaceName);
- if(str.GetLength() > 16) str = str.Left(14) + _T("...");
+ if(str.GetLength() > 16) {
+ str = str.Left(14) + _T("...");
+ }
m_font.SetWindowText(str);
- for(ptrdiff_t i = 0, j = m_charset.GetCount(); i < j; i++)
- {
- if(m_charset.GetItemData(i) == lf.lfCharSet)
- {
+ for(ptrdiff_t i = 0, j = m_charset.GetCount(); i < j; i++) {
+ if(m_charset.GetItemData(i) == lf.lfCharSet) {
m_charset.SetCurSel(i);
break;
}
@@ -267,17 +268,22 @@ void CStyleEditorDialog::OnBnClickedCheck1()
UpdateData();
int avg = 0;
- for(ptrdiff_t i = 0; i < 4; i++) avg += m_alphasliders[i].GetPos();
+ for(ptrdiff_t i = 0; i < 4; i++) {
+ avg += m_alphasliders[i].GetPos();
+ }
avg /= 4;
- for(ptrdiff_t i = 0; i < 4; i++) m_alphasliders[i].SetPos(avg);
+ for(ptrdiff_t i = 0; i < 4; i++) {
+ m_alphasliders[i].SetPos(avg);
+ }
}
void CStyleEditorDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
- if(m_linkalphasliders && pScrollBar)
- {
+ if(m_linkalphasliders && pScrollBar) {
int pos = ((CSliderCtrl*)pScrollBar)->GetPos();
- for(ptrdiff_t i = 0; i < 4; i++) m_alphasliders[i].SetPos(pos);
+ for(ptrdiff_t i = 0; i < 4; i++) {
+ m_alphasliders[i].SetPos(pos);
+ }
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
diff --git a/src/filters/transform/VSFilter/StyleEditorDialog.h b/src/filters/transform/VSFilter/StyleEditorDialog.h
index b0760539d..ce6585d4b 100644
--- a/src/filters/transform/VSFilter/StyleEditorDialog.h
+++ b/src/filters/transform/VSFilter/StyleEditorDialog.h
@@ -46,8 +46,7 @@ public:
DECLARE_MESSAGE_MAP()
protected:
- virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
+ virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) {
CRect r;
GetClientRect(r);
CDC::FromHandle(lpDrawItemStruct->hDC)->FillSolidRect(r, m_pColor ? *m_pColor : ::GetSysColor(COLOR_BTNFACE));
@@ -70,7 +69,7 @@ public:
CStyleEditorDialog(CString title, STSStyle* pstss, CWnd* pParent = NULL); // standard constructor
virtual ~CStyleEditorDialog();
-// Dialog Data
+ // Dialog Data
enum { IDD = IDD_STYLEDIALOG };
STSStyle m_stss;
diff --git a/src/filters/transform/VSFilter/Systray.cpp b/src/filters/transform/VSFilter/Systray.cpp
index 63a4aa0fa..8fcb10948 100644
--- a/src/filters/transform/VSFilter/Systray.cpp
+++ b/src/filters/transform/VSFilter/Systray.cpp
@@ -43,27 +43,25 @@ LRESULT CALLBACK HookProc(UINT code, WPARAM wParam, LPARAM lParam)
{
MSG* msg = (MSG*)lParam;
- if(msg->message == WM_KEYDOWN)
- {
- switch(msg->wParam)
- {
- case VK_F13:
- PostMessage(HWND_BROADCAST, WM_DVSPREVSUB, 0, 0);
- break;
- case VK_F14:
- PostMessage(HWND_BROADCAST, WM_DVSNEXTSUB, 0, 0);
- break;
- case VK_F15:
- PostMessage(HWND_BROADCAST, WM_DVSHIDESUB, 0, 0);
- break;
- case VK_F16:
- PostMessage(HWND_BROADCAST, WM_DVSSHOWSUB, 0, 0);
- break;
- case VK_F17:
- PostMessage(HWND_BROADCAST, WM_DVSSHOWHIDESUB, 0, 0);
- break;
- default:
- break;
+ if(msg->message == WM_KEYDOWN) {
+ switch(msg->wParam) {
+ case VK_F13:
+ PostMessage(HWND_BROADCAST, WM_DVSPREVSUB, 0, 0);
+ break;
+ case VK_F14:
+ PostMessage(HWND_BROADCAST, WM_DVSNEXTSUB, 0, 0);
+ break;
+ case VK_F15:
+ PostMessage(HWND_BROADCAST, WM_DVSHIDESUB, 0, 0);
+ break;
+ case VK_F16:
+ PostMessage(HWND_BROADCAST, WM_DVSSHOWSUB, 0, 0);
+ break;
+ case VK_F17:
+ PostMessage(HWND_BROADCAST, WM_DVSSHOWHIDESUB, 0, 0);
+ break;
+ default:
+ break;
}
}
@@ -75,23 +73,28 @@ class CSystrayWindow : public CWnd
{
SystrayIconData* m_tbid;
- void StepSub(int dir)
- {
+ void StepSub(int dir) {
int iSelected, nLangs;
- if(FAILED(m_tbid->dvs->get_LanguageCount(&nLangs))) return;
- if(FAILED(m_tbid->dvs->get_SelectedLanguage(&iSelected))) return;
- if(nLangs > 0) m_tbid->dvs->put_SelectedLanguage((iSelected+dir+nLangs)%nLangs);
+ if(FAILED(m_tbid->dvs->get_LanguageCount(&nLangs))) {
+ return;
+ }
+ if(FAILED(m_tbid->dvs->get_SelectedLanguage(&iSelected))) {
+ return;
+ }
+ if(nLangs > 0) {
+ m_tbid->dvs->put_SelectedLanguage((iSelected+dir+nLangs)%nLangs);
+ }
}
- void ShowSub(bool fShow)
- {
+ void ShowSub(bool fShow) {
m_tbid->dvs->put_HideSubtitles(!fShow);
}
- void ToggleSub()
- {
+ void ToggleSub() {
bool fShow;
- if(FAILED(m_tbid->dvs->get_HideSubtitles(&fShow))) return;
+ if(FAILED(m_tbid->dvs->get_HideSubtitles(&fShow))) {
+ return;
+ }
m_tbid->dvs->put_HideSubtitles(!fShow);
}
@@ -131,13 +134,13 @@ END_MESSAGE_MAP()
int CSystrayWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
- if(CWnd::OnCreate(lpCreateStruct) == -1)
+ if(CWnd::OnCreate(lpCreateStruct) == -1) {
return -1;
+ }
- if(g_hHook == INVALID_HANDLE_VALUE)
- {
+ if(g_hHook == INVALID_HANDLE_VALUE) {
AFX_MANAGE_STATE(AfxGetStaticModuleState());
-// g_hHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookProc, AfxGetInstanceHandle(), 0);
+ // g_hHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)HookProc, AfxGetInstanceHandle(), 0);
}
SetTimer(1, 5000, NULL);
@@ -160,8 +163,7 @@ void CSystrayWindow::OnDestroy()
tnid.uID = IDI_ICON1;
Shell_NotifyIcon(NIM_DELETE, &tnid);
- if(g_hHook != INVALID_HANDLE_VALUE)
- {
+ if(g_hHook != INVALID_HANDLE_VALUE) {
UnhookWindowsHookEx(g_hHook);
g_hHook = (HHOOK)INVALID_HANDLE_VALUE;
}
@@ -171,11 +173,9 @@ void CSystrayWindow::OnDestroy()
void CSystrayWindow::OnTimer(UINT_PTR nIDEvent)
{
- if(nIDEvent == 1)
- {
+ if(nIDEvent == 1) {
UINT fScreenSaver = 0;
- if(SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (PVOID)&fScreenSaver, 0))
- {
+ if(SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, (PVOID)&fScreenSaver, 0)) {
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, 0, SPIF_SENDWININICHANGE); // this might not be needed at all...
SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, fScreenSaver, 0, SPIF_SENDWININICHANGE);
}
@@ -214,21 +214,22 @@ LRESULT CSystrayWindow::OnTaskBarRestart(WPARAM, LPARAM)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
- if(m_tbid->fShowIcon)
- {
+ if(m_tbid->fShowIcon) {
NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = m_hWnd;
tnid.uID = IDI_ICON1;
tnid.hIcon = (HICON)LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1));
-// tnid.hIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);
+ // tnid.hIcon = (HICON)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 0, 0, LR_LOADTRANSPARENT);
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_NOTIFYICON;
lstrcpyn(tnid.szTip, TEXT("DirectVobSub"), sizeof(tnid.szTip));
BOOL res = Shell_NotifyIcon(NIM_ADD, &tnid);
- if(tnid.hIcon) DestroyIcon(tnid.hIcon);
+ if(tnid.hIcon) {
+ DestroyIcon(tnid.hIcon);
+ }
return res?0:-1;
}
@@ -238,145 +239,138 @@ LRESULT CSystrayWindow::OnTaskBarRestart(WPARAM, LPARAM)
LRESULT CSystrayWindow::OnNotifyIcon(WPARAM wParam, LPARAM lParam)
{
- if((UINT)wParam != IDI_ICON1)
+ if((UINT)wParam != IDI_ICON1) {
return -1;
+ }
HWND hWnd = m_hWnd;
- switch((UINT)lParam)
- {
- case WM_LBUTTONDBLCLK:
- {
- // IMPORTANT: we must not hold the graph at the same time as showing the property page
- // or else when closing the app the graph doesn't get released and dvobsub's JoinFilterGraph
- // is never called to close us down.
-
- CComPtr<IBaseFilter> pBF2;
-
- BeginEnumFilters(m_tbid->graph, pEF, pBF)
- {
- if(!CComQIPtr<IDirectVobSub>(pBF))
- continue;
-
- if(CComQIPtr<IVideoWindow> pVW = m_tbid->graph)
- {
- HWND hwnd;
- if(SUCCEEDED(pVW->get_Owner((OAHWND*)&hwnd))
- || SUCCEEDED(pVW->get_MessageDrain((OAHWND*)&hwnd)))
- hWnd = hwnd;
- }
+ switch((UINT)lParam) {
+ case WM_LBUTTONDBLCLK: {
+ // IMPORTANT: we must not hold the graph at the same time as showing the property page
+ // or else when closing the app the graph doesn't get released and dvobsub's JoinFilterGraph
+ // is never called to close us down.
- pBF2 = pBF;
+ CComPtr<IBaseFilter> pBF2;
- break;
- }
- EndEnumFilters
-
- if(pBF2)
- ShowPPage(pBF2, hWnd);
- }
- break;
+ BeginEnumFilters(m_tbid->graph, pEF, pBF) {
+ if(!CComQIPtr<IDirectVobSub>(pBF)) {
+ continue;
+ }
- case WM_RBUTTONDOWN:
- {
- POINT p;
- GetCursorPos(&p);
+ if(CComQIPtr<IVideoWindow> pVW = m_tbid->graph) {
+ HWND hwnd;
+ if(SUCCEEDED(pVW->get_Owner((OAHWND*)&hwnd))
+ || SUCCEEDED(pVW->get_MessageDrain((OAHWND*)&hwnd))) {
+ hWnd = hwnd;
+ }
+ }
- CInterfaceArray<IAMStreamSelect> pStreams;
- CStringArray names;
+ pBF2 = pBF;
- BeginEnumFilters(m_tbid->graph, pEF, pBF)
- {
- CString name = GetFilterName(pBF);
- if(name.IsEmpty()) continue;
+ break;
+ }
+ EndEnumFilters
- if(CComQIPtr<IAMStreamSelect> pSS = pBF)
- {
- pStreams.Add(pSS);
- names.Add(name);
+ if(pBF2) {
+ ShowPPage(pBF2, hWnd);
}
}
- EndEnumFilters
+ break;
- CMenu popup;
- popup.CreatePopupMenu();
+ case WM_RBUTTONDOWN: {
+ POINT p;
+ GetCursorPos(&p);
- for(ptrdiff_t j = 0; j < pStreams.GetCount(); j++)
- {
- bool fMMSwitcher = !names[j].Compare(_T("Morgan Stream Switcher"));
+ CInterfaceArray<IAMStreamSelect> pStreams;
+ CStringArray names;
+
+ BeginEnumFilters(m_tbid->graph, pEF, pBF) {
+ CString name = GetFilterName(pBF);
+ if(name.IsEmpty()) {
+ continue;
+ }
+
+ if(CComQIPtr<IAMStreamSelect> pSS = pBF) {
+ pStreams.Add(pSS);
+ names.Add(name);
+ }
+ }
+ EndEnumFilters
- DWORD cStreams = 0;
- pStreams[j]->Count(&cStreams);
+ CMenu popup;
+ popup.CreatePopupMenu();
- DWORD flags, group, prevgroup = (DWORD)-1;
+ for(ptrdiff_t j = 0; j < pStreams.GetCount(); j++) {
+ bool fMMSwitcher = !names[j].Compare(_T("Morgan Stream Switcher"));
- for(UINT i = 0; i < cStreams; i++)
- {
- WCHAR* pName = NULL;
+ DWORD cStreams = 0;
+ pStreams[j]->Count(&cStreams);
- if(S_OK == pStreams[j]->Info(i, 0, &flags, 0, &group, &pName, 0, 0))
- {
- if(prevgroup != group && i > 1)
- {
- if(fMMSwitcher) {
- cStreams = i;
- break;
+ DWORD flags, group, prevgroup = (DWORD)-1;
+
+ for(UINT i = 0; i < cStreams; i++) {
+ WCHAR* pName = NULL;
+
+ if(S_OK == pStreams[j]->Info(i, 0, &flags, 0, &group, &pName, 0, 0)) {
+ if(prevgroup != group && i > 1) {
+ if(fMMSwitcher) {
+ cStreams = i;
+ break;
+ }
+ popup.AppendMenu(MF_SEPARATOR);
}
- popup.AppendMenu(MF_SEPARATOR);
- }
- prevgroup = group;
+ prevgroup = group;
- if(pName)
- {
- popup.AppendMenu(MF_ENABLED|MF_STRING|(flags?MF_CHECKED:MF_UNCHECKED), (1<<15)|(j<<8)|(i), CString(pName));
- CoTaskMemFree(pName);
+ if(pName) {
+ popup.AppendMenu(MF_ENABLED|MF_STRING|(flags?MF_CHECKED:MF_UNCHECKED), (1<<15)|(j<<8)|(i), CString(pName));
+ CoTaskMemFree(pName);
+ }
}
}
- }
-
- if(cStreams > 0) popup.AppendMenu(MF_SEPARATOR);
- }
- int i = 0;
-
- TCHAR* str;
- str = CallPPage(m_tbid->graph, i, (HWND)INVALID_HANDLE_VALUE);
- while(str)
- {
- if(_tcsncmp(str, _T("DivX MPEG"), 9) || m_tbid->fRunOnce) // divx3's ppage will crash if the graph hasn't been run at least once yet
- popup.AppendMenu(MF_ENABLED|MF_STRING|MF_UNCHECKED, (1<<14)|(i), str);
+ if(cStreams > 0) {
+ popup.AppendMenu(MF_SEPARATOR);
+ }
+ }
- delete [] str;
+ int i = 0;
- i++;
+ TCHAR* str;
str = CallPPage(m_tbid->graph, i, (HWND)INVALID_HANDLE_VALUE);
- }
+ while(str) {
+ if(_tcsncmp(str, _T("DivX MPEG"), 9) || m_tbid->fRunOnce) { // divx3's ppage will crash if the graph hasn't been run at least once yet
+ popup.AppendMenu(MF_ENABLED|MF_STRING|MF_UNCHECKED, (1<<14)|(i), str);
+ }
- SetForegroundWindow();
- UINT id = popup.TrackPopupMenu(TPM_LEFTBUTTON|TPM_RETURNCMD, p.x, p.y, CWnd::FromHandle(hWnd), 0);
- PostMessage(WM_NULL);
+ delete [] str;
- if(id & (1<<15))
- {
- pStreams[(id>>8)&0x3f]->Enable(id&0xff, AMSTREAMSELECTENABLE_ENABLE);
- }
- else if(id & (1<<14))
- {
- if(CComQIPtr<IVideoWindow> pVW = m_tbid->graph)
- {
- HWND hwnd;
- if(SUCCEEDED(pVW->get_Owner((OAHWND*)&hwnd))
- || SUCCEEDED(pVW->get_MessageDrain((OAHWND*)&hwnd)))
- hWnd = hwnd;
+ i++;
+ str = CallPPage(m_tbid->graph, i, (HWND)INVALID_HANDLE_VALUE);
}
- CallPPage(m_tbid->graph, id&0xff, hWnd);
- }
- }
- break;
+ SetForegroundWindow();
+ UINT id = popup.TrackPopupMenu(TPM_LEFTBUTTON|TPM_RETURNCMD, p.x, p.y, CWnd::FromHandle(hWnd), 0);
+ PostMessage(WM_NULL);
+
+ if(id & (1<<15)) {
+ pStreams[(id>>8)&0x3f]->Enable(id&0xff, AMSTREAMSELECTENABLE_ENABLE);
+ } else if(id & (1<<14)) {
+ if(CComQIPtr<IVideoWindow> pVW = m_tbid->graph) {
+ HWND hwnd;
+ if(SUCCEEDED(pVW->get_Owner((OAHWND*)&hwnd))
+ || SUCCEEDED(pVW->get_MessageDrain((OAHWND*)&hwnd))) {
+ hWnd = hwnd;
+ }
+ }
- default:
+ CallPPage(m_tbid->graph, id&0xff, hWnd);
+ }
+ }
break;
+
+ default:
+ break;
}
return 0;
@@ -389,14 +383,14 @@ DWORD CALLBACK SystrayThreadProc(void* pParam)
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CSystrayWindow wnd((SystrayIconData*)pParam);
- if(!wnd.CreateEx(0, AfxRegisterWndClass(0), _T("DVSWND"), WS_OVERLAPPED, CRect(0, 0, 0, 0), NULL, 0, NULL))
+ if(!wnd.CreateEx(0, AfxRegisterWndClass(0), _T("DVSWND"), WS_OVERLAPPED, CRect(0, 0, 0, 0), NULL, 0, NULL)) {
return (DWORD)-1;
+ }
((SystrayIconData*)pParam)->hSystrayWnd = wnd.m_hWnd;
MSG msg;
- while(GetMessage(&msg, NULL/*wnd.m_hWnd*/, 0, 0))
- {
+ while(GetMessage(&msg, NULL/*wnd.m_hWnd*/, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@@ -417,13 +411,13 @@ static TCHAR* CallPPage(IFilterGraph* pGraph, int idx, HWND hWnd)
CAUUID caGUID;
caGUID.pElems = NULL;
- BeginEnumFilters(pGraph, pEF, pBF)
- {
+ BeginEnumFilters(pGraph, pEF, pBF) {
CComQIPtr<ISpecifyPropertyPages> pSPS = pBF;
- if(!pSPS) continue;
+ if(!pSPS) {
+ continue;
+ }
- if(i == idx)
- {
+ if(i == idx) {
pFilter = pBF;
pSPS->GetPages(&caGUID);
wstr = _wcsdup(CStringW(GetFilterName(pBF))); // double char-wchar conversion happens in the non-unicode build, but anyway... :)
@@ -436,22 +430,23 @@ static TCHAR* CallPPage(IFilterGraph* pGraph, int idx, HWND hWnd)
TCHAR* ret = NULL;
- if(pFilter)
- {
- if(hWnd != INVALID_HANDLE_VALUE)
- {
+ if(pFilter) {
+ if(hWnd != INVALID_HANDLE_VALUE) {
ShowPPage(pFilter, hWnd);
- }
- else
- {
+ } else {
ret = new TCHAR[wcslen(wstr)+1];
- if(ret)
+ if(ret) {
_tcscpy(ret, CString(wstr));
+ }
}
}
- if(caGUID.pElems) CoTaskMemFree(caGUID.pElems);
- if(wstr) free(wstr);
+ if(caGUID.pElems) {
+ CoTaskMemFree(caGUID.pElems);
+ }
+ if(wstr) {
+ free(wstr);
+ }
return(ret);
}
diff --git a/src/filters/transform/VSFilter/VSFilter.cpp b/src/filters/transform/VSFilter/VSFilter.cpp
index 12ae93e67..2bb1d23fb 100644
--- a/src/filters/transform/VSFilter/VSFilter.cpp
+++ b/src/filters/transform/VSFilter/VSFilter.cpp
@@ -44,8 +44,9 @@ extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
BOOL CVSFilterApp::InitInstance()
{
- if(!CWinApp::InitInstance())
+ if(!CWinApp::InitInstance()) {
return FALSE;
+ }
SetRegistryKey(_T("Gabest"));
@@ -82,8 +83,7 @@ CVSFilterApp theApp;
//////////////////////////////////////////////////////////////////////////
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_NULL, &MEDIASUBTYPE_NULL},
{&MEDIATYPE_Video, &MEDIASUBTYPE_YUY2},
{&MEDIATYPE_Video, &MEDIASUBTYPE_YV12},
@@ -95,31 +95,27 @@ const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
{&MEDIATYPE_Video, &MEDIASUBTYPE_RGB24},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn2[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn2[] = {
{&MEDIATYPE_Text, &MEDIASUBTYPE_None},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Video, &MEDIASUBTYPE_None},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut},
{L"Input2", TRUE, FALSE, FALSE, TRUE, &CLSID_NULL, NULL, countof(sudPinTypesIn2), sudPinTypesIn2}
};
-/*const*/ AMOVIESETUP_FILTER sudFilter[] =
-{
+/*const*/
+AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CDirectVobSubFilter), L"DirectVobSub", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
{&__uuidof(CDirectVobSubFilter2), L"DirectVobSub (auto-loading version)", MERIT_PREFERRED+2, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory},
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDirectVobSubFilter>, NULL, &sudFilter[0]},
{sudFilter[1].strName, sudFilter[1].clsID, CreateInstance<CDirectVobSubFilter2>, NULL, &sudFilter[1]},
{L"DVSMainPPage", &__uuidof(CDVSMainPPage), CreateInstance<CDVSMainPPage>},
@@ -140,34 +136,38 @@ STDAPI DllRegisterServer()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
- if(theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_SEENDIVXWARNING), 0) != 1)
+ if(theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_SEENDIVXWARNING), 0) != 1) {
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_SEENDIVXWARNING), 0);
+ }
- if(theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_VMRZOOMENABLED), -1) == -1)
+ if(theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_VMRZOOMENABLED), -1) == -1) {
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_VMRZOOMENABLED), 0);
+ }
- if(theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_ENABLEZPICON), -1) == -1)
+ if(theApp.GetProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_ENABLEZPICON), -1) == -1) {
theApp.WriteProfileInt(ResStr(IDS_R_GENERAL), ResStr(IDS_RG_ENABLEZPICON), 0);
+ }
return AMovieDllRegisterServer2(TRUE);
}
STDAPI DllUnregisterServer()
{
-// DVS_WriteProfileInt2(IDS_R_GENERAL, IDS_RG_SEENDIVXWARNING, 0);
+ // DVS_WriteProfileInt2(IDS_R_GENERAL, IDS_RG_SEENDIVXWARNING, 0);
return AMovieDllRegisterServer2(FALSE);
}
void CALLBACK DirectVobSub(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
- if(FAILED(::CoInitialize(0))) return;
+ if(FAILED(::CoInitialize(0))) {
+ return;
+ }
CComPtr<IBaseFilter> pFilter;
CComQIPtr<ISpecifyPropertyPages> pSpecify;
- if(SUCCEEDED(pFilter.CoCreateInstance(__uuidof(CDirectVobSubFilter))) && (pSpecify = pFilter))
- {
+ if(SUCCEEDED(pFilter.CoCreateInstance(__uuidof(CDirectVobSubFilter))) && (pSpecify = pFilter)) {
ShowPPage(pFilter, hwnd);
}
diff --git a/src/filters/transform/VSFilter/csri.h b/src/filters/transform/VSFilter/csri.h
index 83ee828fa..7d67bae96 100644
--- a/src/filters/transform/VSFilter/csri.h
+++ b/src/filters/transform/VSFilter/csri.h
@@ -43,39 +43,39 @@ extern "C" {
#endif
#ifndef CSRIAPI
-/** CSRI API attributes.
- * defaults to \c extern.
-*/
+ /** CSRI API attributes.
+ * defaults to \c extern.
+ */
#define CSRIAPI extern
#endif
-/** \defgroup base CSRI base API. */
-/*@{*/
+ /** \defgroup base CSRI base API. */
+ /*@{*/
-/** pixel format specification for frames */
-enum csri_pixfmt {
- CSRI_F_RGBA = 0,
- CSRI_F_ARGB,
- CSRI_F_BGRA,
- CSRI_F_ABGR,
+ /** pixel format specification for frames */
+ enum csri_pixfmt {
+ CSRI_F_RGBA = 0,
+ CSRI_F_ARGB,
+ CSRI_F_BGRA,
+ CSRI_F_ABGR,
- CSRI_F_RGB_ = 0x100,
- CSRI_F__RGB,
- CSRI_F_BGR_, /**< Windows "RGB32" */
- CSRI_F__BGR,
+ CSRI_F_RGB_ = 0x100,
+ CSRI_F__RGB,
+ CSRI_F_BGR_, /**< Windows "RGB32" */
+ CSRI_F__BGR,
- CSRI_F_RGB = 0x200,
- CSRI_F_BGR, /**< Windows "RGB24" */
+ CSRI_F_RGB = 0x200,
+ CSRI_F_BGR, /**< Windows "RGB24" */
- CSRI_F_AYUV = 0x1000,
- CSRI_F_YUVA,
- CSRI_F_YVUA,
+ CSRI_F_AYUV = 0x1000,
+ CSRI_F_YUVA,
+ CSRI_F_YVUA,
- CSRI_F_YUY2 = 0x1100,
+ CSRI_F_YUY2 = 0x1100,
- CSRI_F_YV12A = 0x2011, /**< planar YUV 2x2 + alpha plane */
- CSRI_F_YV12 = 0x2111 /**< planar YUV 2x2 */
- };
+ CSRI_F_YV12A = 0x2011, /**< planar YUV 2x2 + alpha plane */
+ CSRI_F_YV12 = 0x2111 /**< planar YUV 2x2 */
+ };
#define csri_is_rgb(x) ((x) < 0x1000)
#define csri_is_yuv(x) ((x) >= 0x1000)
@@ -85,261 +85,261 @@ enum csri_pixfmt {
#define csri_is_yuv_packed(x) ((x) >= 0x1000 && (x) < 0x2000)
#define csri_has_alpha(x) (((x) & 0xfff) < 0x100)
-/** frame/image format specification pre-fed to the renderer */
-struct csri_fmt {
- /** format to be used */
- enum csri_pixfmt pixfmt;
- /** image width, full frame.
- *
- * This should specify the full size of the frame.
- * Specifying the video sub-size (in case of added black
- * borders) is left to an extension.
- */
- unsigned width;
- /** image height */
- unsigned height;
-};
-
-/** single frame to be fed to the renderer. */
-struct csri_frame {
- /** frame format.
- * It is an application bug if this differs from the one
- * passed in struct #csri_fmt to csri_query_fmt()
- */
- enum csri_pixfmt pixfmt;
- /** the frame's data.
- * Packed formats only use planes[0]; planar formats
- * have the data ordered as Y, U, V[, A].
- *
- * Also note that the topmost line always comes first.
- * The Windows biHeight strange-ity is \a NOT duplicated.
- */
- unsigned char *planes[4];
- /** strides for the individual planes.
- * Stride means full byte offset, i.e. do \a not add
- * frame width
- */
- ptrdiff_t strides[4];
-};
+ /** frame/image format specification pre-fed to the renderer */
+ struct csri_fmt {
+ /** format to be used */
+ enum csri_pixfmt pixfmt;
+ /** image width, full frame.
+ *
+ * This should specify the full size of the frame.
+ * Specifying the video sub-size (in case of added black
+ * borders) is left to an extension.
+ */
+ unsigned width;
+ /** image height */
+ unsigned height;
+ };
+
+ /** single frame to be fed to the renderer. */
+ struct csri_frame {
+ /** frame format.
+ * It is an application bug if this differs from the one
+ * passed in struct #csri_fmt to csri_query_fmt()
+ */
+ enum csri_pixfmt pixfmt;
+ /** the frame's data.
+ * Packed formats only use planes[0]; planar formats
+ * have the data ordered as Y, U, V[, A].
+ *
+ * Also note that the topmost line always comes first.
+ * The Windows biHeight strange-ity is \a NOT duplicated.
+ */
+ unsigned char *planes[4];
+ /** strides for the individual planes.
+ * Stride means full byte offset, i.e. do \a not add
+ * frame width
+ */
+ ptrdiff_t strides[4];
+ };
#ifndef CSRI_OWN_HANDLES
-/** opaque renderer data */
-typedef void csri_rend;
-/** opaque instance data */
-typedef void csri_inst;
+ /** opaque renderer data */
+ typedef void csri_rend;
+ /** opaque instance data */
+ typedef void csri_inst;
#endif
#ifdef DOXYGEN
-/** disable the emission of the csri_rend and csri_inst typedefs.
- * define this if you are in a renderer and are typedef'ing
- * csri_rend and csri_inst to your own structs.
-*/
+ /** disable the emission of the csri_rend and csri_inst typedefs.
+ * define this if you are in a renderer and are typedef'ing
+ * csri_rend and csri_inst to your own structs.
+ */
#define CSRI_OWN_HANDLES
#endif
-/** renderer description.
- * \ingroup loader
- */
-struct csri_info {
- /** an identifier for the renderer.
- * - MUST match the regular expression
- * \code ^[a-zA-Z]([a-zA-Z0-9_]*[a-zA-Z0-9])? \endcode
- * i.e. consists only of letters, numbers and underscores;
- * must start with a letter and doesnt have an underscore
- * as the last character.
+ /** renderer description.
+ * \ingroup loader
+ */
+ struct csri_info {
+ /** an identifier for the renderer.
+ * - MUST match the regular expression
+ * \code ^[a-zA-Z]([a-zA-Z0-9_]*[a-zA-Z0-9])? \endcode
+ * i.e. consists only of letters, numbers and underscores;
+ * must start with a letter and doesnt have an underscore
+ * as the last character.
+ */
+ const char *name;
+ /** an identifier to the exact version of the renderer.
+ * most likely a version number or revision identifier.
+ *
+ * The helper library does a strcmp over this field in order
+ * to order multiple instances of the same renderer. Use
+ * higher-byte-value strings for newer renderers.
+ */
+ const char *specific;
+
+ /** a nice name to be presented to the user */
+ const char *longname;
+ /** the renderer's author */
+ const char *author;
+ /** a copyright string. Copyright (c) 2042 by Mr. Nice Guy */
+ const char *copyright;
+ };
+
+ /** data of extension-dependent type.
+ * The field to be used MUST be specified in the extension where it is used.
*/
- const char *name;
- /** an identifier to the exact version of the renderer.
- * most likely a version number or revision identifier.
+ union csri_vardata {
+ long lval;
+ double dval;
+ const char *utf8val;
+ void *otherval;
+ };
+
+ /** extension identifier.
+ * This follows reverse DNS syntax, i.e.:
+ * \code root.branch.leaf \endcode
+ * you can either reverse a registered domain name, e.g.
+ * \code com.microsoft.csri.usegdiplus \endcode
+ * or ask the CSRI maintainers to assign a namespace to you.
*
- * The helper library does a strcmp over this field in order
- * to order multiple instances of the same renderer. Use
- * higher-byte-value strings for newer renderers.
+ * currently registered namespaces are:
+ *
+ * \code
+ * csri.* - official extensions
+ * asa.* - custom extensions of the asa renderer
+ * \endcode
*/
- const char *specific;
-
- /** a nice name to be presented to the user */
- const char *longname;
- /** the renderer's author */
- const char *author;
- /** a copyright string. Copyright (c) 2042 by Mr. Nice Guy */
- const char *copyright;
-};
-
-/** data of extension-dependent type.
- * The field to be used MUST be specified in the extension where it is used.
- */
-union csri_vardata {
- long lval;
- double dval;
- const char *utf8val;
- void *otherval;
-};
-
-/** extension identifier.
- * This follows reverse DNS syntax, i.e.:
- * \code root.branch.leaf \endcode
- * you can either reverse a registered domain name, e.g.
- * \code com.microsoft.csri.usegdiplus \endcode
- * or ask the CSRI maintainers to assign a namespace to you.
- *
- * currently registered namespaces are:
- *
- * \code
- * csri.* - official extensions
- * asa.* - custom extensions of the asa renderer
- * \endcode
- */
-typedef const char *csri_ext_id;
-
-/** script loading parameters.
- * each flag MUST have an associated extension, which can be queried
- * with csri_query_ext(). If the open flag constitutes an extension on its
- * sole own, csri_query_ext() can return a meaningless non-NULL value for
- * it.
- *
- * The data field used must be specified.
- *
- * An extension can have multiple flags. In that case, the flags should have
- * the extension name as common prefix, separated with a dot.
- *
- * A renderer MUST ignore unknown open flags. It MUST NOT return an error
- * just because it does not support a particular flag.
- */
-struct csri_openflag {
- /** flag name */
- csri_ext_id name;
- /** flag data argument */
- union csri_vardata data;
- /** link to next flag */
- struct csri_openflag *next;
-};
-
-/** load a script from a file.
- * \param renderer the handle to the renderer
- * \param filename the path to the file to be loaded. \n
- * The filename should be encoded as UTF-8. Windows renderers are
- * expected to convert it to UTF-16 and use the Unicode Windows API
- * functions.
- * \param flags a linked list of open flags. \n
- * The caller manages memory allocation, i.e. static allocation is OK.
- * \return the renderer instance handle, or NULL on error.
- */
-CSRIAPI csri_inst *csri_open_file(csri_rend *renderer,
- const char *filename, struct csri_openflag *flags);
-
-/** load a script from memory.
- * \param renderer the handle to the renderer
- * \param data pointer to the first data byte. \n
- * The caller manages memory allocation and should free the data after
- * calling csri_open_mem(). If the renderer needs to keep the data, it
- * must copy it. \n
- * The renderer is not allowed to write to the data.
- * \param length length, in bytes, of the data
- * \param flags see csri_open_file()
- * \return the render instance handle, or NULL on error.
- */
-
-CSRIAPI csri_inst *csri_open_mem(csri_rend *renderer,
- const void *data, size_t length, struct csri_openflag *flags);
-
-/** close a renderer instance.
- * \param inst the instance handle.
- */
-CSRIAPI void csri_close(csri_inst *inst);
-
-
-/** query / set the image format and size.
- * \param inst the renderer instance handle
- * \param fmt the format and image size to be used
- * \return 0 if the format was successfully set,
- * any other value in case of error.
- */
-CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt);
-
-/** render a single frame
- * \param inst the renderer instance handle
- * \param frame frame data to render to
- * \param time associated timestamp of the frame
- */
-CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame,
- double time);
-
-
-/** query for an extension.
- * \param rend the renderer handle
- * \param extname the extension's identifier
- * \return NULL if the extension is not supported,
- * a pointer to extension-specific data otherwise
- *
- * The data pointed to by the return value does not neccessarily need to
- * have any meaning; An extension that does not need to return data
- * can return a pointer to whatever it wants, as long as that pointer is
- * not NULL.
- *
- * In the usual case, the pointer is supposed to point to a struct with
- * function pointers and other information as needed.
- */
-CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname);
+ typedef const char *csri_ext_id;
-/*@}*/
+ /** script loading parameters.
+ * each flag MUST have an associated extension, which can be queried
+ * with csri_query_ext(). If the open flag constitutes an extension on its
+ * sole own, csri_query_ext() can return a meaningless non-NULL value for
+ * it.
+ *
+ * The data field used must be specified.
+ *
+ * An extension can have multiple flags. In that case, the flags should have
+ * the extension name as common prefix, separated with a dot.
+ *
+ * A renderer MUST ignore unknown open flags. It MUST NOT return an error
+ * just because it does not support a particular flag.
+ */
+ struct csri_openflag {
+ /** flag name */
+ csri_ext_id name;
+ /** flag data argument */
+ union csri_vardata data;
+ /** link to next flag */
+ struct csri_openflag *next;
+ };
+
+ /** load a script from a file.
+ * \param renderer the handle to the renderer
+ * \param filename the path to the file to be loaded. \n
+ * The filename should be encoded as UTF-8. Windows renderers are
+ * expected to convert it to UTF-16 and use the Unicode Windows API
+ * functions.
+ * \param flags a linked list of open flags. \n
+ * The caller manages memory allocation, i.e. static allocation is OK.
+ * \return the renderer instance handle, or NULL on error.
+ */
+ CSRIAPI csri_inst *csri_open_file(csri_rend *renderer,
+ const char *filename, struct csri_openflag *flags);
+
+ /** load a script from memory.
+ * \param renderer the handle to the renderer
+ * \param data pointer to the first data byte. \n
+ * The caller manages memory allocation and should free the data after
+ * calling csri_open_mem(). If the renderer needs to keep the data, it
+ * must copy it. \n
+ * The renderer is not allowed to write to the data.
+ * \param length length, in bytes, of the data
+ * \param flags see csri_open_file()
+ * \return the render instance handle, or NULL on error.
+ */
-/** \defgroup loader CSRI loader API.
- *
- * These functions locate renderers based on given parameters.
- *
- * <b>Renderers must implement these functions as well.</b>
- *
- * They are used by the library to grab renderer information
- * from a shared object; and also this way a single renderer
- * can be linked directly into an appliaction.
- */
-/*@{*/
-
-/** get renderer information
- * \param rend the renderer handle
- * \return information about the renderer, or NULL in case the renderer
- * encountered an internal error.
- */
-CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend);
-
-/** try to load a given renderer
- * \param name the name of the renderer, as in csri_info.name
- * \param specific the specific version of the renderer,
- * as in csri_info.specific;\n
- * alternatively NULL if any version of the renderer is ok.
- * \return a handle to the renderer if it was successfully loaded,
- * NULL otherwise.
- */
-CSRIAPI csri_rend *csri_renderer_byname(const char *name,
- const char *specific);
-
-/** try to find an implementation of the given extensions.
- * \param next number of extensions pointed to by ext
- * \param ext array of extensions to search for
- * \return a handle to a renderer supporting ALL of the
- * extensions, NULL if none was found.
- */
-CSRIAPI csri_rend *csri_renderer_byext(unsigned n_ext, csri_ext_id *ext);
-
-/** get the default (highest priority) renderer
- * \return a handle to the default renderer, or NULL if
- * no renderer is installed.
- *
- * Together with csri_renderer_next(), this can be used
- * to enumerate all installed renderers.
- */
-CSRIAPI csri_rend *csri_renderer_default();
-
-/** get the next lower priority renderer
- * \param prev the current renderer
- * \return the renderer with the next lower priority than
- * the one named in prev, or NULL if prev is the last
- * renderer installed.
- */
-CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev);
-
-/*@}*/
+ CSRIAPI csri_inst *csri_open_mem(csri_rend *renderer,
+ const void *data, size_t length, struct csri_openflag *flags);
+
+ /** close a renderer instance.
+ * \param inst the instance handle.
+ */
+ CSRIAPI void csri_close(csri_inst *inst);
+
+
+ /** query / set the image format and size.
+ * \param inst the renderer instance handle
+ * \param fmt the format and image size to be used
+ * \return 0 if the format was successfully set,
+ * any other value in case of error.
+ */
+ CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt);
+
+ /** render a single frame
+ * \param inst the renderer instance handle
+ * \param frame frame data to render to
+ * \param time associated timestamp of the frame
+ */
+ CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame,
+ double time);
+
+
+ /** query for an extension.
+ * \param rend the renderer handle
+ * \param extname the extension's identifier
+ * \return NULL if the extension is not supported,
+ * a pointer to extension-specific data otherwise
+ *
+ * The data pointed to by the return value does not neccessarily need to
+ * have any meaning; An extension that does not need to return data
+ * can return a pointer to whatever it wants, as long as that pointer is
+ * not NULL.
+ *
+ * In the usual case, the pointer is supposed to point to a struct with
+ * function pointers and other information as needed.
+ */
+ CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname);
+
+ /*@}*/
+
+ /** \defgroup loader CSRI loader API.
+ *
+ * These functions locate renderers based on given parameters.
+ *
+ * <b>Renderers must implement these functions as well.</b>
+ *
+ * They are used by the library to grab renderer information
+ * from a shared object; and also this way a single renderer
+ * can be linked directly into an appliaction.
+ */
+ /*@{*/
+
+ /** get renderer information
+ * \param rend the renderer handle
+ * \return information about the renderer, or NULL in case the renderer
+ * encountered an internal error.
+ */
+ CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend);
+
+ /** try to load a given renderer
+ * \param name the name of the renderer, as in csri_info.name
+ * \param specific the specific version of the renderer,
+ * as in csri_info.specific;\n
+ * alternatively NULL if any version of the renderer is ok.
+ * \return a handle to the renderer if it was successfully loaded,
+ * NULL otherwise.
+ */
+ CSRIAPI csri_rend *csri_renderer_byname(const char *name,
+ const char *specific);
+
+ /** try to find an implementation of the given extensions.
+ * \param next number of extensions pointed to by ext
+ * \param ext array of extensions to search for
+ * \return a handle to a renderer supporting ALL of the
+ * extensions, NULL if none was found.
+ */
+ CSRIAPI csri_rend *csri_renderer_byext(unsigned n_ext, csri_ext_id *ext);
+
+ /** get the default (highest priority) renderer
+ * \return a handle to the default renderer, or NULL if
+ * no renderer is installed.
+ *
+ * Together with csri_renderer_next(), this can be used
+ * to enumerate all installed renderers.
+ */
+ CSRIAPI csri_rend *csri_renderer_default();
+
+ /** get the next lower priority renderer
+ * \param prev the current renderer
+ * \return the renderer with the next lower priority than
+ * the one named in prev, or NULL if prev is the last
+ * renderer installed.
+ */
+ CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev);
+
+ /*@}*/
#ifdef __cplusplus
}
diff --git a/src/filters/transform/VSFilter/csriapi.cpp b/src/filters/transform/VSFilter/csriapi.cpp
index 059c02c84..498c1d592 100644
--- a/src/filters/transform/VSFilter/csriapi.cpp
+++ b/src/filters/transform/VSFilter/csriapi.cpp
@@ -54,8 +54,9 @@ CSRIAPI csri_inst *csri_open_file(csri_rend *renderer, const char *filename, str
wchar_t *namebuf;
namesize = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
- if (!namesize)
+ if (!namesize) {
return 0;
+ }
namesize++;
namebuf = new wchar_t[namesize];
MultiByteToWideChar(CP_UTF8, 0, filename, -1, namebuf, namesize);
@@ -98,7 +99,9 @@ CSRIAPI csri_inst *csri_open_mem(csri_rend *renderer, const void *data, size_t l
CSRIAPI void csri_close(csri_inst *inst)
{
- if (!inst) return;
+ if (!inst) {
+ return;
+ }
delete inst->rts;
delete inst->cs;
@@ -108,10 +111,13 @@ CSRIAPI void csri_close(csri_inst *inst)
CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt)
{
- if (!inst) return -1;
+ if (!inst) {
+ return -1;
+ }
- if (!fmt->width || !fmt->height)
+ if (!fmt->width || !fmt->height) {
return -1;
+ }
// Check if pixel format is supported
switch (fmt->pixfmt) {
@@ -188,18 +194,18 @@ CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname)
// Get info for renderer
static struct csri_info csri_vsfilter_info = {
#ifdef _DEBUG
- #ifdef _VSMOD
- "vsfiltermod_textsub_debug", // name
- #else
- "vsfilter_textsub_debug", // name
- #endif
+#ifdef _VSMOD
+ "vsfiltermod_textsub_debug", // name
+#else
+ "vsfilter_textsub_debug", // name
+#endif
"2.40", // version (assumed version number, svn revision, patchlevel)
#else
- #ifdef _VSMOD
- "vsfiltermod_textsub", // name
- #else
- "vsfilter_textsub", // name
- #endif
+#ifdef _VSMOD
+ "vsfiltermod_textsub", // name
+#else
+ "vsfilter_textsub", // name
+#endif
"2.40", // version (assumed version number, svn revision, patchlevel)
#endif
// 2.38-0611 is base svn 611
@@ -216,17 +222,18 @@ static struct csri_info csri_vsfilter_info = {
"Gabest", // author
"Copyright (c) 2003-2010 by Gabest and others" // copyright
};
-CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend)
-{
+CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend) {
return &csri_vsfilter_info;
}
// Only one supported, obviously
CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific)
{
- if (strcmp(name, csri_vsfilter_info.name))
+ if (strcmp(name, csri_vsfilter_info.name)) {
return 0;
- if (specific && strcmp(specific, csri_vsfilter_info.specific))
+ }
+ if (specific && strcmp(specific, csri_vsfilter_info.specific)) {
return 0;
+ }
return &csri_vsfilter;
}
// Still just one
diff --git a/src/filters/transform/VSFilter/plugins.cpp b/src/filters/transform/VSFilter/plugins.cpp
index 9f7146b1f..6e4732c0c 100644
--- a/src/filters/transform/VSFilter/plugins.cpp
+++ b/src/filters/transform/VSFilter/plugins.cpp
@@ -39,1104 +39,1102 @@
namespace Plugin
{
-class CFilter : public CAMThread, public CCritSec
-{
-private:
- CString m_fn;
-
-protected:
- float m_fps;
- CCritSec m_csSubLock;
- CComPtr<ISubPicQueue> m_pSubPicQueue;
- CComPtr<ISubPicProvider> m_pSubPicProvider;
- DWORD_PTR m_SubPicProviderId;
-
-public:
- CFilter() : m_fps(-1), m_SubPicProviderId(0) {
- CAMThread::Create();
- }
- virtual ~CFilter() {
- CAMThread::CallWorker(0);
- }
+ class CFilter : public CAMThread, public CCritSec
+ {
+ private:
+ CString m_fn;
+
+ protected:
+ float m_fps;
+ CCritSec m_csSubLock;
+ CComPtr<ISubPicQueue> m_pSubPicQueue;
+ CComPtr<ISubPicProvider> m_pSubPicProvider;
+ DWORD_PTR m_SubPicProviderId;
+
+ public:
+ CFilter() : m_fps(-1), m_SubPicProviderId(0) {
+ CAMThread::Create();
+ }
+ virtual ~CFilter() {
+ CAMThread::CallWorker(0);
+ }
- CString GetFileName() {
- CAutoLock cAutoLock(this);
- return m_fn;
- }
- void SetFileName(CString fn) {
- CAutoLock cAutoLock(this);
- m_fn = fn;
- }
+ CString GetFileName() {
+ CAutoLock cAutoLock(this);
+ return m_fn;
+ }
+ void SetFileName(CString fn) {
+ CAutoLock cAutoLock(this);
+ m_fn = fn;
+ }
- bool Render(SubPicDesc& dst, REFERENCE_TIME rt, float fps)
- {
- if(!m_pSubPicProvider)
- return(false);
+ bool Render(SubPicDesc& dst, REFERENCE_TIME rt, float fps) {
+ if(!m_pSubPicProvider) {
+ return(false);
+ }
- CSize size(dst.w, dst.h);
+ CSize size(dst.w, dst.h);
- if(!m_pSubPicQueue)
- {
- CComPtr<ISubPicAllocator> pAllocator = new CMemSubPicAllocator(dst.type, size);
+ if(!m_pSubPicQueue) {
+ CComPtr<ISubPicAllocator> pAllocator = new CMemSubPicAllocator(dst.type, size);
+
+ HRESULT hr;
+ if(!(m_pSubPicQueue = new CSubPicQueueNoThread(pAllocator, &hr)) || FAILED(hr)) {
+ m_pSubPicQueue = NULL;
+ return(false);
+ }
+ }
+
+ if(m_SubPicProviderId != (DWORD_PTR)(ISubPicProvider*)m_pSubPicProvider) {
+ m_pSubPicQueue->SetSubPicProvider(m_pSubPicProvider);
+ m_SubPicProviderId = (DWORD_PTR)(ISubPicProvider*)m_pSubPicProvider;
+ }
- HRESULT hr;
- if(!(m_pSubPicQueue = new CSubPicQueueNoThread(pAllocator, &hr)) || FAILED(hr))
- {
- m_pSubPicQueue = NULL;
+ CComPtr<ISubPic> pSubPic;
+ if(!m_pSubPicQueue->LookupSubPic(rt, pSubPic)) {
return(false);
}
- }
- if(m_SubPicProviderId != (DWORD_PTR)(ISubPicProvider*)m_pSubPicProvider)
- {
- m_pSubPicQueue->SetSubPicProvider(m_pSubPicProvider);
- m_SubPicProviderId = (DWORD_PTR)(ISubPicProvider*)m_pSubPicProvider;
- }
+ CRect r;
+ pSubPic->GetDirtyRect(r);
- CComPtr<ISubPic> pSubPic;
- if(!m_pSubPicQueue->LookupSubPic(rt, pSubPic))
- return(false);
+ if(dst.type == MSP_RGB32 || dst.type == MSP_RGB24 || dst.type == MSP_RGB16 || dst.type == MSP_RGB15) {
+ dst.h = -dst.h;
+ }
- CRect r;
- pSubPic->GetDirtyRect(r);
+ pSubPic->AlphaBlt(r, r, &dst);
- if(dst.type == MSP_RGB32 || dst.type == MSP_RGB24 || dst.type == MSP_RGB16 || dst.type == MSP_RGB15)
- dst.h = -dst.h;
+ return(true);
+ }
- pSubPic->AlphaBlt(r, r, &dst);
+ DWORD ThreadProc() {
+ SetThreadPriority(m_hThread, THREAD_PRIORITY_LOWEST);
- return(true);
- }
+ CAtlArray<HANDLE> handles;
+ handles.Add(GetRequestHandle());
- DWORD ThreadProc()
- {
- SetThreadPriority(m_hThread, THREAD_PRIORITY_LOWEST);
+ CString fn = GetFileName();
+ CFileStatus fs;
+ fs.m_mtime = 0;
+ CFileGetStatus(fn, fs);
- CAtlArray<HANDLE> handles;
- handles.Add(GetRequestHandle());
+ while(1) {
+ DWORD i = WaitForMultipleObjects(handles.GetCount(), handles.GetData(), FALSE, 1000);
- CString fn = GetFileName();
- CFileStatus fs;
- fs.m_mtime = 0;
- CFileGetStatus(fn, fs);
+ if(WAIT_OBJECT_0 == i) {
+ Reply(S_OK);
+ break;
+ } else if(WAIT_OBJECT_0 + 1 >= i && i <= WAIT_OBJECT_0 + handles.GetCount()) {
+ if(FindNextChangeNotification(handles[i - WAIT_OBJECT_0])) {
+ CFileStatus fs2;
+ fs2.m_mtime = 0;
+ CFileGetStatus(fn, fs2);
- while(1)
- {
- DWORD i = WaitForMultipleObjects(handles.GetCount(), handles.GetData(), FALSE, 1000);
+ if(fs.m_mtime < fs2.m_mtime) {
+ fs.m_mtime = fs2.m_mtime;
- if(WAIT_OBJECT_0 == i)
- {
- Reply(S_OK);
- break;
- }
- else if(WAIT_OBJECT_0 + 1 >= i && i <= WAIT_OBJECT_0 + handles.GetCount())
- {
- if(FindNextChangeNotification(handles[i - WAIT_OBJECT_0]))
- {
- CFileStatus fs2;
- fs2.m_mtime = 0;
- CFileGetStatus(fn, fs2);
-
- if(fs.m_mtime < fs2.m_mtime)
- {
- fs.m_mtime = fs2.m_mtime;
-
- if(CComQIPtr<ISubStream> pSubStream = m_pSubPicProvider)
- {
- CAutoLock cAutoLock(&m_csSubLock);
- pSubStream->Reload();
+ if(CComQIPtr<ISubStream> pSubStream = m_pSubPicProvider) {
+ CAutoLock cAutoLock(&m_csSubLock);
+ pSubStream->Reload();
+ }
}
}
- }
- }
- else if(WAIT_TIMEOUT == i)
- {
- CString fn2 = GetFileName();
-
- if(fn != fn2)
- {
- CPath p(fn2);
- p.RemoveFileSpec();
- HANDLE h = FindFirstChangeNotification(p, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
- if(h != INVALID_HANDLE_VALUE)
- {
- fn = fn2;
- handles.SetCount(1);
- handles.Add(h);
+ } else if(WAIT_TIMEOUT == i) {
+ CString fn2 = GetFileName();
+
+ if(fn != fn2) {
+ CPath p(fn2);
+ p.RemoveFileSpec();
+ HANDLE h = FindFirstChangeNotification(p, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
+ if(h != INVALID_HANDLE_VALUE) {
+ fn = fn2;
+ handles.SetCount(1);
+ handles.Add(h);
+ }
}
+ } else { // if(WAIT_ABANDONED_0 == i || WAIT_FAILED == i)
+ break;
}
}
- else // if(WAIT_ABANDONED_0 == i || WAIT_FAILED == i)
- {
- break;
- }
- }
- m_hThread = 0;
+ m_hThread = 0;
- for(ptrdiff_t i = 1; i < handles.GetCount(); i++)
- FindCloseChangeNotification(handles[i]);
-
- return 0;
- }
-};
+ for(ptrdiff_t i = 1; i < handles.GetCount(); i++) {
+ FindCloseChangeNotification(handles[i]);
+ }
-class CVobSubFilter : virtual public CFilter
-{
-public:
- CVobSubFilter(CString fn = _T(""))
- {
- if(!fn.IsEmpty()) Open(fn);
- }
+ return 0;
+ }
+ };
- bool Open(CString fn)
+ class CVobSubFilter : virtual public CFilter
{
- SetFileName(_T(""));
- m_pSubPicProvider = NULL;
-
- if(CVobSubFile* vsf = new CVobSubFile(&m_csSubLock))
- {
- m_pSubPicProvider = (ISubPicProvider*)vsf;
- if(vsf->Open(CString(fn))) SetFileName(fn);
- else m_pSubPicProvider = NULL;
+ public:
+ CVobSubFilter(CString fn = _T("")) {
+ if(!fn.IsEmpty()) {
+ Open(fn);
+ }
}
- return !!m_pSubPicProvider;
- }
-};
-
-class CTextSubFilter : virtual public CFilter
-{
- int m_CharSet;
+ bool Open(CString fn) {
+ SetFileName(_T(""));
+ m_pSubPicProvider = NULL;
-public:
- CTextSubFilter(CString fn = _T(""), int CharSet = DEFAULT_CHARSET, float fps = -1)
- : m_CharSet(CharSet)
- {
- m_fps = fps;
- if(!fn.IsEmpty()) Open(fn, CharSet);
- }
+ if(CVobSubFile* vsf = new CVobSubFile(&m_csSubLock)) {
+ m_pSubPicProvider = (ISubPicProvider*)vsf;
+ if(vsf->Open(CString(fn))) {
+ SetFileName(fn);
+ } else {
+ m_pSubPicProvider = NULL;
+ }
+ }
- int GetCharSet() {
- return(m_CharSet);
- }
+ return !!m_pSubPicProvider;
+ }
+ };
- bool Open(CString fn, int CharSet = DEFAULT_CHARSET)
+ class CTextSubFilter : virtual public CFilter
{
- SetFileName(_T(""));
- m_pSubPicProvider = NULL;
-
- if(!m_pSubPicProvider)
- {
- if(ssf::CRenderer* ssf = new ssf::CRenderer(&m_csSubLock))
- {
- m_pSubPicProvider = (ISubPicProvider*)ssf;
- if(ssf->Open(CString(fn))) SetFileName(fn);
- else m_pSubPicProvider = NULL;
+ int m_CharSet;
+
+ public:
+ CTextSubFilter(CString fn = _T(""), int CharSet = DEFAULT_CHARSET, float fps = -1)
+ : m_CharSet(CharSet) {
+ m_fps = fps;
+ if(!fn.IsEmpty()) {
+ Open(fn, CharSet);
}
}
- if(!m_pSubPicProvider)
- {
- if(CRenderedTextSubtitle* rts = new CRenderedTextSubtitle(&m_csSubLock))
- {
- m_pSubPicProvider = (ISubPicProvider*)rts;
- if(rts->Open(CString(fn), CharSet)) SetFileName(fn);
- else m_pSubPicProvider = NULL;
- }
+ int GetCharSet() {
+ return(m_CharSet);
}
- return !!m_pSubPicProvider;
- }
-};
-
-#ifndef WIN64
-//
-// old VirtualDub interface
-//
-
-namespace VirtualDub
-{
-//#include <VirtualDub\VirtualDub.h>
-//#include <vd2/OldFilterSDK/VirtualDub.h>
-#include <vd2/extras/FilterSDK/VirtualDub.h>
-
-class CVirtualDubFilter : virtual public CFilter
-{
-public:
- CVirtualDubFilter() {}
- virtual ~CVirtualDubFilter() {}
-
- virtual int RunProc(const FilterActivation* fa, const FilterFunctions* ff)
- {
- SubPicDesc dst;
- dst.type = MSP_RGB32;
- dst.w = fa->src.w;
- dst.h = fa->src.h;
- dst.bpp = 32;
- dst.pitch = fa->src.pitch;
- dst.bits = (LPVOID)fa->src.data;
-
- Render(dst, 10000i64*fa->pfsi->lSourceFrameMS, (float)1000 / fa->pfsi->lMicrosecsPerFrame);
-
- return 0;
- }
-
- virtual long ParamProc(FilterActivation* fa, const FilterFunctions* ff)
- {
- fa->dst.offset = fa->src.offset;
- fa->dst.modulo = fa->src.modulo;
- fa->dst.pitch = fa->src.pitch;
+ bool Open(CString fn, int CharSet = DEFAULT_CHARSET) {
+ SetFileName(_T(""));
+ m_pSubPicProvider = NULL;
+
+ if(!m_pSubPicProvider) {
+ if(ssf::CRenderer* ssf = new ssf::CRenderer(&m_csSubLock)) {
+ m_pSubPicProvider = (ISubPicProvider*)ssf;
+ if(ssf->Open(CString(fn))) {
+ SetFileName(fn);
+ } else {
+ m_pSubPicProvider = NULL;
+ }
+ }
+ }
- return 0;
- }
+ if(!m_pSubPicProvider) {
+ if(CRenderedTextSubtitle* rts = new CRenderedTextSubtitle(&m_csSubLock)) {
+ m_pSubPicProvider = (ISubPicProvider*)rts;
+ if(rts->Open(CString(fn), CharSet)) {
+ SetFileName(fn);
+ } else {
+ m_pSubPicProvider = NULL;
+ }
+ }
+ }
- virtual int ConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd) = 0;
- virtual void StringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str) = 0;
- virtual bool FssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen) = 0;
-};
+ return !!m_pSubPicProvider;
+ }
+ };
-class CVobSubVirtualDubFilter : public CVobSubFilter, public CVirtualDubFilter
-{
-public:
- CVobSubVirtualDubFilter(CString fn = _T(""))
- : CVobSubFilter(fn) {}
+#ifndef WIN64
+ //
+ // old VirtualDub interface
+ //
- int ConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd)
+ namespace VirtualDub
{
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ //#include <VirtualDub\VirtualDub.h>
+ //#include <vd2/OldFilterSDK/VirtualDub.h>
+#include <vd2/extras/FilterSDK/VirtualDub.h>
- CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY,
- _T("VobSub files (*.idx;*.sub)|*.idx;*.sub||"), CWnd::FromHandle(hwnd), 0);
+ class CVirtualDubFilter : virtual public CFilter
+ {
+ public:
+ CVirtualDubFilter() {}
+ virtual ~CVirtualDubFilter() {}
+
+ virtual int RunProc(const FilterActivation* fa, const FilterFunctions* ff) {
+ SubPicDesc dst;
+ dst.type = MSP_RGB32;
+ dst.w = fa->src.w;
+ dst.h = fa->src.h;
+ dst.bpp = 32;
+ dst.pitch = fa->src.pitch;
+ dst.bits = (LPVOID)fa->src.data;
+
+ Render(dst, 10000i64*fa->pfsi->lSourceFrameMS, (float)1000 / fa->pfsi->lMicrosecsPerFrame);
+
+ return 0;
+ }
- if(fd.DoModal() != IDOK) return 1;
+ virtual long ParamProc(FilterActivation* fa, const FilterFunctions* ff) {
+ fa->dst.offset = fa->src.offset;
+ fa->dst.modulo = fa->src.modulo;
+ fa->dst.pitch = fa->src.pitch;
- return Open(fd.GetPathName()) ? 0 : 1;
- }
+ return 0;
+ }
- void StringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str)
- {
- sprintf(str, " (%s)", !GetFileName().IsEmpty() ? CStringA(GetFileName()) : " (empty)");
- }
+ virtual int ConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd) = 0;
+ virtual void StringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str) = 0;
+ virtual bool FssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen) = 0;
+ };
- bool FssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen)
- {
- CStringA fn(GetFileName());
- fn.Replace("\\", "\\\\");
- _snprintf(buf, buflen, "Config(\"%s\")", fn);
- return(true);
- }
-};
+ class CVobSubVirtualDubFilter : public CVobSubFilter, public CVirtualDubFilter
+ {
+ public:
+ CVobSubVirtualDubFilter(CString fn = _T(""))
+ : CVobSubFilter(fn) {}
-class CTextSubVirtualDubFilter : public CTextSubFilter, public CVirtualDubFilter
-{
-public:
- CTextSubVirtualDubFilter(CString fn = _T(""), int CharSet = DEFAULT_CHARSET)
- : CTextSubFilter(fn, CharSet) {}
+ int ConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
- int ConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY,
+ _T("VobSub files (*.idx;*.sub)|*.idx;*.sub||"), CWnd::FromHandle(hwnd), 0);
- const TCHAR formats[] = _T("TextSub files (*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt)|*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt||");
- CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_ENABLETEMPLATE|OFN_ENABLEHOOK,
- formats, CWnd::FromHandle(hwnd), sizeof(OPENFILENAME));
- //OPENFILENAME_SIZE_VERSION_400 /*0* /);
- UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
+ if(fd.DoModal() != IDOK) {
+ return 1;
+ }
- fd.m_pOFN->hInstance = AfxGetResourceHandle();
- fd.m_pOFN->lpTemplateName = MAKEINTRESOURCE(IDD_TEXTSUBOPENTEMPLATE);
- fd.m_pOFN->lpfnHook = (LPOFNHOOKPROC)OpenHookProc;
- fd.m_pOFN->lCustData = (LPARAM)DEFAULT_CHARSET;
+ return Open(fd.GetPathName()) ? 0 : 1;
+ }
- if(fd.DoModal() != IDOK) return 1;
+ void StringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str) {
+ sprintf(str, " (%s)", !GetFileName().IsEmpty() ? CStringA(GetFileName()) : " (empty)");
+ }
- return Open(fd.GetPathName(), fd.m_pOFN->lCustData) ? 0 : 1;
- }
+ bool FssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen) {
+ CStringA fn(GetFileName());
+ fn.Replace("\\", "\\\\");
+ _snprintf(buf, buflen, "Config(\"%s\")", fn);
+ return(true);
+ }
+ };
- void StringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str)
- {
- if(!GetFileName().IsEmpty()) sprintf(str, " (%s, %d)", CStringA(GetFileName()), GetCharSet());
- else sprintf(str, " (empty)");
- }
+ class CTextSubVirtualDubFilter : public CTextSubFilter, public CVirtualDubFilter
+ {
+ public:
+ CTextSubVirtualDubFilter(CString fn = _T(""), int CharSet = DEFAULT_CHARSET)
+ : CTextSubFilter(fn, CharSet) {}
+
+ int ConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
+
+ const TCHAR formats[] = _T("TextSub files (*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt)|*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt||");
+ CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_ENABLETEMPLATE|OFN_ENABLEHOOK,
+ formats, CWnd::FromHandle(hwnd), sizeof(OPENFILENAME));
+ //OPENFILENAME_SIZE_VERSION_400 /*0* /);
+ UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
+
+ fd.m_pOFN->hInstance = AfxGetResourceHandle();
+ fd.m_pOFN->lpTemplateName = MAKEINTRESOURCE(IDD_TEXTSUBOPENTEMPLATE);
+ fd.m_pOFN->lpfnHook = (LPOFNHOOKPROC)OpenHookProc;
+ fd.m_pOFN->lCustData = (LPARAM)DEFAULT_CHARSET;
+
+ if(fd.DoModal() != IDOK) {
+ return 1;
+ }
- bool FssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen)
- {
- CStringA fn(GetFileName());
- fn.Replace("\\", "\\\\");
- _snprintf(buf, buflen, "Config(\"%s\", %d)", fn, GetCharSet());
- return(true);
- }
-};
+ return Open(fd.GetPathName(), fd.m_pOFN->lCustData) ? 0 : 1;
+ }
-int vobsubInitProc(FilterActivation* fa, const FilterFunctions* ff)
-{
- *(CVirtualDubFilter**)fa->filter_data = new CVobSubVirtualDubFilter();
- return !(*(CVirtualDubFilter**)fa->filter_data);
-}
+ void StringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str) {
+ if(!GetFileName().IsEmpty()) {
+ sprintf(str, " (%s, %d)", CStringA(GetFileName()), GetCharSet());
+ } else {
+ sprintf(str, " (empty)");
+ }
+ }
-int textsubInitProc(FilterActivation* fa, const FilterFunctions* ff)
-{
- *(CVirtualDubFilter**)fa->filter_data = new CTextSubVirtualDubFilter();
- return !(*(CVirtualDubFilter**)fa->filter_data);
-}
+ bool FssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen) {
+ CStringA fn(GetFileName());
+ fn.Replace("\\", "\\\\");
+ _snprintf(buf, buflen, "Config(\"%s\", %d)", fn, GetCharSet());
+ return(true);
+ }
+ };
-void baseDeinitProc(FilterActivation* fa, const FilterFunctions* ff)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) delete f, f = NULL;
-}
+ int vobsubInitProc(FilterActivation* fa, const FilterFunctions* ff)
+ {
+ *(CVirtualDubFilter**)fa->filter_data = new CVobSubVirtualDubFilter();
+ return !(*(CVirtualDubFilter**)fa->filter_data);
+ }
-int baseRunProc(const FilterActivation* fa, const FilterFunctions* ff)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->RunProc(fa, ff) : 1;
-}
+ int textsubInitProc(FilterActivation* fa, const FilterFunctions* ff)
+ {
+ *(CVirtualDubFilter**)fa->filter_data = new CTextSubVirtualDubFilter();
+ return !(*(CVirtualDubFilter**)fa->filter_data);
+ }
-long baseParamProc(FilterActivation* fa, const FilterFunctions* ff)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->ParamProc(fa, ff) : 1;
-}
+ void baseDeinitProc(FilterActivation* fa, const FilterFunctions* ff)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ delete f, f = NULL;
+ }
+ }
-int baseConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->ConfigProc(fa, ff, hwnd) : 1;
-}
+ int baseRunProc(const FilterActivation* fa, const FilterFunctions* ff)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->RunProc(fa, ff) : 1;
+ }
-void baseStringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) f->StringProc(fa, ff, str);
-}
+ long baseParamProc(FilterActivation* fa, const FilterFunctions* ff)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->ParamProc(fa, ff) : 1;
+ }
-bool baseFssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->FssProc(fa, ff, buf, buflen) : false;
-}
+ int baseConfigProc(FilterActivation* fa, const FilterFunctions* ff, HWND hwnd)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->ConfigProc(fa, ff, hwnd) : 1;
+ }
-void vobsubScriptConfig(IScriptInterpreter* isi, void* lpVoid, CScriptValue* argv, int argc)
-{
- FilterActivation* fa = (FilterActivation*)lpVoid;
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) delete f;
- f = new CVobSubVirtualDubFilter(CString(*argv[0].asString()));
- *(CVirtualDubFilter**)fa->filter_data = f;
-}
+ void baseStringProc(const FilterActivation* fa, const FilterFunctions* ff, char* str)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ f->StringProc(fa, ff, str);
+ }
+ }
-void textsubScriptConfig(IScriptInterpreter* isi, void* lpVoid, CScriptValue* argv, int argc)
-{
- FilterActivation* fa = (FilterActivation*)lpVoid;
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) delete f;
- f = new CTextSubVirtualDubFilter(CString(*argv[0].asString()), argv[1].asInt());
- *(CVirtualDubFilter**)fa->filter_data = f;
-}
+ bool baseFssProc(FilterActivation* fa, const FilterFunctions* ff, char* buf, int buflen)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->FssProc(fa, ff, buf, buflen) : false;
+ }
-ScriptFunctionDef vobsub_func_defs[]= {
- { (ScriptFunctionPtr)vobsubScriptConfig, "Config", "0s" },
- { NULL },
-};
+ void vobsubScriptConfig(IScriptInterpreter* isi, void* lpVoid, CScriptValue* argv, int argc)
+ {
+ FilterActivation* fa = (FilterActivation*)lpVoid;
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ delete f;
+ }
+ f = new CVobSubVirtualDubFilter(CString(*argv[0].asString()));
+ *(CVirtualDubFilter**)fa->filter_data = f;
+ }
-CScriptObject vobsub_obj= {
- NULL, vobsub_func_defs
-};
+ void textsubScriptConfig(IScriptInterpreter* isi, void* lpVoid, CScriptValue* argv, int argc)
+ {
+ FilterActivation* fa = (FilterActivation*)lpVoid;
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ delete f;
+ }
+ f = new CTextSubVirtualDubFilter(CString(*argv[0].asString()), argv[1].asInt());
+ *(CVirtualDubFilter**)fa->filter_data = f;
+ }
-struct FilterDefinition filterDef_vobsub =
-{
- NULL, NULL, NULL, // next, prev, module
- "VobSub", // name
- "Adds subtitles from a vob sequence.", // desc
- "Gabest", // maker
- NULL, // private_data
- sizeof(CVirtualDubFilter**), // inst_data_size
- vobsubInitProc, // initProc
- baseDeinitProc, // deinitProc
- baseRunProc, // runProc
- baseParamProc, // paramProc
- baseConfigProc, // configProc
- baseStringProc, // stringProc
- NULL, // startProc
- NULL, // endProc
- &vobsub_obj, // script_obj
- baseFssProc, // fssProc
-};
-
-ScriptFunctionDef textsub_func_defs[]= {
- { (ScriptFunctionPtr)textsubScriptConfig, "Config", "0si" },
- { NULL },
-};
-
-CScriptObject textsub_obj= {
- NULL, textsub_func_defs
-};
-
-struct FilterDefinition filterDef_textsub =
-{
- NULL, NULL, NULL, // next, prev, module
+ ScriptFunctionDef vobsub_func_defs[]= {
+ { (ScriptFunctionPtr)vobsubScriptConfig, "Config", "0s" },
+ { NULL },
+ };
+
+ CScriptObject vobsub_obj= {
+ NULL, vobsub_func_defs
+ };
+
+ struct FilterDefinition filterDef_vobsub = {
+ NULL, NULL, NULL, // next, prev, module
+ "VobSub", // name
+ "Adds subtitles from a vob sequence.", // desc
+ "Gabest", // maker
+ NULL, // private_data
+ sizeof(CVirtualDubFilter**), // inst_data_size
+ vobsubInitProc, // initProc
+ baseDeinitProc, // deinitProc
+ baseRunProc, // runProc
+ baseParamProc, // paramProc
+ baseConfigProc, // configProc
+ baseStringProc, // stringProc
+ NULL, // startProc
+ NULL, // endProc
+ &vobsub_obj, // script_obj
+ baseFssProc, // fssProc
+ };
+
+ ScriptFunctionDef textsub_func_defs[]= {
+ { (ScriptFunctionPtr)textsubScriptConfig, "Config", "0si" },
+ { NULL },
+ };
+
+ CScriptObject textsub_obj= {
+ NULL, textsub_func_defs
+ };
+
+ struct FilterDefinition filterDef_textsub = {
+ NULL, NULL, NULL, // next, prev, module
#ifdef _VSMOD
- "TextSubMod", // name
+ "TextSubMod", // name
#else
- "TextSub", // name
+ "TextSub", // name
#endif
- "Adds subtitles from srt, sub, psb, smi, ssa, ass file formats.", // desc
- "Gabest", // maker
- NULL, // private_data
- sizeof(CVirtualDubFilter**), // inst_data_size
- textsubInitProc, // initProc
- baseDeinitProc, // deinitProc
- baseRunProc, // runProc
- baseParamProc, // paramProc
- baseConfigProc, // configProc
- baseStringProc, // stringProc
- NULL, // startProc
- NULL, // endProc
- &textsub_obj, // script_obj
- baseFssProc, // fssProc
-};
-
-static FilterDefinition* fd_vobsub;
-static FilterDefinition* fd_textsub;
-
-extern "C" __declspec(dllexport) int __cdecl VirtualdubFilterModuleInit2(FilterModule *fm, const FilterFunctions *ff, int& vdfd_ver, int& vdfd_compat)
-{
- fd_vobsub = ff->addFilter(fm, &filterDef_vobsub, sizeof(FilterDefinition));
- if(!fd_vobsub)
- return 1;
- fd_textsub = ff->addFilter(fm, &filterDef_textsub, sizeof(FilterDefinition));
- if(!fd_textsub)
- return 1;
+ "Adds subtitles from srt, sub, psb, smi, ssa, ass file formats.", // desc
+ "Gabest", // maker
+ NULL, // private_data
+ sizeof(CVirtualDubFilter**), // inst_data_size
+ textsubInitProc, // initProc
+ baseDeinitProc, // deinitProc
+ baseRunProc, // runProc
+ baseParamProc, // paramProc
+ baseConfigProc, // configProc
+ baseStringProc, // stringProc
+ NULL, // startProc
+ NULL, // endProc
+ &textsub_obj, // script_obj
+ baseFssProc, // fssProc
+ };
+
+ static FilterDefinition* fd_vobsub;
+ static FilterDefinition* fd_textsub;
+
+ extern "C" __declspec(dllexport) int __cdecl VirtualdubFilterModuleInit2(FilterModule *fm, const FilterFunctions *ff, int& vdfd_ver, int& vdfd_compat)
+ {
+ fd_vobsub = ff->addFilter(fm, &filterDef_vobsub, sizeof(FilterDefinition));
+ if(!fd_vobsub) {
+ return 1;
+ }
+ fd_textsub = ff->addFilter(fm, &filterDef_textsub, sizeof(FilterDefinition));
+ if(!fd_textsub) {
+ return 1;
+ }
- vdfd_ver = VIRTUALDUB_FILTERDEF_VERSION;
- vdfd_compat = VIRTUALDUB_FILTERDEF_COMPATIBLE;
+ vdfd_ver = VIRTUALDUB_FILTERDEF_VERSION;
+ vdfd_compat = VIRTUALDUB_FILTERDEF_COMPATIBLE;
- return 0;
-}
+ return 0;
+ }
-extern "C" __declspec(dllexport) void __cdecl VirtualdubFilterModuleDeinit(FilterModule *fm, const FilterFunctions *ff)
-{
- ff->removeFilter(fd_textsub);
- ff->removeFilter(fd_vobsub);
-}
-}/**/
+ extern "C" __declspec(dllexport) void __cdecl VirtualdubFilterModuleDeinit(FilterModule *fm, const FilterFunctions *ff)
+ {
+ ff->removeFilter(fd_textsub);
+ ff->removeFilter(fd_vobsub);
+ }
+ }/**/
#else
-//
-// VirtualDub new plugin interface sdk 1.1
-//
-namespace VirtualDubNew
-{
+ //
+ // VirtualDub new plugin interface sdk 1.1
+ //
+ namespace VirtualDubNew
+ {
#include <vd2/plugin/vdplugin.h>
#include <vd2/plugin/vdvideofilt.h>
-class CVirtualDubFilter : virtual public CFilter
-{
-public:
- CVirtualDubFilter() {}
- virtual ~CVirtualDubFilter() {}
-
- virtual int RunProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff)
- {
- SubPicDesc dst;
- dst.type = MSP_RGB32;
- dst.w = fa->src.w;
- dst.h = fa->src.h;
- dst.bpp = 32;
- dst.pitch = fa->src.pitch;
- dst.bits = (LPVOID)fa->src.data;
-
- Render(dst, 10000i64*fa->pfsi->lSourceFrameMS, (float)1000 / fa->pfsi->lMicrosecsPerFrame);
-
- return 0;
- }
+ class CVirtualDubFilter : virtual public CFilter
+ {
+ public:
+ CVirtualDubFilter() {}
+ virtual ~CVirtualDubFilter() {}
+
+ virtual int RunProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff) {
+ SubPicDesc dst;
+ dst.type = MSP_RGB32;
+ dst.w = fa->src.w;
+ dst.h = fa->src.h;
+ dst.bpp = 32;
+ dst.pitch = fa->src.pitch;
+ dst.bits = (LPVOID)fa->src.data;
+
+ Render(dst, 10000i64*fa->pfsi->lSourceFrameMS, (float)1000 / fa->pfsi->lMicrosecsPerFrame);
+
+ return 0;
+ }
- virtual long ParamProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
- {
- fa->dst.offset = fa->src.offset;
- fa->dst.modulo = fa->src.modulo;
- fa->dst.pitch = fa->src.pitch;
+ virtual long ParamProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff) {
+ fa->dst.offset = fa->src.offset;
+ fa->dst.modulo = fa->src.modulo;
+ fa->dst.pitch = fa->src.pitch;
- return 0;
- }
+ return 0;
+ }
- virtual int ConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd) = 0;
- virtual void StringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str) = 0;
- virtual bool FssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen) = 0;
-};
+ virtual int ConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd) = 0;
+ virtual void StringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str) = 0;
+ virtual bool FssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen) = 0;
+ };
-class CVobSubVirtualDubFilter : public CVobSubFilter, public CVirtualDubFilter
-{
-public:
- CVobSubVirtualDubFilter(CString fn = _T(""))
- : CVobSubFilter(fn) {}
+ class CVobSubVirtualDubFilter : public CVobSubFilter, public CVirtualDubFilter
+ {
+ public:
+ CVobSubVirtualDubFilter(CString fn = _T(""))
+ : CVobSubFilter(fn) {}
- int ConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ int ConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
- CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY,
- _T("VobSub files (*.idx;*.sub)|*.idx;*.sub||"), CWnd::FromHandle((HWND)hwnd), 0);
+ CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY,
+ _T("VobSub files (*.idx;*.sub)|*.idx;*.sub||"), CWnd::FromHandle((HWND)hwnd), 0);
- if(fd.DoModal() != IDOK) return 1;
+ if(fd.DoModal() != IDOK) {
+ return 1;
+ }
- return Open(fd.GetPathName()) ? 0 : 1;
- }
+ return Open(fd.GetPathName()) ? 0 : 1;
+ }
- void StringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str)
- {
- sprintf(str, " (%s)", !GetFileName().IsEmpty() ? CStringA(GetFileName()) : " (empty)");
- }
+ void StringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str) {
+ sprintf(str, " (%s)", !GetFileName().IsEmpty() ? CStringA(GetFileName()) : " (empty)");
+ }
- bool FssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen)
- {
- CStringA fn(GetFileName());
- fn.Replace("\\", "\\\\");
- _snprintf(buf, buflen, "Config(\"%s\")", fn);
- return(true);
- }
-};
+ bool FssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen) {
+ CStringA fn(GetFileName());
+ fn.Replace("\\", "\\\\");
+ _snprintf(buf, buflen, "Config(\"%s\")", fn);
+ return(true);
+ }
+ };
-class CTextSubVirtualDubFilter : public CTextSubFilter, public CVirtualDubFilter
-{
-public:
- CTextSubVirtualDubFilter(CString fn = _T(""), int CharSet = DEFAULT_CHARSET)
- : CTextSubFilter(fn, CharSet) {}
+ class CTextSubVirtualDubFilter : public CTextSubFilter, public CVirtualDubFilter
+ {
+ public:
+ CTextSubVirtualDubFilter(CString fn = _T(""), int CharSet = DEFAULT_CHARSET)
+ : CTextSubFilter(fn, CharSet) {}
- int ConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd)
- {
- AFX_MANAGE_STATE(AfxGetStaticModuleState());
+ int ConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd) {
+ AFX_MANAGE_STATE(AfxGetStaticModuleState());
- /* off encoding changing */
+ /* off encoding changing */
#ifndef _DEBUG
- const TCHAR formats[] = _T("TextSub files (*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt)|*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt||");
- CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_ENABLETEMPLATE|OFN_ENABLEHOOK,
- formats, CWnd::FromHandle((HWND)hwnd), sizeof(OPENFILENAME));
- //OPENFILENAME_SIZE_VERSION_400 /*0*/);
- UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
-
- fd.m_pOFN->hInstance = AfxGetResourceHandle();
- fd.m_pOFN->lpTemplateName = MAKEINTRESOURCE(IDD_TEXTSUBOPENTEMPLATE);
- fd.m_pOFN->lpfnHook = (LPOFNHOOKPROC)OpenHookProc;
- fd.m_pOFN->lCustData = (LPARAM)DEFAULT_CHARSET;
+ const TCHAR formats[] = _T("TextSub files (*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt)|*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt||");
+ CFileDialog fd(TRUE, NULL, GetFileName(), OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY|OFN_ENABLETEMPLATE|OFN_ENABLEHOOK,
+ formats, CWnd::FromHandle((HWND)hwnd), sizeof(OPENFILENAME));
+ //OPENFILENAME_SIZE_VERSION_400 /*0*/);
+ UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
+
+ fd.m_pOFN->hInstance = AfxGetResourceHandle();
+ fd.m_pOFN->lpTemplateName = MAKEINTRESOURCE(IDD_TEXTSUBOPENTEMPLATE);
+ fd.m_pOFN->lpfnHook = (LPOFNHOOKPROC)OpenHookProc;
+ fd.m_pOFN->lCustData = (LPARAM)DEFAULT_CHARSET;
#else
-const TCHAR formats[] = _T("TextSub files (*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt)|*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt||");
-CFileDialog fd(TRUE, NULL, GetFileName(), OFN_ENABLESIZING|OFN_HIDEREADONLY,
- formats, CWnd::FromHandle((HWND)hwnd), sizeof(OPENFILENAME));
+ const TCHAR formats[] = _T("TextSub files (*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt)|*.sub;*.srt;*.smi;*.ssa;*.ass;*.xss;*.psb;*.txt||");
+ CFileDialog fd(TRUE, NULL, GetFileName(), OFN_ENABLESIZING|OFN_HIDEREADONLY,
+ formats, CWnd::FromHandle((HWND)hwnd), sizeof(OPENFILENAME));
#endif
- if(fd.DoModal() != IDOK) return 1;
-
- return Open(fd.GetPathName(), fd.m_pOFN->lCustData) ? 0 : 1;
- }
-
- void StringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str)
- {
- if(!GetFileName().IsEmpty()) sprintf(str, " (%s, %d)", CStringA(GetFileName()), GetCharSet());
- else sprintf(str, " (empty)");
- }
+ if(fd.DoModal() != IDOK) {
+ return 1;
+ }
- bool FssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen)
- {
- CStringA fn(GetFileName());
- fn.Replace("\\", "\\\\");
- _snprintf(buf, buflen, "Config(\"%s\", %d)", fn, GetCharSet());
- return(true);
- }
-};
+ return Open(fd.GetPathName(), fd.m_pOFN->lCustData) ? 0 : 1;
+ }
-int vobsubInitProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
-{
- return !(*(CVirtualDubFilter**)fa->filter_data = new CVobSubVirtualDubFilter());
-}
+ void StringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str) {
+ if(!GetFileName().IsEmpty()) {
+ sprintf(str, " (%s, %d)", CStringA(GetFileName()), GetCharSet());
+ } else {
+ sprintf(str, " (empty)");
+ }
+ }
-int textsubInitProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
-{
- return !(*(CVirtualDubFilter**)fa->filter_data = new CTextSubVirtualDubFilter());
-}
+ bool FssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen) {
+ CStringA fn(GetFileName());
+ fn.Replace("\\", "\\\\");
+ _snprintf(buf, buflen, "Config(\"%s\", %d)", fn, GetCharSet());
+ return(true);
+ }
+ };
-void baseDeinitProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) delete f, f = NULL;
-}
+ int vobsubInitProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
+ {
+ return !(*(CVirtualDubFilter**)fa->filter_data = new CVobSubVirtualDubFilter());
+ }
-int baseRunProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->RunProc(fa, ff) : 1;
-}
+ int textsubInitProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
+ {
+ return !(*(CVirtualDubFilter**)fa->filter_data = new CTextSubVirtualDubFilter());
+ }
-long baseParamProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->ParamProc(fa, ff) : 1;
-}
+ void baseDeinitProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ delete f, f = NULL;
+ }
+ }
-int baseConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->ConfigProc(fa, ff, hwnd) : 1;
-}
+ int baseRunProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->RunProc(fa, ff) : 1;
+ }
-void baseStringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) f->StringProc(fa, ff, str);
-}
+ long baseParamProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->ParamProc(fa, ff) : 1;
+ }
-bool baseFssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen)
-{
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- return f ? f->FssProc(fa, ff, buf, buflen) : false;
-}
+ int baseConfigProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, VDXHWND hwnd)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->ConfigProc(fa, ff, hwnd) : 1;
+ }
-void vobsubScriptConfig(IVDXScriptInterpreter* isi, void* lpVoid, VDXScriptValue* argv, int argc)
-{
- VDXFilterActivation* fa = (VDXFilterActivation*)lpVoid;
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) delete f;
- f = new CVobSubVirtualDubFilter(CString(*argv[0].asString()));
- *(CVirtualDubFilter**)fa->filter_data = f;
-}
+ void baseStringProc(const VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* str)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ f->StringProc(fa, ff, str);
+ }
+ }
-void textsubScriptConfig(IVDXScriptInterpreter* isi, void* lpVoid, VDXScriptValue* argv, int argc)
-{
- VDXFilterActivation* fa = (VDXFilterActivation*)lpVoid;
- CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
- if(f) delete f;
- f = new CTextSubVirtualDubFilter(CString(*argv[0].asString()), argv[1].asInt());
- *(CVirtualDubFilter**)fa->filter_data = f;
-}
+ bool baseFssProc(VDXFilterActivation* fa, const VDXFilterFunctions* ff, char* buf, int buflen)
+ {
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ return f ? f->FssProc(fa, ff, buf, buflen) : false;
+ }
-VDXScriptFunctionDef vobsub_func_defs[]= {
- { (VDXScriptFunctionPtr)vobsubScriptConfig, "Config", "0s" },
- { NULL },
-};
+ void vobsubScriptConfig(IVDXScriptInterpreter* isi, void* lpVoid, VDXScriptValue* argv, int argc)
+ {
+ VDXFilterActivation* fa = (VDXFilterActivation*)lpVoid;
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ delete f;
+ }
+ f = new CVobSubVirtualDubFilter(CString(*argv[0].asString()));
+ *(CVirtualDubFilter**)fa->filter_data = f;
+ }
-VDXScriptObject vobsub_obj= {
- NULL, vobsub_func_defs
-};
+ void textsubScriptConfig(IVDXScriptInterpreter* isi, void* lpVoid, VDXScriptValue* argv, int argc)
+ {
+ VDXFilterActivation* fa = (VDXFilterActivation*)lpVoid;
+ CVirtualDubFilter* f = *(CVirtualDubFilter**)fa->filter_data;
+ if(f) {
+ delete f;
+ }
+ f = new CTextSubVirtualDubFilter(CString(*argv[0].asString()), argv[1].asInt());
+ *(CVirtualDubFilter**)fa->filter_data = f;
+ }
-struct VDXFilterDefinition filterDef_vobsub =
-{
- NULL, NULL, NULL, // next, prev, module
- "VobSub", // name
- "Adds subtitles from a vob sequence.", // desc
- "Gabest", // maker
- NULL, // private_data
- sizeof(CVirtualDubFilter**), // inst_data_size
- vobsubInitProc, // initProc
- baseDeinitProc, // deinitProc
- baseRunProc, // runProc
- baseParamProc, // paramProc
- baseConfigProc, // configProc
- baseStringProc, // stringProc
- NULL, // startProc
- NULL, // endProc
- &vobsub_obj, // script_obj
- baseFssProc, // fssProc
-};
-
-VDXScriptFunctionDef textsub_func_defs[]= {
- { (VDXScriptFunctionPtr)textsubScriptConfig, "Config", "0si" },
- { NULL },
-};
-
-VDXScriptObject textsub_obj= {
- NULL, textsub_func_defs
-};
-
-struct VDXFilterDefinition filterDef_textsub =
-{
- NULL, NULL, NULL, // next, prev, module
+ VDXScriptFunctionDef vobsub_func_defs[]= {
+ { (VDXScriptFunctionPtr)vobsubScriptConfig, "Config", "0s" },
+ { NULL },
+ };
+
+ VDXScriptObject vobsub_obj= {
+ NULL, vobsub_func_defs
+ };
+
+ struct VDXFilterDefinition filterDef_vobsub = {
+ NULL, NULL, NULL, // next, prev, module
+ "VobSub", // name
+ "Adds subtitles from a vob sequence.", // desc
+ "Gabest", // maker
+ NULL, // private_data
+ sizeof(CVirtualDubFilter**), // inst_data_size
+ vobsubInitProc, // initProc
+ baseDeinitProc, // deinitProc
+ baseRunProc, // runProc
+ baseParamProc, // paramProc
+ baseConfigProc, // configProc
+ baseStringProc, // stringProc
+ NULL, // startProc
+ NULL, // endProc
+ &vobsub_obj, // script_obj
+ baseFssProc, // fssProc
+ };
+
+ VDXScriptFunctionDef textsub_func_defs[]= {
+ { (VDXScriptFunctionPtr)textsubScriptConfig, "Config", "0si" },
+ { NULL },
+ };
+
+ VDXScriptObject textsub_obj= {
+ NULL, textsub_func_defs
+ };
+
+ struct VDXFilterDefinition filterDef_textsub = {
+ NULL, NULL, NULL, // next, prev, module
#ifdef _VSMOD
- "TextSubMod", // name
+ "TextSubMod", // name
#else
-"TextSub", // name
+ "TextSub", // name
#endif
- "Adds subtitles from srt, sub, psb, smi, ssa, ass file formats.", // desc
- "Gabest", // maker
- NULL, // private_data
- sizeof(CVirtualDubFilter**), // inst_data_size
- textsubInitProc, // initProc
- baseDeinitProc, // deinitProc
- baseRunProc, // runProc
- baseParamProc, // paramProc
- baseConfigProc, // configProc
- baseStringProc, // stringProc
- NULL, // startProc
- NULL, // endProc
- &textsub_obj, // script_obj
- baseFssProc, // fssProc
-};
-
-static VDXFilterDefinition* fd_vobsub;
-static VDXFilterDefinition* fd_textsub;
-
-extern "C" __declspec(dllexport) int __cdecl VirtualdubFilterModuleInit2(VDXFilterModule *fm, const VDXFilterFunctions *ff, int& vdfd_ver, int& vdfd_compat)
-{
- if(!(fd_vobsub = ff->addFilter(fm, &filterDef_vobsub, sizeof(VDXFilterDefinition)))
- || !(fd_textsub = ff->addFilter(fm, &filterDef_textsub, sizeof(VDXFilterDefinition))))
- return 1;
+ "Adds subtitles from srt, sub, psb, smi, ssa, ass file formats.", // desc
+ "Gabest", // maker
+ NULL, // private_data
+ sizeof(CVirtualDubFilter**), // inst_data_size
+ textsubInitProc, // initProc
+ baseDeinitProc, // deinitProc
+ baseRunProc, // runProc
+ baseParamProc, // paramProc
+ baseConfigProc, // configProc
+ baseStringProc, // stringProc
+ NULL, // startProc
+ NULL, // endProc
+ &textsub_obj, // script_obj
+ baseFssProc, // fssProc
+ };
+
+ static VDXFilterDefinition* fd_vobsub;
+ static VDXFilterDefinition* fd_textsub;
+
+ extern "C" __declspec(dllexport) int __cdecl VirtualdubFilterModuleInit2(VDXFilterModule *fm, const VDXFilterFunctions *ff, int& vdfd_ver, int& vdfd_compat)
+ {
+ if(!(fd_vobsub = ff->addFilter(fm, &filterDef_vobsub, sizeof(VDXFilterDefinition)))
+ || !(fd_textsub = ff->addFilter(fm, &filterDef_textsub, sizeof(VDXFilterDefinition)))) {
+ return 1;
+ }
- vdfd_ver = VIRTUALDUB_FILTERDEF_VERSION;
- vdfd_compat = VIRTUALDUB_FILTERDEF_COMPATIBLE;
+ vdfd_ver = VIRTUALDUB_FILTERDEF_VERSION;
+ vdfd_compat = VIRTUALDUB_FILTERDEF_COMPATIBLE;
- return 0;
-}
+ return 0;
+ }
-extern "C" __declspec(dllexport) void __cdecl VirtualdubFilterModuleDeinit(VDXFilterModule *fm, const VDXFilterFunctions *ff)
-{
- ff->removeFilter(fd_textsub);
- ff->removeFilter(fd_vobsub);
-}
-}
+ extern "C" __declspec(dllexport) void __cdecl VirtualdubFilterModuleDeinit(VDXFilterModule *fm, const VDXFilterFunctions *ff)
+ {
+ ff->removeFilter(fd_textsub);
+ ff->removeFilter(fd_vobsub);
+ }
+ }
#endif
-//
-// Avisynth interface
-//
+ //
+ // Avisynth interface
+ //
-namespace AviSynth1
-{
+ namespace AviSynth1
+ {
#include <avisynth\avisynth1.h>
-class CAvisynthFilter : public GenericVideoFilter, virtual public CFilter
-{
-public:
- CAvisynthFilter(PClip c, IScriptEnvironment* env) : GenericVideoFilter(c) {}
+ class CAvisynthFilter : public GenericVideoFilter, virtual public CFilter
+ {
+ public:
+ CAvisynthFilter(PClip c, IScriptEnvironment* env) : GenericVideoFilter(c) {}
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env)
- {
- PVideoFrame frame = child->GetFrame(n, env);
+ PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) {
+ PVideoFrame frame = child->GetFrame(n, env);
- env->MakeWritable(&frame);
+ env->MakeWritable(&frame);
- SubPicDesc dst;
- dst.w = vi.width;
- dst.h = vi.height;
- dst.pitch = frame->GetPitch();
- dst.bits = (void**)frame->GetWritePtr();
- dst.bpp = vi.BitsPerPixel();
- dst.type =
- vi.IsRGB32() ? ( env->GetVar("RGBA").AsBool() ? MSP_RGBA :MSP_RGB32) :
- vi.IsRGB24() ? MSP_RGB24 :
- vi.IsYUY2() ? MSP_YUY2 :
- -1;
+ SubPicDesc dst;
+ dst.w = vi.width;
+ dst.h = vi.height;
+ dst.pitch = frame->GetPitch();
+ dst.bits = (void**)frame->GetWritePtr();
+ dst.bpp = vi.BitsPerPixel();
+ dst.type =
+ vi.IsRGB32() ? ( env->GetVar("RGBA").AsBool() ? MSP_RGBA :MSP_RGB32) :
+ vi.IsRGB24() ? MSP_RGB24 :
+ vi.IsYUY2() ? MSP_YUY2 :
+ -1;
- float fps = m_fps > 0 ? m_fps : (float)vi.fps_numerator / vi.fps_denominator;
+ float fps = m_fps > 0 ? m_fps : (float)vi.fps_numerator / vi.fps_denominator;
- Render(dst, (REFERENCE_TIME)(10000000i64 * n / fps), fps);
+ Render(dst, (REFERENCE_TIME)(10000000i64 * n / fps), fps);
- return(frame);
- }
-};
+ return(frame);
+ }
+ };
-class CVobSubAvisynthFilter : public CVobSubFilter, public CAvisynthFilter
-{
-public:
- CVobSubAvisynthFilter(PClip c, const char* fn, IScriptEnvironment* env)
- : CVobSubFilter(CString(fn))
- , CAvisynthFilter(c, env)
- {
- if(!m_pSubPicProvider)
- env->ThrowError("VobSub: Can't open \"%s\"", fn);
- }
-};
+ class CVobSubAvisynthFilter : public CVobSubFilter, public CAvisynthFilter
+ {
+ public:
+ CVobSubAvisynthFilter(PClip c, const char* fn, IScriptEnvironment* env)
+ : CVobSubFilter(CString(fn))
+ , CAvisynthFilter(c, env) {
+ if(!m_pSubPicProvider) {
+ env->ThrowError("VobSub: Can't open \"%s\"", fn);
+ }
+ }
+ };
-AVSValue __cdecl VobSubCreateS(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- return(new CVobSubAvisynthFilter(args[0].AsClip(), args[1].AsString(), env));
-}
+ AVSValue __cdecl VobSubCreateS(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ return(new CVobSubAvisynthFilter(args[0].AsClip(), args[1].AsString(), env));
+ }
-class CTextSubAvisynthFilter : public CTextSubFilter, public CAvisynthFilter
-{
-public:
- CTextSubAvisynthFilter(PClip c, IScriptEnvironment* env, const char* fn, int CharSet = DEFAULT_CHARSET, float fps = -1)
- : CTextSubFilter(CString(fn), CharSet, fps)
- , CAvisynthFilter(c, env)
- {
- if(!m_pSubPicProvider)
+ class CTextSubAvisynthFilter : public CTextSubFilter, public CAvisynthFilter
+ {
+ public:
+ CTextSubAvisynthFilter(PClip c, IScriptEnvironment* env, const char* fn, int CharSet = DEFAULT_CHARSET, float fps = -1)
+ : CTextSubFilter(CString(fn), CharSet, fps)
+ , CAvisynthFilter(c, env) {
+ if(!m_pSubPicProvider)
#ifdef _VSMOD
- env->ThrowError("TextSubMod: Can't open \"%s\"", fn);
+ env->ThrowError("TextSubMod: Can't open \"%s\"", fn);
#else
- env->ThrowError("TextSub: Can't open \"%s\"", fn);
+ env->ThrowError("TextSub: Can't open \"%s\"", fn);
#endif
- }
-};
+ }
+ };
-AVSValue __cdecl TextSubCreateS(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- return(new CTextSubAvisynthFilter(args[0].AsClip(), env, args[1].AsString()));
-}
+ AVSValue __cdecl TextSubCreateS(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ return(new CTextSubAvisynthFilter(args[0].AsClip(), env, args[1].AsString()));
+ }
-AVSValue __cdecl TextSubCreateSI(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- return(new CTextSubAvisynthFilter(args[0].AsClip(), env, args[1].AsString(), args[2].AsInt()));
-}
+ AVSValue __cdecl TextSubCreateSI(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ return(new CTextSubAvisynthFilter(args[0].AsClip(), env, args[1].AsString(), args[2].AsInt()));
+ }
-AVSValue __cdecl TextSubCreateSIF(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- return(new CTextSubAvisynthFilter(args[0].AsClip(), env, args[1].AsString(), args[2].AsInt(), args[3].AsFloat()));
-}
+ AVSValue __cdecl TextSubCreateSIF(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ return(new CTextSubAvisynthFilter(args[0].AsClip(), env, args[1].AsString(), args[2].AsInt(), args[3].AsFloat()));
+ }
-AVSValue __cdecl MaskSubCreateSIIFI(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- AVSValue rgb32("RGB32");
- AVSValue tab[5] = {
- args[1],
- args[2],
- args[3],
- args[4],
- rgb32
- };
- AVSValue value(tab,5);
- const char * nom[5]= {
- "width",
- "height",
- "fps",
- "length",
- "pixel_type"
- };
- AVSValue clip(env->Invoke("Blackness",value,nom));
- env->SetVar(env->SaveString("RGBA"),true);
- return(new CTextSubAvisynthFilter(clip.AsClip(), env, args[0].AsString()));
-}
+ AVSValue __cdecl MaskSubCreateSIIFI(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ AVSValue rgb32("RGB32");
+ AVSValue tab[5] = {
+ args[1],
+ args[2],
+ args[3],
+ args[4],
+ rgb32
+ };
+ AVSValue value(tab,5);
+ const char * nom[5]= {
+ "width",
+ "height",
+ "fps",
+ "length",
+ "pixel_type"
+ };
+ AVSValue clip(env->Invoke("Blackness",value,nom));
+ env->SetVar(env->SaveString("RGBA"),true);
+ return(new CTextSubAvisynthFilter(clip.AsClip(), env, args[0].AsString()));
+ }
-extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit(IScriptEnvironment* env)
-{
- env->AddFunction("VobSub", "cs", VobSubCreateS, 0);
+ extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit(IScriptEnvironment* env)
+ {
+ env->AddFunction("VobSub", "cs", VobSubCreateS, 0);
#ifdef _VSMOD
- env->AddFunction("TextSubMod", "cs", TextSubCreateS, 0);
- env->AddFunction("TextSubMod", "csi", TextSubCreateSI, 0);
- env->AddFunction("TextSubMod", "csif", TextSubCreateSIF, 0);
- env->AddFunction("MaskSubMod", "siifi", MaskSubCreateSIIFI, 0);
+ env->AddFunction("TextSubMod", "cs", TextSubCreateS, 0);
+ env->AddFunction("TextSubMod", "csi", TextSubCreateSI, 0);
+ env->AddFunction("TextSubMod", "csif", TextSubCreateSIF, 0);
+ env->AddFunction("MaskSubMod", "siifi", MaskSubCreateSIIFI, 0);
#else
- env->AddFunction("TextSub", "cs", TextSubCreateS, 0);
- env->AddFunction("TextSub", "csi", TextSubCreateSI, 0);
- env->AddFunction("TextSub", "csif", TextSubCreateSIF, 0);
- env->AddFunction("MaskSub", "siifi", MaskSubCreateSIIFI, 0);
+ env->AddFunction("TextSub", "cs", TextSubCreateS, 0);
+ env->AddFunction("TextSub", "csi", TextSubCreateSI, 0);
+ env->AddFunction("TextSub", "csif", TextSubCreateSIF, 0);
+ env->AddFunction("MaskSub", "siifi", MaskSubCreateSIIFI, 0);
#endif
- env->SetVar(env->SaveString("RGBA"),false);
- return(NULL);
-}
-}
+ env->SetVar(env->SaveString("RGBA"),false);
+ return(NULL);
+ }
+ }
-namespace AviSynth25
-{
+ namespace AviSynth25
+ {
#include <avisynth\avisynth25.h>
-static bool s_fSwapUV = false;
+ static bool s_fSwapUV = false;
-class CAvisynthFilter : public GenericVideoFilter, virtual public CFilter
-{
-public:
- VFRTranslator *vfr;
+ class CAvisynthFilter : public GenericVideoFilter, virtual public CFilter
+ {
+ public:
+ VFRTranslator *vfr;
+
+ CAvisynthFilter(PClip c, IScriptEnvironment* env, VFRTranslator *_vfr=0) : GenericVideoFilter(c), vfr(_vfr) {}
+
+ PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) {
+ PVideoFrame frame = child->GetFrame(n, env);
+
+ env->MakeWritable(&frame);
+
+ SubPicDesc dst;
+ dst.w = vi.width;
+ dst.h = vi.height;
+ dst.pitch = frame->GetPitch();
+ dst.pitchUV = frame->GetPitch(PLANAR_U);
+ dst.bits = (void**)frame->GetWritePtr();
+ dst.bitsU = frame->GetWritePtr(PLANAR_U);
+ dst.bitsV = frame->GetWritePtr(PLANAR_V);
+ dst.bpp = dst.pitch/dst.w*8; //vi.BitsPerPixel();
+ dst.type =
+ vi.IsRGB32() ?( env->GetVar("RGBA").AsBool() ? MSP_RGBA : MSP_RGB32) :
+ vi.IsRGB24() ? MSP_RGB24 :
+ vi.IsYUY2() ? MSP_YUY2 :
+ /*vi.IsYV12()*/ vi.pixel_type == VideoInfo::CS_YV12 ? (s_fSwapUV?MSP_IYUV:MSP_YV12) :
+ /*vi.IsIYUV()*/ vi.pixel_type == VideoInfo::CS_IYUV ? (s_fSwapUV?MSP_YV12:MSP_IYUV) :
+ -1;
+
+ float fps = m_fps > 0 ? m_fps : (float)vi.fps_numerator / vi.fps_denominator;
+
+ REFERENCE_TIME timestamp;
+
+ if (!vfr) {
+ timestamp = (REFERENCE_TIME)(10000000i64 * n / fps);
+ } else {
+ timestamp = (REFERENCE_TIME)(10000000 * vfr->TimeStampFromFrameNumber(n));
+ }
- CAvisynthFilter(PClip c, IScriptEnvironment* env, VFRTranslator *_vfr=0) : GenericVideoFilter(c), vfr(_vfr) {}
+ Render(dst, timestamp, fps);
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env)
- {
- PVideoFrame frame = child->GetFrame(n, env);
-
- env->MakeWritable(&frame);
-
- SubPicDesc dst;
- dst.w = vi.width;
- dst.h = vi.height;
- dst.pitch = frame->GetPitch();
- dst.pitchUV = frame->GetPitch(PLANAR_U);
- dst.bits = (void**)frame->GetWritePtr();
- dst.bitsU = frame->GetWritePtr(PLANAR_U);
- dst.bitsV = frame->GetWritePtr(PLANAR_V);
- dst.bpp = dst.pitch/dst.w*8; //vi.BitsPerPixel();
- dst.type =
- vi.IsRGB32() ?( env->GetVar("RGBA").AsBool() ? MSP_RGBA : MSP_RGB32) :
- vi.IsRGB24() ? MSP_RGB24 :
- vi.IsYUY2() ? MSP_YUY2 :
- /*vi.IsYV12()*/ vi.pixel_type == VideoInfo::CS_YV12 ? (s_fSwapUV?MSP_IYUV:MSP_YV12) :
- /*vi.IsIYUV()*/ vi.pixel_type == VideoInfo::CS_IYUV ? (s_fSwapUV?MSP_YV12:MSP_IYUV) :
- -1;
-
- float fps = m_fps > 0 ? m_fps : (float)vi.fps_numerator / vi.fps_denominator;
-
- REFERENCE_TIME timestamp;
-
- if (!vfr)
- timestamp = (REFERENCE_TIME)(10000000i64 * n / fps);
- else
- timestamp = (REFERENCE_TIME)(10000000 * vfr->TimeStampFromFrameNumber(n));
-
- Render(dst, timestamp, fps);
-
- return(frame);
- }
-};
+ return(frame);
+ }
+ };
-class CVobSubAvisynthFilter : public CVobSubFilter, public CAvisynthFilter
-{
-public:
- CVobSubAvisynthFilter(PClip c, const char* fn, IScriptEnvironment* env)
- : CVobSubFilter(CString(fn))
- , CAvisynthFilter(c, env)
- {
- if(!m_pSubPicProvider)
- env->ThrowError("VobSub: Can't open \"%s\"", fn);
- }
-};
+ class CVobSubAvisynthFilter : public CVobSubFilter, public CAvisynthFilter
+ {
+ public:
+ CVobSubAvisynthFilter(PClip c, const char* fn, IScriptEnvironment* env)
+ : CVobSubFilter(CString(fn))
+ , CAvisynthFilter(c, env) {
+ if(!m_pSubPicProvider) {
+ env->ThrowError("VobSub: Can't open \"%s\"", fn);
+ }
+ }
+ };
-AVSValue __cdecl VobSubCreateS(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- return(new CVobSubAvisynthFilter(args[0].AsClip(), args[1].AsString(), env));
-}
+ AVSValue __cdecl VobSubCreateS(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ return(new CVobSubAvisynthFilter(args[0].AsClip(), args[1].AsString(), env));
+ }
-class CTextSubAvisynthFilter : public CTextSubFilter, public CAvisynthFilter
-{
-public:
- CTextSubAvisynthFilter(PClip c, IScriptEnvironment* env, const char* fn, int CharSet = DEFAULT_CHARSET, float fps = -1, VFRTranslator *vfr = 0) //vfr patch
- : CTextSubFilter(CString(fn), CharSet, fps)
- , CAvisynthFilter(c, env, vfr)
- {
- if(!m_pSubPicProvider)
+ class CTextSubAvisynthFilter : public CTextSubFilter, public CAvisynthFilter
+ {
+ public:
+ CTextSubAvisynthFilter(PClip c, IScriptEnvironment* env, const char* fn, int CharSet = DEFAULT_CHARSET, float fps = -1, VFRTranslator *vfr = 0) //vfr patch
+ : CTextSubFilter(CString(fn), CharSet, fps)
+ , CAvisynthFilter(c, env, vfr) {
+ if(!m_pSubPicProvider)
#ifdef _VSMOD
- env->ThrowError("TextSubMod: Can't open \"%s\"", fn);
+ env->ThrowError("TextSubMod: Can't open \"%s\"", fn);
#else
- env->ThrowError("TextSub: Can't open \"%s\"", fn);
+ env->ThrowError("TextSub: Can't open \"%s\"", fn);
#endif
- }
-};
+ }
+ };
-AVSValue __cdecl TextSubCreateGeneral(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- if (!args[1].Defined())
+ AVSValue __cdecl TextSubCreateGeneral(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ if (!args[1].Defined())
#ifdef _VSMOD
- env->ThrowError("TextSubMod: You must specify a subtitle file to use");
+ env->ThrowError("TextSubMod: You must specify a subtitle file to use");
#else
- env->ThrowError("TextSub: You must specify a subtitle file to use");
+ env->ThrowError("TextSub: You must specify a subtitle file to use");
#endif
- VFRTranslator *vfr = 0;
- if (args[4].Defined())
- vfr = GetVFRTranslator(args[4].AsString());
-
- return(new CTextSubAvisynthFilter(
- args[0].AsClip(),
- env,
- args[1].AsString(),
- args[2].AsInt(DEFAULT_CHARSET),
- args[3].AsFloat(-1),
- vfr));
-}
+ VFRTranslator *vfr = 0;
+ if (args[4].Defined()) {
+ vfr = GetVFRTranslator(args[4].AsString());
+ }
-AVSValue __cdecl TextSubSwapUV(AVSValue args, void* user_data, IScriptEnvironment* env)
-{
- s_fSwapUV = args[0].AsBool(false);
- return(AVSValue());
-}
+ return(new CTextSubAvisynthFilter(
+ args[0].AsClip(),
+ env,
+ args[1].AsString(),
+ args[2].AsInt(DEFAULT_CHARSET),
+ args[3].AsFloat(-1),
+ vfr));
+ }
-AVSValue __cdecl MaskSubCreate(AVSValue args, void* user_data, IScriptEnvironment* env)/*SIIFI*/
-{
- if (!args[0].Defined())
+ AVSValue __cdecl TextSubSwapUV(AVSValue args, void* user_data, IScriptEnvironment* env)
+ {
+ s_fSwapUV = args[0].AsBool(false);
+ return(AVSValue());
+ }
+
+ AVSValue __cdecl MaskSubCreate(AVSValue args, void* user_data, IScriptEnvironment* env)/*SIIFI*/
+ {
+ if (!args[0].Defined())
#ifdef _VSMOD
- env->ThrowError("MaskSubMod: You must specify a subtitle file to use");
+ env->ThrowError("MaskSubMod: You must specify a subtitle file to use");
#else
- env->ThrowError("MaskSub: You must specify a subtitle file to use");
+ env->ThrowError("MaskSub: You must specify a subtitle file to use");
#endif
- if (!args[3].Defined() && !args[6].Defined())
+ if (!args[3].Defined() && !args[6].Defined())
#ifdef _VSMOD
- env->ThrowError("MaskSubMod: You must specify either FPS or a VFR timecodes file");
+ env->ThrowError("MaskSubMod: You must specify either FPS or a VFR timecodes file");
#else
- env->ThrowError("MaskSub: You must specify either FPS or a VFR timecodes file");
+ env->ThrowError("MaskSub: You must specify either FPS or a VFR timecodes file");
#endif
- VFRTranslator *vfr = 0;
- if (args[6].Defined())
- vfr = GetVFRTranslator(args[6].AsString());
-
- AVSValue rgb32("RGB32");
- AVSValue fps(args[3].AsFloat(25));
- AVSValue tab[6] = {
- args[1],
- args[2],
- args[3],
- args[4],
- rgb32
- };
- AVSValue value(tab,5);
- const char * nom[5]= {
- "width",
- "height",
- "fps",
- "length",
- "pixel_type"
- };
- AVSValue clip(env->Invoke("Blackness",value,nom));
- env->SetVar(env->SaveString("RGBA"),true);
- //return(new CTextSubAvisynthFilter(clip.AsClip(), env, args[0].AsString()));
- return(new CTextSubAvisynthFilter(
- clip.AsClip(),
- env,
- args[0].AsString(),
- args[5].AsInt(DEFAULT_CHARSET),
- args[3].AsFloat(-1),
- vfr));
-}
+ VFRTranslator *vfr = 0;
+ if (args[6].Defined()) {
+ vfr = GetVFRTranslator(args[6].AsString());
+ }
-extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
-{
- env->AddFunction("VobSub", "cs", VobSubCreateS, 0);
+ AVSValue rgb32("RGB32");
+ AVSValue fps(args[3].AsFloat(25));
+ AVSValue tab[6] = {
+ args[1],
+ args[2],
+ args[3],
+ args[4],
+ rgb32
+ };
+ AVSValue value(tab,5);
+ const char * nom[5]= {
+ "width",
+ "height",
+ "fps",
+ "length",
+ "pixel_type"
+ };
+ AVSValue clip(env->Invoke("Blackness",value,nom));
+ env->SetVar(env->SaveString("RGBA"),true);
+ //return(new CTextSubAvisynthFilter(clip.AsClip(), env, args[0].AsString()));
+ return(new CTextSubAvisynthFilter(
+ clip.AsClip(),
+ env,
+ args[0].AsString(),
+ args[5].AsInt(DEFAULT_CHARSET),
+ args[3].AsFloat(-1),
+ vfr));
+ }
+
+ extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env)
+ {
+ env->AddFunction("VobSub", "cs", VobSubCreateS, 0);
#ifdef _VSMOD
- env->AddFunction("TextSubMod", "c[file]s[charset]i[fps]f[vfr]s", TextSubCreateGeneral, 0);
- env->AddFunction("TextSubModSwapUV", "b", TextSubSwapUV, 0);
- env->AddFunction("MaskSubMod", "[file]s[width]i[height]i[fps]f[length]i[charset]i[vfr]s", MaskSubCreate, 0);
+ env->AddFunction("TextSubMod", "c[file]s[charset]i[fps]f[vfr]s", TextSubCreateGeneral, 0);
+ env->AddFunction("TextSubModSwapUV", "b", TextSubSwapUV, 0);
+ env->AddFunction("MaskSubMod", "[file]s[width]i[height]i[fps]f[length]i[charset]i[vfr]s", MaskSubCreate, 0);
#else
- env->AddFunction("TextSub", "c[file]s[charset]i[fps]f[vfr]s", TextSubCreateGeneral, 0);
- env->AddFunction("TextSubSwapUV", "b", TextSubSwapUV, 0);
- env->AddFunction("MaskSub", "[file]s[width]i[height]i[fps]f[length]i[charset]i[vfr]s", MaskSubCreate, 0);
+ env->AddFunction("TextSub", "c[file]s[charset]i[fps]f[vfr]s", TextSubCreateGeneral, 0);
+ env->AddFunction("TextSubSwapUV", "b", TextSubSwapUV, 0);
+ env->AddFunction("MaskSub", "[file]s[width]i[height]i[fps]f[length]i[charset]i[vfr]s", MaskSubCreate, 0);
#endif
- env->SetVar(env->SaveString("RGBA"),false);
- return(NULL);
-}
-}
+ env->SetVar(env->SaveString("RGBA"),false);
+ return(NULL);
+ }
+ }
}
UINT_PTR CALLBACK OpenHookProc(HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
- switch(uiMsg)
- {
- case WM_NOTIFY:
- {
- OPENFILENAME* ofn = ((OFNOTIFY *)lParam)->lpOFN;
+ switch(uiMsg) {
+ case WM_NOTIFY: {
+ OPENFILENAME* ofn = ((OFNOTIFY *)lParam)->lpOFN;
- if(((NMHDR *)lParam)->code == CDN_FILEOK)
- {
- ofn->lCustData = (LPARAM)CharSetList[SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_GETCURSEL, 0, 0)];
- }
+ if(((NMHDR *)lParam)->code == CDN_FILEOK) {
+ ofn->lCustData = (LPARAM)CharSetList[SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_GETCURSEL, 0, 0)];
+ }
- break;
- }
+ break;
+ }
- case WM_INITDIALOG:
- {
+ case WM_INITDIALOG: {
#ifdef WIN64
- SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
+ SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
#else
- SetWindowLongPtr(hDlg, GWL_USERDATA, lParam);
+ SetWindowLongPtr(hDlg, GWL_USERDATA, lParam);
#endif
- for(ptrdiff_t i = 0; i < CharSetLen; i++)
- {
- CString s;
- s.Format(_T("%s (%d)"), CharSetNames[i], CharSetList[i]);
- SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING, 0, (LONG)(LPCTSTR)s);
- if(CharSetList[i] == (int)((OPENFILENAME*)lParam)->lCustData)
- SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, i, 0);
- }
+ for(ptrdiff_t i = 0; i < CharSetLen; i++) {
+ CString s;
+ s.Format(_T("%s (%d)"), CharSetNames[i], CharSetList[i]);
+ SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING, 0, (LONG)(LPCTSTR)s);
+ if(CharSetList[i] == (int)((OPENFILENAME*)lParam)->lCustData) {
+ SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, i, 0);
+ }
+ }
- break;
- }
+ break;
+ }
- default:
- break;
+ default:
+ break;
}
return FALSE;
diff --git a/src/filters/transform/VSFilter/vfr.cpp b/src/filters/transform/VSFilter/vfr.cpp
index bb56a6126..0c0eb36a5 100644
--- a/src/filters/transform/VSFilter/vfr.cpp
+++ b/src/filters/transform/VSFilter/vfr.cpp
@@ -32,7 +32,8 @@
// Work with seconds per frame (spf) here instead of fps since that's more natural for the translation we're doing
-class TimecodesV1 : public VFRTranslator {
+class TimecodesV1 : public VFRTranslator
+{
private:
// Used when sections run out
double default_spf;
@@ -50,8 +51,7 @@ private:
std::vector<FrameRateSection> sections;
public:
- virtual double TimeStampFromFrameNumber(int n)
- {
+ virtual double TimeStampFromFrameNumber(int n) {
// Find correct section
for (size_t i = 0; i < sections.size(); i++) {
FrameRateSection &sect = sections[i];
@@ -60,12 +60,13 @@ public:
}
}
// Not in a section
- if (n < 0) return 0.0;
+ if (n < 0) {
+ return 0.0;
+ }
return first_non_section_timestamp + (n - first_non_section_frame) * default_spf;
}
- TimecodesV1(FILE *vfrfile)
- {
+ TimecodesV1(FILE *vfrfile) {
char buf[100];
default_spf = -1;
@@ -79,15 +80,18 @@ public:
while (fgets(buf, 100, vfrfile)) {
// Comment?
- if (buf[0] == '#') continue;
+ if (buf[0] == '#') {
+ continue;
+ }
if (_strnicmp(buf, "Assume ", 7) == 0 && default_spf < 0) {
char *num = buf+7;
default_spf = atof(num);
- if (default_spf > 0)
+ if (default_spf > 0) {
default_spf = 1 / default_spf;
- else
+ } else {
default_spf = -1;
+ }
temp_section.spf = default_spf;
continue;
}
@@ -123,7 +127,8 @@ public:
};
-class TimecodesV2 : public VFRTranslator {
+class TimecodesV2 : public VFRTranslator
+{
private:
// Main data
std::vector<double> timestamps;
@@ -133,24 +138,26 @@ private:
double assumed_spf;
public:
- virtual double TimeStampFromFrameNumber(int n)
- {
+ virtual double TimeStampFromFrameNumber(int n) {
if (n < (int)timestamps.size() && n >= 0) {
return timestamps[n];
}
- if (n < 0) return 0.0;
+ if (n < 0) {
+ return 0.0;
+ }
return last_known_timestamp + (n - last_known_frame) * assumed_spf;
}
- TimecodesV2(FILE *vfrfile)
- {
+ TimecodesV2(FILE *vfrfile) {
char buf[50];
timestamps.reserve(8192); // should be enough for most cases
while (fgets(buf, 50, vfrfile)) {
// Comment?
- if (buf[0] == '#') continue;
+ if (buf[0] == '#') {
+ continue;
+ }
// Otherwise assume it's a good timestamp
timestamps.push_back(atof(buf)/1000);
}
diff --git a/src/filters/transform/VSFilter/vfr.h b/src/filters/transform/VSFilter/vfr.h
index a4aafffd4..837577b6e 100644
--- a/src/filters/transform/VSFilter/vfr.h
+++ b/src/filters/transform/VSFilter/vfr.h
@@ -26,7 +26,8 @@
#ifndef VFR_H
#define VFR_H
-class VFRTranslator {
+class VFRTranslator
+{
public:
virtual double TimeStampFromFrameNumber(int n) = 0;
};