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

📄 myendpoint.cpp

📁 VIS H.323 Library V2.1 Release
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
  VIS H.323 Video Conference System
      --Sample for VIS H.323 DLL Library 2.1 Release

  For more information,visit our homepage 
  
    [http://www.115studio.com]

  or mail to us for tech support and bug report

    [support@115studio.com]

  2000-2004 115Studio
  
  2004-04-05
*/
#include "stdafx.h"
#include "VISConf.h"
#include "MyEndPoint.h"
#include "VISConfDlg.h"
#include "ILSClientWnd.h"
#include "config.h"

//
const char * const CallEndReasonNames[]={
	  "EndedByLocalUser",
      "EndedByNoAccept",
      "EndedByAnswerDenied",
      "EndedByRemoteUser",
      "EndedByRefusal",
      "EndedByNoAnswer",
      "EndedByCallerAbort",
      "EndedByTransportFail",
      "EndedByConnectFail",
      "EndedByGatekeeper",
      "EndedByNoUser",
      "EndedByNoBandwidth",
      "EndedByCapabilityExchange",
      "EndedByCallForwarded",
      "EndedBySecurityDenial",
      "EndedByLocalBusy",
      "EndedByLocalCongestion",
      "EndedByRemoteBusy",
      "EndedByRemoteCongestion",
      "EndedByUnreachable",
      "EndedByNoEndPoint",
      "EndedByHostOffline",
	  "EndedByTemporaryFailure"
};
//
const char * const UseGKResultNames[]={
	  "RegistrationSuccessful",
      "InvalidListener",
      "DuplicateAlias",
      "SecurityDenied",
	  "TransportError",
	  "NoGatekeeper",  
	  "FailUnknown"
};

void CMyVideoGrabber::OnStream(BYTE *frame,int width,int height)
{
	if(m_pep) 
	{
		m_pep->m_VideoMixer.Write(0,frame,width,height,FALSE);
		BYTE * p=m_pep->m_dlg.m_LocalVideoWnd.GetBuffer(width,height);
		if(p)
		{
			memcpy(p,frame,width*height*3);
			m_pep->m_dlg.m_LocalVideoWnd.ReleaseBuffer();
		}
	}
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMyEndPoint::CMyEndPoint(CVISConfDlg &dlg):m_dlg(dlg)
{
	m_VideoGrabber.m_pep=this;
	m_hRemoteVideoThread=NULL;
	m_bStopRemoteVideoThread=TRUE;
	m_hRemoteAudioThread=NULL;
	m_bStopRemoteAudioThread=TRUE;
	m_hLocalAudioThread=NULL;
	m_bStopLocalAudioThread=TRUE;
}

CMyEndPoint::~CMyEndPoint()
{
	StopRemoteVideo();
	StopLocalVideo();
	StopRemoteAudio();
	StopLocalAudio();
}

//Called when a call comes
void CMyEndPoint::OnAnswerCall(DWORD connID,const char *RoomID)
{
	char name[256]="";
	GetRemotePartyName(connID,name,256);

	//Log output
	m_dlg.Output("Incoming call from \"%s\",connection ID=%d",name,connID);

	CConfig config;
	if(config.GetBoolean(KEY_REFUSE_ALL_CALL,FALSE))
	{
		//Refuse incoming call
		AnswerCall(connID,FALSE);
		return;
	}

	int count=m_dlg.m_MemberList.GetItemCount();
	
	//Insert item into member list
	int index=m_dlg.m_MemberList.InsertItem(count,name);
	if(index>=0)
	{
		m_dlg.m_MemberList.SetItemData(index,connID);
		m_dlg.m_MemberList.SetItemState(index,LVIS_SELECTED,LVIS_SELECTED);
	}		
	
	m_dlg.UpdateConnStatus(connID);	
	m_dlg.SetForegroundWindow();

	
	//Auto answer
	if(config.GetBoolean(KEY_AUTO_ANSWER,FALSE))
		m_dlg.SendMessage(WM_COMMAND,IDC_ANSWER);

}

//Called when successfully connected with remote EP
void CMyEndPoint::OnWaitForAnswer(DWORD connID)
{	
	char name[256]="";
	GetRemotePartyName(connID,name,256);
	m_dlg.Output("Connected with \"%s\",connection ID=%d",name,connID);

	LVFINDINFO fi;
	fi.flags=LVFI_PARAM;
	fi.lParam=connID;
	int index=m_dlg.m_MemberList.FindItem(&fi);

	if(index>=0)
	{
		//Remote party name got, so update the member list
		m_dlg.m_MemberList.SetItemText(index,0,name);
	}	
	m_dlg.UpdateConnStatus(connID);
}

//Called when disconnected with remote EP
void CMyEndPoint::OnConnectionCleared(DWORD connID, DWORD duration,enum CallEndReason reason)
{
	if(m_dlg.m_PropertiesDlg.m_connID==connID&&m_dlg.m_PropertiesDlg.m_hWnd)
	{
		//Close the properties dialog for this connection
		m_dlg.m_PropertiesDlg.EndDialog(IDCANCEL);
	}

	char name[256]="";
	GetRemotePartyName(connID,name,256);
	
	m_dlg.Output("Disconnected with \"%s\",duration=%d sec,reason=%s,connection ID=%d",name,duration,CallEndReasonNames[reason],connID);
	//Kill the timer for duration
	m_dlg.KillTimer(connID);

	LVFINDINFO fi;
	fi.flags=LVFI_PARAM;
	fi.lParam=connID;
	int index=m_dlg.m_MemberList.FindItem(&fi);
	if(index>=0)
	{
		//Remove the connection from member list
		m_dlg.m_MemberList.DeleteItem(index);
	}
	m_dlg.UpdateButtons();

}
//Called when start talking with remote party
void CMyEndPoint::OnConnectionEstablished(DWORD connID)
{
	char name[256]="";
	GetRemotePartyName(connID,name,256);
	m_dlg.Output("Connection established with \"%s\",connection ID=%d",name,connID);

	m_dlg.UpdateDuration(connID);
	//Set the timer for duration
	m_dlg.SetTimer(connID,1000,NULL);
	
	m_dlg.UpdateConnStatus(connID);
	m_dlg.UpdateButtons();
}

//Called when received audio frame,need delay here!
BOOL CMyEndPoint::OnRenderAudioFrame(DWORD connID,BYTE* frame,int len)
{		
	return m_AudioMixer.Write(connID,frame,len);	
}

//Called when fetch audio frame,need delay here!
BOOL CMyEndPoint::OnReadAudioFrame(DWORD connID,BYTE* frame,int len)
{	
	return m_AudioMixer.Read(connID,frame,len);
}

//Called when audio channel is about to be shut down	
BOOL CMyEndPoint::OnAudioStop(DWORD connID, BOOL outgoing,const char *CodecName)
{	
	DWORD c=0;
	if(m_AudioMixer.ChannelExist(0,outgoing))
		c=1;
	if(m_AudioMixer.GetChannelCount(outgoing)-c<=1)
	{
		if(outgoing)//No need capture local audio,so stop it
			StopLocalAudio();
		else//No need playback remote audio,so stop it
			StopRemoteAudio();
	}
	
	//Remove audio channel in audio mixer
	if(m_AudioMixer.RemoveChannel(connID,outgoing))
	{
		m_dlg.Output("Stop %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);
		
		return TRUE;
	}

	m_dlg.Output("Error occurs when stopping %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);
	//Don't care the return value here
	return FALSE;
}

//Called when audio channel is about to be started
BOOL CMyEndPoint::OnAudioStart(DWORD connID,BOOL outgoing,const char *CodecName)
{
	CConfig config;
	if(outgoing)
	{
		if(config.GetBoolean(KEY_SEND_LOCAL_VOICE,TRUE))
			StartLocalAudio();//If local audio capture thread already started, this function do nothing
	}
	else
	{
		if(config.GetBoolean(KEY_PLAY_RECEIVED_VOICE,TRUE))
			StartRemoteAudio();//If remote audio playback thread already started, this function do nothing
	}
	//Add audio channel to audio mixer
	if(m_AudioMixer.AddChannel(connID,outgoing))
	{
		m_dlg.Output("Start %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);

		return TRUE;
	}

	m_dlg.Output("Error occurs when starting %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);
	//Failed, and the audio channel will not be started
	return FALSE;
	
}

//Called when received a video frame,no need delay here
BOOL CMyEndPoint::OnRenderVideoFrame(DWORD connID,BYTE *frame, int width, int height)
{	
	m_dlg.m_PropertiesDlg.Render(connID,frame,width,height);
	return m_VideoMixer.Write(connID,frame,width,height,FALSE);
}

//Called when fetch a video frame, need delay here!
BOOL CMyEndPoint::OnReadVideoFrame(DWORD connID,BYTE* frame,int width,int height)
{	
	return m_VideoMixer.Read(connID,frame,width,height);	
}

//Called when video channel is about to be shut down
BOOL CMyEndPoint::OnVideoStop(DWORD connID,BOOL outgoing,const char *CodecName)
{		
	if(outgoing==FALSE)
	{	
		DWORD local=0;
		if(m_VideoMixer.ChannelExist(0,FALSE))
			local=1;
		if(m_VideoMixer.GetChannelCount(FALSE)-local==1)
		{
			//No need render remote video, so stop it
			if(m_dlg.m_RemoteVideoWnd.m_hWnd!=NULL)
				m_dlg.OnRemoteVideo();
		}
	}

	//Remove video channel in video mixer
	if(m_VideoMixer.RemoveChannel(connID,outgoing))
	{	
		m_dlg.Output("Stop %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);		
		
		return TRUE;
	}

	m_dlg.Output("Error occurs when stopping %s \"%s\" data %s connection ID=%d",
		outgoing?"transmitting":"receiving",
		CodecName,
		outgoing?"to":"from",
		connID);
	//Don't care the return value here
	return FALSE;
}

//Called when video channel is about to be started
BOOL CMyEndPoint::OnVideoStart(DWORD connID,BOOL outgoing,const char* CodecName)
{
	//Add video channel to video mixer	
	if(m_VideoMixer.AddChannel(connID,outgoing))
	{
		m_dlg.Output("Start %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);
		if(outgoing)
		{
			CConfig config;
			//Set default transmit FPS here
			m_VideoMixer.SetFPS(connID,TRUE,config.GetInteger(KEY_TRANSMIT_FPS,10));
		}
		
		return TRUE;
	}
	m_dlg.Output("Error occurs when starting %s \"%s\" data %s connection ID=%d",
			outgoing?"transmitting":"receiving",
			CodecName,
			outgoing?"to":"from",
			connID);
	//Failed, and the video channel will not be started
	return FALSE;

}

//Called when received user input
void CMyEndPoint::OnReceiveUserInput(DWORD connID,const char* value)
{
	char name[256]="";
	CString s;
	GetRemotePartyName(connID,name,256);
	s.Format("%s:%s\r\r\n",name,value);
	//
	m_dlg.m_UserInputDlg.Append(s);
	if(m_dlg.m_UserInputDlg.m_bAutoPop)
	{
		//Pop up the user input window
		if(!m_dlg.m_UserInputDlg.IsWindowVisible())

⌨️ 快捷键说明

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