⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devicemgr.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "stdafx.h"
#include "Gtmpeg.h"
#include "lib\ViewCtl.h"
#include "GtMpegWnd.h"
// Added by CSC
#include "lib\RecCtl.h"
int            g_RGBColorBits;
///////////////////////////////////////
//
///////////////////////////////////////
CDeviceObject::CDeviceObject(CGtMpegWnd*  pParentWnd,DWORD dwSlotNumber)
{
	m_bRePlay=FALSE;
	m_bRecord=FALSE;
	m_dwCurMode=0;
	m_pParentWnd=pParentWnd;
	m_dwSlotNumber=dwSlotNumber;
	m_sSection.Format("Video_%d",dwSlotNumber+1);
	m_arPlayList.SetSize(0);
	m_arFileName.SetSize(0);
	GetINIParameters();
	InitVideoDecoder();
	m_sRecordRootPath="";
	m_bCheck=FALSE;
	CWnd* pDispWnd=m_pParentWnd->GetDlgItem(IDC_VIDEO_POS+m_dwSlotNumber);
	m_pVideoPlay=new CVideo(pDispWnd);
	m_nStartTicks=-1;
	m_nStartTicks1=-1;
	m_nStartTicks2=-1;
	int nVideoWay=AfxGetApp()->GetProfileInt("系统参数","采集方式",0);
	m_hcg200 = BeginCG200(m_dwSlotNumber+1);
	CG200SetDispMode(m_hcg200,nVideoWay);
}
///////////////////////////////////////////
//
///////////////////////////////////////////
CDeviceObject::~CDeviceObject()
{
  RECCTL_EnableSoundCard(FALSE);
  m_bRePlay=FALSE;
  m_bRecord=FALSE;
  m_dwCurMode=0;
  EndCG200(m_hcg200);
  if(m_arPlayList.GetSize()!=0)
  {
     for(int i=0;i<m_arPlayList.GetSize();i++)
	 {
	    delete m_arPlayList.GetAt(i);
	 }
	 m_arPlayList.RemoveAll();
  }
  if(m_pVideoPlay!=NULL)
	  delete m_pVideoPlay;
}
///////////////////////////////////////
//
///////////////////////////////////////
void CDeviceObject::PlaySubsection()
{
   int nCurTicks=0;
   CString sTxt="";
   if(m_bRePlay)
   {
	    nCurTicks = GetTickCount();
		if (!m_pVideoPlay->IsPlaying())
		{
			  if(!PlaySection())
			  {
				  m_bRePlay=FALSE;
				  m_pVideoPlay->Close();
				  m_pParentWnd->m_nPlays--;
				  StartDisplay();
				  return;
			  }
		}
		if ((nCurTicks - m_nStartTicks1) >=60000)
		{
		  sTxt.Format("回放-%d分 ",(nCurTicks - m_nStartTicks2)/60000);
		  if(m_bRecord)
		  {
		     CString sTmp="";
		     m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->GetWindowText(sTmp);
		     int nFind=sTmp.Find(" ",0);
		     if(nFind!=-1)
			 {
		        sTmp=sTmp.Right(sTmp.GetLength()-nFind+1);
				sTmp.TrimLeft();
			 }
			 sTxt+=sTmp;
		  }
		  m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText(sTxt);
		  m_nStartTicks1 = nCurTicks;
		}
   }
} 
///////////////////////////////////////////
//
///////////////////////////////////////////
void CDeviceObject::RecordSubsection()
{
    int nCurTicks=0;
	CString sTxt="";
	if(m_bRecord)
	{
		nCurTicks = GetTickCount();
		if ((nCurTicks - m_nStartTicks) >=300000)//1分=60000毫秒
		{
		  RECCTL_StopCapture(m_dwSlotNumber);
		  if(m_bSound)
		  {
		  }
		  StartLVE();
		  m_nStartTicks = nCurTicks;
		}
		if ((nCurTicks - m_nStartTicks1) >=60000)
		{
		  sTxt.Format("录像-%d分",(nCurTicks - m_nStartTicks2)/60000);
		  if(m_bRePlay)
		  {
		     CString sTmp;
		     m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->GetWindowText(sTmp);
			 sTxt=sTmp+sTxt;
		  }
		  m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText(sTxt);
		  m_nStartTicks1=nCurTicks;
		}
	}
}
///////////////////////////////////////
//
///////////////////////////////////////
void CDeviceObject::PauseDisplay()
{
    if(m_dwCurMode==0)
	{
	   m_dwCurMode=2;
	   CG200Capture(m_hcg200, FALSE);
       if(!m_bRePlay&&!m_bRecord)
		   m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText("暂停");
	}
}
///////////////////////////////////////
//
///////////////////////////////////////
void CDeviceObject::RestoryDisplay(int nFrame)
{
    if(m_dwCurMode==2)
	{
	   if(nFrame!=-1)
	   {
 	     CWnd *hOutputArea;
	     CRect rect;
		 hOutputArea = AfxGetMainWnd()->GetDlgItem(IDC_VIDEO_POS+m_dwSlotNumber);
	     hOutputArea->GetWindowRect(rect);
		 int nVideoWay=AfxGetApp()->GetProfileInt("系统参数","采集方式",0); 
		 if(nVideoWay==0)
            CG200SetDispWindow(m_hcg200, (int)rect.left, (int)rect.top, rect.Width(), rect.Height());
	     else
 	        CG200SetDispWindow(m_hcg200, (int)rect.left, (int)rect.top, rect.Width(), 2*rect.Height());
         CG200SetDispMode(m_hcg200,nVideoWay);
	   }
	   CG200Capture(m_hcg200, TRUE);
	   m_dwCurMode=0;
       if(!m_bRePlay&&!m_bRecord)
		   m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText("监视");
	}
}
///////////////////////////////////////
//
///////////////////////////////////////
void CDeviceObject::ChangeDisplayColor()
{
    m_ConfigInfo.iVideoBri = AfxGetApp()->GetProfileInt(m_sSection,"亮度",12); 
	m_ConfigInfo.iVideoCta = AfxGetApp()->GetProfileInt(m_sSection,"对比度",75); 
	m_ConfigInfo.iVideoSta = AfxGetApp()->GetProfileInt(m_sSection,"饱和度",64); 
	m_ConfigInfo.iVideoHue = AfxGetApp()->GetProfileInt(m_sSection,"色调",0); 
	CG200SetADParam(m_hcg200,AD_BRIGHTNESS,m_ConfigInfo.iVideoBri+128);
	CG200SetADParam(m_hcg200,AD_CONTRAST,m_ConfigInfo.iVideoCta);
	CG200SetADParam(m_hcg200,AD_HUE,m_ConfigInfo.iVideoHue);
	CG200SetADParam(m_hcg200,AD_SATURATION,m_ConfigInfo.iVideoSta);
	RECCTL_SetVideoDecoder(m_dwSlotNumber,RECTL_BRIGHTNESS,m_ConfigInfo.iVideoBri+128);
	RECCTL_SetVideoDecoder(m_dwSlotNumber,RECTL_CONTRAST,m_ConfigInfo.iVideoCta);
	RECCTL_SetVideoDecoder(m_dwSlotNumber,RECTL_HUE,m_ConfigInfo.iVideoHue);
	RECCTL_SetVideoDecoder(m_dwSlotNumber,RECTL_SATURATION,m_ConfigInfo.iVideoSta);
}
///////////////////////////////////////
//
///////////////////////////////////////
void CDeviceObject::Snap()
{
   CG200Snap(m_hcg200);
}
///////////////////////////////////////
//
///////////////////////////////////////
void CDeviceObject::StartDisplay()
{
	CWnd *hOutputArea;
	CRect rect;
	if(m_bRePlay)
	   StopPlayback();
	m_dwCurMode=0;
	int nVideoWay=AfxGetApp()->GetProfileInt("系统参数","采集方式",0);
	hOutputArea = AfxGetMainWnd()->GetDlgItem(IDC_VIDEO_POS+m_dwSlotNumber);
	hOutputArea->GetWindowRect(rect);
	CG200SetColorSpace(m_hcg200,g_RGBColorBits);
	ChangeDisplayColor();
	if(nVideoWay==0)
       CG200SetDispWindow(m_hcg200, (int)rect.left, (int)rect.top, rect.Width(), rect.Height());
	else
 	   CG200SetDispWindow(m_hcg200, (int)rect.left, (int)rect.top, rect.Width(), 2*rect.Height());
	CG200Capture(m_hcg200, TRUE);
    if(!m_bRePlay&&!m_bRecord)
	    m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText("监视");
	return;
}
///////////////////////////////////////
//
///////////////////////////////////////
BOOL CDeviceObject::StartRecord()
{
	if(m_bCheck)
		return FALSE;
	if(!theApp.m_bRecord)
		return TRUE;
	if(!StartLVE())
		return FALSE;
	m_bRecord =TRUE;
	m_nStartTicks=GetTickCount();
	m_nStartTicks1=m_nStartTicks;
	m_nStartTicks2=m_nStartTicks;
	CString sTxt="录像-0分";
	if(m_bRePlay)
	{
	   CString sTmp;
	   m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->GetWindowText(sTmp);
	   sTxt=sTmp+sTxt;
	}
	m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText(sTxt);
    return TRUE;
}
///////////////////////////////////////
//
///////////////////////////////////////
BOOL CDeviceObject::StartPlayback()
{
	m_pParentWnd->GetDlgItem(IDC_VIDEO_POS+m_dwSlotNumber)->Invalidate();
	if(!Playback())
		return FALSE;
	m_nStartTicks=GetTickCount();
	m_nStartTicks1=m_nStartTicks;
	m_nStartTicks2=m_nStartTicks;
	CString sTxt="回放-0分 ";
	if(m_bRecord)
	{
	    CString sTmp="";
	    m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->GetWindowText(sTmp);
	    int nFind=sTmp.Find(" ",0);
	    if(nFind!=-1)
		{
		  sTmp=sTmp.Right(sTmp.GetLength()-nFind-1);
		}
		sTmp.TrimLeft();
		sTxt+=sTmp;
	}
	m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText(sTxt);
	return TRUE;
}
/////////////////////////////////////////
//
/////////////////////////////////////////
void CDeviceObject::StopDisplay()
{
  if(m_dwCurMode==0||m_dwCurMode==2)
  {
	  if(m_dwCurMode==0)
		  CG200Capture(m_hcg200, FALSE);
	  m_dwCurMode=1;
	  if(!m_bRePlay&&!m_bRecord)
	      m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText("停止");
  }
  return;
}
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
BOOL CDeviceObject::StopRecord()
{
	if(!theApp.m_bRecord)
		return TRUE;
	RECCTL_StopCapture( m_dwSlotNumber );
	VIEWCTL_CloseDisplay(m_dwSlotNumber, TRUE);
	m_bRecord=FALSE;
	m_nStartTicks=-1;
	m_nStartTicks1=-1;
	m_nStartTicks2=-1;
	if(!m_bRecord&&!m_bRePlay)
	{
	    if(m_dwCurMode==0)
		  m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText("监视");
	}
	return TRUE;
}
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
BOOL  CDeviceObject::StopCheck()
{
	if(!m_bCheck)
		return TRUE;
	RECCTL_StopCapture( m_dwSlotNumber );
	VIEWCTL_CloseDisplay(m_dwSlotNumber, TRUE);
	m_bCheck=FALSE;
	return TRUE;
}
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
BOOL  CDeviceObject::StopPlayback()
{
	m_bRePlay=FALSE;
	Sleep(1000);
    m_pVideoPlay->Close();
	m_arFileName.SetSize(0);
	if(m_arPlayList.GetSize()!=0)
	{
       for(int i=0;i<m_arPlayList.GetSize();i++)
	       delete m_arPlayList.GetAt(i);
	   m_arPlayList.RemoveAll();
	}
    m_arPlayList.SetSize(0);
	if(m_bRecord)
	{
	    CString sTmp="";
	    m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->GetWindowText(sTmp);
	    int nFind=sTmp.Find(" ",0);
	    if(nFind!=-1)
		{
		  sTmp=sTmp.Right(sTmp.GetLength()-nFind-1);
		}
	    m_pParentWnd->GetDlgItem(IDC_CHANNEL_STATES0+m_dwSlotNumber)->SetWindowText(sTmp);
	}
	return TRUE;
}
////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////
BOOL CDeviceObject::Close()
{
	if(m_bRePlay)
        StopPlayback();
	if(m_bRecord)
		StopRecord();
    if(m_dwCurMode==0)
        StopDisplay();
	return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
void CDeviceObject::ChangeVideo()
{
	m_ConfigInfo.iRecordMode = AfxGetApp()->GetProfileInt(m_sSection,"录制模式",0);
	m_ConfigInfo.iVideoStandard = AfxGetApp()->GetProfileInt(m_sSection,"视频信号源制式",1);
	m_ConfigInfo.iPictureSize = AfxGetApp()->GetProfileInt(m_sSection,"图像尺寸",0);
}
///////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
void CDeviceObject::GetINIParameters()
{
	m_ConfigInfo.iInputSource = AfxGetApp()->GetProfileInt(m_sSection,"源路",0);
	m_ConfigInfo.iVideoStandard = AfxGetApp()->GetProfileInt(m_sSection,"视频信号源制式",1);
	m_ConfigInfo.iVCD = AfxGetApp()->GetProfileInt(m_sSection,"VCD标准",0);
	m_ConfigInfo.iRecordMode = AfxGetApp()->GetProfileInt(m_sSection,"录制模式",0);
	m_ConfigInfo.iVideoCons = AfxGetApp()->GetProfileInt(m_sSection,"常量位速率",1); 
	m_ConfigInfo.iVideoConsVal = AfxGetApp()->GetProfileInt(m_sSection,"常量位速率值",500);//1150,500 
	m_ConfigInfo.iPictureSize = AfxGetApp()->GetProfileInt(m_sSection,"图像尺寸",0);
	m_ConfigInfo.iAudioBitrate = AfxGetApp()->GetProfileInt(m_sSection,"音频速率",224);
	m_ConfigInfo.iAudioSampleRate = AfxGetApp()->GetProfileInt(m_sSection,"音频采样速率",44100); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -