⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channel.cpp

📁 VC++开发的一个电话录音程序
💻 CPP
字号:
#include "stdafx.h"
#include "PhoneRec.h"
#include "Channel.h"
#include "PhonicDll.h"
#include "PhoneRecView.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

extern CPhoneRecView* g_pMgr;
extern CDatabase g_dbCust;	


LPCTSTR GetChannelTypeText( int iChannelType )
{
	switch(iChannelType)
	{
	case CH_USER:			return "内线";
	case CH_ANALOG_TRUNK:	return "外线";
	case CH_HIGH_IMPEDANCE:	return "高阻";
	case CH_DIGITAL_TRUNK:	return "数字";
	case CH_MAX:			return " 空 ";
	default:				return "未知";
	}
}


LPCTSTR GetStateString(int State)
{
	switch( State )
	{
	case STATE_IDLE:			return _T("IDLE");
	case STATE_IN_CALLING:		return _T("I_CALLING");
	case STATE_IN_RINGING:		return _T("I_RINGING");
	case STATE_IN_TALK:			return _T("I_TALK");
	case STATE_IN_HANGUP:		return _T("I_HANGUP");
	case STATE_IN_RELEASE:		return _T("I_RELEASE");
	case STATE_OUT_CALLING:		return _T("O_CALLING");
	case STATE_OUT_RINGING:		return _T("O_RINGING");
	case STATE_OUT_TALK:		return _T("O_TALK");
	case STATE_OUT_HANGUP:		return _T("O_HANGUP");
	case STATE_OUT_RELEASE:		return _T("O_RELEASE");
	case STATE_DISABLE:			return _T("DISABLE");
	}
	return _T("???");
}

//取得配置文件路径
CString GetConfigFilePath()
{
	//当前文件路径
	char FileBuffer[100];
	DWORD b = GetModuleFileName( AfxGetInstanceHandle(), FileBuffer, 256);
	CString strFilePath(FileBuffer);
	strFilePath.Delete(strFilePath.GetLength()-12,12);
	strFilePath = strFilePath +"\\ReSavePath.ini";
	return strFilePath;
}

//获取录音文件根目录
CString GetReSaveHomePath()
{
	char FilePathBuffer[100];
	CString strTempPath;

	GetPrivateProfileString( "Record", "Path", "C:\\Record", FilePathBuffer, 10, GetConfigFilePath() );	
	strTempPath = FilePathBuffer;
	return strTempPath;
}

//检查文件目录是否已经创建
void CheckCreateDir( CString strPath)
{
	if(  !PathFileExists( strPath ) )
	{
		CString	strDir = strPath;
		CString	strTmpDir;
		int iFind, iStartPos;
		
		iStartPos = 0;
		iFind = strDir.Find( ':', iStartPos);
		if( iFind >= 0 )
		{
			iStartPos = iFind+2;
		}
		
		do
		{
			iFind = strDir.Find( '\\', iStartPos);
			if( iFind == 0 ) 
			{
				iStartPos = iFind+1;
				continue;
			}
			else if( iFind > 0 ) 
			{
				strTmpDir = strDir.Left( iFind );
				if( !PathFileExists( strPath ) )
				{
					CreateDirectory( (LPCTSTR)strTmpDir, NULL );
				}	
				iStartPos = iFind+1;
			}
			else
			{
				if( !PathFileExists( strPath ) )
				{
					CreateDirectory( (LPCTSTR)strDir, NULL );				
				}
				break;
			}
		}while(1);
	}
}

CChannel::CChannel( int iLineID, CPhonic* pCtrl )
{
 
	m_pCtrl = pCtrl;
	m_iLineID = iLineID;
	m_eChannelType	= ( EChannelType )( pCtrl->GetChannelType( m_iLineID ));
	m_iChannelID	= pCtrl->GetChannelID( m_iLineID );

	switch(m_eChannelType)
	{
	case CH_USER:
		m_eLineImage = imgPhoneNormal;
		break;
	case CH_ANALOG_TRUNK:
		m_eLineImage = imgPhoneNormal;
		break;
	case CH_HIGH_IMPEDANCE:
		m_eLineImage = imgMonitorNormal;
		break;
	case CH_MAX:
		m_eLineImage = imgSpace;
		break;
	}
	
	GetEnableRecord();
	GetPhone();
	GetReMode();
}

CChannel::~CChannel()
{

}

void CChannel::OnState(int state)
{
	m_iChannelState = state;
	
	switch( m_eChannelType )
	{
	case CH_USER:
	case CH_ANALOG_TRUNK:
		switch(m_iChannelState)
		{
		case STATE_IN_CALLING:
		case STATE_IN_RINGING:
		case STATE_OUT_CALLING:
		case STATE_OUT_RINGING:
			m_eLineImage = imgPhoneRing;
			break;
		case STATE_OUT_TALK:
		case STATE_IN_TALK:
			m_eLineImage = imgPhoneTalk;
			break;
		case STATE_IN_RELEASE:
		case STATE_IN_HANGUP:
		case STATE_IDLE:
		case STATE_OUT_HANGUP:
		case STATE_OUT_RELEASE:
		case STATE_DISABLE:
			m_eLineImage = imgPhoneNormal;
			break;
		}
		break;
		case CH_HIGH_IMPEDANCE:
			switch(m_iChannelState)
			{
			case STATE_IN_CALLING:
			case STATE_IN_RINGING:
			case STATE_OUT_CALLING:
			case STATE_OUT_RINGING:
				m_eLineImage = imgMonitorRing;
				break;
			case STATE_OUT_TALK:
			case STATE_IN_TALK:
				m_eLineImage = imgMonitorTalk;
				break;
			case STATE_IN_RELEASE:
			case STATE_IN_HANGUP:
			case STATE_IDLE:
			case STATE_OUT_HANGUP:
			case STATE_OUT_RELEASE:
			case STATE_DISABLE:
				m_eLineImage = imgMonitorNormal;
				break;
			}
			break;
			case CH_MAX:
				m_eLineImage = imgSpace;
				break;
	}
	ShowChannelState();
}
void CChannel::ShowChannelState(void)
{
	g_pMgr->m_pButtonArray[ GetLineID()]->SetIcon( g_pMgr->m_LargeImageList.ExtractIcon( GetLineImage() ) );	
}

void CChannel::OnIdle()
{

}

void CChannel::OnCallIn(char *callerID, char *phoneNum)
{
	m_strCallerID	= callerID;
	CTime curTime = CTime::GetCurrentTime();
	m_strCallTime = curTime.Format("%y-%m-%d  %H:%M:%S");
	
	m_strDTMF.Empty();
	
	ShowChannelState();
}

void CChannel::OnCallOutFinish()
{
	m_strDTMF.Empty();
}

void CChannel::OnCallFail(int cause)
{
	Hangup();
}

void CChannel::OnHangup(int cause)
{
	Hangup();
}

void CChannel::OnDTMF(char dtmf)
{
	m_strDTMF += dtmf;
	
	ShowChannelState();
}

void CChannel::OnPlayEnd(int completeSize)
{
	StopPlay();
}

void CChannel::OnRecordEnd(int completeSize)
{
	StopRecord();
}

void CChannel::OnFlash() 
{

}

void CChannel::OnRing()
{

}

void CChannel::OnDeviceTimer()
{

}

void CChannel::OnAnswer()
{
	Answer( );
}

int  CChannel::TalkWith(int srcType, int srcID)
{
	return m_pCtrl->TalkWith( GetChannelType(), GetChannelID(), srcType, srcID);
}

int  CChannel::BreakTalk()
{
	return m_pCtrl->BreakTalk( GetChannelType(), GetChannelID() );
}

int  CChannel::ListenTo(int srcType, int srcID)
{
	return m_pCtrl->ListenTo( GetChannelType(), GetChannelID(), srcType, srcID );
}

int  CChannel::BreakListen()
{
	return m_pCtrl->BreakListen( GetChannelType(), GetChannelID() );
}

int  CChannel::SetDeviceTimer( int timer)
{
	return m_pCtrl->SetDeviceTimer( GetChannelType(), GetChannelID(), timer );
}

int  CChannel::ClearDeviceTimer()
{
	return m_pCtrl->ClearDeviceTimer( GetChannelType(), GetChannelID() );
}

int  CChannel::MakeCall( const char * callerID, const char * phoneNumber, int overtime)
{
	return m_pCtrl->MakeCall( GetChannelType(), GetChannelID(), callerID, phoneNumber, overtime );
}

int  CChannel::Answer()
{
	return m_pCtrl->Answer( GetChannelType(), GetChannelID(), 1 );
}

int  CChannel::Hangup()
{
	StopPlay();
	StopRecord();
	BreakTalk();
	BreakListen();
	m_strDTMF.Empty();
	ShowChannelState();

	return m_pCtrl->Hangup( GetChannelType(), GetChannelID(), 0 );
}

int  CChannel::SetVoiceVolume( int volume, int type)
{
	return m_pCtrl->SetVoiceVolume( GetChannelType(), GetChannelID(), volume, type );
}

int  CChannel::SetVoiceCoder( int lCoder)
{
	return 0;
	//return m_pCtrl->SetVoiceCoder( GetChannelType(), GetChannelID(), lCoder );
}

int  CChannel::PlayPromptVoice( int pmtIndex, int loopCount)
{
	return m_pCtrl->PlayPromptVoice( GetChannelType(), GetChannelID(), pmtIndex, loopCount );
}

