VoiceExchange.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // VoiceExchange.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "newclient.h"
  5. #include "VoiceExchange.h"
  6. #include "newclientDlg.h"
  7. #include "Interface.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CVoiceExchange dialog
  15. extern SERVER_INFO serverinfo[MAXIPNUMBER];
  16. LONG lVoiceIndex = -1;
  17. HANDLE hSendFile = NULL;
  18. HANDLE hRevFile = NULL;
  19. DWORD dwReturn = 0;
  20. CONST BYTE FileHeader[40] = {0x34,0x48,0x4B,0x48,0xFE,0xB3,0xD0,0xD6,0x08,0x03,0x04,0x20,0x00,0x00,0x00,0x00,
  21. 0x02,0x10,0x01,0x10,0x01,0x10,0x10,0x00,0x80,0x3E,0x00,0x00,0x60,0x01,0x20,0x01,
  22. 0x11,0x10,0x00,0x00,0x00,0x00,0x00,0x00};
  23. LPVOID phis = NULL;
  24. BYTE outbuf[1280];
  25. BYTE inbuf[80];
  26. //语音对讲时的数据回调,byAudioFlag = 0表示采集到的数据,byAudioFlag = 1表示接收到的数据
  27. void CALLBACK fVoiceDataCallBack(LONG lVoiceComHandle,char *pRecvDataBuffer,DWORD dwBufSize,BYTE byAudioFlag,DWORD dwUser)
  28. {
  29. #if 0
  30. if(byAudioFlag == 0)
  31. {
  32. if(hSendFile)
  33. {
  34. if(phis)
  35. {
  36. NET_DVR_EncodeG722Frame(phis, (LPBYTE)pRecvDataBuffer, outbuf);
  37. }
  38. WriteFile(hSendFile, /*pRecvDataBuffer*/outbuf, /*dwBufSize*/80, &dwReturn, NULL);
  39. }
  40. }
  41. else
  42. if(byAudioFlag == 1)
  43. {
  44. if(hRevFile)
  45. {
  46. if(phis)
  47. {
  48. memcpy(inbuf, (LPBYTE)pRecvDataBuffer, 80);
  49. NET_DVR_DecodeG722Frame(phis, inbuf, outbuf);
  50. }
  51. WriteFile(hRevFile, /*pRecvDataBuffer*/outbuf, /*dwBufSize*/1280, &dwReturn, NULL);
  52. }
  53. }
  54. #endif
  55. }
  56. CVoiceExchange::CVoiceExchange(CWnd* pParent /*=NULL*/)
  57. : CDialog(CVoiceExchange::IDD, pParent)
  58. {
  59. //{{AFX_DATA_INIT(CVoiceExchange)
  60. // NOTE: the ClassWizard will add member initialization here
  61. //}}AFX_DATA_INIT
  62. }
  63. void CVoiceExchange::DoDataExchange(CDataExchange* pDX)
  64. {
  65. CDialog::DoDataExchange(pDX);
  66. //{{AFX_DATA_MAP(CVoiceExchange)
  67. DDX_Control(pDX, IDC_COMBOAUDEXCH, m_ServerCtrl);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CVoiceExchange, CDialog)
  71. //{{AFX_MSG_MAP(CVoiceExchange)
  72. ON_BN_CLICKED(IDC_AUDSTART, OnAudstart)
  73. ON_CBN_SELCHANGE(IDC_COMBOAUDEXCH, OnSelchangeComboaudexch)
  74. ON_BN_CLICKED(IDEXIT, OnExit)
  75. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  76. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  77. //}}AFX_MSG_MAP
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CVoiceExchange message handlers
  81. BOOL CVoiceExchange::OnInitDialog()
  82. {
  83. CDialog::OnInitDialog();
  84. // TODO: Add extra initialization here
  85. int i, iNum;
  86. m_ServerCtrl.InsertString(0,"请选择视频服务器地址");
  87. for(i = 0; i < MAXIPNUMBER; i++)
  88. {
  89. if(serverinfo[i].m_iServerChannelNumber >= 0)
  90. {
  91. iNum = m_ServerCtrl.AddString(serverinfo[i].m_csServerName);
  92. m_ServerCtrl.SetItemData(iNum, i);
  93. }
  94. }
  95. m_ServerCtrl.SetCurSel(0);
  96. /*
  97. phis = NET_DVR_InitG722Decoder(16000);
  98. if(phis == NULL)
  99. {
  100. AfxMessageBox("!!!!!");
  101. }
  102. hRevFile = CreateFile("c:\\aaa.wav", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  103. if (hRevFile == INVALID_HANDLE_VALUE)
  104. {
  105. return FALSE;
  106. }
  107. */
  108. return TRUE; // return TRUE unless you set the focus to a control
  109. // EXCEPTION: OCX Property Pages should return FALSE
  110. }
  111. void CVoiceExchange::OnAudstart()
  112. {
  113. // TODO: Add your control notification handler code here
  114. UpdateData(TRUE);
  115. if(m_ServerCtrl.GetCurSel()==0)
  116. {
  117. AfxMessageBox("请选择视频服务器!");
  118. return;
  119. }
  120. /*
  121. if(NET_DVR_ClientAudioStart())
  122. {
  123. AfxMessageBox("语音广播成功!");
  124. }
  125. else
  126. {
  127. AfxMessageBox("语音广播失败!");
  128. }
  129. */ if(lVoiceIndex >= 0)
  130. {
  131. if(NET_DVR_StopVoiceCom(lVoiceIndex))
  132. {
  133. lVoiceIndex = -1;
  134. }
  135. else
  136. {
  137. AfxMessageBox("请先关闭对讲!");
  138. return;
  139. }
  140. }
  141. Sleep(300);
  142. lVoiceIndex = NET_DVR_StartVoiceCom(m_lServerID, fVoiceDataCallBack, 88);
  143. // lVoiceIndex = NET_DVR_StartVoiceCom(m_lServerID, NULL, 0);
  144. if(lVoiceIndex == -1)
  145. {
  146. CString sTemp;
  147. sTemp.Format("ERROR: NET_DVR_StartVoiceCom = %d \n", NET_DVR_GetLastError());
  148. TRACE(sTemp);
  149. AfxMessageBox("语音对讲失败!");
  150. return ;
  151. }
  152. else
  153. {
  154. AfxMessageBox("语音对讲成功!");
  155. }
  156. }
  157. void CVoiceExchange::OnSelchangeComboaudexch()
  158. {
  159. // TODO: Add your control notification handler code here
  160. int i,ipnum;
  161. i = m_ServerCtrl.GetCurSel();
  162. if(i >= 1)
  163. {
  164. ipnum = m_ServerCtrl.GetItemData(i);
  165. m_lServerID = serverinfo[ipnum].m_lServerID;
  166. }
  167. UpdateData(FALSE);
  168. }
  169. void CVoiceExchange::OnExit()
  170. {
  171. // TODO: Add your control notification handler code here
  172. /* if(NET_DVR_ClientAudioStop())
  173. {
  174. AfxMessageBox("语音广播结束成功!");
  175. }
  176. else
  177. {
  178. AfxMessageBox("语音广播结束失败!");
  179. }
  180. */
  181. /* if(hRevFile)
  182. {
  183. CloseHandle(hRevFile);
  184. hSendFile = NULL;
  185. }
  186. if(phis)
  187. {
  188. NET_DVR_ReleaseG722Decoder(phis);
  189. phis = NULL;
  190. }
  191. */
  192. CDialog::OnCancel();
  193. }
  194. void CVoiceExchange::OnCancel()
  195. {
  196. // TODO: Add extra cleanup here
  197. // CDialog::OnCancel();
  198. }
  199. void CVoiceExchange::OnButton1()
  200. {
  201. // TODO: Add your control notification handler code here
  202. UpdateData(TRUE);
  203. if(m_ServerCtrl.GetCurSel()==0)
  204. {
  205. AfxMessageBox("请选择视频服务器!");
  206. return;
  207. }
  208. NET_DVR_AddDVR(m_lServerID);
  209. }
  210. void CVoiceExchange::OnButton2()
  211. {
  212. // TODO: Add your control notification handler code here
  213. UpdateData(TRUE);
  214. if(m_ServerCtrl.GetCurSel()==0)
  215. {
  216. AfxMessageBox("请选择视频服务器!");
  217. return;
  218. }
  219. NET_DVR_DelDVR(m_lServerID);
  220. }