FrmCameraPlayerF.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 "dxGDIPlusClasses"
  12. #pragma link "PasLibVlcPlayerUnit"
  13. #pragma resource "*.dfm"
  14. TFrmCameraPlayer *FrmCameraPlayer = NULL;
  15. //---------------------------------------------------------------------------
  16. __fastcall TFrmCameraPlayer::TFrmCameraPlayer(TComponent* Owner)
  17. : TForm(Owner)
  18. {
  19. IsTerm = false;
  20. FPlay = false;
  21. FAutoPlay = true;
  22. FUserStop = false;
  23. FConHandle = 0;
  24. FFullScreen = false;
  25. FParent = this->Parent;
  26. PnlCamera->Tag = (int)this;
  27. //mmLog->Lines->Clear();
  28. }
  29. //---------------------------------------------------------------------------
  30. void __fastcall TFrmCameraPlayer::TmrShowTimer(TObject *Sender)
  31. {
  32. TmrShow->Enabled = false;
  33. if (IsTerm) {
  34. return;
  35. }
  36. if (Installed)
  37. {
  38. PopupMenu = PopupMenu1;
  39. ImgNoData->Visible = false;
  40. PnlName->Caption = CTLR_NMBR + ": " + NAME;
  41. Play();
  42. }
  43. else
  44. {
  45. PasLibVlcPlayer1->Visible = false;
  46. PopupMenu = NULL;
  47. PnlCamera->Caption = NAME;
  48. LoadEmptyImage();
  49. }
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TFrmCameraPlayer::LoadEmptyImage()
  53. {
  54. try
  55. {
  56. #if 0
  57. String sImageFile = g_AppCfg.sEmptyImg;
  58. if (sImageFile != "")
  59. {
  60. ImgNoData->Picture->LoadFromFile(sImageFile);
  61. ImgNoData->Align = alClient;
  62. }
  63. #endif
  64. ImgNoData->Visible = true;
  65. }
  66. catch(Exception &e)
  67. {
  68. ImgNoData->Visible = true;
  69. }
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TFrmCameraPlayer::FormShow(TObject *Sender)
  73. {
  74. Refresh();
  75. this->FLastBounds = this->BoundsRect;
  76. // TmrShow->Enabled = true;
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TFrmCameraPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  80. {
  81. try {
  82. Stop();
  83. } catch(...) {}
  84. Action = caFree;
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
  88. {
  89. try {
  90. Stop();
  91. } catch(...) {}
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
  95. {
  96. FAutoPlay = true;
  97. Play();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
  101. {
  102. PasLibVlcPlayer1->Visible = false;
  103. PasLibVlcPlayer1->Refresh();
  104. PnlCamera->Refresh();
  105. FUserStop = true;
  106. FAutoPlay = false;
  107. Stop();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TFrmCameraPlayer::AutoPlay()
  111. {
  112. FAutoPlay = true;
  113. TmrShow->Enabled = true;
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TFrmCameraPlayer::CameraLog(String ALogMsg)
  117. {
  118. PnlCamera->Caption = ALogMsg;
  119. PnlCamera->Refresh();
  120. Application->ProcessMessages();
  121. }
  122. //---------------------------------------------------------------------------
  123. void __fastcall TFrmCameraPlayer::Play()
  124. {
  125. if (PasLibVlcPlayer1->Visible) {
  126. PasLibVlcPlayer1->Visible = false;
  127. }
  128. Stop();
  129. if (STRM_ADDR == "") {
  130. CameraLog("### 영상정보가 없습니다 ###");
  131. return;
  132. }
  133. CameraLog("--- 영상 연결 중 ---");
  134. try
  135. {
  136. //PasLibVlcPlayer1->VLC->Path = "plugins";
  137. PasLibVlcPlayer1->Play(STRM_ADDR);
  138. FConHandle = 1;
  139. Application->ProcessMessages();
  140. AdjustVideoFit();
  141. if (FConHandle > 0)
  142. {
  143. if (ImgNoData->Visible == true) {
  144. ImgNoData->Visible = false;
  145. }
  146. }
  147. Application->ProcessMessages();
  148. }
  149. catch(Exception &e)
  150. {
  151. }
  152. FPlay = true;
  153. }
  154. //---------------------------------------------------------------------------
  155. void __fastcall TFrmCameraPlayer::Stop()
  156. {
  157. if (!FPlay) return;
  158. FPlay = false;
  159. if (STRM_ADDR == "") {
  160. return;
  161. }
  162. CameraLog("--- 영상 연결 해제 ---");
  163. try
  164. {
  165. if (FConHandle > 0)
  166. {
  167. PasLibVlcPlayer1->Stop();
  168. }
  169. Application->ProcessMessages();
  170. FConHandle = 0;
  171. }
  172. catch(Exception &e)
  173. {
  174. }
  175. CameraLog("*** 영상 연결 종료 ***");
  176. FConHandle = 0;
  177. FPlay = false;
  178. }
  179. //---------------------------------------------------------------------------
  180. void __fastcall TFrmCameraPlayer::AdjustVideoFit()
  181. {
  182. try {
  183. if (FConHandle > 0) {
  184. String ratioData = IntToStr(PasLibVlcPlayer1->Width) + ":" + IntToStr(PasLibVlcPlayer1->Height);
  185. PasLibVlcPlayer1->SetVideoAspectRatio(ratioData);
  186. }
  187. }
  188. catch(Exception &e) {
  189. }
  190. }
  191. //---------------------------------------------------------------------------
  192. void __fastcall TFrmCameraPlayer::Term()
  193. {
  194. IsTerm = true;
  195. Stop();
  196. }
  197. //---------------------------------------------------------------------------
  198. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
  199. {
  200. FAutoPlay = true;
  201. Installed = AInstalled;
  202. CTLR_NMBR = ACtlrNmbr;
  203. NAME = AName;
  204. STRM_ADDR = AStrmAddr;
  205. FULL_STRM_ADDR = AFullStrmAddr;
  206. VIEW_MODE = AViewMode;
  207. Caption = NAME;
  208. PnlName->Caption = NAME;
  209. PnlCamera->Caption = AStrmAddr;
  210. FUserStop = false;
  211. }
  212. //---------------------------------------------------------------------------
  213. void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
  214. {
  215. // 여기서 더블클릭은 최대화면을 호출하는 것임
  216. #if 0
  217. FrmCameraScreen->TmrFullScreen->Enabled = false;
  218. FrmCameraScreen->FFullScreenIdx = Tag;
  219. FrmCameraScreen->TmrFullScreen->Enabled = true;
  220. #endif
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1DblClick(TObject *Sender)
  224. {
  225. FrmCameraScreen->TmrFullScreen->Enabled = false;
  226. FrmCameraScreen->FFullScreenIdx = Tag;
  227. FrmCameraScreen->TmrFullScreen->Enabled = true;
  228. }
  229. //---------------------------------------------------------------------------
  230. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  231. {
  232. FrmCameraInfo = new TFrmCameraInfo(this);
  233. FrmCameraInfo->Edit1->Text = CTLR_NMBR;
  234. FrmCameraInfo->Edit2->Text = NAME;
  235. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  236. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  237. FrmCameraInfo->ShowModal();
  238. delete FrmCameraInfo;
  239. FrmCameraInfo = NULL;
  240. }
  241. //---------------------------------------------------------------------------
  242. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPlaying(TObject *Sender)
  243. {
  244. // 표출시작
  245. #if 0
  246. if (FConHandle > 0)
  247. {
  248. if (PasLibVlcPlayer1->Visible == false) {
  249. PasLibVlcPlayer1->Visible = true;
  250. }
  251. if (ImgNoData->Visible == true) {
  252. ImgNoData->Visible = false;
  253. }
  254. }
  255. #endif
  256. AdjustVideoFit();
  257. FUserStop = false;
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerMediaChanged(TObject *Sender, UnicodeString mrl)
  261. {
  262. // 스트리밍 변경됨
  263. AdjustVideoFit();
  264. }
  265. //---------------------------------------------------------------------------
  266. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerStopped(TObject *Sender)
  267. {
  268. if (FAutoPlay && FUserStop) {
  269. if (PasLibVlcPlayer1->Visible) {
  270. PasLibVlcPlayer1->Visible = false;
  271. }
  272. CameraLog("@@@ 영상 표출 종료 @@@");
  273. TmrShow->Enabled = false;
  274. TmrShow->Interval = 500;
  275. TmrShow->Enabled = true;
  276. }
  277. }
  278. //---------------------------------------------------------------------------
  279. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerEncounteredError(TObject *Sender)
  280. {
  281. if (PasLibVlcPlayer1->Visible) {
  282. PasLibVlcPlayer1->Visible = false;
  283. }
  284. CameraLog("@@@ 영상 표출 오류 @@@");
  285. }
  286. //---------------------------------------------------------------------------
  287. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerOpening(TObject *Sender)
  288. {
  289. #if 0
  290. // 표출시작
  291. if (FConHandle > 0)
  292. {
  293. if (PasLibVlcPlayer1->Visible == false) {
  294. PasLibVlcPlayer1->Visible = true;
  295. }
  296. if (ImgNoData->Visible == true) {
  297. ImgNoData->Visible = false;
  298. }
  299. }
  300. AdjustVideoFit();
  301. #endif
  302. }
  303. //---------------------------------------------------------------------------
  304. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPositionChanged(TObject *Sender, float position)
  305. {
  306. if (PasLibVlcPlayer1->Visible == false) {
  307. PasLibVlcPlayer1->Visible = true;
  308. PnlCamera->Refresh();
  309. AdjustVideoFit();
  310. }
  311. if (ImgNoData->Visible == true) {
  312. ImgNoData->Visible = false;
  313. }
  314. }
  315. //---------------------------------------------------------------------------