📄 iptdevice.cpp
字号:
//*****************************************************************************
// Purpose :
// Open ipml in 3PCC mode
// Parameters:
// none
// Returns:
// true = success
//*****************************************************************************
bool CIptDevice::OpenIpml(){
bool brc = true;
if (Is3PCCMode() ){
m_ntwk_srl_handle = ipm_Open(m_ipm_name, NULL, EV_SYNC);
int rc = (m_ntwk_srl_handle > 0)?0:-1;
LOG( RC(rc), m_ipm_name,
"0x%x = ipm_Open (name = %s, EV_SYNC)",
m_ntwk_srl_handle, m_ipm_name );
if (rc == -1 ){
brc = false;
process_ipml_error(m_ntwk_srl_handle, m_ipm_name);
} else {
separate_ntwk_open = true;
if (!EnableIpmlEvents()) {
brc = false;
}
} // else - open success ends
if (brc){
ReserveResource();
} // brc
} // 3PCC mode
return brc;
}
//*****************************************************************************
// Purpose :
// Get Network handle ( GC_MEDIADEVICE )
// Parameters:
// none
// Returns:
// true = success
//*****************************************************************************
bool CIptDevice::GetMediaResourceHandle(){
bool brc = true;
if (Is3PCCMode() ){
if ( ! GetLocalMediaInfo(MEDIATYPE_AUDIO_LOCAL_RTP_INFO, &m_LocalRtpPort) ) {
brc = false;
}
}else {
// 1PCC mode
int rc = gc_GetResourceH(m_srl_handle, (int *)&m_ntwk_srl_handle, GC_MEDIADEVICE);
LOG( RC(rc), GetName(),
"%d = gc_GetResourceH (hndl = 0x%x, ipml_hndl := 0x%x, GC_MEDIADEVICE)",
rc, m_srl_handle, m_ntwk_srl_handle );
if (rc != GC_SUCCESS) {
brc = false;
process_gc_error();
}
}
return brc;
}// End of GetMediaResourceHandle()
//*****************************************************************************
// Purpose :
// Make SDP message for 3PCC mode
// Parameters:
// none
// Returns:
// true = success
//*****************************************************************************
# ifdef _WIN32
# define NL "\n\r"
# else
# define NL "\n"
# endif
bool CIptDevice::MakeSdpMessage(int sdp_type){
time_t now;
time(&now);
char msg[MAX_SDP_MESSAGE];
GC_PARM_BLK *gc_parm_blkp = 0;
// \n\r
const char *rtpmap;
if (selected_coder.unCoderPayloadType == 0){
rtpmap = "0 PCMU/8000";
}else {
rtpmap = "8 PCMA/8000";
}
snprintf(msg, sizeof(msg)-1,
"v=0"NL
"o=Dialogic_IPCCLib %d %d IN IP4 %s"NL // 8000, 8000, IpAddr
"s=CnfDemo"NL
"c=IN IP4 %s"NL // IpAddr
"t=0 0"NL
"a=direction:active"NL
"m=audio %d RTP/AVP %d"NL // Port, Coder 8? (18 2 15)
"a=rtpmap:%s"NL
// "a=rtpmap:0 PCMU/8000"NL
// "a=rtpmap:8 PCMA/8000"NL
"a=rtpmap:101 telephone-event/8000"NL
"a=ptime:%d"NL
"a=sendrecv"NL,
40375936, 40375937, m_LocalRtpPort.cIPAddress,
m_LocalRtpPort.cIPAddress,
m_LocalRtpPort.unPortId, selected_coder.unCoderPayloadType,
rtpmap, selected_coder.eFrameSize);
int rc = gc_util_insert_parm_ref_ex( &gc_parm_blkp,
IPSET_SDP,
sdp_type,
strlen(msg)+1,
msg);
if (rc == GC_SUCCESS) {
GC_PARM_DATA_EXT parm;
INIT_GC_PARM_DATA_EXT(&parm);
LOG(LOG_DBG, GetName(), "Sending SDP message:");
while ( GC_SUCCESS == gc_util_next_parm_ex(gc_parm_blkp, &parm) ){
dump_parm(&parm);
} // while
rc = gc_SetUserInfo( GCTGT_GCLIB_CRN,
m_crn,
gc_parm_blkp,
GC_NEXT_OUTBOUND_MSG);
LOG( RC(rc), GetName(),
"%d = gc_SetUserInfo (GCTHT_GCLIB_CRN, m_crn = 0x%x, gc_parm_blkp, GC_NEXT_OUTBOUND_MSG)",
rc, m_crn );
if (rc != GC_SUCCESS){
process_gc_error();
}
gc_util_delete_parm_blk(gc_parm_blkp);
}
return (rc == GC_SUCCESS);
}
//*****************************************************************************
// Purpose :
// Stop IP media
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CIptDevice::StopMedia(){
if (m_ipm_started ) {
int rc = ipm_Stop(m_ntwk_srl_handle, STOP_ALL, EV_SYNC);
LOG( RC(rc), m_ipm_name,
"%d = ipm_Stop (handle=0x%x,STOP_ALL, EV_SYNC)",
rc, m_ntwk_srl_handle );
if (rc != 0){
process_ipml_error(m_ntwk_srl_handle, m_ipm_name);
return false;
} else {
m_ipm_started = true;
}
}
return true;
}
//*****************************************************************************
// Purpose :
// Dump media info structure
// Parameters:
// IPM_MEDIA_INFO structure
// Returns:
// bool (true = success)
//*****************************************************************************
void CIptDevice::DumpMediaInfo(IPM_MEDIA_INFO *pMediaInfo){
LOG(LOG_API, GetName(), "Media info structure ( %d elements )",pMediaInfo->unCount);
for (unsigned int inx = 0; inx<pMediaInfo->unCount; inx++){
DumpMediaData(&(pMediaInfo->MediaData[inx]));
}
return;
}
//*****************************************************************************
// Purpose :
// Dump Port info structure
// Parameters:
// IPM_PORT_INFO
// Returns:
// bool (true = success)
//*****************************************************************************
void CIptDevice::DumpPortInfo(IPM_PORT_INFO *pPort){
LOG(LOG_API, GetName(), " IP = %s:%d",pPort->cIPAddress, pPort->unPortId);
return;
}
//*****************************************************************************
// Purpose :
// Dump coder info structire
// Parameters:
// IPM_AUDIO_CODER_INFO
// Returns:
// bool (true = success)
//*****************************************************************************
void CIptDevice::DumpAudioCoderInfo(IPM_AUDIO_CODER_INFO *pCoder){
const char *coder_name = ip_coder_name(pCoder->eCoderType);
const char *framesize_name = ip_framesize_name(pCoder->eFrameSize);
const char *vad_name = ip_vad_name(pCoder->eVadEnable);
LOG(LOG_API, GetName(), " eCoderType = %d %s", pCoder->eCoderType, coder_name);
LOG(LOG_API, GetName(), " eFrameSize = %d %s", pCoder->eFrameSize, framesize_name);
LOG(LOG_API, GetName(), " unFramesPerPkt = %d", pCoder->unFramesPerPkt);
LOG(LOG_API, GetName(), " eVadEnable = %d %s", pCoder->eVadEnable, vad_name);
LOG(LOG_API, GetName(), " unCoderPayloadType = %d", pCoder->unCoderPayloadType);
LOG(LOG_API, GetName(), " unRedPayloadType = %d", pCoder->unRedPayloadType);
}
//*****************************************************************************
// Purpose :
// Dump media data structure
// Parameters:
// IPM_MEDIA
// Returns:
// bool (true = success)
//*****************************************************************************
void CIptDevice::DumpMediaData(IPM_MEDIA *pMedia){
switch(pMedia->eMediaType){
case MEDIATYPE_LOCAL_RTP_INFO:
LOG(LOG_API, GetName(), " MEDIATYPE_LOCAL_RTP_INFO");
DumpPortInfo(&pMedia->mediaInfo.PortInfo);
break;
case MEDIATYPE_REMOTE_RTP_INFO:
LOG(LOG_API, GetName(), " MEDIATYPE_REMOTE_RTP_INFO");
DumpPortInfo(&pMedia->mediaInfo.PortInfo);
break;
case MEDIATYPE_LOCAL_RTCP_INFO:
LOG(LOG_API, GetName(), " MEDIATYPE_LOCAL_RTCP_INFO");
DumpPortInfo(&pMedia->mediaInfo.PortInfo);
break;
case MEDIATYPE_REMOTE_RTCP_INFO:
LOG(LOG_API, GetName(), " MEDIATYPE_REMOTE_RTCP_INFO");
DumpPortInfo(&pMedia->mediaInfo.PortInfo);
break;
case MEDIATYPE_REMOTE_CODER_INFO:
LOG(LOG_API, GetName(), " MEDIATYPE_REMOTE_CODER_INFO");
DumpAudioCoderInfo(&pMedia->mediaInfo.AudioCoderInfo);
break;
case MEDIATYPE_LOCAL_CODER_INFO:
LOG(LOG_API, GetName(), " MEDIATYPE_LOCAL_CODER_INFO");
DumpAudioCoderInfo(&pMedia->mediaInfo.AudioCoderInfo);
break;
default:
LOG(LOG_API, GetName(), " MEDIATYPE: %d - not supported",pMedia->eMediaType );
break;
} // switch
return;
}
//*****************************************************************************
// Purpose :
// Start IP media
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CIptDevice::StartMedia(){
IPM_MEDIA_INFO MediaInfo;
unsigned int inx = 0;
if ( Is3PCCMode() ) {
MediaInfo.MediaData[inx].eMediaType = MEDIATYPE_LOCAL_RTP_INFO;
MediaInfo.MediaData[inx].mediaInfo.PortInfo = m_LocalRtpPort;
inx++;
MediaInfo.MediaData[inx].eMediaType = MEDIATYPE_LOCAL_RTCP_INFO;
MediaInfo.MediaData[inx].mediaInfo.PortInfo = m_LocalRtcpPort;
inx++;
MediaInfo.MediaData[inx].eMediaType = MEDIATYPE_REMOTE_RTP_INFO;
MediaInfo.MediaData[inx].mediaInfo.PortInfo.unPortId = m_pSdpParser->m_MediaInfo.m_remote_port;
str_safecopy( MediaInfo.MediaData[inx].mediaInfo.PortInfo.cIPAddress,
sizeof(MediaInfo.MediaData[0].mediaInfo.PortInfo.cIPAddress),
m_pSdpParser->m_MediaInfo.sdp_remote_ip );
inx++;
// This port is next to RTP port
MediaInfo.MediaData[inx].eMediaType = MEDIATYPE_REMOTE_RTCP_INFO;
MediaInfo.MediaData[inx].mediaInfo.PortInfo.unPortId = m_pSdpParser->m_MediaInfo.m_remote_port+1;
str_safecopy( MediaInfo.MediaData[inx].mediaInfo.PortInfo.cIPAddress,
sizeof(MediaInfo.MediaData[0].mediaInfo.PortInfo.cIPAddress),
m_pSdpParser->m_MediaInfo.sdp_remote_ip );
inx++;
IPM_CODER_INFO LocalCoder;
IPM_CODER_INFO RemoteCoder;
LocalCoder.eCoderType = selected_coder.eCoderType;
LocalCoder.eFrameSize = selected_coder.eFrameSize;
LocalCoder.eVadEnable = selected_coder.eVadEnable ;
LocalCoder.unFramesPerPkt = 1;
LocalCoder.unCoderPayloadType = selected_coder.unCoderPayloadType;
LocalCoder.unRedPayloadType = selected_coder.unRedPayloadType;
RemoteCoder = LocalCoder;
MediaInfo.MediaData[inx].eMediaType = MEDIATYPE_REMOTE_CODER_INFO;
MediaInfo.MediaData[inx].mediaInfo.CoderInfo = RemoteCoder;
inx++;
MediaInfo.MediaData[inx].eMediaType = MEDIATYPE_LOCAL_CODER_INFO;
MediaInfo.MediaData[inx].mediaInfo.CoderInfo = LocalCoder;
inx++;
MediaInfo.unCount = inx;
DumpMediaInfo(&MediaInfo);
int rc = ipm_StartMedia(m_ntwk_srl_handle, &MediaInfo,
DATA_IP_TDM_BIDIRECTIONAL, EV_SYNC);
LOG( RC(rc), m_ipm_name,
"%d = ipm_StartMedia (handle=0x%x,IpmMediaInfo,DATA_IP_TDM_BIDIRECTIONAL, EV_SYNC)",
rc, m_ntwk_srl_handle );
if (rc != 0){
process_ipml_error(m_ntwk_srl_handle, m_ipm_name);
return false;
} else {
m_ipm_started = true;
}
SetDtmfTransfer();
}else {
LOG(LOG_ERR1, GetName(), "Application error: StartMedia in none 3PCC mode");
}
return true;
}
//*****************************************************************************
// Purpose :
// Drop current call
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CIptDevice::DropCall(){
StopMedia();
return CNtwkDevice::DropCall();
} // End of DropCall()
//*****************************************************************************
// Purpose :
// Reset line device
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CIptDevice::ResetLineDev(){
StopMedia();
return CNtwkDevice::ResetLineDev();
} // End of ResetLineDev()
//*****************************************************************************
// Purpose :
// Answer to incoming call
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CIptDevice::AnswerCall(){
if (Is3PCCMode() ){
if (! StartMedia() ){
DropRequest();
} else {
if ( !DoAcceptCall() ){
if (! MakeSdpMessage( IPPARM_SDP_ANSWER) ){
LOG( RC(-1), GetName(),
"MakeSdpMessage failed)");
return false;
}
}
}
}
return CNtwkDevice::AnswerCall();
} // End of AnswerCall()
//*****************************************************************************
// Purpose :
// Accept to incoming call
// Parameters:
// none
// Returns:
// bool (true = success)
//*****************************************************************************
bool CIptDevice::AcceptCall(){
if (DoAcceptCall() && Is3PCCMode() ) {
if (! MakeSdpMessage( IPPARM_SDP_ANSWER) ){
LOG( RC(-1), GetName(),
"MakeSdpMessage failed)");
return false;
}
}
return CNtwkDevice::AcceptCall();
} // End of AcceptCall()
//*****************************************************************************
// Purpose :
// Handle GCEV_REQ_MODIFY_CALL
// Parameters:
// Returns:
// success flag
//*****************************************************************************
bool CIptDevice::ModifyCall(){
// Implement here responce to GCEV_REQ_MODIFY_CALL
// if ASYNC function is involved, change appropriately state machine
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -