www.pudn.com > demo_client_VE_Lite.zip > VoiceEngine_DemoAppDlg.cpp
// VoiceEngine_DemoAppDlg.cpp : implementation file
#include "stdafx.h"
#include "VoiceEngine_DemoApp.h"
#include "VoiceEngine_DemoAppDlg.h"
#include
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVoiceEngine_DemoAppDlg dialog
CVoiceEngine_DemoAppDlg::CVoiceEngine_DemoAppDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVoiceEngine_DemoAppDlg::IDD, pParent), m_VoiceEngine(GetGipsVoiceEngineLite())
{
//{{AFX_DATA_INIT(CVoiceEngine_DemoAppDlg)
m_isacbitrate = 480;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVoiceEngine_DemoAppDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVoiceEngine_DemoAppDlg)
DDX_Control(pDX, IDC_AGC, m_AGC);
DDX_Control(pDX, IDC_SEL_MIC, m_checkoncall1);
DDX_Control(pDX, IDC_SEL_SPEAKER, m_checkoncall);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVoiceEngine_DemoAppDlg, CDialog)
//{{AFX_MSG_MAP(CVoiceEngine_DemoAppDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OnCall, OnStartListen)
ON_BN_CLICKED(IDC_OnHangUp, OnStopListen)
ON_CBN_SELCHANGE(IDC_CODEC, OnSelchangeCodec)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_DTMF, OnButtonDtmf)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_VOLPLAYBACK, OnReleasedcaptureVolplayback)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_VOLRECORDING, OnReleasedcaptureVolrecording)
ON_CBN_SELCHANGE(IDC_SEL_SPEAKER, OnSelchangeSelSpeaker)
ON_CBN_SELCHANGE(IDC_SEL_MIC, OnSelchangeSelMic)
ON_BN_CLICKED(IDC_AGC, OnAgc)
ON_BN_CLICKED(IDC_HOLDCALL3, OnHoldcall3)
ON_BN_CLICKED(IDC_MUTE1, OnMute1)
ON_WM_TIMER()
ON_BN_CLICKED(IDOK6, OnVersion)
ON_BN_CLICKED(IDOK4, OnQuit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVoiceEngine_DemoAppDlg message handlers
///////////////////////
//Here starts the sample code
BOOL CVoiceEngine_DemoAppDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int nChannelID = 0;
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// GIPS: Initialize VoiceEngine returns 0 if succesful and -1 otherwise
if(m_VoiceEngine.GIPSVE_Init(5,15,2007) == -1)
AfxMessageBox("Init failed.",MB_OK);
// GIPS: To enable Trace replace the mode in GIPSVE_SetTrace from 0 to 2,
//default file name is Trace.txt and is generated in the same directory as the executable is started from
if(m_VoiceEngine.GIPSVE_CheckIfAudioIsAvailable(1,1))
AfxMessageBox(CString("Audio device error"));
// GIPS: Checks if the Channel was created succesfully
if(m_VoiceEngine.GIPSVE_CreateChannel()== -1)
AfxMessageBox(CString("Create channel failed."));
// GIPS: Set default values for edit boxes for the testApp
SetDlgItemInt(IDC_SENDPORT, 8500);
SetDlgItemInt(IDC_RECPORT, 8500);
SetDlgItemText(IDC_SENDIP, "127.0.0.1");
// GIPS: Assume network type 0
if(m_VoiceEngine.GIPSVE_SetNetworkStatus(0))
AfxMessageBox("Set network failed.",MB_OK);
// GIPS: Get available codec list for channel
CComboBox * box;
box=(CComboBox*)GetDlgItem(IDC_CODEC);
box->ResetContent();
int num=m_VoiceEngine.GIPSVE_GetNofCodecs();
GIPS_CodecInst codecInst;
for(int i=0;iAddString(codecInst.plname);
}
box->SetCurSel(0);
// GIPS: Get available Mic list and display it in the testApp
box=(CComboBox*)GetDlgItem(IDC_SEL_MIC);
box->ResetContent();
MMRESULT deverr;
int numdev, dev;
char tmpstr[1024], tmpstr2[256];
WAVEINCAPS device;
tmpstr[0]='\0';
numdev = waveInGetNumDevs();
for (dev = 0; dev < numdev; dev++)
{
deverr = waveInGetDevCaps(dev, &device, sizeof(WAVEINCAPS));
if (deverr != MMSYSERR_NOERROR)
{
sprintf(tmpstr, "waveInGetDevCaps call failed with error %d", deverr);
AfxMessageBox(tmpstr,MB_OK);
}else
{
sprintf(tmpstr2, "Device %d is called %s\n", dev, device.szPname);
strcat(tmpstr, tmpstr2);
box->AddString(device.szPname);
}
}
box->SetCurSel(0);
// GIPS: Get available Speaker list and display it in the testApp
box=(CComboBox*)GetDlgItem(IDC_SEL_SPEAKER);
box->ResetContent();
WAVEOUTCAPS deviceOut;
tmpstr[0]='\0';
numdev = waveOutGetNumDevs();
for (dev = 0; dev < numdev; dev++)
{
deverr = waveOutGetDevCaps(dev, &deviceOut, sizeof(WAVEOUTCAPS));
if (deverr != MMSYSERR_NOERROR)
{
sprintf(tmpstr, "waveInGetDevCaps call failed with error %d", deverr);
AfxMessageBox(tmpstr,MB_OK);
}else
{
sprintf(tmpstr2, "Device %d is called %s\n", dev, deviceOut.szPname);
strcat(tmpstr, tmpstr2);
box->AddString(deviceOut.szPname);
}
}
box->SetCurSel(0);
// GIPS: Displaying DTMF Inband and Outband in the TestApp
box=(CComboBox*)GetDlgItem(IDC_DTMF_IN_OUT);
box->AddString("Inband");
box->AddString("Outband");
box->SetCurSel(0);
GIPS_CodecInst dtmfoutband = { 106 , "audio/telephone-event" , 8000 , 1600 , 0 };
m_VoiceEngine.GIPSVE_SetDTMFPayloadType(0,106);
m_VoiceEngine.GIPSVE_SetRecPayloadType(0, &dtmfoutband);
// AGC ON OnInit in the TestApp
m_AGC.SetCheck(1);
// GIPS: Enables the transmission of RTCP sender port
int res=m_VoiceEngine.GIPSVE_EnableRTCP(0,1);
if (res >= 0)
{
AfxMessageBox("WELCOME TO GIPS VoiceEngineLite");
}
// GIPS: Speaker and Microphone controls
// Making sliders for Voume and Mic in the Test APP
CSliderCtrl * slider;
slider=(CSliderCtrl *)GetDlgItem (IDC_VOLPLAYBACK);
slider->SetRangeMin(0);
slider->SetRangeMax(255);
// GIPS: Show loudspeaker level in the TestApp
int vol = m_VoiceEngine.GIPSVE_GetSpeakerVolume();
slider->SetPos(vol);
CSliderCtrl * slider2;
slider2=(CSliderCtrl *)GetDlgItem (IDC_VOLRECORDING);
slider2->SetRangeMin(0);
slider2->SetRangeMax(255);
// GIPS: Show Mic level in the TestApp
vol = m_VoiceEngine.GIPSVE_GetMicVolume();
if(vol==-1)
{
AfxMessageBox("GIPSVE_GetMicVolume() failed.",MB_OK);
} else
{
slider2->SetPos(vol);
}
SetTimer(0,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CVoiceEngine_DemoAppDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
} else
{
CDialog::OnSysCommand(nID, lParam);
}
}
//If you add a minimize button to your dialog, you will need the code below
//to draw the icon. For MFC applications using the document/view model,
//this is automatically done for you by the framework.
void CVoiceEngine_DemoAppDlg::OnPaint()
{
if (IsIconic())
{
// device context for painting
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
} else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags the minimized window.
HCURSOR CVoiceEngine_DemoAppDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// Note Start Listen function includes the functionality of Listen , Play and Send
// Its displayed as Call button in the Test APP
void CVoiceEngine_DemoAppDlg::OnStartListen()
{
m_checkoncall.EnableWindow(0);
m_checkoncall1.EnableWindow(0);
// GIPS: Set receive and send port.
if(m_VoiceEngine.GIPSVE_SetRecPort(0,GetDlgItemInt(IDC_RECPORT)) == -1)
AfxMessageBox("Set rec port failed.",MB_OK);
if(m_VoiceEngine.GIPSVE_StartListen(0))
{
AfxMessageBox("Start listen failed.",MB_OK);
}
if(m_VoiceEngine.GIPSVE_StartPlayout(0))
{
AfxMessageBox("Start playout failed.",MB_OK);
}
GIPS_CodecInst codecInst;
char sendIP[64];
CComboBox * box2;
box2=(CComboBox*)GetDlgItem(IDC_CODEC);
// GIPS: Get the preferred codec.
if(m_VoiceEngine.GIPSVE_GetCodec(box2->GetCurSel(),&codecInst) == -1)
AfxMessageBox(CString("Get codec failed."));
// GIPS: Set send codec to the preferred codec.
UpdateData(TRUE);
codecInst.pacsize = m_isacbitrate;
if(m_VoiceEngine.GIPSVE_SetSendCodec(0,&codecInst) == -1)
AfxMessageBox("Set codec failed.",MB_OK);
if(m_VoiceEngine.GIPSVE_SetSendPort(0,GetDlgItemInt(IDC_SENDPORT)) == -1)
AfxMessageBox("Set send port failed.",MB_OK);
// GIPS: Get the IP-address and cast it to char
GetDlgItemText(IDC_SENDIP,sendIP,64);
if(m_VoiceEngine.GIPSVE_SetSendIP(0,sendIP) == -1)
{
AfxMessageBox("set send ip failed.",MB_OK);
}
if(m_VoiceEngine.GIPSVE_StartSend(0))
{
AfxMessageBox("Start send failed.",MB_OK);
}
}
// Note OnStopListen includes the functionality of stop Listen , play and send
// Its displayed as HangUp Button in the TestApp
void CVoiceEngine_DemoAppDlg::OnStopListen()
{
m_checkoncall.EnableWindow(1);
m_checkoncall1.EnableWindow(1);
if(m_VoiceEngine.GIPSVE_StopListen(0))
{
AfxMessageBox("Stop listen failed for channel 0.",MB_OK);
}
if(m_VoiceEngine.GIPSVE_StopPlayout(0))
{
AfxMessageBox("Stop play failed for channel 0.",MB_OK);
}
if(m_VoiceEngine.GIPSVE_StopSend(0))
AfxMessageBox("Stop send failed for channel 0.",MB_OK);
}
// GIPS: To select the codec from the dropdowm Menu
void CVoiceEngine_DemoAppDlg::OnSelchangeCodec()
{
// GIPS: User has selected a new send codec.
GIPS_CodecInst codecInst;
CComboBox * box;
box=(CComboBox*)GetDlgItem(IDC_CODEC);
//GIPS: Get the selected codec.
if(m_VoiceEngine.GIPSVE_GetCodec(box->GetCurSel(),&codecInst) == -1)
AfxMessageBox(CString("Get codec failed."));
//GIPS: Set send codec to the selected codec.
if(m_VoiceEngine.GIPSVE_SetSendCodec(0,&codecInst) == -1)
AfxMessageBox("Set codec failed.",MB_OK);
}
// GIPS: CODEC Information
void CVoiceEngine_DemoAppDlg::OnButton7()
{
GIPS_CodecInst mycodec;
if(m_VoiceEngine.GIPSVE_GetCurrentSendCodec(0,&mycodec) == -1)
return;
char info[255];
int nChannelNum = m_VoiceEngine.GIPSVE_GetNoOfChannels();
sprintf(info,"codec pltype:%d,codec name:%s,codec plsize:%d,codec rate:%d,frequence:%d,CHANNEL:%d",
mycodec.pltype,
mycodec.plname,
mycodec.pacsize,
mycodec.rate,
mycodec.plfreq,
nChannelNum);
AfxMessageBox(info,MB_OK);
}
// GIPS:DTMF error handling
void CVoiceEngine_DemoAppDlg::OnButton8()
{
if(m_VoiceEngine.GIPSVE_PlayDTMFTone(20) == -1)
{
AfxMessageBox("play dtmf failed.",MB_OK);
char err[100];
int nErrNo = m_VoiceEngine.GIPSVE_GetLastError();
sprintf(err,"%d",nErrNo);
AfxMessageBox(err,MB_OK);
}
Sleep(1000);
if(m_VoiceEngine.GIPSVE_PlayDTMFTone(1) == -1)
{
AfxMessageBox("play dtmf failed.",MB_OK);
}
Sleep(1000);
if(m_VoiceEngine.GIPSVE_PlayDTMFTone(2) == -1)
{
AfxMessageBox("play dtmf failed.",MB_OK);
}
}
// GIPS: Sends DTMF tone 9 inband/outband
void CVoiceEngine_DemoAppDlg::OnButtonDtmf()
{
CComboBox * box3;
box3=(CComboBox*)GetDlgItem(IDC_DTMF_IN_OUT);
if(box3->GetCurSel() == 1)
{
m_VoiceEngine.GIPSVE_SendDTMF(0,9,0);
}
else
m_VoiceEngine.GIPSVE_SendDTMF(0,9,1);
}
//GIPS: Speaker Volume
void CVoiceEngine_DemoAppDlg::OnReleasedcaptureVolplayback(NMHDR* pNMHDR, LRESULT* pResult)
{
//GIPS: Get new level
CSliderCtrl * slider;
slider=(CSliderCtrl *)GetDlgItem (IDC_VOLPLAYBACK);
int vol = slider->GetPos();
m_VoiceEngine.GIPSVE_SetSpeakerVolume(vol);
*pResult = 0;
}
// GIPS: Microphone Volume
void CVoiceEngine_DemoAppDlg::OnReleasedcaptureVolrecording(NMHDR* pNMHDR, LRESULT* pResult)
{
// GIPS: Get new level
CSliderCtrl * slider;
slider=(CSliderCtrl *)GetDlgItem (IDC_VOLRECORDING);
int vol = slider->GetPos();
m_VoiceEngine.GIPSVE_SetMicVolume(vol);
*pResult = 0;
}
// GIPS: Timer for speaker and Mic
void CVoiceEngine_DemoAppDlg::OnTimer(UINT nIDEvent)
{
// GIPS: Set the volume controls' settings.
CSliderCtrl * slider;
slider=(CSliderCtrl *)GetDlgItem (IDC_VOLPLAYBACK);
slider->SetRangeMin(0);
slider->SetRangeMax(255);
// GIPS:Show loudspeaker level
unsigned int vol = m_VoiceEngine.GIPSVE_GetSpeakerVolume();
slider->SetPos((int)vol);
CSliderCtrl * slider2;
slider2=(CSliderCtrl *)GetDlgItem (IDC_VOLRECORDING);
slider2->SetRangeMin(0);
slider2->SetRangeMax(255);
// GIPS: Show recording level
vol = m_VoiceEngine.GIPSVE_GetMicVolume();
slider2->SetPos((int)vol);
SetTimer(0,2000,NULL);
CDialog::OnTimer(nIDEvent);
}
// GIPS:Change and select the speaker Device in the TestApp
void CVoiceEngine_DemoAppDlg::OnSelchangeSelSpeaker()
{
CComboBox * box1;
box1=(CComboBox*)GetDlgItem(IDC_SEL_MIC);
CComboBox * box2;
box2=(CComboBox*)GetDlgItem(IDC_SEL_SPEAKER);
// GIPS: Get the selected speaker device.
if(m_VoiceEngine.GIPSVE_SetSoundDevices(box1->GetCurSel(),box2->GetCurSel()) == -1)
{
AfxMessageBox("Change Device Error");
return ;
}
}
// GIPS: Change the MICrophone Device in the TestApp
void CVoiceEngine_DemoAppDlg::OnSelchangeSelMic()
{
CComboBox * box1;
box1=(CComboBox*)GetDlgItem(IDC_SEL_MIC);
CComboBox * box2;
box2=(CComboBox*)GetDlgItem(IDC_SEL_SPEAKER);
//GIPS: Get the selected speaker device.
if( m_VoiceEngine.GIPSVE_SetSoundDevices(box1->GetCurSel(),box2->GetCurSel()) == -1)
{
AfxMessageBox("Change Device Error");
return ;
}
}
// GIPS: Checking the Automatic Gain Control (AGC) status
void CVoiceEngine_DemoAppDlg::OnAgc()
{
short AGC= m_VoiceEngine.GIPSVE_GetAGCStatus();
if(AGC == -1)
{
AfxMessageBox("AGC functionality is not available.", MB_OK);
return;
}
else if(AGC==0)
AGC = 1;
else
{
AGC = 0;
}
m_VoiceEngine.GIPSVE_SetAGCStatus(AGC);
}
// GIPS: Function for Hold Call
void CVoiceEngine_DemoAppDlg::OnHoldcall3()
{
static bool HoldCall=false;
HoldCall=!HoldCall;
if(m_VoiceEngine.GIPSVE_PutOnHold(0,HoldCall)<0)
AfxMessageBox("Hold call error",MB_OK);
}
// GIPS: Function for MUTE
void CVoiceEngine_DemoAppDlg::OnMute1()
{
static int muted=0;
muted=!muted;
if(m_VoiceEngine.GIPSVE_MuteMic(0,muted)<0)
AfxMessageBox("Mute error",MB_OK);
}
// GIPS:Displays the Version for VoiceEngine
void CVoiceEngine_DemoAppDlg::OnVersion()
{
//GIPS: Display product versions
char txt[512];
if(m_VoiceEngine.GIPSVE_GetVersion(txt, 512)!= -1)
AfxMessageBox(txt,MB_OK);
else
AfxMessageBox("Could not display version",MB_OK);
}
// GIPS: Quits VoiceEngine
void CVoiceEngine_DemoAppDlg::OnQuit()
{
//GIPS: Terminate VoiceEngine
if(m_VoiceEngine.GIPSVE_Terminate()==-1)
AfxMessageBox("GIPSVE_Terminate returned an error.",MB_OK);
CDialog::OnOK();
}