WCAM020MF.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSSkinF.h"
  5. #include "ITSUtilF.h"
  6. #include "ITSLangTransF.h"
  7. #pragma hdrstop
  8. #include "WCAM020MF.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "cxButtons"
  12. #pragma link "cxCalc"
  13. #pragma link "cxCheckBox"
  14. #pragma link "cxClasses"
  15. #pragma link "cxContainer"
  16. #pragma link "cxControls"
  17. #pragma link "cxCustomData"
  18. #pragma link "cxData"
  19. #pragma link "cxDataStorage"
  20. #pragma link "cxEdit"
  21. #pragma link "cxFilter"
  22. #pragma link "cxGraphics"
  23. #pragma link "cxGrid"
  24. #pragma link "cxGridBandedTableView"
  25. #pragma link "cxGridCustomTableView"
  26. #pragma link "cxGridCustomView"
  27. #pragma link "cxGridLevel"
  28. #pragma link "cxGridTableView"
  29. #pragma link "cxGroupBox"
  30. #pragma link "cxLabel"
  31. #pragma link "cxLookAndFeelPainters"
  32. #pragma link "cxLookAndFeels"
  33. #pragma link "cxMaskEdit"
  34. #pragma link "cxPC"
  35. #pragma link "cxPCdxBarPopupMenu"
  36. #pragma link "cxSpinEdit"
  37. #pragma link "cxStyles"
  38. #pragma link "cxTextEdit"
  39. #pragma link "dxSkinBlue"
  40. #pragma link "dxSkinsCore"
  41. #pragma link "dxSkinscxPCPainter"
  42. #pragma link "FFBaseComponent"
  43. #pragma link "FFBasePlay"
  44. #pragma link "FFPlay"
  45. #pragma link "FRAME_WCamStateListF"
  46. #pragma link "IdBaseComponent"
  47. #pragma link "IdComponent"
  48. #pragma link "IdIcmpClient"
  49. #pragma link "IdRawBase"
  50. #pragma link "IdRawClient"
  51. #pragma link "ImageBtn"
  52. #pragma link "XNVTViewerCtrlLib_OCX"
  53. #pragma resource "*.dfm"
  54. TWCAM020M *WCAM020M = NULL;
  55. //{* Information Bar *}
  56. #define CAP_CAMERA_NAME 0x01
  57. #define CAP_TIME 0x02
  58. #define CAP_CHANNEL 0x04
  59. #define CAP_SIZE 0x08
  60. #define CAP_EVENT 0x10
  61. #define CAP_FPSCHANGED 0x20
  62. //{* Pan/tilt/Zoom and Transparent controls *}
  63. #define CTL_FOCUS_CONT 0x2001
  64. #define CTL_PTZ_CONT 0x2002
  65. #define CTL_TRANSPARENT 0x7000
  66. #define CTL_TRANSPARENT_RS232 0x7001
  67. //{* OCXState for NVSMPEG4OCX *}
  68. #define GRAPH_NONE 0x00000000
  69. #define GRAPH_PREVIEW 0x00000001
  70. #define GRAPH_CAPTURE 0x00000002
  71. #define GRAPH_PREVIEWCAPTURE 0x00000003
  72. #define GRAPH_AUDIO_LISTEN 0x00000100
  73. #define GRAPH_AUDIO_CAPTURE 0x00000200
  74. #define GRAPH_AUDIO_LISTENCAPTURE 0x00000400
  75. #define GRAPH_STATE_RUNNING 0x80000000
  76. #define SB_PAN_LEFT 0x000000C4
  77. #define SB_PAN_RIGHT 0x0000003C
  78. #define SB_TILT_UP 0x00003C00
  79. #define SB_TILT_DOWN 0x0000C400
  80. #define SB_ZOOM_IN 0x003C0000
  81. #define SB_ZOOM_OUT 0x00C40000
  82. #define SB_FOCUS_IN 0x3C
  83. #define SB_FOCUS_OUT 0xC4
  84. enum { E_MJPG=0, E_MP4S, E_DX50, E_MPEG2, E_MPEG1, E_H264 };
  85. enum { BR_32K=0, BR_64K, BR_128K, BR_256K, BR_384K, BR_500K, BR_750K, BR_1M, BR_1_5M, BR_2M, BR_4M, BR_5M, BR_6M, BR_7M, BR_8M };
  86. enum { S_1080P=0, S_720P, S_D1, S_4CIF, S_VGA, S_HD1, S_H4CIF, S_HVGA, S_CIF, S_QVGA, S_QCIF, S_QQVGA };
  87. #define PRESET_SET 0x1020 // Unsigned 1 byte
  88. #define PRESET_MOVE 0x1021 // Unsigned 1 byte
  89. #define PRESET_CLEAR 0x1022 // Unsigned 1 byte
  90. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  91. //---------------------------------------------------------------------------
  92. __fastcall TWCAM020M::TWCAM020M(TComponent* Owner)
  93. : TForm(Owner)
  94. {
  95. //::CoInitialize(NULL);
  96. LangTrans->Translate(this, ITSDb_GetConnection());
  97. ITSSkin_Load(this);
  98. LoadLocalSkin();
  99. CMM_LoadForm(g_sFormsDir, this);
  100. FSelCtlr = NULL;
  101. FRAMEWCamStateList1->PnlTop->Visible = false;
  102. FRAMEWCamStateList1->PnlBottom->Visible = false;
  103. FRAMEWCamStateList1->TvList->OptionsView->Footer = false;
  104. FRAMEWCamStateList1->Col04->Visible = false;
  105. FRAMEWCamStateList1->Col05->Visible = false;
  106. FRAMEWCamStateList1->Col06->Visible = true;
  107. FRAMEWCamStateList1->ColumnSel->Visible = false;
  108. PgControl->ActivePageIndex = 0;
  109. FSelIds = new TStringList();
  110. FTitle = Caption;
  111. //TabPreset->Visible = false;
  112. //TabPreset->TabVisible = false;
  113. FStrmPlay = false;
  114. String sAVILibDir = g_sAppDir + "LibAV";
  115. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  116. FFPlayer1->DisableFPUExceptions();
  117. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  118. {
  119. reMsg->Lines->Add("영상표출 라이브러리 초기화 실패.");
  120. #if 0
  121. if (g_AppCfg.sLang != "kr") Application->MessageBox(L"Stream display library load failed.", L"Stream display fail", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  122. else Application->MessageBox(L"영상표출 라이브러리를 로드하지 못하였습니다.", L"영상표출 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  123. #endif
  124. }
  125. PgCam->Properties->HideTabs = true;
  126. PnlCamera->ParentColor = false;
  127. FTmrShow = true;
  128. }
  129. //---------------------------------------------------------------------------
  130. void __fastcall TWCAM020M::CommClose()
  131. {
  132. try
  133. {
  134. SAFE_DELETE(FSelIds);
  135. CMM_SaveForm(g_sFormsDir, this);
  136. CloseWebCamera();
  137. CloseRtsp();
  138. //::CoUninitialize();
  139. }
  140. catch(...)
  141. {
  142. }
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TWCAM020M::FormShow(TObject *Sender)
  146. {
  147. Refresh();
  148. TmrShow->Enabled = FTmrShow;
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TWCAM020M::FormActivate(TObject *Sender)
  152. {
  153. ActivateForm(true);
  154. }
  155. //---------------------------------------------------------------------------
  156. void __fastcall TWCAM020M::FormDeactivate(TObject *Sender)
  157. {
  158. ActivateForm(false);
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TWCAM020M::LoadLocalSkin()
  162. {
  163. PnlCamera->ParentColor = false;
  164. PnlCamera->Color = clBlack;
  165. //XNVTViewerCtrl1->Visible = false;
  166. Refresh();
  167. }
  168. //---------------------------------------------------------------------------
  169. void __fastcall TWCAM020M::TmrShowTimer(TObject *Sender)
  170. {
  171. TmrShow->Enabled = false;
  172. FRAMEWCamStateList1->UpdateList();
  173. FRAMEWCamStateList1->CxList->Enabled = false;
  174. UpdatePingList();
  175. FRAMEWCamStateList1->CxList->Enabled = true;
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TWCAM020M::FormClose(TObject *Sender, TCloseAction &Action)
  179. {
  180. try {
  181. CommClose();
  182. WCAM020M = NULL;
  183. Action = caFree;
  184. } catch(...) {}
  185. }
  186. //---------------------------------------------------------------------------
  187. void __fastcall TWCAM020M::OnMainFormMessage(TMessage &Msg)
  188. {
  189. }
  190. //---------------------------------------------------------------------------
  191. void __fastcall TWCAM020M::OnCctvStateRefreshMessage(TMessage &Msg)
  192. {
  193. FRAMEWCamStateList1->RefreshStatus();
  194. RefreshPingList();
  195. }
  196. //---------------------------------------------------------------------------
  197. void __fastcall TWCAM020M::ActivateForm(bool AActivate)
  198. {
  199. if (AActivate) FRAMEWCamStateList1->RefreshStatus();
  200. }
  201. //---------------------------------------------------------------------------
  202. void __fastcall TWCAM020M::DisplayInfo()
  203. {
  204. ClearPreset();
  205. FSelCtlr = NULL;
  206. PnlCctv->Caption = " " + lblSelCctv->Caption + " -";//" Select CCTV: -";
  207. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  208. TcxDataController *pGDC = TvList->DataController;
  209. int nSelIdx = CMM_GetRecordIndex(TvList);
  210. if (nSelIdx < 0) return;
  211. String CTLR_NMBR = VarToStr(pGDC->Values[nSelIdx][FRAMEWCamStateList1->Col01->Index]);
  212. int nMemPtr = (int)pGDC->Values[nSelIdx][FRAMEWCamStateList1->Col99->Index];
  213. FSelCtlr = (TWCamCtlr*)nMemPtr;
  214. if (!FSelCtlr) return;
  215. PnlCctv->Caption = " " + lblSelCctv->Caption + " [" + FSelCtlr->WCAM_CTLR_ID + "] " + FSelCtlr->WCAM_NM;
  216. PnlCamConrtol->Enabled = false;
  217. PnlPreset->Enabled = false;
  218. try
  219. {
  220. if (FSelCtlr->WCAM_TYPE_CD == "WEB")
  221. {
  222. CloseRtsp();
  223. if (OpenWebCamera())
  224. {
  225. InitPreset();
  226. PnlCamConrtol->Enabled = true;
  227. PnlPreset->Enabled = true;
  228. }
  229. }
  230. else
  231. {
  232. CloseWebCamera();
  233. if (XNVTViewerCtrl1->Visible) XNVTViewerCtrl1->Visible = false;
  234. OpenRtsp();
  235. }
  236. }
  237. catch(Exception &e)
  238. {
  239. }
  240. BtnWebCamUrl->Enabled = true;
  241. }
  242. //---------------------------------------------------------------------------
  243. bool __fastcall TWCAM020M::OpenRtsp()
  244. {
  245. if (!FSelCtlr) return false;
  246. try
  247. {
  248. reMsg->Lines->Clear();
  249. CloseRtsp();
  250. FStrmAddr = FSelCtlr->STRM_SESN_NM.Trim();
  251. if (FStrmAddr != "")
  252. {
  253. FFPlayer1->AspectRatio = -1;//ChkFullScreen->Checked ? -1 : 0;
  254. FFPlayer1->TryOpen(FStrmAddr, PnlCamera->Handle);
  255. FStrmPlay = true;
  256. }
  257. }
  258. catch(Exception &e)
  259. {
  260. }
  261. return true;
  262. }
  263. //---------------------------------------------------------------------------
  264. void __fastcall TWCAM020M::CloseRtsp()
  265. {
  266. if (!FStrmPlay) return;
  267. try
  268. {
  269. if (FFPlayer1->ScreenHandle != NULL)
  270. {
  271. FFPlayer1->Stop(true);
  272. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  273. UpdateWindow(FFPlayer1->ScreenHandle);
  274. //FFPlayer1->ScreenHandle = NULL;
  275. }
  276. }
  277. catch(Exception &e)
  278. {
  279. }
  280. FStrmPlay = false;
  281. }
  282. //---------------------------------------------------------------------------
  283. void __fastcall TWCAM020M::BtnAllSelectClick(TObject *Sender)
  284. {
  285. TcxButton *pBtn = (TcxButton*)Sender;
  286. if (PgControl->Properties->ActivePage != TabPing)
  287. CMM_CheckAllListItem(FRAMEWCamStateList1->TvList, FRAMEWCamStateList1->ColumnSel->Index, pBtn->Tag);
  288. else
  289. CMM_CheckAllListItem(TvPing, ColumnSel->Index, pBtn->Tag);
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TWCAM020M::ClearCheckList()
  293. {
  294. #if 0
  295. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  296. TcxDataController *pGDC = TvList->DataController;
  297. try
  298. {
  299. TvList->BeginUpdate();
  300. pGDC->BeginUpdate();
  301. int nRows = pGDC->RecordCount;
  302. for (int ii = 0; ii < nRows; ii++)
  303. {
  304. pGDC->Values[ii][FRAMEWCamStateList1->ColumnSel->Index] = false;
  305. }
  306. }
  307. __finally
  308. {
  309. pGDC->EndUpdate();
  310. TvList->EndUpdate();
  311. }
  312. #endif
  313. }
  314. //---------------------------------------------------------------------------
  315. void __fastcall TWCAM020M::FRAMEWCamStateList1TvListCellDblClick(TcxCustomGridTableView *Sender,
  316. TcxGridTableDataCellViewInfo *ACellViewInfo, TMouseButton AButton,
  317. TShiftState AShift, bool &AHandled)
  318. {
  319. if (!ACellViewInfo) return;
  320. ClearCheckList();
  321. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  322. TcxDataController *pGDC = TvList->DataController;
  323. int nSelIdx = CMM_GetRecordIndex(TvList);
  324. if (nSelIdx < 0) return;
  325. pGDC->Values[nSelIdx][FRAMEWCamStateList1->ColumnSel->Index] = true;
  326. DisplayInfo();
  327. }
  328. //---------------------------------------------------------------------------
  329. int __fastcall TWCAM020M::GetSelListItems(bool ACommCheck/*=true*/)
  330. {
  331. TcxGridBandedTableView *TvList = FRAMEWCamStateList1->TvList;
  332. TcxDataController *pGDC = TvList->DataController;
  333. FSelIds->Clear();
  334. try
  335. {
  336. bool bSelected;
  337. int nRows = TvList->ViewData->RecordCount;
  338. TvList->BeginUpdate();
  339. for (int ii = 0; ii < nRows; ii++)
  340. {
  341. TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
  342. int nMemPtr = (int)ARow->Values[FRAMEWCamStateList1->Col99->Index];
  343. TWCamCtlr *pCctv = (TWCamCtlr*)nMemPtr;
  344. if (!pCctv) continue;
  345. bSelected = (bool)ARow->Values[FRAMEWCamStateList1->ColumnSel->Index];
  346. if (bSelected)
  347. {
  348. String CTLR_NMBR = ARow->Values[FRAMEWCamStateList1->Col01->Index];
  349. if (ACommCheck)
  350. {
  351. if (pCctv->STATE.Comm == wcam_normal)
  352. {
  353. FSelIds->Add(CTLR_NMBR);
  354. }
  355. }
  356. else
  357. {
  358. FSelIds->Add(CTLR_NMBR);
  359. }
  360. }
  361. }
  362. }
  363. __finally
  364. {
  365. TvList->EndUpdate();
  366. }
  367. return FSelIds->Count;
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TWCAM020M::BtnWebCamUrlClick(TObject *Sender)
  371. {
  372. if (FSelCtlr)
  373. {
  374. if (FSelCtlr->WCAM_CTLR_IP.Trim() != "")
  375. {
  376. String sUrl = "http://" + FSelCtlr->WCAM_CTLR_IP.Trim();
  377. ShellExecute(NULL, NULL, sUrl.c_str(), NULL, NULL, 0);
  378. }
  379. }
  380. }
  381. //---------------------------------------------------------------------------
  382. void __fastcall TWCAM020M::PgControlPageChanging(TObject *Sender, TcxTabSheet *NewPage,
  383. bool &AllowChange)
  384. {
  385. if (NewPage == TabPing)
  386. {
  387. BtnAllSelect->Visible = false;
  388. BtnAllClear->Visible = false;
  389. BtnReverse->Visible = false;
  390. }
  391. else
  392. {
  393. #if 0
  394. if (BtnAllSelect->Visible == false) BtnAllSelect->Visible = true;;
  395. if (BtnAllClear->Visible == false) BtnAllClear->Visible = true;;
  396. if (BtnReverse->Visible == false) BtnReverse->Visible = true;;
  397. #endif
  398. }
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TWCAM020M::UpdatePingList()
  402. {
  403. CMM_ClearGridTableView(TvPing);
  404. int ii, jj;
  405. int nCols = 0;
  406. TcxDataController *pGDC = TvPing->DataController;
  407. WCamCtlrManager->FLists.Lock();
  408. try
  409. {
  410. int nRow;
  411. TvPing->BeginUpdate();
  412. pGDC->BeginUpdate();
  413. FOR_STL(TWCamCtlr*, pObj, WCamCtlrManager->FLists)
  414. {
  415. if (pObj->DEL_YN == "Y") continue;
  416. nRow = pGDC->AppendRecord();
  417. if (pObj->STATE.Comm == wcam_normal) pGDC->Values[nRow][ColumnSel->Index] = false;
  418. else pGDC->Values[nRow][ColumnSel->Index] = true;
  419. pGDC->Values[nRow][Col01->Index] = String(pObj->WCAM_CTLR_NMBR);
  420. pGDC->Values[nRow][Col02->Index] = pObj->WCAM_CTLR_ID;
  421. pGDC->Values[nRow][Col03->Index] = pObj->WCAM_NM;
  422. pGDC->Values[nRow][Col04->Index] = pObj->STATE.Comm == wcam_normal ? FrmLang->lblComm0->Caption : FrmLang->lblComm1->Caption;
  423. pGDC->Values[nRow][Col05->Index] = pObj->WCAM_CTLR_IP;
  424. pGDC->Values[nRow][Col06->Index] = "-";
  425. pGDC->Values[nRow][Col07->Index] = "-";
  426. pGDC->Values[nRow][Col08->Index] = "-";
  427. pGDC->Values[nRow][Col09->Index] = pObj->WCAM_CTLR_IP;
  428. pGDC->Values[nRow][Col10->Index] = "-";
  429. pGDC->Values[nRow][Col11->Index] = "-";
  430. pGDC->Values[nRow][Col12->Index] = "-";
  431. pGDC->Values[nRow][Col99->Index] = (int)pObj;
  432. }
  433. }
  434. __finally
  435. {
  436. WCamCtlrManager->FLists.UnLock();
  437. pGDC->EndUpdate();
  438. TvPing->EndUpdate();
  439. }
  440. }
  441. //---------------------------------------------------------------------------
  442. void __fastcall TWCAM020M::RefreshPingList(bool AInit/*=false*/)
  443. {
  444. TcxDataController *pGDC = TvPing->DataController;
  445. try
  446. {
  447. TvPing->BeginUpdate();
  448. pGDC->BeginUpdate();
  449. int nRows = pGDC->RecordCount;
  450. for(int nRow = 0; nRow < nRows; nRow++)
  451. {
  452. int nMemPtr = TvPing->DataController->Values[nRow][Col99->Index];
  453. TWCamCtlr *pObj = (TWCamCtlr*)nMemPtr;
  454. if (!pObj) continue;
  455. if (AInit == false && PgControl->Properties->ActivePage != TabPing)
  456. {
  457. if (pObj->STATE.Comm == cctv_normal) pGDC->Values[nRow][ColumnSel->Index] = false;
  458. else pGDC->Values[nRow][ColumnSel->Index] = true;
  459. }
  460. if (AInit)
  461. {
  462. pGDC->Values[nRow][Col06->Index] = "-";
  463. pGDC->Values[nRow][Col07->Index] = "-";
  464. pGDC->Values[nRow][Col08->Index] = "-";
  465. pGDC->Values[nRow][Col10->Index] = "-";
  466. pGDC->Values[nRow][Col11->Index] = "-";
  467. pGDC->Values[nRow][Col12->Index] = "-";
  468. }
  469. pGDC->Values[nRow][Col04->Index] = pObj->STATE.Comm == wcam_normal ? FrmLang->lblComm0->Caption : FrmLang->lblComm1->Caption;
  470. }
  471. }
  472. __finally
  473. {
  474. pGDC->EndUpdate();
  475. TvPing->EndUpdate();
  476. }
  477. }
  478. //---------------------------------------------------------------------------
  479. void __fastcall TWCAM020M::PingNetwork(String AIp, int APort)
  480. {
  481. try
  482. {
  483. IdIcmpClient1->Host = AIp;
  484. IdIcmpClient1->Port = EdPingPort->Value/*512*/;
  485. IdIcmpClient1->ReceiveTimeout = EdPingTimeout->Value;
  486. IdIcmpClient1->Ping(IdIcmpClient1->Host, IdIcmpClient1->Port);
  487. }
  488. catch (Exception &e)
  489. {
  490. Application->ShowException(&e);
  491. }
  492. catch(...)
  493. {
  494. ShowMessage("Ping error[Unknown]");
  495. }
  496. }
  497. //---------------------------------------------------------------------------
  498. void __fastcall TWCAM020M::BtnNwkPingClick(TObject *Sender)
  499. {
  500. TWaitCursor waitCrs;
  501. TcxDataController *pGDC = TvPing->DataController;
  502. int nRows = pGDC->RecordCount;
  503. String sMsg;
  504. int nSelCnt = CMM_GetCheckCount(TvPing, ColumnSel->Index);
  505. if (0 == nSelCnt)
  506. {
  507. sMsg = cxLabel14->Caption;
  508. Application->MessageBox(sMsg.c_str(), L"Web Camera Network Ping Test", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  509. CxPing->SetFocus();
  510. return;
  511. }
  512. RefreshPingList(true);
  513. PnlPing->Enabled = false;
  514. String sSvrIp;
  515. int nSvrPort;
  516. bool bPing;
  517. for (int ii = 0; ii < nRows; ii++)
  518. {
  519. bPing = pGDC->Values[ii][ColumnSel->Index];
  520. if (!bPing) continue;
  521. //pGDC->Values[ii][ColPingMon->Index] = Now().FormatString("yyyy-mm-dd hh:mm:ss");
  522. FPingType = 1;
  523. sSvrIp = pGDC->Values[ii][Col05->Index];
  524. if (sSvrIp == NULL || sSvrIp.IsEmpty())
  525. {
  526. continue;
  527. }
  528. pGDC->Values[ii][Col06->Index] = "?";
  529. pGDC->Values[ii][Col07->Index] = "?";
  530. pGDC->Values[ii][Col08->Index] = "?";
  531. nSvrPort = 0;
  532. FPingTimeout = false;
  533. PingNetwork(sSvrIp.Trim(), nSvrPort);
  534. if (FPingTimeout)
  535. {
  536. pGDC->Values[ii][Col08->Index] = "Time out";
  537. }
  538. Application->ProcessMessages();
  539. FPingType = 2;
  540. sSvrIp = pGDC->Values[ii][Col09->Index];
  541. if (sSvrIp == NULL || sSvrIp.IsEmpty())
  542. {
  543. continue;
  544. }
  545. pGDC->Values[ii][Col10->Index] = "?";
  546. pGDC->Values[ii][Col11->Index] = "?";
  547. pGDC->Values[ii][Col12->Index] = "?";
  548. nSvrPort = 0;
  549. FPingTimeout = false;
  550. PingNetwork(sSvrIp.Trim(), nSvrPort);
  551. if (FPingTimeout)
  552. {
  553. pGDC->Values[ii][Col12->Index] = "Time out";
  554. }
  555. Application->ProcessMessages();
  556. }
  557. PnlPing->Enabled = true;
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TWCAM020M::BtnNwkPingClearClick(TObject *Sender)
  561. {
  562. RefreshPingList(true);
  563. }
  564. //---------------------------------------------------------------------------
  565. void __fastcall TWCAM020M::Col04CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  566. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  567. {
  568. try
  569. {
  570. TColor tColor;
  571. String sStatus = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  572. tColor = ACanvas->Brush->Color;
  573. if (sStatus.Pos("-")) tColor = clGray;
  574. else if (sStatus.Pos(FrmLang->lblComm1->Caption.Trim())) tColor = clRed;
  575. else tColor = clLime;
  576. ACanvas->SetBrushColor(tColor);
  577. ACanvas->Font->Color = clBlack;
  578. }
  579. catch(Exception &e)
  580. {
  581. }
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TWCAM020M::IdIcmpClient1Reply(TComponent *ASender, const TReplyStatus *AReplyStatus)
  585. {
  586. try
  587. {
  588. String sRcvIp = AReplyStatus->FromIpAddress;
  589. int nRcvPort= IdIcmpClient1->Port;
  590. if (rsTimeOut == AReplyStatus->ReplyStatusType || sRcvIp == "0.0.0.0")
  591. {
  592. FPingTimeout = true;
  593. return;
  594. }
  595. TcxDataController *pGDC = TvPing->DataController;
  596. int nRows = pGDC->RecordCount;
  597. String sSvrIp;
  598. for (int ii = 0; ii < nRows; ii++)
  599. {
  600. if (FPingType == 1)
  601. sSvrIp = pGDC->Values[ii][Col05->Index];
  602. else
  603. sSvrIp = pGDC->Values[ii][Col09->Index];
  604. int nSvrPort = 0;
  605. if (sSvrIp.Trim() == sRcvIp && nRcvPort == nSvrPort)
  606. {
  607. if (FPingType == 1)
  608. {
  609. if (AReplyStatus->MsRoundTripTime > 100)
  610. {
  611. pGDC->Values[ii][Col08->Index] = "Delayed";
  612. }
  613. else
  614. {
  615. pGDC->Values[ii][Col08->Index] = "Normal";
  616. }
  617. pGDC->Values[ii][Col06->Index] = String(AReplyStatus->MsRoundTripTime) + " ";
  618. pGDC->Values[ii][Col07->Index] = String(AReplyStatus->TimeToLive) + " ";
  619. }
  620. else
  621. {
  622. if (AReplyStatus->MsRoundTripTime > 100)
  623. {
  624. pGDC->Values[ii][Col12->Index] = "Delayed";
  625. }
  626. else
  627. {
  628. pGDC->Values[ii][Col12->Index] = "Normal";
  629. }
  630. pGDC->Values[ii][Col10->Index] = String(AReplyStatus->MsRoundTripTime) + " ";
  631. pGDC->Values[ii][Col11->Index] = String(AReplyStatus->TimeToLive) + " ";
  632. }
  633. break;
  634. }
  635. }
  636. }
  637. catch(Exception &e)
  638. {
  639. }
  640. }
  641. //---------------------------------------------------------------------------
  642. void __fastcall TWCAM020M::Col08CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  643. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  644. {
  645. try
  646. {
  647. int iIndex = AViewInfo->Item->Index;
  648. ACanvas->Canvas->Brush->Style = bsSolid;
  649. String val = AViewInfo->GridRecord->DisplayTexts[iIndex];
  650. ACanvas->Canvas->Font->Color = clBlack;
  651. if (val == "Normal") ACanvas->Canvas->Brush->Color = clLime;
  652. else if (val == "Delayed") ACanvas->Canvas->Brush->Color = clRed;
  653. else if (val == "Time out") ACanvas->Canvas->Brush->Color = clRed;
  654. else ACanvas->Canvas->Brush->Color = clSilver;
  655. } catch(...) {}
  656. }
  657. //---------------------------------------------------------------------------
  658. void __fastcall TWCAM020M::TvPingCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
  659. TMouseButton AButton, TShiftState AShift,
  660. bool &AHandled)
  661. {
  662. if (!ACellViewInfo) return;
  663. TcxGridDataController *pGDC = TvPing->DataController;
  664. int nRow = pGDC->FocusedRecordIndex;
  665. if( nRow <= -1 )
  666. return;
  667. if (ACellViewInfo->Item->Index == Col05->Index ||
  668. ACellViewInfo->Item->Index == Col09->Index)
  669. {
  670. String sSvrIp = pGDC->Values[nRow][ACellViewInfo->Item->Index];
  671. ITSUtil_NetworkPing(sSvrIp);
  672. }
  673. }
  674. //---------------------------------------------------------------------------
  675. bool __fastcall TWCAM020M::OpenWebCamera()
  676. {
  677. if (!FSelCtlr) return false;
  678. try
  679. {
  680. reMsg->Lines->Clear();
  681. CloseWebCamera();
  682. if (!XNVTViewerCtrl1->Visible) XNVTViewerCtrl1->Visible = true;
  683. XNVTViewerCtrl1->IPAddress = FSelCtlr->WCAM_CTLR_IP;
  684. XNVTViewerCtrl1->Port = FSelCtlr->CMRA_PORT;
  685. XNVTViewerCtrl1->ID = FSelCtlr->CMRA_ID;
  686. XNVTViewerCtrl1->Password = FSelCtlr->CMRA_PSWD;
  687. XNVTViewerCtrl1->Channel = FSelCtlr->CMRA_CHNL;
  688. XNVTViewerCtrl1->EnableBackChannelAudio = false;
  689. if (XNVTViewerCtrl1->Preview())
  690. {
  691. BtnSaveImgFile->Enabled = true;
  692. return true;
  693. }
  694. BtnSaveImgFile->Enabled = false;
  695. }
  696. catch(...)
  697. {
  698. }
  699. return false;
  700. }
  701. //---------------------------------------------------------------------------
  702. void __fastcall TWCAM020M::CloseWebCamera()
  703. {
  704. try
  705. {
  706. XNVTViewerCtrl1->Stop();
  707. }
  708. catch(...)
  709. {
  710. }
  711. }
  712. //---------------------------------------------------------------------------
  713. void __fastcall TWCAM020M::BtnZoomInOutMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  714. {
  715. try
  716. {
  717. TImageBtn *pBtn = (TImageBtn*)Sender;
  718. if (pBtn->Tag == 0)
  719. {
  720. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_ZOOM_IN, 3);
  721. }
  722. else
  723. {
  724. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_ZOOM_OUT, 3);
  725. }
  726. }
  727. catch(...) {}
  728. }
  729. //---------------------------------------------------------------------------
  730. void __fastcall TWCAM020M::BtnZoomInOutMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  731. {
  732. try
  733. {
  734. TImageBtn *pBtn = (TImageBtn*)Sender;
  735. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, 0x000000, 3);
  736. }
  737. catch(...) {}
  738. }
  739. //---------------------------------------------------------------------------
  740. void __fastcall TWCAM020M::BtnFocusInOutMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  741. {
  742. try
  743. {
  744. TImageBtn *pBtn = (TImageBtn*)Sender;
  745. if (pBtn->Tag == 0)
  746. {
  747. XNVTViewerCtrl1->PutCamCtl(CTL_FOCUS_CONT, SB_FOCUS_IN, 1);
  748. }
  749. else
  750. {
  751. XNVTViewerCtrl1->PutCamCtl(CTL_FOCUS_CONT, SB_FOCUS_OUT, 1);
  752. }
  753. }
  754. catch(...) {}
  755. }
  756. //---------------------------------------------------------------------------
  757. void __fastcall TWCAM020M::BtnFocusInOutMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  758. {
  759. try
  760. {
  761. TImageBtn *pBtn = (TImageBtn*)Sender;
  762. XNVTViewerCtrl1->PutCamCtl(CTL_FOCUS_CONT, 0x000000, 3);
  763. }
  764. catch(...) {}
  765. }
  766. //---------------------------------------------------------------------------
  767. void __fastcall TWCAM020M::BtnPanTileMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  768. {
  769. try
  770. {
  771. TImageBtn *pBtn = (TImageBtn*)Sender;
  772. switch(pBtn->Tag)
  773. {
  774. case 0: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_TILT_UP, 3); break; // Up
  775. case 1: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_TILT_DOWN, 3); break; // Down
  776. case 2: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_PAN_LEFT, 3); break; // Left
  777. case 3: XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, SB_PAN_RIGHT, 3); break; // Right
  778. }
  779. }
  780. catch(...) {}
  781. }
  782. //---------------------------------------------------------------------------
  783. void __fastcall TWCAM020M::BtnPanTileMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  784. {
  785. // Zoom In/Out MouseUp Event 와 동일
  786. try
  787. {
  788. TImageBtn *pBtn = (TImageBtn*)Sender;
  789. XNVTViewerCtrl1->PutCamCtl(CTL_PTZ_CONT, 0x000000, 3);
  790. }
  791. catch(...) {}
  792. }
  793. //---------------------------------------------------------------------------
  794. void __fastcall TWCAM020M::BtnSaveImgFileClick(TObject *Sender)
  795. {
  796. String sSaveFileName;
  797. if (!FSelCtlr || XNVTViewerCtrl1->OCXState == GRAPH_NONE)
  798. {
  799. String sMsg = cxLabel1->Caption;
  800. Application->MessageBox(sMsg.c_str(), L"Save Snap Shot", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  801. return;
  802. }
  803. sSaveFileName.printf(L"%s\\%d_%s.bmp", g_sTempDir.c_str(), FSelCtlr->WCAM_CTLR_NMBR, Now().FormatString("yyyymmddhhnnss").c_str());
  804. if (XNVTViewerCtrl1->FileSnapShot(sSaveFileName.c_str()))
  805. {
  806. Application->MessageBox(sSaveFileName.c_str(), L"Save Snap Shot Success", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  807. }
  808. else
  809. {
  810. Application->MessageBox(cxLabel2->Caption.c_str(), L"Save Snap Shot Fail", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  811. }
  812. }
  813. //---------------------------------------------------------------------------
  814. void __fastcall TWCAM020M::ClearPreset()
  815. {
  816. CMM_ClearGridTableView(TvPreset);
  817. SePresetNo->Value = 1;
  818. EdPresetName->Text = "";
  819. ChkCctvPresetDef->Checked = false;
  820. //PnlPreset->Enabled = false;
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TWCAM020M::InitPreset()
  824. {
  825. if (!FSelCtlr) return;
  826. ClearPreset();
  827. TcxDataController* pGDC = TvPreset->DataController;
  828. TvPreset->BeginUpdate();
  829. try
  830. {
  831. FSelCtlr->FLists.Lock();
  832. try
  833. {
  834. FOR_STL(TWCamPset*, pObj, FSelCtlr->FLists)
  835. {
  836. if (pObj->DEL_YN == "Y") continue;
  837. int nRow = pGDC->AppendRecord();
  838. pGDC->Values[nRow][ColPresetNo->Index] = String(pObj->PSET_NMBR);
  839. pGDC->Values[nRow][ColPresetName->Index] = pObj->PSET_NM;
  840. pGDC->Values[nRow][ColPresetPan->Index] = String(pObj->PAN);
  841. pGDC->Values[nRow][ColPresetTilt->Index] = String(pObj->TILT);
  842. pGDC->Values[nRow][ColPresetZoom->Index] = String(pObj->ZOOM);
  843. pGDC->Values[nRow][ColPresetFocus->Index] = String(pObj->FOCS);
  844. pGDC->Values[nRow][ColPresetAngle->Index] = "";
  845. pGDC->Values[nRow][ColPresetDefault->Index] = pObj->DFLT_YN;
  846. }
  847. }
  848. __finally
  849. {
  850. FSelCtlr->FLists.UnLock();
  851. }
  852. }
  853. __finally
  854. {
  855. TvPreset->EndUpdate();
  856. PnlPreset->Enabled = true;
  857. BtnCctvPresetDel->Enabled = false;
  858. }
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TWCAM020M::BtnCctvPresetClick(TObject *Sender)
  862. {
  863. //프리셋 이동
  864. if (FSelCtlr)
  865. {
  866. int nPresetNo = SePresetNo->Value;
  867. if (XNVTViewerCtrl1->PutCamCtl(PRESET_MOVE, nPresetNo, 1))
  868. {
  869. }
  870. }
  871. }
  872. //---------------------------------------------------------------------------
  873. void __fastcall TWCAM020M::BtnCctvPresetSetClick(TObject *Sender)
  874. {
  875. //프리셋 설정
  876. if (FSelCtlr)
  877. {
  878. int nPresetNo = SePresetNo->Value;
  879. String sPresetNm = EdPresetName->Text.Trim();
  880. String sDefault = ChkCctvPresetDef->Checked ? "Y" : "N";
  881. if (sPresetNm == "")
  882. {
  883. String sMsg;
  884. sMsg = cxLabel3->Caption;//"프리셋 명을 입력하세요..";
  885. Application->MessageBox(sMsg.c_str(), cxLabel4->Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  886. EdPresetName->SetFocus();
  887. }
  888. if (XNVTViewerCtrl1->PutCamCtl(PRESET_SET, nPresetNo, 1))
  889. {
  890. TWCamPset *pSet = FSelCtlr->FLists.Find(nPresetNo);
  891. if (!pSet)
  892. {
  893. pSet = new TWCamPset();
  894. pSet->WCAM_CTLR_NMBR = FSelCtlr->WCAM_CTLR_NMBR;
  895. pSet->PSET_NMBR = nPresetNo;
  896. FSelCtlr->FLists.Push(pSet->PSET_NMBR, pSet);
  897. }
  898. pSet->PSET_NM = sPresetNm;
  899. pSet->DFLT_YN = sDefault;
  900. pSet->DEL_YN = "N";
  901. WCamCtlrManager->SavePreSet(FSelCtlr);
  902. InitPreset();
  903. SePresetNo->Value = nPresetNo;
  904. EdPresetName->Text = sPresetNm;
  905. ChkCctvPresetDef->Checked = sDefault == "Y" ? true : false;
  906. BtnCctvPresetDel->Enabled = true;
  907. }
  908. }
  909. }
  910. //---------------------------------------------------------------------------
  911. void __fastcall TWCAM020M::BtnCctvPresetDelClick(TObject *Sender)
  912. {
  913. //프리셋 삭제
  914. if (FSelCtlr)
  915. {
  916. int nPresetNo = SePresetNo->Value;
  917. if (XNVTViewerCtrl1->PutCamCtl(PRESET_CLEAR, nPresetNo, 1))
  918. {
  919. TWCamPset *pSet = FSelCtlr->FLists.Find(nPresetNo);
  920. if (!pSet)
  921. {
  922. return;
  923. }
  924. pSet->PSET_NM = "";
  925. pSet->DEL_YN = "Y";
  926. WCamCtlrManager->SavePreSet(FSelCtlr);
  927. InitPreset();
  928. }
  929. }
  930. }
  931. //---------------------------------------------------------------------------
  932. void __fastcall TWCAM020M::TvPresetCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
  933. TMouseButton AButton, TShiftState AShift, bool &AHandled)
  934. {
  935. if (!ACellViewInfo) return;
  936. int nRow = TvPreset->DataController->FocusedRecordIndex;
  937. if( nRow <= -1 )
  938. return;
  939. String sPresetNo = TvPreset->DataController->Values[nRow][ColPresetNo->Index];
  940. String sPresetNm = TvPreset->DataController->Values[nRow][ColPresetName->Index];
  941. String sDefault = TvPreset->DataController->Values[nRow][ColPresetDefault->Index];
  942. ChkCctvPresetDef->Checked = sDefault == "Y" ? true : false;
  943. SePresetNo->Value = sPresetNo.ToIntDef(1);
  944. EdPresetName->Text = sPresetNm;
  945. BtnCctvPresetDel->Enabled = true;
  946. }
  947. //---------------------------------------------------------------------------
  948. void __fastcall TWCAM020M::SePresetNoPropertiesEditValueChanged(TObject *Sender)
  949. {
  950. if (FSelCtlr)
  951. {
  952. int nPresetNo = SePresetNo->Value;
  953. TWCamPset* pSet = FSelCtlr->FLists.Find(nPresetNo);
  954. if (pSet) BtnCctvPresetDel->Enabled = true;
  955. else BtnCctvPresetDel->Enabled = false;
  956. }
  957. }
  958. //---------------------------------------------------------------------------
  959. void __fastcall TWCAM020M::reMsgDblClick(TObject *Sender)
  960. {
  961. reMsg->Lines->Clear();
  962. }
  963. //---------------------------------------------------------------------------
  964. void __fastcall TWCAM020M::XNVTViewerCtrl1EventNotify(TObject *Sender, BSTR message, long message_size)
  965. {
  966. reMsg->Lines->Add(message);
  967. }
  968. //---------------------------------------------------------------------------
  969. void __fastcall TWCAM020M::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  970. {
  971. switch(APlayState)
  972. {
  973. case Ffbasecomponent::psPlay: reMsg->Lines->Add("Play..."); break;
  974. case Ffbasecomponent::psResume: reMsg->Lines->Add("Resume."); break;
  975. case Ffbasecomponent::psPause: reMsg->Lines->Add("Pause.."); break;
  976. case Ffbasecomponent::psStep: reMsg->Lines->Add("Step..."); break;
  977. case Ffbasecomponent::psStop:
  978. if (FFPlayer1->ScreenHandle != NULL)
  979. {
  980. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  981. UpdateWindow(FFPlayer1->ScreenHandle);
  982. //FFPlayer1->ScreenHandle = NULL;
  983. }
  984. reMsg->Lines->Add("Stop...");
  985. break;
  986. case Ffbasecomponent::psEnd:
  987. {
  988. FFPlayer1->Stop(true);
  989. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  990. UpdateWindow(FFPlayer1->ScreenHandle);
  991. //FFPlayer1->ScreenHandle = NULL;
  992. FStrmPlay = false;
  993. }
  994. reMsg->Lines->Add("End...");
  995. break;
  996. }
  997. }
  998. //---------------------------------------------------------------------------