Beispiel #1
0
 private void SubHeadReceived(SNM_RESPONSE resonse)
 {
     if (HeadReceived != null)
     {
         HeadReceived(mUser, resonse);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Received head info,call this function will prepare convert,play or write,must be called before ReceivedData
 /// </summary>
 /// <param name="response"></param>
 public void ReceiveHead(SNM_RESPONSE response)
 {
     SubDebug(string.Format("Head received,voice format:{0}\tchannel:{1}", (EVLVoiceFormat)response.format, response.channel));
     SubHeadReceived(response);
     if (mIsDecodeData)
     {
         PrepareConvert((EVLVoiceFormat)response.format);
     }
     if (mIsPlayWave)
     {
         PreparePlay((EVLVoiceFormat)response.format);
     }
     if (mIsSrcWriteFile || mIsPcmWriteFile)
     {
         PrepareWrite((EVLVoiceFormat)response.format);
     }
 }
Beispiel #3
0
        private void PrepareReceive(SNM_RESPONSE response)
        {
            mHeader = response;
            SubDebug(string.Format("Call PrepareReceive,Current voice format:{0}.", (EVLVoiceFormat)response.format));
            switch (mHeader.format)
            {
            case (int)EVLVoiceFormat.MT_MSGSM:
                mBlockSize = 325;
                break;

            case (int)EVLVoiceFormat.MT_PCM_Raw_16bit:
                mBlockSize = 3200;
                break;

            case (int)EVLVoiceFormat.MT_PCM_Raw_u8bit:
                mBlockSize = 1600;
                break;

            case (int)EVLVoiceFormat.MT_OKI_ADPCM_SR8:
                mBlockSize = 800;
                break;

            case (int)EVLVoiceFormat.MT_G729A_8K:
                mBlockSize = 200;
                break;

            case (int)EVLVoiceFormat.MT_PCM_ALaw_Stereo:
                mBlockSize = 3200;
                break;

            case (int)EVLVoiceFormat.MT_MP3_32K_STEREO:
                mBlockSize = 1608;
                break;
            //Other voice format not impliment so on.

            default:
                SubDebug(string.Format("Wave format not support,wave format:{0}", (EVLVoiceFormat)mHeader.format));
                mBlockSize = 325;
                return;
            }
        }
Beispiel #4
0
 void mConnector_HeadReceived(SNM_RESPONSE response)
 {
     ReceiveHead(response);
 }
Beispiel #5
0
        private void Worker()
        {
            int iInteval = NMonDefines.CONNECTOR_RECONINTEVAL * 100;
            int iRet;

            byte[] bBuffer = new byte[NMonDefines.CONNECTOR_BUFFERSIZE];
            while (true)
            {
                //Not connected
                if (!mConnected || mClient == null || !mClient.Connected)
                {
                    //reconnect to server per inteval
                    mInit        = true;
                    mReceiveHead = true;
                    if (iInteval == NMonDefines.CONNECTOR_RECONINTEVAL * 100)
                    {
                        MakeConnection();
                        iInteval = 0;
                    }
                    else
                    {
                        iInteval++;
                    }
                }
                else
                {
                    //Not requested,so first send request to server
                    if (mInit)
                    {
                        SubDebug(string.Format("Send request start."));
                        SNM_REQUEST request = new SNM_REQUEST();
                        request.channel = (ushort)mNetMonParam.Channel;
                        request.flag    = NMonDefines.NM_KEEP_ON_IDLE;
                        request.size    = (ushort)Marshal.SizeOf(request);
                        if (SendData(Converter.Struct2Bytes(request)))
                        {
                            mInit = false;
                        }
                    }
                    else
                    {
                        //Check for disconnect
                        if (mClient.Poll(-1, SelectMode.SelectRead))
                        {
                            if (mClient.Available == 0)
                            {
                                SubDebug(string.Format("Server disconnected,Connector will reconnect later."));
                                mConnected = false;
                            }
                        }
                        while (mClient.Available > 0)
                        {
                            bBuffer.Initialize();
                            //Accept voice format info
                            if (mReceiveHead)
                            {
                                SubDebug(string.Format("Receive voice header start."));
                                int iHeadLenght = Marshal.SizeOf(typeof(SNM_RESPONSE));
                                iRet = mClient.Receive(bBuffer, iHeadLenght, SocketFlags.None);
                                if (iRet == iHeadLenght)
                                {
                                    byte[] temp = new byte[iRet];
                                    Array.Copy(bBuffer, temp, iRet);
                                    SNM_RESPONSE response = (SNM_RESPONSE)Converter.Bytes2Struct(temp, typeof(SNM_RESPONSE));
                                    PrepareReceive(response);
                                    SubHeadReceived(response);
                                    mReceiveHead = false;
                                }
                                else
                                {
                                    SubDebug(string.Format("Receive head data fail.Received length:{0}\tPossible length:{1}", iRet, iHeadLenght));
                                }
                            }
                            else
                            {
                                iRet = 0;
                                while (iRet < mBlockSize)
                                {
                                    int iTemp = mClient.Receive(bBuffer, iRet, mBlockSize - iRet, SocketFlags.None);
                                    iRet += iTemp;
                                    Thread.Sleep(10);
                                }
                                //iRet = mClient.Receive(bBuffer, mBlockSize, SocketFlags.None);
                                byte[] temp = new byte[iRet];
                                Array.Copy(bBuffer, temp, iRet);
                                SubDataReceived(temp, iRet);
                                //SubDataReceived(bBuffer, mBlockSize);
                            }
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }