Exemple #1
0
        void RecInstance_EndOfRtpStreamEvent(object sender, EventArgs e)
        {
            RtpRecordInfo ingdata = (RtpRecordInfo)sender;

            if (ingdata != null)
            {
                double _idx      = ingdata.idx;
                string _savepath = ingdata.savepath;
                string _savefn   = ingdata.filename;
                string _ext      = ingdata.ext;
                string _peer     = ingdata.peer;

                lock (RecordIngList)
                {
                    RecordIngList.Remove(ingdata);
                }

                ingdata.Dispose();
                ingdata = null;

                if (_option.SaveFileType == "MP3")
                {
                    _savefn = this.LameWavToMp3(_savepath, _savefn);
                }

                // double _fnlen = FilePlayTime(string.Format(@"{0}\{1}", _savepath, _savefn));

                // this.FileName2DB(_idx, _savefn, _fnlen, _ext, _peer);
            }
            else
            {
                util.WriteLog("RecInstance_EndOfRtpStreamEvent ingdata : NULL");
            }
        }
Exemple #2
0
        void RecInstance_EndOfRtpStreamEvent(object sender, EventArgs e)
        {
            RtpRecordInfo ingdata = (RtpRecordInfo)sender;

            if (ingdata != null)
            {
                string _savepath = ingdata.savepath;
                string _savefn   = ingdata.filename;
                string _ext      = ingdata.ext;
                string _peer     = ingdata.peer;

#if false
                var __tmpCollection = _innertelstatus.FirstOrDefault(x => x.Telnum == ingdata.ext);
                if (__tmpCollection != null)
                {
                    lock (_innertelstatus)
                    {
                        _innertelstatus.Remove(__tmpCollection);
                    }
                }
#endif

                lock (RecordIngList)
                {
                    RecordIngList.Remove(ingdata);
                }

                ingdata.Dispose();
                ingdata = null;

                if (Options.filetype.Equals("mp3"))
                {
                    _savefn = this.LameWavToMp3(_savepath, _savefn);
                }

                this.FileName2DB(_savefn, _ext, _peer);
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
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);
            }
        }