|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package icssessionmanager
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/binary"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
|
@ -27,6 +28,11 @@ import (
|
|
|
|
|
"gitlab.com/ics_cinnamon/voicegateway/sipasm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
REFER = 0
|
|
|
|
|
RANGE = 10000
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (s *IcsSession) SetRegisterStatus(status int) int {
|
|
|
|
|
s.registerStatus = status
|
|
|
|
|
|
|
|
|
@ -275,15 +281,23 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
agentString := func() string {
|
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
index := rand.Intn(1)
|
|
|
|
|
list := []string{"07012345678"}
|
|
|
|
|
return list[index]
|
|
|
|
|
}()
|
|
|
|
|
fmt.Println(agentString)
|
|
|
|
|
|
|
|
|
|
//sim
|
|
|
|
|
inviteMethod := fmt.Sprintf("sip:%s@172.31.29.47;transport=%s", s.AgentName, transport) // nlb(DNS)를 한번 갔다온 ip를 넣어줘야함.
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", s.AgentName, ip)
|
|
|
|
|
from := fmt.Sprintf("<sip:%s@%s>;tag=%s", inviteto, ip, sipasm.GenerateTag())
|
|
|
|
|
if conf.Representative.Value {
|
|
|
|
|
inviteMethod = fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", ip, transport)
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip)
|
|
|
|
|
to = fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
|
|
|
|
|
inviteMethod = fmt.Sprintf("sip:%s@%s;transport=%s", agentString, ip, transport)
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", agentString, ip)
|
|
|
|
|
to = fmt.Sprintf("<sip:%s@%s;user=phone>", agentString, ip)
|
|
|
|
|
// agentName := s.AgentName
|
|
|
|
|
// agentSplit := agentName[len(agentName)-2:len(agentName)]
|
|
|
|
|
// telNo := fmt.Sprintf("010243427%s", agentSplit)
|
|
|
|
@ -334,9 +348,11 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, s.referto)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAINUMBER, s.xaiNumber)
|
|
|
|
|
//reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_EXPIRES, expires)
|
|
|
|
|
|
|
|
|
|
if agentString == "AISB" {
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, s.referto)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAINUMBER, s.xaiNumber)
|
|
|
|
|
}
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
@ -344,15 +360,12 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, sdpLength)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
s.inviteDuration = time.Now()
|
|
|
|
|
wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqInvite.String()))
|
|
|
|
|
if werr != nil {
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// s.callID = callid
|
|
|
|
|
// s.callID = uuid.New().String()
|
|
|
|
|
|
|
|
|
|
if conf.Representative.Value {
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_READY)
|
|
|
|
|
} else {
|
|
|
|
@ -365,6 +378,7 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
|
reqInvite.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inviteFunc()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -373,6 +387,12 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
|
|
|
|
|
agentString := func() string {
|
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
index := rand.Intn(1)
|
|
|
|
|
list := []string{"07012345678"}
|
|
|
|
|
return list[index]
|
|
|
|
|
}()
|
|
|
|
|
// TODO - send bye
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
@ -391,26 +411,36 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
inviteMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", proxy, transport)
|
|
|
|
|
inviteMethod := fmt.Sprintf("sip:%s@%s;transport=%s", agentString, proxy, transport)
|
|
|
|
|
reqInvite := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_INVITE, inviteMethod)
|
|
|
|
|
|
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP %s;rport;branch=%s", ip, sipasm.GenerateBranch())
|
|
|
|
|
maxforwards := "70"
|
|
|
|
|
agentName := s.AgentName
|
|
|
|
|
agentSplit := agentName[len(agentName)-2 : len(agentName)]
|
|
|
|
|
agentSplit := agentName[len(agentName)-1:]
|
|
|
|
|
_, atoiErr := strconv.Atoi(agentSplit)
|
|
|
|
|
if atoiErr != nil {
|
|
|
|
|
agentSplit = fmt.Sprint("0", agentSplit[1:])
|
|
|
|
|
}
|
|
|
|
|
cust1 := strings.SplitN(sip.From, "@", 2)
|
|
|
|
|
cust2 := strings.SplitN(cust1[0], ":", 2)
|
|
|
|
|
|
|
|
|
|
telNo := fmt.Sprintf("%s%s", cust2[1][0:9], agentSplit)
|
|
|
|
|
telNo := fmt.Sprintf("%s%s", cust2[1][0:8], agentSplit)
|
|
|
|
|
s.CustID = telNo
|
|
|
|
|
|
|
|
|
|
fmt.Println(s.CustID)
|
|
|
|
|
|
|
|
|
|
from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", telNo, ip, sipasm.GenerateTag())
|
|
|
|
|
|
|
|
|
|
fmt.Println(telNo)
|
|
|
|
|
fmt.Println(from)
|
|
|
|
|
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
s.referto = sip.XAICall
|
|
|
|
|
s.xaiNumber = sip.XAICallNumber
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", agentString, ip)
|
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
|
|
|
|
|
// postfix := fmt.Sprintf("@%s", ip)
|
|
|
|
|
var callid string
|
|
|
|
@ -429,7 +459,7 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
s.m.Unlock()
|
|
|
|
|
cseq := fmt.Sprintf("%d INVITE", s.Cseq)
|
|
|
|
|
s.Cseq++
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", "AISB", ip, port, transport)
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", agentString, ip, port, transport)
|
|
|
|
|
//expires := fmt.Sprintf("%d", conf.AgentConfig[s.ID].RegisterConfig.RegisterExpire)
|
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
@ -448,14 +478,19 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, sip.XAICall)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAINUMBER, s.xaiNumber)
|
|
|
|
|
if agentString == "AISB" {
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, sip.XAICall)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAINUMBER, s.xaiNumber)
|
|
|
|
|
}
|
|
|
|
|
//reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_EXPIRES, expires)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_TYPE, "application/sdp")
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, sdpLength)
|
|
|
|
|
if agentString != "AISB" {
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_DIVERSION, "07077399939")
|
|
|
|
|
}
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send INVITE! [%s] -> [%s] \r\n %+v\r\n",
|
|
|
|
@ -856,6 +891,8 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
// s.InviteSIP = sip
|
|
|
|
|
|
|
|
|
|
inviteDuration := time.Since(s.inviteDuration)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "####INVITE <-> INVITE ACK => %+v", inviteDuration)
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
// set agentinfo
|
|
|
|
@ -916,7 +953,7 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", s.CustID, ip, sipasm.GenerateTag())
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "07012345678", ip)
|
|
|
|
|
// if s.InviteSIP != nil {
|
|
|
|
|
// from = s.InviteSIP.From
|
|
|
|
|
// to = s.InviteSIP.To
|
|
|
|
@ -1102,6 +1139,7 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// fmt.Println(s)
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
wlen,
|
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
@ -1422,20 +1460,30 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
// seq := s.rtpSeq
|
|
|
|
|
|
|
|
|
|
// voiceFilePath := "/home/leejj9612/sim/voice/9001-RX-1648533187911907029.pcm"
|
|
|
|
|
voiceFilePath := "/home/icsvsim/voice/Sample.pcm"
|
|
|
|
|
voiceFilePath := "/home/icsvsim/voice/tvoice.wav"
|
|
|
|
|
readPcmData, ferr := ioutil.ReadFile(voiceFilePath)
|
|
|
|
|
if ferr != nil {
|
|
|
|
|
// fmt.Println("Read Voice File error ", ferr)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "VoiceFile Read ERROR")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData)
|
|
|
|
|
|
|
|
|
|
s.m.Lock()
|
|
|
|
|
// pcmDataLen := len(s.tts)
|
|
|
|
|
pcmDataLen := len(readPcmData)
|
|
|
|
|
|
|
|
|
|
//ljhwan
|
|
|
|
|
// pcmDataLen := len(readPcmData)
|
|
|
|
|
// pcmData := make([]byte, pcmDataLen*46)
|
|
|
|
|
|
|
|
|
|
// for count := 0; count < 46; count++ {
|
|
|
|
|
// copy(pcmData[(pcmDataLen-44)*count:], readPcmData[44:]) //cut off wave header
|
|
|
|
|
// }
|
|
|
|
|
pcmDataLen := len(readPcmData) - 44
|
|
|
|
|
pcmData := make([]byte, pcmDataLen)
|
|
|
|
|
copy(pcmData, readPcmData[44:]) //cut off wave header
|
|
|
|
|
|
|
|
|
|
// pcmData := make([]byte, pcmDataLen)
|
|
|
|
|
//copy(pcmData, readPcmData) //cut off wave header
|
|
|
|
|
// fmt.Printf("@@@@@ Read Data len: %d\r\n@@@@@ data: %+v\r\n@@@@@ copyData: %+v \r\n\r\n", pcmDataLen, readPcmData, pcmData)
|
|
|
|
|
//pcmData := s.tts[44:] //cut off wave header
|
|
|
|
|
//fmt.Println("pcmData len>>>", pcmDataLen, len(s.tts))
|
|
|
|
@ -1458,96 +1506,122 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var rtp *icsrtp.RTP
|
|
|
|
|
if conf.CallEndInfo.Value {
|
|
|
|
|
|
|
|
|
|
if !conf.CallEndInfo.Value {
|
|
|
|
|
// for {
|
|
|
|
|
// // fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc)
|
|
|
|
|
// select {
|
|
|
|
|
// case <-t.STOP:
|
|
|
|
|
// // s.rrData.Clear()
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
|
|
|
|
|
// return
|
|
|
|
|
// case <-t.GetTick():
|
|
|
|
|
// if s.TTSFlag.Load().(bool) {
|
|
|
|
|
// iter = 0
|
|
|
|
|
// totalSentLen = 0
|
|
|
|
|
// offset = 0
|
|
|
|
|
// psize = icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
// ts = s.rtpTS
|
|
|
|
|
// seq = s.rtpSeq
|
|
|
|
|
// } else {
|
|
|
|
|
// offset = pcmDataLen
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if pcmDataLen < offset+psize {
|
|
|
|
|
// continue
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// payload := pcmData[offset : offset+psize]
|
|
|
|
|
|
|
|
|
|
// if iter == 0 {
|
|
|
|
|
// if offset+psize >= pcmDataLen {
|
|
|
|
|
// offset = 0
|
|
|
|
|
// }
|
|
|
|
|
// rtp = icsrtp.NewRTP(1, //set mark bit
|
|
|
|
|
// int(s.payloadType),
|
|
|
|
|
// int(seq),
|
|
|
|
|
// int(ts),
|
|
|
|
|
// int(s.rtpSSRC),
|
|
|
|
|
// payload)
|
|
|
|
|
// totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
// offset += psize
|
|
|
|
|
// } else {
|
|
|
|
|
// if offset+psize >= pcmDataLen {
|
|
|
|
|
// offset = 0
|
|
|
|
|
// }
|
|
|
|
|
// rtp = icsrtp.NewRTP(0,
|
|
|
|
|
// int(s.payloadType),
|
|
|
|
|
// int(seq),
|
|
|
|
|
// int(ts),
|
|
|
|
|
// int(s.rtpSSRC),
|
|
|
|
|
// payload)
|
|
|
|
|
// totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
// offset += psize
|
|
|
|
|
// }
|
|
|
|
|
// iter++
|
|
|
|
|
// ts += uint32(psize)
|
|
|
|
|
// seq++
|
|
|
|
|
// s.txCnt++
|
|
|
|
|
|
|
|
|
|
// wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
|
|
|
|
|
// if werr != nil {
|
|
|
|
|
// fmt.Println(wlen, werr)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// // time.Sleep(time.Second)
|
|
|
|
|
// }
|
|
|
|
|
// s.RequestBYE(s.InviteSIP)
|
|
|
|
|
} else {
|
|
|
|
|
// iter := 0
|
|
|
|
|
// totalSentLen := 0
|
|
|
|
|
// offset := pcmDataLen
|
|
|
|
|
// psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
// ts := s.rtpTS
|
|
|
|
|
// seq := s.rtpSeq
|
|
|
|
|
// s.PreTTSFlag = true
|
|
|
|
|
for {
|
|
|
|
|
// fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc)
|
|
|
|
|
select {
|
|
|
|
|
case <-t.STOP:
|
|
|
|
|
// s.rrData.Clear()
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
|
|
|
|
|
return
|
|
|
|
|
case <-t.GetTick():
|
|
|
|
|
if pcmDataLen < offset+psize {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
uplus에서 샘플 음성으로 pcma를 사용(이미 인코딩 되있는 음성파일이라 읽어서 160씩 보내주면됨)
|
|
|
|
|
- 인코딩 할 필요 없는 파일이라 인코딩 제거
|
|
|
|
|
- pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행)
|
|
|
|
|
*/
|
|
|
|
|
payload := pcmData[offset : offset+psize]
|
|
|
|
|
|
|
|
|
|
if iter == 0 {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
epd := s.epd
|
|
|
|
|
if epd == 2 {
|
|
|
|
|
if s.preepd == 1 {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## SEND TTS ")
|
|
|
|
|
iter = 0
|
|
|
|
|
totalSentLen = 0
|
|
|
|
|
offset = 0
|
|
|
|
|
psize = icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
ts = s.rtpTS
|
|
|
|
|
seq = s.rtpSeq
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(1, //set mark bit
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize
|
|
|
|
|
} else {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
} else if epd == 1 {
|
|
|
|
|
if s.preepd == 0 {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## STOP TTS ")
|
|
|
|
|
offset = pcmDataLen
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(0,
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize
|
|
|
|
|
}
|
|
|
|
|
iter++
|
|
|
|
|
ts += uint32(psize)
|
|
|
|
|
seq++
|
|
|
|
|
s.txCnt++
|
|
|
|
|
|
|
|
|
|
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
|
|
|
|
|
if werr != nil {
|
|
|
|
|
fmt.Println(wlen, werr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// time.Sleep(time.Second)
|
|
|
|
|
}
|
|
|
|
|
// s.RequestBYE(s.InviteSIP)
|
|
|
|
|
} else {
|
|
|
|
|
for {
|
|
|
|
|
iter := 0
|
|
|
|
|
totalSentLen := 0
|
|
|
|
|
offset := 0
|
|
|
|
|
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
ts := s.rtpTS
|
|
|
|
|
seq := s.rtpSeq
|
|
|
|
|
for t1 := range t.GetTick() {
|
|
|
|
|
if pcmDataLen < offset+psize*2 {
|
|
|
|
|
break
|
|
|
|
|
s.preepd = epd
|
|
|
|
|
data := make([]byte, 0)
|
|
|
|
|
if pcmDataLen < offset+psize*2 || epd != 2 {
|
|
|
|
|
data = make([]byte, psize*2)
|
|
|
|
|
for index, _ := range data {
|
|
|
|
|
data[index] = 0x00
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
data = pcmData[offset : offset+psize*2]
|
|
|
|
|
}
|
|
|
|
|
payload, convErr := s.TxConverter.Encode(pcmData[offset : offset+psize*2])
|
|
|
|
|
|
|
|
|
|
payload, convErr := s.TxConverter.Encode(data)
|
|
|
|
|
if convErr != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1048@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
/*
|
|
|
|
|
wflen, wferr := ttsfile1.Write(payload)
|
|
|
|
|
if wferr != nil {
|
|
|
|
|
fmt.Println("file.write error", wferr, wflen)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
ttsfile1.Sync()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if iter == 0 {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(1, //set mark bit
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
@ -1557,12 +1631,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize * 2
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
} else {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(0,
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
@ -1572,32 +1641,30 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize * 2
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
}
|
|
|
|
|
iter++
|
|
|
|
|
ts += uint32(psize)
|
|
|
|
|
seq++
|
|
|
|
|
s.txCnt++
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1095@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
|
|
|
|
|
if werr != nil {
|
|
|
|
|
fmt.Println(t1, wlen, werr)
|
|
|
|
|
fmt.Println(wlen, werr)
|
|
|
|
|
}
|
|
|
|
|
//fmt.Printf("wlen: %d\r", totalSentLen)
|
|
|
|
|
//l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", wlen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("Sent RTP(%d) to [%s] [%s]\r\n", totalSentLen, s.rtpMediaNeter.RemoteAddr().String(), s.AgentName )
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", totalSentLen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
// s.RequestBYE(s.InviteSIP)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *IcsSession) ReadRTP() {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
defer func() {
|
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
|
fmt.Println("ReadRTP Panic", r)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "ReadRTP Panic - %s", r)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
svc := icssvc.GetServiceStatus()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
|
|
|
|
@ -1620,15 +1687,12 @@ func (s *IcsSession) ReadRTP() {
|
|
|
|
|
// s.ExpTimer.Start()
|
|
|
|
|
// go s.ExpiredRTP(s.readTimer)
|
|
|
|
|
for !svc.GetExit() || !svc.GetStop() {
|
|
|
|
|
//fmt.Println(">>>", s.ID, s.rtpMediaNeter.LocalAddr().String())
|
|
|
|
|
|
|
|
|
|
if s.rtpMediaNeter == nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "######### media neter nil!!!")
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, _, rlen, rerr := s.rtpMediaNeter.ReadRTP()
|
|
|
|
|
//data, raddr, rlen, rerr := s.rtpMediaNeter.ReadRTP()
|
|
|
|
|
if rerr != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "%s-%s", rerr.GetMessage(), rerr.GetError())
|
|
|
|
|
break
|
|
|
|
@ -1642,7 +1706,6 @@ func (s *IcsSession) ReadRTP() {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
RPT := rtp.GetPayloadType()
|
|
|
|
|
|
|
|
|
|
if RPT == icspacketparser.PayloadType(101) { //rfc2833
|
|
|
|
|
///////////////
|
|
|
|
|
//dtmf
|
|
|
|
@ -1688,6 +1751,37 @@ func (s *IcsSession) ReadRTP() {
|
|
|
|
|
// fmt.Println("Recev 21 TTS!!!")
|
|
|
|
|
s.expRead = time.Now()
|
|
|
|
|
s.expCheck = false
|
|
|
|
|
pcm, cerr := s.RxConverter.Decode(rtp.Payload)
|
|
|
|
|
if cerr != nil {
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_ERROR, s.ID, cerr.GetMessage())
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
average, _ := calAverage(pcm)
|
|
|
|
|
if average > REFER+RANGE {
|
|
|
|
|
s.vaildcnt++
|
|
|
|
|
if s.vaildcnt > 5 {
|
|
|
|
|
s.silencecnt = 0
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
s.silencecnt++
|
|
|
|
|
if s.silencecnt > 50 {
|
|
|
|
|
s.vaildcnt = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.silencecnt > 200 {
|
|
|
|
|
if s.epd == 1 {
|
|
|
|
|
s.epd = 2
|
|
|
|
|
s.silencecnt = 0
|
|
|
|
|
} else if s.epd == 2 {
|
|
|
|
|
s.epd = 0
|
|
|
|
|
}
|
|
|
|
|
} else if s.vaildcnt > 10 {
|
|
|
|
|
if s.epd == 0 {
|
|
|
|
|
s.epd = 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//rtp decoding
|
|
|
|
|
pcm, cerr := s.RxConverter.Decode(rtp.Payload)
|
|
|
|
@ -1730,6 +1824,25 @@ func (s *IcsSession) ReadRTP() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func calAverage(target []byte) (int, error) {
|
|
|
|
|
var sum uint32 = 0
|
|
|
|
|
var err error = nil
|
|
|
|
|
|
|
|
|
|
length := len(target)
|
|
|
|
|
if length != 0 {
|
|
|
|
|
for i := 0; i < length; i += 2 {
|
|
|
|
|
if i+1 < length {
|
|
|
|
|
data := []byte{target[i+1], target[i]}
|
|
|
|
|
sum = sum + uint32(binary.BigEndian.Uint16(data))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
err = fmt.Errorf("Error: integer divide by zero %+v", target)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return int(int(sum) / (length / 2)), err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// func (s *IcsSession)ExpiredRTP(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
func (s *IcsSession) ExpiredRTP(t time.Ticker) {
|
|
|
|
|
s.mychannel = make(chan bool)
|
|
|
|
@ -1956,7 +2069,7 @@ func (s *IcsSession) RequestBYESIM() {
|
|
|
|
|
// contactName := strings.SplitN(contactName1[1], "@", 2)
|
|
|
|
|
|
|
|
|
|
optfunc := func() {
|
|
|
|
|
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", conf.SIPConfig.SIPProxy, transport)
|
|
|
|
|
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "07012345678", conf.SIPConfig.SIPProxy, transport)
|
|
|
|
|
reqOpt := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_BYE, optMethod)
|
|
|
|
|
|
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP %s:%d;branch=%s", ip, port, sipasm.GenerateBranch())
|
|
|
|
@ -2025,7 +2138,7 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
|
|
|
|
|
// contactName := strings.SplitN(contactName1[1], "@", 2)
|
|
|
|
|
|
|
|
|
|
optfunc := func() {
|
|
|
|
|
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", conf.SIPConfig.SIPProxy, transport)
|
|
|
|
|
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "07012345678", conf.SIPConfig.SIPProxy, transport)
|
|
|
|
|
reqOpt := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_BYE, optMethod)
|
|
|
|
|
|
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP %s:%d;branch=%s", ip, port, sipasm.GenerateBranch())
|
|
|
|
@ -2034,10 +2147,10 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
|
|
|
|
|
// from := strings.SplitN(inviteSIP.From, ": ", 2)
|
|
|
|
|
//from := fmt.Sprintf("<sip:%s@%s>;tag=%s", s.AgentName, ip, sipasm.GenerateTag())
|
|
|
|
|
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip)
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", "07012345678", ip)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "07012345678", ip)
|
|
|
|
|
if s.InviteSIP != nil {
|
|
|
|
|
from = s.InviteSIP.From
|
|
|
|
|
// to = s.InviteSIP.To
|
|
|
|
@ -2048,7 +2161,7 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
|
|
|
|
|
cseq := fmt.Sprintf("%d BYE", s.Cseq)
|
|
|
|
|
s.Cseq++
|
|
|
|
|
//referto := fmt.Sprintf("<sip:01025670081@192.168.0.221>")
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", "AISB", ip, port, transport)
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", "07012345678", ip, port, transport)
|
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
|
supported := "timer,path,replaces"
|
|
|
|
|