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

📄 mp_apdlg.cpp

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// MP_APDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MP_AP.h"
#include "MP_APDlg.h"
#include "ServerUtl.h"
#include "PacketMaker.h"
#include <direct.h>
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#ifdef STATICLIB
#include "AVSynchronizer_Static.h"
#include "DataBroker_Static.h"
#endif


#define EVENT_DRIVEN_RECORD_TIME	50
#define	CONST_READUART_WAIT			5000

CRITICAL_SECTION g_CS[MAX_CHANNELS];
HANDLE			g_hAvSync;
HANDLE			g_hDataBroker;
HANDLE			g_hDatabase;
HANDLE			g_ExitWait[MAX_CHANNELS];
HANDLE			g_hDisconnectOK = NULL;
TCHANNEL_INFO	g_Channel_Info[MAX_CHANNELS];
int				g_iFocus;
char			g_chDBPath[64];
int				g_nMaxChannel = 16;
int				g_nImageSize = 0;

DWORD			g_VideoCount = 0;
DWORD			g_AudioCount = 0;
DWORD			g_SynTime = 0;
DWORD			g_dwLayout = 0;
DWORD			g_dwOrgPicCap = 0;
DWORD			g_dwInitOpt = 0;
DWORD			g_dwShowDZWnd = 0;
HBITMAP			g_hBMP;
BOOL			g_bSnapAllChannel = FALSE;

BOOL			g_bDrawOnGraph = FALSE;
BOOL			g_bDeblocking = FALSE;

int				g_nAVRawCCB = 0;
int				g_nAVRawDBAskType = PF_BMP24;
BOOL			g_bAVRawCBOwnBuf = FALSE;
BOOL			g_bAVRawCBWriteFile = FALSE;
char			g_szAVCBExtName[MAX_PATH] = "bmp";
BOOL			g_bAutoForceI = FALSE;
int				g_nForcePeriod=1000;

char			g_szProxy[256];
int				g_nProxyPort = 3128;

// for decoder channel
int				g_nMaxDecoderFileNum = 50;
char			g_szExtName[MAX_PATH] = "bmp";
int				g_nDecoderAskType = PF_BMP24;
BOOL			g_bShowQueueFull = FALSE;
int				g_nDecoderMedia = 1;
char			g_szPkgFile[MAX_PATH];

char            g_chINIPath[MAX_PATH];

// call back function
SCODE __stdcall AvSynchronizerAVCB(DWORD dwContext, EMEDIATYPE tFrameType, TFRAMEINFO * tframeinfo );
SCODE DataBrokerAVCallBack(DWORD dwContext,TMediaDataPacketInfo *pMediaDataPacket);
SCODE DataBrokerInputAVCallBack(DWORD dwContext,TMediaDataPacketInfo *pMediaDataPacket);										   
SCODE DataBrokerStatusCallBack(DWORD dwContext, TDataBrokerStatusType tStatusType, PVOID pvParam1, PVOID pvParam2); 
SCODE DataBrokerInputStatusCallBack(DWORD dwContext, TDataBrokerStatusType tStatusType, PVOID pvParam1, PVOID pvParam2);
SCODE AvSyhchronizerStatusCallBack(DWORD dwContext, DWORD dwStatusCode, DWORD dwParam1, DWORD dwParam2);
SCODE AvSyhchronizerDisplayCallBack(DWORD dwContext,TDISPLAYINFO* ptDisplayInfo );
SCODE __stdcall DataBrokerTxCallBack(DWORD dwContext, BYTE **ppbyData, DWORD *pdwLen, DWORD *pdwDataTimePeriod);

