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

📄 interface.cpp

📁 UDP语音通讯控件源码
💻 CPP
字号:
// Interface.cpp: implementation of the CInterface class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Interface.h"
#include "head.h"
#include "MyWaveIn.h"	// Added by ClassView
#include "WaveOut.h"	// Added by ClassView
#include "UdpSocket.h"
#include <afxmt.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWaveOut *g_pOut;
CCriticalSection g_soLock;

CInterface::CInterface():
	m_bIni (FALSE)
{	
	m_bWork = FALSE;
	m_pUdp = new CUdpSocket();

	g_pOut = new CWaveOut();
	m_pIn = new CMyWaveIn(m_pUdp);
}

CInterface::~CInterface()
{
	if (m_bWork)
	{
		End();
		delete m_pIn;
		delete g_pOut;
		delete m_pUdp;
	}
}
BOOL CInterface::Setip_port(CString Userip,UINT UserPort,UINT MyPort)
{
	if (m_bWork)
	{
		TRACE("The talk has worked.\n");
		return FALSE;
	}
	if (!m_bIni)
	{
		Ini();
	}
	m_pUdp->SetIp (Userip);
	m_pUdp->SetPort(UserPort);
	if (!m_pUdp->Ini(MyPort))
		return FALSE;
	m_bWork = TRUE;
	return TRUE;
}
BOOL CInterface::Play()
{
	m_pIn->EnableSend (TRUE);
	return TRUE;
}

BOOL CInterface::End()
{
	if (!m_bWork)
	{
		return FALSE;
	}
	m_pIn->EnableSend (FALSE);
	m_pIn->StopRec ();
	g_pOut->StopPlay ();
	m_pUdp->CloseSocket ();
	m_bIni = FALSE;
	m_bWork = FALSE;
	return TRUE;
}

BOOL CInterface::Ini()
{
	if (m_bIni)
	{
		return FALSE;
	}
	if (!g_pOut->StartPlay ())
	{
		goto Exit1;
	};
	if (!m_pIn->StartRec ())
	{
		goto Exit2;
	};
	m_bIni = TRUE;
	goto Exit;
Exit2:
	g_pOut->StopPlay ();
Exit1:
	m_pUdp->CloseSocket ();
Exit:
	return m_bIni;
}

⌨️ 快捷键说明

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