-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMpegac.h
More file actions
287 lines (228 loc) · 10.1 KB
/
Mpegac.h
File metadata and controls
287 lines (228 loc) · 10.1 KB
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
/*
* LAME MP3 encoder for DirectShow
* DirectShow filter implementation
*
* Copyright (c) 2000-2005 Marie Orlova, Peter Gubanov, Vitaly Ivanov, Elecard Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <mmreg.h>
#include "Encoder.h"
#define KEY_LAME_ENCODER "SOFTWARE\\GNU\\LAME MPEG Layer III Audio Encoder Filter"
#define VALUE_BITRATE "Bitrate"
#define VALUE_VARIABLE "Variable"
#define VALUE_VARIABLEMIN "VariableMin"
#define VALUE_VARIABLEMAX "VariableMax"
#define VALUE_QUALITY "Quality"
#define VALUE_VBR_QUALITY "VBR Quality"
#define VALUE_SAMPLE_RATE "Sample Rate"
#define VALUE_STEREO_MODE "Stereo Mode"
#define VALUE_FORCE_MS "Force MS"
#define VALUE_LAYER "Layer"
#define VALUE_ORIGINAL "Original"
#define VALUE_COPYRIGHT "Copyright"
#define VALUE_CRC "CRC"
#define VALUE_FORCE_MONO "Force Mono"
#define VALUE_SET_DURATION "Set Duration"
#define VALUE_SAMPLE_OVERLAP "Allow sample overlap"
#define VALUE_PES "PES"
#define VALUE_ENFORCE_MIN "EnforceVBRmin"
#define VALUE_VOICE "Voice Mode"
#define VALUE_KEEP_ALL_FREQ "Keep All Frequencies"
#define VALUE_STRICT_ISO "Strict ISO"
#define VALUE_DISABLE_SHORT_BLOCK "No Short Block"
#define VALUE_XING_TAG "Xing Tag"
#define VALUE_MODE_FIXED "Mode Fixed"
typedef struct
{
DWORD nSampleRate;
DWORD nBitRate;
MPEG_mode ChMode; //Channel coding mode
} current_output_format_t;
typedef struct
{
DWORD nSampleRate;
DWORD nBitRate;
} output_caps_t;
typedef struct
{
LONGLONG sample;
REFERENCE_TIME delta;
BOOL applied;
} resync_point_t;
#define RESYNC_COUNT 4
// The maximum number of capabilities that we can expose in our IAMStreamConfig
// implementation is currently set to 100. This number is larger than we
// should ever realistically need. However, a cleaner implementation might
// be to use a dynamically sized array like std::vector or CAtlArray to
// hold this data.
#define MAX_IAMSTREAMCONFIG_CAPS 100
///////////////////////////////////////////////////////////////////
// CMpegAudEnc class - implementation for ITransformFilter interface
///////////////////////////////////////////////////////////////////
class CMpegAudEncOutPin;
class CMpegAudEncPropertyPage;
class CMpegAudEnc : public CTransformFilter,
public ISpecifyPropertyPages,
public IAudioEncoderProperties,
public CPersistStream
{
public:
DECLARE_IUNKNOWN
static CUnknown *CreateInstance(LPUNKNOWN lpunk, HRESULT *phr);
LPAMOVIESETUP_FILTER GetSetupData();
HRESULT Reconnect();
HRESULT Receive(IMediaSample *pSample);
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 direction,const CMediaType *pmt);
//
HRESULT StartStreaming();
HRESULT StopStreaming();
HRESULT EndOfStream();
HRESULT BeginFlush();
~CMpegAudEnc(void);
// ISpecifyPropertyPages
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
STDMETHODIMP GetPages(CAUUID *pPages);
// IAudioEncoderProperties
STDMETHODIMP get_PESOutputEnabled(DWORD *dwEnabled); // PES header. Obsolete
STDMETHODIMP set_PESOutputEnabled(DWORD dwEnabled); // PES header. Obsolete
STDMETHODIMP get_MPEGLayer(DWORD *dwLayer);
STDMETHODIMP set_MPEGLayer(DWORD dwLayer);
STDMETHODIMP get_Bitrate(DWORD *dwBitrate);
STDMETHODIMP set_Bitrate(DWORD dwBitrate);
STDMETHODIMP get_Variable(DWORD *dwVariable);
STDMETHODIMP set_Variable(DWORD dwVariable);
STDMETHODIMP get_VariableMin(DWORD *dwMin);
STDMETHODIMP set_VariableMin(DWORD dwMin);
STDMETHODIMP get_VariableMax(DWORD *dwMax);
STDMETHODIMP set_VariableMax(DWORD dwMax);
STDMETHODIMP get_Quality(DWORD *dwQuality);
STDMETHODIMP set_Quality(DWORD dwQuality);
STDMETHODIMP get_VariableQ(DWORD *dwVBRq);
STDMETHODIMP set_VariableQ(DWORD dwVBRq);
STDMETHODIMP get_SourceSampleRate(DWORD *dwSampleRate);
STDMETHODIMP get_SourceChannels(DWORD *dwChannels);
STDMETHODIMP get_SampleRate(DWORD *dwSampleRate);
STDMETHODIMP set_SampleRate(DWORD dwSampleRate);
STDMETHODIMP get_ChannelMode(DWORD *dwChannelMode);
STDMETHODIMP set_ChannelMode(DWORD dwChannelMode);
STDMETHODIMP get_ForceMS(DWORD *dwFlag);
STDMETHODIMP set_ForceMS(DWORD dwFlag);
STDMETHODIMP get_EnforceVBRmin(DWORD *dwFlag);
STDMETHODIMP set_EnforceVBRmin(DWORD dwFlag);
STDMETHODIMP get_VoiceMode(DWORD *dwFlag);
STDMETHODIMP set_VoiceMode(DWORD dwFlag);
STDMETHODIMP get_KeepAllFreq(DWORD *dwFlag);
STDMETHODIMP set_KeepAllFreq(DWORD dwFlag);
STDMETHODIMP get_StrictISO(DWORD *dwFlag);
STDMETHODIMP set_StrictISO(DWORD dwFlag);
STDMETHODIMP get_NoShortBlock(DWORD *dwNoShortBlock);
STDMETHODIMP set_NoShortBlock(DWORD dwNoShortBlock);
STDMETHODIMP get_XingTag(DWORD *dwXingTag);
STDMETHODIMP set_XingTag(DWORD dwXingTag);
STDMETHODIMP get_ModeFixed(DWORD *dwModeFixed);
STDMETHODIMP set_ModeFixed(DWORD dwModeFixed);
STDMETHODIMP get_CRCFlag(DWORD *dwFlag);
STDMETHODIMP set_CRCFlag(DWORD dwFlag);
STDMETHODIMP get_ForceMono(DWORD *dwFlag);
STDMETHODIMP set_ForceMono(DWORD dwFlag);
STDMETHODIMP get_SetDuration(DWORD *dwFlag);
STDMETHODIMP set_SetDuration(DWORD dwFlag);
STDMETHODIMP get_OriginalFlag(DWORD *dwFlag);
STDMETHODIMP set_OriginalFlag(DWORD dwFlag);
STDMETHODIMP get_CopyrightFlag(DWORD *dwFlag);
STDMETHODIMP set_CopyrightFlag(DWORD dwFlag);
STDMETHODIMP get_SampleOverlap(DWORD *dwFlag);
STDMETHODIMP set_SampleOverlap(DWORD dwFlag);
STDMETHODIMP get_ParameterBlockSize(BYTE *pcBlock, DWORD *pdwSize);
STDMETHODIMP set_ParameterBlockSize(BYTE *pcBlock, DWORD dwSize);
STDMETHODIMP DefaultAudioEncoderProperties();
STDMETHODIMP LoadAudioEncoderPropertiesFromRegistry();
STDMETHODIMP SaveAudioEncoderPropertiesToRegistry();
STDMETHODIMP InputTypeDefined();
STDMETHODIMP ApplyChanges();
// CPersistStream
HRESULT WriteToStream(IStream *pStream);
HRESULT ReadFromStream(IStream *pStream);
int SizeMax();
STDMETHODIMP GetClassID(CLSID *pClsid);
private:
CMpegAudEnc(LPUNKNOWN lpunk, HRESULT *phr);
HRESULT FlushEncodedSamples();
void ReadPresetSettings(MPEG_ENCODER_CONFIG *pmabsi);
void LoadOutputCapabilities(DWORD sample_rate);
// Encoder object
CEncoder m_Encoder;
REFERENCE_TIME m_rtStreamTime;
REFERENCE_TIME m_rtFrameTime;
REFERENCE_TIME m_rtEstimated;
// Synchronization data
LONGLONG m_samplesIn;
LONGLONG m_samplesOut;
int m_samplesPerFrame;
int m_bytesPerSample;
float m_bytesToDuration;
resync_point_t m_sync[RESYNC_COUNT];
int m_sync_in_idx;
int m_sync_out_idx;
BOOL m_hasFinished;
CCritSec m_cs;
DWORD m_setDuration;
DWORD m_allowOverlap;
REFERENCE_TIME m_rtBytePos;
BOOL m_bStreamOutput; // Binary stream output
long m_cbStreamAlignment; // Stream block size
int m_CapsNum;
int m_currentMediaTypeIndex;
output_caps_t OutputCaps[MAX_IAMSTREAMCONFIG_CAPS];
protected:
friend class CMpegAudEncOutPin;
friend class CMpegAudEncPropertyPage;
};
class CMpegAudEncOutPin : public CTransformOutputPin, public IAMStreamConfig
{
public:
//////////////////////////////////////////////////////////////////////////
// IUnknown
//////////////////////////////////////////////////////////////////////////
DECLARE_IUNKNOWN
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);
//////////////////////////////////////////////////////////////////////////
// IAMStreamConfig
//////////////////////////////////////////////////////////////////////////
HRESULT STDMETHODCALLTYPE SetFormat(AM_MEDIA_TYPE *pmt);
HRESULT STDMETHODCALLTYPE GetFormat(AM_MEDIA_TYPE **ppmt);
HRESULT STDMETHODCALLTYPE GetNumberOfCapabilities(int *piCount, int *piSize);
HRESULT STDMETHODCALLTYPE GetStreamCaps(int iIndex, AM_MEDIA_TYPE **pmt, BYTE *pSCC);
//////////////////////////////////////////////////////////////////////////
// CTransformOutputPin
//////////////////////////////////////////////////////////////////////////
CMpegAudEncOutPin( CMpegAudEnc * pFilter, HRESULT * pHr );
~CMpegAudEncOutPin();
HRESULT CheckMediaType(const CMediaType *pmtOut);
HRESULT GetMediaType(int iPosition, CMediaType *pmt);
HRESULT SetMediaType(const CMediaType *pmt);
private:
BOOL m_SetFormat;
CMpegAudEnc *m_pFilter;
current_output_format_t m_CurrentOutputFormat;
protected:
friend class CMpegAudEnc;
};