1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
/*
* Copyright (C) 2010-2014 Hendrik Leppkes
* http://www.1f0.de
*
* 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 of the License, 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Initial design and concept by Gabest and the MPC-HC Team, copyright under GPLv2
* Contributions by Ti-BEN from the XBMC DSPlayer Project, also under GPLv2
*/
#pragma once
#include <string>
#include <list>
#include <set>
#include <vector>
#include <map>
#include "PacketQueue.h"
#include "BaseDemuxer.h"
#include "LAVSplitterSettingsInternal.h"
#include "SettingsProp.h"
#include "IBufferInfo.h"
#include "ISpecifyPropertyPages2.h"
#include "LAVSplitterTrayIcon.h"
#define LAVF_REGISTRY_KEY L"Software\\LAV\\Splitter"
#define LAVF_REGISTRY_KEY_FORMATS LAVF_REGISTRY_KEY L"\\Formats"
#define LAVF_LOG_FILE L"LAVSplitter.txt"
#define MAX_PTS_SHIFT 50000000i64
class CLAVOutputPin;
class CLAVInputPin;
#ifdef _MSC_VER
#pragma warning(disable: 4355)
#endif
[uuid("171252A0-8820-4AFE-9DF8-5C92B2D66B04")]
class CLAVSplitter
: public CBaseFilter
, public CCritSec
, protected CAMThread
, public IFileSourceFilter
, public IMediaSeeking
, public IAMStreamSelect
, public IAMOpenProgress
, public ILAVFSettingsInternal
, public ISpecifyPropertyPages2
, public IObjectWithSite
, public IBufferInfo
{
public:
CLAVSplitter(LPUNKNOWN pUnk, HRESULT* phr);
virtual ~CLAVSplitter();
static void CALLBACK StaticInit(BOOL bLoading, const CLSID *clsid);
// IUnknown
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// CBaseFilter methods
int GetPinCount();
CBasePin *GetPin(int n);
STDMETHODIMP GetClassID(CLSID* pClsID);
STDMETHODIMP Stop();
STDMETHODIMP Pause();
STDMETHODIMP Run(REFERENCE_TIME tStart);
STDMETHODIMP JoinFilterGraph(IFilterGraph * pGraph, LPCWSTR pName);
// IFileSourceFilter
STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE * pmt);
STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName, AM_MEDIA_TYPE *pmt);
// IMediaSeeking
STDMETHODIMP GetCapabilities(DWORD* pCapabilities);
STDMETHODIMP CheckCapabilities(DWORD* pCapabilities);
STDMETHODIMP IsFormatSupported(const GUID* pFormat);
STDMETHODIMP QueryPreferredFormat(GUID* pFormat);
STDMETHODIMP GetTimeFormat(GUID* pFormat);
STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat);
STDMETHODIMP SetTimeFormat(const GUID* pFormat);
STDMETHODIMP GetDuration(LONGLONG* pDuration);
STDMETHODIMP GetStopPosition(LONGLONG* pStop);
STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent);
STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat);
STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags);
STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop);
STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest);
STDMETHODIMP SetRate(double dRate);
STDMETHODIMP GetRate(double* pdRate);
STDMETHODIMP GetPreroll(LONGLONG* pllPreroll);
// 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);
// IAMOpenProgress
STDMETHODIMP QueryProgress(LONGLONG *pllTotal, LONGLONG *pllCurrent);
STDMETHODIMP AbortOperation();
// ISpecifyPropertyPages2
STDMETHODIMP GetPages(CAUUID *pPages);
STDMETHODIMP CreatePage(const GUID& guid, IPropertyPage** ppPage);
// IObjectWithSite
STDMETHODIMP SetSite(IUnknown *pUnkSite);
STDMETHODIMP GetSite(REFIID riid, void **ppvSite);
// IBufferInfo
STDMETHODIMP_(int) GetCount();
STDMETHODIMP GetStatus(int i, int& samples, int& size);
STDMETHODIMP_(DWORD) GetPriority();
// ILAVFSettings
STDMETHODIMP SetRuntimeConfig(BOOL bRuntimeConfig);
STDMETHODIMP GetPreferredLanguages(LPWSTR *ppLanguages);
STDMETHODIMP SetPreferredLanguages(LPCWSTR pLanguages);
STDMETHODIMP GetPreferredSubtitleLanguages(LPWSTR *ppLanguages);
STDMETHODIMP SetPreferredSubtitleLanguages(LPCWSTR pLanguages);
STDMETHODIMP_(LAVSubtitleMode) GetSubtitleMode();
STDMETHODIMP SetSubtitleMode(LAVSubtitleMode mode);
STDMETHODIMP_(BOOL) GetSubtitleMatchingLanguage();
STDMETHODIMP SetSubtitleMatchingLanguage(BOOL dwMode);
STDMETHODIMP_(BOOL) GetPGSForcedStream();
STDMETHODIMP SetPGSForcedStream(BOOL bFlag);
STDMETHODIMP_(BOOL) GetPGSOnlyForced();
STDMETHODIMP SetPGSOnlyForced(BOOL bForced);
STDMETHODIMP_(int) GetVC1TimestampMode();
STDMETHODIMP SetVC1TimestampMode(int iMode);
STDMETHODIMP SetSubstreamsEnabled(BOOL bSubStreams);
STDMETHODIMP_(BOOL) GetSubstreamsEnabled();
STDMETHODIMP SetVideoParsingEnabled(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetVideoParsingEnabled();
STDMETHODIMP SetFixBrokenHDPVR(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetFixBrokenHDPVR();
STDMETHODIMP_(HRESULT) SetFormatEnabled(LPCSTR strFormat, BOOL bEnabled);
STDMETHODIMP_(BOOL) IsFormatEnabled(LPCSTR strFormat);
STDMETHODIMP SetStreamSwitchRemoveAudio(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetStreamSwitchRemoveAudio();
STDMETHODIMP GetAdvancedSubtitleConfig(LPWSTR *ppAdvancedConfig);
STDMETHODIMP SetAdvancedSubtitleConfig(LPCWSTR pAdvancedConfig);
STDMETHODIMP SetUseAudioForHearingVisuallyImpaired(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetUseAudioForHearingVisuallyImpaired();
STDMETHODIMP SetMaxQueueMemSize(DWORD dwMaxSize);
STDMETHODIMP_(DWORD) GetMaxQueueMemSize();
STDMETHODIMP SetTrayIcon(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetTrayIcon();
STDMETHODIMP SetPreferHighQualityAudioStreams(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetPreferHighQualityAudioStreams();
STDMETHODIMP SetLoadMatroskaExternalSegments(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetLoadMatroskaExternalSegments();
STDMETHODIMP GetFormats(LPSTR** formats, UINT* nFormats);
STDMETHODIMP SetNetworkStreamAnalysisDuration(DWORD dwDuration);
STDMETHODIMP_(DWORD) GetNetworkStreamAnalysisDuration();
// ILAVSplitterSettingsInternal
STDMETHODIMP_(LPCSTR) GetInputFormat() { if (m_pDemuxer) return m_pDemuxer->GetContainerFormat(); return nullptr; }
STDMETHODIMP_(std::set<FormatInfo>&) GetInputFormats();
STDMETHODIMP_(BOOL) IsVC1CorrectionRequired();
STDMETHODIMP_(CMediaType *) GetOutputMediatype(int stream);
STDMETHODIMP_(IFilterGraph *) GetFilterGraph() { if (m_pGraph) { m_pGraph->AddRef(); return m_pGraph; } return nullptr; }
STDMETHODIMP_(DWORD) GetStreamFlags(DWORD dwStream) { if (m_pDemuxer) return m_pDemuxer->GetStreamFlags(dwStream); return 0; }
STDMETHODIMP_(int) GetPixelFormat(DWORD dwStream) { if (m_pDemuxer) return m_pDemuxer->GetPixelFormat(dwStream); return AV_PIX_FMT_NONE; }
STDMETHODIMP_(int) GetHasBFrames(DWORD dwStream){ if (m_pDemuxer) return m_pDemuxer->GetHasBFrames(dwStream); return -1; }
// Settings helper
std::list<std::string> GetPreferredAudioLanguageList();
std::list<CSubtitleSelector> GetSubtitleSelectors();
bool IsAnyPinDrying();
void SetFakeASFReader(BOOL bFlag) { m_bFakeASFReader = bFlag; }
protected:
// CAMThread
enum {CMD_EXIT, CMD_SEEK};
DWORD ThreadProc();
HRESULT DemuxSeek(REFERENCE_TIME rtStart);
HRESULT DemuxNextPacket();
HRESULT DeliverPacket(Packet *pPacket);
void DeliverBeginFlush();
void DeliverEndFlush();
STDMETHODIMP Close();
STDMETHODIMP DeleteOutputs();
STDMETHODIMP InitDemuxer();
friend class CLAVOutputPin;
STDMETHODIMP SetPositionsInternal(void *caller, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags);
public:
CLAVOutputPin *GetOutputPin(DWORD streamId, BOOL bActiveOnly = FALSE);
STDMETHODIMP RenameOutputPin(DWORD TrackNumSrc, DWORD TrackNumDst, std::vector<CMediaType> pmts);
STDMETHODIMP UpdateForcedSubtitleMediaType();
STDMETHODIMP CompleteInputConnection();
STDMETHODIMP BreakInputConnection();
protected:
STDMETHODIMP LoadDefaults();
STDMETHODIMP ReadSettings(HKEY rootKey);
STDMETHODIMP LoadSettings();
STDMETHODIMP SaveSettings();
STDMETHODIMP CreateTrayIcon();
protected:
CLAVInputPin *m_pInput;
private:
CCritSec m_csPins;
std::vector<CLAVOutputPin *> m_pPins;
std::vector<CLAVOutputPin *> m_pActivePins;
std::vector<CLAVOutputPin *> m_pRetiredPins;
std::set<DWORD> m_bDiscontinuitySent;
std::wstring m_fileName;
std::wstring m_processName;
CBaseDemuxer *m_pDemuxer = nullptr;
BOOL m_bPlaybackStarted = FALSE;
BOOL m_bFakeASFReader = FALSE;
// Times
REFERENCE_TIME m_rtStart = 0;
REFERENCE_TIME m_rtStop = 0;
REFERENCE_TIME m_rtCurrent = 0;
REFERENCE_TIME m_rtNewStart = 0;
REFERENCE_TIME m_rtNewStop = 0;
REFERENCE_TIME m_rtOffset = 0;
double m_dRate = 1.0;
BOOL m_bStopValid = FALSE;
// Seeking
REFERENCE_TIME m_rtLastStart = _I64_MIN;
REFERENCE_TIME m_rtLastStop = _I64_MIN;
std::set<void *> m_LastSeekers;
CAMEvent m_ePlaybackInit{TRUE};
// flushing
bool m_fFlushing = FALSE;
CAMEvent m_eEndFlush;
std::set<FormatInfo> m_InputFormats;
// Settings
struct Settings {
BOOL TrayIcon;
std::wstring prefAudioLangs;
std::wstring prefSubLangs;
std::wstring subtitleAdvanced;
LAVSubtitleMode subtitleMode;
BOOL PGSForcedStream;
BOOL PGSOnlyForced;
int vc1Mode;
BOOL substreams;
BOOL MatroskaExternalSegments;
BOOL StreamSwitchRemoveAudio;
BOOL ImpairedAudio;
BOOL PreferHighQualityAudio;
DWORD QueueMaxSize;
DWORD NetworkAnalysisDuration;
std::map<std::string, BOOL> formats;
} m_settings;
BOOL m_bRuntimeConfig = FALSE;
IUnknown *m_pSite = nullptr;
CBaseTrayIcon *m_pTrayIcon = nullptr;
};
[uuid("B98D13E7-55DB-4385-A33D-09FD1BA26338")]
class CLAVSplitterSource : public CLAVSplitter
{
public:
// construct only via class factory
CLAVSplitterSource(LPUNKNOWN pUnk, HRESULT* phr);
virtual ~CLAVSplitterSource();
// IUnknown
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
};
|