interface.cpp

来自「UDP语音通讯控件源码」· C++ 代码 · 共 107 行

CPP
107
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?