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
|
/*
* 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 <stdint.h>
#include "libmad/msvc++/mad.h"
#include "a52dec/include/a52.h"
#include "libdca/include/dts.h"
//#include "faad2/include/neaacdec.h" // conflicts with dxtrans.h
//#include "libvorbisidec/ivorbiscodec.h"
#include "libvorbisidec/vorbis/codec.h"
#include "../../../decss/DeCSSInputPin.h"
#include "IMpaDecFilter.h"
#include "MpaDecSettingsWnd.h"
struct aac_state_t
{
void* h; // NeAACDecHandle h;
DWORD freq;
BYTE channels;
aac_state_t();
~aac_state_t();
bool open();
void close();
bool init(const CMediaType& mt);
};
struct ps2_state_t
{
bool sync;
double a[2], b[2];
ps2_state_t() {reset();}
void reset() {sync = false; a[0] = a[1] = b[0] = b[1] = 0;}
};
struct vorbis_state_t
{
vorbis_info vi;
vorbis_comment vc;
vorbis_block vb;
vorbis_dsp_state vd;
ogg_packet op;
int packetno;
double postgain;
vorbis_state_t();
~vorbis_state_t();
void clear();
bool init(const CMediaType& mt);
};
struct flac_state_t
{
void* pDecoder;
HRESULT hr;
};
struct AVCodec;
struct AVCodecContext;
struct AVFrame;
struct AVCodecParserContext;
class __declspec(uuid("3D446B6F-71DE-4437-BE15-8CE47174340F"))
CMpaDecFilter
: public CTransformFilter
, public IMpaDecFilter
, public ISpecifyPropertyPages2
{
protected:
CCritSec m_csReceive;
a52_state_t* m_a52_state;
dts_state_t* m_dts_state;
aac_state_t m_aac_state;
mad_stream m_stream;
mad_frame m_frame;
mad_synth m_synth;
ps2_state_t m_ps2_state;
vorbis_state_t m_vorbis;
flac_state_t m_flac;
DolbyDigitalMode m_DolbyDigitalMode;
// === FFMpeg variables
AVCodec* m_pAVCodec;
AVCodecContext* m_pAVCtx;
AVCodecParserContext* m_pParser;
BYTE* m_pPCMData;
CAtlArray<BYTE> m_buff;
REFERENCE_TIME m_rtStart;
bool m_fDiscontinuity;
float m_sample_max;
HRESULT ProcessLPCM();
HRESULT ProcessHdmvLPCM(bool bAlignOldBuffer);
HRESULT ProcessAC3();
HRESULT ProcessA52(BYTE* p, int buffsize, int& size, bool& fEnoughData);
HRESULT ProcessDTS();
HRESULT ProcessAAC();
HRESULT ProcessPS2PCM();
HRESULT ProcessPS2ADPCM();
HRESULT ProcessVorbis();
HRESULT ProcessFlac();
HRESULT ProcessMPA();
HRESULT ProcessFfmpeg(int nCodecId);
HRESULT ProcessPCMraw();
HRESULT ProcessPCMtwos();
HRESULT ProcessPCMintSE();
HRESULT ProcessPCMfloatBE();
HRESULT GetDeliveryBuffer(IMediaSample** pSample, BYTE** pData);
HRESULT Deliver(CAtlArray<float>& pBuff, DWORD nSamplesPerSec, WORD nChannels, DWORD dwChannelMask = 0);
HRESULT Deliver(BYTE* pBuff, int size, int bit_rate, BYTE type);
HRESULT ReconnectOutput(int nSamples, CMediaType& mt);
CMediaType CreateMediaType(MPCSampleFormat sf, DWORD nSamplesPerSec, WORD nChannels, DWORD dwChannelMask = 0);
CMediaType CreateMediaTypeSPDIF();
void FlacInitDecoder();
void flac_stream_finish();
bool InitFfmpeg(int nCodecId);
void ffmpeg_stream_finish();
HRESULT DeliverFfmpeg(int nCodecId, BYTE* p, int buffsize, int& size);
static void LogLibAVCodec(void* par,int level,const char *fmt,va_list valist);
BYTE* m_pFFBuffer;
int m_nFFBufferSize;
protected:
CCritSec m_csProps;
MPCSampleFormat m_iSampleFormat;
bool m_fNormalize;
int m_iSpeakerConfig[etlast];
bool m_fDynamicRangeControl[etlast];
float m_boost;
public:
CMpaDecFilter(LPUNKNOWN lpunk, HRESULT* phr);
virtual ~CMpaDecFilter();
DECLARE_IUNKNOWN
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
HRESULT EndOfStream();
HRESULT BeginFlush();
HRESULT EndFlush();
HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
HRESULT Receive(IMediaSample* pIn);
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 StartStreaming();
HRESULT StopStreaming();
// ISpecifyPropertyPages2
STDMETHODIMP GetPages(CAUUID* pPages);
STDMETHODIMP CreatePage(const GUID& guid, IPropertyPage** ppPage);
// IMpaDecFilter
STDMETHODIMP SetSampleFormat(MPCSampleFormat sf);
STDMETHODIMP_(MPCSampleFormat) GetSampleFormat();
STDMETHODIMP SetNormalize(bool fNormalize);
STDMETHODIMP_(bool) GetNormalize();
STDMETHODIMP SetSpeakerConfig(enctype et, int sc);
STDMETHODIMP_(int) GetSpeakerConfig(enctype et);
STDMETHODIMP SetDynamicRangeControl(enctype et, bool fDRC);
STDMETHODIMP_(bool) GetDynamicRangeControl(enctype et);
STDMETHODIMP SetBoost(float boost);
STDMETHODIMP_(float) GetBoost();
STDMETHODIMP_(DolbyDigitalMode) GetDolbyDigitalMode();
STDMETHODIMP SaveSettings();
void FlacFillBuffer(BYTE buffer[], size_t *bytes);
void FlacDeliverBuffer (unsigned blocksize, const __int32 * const buffer[]);
};
class CMpaDecInputPin : public CDeCSSInputPin
{
public:
CMpaDecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName);
};
|