Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
jiyoungcheon | ff8a931e66 | 2 weeks ago |
jiyoungcheon | 62b2392347 | 2 weeks ago |
jiyoungcheon | af2fc0fef5 | 3 weeks ago |
jiyoungcheon | e1027615b8 | 3 weeks ago |
jiyoungcheon | 1541c9013e | 3 weeks ago |
jiyoungcheon | 6935143044 | 3 weeks ago |
jiyoungcheon | 2ff652d860 | 3 weeks ago |
jiyoungcheon | 350160ebc1 | 3 weeks ago |
jiyoungcheon | 35287f83de | 3 weeks ago |
jiyoungcheon | 8081bd62f0 | 3 weeks ago |
jiyoungcheon | 4f4ee4afac | 3 weeks ago |
= | f0b490e2b2 | 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/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue