Esempio n. 1
0
        void DoItFromSocketMessage(byte[] buffer)
        {
            CommandMsg msg = util.GetObject <CommandMsg>(buffer);

            //if (msg.cmd == USRSTRUCTS.ENABLE_NAT_CALL_RECORD_RES)
            //{
            //    timer = new System.Timers.Timer();
            //    timer.Interval = 40000;
            //    timer.Elapsed += Sessiontimer_Elapsed;
            //    timer.Start();

            //    if (RecordRequestedSuccessOnNatEvent != null)
            //        RecordRequestedSuccessOnNatEvent(this, msg);

            //    return;
            //}

            RecordInfo_t recInfo = util.GetObject <RecordInfo_t>(buffer);

            int nDataSize = recInfo.size - 12;

            if (nDataSize != 80 && nDataSize != 160 && nDataSize != 240 && nDataSize != 10 && nDataSize != -12)
            {
                return;
            }

            // util.WriteLog(string.Format("seq:{0}, ext:{1}, peer:{2}, isExtension:{3}, size:{4}, bytesLength:{5}", recInfo.seq, recInfo.extension, recInfo.peer_number, recInfo.isExtension, recInfo.size - 12, recInfo.voice.Length));

            this.StackRtp2Instance(recInfo);
        }
Esempio n. 2
0
        private void DoItFromSocketMessage(object sender, object e)
        {
            switch (client.SocketMsgKinds)
            {
            case MsgKinds.CdrRequest:
                CdrRequest_t cdr_req = (CdrRequest_t)e;
                CdrList      cdrlist = (CdrList)util.GetObject <CdrList>(cdr_req.data);

                HUDPClient cl = (HUDPClient)sender;
                cl.Send(2, MsgKinds.CdrResponse, cdr_req);
                break;

            case MsgKinds.RecordInfo:
                RecordInfo_t recInfo = (RecordInfo_t)e;
                //if (recInfo.isExtension == 0)
                //    return;

                //string filename = string.Empty;
                //byte[] voiceSrc = recInfo.voice;
                int nDataSize = recInfo.size - 12;

                if (nDataSize != 80 && nDataSize != 160 && nDataSize != 240 && nDataSize != -12)
                {
                    break;
                }

                //this.Rtp2Wav(recInfo, nDataSize);
                this.Rtp2Wav2(recInfo, nDataSize);
                //this.Rtp2Binary(recInfo, nDataSize);
                break;
            }
        }
Esempio n. 3
0
        private void RtpReceive(byte[] buffer)
        {
            RecordInfo_t recInfo   = util.GetObject <RecordInfo_t>(buffer);
            int          nDataSize = recInfo.size - 12;

            if (nDataSize != 80 && nDataSize != 160 && nDataSize != 240 && nDataSize != -12)
            {
                return;
            }

            // util.WriteLog(string.Format("seq:{0}, ext:{1}, peer:{2}, isExtension:{3}, size:{4}, bytesLength:{5}", recInfo.seq, recInfo.peer_number, recInfo.extension, recInfo.isExtension, recInfo.size - 12, recInfo.voice.Length));
            // util.WriteLogTest("");

#if false
            // 녹취 할 수 있는 내선 리스트 추가 및 상태 체크
            var __tmpCollection = _innertelstatus.Where(x => x.Telnum == recInfo.extension);
            if (__tmpCollection.Count() < 1)
            {
                lock (_innertelstatus)
                {
                    _innertelstatus.Add(new InnerTel()
                    {
                        Telnum = recInfo.extension, TellerName = string.Empty, PeerNum = recInfo.peer_number
                    });
                }
            }
            else
            {
                InnerTel __tmpinntel = _innertelstatus.FirstOrDefault(x => x.Telnum == recInfo.extension);
                int      __idx       = _innertelstatus.IndexOf(__tmpinntel);
                _innertelstatus[__idx].PeerNum = recInfo.peer_number;
            }
            // 내선 리스트 추가 및 상태 체크
#endif
#if false
            // RTP Redirect
            foreach (InterceptorClient __ic in _rtpRedirectClientList)
            {
                if (recInfo.extension == __ic.ReqtelNum)
                {
                    _sockRTPSrv.SendTo(buffer, 0, buffer.Length, SocketFlags.None, __ic.ClientIPEP);
                }
            }
#endif
            this.StackRtp2Instance(recInfo, buffer);
        }
Esempio n. 4
0
        private void StackRtp2Instance(RecordInfo_t _recInfo)
        {
            var _ingInstance = RecordIngList.FirstOrDefault(x => x.ext == _recInfo.extension && x.peer == _recInfo.peer_number);
            if (_ingInstance == null)
            {
                byte[] rtpbuff = new byte[_recInfo.size];
                Array.Copy(_recInfo.voice, 0, rtpbuff, 0, _recInfo.size);
                WinSound.RTPPacket rtp = new WinSound.RTPPacket(rtpbuff);

                WaveFormat _wavformat;

                switch (rtp.PayloadType)
                {
                    case 0:
                        _wavformat = WaveFormat.CreateMuLawFormat(8000, 1);
                        break;
                    case 8:
                        _wavformat = WaveFormat.CreateALawFormat(8000, 1);
                        break;
                    case 4:
                        _wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G723, 8000, 1, 8000 * 1, 1, 8);
                        break;
                    case 18:
                        _wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G729, 8000, 1, 8000 * 1, 1, 8);
                        break;
                    default:
                        _wavformat = WaveFormat.CreateALawFormat(8000, 1);
                        break;
                }

                DateTime now = DateTime.Now;
                TimeSpan ts = now - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);

                string _header = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond);
                string _datepath = string.Format("{0:0000}-{1:00}-{2:00}", now.Year, now.Month, now.Day);
                string _fileName = string.Format("{0}_{1}_{2}.wav", _header, _recInfo.extension, _recInfo.peer_number);
                string _wavFileName = string.Format(@"{0}\{1}\{2}", _option.SaveDirectory, _datepath, _fileName);

                string _path = string.Format(@"{0}\{1}", _option.SaveDirectory, _datepath);
                if (!Directory.Exists(_path))
                    Directory.CreateDirectory(_path);

                RtpRecordInfo RecInstance = new RtpRecordInfo(_wavformat, string.Format(@"{0}\{1}", _option.SaveDirectory, _datepath), _fileName) { ext = _recInfo.extension, peer = _recInfo.peer_number, codec = _wavformat, idx = ts.TotalMilliseconds, savepath = string.Format(@"{0}\{1}", _option.SaveDirectory, _datepath), filename = _fileName };

                RecInstance.EndOfRtpStreamEvent += RecInstance_EndOfRtpStreamEvent;

                RecInstance.Add(_recInfo);
                lock (RecordIngList)
                {
                    RecordIngList.Add(RecInstance);
                }
            }
            else
            {
                _ingInstance.Add(_recInfo);
            }
        }
Esempio n. 5
0
        public void Add(RecordInfo_t obj)
        {
            // string msg = string.Format("seq:{0}, ext:{1}, peer:{2}, isExtension:{3}, size:{4}, codec:{5}", obj.seq, obj.extension, obj.peer_number, obj.isExtension, obj.size - 12, obj.codec);
            // util.WriteLogTest3(msg, this.filename);

            if (obj.size == 0)
                endcount++;

            if (endcount > 1)
            {
                if (timer != null)
                {
                    timer.Enabled = false;
                    timer = null;
                }

                if (endtimer != null)
                {
                    endtimer.Enabled = false;
                    endtimer = null;
                }

                System.Threading.Thread.Sleep(3000);

                this.MixRtp(MixType.FINAL);

                if (EndOfRtpStreamEvent != null)
                    EndOfRtpStreamEvent(this, new EventArgs());

                return;
            }

            if (endtimer != null)
            {
                endtimer.Enabled = false;
                endtimer.Enabled = true;
            }

            if (obj.size == 0) return;

            if (obj.isExtension == 1)
            {
                lock (listIn)
                {
                    listIn.Add(new ReceivedRtp() { seq = obj.seq, size = obj.size, isExtension = obj.isExtension, ext = obj.extension, peer = obj.peer_number, buff = obj.voice });
                }
            }
            else
            {
                lock (listOut)
                {
                    listOut.Add(new ReceivedRtp() { seq = obj.seq, size = obj.size, isExtension = obj.isExtension, ext = obj.extension, peer = obj.peer_number, buff = obj.voice });
                }
            }
        }
Esempio n. 6
0
        private void StackRtp2Instance(RecordInfo_t recInfo, byte[] buffer)
        {
            var ingInstance = RecordIngList.FirstOrDefault(x => x.ext == recInfo.extension && x.peer == recInfo.peer_number);
            if (ingInstance == null)
            {
                byte[] rtpbuff = new byte[recInfo.size];
                Array.Copy(recInfo.voice, 0, rtpbuff, 0, recInfo.size);
                WinSound.RTPPacket rtp = new WinSound.RTPPacket(rtpbuff);

                WaveFormat wavformat;

                switch (rtp.PayloadType)
                {
                    case 0:
                        wavformat = WaveFormat.CreateMuLawFormat(8000, 1);
                        break;
                    case 8:
                        wavformat = WaveFormat.CreateALawFormat(8000, 1);
                        break;
                    case 4:
                        wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G723, 8000, 1, 8000, 1, 8);
                        break;
                    case 18:
                        wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G729, 8000, 1, 8000, 1, 8);
                        break;
                    default:
                        wavformat = WaveFormat.CreateALawFormat(8000, 1);
                        break;
                }

                DateTime now = DateTime.Now;
                TimeSpan ts = now - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);

                string header = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond);
                string datepath = string.Format("{0:0000}-{1:00}-{2:00}", now.Year, now.Month, now.Day);
                string fileName = string.Format("{0}_{1}_{2}.wav", header, recInfo.extension, recInfo.peer_number);

                string path = string.Format(@"{0}\{1}", Options.savedir, datepath);

                if (!Directory.Exists(path)) Directory.CreateDirectory(path);

                RtpRecordInfo RecInstance = new RtpRecordInfo(wavformat, path, fileName) { ext = recInfo.extension, peer = recInfo.peer_number, codec = wavformat, idx = ts.TotalMilliseconds, savepath = path, filename = fileName };

                RecInstance.EndOfRtpStreamEvent += RecInstance_EndOfRtpStreamEvent;

                // util.WriteLogTest3(recInfo.isExtension.ToString() + " : >> RTPPacket Codec : " + rtp.PayloadType.ToString() + " // RecInfo Codec : " + recInfo.codec.ToString(), fileName + "_codec");
                RecInstance.chkcount++;
                RecInstance.firstIsExtension = recInfo.isExtension;

                RecInstance.Add(recInfo);
                lock (RecordIngList)
                {
                    RecordIngList.Add(RecInstance);
                }
            }
            else
            {
                //if (ingInstance.chkcount == 1 && ingInstance.firstIsExtension != recInfo.isExtension)
                //{
                //    byte[] rtpbuff = new byte[recInfo.size];
                //    Array.Copy(recInfo.voice, 0, rtpbuff, 0, recInfo.size);
                //    WinSound.RTPPacket rtp = new WinSound.RTPPacket(rtpbuff);

                //    util.WriteLogTest3(recInfo.isExtension.ToString() + " : >> RTPPacket Codec : " + rtp.PayloadType.ToString() + " // Structure Codec : " + recInfo.codec.ToString(), ingInstance.filename + "_codec");
                //    ingInstance.chkcount++;
                //}

                ingInstance.Add(recInfo);
            }
        }
Esempio n. 7
0
        public void Rtp2Wav2(RecordInfo_t recordInfo, int dataSize)
        {
            string fn = string.Empty;

            RcvData ingData = null;

            ingData = rcvqueList.Find(
                delegate(RcvData qlist)
            {
                return(qlist.extension == recordInfo.extension && qlist.peernumber == recordInfo.peer_number);
            });

            if (ingData == null)
            {
                DateTime now  = DateTime.Now;
                int      yyyy = now.Year;
                int      mm   = now.Month;
                int      dd   = now.Day;
                int      hh   = now.Hour;
                int      m    = now.Minute;
                int      sec  = now.Second;
                int      ms   = now.Millisecond;

                seqnum = string.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}", yyyy, mm, dd, hh, m, sec, ms);

                ingData = new RcvData()
                {
                    extension = recordInfo.extension, peernumber = recordInfo.peer_number, seqnum = seqnum
                };
                rcvqueList.Add(ingData);
            }

            if (dataSize == -12)
            {
                // MP3로 저장할 경우 이 곳에서 마지막에 wav를 mp3로 변환

                ProcessMixing2(ingData, dataSize);

                lock (rcvqueList)
                {
                    rcvqueList.Remove(ingData);
                }

                return;
            }

            RecInfos recinfo = new RecInfos()
            {
                rcvData = ingData
                ,
                isExtension = recordInfo.isExtension
                ,
                seq = recordInfo.seq
                ,
                size = recordInfo.size
                ,
                voice = recordInfo.voice
            };

            if (recordInfo.isExtension == 0)
            {
                lock (lExtension0)
                {
                    lExtension0.Add(recinfo);
                }
            }

            if (recordInfo.isExtension == 1)
            {
                lock (lExtension1)
                {
                    lExtension1.Add(recinfo);
                }
            }

            int list0 = lExtension0.Count(
                delegate(RecInfos list)
            {
                return(list.rcvData.Equals(ingData) && list.isExtension == 0);
            });

            int list1 = lExtension1.Count(
                delegate(RecInfos list)
            {
                return(list.rcvData.Equals(ingData) && list.isExtension == 1);
            });

            if (list0 >= 20 && list1 >= 20)
            {
                ProcessMixing2(ingData, dataSize);
            }
        }
Esempio n. 8
0
        private void StackRtp2Instance(RecordInfo_t _recInfo)
        {
            var _ingInstance = RecordIngList.FirstOrDefault(x => x.ext == _recInfo.extension && x.peer == _recInfo.peer_number);

            if (_ingInstance == null)
            {
                byte[] rtpbuff = new byte[_recInfo.size];
                Array.Copy(_recInfo.voice, 0, rtpbuff, 0, _recInfo.size);
                WinSound.RTPPacket rtp = new WinSound.RTPPacket(rtpbuff);

                WaveFormat _wavformat;

                switch (rtp.PayloadType)
                {
                case 0:
                    _wavformat = WaveFormat.CreateMuLawFormat(8000, 1);
                    break;

                case 8:
                    _wavformat = WaveFormat.CreateALawFormat(8000, 1);
                    break;

                case 4:
                    _wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G723, 8000, 1, 8000 * 1, 1, 8);
                    break;

                case 18:
                    _wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G729, 8000, 1, 8000 * 1, 1, 8);
                    break;

                default:
                    _wavformat = WaveFormat.CreateALawFormat(8000, 1);
                    break;
                }

                DateTime now = DateTime.Now;
                TimeSpan ts  = now - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);

                string _header      = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond);
                string _datepath    = string.Format("{0:0000}-{1:00}-{2:00}", now.Year, now.Month, now.Day);
                string _fileName    = string.Format("{0}_{1}_{2}.wav", _header, _recInfo.extension, _recInfo.peer_number);
                string _wavFileName = string.Format(@"{0}\{1}\{2}", _option.SaveDirectory, _datepath, _fileName);

                string _path = string.Format(@"{0}\{1}", _option.SaveDirectory, _datepath);
                if (!Directory.Exists(_path))
                {
                    Directory.CreateDirectory(_path);
                }

                RtpRecordInfo RecInstance = new RtpRecordInfo(_wavformat, string.Format(@"{0}\{1}", _option.SaveDirectory, _datepath), _fileName)
                {
                    ext = _recInfo.extension, peer = _recInfo.peer_number, codec = _wavformat, idx = ts.TotalMilliseconds, savepath = string.Format(@"{0}\{1}", _option.SaveDirectory, _datepath), filename = _fileName
                };

                RecInstance.EndOfRtpStreamEvent += RecInstance_EndOfRtpStreamEvent;

                RecInstance.Add(_recInfo);
                lock (RecordIngList)
                {
                    RecordIngList.Add(RecInstance);
                }
            }
            else
            {
                _ingInstance.Add(_recInfo);
            }
        }
Esempio n. 9
0
        public void Rtp2Wav2(RecordInfo_t recordInfo, int dataSize)
        {
            string fn = string.Empty;

            RcvData ingData = null;
            ingData = rcvqueList.Find(
                delegate(RcvData qlist)
                {
                    return qlist.extension == recordInfo.extension && qlist.peernumber == recordInfo.peer_number;
                });

            if (ingData == null)
            {
                DateTime now = DateTime.Now;
                int yyyy = now.Year;
                int mm = now.Month;
                int dd = now.Day;
                int hh = now.Hour;
                int m = now.Minute;
                int sec = now.Second;
                int ms = now.Millisecond;

                seqnum = string.Format("{0}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}", yyyy, mm, dd, hh, m, sec, ms);

                ingData = new RcvData() { extension = recordInfo.extension, peernumber = recordInfo.peer_number, seqnum = seqnum };
                rcvqueList.Add(ingData);
            }

            if (dataSize == -12)
            {
                // MP3로 저장할 경우 이 곳에서 마지막에 wav를 mp3로 변환

                ProcessMixing2(ingData, dataSize);

                lock (rcvqueList)
                {
                    rcvqueList.Remove(ingData);
                }

                return;
            }

            RecInfos recinfo = new RecInfos()
            {
                rcvData = ingData
                ,
                isExtension = recordInfo.isExtension
                ,
                seq = recordInfo.seq
                ,
                size = recordInfo.size
                ,
                voice = recordInfo.voice
            };

            if (recordInfo.isExtension == 0)
            {
                lock (lExtension0)
                {
                    lExtension0.Add(recinfo);
                }
            }

            if (recordInfo.isExtension == 1)
            {
                lock (lExtension1)
                {
                    lExtension1.Add(recinfo);
                }
            }

            int list0 = lExtension0.Count(
                    delegate(RecInfos list)
                    {
                        return list.rcvData.Equals(ingData) && list.isExtension == 0;
                    });

            int list1 = lExtension1.Count(
                    delegate(RecInfos list)
                    {
                        return list.rcvData.Equals(ingData) && list.isExtension == 1;
                    });

            if (list0 >= 20 && list1 >= 20)
            {
                ProcessMixing2(ingData, dataSize);
            }
        }
Esempio n. 10
0
        private void StackRtp2Instance(RecordInfo_t recInfo, byte[] buffer)
        {
            var ingInstance = RecordIngList.FirstOrDefault(x => x.ext == recInfo.extension && x.peer == recInfo.peer_number);

            if (ingInstance == null)
            {
                byte[] rtpbuff = new byte[recInfo.size];
                Array.Copy(recInfo.voice, 0, rtpbuff, 0, recInfo.size);
                WinSound.RTPPacket rtp = new WinSound.RTPPacket(rtpbuff);

                WaveFormat wavformat;

                switch (rtp.PayloadType)
                {
                case 0:
                    wavformat = WaveFormat.CreateMuLawFormat(8000, 1);
                    break;

                case 8:
                    wavformat = WaveFormat.CreateALawFormat(8000, 1);
                    break;

                case 4:
                    wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G723, 8000, 1, 8000, 1, 8);
                    break;

                case 18:
                    wavformat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.G729, 8000, 1, 8000, 1, 8);
                    break;

                default:
                    wavformat = WaveFormat.CreateALawFormat(8000, 1);
                    break;
                }

                DateTime now = DateTime.Now;
                TimeSpan ts  = now - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);

                string header   = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond);
                string datepath = string.Format("{0:0000}-{1:00}-{2:00}", now.Year, now.Month, now.Day);
                string fileName = string.Format("{0}_{1}_{2}.wav", header, recInfo.extension, recInfo.peer_number);

                string path = string.Format(@"{0}\{1}", Options.savedir, datepath);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                RtpRecordInfo RecInstance = new RtpRecordInfo(wavformat, path, fileName)
                {
                    ext = recInfo.extension, peer = recInfo.peer_number, codec = wavformat, idx = ts.TotalMilliseconds, savepath = path, filename = fileName
                };

                RecInstance.EndOfRtpStreamEvent += RecInstance_EndOfRtpStreamEvent;

                // util.WriteLogTest3(recInfo.isExtension.ToString() + " : >> RTPPacket Codec : " + rtp.PayloadType.ToString() + " // RecInfo Codec : " + recInfo.codec.ToString(), fileName + "_codec");
                RecInstance.chkcount++;
                RecInstance.firstIsExtension = recInfo.isExtension;

                RecInstance.Add(recInfo);
                lock (RecordIngList)
                {
                    RecordIngList.Add(RecInstance);
                }
            }
            else
            {
                //if (ingInstance.chkcount == 1 && ingInstance.firstIsExtension != recInfo.isExtension)
                //{
                //    byte[] rtpbuff = new byte[recInfo.size];
                //    Array.Copy(recInfo.voice, 0, rtpbuff, 0, recInfo.size);
                //    WinSound.RTPPacket rtp = new WinSound.RTPPacket(rtpbuff);

                //    util.WriteLogTest3(recInfo.isExtension.ToString() + " : >> RTPPacket Codec : " + rtp.PayloadType.ToString() + " // Structure Codec : " + recInfo.codec.ToString(), ingInstance.filename + "_codec");
                //    ingInstance.chkcount++;
                //}

                ingInstance.Add(recInfo);
            }
        }