FrmCameraPlayerF.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "FrmCameraPlayerF.h"
  5. #include "FrmCameraFullScreenF.h"
  6. #include "FrmCameraInfoF.h"
  7. #include "FrmCameraScreenF.h"
  8. #pragma hdrstop
  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 link "AcesTechXPlayer2Lib_OCX"
  25. #pragma resource "*.dfm"
  26. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  27. #define FFPLAYER 0
  28. #define ACES 1
  29. TFrmCameraPlayer *FrmCameraPlayer = NULL;
  30. //---------------------------------------------------------------------------
  31. __fastcall TFrmCameraPlayer::TFrmCameraPlayer(TComponent* Owner)
  32. : TForm(Owner)
  33. {
  34. FPlay = false;
  35. FAutoPlay = true;
  36. FConHandle = 0;
  37. FFullScreen = false;
  38. FParent = this->Parent;
  39. PnlCamera->Tag = (int)this;
  40. #if FFPLAYER
  41. AcesTechXPlayer21->Visible = false;
  42. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  43. FFPlayer1->DisableFPUExceptions();
  44. if (!FFPlayer1->AVLibLoaded())
  45. {
  46. String sAVILibDir = g_sAppDir + "LibAV";
  47. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  48. {
  49. if (g_AppCfg.sLang != "kr") Application->MessageBox(L"Stream display library load failed.", L"Stream display fail", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  50. else Application->MessageBox(L"영상표출 라이브러리를 로드하지 못하였습니다.", L"영상표출 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  51. return;
  52. }
  53. }
  54. #endif
  55. #if ACES
  56. #endif
  57. if (g_AppCfg.sLang != "kr")
  58. {
  59. MnuConnect->Caption = "Connect";
  60. MnuDisconnect->Caption = "Disconnect";
  61. MnuInfo->Caption = "Information...";
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TFrmCameraPlayer::TmrShowTimer(TObject *Sender)
  66. {
  67. TmrShow->Enabled = false;
  68. if (Installed)
  69. {
  70. PopupMenu = PopupMenu1;
  71. ImgNoData->Visible = false;
  72. PnlName->Caption = String(CTLR_NMBR) + ": " + NAME;
  73. Play();
  74. }
  75. else
  76. {
  77. PopupMenu = NULL;
  78. PnlCamera->Caption = NAME;
  79. LoadEmptyImage();
  80. }
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TFrmCameraPlayer::LoadEmptyImage()
  84. {
  85. try
  86. {
  87. String sImageFile = g_AppCfg.sEmptyImg;
  88. if (sImageFile != "")
  89. {
  90. ImgNoData->Picture->LoadFromFile(sImageFile);
  91. ImgNoData->Align = alClient;
  92. ImgNoData->Visible = true;
  93. }
  94. }
  95. catch(Exception &e)
  96. {
  97. ImgNoData->Visible = true;
  98. }
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TFrmCameraPlayer::FormShow(TObject *Sender)
  102. {
  103. Refresh();
  104. this->FLastBounds = this->BoundsRect;
  105. // TmrShow->Enabled = true;
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TFrmCameraPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  109. {
  110. try {
  111. Stop();
  112. } catch(...) {}
  113. Action = caFree;
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
  117. {
  118. try {
  119. Stop();
  120. } catch(...) {}
  121. }
  122. //---------------------------------------------------------------------------
  123. void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
  124. {
  125. FAutoPlay = true;
  126. Play();
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
  130. {
  131. FAutoPlay = false;
  132. Stop();
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TFrmCameraPlayer::AutoPlay()
  136. {
  137. FAutoPlay = true;
  138. TmrShow->Enabled = true;
  139. }
  140. //---------------------------------------------------------------------------
  141. void __fastcall TFrmCameraPlayer::Play()
  142. {
  143. Stop();
  144. PnlCamera->Caption = "Try connect...";
  145. try
  146. {
  147. #if FFPLAYER
  148. FFPlayer1->AspectRatio = -1;
  149. FFPlayer1->TryOpen(STRM_ADDR, PnlCamera->Handle);
  150. FConHandle = (long)FFPlayer1->ScreenHandle;
  151. #endif
  152. #if ACES
  153. AcesTechXPlayer21->URL = STRM_ADDR;
  154. FConHandle = AcesTechXPlayer21->ConnectAsync();
  155. if (FConHandle > 0)
  156. {
  157. }
  158. #endif
  159. Application->ProcessMessages();
  160. }
  161. catch(Exception &e)
  162. {
  163. }
  164. FPlay = true;
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TFrmCameraPlayer::Stop()
  168. {
  169. if (!FPlay) return;
  170. FPlay = false;
  171. PnlCamera->Caption = "Try disconnect";
  172. try
  173. {
  174. #if FFPLAYER
  175. if (FFPlayer1->ScreenHandle != NULL)
  176. {
  177. FFPlayer1->Stop(true);
  178. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  179. UpdateWindow(FFPlayer1->ScreenHandle);
  180. }
  181. #endif
  182. #if ACES
  183. if (FConHandle > 0)
  184. {
  185. AcesTechXPlayer21->Close();
  186. }
  187. #endif
  188. Application->ProcessMessages();
  189. FConHandle = 0;
  190. }
  191. catch(Exception &e)
  192. {
  193. }
  194. PnlCamera->Caption = "Disconnected";
  195. FConHandle = 0;
  196. FPlay = false;
  197. }
  198. //---------------------------------------------------------------------------
  199. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, int ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
  200. {
  201. FAutoPlay = true;
  202. Installed = AInstalled;
  203. CTLR_NMBR = ACtlrNmbr;
  204. NAME = AName;
  205. STRM_ADDR = AStrmAddr;
  206. FULL_STRM_ADDR = AFullStrmAddr;
  207. VIEW_MODE = AViewMode;
  208. Caption = NAME;
  209. PnlName->Caption = NAME;
  210. PnlCamera->Caption = AStrmAddr;
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
  214. {
  215. // 여기서 더블클릭은 최대화면을 호출하는 것임
  216. #if 0
  217. TFrmCameraFullScreen *pFrmFullScreen = new TFrmCameraFullScreen(this);
  218. pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
  219. pFrmFullScreen->PnlStream->Align = alNone;
  220. pFrmFullScreen->PnlStream->Align = alClient;
  221. pFrmFullScreen->RTSP_ADDR = FULL_STRM_ADDR;
  222. pFrmFullScreen->ShowModal();
  223. PnlCamera->Parent = this;
  224. PnlCamera->Tag = (int)this;
  225. delete pFrmFullScreen;
  226. pFrmFullScreen = NULL;
  227. #else
  228. #if FFPLAYER
  229. FrmCameraScreen->TmrFullScreen->Enabled = false;
  230. FrmCameraScreen->FFullScreenIdx = Tag;
  231. FrmCameraScreen->TmrFullScreen->Enabled = true;
  232. #endif
  233. #endif
  234. }
  235. //---------------------------------------------------------------------------
  236. void __fastcall TFrmCameraPlayer::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  237. {
  238. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  239. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  240. {
  241. if (FPlay)
  242. {
  243. Caption = Caption + " : Disconnected";
  244. TmrShow->Enabled = true;
  245. }
  246. }
  247. }
  248. //---------------------------------------------------------------------------
  249. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  250. {
  251. FrmCameraInfo = new TFrmCameraInfo(this);
  252. FrmCameraInfo->Edit1->Text = String(CTLR_NMBR);
  253. FrmCameraInfo->Edit2->Text = NAME;
  254. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  255. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  256. FrmCameraInfo->ShowModal();
  257. FrmCameraInfo = NULL;
  258. }
  259. //---------------------------------------------------------------------------