📄 chtnt.cpp
字号:
/*----------------------------------------------------------------------------
_ _ _
/\ | | | (_)
/ \ _ __ __| |_ __ ___ _ __ ___ ___ __| |_ __ _
/ /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
/ ____ \| | | | (_| | | | (_) | | | | | | __/ (_| | | (_| |
/_/ \_\_| |_|\__,_|_| \___/|_| |_| |_|\___|\__,_|_|\__,_|
The contents of this file are subject to the Andromedia Public
License Version 1.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.andromedia.com/APL/
Software distributed under the License is distributed on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Pueblo client code, released November 4, 1998.
The Initial Developer of the Original Code is Andromedia Incorporated.
Portions created by Andromedia are Copyright (C) 1998 Andromedia
Incorporated. All Rights Reserved.
Andromedia Incorporated 415.365.6700
818 Mission Street - 2nd Floor 415.365.6701 fax
San Francisco, CA 94103
Contributor(s):
--------------------------------------------------------------------------
Chaco team: Dan Greening, Glenn Crocker, Jim Doubek,
Coyote Lussier, Pritham Shetty.
Wrote and designed original codebase.
------------------------------------------------------------------------------
Implementation of the ChTNT object, which manages the interface between
TNT and the Sound Module.
----------------------------------------------------------------------------*/
// $Header: /home/cvs/chaco/modules/client/msw/ChSound/ChTNT.cpp,v 1.18 1996/10/16 21:20:53 coyote Exp $
#include "headers.h"
#if defined( CH_USE_VOXWARE )
#include <ChReg.h>
#include "ChSpeechPrefs.h"
#include "ChSpeechStatus.h"
#include "ChTNT.h"
/*----------------------------------------------------------------------------
Constants
----------------------------------------------------------------------------*/
#define DEF_TNT_PORT 12380
/* This should be set to zero
if Voxware ever fixes the
problem of returning the
correct port number */
#define TNT_PORT DEF_TNT_PORT
/* The following is the number
of milliseconds that TNT
will continue to transmit
if it encounters silence.
Probably best not to change
this. */
#define TNT_SILENT_WINDOW 500
/* The following is the number
of milliseconds until playback
occurs. */
#define TNT_PLAYBACK_DELAY 300
/* The following is the activation
level */
#define TNT_ACTIVATION_LEVEL 160
/*----------------------------------------------------------------------------
ChTNT static member variables
----------------------------------------------------------------------------*/
ChTNT* ChTNT::m_this = 0;
int ChTNT::m_iUsage = 0;
TNT_HANDLE ChTNT::m_hTNT = 0;
ChTNTSessionMgr ChTNT::m_tntSessions;
chuint16 ChTNT::m_suTNTPort = 0;
string ChTNT::m_strTNTLocalHost;
TNT_USER_INFO ChTNT::m_userInfo;
chuint32 ChTNT::m_luMikeVolume;
chuint32 ChTNT::m_luMikeSensitivity = TNT_ACTIVATION_LEVEL;
bool ChTNT::m_boolRejectCalls = false;
ChSpeechStatus* ChTNT::m_pStatus = 0;
/*----------------------------------------------------------------------------
ChTNT public methods
----------------------------------------------------------------------------*/
ChTNT::ChTNT( ChSpeechStatus* pSpeechStatus )
{
ASSERT( 0 != pSpeechStatus );
m_pStatus = pSpeechStatus;
pSpeechStatus->SetTNT( this );
if (0 == m_iUsage)
{
TNT_INITIALIZE tntInit;
TNT_TRANSACTION_HANDLE hTransaction;
TNT_RETCODE retCode;
m_this = this;
ChMemClearStruct( &m_userInfo );
m_userInfo.wSizeOfUserInfo = sizeof( TNT_USER_INFO );
ChMemClearStruct( &tntInit );
tntInit.wSizeOfInitialize = sizeof( TNT_INITIALIZE );
tntInit.usListenPort = TNT_PORT;
tntInit.lpNotifyProc = NotifyProc;
#if defined( CH_DEBUG )
{
tntInit.dwDebugLevel = TNT_DEBUG_WARNING | TNT_DEBUG_ERROR;
}
#endif // defined( CH_DEBUG )
retCode = tntInitialize( &m_hTNT, &hTransaction, 0, &tntInit );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer, "TNT: Error calling tntInitialize (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
m_hTNT = 0;
}
else
{
chuint16 suFullDuplex = false;
retCode = tntSoundQueryDuplex( GetTNTHandle(), 0, 0,
&suFullDuplex );
retCode = tntSoundSetDevices( GetTNTHandle(), 0, 0,
!!suFullDuplex );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling "
"tntSoundSetDevices (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
retCode = tntSoundHandsOffMode( GetTNTHandle(),
TNT_HANDS_OFF_MODE );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling "
"tntSoundHandsOffMode (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
// Set the user information
ChMemClearStruct( &m_userInfo );
m_userInfo.wSizeOfUserInfo = sizeof( TNT_USER_INFO );
strcpy( m_userInfo.szFirstName, "Pueblo" );
strcpy( m_userInfo.szLastName, "User" );
retCode = tntSetUserInfo( GetTNTHandle(), &m_userInfo );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntSetUserInfo (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
UpdatePrefs();
}
}
m_iUsage++;
}
ChTNT::~ChTNT()
{
if (0 == --m_iUsage)
{
if (GetTNTHandle())
{
TNT_RETCODE retCode;
retCode = tntCleanup( GetTNTHandle() );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer, "TNT: Error calling tntCleanup (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
}
m_hTNT = 0;
}
}
/*----------------------------------------------------------------------------
ChTNT public methods
----------------------------------------------------------------------------*/
bool ChTNT::MakeCall( const string& strCallId, const string& strHost,
chuint16 suPort, chflag32 flOptions,
chflag32 flRemoteOptions )
{
TNT_USER_INFO destUserInfo;
TNT_RETCODE retCode;
TNT_TRANSACTION_HANDLE hTransaction;
bool boolSuccess;
// Copy information to be shared
ASSERT( TNT_MAX_LASTNAME_LENGTH > sizeof( chflag32 ) );
sprintf( m_userInfo.szLastName, "%d", flRemoteOptions );
strncpy( m_userInfo.szFirstName, (const char*)strCallId, TNT_MAX_LASTNAME_LENGTH );
m_userInfo.szFirstName[TNT_MAX_LASTNAME_LENGTH - 1] = '\0';
retCode = tntSetUserInfo( GetTNTHandle(), &m_userInfo );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntSetUserInfo (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
ChMemClearStruct( &destUserInfo );
destUserInfo.wSizeOfUserInfo = sizeof( TNT_USER_INFO );
strcpy( destUserInfo.szNetAddress, (const char*)strHost );
destUserInfo.usPort = suPort;
retCode = tntSessionEstablish( GetTNTHandle(), &hTransaction,
0, &destUserInfo, USE_UDP, 0 );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntEstablishSession (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
boolSuccess = false;
}
return boolSuccess;
}
bool ChTNT::Hangup( const string& strCallId )
{
bool boolSuccess;
boolSuccess = m_tntSessions.Hangup( GetTNTHandle(), strCallId );
return boolSuccess;
}
void ChTNT::ForceTalk( bool boolTalk )
{
unsigned short suState;
suState = boolTalk ? TNT_START_TALK : TNT_STOP_TALK;
tntSoundSetTalkState( GetTNTHandle(), suState );
}
void ChTNT::PlayVoxFile( const string& strFilepath )
{
TNT_RETCODE retCode = TNT_NO_ERROR;
// TNT_TRANSACTION_HANDLE hTransaction;
// retCode = tntPlaySound( GetTNTHandle(), &hTransaction, 0,
// (const char*)strFilepath, TNT_SOUND_VOX_FILE );
#if defined( CH_DEBUG )
{
if (TNT_NO_ERROR != retCode)
{
char cBuffer[160];
sprintf( cBuffer, "TNT: Error calling tntPlaySound (%hu)\n",
retCode );
TRACE( cBuffer );
}
}
#endif // defined( CH_DEBUG )
}
void ChTNT::UpdatePrefs()
{
ChRegistry reg( SOUND_PREFS_GROUP );
chint32 lVolume;
TNT_RETCODE retCode = TNT_NO_ERROR;
reg.ReadBool( SOUND_PREFS_REJECT_CALLS, m_boolRejectCalls,
SOUND_PREFS_REJECT_CALLS_DEF );
reg.Read( SOUND_PREFS_MIKE_VOLUME, m_luMikeVolume,
SOUND_PREFS_MIKE_VOLUME_DEF );
retCode = tntSoundSetRecordLevel( GetTNTHandle(), GetMikeVolume() );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntSoundSetRecordLevel (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
reg.Read( SOUND_PREFS_SPEECH_VOLUME, lVolume, SPEECH_OUT_VOLUME_MAX );
if (lVolume < 0)
{
lVolume = 0;
}
else if (lVolume > SPEECH_OUT_VOLUME_MAX)
{
lVolume = SPEECH_OUT_VOLUME_MAX;
}
retCode = tntSoundSetSpeakerVolume( GetTNTHandle(), lVolume );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntSoundSetSpeakerVolume (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntSoundMuteMicrophone (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
retCode = tntVoxSetGainControl( GetTNTHandle(), true, 5 );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntVoxGetGainControl (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
retCode = tntVoxSetActivationLevel( GetTNTHandle(),
(chuint16)GetMikeSensitivity() );
if (TNT_NO_ERROR != retCode)
{
#if defined( CH_DEBUG )
{
char cBuffer[160];
sprintf( cBuffer,
"TNT: Error calling tntVoxSetActivationLevel (%hu)\n",
retCode );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
}
}
/*----------------------------------------------------------------------------
ChTNT notification callback
----------------------------------------------------------------------------*/
TNT_RETCODE TNT_FAR TNT_PASCAL TNT_LOADDS
ChTNT::NotifyProc( TNT_HANDLE hTNT, unsigned short wMessage,
TNT_TRANSACTION_HANDLE hTransaction,
unsigned long dwParam1, unsigned long dwParam2,
TNT_USER_HANDLE hUser )
{
#if defined( CH_DEBUG )
char cBuffer[160];
#endif // defined( CH_DEBUG )
// Get the 'this' pointer
switch (wMessage)
{
case TNT_NOTIFY_INIT_STATUS:
{
break;
}
case TNT_NOTIFY_LOCAL_IP_PORT:
{
char* pstrAddress = (char*)dwParam1;
chuint16 suPort = (chuint16)dwParam2;
SetTNTPort( suPort );
#if defined( CH_DEBUG )
{
sprintf( cBuffer, "TNT: Local port is %hu\n", suPort );
TRACE( cBuffer );
}
#endif // defined( CH_DEBUG )
break;
}
case TNT_NOTIFY_MIC_VOLUME_CHANGE:
{
return TNT_NO_ERROR;
}
case TNT_NOTIFY_SPEAKER_VOLUME_CHANGE:
{
return TNT_NO_ERROR;
}
case TNT_NOTIFY_BUFFER_LEVEL_CHANGE:
{
return TNT_NO_ERROR;
}
case TNT_NOTIFY_MIC_GAINMETER_CHANGE:
{
GetStatus()->SetRecordLevel( (int)dwParam1 );
return TNT_NO_ERROR;
}
case TNT_NOTIFY_SESSION_STATUS:
{
TNT_SESSION_INFO* pSessionInfo = (TNT_SESSION_INFO*)dwParam2;
switch( dwParam1 )
{
case TNT_SESSION_ESTABLISHED:
{
TNT_RETCODE retCode;
TNT_SESSION_HANDLE hSession;
string strCallId;
chflag32 flOptions;
hSession = pSessionInfo->hSession;
strCallId = pSessionInfo->RemoteUserInfo.szFirstName;
flOptions =
atol( pSessionInfo->RemoteUserInfo.szLastName );
TRACE( "TNT: Call is established.\n" );
m_tntSessions.Set( strCallId, hSession, flOptions );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -