FrmCrsStreamPlayer2F.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSLangTransF.h"
  5. #pragma hdrstop
  6. #include "FrmFullScreenF.h"
  7. #include "FrmCrsStreamPlayer2F.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. //TFrmCrsStreamPlayer *FrmCrsStreamPlayer;
  28. //---------------------------------------------------------------------------
  29. __fastcall TFrmCrsStreamPlayer2::TFrmCrsStreamPlayer2(TComponent* Owner)
  30. : TForm(Owner)
  31. {
  32. LangTrans->Translate(this, ITSDb_GetConnection());
  33. for (int ii = 0; ii < MAX_CRSCAM; ii++)
  34. {
  35. FObj.info[ii].Installed = false;
  36. FObj.info[ii].PnlStream = (TPanel*)FindComponent("PnlCam"+IntToStr(ii+1));
  37. FObj.info[ii].PnlTitle = (TPanel*)FindComponent("PnlTitle"+IntToStr(ii+1));
  38. FObj.info[ii].Cmra = NULL;
  39. FObj.info[ii].FConHandle = 0;
  40. FObj.info[ii].Timer = (TTimer*)FindComponent("Timer"+IntToStr(ii+1));;
  41. #if FFPLAY
  42. FObj.info[ii].FFPlayer = (TFFPlayer*)FindComponent("FFPlayer"+IntToStr(ii+1));
  43. FObj.info[ii].AcesTechXPlayer = (TAcesTechXPlayer2*)FindComponent("AcesTechXPlayer2"+IntToStr(ii+1));
  44. if (FObj.info[ii].AcesTechXPlayer)
  45. {
  46. FObj.info[ii].AcesTechXPlayer->Visible = false;
  47. }
  48. FObj.info[ii].FFPlayer->SetLicenseKey(LICENSE_KEY);
  49. FObj.info[ii].FFPlayer->DisableFPUExceptions();
  50. #endif
  51. #if ACES
  52. FObj.info[ii].AcesTechXPlayer = (TAcesTechXPlayer2*)FindComponent("AcesTechXPlayer2"+IntToStr(ii+1));
  53. FObj.info[ii].AcesTechXPlayer->Align = alClient;
  54. #endif
  55. FObj.info[ii].PnlStream->Tag = (int)this;
  56. FObj.info[ii].PnlTitle->Caption = "---";
  57. //FObj.info[ii].PnlStream->Visible = false;
  58. }
  59. PnlBlob->Visible = false;
  60. PnlBlob->Align = alClient;
  61. FDispBlob = false;
  62. FPlay = false;
  63. FAutoPlay = true;
  64. FFullScreen = false;
  65. InitCamera(NULL, FAutoPlay);
  66. FParent = this->Parent;
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TFrmCrsStreamPlayer2::TmrShowTimer(TObject *Sender)
  70. {
  71. TTimer *Timer = (TTimer*)Sender;
  72. int idx = (int)Timer->Tag;
  73. FObj.info[idx].Timer->Enabled = false;
  74. //if (FObj.Installed)
  75. {
  76. //Caption = FObj.ID + ": " + FObj.NAME;
  77. //if (FDispBlob == false)
  78. {
  79. Connect(idx);
  80. }
  81. }
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TFrmCrsStreamPlayer2::FormShow(TObject *Sender)
  85. {
  86. Refresh();
  87. this->FLastBounds = this->BoundsRect;
  88. if (FCross == NULL)
  89. {
  90. return;
  91. }
  92. int camCnt = 0;
  93. FOR_STL(TCrossCam *, pCrsCam, FCross->FLists)
  94. {
  95. FObj.info[camCnt].Installed = true;
  96. FObj.info[camCnt].Cmra = pCrsCam;
  97. FObj.info[camCnt].PnlTitle->Caption = pCrsCam->CAM_NM;
  98. camCnt++;
  99. if (camCnt >= MAX_CRSCAM)
  100. {
  101. break;
  102. }
  103. }
  104. #if FFPLAY
  105. String sAVILibDir = g_sAppDir + "LibAV";
  106. for (int ii = 0; ii < MAX_CRSCAM; ii++)
  107. {
  108. if (FObj.info[ii].Installed == false)
  109. {
  110. continue;
  111. }
  112. if (!FObj.info[ii].FFPlayer->AVLibLoaded())
  113. {
  114. if (!FObj.info[ii].FFPlayer->LoadAVLib(sAVILibDir))
  115. {
  116. Application->MessageBox(lblErr1->Caption.c_str(),//L"영상표출 라이브러리를 로드하지 못하였습니다.",
  117. lblErr2->Caption.c_str(),//L"영상표출 오류",
  118. MB_OK|MB_ICONERROR|MB_APPLMODAL);
  119. return;
  120. }
  121. }
  122. }
  123. #endif
  124. for (int ii = 0; ii < MAX_CRSCAM; ii++)
  125. {
  126. if (FObj.info[ii].Installed)
  127. {
  128. if (FObj.info[ii].PnlStream->Visible == false) FObj.info[ii].PnlStream->Visible = true;
  129. FObj.info[ii].Timer->Enabled = true;
  130. }
  131. }
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TFrmCrsStreamPlayer2::FormClose(TObject *Sender, TCloseAction &Action)
  135. {
  136. ReleaseCamera();
  137. Action = caFree;
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TFrmCrsStreamPlayer2::FormDestroy(TObject *Sender)
  141. {
  142. ReleaseCamera();
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TFrmCrsStreamPlayer2::ReleaseCamera()
  146. {
  147. try {
  148. for (int ii = 0; ii < MAX_CRSCAM; ii++)
  149. {
  150. if (FObj.info[ii].Installed)
  151. {
  152. Disconnect(ii);
  153. }
  154. }
  155. if (FCross) FCross->FData1 = NULL;
  156. } catch(...) {}
  157. }
  158. //---------------------------------------------------------------------------
  159. void __fastcall TFrmCrsStreamPlayer2::MnuConnectClick(TObject *Sender)
  160. {
  161. FAutoPlay = true;
  162. Connect(0);
  163. }
  164. //---------------------------------------------------------------------------
  165. void __fastcall TFrmCrsStreamPlayer2::MnuDisconnectClick(TObject *Sender)
  166. {
  167. FAutoPlay = false;
  168. Disconnect(0);
  169. }
  170. //---------------------------------------------------------------------------
  171. void __fastcall TFrmCrsStreamPlayer2::Connect(int AIdx)
  172. {
  173. Disconnect(AIdx);
  174. try
  175. {
  176. CRSCAM_PLAYER_INFO *pInfo = &FObj.info[AIdx];
  177. if (pInfo->Installed == false)
  178. {
  179. return;
  180. }
  181. pInfo->PnlStream->Caption = "Connecting...";
  182. pInfo->PnlTitle->Caption = pInfo->Cmra->CAM_NM;
  183. #if FFPLAY
  184. TFFPlayer *FFPlayer = pInfo->FFPlayer;
  185. FFPlayer->AspectRatio = -1;
  186. FFPlayer->TryOpen(pInfo->Cmra->RTSP_URL, pInfo->PnlStream->Handle);
  187. FConHandle = (long)FFPlayer->ScreenHandle;
  188. #endif
  189. #if ACES
  190. pInfo->AcesTechXPlayer->URL = pInfo->Cmra->RTSP_URL;
  191. pInfo->FConHandle = pInfo->AcesTechXPlayer->ConnectAsync();
  192. if (pInfo->FConHandle > 0)
  193. {
  194. }
  195. #endif
  196. Application->ProcessMessages();
  197. }
  198. catch(Exception &e)
  199. {
  200. }
  201. FPlay = true;
  202. }
  203. //---------------------------------------------------------------------------
  204. void __fastcall TFrmCrsStreamPlayer2::Disconnect(int AIdx)
  205. {
  206. if (!FPlay) return;
  207. FPlay = false;
  208. try
  209. {
  210. CRSCAM_PLAYER_INFO *pInfo = &FObj.info[AIdx];
  211. if (pInfo->Installed == false)
  212. {
  213. return;
  214. }
  215. #if FFPLAY
  216. TFFPlayer *FFPlayer = pInfo->FFPlayer;
  217. if (FFPlayer->ScreenHandle != NULL)
  218. {
  219. FFPlayer->Stop(true);
  220. PostMessage(FFPlayer->ScreenHandle, CM_INVALIDATE, 0, 0);
  221. UpdateWindow(FFPlayer->ScreenHandle);
  222. FFPlayer->ScreenHandle = NULL;
  223. }
  224. #endif
  225. #if ACES
  226. if (pInfo->FConHandle > 0)
  227. {
  228. pInfo->AcesTechXPlayer->Close();
  229. }
  230. #endif
  231. pInfo->FConHandle = 0;
  232. pInfo->PnlStream->Caption = "Disconnected";
  233. Application->ProcessMessages();
  234. }
  235. catch(Exception &e)
  236. {
  237. }
  238. FPlay = false;
  239. }
  240. //---------------------------------------------------------------------------
  241. void __fastcall TFrmCrsStreamPlayer2::InitCamera(void *ACctv, bool AAutoPlay/*=true*/)
  242. {
  243. FAutoPlay = AAutoPlay;
  244. }
  245. //---------------------------------------------------------------------------
  246. void __fastcall TFrmCrsStreamPlayer2::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  247. {
  248. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  249. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  250. {
  251. if (FPlay)
  252. {
  253. TFFPlayer *Player = (TFFPlayer*)Sender;
  254. int idx = (int)Player->Tag;
  255. FObj.info[idx].PnlTitle->Caption = FObj.info[idx].Cmra->CAM_NM + " : Disconnected";
  256. FObj.info[idx].Timer->Enabled = true;
  257. }
  258. }
  259. }
  260. //---------------------------------------------------------------------------