FrmStreamPlayerF.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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) FObj.Data->FData1 = NULL;
  98. } catch(...) {}
  99. Action = caFree;
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TFrmStreamPlayer::FormDestroy(TObject *Sender)
  103. {
  104. try {
  105. Disconnect();
  106. if (FObj.Data) FObj.Data->FData1 = NULL;
  107. } catch(...) {}
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TFrmStreamPlayer::RefreshPlayer()
  111. {
  112. FDispBlob = false;
  113. PnlBlob->Visible = false;
  114. if (FObj.Installed == false) return;
  115. String sQry;
  116. //CCTV영상인 경우 대체영상 표출 여부 확인
  117. if (FObj.FCLT_TYPE == "CCTV")
  118. {
  119. sQry = "SELECT CCTV_SBST_DSPL_YN, CCTV_SBST_IMGN \r\n"
  120. " FROM TB_CCTV_CTLR \r\n"
  121. " WHERE CCTV_CTLR_ID = :p01 \r\n";
  122. }
  123. else
  124. {
  125. FDispBlob = false;
  126. PnlBlob->Visible = false;
  127. PnlStream->Visible = true;
  128. return;
  129. }
  130. try
  131. {
  132. pADO->Close();
  133. pADO->SQL->Clear();
  134. pADO->Connection = ITSDb_GetConnection();
  135. pADO->SQL->Text = sQry;
  136. pADO->Parameters->ParamByName("p01")->Value = FObj.ID;
  137. pADO->Prepared = true;
  138. pADO->Open();
  139. }
  140. catch(EDatabaseError &E)
  141. {
  142. PnlBlob->Caption = lblErr3->Caption;//"대체영상 이미지 정보 읽기 실패";
  143. ShowMessage(String(E.ClassName()) + E.Message);
  144. return;
  145. }
  146. if (pADO->RecordCount == 0)
  147. {
  148. pADO->Close();
  149. return;
  150. }
  151. ForceDirectories(g_sTempDir);
  152. TADOBlobStream *BS;
  153. int nFileSize = 0;
  154. String sImgFile = g_sTempDir + "CCTVB_" + FObj.ID + ".bmp";
  155. try {
  156. DeleteFile(sImgFile);
  157. } catch(...) {}
  158. String sDispBlob = "N";
  159. try
  160. {
  161. sDispBlob = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString;
  162. if (sDispBlob == "Y")
  163. {
  164. BS = (TADOBlobStream *)pADO->CreateBlobStream(pADO->FieldByName("CCTV_SBST_IMGN"), bmRead);
  165. //ImgBlob->Picture->Graphic->LoadFromStream(BS);
  166. BS->SaveToFile(sImgFile);
  167. nFileSize = BS->Size;
  168. delete BS;
  169. }
  170. pADO->Close();
  171. }
  172. catch(Exception &e)
  173. {
  174. delete BS;
  175. PnlBlob->Caption = lblErr4->Caption;//"대체영상 이미지 스트림 로딩 실패";
  176. return;
  177. }
  178. if (sDispBlob == "Y")
  179. {
  180. FDispBlob = true;
  181. PnlBlob->Visible = true;
  182. PnlStream->Visible = false;
  183. if (nFileSize)
  184. {
  185. try
  186. {
  187. ImgBlob->Picture->LoadFromFile(sImgFile);
  188. return;
  189. }
  190. catch(...)
  191. {
  192. ImgBlob->Visible = false;
  193. PnlBlob->Caption = lblErr5->Caption;//"대체영상 이미지 파일 로딩 실패";
  194. return;
  195. }
  196. }
  197. else
  198. {
  199. ImgBlob->Visible = false;
  200. PnlBlob->Caption = lblErr6->Caption;//"대체영상 이미지 사이즈 오류";
  201. }
  202. }
  203. else
  204. {
  205. FDispBlob = false;
  206. PnlBlob->Visible = false;
  207. PnlStream->Visible = true;
  208. }
  209. }
  210. //---------------------------------------------------------------------------
  211. void __fastcall TFrmStreamPlayer::MnuConnectClick(TObject *Sender)
  212. {
  213. FAutoPlay = true;
  214. Connect();
  215. }
  216. //---------------------------------------------------------------------------
  217. void __fastcall TFrmStreamPlayer::MnuDisconnectClick(TObject *Sender)
  218. {
  219. FAutoPlay = false;
  220. Disconnect();
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TFrmStreamPlayer::Connect()
  224. {
  225. Disconnect();
  226. PnlStream->Caption = FObj.STRM_ADDR;//"Connecting...";
  227. try
  228. {
  229. #if FFPLAY
  230. FFPlayer1->AspectRatio = -1;
  231. FFPlayer1->TryOpen(FObj.STRM_ADDR, PnlStream->Handle);
  232. FConHandle = (long)FFPlayer1->ScreenHandle;
  233. #endif
  234. #if ACES
  235. AcesTechXPlayer21->URL = FObj.STRM_ADDR;
  236. FConHandle = AcesTechXPlayer21->ConnectAsync();
  237. if (FConHandle > 0)
  238. {
  239. }
  240. #endif
  241. Application->ProcessMessages();
  242. }
  243. catch(Exception &e)
  244. {
  245. }
  246. FPlay = true;
  247. }
  248. //---------------------------------------------------------------------------
  249. void __fastcall TFrmStreamPlayer::Disconnect()
  250. {
  251. if (!FPlay) return;
  252. FPlay = false;
  253. PnlStream->Caption = "Disconnect";
  254. try
  255. {
  256. #if FFPLAY
  257. if (FFPlayer1->ScreenHandle != NULL)
  258. {
  259. FFPlayer1->Stop(true);
  260. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  261. UpdateWindow(FFPlayer1->ScreenHandle);
  262. FFPlayer1->ScreenHandle = NULL;
  263. }
  264. #endif
  265. #if ACES
  266. if (FConHandle > 0)
  267. {
  268. AcesTechXPlayer21->Close();
  269. }
  270. #endif
  271. Application->ProcessMessages();
  272. FConHandle = 0;
  273. }
  274. catch(Exception &e)
  275. {
  276. }
  277. PnlStream->Caption = "Disconnected";
  278. FConHandle = 0;
  279. FPlay = false;
  280. }
  281. //---------------------------------------------------------------------------
  282. void __fastcall TFrmStreamPlayer::InitCamera(void *ACctv, bool AAutoPlay/*=true*/)
  283. {
  284. FAutoPlay = AAutoPlay;
  285. }
  286. //---------------------------------------------------------------------------
  287. void __fastcall TFrmStreamPlayer::MaxOrNormalForm(TForm *AForm, bool AMax)
  288. {
  289. if (AMax)
  290. {
  291. //this->FParent = this->Parent;
  292. //AForm->Parent = FrmMain; //Application->MainForm;
  293. this->FLastBounds = AForm->BoundsRect;
  294. AForm->BorderStyle = bsNone;
  295. AForm->FormStyle = fsStayOnTop;
  296. AForm->BoundsRect = AForm->Monitor->BoundsRect;
  297. PnlStream->Align = alClient;
  298. #if 0
  299. ShowMessage(String(AForm->BoundsRect.Left) + ", " +
  300. String(AForm->BoundsRect.Top) + ": " +
  301. String(AForm->BoundsRect.Width()) + ", " +
  302. String(AForm->BoundsRect.Height()) );
  303. #endif
  304. }
  305. else
  306. {
  307. //AForm->Parent = this->FParent;
  308. AForm->FormStyle = fsNormal;
  309. AForm->BorderStyle = bsToolWindow;
  310. AForm->BoundsRect = this->FLastBounds;
  311. PnlStream->Align = alClient;
  312. }
  313. }
  314. //---------------------------------------------------------------------------
  315. void __fastcall TFrmStreamPlayer::PnlStreamDblClick(TObject *Sender)
  316. {
  317. #if 0
  318. if (FFullScreen == false)
  319. {
  320. MaxOrNormalForm(this, true);
  321. FFullScreen = true;
  322. }
  323. else
  324. {
  325. MaxOrNormalForm(this, false);
  326. FFullScreen = false;
  327. }
  328. #else
  329. #if FFPLAY
  330. // 여기서 더블클릭은 최대화면을 호출하는 것임
  331. TFrmFullScreen *pFrmFullScreen = new TFrmFullScreen(this);
  332. pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
  333. pFrmFullScreen->PnlStream->Align = alNone;
  334. pFrmFullScreen->PnlStream->Align = alClient;
  335. if (FObj.FULL_STRM_ADDR != "")
  336. {
  337. pFrmFullScreen->STRM_ADDR = FObj.FULL_STRM_ADDR;
  338. }
  339. else
  340. {
  341. pFrmFullScreen->STRM_ADDR = FObj.STRM_ADDR;
  342. }
  343. pFrmFullScreen->ShowModal();
  344. PnlStream->Parent = this;
  345. PnlStream->Tag = (int)this;
  346. delete pFrmFullScreen;
  347. pFrmFullScreen = NULL;
  348. #endif
  349. #endif
  350. #if 0
  351. TForm *pForm = (TForm*)PnlStream->Tag;
  352. if (pForm == this)
  353. {
  354. TFrmFullScreen *pFrmFullScreen = new TFrmFullScreen(this);
  355. pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
  356. pFrmFullScreen->PnlStream->Align = alNone;
  357. pFrmFullScreen->PnlStream->Align = alClient;
  358. pFrmFullScreen->STREAM_ADDR = FObj.STREAM_ADDR;
  359. PnlStream->Parent = pFrmFullScreen->PnlStream;
  360. PnlStream->Tag = (int)pFrmFullScreen;
  361. PnlStream->Align = alClient;
  362. pFrmFullScreen->ShowModal();
  363. FFPlayer1->ScreenHandle = PnlStream->Handle;
  364. PnlStream->Parent = this;
  365. PnlStream->Tag = (int)this;
  366. delete pFrmFullScreen;
  367. pFrmFullScreen = NULL;
  368. }
  369. else
  370. {
  371. PnlStream->Parent = this;
  372. PnlStream->Tag = (int)this;
  373. TFrmFullScreen *pFullForm = (TFrmFullScreen*)pForm;
  374. pFullForm->TmrClose->Enabled = true;
  375. }
  376. #endif
  377. }
  378. //---------------------------------------------------------------------------
  379. void __fastcall TFrmStreamPlayer::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  380. {
  381. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  382. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  383. {
  384. if (FPlay)
  385. {
  386. Caption = Caption + " : Disconnected";
  387. TmrShow->Enabled = true;
  388. }
  389. }
  390. }
  391. //---------------------------------------------------------------------------