FRAME_CameraF.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSLangTransF.h"
  5. #pragma hdrstop
  6. #include "FRAME_CameraF.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 link "dxGDIPlusClasses"
  14. #pragma resource "*.dfm"
  15. TFRAMECamera *FRAMECamera;
  16. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  17. #define FFPLAY 0
  18. #define ACES 1
  19. //---------------------------------------------------------------------------
  20. __fastcall TFRAMECamera::TFRAMECamera(TComponent* Owner)
  21. : TFrame(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. bool __fastcall TFRAMECamera::Init(String AMngrNmbr, String ACtlrId, String ACtlrNm, String AStreamUrl)
  26. {
  27. #if FFPLAY
  28. AcesTechXPlayer2->Visible = false;
  29. FFPlayer->SetLicenseKey(LICENSE_KEY);
  30. FFPlayer->DisableFPUExceptions();
  31. #endif
  32. #if ACES
  33. AcesTechXPlayer2->Align = alClient;
  34. AcesTechXPlayer2->Visible = true;
  35. #endif
  36. Disconnect();
  37. PnlTitle->Visible = true;
  38. FMngrNmbr = AMngrNmbr;
  39. FCtlrId = ACtlrId;
  40. FCtlrNm = ACtlrNm;
  41. FStreamUrl = AStreamUrl;
  42. FPlay = false;
  43. FConHandle = 0;
  44. PnlTitle->Caption = FCtlrNm;
  45. PnlStream->Font->Color = clWhite;
  46. #if FFPLAY
  47. String sAVILibDir = g_sAppDir + "LibAV";
  48. if (!FFPlayer->AVLibLoaded())
  49. {
  50. if (!FFPlayer->LoadAVLib(sAVILibDir))
  51. {
  52. PnlTitle->Caption = FCtlrNm + ": 영상표출 라이브러리를 로드 실패!!";
  53. return false;
  54. }
  55. }
  56. #endif
  57. if (FStreamUrl == "") {
  58. PnlTitle->Caption = FCtlrNm + ", Stream URL Empty!";
  59. PnlStream->Caption = "Invalid Stream Address!!!";//영상주소가 설정되지 않았습니다.";
  60. PnlStream->Font->Color = clWhite;
  61. }
  62. ImgDefault->Visible = false;
  63. Timer1->Enabled = true;
  64. return true;
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TFRAMECamera::Timer1Timer(TObject *Sender)
  68. {
  69. Timer1->Enabled = false;
  70. Connect();
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TFRAMECamera::Connect()
  74. {
  75. Disconnect();
  76. try
  77. {
  78. if (FStreamUrl != "") {
  79. PnlStream->Caption = FStreamUrl + ", Connecting...";
  80. PnlTitle->Caption = FCtlrNm;
  81. #if FFPLAY
  82. FFPlayer->AspectRatio = -1;
  83. FFPlayer->TryOpen(FStreamUrl, PnlStream->Handle);
  84. FConHandle = (long)FFPlayer->ScreenHandle;
  85. #endif
  86. #if ACES
  87. AcesTechXPlayer2->URL = FStreamUrl;
  88. FConHandle = AcesTechXPlayer2->ConnectAsync();
  89. if (FConHandle > 0)
  90. {
  91. }
  92. #endif
  93. FPlay = true;
  94. }
  95. Application->ProcessMessages();
  96. }
  97. catch(Exception &e)
  98. {
  99. }
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TFRAMECamera::Disconnect()
  103. {
  104. Timer1->Enabled = false;
  105. if (!FPlay) return;
  106. FPlay = false;
  107. try
  108. {
  109. if (FStreamUrl != "") {
  110. #if FFPLAY
  111. if (FFPlayer->ScreenHandle != NULL)
  112. {
  113. FFPlayer->Stop(true);
  114. PostMessage(FFPlayer->ScreenHandle, CM_INVALIDATE, 0, 0);
  115. UpdateWindow(FFPlayer->ScreenHandle);
  116. FFPlayer->ScreenHandle = NULL;
  117. }
  118. #endif
  119. #if ACES
  120. if (FConHandle > 0)
  121. {
  122. AcesTechXPlayer2->Close();
  123. }
  124. #endif
  125. PnlStream->Caption = "Disconnected";
  126. }
  127. FConHandle = 0;
  128. Application->ProcessMessages();
  129. }
  130. catch(Exception &e)
  131. {
  132. }
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TFRAMECamera::FFPlayerState(TObject *Sender, TPlayState APlayState)
  136. {
  137. enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
  138. if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
  139. {
  140. PnlTitle->Caption = FCtlrNm + " : Disconnected";
  141. Timer1->Enabled = true;
  142. }
  143. }
  144. //---------------------------------------------------------------------------