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(); talkTarget = null; ds = null; }
private void AudioIn(HttpRequest req, int cameraId) { CameraWindow cw = _parent.GetCameraWindow(cameraId); ITalkTarget talkTarget = null; var ds = new AudioInStream { RecordingFormat = new WaveFormat(22050, 16, 1) }; switch (cw.Camobject.settings.audiomodel) { case "Foscam": ds.Interval = 40; ds.PacketSize = 882; // (40ms packet at 22050 bytes per second) talkTarget = new TalkFoscam(cw.Camobject.settings.audioip, cw.Camobject.settings.audioport, cw.Camobject.settings.audiousername, cw.Camobject.settings.audiopassword, ds); break; case "NetworkKinect": ds.Interval = 40; ds.PacketSize = 882; talkTarget = new TalkNetworkKinect(cw.Camobject.settings.audioip, cw.Camobject.settings.audioport, ds); break; case "iSpyServer": ds.Interval = 40; ds.PacketSize = 882; talkTarget = new TalkiSpyServer(cw.Camobject.settings.audioip, cw.Camobject.settings.audioport, ds); break; case "Axis": talkTarget = new TalkAxis(cw.Camobject.settings.audioip, cw.Camobject.settings.audioport, cw.Camobject.settings.audiousername, cw.Camobject.settings.audiopassword, ds); break; default: //local playback talkTarget = new TalkLocal(ds); break; } 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 { } Finish: DisconnectRequest(req); ds.Stop(); talkTarget.Stop(); talkTarget = null; ds = null; }