123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include "AppGlobalF.h"
- #include "FrmCameraPlayerF.h"
- #include "FrmCameraFullScreenF.h"
- #include "FrmCameraInfoF.h"
- #include "FrmCameraScreenF.h"
- #pragma hdrstop
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "dxGDIPlusClasses"
- #pragma link "PasLibVlcPlayerUnit"
- #pragma resource "*.dfm"
- TFrmCameraPlayer *FrmCameraPlayer = NULL;
- //---------------------------------------------------------------------------
- __fastcall TFrmCameraPlayer::TFrmCameraPlayer(TComponent* Owner)
- : TForm(Owner)
- {
- IsTerm = false;
- FPlay = false;
- FAutoPlay = true;
- FUserStop = false;
- FConHandle = 0;
- FFullScreen = false;
- FParent = this->Parent;
- PnlCamera->Tag = (int)this;
- //mmLog->Lines->Clear();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::TmrShowTimer(TObject *Sender)
- {
- TmrShow->Enabled = false;
- if (IsTerm) {
- return;
- }
- if (Installed)
- {
- PopupMenu = PopupMenu1;
- ImgNoData->Visible = false;
- //PnlName->Caption = CTLR_NMBR + ": " + NAME;
- PnlName->Caption = " " + NAME;
- Play();
- }
- else
- {
- PasLibVlcPlayer1->Visible = false;
- PopupMenu = NULL;
- PnlCamera->Caption = " " + NAME;
- LoadEmptyImage();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::LoadEmptyImage()
- {
- try
- {
- #if 0
- String sImageFile = g_AppCfg.sEmptyImg;
- if (sImageFile != "")
- {
- ImgNoData->Picture->LoadFromFile(sImageFile);
- ImgNoData->Align = alClient;
- }
- #endif
- ImgNoData->Visible = true;
- }
- catch(Exception &e)
- {
- ImgNoData->Visible = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::FormShow(TObject *Sender)
- {
- Refresh();
- this->FLastBounds = this->BoundsRect;
- // TmrShow->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::FormClose(TObject *Sender, TCloseAction &Action)
- {
- try {
- FAutoPlay = false;
- Stop();
- } catch(...) {}
- Action = caFree;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::FormDestroy(TObject *Sender)
- {
- try {
- FAutoPlay = false;
- Stop();
- } catch(...) {}
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::MnuConnectClick(TObject *Sender)
- {
- FUserStop = true;
- Play();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::MnuDisconnectClick(TObject *Sender)
- {
- PasLibVlcPlayer1->Visible = false;
- PasLibVlcPlayer1->Refresh();
- PnlCamera->Refresh();
- FUserStop = true;
- FAutoPlay = false;
- Stop();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::AutoPlay()
- {
- FAutoPlay = true;
- TmrShow->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::CameraLog(String ALogMsg)
- {
- PnlCamera->Caption = ALogMsg;
- PnlCamera->Refresh();
- #if 0
- AnsiString strmAddr = AnsiString(STRM_ADDR);
- if (strmAddr == "") {
- strmAddr = "Empty Addr";
- }
- AnsiString sAutoPlay = FAutoPlay ? "AutoPlay:True" : "AutoPlay:False";
- AnsiString sUserStop = FUserStop ? "UserStop:True" : "UserStop:False";
- LOGINFO("%s,%s, %s: %s", sAutoPlay.c_str(), sUserStop.c_str(), strmAddr.c_str(), AnsiString(ALogMsg).c_str());
- #endif
- Application->ProcessMessages();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::Play()
- {
- if (FPlay) return;
- if (PasLibVlcPlayer1->Visible) {
- PasLibVlcPlayer1->Visible = false;
- }
- Stop();
- if (STRM_ADDR == "") {
- CameraLog("### 영상정보가 없습니다 ###");
- return;
- }
- CameraLog("--- 영상 연결 중 ---");
- try
- {
- ///--udp-caching=500 --tcp-caching=500 --realrtsp-caching=500
- //ffplay.exe rtsp://224.1.1.1:8086 -fflags nobuffer -flags low_delay -avioflags direct -fflags discardcorrupt
- //PasLibVlcPlayer1->VLC->Path = "plugins";
- //PasLibVlcPlayer1->VLC->AddOption("http-caching=300");
- PasLibVlcPlayer1->VLC->AddOption("live-capture-caching=300");
- PasLibVlcPlayer1->VLC->AddOption("file-caching=300");
- PasLibVlcPlayer1->VLC->AddOption("disk-caching=300");
- PasLibVlcPlayer1->VLC->AddOption("network-caching=300");
- //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw=none");
- //PasLibVlcPlayer1->VLC->AddOption("avcodec-hw={any,d3d11va,dxva2,none}");
- //PasLibVlcPlayer1->VLC->AddOption("avcodec-threads=0");
- //PasLibVlcPlayer1->VLC->AddOption("no-sout-all");
- //PasLibVlcPlayer1->VLC->AddOption("sout-keep");
- //PasLibVlcPlayer1->VLC->AddOption(":file-caching=300");
- //PasLibVlcPlayer1->VLC->AddOption(":network-caching=300");
- //PasLibVlcPlayer1->VLC->AddOption(":avcodec-hw=none");
- //PasLibVlcPlayer1->VLC->AddOption("--avcodec-threads=0");
- //PasLibVlcPlayer1->VLC->AddOption(":no-sout-all");
- //PasLibVlcPlayer1->VLC->AddOption(":sout-keep");
- PasLibVlcPlayer1->Play(STRM_ADDR);
- FConHandle = 1;
- Application->ProcessMessages();
- AdjustVideoFit();
- if (FConHandle > 0)
- {
- if (ImgNoData->Visible == true) {
- ImgNoData->Visible = false;
- }
- }
- //PnlName->Caption = libvlc_get_install_path();
- Application->ProcessMessages();
- }
- catch(Exception &e)
- {
- }
- FPlay = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::Stop()
- {
- if (!FPlay) return;
- FPlay = false;
- if (STRM_ADDR == "") {
- return;
- }
- CameraLog("--- 영상 연결 해제 ---");
- try
- {
- if (FConHandle > 0)
- {
- PasLibVlcPlayer1->Stop();
- }
- Application->ProcessMessages();
- FConHandle = 0;
- }
- catch(Exception &e)
- {
- }
- CameraLog("*** 영상 연결 종료 ***");
- FConHandle = 0;
- FPlay = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::AdjustVideoFit()
- {
- try {
- if (FConHandle > 0 && PasLibVlcPlayer1->IsPlay()) {
- String ratioData = IntToStr(PasLibVlcPlayer1->Width) + ":" + IntToStr(PasLibVlcPlayer1->Height);
- PasLibVlcPlayer1->SetVideoAspectRatio(ratioData);
- }
- }
- catch(Exception &e) {
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::Term()
- {
- IsTerm = true;
- Stop();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::InitCamera(bool AInstalled, String ACtlrNmbr, String AName, String AStrmAddr, String AFullStrmAddr, int AViewMode)
- {
- FAutoPlay = true;
- Installed = AInstalled;
- CTLR_NMBR = ACtlrNmbr;
- NAME = AName;
- STRM_ADDR = AStrmAddr;
- FULL_STRM_ADDR = AFullStrmAddr;
- VIEW_MODE = AViewMode;
- Caption = NAME;
- PnlName->Caption = NAME;
- PnlCamera->Caption = AStrmAddr;
- FUserStop = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PnlCameraDblClick(TObject *Sender)
- {
- // 여기서 더블클릭은 최대화면을 호출하는 것임
- #if 0
- FrmCameraScreen->TmrFullScreen->Enabled = false;
- FrmCameraScreen->FFullScreenIdx = Tag;
- FrmCameraScreen->TmrFullScreen->Enabled = true;
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1DblClick(TObject *Sender)
- {
- FrmCameraScreen->TmrFullScreen->Enabled = false;
- FrmCameraScreen->FFullScreenIdx = Tag;
- FrmCameraScreen->TmrFullScreen->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::MnuInfoClick(TObject *Sender)
- {
- FrmCameraInfo = new TFrmCameraInfo(this);
- FrmCameraInfo->Edit1->Text = CTLR_NMBR;
- FrmCameraInfo->Edit2->Text = NAME;
- FrmCameraInfo->Edit3->Text = STRM_ADDR;
- FrmCameraInfo->Edit4->Text = FULL_STRM_ADDR;
- FrmCameraInfo->ShowModal();
- delete FrmCameraInfo;
- FrmCameraInfo = NULL;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPlaying(TObject *Sender)
- {
- // 표출시작
- #if 0
- if (FConHandle > 0)
- {
- if (PasLibVlcPlayer1->Visible == false) {
- PasLibVlcPlayer1->Visible = true;
- }
- if (ImgNoData->Visible == true) {
- ImgNoData->Visible = false;
- }
- }
- #endif
- AdjustVideoFit();
- FUserStop = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerMediaChanged(TObject *Sender, UnicodeString mrl)
- {
- // 스트리밍 변경됨
- CameraLog("@@@ 영상 연결 중.. @@@");
- AdjustVideoFit();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerStopped(TObject *Sender)
- {
- CameraLog("@@@ 영상 표출이 종료됨 @@@");
- if (FAutoPlay && FUserStop) {
- if (PasLibVlcPlayer1->Visible) {
- PasLibVlcPlayer1->Visible = false;
- }
- //CameraLog("@@@ 영상 표출 종료 @@@");
- }
- FPlay = false;
- if (FAutoPlay) {
- TmrShow->Enabled = false;
- TmrShow->Interval = 1000;
- TmrShow->Enabled = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerEncounteredError(TObject *Sender)
- {
- if (PasLibVlcPlayer1->Visible) {
- PasLibVlcPlayer1->Visible = false;
- }
- CameraLog("@@@ 영상 표출 오류 @@@");
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerOpening(TObject *Sender)
- {
- #if 0
- // 표출시작
- if (FConHandle > 0)
- {
- if (PasLibVlcPlayer1->Visible == false) {
- PasLibVlcPlayer1->Visible = true;
- }
- if (ImgNoData->Visible == true) {
- ImgNoData->Visible = false;
- }
- }
- AdjustVideoFit();
- #endif
- AdjustVideoFit();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmCameraPlayer::PasLibVlcPlayer1MediaPlayerPositionChanged(TObject *Sender, float position)
- {
- if (PasLibVlcPlayer1->Visible == false) {
- PasLibVlcPlayer1->Visible = true;
- PnlCamera->Refresh();
- AdjustVideoFit();
- }
- if (ImgNoData->Visible == true) {
- ImgNoData->Visible = false;
- }
- #if 0
- case PasLibVlcPlayer1.GetState() of
- plvPlayer_NothingSpecial: stateName := 'Idle';
- plvPlayer_Opening: stateName := 'Opening';
- plvPlayer_Buffering: stateName := 'Buffering';
- plvPlayer_Playing: stateName := 'Playing';
- plvPlayer_Paused: stateName := 'Paused';
- plvPlayer_Stopped: stateName := 'Stopped';
- plvPlayer_Ended: stateName := 'Ended';
- plvPlayer_Error: stateName := 'Error';
- else stateName := 'Unknown';
- end;
- var
- info : string;
- sar_num, sar_den : LongWord;
- begin
- info := 'Aspect ratio = ' + PasLibVlcPlayer1.GetVideoAspectRatio();
- if (PasLibVlcPlayer1.GetVideoSampleAspectRatio(sar_num, sar_den)) then
- begin
- info := info + ', SampleAspectRatio = ' + IntToStr(sar_num) + ':' + IntToStr(sar_den);
- end;
- MessageDlg(
- info,
- mtInformation, [mbOK], 0);
- end;
- main libvlc debug: configured with /builds/videolan/vlc/extras/package/win32/../../../configure '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-shout' '--enable-goom' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=i686-w64-mingw32' '--with-contrib=../contrib/i686-w64-mingw32' '--with-breakpad=https://win.crashes.videolan.org' '--enable-qt' '--enable-skins2' '--enable-dvdread' '--enable-caca' 'host_alias=i686-w64-mingw32' 'CFLAGS= -D_WIN32_WINNT=0x0502 -DWINVER=0x502 -D__MSVCRT_VERSION__=0x700 ' 'CXXFLAGS= -D_WIN32_WINNT=0x0502 -DWINVER=0x502 -D__MSVCRT_VERSION__=0x700 ' 'PKG_CONFIG=pkg-config' 'PKG_CONFIG_LIBDIR=/usr/i686-w64-mingw32/lib/pkgconfig:/usr/lib/i686-w64-mingw32/pkgconfig'
- #endif
- }
- //---------------------------------------------------------------------------
|