//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FrmCameraFullScreenF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FFBaseComponent"
#pragma link "FFBasePlay"
#pragma link "FFPlay"
#pragma resource "*.dfm"
TFrmCameraFullScreen *FrmCameraFullScreen = NULL;
//---------------------------------------------------------------------------
__fastcall TFrmCameraFullScreen::TFrmCameraFullScreen(TComponent* Owner)
    : TForm(Owner)
{
    this->Color = clBlack;
    PnlStream->ParentColor = false;
    PnlStream->Color = clBlack;
}
//---------------------------------------------------------------------------
void __fastcall TFrmCameraFullScreen::PnlStreamDblClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TFrmCameraFullScreen::FormClose(TObject *Sender, TCloseAction &Action)
{
    Disconnect();

    FrmCameraFullScreen = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TFrmCameraFullScreen::FormDblClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCameraFullScreen::FormShow(TObject *Sender)
{
    Refresh();
    Application->ProcessMessages();

    this->Color = clBlack;
    PnlStream->ParentColor = false;
    PnlStream->Color = clBlack;

    Connect();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCameraFullScreen::Connect()
{
    Disconnect();

    PnlStream->Caption = "Try connect...";

    try
    {
        FFPlayer1->AspectRatio = -1;
        FFPlayer1->TryOpen(RTSP_ADDR, PnlStream->Handle);
        FConHandle = (long)FFPlayer1->ScreenHandle;
        Application->ProcessMessages();
    }
    catch(Exception &e)
    {
    }
    FPlay = true;
}
//---------------------------------------------------------------------------

void __fastcall TFrmCameraFullScreen::Disconnect()
{
    if (!FPlay) return;

    FPlay = false;
    PnlStream->Caption = "Try disconnect";
    try
    {
        if (FFPlayer1->ScreenHandle != NULL)
        {
            FFPlayer1->Stop(true);
            PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
            UpdateWindow(FFPlayer1->ScreenHandle);
        }
        Application->ProcessMessages();
        FConHandle = 0;
    }
    catch(Exception &e)
    {
    }

    PnlStream->Caption = "Disconnected";
    FConHandle = 0;
    FPlay = false;
}
//---------------------------------------------------------------------------

void __fastcall TFrmCameraFullScreen::TmrCloseTimer(TObject *Sender)
{
    TmrClose->Enabled = false;
    Close();
}
//---------------------------------------------------------------------------

