FrmCameraPlayerF.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. FAutoPlay = false;
  83. Stop();
  84. } catch(...) {}
  85. Action = caFree;
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
  89. {
  90. try {
  91. FAutoPlay = false;
  92. Stop();
  93. } catch(...) {}
  94. }
  95. //---------------------------------------------------------------------------
  96. void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
  97. {
  98. FUserStop = true;
  99. Play();
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
  103. {
  104. PasLibVlcPlayer1->Visible = false;
  105. PasLibVlcPlayer1->Refresh();
  106. PnlCamera->Refresh();
  107. FUserStop = true;
  108. FAutoPlay = false;
  109. Stop();
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TFrmCameraPlayer::AutoPlay()
  113. {
  114. FAutoPlay = true;
  115. TmrShow->Enabled = true;
  116. }
  117. //---------------------------------------------------------------------------
  118. void __fastcall TFrmCameraPlayer::CameraLog(String ALogMsg)
  119. {
  120. PnlCamera->Caption = ALogMsg;
  121. PnlCamera->Refresh();
  122. #if 0
  123. AnsiString strmAddr = AnsiString(STRM_ADDR);
  124. if (strmAddr == "") {
  125. strmAddr = "Empty Addr";
  126. }
  127. AnsiString sAutoPlay = FAutoPlay ? "AutoPlay:True" : "AutoPlay:False";
  128. AnsiString sUserStop = FUserStop ? "UserStop:True" : "UserStop:False";
  129. LOGINFO("%s,%s, %s: %s", sAutoPlay.c_str(), sUserStop.c_str(), strmAddr.c_str(), AnsiString(ALogMsg).c_str());
  130. #endif
  131. Application->ProcessMessages();
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TFrmCameraPlayer::Play()
  135. {
  136. if (FPlay) return;
  137. if (PasLibVlcPlayer1->Visible) {
  138. PasLibVlcPlayer1->Visible = false;
  139. }
  140. Stop();
  141. if (STRM_ADDR == "") {
  142. CameraLog("### 영상정보가 없습니다 ###");
  143. return;
  144. }
  145. CameraLog("--- 영상 연결 중 ---");
  146. try
  147. {
  148. //PasLibVlcPlayer1->VLC->Path = "plugins";
  149. PasLibVlcPlayer1->VLC->AddOption("http-caching=300");
  150. PasLibVlcPlayer1->VLC->AddOption("file-caching=300");
  151. PasLibVlcPlayer1->VLC->AddOption("network-caching=500");
  152. //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw=none");
  153. PasLibVlcPlayer1->Play(STRM_ADDR);
  154. FConHandle = 1;
  155. Application->ProcessMessages();
  156. AdjustVideoFit();
  157. if (FConHandle > 0)
  158. {
  159. if (ImgNoData->Visible == true) {
  160. ImgNoData->Visible = false;
  161. }
  162. }
  163. Application->ProcessMessages();
  164. }
  165. catch(Exception &e)
  166. {
  167. }
  168. FPlay = true;
  169. }
  170. //---------------------------------------------------------------------------
  171. void __fastcall TFrmCameraPlayer::Stop()
  172. {
  173. if (!FPlay) return;
  174. FPlay = false;
  175. if (STRM_ADDR == "") {
  176. return;
  177. }
  178. CameraLog("--- 영상 연결 해제 ---");
  179. try
  180. {
  181. if (FConHandle > 0)
  182. {
  183. PasLibVlcPlayer1->Stop();
  184. }
  185. Application->ProcessMessages();
  186. FConHandle = 0;
  187. }
  188. catch(Exception &e)
  189. {
  190. }
  191. CameraLog("*** 영상 연결 종료 ***");
  192. FConHandle = 0;
  193. FPlay = false;
  194. }
  195. //---------------------------------------------------------------------------
  196. void __fastcall TFrmCameraPlayer::AdjustVideoFit()
  197. {
  198. try {
  199. if (FConHandle > 0 && PasLibVlcPlayer1->IsPlay()) {
  200. String ratioData = IntToStr(PasLibVlcPlayer1->Width) + ":" + IntToStr(PasLibVlcPlayer1->Height);
  201. PasLibVlcPlayer1->SetVideoAspectRatio(ratioData);
  202. }
  203. }
  204. catch(Exception &e) {
  205. }
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TFrmCameraPlayer::Term()
  209. {
  210. IsTerm = true;
  211. Stop();
  212. }
  213. //---------------------------------------------------------------------------
  214. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
  215. {
  216. FAutoPlay = true;
  217. Installed = AInstalled;
  218. CTLR_NMBR = ACtlrNmbr;
  219. NAME = AName;
  220. STRM_ADDR = AStrmAddr;
  221. FULL_STRM_ADDR = AFullStrmAddr;
  222. VIEW_MODE = AViewMode;
  223. Caption = NAME;
  224. PnlName->Caption = NAME;
  225. PnlCamera->Caption = AStrmAddr;
  226. FUserStop = false;
  227. }
  228. //---------------------------------------------------------------------------
  229. void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
  230. {
  231. // 여기서 더블클릭은 최대화면을 호출하는 것임
  232. #if 0
  233. FrmCameraScreen->TmrFullScreen->Enabled = false;
  234. FrmCameraScreen->FFullScreenIdx = Tag;
  235. FrmCameraScreen->TmrFullScreen->Enabled = true;
  236. #endif
  237. }
  238. //---------------------------------------------------------------------------
  239. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1DblClick(TObject *Sender)
  240. {
  241. FrmCameraScreen->TmrFullScreen->Enabled = false;
  242. FrmCameraScreen->FFullScreenIdx = Tag;
  243. FrmCameraScreen->TmrFullScreen->Enabled = true;
  244. }
  245. //---------------------------------------------------------------------------
  246. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  247. {
  248. FrmCameraInfo = new TFrmCameraInfo(this);
  249. FrmCameraInfo->Edit1->Text = CTLR_NMBR;
  250. FrmCameraInfo->Edit2->Text = NAME;
  251. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  252. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  253. FrmCameraInfo->ShowModal();
  254. delete FrmCameraInfo;
  255. FrmCameraInfo = NULL;
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPlaying(TObject *Sender)
  259. {
  260. // 표출시작
  261. #if 0
  262. if (FConHandle > 0)
  263. {
  264. if (PasLibVlcPlayer1->Visible == false) {
  265. PasLibVlcPlayer1->Visible = true;
  266. }
  267. if (ImgNoData->Visible == true) {
  268. ImgNoData->Visible = false;
  269. }
  270. }
  271. #endif
  272. AdjustVideoFit();
  273. FUserStop = false;
  274. }
  275. //---------------------------------------------------------------------------
  276. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerMediaChanged(TObject *Sender, UnicodeString mrl)
  277. {
  278. // 스트리밍 변경됨
  279. CameraLog("@@@ 영상 연결 중.. @@@");
  280. AdjustVideoFit();
  281. }
  282. //---------------------------------------------------------------------------
  283. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerStopped(TObject *Sender)
  284. {
  285. CameraLog("@@@ 영상 표출이 종료됨 @@@");
  286. if (FAutoPlay && FUserStop) {
  287. if (PasLibVlcPlayer1->Visible) {
  288. PasLibVlcPlayer1->Visible = false;
  289. }
  290. //CameraLog("@@@ 영상 표출 종료 @@@");
  291. }
  292. FPlay = false;
  293. if (FAutoPlay) {
  294. TmrShow->Enabled = false;
  295. TmrShow->Interval = 1000;
  296. TmrShow->Enabled = true;
  297. }
  298. }
  299. //---------------------------------------------------------------------------
  300. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerEncounteredError(TObject *Sender)
  301. {
  302. if (PasLibVlcPlayer1->Visible) {
  303. PasLibVlcPlayer1->Visible = false;
  304. }
  305. CameraLog("@@@ 영상 표출 오류 @@@");
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerOpening(TObject *Sender)
  309. {
  310. #if 0
  311. // 표출시작
  312. if (FConHandle > 0)
  313. {
  314. if (PasLibVlcPlayer1->Visible == false) {
  315. PasLibVlcPlayer1->Visible = true;
  316. }
  317. if (ImgNoData->Visible == true) {
  318. ImgNoData->Visible = false;
  319. }
  320. }
  321. AdjustVideoFit();
  322. #endif
  323. AdjustVideoFit();
  324. }
  325. //---------------------------------------------------------------------------
  326. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPositionChanged(TObject *Sender, float position)
  327. {
  328. if (PasLibVlcPlayer1->Visible == false) {
  329. PasLibVlcPlayer1->Visible = true;
  330. PnlCamera->Refresh();
  331. AdjustVideoFit();
  332. }
  333. if (ImgNoData->Visible == true) {
  334. ImgNoData->Visible = false;
  335. }
  336. }
  337. //---------------------------------------------------------------------------