FrmCameraF.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FrmCameraF.h"
  5. #include "AppGlobalF.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "AcesTechXPlayer2Lib_OCX"
  9. #pragma link "cxContainer"
  10. #pragma link "cxControls"
  11. #pragma link "cxEdit"
  12. #pragma link "cxGraphics"
  13. #pragma link "cxLabel"
  14. #pragma link "cxLookAndFeelPainters"
  15. #pragma link "cxLookAndFeels"
  16. #pragma link "dxSkinsCore"
  17. #pragma link "dxSkinBlack"
  18. #pragma link "dxSkinBlue"
  19. #pragma resource "*.dfm"
  20. TFrmCamera *FrmCamera = NULL;
  21. //---------------------------------------------------------------------------
  22. __fastcall TFrmCamera::TFrmCamera(TComponent* Owner, TXCctv *ACctv, bool AAutoPlay)
  23. : TForm(Owner)
  24. {
  25. FPlay = false;
  26. FAutoPlay = AAutoPlay;
  27. FConHandle = 0;
  28. FInstalled = false;
  29. #if 0
  30. AcesTechXPlayer21 = NULL;
  31. #else
  32. //AcesTechXPlayer21->DoubleBuffered = true;
  33. #endif
  34. InitCamera(ACctv, FAutoPlay);
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TFrmCamera::MnuConnectClick(TObject *Sender)
  38. {
  39. FAutoPlay = true;
  40. Connect();
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TFrmCamera::MnuDisconnectClick(TObject *Sender)
  44. {
  45. FAutoPlay = false;
  46. Disconnect();
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TFrmCamera::MnuReleaseClick(TObject *Sender)
  50. {
  51. CameraRelease();
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TFrmCamera::Connect()
  55. {
  56. Disconnect();
  57. if (FId.IsEmpty()) return;
  58. if (FViewAddress.IsEmpty()) return;
  59. PnlCamera->Caption = "Connect...";
  60. if (AcesTechXPlayer21) AcesTechXPlayer21->Visible = true;
  61. try
  62. {
  63. if (AcesTechXPlayer21)
  64. {
  65. AcesTechXPlayer21->URL = FViewAddress;
  66. FConHandle = AcesTechXPlayer21->ConnectAsync();
  67. }
  68. }
  69. catch(...)
  70. {
  71. }
  72. FPlay = true;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TFrmCamera::Disconnect()
  76. {
  77. if (!FPlay) return;
  78. try
  79. {
  80. //if (FConHandle)
  81. {
  82. if (AcesTechXPlayer21) AcesTechXPlayer21->Close();
  83. }
  84. FConHandle = 0;
  85. }
  86. catch(...)
  87. {
  88. }
  89. PnlCamera->Caption = "Disconnected";
  90. if (AcesTechXPlayer21) AcesTechXPlayer21->Visible = false;
  91. FConHandle = 0;
  92. FPlay = false;
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TFrmCamera::CameraRelease()
  96. {
  97. Disconnect();
  98. PnlCamera->Caption = "";
  99. if (AcesTechXPlayer21) AcesTechXPlayer21->Visible = false;
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TFrmCamera::InitCamera(TXCctv *ACctv, bool AAutoPlay/*=true*/)
  103. {
  104. FAutoPlay = AAutoPlay;
  105. PopupMenu = NULL;
  106. if (!ACctv)
  107. {
  108. FId = "";
  109. FGroup = "";
  110. FName = "";
  111. FStreamingType = "";
  112. FViewAddress = "";
  113. FFullAddress = "";
  114. PnlCamera->Caption = "-Empty-";
  115. DisplayName(" ");
  116. FInstalled = false;
  117. AcesTechXPlayer21->Visible = false;
  118. try
  119. {
  120. String sImageFile = ExtractFilePath(Application->ExeName) + "\\image\\vmscam.bmp";
  121. ImgNoData->Picture->LoadFromFile(sImageFile);
  122. ImgNoData->Align = alClient;
  123. ImgNoData->Visible = true;
  124. LblName->Visible = false;
  125. PnlName->Visible = false;
  126. }
  127. catch(Exception &e)
  128. {
  129. ImgNoData->Visible = false;
  130. }
  131. }
  132. else
  133. {
  134. #if 0
  135. AcesTechXPlayer21 = new TAcesTechXPlayer2(this);
  136. AcesTechXPlayer21->Parent = PnlCamera;
  137. AcesTechXPlayer21->Align = alClient;
  138. //AcesTechXPlayer21->DoubleBuffered = true;
  139. #endif
  140. //AcesTechXPlayer21->Visible = true;
  141. FId = ACctv->Id;
  142. FGroup = ACctv->Group;
  143. FName = "[" + ACctv->CAMID + "] " + ACctv->Name;
  144. FStreamingType = ACctv->StreamingType;
  145. FViewAddress = ACctv->ViewAddress;
  146. FFullAddress = ACctv->FullAddress;
  147. PnlCamera->Caption = "Disconnected";
  148. DisplayName(FName);
  149. FInstalled = true;
  150. if (FViewAddress.IsEmpty())
  151. {
  152. AcesTechXPlayer21->Visible = false;
  153. PnlCamera->Caption = "Streamming Address Error";
  154. }
  155. else
  156. {
  157. PopupMenu = PopupMenu1;
  158. }
  159. }
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TFrmCamera::DisplayName(String AName)
  163. {
  164. PnlName->Caption = " " + FName;
  165. PnlName->Visible = true;
  166. PnlName->Refresh();
  167. LblName->Visible = false;
  168. #if 0
  169. LblName->Caption = FName;
  170. LblName->Transparent = false;
  171. LblName->Transparent = true;
  172. LblName->Visible = true;
  173. LblName->Refresh();
  174. LblName->BringToFront();
  175. #endif
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TFrmCamera::TmrPlayTimer(TObject *Sender)
  179. {
  180. TmrStop->Enabled = false;
  181. TmrPlay->Enabled = false;
  182. Connect();
  183. }
  184. //---------------------------------------------------------------------------
  185. void __fastcall TFrmCamera::TmrStopTimer(TObject *Sender)
  186. {
  187. TmrPlay->Enabled = false;
  188. TmrStop->Enabled = false;
  189. Disconnect();
  190. }
  191. //---------------------------------------------------------------------------