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
|
/*
* Copyright (C) 2010-2013 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.
*/
#pragma once
#include "decoders/ILAVDecoder.h"
#include "DecodeThread.h"
#include "ILAVPinInfo.h"
#include "LAVPixFmtConverter.h"
#include "LAVVideoSettings.h"
#include "FloatingAverage.h"
#include "ISpecifyPropertyPages2.h"
#include "SynchronizedQueue.h"
#include "subtitles/LAVSubtitleConsumer.h"
#include "subtitles/LAVVideoSubtitleInputPin.h"
#include "BaseTrayIcon.h"
#define LAVC_VIDEO_REGISTRY_KEY L"Software\\LAV\\Video"
#define LAVC_VIDEO_REGISTRY_KEY_FORMATS L"Software\\LAV\\Video\\Formats"
#define LAVC_VIDEO_REGISTRY_KEY_OUTPUT L"Software\\LAV\\Video\\Output"
#define LAVC_VIDEO_REGISTRY_KEY_HWACCEL L"Software\\LAV\\Video\\HWAccel"
#define LAVC_VIDEO_LOG_FILE L"LAVVideo.txt"
#define DEBUG_FRAME_TIMINGS 0
#define DEBUG_PIXELCONV_TIMINGS 0
#define LAV_MT_FILTER_QUEUE_SIZE 4
typedef struct {
REFERENCE_TIME rtStart;
REFERENCE_TIME rtStop;
} TimingCache;
[uuid("EE30215D-164F-4A92-A4EB-9D4C13390F9F")]
class CLAVVideo : public CTransformFilter, public ISpecifyPropertyPages2, public ILAVVideoSettings, public ILAVVideoStatus, public ILAVVideoCallback
{
public:
CLAVVideo(LPUNKNOWN pUnk, HRESULT* phr);
~CLAVVideo();
static void CALLBACK StaticInit(BOOL bLoading, const CLSID *clsid);
// IUnknown
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// ISpecifyPropertyPages2
STDMETHODIMP GetPages(CAUUID *pPages);
STDMETHODIMP CreatePage(const GUID& guid, IPropertyPage** ppPage);
// ILAVVideoSettings
STDMETHODIMP SetRuntimeConfig(BOOL bRuntimeConfig);
STDMETHODIMP SetFormatConfiguration(LAVVideoCodec vCodec, BOOL bEnabled);
STDMETHODIMP_(BOOL) GetFormatConfiguration(LAVVideoCodec vCodec);
STDMETHODIMP SetNumThreads(DWORD dwNum);
STDMETHODIMP_(DWORD) GetNumThreads();
STDMETHODIMP SetStreamAR(DWORD bStreamAR);
STDMETHODIMP_(DWORD) GetStreamAR();
STDMETHODIMP SetPixelFormat(LAVOutPixFmts pixFmt, BOOL bEnabled);
STDMETHODIMP_(BOOL) GetPixelFormat(LAVOutPixFmts pixFmt);
STDMETHODIMP SetRGBOutputRange(DWORD dwRange);
STDMETHODIMP_(DWORD) GetRGBOutputRange();
STDMETHODIMP SetDeintFieldOrder(LAVDeintFieldOrder fieldOrder);
STDMETHODIMP_(LAVDeintFieldOrder) GetDeintFieldOrder();
STDMETHODIMP SetDeintForce(BOOL bForce);
STDMETHODIMP_(BOOL) GetDeintForce();
STDMETHODIMP SetDeintAggressive(BOOL bAggressive);
STDMETHODIMP_(BOOL) GetDeintAggressive();
STDMETHODIMP_(DWORD) CheckHWAccelSupport(LAVHWAccel hwAccel);
STDMETHODIMP SetHWAccel(LAVHWAccel hwAccel);
STDMETHODIMP_(LAVHWAccel) GetHWAccel();
STDMETHODIMP SetHWAccelCodec(LAVVideoHWCodec hwAccelCodec, BOOL bEnabled);
STDMETHODIMP_(BOOL) GetHWAccelCodec(LAVVideoHWCodec hwAccelCodec);
STDMETHODIMP SetHWAccelDeintMode(LAVHWDeintModes deintMode);
STDMETHODIMP_(LAVHWDeintModes) GetHWAccelDeintMode();
STDMETHODIMP SetHWAccelDeintOutput(LAVDeintOutput deintOutput);
STDMETHODIMP_(LAVDeintOutput) GetHWAccelDeintOutput();
STDMETHODIMP SetHWAccelDeintHQ(BOOL bHQ);
STDMETHODIMP_(BOOL) GetHWAccelDeintHQ();
STDMETHODIMP SetSWDeintMode(LAVSWDeintModes deintMode);
STDMETHODIMP_(LAVSWDeintModes) GetSWDeintMode();
STDMETHODIMP SetSWDeintOutput(LAVDeintOutput deintOutput);
STDMETHODIMP_(LAVDeintOutput) GetSWDeintOutput();
STDMETHODIMP SetDeintTreatAsProgressive(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetDeintTreatAsProgressive();
STDMETHODIMP SetDitherMode(LAVDitherMode ditherMode);
STDMETHODIMP_(LAVDitherMode) GetDitherMode();
STDMETHODIMP SetUseMSWMV9Decoder(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetUseMSWMV9Decoder();
STDMETHODIMP SetDVDVideoSupport(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetDVDVideoSupport();
STDMETHODIMP SetHWAccelResolutionFlags(DWORD dwResFlags);
STDMETHODIMP_(DWORD) GetHWAccelResolutionFlags();
STDMETHODIMP SetTrayIcon(BOOL bEnabled);
STDMETHODIMP_(BOOL) GetTrayIcon();
STDMETHODIMP SetDeinterlacingMode(LAVDeintMode deintMode);
STDMETHODIMP_(LAVDeintMode) GetDeinterlacingMode();
STDMETHODIMP SetGPUDeviceIndex(DWORD dwDevice);
// ILAVVideoStatus
STDMETHODIMP_(const WCHAR *) GetActiveDecoderName() { return m_Decoder.GetDecoderName(); }
// CTransformFilter
HRESULT CheckInputType(const CMediaType* mtIn);
HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
HRESULT DecideBufferSize(IMemAllocator * pAllocator, ALLOCATOR_PROPERTIES *pprop);
HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
HRESULT SetMediaType(PIN_DIRECTION dir, const CMediaType *pmt);
HRESULT EndOfStream();
HRESULT BeginFlush();
HRESULT EndFlush();
HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
HRESULT Receive(IMediaSample *pIn);
HRESULT CheckConnect(PIN_DIRECTION dir, IPin *pPin);
HRESULT BreakConnect(PIN_DIRECTION dir);
HRESULT CompleteConnect(PIN_DIRECTION dir, IPin *pReceivePin);
int GetPinCount();
CBasePin* GetPin(int n);
STDMETHODIMP JoinFilterGraph(IFilterGraph * pGraph, LPCWSTR pName);
// ILAVVideoCallback
STDMETHODIMP AllocateFrame(LAVFrame **ppFrame);
STDMETHODIMP ReleaseFrame(LAVFrame **ppFrame);
STDMETHODIMP Deliver(LAVFrame *pFrame);
STDMETHODIMP_(LPWSTR) GetFileExtension();
STDMETHODIMP_(BOOL) FilterInGraph(PIN_DIRECTION dir, const GUID &clsid) { if (dir == PINDIR_INPUT) return FilterInGraphSafe(m_pInput, clsid); else return FilterInGraphSafe(m_pOutput, clsid); }
STDMETHODIMP_(DWORD) GetDecodeFlags() { return m_dwDecodeFlags; }
STDMETHODIMP_(CMediaType&) GetInputMediaType() { return m_pInput->CurrentMediaType(); }
STDMETHODIMP GetLAVPinInfo(LAVPinInfo &info) { if (m_LAVPinInfoValid) { info = m_LAVPinInfo; return S_OK; } return E_FAIL; }
STDMETHODIMP_(CBasePin*) GetOutputPin() { return m_pOutput; }
STDMETHODIMP_(CMediaType&) GetOutputMediaType() { return m_pOutput->CurrentMediaType(); }
STDMETHODIMP DVDStripPacket(BYTE*& p, long& len) { static_cast<CDeCSSTransformInputPin*>(m_pInput)->StripPacket(p, len); return S_OK; }
STDMETHODIMP_(LAVFrame*) GetFlushFrame();
STDMETHODIMP ReleaseAllDXVAResources() { ReleaseLastSequenceFrame(); return S_OK; }
STDMETHODIMP_(DWORD) GetGPUDeviceIndex() { return m_dwGPUDeviceIndex; }
public:
// Pin Configuration
const static AMOVIESETUP_MEDIATYPE sudPinTypesIn[];
const static int sudPinTypesInCount;
const static AMOVIESETUP_MEDIATYPE sudPinTypesOut[];
const static int sudPinTypesOutCount;
private:
HRESULT LoadDefaults();
HRESULT ReadSettings(HKEY rootKey);
HRESULT LoadSettings();
HRESULT SaveSettings();
HRESULT CreateTrayIcon();
HRESULT CreateDecoder(const CMediaType *pmt);
HRESULT GetDeliveryBuffer(IMediaSample** ppOut, int width, int height, AVRational ar, DXVA2_ExtendedFormat dxvaExtFormat, REFERENCE_TIME avgFrameDuration);
HRESULT ReconnectOutput(int width, int height, AVRational ar, DXVA2_ExtendedFormat dxvaExtFlags, REFERENCE_TIME avgFrameDuration, BOOL bDXVA = FALSE);
HRESULT SetFrameFlags(IMediaSample* pMS, LAVFrame *pFrame);
HRESULT NegotiatePixelFormat(CMediaType &mt, int width, int height);
BOOL IsInterlaced();
HRESULT Filter(LAVFrame *pFrame);
HRESULT DeliverToRenderer(LAVFrame *pFrame);
HRESULT PerformFlush();
HRESULT ReleaseLastSequenceFrame();
HRESULT GetD3DBuffer(LAVFrame *pFrame);
HRESULT RedrawStillImage();
HRESULT SetInDVDMenu(bool menu) { m_bInDVDMenu = menu; return S_OK; }
enum {CNTRL_EXIT, CNTRL_REDRAW};
HRESULT ControlCmd(DWORD cmd) {
return m_ControlThread->CallWorker(cmd);
}
private:
friend class CVideoOutputPin;
friend class CDecodeThread;
friend class CLAVControlThread;
friend class CLAVSubtitleProvider;
friend class CLAVSubtitleConsumer;
CDecodeThread m_Decoder;
CAMThread *m_ControlThread = nullptr;
REFERENCE_TIME m_rtPrevStart = 0;
REFERENCE_TIME m_rtPrevStop = 0;
BOOL m_bForceInputAR = FALSE;
BOOL m_bSendMediaType = FALSE;
BOOL m_bFlushing = FALSE;
HRESULT m_hrDeliver = S_OK;
CLAVPixFmtConverter m_PixFmtConverter;
std::wstring m_strExtension;
BOOL m_bDXVAExtFormatSupport = TRUE;
DWORD m_bMadVR = -1;
DWORD m_bOverlayMixer = -1;
DWORD m_dwDecodeFlags = 0;
BOOL m_bInDVDMenu = FALSE;
AVFilterGraph *m_pFilterGraph = nullptr;
AVFilterContext *m_pFilterBufferSrc = nullptr;
AVFilterContext *m_pFilterBufferSink = nullptr;
LAVPixelFormat m_filterPixFmt = LAVPixFmt_None;
int m_filterWidth = 0;
int m_filterHeight = 0;
LAVFrame m_FilterPrevFrame;
BOOL m_LAVPinInfoValid = FALSE;
LAVPinInfo m_LAVPinInfo;
CLAVVideoSubtitleInputPin *m_pSubtitleInput = nullptr;
CLAVSubtitleConsumer *m_SubtitleConsumer = nullptr;
LAVFrame *m_pLastSequenceFrame = nullptr;
AM_SimpleRateChange m_DVDRate = AM_SimpleRateChange{AV_NOPTS_VALUE, 10000};
BOOL m_bRuntimeConfig = FALSE;
struct VideoSettings {
BOOL TrayIcon;
DWORD StreamAR;
DWORD NumThreads;
BOOL bFormats[Codec_VideoNB];
BOOL bMSWMV9DMO;
BOOL bPixFmts[LAVOutPixFmt_NB];
DWORD RGBRange;
DWORD HWAccel;
BOOL bHWFormats[HWCodec_NB];
DWORD HWAccelResFlags;
DWORD HWDeintMode;
DWORD HWDeintOutput;
BOOL HWDeintHQ;
DWORD DeintFieldOrder;
LAVDeintMode DeintMode;
DWORD SWDeintMode;
DWORD SWDeintOutput;
DWORD DitherMode;
BOOL bDVDVideo;
} m_settings;
DWORD m_dwGPUDeviceIndex = DWORD_MAX;
CBaseTrayIcon *m_pTrayIcon = nullptr;
#ifdef DEBUG
FloatingAverage<double> m_pixFmtTimingAvg;
#endif
};
|