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

MpaDecFilter.h « MpaDecFilter « transform « filters « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 04f8018c2030ee9e20a0482df3140cb53dcbfa21 (plain)
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
/*
 * $Id$
 *
 * (C) 2003-2006 Gabest
 * (C) 2006-2010 see AUTHORS
 *
 *  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/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"
#include "../../../apps/mplayerc/internal_filter_config.h"


#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AAC
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);
};
#endif

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;
	}
};

#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
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);
};
#endif

#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
struct flac_state_t {
	void*				pDecoder;
	HRESULT				hr;
};

struct AVCodec;
struct AVCodecContext;
struct AVFrame;
struct AVCodecParserContext;
#endif


class __declspec(uuid("3D446B6F-71DE-4437-BE15-8CE47174340F"))
	CMpaDecFilter
	: public CTransformFilter
	, public IMpaDecFilter
	, public ISpecifyPropertyPages2
{
protected:
	CCritSec m_csReceive;

#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AC3
	a52_state_t*			m_a52_state;
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_DTS
	dts_state_t*			m_dts_state;
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AAC
	aac_state_t				m_aac_state;
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_MPEGAUDIO
	mad_stream				m_stream;
	mad_frame				m_frame;
	mad_synth				m_synth;
#endif
	ps2_state_t				m_ps2_state;
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
	vorbis_state_t			m_vorbis;
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
	flac_state_t			m_flac;
#endif
	DolbyDigitalMode		m_DolbyDigitalMode;

#if defined(REGISTER_FILTER) | HAS_FFMPEG_AUDIO_DECODERS
	// === FFMpeg variables
	AVCodec*				m_pAVCodec;
	AVCodecContext*			m_pAVCtx;
	AVCodecParserContext*	m_pParser;
	BYTE*					m_pPCMData;
#endif

	CAtlArray<BYTE> m_buff;
	REFERENCE_TIME m_rtStart;
	bool m_fDiscontinuity;

	float m_sample_max;

#if defined(REGISTER_FILTER) | INTERNAL_DECODER_LPCM
	HRESULT ProcessLPCM();
	HRESULT ProcessHdmvLPCM(bool bAlignOldBuffer);
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AC3
	HRESULT ProcessAC3();
	HRESULT ProcessA52(BYTE* p, int buffsize, int& size, bool& fEnoughData);
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_DTS
	HRESULT ProcessDTS();
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_AAC
	HRESULT ProcessAAC();
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_PS2AUDIO
	HRESULT ProcessPS2PCM();
	HRESULT ProcessPS2ADPCM();
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_VORBIS
	HRESULT ProcessVorbis();
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
	HRESULT ProcessFlac();
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_MPEGAUDIO
	HRESULT ProcessMPA();
#endif
#if defined(REGISTER_FILTER) | HAS_FFMPEG_AUDIO_DECODERS
	HRESULT ProcessFFmpeg(int nCodecId);
#endif
#if defined(REGISTER_FILTER) | INTERNAL_DECODER_PCM
	HRESULT ProcessPCMraw();
	HRESULT ProcessPCMintBE();
	HRESULT ProcessPCMintLE();
	HRESULT ProcessPCMfloatBE();
	HRESULT ProcessPCMfloatLE();
#endif

	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();

#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
	void	FlacInitDecoder();
	void	flac_stream_finish();
#endif

#if defined(REGISTER_FILTER) | HAS_FFMPEG_AUDIO_DECODERS
	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;
#endif

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();

#if defined(REGISTER_FILTER) | INTERNAL_DECODER_FLAC
	void	FlacFillBuffer(BYTE buffer[], size_t *bytes);
	void	FlacDeliverBuffer (unsigned blocksize, const __int32 * const buffer[]);
#endif
};

class CMpaDecInputPin : public CDeCSSInputPin
{
public:
	CMpaDecInputPin(CTransformFilter* pFilter, HRESULT* phr, LPWSTR pName);
};