📄 acm.cpp
字号:
/** * * Lame ACM wrapper, encode/decode MP3 based RIFF/AVI files in MS Windows * * Copyright (c) 2002 Steve Lhomme <steve.lhomme at free.fr> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 * */ /*! \author Steve Lhomme \version \$Id: ACM.cpp,v 1.18 2005/03/13 14:43:21 robert Exp $*/#if !defined(STRICT)#define STRICT#endif // STRICT#include <algorithm>#include <windows.h>#include <windowsx.h>#include <intshcut.h>#include <mmreg.h>#include <msacm.h>#include <msacmdrv.h>#include <assert.h>#include <version.h>#include "adebug.h"#include "resource.h"#include "ACMStream.h"#ifdef ENABLE_DECODING#include "DecodeStream.h"#endif // ENABLE_DECODING#include "ACM.h"#ifndef IDC_HAND#define IDC_HAND MAKEINTRESOURCE(32649)#endif // IDC_HANDchar ACM::VersionString[20];const char ACM_VERSION[] = "0.9.0";#ifdef WIN32//// 32-bit versions//#if (WINVER >= 0x0400) #define VERSION_ACM_DRIVER MAKE_ACM_VERSION(4, 0, 0)#else#define VERSION_ACM_DRIVER MAKE_ACM_VERSION(3, 51, 0)#endif#define VERSION_MSACM MAKE_ACM_VERSION(3, 50, 0)#else//// 16-bit versions//#define VERSION_ACM_DRIVER MAKE_ACM_VERSION(1, 0, 0)#define VERSION_MSACM MAKE_ACM_VERSION(2, 1, 0)#endif#define PERSONAL_FORMAT WAVE_FORMAT_MPEGLAYER3#define SIZE_FORMAT_STRUCT sizeof(MPEGLAYER3WAVEFORMAT)//#define SIZE_FORMAT_STRUCT 0//static const char channel_mode[][13] = {"mono","stereo","joint stereo","dual channel"};static const char channel_mode[][13] = {"mono","stereo"};static const unsigned int mpeg1_freq[] = {48000,44100,32000};static const unsigned int mpeg2_freq[] = {24000,22050,16000,12000,11025,8000};static const unsigned int mpeg1_bitrate[] = {320, 256, 224, 192, 160, 128, 112, 96, 80, 64, 56, 48, 40, 32};static const unsigned int mpeg2_bitrate[] = {160, 144, 128, 112, 96, 80, 64, 56, 48, 40, 32, 24, 16, 8};#define SIZE_CHANNEL_MODE (sizeof(channel_mode) / (sizeof(char) * 13))#define SIZE_FREQ_MPEG1 (sizeof(mpeg1_freq) / sizeof(unsigned int))#define SIZE_FREQ_MPEG2 (sizeof(mpeg2_freq) / sizeof(unsigned int))#define SIZE_BITRATE_MPEG1 (sizeof(mpeg1_bitrate) / sizeof(unsigned int))#define SIZE_BITRATE_MPEG2 (sizeof(mpeg2_bitrate) / sizeof(unsigned int))static const int FORMAT_TAG_MAX_NB = 2; // PCM and PERSONAL (mandatory to have at least PCM and your format)static const int FILTER_TAG_MAX_NB = 0; // this is a codec, not a filter// number of supported PCM formatsstatic const int FORMAT_MAX_NB_PCM = 2 * // number of PCM channel mode (stereo/mono) (SIZE_FREQ_MPEG1 + // number of MPEG 1 sampling freq SIZE_FREQ_MPEG2); // number of MPEG 2 sampling freq//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bool bitrate_item::operator<(const bitrate_item & other_bitrate) const{ return (other_bitrate.frequency < frequency || (other_bitrate.frequency == frequency && (other_bitrate.bitrate < bitrate || (other_bitrate.bitrate == bitrate && (other_bitrate.channels < channels)))));}//////////////////////////////////////////////////////////////////////// Configuration Dialog///////////////////////////////////////////////////////////////////////*static CALLBACK ConfigProc( HWND hwndDlg, // handle to dialog boxUINT uMsg, // messageWPARAM wParam, // first message parameterLPARAM lParam // second message parameter){ BOOL bResult; switch (uMsg) { case WM_COMMAND: UINT command; command = GET_WM_COMMAND_ID(wParam, lParam); if (IDOK == command) { EndDialog(hwndDlg, (IDOK == command)); } else if (IDCANCEL == command) { EndDialog(hwndDlg, (IDOK == command)); } bResult = FALSE; break; default: bResult = FALSE; // will be treated by DefWindowProc} return bResult;}inline DWORD ACM::Configure(HWND hParentWindow, LPDRVCONFIGINFO pConfig){ my_debug.OutPut(DEBUG_LEVEL_FUNC_START, "ACM : Configure (Parent Window = 0x%08X)",hParentWindow); DialogBoxParam( my_hModule, MAKEINTRESOURCE(IDD_CONFIG), hParentWindow, ::ConfigProc , (LPARAM)this); return DRVCNF_OK; // Can also return // DRVCNF_CANCEL // and DRVCNF_RESTART}*///////////////////////////////////////////////////////////////////////// About Dialog//////////////////////////////////////////////////////////////////////static BOOL CALLBACK AboutProc( HWND hwndDlg, // handle to dialog boxUINT uMsg, // messageWPARAM wParam, // first message parameterLPARAM lParam // second message parameter){ static HBRUSH hBrushStatic = NULL;// static LOGFONT lf; // structure for font information // static HFONT hfnt; static HCURSOR hcOverCursor = NULL; BOOL bResult; switch (uMsg) { case WM_INITDIALOG: char tmp[150]; wsprintf(tmp,"LAME MP3 codec v%s", ACM::GetVersionString()); ::SetWindowText(GetDlgItem( hwndDlg, IDC_STATIC_ABOUT_TITLE), tmp);/* ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf); lf.lfUnderline = TRUE; hfnt = ::CreateFontIndirect(&lf); ::SendMessage(::GetDlgItem(hwndDlg,IDC_STATIC_ABOUT_URL), WM_SETFONT, (WPARAM) hfnt, TRUE);* / hBrushStatic = ::CreateSolidBrush(::GetSysColor (COLOR_BTNFACE));*/ hcOverCursor = ::LoadCursor(NULL,(LPCTSTR)IDC_HAND); if (hcOverCursor == NULL) hcOverCursor = ::LoadCursor(NULL,(LPCTSTR)IDC_CROSS); bResult = TRUE; break;/* case WM_CTLCOLORSTATIC: /// \todo only if there are URLs if ((HWND)lParam == ::GetDlgItem(hwndDlg,IDC_STATIC_ABOUT_URL)) { ::SetTextColor((HDC)wParam, ::GetSysColor (COLOR_HIGHLIGHT)); ::SetBkColor((HDC)wParam, ::GetSysColor (COLOR_BTNFACE)); return (LRESULT) hBrushStatic; } else return (LRESULT) NULL;*/ case WM_MOUSEMOVE: { POINT pnt; ::GetCursorPos(&pnt); RECT rect; ::GetWindowRect( ::GetDlgItem(hwndDlg,IDC_STATIC_ABOUT_URL), &rect); if ( ::PtInRect(&rect,pnt) ) { ::SetCursor(hcOverCursor); } } break; case WM_LBUTTONUP: { POINT pnt; ::GetCursorPos(&pnt); RECT rect; ::GetWindowRect( ::GetDlgItem(hwndDlg,IDC_STATIC_ABOUT_URL), &rect); TCHAR Url[200]; bool bUrl = false; if (::PtInRect(&rect,pnt)) { wsprintf(Url,LAME_URL); bUrl = true; } if (bUrl) { LPSTR tmpStr; HRESULT hresult = ::TranslateURL(Url, TRANSLATEURL_FL_GUESS_PROTOCOL|TRANSLATEURL_FL_GUESS_PROTOCOL, &tmpStr); if (hresult == S_OK) ::ShellExecute(hwndDlg,"open",tmpStr,NULL,"",SW_SHOWMAXIMIZED ); else if (hresult == S_FALSE) ::ShellExecute(hwndDlg,"open",Url,NULL,"",SW_SHOWMAXIMIZED ); } } break; case WM_COMMAND: UINT command; command = GET_WM_COMMAND_ID(wParam, lParam); if (IDOK == command) { EndDialog(hwndDlg, TRUE); } bResult = FALSE; break; case IDC_STATIC_ABOUT_URL: break; default: bResult = FALSE; // will be treated by DefWindowProc} return bResult;}inline DWORD ACM::About(HWND hParentWindow){ my_debug.OutPut(DEBUG_LEVEL_FUNC_START, "ACM : About (Parent Window = 0x%08X)",hParentWindow); DialogBoxParam( my_hModule, MAKEINTRESOURCE(IDD_ABOUT), hParentWindow, ::AboutProc , (LPARAM)this); return DRVCNF_OK; // Can also return// DRVCNF_CANCEL// and DRVCNF_RESTART}//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////ACM::ACM( HMODULE hModule ) :my_hModule(hModule), my_hIcon(NULL), my_debug(ADbg(DEBUG_LEVEL_CREATION)), my_EncodingProperties(hModule){ my_EncodingProperties.ParamsRestore(); /// \todo get the debug level from the registry unsigned char DebugFileName[512]; char tmp[128]; wsprintf(tmp,"LAMEacm 0x%08X",this); my_debug.setPrefix(tmp); /// \todo get it from the registry my_debug.setIncludeTime(true); /// \todo get it from the registry // Check in the registry if we have to Output Debug information DebugFileName[0] = '\0'; HKEY OssKey; if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\MUKOLI", 0, KEY_READ , &OssKey ) == ERROR_SUCCESS) { DWORD DataType; DWORD DebugFileNameSize = 512; if (RegQueryValueEx( OssKey, "DebugFile", NULL, &DataType, DebugFileName, &DebugFileNameSize ) == ERROR_SUCCESS) { if (DataType == REG_SZ) { my_debug.setUseFile(true); my_debug.setDebugFile((char *)DebugFileName); my_debug.OutPut("Debug file is %s",(char *)DebugFileName); } } }#if LAME_ALPHA_VERSION > 0 wsprintf(VersionString,"%s - %d.%d (alpha %d)", ACM_VERSION, LAME_MAJOR_VERSION, LAME_MINOR_VERSION,LAME_PATCH_VERSION);#elif LAME_BETA_VERSION > 0 wsprintf(VersionString,"%s - %d.%d (beta %d)", ACM_VERSION, LAME_MAJOR_VERSION, LAME_MINOR_VERSION, LAME_PATCH_VERSION);#else wsprintf(VersionString,"%s - %d.%d (stable)", ACM_VERSION, LAME_MAJOR_VERSION, LAME_MINOR_VERSION);#endif BuildBitrateTable(); my_debug.OutPut(DEBUG_LEVEL_FUNC_START, "New ACM Creation (0x%08X)",this);}ACM::~ACM(){// not used, it's done automatically when closing the driver if (my_hIcon != NULL)// CloseHandle(my_hIcon); bitrate_table.clear(); my_debug.OutPut(DEBUG_LEVEL_FUNC_START, "ACM Deleted (0x%08X)",this);}//////////////////////////////////////////////////////////////////////// Main message handler//////////////////////////////////////////////////////////////////////LONG ACM::DriverProcedure(const HDRVR hdrvr, const UINT msg, LONG lParam1, LONG lParam2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -