FrmStreamPlayerF.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSLangTransF.h"
  5. #pragma hdrstop
  6. #include "FrmFullScreenF.h"
  7. #include "FrmStreamPlayerF.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "FFBaseComponent"
  11. #pragma link "FFBasePlay"
  12. #pragma link "FFPlay"
  13. #pragma link "cxContainer"
  14. #pragma link "cxControls"
  15. #pragma link "cxEdit"
  16. #pragma link "cxGraphics"
  17. #pragma link "cxLabel"
  18. #pragma link "cxLookAndFeelPainters"
  19. #pragma link "cxLookAndFeels"
  20. #pragma link "dxSkinBlack"
  21. #pragma link "dxSkinBlue"
  22. #pragma link "dxSkinsCore"
  23. #pragma link "dxSkinMcSkin"
  24. #pragma link "AcesTechXPlayer2Lib_OCX"
  25. #pragma resource "*.dfm"
  26. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  27. #define FFPLAY 0
  28. #define ACES 1
  29. //TFrmStreamPlayer *FrmStreamPlayer;
  30. //---------------------------------------------------------------------------
  31. __fastcall TFrmStreamPlayer::TFrmStreamPlayer(TComponent* Owner)
  32. : TForm(Owner)
  33. {
  34. LangTrans->Translate(this, ITSDb_GetConnection());
  35. FObj.Installed = false;
  36. FObj.Data = NULL;
  37. PnlBlob->Visible = false;
  38. PnlBlob->Align = alClient;
  39. FDispBlob = false;
  40. FPlay = false;
  41. FAutoPlay = true;
  42. FConHandle = 0;
  43. FFullScreen = false;
  44. InitCamera(NULL, FAutoPlay);
  45. FParent = this->Parent;
  46. PnlStream->Tag = (int)this;
  47. #if FFPLAY
  48. AcesTechXPlayer21->Visible = false;
  49. #endif
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TFrmStreamPlayer::TmrShowTimer(TObject *Sender)
  53. {
  54. TmrShow->Enabled = false;
  55. if (FObj.Installed)
  56. {
  57. Caption = FObj.ID + ": " + FObj.NAME;
  58. if (FDispBlob == false)
  59. {
  60. Connect();
  61. }
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TFrmStreamPlayer::FormShow(TObject *Sender)
  66. {
  67. if (FObj.Installed) PnlStream->Caption = FObj.NAME;
  68. else PnlStream->Caption = "";
  69. Refresh();
  70. this->FLastBounds = this->BoundsRect;
  71. RefreshPlayer();
  72. if (PnlStream->Visible)
  73. {
  74. #if FFPLAY
  75. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  76. FFPlayer1->DisableFPUExceptions();
  77. if (!FFPlayer1->AVLibLoaded())
  78. {
  79. String sAVILibDir = g_sAppDir + "LibAV";
  80. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  81. {
  82. Application->MessageBox(lblErr1->Caption.c_str(),//L"영상표출 라이브러리를 로드하지 못하였습니다.",
  83. lblErr2->Caption.c_str(),//L"영상표출 오류",
  84. MB_OK|MB_ICONERROR|MB_APPLMODAL);
  85. return;
  86. }
  87. }
  88. #endif
  89. }
  90. TmrShow->Enabled = true;
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TFrmStreamPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  94. {
  95. try {
  96. Disconnect();
  97. if (FObj.Data) {
  98. FObj.Data->FData1 = NULL;
  99. FObj.Data->FData3 = NULL;
  100. }
  101. } catch(...) {}
  102. Action = caFree;
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TFrmStreamPlayer::FormDestroy(TObject *Sender)
  106. {
  107. try {
  108. Disconnect();
  109. if (FObj.Data) {
  110. FObj.Data->FData1 = NULL;
  111. FObj.Data->FData3 = NULL;
  112. }
  113. } catch(...) {}
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TFrmStreamPlayer::RefreshPlayer()
  117. {
  118. FDispBlob = false;
  119. PnlBlob->Visible = false;
  120. if (FObj.Installed == false) return;
  121. String sQry;
  122. //CCTV영상인 경우 대체영상 표출 여부 확인
  123. if (FObj.FCLT_TYPE == "CCTV")
  124. {
  125. sQry = "SELECT CCTV_SBST_DSPL_YN, CCTV_SBST_IMGN \r\n"
  126. " FROM TB_CCTV_CTLR \r\n"
  127. " WHERE CCTV_CTLR_ID = :p01 \r\n";
  128. }
  129. else
  130. {
  131. FDispBlob = false;
  132. PnlBlob->Visible = false;
  133. PnlStream->Visible = true;
  134. return;
  135. }
  136. try
  137. {
  138. pADO->Close();
  139. pADO->SQL->Clear();
  140. pADO->Connection = ITSDb_GetConnection();
  141. pADO->SQL->Text = sQry;
  142. pADO->Parameters->ParamByName("p01")->Value = FObj.ID;
  143. pADO->Prepared = true;
  144. pADO->Open();
  145. }
  146. catch(EDatabaseError &E)
  147. {
  148. PnlBlob->Caption = lblErr3->Caption;//"대체영상 이미지 정보 읽기 실패";
  149. ShowMessage(String(E.ClassName()) + E.Message);
  150. return;
  151. }
  152. if (pADO->RecordCount == 0)
  153. {
  154. pADO->Close();
  155. return;
  156. }
  157. ForceDirectories(g_sTempDir);
  158. TADOBlobStream *BS;
  159. int nFileSize = 0;
  160. String sImgFile = g_sTempDir + "CCTVB_" + FObj.ID + ".bmp";
  161. try {
  162. DeleteFile(sImgFile);
  163. } catch(...) {}
  164. String sDispBlob = "N";
  165. try
  166. {
  167. sDispBlob = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString;
  168. if (sDispBlob == "Y")
  169. {
  170. BS = (TADOBlobStream *)pADO->CreateBlobStream(pADO->FieldByName("CCTV_SBST_IMGN"), bmRead);
  171. //ImgBlob->Picture->Graphic->LoadFromStream(BS);
  172. BS->SaveToFile(sImgFile);
  173. nFileSize = BS->Size;
  174. delete BS;
  175. }
  176. pADO->Close();
  177. }
  178. catch(Exception &e)
  179. {
  180. delete BS;
  181. PnlBlob->Caption = lblErr4->Caption;//"대체영상 이미지 스트림 로딩 실패";
  182. return;
  183. }
  184. if (sDispBlob == "Y")
  185. {
  186. FDispBlob = true;
  187. PnlBlob->Visible = true;
  188. PnlStream->Visible = false;
  189. if (nFileSize)
  190. {
  191. try
  192. {
  193. ImgBlob->Picture->LoadFromFile(sImgFile);
  194. return;
  195. }
  196. catch(...)
  197. {
  198. ImgBlob->Visible = false;
  199. PnlBlob->Caption = lblErr5->Caption;//"대체영상 이미지 파일 로딩 실패";
  200. return;
  201. }
  202. }
  203. else
  204. {
  205. ImgBlob->Visible = false;
  206. PnlBlob->Caption = lblErr6->Caption;//"대체영상 이미지 사이즈 오류";
  207. }
  208. }
  209. else
  210. {
  211. FDispBlob = false;
  212. PnlBlob->Visible = false;
  213. PnlStream->Visible = true;
  214. }
  215. }
  216. //---------------------------------------------------------------------------
  217. void __fastcall TFrmStreamPlayer::MnuConnectClick(TObject *Sender)
  218. {
  219. FAutoPlay = true;
  220. Connect();
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TFrmStreamPlayer::MnuDisconnectClick(TObject *Sender)
  224. {
  225. FAutoPlay = false;
  226. Disconnect();
  227. }
  228. //---------------------------------------------------------------------------
  229. void __fastcall TFrmStreamPlayer::Connect()
  230. {
  231. Disconnect();
  232. PnlStream->Caption = FObj.STRM_ADDR;//"Connecting...";
  233. try
  234. {
  235. #if FFPLAY
  236. FFPlayer1->AspectRatio = -1;
  237. FFPlayer1->TryOpen(FObj.STRM_ADDR, PnlStream->Handle);
  238. FConHandle = (long)FFPlayer1->ScreenHandle;
  239. #endif
  240. #if ACES
  241. AcesTechXPlayer21->URL = FObj.STRM_ADDR;
  242. FConHandle = AcesTechXPlayer21->ConnectAsync();
  243. if (FConHandle > 0)
  244. {
  245. }
  246. #endif
  247. Application->ProcessMessages();
  248. }
  249. catch(Exception &e)
  250. {
  251. }
  252. FPlay = true;
  253. }
  254. //---------------------------------------------------------------------------
  255. void __fastcall TFrmStreamPlayer::Disconnect()
  256. {
  257. if (!FPlay) return;
  258. FPlay = false;
  259. PnlStream->Caption = "Disconnect";
  260. try
  261. {
  262. #if FFPLAY
  263. if (FFPlayer1->ScreenHandle != NULL)
  264. {
  265. FFPlayer1->Stop(true);
  266. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  267. UpdateWindow(FFPlayer1->ScreenHandle);
  268. FFPlayer1->ScreenHandle = NULL;
  269. }
  270. #endif
  271. #if ACES
  272. if (FConHandle > 0)
  273. {
  274. AcesTechXPlayer21->Close();
  275. }
  276. #endif
  277. Application->ProcessMessages();
  278. FConHandle = 0;
  279. }
  280. catch(Exception &e)
  281. {
  282. }
  283. PnlStream->Caption = "Disconnected";
  284. FConHandle = 0;
  285. FPlay = false;
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TFrmStreamPlayer::InitCamera(void *ACctv, bool AAutoPlay/*=true*/)
  289. {
  290. FAutoPlay = AAutoPlay;
  291. }
  292. //---------------------------------------------------------------------------
  293. void __fastcall TFrmStreamPlayer::MaxOrNormalForm(TForm *AForm, bool AMax)
  294. {
  295. if (AMax)
  296. {
  297. //this->FParent = this->Parent;
  298. //AForm->Parent = FrmMain; //Application->MainForm;
  299. this->FLastBounds = AForm->BoundsRect;
  300. AForm->BorderStyle = bsNone;
  301. AForm->FormStyle = fsStayOnTop;
  302. AForm->BoundsRect = AForm->Monitor->BoundsRect;
  303. PnlStream->Align = alClient;
  304. #if 0
  305. ShowMessage(String(AForm->BoundsRect.Left) + ", " +
  306. String(AForm->BoundsRect.Top) + ": " +
  307. String(AForm->BoundsRect.Width()) + ", " +
  308. String(AForm->BoundsRect.Height()) );
  309. #endif
  310. }
  311. else
  312. {
  313. //AForm->Parent = this->FParent;
  314. AForm->FormStyle = fsNormal;
  315. AForm->BorderStyle = bsToolWindow;
  316. AForm->BoundsRect = this->FLastBounds;
  317. PnlStream->Align = alClient;
  318. }
  319. }
  320. //---------------------------------------------------------------------------
  321. void __fastcall TFrmStreamPlayer::PnlStreamDblClick(TObject *Sender)
  322. {
  323. #if 0
  324. if (FFullScreen == false)
  325. {
  326. MaxOrNormalForm(this, true);
  327. FFullScreen = true;
  328. }
  329. else
  330. {
  331. MaxOrNormalForm(this, false);
  332. FFullScreen = false;
  333. }
  334. #else
  335. #if FFPLAY
  336. // 여기서 더블클릭은 최대화면을 호출하는 것임
  337. TFrmFullScreen *pFrmFullScreen = new TFrmFullScreen(this);
  338. pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
  339. pFrmFullScreen->PnlStream->Align = alNone;
  340. pFrmFullScreen->PnlStream->Align = alClient;
  341. if (FObj.FULL_STRM_ADDR != "")
  342. {
  343. pFrmFullScreen->STRM_ADDR = FObj.FULL_STRM_ADDR;
  344. }
  345. else
  346. {
  347. pFrmFullScreen->STRM_ADDR = FObj.STRM_ADDR;
  348. }
  349. pFrmFullScreen->ShowModal();
  350. PnlStream->Parent = this;
  351. PnlStream->Tag = (int)this;
  352. delete pFrmFullScreen;
  353. pFrmFullScreen = NULL;
  354. #endif
  355. #endif
  356. #if 0
  357. TForm *pForm = (TForm*)PnlStream->Tag;
  358. if (pForm == this)
  359. {
  360. TFrmFullScreen *pFrmFullScreen = new TFrmFullScreen(this);
  361. pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
  362. pFrmFullScreen->PnlStream->Align = alNone;
  363. pFrmFullScreen->PnlStream->Align = alClient;
  364. pFrmFullScreen->STREAM_ADDR = FObj.STREAM_ADDR;
  365. PnlStream->Parent = pFrmFullScreen->PnlStream;
  366. PnlStream->Tag = (int)pFrmFullScreen;
  367. PnlStream->Align = alClient;
  368. pFrmFullScreen->ShowModal();
  369. FFPlayer1->ScreenHandle = PnlStream->Handle;
  370. PnlStream->Parent = this;
  371. PnlStream->Tag = (int)this;
  372. delete pFrmFullScreen;
  373. pFrmFullScreen = NULL;
  374. }
  375. else
  376. {
  377. PnlStream->Parent = this;
  378. PnlStream->Tag = (int)this;
  379. TFrmFullScreen *pFullForm = (TFrmFullScreen*)pForm;
  380. pFullForm->TmrClose->Enabled = true;
  381. }
  382. #endif
  383. }
  384. //---------------------------------------------------------------------------
  385. void __fastcall TFrmStreamPlayer::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  386. {
  387. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  388. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  389. {
  390. if (FPlay)
  391. {
  392. Caption = Caption + " : Disconnected";
  393. TmrShow->Enabled = true;
  394. }
  395. }
  396. }
  397. //---------------------------------------------------------------------------