void ReadParameters()
{
	// get mp_ap.ini path
	
	DWORD dwRes = GetModuleFileName( NULL/*AfxGetInstanceHandle()*/,g_chINIPath,sizeof(g_chINIPath));	
	char *b;		

	b = g_chINIPath;	 
    b = strrchr(b+1,'.');
	strcpy((b+1),"ini");
	
	// read parameters from mp_ap.ini 
	GetPrivateProfileString("System", "DB_PATH", "c:\\DB", g_chDBPath, 200, g_chINIPath);
	g_iFocus = GetPrivateProfileInt("System","Focus_Channel", 0, g_chINIPath);
	g_SynTime = GetPrivateProfileInt("System", "Sync", 0, g_chINIPath);
	g_dwLayout = GetPrivateProfileInt("System", "Layout", 0, g_chINIPath);
	g_dwOrgPicCap = GetPrivateProfileInt("System","OrgPicCap", 0, g_chINIPath);
	g_nMaxChannel = GetPrivateProfileInt("System","MaxChannels",4,g_chINIPath);
	int nVal = GetPrivateProfileInt("System", "OutputDevice", 0, g_chINIPath);

	if (nVal == 1)
		g_dwInitOpt = USE_GDI_ONLY;
	else if (nVal == 2)
		g_dwInitOpt = USE_DIRECTDRAW_ONLY;
	else if (nVal == 3)
		g_dwInitOpt = USE_GDI_ONLY | BETTER_GDI_STRETCH;

	if (g_dwOrgPicCap != 0)
		g_dwInitOpt |= ORG_SIZE_MODE;

	nVal = GetPrivateProfileInt("System","CaptionOnGraph", 0, g_chINIPath);
	g_bDrawOnGraph = (nVal != 0);
	if (g_bDrawOnGraph)
		g_dwInitOpt |= CAPTION_ON_GRAPH;

	nVal = GetPrivateProfileInt("System","OnePass", 0, g_chINIPath);
	if (nVal == 1)
		g_dwInitOpt |= ONE_PASS_DDRAW;

	nVal = GetPrivateProfileInt("System","IndividualYUV", 0, g_chINIPath);
	if (nVal == 1)
		g_dwInitOpt |= INDIVIDUAL_SURFACE;

	nVal = GetPrivateProfileInt("System","Deblocking", 0, g_chINIPath);
	g_bDeblocking = (nVal != 0);

	nVal = GetPrivateProfileInt("System","AVNonSync", 0, g_chINIPath);
	if (nVal == 1)
		g_dwInitOpt |= AV_DONT_SYNC;

	nVal = GetPrivateProfileInt("System","ImageSize", 0, g_chINIPath);
	if (nVal == 1)
		g_nImageSize = 1;
	else if (nVal == 2)
		g_nImageSize = 2;

	nVal = GetPrivateProfileInt("System","SnapAll", 0, g_chINIPath);
	if (nVal == 1)
		g_bSnapAllChannel = TRUE;

	if (g_dwLayout > 1)
		g_dwLayout = 1;
	char chSection[16];

	nVal = GetPrivateProfileInt("System","MaxDecoderFileNum", 50, g_chINIPath);
	if (nVal > 500)
		g_nMaxDecoderFileNum = 500;
	else if (nVal < 1)
		g_nMaxDecoderFileNum = 1;
	else
		g_nMaxDecoderFileNum = nVal;
	
	g_nDecoderMedia = GetPrivateProfileInt("System","DecoderMedia", 1, g_chINIPath);
	if (g_nDecoderMedia < 1)
		g_nDecoderMedia = 1;
	if (g_nDecoderMedia > 3)
		g_nDecoderMedia = 3;

	nVal = GetPrivateProfileInt("System","AutoForceI", 0, g_chINIPath);
	if (nVal)
		g_bAutoForceI = TRUE;

	g_nForcePeriod = GetPrivateProfileInt("System","ForcePeriod", 0, g_chINIPath);

	nVal = GetPrivateProfileInt("System","ShowQueueFull", 0, g_chINIPath);
	if (nVal)
		g_bShowQueueFull = TRUE;

	g_dwShowDZWnd = GetPrivateProfileInt("System","DigitalZoomWnd", 6, g_chINIPath);

 	nVal = GetPrivateProfileInt("System","DecoderVideoType", 6, g_chINIPath);
 	
 	switch (nVal)
 	{
 		case 1 :// YUY2
 			strcpy(g_szExtName, "yuv");
			g_nDecoderAskType = PF_YUY2;
 			break;
 		case 2 ://PF_RGB16565
 			strcpy(g_szExtName, "rgb");
			g_nDecoderAskType = PF_RGB16565;
 			break;
 		case 3 ://PF_RGB24
 			strcpy(g_szExtName, "rgb");
			g_nDecoderAskType = PF_RGB24;
 			break;
 		case 4 ://PF_RGB32
 			strcpy(g_szExtName, "rgb");
			g_nDecoderAskType = PF_RGB32;
 			break;
 		case  5 ://PF_BMP16565
 			strcpy(g_szExtName, "bmp");
			g_nDecoderAskType = PF_BMP16565;
 			break;
 		case  7 : //PF_BMP32
 			strcpy(g_szExtName, "bmp");
			g_nDecoderAskType = PF_BMP32;
 			break;
 		case  8 : // PF_JPEG
 			strcpy(g_szExtName, "jpg");
			g_nDecoderAskType = PF_JPEG;
 			break;
		case  9 : // PF_RGB16555
 			strcpy(g_szExtName, "rgb");
			g_nDecoderAskType = PF_RGB16555;
 			break;
 		case  10 : // PF_BMP16555
 			strcpy(g_szExtName, "bmp");
			g_nDecoderAskType = PF_BMP16555;
 			break;
 		case  11 : // PF_YUV
 			strcpy(g_szExtName, "yuv");
			g_nDecoderAskType = PF_YUV;
 			break;
 		default:  // PF_BMP24
 			strcpy(g_szExtName, "bmp");
			g_nDecoderAskType = PF_BMP24;
 			break; 		
 	}

	GetPrivateProfileString("System", "Proxy", "", g_szProxy, 256, g_chINIPath);
	g_nProxyPort = GetPrivateProfileInt("System", "ProxyPort", 3128, g_chINIPath);

	GetPrivateProfileString("System", "PackageFile", "", g_szPkgFile, sizeof(g_szPkgFile), g_chINIPath);
	nVal = GetPrivateProfileInt("System","TestPacketMaker", 0, g_chINIPath);

	g_nAVRawCCB = GetPrivateProfileInt("System","AVCBRawCallback", 0, g_chINIPath);
	g_nAVRawCCB &= 3;

	nVal = GetPrivateProfileInt("System","AVCBVideoRawType", 6, g_chINIPath);

	switch (nVal)
 	{
 		case  1 :// YUY2
 			strcpy(g_szAVCBExtName, "yuv");
			g_nAVRawDBAskType = PF_YUY2;
 			break;
 		case  2 ://PF_RGB16565
 			strcpy(g_szAVCBExtName, "rgb");
			g_nAVRawDBAskType = PF_RGB16565;
 			break;
 		case  3 ://PF_RGB24
 			strcpy(g_szAVCBExtName, "rgb");
			g_nAVRawDBAskType = PF_RGB24;
 			break;
 		case  4 ://PF_RGB32
 			strcpy(g_szAVCBExtName, "rgb");
			g_nAVRawDBAskType = PF_RGB32;
 			break;
 		case  5 ://PF_BMP16565
 			strcpy(g_szAVCBExtName, "bmp");
			g_nAVRawDBAskType = PF_BMP16565;
 			break;
 		case  7 : //PF_BMP32
 			strcpy(g_szAVCBExtName, "bmp");
			g_nAVRawDBAskType = PF_BMP32;
 			break;
 		case  8 : // PF_JPEG
 			strcpy(g_szAVCBExtName, "jpg");
			g_nAVRawDBAskType = PF_JPEG;
 			break;
		case  9 : // PF_RGB16555
 			strcpy(g_szAVCBExtName, "rgb");
			g_nAVRawDBAskType = PF_RGB16555;
 			break;
 		case  10 : // PF_BMP16555
 			strcpy(g_szAVCBExtName, "bmp");
			g_nAVRawDBAskType = PF_BMP16555;
 			break;
 		case  11 : // PF_YUV
 			strcpy(g_szAVCBExtName, "yuv");
			g_nAVRawDBAskType = PF_YUV;
 			break;
 		default:  // PF_BMP24
 			strcpy(g_szAVCBExtName, "bmp");
			g_nAVRawDBAskType = PF_BMP24;
 			break; 		
 	}

	nVal = GetPrivateProfileInt("System","AVCBUseOwnBuffer", 0, g_chINIPath);
	if (nVal)
		g_bAVRawCBOwnBuf = TRUE;

	nVal = GetPrivateProfileInt("System","AVCBWriteFile", 0, g_chINIPath);
	if (nVal)
			g_bAVRawCBWriteFile = TRUE;

	if (g_nMaxChannel < 1)
		g_nMaxChannel = 4;
	else if (g_nMaxChannel > 16)
		g_nMaxChannel = 16;

	for ( int i = 0; i < g_nMaxChannel ; i++ )
	{
		sprintf(chSection,"Channel_%d",i+1);

		GetPrivateProfileString(chSection, "Host_IP", NULL,g_Channel_Info[i].chHostIP, sizeof(g_Channel_Info[i].chHostIP), g_chINIPath);
		GetPrivateProfileString(chSection, "User_Name", NULL,g_Channel_Info[i].chUserName, sizeof(g_Channel_Info[i].chUserName), g_chINIPath);
		GetPrivateProfileString(chSection, "Password", NULL,g_Channel_Info[i].chPassword, sizeof(g_Channel_Info[i].chPassword), g_chINIPath);
		GetPrivateProfileString(chSection, "Server_Model", NULL,g_Channel_Info[i].chServer_Type, sizeof(g_Channel_Info[i].chServer_Type), g_chINIPath);
		GetPrivateProfileString(chSection, "UserUrl", NULL,g_Channel_Info[i].szUserUrl, sizeof(g_Channel_Info[i].szUserUrl), g_chINIPath);
		GetPrivateProfileString(chSection, "UserParameters", NULL,g_Channel_Info[i].szUserUrlExtra, sizeof(g_Channel_Info[i].szUserUrlExtra), g_chINIPath);
		
		g_Channel_Info[i].dwHTTPPort = (DWORD) GetPrivateProfileInt(chSection, "HTTP_Port", 80, g_chINIPath);
		g_Channel_Info[i].dwCtrlPort = (DWORD) GetPrivateProfileInt(chSection, "RTSP_Port", 554, g_chINIPath);
		g_Channel_Info[i].dwProtocol = (DWORD) GetPrivateProfileInt(chSection, "Protocol", 1, g_chINIPath);
		g_Channel_Info[i].dwCamera = (DWORD) GetPrivateProfileInt(chSection, "Camera", 1, g_chINIPath);
		g_Channel_Info[i].dwVolume = (DWORD) GetPrivateProfileInt(chSection, "Volume", 5000, g_chINIPath);

		DWORD dwTemp = (DWORD) GetPrivateProfileInt(chSection, "NetPacketCallback",0, g_chINIPath );
		
		if (dwTemp != 0)
			g_Channel_Info[i].bNetPacketCallback = TRUE;

		g_Channel_Info[i].dwWantMedia = (DWORD) GetPrivateProfileInt(chSection, "MediaType",0, g_chINIPath );		
		
		if (g_Channel_Info[i].dwWantMedia == 0)
		{
			if (g_Channel_Info[i].chServer_Type[2])
			{
				if (g_Channel_Info[i].chServer_Type[2] > '2' &&
					strncmp(g_Channel_Info[i].chServer_Type, "IP31x1-TLFN", 11) != 0)
					g_Channel_Info[i].dwWantMedia = 3;
				else
					g_Channel_Info[i].dwWantMedia = 1;
			}
		}		
		g_Channel_Info[i].bConnecting=FALSE;
		g_Channel_Info[i].bRecording=FALSE;		
	}	
}

void WriteParameters()
{
	
    char chValue[64];
	char chSection[16];
  
	sprintf(chValue, "%s", g_chDBPath);
	WritePrivateProfileString("System", "DB_PATH", chValue, g_chINIPath);	

	sprintf(chValue,"%d", g_iFocus);
	WritePrivateProfileString("System", "Focus_Channel", chValue, g_chINIPath);

	sprintf(chValue, "%d", g_SynTime);
	WritePrivateProfileString("System","Sync",chValue,g_chINIPath);	
	for ( int i = 0; i < g_nMaxChannel ; i++ )
	{
		sprintf(chSection,"Channel_%d",i+1);
		
		WritePrivateProfileString(chSection, "Host_IP", g_Channel_Info[i].chHostIP, g_chINIPath);
		WritePrivateProfileString(chSection, "User_Name", g_Channel_Info[i].chUserName, g_chINIPath);
		WritePrivateProfileString(chSection, "Password", g_Channel_Info[i].chPassword, g_chINIPath);
		WritePrivateProfileString(chSection, "Server_Model", g_Channel_Info[i].chServer_Type, g_chINIPath);

		sprintf(chValue, "%d", g_Channel_Info[i].dwWantMedia);
		WritePrivateProfileString(chSection, "MediaType", chValue, g_chINIPath);

		sprintf(chValue,"%d",g_Channel_Info[i].dwHTTPPort);
		WritePrivateProfileString(chSection, "HTTP_Port", chValue, g_chINIPath);

		sprintf(chValue,"%d",g_Channel_Info[i].dwProtocol);
		WritePrivateProfileString(chSection, "Protocol", chValue, g_chINIPath);

		sprintf(chValue,"%d",g_Channel_Info[i].dwVolume);		
		WritePrivateProfileString(chSection, "Volume", chValue, g_chINIPath);

		sprintf(chValue,"%d",g_Channel_Info[i].dwCamera);
		WritePrivateProfileString(chSection, "Camera", chValue, g_chINIPath);
	}
}
// CMP_APDlg dialog
CMP_APDlg::~CMP_APDlg()
{
	for ( int i = 0 ; i < g_nMaxChannel ; i ++ )
	{
		DeleteCriticalSection(&g_CS[i]);
	}

	if (g_hBMP)
		::DeleteObject(g_hBMP);

	if (m_hUpgradeThread)
		CloseHandle(m_hUpgradeThread);

	DeleteCriticalSection(&m_CS);
}

