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

📄 mp_apdlg.cpp

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		{
			// call disconnect channel
			EnterCriticalSection(&m_CS);
			g_Channel_Info[g_iFocus].bUserStop = TRUE;
			g_Channel_Info[g_iFocus].bNeedReconnect = FALSE;
			LeaveCriticalSection(&m_CS);
			Disconnect_Channel();
		}
		else
		{
			char chTemp[32];
			sprintf(chTemp,"Channel %d",g_iFocus);
			MessageBox(" Please stop recording!",chTemp,MB_ICONWARNING);
		}
		
	}
	CheckUI();
}

void CMP_APDlg::OnBnClickedButtonRecord()
{
	// TODO: Add your control notification handler code here
	//CString csTemp;
	//CButton_Record.GetWindowText(csTemp);
	//if ( csTemp.Find("Stop",0) == -1 )
	
	if (g_Channel_Info[g_iFocus].bRecording == FALSE)
	{
		if ( g_Channel_Info[g_iFocus].bConnecting==TRUE)
		{
			g_Channel_Info[g_iFocus].bRecording=TRUE;
			CButton_Record.SetWindowText("Stop");
			StartRecord_Channel();
		}
		else
		{
			char chTemp[32];
			sprintf(chTemp,"Channel %d",g_iFocus);
			MessageBox(" No connecting!",chTemp,MB_ICONWARNING);
		}
	}
	else
	{
		g_Channel_Info[g_iFocus].bRecording=FALSE;
		StopRecord_Channel();
		CButton_Record.SetWindowText("Record");
	}
}

//=================================================================
//	Function   : Initial_Module
//	Description: initial DataBroker and AvSyhchronizer
//				 
//	Parameters :                     
//	Return     : 
//=================================================================
int CMP_APDlg::Initial_Module(void)
{
	// step1. Initial DB
	SCODE sRet;
	char szBuf[MAX_PATH];

	//for static library, call this function to initialize needed resources
#ifdef STATICLIB
	TMainProfileStaticOptopn	tMainProfileOpt;

	tMainProfileOpt.dwOption = eDataBroker_Use2K | eDataBroker_Use3K | eDataBroker_Use5K | 
		eDataBroker_Use7K;

	MainProfileStatic_Initial(tMainProfileOpt);
#endif	

	TMediaDBInitOption tInitOption;
	tInitOption.pszDatabasePath=g_chDBPath;
	tInitOption.dwVersion=DATABASE_VERSION;
	sRet = MediaDB_Initial(&g_hDatabase,&tInitOption,DB_CREATE | DB_OPEN);
	if (IS_FAIL(sRet))
	{
		sprintf(szBuf, "MediaDB_Initial failed with error %X", sRet);
		MessageBox(szBuf, "Error", MB_OK);
		return -1;
	}
    // step2. create/open location of DB
	/*
	TMediaLocationOption tLocOption;
	for ( int i=0 ; i < MAX_CHANNELS ; i ++ )
	{
		tLocOption.pszLocation=g_Channel_Info[i].chDBLocation;
		tLocOption.dwMaxFileSize=1024*1024*6;
		tLocOption.dwMaxIndexNumber=1024;
		if ( MediaDB_CreateLocation(g_hDatabase,&tLocOption,&(g_Channel_Info[i].hDBLocation)) != S_OK )
		{	
			MediaDB_OpenLocation(g_hDatabase,&tLocOption,&(g_Channel_Info[i].hDBLocation));
		}
	}*/
    // step3. initial DataBroker

	sRet = DataBroker_Initial(&g_hDataBroker, g_nMaxChannel * 2,DataBrokerStatusCallBack,DataBrokerAVCallBack,
		mctJPEG | mctH263 | mctMP4V | mctG7221 | mctG729A | mctAAC | mctGAMR, 0,
		DATABROKER_VERSION);
	if (IS_FAIL(sRet))
	{
		sprintf(szBuf, "DataBroker_Initial failed with error %X", sRet);
		MessageBox(szBuf, "Error", MB_OK);
		return -1;
	}

	if (g_szProxy[0] != 0)
	{
		TDataBrokerOptions tDBOpt;

		memset(&tDBOpt, 0, sizeof(tDBOpt));
		tDBOpt.bEnableProxy = TRUE;
		tDBOpt.dwProxyPort = g_nProxyPort;
		strcpy(tDBOpt.szProxyName , g_szProxy);
		tDBOpt.dwFlags = eOptEnableProxy | eOptProxyPort | eOptProxyName;

		DataBroker_SetOptions(g_hDataBroker, &tDBOpt);
	}

	// step4. initial AvSyhchronizer
	DWORD dwExtra = CHANGE_TIME_PRECISION;

	sRet = AvSynchronizer_InitialEx(&g_hAvSync,AvSyhchronizerStatusCallBack,
		AvSyhchronizerDisplayCallBack,
		//NULL,
		this->m_hWnd,AUDIOOUT_FOCUS_STICKY,g_SynTime,AVSYNCHRONIZER_VERSION, 
		g_dwInitOpt | dwExtra, RGB(82, 130, 148));
	if (IS_FAIL(sRet))
	{
		sprintf(szBuf, "AvSynchronizer_Initial failed with error %X", sRet);
		MessageBox(szBuf, "Error", MB_OK);
		return -1;
	}

//#ifdef STATICLIB
//	AvSynchronizer_UseAllCodecs();
//	AvSynchronizer_UseAudioOut();
//	AvSynchronizer_ShowCaption();
//#endif	

	if (sRet == AVSYNCHRONIZER_S_NO_AUDIO_PLAY)
	{
		m_bNoAudio = TRUE;
	}

	PacketMaker_Initial(&m_hPacketMaker, 0, PACKET_MAKER_VERSION);

	// step5. create connection of the DataBroker
	for ( int i=0 ; i < g_nMaxChannel ; i ++ )
	{
		sRet = DataBroker_CreateConnection(g_hDataBroker,&(g_Channel_Info[i].hConn));
		if (IS_FAIL(sRet))
		{
			sprintf(szBuf, "DataBroker_CreateConnection for channel %d failed with error %X", i + 1, sRet);
			MessageBox(szBuf, "Error", MB_OK);
			return -1;
		}

		if (g_Channel_Info[i].bNetPacketCallback)
		{
			sRet = DataBroker_CreateInputEx(g_hDataBroker, &g_Channel_Info[i].hDataBrokerInput);
			if (IS_FAIL(sRet))
			{
				sprintf(szBuf, "DataBroker_CreateInputEx for channel %d failed with error %X", i + 1, sRet);
				MessageBox(szBuf, "Error", MB_OK);
				return -1;
			}

		}

		int nRet = CreateAvSyncChannel (i);
		if (nRet != 0)
			return -1;
	}

	// if one channel mode and show dz is enabled
	if (g_nMaxChannel == 1 && g_dwShowDZWnd != 0)
	{
		TDIGITALZOOMPARAM tDigitalZoom;
		ZeroMemory(&tDigitalZoom, sizeof(tDigitalZoom));

#ifdef _DZ_WND
		tDigitalZoom.bCanvasWin = TRUE;
		tDigitalZoom.unCanvas.hTarget = GetDlgItem(IDC_STATIC_DZWND)->m_hWnd;
		tDigitalZoom.bDisplayed = TRUE;
		tDigitalZoom.bZoomEnabled = TRUE;
		tDigitalZoom.bZoomWin = TRUE;
		tDigitalZoom.unZoom.hZoomArea = GetDlgItem(IDC_STATIC_DZWND_CHILD)->m_hWnd;
		GetDlgItem(IDC_STATIC_DZWND)->SetWindowPos(GetDlgItem(IDC_STATIC_DZWND_CHILD), 0, 0, 0, 0, SWP_NOSIZE |
			SWP_NOMOVE);
#else
		tDigitalZoom.bCanvasWin = FALSE;
		GetDlgItem(IDC_STATIC_DZWND)->GetWindowRect(&tDigitalZoom.unCanvas.rectTarget);
		tDigitalZoom.bDisplayed = TRUE;
		tDigitalZoom.bZoomEnabled = TRUE;
		tDigitalZoom.bZoomWin = FALSE;
		GetDlgItem(IDC_STATIC_DZWND_CHILD)->GetWindowRect(&tDigitalZoom.unZoom.rectZoomArea);
		GetDlgItem(IDC_STATIC_DZWND)->SetWindowPos(GetDlgItem(IDC_STATIC_DZWND_CHILD), 0, 0, 0, 0, SWP_NOSIZE |
			SWP_NOMOVE);
#endif // _DZ_WND
		/*
		GetDlgItem(IDC_STATIC_DZWND)->GetWindowRect(&tDigitalZoom.unZoom.rectZoomArea);
		tDigitalZoom.unZoom.rectZoomArea.left += 30;
		tDigitalZoom.unZoom.rectZoomArea.top += 30;
		tDigitalZoom.unZoom.rectZoomArea.right -= 30;
		tDigitalZoom.unZoom.rectZoomArea.bottom -= 30;
		*/

		AvSynchronizer_SetChannelOption(g_Channel_Info[0].hChannel, SETCH_DIGITAL_ZOOM,
			(DWORD) &tDigitalZoom, DZ_CANVAS | DZ_CANVAS_DISPLAY | DZ_ZOOM_AREA | DZ_ENABLE_ZOOM);

	}

	ServerUtl_Initial(&m_hServUtil,SERVERUTL_VERSION);

	if (!m_bNoAudio)
	{
		if (InitialAudioCapture() != 0)
		{
			MessageBox("Could not initialize capture device, talk will not be available", "Information", MB_OK);
			//return -1;
			return 0;
		}
	}

	return 0;
}

//=================================================================
//	Function   : Release_Module
//	Description: release DataBroker and AvSyhchronizer
//				 
//	Parameters :                     
//	Return     : 
//=================================================================
int CMP_APDlg::Release_Module(void)
{
	// step1. delete connection of DataBroker & close location of DB
	int nOldFocus = g_iFocus;

	for ( int i=0 ; i < g_nMaxChannel ; i ++ )
	{
		g_ExitWait[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
		g_iFocus=i;
		StopRecord_Channel();
		if (g_Channel_Info[i].bConnecting == TRUE ||
			g_Channel_Info[i].chStatus == channelConnecting)
		{
			TRACE("Release_Module: Disconnect_Channel %d\n", i);
			g_Channel_Info[i].bExitBlock = TRUE;

			Disconnect_Channel(i, TRUE);
		}
		else
		{
			TRACE("Release_Module: Set Event %d\n", i);
			SetEvent(g_ExitWait[i]);
		}
		g_Channel_Info[i].bConnecting = FALSE;
	}

	WaitForMultipleObjects(g_nMaxChannel, g_ExitWait, TRUE, INFINITE);

	for ( i=0 ; i < g_nMaxChannel ; i ++ )
	{
		CloseHandle(g_ExitWait[i]);
		g_iFocus=i;

		AvSynchronizer_DeleteChannel (g_hAvSync,&g_Channel_Info[i].hChannel);
		if (g_Channel_Info[i].hDecoderChannel)
			AvSynchronizer_DeleteDecoderChannel(g_hAvSync, &g_Channel_Info[i].hDecoderChannel);
		if (g_Channel_Info[i].hPacketMakerChannel)
			PacketMaker_DeleteChannel(&g_Channel_Info[i].hPacketMakerChannel);
		if (g_Channel_Info[i].pbyVideoBuff)
			free(g_Channel_Info[i].pbyVideoBuff);
		if (g_Channel_Info[i].pbyAudioBuff)
			free(g_Channel_Info[i].pbyAudioBuff);

		g_Channel_Info[i].hChannel=NULL;

		if (g_Channel_Info[i].pFileMedia)
			fclose(g_Channel_Info[i].pFileMedia);
		if (g_Channel_Info[i].pbyTxData)
			free(g_Channel_Info[i].pbyTxData);

	}
	g_iFocus = nOldFocus;
   
	MediaDB_Release(g_hDatabase);
	if (m_hServUtil)
		ServerUtl_Release(&m_hServUtil);

	ReleaseAudioCapture();
	AvSynchronizer_Release(&g_hAvSync);

	// step2. release DataBroker/AvSyhchronizer/DB
	for ( i=0 ; i < g_nMaxChannel ; i ++ )
	{
		DataBroker_DeleteConnection(g_hDataBroker,&(g_Channel_Info[i].hConn));

		if (g_Channel_Info[i].hDataBrokerInput)
			DataBroker_DeleteInputEx(g_hDataBroker, &g_Channel_Info[i].hDataBrokerInput);
	}
	DataBroker_Release(&g_hDataBroker);
	//for static library, call this function to release resources
#ifdef STATICLIB
	MainProfileStatic_Release();
#endif
	return 0;
}

int 
CMP_APDlg::CreateAvSyncChannel(int nIndex)
{
	TCHANNELOPTION tChannelOptions;
	ZeroMemory(&tChannelOptions,sizeof(tChannelOptions));

	tChannelOptions.dwTopBorderSize=20;
	tChannelOptions.dwBottomBorderSize=0;
#ifdef _LR_BORDER_FLASH
	tChannelOptions.dwLeftBorderSize=20;
	tChannelOptions.dwRightBorderSize=20;
#else
	tChannelOptions.dwLeftBorderSize=0;
	tChannelOptions.dwRightBorderSize=0;
#endif // _LR_BORDER_FLASH
	tChannelOptions.dwDisplayContext=g_Channel_Info[nIndex].dwContext;
	tChannelOptions.hDisplay=g_Channel_Info[nIndex].hDisplay;
	tChannelOptions.dwVolume=50*g_Channel_Info[nIndex].dwVolume;
	tChannelOptions.bAudioOut =TRUE;
	tChannelOptions.bMotionAlert =TRUE;
	tChannelOptions.dwMotionRect=0x80000000 | RGB(0, 255, 255);
	tChannelOptions.dwMotionRectAlert=0;
	if (g_dwOrgPicCap != 0)
	{
		tChannelOptions.bOrgSizeCallback = TRUE;
		tChannelOptions.dwOrgSizeTopBorder = 20;
		tChannelOptions.dwOrgSizeBottomBorder = 20;
		tChannelOptions.dwOrgSizeLeftBorder = 10;
		tChannelOptions.dwOrgSizeRightBorder = 10;
	}
	tChannelOptions.hBMP=g_hBMP;
	tChannelOptions.dwFlags=CH_BITMAP|CH_MOTIONRECT|CH_MOTIONRECTALERT|CH_MOTION|CH_DISPLAYCONTEXT|CH_AUDIOOUT|CH_ALLBORDER|CH_VOLUME;
	//tChannelOptions.dwFlags=CH_MOTIONRECT|CH_MOTIONRECTALERT|CH_MOTION|CH_DISPLAYCONTEXT|CH_AUDIOOUT|CH_ALLBORDER|CH_VOLUME;
	//tChannelOptions.dwFlags=CH_MOTIONRECT|CH_MOTIONRECTALERT|CH_MOTION|CH_DISPLAYCONTEXT|CH_AUDIOOUT|CH_ALLBORDER|CH_VOLUME;

	char szBuf[MAX_PATH];
	
	SCODE sRet = AvSynchronizer_CreateChannel (g_hAvSync,
		&(g_Channel_Info[nIndex].hChannel),
		tChannelOptions );
	if (IS_FAIL(sRet))
	{
		sprintf(szBuf, "AvSynchronizer_CreateChannel failed with error code %X", sRet);
		MessageBox(szBuf, "Error", MB_OK);
		return -1;
	}

	AvSynchronizer_SetChannelOption(g_Channel_Info[nIndex].hChannel, SETCH_CLEAR_QUEUE, 2, 0);

	// set deblocking if any
	AvSynchronizer_SetChannelOption(g_Channel_Info[nIndex].hChannel, SETCH_DEBLOCKING, (DWORD) g_bDeblocking, 0);
	if (g_bDrawOnGraph)
		

⌨️ 快捷键说明

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