FrmCameraPlayerF.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 "dxGDIPlusClasses"
  25. #pragma link "IdBaseComponent"
  26. #pragma link "IdComponent"
  27. #pragma link "IdExplicitTLSClientServerBase"
  28. #pragma link "IdFTP"
  29. #pragma link "IdTCPClient"
  30. #pragma link "IdTCPConnection"
  31. #pragma link "FFLog"
  32. #pragma resource "*.dfm"
  33. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  34. #define FFPLAYER 1
  35. TFrmCameraPlayer *FrmCameraPlayer = NULL;
  36. //---------------------------------------------------------------------------
  37. __fastcall TFrmCameraPlayer::TFrmCameraPlayer(TComponent* Owner)
  38. : TForm(Owner)
  39. {
  40. IsTerm = false;
  41. FPlay = false;
  42. FAutoPlay = true;
  43. FConHandle = 0;
  44. FFullScreen = false;
  45. FParent = this->Parent;
  46. PnlCamera->Tag = (int)this;
  47. //mmLog->Lines->Clear();
  48. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  49. FFPlayer1->DisableFPUExceptions();
  50. //FFPlayer1->ReadTimeout = 30 * 1000;
  51. //FFPlayer1->opt_default("fpsprobesize", "200000");
  52. //FFPlayer1->opt_default("probesize", "200000");
  53. if (!FFPlayer1->AVLibLoaded())
  54. {
  55. String sAVILibDir = g_sAppDir + "LibAV";
  56. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  57. {
  58. Application->MessageBox(L"영상표출 라이브러리를 로드하지 못하였습니다.", L"영상표출 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  59. return;
  60. }
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TFrmCameraPlayer::TmrShowTimer(TObject *Sender)
  65. {
  66. TmrShow->Enabled = false;
  67. if (IsTerm) {
  68. return;
  69. }
  70. if (Installed)
  71. {
  72. PopupMenu = PopupMenu1;
  73. ImgNoData->Visible = false;
  74. PnlName->Caption = CTLR_NMBR + ": " + NAME;
  75. Play();
  76. }
  77. else
  78. {
  79. PopupMenu = NULL;
  80. PnlCamera->Caption = NAME;
  81. LoadEmptyImage();
  82. }
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TFrmCameraPlayer::LoadEmptyImage()
  86. {
  87. try
  88. {
  89. #if 0
  90. String sImageFile = g_AppCfg.sEmptyImg;
  91. if (sImageFile != "")
  92. {
  93. ImgNoData->Picture->LoadFromFile(sImageFile);
  94. ImgNoData->Align = alClient;
  95. }
  96. #endif
  97. ImgNoData->Visible = true;
  98. }
  99. catch(Exception &e)
  100. {
  101. ImgNoData->Visible = true;
  102. }
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TFrmCameraPlayer::FormShow(TObject *Sender)
  106. {
  107. Refresh();
  108. this->FLastBounds = this->BoundsRect;
  109. // TmrShow->Enabled = true;
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TFrmCameraPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  113. {
  114. try {
  115. Stop();
  116. } catch(...) {}
  117. Action = caFree;
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
  121. {
  122. try {
  123. Stop();
  124. } catch(...) {}
  125. }
  126. //---------------------------------------------------------------------------
  127. void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
  128. {
  129. FAutoPlay = true;
  130. Play();
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
  134. {
  135. FAutoPlay = false;
  136. Stop();
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TFrmCameraPlayer::AutoPlay()
  140. {
  141. FAutoPlay = true;
  142. TmrShow->Enabled = true;
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TFrmCameraPlayer::Play()
  146. {
  147. Stop();
  148. if (STRM_ADDR == "") {
  149. PnlCamera->Caption = "영상정보가 없습니다";
  150. return;
  151. }
  152. PnlCamera->Caption = "영상 연결 중...";
  153. try
  154. {
  155. FFPlayer1->AspectRatio = -1;
  156. FFPlayer1->TryOpen(STRM_ADDR, PnlCamera->Handle);
  157. FConHandle = (long)FFPlayer1->ScreenHandle;
  158. Application->ProcessMessages();
  159. }
  160. catch(Exception &e)
  161. {
  162. }
  163. FPlay = true;
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TFrmCameraPlayer::Term()
  167. {
  168. IsTerm = true;
  169. Stop();
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TFrmCameraPlayer::Stop()
  173. {
  174. if (!FPlay) return;
  175. FPlay = false;
  176. if (STRM_ADDR == "") {
  177. return;
  178. }
  179. PnlCamera->Caption = "영상 연결 해제...";
  180. try
  181. {
  182. if (FFPlayer1->ScreenHandle != NULL)
  183. {
  184. FFPlayer1->Stop(true);
  185. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  186. UpdateWindow(FFPlayer1->ScreenHandle);
  187. }
  188. Application->ProcessMessages();
  189. FConHandle = 0;
  190. }
  191. catch(Exception &e)
  192. {
  193. }
  194. PnlCamera->Caption = "영상 연결 종료";
  195. FConHandle = 0;
  196. FPlay = false;
  197. }
  198. //---------------------------------------------------------------------------
  199. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String 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. FrmCameraScreen->TmrFullScreen->Enabled = false;
  217. FrmCameraScreen->FFullScreenIdx = Tag;
  218. FrmCameraScreen->TmrFullScreen->Enabled = true;
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TFrmCameraPlayer::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  222. {
  223. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  224. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  225. {
  226. if (FPlay)
  227. {
  228. FPlay = false;
  229. if (FFPlayer1->ScreenHandle != NULL)
  230. {
  231. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  232. UpdateWindow(FFPlayer1->ScreenHandle);
  233. }
  234. Application->ProcessMessages();
  235. FConHandle = 0;
  236. Caption = Caption + " : 연결종료";
  237. PnlCamera->Caption = "연결이 종료됨";
  238. TmrShow->Enabled = true;
  239. }
  240. }
  241. #if 0
  242. if (APlayState == Ffbasecomponent::psPlay) {
  243. mmLog->Lines->Add("psPlay");
  244. }
  245. else if (APlayState == Ffbasecomponent::psPause) {
  246. mmLog->Lines->Add("psPause");
  247. }
  248. else if (APlayState == Ffbasecomponent::psResume) {
  249. mmLog->Lines->Add("psResume");
  250. }
  251. else if (APlayState == Ffbasecomponent::psStep) {
  252. mmLog->Lines->Add("psStep");
  253. }
  254. else if (APlayState == Ffbasecomponent::psStop) {
  255. mmLog->Lines->Add("psStop");
  256. }
  257. else if (APlayState == Ffbasecomponent::psEnd) {
  258. mmLog->Lines->Add("psEnd");
  259. }
  260. #endif
  261. }
  262. //---------------------------------------------------------------------------
  263. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  264. {
  265. FrmCameraInfo = new TFrmCameraInfo(this);
  266. FrmCameraInfo->Edit1->Text = CTLR_NMBR;
  267. FrmCameraInfo->Edit2->Text = NAME;
  268. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  269. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  270. FrmCameraInfo->ShowModal();
  271. FrmCameraInfo = NULL;
  272. }
  273. //---------------------------------------------------------------------------