VideoNetDlg.cpp
上传用户:panstart
上传日期:2022-04-12
资源大小:199k
文件大小:19k
源码类别:

IP电话/视频会议

开发平台:

C++ Builder

  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. //    Project     : VideoNet version 1.1.
  5. //    Description : Peer to Peer Video Conferencing over the LAN.
  6. //   Author      : Nagareshwar Y Talekar ( nsry2002@yahoo.co.in)
  7. //    Date        : 15-6-2004.
  8. //
  9. //
  10. //    File description : 
  11. //    Name    : VideoNetDlg.cpp
  12. //    Details : Main dialog class
  13. //
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "VideoNet.h"
  18. #include "VideoNetDlg.h"
  19. #include "Resource.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAboutDlg dialog used for App About
  27. class CAboutDlg : public CDialog
  28. {
  29. public:
  30. CAboutDlg();
  31. // Dialog Data
  32. //{{AFX_DATA(CAboutDlg)
  33. enum { IDD = IDD_ABOUTBOX };
  34. //}}AFX_DATA
  35. // ClassWizard generated virtual function overrides
  36. //{{AFX_VIRTUAL(CAboutDlg)
  37. protected:
  38. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  39. //}}AFX_VIRTUAL
  40. // Implementation
  41. protected:
  42. //{{AFX_MSG(CAboutDlg)
  43. //}}AFX_MSG
  44. DECLARE_MESSAGE_MAP()
  45. };
  46. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  47. {
  48. //{{AFX_DATA_INIT(CAboutDlg)
  49. //}}AFX_DATA_INIT
  50. }
  51. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  52. {
  53. CDialog::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(CAboutDlg)
  55. //}}AFX_DATA_MAP
  56. }
  57. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  58. //{{AFX_MSG_MAP(CAboutDlg)
  59. // No message handlers
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CVideoNetDlg dialog
  64. // Global varialbes...
  65. int count=0;
  66. unsigned char cdata[10000];
  67. int cbuffer_size=10000;
  68. unsigned char rgbdata[80000];
  69. int buffersize=80000;
  70. // Callback function gets invoked during compression...
  71. // It returns the compressed data byte by byte...
  72. void OwnWriteFunction(int byte)
  73. {
  74. if(count<cbuffer_size)
  75. cdata[count]=(unsigned char)byte;
  76. count++;
  77. }
  78. CVideoNetDlg::CVideoNetDlg(CWnd* pParent /*=NULL*/)
  79. : CDialog(CVideoNetDlg::IDD, pParent)
  80. {
  81. //{{AFX_DATA_INIT(CVideoNetDlg)
  82. // NOTE: the ClassWizard will add member initialization here
  83. //}}AFX_DATA_INIT
  84. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  85. }
  86. void CVideoNetDlg::DoDataExchange(CDataExchange* pDX)
  87. {
  88. CDialog::DoDataExchange(pDX);
  89. //{{AFX_DATA_MAP(CVideoNetDlg)
  90. // NOTE: the ClassWizard will add DDX and DDV calls here
  91. //}}AFX_DATA_MAP
  92. }
  93. BEGIN_MESSAGE_MAP(CVideoNetDlg, CDialog)
  94. //{{AFX_MSG_MAP(CVideoNetDlg)
  95. ON_WM_SYSCOMMAND()
  96. ON_WM_PAINT()
  97. ON_WM_QUERYDRAGICON()
  98. // Conference menu handlers
  99. ON_COMMAND(CONF_CONNECT,OnConnect)
  100. ON_COMMAND(CONF_DISCONNECT,OnDisconnect)
  101. ON_COMMAND(CONF_EXIT,OnCancel)
  102. // View menu handlers
  103. ON_COMMAND(VIEW_LOCAL,OnViewLocal)
  104. ON_COMMAND(VIEW_REMOTE,OnViewRemote)
  105. // Audio menu handlers
  106. ON_COMMAND(AUDIO_CONTROL,OnVolumeControl)
  107. ON_COMMAND(AUDIO_SEND,OnAudioSend)
  108. ON_COMMAND(AUDIO_RECEIVE,OnAudioReceive)
  109. // Video menu handlers
  110. ON_COMMAND(VIDEO_SEND,OnVideoSend)
  111. ON_COMMAND(VIDEO_RECEIVE,OnVideoReceive)
  112. // Help menu handlers
  113. ON_COMMAND(HELP_ABOUT,OnAbout)
  114. ON_COMMAND(IDC_BUTTON1,OnSendMesg)
  115. //}}AFX_MSG_MAP
  116. END_MESSAGE_MAP()
  117. BOOL CVideoNetDlg::OnInitDialog()
  118. {
  119. CDialog::OnInitDialog();
  120. // Add "About..." menu item to system menu.
  121. // IDM_ABOUTBOX must be in the system command range.
  122. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  123. ASSERT(IDM_ABOUTBOX < 0xF000);
  124. CMenu* pSysMenu = GetSystemMenu(FALSE);
  125. if (pSysMenu != NULL)
  126. {
  127. CString strAboutMenu;
  128. strAboutMenu.LoadString(IDS_ABOUTBOX);
  129. if (!strAboutMenu.IsEmpty())
  130. {
  131. pSysMenu->AppendMenu(MF_SEPARATOR);
  132. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  133. }
  134. }
  135. SetIcon(m_hIcon, TRUE); // Set big icon
  136. SetIcon(m_hIcon, FALSE); // Set small icon
  137. // Open log file...
  138. log.Open("main.log",CFile::modeCreate | CFile::modeWrite);
  139. // Disable the menu items...at startup
  140. menu=this->GetMenu();
  141. menu->EnableMenuItem(CONF_CONNECT,MF_ENABLED);
  142. menu->EnableMenuItem(CONF_DISCONNECT,MF_DISABLED | MF_GRAYED);
  143. menu->EnableMenuItem(AUDIO_SEND,MF_GRAYED);
  144. menu->EnableMenuItem(AUDIO_RECEIVE,MF_GRAYED);
  145. menu->EnableMenuItem(VIDEO_SEND,MF_GRAYED);
  146. menu->EnableMenuItem(VIDEO_RECEIVE,MF_GRAYED);
  147. menu->EnableMenuItem(VIEW_LOCAL,MF_GRAYED);
  148. menu->EnableMenuItem(VIEW_REMOTE,MF_GRAYED);
  149. list=(CListBox*)GetDlgItem(IDC_LIST1);
  150. bsend=(CButton*)GetDlgItem(IDC_BUTTON1);
  151. // Disable the send button
  152. bsend->EnableWindow(FALSE);
  153. // Create Recording  thread
  154. record=new RecordSound(this);
  155. record->CreateThread();
  156. // Create Player thread
  157. play=new PlaySound1(this);
  158. play->CreateThread();
  159. // Prepare for capture video from webcam...
  160. vidcap=new VideoCapture();
  161. vidcap->SetDialog(this);
  162. if(vidcap->Initialize()) // success
  163. {
  164. this->m_bmpinfo=&vidcap->m_bmpinfo;
  165. isVideo=TRUE;
  166. // Initialize the compressor
  167.      // Initialize table for RGB to YUV conversion
  168. InitLookupTable();
  169. // Initialize the compressor
  170. cparams.format = CPARAM_QCIF;
  171. InitH263Encoder(&cparams);  
  172. // Set up the callback function
  173. WriteByteFunction = OwnWriteFunction;
  174. }
  175. else
  176. {
  177. isVideo=FALSE;
  178. // Setup bmpinfo structure yourself
  179. m_bmpinfo=new BITMAPINFO;
  180. m_bmpinfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  181. m_bmpinfo->bmiHeader.biWidth=IMAGE_WIDTH;
  182. m_bmpinfo->bmiHeader.biHeight=IMAGE_HEIGHT;
  183. m_bmpinfo->bmiHeader.biPlanes=1;
  184. m_bmpinfo->bmiHeader.biBitCount=24;
  185. m_bmpinfo->bmiHeader.biCompression=0;
  186. m_bmpinfo->bmiHeader.biSizeImage=0;
  187. m_bmpinfo->bmiHeader.biXPelsPerMeter=0;
  188. m_bmpinfo->bmiHeader.biYPelsPerMeter=0;
  189. m_bmpinfo->bmiHeader.biClrUsed=0;
  190. m_bmpinfo->bmiHeader.biClrImportant=0;
  191. // Disable menu items...
  192. menu->EnableMenuItem(VIEW_LOCAL,MF_DISABLED | MF_GRAYED);
  193. menu->EnableMenuItem(VIDEO_SEND,MF_DISABLED | MF_GRAYED);
  194. }
  195. // Capturing is not yet started...
  196. isCaptureStarted=FALSE;
  197. isViewLocalVideo=TRUE;
  198. isViewRemoteVideo=TRUE;
  199. isAudioSend=TRUE;
  200. isAudioReceive=TRUE;
  201. isVideoSend=TRUE;
  202. isVideoReceive=TRUE;
  203. // Initialize decompressor
  204. InitH263Decoder();
  205. // Adjust display windows
  206. CWnd *wnd,*bwnd;
  207. CRect rect,brect;
  208. // For local video display window
  209. wnd=this->GetDlgItem(IDC_LOCALVIDEO);
  210.     bwnd=this->GetDlgItem(IDC_LOCALBORDER);
  211.     bwnd->GetWindowRect(brect);
  212. ScreenToClient(brect);
  213. local_wnd_x=brect.TopLeft().x+(brect.Width()-IMAGE_WIDTH)/2;
  214. local_wnd_y=brect.TopLeft().y+(brect.Height()-IMAGE_HEIGHT)/2;
  215. // Centre the local video window
  216. wnd->SetWindowPos(&wndTop,local_wnd_x-4,local_wnd_y-4,IMAGE_WIDTH+9,IMAGE_HEIGHT+9,SWP_SHOWWINDOW | SWP_DRAWFRAME);
  217. // For remote video display window
  218. wnd=this->GetDlgItem(IDC_REMOTEVIDEO); // Video display window
  219.     bwnd=this->GetDlgItem(IDC_REMOTEBORDER); // Border window...
  220.     bwnd->GetWindowRect(brect);
  221. ScreenToClient(brect);
  222. remote_wnd_x=brect.TopLeft().x+(brect.Width()-IMAGE_WIDTH)/2;
  223. remote_wnd_y=brect.TopLeft().y+(brect.Height()-IMAGE_HEIGHT)/2;
  224. // Centre the remote video window
  225. wnd->SetWindowPos(&wndTop,remote_wnd_x-4,remote_wnd_y-4,IMAGE_WIDTH+9,IMAGE_HEIGHT+9,SWP_SHOWWINDOW | SWP_DRAWFRAME);
  226. // Get Dialog DC
  227. m_hdc=this->GetDC()->m_hDC;
  228. // Initialize DIB for drawing...
  229. hdib=::DrawDibOpen();
  230. if(hdib!=NULL)
  231. {
  232.  
  233. ::DrawDibBegin(hdib,
  234.    m_hdc,
  235.    -1, // don't stretch
  236.    -1, // don't stretch
  237.    &m_bmpinfo->bmiHeader,
  238.    IMAGE_WIDTH,         // width of image
  239.    IMAGE_HEIGHT,        // height of image
  240.    0
  241.    );
  242. }
  243.     
  244. // Setup the connect dialog box
  245. connectdlg=new ConnectDlg(NULL);
  246. connectdlg->SetParent(this);
  247. // Setup the parent for differnt datagram sockets
  248. dcontrol.SetParent(this);
  249. daudio.SetParent(this);
  250. dvideo.SetParent(this);
  251. dtext.SetParent(this);
  252. // Create  control datagram socket for handling messages
  253. dcontrol.CreateSocket(PORT_CONTROL,TYPE_CONTROL);
  254. // Conference not yet started...
  255. isStarted=FALSE;
  256. return TRUE;  // return TRUE  unless you set the focus to a control
  257. }
  258. void CVideoNetDlg::OnSysCommand(UINT nID, LPARAM lParam)
  259. {
  260. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  261. {
  262. CAboutDlg dlgAbout;
  263. dlgAbout.DoModal();
  264. }
  265. else
  266. {
  267. CDialog::OnSysCommand(nID, lParam);
  268. }
  269. }
  270. //  If you add a minimize button to your dialog, you will need the code below
  271. //  to draw the icon.  For MFC applications using the document/view model,
  272. //  this is automatically done for you by the framework.
  273. void CVideoNetDlg::OnPaint() 
  274. {
  275. if (IsIconic())
  276. {
  277. CPaintDC dc(this); // device context for painting
  278. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  279. // Center icon in client rectangle
  280. int cxIcon = GetSystemMetrics(SM_CXICON);
  281. int cyIcon = GetSystemMetrics(SM_CYICON);
  282. CRect rect;
  283. GetClientRect(&rect);
  284. int x = (rect.Width() - cxIcon + 1) / 2;
  285. int y = (rect.Height() - cyIcon + 1) / 2;
  286. // Draw the icon
  287. dc.DrawIcon(x, y, m_hIcon);
  288. }
  289. else
  290. {
  291. CDialog::OnPaint();
  292. }
  293. }
  294. HCURSOR CVideoNetDlg::OnQueryDragIcon()
  295. {
  296. return (HCURSOR) m_hIcon;
  297. }
  298. void CVideoNetDlg::OnCancel() 
  299. {
  300. // If conference is going on...then 
  301. // it must be destroyed...
  302. if(isStarted)
  303. DestroyConference();
  304. // Close the control session
  305. dcontrol.CloseSocket();
  306. // End recording and player thread
  307. record->PostThreadMessage(WM_RECORDSOUND_ENDTHREAD,0,0);
  308. play->PostThreadMessage(WM_PLAYSOUND_ENDTHREAD,0,0);
  309. // Close the video capture device
  310. vidcap->Destroy();
  311. // Close graphics....
  312. if(hdib!=NULL)
  313. {
  314. ::DrawDibEnd(hdib);
  315. ::DrawDibClose(hdib);
  316. }
  317. // Close the encoder
  318. if(isVideo)
  319. ExitH263Encoder(&cparams);
  320. // close decoder ......
  321. ExitH263Decoder();
  322. CDialog::OnCancel();
  323. }
  324. /**
  325. *   Connect to remote host
  326. *   Invoked when user presses connect menu item
  327. *   Displays the connect dialog box
  328. */
  329. void CVideoNetDlg::OnConnect()
  330. {
  331. // Show the connect dialog box
  332. connectdlg->DoModal();
  333. }
  334. /**
  335. *   Disconnect the remote host
  336. *   Invoked when user presses disconnect menu item
  337. *   Stops the current conference
  338. */
  339. void CVideoNetDlg::OnDisconnect()
  340. {
  341. // Send notification to the remote host...
  342. dcontrol.SendControlMessage(MESG_DISCONNECT,NULL);
  343. DestroyConference();
  344. }
  345. /**
  346. *   Show / Hide the local video screen
  347. */
  348. void CVideoNetDlg::OnViewLocal()
  349. {
  350. CMenu *menu=this->GetMenu();
  351. if(isViewLocalVideo)
  352. {
  353. isViewLocalVideo=FALSE;
  354. menu->CheckMenuItem(VIEW_LOCAL,MF_BYCOMMAND | MF_UNCHECKED);
  355. }
  356. else
  357. {
  358. isViewLocalVideo=TRUE;
  359. menu->CheckMenuItem(VIEW_LOCAL,MF_BYCOMMAND | MF_CHECKED);
  360. }
  361. }
  362. /**
  363. *   Show / Hide the remote video screen
  364. */
  365. void CVideoNetDlg::OnViewRemote()
  366. {
  367. CMenu *menu=this->GetMenu();
  368. if(isViewRemoteVideo)
  369. {
  370. isViewRemoteVideo=FALSE;
  371. menu->CheckMenuItem(VIEW_REMOTE,MF_BYCOMMAND | MF_UNCHECKED);
  372. }
  373. else
  374. {
  375. isViewRemoteVideo=TRUE;
  376. menu->CheckMenuItem(VIEW_REMOTE,MF_BYCOMMAND | MF_CHECKED);
  377. }
  378. }
  379. /**
  380. *   Displays the volume control dialog box
  381. */
  382. void CVideoNetDlg::OnVolumeControl()
  383. {
  384. Volume vol(IDD_DIALOG3);
  385.  vol.DoModal();
  386. }
  387. /**
  388. *   Enables/Disables transmission of audio
  389. *     Invoked when user presses Audio -> Send menu item
  390. */
  391. void CVideoNetDlg::OnAudioSend()
  392. {
  393. if(isAudioSend)
  394. {
  395. // Stop recording audio
  396. record->SuspendThread();
  397. //>PostThreadMessage(WM_RECORDSOUND_STOPRECORDING,0,0);
  398. isAudioSend=FALSE;
  399. menu->CheckMenuItem(AUDIO_SEND,MF_BYCOMMAND | MF_UNCHECKED);
  400. }
  401. else
  402. {
  403. // Start recording audio
  404. record->ResumeThread();
  405. //record->PostThreadMessage(WM_RECORDSOUND_STARTRECORDING,0,0);
  406. isAudioSend=TRUE;
  407. menu->CheckMenuItem(AUDIO_SEND,MF_BYCOMMAND | MF_CHECKED);
  408. }
  409. }
  410. /**
  411. *   Enables/Disables reception of audio
  412. *     Invoked when user presses Audio -> Receive menu item
  413. */
  414. void CVideoNetDlg::OnAudioReceive()
  415. {
  416. if(isAudioReceive)
  417. {
  418. isAudioReceive=FALSE;
  419. menu->CheckMenuItem(AUDIO_RECEIVE,MF_BYCOMMAND | MF_UNCHECKED);
  420. }
  421. else
  422. {
  423. isAudioReceive=TRUE;
  424. menu->CheckMenuItem(AUDIO_RECEIVE,MF_BYCOMMAND | MF_CHECKED);
  425. }
  426. }
  427. /**
  428. *   Enables/Disables transmission of video
  429. *     Invoked when user presses Video-> Send menu item
  430. */
  431. void CVideoNetDlg::OnVideoSend()
  432. {
  433. if(isVideoSend)
  434. {
  435. isVideoSend=FALSE;
  436. menu->CheckMenuItem(VIDEO_SEND,MF_BYCOMMAND | MF_UNCHECKED);
  437. }
  438. else
  439. {
  440. isVideoSend=TRUE;
  441. menu->CheckMenuItem(VIDEO_SEND,MF_BYCOMMAND | MF_CHECKED);
  442. }
  443. }
  444. /**
  445. *   Enables/Disables reception of video
  446. *     Invoked when user presses Video -> Receive menu item
  447. */
  448. void CVideoNetDlg::OnVideoReceive()
  449. {
  450. if(isVideoReceive)
  451. {
  452. isVideoReceive=FALSE;
  453. menu->CheckMenuItem(VIDEO_RECEIVE,MF_BYCOMMAND | MF_UNCHECKED);
  454. }
  455. else
  456. {
  457. isVideoReceive=TRUE;
  458. menu->CheckMenuItem(VIDEO_RECEIVE,MF_BYCOMMAND | MF_CHECKED);
  459. }
  460. }
  461. /**
  462. *   Display the about dialog box
  463. */
  464. void CVideoNetDlg::OnAbout()
  465. {
  466. CAboutDlg dlgAbout;
  467. dlgAbout.DoModal();
  468. }
  469. /**
  470. *   Send the message to remote host
  471. */
  472. void CVideoNetDlg::OnSendMesg()
  473. {
  474. unsigned char data[500];
  475. GetDlgItemText(IDC_EDIT1,(char*)data,500);
  476. if(strlen((const char*)data)>0)
  477. {
  478. dtext.SendTextData(data,strlen((const char*)data));
  479. SetDlgItemText(IDC_EDIT1,"");
  480. }
  481. }
  482. /**
  483. *   Display mesg received from the remote host
  484. */
  485. void CVideoNetDlg::DisplayMesg(char *mesg)
  486. {
  487. list->AddString(mesg);
  488. // Highlight the currently added string
  489. // This will scroll the window automatically
  490. list->SetCurSel(list->GetCount()-1);
  491. }
  492. /**
  493. *   Display frame got from remote host
  494. */
  495. void CVideoNetDlg::DisplayRemoteFrame(unsigned char *data,int size)
  496. {
  497. int retvalue;
  498. // If remote view disabled then return...
  499. if(!isViewRemoteVideo)
  500. return;
  501. // If video reception disabled..then return..
  502. if(!isVideoReceive)
  503. return;
  504. retvalue=DecompressFrame(data,size,rgbdata,buffersize);
  505. if(!retvalue)
  506. {
  507. log.WriteString("n Decompression failed");
  508. return;
  509. }
  510. log.WriteString("n Decompression succeeded");
  511. ::DrawDibDraw(hdib,
  512.   m_hdc,
  513.   remote_wnd_x, // dest : left pos
  514.   remote_wnd_y, // dest : top pos
  515.   -1,  // don't zoom x
  516.   -1,  // don't zoom y
  517.   &m_bmpinfo->bmiHeader,  // bmp header info
  518.   rgbdata,  // bmp data
  519.   0,  // src :left
  520.   0,  // src :top
  521.   IMAGE_WIDTH,  // src : width
  522.   IMAGE_HEIGHT,  // src : height
  523.   DDF_SAME_DRAW  // use prev params....
  524.   );
  525. }
  526. /**
  527. *
  528. * Send the video frame to the remote host...
  529. *
  530. */
  531. void CVideoNetDlg::SendVideo(BYTE *data,int size)
  532. {
  533. CRect wndrect;
  534. Bits bits; // Various count about compression
  535. if(vidcap->isOver==TRUE)
  536. return;
  537. if(data==NULL)
  538. return;
  539. // Display the captured frame...
  540. if(isViewLocalVideo)
  541. {
  542. ::DrawDibDraw(hdib,
  543.   m_hdc,
  544.   local_wnd_x, // dest : left pos
  545.   local_wnd_y, // dest : top pos
  546.   -1,  // don't zoom x
  547.   -1,  // don't zoom y
  548.   &m_bmpinfo->bmiHeader,  // bmp header info
  549.   data,  // bmp data
  550.   0,  // src :left
  551.   0,  // src :top
  552.   IMAGE_WIDTH,  // src : width
  553.   IMAGE_HEIGHT,  // src : height
  554.   DDF_SAME_DRAW  // use prev params....
  555.   );
  556. }
  557. if(isVideoSend)
  558. {
  559. //log.WriteString("n Converting to YUV format..");
  560. //Convert the data from rgb format to YUV format
  561. ConvertRGB2YUV(IMAGE_WIDTH,IMAGE_HEIGHT,data,yuv);
  562. // Reset the counter
  563. count=0;
  564. //Compress the data...to h263
  565. cparams.format=CPARAM_QCIF;
  566. cparams.inter = CPARAM_INTRA;  
  567. cparams.Q_intra = 8;
  568. cparams.data=yuv; //  Data in YUV format...
  569. CompressFrame(&cparams, &bits);
  570. // Transmit the compressed frame
  571. //log.WriteString("Transmitting the frame");
  572. dvideo.SendVideoData(cdata,count);
  573. }
  574. }
  575. /**
  576. *   Start the conference ....
  577. *
  578. */
  579. void CVideoNetDlg::StartConference()
  580. {
  581. // If already started....then return
  582. if(isStarted)
  583. return;
  584. isStarted=TRUE;
  585. isViewLocalVideo=TRUE;
  586. isViewRemoteVideo=TRUE;
  587. // Enable / Disable menu items...
  588. menu->EnableMenuItem(CONF_CONNECT,MF_DISABLED | MF_GRAYED);
  589. menu->EnableMenuItem(CONF_DISCONNECT,MF_ENABLED);
  590. menu->EnableMenuItem(AUDIO_SEND,MF_ENABLED);
  591. menu->EnableMenuItem(AUDIO_RECEIVE,MF_ENABLED);
  592. menu->EnableMenuItem(VIDEO_SEND,MF_ENABLED);
  593. menu->EnableMenuItem(VIDEO_RECEIVE,MF_ENABLED);
  594. menu->EnableMenuItem(VIEW_LOCAL,MF_ENABLED);
  595. menu->EnableMenuItem(VIEW_REMOTE,MF_ENABLED);
  596. menu->CheckMenuItem(VIEW_LOCAL,MF_BYCOMMAND | MF_CHECKED);
  597. menu->CheckMenuItem(VIEW_REMOTE,MF_BYCOMMAND | MF_CHECKED);
  598. // Start text Session
  599. dtext.CreateSocket(PORT_TEXT,TYPE_TEXT);
  600. // Enable the send button
  601. bsend->EnableWindow(TRUE);
  602. // Start audio Session
  603. daudio.CreateSocket(PORT_AUDIO,TYPE_AUDIO);
  604. // Start video Session
  605. dvideo.CreateSocket(PORT_VIDEO,TYPE_VIDEO);
  606. // Start recording audio
  607. record->PostThreadMessage(WM_RECORDSOUND_STARTRECORDING,0,0);
  608. // Start playing audio
  609. play->PostThreadMessage(WM_PLAYSOUND_STARTPLAYING,0,0);
  610. // Start capturing video
  611. if(isVideo)
  612. {
  613. if(vidcap->StartCapture()==FALSE)
  614. {
  615. MessageBox("Unable to start the capture");
  616. isCaptureStarted=FALSE;
  617. }
  618. else
  619. {
  620. isCaptureStarted=TRUE;
  621. }
  622. }
  623. }
  624. /**
  625. *   Destroy the current conference
  626. */
  627. void CVideoNetDlg::DestroyConference()
  628. {
  629. // If not started / already destroyed..then return;
  630. if(isStarted==FALSE)
  631. return;
  632. isStarted=FALSE;
  633. isViewLocalVideo=FALSE;
  634. isViewRemoteVideo=FALSE;
  635. // Enable/disable menu items
  636. menu->EnableMenuItem(CONF_CONNECT,MF_ENABLED);
  637. menu->EnableMenuItem(CONF_DISCONNECT,MF_DISABLED | MF_GRAYED);
  638. // Disable Text session
  639. dtext.CloseSocket();
  640. // Disable the send button...
  641. bsend->EnableWindow(FALSE);
  642. // Clear the contents of text chat windows
  643. SetDlgItemText(IDC_EDIT1,"");
  644. list->ResetContent();
  645. // If recording is going on ...then stop it
  646. if(isAudioSend)
  647. record->SuspendThread();
  648. record->PostThreadMessage(WM_RECORDSOUND_STOPRECORDING,0,0);  
  649. // stop audio session
  650. daudio.CloseSocket();
  651. // stop playing audio
  652. play->PostThreadMessage(WM_PLAYSOUND_STOPPLAYING,0,0);
  653. // stop capturing video
  654. if(isVideo && isCaptureStarted)
  655. vidcap->StopCapture();
  656. // stop video session
  657. dvideo.CloseSocket();
  658. // Update local and remote viewer..
  659. CWnd *wnd=(CWnd*)this->GetDlgItem(IDC_LOCALVIDEO);
  660.     wnd->Invalidate(TRUE);
  661. wnd=(CWnd*)this->GetDlgItem(IDC_REMOTEVIDEO);
  662.     wnd->Invalidate(TRUE);
  663. // Reset the status..
  664. record->ResumeThread();
  665. isAudioSend=TRUE;
  666. menu->CheckMenuItem(AUDIO_SEND,MF_BYCOMMAND | MF_CHECKED);
  667. isAudioReceive=TRUE;
  668. menu->CheckMenuItem(AUDIO_RECEIVE,MF_BYCOMMAND | MF_CHECKED);
  669. isVideoSend=TRUE;
  670. menu->CheckMenuItem(VIDEO_SEND,MF_BYCOMMAND | MF_CHECKED);
  671. isVideoReceive=TRUE;
  672. menu->CheckMenuItem(VIDEO_RECEIVE,MF_BYCOMMAND | MF_CHECKED);
  673. menu->EnableMenuItem(AUDIO_SEND,MF_GRAYED);
  674. menu->EnableMenuItem(AUDIO_RECEIVE,MF_GRAYED);
  675. menu->EnableMenuItem(VIDEO_SEND,MF_GRAYED);
  676. menu->EnableMenuItem(VIDEO_RECEIVE,MF_GRAYED);
  677. menu->EnableMenuItem(VIEW_LOCAL,MF_GRAYED);
  678. menu->EnableMenuItem(VIEW_REMOTE,MF_GRAYED);
  679. }