FrmCameraPlayerF.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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::CameraInfo(String ALogInfo)
  136. {
  137. lblRate->Caption = ALogInfo;
  138. lblRate->Refresh();
  139. reMemo->Lines->Add(ALogInfo);
  140. Application->ProcessMessages();
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TFrmCameraPlayer::Play()
  144. {
  145. if (FPlay) return;
  146. if (PasLibVlcPlayer1->Visible) {
  147. PasLibVlcPlayer1->Visible = false;
  148. }
  149. Stop();
  150. if (STRM_ADDR == "") {
  151. CameraLog("### 영상정보가 없습니다 ###");
  152. return;
  153. }
  154. CameraLog("--- 영상 연결 중 ---");
  155. try
  156. {
  157. ///--udp-caching=500 --tcp-caching=500 --realrtsp-caching=500
  158. //ffplay.exe rtsp://224.1.1.1:8086 -fflags nobuffer -flags low_delay -avioflags direct -fflags discardcorrupt
  159. //PasLibVlcPlayer1->VLC->Path = "plugins";
  160. //PasLibVlcPlayer1->VLC->AddOption("http-caching=300");
  161. PasLibVlcPlayer1->VLC->AddOption("live-capture-caching=300");
  162. PasLibVlcPlayer1->VLC->AddOption("file-caching=300");
  163. PasLibVlcPlayer1->VLC->AddOption("disk-caching=300");
  164. PasLibVlcPlayer1->VLC->AddOption("network-caching=300");
  165. //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw=none");
  166. //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw={any,d3d11va,dxva2,none}");
  167. //PasLibVlcPlayer1->VLC->AddOption("avcodec-threads=0");
  168. //PasLibVlcPlayer1->VLC->AddOption("no-sout-all");
  169. //PasLibVlcPlayer1->VLC->AddOption("sout-keep");
  170. //PasLibVlcPlayer1->VLC->AddOption(":file-caching=300");
  171. //PasLibVlcPlayer1->VLC->AddOption(":network-caching=300");
  172. //PasLibVlcPlayer1->VLC->AddOption(":avcodec-hw=none");
  173. //PasLibVlcPlayer1->VLC->AddOption("--avcodec-threads=0");
  174. //PasLibVlcPlayer1->VLC->AddOption(":no-sout-all");
  175. //PasLibVlcPlayer1->VLC->AddOption(":sout-keep");
  176. PasLibVlcPlayer1->Play(STRM_ADDR);
  177. FConHandle = 1;
  178. Application->ProcessMessages();
  179. AdjustVideoFit();
  180. if (FConHandle > 0)
  181. {
  182. if (ImgNoData->Visible == true) {
  183. ImgNoData->Visible = false;
  184. }
  185. }
  186. //PnlName->Caption = libvlc_get_install_path();
  187. Application->ProcessMessages();
  188. }
  189. catch(Exception &e)
  190. {
  191. }
  192. FPlay = true;
  193. }
  194. //---------------------------------------------------------------------------
  195. void __fastcall TFrmCameraPlayer::Stop()
  196. {
  197. if (!FPlay) return;
  198. FPlay = false;
  199. if (STRM_ADDR == "") {
  200. return;
  201. }
  202. CameraLog("--- 영상 연결 해제 ---");
  203. try
  204. {
  205. if (FConHandle > 0)
  206. {
  207. PasLibVlcPlayer1->Stop();
  208. }
  209. Application->ProcessMessages();
  210. FConHandle = 0;
  211. }
  212. catch(Exception &e)
  213. {
  214. }
  215. CameraLog("*** 영상 연결 종료 ***");
  216. FConHandle = 0;
  217. FPlay = false;
  218. }
  219. //---------------------------------------------------------------------------
  220. void __fastcall TFrmCameraPlayer::AdjustVideoFit()
  221. {
  222. try {
  223. if (FConHandle > 0 && PasLibVlcPlayer1->IsPlay()) {
  224. String ratioData = IntToStr(PasLibVlcPlayer1->Width) + ":" + IntToStr(PasLibVlcPlayer1->Height);
  225. PasLibVlcPlayer1->SetVideoAspectRatio(ratioData);
  226. }
  227. }
  228. catch(Exception &e) {
  229. }
  230. }
  231. //---------------------------------------------------------------------------
  232. void __fastcall TFrmCameraPlayer::Term()
  233. {
  234. IsTerm = true;
  235. Stop();
  236. }
  237. //---------------------------------------------------------------------------
  238. void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
  239. {
  240. FAutoPlay = true;
  241. Installed = AInstalled;
  242. CTLR_NMBR = ACtlrNmbr;
  243. NAME = AName;
  244. STRM_ADDR = AStrmAddr;
  245. FULL_STRM_ADDR = AFullStrmAddr;
  246. VIEW_MODE = AViewMode;
  247. Caption = NAME;
  248. PnlName->Caption = NAME;
  249. PnlCamera->Caption = AStrmAddr;
  250. FUserStop = false;
  251. }
  252. //---------------------------------------------------------------------------
  253. void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
  254. {
  255. // 여기서 더블클릭은 최대화면을 호출하는 것임
  256. #if 0
  257. FrmCameraScreen->TmrFullScreen->Enabled = false;
  258. FrmCameraScreen->FFullScreenIdx = Tag;
  259. FrmCameraScreen->TmrFullScreen->Enabled = true;
  260. #endif
  261. }
  262. //---------------------------------------------------------------------------
  263. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1DblClick(TObject *Sender)
  264. {
  265. FrmCameraScreen->TmrFullScreen->Enabled = false;
  266. FrmCameraScreen->FFullScreenIdx = Tag;
  267. FrmCameraScreen->TmrFullScreen->Enabled = true;
  268. }
  269. //---------------------------------------------------------------------------
  270. void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
  271. {
  272. FrmCameraInfo = new TFrmCameraInfo(this);
  273. FrmCameraInfo->Edit1->Text = CTLR_NMBR;
  274. FrmCameraInfo->Edit2->Text = NAME;
  275. FrmCameraInfo->Edit3->Text = STRM_ADDR;
  276. FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
  277. FrmCameraInfo->ShowModal();
  278. delete FrmCameraInfo;
  279. FrmCameraInfo = NULL;
  280. }
  281. //---------------------------------------------------------------------------
  282. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPlaying(TObject *Sender)
  283. {
  284. // 표출시작
  285. #if 0
  286. if (FConHandle > 0)
  287. {
  288. if (PasLibVlcPlayer1->Visible == false) {
  289. PasLibVlcPlayer1->Visible = true;
  290. }
  291. if (ImgNoData->Visible == true) {
  292. ImgNoData->Visible = false;
  293. }
  294. }
  295. #endif
  296. AdjustVideoFit();
  297. FUserStop = false;
  298. }
  299. //---------------------------------------------------------------------------
  300. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerMediaChanged(TObject *Sender, UnicodeString mrl)
  301. {
  302. // 스트리밍 변경됨
  303. CameraLog("@@@ 영상 연결 중.. @@@");
  304. AdjustVideoFit();
  305. }
  306. //---------------------------------------------------------------------------
  307. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerStopped(TObject *Sender)
  308. {
  309. CameraLog("@@@ 영상 표출이 종료됨 @@@");
  310. if (FAutoPlay && FUserStop) {
  311. if (PasLibVlcPlayer1->Visible) {
  312. PasLibVlcPlayer1->Visible = false;
  313. }
  314. //CameraLog("@@@ 영상 표출 종료 @@@");
  315. }
  316. FPlay = false;
  317. if (FAutoPlay) {
  318. TmrShow->Enabled = false;
  319. TmrShow->Interval = 1000;
  320. TmrShow->Enabled = true;
  321. }
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerEncounteredError(TObject *Sender)
  325. {
  326. if (PasLibVlcPlayer1->Visible) {
  327. PasLibVlcPlayer1->Visible = false;
  328. }
  329. CameraLog("@@@ 영상 표출 오류 @@@");
  330. }
  331. //---------------------------------------------------------------------------
  332. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerOpening(TObject *Sender)
  333. {
  334. if (PasLibVlcPlayer1->Visible == false) {
  335. PasLibVlcPlayer1->Visible = true;
  336. PnlCamera->Refresh();
  337. AdjustVideoFit();
  338. }
  339. if (ImgNoData->Visible == true) {
  340. ImgNoData->Visible = false;
  341. }
  342. CameraInfo("PlayerOpening");
  343. #if 0
  344. // 표출시작
  345. if (FConHandle > 0)
  346. {
  347. if (PasLibVlcPlayer1->Visible == false) {
  348. PasLibVlcPlayer1->Visible = true;
  349. }
  350. if (ImgNoData->Visible == true) {
  351. ImgNoData->Visible = false;
  352. }
  353. }
  354. AdjustVideoFit();
  355. #endif
  356. // 영상이 연결됨
  357. AdjustVideoFit();
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPositionChanged(TObject *Sender, float position)
  361. {
  362. #if 0
  363. if (PasLibVlcPlayer1->Visible == false) {
  364. PasLibVlcPlayer1->Visible = true;
  365. PnlCamera->Refresh();
  366. AdjustVideoFit();
  367. }
  368. if (ImgNoData->Visible == true) {
  369. ImgNoData->Visible = false;
  370. }
  371. CameraInfo("Changed: " + String(position) + ", " + String(PasLibVlcPlayer1->GetState()));
  372. #endif
  373. #if 0
  374. case PasLibVlcPlayer1.GetState() of
  375. plvPlayer_NothingSpecial: stateName := 'Idle';
  376. plvPlayer_Opening: stateName := 'Opening';
  377. plvPlayer_Buffering: stateName := 'Buffering';
  378. plvPlayer_Playing: stateName := 'Playing';
  379. plvPlayer_Paused: stateName := 'Paused';
  380. plvPlayer_Stopped: stateName := 'Stopped';
  381. plvPlayer_Ended: stateName := 'Ended';
  382. plvPlayer_Error: stateName := 'Error';
  383. else stateName := 'Unknown';
  384. end;
  385. var
  386. info : string;
  387. sar_num, sar_den : LongWord;
  388. begin
  389. info := 'Aspect ratio = ' + PasLibVlcPlayer1.GetVideoAspectRatio();
  390. if (PasLibVlcPlayer1.GetVideoSampleAspectRatio(sar_num, sar_den)) then
  391. begin
  392. info := info + ', SampleAspectRatio = ' + IntToStr(sar_num) + ':' + IntToStr(sar_den);
  393. end;
  394. MessageDlg(
  395. info,
  396. mtInformation, [mbOK], 0);
  397. end;
  398. 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'
  399. #endif
  400. }
  401. //---------------------------------------------------------------------------
  402. void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerTimeChanged(TObject *Sender, __int64 time)
  403. {
  404. CameraInfo("TimeChanged: " + String(time));
  405. }
  406. //---------------------------------------------------------------------------