int  CChannel::PlayPromptVoiceArray( long* pPmtIndexArray, int pmtCount, int loopCount)
{
	return m_pCtrl->PlayPromptVoiceArray( GetChannelType(), GetChannelID(), pPmtIndexArray, pmtCount, loopCount );
}

int  CChannel::PlayFile( const char * fileName, int offset, int voiceSize)
{
	return m_pCtrl->PlayFile( GetChannelType(), GetChannelID(), fileName, offset, voiceSize );
}

int  CChannel::PlayPause( int bPause)
{
	return m_pCtrl->PlayPause( GetChannelType(), GetChannelID(), bPause );
}

int  CChannel::SendDtmf( const char * dtmfString, int toneTime, int silenceTime, int scale)
{
	return m_pCtrl->SendDtmf( GetChannelType(), GetChannelID(), dtmfString, toneTime, silenceTime, scale );
}

int  CChannel::PlayTone( float fFrequency, int dwTimeLength, int dwScale, const char * attrib)
{
	return m_pCtrl->PlayTone( GetChannelType(), GetChannelID(), fFrequency, dwTimeLength, dwScale, attrib );
}

int  CChannel::PlayText( const char * text, int isMale, int speed)
{
	return m_pCtrl->PlayText( GetChannelType(), GetChannelID(), text, isMale, speed );
}

int  CChannel::PlayTextFile( char* text, int isMale, int speed)
{
	return m_pCtrl->PlayTextFile( GetChannelType(), GetChannelID(), text, isMale, speed );
}

int  CChannel::StopPlay()
{
	return m_pCtrl->StopPlay( GetChannelType(), GetChannelID() );
}

int  CChannel::RecordFile( const char * fileName, int offset, int voiceSize)
{
	return m_pCtrl->RecordFile( GetChannelType(), GetChannelID(), fileName, offset, voiceSize );
}

int  CChannel::RecordPause( int bPause)
{
	return m_pCtrl->RecordPause( GetChannelType(), GetChannelID(), bPause );
}

int  CChannel::StopRecord()
{
	return m_pCtrl->StopRecord( GetChannelType(), GetChannelID() );
}

int CChannel::SetSilenceThreshold(long lSilenceThreshold)
{
	return m_pCtrl->SetSilenceThreshold( GetChannelType(), GetChannelID(), lSilenceThreshold );
}

//初始化通道号码
void CChannel::GetPhone()
{
	CRecordset rs( &g_dbCust );

	CString strLineID;

	strLineID.Format("%d", GetLineID() );

	CString strSQL = "Select PhoneNum  from LineSet where LineID = '"+ strLineID + "'" ;
	
	rs.Open( CRecordset::dynaset, _T( strSQL ) );

	while( !rs.IsEOF( ) )
	{
		rs.GetFieldValue( "PhoneNum", m_strPhone );
		break;
	}

	rs.Close();
}

//初始化通道录音是否启动
void CChannel::GetEnableRecord()
{
	CRecordset rs( &g_dbCust );

	CString strReEab;

	CString strLineID;
	
	strLineID.Format("%d", GetLineID() );

	CString strSQL = "Select ReEable  from LineSet where LineID = '"+ strLineID + "'" ;
	
	rs.Open( CRecordset::dynaset, _T( strSQL ) );

	while( !rs.IsEOF( ) )
	{
		rs.GetFieldValue( "ReEable", strReEab );
		break;
	}
	rs.Close();
	
	m_bRecordEnable = atoi( strReEab );
}

//初始化通道录音录音方式
void CChannel::GetReMode()
{
	CRecordset rs( &g_dbCust );

	CString strReMode;

	CString strLineID;

	strLineID.Format("%d", GetLineID() );

	CString strSQL = "Select ReMode  from LineSet where LineID = '"+ strLineID + "'" ;
	
	rs.Open( CRecordset::dynaset, _T( strSQL ) );

	while( !rs.IsEOF( ) )
	{
		rs.GetFieldValue( "ReMode", strReMode );
		break;
	}
	rs.Close();
	
	m_bRecordMode = atoi( strReMode );
}

BOOL CChannel::ParseFskCallerID(const char * buffer, int len)
{
	int iBase,i;
	if( !buffer)
		return FALSE;
	// invalide caller id
	if( len > 64)
		return FALSE;

	if( buffer[0] == 0xff ||  buffer[0] == 0xfd ||  buffer[0] == 0xf5 || buffer[0] == 0xd5)
		iBase = 3;
	else
		iBase = 2;

	if( len >= iBase+8)
	{
		for(i = iBase ; i < iBase+8  ; i ++)
		{
			//m_strCalleeNumber += buffer[i];
		}
		for( ; i < len ;  i++)
		{
			m_strCallerID += buffer[i];
		}
		return TRUE;
	}	 
	else
	{
		m_strCallerID.Empty();
		return FALSE;
	}
	return FALSE;
}















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -