FrmCameraPlayerF.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. PnlName->Caption = " " + NAME;
  42. Play();
  43. }
  44. else
  45. {
  46. PasLibVlcPlayer1->Visible = false;
  47. PopupMenu = NULL;
  48. PnlCamera->Caption = " " + NAME;
  49. LoadEmptyImage();
  50. }
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TFrmCameraPlayer::LoadEmptyImage()
  54. {
  55. try
  56. {
  57. #if 0
  58. String sImageFile = g_AppCfg.sEmptyImg;
  59. if (sImageFile != "")
  60. {
  61. ImgNoData->Picture->LoadFromFile(sImageFile);
  62. ImgNoData->Align = alClient;
  63. }
  64. #endif
  65. ImgNoData->Visible = true;
  66. }
  67. catch(Exception &e)
  68. {
  69. ImgNoData->Visible = true;
  70. }
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TFrmCameraPlayer::FormShow(TObject *Sender)
  74. {
  75. Refresh();
  76. this->FLastBounds = this->BoundsRect;
  77. // TmrShow->Enabled = true;
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TFrmCameraPlayer::FormClose(TObject *Sender, TCloseAction &Action)
  81. {
  82. try {
  83. FAutoPlay = false;
  84. Stop();
  85. } catch(...) {}
  86. Action = caFree;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
  90. {
  91. try {
  92. FAutoPlay = false;
  93. Stop();
  94. } catch(...) {}
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
  98. {
  99. FUserStop = true;
  100. Play();
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
  104. {
  105. PasLibVlcPlayer1->Visible = false;
  106. PasLibVlcPlayer1->Refresh();
  107. PnlCamera->Refresh();
  108. FUserStop = true;
  109. FAutoPlay = false;
  110. Stop();
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TFrmCameraPlayer::AutoPlay()
  114. {
  115. FAutoPlay = true;
  116. TmrShow->Enabled = true;
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TFrmCameraPlayer::CameraLog(String ALogMsg)
  120. {
  121. PnlCamera->Caption = ALogMsg;
  122. PnlCamera->Refresh();
  123. #if 0
  124. AnsiString strmAddr = AnsiString(STRM_ADDR);
  125. if (strmAddr == "") {
  126. strmAddr = "Empty Addr";
  127. }
  128. AnsiString sAutoPlay = FAutoPlay ? "AutoPlay:True" : "AutoPlay:False";
  129. AnsiString sUserStop = FUserStop ? "UserStop:True" : "UserStop:False";
  130. LOGINFO("%s,%s, %s: %s", sAutoPlay.c_str(), sUserStop.c_str(), strmAddr.c_str(), AnsiString(ALogMsg).c_str());
  131. #endif
  132. Application->ProcessMessages();
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TFrmCameraPlayer::Play()
  136. {
  137. if (FPlay) return;
  138. if (PasLibVlcPlayer1->Visible) {
  139. PasLibVlcPlayer1->Visible = false;
  140. }
  141. Stop();
  142. if (STRM_ADDR == "") {
  143. CameraLog("### 영상정보가 없습니다 ###");
  144. return;
  145. }
  146. CameraLog("--- 영상 연결 중 ---");
  147. try
  148. {
  149. ///--udp-caching=500 --tcp-caching=500 --realrtsp-caching=500
  150. //ffplay.exe rtsp://224.1.1.1:8086 -fflags nobuffer -flags low_delay -avioflags direct -fflags discardcorrupt
  151. //PasLibVlcPlayer1->VLC->Path = "plugins";
  152. //PasLibVlcPlayer1->VLC->AddOption("http-caching=300");
  153. PasLibVlcPlayer1->VLC->AddOption("live-capture-caching=300");
  154. PasLibVlcPlayer1->VLC->AddOption("file-caching=300");
  155. PasLibVlcPlayer1->VLC->AddOption("disk-caching=300");
  156. PasLibVlcPlayer1->VLC->AddOption("network-caching=300");
  157. //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw=none");
  158. //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw={any,d3d11va,dxva2,none}");
  159. //PasLibVlcPlayer1->VLC->AddOption("avcodec-threads=0");
  160. //PasLibVlcPlayer1->VLC->AddOption("no-sout-all");
  161. //PasLibVlcPlayer1->VLC->AddOption("sout-keep");
  162. //PasLibVlcPlayer1->VLC->AddOption(":file-caching=300");
  163. //PasLibVlcPlayer1->VLC->AddOption(":network-caching=300");
  164. //PasLibVlcPlayer1->VLC->AddOption(":avcodec-hw=none");
  165. //PasLibVlcPlayer1->VLC->AddOption("--avcodec-threads=0");
  166. //PasLibVlcPlayer1->VLC->AddOption(":no-sout-all");
  167. //PasLibVlcPlayer1->VLC->AddOption(":sout-keep");
  168. PasLibVlcPlayer1->Play(STRM_ADDR);
  169. FConHandle = 1;
  170. Application->ProcessMessages();
  171. AdjustVideoFit();
  172. if (FConHandle > 0)
  173. {
  174. if (ImgNoData->Visible == true) {
  175. ImgNoData->Visible = false;
  176. }
  177. }
  178. //PnlName->Caption = libvlc_get_install_path();
  179. Application->ProcessMessages();
  180. }
  181. catch(Exception &e)
  182. {
  183. }
  184. FPlay = true;
  185. }
  186. //---------------------------------------------------------------------------
  187. void __fastcall TFrmCameraPlayer::Stop()
  188. {
  189. if (!FPlay) return;
  190. FPlay = false;
  191. if (STRM_ADDR == "") {
  192. return;
  193. }
  194. CameraLog("--- 영상 연결 해제 ---");
  195. try
  196. {
  197. if (FConHandle > 0)
  198. {
  199. PasLibVlcPlayer1->Stop();
  200. }
  201. Application->ProcessMessages();
  202. FConHandle = 0;
  203. }
  204. catch(Exception &e)
  205. {
  206. }
  207. CameraLog("*** 영상 연결 종료 ***");
  208. FConHandle = 0;
  209. FPlay = false;
  210. }
  211. //---------------------------------------------------------------------------
  212. void __fastcall TFrmCameraPlayer::AdjustVideoFit()
  213. {
  214. try {
  215. if (FConHandle > 0 && PasLibVlcPlayer1->IsPlay()) {
  216. String ratioData = IntToStr(PasLibVlcPlayer1->Width) + ":" + IntToStr(PasLibVlcPlayer1->Height);
  217. PasLibVlcPlayer1->SetVideoAspectRatio(ratioData);
  218. }
  219. }
  220. catch(Exception &e) {
  221. }
  222. }
  223. //---------------------------------------------------------------------------
  224. void __fastcall TFrmCameraPlayer::Term()
  225. {
  226. IsTerm = true;
  227. Stop();
  228. }
  229. //---------------------------------------------------------------------------
  230. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
  231. {
  232. FAutoPlay = true;
  233. Installed = AInstalled;
  234. CTLR_NMBR = ACtlrNmbr;
  235. NAME = AName;
  236. STRM_ADDR = AStrmAddr;
  237. FULL_STRM_ADDR = AFullStrmAddr;
  238. VIEW_MODE = AViewMode;
  239. Caption = NAME;
  240. PnlName->Caption = NAME;
  241. PnlCamera->Caption = AStrmAddr;
  242. FUserStop = false;
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
  246. {
  247. // 여기서 더블클릭은 최대화면을 호출하는 것임
  248. #if 0
  249. FrmCameraScreen->TmrFullScreen->Enabled = false;
  250. FrmCameraScreen->FFullScreenIdx = Tag;
  251. FrmCameraScreen->TmrFullScreen->Enabled = true;
  252. #endif
  253. }
  254. //---------------------------------------------------------------------------
  255. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1DblClick(TObject *Sender)
  256. {
  257. FrmCameraScreen->TmrFullScreen->Enabled = false;
  258. FrmCameraScreen->FFullScreenIdx = Tag;
  259. FrmCameraScreen->TmrFullScreen->Enabled = true;
  260. }
  261. //---------------------------------------------------------------------------
  262. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  263. {
  264. FrmCameraInfo = new TFrmCameraInfo(this);
  265. FrmCameraInfo->Edit1->Text = CTLR_NMBR;
  266. FrmCameraInfo->Edit2->Text = NAME;
  267. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  268. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  269. FrmCameraInfo->ShowModal();
  270. delete FrmCameraInfo;
  271. FrmCameraInfo = NULL;
  272. }
  273. //---------------------------------------------------------------------------
  274. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPlaying(TObject *Sender)
  275. {
  276. // 표출시작
  277. #if 0
  278. if (FConHandle > 0)
  279. {
  280. if (PasLibVlcPlayer1->Visible == false) {
  281. PasLibVlcPlayer1->Visible = true;
  282. }
  283. if (ImgNoData->Visible == true) {
  284. ImgNoData->Visible = false;
  285. }
  286. }
  287. #endif
  288. AdjustVideoFit();
  289. FUserStop = false;
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerMediaChanged(TObject *Sender, UnicodeString mrl)
  293. {
  294. // 스트리밍 변경됨
  295. CameraLog("@@@ 영상 연결 중.. @@@");
  296. AdjustVideoFit();
  297. }
  298. //---------------------------------------------------------------------------
  299. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerStopped(TObject *Sender)
  300. {
  301. CameraLog("@@@ 영상 표출이 종료됨 @@@");
  302. if (FAutoPlay && FUserStop) {
  303. if (PasLibVlcPlayer1->Visible) {
  304. PasLibVlcPlayer1->Visible = false;
  305. }
  306. //CameraLog("@@@ 영상 표출 종료 @@@");
  307. }
  308. FPlay = false;
  309. if (FAutoPlay) {
  310. TmrShow->Enabled = false;
  311. TmrShow->Interval = 1000;
  312. TmrShow->Enabled = true;
  313. }
  314. }
  315. //---------------------------------------------------------------------------
  316. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerEncounteredError(TObject *Sender)
  317. {
  318. if (PasLibVlcPlayer1->Visible) {
  319. PasLibVlcPlayer1->Visible = false;
  320. }
  321. CameraLog("@@@ 영상 표출 오류 @@@");
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerOpening(TObject *Sender)
  325. {
  326. #if 0
  327. // 표출시작
  328. if (FConHandle > 0)
  329. {
  330. if (PasLibVlcPlayer1->Visible == false) {
  331. PasLibVlcPlayer1->Visible = true;
  332. }
  333. if (ImgNoData->Visible == true) {
  334. ImgNoData->Visible = false;
  335. }
  336. }
  337. AdjustVideoFit();
  338. #endif
  339. AdjustVideoFit();
  340. }
  341. //---------------------------------------------------------------------------
  342. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPositionChanged(TObject *Sender, float position)
  343. {
  344. if (PasLibVlcPlayer1->Visible == false) {
  345. PasLibVlcPlayer1->Visible = true;
  346. PnlCamera->Refresh();
  347. AdjustVideoFit();
  348. }
  349. if (ImgNoData->Visible == true) {
  350. ImgNoData->Visible = false;
  351. }
  352. #if 0
  353. case PasLibVlcPlayer1.GetState() of
  354. plvPlayer_NothingSpecial: stateName := 'Idle';
  355. plvPlayer_Opening: stateName := 'Opening';
  356. plvPlayer_Buffering: stateName := 'Buffering';
  357. plvPlayer_Playing: stateName := 'Playing';
  358. plvPlayer_Paused: stateName := 'Paused';
  359. plvPlayer_Stopped: stateName := 'Stopped';
  360. plvPlayer_Ended: stateName := 'Ended';
  361. plvPlayer_Error: stateName := 'Error';
  362. else stateName := 'Unknown';
  363. end;
  364. var
  365. info : string;
  366. sar_num, sar_den : LongWord;
  367. begin
  368. info := 'Aspect ratio = ' + PasLibVlcPlayer1.GetVideoAspectRatio();
  369. if (PasLibVlcPlayer1.GetVideoSampleAspectRatio(sar_num, sar_den)) then
  370. begin
  371. info := info + ', SampleAspectRatio = ' + IntToStr(sar_num) + ':' + IntToStr(sar_den);
  372. end;
  373. MessageDlg(
  374. info,
  375. mtInformation, [mbOK], 0);
  376. end;
  377. main libvlc debug: configured with /builds/videolan/vlc/extras/package/win32/../../../configure '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-shout' '--enable-goom' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=i686-w64-mingw32' '--with-contrib=../contrib/i686-w64-mingw32' '--with-breakpad=https://win.crashes.videolan.org' '--enable-qt' '--enable-skins2' '--enable-dvdread' '--enable-caca' 'host_alias=i686-w64-mingw32' 'CFLAGS= -D_WIN32_WINNT=0x0502 -DWINVER=0x502 -D__MSVCRT_VERSION__=0x700 ' 'CXXFLAGS= -D_WIN32_WINNT=0x0502 -DWINVER=0x502 -D__MSVCRT_VERSION__=0x700 ' 'PKG_CONFIG=pkg-config' 'PKG_CONFIG_LIBDIR=/usr/i686-w64-mingw32/lib/pkgconfig:/usr/lib/i686-w64-mingw32/pkgconfig'
  378. #endif
  379. }
  380. //---------------------------------------------------------------------------