• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  *
3  * Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows
4  *
5  *  Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 
23 /*!
24 	\author Steve Lhomme
25 	\version \$Id$
26 */
27 
28 #if !defined(_AENCODEPROPERTIES_H__INCLUDED_)
29 #define _AENCODEPROPERTIES_H__INCLUDED_
30 
31 #if _MSC_VER > 1000
32 #pragma once
33 #endif // _MSC_VER > 1000
34 
35 #include <windows.h>
36 #include <string>
37 
38 #include "ADbg/ADbg.h"
39 //#include "BladeMP3EncDLL.h"
40 #include "tinyxml/tinyxml.h"
41 //#include "AParameters/AParameters.h"
42 
43 typedef const struct {
44 	UINT id;
45 	const char *tip;
46 } ToolTipItem;
47 /**
48   \class AEncodeProperties
49   \brief the AEncodeProperties class is responsible for handling all the encoding properties
50 */
51 class AEncodeProperties
52 {
53 public:
54 	/**
55 		\brief default constructor
56 
57 		\param the windows module with which you can retrieve many informations
58 	*/
59 	AEncodeProperties(HMODULE hModule);
60 
61 	/**
62 		\brief default destructor
63 	*/
~AEncodeProperties()64 	virtual ~AEncodeProperties() {}
65 
66 	/**
67 		\enum BRMode
68 		\brief A bitrate mode (CBR, VBR, ABR)
69 	*/
70 	enum BRMode { BR_CBR, BR_VBR, BR_ABR };
71 
72 	/**
73 		\brief Handle all the commands that occur in the Config dialog box
74 	*/
75 	bool HandleDialogCommand(const HWND parentWnd, const WPARAM wParam, const LPARAM lParam);
76 	/**
77 		\brief check wether 2 instances are equal, ie have the same encoding parameters
78 	*/
79 	bool operator != (const AEncodeProperties & the_instance) const;
80 
81 	/**
82 		\brief Check wether the Encode process should use the Copyright bit
83 	*/
GetCopyrightMode()84 	inline const bool GetCopyrightMode() const { return bCopyright; }
85 	/**
86 		\brief Check wether the Encode process should use the CRC bit
87 	*/
GetCRCMode()88 	inline const bool GetCRCMode() const { return bCRC; }
89 	/**
90 		\brief Check wether the Encode process should use the Original bit
91 	*/
GetOriginalMode()92 	inline const bool GetOriginalMode() const { return bOriginal; }
93 	/**
94 		\brief Check wether the Encode process should use the Private bit
95 	*/
GetPrivateMode()96 	inline const bool GetPrivateMode() const { return bPrivate; }
97 	/**
98 		\brief Check wether the Encode process should use the Smart Bitrate output
99 	*/
GetSmartOutputMode()100 	inline const bool GetSmartOutputMode() const { return bSmartOutput; }
101 	/**
102 		\brief Check wether the Encode process should allow Average Bitrate output
103 	*/
GetAbrOutputMode()104 	inline const bool GetAbrOutputMode() const { return bAbrOutput; }
105 
106 	/**
107 		\brief Check wether the Encode process shouldn't use the Bit Reservoir
108 	*/
GetNoBiResMode()109 	inline const bool GetNoBiResMode() const { return bNoBitRes; }
110 
111 	/**
112 		\brief Check wether the Encode process should force the channel mode (stereo or mono resampling)
113 	*/
GetForceChannelMode()114 	inline const bool GetForceChannelMode() const { return bForceChannel; }
115 
116 	/**
117 		\brief Check wether the Encode process should use the VBR mode
118 	*/
GetVBRUseMode()119 	inline const BRMode GetVBRUseMode() const { return mBRmode; }
120 	/**
121 		\brief Check wether the Encode process should use the Xing frame in the VBR mode
122 		\note the Xing frame is a silent frame at the beginning that contain VBR statistics about the file.
123 	*/
GetXingFrameMode()124 	inline const bool GetXingFrameMode() const { return bXingFrame; }
125 
126 	/**
127 		\brief Check wether the Encode process should resample before encoding
128 	*/
GetResampleMode()129 	inline const bool GetResampleMode() const { return bResample; }
130 
131 	/**
132 		\brief Set wether the Encode process should use the Copyright bit
133 	*/
SetCopyrightMode(const bool bMode)134 	inline void SetCopyrightMode(const bool bMode) { bCopyright = bMode; }
135 	/**
136 		\brief Set wether the Encode process should use the CRC bit
137 	*/
SetCRCMode(const bool bMode)138 	inline void SetCRCMode(const bool bMode) { bCRC = bMode; }
139 	/**
140 		\brief Set wether the Encode process should use the Original bit
141 	*/
SetOriginalMode(const bool bMode)142 	inline void SetOriginalMode(const bool bMode) { bOriginal = bMode; }
143 	/**
144 		\brief Set wether the Encode process should use the Private bit
145 	*/
SetPrivateMode(const bool bMode)146 	inline void SetPrivateMode(const bool bMode) { bPrivate = bMode; }
147 
148 	/**
149 		\brief Set wether the Encode process should use the Smart Bitrate output
150 	*/
SetSmartOutputMode(const bool bMode)151 	inline void SetSmartOutputMode(const bool bMode) { bSmartOutput = bMode; }
152 	/**
153 		\brief Set wether the Encode process should use the Average Bitrate output
154 	*/
SetAbrOutputMode(const bool bMode)155 	inline void SetAbrOutputMode(const bool bMode) { bAbrOutput = bMode; }
156 
157 
158 	/**
159 		\brief Set wether the Encode process shouldn't use the Bit Reservoir
160 	*/
SetNoBiResMode(const bool bMode)161 	inline void SetNoBiResMode(const bool bMode) { bNoBitRes = bMode; }
162 
163 	/**
164 		\brief Set wether the Encode process should force the channel mode (stereo or mono resampling)
165 	*/
SetForceChannelMode(const bool bMode)166 	inline void SetForceChannelMode(const bool bMode) { bForceChannel = bMode; }
167 
168 	/**
169 		\brief Set wether the Encode process should use the VBR mode
170 	*/
SetVBRUseMode(const BRMode mode)171 	inline void SetVBRUseMode(const BRMode mode) { mBRmode = mode; }
172 
173 	/**
174 		\brief Set wether the Encode process should use the Xing frame in the VBR mode
175 		\note the Xing frame is a silent frame at the beginning that contain VBR statistics about the file.
176 	*/
SetXingFrameMode(const bool bMode)177 	inline void SetXingFrameMode(const bool bMode) { bXingFrame = bMode; }
178 
179 	/**
180 		\brief CBR : Get the bitrate to use         /
181 		       VBR : Get the minimum bitrate value
182 	*/
183 	const unsigned int GetBitrateValue() const;
184 
185 	/**
186 		\brief Get the current (VBR:min) bitrate for the specified MPEG version
187 
188 		\param bitrate the data that will be filled with the bitrate
189 		\param MPEG_Version The MPEG version (MPEG1 or MPEG2)
190 
191 		\return 0 if the bitrate is not found, 1 if the bitrate is found
192 	*/
193 	const int GetBitrateValue(DWORD & bitrate, const DWORD MPEG_Version) const;
194 	/**
195 		\brief Get the current (VBR:min) bitrate for MPEG I
196 
197 		\param bitrate the data that will be filled with the bitrate
198 
199 		\return 0 if the bitrate is not found, 1 if the bitrate is found
200 	*/
201 	const int GetBitrateValueMPEG1(DWORD & bitrate) const;
202 	/**
203 		\brief Get the current (VBR:min) bitrate for MPEG II
204 
205 		\param bitrate the data that will be filled with the bitrate
206 
207 		\return 0 if the bitrate is not found, 1 if the bitrate is found
208 	*/
209 	const int GetBitrateValueMPEG2(DWORD & bitrate) const;
210 
211 	/**
212 		\brief Get the current (VBR:min) bitrate in the form of a string
213 
214 		\param string the string that will be filled
215 		\param string_size the size of the string
216 
217 		\return -1 if the bitrate is not found, and the number of char copied otherwise
218 	*/
GetBitrateString(char * string,int string_size)219 	inline const int GetBitrateString(char * string, int string_size) const {return GetBitrateString(string,string_size,nMinBitrateIndex); }
220 
221 	/**
222 		\brief Get the (VBR:min) bitrate corresponding to the specified index in the form of a string
223 
224 		\param string the string that will be filled
225 		\param string_size the size of the string
226 		\param a_bitrateID the index in the Bitrate table
227 
228 		\return -1 if the bitrate is not found, and the number of char copied otherwise
229 	*/
230 	const int GetBitrateString(char * string, int string_size, int a_bitrateID) const;
231 
232 	/**
233 		\brief Get the number of possible bitrates
234 	*/
GetBitrateLentgh()235 	inline const int GetBitrateLentgh() const { return sizeof(the_Bitrates) / sizeof(unsigned int); }
236 	/**
237 		\brief Get the number of possible sampling frequencies
238 	*/
GetResampleFreq()239 	inline const unsigned int GetResampleFreq() const { return the_SamplingFreqs[nSamplingFreqIndex]; }
240 	/**
241 		\brief Get the max compression ratio allowed (1:15 default)
242 	*/
GetSmartRatio()243 	inline double GetSmartRatio() const { return SmartRatioMax;}
244 	/**
245 		\brief Get the min ABR bitrate possible
246 	*/
GetAbrBitrateMin()247 	inline unsigned int GetAbrBitrateMin() const { return AverageBitrate_Min;}
248 	/**
249 		\brief Get the max ABR bitrate possible
250 	*/
GetAbrBitrateMax()251 	inline unsigned int GetAbrBitrateMax() const { return AverageBitrate_Max;}
252 	/**
253 		\brief Get the step between ABR bitrates
254 	*/
GetAbrBitrateStep()255 	inline unsigned int GetAbrBitrateStep() const { return AverageBitrate_Step;}
256 
257 	/**
258 		\brief Get the VBR attributes for a specified MPEG version
259 
260 		\param MaxBitrate receive the maximum bitrate possible in the VBR mode
261 		\param Quality receive the quality value (0 to 9 see Lame doc for more info)
262 		\param VBRHeader receive the value that indicates wether the VBR/Xing header should be filled
263 		\param MPEG_Version The MPEG version (MPEG1 or MPEG2)
264 
265 		\return the VBR mode (Old, New, ABR, MTRH, Default or None)
266 	*/
267 //	VBRMETHOD GetVBRValue(DWORD & MaxBitrate, int & Quality, DWORD & AbrBitrate, BOOL & VBRHeader, const DWORD MPEG_Version) const;
268 
269 	/**
270 		\brief Get the Lame DLL Location
271 	*/
272 //	const char * GetDllLocation() const { return DllLocation.c_str(); }
273 	/**
274 		\brief Set the Lame DLL Location
275 	*/
276 //	void SetDllLocation( const char * the_string ) { DllLocation = the_string; }
277 
278 	/**
279 		\brief Get the output directory for encoding
280 	*/
281 //	const char * GetOutputDirectory() const { return OutputDir.c_str(); }
282 	/**
283 		\brief Set the output directory for encoding
284 	*/
285 //	void SetOutputDirectory( const char * the_string ) { OutputDir = the_string; }
286 
287 	/**
288 		\brief Get the current channel mode to use
289 	*/
290 	const unsigned int GetChannelModeValue() const;
291 	/**
292 		\brief Get the current channel mode in the form of a string
293 	*/
GetChannelModeString()294 	inline const char * GetChannelModeString() const {return GetChannelModeString(nChannelIndex); }
295 	/**
296 		\brief Get the channel mode in the form of a string for the specified Channel mode index
297 
298 		\param a_channelID the Channel mode index (see GetChannelLentgh())
299 	*/
300 	const char * GetChannelModeString(const int a_channelID) const;
301 	/**
302 		\brief Get the number of possible channel mode
303 	*/
GetChannelLentgh()304 	inline const int GetChannelLentgh() const { return 3; }
305 
306 	/**
307 		\brief Get the current preset to use, see lame documentation/code for more info on the possible presets
308 	*/
309 //	const LAME_QUALTIY_PRESET GetPresetModeValue() const;
310 	/**
311 		\brief Get the preset in the form of a string for the specified Channel mode index
312 
313 		\param a_presetID the preset index (see GetPresetLentgh())
314 	*/
315 	const char * GetPresetModeString(const int a_presetID) const;
316 	/**
317 		\brief Get the number of possible presets
318 	*/
319 //	inline const int GetPresetLentgh() const { return sizeof(the_Presets) / sizeof(LAME_QUALTIY_PRESET); }
320 
321 	/**
322 		\brief Start the user configuration process (called by AOut::config())
323 	*/
324 	bool Config(const HINSTANCE hInstance, const HWND HwndParent);
325 
326 	/**
327 		\brief Init the config dialog box with the right texts and choices
328 	*/
329 	bool InitConfigDlg(HWND hDialog);
330 
331 	/**
332 		\brief Update the instance parameters from the config dialog box
333 	*/
334 	bool UpdateValueFromDlg(HWND hDialog);
335 	/**
336 		\brief Update the config dialog box from the instance parameters
337 	*/
338 	bool UpdateDlgFromValue(HWND hDialog);
339 
340 	/**
341 		\brief Update the config dialog box with the BitRate mode
342 	*/
343 	static void DisplayVbrOptions(const HWND hDialog, const BRMode the_mode);
344 
345 	/**
346 		\brief Handle the saving of parameters when something has changed in the config dialog box
347 	*/
348 	void SaveParams(const HWND hDialog);
349 
350 	/**
351 		\brief Save the current parameters (current config in use)
352 	*/
353 	void ParamsSave(void);
354 	/**
355 		\brief Load the parameters (current config in use)
356 	*/
357 	void ParamsRestore(void);
358 
359 	/**
360 		\brief Select the specified config name as the new default one
361 	*/
362 	void SelectSavedParams(const std::string config_name);
363 	/**
364 		\brief Save the current parameters to the specified config name
365 	*/
366 	void SaveValuesToStringKey(const std::string & config_name);
367 	/**
368 		\brief Rename the current config name to something else
369 	*/
370 	bool RenameCurrentTo(const std::string & new_config_name);
371 	/**
372 		\brief Delete the config name from the saved configs
373 	*/
374 	bool DeleteConfig(const std::string & config_name);
375 
376 	ADbg              my_debug;
377 
378 	/**
379 		\brief Update the slides value (on scroll)
380 	*/
381 	void UpdateDlgFromSlides(HWND parent_window) const;
382 
383 	static ToolTipItem Tooltips[13];
384 private:
385 
386 	bool bCopyright;
387 	bool bCRC;
388 	bool bOriginal;
389 	bool bPrivate;
390 	bool bNoBitRes;
391 	BRMode mBRmode;
392 	bool bXingFrame;
393 	bool bForceChannel;
394 	bool bResample;
395 	bool bSmartOutput;
396 	bool bAbrOutput;
397 
398 	int VbrQuality;
399 	unsigned int AverageBitrate_Min;
400 	unsigned int AverageBitrate_Max;
401 	unsigned int AverageBitrate_Step;
402 
403 	double SmartRatioMax;
404 
405 	static const unsigned int the_ChannelModes[3];
406 	int nChannelIndex;
407 
408 	static const unsigned int the_Bitrates[18];
409 	static const unsigned int the_MPEG1_Bitrates[14];
410 	static const unsigned int the_MPEG2_Bitrates[14];
411 	int nMinBitrateIndex; // CBR and VBR
412 	int nMaxBitrateIndex; // only used in VBR mode
413 
414 	static const unsigned int the_SamplingFreqs[9];
415 	int nSamplingFreqIndex;
416 
417 //	static const LAME_QUALTIY_PRESET the_Presets[17];
418 	int nPresetIndex;
419 
420 //	char DllLocation[512];
421 //	std::string DllLocation;
422 //	char OutputDir[MAX_PATH];
423 //	std::string OutputDir;
424 
425 //	AParameters my_base_parameters;
426 	TiXmlDocument my_stored_data;
427 	std::string my_store_location;
428 	std::string my_current_config;
429 
430 //	HINSTANCE hDllInstance;
431 
432 	void SaveValuesToElement(TiXmlElement * the_element) const;
433 	inline void SetAttributeBool(TiXmlElement * the_elt,const std::string & the_string, const bool the_value) const;
434 	void UpdateConfigs(const HWND HwndDlg);
435 	void EnableAbrOptions(HWND hDialog, bool enable);
436 
437 	HMODULE my_hModule;
438 
439 	/**
440 		\brief
441 
442 		\param config_name
443 		\param parentNode
444 	*/
445 	void GetValuesFromKey(const std::string & config_name, const TiXmlNode & parentNode);
446 };
447 
448 #endif // !defined(_AENCODEPROPERTIES_H__INCLUDED_)
449