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
|
/*
* Copyright (C) 2003-2006 Gabest
* http://www.gabest.org
*
* 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.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include <atlcoll.h>
#include <Videoacc.h>
#include "../../../DeCSS/DeCSSInputPin.h"
#include "../BaseVideoFilter/BaseVideoFilter.h"
#include "IMpeg2DecFilter.h"
#include "Mpeg2DecSettingsWnd.h"
class CSubpicInputPin;
class CClosedCaptionOutputPin;
class CMpeg2Dec;
class __declspec(uuid("39F498AF-1A09-4275-B193-673B0BA3D478"))
CMpeg2DecFilter
: public CBaseVideoFilter
, public IMpeg2DecFilter
, public ISpecifyPropertyPages2
{
CSubpicInputPin* m_pSubpicInput;
CClosedCaptionOutputPin* m_pClosedCaptionOutput;
CAutoPtr<CMpeg2Dec> m_dec;
REFERENCE_TIME m_AvgTimePerFrame;
bool m_fWaitForKeyFrame;
bool m_fInitializedBuffer;
struct framebuf
{
int w, h, pitch;
BYTE* buf_base;
BYTE* buf[6];
REFERENCE_TIME rtStart, rtStop;
DWORD flags;
ditype di;
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;
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;
}
void Free()
{
if(buf_base) _aligned_free(buf_base);
buf_base = NULL;
}
} m_fb;
bool m_fFilm;
void SetDeinterlaceMethod();
void SetTypeSpecificFlags(IMediaSample* pMS);
AM_SimpleRateChange m_rate;
protected:
void InputTypeChanged();
HRESULT Transform(IMediaSample* pIn);
bool IsVideoInterlaced();
public:
CMpeg2DecFilter(LPUNKNOWN lpunk, HRESULT* phr);
virtual ~CMpeg2DecFilter();
DECLARE_IUNKNOWN
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT DeliverFast();
HRESULT DeliverNormal();
HRESULT Deliver(bool fRepeatLast);
int GetPinCount();
CBasePin* GetPin(int n);
HRESULT EndOfStream();
HRESULT BeginFlush();
HRESULT EndFlush();
HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
HRESULT CheckConnect(PIN_DIRECTION dir, IPin* pPin);
HRESULT CheckInputType(const CMediaType* mtIn);
HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
HRESULT StartStreaming();
HRESULT StopStreaming();
bool m_fDropFrames;
HRESULT AlterQuality(Quality q);
protected:
CCritSec m_csProps;
ditype m_ditype;
float m_bright, m_cont, m_hue, m_sat;
BYTE m_YTbl[256], m_UTbl[256*256], m_VTbl[256*256];
bool m_fForcedSubs;
bool m_fPlanarYUV;
bool m_fInterlaced;
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
STDMETHODIMP GetPages(CAUUID* pPages);
STDMETHODIMP CreatePage(const GUID& guid, IPropertyPage** ppPage);
// IMpeg2DecFilter
STDMETHODIMP SetDeinterlaceMethod(ditype di);
STDMETHODIMP_(ditype) GetDeinterlaceMethod();
STDMETHODIMP SetBrightness(float bright);
STDMETHODIMP SetContrast(float cont);
STDMETHODIMP SetHue(float hue);
STDMETHODIMP SetSaturation(float sat);
STDMETHODIMP_(float) GetBrightness();
STDMETHODIMP_(float) GetContrast();
STDMETHODIMP_(float) GetHue();
STDMETHODIMP_(float) GetSaturation();
STDMETHODIMP EnableForcedSubtitles(bool fEnable);
STDMETHODIMP_(bool) IsForcedSubtitlesEnabled();
STDMETHODIMP EnablePlanarYUV(bool fEnable);
STDMETHODIMP_(bool) IsPlanarYUVEnabled();
// IMpeg2DecFilter2
STDMETHODIMP EnableInterlaced(bool fEnable);
STDMETHODIMP_(bool) IsInterlacedEnabled();
};
class CMpeg2DecInputPin : public CDeCSSInputPin
{
LONG m_CorrectTS;
public:
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);
};
class CMpeg2DecOutputPin : public CBaseVideoOutputPin
{
public:
CMpeg2DecOutputPin(CBaseVideoFilter* pFilter, HRESULT* phr, LPWSTR pName);
CAutoPtr<COutputQueue> m_pOutputQueue;
HRESULT Active();
HRESULT Inactive();
HRESULT Deliver(IMediaSample* pMediaSample);
HRESULT DeliverEndOfStream();
HRESULT DeliverBeginFlush();
HRESULT DeliverEndFlush();
HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
};
class CSubpicInputPin : public CMpeg2DecInputPin
{
CCritSec m_csReceive;
AM_PROPERTY_COMPOSIT_ON m_spon;
AM_DVD_YUV m_sppal[16];
bool m_fsppal;
CAutoPtr<AM_PROPERTY_SPHLI> m_sphli; // temp
class spu : public CAtlArray<BYTE>
{
public:
bool m_fForced;
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;}
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;
};
class dvdspu : public spu
{
public:
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);
};
class cvdspu : public spu
{
public:
AM_DVD_YUV m_sppal[2][4];
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);
};
class svcdspu : public spu
{
public:
AM_DVD_YUV m_sppal[4];
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);
};
CAutoPtrList<spu> m_sps;
protected:
HRESULT Transform(IMediaSample* pSample);
public:
CSubpicInputPin(CTransformFilter* pFilter, HRESULT* phr);
bool HasAnythingToRender(REFERENCE_TIME rt);
void RenderSubpics(REFERENCE_TIME rt, BYTE** p, int w, int h);
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;}
// IKsPropertySet
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
{
public:
CClosedCaptionOutputPin(CBaseFilter* pFilter, CCritSec* pLock, HRESULT* phr);
HRESULT CheckMediaType(const CMediaType* mtOut);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties);
CMediaType& CurrentMediaType() {return m_mt;}
HRESULT Deliver(const void* ptr, int len);
};
|