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

📄 rtcoutgoingdlg.cpp

📁 再贡献一份基于osip 协议栈的用户代理
💻 CPP
📖 第 1 页 / 共 5 页
字号:

	hr = m_pIRTCClient->Initialize();

	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("IRTCClient::Initialize : Failed 0x%x"), 
			hr);
		return hr;
	}

	return hr;
}

/**********************************************************
//@StateSessionControl
//
//@Description
//  
//  Call Control for this App we are only concerned with 
//  either answering the call or disconnecting
//

//@Args In:     SESSION_OPERATION = {STO_CREATE | 
									 STO_CREATE_SIP |
									 STO_ANSWER |
									 STO_TERMINATE}
//@Args Out:    HRESULT
//
//*********************************************************/


HRESULT 
CRTCOutgoingDlg::StateSessionControl(SESSION_OPERATION soType)
{

	HRESULT hr = S_OK;
	BSTR    bstrURI       = NULL;

	_ASSERTE(NULL != this);

	switch(soType) 
	{

	case STO_CREATE:
	case STO_CREATE_SIP:
		{

			//
			// Disable the Tunning Wizard upon session creation
			//

			StateTuneIDC(VARIANT_FALSE);

			CString cstrURI;

			if (soType == STO_CREATE) {
				m_editDURI.GetWindowText(cstrURI);

				if (TRUE == cstrURI.IsEmpty())
				{
					LOGMSGERROR(_T("Set the Destination URI"));
					return hr;
				}
				// here add check of sip uri - add sip: and the default domain? 
				// (or maybe this is done if there is an profile (=REGISTER?) 
				// for this session
				if (cstrURI.Find(_T("sip:")) != 0) { // no sip: at beginning
					//add sip:
					cstrURI = CString(_T("sip:")) + cstrURI;
					//LOGMSGERROR(_T("Prepending 'sip:'"));
				}
				if (cstrURI.Find(_T("@")) == -1) { // no @ found
					CString sipDomain;
					m_editSipDomain.GetWindowText(sipDomain);
					//add default domain
					cstrURI = cstrURI + _T("@") + sipDomain;
					//LOGMSGERROR(_T("Using the default domain"));
				}
			} else { // STO_CREATE_SIP
				m_editSIP.GetWindowText(cstrURI);

				if (TRUE == cstrURI.IsEmpty())
				{
					LOGMSGERROR(_T("No destination URI in SIP URI field"), hr);
					return hr;
				}
			}

			bstrURI   = cstrURI.AllocSysString();

			_ASSERTE(NULL != bstrURI);

			hr = m_pIRTCClient->CreateSession( m_SessionType, 
											   NULL, 
											   NULL,
											   0,
											   &m_pIRTCSession);

			if ( FAILED(hr) )
			{

				LOGMSGERROR(_T("IRTCSession::CreateSession() Failed 0x%x"), hr);
				return hr;
			}

			hr = m_pIRTCSession->AddParticipant(bstrURI, 
												bstrURI, 
												&m_pIRTCParty);

			if ( FAILED(hr) )
			{

				LOGMSGERROR(_T("IRTCSession::AddParticipant() Failed 0x%x"), hr);
				return hr;
			}

			FREE_BSTR_IF(bstrURI);

			break;
		}
	case STO_ANSWER:
		{
			
			hr = m_pIRTCSession->Answer();


			if ( FAILED(hr) )
			{

				LOGMSGERROR(_T("IRTCSession::Answer() Failed 0x%x"), hr);

				return hr;
			}

			//
			// Enable the Disconnect Button
			//

			StateDisconnectIDC(VARIANT_TRUE);
			
			break;
		}
	case STO_TERMINATE:
		{

			hr = m_pIRTCSession->Terminate( RTCTR_NORMAL );

			if ( FAILED(hr) )
			{
				LOGMSGERROR(_T("IRTCSession:::Terminate() Failed 0x%x"), hr);
			}

			break;
		}
	default:
		return E_NOTIMPL;

	}

	return hr;
}

/**********************************************************
//@StateListenMode
//
//@Description
//  
// Call to set the List Mode on the Client to open and 
// list to corresponding SIP ports
//
//
//@Args In:     RTC_LISTEN_MODE = {see RTC SDK for types}
//@Args Out:    HRESULT
//
//*********************************************************/
HRESULT 
CRTCOutgoingDlg::StateListenMode(RTC_LISTEN_MODE lMode)
{

	HRESULT hr = S_OK;

	_ASSERTE(NULL != this);
	_ASSERTE(NULL != m_pIRTCClient);

	hr = m_pIRTCClient->put_ListenForIncomingSessions(lMode);

	if (FAILED(hr))
	{

		LOGMSGERROR(_T("IRTCClient::put_ListenForIncomingSessions Failed 0x%x"), 
			hr);
		return hr;
	}

	return hr;
}



/**********************************************************
//@StateQueryActiveMedia
//
//@Description
//  
// Query for Active media streams on the Client
//
//
//@Args In:     Void
//@Args Out:    long active media mask
//
//*********************************************************/

HRESULT 
CRTCOutgoingDlg::StateQueryActiveMedia(LONG *plActiveMedia)
{
	HRESULT hr = S_OK;

	_ASSERTE(NULL != this);
	_ASSERTE(NULL != m_pIRTCClient);



	LONG   lActive   = 0;
	BSTR   bstrMedia = NULL;

	hr = m_pIRTCClient->get_ActiveMedia(&lActive);

	if (FAILED(hr))
	{
		LOGMSGERROR(_T("IRTCClient::get_ActiveMedia() Failed 0x%x"), hr);
		return hr;
	}

	*plActiveMedia = lActive;


	FREE_BSTR_IF(bstrMedia);

	return hr;
}

/**********************************************************
//@StateSinkEvent()
//
//@Description
//  
//  set the Connection point source and event filter
//
//@Args In:     LONG Event Mask
//@Args Out:    None
//
//
//*********************************************************/
HRESULT 
CRTCOutgoingDlg::StateSinkEvent(LONG lEventMask)
{

	HRESULT                   hr          = S_OK;
	IUnknown                  *pUnknown   = NULL;
	IConnectionPointContainer *pCPC       = NULL;
	IConnectionPoint          *pCP        = NULL;
	
	_ASSERTE(NULL != this);

	
	//
	// Right now I will actually override this.
	//

	lEventMask = RTCEF_CLIENT                     |
				 RTCEF_SESSION_STATE_CHANGE       |
				 RTCEF_MEDIA						|
				 RTCEF_PROFILE						|
				 RTCEF_REGISTRATION_STATE_CHANGE;

				
	hr = m_pIRTCClient->put_EventFilter(lEventMask);


	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("IRTCClient::put_EventFilter Failed 0x%x"), 
			hr);

		return hr;
	}

	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("InitializeSink() Failed 0x%x"), hr);
		return hr;
	}

	hr = QueryInterface(IID_IUnknown,
				        reinterpret_cast<void**> (&pUnknown)
					   );

	if (FAILED(hr)) 
	{
		LOGMSGERROR(_T("QueryInterface(IUnknown) Failed 0x%x"), hr);
		return hr;
	}

	


	hr = m_pIRTCClient->QueryInterface(IID_IConnectionPointContainer,
								   reinterpret_cast<void**> (&pCPC)
								   );

	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("IRTCClient::QueryInterface(IConnectionPointContainer) Failed 0x%x"),
			hr);

		return hr;
	}

	
	hr = pCPC->FindConnectionPoint( IID_IRTCEventNotification, 
									&pCP );


	if (FAILED(hr)) 
	{
		LOGMSGERROR(_T("IConnectionPointContainer::FindConnectionPoint() Failed 0x%x"), 
			hr);

		pCPC->Release();
		return hr;
	}


	hr = pCP->Advise( pUnknown, &m_dwEventCookie );

	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("IConnectionPoint::Advise() Failed 0x%x"), hr);

		pCPC->Release();
		pCP->Release();
		return hr;
	}


	pCP->Release();
	pCPC->Release();
	pUnknown->Release(); 

	return hr;
}


/**********************************************************
//@StateUnSinkEvent
//
//@Description
//  
//  unsink event connection point
//
//@Args In:     None
//@Args Out:    None
//
//
//*********************************************************/
HRESULT 
CRTCOutgoingDlg::StateUnSinkEvent()
{

	HRESULT					   hr	      = S_OK;
	IUnknown                  *pUnknown   = NULL;
	IConnectionPointContainer *pCPC       = NULL;
	IConnectionPoint          *pCP        = NULL;
	

	hr = QueryInterface(IID_IUnknown,
					    reinterpret_cast<void**> (&pUnknown)
					   );

	if (FAILED(hr)) 
	{
		LOGMSGERROR(_T("QueryInterface(IUnknown) Failed 0x%x"), hr);
		return hr;
	}


	hr = m_pIRTCClient->QueryInterface(IID_IConnectionPointContainer,
								   reinterpret_cast<void**> (&pCPC)
								   );

	if (FAILED(hr)) 
	{
		LOGMSGERROR(_T("IRTCClient::QueryInterface(IConnectionPointContainer) Failed 0x%x"), hr);

		return hr;
	}

	
	hr = pCPC->FindConnectionPoint( IID_IRTCEventNotification, 
									&pCP );


	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("IConnectionPointContainer::FindConnectionPoint Failed 0x%x"), 
			hr);


		pCPC->Release();
		return hr;
	}


	hr = pCP->Unadvise( m_dwEventCookie );

	if (FAILED(hr)) 
	{

		LOGMSGERROR(_T("IConnectionPoint::Unadvise() Failed 0x%x"), 
			hr);

		pCPC->Release();
		pCP->Release();
		return hr;
	}


	pCP->Release();
	pCPC->Release();
	pUnknown->Release(); 


	return hr;
}

/**********************************************************
//@ReleaseStateMachine
//
//@Description
//  
//  Internal Destructor , releases all the Interfaces
//
//@Args In:     None
//@Args Out:    None
//
//
//*********************************************************/

HRESULT
CRTCOutgoingDlg::ReleaseStateMachine()
{

	ULONG ulRef         = 0;
	BOOL  fRet          = FALSE;

	if ( NULL != m_pIRecvVideo )
	{

		ulRef = m_pIRecvVideo->Release();
		m_pIRecvVideo  = NULL;
	}

	if ( NULL != m_pIPrevVideo )
	{
		ulRef = m_pIPrevVideo->Release();
		m_pIRecvVideo = NULL;

	}

	if ( NULL != m_pIRTCSession )
	{
		ulRef = m_pIRTCSession->Release();
		m_pIRTCSession = NULL;
	}

	if ( NULL != m_pIRTCParty)
	{
		ulRef = m_pIRTCParty->Release();
		m_pIRTCParty = NULL;
	}

	return S_OK;

}

/**********************************************************
//@AddToMediaCapabilities
//
//@Description
//  
//  Add Media Capability to the Client
//
//@Args In:     None
//@Args Out:    None
//
//
//*********************************************************/

HRESULT 
CRTCOutgoingDlg::AddToMediaCapabilities(LONG lMedia, VARIANT_BOOL fPersist)
{

	HRESULT hr = S_OK;
	LONG    lGetMedia = 0;
	LONG    lSetMedia = 0;

	_ASSERTE(NULL != m_pIRTCClient);

	hr = m_pIRTCClient->get_MediaCapabilities(&lGetMedia);

	
	if (FAILED(hr))
	{
		LOGMSGERROR(_T("IRTCClient::get_MediaCapabilities() Failed 0x%x"), hr);
		return hr;
	}
	else
	{

		lSetMedia = lGetMedia | lMedia;



		hr = m_pIRTCClient->SetPreferredMediaTypes(lSetMedia, fPersist);

		if (FAILED(hr))
		{
			LOGMSGERROR(_T("IRTCClient::SetPreferredMediaTypes Failed 0x%x"), hr);
			return hr;
		}

	}

	return hr;
}


/**********************************************************
//@RemoveFromMediaCapabilities
//
//@Description
//  
// Removing Media Capabilities from Media
//
//@Args In:     None
//@Args Out:    None
//
//
//*********************************************************/
HRESULT 
CRTCOutgoingDlg::RemoveFromMediaCapabilities(LONG lMedia, 
											 VARIANT_BOOL fPersist)
{
	HRESULT hr = S_OK;
	LONG    lGetMedia = 0;
	LONG    lSetMedia = 0;

	_ASSERTE(NULL != m_pIRTCClient);

	hr = m_pIRTCClient->get_MediaCapabilities(&lGetMedia);

	
	if (FAILED(hr))
	{
		LOGMSGERROR(_T("IRTCClient::get_MediaCapabilities() Failed 0x%x"), hr);
		return hr;
	}
	else
	{
		//
		// are the media bits set
		//

		if ( (lGetMedia & lMedia) == lMedia ) 
		{

			lSetMedia = lGetMedia & (~lMedia);

⌨️ 快捷键说明

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