📄 config.c
字号:
{
nConfig++;
}
*pnEncodeSetting = nConfig - 1; // We went too far.
//
// get the time, do decode, get the time
//
//
dwTime = timeGetTime();
padsi->cbStruct = sizeof(*padsi);
padsi->pwfxSrc = (LPWAVEFORMATEX) pgsmwf;
padsi->pwfxDst = (LPWAVEFORMATEX) ppcmwf;
padsi->dwDriver = (DWORD_PTR) psi;
padsh->cbStruct = sizeof(*padsh);
padsh->pbSrc = pbGSM;
padsh->cbSrcLength = cbGSMLength;
padsh->pbDst = pbPCM;
padsh->cbDstLength = cbPCMLength;
padsh->fdwConvert = ACM_STREAMCONVERTF_BLOCKALIGN | ACM_STREAMCONVERTF_START;
gsm610Decode(padsi, padsh);
dwTime = timeGetTime() - dwTime;
//
// calculate what we might be able to do in real-time
//
//
if (dwTime == 0)
dwMaxRate = 0xFFFFFFFFL;
else
dwMaxRate = (1000L * 2L * ppcmwf->wf.nSamplesPerSec / dwTime);
if ( (0xFFFFFFFFL / pdi->nConfigPercentCPU) >= dwMaxRate )
dwMaxRate = dwMaxRate * pdi->nConfigPercentCPU / 100;
if (dwMaxRate > 0xFFFFL)
dwMaxRate = 0xFFFFL;
DPF(1,"Decode dwMaxRate=%u", dwMaxRate);
//
// Now set the configuration based on these values. We scan the
// gaRateListFormat[] array looking at the dwMonoRate to determine
// the appropriate setting.
//
nConfig = 0;
while( gaRateListFormat[nConfig].dwMonoRate < dwMaxRate &&
MSGSM610_CONFIG_NUMSETTINGS > nConfig )
{
nConfig++;
}
*pnDecodeSetting = nConfig - 1; // We went too far.
//
// Clean up
//
//
errReturn:
GlobalUnlockFree(padsh, hadsh);
GlobalUnlockFree(padsi, hadsi);
GlobalUnlockFree(ppcmwf, hpcmwf);
GlobalUnlockFree(pgsmwf, hgsmwf);
GlobalUnlockFree(pbPCM, hbPCM);
GlobalUnlockFree(pbGSM, hbGSM);
SetCursor(hCursorSave);
return uIDS;
}
//==========================================================================;
//
//
//
//
//==========================================================================;
//--------------------------------------------------------------------------;
//
// BOOL acmdDlgProcConfigure
//
// Description:
// This routine handles the configuration dialog box.
//
// Arguments:
// HWND hwnd:
//
// UINT uMsg:
//
// WPARAM wParam:
//
// LPARAM lParam:
//
// Return (BOOL):
//
//
// Note: In order to avoid using a static fHelpRunning flag which will
// still be here after we exit, we allocate an fHelpRunning
// variable in the DRIVERINSTANCE structure. This is purely to
// avoid static variables (which force us to have a data segment
// of 4K); the fHelpRunning is not used in any other procedures.
//
//--------------------------------------------------------------------------;
INT_PTR FNWCALLBACK acmdDlgProcConfigure
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
PDRIVERINSTANCE pdi;
HWND hctrlEnc;
HWND hctrlDec;
UINT uCmdId;
UINT u;
int n;
TCHAR szFormat[MSGSM610_CONFIG_TEXTLEN];
TCHAR szOutput[MSGSM610_CONFIG_TEXTLEN];
UINT nConfigMaxRTEncodeSetting;
UINT nConfigMaxRTDecodeSetting;
switch (uMsg)
{
case WM_INITDIALOG:
pdi = (PDRIVERINSTANCE)lParam;
pdi->fHelpRunning = FALSE; // Used only in this procedure.
#ifdef WIN4
//
// This driver is marked Windows Subsystem version 3.5 in order
// that it be compatible with Daytona - however, that means that
// Chicago will think it is a Win 3.1 application and give it
// Win 3.1 default colors. This makes the config dialog look
// white, whereas the Chicago default uses 3DFACE. This code
// (and the CTLCOLOR messages) sets the colors explicitly.
//
pdi->hbrDialog = CreateSolidBrush( GetSysColor(COLOR_3DFACE) );
#endif
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
nConfigMaxRTEncodeSetting = pdi->nConfigMaxRTEncodeSetting;
nConfigMaxRTDecodeSetting = pdi->nConfigMaxRTDecodeSetting;
hctrlEnc = GetDlgItem(hwnd, IDC_COMBO_MAXRTENCODE);
hctrlDec = GetDlgItem(hwnd, IDC_COMBO_MAXRTDECODE);
for( u=0; u<MSGSM610_CONFIG_NUMSETTINGS; u++ )
{
LoadString( pdi->hinst, gaRateListFormat[u].idsFormat,
szFormat, SIZEOF(szFormat) );
switch( gaRateListFormat[u].uFormatType )
{
case CONFIG_RLF_NONUMBER:
lstrcpy( szOutput, szFormat );
break;
case CONFIG_RLF_MONOONLY:
wsprintf( szOutput, szFormat,
gaRateListFormat[u].dwMonoRate );
break;
}
ComboBox_AddString(hctrlEnc, szOutput);
ComboBox_AddString(hctrlDec, szOutput);
}
ComboBox_SetCurSel( hctrlEnc, nConfigMaxRTEncodeSetting );
ComboBox_SetCurSel( hctrlDec, nConfigMaxRTDecodeSetting );
return (TRUE);
case WM_DESTROY:
pdi = (PDRIVERINSTANCE)GetWindowLongPtr(hwnd, DWLP_USER);
if (pdi->fHelpRunning)
{
WinHelp(hwnd, gszHelpFilename, HELP_QUIT, 0L);
}
#ifdef WIN4
DeleteObject( pdi->hbrDialog );
#endif
//
// Let dialog box process this message
//
//
return (FALSE);
#ifdef WIN4
//
// Handle CTLCOLOR messages to get the dialog boxes to the default
// Chicago colors. See the INITDIALOG message, above.
//
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORDLG:
case WM_CTLCOLORBTN:
SetTextColor( (HDC)wParam, GetSysColor(COLOR_WINDOWTEXT) );
SetBkColor( (HDC)wParam, GetSysColor(COLOR_3DFACE) );
pdi = (PDRIVERINSTANCE)GetWindowLongPtr(hwnd, DWLP_USER);
return (UINT_PTR)(pdi->hbrDialog);
#endif
case WM_HELP:
WinHelp(((LPHELPINFO)lParam)->hItemHandle, gszHelpFilename,
HELP_WM_HELP, (ULONG_PTR)aKeyWordIds);
return TRUE;
case WM_COMMAND:
pdi = (PDRIVERINSTANCE)GetWindowLongPtr(hwnd, DWLP_USER);
uCmdId = (UINT) wParam;
switch (uCmdId)
{
case IDC_BTN_AUTOCONFIG:
{
UINT uErrorIDS;
uErrorIDS = configAutoConfig( pdi,
&nConfigMaxRTEncodeSetting,
&nConfigMaxRTDecodeSetting );
if( 0==uErrorIDS )
{
//
// No error - set dialog box settings.
//
hctrlEnc = GetDlgItem( hwnd, IDC_COMBO_MAXRTENCODE );
ComboBox_SetCurSel( hctrlEnc, nConfigMaxRTEncodeSetting );
hctrlDec = GetDlgItem( hwnd, IDC_COMBO_MAXRTDECODE );
ComboBox_SetCurSel( hctrlDec, nConfigMaxRTDecodeSetting );
}
else
{
//
// Display error message.
//
TCHAR tstrErr[200];
TCHAR tstrErrTitle[200];
if (0 == LoadString(pdi->hinst, IDS_ERROR, tstrErrTitle, SIZEOF(tstrErrTitle)))
break;
if (0 == LoadString(pdi->hinst, uErrorIDS, tstrErr, SIZEOF(tstrErr)))
break;
MessageBox(hwnd, tstrErr, tstrErrTitle, MB_ICONEXCLAMATION | MB_OK);
}
}
break;
case IDOK:
n = DRVCNF_CANCEL;
//
// RT Encode setting
//
hctrlEnc = GetDlgItem(hwnd, IDC_COMBO_MAXRTENCODE);
nConfigMaxRTEncodeSetting = ComboBox_GetCurSel( hctrlEnc );
if (nConfigMaxRTEncodeSetting != pdi->nConfigMaxRTEncodeSetting)
{
pdi->nConfigMaxRTEncodeSetting = nConfigMaxRTEncodeSetting;
n = DRVCNF_OK;
}
//
// RT Decode setting
//
hctrlDec = GetDlgItem(hwnd, IDC_COMBO_MAXRTDECODE);
nConfigMaxRTDecodeSetting = ComboBox_GetCurSel( hctrlDec );
if (nConfigMaxRTDecodeSetting != pdi->nConfigMaxRTDecodeSetting)
{
pdi->nConfigMaxRTDecodeSetting = nConfigMaxRTDecodeSetting;
n = DRVCNF_OK;
}
//
// If we changed something, write the data to the
// registry.
//
if( DRVCNF_OK == n )
{
configWriteConfiguration( pdi );
}
EndDialog(hwnd, DRVCNF_OK);
break;
case IDCANCEL:
EndDialog(hwnd, DRVCNF_CANCEL);
break;
case IDC_BTN_HELP:
pdi->fHelpRunning = TRUE;
WinHelp(hwnd, gszHelpFilename, HELP_CONTEXT, HELPCONTEXT_MSGSM610);
break;
}
return (TRUE);
}
return (FALSE);
} // gsm610DlgProcConfigure()
//--------------------------------------------------------------------------;
//
// BOOL acmdDriverConfigInit
//
// Description:
// This routine initializes the configuration parameters by reading them
// from the registry. If there are no entries in the registry, this
// codec auto-configures itself and writes the results to the registry.
// If the auto-configure fails, or if we don't know our alias name,
// then we set the configuration to default values.
//
// Arguments:
// PDRIVERINSTANCE pdi:
//
// LPCTSTR pszAliasName:
//
// Return (BOOL):
//
//
//--------------------------------------------------------------------------;
BOOL FNGLOBAL acmdDriverConfigInit
(
PDRIVERINSTANCE pdi,
LPCTSTR pszAliasName
)
{
HKEY hkey;
UINT nEncodeSetting;
UINT nDecodeSetting;
UINT uErrorIDS;
//
// If pszAliasName is NULL then just set all defaults
//
//
if (NULL == pszAliasName)
{
DPF(2,"acmdDriverConfigInit: no alias name; using default settings.");
configSetDefaults( pdi );
return (TRUE);
}
//
// If we haven't got an open hkey, then open it. Note that this routine
// may be called more than once; on the second time, we should not
// re-open the key.
//
if( NULL == pdi->hkey )
{
RegCreateKeyEx( MSGSM610_CONFIG_DEFAULTKEY, gszMultimediaKey, 0,
NULL, 0, KEY_CREATE_SUB_KEY, NULL, &hkey, NULL );
if( NULL != hkey )
{
ASSERT( NULL != pszAliasName );
RegCreateKeyEx( hkey, pszAliasName, 0, NULL, 0,
KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
NULL, &pdi->hkey, NULL );
RegCloseKey( hkey );
}
}
//
// Read configuration data from registry.
//
if( NULL == pdi->hkey )
{
configSetDefaults( pdi );
}
else
{
pdi->nConfigMaxRTEncodeSetting =
(UINT)dwReadRegistryDefault( pdi->hkey,
(LPTSTR)gszMaxRTEncodeSetting,
MSGSM610_CONFIG_UNCONFIGURED );
pdi->nConfigMaxRTDecodeSetting =
(UINT)dwReadRegistryDefault( pdi->hkey,
(LPTSTR)gszMaxRTDecodeSetting,
MSGSM610_CONFIG_UNCONFIGURED );
pdi->nConfigPercentCPU =
(UINT)dwReadRegistryDefault( pdi->hkey,
(LPTSTR)gszPercentCPU,
MSGSM610_CONFIG_DEFAULT_PERCENTCPU );
//
// Check that nConfigPercentCPU is a valid value.
//
if( pdi->nConfigPercentCPU <= 0 )
{
pdi->nConfigPercentCPU = MSGSM610_CONFIG_DEFAULT_PERCENTCPU;
}
}
//
// If either the encode or decode setting is out of range, then
// we call the auto-configure routine and write out the results.
// This should only happen the first time the codec is run.
//
if( MSGSM610_CONFIG_NUMSETTINGS <= pdi->nConfigMaxRTEncodeSetting ||
MSGSM610_CONFIG_NUMSETTINGS <= pdi->nConfigMaxRTDecodeSetting )
{
DPF( 1, "acmdDriverConfigInit: performing initial auto-config." );
uErrorIDS = configAutoConfig( pdi,
&nEncodeSetting,
&nDecodeSetting );
if( 0 != uErrorIDS )
{
//
// Error in auto-config. Use defaults instead.
//
nEncodeSetting = MSGSM610_CONFIG_DEFAULT_MAXRTENCODESETTING;
nDecodeSetting = MSGSM610_CONFIG_DEFAULT_MAXRTDECODESETTING;
}
pdi->nConfigMaxRTEncodeSetting = nEncodeSetting;
pdi->nConfigMaxRTDecodeSetting = nDecodeSetting;
//
// Always write the results to the registry, even if we hit an
// error, so we won't hit the automatic auto-config next
// time we run. One failure is enough!
//
configWriteConfiguration( pdi );
}
return (TRUE);
} // acmdDriverConfigInit()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -