diff --git a/icscbtimer/icscbtimer.go b/icscbtimer/icscbtimer.go index 223ac09..7bcf48d 100644 --- a/icscbtimer/icscbtimer.go +++ b/icscbtimer/icscbtimer.go @@ -11,6 +11,7 @@ type IcsCBTimer struct { ticker *time.Ticker d time.Duration cbfunc IcsCBTimerFunc + STOP chan bool } func NewCBTimer(d time.Duration, callbackfunc IcsCBTimerFunc) *IcsCBTimer { @@ -33,6 +34,8 @@ func (t *IcsCBTimer) Start() { } t.ticker = time.NewTicker(t.d) + t.STOP = make(chan bool, 1) + go t.cbfunc(t) } @@ -41,5 +44,6 @@ func (t *IcsCBTimer) Stop() { return } + t.STOP <- true t.ticker.Stop() } diff --git a/icssessionmanager/agentoperator.go b/icssessionmanager/agentoperator.go index 9fe36fe..2a97cb0 100644 --- a/icssessionmanager/agentoperator.go +++ b/icssessionmanager/agentoperator.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/google/uuid" + // "github.com/google/uuid" "gitlab.com/ics_cinnamon/voicegateway/icscbtimer" "gitlab.com/ics_cinnamon/voicegateway/icsconf" "gitlab.com/ics_cinnamon/voicegateway/icsdtmf" @@ -297,8 +297,11 @@ func (s *IcsSession) RequestInvite(inviteto string) { // postfix := "192.168.0.83" 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.callID = uuid.New().String() + s.callID = callid s.m.Unlock() callid = s.callID // if len(s.callID) != 0 { @@ -409,7 +412,9 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { //to := fmt.Sprintf("", s.AgentName, ip) // postfix := fmt.Sprintf("@%s", ip) 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 { // callid = s.callID // //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) from := fmt.Sprintf(";tag=%s", s.CustID, ip, sipasm.GenerateTag()) - to := fmt.Sprintf("", s.CustID, ip) - if s.InviteSIP != nil { - from = s.InviteSIP.From - to = s.InviteSIP.To - } + to := fmt.Sprintf("", "AISB", ip) + // if s.InviteSIP != nil { + // from = s.InviteSIP.From + // to = s.InviteSIP.To + // } //to := fmt.Sprintf("", "01025670081", "192.168.0.221") //to := fmt.Sprintf("", "01025670081", ip) //to := fmt.Sprintf("", s.AgentName, ip) @@ -1294,6 +1299,7 @@ func (s *IcsSession) SendRequestInvite() { s.simLoopCount += 1 } else { 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) l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "RTP Payload : %d [%p], Destination: %+v", s.payloadType, @@ -1419,7 +1425,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { 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") + l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "VoiceFile Read ERROR") return } // 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)) 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 s.TxConverter, cerr = icsmediaconv.NewConverter(s.ID, s.payloadType, false) if cerr != nil { @@ -1443,25 +1456,18 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { } else { 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 if conf.CallEndInfo.Value { - for lc := 0; lc < conf.CallEndInfo.Loop; lc++ { + for { // fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc) - iter := 0 - totalSentLen := 0 - offset := 0 - psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize - ts := s.rtpTS - seq := s.rtpSeq - // 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() { + 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 { - //fmt.Println("BREAK!", pcmDataLen, offset+psize*2) break } /* @@ -1470,25 +1476,9 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { - pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행) */ 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 offset+psize >= pcmDataLen { - //if offset+psize >= alawDataLen { offset = 0 } rtp = icsrtp.NewRTP(1, //set mark bit @@ -1497,13 +1487,10 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { int(ts), int(s.rtpSSRC), payload) - //alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize]) totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize offset += psize - //offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize } else { if offset+psize >= pcmDataLen { - //if offset+psize >= alawDataLen { offset = 0 } rtp = icsrtp.NewRTP(0, @@ -1512,31 +1499,22 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { int(ts), int(s.rtpSSRC), payload) - //alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize]) totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize offset += psize - //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 { - // l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "@@@@@@@@@@@@@@@@@ writRTP ERROR t1: %+v, wlen: %+v, werr: %+v\r\n", t1, wlen, werr) - 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) + // time.Sleep(time.Second) } - s.RequestBYE(s.InviteSIP) + // s.RequestBYE(s.InviteSIP) } else { for { iter := 0 @@ -1547,11 +1525,9 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { seq := s.rtpSeq for t1 := range t.GetTick() { if pcmDataLen < offset+psize*2 { - //fmt.Println("BREAK!", pcmDataLen, offset+psize*2) break } 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 { l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError()) return @@ -2061,13 +2037,13 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) { s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip) l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri) - to := fmt.Sprintf("", s.CustID, ip) + to := fmt.Sprintf("", "AISB", ip) if s.InviteSIP != nil { from = s.InviteSIP.From - to = s.InviteSIP.To + // to = s.InviteSIP.To } - // to := strings.SplitN(inviteSIP.To, ": ", 2) - //to := fmt.Sprintf("", s.AgentName, ip) + // to := strings.SplitN(inviteSIP.To, ":", 2) + // to := fmt.Sprintf("", s.AgentName, ip) callid := inviteSIP.GetCallID() cseq := fmt.Sprintf("%d BYE", 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_MAX_FORWARDS, maxforwards) - reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, to) - reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, from) + reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, from) + reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, to) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq) reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)