FrmStreamPlayerF.cpp 11 KB

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