FrmCrsCmraF.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSLangTransF.h"
  5. #pragma hdrstop
  6. #include "FrmCrsCmraF.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma link "AcesTechXPlayer2Lib_OCX"
  10. #pragma link "FFBaseComponent"
  11. #pragma link "FFBasePlay"
  12. #pragma link "FFPlay"
  13. #pragma resource "*.dfm"
  14. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  15. //TFrmCrsCamra *FrmCrsCamra;
  16. //---------------------------------------------------------------------------
  17. __fastcall TFrmCrsCamra::TFrmCrsCamra(TComponent* Owner, TCrossCam *ACmra)
  18. : TForm(Owner)
  19. {
  20. FCmra = ACmra;
  21. FPlay = false;
  22. if (FCmra == NULL) {
  23. PnlTitle->Visible = false;
  24. }
  25. #if FFPLAY
  26. AcesTechXPlayer2->Visible = false;
  27. FFPlayer->SetLicenseKey(LICENSE_KEY);
  28. FFPlayer->DisableFPUExceptions();
  29. #endif
  30. #if ACES
  31. AcesTechXPlayer2->Align = alClient;
  32. AcesTechXPlayer2->Visible = true;
  33. #endif
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TFrmCrsCamra::FormClose(TObject *Sender, TCloseAction &Action)
  37. {
  38. Action = caFree;
  39. }
  40. //---------------------------------------------------------------------------
  41. void __fastcall TFrmCrsCamra::FormDestroy(TObject *Sender)
  42. {
  43. Disconnect();
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TFrmCrsCamra::FFPlayerState(TObject *Sender, TPlayState APlayState)
  47. {
  48. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  49. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  50. {
  51. PnlTitle->Caption = FCmra->CAM_NM + " : Disconnected";
  52. Timer1->Enabled = true;
  53. }
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TFrmCrsCamra::FormShow(TObject *Sender)
  57. {
  58. Refresh();
  59. if (FCmra == NULL)
  60. {
  61. return;
  62. }
  63. PnlTitle->Caption = FCmra->CAM_NM;
  64. if (FCmra->RTSP_URL == "")
  65. {
  66. return;
  67. }
  68. #if FFPLAY
  69. String sAVILibDir = g_sAppDir + "LibAV";
  70. if (!FFPlayer->AVLibLoaded())
  71. {
  72. if (!FFPlayer->LoadAVLib(sAVILibDir))
  73. {
  74. PnlTitle->Caption = FCmra->CAM_NM + ": 영상표출 라이브러리를 로드 실패!!";
  75. return;
  76. }
  77. }
  78. #endif
  79. Timer1->Enabled = true;
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TFrmCrsCamra::Timer1Timer(TObject *Sender)
  83. {
  84. Timer1->Enabled = false;
  85. Connect();
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TFrmCrsCamra::Connect()
  89. {
  90. Disconnect();
  91. try
  92. {
  93. PnlStream->Caption = "Connecting...";
  94. PnlTitle->Caption = FCmra->CAM_NM;
  95. #if FFPLAY
  96. FFPlayer->AspectRatio = -1;
  97. FFPlayer->TryOpen(FCmra->RTSP_URL, PnlStream->Handle);
  98. FConHandle = (long)FFPlayer->ScreenHandle;
  99. #endif
  100. #if ACES
  101. AcesTechXPlayer2->URL = FCmra->RTSP_URL;
  102. FConHandle = AcesTechXPlayer2->ConnectAsync();
  103. if (FConHandle > 0)
  104. {
  105. }
  106. #endif
  107. FPlay = true;
  108. Application->ProcessMessages();
  109. }
  110. catch(Exception &e)
  111. {
  112. }
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TFrmCrsCamra::Disconnect()
  116. {
  117. if (!FPlay) return;
  118. FPlay = false;
  119. try
  120. {
  121. #if FFPLAY
  122. if (FFPlayer->ScreenHandle != NULL)
  123. {
  124. FFPlayer->Stop(true);
  125. PostMessage(FFPlayer->ScreenHandle, CM_INVALIDATE, 0, 0);
  126. UpdateWindow(FFPlayer->ScreenHandle);
  127. FFPlayer->ScreenHandle = NULL;
  128. }
  129. #endif
  130. #if ACES
  131. if (FConHandle > 0)
  132. {
  133. AcesTechXPlayer2->Close();
  134. }
  135. #endif
  136. FConHandle = 0;
  137. PnlStream->Caption = "Disconnected";
  138. Application->ProcessMessages();
  139. }
  140. catch(Exception &e)
  141. {
  142. }
  143. }
  144. //---------------------------------------------------------------------------