Exemple #1
0
        private void AudioIn(HttpRequest req, int cameraId)
        {
            CameraWindow cw = MainForm.InstanceReference.GetCameraWindow(cameraId);
            if (cw == null)
                return;
            var wf = new WaveFormat(22050, 16, 1);
            var ds = new AudioInStream {RecordingFormat = wf};
            var talkTarget = TalkHelper.GetTalkTarget(cw.Camobject, ds); 
            
            ds.Start();
            talkTarget.Start();
            ds.PacketSize = 4410;
            var bBuffer = new byte[ds.PacketSize*4];
            try
            {
                int j = 0;
                bool pktComplete = false;
                DateTime dt = Helper.Now;
                while (req.TcpClient.Client.Connected) // && talkTarget.Connected)
                {
                    while (!pktComplete && req.TcpClient.Client.Connected)
                    {
                        int i = req.TcpClient.Client.Receive(bBuffer, j, ds.PacketSize, SocketFlags.None);
                        if (i == 0)
                            goto Finish;
                        j += i;
                        while (j >= ds.PacketSize)
                        {
                            var data = new byte[ds.PacketSize];
                            Buffer.BlockCopy(bBuffer, 0, data, 0, ds.PacketSize);
                            ds.AddSamples(data);
                            int ms = Convert.ToInt32((Helper.Now - dt).TotalMilliseconds);
                            if (ms < 40)
                                Thread.Sleep(40 - ms);
                            dt = Helper.Now;
                            pktComplete = true;
                            Buffer.BlockCopy(bBuffer, ds.PacketSize, bBuffer, 0, j - ds.PacketSize);
                            j = j - ds.PacketSize;

                        }
                    }
                    pktComplete = false;
                }
            }
            catch
            {
                // ignored
            }
            Finish:
                DisconnectRequest(req);
                ds.Stop();
                talkTarget.Stop();
            
        }
Exemple #2
0
        private void AudioIn(HttpRequest req, int cameraId)
        {
            CameraWindow cw = _parent.GetCameraWindow(cameraId);
            var ds = new AudioInStream { RecordingFormat = new WaveFormat(22050, 16, 1) };
            ITalkTarget talkTarget = TalkHelper.GetTalkTarget(cw.Camobject, ds);

            ds.Start();
            talkTarget.Start();
            ds.PacketSize = 4410;
            var bBuffer = new byte[ds.PacketSize*4];
            //IWavePlayer WaveOut = new DirectSoundOut(100);
            //WaveOut.Init(ds.WaveOutProvider);
            //WaveOut.Play();
            try
            {
                int j = 0;
                //DateTime dtStart = Helper.Now;
                bool pktComplete = false;
                DateTime dt = Helper.Now;
                while (req.TcpClient.Client.Connected) // && talkTarget.Connected)
                {
                    while (!pktComplete && req.TcpClient.Client.Connected)
                    {
                        // DateTime sR = Helper.Now;

                        int i = req.TcpClient.Client.Receive(bBuffer, j, ds.PacketSize, SocketFlags.None);
                        if (i == 0)
                            goto Finish;
                        j += i;
                        while (j >= ds.PacketSize)
                        {
                            var data = new byte[ds.PacketSize];
                            Buffer.BlockCopy(bBuffer, 0, data, 0, ds.PacketSize);
                            ds.AddSamples(data);
                            int ms = Convert.ToInt32((Helper.Now - dt).TotalMilliseconds);
                            if (ms < 40)
                                Thread.Sleep(40 - ms);
                            dt = Helper.Now;
                            pktComplete = true;
                            Buffer.BlockCopy(bBuffer, ds.PacketSize, bBuffer, 0, j - ds.PacketSize);
                            j = j - ds.PacketSize;

                        }
                    }
                    pktComplete = false;

                    //Thread.Sleep(50);
                }
            }
            catch(Exception ex)
            {
                MainForm.LogExceptionToFile(ex,"Talk (network)");
            }
            Finish:
                DisconnectRequest(req);
                ds.Stop();
                talkTarget.Stop();
        }