FRAME_CameraF.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSLangTransF.h"
  5. #pragma hdrstop
  6. #include "FRAME_CameraF.h"
  7. #include "FrmCameraScreenF.h"
  8. #include "FrmCameraInfoF.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "FFBaseComponent"
  12. #pragma link "FFBasePlay"
  13. #pragma link "FFPlay"
  14. #pragma link "dxGDIPlusClasses"
  15. #pragma resource "*.dfm"
  16. TFRAMECamera *FRAMECamera;
  17. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  18. #define FFPLAY 1
  19. //---------------------------------------------------------------------------
  20. __fastcall TFRAMECamera::TFRAMECamera(TComponent* Owner)
  21. : TFrame(Owner)
  22. {
  23. FPlay = false;
  24. FAutoPlay = true;
  25. FConHandle = 0;
  26. FFullScreen = false;
  27. FParent = this->Parent;
  28. PnlStream->Tag = (int)this;
  29. FCrsCam = NULL;
  30. PnlStream->Font->Color = clWhite;
  31. FFPlayer->SetLicenseKey(LICENSE_KEY);
  32. FFPlayer->DisableFPUExceptions();
  33. String sAVILibDir = g_sAppDir + "LibAV";
  34. if (!FFPlayer->AVLibLoaded())
  35. {
  36. if (!FFPlayer->LoadAVLib(sAVILibDir))
  37. {
  38. PnlTitle->Caption = FCtlrNm + ": 영상표출 라이브러리를 로드 실패!!";
  39. }
  40. }
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TFRAMECamera::LoadEmptyImage()
  44. {
  45. try {
  46. String sImageFile = g_sAppDir + "Image\\crs_empty.bmp";
  47. if (FileExists(sImageFile)) {
  48. ImgNoData->Picture->LoadFromFile(sImageFile);
  49. ImgNoData->Align = alClient;
  50. //ImgNoData->Visible = true;
  51. }
  52. else {
  53. sImageFile = g_AppCfg.sEmptyImg;
  54. if (sImageFile != "") {
  55. ImgNoData->Picture->LoadFromFile(sImageFile);
  56. ImgNoData->Align = alClient;
  57. //ImgNoData->Visible = true;
  58. }
  59. }
  60. } catch(Exception &e) {
  61. //ImgNoData->Visible = true;
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. bool __fastcall TFRAMECamera::Init(TScreenCtlr *ACrsCam, String AMngrNmbr, String ACtlrId, String ACtlrNm, String AStreamUrl)
  66. {
  67. if (FCrsCam != NULL) {
  68. Disconnect();
  69. }
  70. FPlay = false;
  71. FAutoPlay = true;
  72. FConHandle = 0;
  73. FFullScreen = false;
  74. FCrsCam = ACrsCam;
  75. FMngrNmbr = AMngrNmbr;
  76. FCtlrId = ACtlrId;
  77. FCtlrNm = ACtlrNm;
  78. FStreamUrl = AStreamUrl;
  79. FPlay = false;
  80. FConHandle = 0;
  81. PnlTitle->Caption = FCtlrNm;
  82. PnlStream->Caption = "";
  83. PopupMenu = NULL;
  84. if (FCrsCam != NULL) {
  85. if (FStreamUrl == "") {
  86. PnlTitle->Caption = FCtlrNm + ", Stream URL Empty!";
  87. PnlStream->Caption = "Invalid Stream Address!!!";//영상주소가 설정되지 않았습니다.";
  88. PnlTitle->Visible = true;
  89. Timer1->Enabled = false;
  90. ImgNoData->Visible = false;
  91. }
  92. else {
  93. PnlStream->Caption = "";
  94. PnlTitle->Visible = true;
  95. Timer1->Enabled = true;
  96. ImgNoData->Visible = false;
  97. PopupMenu = PopupMenu1;
  98. }
  99. }
  100. else {
  101. PnlTitle->Visible = false;
  102. Timer1->Enabled = false;
  103. ImgNoData->Visible = true;
  104. }
  105. return true;
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TFRAMECamera::Timer1Timer(TObject *Sender)
  109. {
  110. Timer1->Enabled = false;
  111. Connect();
  112. }
  113. //---------------------------------------------------------------------------
  114. void __fastcall TFRAMECamera::Connect()
  115. {
  116. Disconnect();
  117. try
  118. {
  119. if (FStreamUrl != "") {
  120. PnlStream->Caption = FStreamUrl + ", Connecting...";
  121. PnlTitle->Caption = FCtlrNm;
  122. FFPlayer->AspectRatio = -1;
  123. FFPlayer->TryOpen(FStreamUrl, PnlStream->Handle);
  124. FConHandle = (long)FFPlayer->ScreenHandle;
  125. FPlay = true;
  126. }
  127. Application->ProcessMessages();
  128. }
  129. catch(Exception &e) {
  130. }
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TFRAMECamera::Disconnect()
  134. {
  135. Timer1->Enabled = false;
  136. if (!FPlay) return;
  137. FPlay = false;
  138. try {
  139. if (FStreamUrl != "") {
  140. if (FFPlayer->ScreenHandle != NULL)
  141. {
  142. FFPlayer->Stop(true);
  143. PostMessage(FFPlayer->ScreenHandle, CM_INVALIDATE, 0, 0);
  144. UpdateWindow(FFPlayer->ScreenHandle);
  145. FFPlayer->ScreenHandle = NULL;
  146. }
  147. PnlStream->Caption = "Disconnected";
  148. }
  149. FConHandle = 0;
  150. Application->ProcessMessages();
  151. }
  152. catch(Exception &e) {
  153. }
  154. }
  155. //---------------------------------------------------------------------------
  156. void __fastcall TFRAMECamera::FFPlayerState(TObject *Sender, TPlayState APlayState)
  157. {
  158. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  159. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd) {
  160. PnlTitle->Caption = FCtlrNm + " : Disconnected";
  161. Timer1->Enabled = true;
  162. }
  163. }
  164. //---------------------------------------------------------------------------
  165. void __fastcall TFRAMECamera::MnuFullScreenClick(TObject *Sender)
  166. {
  167. TMenuItem *pMenuItem = (TMenuItem*)Sender;
  168. if (FCrsCam != NULL) {
  169. if (pMenuItem->Tag == 0) {
  170. Disconnect();
  171. Connect();
  172. }
  173. else if (pMenuItem->Tag == 1) {
  174. Disconnect();
  175. }
  176. else if (pMenuItem->Tag == 2) {
  177. if (FCrsCam != NULL) {
  178. FrmCameraScreen->TmrFullScreen->Enabled = false;
  179. FrmCameraScreen->FFullCrsCam = FCrsCam;
  180. FrmCameraScreen->TmrFullScreen->Enabled = true;
  181. }
  182. }
  183. else if (pMenuItem->Tag == 3) {
  184. FrmCameraInfo = new TFrmCameraInfo(this);
  185. FrmCameraInfo->Edit1->Text = FCrsCam->CAM_ID;
  186. FrmCameraInfo->Edit2->Text = FCrsCam->CAM_NAME;
  187. FrmCameraInfo->Edit3->Text = FCrsCam->STRM_ADDR;
  188. FrmCameraInfo->Edit4->Text = FCrsCam->FULL_STRM_ADDR;
  189. FrmCameraInfo->ShowModal();
  190. FrmCameraInfo = NULL;
  191. }
  192. }
  193. }
  194. //---------------------------------------------------------------------------
  195. void __fastcall TFRAMECamera::PnlStreamDblClick(TObject *Sender)
  196. {
  197. if (FCrsCam != NULL) {
  198. FrmCameraScreen->TmrFullScreen->Enabled = false;
  199. FrmCameraScreen->FFullCrsCam = FCrsCam;
  200. FrmCameraScreen->TmrFullScreen->Enabled = true;
  201. }
  202. }
  203. //---------------------------------------------------------------------------