CMP_APDlg::CMP_APDlg(CWnd* pParent)
	: CDialog(CMP_APDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_hServUtil = NULL;
	m_bExit = FALSE;
	m_nFRCount = 0;
	m_hUpgradeThread = NULL;
	m_bNoAudio = FALSE;
	m_hAudioCapCh = NULL;
	m_hPacketMaker = NULL;
	m_bCapturing = FALSE;
	InitializeCriticalSection(&m_CS);
}

void CMP_APDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_SCREEN, CStatic_Screen);
	DDX_Control(pDX, IDC_STATIC_DISPLAY1, CStatic_Display1);
	DDX_Control(pDX, IDC_STATIC_DISPLAY2, CStatic_Display2);
	DDX_Control(pDX, IDC_STATIC_DISPLAY3, CStatic_Display3);
	DDX_Control(pDX, IDC_STATIC_DISPLAY4, CStatic_Display4);
	DDX_Radio(pDX,IDC_RADIO_CH1,g_iFocus);
	DDX_Control(pDX, IDC_BUTTON_CH_SETTING, CButton_CH_Setting);
	DDX_Control(pDX, IDC_SLIDER_VOLUME, CSliderCtrl_Volume);
	DDX_Control(pDX, IDC_BUTTON_CONNECT, CButton_Connect);
	DDX_Control(pDX, IDC_BUTTON_RECORD, CButton_Record);
	DDX_Control(pDX, IDC_BUTTON_SNAP, CButton_Snap);
	DDX_Control(pDX, IDC_SLIDER_RANGE, CSliderCtrl_Range);
	DDX_Control(pDX, IDC_BUTTON_PAUSE, CButton_Pause);
	DDX_Control(pDX, IDC_BUTTON_PLAY, CButton_Play);
	DDX_Control(pDX, IDC_STATIC_CONNECT, CSTatic_Connect);
	DDX_Control(pDX, IDC_STATIC_STATUS, m_STATIC_STATUS);
	DDX_Control(pDX, IDC_STATIC_DI, m_DIPrompt);
	DDX_Control(pDX, IDC_STATIC_DIVAL1, m_DIVal);
	DDX_Control(pDX, IDC_ENLARGE_WND, CButton_EnlargeWnd);

⌨️ 快捷键说明

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