FrmStreamPlayerF.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "FrmStreamPlayerF.h"
  4. #include "AppGlobalF.h"
  5. #include "FrmFullScreenF.h"
  6. #include "ITSLangTransF.h"
  7. #pragma hdrstop
  8. #include "FrmMainF.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "FFBaseComponent"
  12. #pragma link "FFBasePlay"
  13. #pragma link "FFPlay"
  14. #pragma link "cxContainer"
  15. #pragma link "cxControls"
  16. #pragma link "cxEdit"
  17. #pragma link "cxGraphics"
  18. #pragma link "cxLabel"
  19. #pragma link "cxLookAndFeelPainters"
  20. #pragma link "cxLookAndFeels"
  21. #pragma link "dxSkinBlack"
  22. #pragma link "dxSkinBlue"
  23. #pragma link "dxSkinsCore"
  24. #pragma resource "*.dfm"
  25. //TFrmStreamPlayer *FrmStreamPlayer;
  26. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  27. //---------------------------------------------------------------------------
  28. __fastcall TFrmStreamPlayer::TFrmStreamPlayer(TComponent* Owner)
  29. : TForm(Owner)
  30. {
  31. LangTrans->Translate(this, ITSDb_GetConnection());
  32. FObj.Installed = false;
  33. FObj.IsCctv = false;
  34. FObj.Data = NULL;
  35. PnlBlob->Visible = false;
  36. PnlBlob->Align = alClient;
  37. FDispBlob = false;
  38. FPlay = false;
  39. FAutoPlay = true;
  40. FConHandle = 0;
  41. FFullScreen = false;
  42. InitCamera(NULL, FAutoPlay);
  43. FParent = this->Parent;
  44. PnlStream->Tag = (int)this;
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TFrmStreamPlayer::TmrShowTimer(TObject *Sender)
  48. {
  49. TmrShow->Enabled = false;
  50. if (FObj.Installed)
  51. {
  52. Caption = FObj.ID + ": " + FObj.NAME;
  53. if (FDispBlob == false)
  54. {
  55. Connect();
  56. }
  57. }
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TFrmStreamPlayer::FormShow(TObject *Sender)
  61. {
  62. #if 1
  63. if (FObj.Installed) PnlStream->Caption = FObj.NAME;
  64. else PnlStream->Caption = "";
  65. #endif
  66. Refresh();
  67. this->FLastBounds = this->BoundsRect;
  68. //CCTV영상인 경우 대체영상 표출 여부 확인
  69. RefreshPlayer();
  70. if (PnlStream->Visible)
  71. {
  72. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  73. FFPlayer1->DisableFPUExceptions();
  74. if (!FFPlayer1->AVLibLoaded())
  75. {
  76. String sAVILibDir = g_sAppDir + "LibAV";
  77. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  78. {
  79. Application->MessageBox(lblErr1->Caption.c_str(),//L"영상표출 라이브러리를 로드하지 못하였습니다.",
  80. lblErr2->Caption.c_str(),//L"영상표출 오류",
  81. MB_OK|MB_ICONERROR|MB_APPLMODAL);
  82. return;
  83. }
  84. }
  85. }
  86. TmrShow->Enabled = true;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TFrmStreamPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  90. {
  91. try {
  92. Disconnect();
  93. if (FObj.Data) *FObj.Data = NULL;
  94. } catch(...) {}
  95. Action = caFree;
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TFrmStreamPlayer::FormDestroy(TObject *Sender)
  99. {
  100. try {
  101. Disconnect();
  102. if (FObj.Data) *FObj.Data = NULL;
  103. } catch(...) {}
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TFrmStreamPlayer::RefreshPlayer()
  107. {
  108. FDispBlob = false;
  109. PnlBlob->Visible = false;
  110. if (FObj.IsCctv == false) return;
  111. String sQry;
  112. sQry = "SELECT CCTV_SBST_DSPL_YN, CCTV_SBST_IMGN \r\n"
  113. " FROM TB_CCTV_CTLR \r\n"
  114. " WHERE CCTV_CTLR_ID = :p01 \r\n";
  115. try
  116. {
  117. pADO->Close();
  118. pADO->SQL->Clear();
  119. pADO->Connection = ITSDb_GetConnection();
  120. pADO->SQL->Text = sQry;
  121. pADO->Parameters->ParamByName("p01")->Value = FObj.ID;
  122. pADO->Open();
  123. }
  124. catch(EDatabaseError &E)
  125. {
  126. PnlBlob->Caption = lblErr3->Caption;//"대체영상 이미지 정보 읽기 실패";
  127. ShowMessage(String(E.ClassName()) + E.Message);
  128. return;
  129. }
  130. if (pADO->RecordCount == 0)
  131. {
  132. pADO->Close();
  133. return;
  134. }
  135. ForceDirectories(g_sTempDir);
  136. TADOBlobStream *BS;
  137. int nFileSize = 0;
  138. String sImgFile = g_sTempDir + "CCTVB_" + FObj.ID + ".bmp";
  139. try {
  140. DeleteFile(sImgFile);
  141. } catch(...) {}
  142. String sDispBlob;
  143. try
  144. {
  145. sDispBlob = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString;
  146. if (sDispBlob == "Y")
  147. {
  148. BS = (TADOBlobStream *)pADO->CreateBlobStream(pADO->FieldByName("CCTV_SBST_IMGN"), bmRead);
  149. //ImgBlob->Picture->Graphic->LoadFromStream(BS);
  150. BS->SaveToFile(sImgFile);
  151. nFileSize = BS->Size;
  152. delete BS;
  153. }
  154. pADO->Close();
  155. }
  156. catch(Exception &e)
  157. {
  158. delete BS;
  159. PnlBlob->Caption = lblErr4->Caption;//"대체영상 이미지 스트림 로딩 실패";
  160. return;
  161. }
  162. if (sDispBlob == "Y")
  163. {
  164. FDispBlob = true;
  165. PnlBlob->Visible = true;
  166. PnlStream->Visible = false;
  167. if (nFileSize)
  168. {
  169. try
  170. {
  171. ImgBlob->Picture->LoadFromFile(sImgFile);
  172. return;
  173. }
  174. catch(...)
  175. {
  176. ImgBlob->Visible = false;
  177. PnlBlob->Caption = lblErr5->Caption;//"대체영상 이미지 파일 로딩 실패";
  178. return;
  179. }
  180. }
  181. else
  182. {
  183. ImgBlob->Visible = false;
  184. PnlBlob->Caption = lblErr6->Caption;//"대체영상 이미지 사이즈 오류";
  185. }
  186. }
  187. else
  188. {
  189. FDispBlob = false;
  190. PnlBlob->Visible = false;
  191. PnlStream->Visible = true;
  192. }
  193. }
  194. //---------------------------------------------------------------------------
  195. void __fastcall TFrmStreamPlayer::MnuConnectClick(TObject *Sender)
  196. {
  197. FAutoPlay = true;
  198. Connect();
  199. }
  200. //---------------------------------------------------------------------------
  201. void __fastcall TFrmStreamPlayer::MnuDisconnectClick(TObject *Sender)
  202. {
  203. FAutoPlay = false;
  204. Disconnect();
  205. }
  206. //---------------------------------------------------------------------------
  207. void __fastcall TFrmStreamPlayer::Connect()
  208. {
  209. Disconnect();
  210. PnlStream->Caption = "Connecting...";
  211. try
  212. {
  213. FFPlayer1->TryOpen(FObj.RTSP_ADDR, PnlStream->Handle);
  214. FConHandle = (long)FFPlayer1->ScreenHandle;
  215. Application->ProcessMessages();
  216. }
  217. catch(Exception &e)
  218. {
  219. }
  220. FPlay = true;
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TFrmStreamPlayer::Disconnect()
  224. {
  225. if (!FPlay) return;
  226. FPlay = false;
  227. PnlStream->Caption = "Disconnect";
  228. try
  229. {
  230. if (FFPlayer1->ScreenHandle != NULL)
  231. {
  232. FFPlayer1->Stop(true);
  233. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  234. UpdateWindow(FFPlayer1->ScreenHandle);
  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. //---------------------------------------------------------------------------