📄 simpleextdevice.cxx
字号:
cpLog( LOG_DEBUG, "rtp port %d released", port ); port = audioStack->releaseRtcpPort(); cpLog( LOG_DEBUG, "rtcp port %d released", port ); delete audioStack; audioStack = 0; } if ( _DTMFInterface ) { delete _DTMFInterface; _DTMFInterface = 0; } deviceMutex.unlock();}//***************************************************************************//***************************************************************************//***************************************************************************// SimpleExtDevice::audioStart//// description: creates a new rtp session and also allocates memory for// incoming and outgoing rtp packet. //***************************************************************************intSimpleExtDevice::audioStart (const HardwareAudioRequest& request){ if ( audioActive ) { cpLog(LOG_ERR, "Audio channel is already active. Ignoring"); return 0; } deviceMutex.lock(); if ( audioStack == 0 ) { audioStack = new RtpSession(request.remoteHost, request.remotePort, request.localPort, request.remotePort + 1, request.localPort + 1, rtpPayloadPCMU, rtpPayloadPCMU, 5); } else { RtpSessionState sessionState = audioStack->getSessionState(); switch ( sessionState ) { case rtp_session_sendonly: //turn on the receive if ( request.localPort != 0 ) { audioStack->setSessionState(rtp_session_sendrecv); audioStack->setReceiver(request.localPort, request.localPort + 1, 0, rtpPayloadPCMU, rtpPayloadPCMU, 5); } break; case rtp_session_recvonly: //turn on the send if ( request.remotePort != 0 ) { audioStack->setSessionState(rtp_session_sendrecv); audioStack->setTransmiter(request.remoteHost, request.remotePort, request.remotePort + 1, rtpPayloadPCMU, rtpPayloadPCMU); } break; case rtp_session_sendrecv: deviceMutex.unlock(); return 0; break; default: audioStack->setSessionState(rtp_session_sendrecv); //turn on the send if ( request.remotePort != 0 ) { audioStack->setTransmiter(request.remoteHost, request.remotePort, request.remotePort + 1, rtpPayloadPCMU, rtpPayloadPCMU); } //turn on the receive if ( request.localPort != 0 ) { audioStack->setReceiver(request.localPort, request.localPort + 1, 0, rtpPayloadPCMU, rtpPayloadPCMU, 5); } break; } } _DTMFInterface = new RtpDevice < SimpleExtDevice > ( this ); audioStack->setDTMFInterface( _DTMFInterface ); // allocate RTP packet spaces inRtpPkt = 0; audioStack->setSessionState(rtp_session_sendrecv); audioStack->setNetworkPktSize( request.rtpPacketSize * 8); networkPktSize = request.rtpPacketSize; audioStack->setApiPktSize(request.rtpPacketSize * 8); packetCount = 0; // mark audio as active audioActive = true; hasPlayed = false;// nextTime = vm_gettimeofday(); deviceMutex.unlock(); return 0;} // end SimpleExtDevice::audioStart()//***************************************************************************// SimpleExtDevice::audioStop//// description: tears down audio. cleans up by delete objects created when// audioStart was called... inBuffer, outBuffer, audioStack,// rtp packets.//***************************************************************************intSimpleExtDevice::audioStop (void){ // if (!audioActive) return 1; // mark audio as deactivated. cpLog(LOG_DEBUG, "Audio Stop received."); deviceMutex.lock(); audioActive = false; hookStateOffhook = false; reportEvent(sessionQ, DeviceEventHookDown); player.stop(); recorder.close();// vm.sendClose(); close(ss); ss = -1; cpLog(LOG_DEBUG,"End of session"); if ( audioStack ) { audioStack->unsetDTMFInterface( _DTMFInterface ); delete audioStack; audioStack = NULL; } if ( _DTMFInterface ) { delete _DTMFInterface; _DTMFInterface = 0; } cpLog(LOG_DEBUG, "Num of RTP packets received :%d", packetCount); deviceMutex.unlock(); return 0;} // end SimpleExtDevice::audioStop()voidSimpleExtDevice::provideRingStart(){ deviceMutex.lock(); if( ss > 0 ) { cpLog(LOG_ERR, "Already active!!! (%d)", ss); deviceMutex.unlock(); return ; } /* Redundancy : Try to connect to the one of the Vmservers * configured in the config file. */ vector<string>& vmServers=UaConfiguration::instance()->getVMServers(); unsigned int i; for( i = 0; i < vmServers.size() ; i++ ) { /** Open the socket */ cpLog(LOG_DEBUG,"Trying %s:%d",vmServers[i].c_str(),8024); /** Connect to the Server */#if 0 if( vm.connect(vmServers[i].c_str(),8024) ) { cpLog(LOG_DEBUG,"Server connected"); break; } else { cpLog(LOG_DEBUG,"Server not responding, trying the next one"); }#endif } if( i==vmServers.size() ) { cpLog(LOG_ERR,"Can't find any live vm servers"); /** Release the Mutex */ deviceMutex.unlock(); return; } // ss = vm.getFd();// vm.setSessionInfo(CallerId,CalleeId,"5000",ForwardReason,NumberOfForwards); hookStateOffhook = true; reportEvent(sessionQ, DeviceEventHookUp); deviceMutex.unlock();}voidSimpleExtDevice::provideRingStop(){}voidSimpleExtDevice::provideDialToneStart(){}voidSimpleExtDevice::provideDialToneStop(){}voidSimpleExtDevice::provideLocalRingbackStart(){}voidSimpleExtDevice::provideLocalRingbackStop(){}voidSimpleExtDevice::provideBusyToneStart(){}voidSimpleExtDevice::provideBusyToneStop(){}voidSimpleExtDevice::provideFastBusyToneStart(){}voidSimpleExtDevice::provideFastBusyToneStop(){}voidSimpleExtDevice::provideCallWaitingBeepStart(){}voidSimpleExtDevice::provideCallWaitingBeepStop(){}voidSimpleExtDevice::provideDtmf(DeviceSignalType signal){ char digit; switch ( signal ) { case DeviceSignalDigitStar: digit = '*'; break; case DeviceSignalDigitHash: digit = '#'; break; case DeviceSignalDigit0: digit = '0'; break; case DeviceSignalDigit1: digit = '1'; break; case DeviceSignalDigit2: digit = '2'; break; case DeviceSignalDigit3: digit = '3'; break; case DeviceSignalDigit4: digit = '4'; break; case DeviceSignalDigit5: digit = '5'; break; case DeviceSignalDigit6: digit = '6'; break; case DeviceSignalDigit7: digit = '7'; break; case DeviceSignalDigit8: digit = '8'; break; case DeviceSignalDigit9: digit = '9'; break; default: cpLog(LOG_ERR, "Unrecognized DTMF key received from event stack"); return; } deviceMutex.lock(); cpLog(LOG_DEBUG, "Sending %d to vmserver", digit);// vm.sendDtmf(digit); deviceMutex.unlock(); return ;}voidSimpleExtDevice::recvRTPDTMF( int digit, int duration ){ cpLog(LOG_DEBUG, "DTMF digit %d has been received from RTP stack", digit); DeviceSignalType dtmfSignal = DeviceSignalNULL; switch ( digit ) { case 0: reportEvent(sessionQ, DeviceEventDtmf0); break; case 1: reportEvent(sessionQ, DeviceEventDtmf1); break; case 2: reportEvent(sessionQ, DeviceEventDtmf2); break; case 3: reportEvent(sessionQ, DeviceEventDtmf3); break; case 4: reportEvent(sessionQ, DeviceEventDtmf4); break; case 5: reportEvent(sessionQ, DeviceEventDtmf5); break; case 6: reportEvent(sessionQ, DeviceEventDtmf6); break; case 7: reportEvent(sessionQ, DeviceEventDtmf7); break; case 8: reportEvent(sessionQ, DeviceEventDtmf8); break; case 9: reportEvent(sessionQ, DeviceEventDtmf9); break; case 10: reportEvent(sessionQ, DeviceEventDtmfStar); break; case 11: reportEvent(sessionQ, DeviceEventDtmfHash); break; default: cpLog(LOG_ERR, "Unrecognized DTMF key received from RTP stack"); return; } Sptr < UaHardwareEvent > signal = new UaHardwareEvent( UaDevice::getDeviceQueue() ); signal->type = HardwareSignalType; signal->signalOrRequest.signal = dtmfSignal; UaDevice::getDeviceQueue()->add( signal ); return ;}voidSimpleExtDevice::provideCallInfo(string sCallerId, string sCalleeId, string sForwardReason){ cpLog(LOG_DEBUG, "Call from %s to %s", sCallerId.c_str(), sCalleeId.c_str()); CallerId = sCallerId; CalleeId = sCalleeId; if ( CalleeId == "" ) CalleeId = "5000"; if ( CallerId == "" ) CallerId = "unknown"; cpLog(LOG_DEBUG,"Sending call info"); if ( sCalleeId == "5000" ) { cpLog(LOG_DEBUG," Direct call to 5000"); NumberOfForwards = 0; ForwardReason = "UNK"; } else if ( sForwardReason == "" || sForwardReason == "Unknown" && !fwdFlag ) { cpLog(LOG_DEBUG," Forward reason unknown"); NumberOfForwards = 0; ForwardReason = "UNK"; } else { cpLog(LOG_DEBUG," Forward No Answer"); NumberOfForwards = 1; ForwardReason = "FNA"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -