Compare commits

...

12 Commits

Author SHA1 Message Date
jiyoungcheon ff8a931e66 rollback 2 weeks ago
jiyoungcheon 62b2392347 voiceName, speed, volume, pitch -> string to int 2 weeks ago
jiyoungcheon af2fc0fef5 UnixMilli method does not exist 3 weeks ago
jiyoungcheon e1027615b8 announcement 잘못된 코드 제거 3 weeks ago
jiyoungcheon 1541c9013e dubug log was not printing due to setup 3 weeks ago
jiyoungcheon 6935143044 unixmilli->unixnano 3 weeks ago
jiyoungcheon 2ff652d860 timecheck added 3 weeks ago
jiyoungcheon 350160ebc1 방향 바꿈, 중복제거 3 weeks ago
jiyoungcheon 35287f83de joy4 deleted 3 weeks ago
jiyoungcheon 8081bd62f0 icsanalyzesip.go deleted 3 weeks ago
jiyoungcheon 4f4ee4afac log added with theccinnamon joy4 3 weeks ago
= f0b490e2b2 poc용 최신 3 months ago

@ -1 +1 @@
scp -v -i /home/ljhwan206/etc/key.pem voicegateway ec2-user@15.165.95.232:/home/ec2-user/vgw/svc/icsbot/bin/
scp -v -i /home/ljhwan206/etc/key.pem voicebot ec2-user@15.165.95.232:/home/ec2-user/vgw/svc/icsbot/bin/

@ -7,7 +7,8 @@ require (
cloud.google.com/go/texttospeech v1.0.0
github.com/gorilla/websocket v1.4.2
github.com/stretchr/testify v1.7.0
gitlab.com/ics_cinnamon/joy4 v1.0.25
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb
)
replace gitlab.com/ics_cinnamon/joy4 => ../joy4

@ -162,7 +162,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@ -180,10 +179,6 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
gitlab.com/ics_cinnamon/joy4 v1.0.24 h1:MQlMxeJ5ZBEerHzHf1D+/ruTeA1YXJKL5XbJdI3NVf4=
gitlab.com/ics_cinnamon/joy4 v1.0.24/go.mod h1:LFfF6nA92KMmd/hrGEgQzkIsX/n+IlqCI8vbY8/NnNI=
gitlab.com/ics_cinnamon/joy4 v1.0.25 h1:e20ciX68hnLv50GVENWDeyYkKz0XiX6ALevQfeSfrQc=
gitlab.com/ics_cinnamon/joy4 v1.0.25/go.mod h1:LFfF6nA92KMmd/hrGEgQzkIsX/n+IlqCI8vbY8/NnNI=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@ -193,8 +188,6 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
gocv.io/x/gocv v0.27.0 h1:3X8I74ULsWHd4m7DQRv2Nqx5VkKscfUFnKgLNodiboI=
gocv.io/x/gocv v0.27.0/go.mod h1:n4LnYjykU6y9gn48yZf4eLCdtuSb77XxSkW6g0wGf/A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

@ -62,104 +62,6 @@ func (exe IcsExec) Execute() *icserror.IcsError {
sm := icssessionmanager.NewSessionManager()
sm.Load()
/////////////////////////////////////////////////////////////////////
//start Heart beat TCP server
// hbDone := make(chan *icserror.IcsError)
// if exe.config.HeartBeat.Value {
// go func() {
// saddr := fmt.Sprintf(":%d", exe.config.HeartBeat.Port)
// hbladdr := icsnet.NewNetAddrWithIPAddr(saddr)
// var hbErr *icserror.IcsError
// //set handler
// exe.hbNet, hbErr = icsnet.ListenAndServeTCP(&hbladdr, nil, LINEEND1, TCPConnHandlerHeartBeat)
// if hbErr != nil {
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "Heart beat Listen - %s", hbErr.GetError())
// hbDone <- hbErr
// } else {
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Liesting Heart beat - %s", saddr)
// }
// }()
// }
// /////////////////////////////////////////////////////////////////////
// //start Call signal TCP server
// csDone := make(chan *icserror.IcsError)
// p1 := &exe.config.ServerConfig.CSConfig.Port
// go func() {
// //saddr := fmt.Sprintf("%s:%d", exe.config.STTConfig.SrcIP, exe.config.STTConfig.Port)
// cslAddr := icsnet.NewNetAddrWithIPPort("0.0.0.0", *p1)
// //cslAddr := icsnet.NewNetAddrWithIPPort("0.0.0.0", exe.config.AgentConfig[idx].CSConfig.Port)
// //cslAddr := icsnet.NewNetAddrWithIPPort("0.0.0.0", exe.config.AgentConfig[iter].CSConfig.Port)
// var csErr *icserror.IcsError
// //set handler
// exe.csNet, csErr = icsnet.ListenAndServeTCP(&cslAddr, nil, LINEEND2, TCPConnHandlerCS)
// if csErr != nil {
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "Call Signal Listen failure - %s", csErr.GetMessage())
// csDone <- csErr
// } else {
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Listening Call Signal - %s", cslAddr)
// }
// }()
// /////////////////////////////////////////////////////////////////////
// //start STT TCP server
// sttDone := make(chan *icserror.IcsError)
// if exe.config.STTConfig.Value {
// go func() {
// saddr := fmt.Sprintf("%s:%d", exe.config.STTConfig.SrcIP, exe.config.STTConfig.Port)
// STTladdr := icsnet.NewNetAddrWithIPAddr(saddr)
// var sttErr *icserror.IcsError
// //set handler
// exe.sttNet, sttErr = icsnet.ListenAndServeTCP(&STTladdr, nil, LINEEND1, TCPConnHandlerSTT)
// if sttErr != nil {
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "STT Listen failure - %s", sttErr.GetMessage())
// sttDone <- sttErr
// } else {
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Listening STT - %s", saddr)
// }
// //sttDone <- nil
// }()
// }
// /////////////////////////////////////////////////////////////////////
// //start TTS TCP server
// ttsDone := make(chan *icserror.IcsError)
// if exe.config.TTSConfig.Value {
// go func() {
// saddr := fmt.Sprintf("%s:%d", exe.config.TTSConfig.SrcIP, exe.config.TTSConfig.Port)
// TTSladdr := icsnet.NewNetAddrWithIPAddr(saddr)
// var ttsErr *icserror.IcsError
// //set handler
// exe.ttsNet, ttsErr = icsnet.ListenAndServeTCP(&TTSladdr, nil, LINEEND2, TCPConnHandlerTTS)
// if ttsErr != nil {
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "TTS Listen - %s", ttsErr.GetMessage())
// ttsDone <- ttsErr
// } else {
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Listening TTS - %s", saddr)
// }
// //ttsDone <- nil
// }()
// }
// /////////////////////////////////////////////////////////////////////
// //start command TCP server
// cmdDone := make(chan *icserror.IcsError)
// if exe.config.CommandConfig.Value {
// go func() {
// saddr := fmt.Sprintf("%s:%d", exe.config.CommandConfig.SrcIP, exe.config.CommandConfig.Port)
// CMDladdr := icsnet.NewNetAddrWithIPAddr(saddr)
// var cmdErr *icserror.IcsError
// //set handler
// exe.cmdNet, cmdErr = icsnet.ListenAndServeTCP(&CMDladdr, nil, LINEEND2, TCPConnHandlerCommand)
// if cmdErr != nil {
// l.Printf(icslog.LOG_LEVEL_ERROR, -1, "Bot Command Listen - %s", cmdErr.GetMessage())
// cmdDone <- cmdErr
// } else {
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Listeing Bot Command Listen - %s", saddr)
// }
// //ttsDone <- nil
// }()
// }
/////////////////////////////////////////////////////////////////////
//make http handler
httpDone := make(chan error)

File diff suppressed because it is too large Load Diff

@ -183,3 +183,81 @@ func (l *IcsLog) Print(level int, sessionID int, msg string) {
l.M.Unlock()
}
}
func (l *IcsLog) PrintAnnouce(msg string, customer bool) {
//check disk full
aSpace := icsutil.GetDiskAvailableSpace(filepath.Dir(l.LogFileName))
if aSpace < uint64(l.conf.Disklimit*ONEMB) {
//if aSpace < uint64(l.conf.LogConfig.Disklimit*ONEMB) {
if !l.IsDiskFull {
msg = fmt.Sprintf("Disk Full! Available Disk Space: %dMB", aSpace/ONEMB)
l.logger.Output(2, msg)
if l.LogFile != nil {
l.LogFile.WriteString(l.buf.String())
}
l.buf.Reset()
l.IsDiskFull = true
}
return
}
l.M.Lock()
if l.checkLogRotate() {
//check log size
stat, err := os.Stat(l.LogFileName)
if err != nil {
msg = fmt.Sprintf("Could not get log file(%s) size", l.LogFileName)
l.logger.Output(2, msg)
if l.LogFile != nil {
l.LogFile.WriteString(l.buf.String())
}
l.buf.Reset()
l.M.Unlock()
return
}
if stat.Size()/ONEMB >= int64(l.logSize) {
//shift log files
rotateNum := gIcsLog.getTodayLogFileNum()
//fmt.Println("rotate num:", rotateNum, "log size:", stat.Size()/ONEMB, l.logSize)
if rotateNum > 0 && rotateNum < gIcsLog.rotateNum {
gIcsLog.shiftLogFiles(rotateNum)
l.LogFile.Sync()
l.LogFile.Close()
//open new log file
var oerr error
l.LogFile, oerr = os.OpenFile(l.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if oerr != nil {
icserror.ICSERRFileOpen.SetError(oerr)
icserror.ICSERRFileOpen.PrintWithCaller(0)
l.M.Unlock()
return
}
} else {
l.M.Unlock()
return
}
}
}
var logmsg string
if customer {
logmsg = fmt.Sprintf(">>> %s\n", msg)
} else {
logmsg = fmt.Sprintf("<<< %s\n", msg)
}
l.logger.Output(2, logmsg)
if l.LogFile != nil {
l.LogFile.WriteString(l.buf.String())
}
l.buf.Reset()
l.M.Unlock()
}

@ -1,147 +0,0 @@
package icsmediaconv
import (
"sync"
"gitlab.com/cinnamon/voiceagent/icserror"
"gitlab.com/cinnamon/voiceagent/icslog"
"gitlab.com/cinnamon/voiceagent/icspacketparser"
"gitlab.com/ics_cinnamon/joy4/av"
"gitlab.com/ics_cinnamon/joy4/cgo/ffmpeg"
"gitlab.com/ics_cinnamon/joy4/codec"
)
const (
ICS_PT_MULAW = 0
ICS_PT_ALAW = 8
ICS_PT_G729 = 18
ICS_PT_END = ICS_PT_G729
)
const PCM_8K_16BIT_10MS_SIZE = 160
type Converter struct {
payloadtype icspacketparser.PayloadType
codec av.AudioCodecData
decoder *ffmpeg.AudioDecoder
samplingRate int
onePacketSize int
isStart bool
m *sync.Mutex
ID int
}
func NewConverter(id int, pt icspacketparser.PayloadType) (*Converter, *icserror.IcsError) {
conv := &Converter{payloadtype: pt}
conv.ID = id
conv.isStart = false
conv.m = &sync.Mutex{}
switch pt {
case ICS_PT_MULAW:
conv.codec = codec.NewPCMMulawCodecData()
conv.samplingRate = 8000
conv.onePacketSize = 160
case ICS_PT_ALAW:
conv.codec = codec.NewPCMAlawCodecData()
conv.samplingRate = 8000
conv.onePacketSize = 160
case ICS_PT_G729:
conv.codec = codec.NewG729CodecData()
conv.samplingRate = 8000
conv.onePacketSize = 10
default:
return nil, icserror.ICSERRCONVNotSupportedCodec
}
var err error
conv.decoder, err = ffmpeg.NewAudioDecoder(conv.codec)
if err != nil {
icserror.ICSERRCONVNotSupportedCodec.SetError(err)
return nil, icserror.ICSERRCONVNotSupportedCodec
}
ffmpeg.SetLogLevel(ffmpeg.QUIET)
conv.Start()
l := icslog.GetIcsLog()
l.Printf(icslog.LOG_LEVEL_DEBUG2, id, "### NewDecode()")
return conv, nil
}
func (c *Converter) Start() {
c.m.Lock()
c.isStart = true
c.m.Unlock()
}
func (c *Converter) Stop() {
c.m.Lock()
c.isStart = false
c.m.Unlock()
}
func (c *Converter) IsStart() bool {
return c.isStart
}
func (c *Converter) Close() {
c.Stop()
c.decoder.Close()
l := icslog.GetIcsLog()
l.Print(icslog.LOG_LEVEL_INFO, c.ID, "Closed Decoder")
}
func (c *Converter) Decode(packet []byte) ([]byte, *icserror.IcsError) {
//l := icslog.GetIcsLog()
//l.Printf(icslog.LOG_LEVEL_DEBUG2, -1, "converter### Decode() packet length: %d", len(packet))
retBuf := make([]byte, PCM_8K_16BIT_10MS_SIZE*2)
packetLen := len(packet)
iter := 0
for packetLen >= c.onePacketSize {
packetLen -= c.onePacketSize
//fmt.Printf("### Decode() iter(%d) packetlen(%d)\n", iter, packetLen)
buf := packet[c.onePacketSize*iter : c.onePacketSize*(iter+1)]
//fmt.Printf("### Decode() iter(%d), buf length %d %v\n", iter, len(buf), buf)
//l.Printf(icslog.LOG_LEVEL_DEBUG2, c.ID, "### Decode() iter(%d), buf length %d %v", iter, len(buf), buf)
c.m.Lock()
if c.IsStart() {
ok, frame, errDec := c.decoder.Decode(buf)
if !ok {
icserror.ICSERRCONVDecodeFail.SetError(errDec)
//icserror.ICSERRCONVDecodeFail.Print()
c.m.Unlock()
return nil, icserror.ICSERRCONVDecodeFail
}
//fmt.Println("###frame len", iter, PCM_8K_16BIT_10MS_SIZE*iter, PCM_8K_16BIT_10MS_SIZE*(iter+1))
//fmt.Println("###frame len", len(frame.Data[0]), len(frame.Data), frame)
copy(retBuf[PCM_8K_16BIT_10MS_SIZE*iter:PCM_8K_16BIT_10MS_SIZE*(iter+1)], frame.Data[0][:PCM_8K_16BIT_10MS_SIZE])
}
c.m.Unlock()
/*
f1, err := os.OpenFile("./tx.voice.raw", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
f1.Write(frame.Data[0][:PCM_8K_16BIT_10MS_SIZE])
f1.Sync()
f1.Close()
*/
iter++
}
//fmt.Println("###retBuf len", len(retBuf), retBuf)
return retBuf, nil
}

@ -1,76 +0,0 @@
package icssessionmanager
import (
"strings"
"gitlab.com/cinnamon/voiceagent/icserror"
"gitlab.com/cinnamon/voiceagent/icslog"
"gitlab.com/cinnamon/voiceagent/icspacketparser"
"gitlab.com/cinnamon/voiceagent/icssvc"
"gitlab.com/cinnamon/voiceagent/recorddata"
)
func (s *IcsSession) analyzeRTP(rtp *icspacketparser.RTP) *icserror.IcsError {
l := icslog.GetIcsLog()
RPT := rtp.GetPayloadType()
SPT := s.GetPayloadType()
if SPT == RPT {
if s.VoiceNeter == nil {
l.Print(icslog.LOG_LEVEL_ERROR, s.ID, icserror.ICSERRNETNotConnectError.GetMessage())
return icserror.ICSERRNETNotConnectError
}
voicedata := recorddata.NewVoiceData()
svc := icssvc.GetServiceStatus()
conf := svc.GetIcsConfig()
if strings.Compare(conf.HTTPConfig.SrcIP, rtp.SrcAddr.IPv4String) == 0 { //RX
//if strings.Compare(conf.PbxConfig.PbxIp, rtp.SrcAddr.IPv4String) == 0 { //RX
/*//////////////////
s.rxFile.Write(rtp.Payload)
*/ //////////////////
pcm, err := s.RxConverter.Decode(rtp.Payload)
if err != nil {
l.Print(icslog.LOG_LEVEL_ERROR, s.ID, err.GetMessage())
return err
}
if s.rxSeq == -1 {
s.rxSeq = int(rtp.Seq)
}
voicedata.SetData(s.ServerID, s.Station, int32(rtp.Seq-uint16(s.rxSeq)), s.StartTimeStamp, "0", "0", pcm)
wsize, err := s.VoiceNeter.Write(voicedata.GetData())
if wsize == -1 || err != nil {
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "RTP send error-%v", err.GetError())
return err
}
} else { //TX
/*//////////////////
s.txFile.Write(rtp.Payload)
*/ //////////////////
pcm, err := s.TxConverter.Decode(rtp.Payload)
if err != nil {
l.Print(icslog.LOG_LEVEL_ERROR, s.ID, err.GetMessage())
return err
}
if s.txSeq == -1 {
s.txSeq = int(rtp.Seq)
}
voicedata.SetData(s.ServerID, s.Station, int32(rtp.Seq-uint16(s.txSeq)), s.StartTimeStamp, "1", "0", pcm)
wsize, err := s.VoiceNeter.Write(voicedata.GetData())
if wsize == -1 || err != nil {
//l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "RTP send error-%v", err.GetError())
return err
}
}
} else {
l.Print(icslog.LOG_LEVEL_ERROR, s.ID, "NO same payload type!!!")
}
return nil
}

@ -1,211 +0,0 @@
package icssessionmanager
import (
"strconv"
"strings"
"time"
"gitlab.com/cinnamon/voiceagent/icserror"
"gitlab.com/cinnamon/voiceagent/icslog"
"gitlab.com/cinnamon/voiceagent/icsmediaconv"
"gitlab.com/cinnamon/voiceagent/icsnet"
"gitlab.com/cinnamon/voiceagent/icspacketparser"
"gitlab.com/cinnamon/voiceagent/icssvc"
"gitlab.com/cinnamon/voiceagent/recorddata/writecallsignal"
)
func (s *IcsSession) analyzeSIP(sip *icspacketparser.SIP) *icserror.IcsError {
// fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>")
// fmt.Println("sip.Method", sip.Method)
// fmt.Println("sip.Version", sip.Version)
// fmt.Println("sip.Headers", sip.Headers)
// fmt.Println("sip.Source", sip.Source)
// fmt.Printf("%+v\n", sip)
//fmt.Println(">>>>>>>>>>>>>>>>>>>>>>> sip.Method", sip.Method)
l := icslog.GetIcsLog()
// fmt.Println(">>>>>>>>>>>>>>>>>>>>>>> sip.Method", sip.Method)
if sip.Method == icspacketparser.ICS_SIP_METHOD_INVITE {
s.setSrcPort(sip)
payload, err := s.setSDPMediaPayload(sip)
if err != nil {
return icserror.ICSERRSDPAudiotagPortValue
} else {
s.invitePayloads = payload
}
} else if strings.Contains(sip.Cseq, " INVITE") {
s.setDstPort(sip)
}
if sip.Method == icspacketparser.ICS_SIP_METHOD_SIP20 && !s.isFoundPayload {
// fmt.Println(">>>>>>>>>>>>>>> ICS_SIP_METHOD_SIP20", sip.ResType, sip.ContentType, sip.ContentLength)
if strings.Contains(sip.ContentType, "sdp") && sip.ContentLength > 0 {
payload, err := s.compareSDPMediaPayload(sip)
if err != nil {
return icserror.ICSERRSDPAudiotagPortValue
} else {
s.isFoundPayload = true
s.payloadType = icspacketparser.PayloadType(payload)
//fmt.Println("s.payload >>>>>>>>>>>>>>>", s.payloadType)
//create media decoder
var cerr *icserror.IcsError
s.TxConverter, cerr = icsmediaconv.NewConverter(s.ID, s.payloadType)
if cerr != nil {
//s.isFoundPayload = false
//cerr.Print()
l.Printf(icslog.LOG_LEVEL_FATAL, s.ID, "Failed to New Tx Converter-%v", cerr)
s.SendVoiceGatewayByeSignal()
return cerr
} else {
l.Print(icslog.LOG_LEVEL_INFO, s.ID, "New Tx Converter(Decoder)")
}
s.RxConverter, cerr = icsmediaconv.NewConverter(s.ID, s.payloadType)
if cerr != nil {
//s.isFoundPayload = false
l.Printf(icslog.LOG_LEVEL_FATAL, s.ID, "Failed to New Rx Converter-%v", cerr)
s.SendVoiceGatewayByeSignal()
return cerr
} else {
l.Print(icslog.LOG_LEVEL_INFO, s.ID, "New Rx Converter(Decoder)")
}
//init VoiceAgent net
conf := icssvc.GetServiceStatus().GetIcsConfig()
if conf != nil {
//set call signal remote addr
csraddr := icsnet.NewNetAddrWithIPPort("127.0.0.1", 1111)
csladdr := icsnet.NewNetAddrWithIPPort("127.0.0.1", 2222)
//csraddr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.AgentAddr.VoiceAgentIP, conf.VoiceAgentConfig.AgentAddr.CallSignalPort)
//csladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.ServerPort)
//set Voice remote addr
vraddr := icsnet.NewNetAddrWithIPPort("127.0.0.1", 3333)
//vraddr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.AgentAddr.VoiceAgentIP, conf.VoiceAgentConfig.AgentAddr.VoicePort)
//vladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.BasePort)
s.VoiceNeter = icsnet.NewUDP(nil, &vraddr)
//s.VoiceNeter = icsnet.NewUDP(&vladdr, &vraddr)
conerr := s.VoiceNeter.Connect()
if conerr != nil {
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Error init Voice Neter[%s->%s]-%v", s.VoiceNeter.LocalAddr().String(), vraddr.String(), conerr.GetError())
s.SendVoiceGatewayByeSignal()
return conerr
}
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Voice(UDP) Connected to VoiceAgent[%s->%s]", s.VoiceNeter.LocalAddr().String(), vraddr.String())
//send call signal data to VoiceAgent
defer func() {
if err := recover(); err != nil {
l.Print(icslog.LOG_LEVEL_WARN, s.ID, icserror.ICSERRNETNotConnectError.GetMessage())
}
}()
var inout string = "O"
if s.GetDirection() {
inout = "I"
}
callsignal := writecallsignal.NewCallSignalData()
//callsignal := recorddata.NewCallSignalData()
//s.StartTimeStamp = time.Now().UnixNano() / 1e6
s.StartTimeStamp = time.Now().UnixNano()
callsignal.SetData(s.ChannelID, s.ServerID, s.Station, "CUSTID", s.StartTimeStamp, 0, "S", inout)
wlen, werr := icsnet.SendCallSignal(&csladdr, &csraddr, callsignal.GetData())
if werr == nil {
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Transmitted Call-Start signal to VoiceAgent(%d)", wlen)
}
}
}
}
}
return nil
}
func (s *IcsSession) setSrcPort(sip *icspacketparser.SIP) *icserror.IcsError {
if sip.Content == nil {
//error 처리 invite인데, sdp 데이터가 없음
return icserror.ICSERRINVITERequired
} else {
// fmt.Println("sdpMedias", *sip.Content.Media)
port, err := s.findSDPMediaAudioPort(sip)
if err != nil {
return icserror.ICSERRSDPAudiotagPortValue
} else {
s.srcPort = port
}
}
return nil
}
func (s *IcsSession) setDstPort(sip *icspacketparser.SIP) *icserror.IcsError {
// fmt.Println(">>>>>>>>>>>>>>>>>>>>>>> sip.Cseq", sip.Cseq, sip.Method)
if sip.Method == icspacketparser.ICS_SIP_METHOD_SIP20 && sip.ResType == "200" {
if sip.Content == nil {
//error 처리 INVITE처리의 200 OK인데, sdp 데이터가 없음
return icserror.ICSERR200OKRequired
} else {
// fmt.Println("sdpMedias", *sip.Content.Media)
port, err := s.findSDPMediaAudioPort(sip)
if err != nil {
return icserror.ICSERRSDPAudiotagPortValue
} else {
s.dstPort = port
}
}
} else if sip.Method == icspacketparser.ICS_SIP_METHOD_BYE {
//fmt.Println(">>>>>>>>>>> haup up event")
// s.RemoveSession()
}
return nil
}
func (s *IcsSession) findSDPMediaAudioPort(sip *icspacketparser.SIP) (int, *icserror.IcsError) {
for _, value := range *sip.Content.Media {
if strings.Contains(value.MediaDescription, "audio ") {
arrSdpMedia := strings.Split(value.MediaDescription, " ")
port, err := strconv.Atoi(arrSdpMedia[1])
if err != nil {
return -1, icserror.ICSERRSDPAudiotagPortValue
} else {
//fmt.Println(">>>>>>>>>>>>>>>>>>>>>>> port", port)
return port, nil
}
} else {
return -1, icserror.ICSERRNotFoundSdpMedia
}
}
return -1, icserror.ICSERRNotFoundSdpMedia
}
func (s *IcsSession) setSDPMediaPayload(sip *icspacketparser.SIP) ([]string, *icserror.IcsError) {
for _, value := range *sip.Content.Media {
if strings.Contains(value.MediaDescription, "audio ") {
//fmt.Println("value.Payload >>>>>>>>>>>", value.Payload)
return value.Payload, nil
} else {
return nil, icserror.ICSERRNotFoundSdpMedia
}
}
return nil, icserror.ICSERRNotFoundSdpMedia
}
func (s *IcsSession) compareSDPMediaPayload(sip *icspacketparser.SIP) (int, *icserror.IcsError) {
for _, value := range *sip.Content.Media {
for _, thisPayload := range value.Payload {
for _, invitePayload := range s.invitePayloads {
if thisPayload == invitePayload {
payload, err := strconv.Atoi(thisPayload)
if err != nil {
return -1, icserror.ICSERRSDPAudiotagPortValue
} else {
return payload, nil
}
}
}
}
}
return -1, icserror.ICSERRNotFoundSdpMedia
}

