123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- // VoiceExchange.cpp : implementation file
- //
- #include "stdafx.h"
- #include "newclient.h"
- #include "VoiceExchange.h"
- #include "newclientDlg.h"
- #include "Interface.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CVoiceExchange dialog
- extern SERVER_INFO serverinfo[MAXIPNUMBER];
- LONG lVoiceIndex = -1;
- HANDLE hSendFile = NULL;
- HANDLE hRevFile = NULL;
- DWORD dwReturn = 0;
- CONST BYTE FileHeader[40] = {0x34,0x48,0x4B,0x48,0xFE,0xB3,0xD0,0xD6,0x08,0x03,0x04,0x20,0x00,0x00,0x00,0x00,
- 0x02,0x10,0x01,0x10,0x01,0x10,0x10,0x00,0x80,0x3E,0x00,0x00,0x60,0x01,0x20,0x01,
- 0x11,0x10,0x00,0x00,0x00,0x00,0x00,0x00};
- LPVOID phis = NULL;
- BYTE outbuf[1280];
- BYTE inbuf[80];
- //语音对讲时的数据回调,byAudioFlag = 0表示采集到的数据,byAudioFlag = 1表示接收到的数据
- void CALLBACK fVoiceDataCallBack(LONG lVoiceComHandle,char *pRecvDataBuffer,DWORD dwBufSize,BYTE byAudioFlag,DWORD dwUser)
- {
- #if 0
- if(byAudioFlag == 0)
- {
- if(hSendFile)
- {
- if(phis)
- {
- NET_DVR_EncodeG722Frame(phis, (LPBYTE)pRecvDataBuffer, outbuf);
- }
- WriteFile(hSendFile, /*pRecvDataBuffer*/outbuf, /*dwBufSize*/80, &dwReturn, NULL);
- }
- }
- else
- if(byAudioFlag == 1)
- {
- if(hRevFile)
- {
- if(phis)
- {
- memcpy(inbuf, (LPBYTE)pRecvDataBuffer, 80);
- NET_DVR_DecodeG722Frame(phis, inbuf, outbuf);
- }
- WriteFile(hRevFile, /*pRecvDataBuffer*/outbuf, /*dwBufSize*/1280, &dwReturn, NULL);
- }
- }
- #endif
- }
- CVoiceExchange::CVoiceExchange(CWnd* pParent /*=NULL*/)
- : CDialog(CVoiceExchange::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CVoiceExchange)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CVoiceExchange::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CVoiceExchange)
- DDX_Control(pDX, IDC_COMBOAUDEXCH, m_ServerCtrl);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CVoiceExchange, CDialog)
- //{{AFX_MSG_MAP(CVoiceExchange)
- ON_BN_CLICKED(IDC_AUDSTART, OnAudstart)
- ON_CBN_SELCHANGE(IDC_COMBOAUDEXCH, OnSelchangeComboaudexch)
- ON_BN_CLICKED(IDEXIT, OnExit)
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CVoiceExchange message handlers
- BOOL CVoiceExchange::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- int i, iNum;
-
- m_ServerCtrl.InsertString(0,"请选择视频服务器地址");
- for(i = 0; i < MAXIPNUMBER; i++)
- {
- if(serverinfo[i].m_iServerChannelNumber >= 0)
- {
- iNum = m_ServerCtrl.AddString(serverinfo[i].m_csServerName);
- m_ServerCtrl.SetItemData(iNum, i);
- }
- }
- m_ServerCtrl.SetCurSel(0);
- /*
- phis = NET_DVR_InitG722Decoder(16000);
- if(phis == NULL)
- {
- AfxMessageBox("!!!!!");
- }
-
- hRevFile = CreateFile("c:\\aaa.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hRevFile == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
- */
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void CVoiceExchange::OnAudstart()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(m_ServerCtrl.GetCurSel()==0)
- {
- AfxMessageBox("请选择视频服务器!");
- return;
- }
- /*
- if(NET_DVR_ClientAudioStart())
- {
- AfxMessageBox("语音广播成功!");
- }
- else
- {
- AfxMessageBox("语音广播失败!");
- }
- */ if(lVoiceIndex >= 0)
- {
- if(NET_DVR_StopVoiceCom(lVoiceIndex))
- {
- lVoiceIndex = -1;
- }
- else
- {
- AfxMessageBox("请先关闭对讲!");
- return;
- }
- }
- Sleep(300);
- lVoiceIndex = NET_DVR_StartVoiceCom(m_lServerID, fVoiceDataCallBack, 88);
- // lVoiceIndex = NET_DVR_StartVoiceCom(m_lServerID, NULL, 0);
- if(lVoiceIndex == -1)
- {
- CString sTemp;
- sTemp.Format("ERROR: NET_DVR_StartVoiceCom = %d \n", NET_DVR_GetLastError());
- TRACE(sTemp);
- AfxMessageBox("语音对讲失败!");
- return ;
- }
- else
- {
- AfxMessageBox("语音对讲成功!");
- }
- }
- void CVoiceExchange::OnSelchangeComboaudexch()
- {
- // TODO: Add your control notification handler code here
- int i,ipnum;
-
- i = m_ServerCtrl.GetCurSel();
- if(i >= 1)
- {
- ipnum = m_ServerCtrl.GetItemData(i);
- m_lServerID = serverinfo[ipnum].m_lServerID;
- }
- UpdateData(FALSE);
- }
- void CVoiceExchange::OnExit()
- {
- // TODO: Add your control notification handler code here
- /* if(NET_DVR_ClientAudioStop())
- {
- AfxMessageBox("语音广播结束成功!");
- }
- else
- {
- AfxMessageBox("语音广播结束失败!");
- }
- */
- /* if(hRevFile)
- {
- CloseHandle(hRevFile);
- hSendFile = NULL;
- }
- if(phis)
- {
- NET_DVR_ReleaseG722Decoder(phis);
- phis = NULL;
- }
- */
- CDialog::OnCancel();
- }
- void CVoiceExchange::OnCancel()
- {
- // TODO: Add extra cleanup here
-
- // CDialog::OnCancel();
- }
- void CVoiceExchange::OnButton1()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(m_ServerCtrl.GetCurSel()==0)
- {
- AfxMessageBox("请选择视频服务器!");
- return;
- }
- NET_DVR_AddDVR(m_lServerID);
- }
- void CVoiceExchange::OnButton2()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- if(m_ServerCtrl.GetCurSel()==0)
- {
- AfxMessageBox("请选择视频服务器!");
- return;
- }
-
- NET_DVR_DelDVR(m_lServerID);
- }
|