clientdemoDlg.cpp 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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. }