123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include "AppGlobalF.h"
- #include "ITSLangTransF.h"
- #pragma hdrstop
- #include "FrmFullScreenF.h"
- #include "FrmStreamPlayerF.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "FFBaseComponent"
- #pragma link "FFBasePlay"
- #pragma link "FFPlay"
- #pragma link "cxContainer"
- #pragma link "cxControls"
- #pragma link "cxEdit"
- #pragma link "cxGraphics"
- #pragma link "cxLabel"
- #pragma link "cxLookAndFeelPainters"
- #pragma link "cxLookAndFeels"
- #pragma link "dxSkinBlack"
- #pragma link "dxSkinBlue"
- #pragma link "dxSkinsCore"
- #pragma resource "*.dfm"
- #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
- //TFrmStreamPlayer *FrmStreamPlayer;
- //---------------------------------------------------------------------------
- __fastcall TFrmStreamPlayer::TFrmStreamPlayer(TComponent* Owner)
- : TForm(Owner)
- {
- LangTrans->Translate(this, ITSDb_GetConnection());
- FObj.Installed = false;
- FObj.IsCctv = false;
- FObj.Data = NULL;
- PnlBlob->Visible = false;
- PnlBlob->Align = alClient;
- FDispBlob = false;
- FPlay = false;
- FAutoPlay = true;
- FConHandle = 0;
- FFullScreen = false;
- InitCamera(NULL, FAutoPlay);
- FParent = this->Parent;
- PnlStream->Tag = (int)this;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::TmrShowTimer(TObject *Sender)
- {
- TmrShow->Enabled = false;
- if (FObj.Installed)
- {
- Caption = FObj.ID + ": " + FObj.NAME;
- if (FDispBlob == false)
- {
- Connect();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::FormShow(TObject *Sender)
- {
- if (FObj.Installed) PnlStream->Caption = FObj.NAME;
- else PnlStream->Caption = "";
- Refresh();
- this->FLastBounds = this->BoundsRect;
- //CCTV영상인 경우 대체영상 표출 여부 확인
- RefreshPlayer();
- if (PnlStream->Visible)
- {
- FFPlayer1->SetLicenseKey(LICENSE_KEY);
- FFPlayer1->DisableFPUExceptions();
- if (!FFPlayer1->AVLibLoaded())
- {
- String sAVILibDir = g_sAppDir + "LibAV";
- if (!FFPlayer1->LoadAVLib(sAVILibDir))
- {
- Application->MessageBox(lblErr1->Caption.c_str(),//L"영상표출 라이브러리를 로드하지 못하였습니다.",
- lblErr2->Caption.c_str(),//L"영상표출 오류",
- MB_OK|MB_ICONERROR|MB_APPLMODAL);
- return;
- }
- }
- }
- TmrShow->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::FormClose(TObject *Sender, TCloseAction &Action)
- {
- try {
- Disconnect();
- if (FObj.Data) FObj.Data->FData1 = NULL;
- } catch(...) {}
- Action = caFree;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::FormDestroy(TObject *Sender)
- {
- try {
- Disconnect();
- if (FObj.Data) FObj.Data->FData1 = NULL;
- } catch(...) {}
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::RefreshPlayer()
- {
- FDispBlob = false;
- PnlBlob->Visible = false;
- if (FObj.IsCctv == false) return;
- String sQry;
- sQry = "SELECT CCTV_SBST_DSPL_YN, CCTV_SBST_IMGN \r\n"
- " FROM TB_CCTV_CTLR \r\n"
- " WHERE CCTV_CTLR_ID = :p01 \r\n";
- try
- {
- pADO->Close();
- pADO->SQL->Clear();
- pADO->Connection = ITSDb_GetConnection();
- pADO->SQL->Text = sQry;
- pADO->Parameters->ParamByName("p01")->Value = FObj.ID;
- pADO->Prepared = true;
- pADO->Open();
- }
- catch(EDatabaseError &E)
- {
- PnlBlob->Caption = lblErr3->Caption;//"대체영상 이미지 정보 읽기 실패";
- ShowMessage(String(E.ClassName()) + E.Message);
- return;
- }
- if (pADO->RecordCount == 0)
- {
- pADO->Close();
- return;
- }
- ForceDirectories(g_sTempDir);
- TADOBlobStream *BS;
- int nFileSize = 0;
- String sImgFile = g_sTempDir + "CCTVB_" + FObj.ID + ".bmp";
- try {
- DeleteFile(sImgFile);
- } catch(...) {}
- String sDispBlob;
- try
- {
- sDispBlob = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString;
- if (sDispBlob == "Y")
- {
- BS = (TADOBlobStream *)pADO->CreateBlobStream(pADO->FieldByName("CCTV_SBST_IMGN"), bmRead);
- //ImgBlob->Picture->Graphic->LoadFromStream(BS);
- BS->SaveToFile(sImgFile);
- nFileSize = BS->Size;
- delete BS;
- }
- pADO->Close();
- }
- catch(Exception &e)
- {
- delete BS;
- PnlBlob->Caption = lblErr4->Caption;//"대체영상 이미지 스트림 로딩 실패";
- return;
- }
- if (sDispBlob == "Y")
- {
- FDispBlob = true;
- PnlBlob->Visible = true;
- PnlStream->Visible = false;
- if (nFileSize)
- {
- try
- {
- ImgBlob->Picture->LoadFromFile(sImgFile);
- return;
- }
- catch(...)
- {
- ImgBlob->Visible = false;
- PnlBlob->Caption = lblErr5->Caption;//"대체영상 이미지 파일 로딩 실패";
- return;
- }
- }
- else
- {
- ImgBlob->Visible = false;
- PnlBlob->Caption = lblErr6->Caption;//"대체영상 이미지 사이즈 오류";
- }
- }
- else
- {
- FDispBlob = false;
- PnlBlob->Visible = false;
- PnlStream->Visible = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::MnuConnectClick(TObject *Sender)
- {
- FAutoPlay = true;
- Connect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::MnuDisconnectClick(TObject *Sender)
- {
- FAutoPlay = false;
- Disconnect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::Connect()
- {
- Disconnect();
- PnlStream->Caption = FObj.RTSP_ADDR;//"Connecting...";
- try
- {
- FFPlayer1->AspectRatio = -1;
- FFPlayer1->TryOpen(FObj.RTSP_ADDR, PnlStream->Handle);
- FConHandle = (long)FFPlayer1->ScreenHandle;
- Application->ProcessMessages();
- }
- catch(Exception &e)
- {
- }
- FPlay = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::Disconnect()
- {
- if (!FPlay) return;
- FPlay = false;
- PnlStream->Caption = "Disconnect";
- try
- {
- if (FFPlayer1->ScreenHandle != NULL)
- {
- FFPlayer1->Stop(true);
- PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
- UpdateWindow(FFPlayer1->ScreenHandle);
- FFPlayer1->ScreenHandle = NULL;
- }
- Application->ProcessMessages();
- FConHandle = 0;
- }
- catch(Exception &e)
- {
- }
- PnlStream->Caption = "Disconnected";
- FConHandle = 0;
- FPlay = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::InitCamera(void *ACctv, bool AAutoPlay/*=true*/)
- {
- FAutoPlay = AAutoPlay;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::MaxOrNormalForm(TForm *AForm, bool AMax)
- {
- if (AMax)
- {
- //this->FParent = this->Parent;
- //AForm->Parent = FrmMain; //Application->MainForm;
- this->FLastBounds = AForm->BoundsRect;
- AForm->BorderStyle = bsNone;
- AForm->FormStyle = fsStayOnTop;
- AForm->BoundsRect = AForm->Monitor->BoundsRect;
- PnlStream->Align = alClient;
- #if 0
- ShowMessage(String(AForm->BoundsRect.Left) + ", " +
- String(AForm->BoundsRect.Top) + ": " +
- String(AForm->BoundsRect.Width()) + ", " +
- String(AForm->BoundsRect.Height()) );
- #endif
- }
- else
- {
- //AForm->Parent = this->FParent;
- AForm->FormStyle = fsNormal;
- AForm->BorderStyle = bsToolWindow;
- AForm->BoundsRect = this->FLastBounds;
- PnlStream->Align = alClient;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::PnlStreamDblClick(TObject *Sender)
- {
- #if 0
- if (FFullScreen == false)
- {
- MaxOrNormalForm(this, true);
- FFullScreen = true;
- }
- else
- {
- MaxOrNormalForm(this, false);
- FFullScreen = false;
- }
- #else
- // 여기서 더블클릭은 최대화면을 호출하는 것임
- TFrmFullScreen *pFrmFullScreen = new TFrmFullScreen(this);
- pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
- pFrmFullScreen->PnlStream->Align = alNone;
- pFrmFullScreen->PnlStream->Align = alClient;
- pFrmFullScreen->RTSP_ADDR = FObj.RTSP_ADDR;
- pFrmFullScreen->ShowModal();
- PnlStream->Parent = this;
- PnlStream->Tag = (int)this;
- delete pFrmFullScreen;
- pFrmFullScreen = NULL;
- #endif
- #if 0
- TForm *pForm = (TForm*)PnlStream->Tag;
- if (pForm == this)
- {
- TFrmFullScreen *pFrmFullScreen = new TFrmFullScreen(this);
- pFrmFullScreen->BoundsRect = this->Monitor->BoundsRect;
- pFrmFullScreen->PnlStream->Align = alNone;
- pFrmFullScreen->PnlStream->Align = alClient;
- pFrmFullScreen->RTSP_ADDR = FObj.RTSP_ADDR;
- PnlStream->Parent = pFrmFullScreen->PnlStream;
- PnlStream->Tag = (int)pFrmFullScreen;
- PnlStream->Align = alClient;
- pFrmFullScreen->ShowModal();
- FFPlayer1->ScreenHandle = PnlStream->Handle;
- PnlStream->Parent = this;
- PnlStream->Tag = (int)this;
- delete pFrmFullScreen;
- pFrmFullScreen = NULL;
- }
- else
- {
- PnlStream->Parent = this;
- PnlStream->Tag = (int)this;
- TFrmFullScreen *pFullForm = (TFrmFullScreen*)pForm;
- pFullForm->TmrClose->Enabled = true;
- }
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmStreamPlayer::FFPlayer1State(TObject *Sender, TPlayState APlayState)
- {
- enum TPlayState { psPlay, psPause, psResume, psStep, psStop, psEnd };
- if (APlayState == Ffbasecomponent::psStop || APlayState == Ffbasecomponent::psEnd)
- {
- if (FPlay)
- {
- Caption = Caption + " : Disconnected";
- TmrShow->Enabled = true;
- }
- }
- }
- //---------------------------------------------------------------------------
|