FrmCameraPlayerF.cpp 7.3 KB

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