Ejemplo n.º 1
0
        private void DataProc(uint br, IntPtr data)
        {
            //byte[] ucEvrc = new byte[AUDIOPACKLENGTH];
            //ucEvrc[0] = 3;//语音数据标记
            ////音频数据压缩,数据长度:输出EVRC 10  输入PCM 320,测试bug在此处后面
            //EvrcProtocal.evrc_encode(ref ucEvrc[1], ref data);//todo:原有Evrc.dll方法

            byte[] recv = new byte[23];
            var    rtn  = EvrcProtocal.CCSEncode(data);//todo:替换为CCS.dll方法

            Marshal.Copy(rtn, recv, 0, 23);

            //复制编码结果到音频流缓存区EvrcBuff中
            for (var i = 0; i < 11; i++)
            {
                EvrcBuff[EvrcPtr, i] = recv[i];
            }
            EvrcPtr++;
            //音频流缓存区EvrcBuff满则发UDP包至服务器
            if (EvrcPtr >= 10)
            {
                SendEvrcPacket(10);
                EvrcPtr = 0;//重置音频流行计算偏移量
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 弹起取消喊话
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDo_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                _sendbuff = new byte[1000];
                //请求
                var rtn = EvrcProtocal.proto_make_release_mic_packet(PubUser.default_group, ref _sendbuff[0]);
                _clientSocket.Send(_sendbuff, rtn, SocketFlags.None);

                _recvbuff = new byte[1000];
                int len = _clientSocket.Receive(_recvbuff, 1000, SocketFlags.None);
                if (len == 0)
                {
                    ShowMsg("停止喊话req:没有接收到服务器响应。");
                    return;
                }
                uint vlen       = 0;
                var  checkedrtn = CrcCheck(_recvbuff, len, ref vlen);//CRC校验
                //解包请求
                var entgack = EvrcProtocal.proto_unpack_release_mic_ack(ref checkedrtn[5], vlen - 5);
                StopCollectSound();
                ShowMsg("停止喊话res:" + (entgack != 0));
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 开始喊话
        /// </summary>
        private void StartCollectSound()
        {
            try
            {
                if (IsRecoding)
                {
                    return;
                }

                ////初始化音频编码解码
                //EvrcProtocal.InitEncoder();
                //EvrcProtocal.InitDecoder();
                EvrcProtocal.StartSpeech();
                var rtn = 0;
                hRecord = IntPtr.Zero;
                rtn     = PcmAudio.waveInOpen(out hRecord, -1, ref lpFormat, _wd, 0, 0x00030000);

                if (rtn == 0)//成功返回0
                {
                    //将准备好的buffer提供给音频输入设备
                    for (int i = 0; i < MAXRECBUFFER; i++)
                    {
                        //准备一个bufrer给输入设备
                        PcmAudio.waveInPrepareHeader(hRecord, ref globalhdr[i], (UInt32)Marshal.SizeOf(typeof(PcmAudio.WaveHdr)));
                        //发送一个buffer给指定的输入设备,当buffer填满将会通知程序
                        PcmAudio.waveInAddBuffer(hRecord, ref globalhdr[i], (UInt32)Marshal.SizeOf(typeof(PcmAudio.WaveHdr)));
                    }
                    //开启指定的输入采集设备
                    rtn = PcmAudio.waveInStart(hRecord);
                    if (rtn == 0)
                    {
                        IsRecoding = true;
                        ShowMsg("正在采集音频数据...");
                    }
                    else
                    {
                        ShowMsg("采集音频失败");
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// CRC校验
        /// </summary>
        /// <param name="recvbuf"></param>
        /// <param name="recvlength"></param>
        /// <param name="vLen"></param>
        /// <returns></returns>
        private static byte[] CrcCheck(byte[] recvbuf, int recvlength, ref uint vLen)
        {
            uint uiValidLen = (((uint)recvbuf[0]) << 24) | (((uint)recvbuf[1]) << 16) |
                              (((uint)recvbuf[2]) << 8) | ((uint)recvbuf[3]);

            vLen = uiValidLen;
            if ((uiValidLen + 4) > recvlength || recvlength < 9)
            {
                return(null);
            }
            var uiReCrc = (((uint)recvbuf[uiValidLen]) << 24) | (((uint)recvbuf[uiValidLen + 1]) << 16) |
                          (((uint)recvbuf[uiValidLen + 2]) << 8) | ((uint)recvbuf[uiValidLen + 3]);

            if (uiReCrc != EvrcProtocal.ZTE_CRC(ref recvbuf[0], uiValidLen))
            {
                return(null);
            }
            return(recvbuf);
        }
Ejemplo n.º 5
0
 private void Udptimer_Tick(object sender, EventArgs e)
 {
     if (_voiceSocket == null || !_voiceSocket.Connected)
     {
         return;
     }
     if (gRunPar.udpHbCnt++ >= 4)
     {
         //以下发送心跳包
         var udpsndbuf = new byte[100];
         var uiSndLen  = EvrcProtocal.proto_make_ping_packet((uint)user.uid, ref udpsndbuf[0]);//测试ping
         ShowMsg("ping服务器:" + uiSndLen);
         if (uiSndLen > 0)
         {
             SendUdpPacket(_voiceSocket, user.iSetPar.ip, POC_NET_UDP_PORT, udpsndbuf, uiSndLen);
             ShowMsg("已发送UDP心跳包。");
         }
         gRunPar.udpHbCnt = 0;
     }
 }
Ejemplo n.º 6
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            {
                ReceiveTimeout = 30 * 1000,
                SendTimeout    = 30 * 1000
            };
            _clientSocket.Connect(new IPEndPoint(IPAddress.Parse(txtIP.Text), POC_NET_TCP_PORT));

            tvGroup.Nodes.Clear();
            lvGroup.Items.Clear();

            //登录参数
            user = new EvrcProtocal.stUser
            {
                iSetPar =
                {
                    ip      = txtIP.Text,
                    account = txtUsr.Text,
                    passwd  = txtPwd.Text
                }
            };
            //1、获取登录
            _sendbuff = new byte[1000];
            var loginpack = EvrcProtocal.proto_make_login_packet(ref user, ref _sendbuff[0]);

            _clientSocket.Send(_sendbuff, loginpack, SocketFlags.None);
            _recvbuff = new byte[1000];
            int  len  = _clientSocket.Receive(_recvbuff, 1000, SocketFlags.None);
            uint vlen = 0;

            byte[] checkedrtn = CrcCheck(_recvbuff, len, ref vlen);//CRC校验
            //登录解包(此处回填登录参数)
            var loginunpack = EvrcProtocal.proto_unpack_login_ack(ref user, ref checkedrtn[5], vlen - 5);
            var name        = TrimStr(Encoding.UTF8.GetString(user.username));

            ShowMsg("登陆解包res:" + (loginunpack != 0) + ";uid=" + user.uid + ";username="******";defaultgroup=" + user.default_group);

            //2、获取组
            _sendbuff = new byte[1000];
            var reqgroup = EvrcProtocal.proto_make_query_group_packet(ref _sendbuff[0]);

            //ShowMsg("获取组结果:" + reqgroup);
            _clientSocket.Send(_sendbuff, reqgroup, SocketFlags.None);
            _recvbuff  = new byte[1000];
            len        = _clientSocket.Receive(_recvbuff, 1000, SocketFlags.None);
            checkedrtn = CrcCheck(_recvbuff, len, ref vlen);//CRC校验
            //解包组
            var upkgroup = EvrcProtocal.proto_unpack_query_group_ack(ref checkedrtn[5], vlen - 5);

            ShowMsg("获取组解包res:" + (upkgroup != 0));

            //0、进入群组
            _sendbuff = new byte[1000];
            var entg = EvrcProtocal.proto_make_enter_group_packet(user.default_group, ref _sendbuff[0]);

            //ShowMsg("进入群组结果:"+entg);
            _clientSocket.Send(_sendbuff, entg, SocketFlags.None);
            _recvbuff  = new byte[1000];
            len        = _clientSocket.Receive(_recvbuff, 1000, SocketFlags.None);
            checkedrtn = CrcCheck(_recvbuff, len, ref vlen);//CRC校验
            //解包进入群组
            var entgack = EvrcProtocal.proto_unpack_enter_group_ack(ref checkedrtn[5], vlen - 5);

            ShowMsg("进入群组解包res:" + (entgack != 0));

            //3、解析组
            var gl        = EvrcProtocal.proto_get_group_list();
            var grouplist = (EvrcProtocal.stGroupList)Marshal.PtrToStructure(gl, typeof(EvrcProtocal.stGroupList));

            ShowMsg("获取组结果:组数" + grouplist.uiTotal);
            var nowhead = grouplist.pHead;
            var now     = (EvrcProtocal.stGroupNode)Marshal.PtrToStructure(nowhead, typeof(EvrcProtocal.stGroupNode));

            while (true)
            {
                if (now == null)
                {
                    break;
                }
                var name1 = TrimStr(Encoding.UTF8.GetString(now.iGroup.gname));
                ShowMsg("解析组:gid=" + now.iGroup.gid + ";gname=" + name1 + ";number_n=" + now.iGroup.number_n);
                tvGroup.Nodes.Add(now.iGroup.gid.ToString(), name1);

                //4、根据组获取用户
                _sendbuff = new byte[1000];
                var mbr = EvrcProtocal.proto_make_query_member_packet(now.iGroup.gid, ref _sendbuff[0]);//now.iGroup.gid|user.default_group
                _clientSocket.Send(_sendbuff, mbr, SocketFlags.None);
                _recvbuff  = new byte[1000];
                len        = _clientSocket.Receive(_recvbuff, 1000, SocketFlags.None);
                checkedrtn = CrcCheck(_recvbuff, len, ref vlen);//CRC校验
                var dembr = EvrcProtocal.proto_unpack_query_member_ack(ref checkedrtn[5], vlen - 5);
                ShowMsg("解包用户res:" + (dembr != 0));

                var ml      = EvrcProtocal.proto_get_user_list();
                var mbrlist = (EvrcProtocal.stUserList)Marshal.PtrToStructure(ml, typeof(EvrcProtocal.stUserList));

                ShowMsg("获取用户结果:用户数" + mbrlist.uiTotal);
                var head   = mbrlist.pHead;
                var mbrnow = (EvrcProtocal.stUserNode)Marshal.PtrToStructure(head, typeof(EvrcProtocal.stUserNode));
                while (true)
                {
                    if (mbrnow == null)
                    {
                        break;
                    }
                    var name2 = TrimStr(Encoding.UTF8.GetString(mbrnow.uname));
                    ShowMsg("解析用户:uid=" + mbrnow.uid + ";online=" + mbrnow.online + ";uname=" + name2);
                    tvGroup.Nodes.Find(now.iGroup.gid.ToString(), false)[0].Nodes.Add(mbrnow.uid.ToString(), name2);

                    mbrnow = (EvrcProtocal.stUserNode)Marshal.PtrToStructure(mbrnow.pNext, typeof(EvrcProtocal.stUserNode));
                }
                now = (EvrcProtocal.stGroupNode)Marshal.PtrToStructure(now.pNext, typeof(EvrcProtocal.stGroupNode));
            }
            tvGroup.ExpandAll();
            PubUser           = user;
            btnDo.Enabled     = true;
            btnLogin.Enabled  = false;
            btnLogout.Enabled = true;
        }