FrmCameraPlayerF.cpp 7.4 KB

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