clientdemoDlg.cpp 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. // clientdemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "clientdemo.h"
  5. #include "clientdemoDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define WM_MYCOMMAND WM_USER+1
  12. #define DEFAULTVAL 64
  13. //#define RECORD_ONLY
  14. int count;
  15. HWND hWnd1,hWnd2,hWnd3,hWnd4,hWnd5,hWnd6,hWnd7,hWnd8;
  16. //int filecount=20;
  17. DWORD num1;
  18. UINT timers;
  19. int ipos=0;
  20. BOOL bpos=FALSE;
  21. RECT rinit;
  22. CRect m_OldRect;
  23. int filecount=0;
  24. UINT filetimer=0;
  25. int capcount=0;
  26. CRect orirc;
  27. BOOL blarged=FALSE;
  28. WORD testnum=0;
  29. BOOL bmode=FALSE;
  30. BOOL g_bCapPic=FALSE;
  31. UINT remains=0;
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CAboutDlg dialog used for App About
  34. class CAboutDlg : public CDialog
  35. {
  36. public:
  37. CAboutDlg();
  38. // Dialog Data
  39. //{{AFX_DATA(CAboutDlg)
  40. enum { IDD = IDD_ABOUTBOX };
  41. //}}AFX_DATA
  42. // ClassWizard generated virtual function overrides
  43. //{{AFX_VIRTUAL(CAboutDlg)
  44. protected:
  45. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  46. //}}AFX_VIRTUAL
  47. // Implementation
  48. protected:
  49. //{{AFX_MSG(CAboutDlg)
  50. //}}AFX_MSG
  51. DECLARE_MESSAGE_MAP()
  52. };
  53. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  54. {
  55. //{{AFX_DATA_INIT(CAboutDlg)
  56. //}}AFX_DATA_INIT
  57. }
  58. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  59. {
  60. CDialog::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CAboutDlg)
  62. //}}AFX_DATA_MAP
  63. }
  64. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  65. //{{AFX_MSG_MAP(CAboutDlg)
  66. // No message handlers
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CClientdemoDlg dialog
  71. CClientdemoDlg::CClientdemoDlg(CWnd* pParent /*=NULL*/)
  72. : CDialog(CClientdemoDlg::IDD, pParent)
  73. {
  74. //{{AFX_DATA_INIT(CClientdemoDlg)
  75. m_linktype = 0;
  76. m_ipadd = _T("192.168.1.247");
  77. m_shownum = 1;
  78. m_delaytype = -1;
  79. m_showmode = -1;
  80. m_bframenum = -1;
  81. m_frameshow = _T("");
  82. //}}AFX_DATA_INIT
  83. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  84. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  85. }
  86. void CClientdemoDlg::DoDataExchange(CDataExchange* pDX)
  87. {
  88. CDialog::DoDataExchange(pDX);
  89. //{{AFX_DATA_MAP(CClientdemoDlg)
  90. DDX_Control(pDX, IDC_SLIDER4, m_hue);
  91. DDX_Control(pDX, IDC_SLIDER3, m_saturation);
  92. DDX_Control(pDX, IDC_SLIDER2, m_contrast);
  93. DDX_Control(pDX, IDC_SLIDER1, m_brightness);
  94. DDX_Control(pDX, IDC_COMBO1, m_windowCtrl);
  95. DDX_Control(pDX, IDC_STATIC8, m_video8);
  96. DDX_Control(pDX, IDC_STATIC7, m_video7);
  97. DDX_Control(pDX, IDC_STATIC6, m_video6);
  98. DDX_Control(pDX, IDC_STATIC5, m_video5);
  99. DDX_Radio(pDX, IDC_TCP, m_linktype);
  100. DDX_Text(pDX, IDC_IPADDRESS, m_ipadd);
  101. DDX_Text(pDX, IDC_SHOWNUM, m_shownum);
  102. DDX_Radio(pDX, IDC_DELAY1, m_delaytype);
  103. DDX_Radio(pDX, IDC_SHOWMODE1, m_showmode);
  104. DDX_Radio(pDX, IDC_RADIOBFRAM0, m_bframenum);
  105. DDX_Text(pDX, IDC_STATICFRAME, m_frameshow);
  106. //}}AFX_DATA_MAP
  107. }
  108. BEGIN_MESSAGE_MAP(CClientdemoDlg, CDialog)
  109. //ON_MESSAGE(WM_MYCOMMAND,OnMyCommand)
  110. //{{AFX_MSG_MAP(CClientdemoDlg)
  111. ON_WM_SYSCOMMAND()
  112. ON_WM_PAINT()
  113. ON_WM_QUERYDRAGICON()
  114. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  115. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  116. ON_WM_TIMER()
  117. ON_BN_CLICKED(IDC_STATIC5, OnStatic5)
  118. ON_BN_CLICKED(IDC_STATIC7, OnStatic7)
  119. ON_BN_CLICKED(IDC_STATIC6, OnStatic6)
  120. ON_BN_CLICKED(IDC_STATIC8, OnStatic8)
  121. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  122. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  123. ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
  124. ON_WM_DESTROY()
  125. ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
  126. ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
  127. ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
  128. ON_WM_HSCROLL()
  129. ON_WM_CTLCOLOR()
  130. ON_BN_CLICKED(IDC_SHOWMODE2, OnShowmode2)
  131. ON_BN_CLICKED(IDC_SHOWMODE1, OnShowmode1)
  132. ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
  133. ON_BN_CLICKED(IDC_RADIOBFRAM0, OnRadiobfram0)
  134. ON_BN_CLICKED(IDC_RADIOBFRAM1, OnRadiobfram1)
  135. ON_BN_CLICKED(IDC_RADIOBFRAM2, OnRadiobfram2)
  136. ON_BN_CLICKED(IDC_BUTTON_CLEAN_BUFFER, OnButtonCleanBuffer)
  137. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  138. ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
  139. ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER2, OnReleasedcaptureSlider2)
  140. ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER3, OnReleasedcaptureSlider3)
  141. ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER4, OnReleasedcaptureSlider4)
  142. ON_CONTROL(STN_DBLCLK,IDC_STATIC5,OnDbStatic1)
  143. ON_CONTROL(STN_DBLCLK,IDC_STATIC6,OnDbStatic2)
  144. ON_CONTROL(STN_DBLCLK,IDC_STATIC7,OnDbStatic3)
  145. ON_CONTROL(STN_DBLCLK,IDC_STATIC8,OnDbStatic4)
  146. ON_BN_CLICKED(IDC_BUTTONDEFAULT, OnButtondefault)
  147. //}}AFX_MSG_MAP
  148. END_MESSAGE_MAP()
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CClientdemoDlg message handlers
  151. void CALLBACK DrawFun(LONG StockHandle,HDC hDc,LONG nUser)
  152. {
  153. // if (StockHandle == 0)
  154. {
  155. //直接写
  156. // TextOut(hDc,5,5,"abcdef",5);
  157. }
  158. }
  159. void CALLBACK CapPicFun(long nPort,\
  160. char * pBuf,long nSize,\
  161. long nWidth,long nHeight,\
  162. long nStamp,long nType,long nReceaved)
  163. {
  164. if(!((g_bCapPic) && (nPort == ipos)))
  165. return;
  166. CString csFile;
  167. switch(nType)
  168. {
  169. case T_UYVY:
  170. csFile="c:\\uyvy.bmp";
  171. break;
  172. case T_YV12:
  173. csFile="c:\\yv12.bmp";
  174. break;
  175. case T_RGB32:
  176. csFile="c:\\rgb.bmp";
  177. break;
  178. default:
  179. return ;
  180. }
  181. MP4_ClientSavePicFile(pBuf,nSize,nWidth,nHeight,nType,csFile.GetBuffer(csFile.GetLength()));
  182. g_bCapPic=FALSE;
  183. }
  184. BOOL CClientdemoDlg::OnInitDialog()
  185. {
  186. CDialog::OnInitDialog();
  187. // Add "About..." menu item to system menu.
  188. // IDM_ABOUTBOX must be in the system command range.
  189. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  190. ASSERT(IDM_ABOUTBOX < 0xF000);
  191. CMenu* pSysMenu = GetSystemMenu(FALSE);
  192. if (pSysMenu != NULL)
  193. {
  194. CString strAboutMenu;
  195. strAboutMenu.LoadString(IDS_ABOUTBOX);
  196. if (!strAboutMenu.IsEmpty())
  197. {
  198. pSysMenu->AppendMenu(MF_SEPARATOR);
  199. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  200. }
  201. }
  202. // Set the icon for this dialog. The framework does this automatically
  203. // when the application's main window is not a dialog
  204. SetIcon(m_hIcon, TRUE); // Set big icon
  205. SetIcon(m_hIcon, FALSE); // Set small icon
  206. MP4_ClientSetNetPort(5050,6050);
  207. MP4_ClientStartup(WM_MYCOMMAND,this->m_hWnd);
  208. // m_playtryl.SetRange(1,100,TRUE);
  209. m_delaytype =3;
  210. m_showmode = 0;
  211. m_bframenum = 2;
  212. UpdateData(FALSE);
  213. nn1=nn2=nn3=nn4=-1;
  214. m_iWndNum = -1;
  215. m_windowCtrl.SetCurSel(m_iWndNum);
  216. m_brightness.SetRange(0, 128,TRUE);
  217. m_contrast.SetRange(0, 128,TRUE);
  218. m_saturation.SetRange(0, 128,TRUE);
  219. m_hue.SetRange(0, 128,TRUE);
  220. m_brightness.SetPos(DEFAULTVAL);
  221. m_contrast.SetPos(DEFAULTVAL);
  222. m_saturation.SetPos(DEFAULTVAL);
  223. m_hue.SetPos(DEFAULTVAL);
  224. // TODO: Add extra initialization here
  225. return TRUE; // return TRUE unless you set the focus to a control
  226. }
  227. void CClientdemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  228. {
  229. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  230. {
  231. CAboutDlg dlgAbout;
  232. dlgAbout.DoModal();
  233. }
  234. else
  235. {
  236. CDialog::OnSysCommand(nID, lParam);
  237. }
  238. }
  239. // If you add a minimize button to your dialog, you will need the code below
  240. // to draw the icon. For MFC applications using the document/view model,
  241. // this is automatically done for you by the framework.
  242. void CClientdemoDlg::OnPaint()
  243. {
  244. if (IsIconic())
  245. {
  246. CPaintDC dc(this); // device context for painting
  247. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  248. // Center icon in client rectangle
  249. int cxIcon = GetSystemMetrics(SM_CXICON);
  250. int cyIcon = GetSystemMetrics(SM_CYICON);
  251. CRect rect;
  252. GetClientRect(&rect);
  253. int x = (rect.Width() - cxIcon + 1) / 2;
  254. int y = (rect.Height() - cyIcon + 1) / 2;
  255. // Draw the icon
  256. dc.DrawIcon(x, y, m_hIcon);
  257. }
  258. else
  259. {
  260. CDialog::OnPaint();
  261. }
  262. }
  263. // The system calls this to obtain the cursor to display while the user drags
  264. // the minimized window.
  265. HCURSOR CClientdemoDlg::OnQueryDragIcon()
  266. {
  267. return (HCURSOR) m_hIcon;
  268. }
  269. void CALLBACK ReadDataCallBack(DWORD nPort,UCHAR *pPacketBuffer,DWORD nPacketSize)
  270. {
  271. TRACE("%d\n",nPacketSize);
  272. }
  273. void CClientdemoDlg::OnButton1()
  274. {
  275. CWnd* pButton1;
  276. CString csFile;
  277. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON1);
  278. pButton1->EnableWindow(FALSE);
  279. UpdateData(TRUE);
  280. if (m_showmode == 0)
  281. {
  282. MP4_ClientSetShowMode(NORMALMODE,0);
  283. }
  284. else
  285. {
  286. MP4_ClientSetShowMode(OVERLAYMODE,COLORREF(0xff00ff));
  287. }
  288. nn1=nn2=nn3=nn4 = -1;
  289. int itemp = m_shownum;
  290. char ips[256];
  291. sprintf(ips,"%s",m_ipadd);
  292. hWnd5 = m_video5.GetSafeHwnd();//
  293. aa5.m_bRemoteChannel = 0;
  294. switch(m_linktype)
  295. {
  296. case 0:
  297. aa5.m_bSendMode = TCPMODE;
  298. break;
  299. case 1:
  300. aa5.m_bSendMode = UDPMODE;
  301. break;
  302. case 2:
  303. aa5.m_bSendMode = MULTIMODE;
  304. break;
  305. case 3:
  306. aa5.m_bSendMode = DIALING;
  307. break;
  308. case 4:
  309. aa5.m_bSendMode = AUDIODETACH;
  310. break;
  311. default:
  312. aa5.m_bSendMode = TCPMODE;
  313. break;
  314. }
  315. aa5.m_sIPAddress = ips;
  316. //2003.12.2
  317. //如果想只录像,而不进行解码,可以将m_hShowVideo设置成NULL
  318. //If you just want to record without decode on client side,
  319. //please set m_hShowVideo as NULL
  320. #if defined RECORD_ONLY
  321. aa5.m_hShowVideo = NULL;
  322. #else
  323. aa5.m_hShowVideo = hWnd5;
  324. #endif
  325. // add 2003.12.2
  326. //m_nImgFormat 指明想要获取的图像格式
  327. //依赖服务器端的设置。如果不设置,获取的是服务器的缺省格式
  328. //m_nImgFormat indicates the picture format you get on the client side,
  329. //It depends on the setting of Server side.
  330. aa5.m_nImgFormat = 0; // request CIF format
  331. // aa5.m_nImgFormat = 1; // request QCIF format
  332. aa5.m_sUserName = "123";
  333. aa5.m_sUserPassword="w";
  334. aa5.m_bUserCheck = TRUE;
  335. MP4_ClientSetTTL(64);
  336. nn1 = MP4_ClientStart(&aa5,ReadDataCallBack);
  337. if (nn1 == -1)
  338. {
  339. MessageBox("error");
  340. return;
  341. }
  342. //
  343. BOOL breturn;
  344. breturn = MP4_ClientRigisterDrawFun(nn1,DrawFun,0);
  345. switch(m_delaytype)
  346. {
  347. case 0:
  348. MP4_ClientSetBufferNum(nn1,40);
  349. MP4_ClientSetPlayDelay(nn1,580);
  350. break;
  351. case 1:
  352. MP4_ClientSetBufferNum(nn1,15);
  353. MP4_ClientSetPlayDelay(nn1,40);
  354. break;
  355. case 2:
  356. MP4_ClientSetBufferNum(nn1,15);
  357. MP4_ClientSetPlayDelay(nn1,0);
  358. break;
  359. case 3:
  360. MP4_ClientSetBufferNum(nn1,0);
  361. MP4_ClientSetPlayDelay(nn1,0);
  362. break;
  363. }
  364. // MP4_ClientThrowBFrame(nn1,m_bframenum);
  365. MP4_ClientSetCapPicCallBack(nn1,CapPicFun);
  366. itemp --;
  367. if (itemp<=0)
  368. goto GOTOEND;
  369. if (m_showmode == 1)
  370. {
  371. goto GOTOEND;
  372. }
  373. Sleep(200);
  374. hWnd6 = m_video6.GetSafeHwnd();//
  375. aa6.m_bRemoteChannel =1;
  376. switch(m_linktype)
  377. {
  378. case 0:
  379. aa6.m_bSendMode = TCPMODE;
  380. break;
  381. case 1:
  382. aa6.m_bSendMode = UDPMODE;
  383. break;
  384. case 2:
  385. aa6.m_bSendMode = MULTIMODE;
  386. break;
  387. case 3:
  388. aa6.m_bSendMode = DIALING;
  389. break;
  390. case 4:
  391. aa6.m_bSendMode = AUDIODETACH;
  392. break;
  393. default:
  394. aa6.m_bSendMode = TCPMODE;
  395. break;
  396. }
  397. aa6.m_sIPAddress = ips;
  398. #if defined RECORD_ONLY
  399. aa6.m_hShowVideo = NULL;
  400. #else
  401. aa6.m_hShowVideo = hWnd6;
  402. #endif
  403. aa6.m_nImgFormat = 0;
  404. aa6.m_sUserName = "123";
  405. aa6.m_sUserPassword="w";
  406. aa6.m_bUserCheck = TRUE;
  407. MP4_ClientSetTTL(32);
  408. nn2 = MP4_ClientStart(&aa6,NULL);
  409. if (nn2 == -1)
  410. {
  411. MessageBox("error");
  412. return;
  413. }
  414. switch(m_delaytype)
  415. {
  416. case 0:
  417. MP4_ClientSetBufferNum(nn2,40);
  418. MP4_ClientSetPlayDelay(nn2,580);
  419. break;
  420. case 1:
  421. MP4_ClientSetBufferNum(nn2,15);
  422. MP4_ClientSetPlayDelay(nn2,30);
  423. break;
  424. case 2:
  425. MP4_ClientSetBufferNum(nn2,15);
  426. MP4_ClientSetPlayDelay(nn2,0);
  427. break;
  428. case 3:
  429. MP4_ClientSetBufferNum(nn2,0);
  430. MP4_ClientSetPlayDelay(nn2,0);
  431. break;
  432. }
  433. // MP4_ClientThrowBFrame(nn2,m_bframenum);
  434. MP4_ClientSetCapPicCallBack(nn2,CapPicFun);
  435. itemp --;
  436. if (itemp<=0)
  437. goto GOTOEND;
  438. Sleep(200);
  439. hWnd7 = m_video7.GetSafeHwnd();//
  440. aa7.m_bRemoteChannel = 2;
  441. switch(m_linktype)
  442. {
  443. case 0:
  444. aa7.m_bSendMode = TCPMODE;
  445. break;
  446. case 1:
  447. aa7.m_bSendMode = UDPMODE;
  448. break;
  449. case 2:
  450. aa7.m_bSendMode = MULTIMODE;
  451. break;
  452. case 3:
  453. aa7.m_bSendMode = DIALING;
  454. break;
  455. case 4:
  456. aa7.m_bSendMode = AUDIODETACH;
  457. break;
  458. default:
  459. aa7.m_bSendMode = TCPMODE;
  460. break;
  461. }
  462. aa7.m_sIPAddress = ips;
  463. #if defined RECORD_ONLY
  464. aa7.m_hShowVideo = NULL;
  465. #else
  466. aa7.m_hShowVideo = hWnd7;
  467. #endif
  468. aa7.m_nImgFormat = 0;
  469. aa7.m_sUserName = "123";
  470. aa7.m_sUserPassword="w";
  471. aa7.m_bUserCheck = TRUE;
  472. MP4_ClientSetTTL(64);
  473. nn3 = MP4_ClientStart(&aa7,NULL);
  474. if (nn3 == -1)
  475. {
  476. MessageBox("error");
  477. return;
  478. }
  479. switch(m_delaytype)
  480. {
  481. case 0:
  482. MP4_ClientSetBufferNum(nn3,40);
  483. MP4_ClientSetPlayDelay(nn3,580);
  484. break;
  485. case 1:
  486. MP4_ClientSetBufferNum(nn3,15);
  487. MP4_ClientSetPlayDelay(nn3,30);
  488. break;
  489. case 2:
  490. MP4_ClientSetBufferNum(nn3,15);
  491. MP4_ClientSetPlayDelay(nn3,0);
  492. break;
  493. case 3:
  494. MP4_ClientSetBufferNum(nn3,0);
  495. MP4_ClientSetPlayDelay(nn3,0);
  496. break;
  497. }
  498. // MP4_ClientThrowBFrame(nn3,m_bframenum);
  499. MP4_ClientSetCapPicCallBack(nn3,CapPicFun);
  500. itemp --;
  501. if (itemp<=0)
  502. goto GOTOEND;
  503. Sleep(200);
  504. hWnd8 = m_video8.GetSafeHwnd();//
  505. aa8.m_bRemoteChannel = 3;
  506. switch(m_linktype)
  507. {
  508. case 0:
  509. aa8.m_bSendMode = TCPMODE;
  510. break;
  511. case 1:
  512. aa8.m_bSendMode = UDPMODE;
  513. break;
  514. case 2:
  515. aa8.m_bSendMode = MULTIMODE;
  516. break;
  517. case 3:
  518. aa8.m_bSendMode = DIALING;
  519. break;
  520. case 4:
  521. aa8.m_bSendMode = AUDIODETACH;
  522. break;
  523. default:
  524. aa8.m_bSendMode = TCPMODE;
  525. break;
  526. }
  527. aa8.m_sIPAddress = ips;
  528. #if defined RECORD_ONLY
  529. aa8.m_hShowVideo = NULL;
  530. #else
  531. aa8.m_hShowVideo = hWnd8;
  532. #endif
  533. aa8.m_nImgFormat = 0;
  534. aa8.m_sUserName = "123";
  535. aa8.m_sUserPassword="w";
  536. aa8.m_bUserCheck = TRUE;
  537. MP4_ClientSetTTL(64);
  538. nn4 = MP4_ClientStart(&aa8,NULL);
  539. if (nn4 == -1)
  540. {
  541. MessageBox("Error");
  542. return;
  543. }
  544. switch(m_delaytype)
  545. {
  546. case 0:
  547. MP4_ClientSetBufferNum(nn4,40);
  548. MP4_ClientSetPlayDelay(nn4,580);
  549. break;
  550. case 1:
  551. MP4_ClientSetBufferNum(nn4,15);
  552. MP4_ClientSetPlayDelay(nn4,30);
  553. break;
  554. case 2:
  555. MP4_ClientSetBufferNum(nn4,15);
  556. MP4_ClientSetPlayDelay(nn4,0);
  557. break;
  558. case 3:
  559. MP4_ClientSetBufferNum(nn4,0);
  560. MP4_ClientSetPlayDelay(nn4,0);
  561. break;
  562. }
  563. // MP4_ClientThrowBFrame(nn4,m_bframenum);
  564. MP4_ClientSetCapPicCallBack(nn4,CapPicFun);
  565. GOTOEND:
  566. // remains=SetTimer(10,1000,NULL);
  567. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON2);
  568. pButton1->EnableWindow(TRUE);
  569. if(nn1 >= 0)
  570. {
  571. m_iWndNum = 1;
  572. m_windowCtrl.SetCurSel(m_iWndNum-1);
  573. OnSelchangeCombo1();
  574. }
  575. }
  576. void CClientdemoDlg::OnButton2()
  577. {
  578. CWnd* pButton1;
  579. /*
  580. if (remains)
  581. {
  582. remains = 0;
  583. KillTimer(remains);
  584. }
  585. */
  586. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON2);
  587. pButton1->EnableWindow(FALSE);
  588. if (filetimer)
  589. {
  590. KillTimer(filetimer);
  591. filetimer = 0;
  592. }
  593. if (nn1 >= 0)
  594. {
  595. MP4_ClientStopCapture(nn1);
  596. MP4_ClientStop(nn1);
  597. }
  598. nn1=-1;
  599. Sleep(100);
  600. if (nn2 >= 0)
  601. {
  602. MP4_ClientStopCapture(nn2);
  603. MP4_ClientStop(nn2);
  604. }
  605. Sleep(100);
  606. nn2=-1;
  607. if (nn3 >= 0)
  608. {
  609. MP4_ClientStopCapture(nn3);
  610. MP4_ClientStop(nn3);
  611. }
  612. Sleep(100);
  613. nn3=-1;
  614. if (nn4 >= 0)
  615. {
  616. MP4_ClientStopCapture(nn4);
  617. MP4_ClientStop(nn4);
  618. }
  619. Sleep(100);
  620. nn4=-1;
  621. m_video5.Invalidate(TRUE);
  622. m_video6.Invalidate(TRUE);
  623. m_video7.Invalidate(TRUE);
  624. m_video8.Invalidate(TRUE);
  625. UpdateData(FALSE);
  626. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON1);
  627. pButton1->EnableWindow(TRUE);
  628. MessageBox("End!");
  629. }
  630. void CClientdemoDlg::OnTimer(UINT nIDEvent)
  631. {
  632. if (nIDEvent == 1)
  633. {
  634. }
  635. else if (nIDEvent == 10)
  636. {
  637. if (nn1>=0)
  638. {
  639. m_frameshow.Format("nowframenum:%ld",MP4_ClientGetFrameNum(nn1));
  640. UpdateData(FALSE);
  641. }
  642. }
  643. CDialog::OnTimer(nIDEvent);
  644. }
  645. void CClientdemoDlg::OnStatic5()
  646. {
  647. // TODO: Add your control notification handler code here
  648. ipos = 0;
  649. }
  650. void CClientdemoDlg::OnStatic7()
  651. {
  652. ipos = 2;
  653. }
  654. void CClientdemoDlg::OnStatic6()
  655. {
  656. ipos = 1;
  657. }
  658. void CClientdemoDlg::OnStatic8()
  659. {
  660. ipos = 3;
  661. }
  662. void CClientdemoDlg::OnButton4()
  663. {
  664. CWnd* pButton1;
  665. if (nn1>=0)
  666. MP4_ClientStopCapture(nn1);
  667. if (nn2>=0)
  668. MP4_ClientStopCapture(nn2);
  669. if (nn3>=0)
  670. MP4_ClientStopCapture(nn3);
  671. if (nn4>=0)
  672. MP4_ClientStopCapture(nn4);
  673. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON4);
  674. pButton1->EnableWindow(FALSE);
  675. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON8);
  676. pButton1->EnableWindow(TRUE);
  677. }
  678. void CClientdemoDlg::OnButton3()
  679. {
  680. char ctemp[256];
  681. char ips[256];
  682. WORD wtemp;
  683. UpdateData(TRUE);
  684. sprintf(ips,"%s",m_ipadd);
  685. wtemp = MP4_ClientGetServerChanNum(ips);
  686. sprintf(ctemp,"%d",wtemp);
  687. MessageBox(ctemp);
  688. }
  689. void CClientdemoDlg::OnButton6()
  690. {
  691. char ctemp[256];
  692. char sendcont[500];
  693. CString firstco;
  694. firstco = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
  695. MP4_ClientSetWait(3000,10);
  696. // for(int i=0;i<100;i++)
  697. {
  698. memset(sendcont,0,500);
  699. UpdateData(TRUE);
  700. sprintf(ctemp,"%s",m_ipadd);
  701. sprintf(sendcont,"%s send content %d",firstco,testnum);
  702. testnum++;
  703. if (testnum > 200)
  704. testnum=0;
  705. MP4_ClientCommandtoServer((LPCTSTR)ctemp,sendcont,400);
  706. Sleep(100);
  707. }
  708. }
  709. void CClientdemoDlg::OnMyCommand(WPARAM wParam, LPARAM lParam)
  710. {
  711. char ctemp[1000];
  712. switch((BYTE)wParam)
  713. {
  714. case RECDATAERR:
  715. {
  716. CTime time;
  717. time = CTime::GetCurrentTime();
  718. sprintf(ctemp,"%d index%d,receive error",time.GetHour(),(BYTE)lParam);
  719. break;
  720. }
  721. case PLAYERR:
  722. {
  723. CTime time;
  724. time = CTime::GetCurrentTime();
  725. sprintf(ctemp,"%d index%d,play error",time.GetHour(),(BYTE)lParam);
  726. break;
  727. }
  728. case REFUSED:
  729. {
  730. CTime time;
  731. time = CTime::GetCurrentTime();
  732. sprintf(ctemp,"%d index%d,no permission",time.GetHour(),(BYTE)lParam);
  733. break;
  734. }
  735. case VERSIONERR:
  736. {
  737. CTime time;
  738. time = CTime::GetCurrentTime();
  739. sprintf(ctemp,"%d index%d,version error",time.GetHour(),(BYTE)lParam);
  740. break;
  741. }
  742. case GETSTRING:
  743. {
  744. WORD tlen;
  745. char ips[30];
  746. memset(ctemp,0,1000);
  747. MP4_ClientReadLastMessage(ips,ctemp,&tlen);
  748. sprintf(&(ctemp[tlen]),"\r\n");
  749. // TRACE(ctemp);
  750. break;
  751. }
  752. default:
  753. {
  754. sprintf(ctemp,"index%d,message%d",(BYTE)lParam,(BYTE)wParam);
  755. break;
  756. }
  757. }
  758. MessageBox(ctemp);
  759. }
  760. void CClientdemoDlg::OnDestroy()
  761. {
  762. if (nn1 >= 0)
  763. {
  764. MP4_ClientStopCapture(nn1);
  765. // ClientStopPlay(nn5);
  766. MP4_ClientStop(nn1);
  767. }
  768. if (nn2 >= 0)
  769. {
  770. MP4_ClientStopCapture(nn2);
  771. // ClientStopPlay(nn5);
  772. MP4_ClientStop(nn2);
  773. }
  774. if (nn3 >= 0)
  775. {
  776. MP4_ClientStopCapture(nn3);
  777. // ClientStopPlay(nn5);
  778. MP4_ClientStop(nn3);
  779. }
  780. if (nn4 >= 0)
  781. {
  782. MP4_ClientStopCapture(nn4);
  783. // ClientStopPlay(nn5);
  784. MP4_ClientStop(nn4);
  785. }
  786. MP4_ClientCleanup();
  787. CDialog::OnDestroy();
  788. }
  789. void CClientdemoDlg::OnButton5()
  790. {
  791. char ctemp[256];
  792. UpdateData(TRUE);
  793. sprintf(ctemp,"%s",m_ipadd);
  794. MP4_ClientShut((LPCTSTR)ctemp,0);
  795. }
  796. void CClientdemoDlg::OnButton7()
  797. {
  798. MP4_ClientAudioStop();
  799. }
  800. void CClientdemoDlg::OnDbStatic1()
  801. {
  802. if (nn1 >= 0 )
  803. {
  804. MP4_ClientAudioStart(nn1);
  805. MP4_ClientAudioVolume(0xfff0);
  806. }
  807. if (blarged)
  808. {
  809. ScreenToClient((LPPOINT)&orirc);
  810. ScreenToClient((LPPOINT)&orirc+1);
  811. m_video5.MoveWindow(orirc,TRUE);
  812. m_video6.ShowWindow(SW_SHOW);
  813. m_video7.ShowWindow(SW_SHOW);
  814. m_video8.ShowWindow(SW_SHOW);
  815. blarged = FALSE;
  816. }
  817. else
  818. {
  819. m_video6.ShowWindow(SW_HIDE);
  820. m_video7.ShowWindow(SW_HIDE);
  821. m_video8.ShowWindow(SW_HIDE);
  822. m_video5.GetWindowRect(&orirc);
  823. m_video5.MoveWindow(10,10,(int)(352*1.6),(int)(288*1.6),TRUE);
  824. blarged = TRUE;
  825. }
  826. }
  827. void CClientdemoDlg::OnDbStatic2()
  828. {
  829. if (nn2 >=0 )
  830. {
  831. MP4_ClientAudioStart(nn2);
  832. MP4_ClientAudioVolume(0xfff0);
  833. }
  834. }
  835. void CClientdemoDlg::OnDbStatic3()
  836. {
  837. if (nn3 >=0 )
  838. {
  839. MP4_ClientAudioStart(nn3);
  840. MP4_ClientAudioVolume(0xfff0);
  841. }
  842. }
  843. void CClientdemoDlg::OnDbStatic4()
  844. {
  845. if (nn4 >=0 )
  846. {
  847. MP4_ClientAudioStart(nn4);
  848. MP4_ClientAudioVolume(0xfff0);
  849. }
  850. }
  851. BOOL CClientdemoDlg::DestroyWindow()
  852. {
  853. return CDialog::DestroyWindow();
  854. }
  855. void CClientdemoDlg::OnButton8()
  856. {
  857. char filename[256];
  858. CWnd* pButton1;
  859. if (nn1 >= 0)
  860. {
  861. sprintf(filename,"d:\\mp4test1_%d.mp4",capcount);
  862. MP4_ClientStartCaptureFile(nn1,filename);
  863. //MP4_ClientStartCapture(nn1);
  864. }
  865. if (nn2 >= 0)
  866. {
  867. sprintf(filename,"d:\\mp4test2_%d.mp4",capcount);
  868. MP4_ClientStartCaptureFile(nn2,filename);
  869. }
  870. if (nn3 >= 0)
  871. {
  872. sprintf(filename,"d:\\mp4test3_%d.mp4",capcount);
  873. MP4_ClientStartCaptureFile(nn3,filename);
  874. }
  875. if (nn4 >= 0)
  876. {
  877. sprintf(filename,"d:\\mp4test4_%d.mp4",capcount);
  878. MP4_ClientStartCaptureFile(nn4,filename);
  879. }
  880. capcount++;
  881. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON4);
  882. pButton1->EnableWindow(TRUE);
  883. pButton1 = (CButton*)GetDlgItem(IDC_BUTTON8);
  884. pButton1->EnableWindow(FALSE);
  885. //
  886. }
  887. void CClientdemoDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  888. {
  889. //
  890. // char cpos;
  891. // cpos = (char)(m_playtryl.GetPos());
  892. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  893. }
  894. HBRUSH CClientdemoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  895. {
  896. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  897. // TODO: Return a different brush if the default is not desired
  898. if (bmode)
  899. {
  900. CWnd*pSubWnd=GetDlgItem(IDC_STATIC5);
  901. if(pWnd->m_hWnd==pSubWnd->m_hWnd)
  902. {
  903. pDC->SetBkColor(RGB(255,0,255));
  904. HBRUSH hBrush=::CreateSolidBrush(COLORREF(0xff00ff));
  905. return hBrush;
  906. }
  907. }
  908. return hbr;
  909. }
  910. void CClientdemoDlg::OnShowmode2()
  911. {
  912. bmode = TRUE;
  913. GetDlgItem(IDC_STATIC5)->Invalidate(TRUE);
  914. }
  915. void CClientdemoDlg::OnShowmode1()
  916. {
  917. bmode = FALSE;
  918. GetDlgItem(IDC_STATIC5)->Invalidate(TRUE);
  919. }
  920. void CClientdemoDlg::OnButton10()
  921. {
  922. g_bCapPic = TRUE;
  923. }
  924. void CClientdemoDlg::OnRadiobfram0()
  925. {
  926. if (nn1>=0)
  927. {
  928. // MP4_ClientThrowBFrame(nn1,0);
  929. }
  930. if (nn2>=0)
  931. {
  932. // MP4_ClientThrowBFrame(nn2,0);
  933. }
  934. if (nn3>=0)
  935. {
  936. // MP4_ClientThrowBFrame(nn3,0);
  937. }
  938. if (nn4>=0)
  939. {
  940. // MP4_ClientThrowBFrame(nn4,0);
  941. }
  942. }
  943. void CClientdemoDlg::OnRadiobfram1()
  944. {
  945. if (nn1>=0)
  946. {
  947. // MP4_ClientThrowBFrame(nn1,1);
  948. }
  949. if (nn2>=0)
  950. {
  951. // MP4_ClientThrowBFrame(nn2,1);
  952. }
  953. if (nn3>=0)
  954. {
  955. // MP4_ClientThrowBFrame(nn3,1);
  956. }
  957. if (nn4>=0)
  958. {
  959. // MP4_ClientThrowBFrame(nn4,1);
  960. }
  961. }
  962. void CClientdemoDlg::OnRadiobfram2()
  963. {
  964. if (nn1>=0)
  965. {
  966. // MP4_ClientThrowBFrame(nn1,2);
  967. }
  968. if (nn2>=0)
  969. {
  970. // MP4_ClientThrowBFrame(nn2,2);
  971. }
  972. if (nn3>=0)
  973. {
  974. // MP4_ClientThrowBFrame(nn3,2);
  975. }
  976. if (nn4>=0)
  977. {
  978. // MP4_ClientThrowBFrame(nn4,2);
  979. }
  980. }
  981. void CClientdemoDlg::OnButtonCleanBuffer()
  982. {
  983. // clean client buffer
  984. //if ( nn1 != -1 )
  985. // MP4_ClientCleanBuffer(nn1,0);
  986. // clean server buffer
  987. //if ( nn1 != - 1)
  988. // MP4_ClientCleanBuffer(nn1,1);
  989. // clean server/client buffer
  990. if ( nn1 != -1 )
  991. MP4_ClientCleanBuffer(nn1,2);
  992. }
  993. void CClientdemoDlg::OnSelchangeCombo1()
  994. {
  995. // TODO: Add your control notification handler code here
  996. UpdateData(TRUE);
  997. m_iWndNum = m_windowCtrl.GetCurSel()+1;
  998. switch(m_iWndNum) {
  999. case 1:
  1000. if(nn1 >= 0)
  1001. {
  1002. if(MP4_ClientGetVideoPara(nn1, 0, &m_iBrightness, &m_iContrast, &m_iSaturation, &m_iHue))
  1003. {
  1004. m_brightness.SetPos(m_iBrightness);
  1005. m_contrast.SetPos(m_iContrast);
  1006. m_saturation.SetPos(m_iSaturation);
  1007. m_hue.SetPos(m_iHue);
  1008. return;
  1009. }
  1010. }
  1011. break;
  1012. case 2:
  1013. if(nn2 >= 0)
  1014. {
  1015. if(MP4_ClientGetVideoPara(nn2, 0, &m_iBrightness, &m_iContrast, &m_iSaturation, &m_iHue))
  1016. {
  1017. m_brightness.SetPos(m_iBrightness);
  1018. m_contrast.SetPos(m_iContrast);
  1019. m_saturation.SetPos(m_iSaturation);
  1020. m_hue.SetPos(m_iHue);
  1021. return;
  1022. }
  1023. }
  1024. break;
  1025. case 3:
  1026. if(nn3 >= 0)
  1027. {
  1028. if(MP4_ClientGetVideoPara(nn3, 0, &m_iBrightness, &m_iContrast, &m_iSaturation, &m_iHue))
  1029. {
  1030. m_brightness.SetPos(m_iBrightness);
  1031. m_contrast.SetPos(m_iContrast);
  1032. m_saturation.SetPos(m_iSaturation);
  1033. m_hue.SetPos(m_iHue);
  1034. return;
  1035. }
  1036. }
  1037. break;
  1038. case 4:
  1039. if(nn4 >= 0)
  1040. {
  1041. if(MP4_ClientGetVideoPara(nn4, 0, &m_iBrightness, &m_iContrast, &m_iSaturation, &m_iHue))
  1042. {
  1043. m_brightness.SetPos(m_iBrightness);
  1044. m_contrast.SetPos(m_iContrast);
  1045. m_saturation.SetPos(m_iSaturation);
  1046. m_hue.SetPos(m_iHue);
  1047. return;
  1048. }
  1049. }
  1050. break;
  1051. default:
  1052. break;
  1053. }
  1054. // AfxMessageBox("Get Video Parameter Failed!");
  1055. m_iBrightness = m_iContrast = m_iSaturation = m_iHue = DEFAULTVAL;
  1056. m_brightness.SetPos(DEFAULTVAL);
  1057. m_contrast.SetPos(DEFAULTVAL);
  1058. m_saturation.SetPos(DEFAULTVAL);
  1059. m_hue.SetPos(DEFAULTVAL);
  1060. }
  1061. void CClientdemoDlg::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
  1062. {
  1063. // TODO: Add your control notification handler code here
  1064. m_iBrightness = m_brightness.GetPos();
  1065. SliderContral();
  1066. *pResult = 0;
  1067. }
  1068. void CClientdemoDlg::OnReleasedcaptureSlider2(NMHDR* pNMHDR, LRESULT* pResult)
  1069. {
  1070. // TODO: Add your control notification handler code here
  1071. m_iContrast = m_contrast.GetPos();
  1072. SliderContral();
  1073. *pResult = 0;
  1074. }
  1075. void CClientdemoDlg::OnReleasedcaptureSlider3(NMHDR* pNMHDR, LRESULT* pResult)
  1076. {
  1077. // TODO: Add your control notification handler code here
  1078. m_iSaturation = m_saturation.GetPos();
  1079. SliderContral();
  1080. *pResult = 0;
  1081. }
  1082. void CClientdemoDlg::OnReleasedcaptureSlider4(NMHDR* pNMHDR, LRESULT* pResult)
  1083. {
  1084. // TODO: Add your control notification handler code here
  1085. m_iHue = m_hue.GetPos();
  1086. SliderContral();
  1087. *pResult = 0;
  1088. }
  1089. BOOL CClientdemoDlg::SliderContral()
  1090. {
  1091. switch(m_iWndNum) {
  1092. case 1:
  1093. if(nn1 >= 0)
  1094. {
  1095. if(!MP4_ClientSetVideoPara(nn1, 0, m_iBrightness, m_iContrast, m_iSaturation, m_iHue))
  1096. {
  1097. AfxMessageBox("Set Video Parameter Failed!");
  1098. }
  1099. }
  1100. break;
  1101. case 2:
  1102. if(nn2 >= 0)
  1103. {
  1104. if(!MP4_ClientSetVideoPara(nn2, 0, m_iBrightness, m_iContrast, m_iSaturation, m_iHue))
  1105. {
  1106. AfxMessageBox("Set Video Parameter Failed!");
  1107. }
  1108. }
  1109. break;
  1110. case 3:
  1111. if(nn3 >= 0)
  1112. {
  1113. if(!MP4_ClientSetVideoPara(nn3, 0, m_iBrightness, m_iContrast, m_iSaturation, m_iHue))
  1114. {
  1115. AfxMessageBox("Set Video Parameter Failed!");
  1116. }
  1117. }
  1118. break;
  1119. case 4:
  1120. if(nn4 >= 0)
  1121. {
  1122. if(!MP4_ClientSetVideoPara(nn4, 0, m_iBrightness, m_iContrast, m_iSaturation, m_iHue))
  1123. {
  1124. AfxMessageBox("Set Video Parameter Failed!");
  1125. }
  1126. }
  1127. break;
  1128. default:
  1129. break;
  1130. }
  1131. return TRUE;
  1132. }
  1133. void CClientdemoDlg::OnButtondefault()
  1134. {
  1135. // TODO: Add your control notification handler code here
  1136. m_iBrightness = m_iContrast = m_iSaturation = m_iHue = DEFAULTVAL;
  1137. SliderContral();
  1138. m_brightness.SetPos(m_iBrightness);
  1139. m_contrast.SetPos(m_iContrast);
  1140. m_saturation.SetPos(m_iSaturation);
  1141. m_hue.SetPos(m_iHue);
  1142. }