@ -14,7 +14,6 @@ import (
"gitlab.com/cinnamon/voiceagent/icsevent"
"gitlab.com/cinnamon/voiceagent/icshttpclient"
"gitlab.com/cinnamon/voiceagent/icslog"
"gitlab.com/cinnamon/voiceagent/icsmediaconv"
"gitlab.com/cinnamon/voiceagent/icsnet"
"gitlab.com/cinnamon/voiceagent/icspacketparser"
"gitlab.com/cinnamon/voiceagent/icssvc"
@ -23,7 +22,6 @@ import (
"gitlab.com/cinnamon/voiceagent/recorddata/readcallsignal"
"gitlab.com/cinnamon/voiceagent/recorddata/responsecs"
"gitlab.com/cinnamon/voiceagent/stt"
"gitlab.com/ics_cinnamon/joy4/format"
)
type IcsSession struct {
@ -52,13 +50,13 @@ type IcsSession struct {
invitePayloads []string
payloadType icspacketparser.PayloadType
isFoundPayload bool
TxConverter *icsmediaconv.Converter
RxConverter *icsmediaconv.Converter
txSeq int //first TX seq num
rxSeq int //first RX seq num
STTTx *stt.STT
STTRx *stt.STT
cs *readcallsignal.CallSignal
// TxConverter *icsmediaconv.Converter
// RxConverter *icsmediaconv.Converter
txSeq int //first TX seq num
rxSeq int //first RX seq num
STTTx *stt.STT
STTRx *stt.STT
cs *readcallsignal.CallSignal
isSTTStartTimer *time.Timer
isSTTStart bool
@ -107,12 +105,12 @@ const (
//////////////////////////////////////////////////////////////////
//session routine
//init ffmpeg
func init() {
format.RegisterAll()
}
// // init ffmpeg
// func init() {
// format.RegisterAll()
// }
//on/off check the session idle
// on/off check the session idle
func (s *IcsSession) Start() {
s.SetTimestamp(time.Now())
@ -358,13 +356,13 @@ func (s *IcsSession) Run() *icserror.IcsError {
*/
case icspacketparser.SIP:
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Get SIP Event[%d]", evt.ID)
sip := v
s.analyzeSIP(&sip)
// sip := v
// s.analyzeSIP(&sip)
case icspacketparser.RTP:
//l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Get RTP Event[%d]", evt.ID)
rtp := v
// rtp := v
//fmt.Println(rtp)
s.analyzeRTP(&rtp)
// s.analyzeRTP(&rtp)
//default:
//fmt.Println(time.Now(), "NOT DEFINED EVENT TYPE!!!!!!!!!!!!!!!!!")
default:

@ -17,8 +17,8 @@ import (
"gitlab.com/cinnamon/voiceagent/recorddata/responsecs"
)
//////////////////////////////////////////////////////////////////
//session operator
// ////////////////////////////////////////////////////////////////
// session operator
func findSessionWithCallID(callId string) *IcsSession {
sessions := getSessionInstance()
for _, session := range sessions {
@ -256,14 +256,14 @@ func (s *IcsSession) RemoveSession() *icserror.IcsError {
s.sstation = e.sstation
s.isFoundPayload = false
if s.RxConverter != nil {
s.RxConverter.Close()
s.RxConverter = nil
}
if s.TxConverter != nil {
s.TxConverter.Close()
s.TxConverter = nil
}
// if s.RxConverter != nil {
// s.RxConverter.Close()
// s.RxConverter = nil
// }
// if s.TxConverter != nil {
// s.TxConverter.Close()
// s.TxConverter = nil
// }
s.botStatus = nil
s.botToken = ""
@ -313,8 +313,7 @@ func (s *IcsSession) CheckSignalMethod(sip icspacketparser.SIP) *icserror.IcsErr
return nil
}
//////////////////////////////////////////////////////////////////
//
// ////////////////////////////////////////////////////////////////
func (s *IcsSession) SetTimestamp(now time.Time) {
s.lastTimestamp = now
}
@ -412,8 +411,8 @@ func (s *IcsSession) SendVoiceGatewayBotByeSignal(url string, custid string, sst
}
}
//////////////////////////////////////////
//DTMF
// ////////////////////////////////////////
// DTMF
// add DTMF
func (s *IcsSession) AddDtmf() {
inputDtmf := s.cs.InOut

Binary file not shown.

Binary file not shown.

@ -62,8 +62,8 @@ func main() {
}
//configuration
configFile := fmt.Sprintf("/home/icsbot/config/icsbot.xml")
//configFile := fmt.Sprintf("%s/config/icsvc.xml", service.GetHomeDir())
// configFile := fmt.Sprintf("/home/icsbot/config/icsbot.xml")
configFile := fmt.Sprintf("%s/config/icsbot.xml", homeDir)
//fmt.Println("Config file:", configFile)
conf, confErr := icsconf.OpenConfig(configFile, homeDir)
if confErr != nil {

Loading…
Cancel
Save