FrmCameraPlayerF.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. PnlName->Visible = g_AppCfg.bCameraTitle;
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TFrmCameraPlayer::TmrShowTimer(TObject *Sender)
  67. {
  68. TmrShow->Enabled = false;
  69. if (Installed)
  70. {
  71. PopupMenu = PopupMenu1;
  72. ImgNoData->Visible = false;
  73. //PnlName->Caption = String(CTLR_NMBR) + ": " + NAME;
  74. PnlName->Caption = " " + NAME;
  75. Play();
  76. }
  77. else
  78. {
  79. #if ACES
  80. AcesTechXPlayer21->Visible = false;
  81. #endif
  82. PopupMenu = NULL;
  83. PnlCamera->Caption = NAME;
  84. LoadEmptyImage();
  85. }
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TFrmCameraPlayer::LoadEmptyImage()
  89. {
  90. try
  91. {
  92. String sImageFile = g_AppCfg.sEmptyImg;
  93. if (sImageFile != "")
  94. {
  95. ImgNoData->Picture->LoadFromFile(sImageFile);
  96. ImgNoData->Align = alClient;
  97. ImgNoData->Visible = true;
  98. }
  99. }
  100. catch(Exception &e)
  101. {
  102. ImgNoData->Visible = true;
  103. }
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TFrmCameraPlayer::FormShow(TObject *Sender)
  107. {
  108. Refresh();
  109. this->FLastBounds = this->BoundsRect;
  110. // TmrShow->Enabled = true;
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TFrmCameraPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  114. {
  115. try {
  116. Stop();
  117. } catch(...) {}
  118. Action = caFree;
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
  122. {
  123. try {
  124. Stop();
  125. } catch(...) {}
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
  129. {
  130. FAutoPlay = true;
  131. Play();
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
  135. {
  136. FAutoPlay = false;
  137. Stop();
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TFrmCameraPlayer::AutoPlay()
  141. {
  142. FAutoPlay = true;
  143. TmrShow->Enabled = true;
  144. }
  145. //---------------------------------------------------------------------------
  146. void __fastcall TFrmCameraPlayer::Play()
  147. {
  148. Stop();
  149. PnlCamera->Caption = "Try connect...";
  150. try
  151. {
  152. #if FFPLAYER
  153. FFPlayer1->AspectRatio = -1;
  154. FFPlayer1->TryOpen(STRM_ADDR, PnlCamera->Handle);
  155. FConHandle = (long)FFPlayer1->ScreenHandle;
  156. #endif
  157. #if ACES
  158. AcesTechXPlayer21->URL = STRM_ADDR;
  159. FConHandle = AcesTechXPlayer21->ConnectAsync();
  160. if (FConHandle > 0)
  161. {
  162. }
  163. #endif
  164. Application->ProcessMessages();
  165. }
  166. catch(Exception &e)
  167. {
  168. }
  169. FPlay = true;
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TFrmCameraPlayer::Stop()
  173. {
  174. if (!FPlay) return;
  175. FPlay = false;
  176. PnlCamera->Caption = "Try disconnect";
  177. try
  178. {
  179. #if FFPLAYER
  180. if (FFPlayer1->ScreenHandle != NULL)
  181. {
  182. FFPlayer1->Stop(true);
  183. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  184. UpdateWindow(FFPlayer1->ScreenHandle);
  185. }
  186. #endif
  187. #if ACES
  188. if (FConHandle > 0)
  189. {
  190. AcesTechXPlayer21->Close();
  191. }
  192. #endif
  193. Application->ProcessMessages();
  194. FConHandle = 0;
  195. }
  196. catch(Exception &e)
  197. {
  198. }
  199. PnlCamera->Caption = "Disconnected";
  200. FConHandle = 0;
  201. FPlay = false;
  202. }
  203. //---------------------------------------------------------------------------
  204. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
  205. {
  206. FAutoPlay = true;
  207. Installed = AInstalled;
  208. CTLR_NMBR = ACtlrNmbr;
  209. NAME = AName;
  210. STRM_ADDR = AStrmAddr;
  211. FULL_STRM_ADDR = AFullStrmAddr;
  212. VIEW_MODE = AViewMode;
  213. Caption = NAME;
  214. PnlName->Caption = NAME;
  215. PnlCamera->Caption = AStrmAddr;
  216. }
  217. //---------------------------------------------------------------------------
  218. void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
  219. {
  220. // 여기서 더블클릭은 최대화면을 호출하는 것임
  221. #if 0
  222. TFrmCameraFullScreen *pFrmFullScreen = new TFrmCameraFullScreen(this);
  223. pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
  224. pFrmFullScreen->PnlStream->Align = alNone;
  225. pFrmFullScreen->PnlStream->Align = alClient;
  226. pFrmFullScreen->RTSP_ADDR = FULL_STRM_ADDR;
  227. pFrmFullScreen->ShowModal();
  228. PnlCamera->Parent = this;
  229. PnlCamera->Tag = (int)this;
  230. delete pFrmFullScreen;
  231. pFrmFullScreen = NULL;
  232. #else
  233. #if FFPLAYER
  234. FrmCameraScreen->TmrFullScreen->Enabled = false;
  235. FrmCameraScreen->FFullScreenIdx = Tag;
  236. FrmCameraScreen->TmrFullScreen->Enabled = true;
  237. #endif
  238. #endif
  239. }
  240. //---------------------------------------------------------------------------
  241. void __fastcall TFrmCameraPlayer::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  242. {
  243. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  244. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  245. {
  246. if (FPlay)
  247. {
  248. Caption = Caption + " : Disconnected";
  249. TmrShow->Enabled = true;
  250. }
  251. }
  252. }
  253. //---------------------------------------------------------------------------
  254. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  255. {
  256. FrmCameraInfo = new TFrmCameraInfo(this);
  257. FrmCameraInfo->Edit1->Text = String(CTLR_NMBR);
  258. FrmCameraInfo->Edit2->Text = NAME;
  259. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  260. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  261. FrmCameraInfo->ShowModal();
  262. FrmCameraInfo = NULL;
  263. }
  264. //---------------------------------------------------------------------------