1. rtp stop 수정

2. simul loop count 수정
main
jjLee 2 years ago
parent 24e317271d
commit 72e3723564

@ -11,6 +11,7 @@ type IcsCBTimer struct {
ticker *time.Ticker ticker *time.Ticker
d time.Duration d time.Duration
cbfunc IcsCBTimerFunc cbfunc IcsCBTimerFunc
STOP chan bool
} }
func NewCBTimer(d time.Duration, callbackfunc IcsCBTimerFunc) *IcsCBTimer { func NewCBTimer(d time.Duration, callbackfunc IcsCBTimerFunc) *IcsCBTimer {
@ -33,6 +34,8 @@ func (t *IcsCBTimer) Start() {
} }
t.ticker = time.NewTicker(t.d) t.ticker = time.NewTicker(t.d)
t.STOP = make(chan bool, 1)
go t.cbfunc(t) go t.cbfunc(t)
} }
@ -41,5 +44,6 @@ func (t *IcsCBTimer) Stop() {
return return
} }
t.STOP <- true
t.ticker.Stop() t.ticker.Stop()
} }

@ -10,7 +10,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/google/uuid" // "github.com/google/uuid"
"gitlab.com/ics_cinnamon/voicegateway/icscbtimer" "gitlab.com/ics_cinnamon/voicegateway/icscbtimer"
"gitlab.com/ics_cinnamon/voicegateway/icsconf" "gitlab.com/ics_cinnamon/voicegateway/icsconf"
"gitlab.com/ics_cinnamon/voicegateway/icsdtmf" "gitlab.com/ics_cinnamon/voicegateway/icsdtmf"
@ -297,8 +297,11 @@ func (s *IcsSession) RequestInvite(inviteto string) {
// postfix := "192.168.0.83" // postfix := "192.168.0.83"
var callid string var callid string
now := time.Now().UnixNano()
callid = fmt.Sprintf("%d%s2@%s", now, s.AgentName,ip)
// s.callID = uuid.New().String()
s.m.Lock() s.m.Lock()
s.callID = uuid.New().String() s.callID = callid
s.m.Unlock() s.m.Unlock()
callid = s.callID callid = s.callID
// if len(s.callID) != 0 { // if len(s.callID) != 0 {
@ -409,7 +412,9 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip) //to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
// postfix := fmt.Sprintf("@%s", ip) // postfix := fmt.Sprintf("@%s", ip)
var callid string var callid string
callid = uuid.New().String() // callid = uuid.New().String()
now := time.Now().UnixNano()
callid = fmt.Sprintf("%d%s2@%s", now, agentName,ip)
// if len(s.callID) != 0 { // if len(s.callID) != 0 {
// callid = s.callID // callid = s.callID
// //if len(s.regiCallID) != 0 { // //if len(s.regiCallID) != 0 {
@ -908,11 +913,11 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri) 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()) from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", s.CustID, ip, sipasm.GenerateTag())
to := fmt.Sprintf("<sip:%s@%s;user=phone>", s.CustID, ip) to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
if s.InviteSIP != nil { // if s.InviteSIP != nil {
from = s.InviteSIP.From // from = s.InviteSIP.From
to = s.InviteSIP.To // to = s.InviteSIP.To
} // }
//to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", "192.168.0.221") //to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", "192.168.0.221")
//to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", ip) //to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", ip)
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip) //to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
@ -1294,6 +1299,7 @@ func (s *IcsSession) SendRequestInvite() {
s.simLoopCount += 1 s.simLoopCount += 1
} else { } else {
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END %d !!!!!!!\r\n", s.AgentName, s.simLoopCount) l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END %d !!!!!!!\r\n", s.AgentName, s.simLoopCount)
s.simLoopCount = 1
} }
} }
@ -1386,7 +1392,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
} }
}() }()
l.Print(icslog.LOG_LEVEL_INFO, s.ID, "Started Callback SendRTPCB") l.Print(icslog.LOG_LEVEL_INFO, s.ID, "######## Started Callback SendRTPCB")
//fmt.Printf(">>>>>neter: %d %+v\n", s.ID, s.rtpMediaNeter) //fmt.Printf(">>>>>neter: %d %+v\n", s.ID, s.rtpMediaNeter)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "RTP Payload : %d [%p], Destination: %+v", l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "RTP Payload : %d [%p], Destination: %+v",
s.payloadType, s.payloadType,
@ -1419,7 +1425,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
readPcmData, ferr := ioutil.ReadFile(voiceFilePath) readPcmData, ferr := ioutil.ReadFile(voiceFilePath)
if ferr != nil { if ferr != nil {
// fmt.Println("Read Voice File error ", ferr) // fmt.Println("Read Voice File error ", ferr)
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ VoiceFile Read ERROR") l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "VoiceFile Read ERROR")
return return
} }
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData) // l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData)
@ -1435,6 +1441,13 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
//fmt.Println("pcmData len>>>", pcmDataLen, len(s.tts)) //fmt.Println("pcmData len>>>", pcmDataLen, len(s.tts))
s.m.Unlock() s.m.Unlock()
iter := 0
totalSentLen := 0
offset := 0
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
ts := s.rtpTS
seq := s.rtpSeq
var cerr *icserror.IcsError var cerr *icserror.IcsError
s.TxConverter, cerr = icsmediaconv.NewConverter(s.ID, s.payloadType, false) s.TxConverter, cerr = icsmediaconv.NewConverter(s.ID, s.payloadType, false)
if cerr != nil { if cerr != nil {
@ -1443,25 +1456,18 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
} else { } else {
l.Print(icslog.LOG_LEVEL_INFO, s.ID, "New Tx Converter(Encoder)") l.Print(icslog.LOG_LEVEL_INFO, s.ID, "New Tx Converter(Encoder)")
} }
//defer s.TxConverter.Close()
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "@@@@@@@@@@@@@@@@@ pcmDataLen : %d, loop Count: %d \r\n", pcmDataLen, conf.CallEndInfo.Loop)
// fmt.Printf("@@@@@@@@@@@@@@@@@ pcmDataLen : %d, loop Count: %d \r\n", pcmDataLen, conf.CallEndInfo.Loop)
//fmt.Println(">>>", s.payloadType, icspacketparser.RTPPayloadInfo[s.payloadType].PSize)
var rtp *icsrtp.RTP var rtp *icsrtp.RTP
if conf.CallEndInfo.Value { if conf.CallEndInfo.Value {
for lc := 0; lc < conf.CallEndInfo.Loop; lc++ { for {
// fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc) // fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc)
iter := 0 select {
totalSentLen := 0 case <-t.STOP:
offset := 0 // s.rrData.Clear()
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
ts := s.rtpTS return
seq := s.rtpSeq case <- t.GetTick():
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "@@@@@@@@@@@@@@@@@ writRTP ERROR offset: %+v, psize: %+v, ts: %+v\r\n", offset, psize, ts)
for t1 := range t.GetTick() {
if pcmDataLen < offset+psize { if pcmDataLen < offset+psize {
//fmt.Println("BREAK!", pcmDataLen, offset+psize*2)
break break
} }
/* /*
@ -1470,25 +1476,9 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
- pcma 160 ( ) - pcma 160 ( )
*/ */
payload := pcmData[offset : offset+psize] payload := pcmData[offset : offset+psize]
//payload, convErr := s.TxConverter.Encode(s.tts[offset : offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
// 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 iter == 0 {
if offset+psize >= pcmDataLen { if offset+psize >= pcmDataLen {
//if offset+psize >= alawDataLen {
offset = 0 offset = 0
} }
rtp = icsrtp.NewRTP(1, //set mark bit rtp = icsrtp.NewRTP(1, //set mark bit
@ -1497,13 +1487,10 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
int(ts), int(ts),
int(s.rtpSSRC), int(s.rtpSSRC),
payload) payload)
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
offset += psize offset += psize
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
} else { } else {
if offset+psize >= pcmDataLen { if offset+psize >= pcmDataLen {
//if offset+psize >= alawDataLen {
offset = 0 offset = 0
} }
rtp = icsrtp.NewRTP(0, rtp = icsrtp.NewRTP(0,
@ -1512,31 +1499,22 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
int(ts), int(ts),
int(s.rtpSSRC), int(s.rtpSSRC),
payload) payload)
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
offset += psize offset += psize
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
} }
iter++ iter++
ts += uint32(psize) ts += uint32(psize)
seq++ seq++
s.txCnt++ s.txCnt++
//fmt.Printf("1095@@@@ %+v\n", s.rtpMediaNeter)
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte()) wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
if werr != nil { if werr != nil {
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "@@@@@@@@@@@@@@@@@ writRTP ERROR t1: %+v, wlen: %+v, werr: %+v\r\n", t1, wlen, werr) fmt.Println(wlen, werr)
fmt.Println(t1, 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 ) // time.Sleep(time.Second)
// 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) // s.RequestBYE(s.InviteSIP)
} else { } else {
for { for {
iter := 0 iter := 0
@ -1547,11 +1525,9 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
seq := s.rtpSeq seq := s.rtpSeq
for t1 := range t.GetTick() { for t1 := range t.GetTick() {
if pcmDataLen < offset+psize*2 { if pcmDataLen < offset+psize*2 {
//fmt.Println("BREAK!", pcmDataLen, offset+psize*2)
break break
} }
payload, convErr := s.TxConverter.Encode(pcmData[offset : offset+psize*2]) payload, convErr := s.TxConverter.Encode(pcmData[offset : offset+psize*2])
//payload, convErr := s.TxConverter.Encode(s.tts[offset : offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
if convErr != nil { if convErr != nil {
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError()) l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError())
return return
@ -2061,13 +2037,13 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip) s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri) l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
to := fmt.Sprintf("<sip:%s@%s;user=phone>", s.CustID, ip) to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
if s.InviteSIP != nil { if s.InviteSIP != nil {
from = s.InviteSIP.From from = s.InviteSIP.From
to = s.InviteSIP.To // to = s.InviteSIP.To
} }
// to := strings.SplitN(inviteSIP.To, ": ", 2) // to := strings.SplitN(inviteSIP.To, ":", 2)
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip) // to := fmt.Sprintf("<sip:AISB@%s;user=phone>", s.AgentName, ip)
callid := inviteSIP.GetCallID() callid := inviteSIP.GetCallID()
cseq := fmt.Sprintf("%d BYE", s.Cseq) cseq := fmt.Sprintf("%d BYE", s.Cseq)
s.Cseq++ s.Cseq++
@ -2080,8 +2056,8 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, via) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, via)
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, to) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, from)
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, from) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, to)
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)

Loading…
Cancel
Save