FrmIcsCameraF.cpp 5.6 KB

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