/// <summary> /// 连接主端,获取音频信号并播放 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void connectButton_Click(object sender, EventArgs e) { string str = textBox1.Text; if (!string.IsNullOrEmpty(str)) { OutMic = AddMicrophone(); OutMic.settings.sourcename = str; OutMic.settings.deviceout = ((ListItem)ddlAudioOut.SelectedItem).Value[0]; if (OutVolumeLevel == null) { OutVolumeLevel = new VolumeLevel(OutMic); } else { OutVolumeLevel.Micobject = OutMic; } this.panel.Controls.Add(OutVolumeLevel); OutVolumeLevel.Dock = DockStyle.Fill; OutVolumeLevel.ParentForm = this; OutVolumeLevel.Listening = true; OutVolumeLevel.Refresh(); OutVolumeLevel.Enable(); //OutVolumeLevel.Invalidate(); } }
private void button1_Click(object sender, EventArgs e) { string str = textBox1.Text; if (!string.IsNullOrEmpty(str)) { OutMic = AddMicrophone(); OutMic.settings.sourcename = str; OutMic.settings.active = true; OutMic.settings.deviceout = ((ListItem)ddlAudioOut.SelectedItem).Value[0]; OutVolumeLevel = new VolumeLevel(OutMic); this.panel2.Controls.Add(OutVolumeLevel); OutVolumeLevel.Dock = DockStyle.Fill; OutVolumeLevel.Listening = true; // OutVolumeLevel.Enable(); OutVolumeLevel.Apply(); } }
public void StartListen() { while (Running && numErr < 5) { //Accept a new connection try { Socket mySocket = myListener.AcceptSocket(); if (MySockets.Count() < _socketindex + 1) { MySockets.Add(mySocket); } else { MySockets[_socketindex] = mySocket; } if (mySocket.Connected) { mySocket.NoDelay = true; mySocket.ReceiveBufferSize = 8192; mySocket.ReceiveTimeout = 1500; try { //make a byte array and receive data from the client string sBuffer; string sHttpVersion; Byte[] bReceive = new Byte[1024]; mySocket.Receive(bReceive); sBuffer = Encoding.ASCII.GetString(bReceive); if (sBuffer.Substring(0, 4) == "TALK") { var socket = mySocket; var feed = new Thread(p => AudioIn(socket)); _socketindex++; feed.Start(); continue; } if (sBuffer.Substring(0, 3) != "GET") { continue; } int iStartPos = sBuffer.IndexOf("HTTP", 1, StringComparison.Ordinal); sHttpVersion = sBuffer.Substring(iStartPos, 8); int cid = -1, vid = -1, camid = -1; int w = -1, h = -1; string qs = sBuffer.Substring(4); qs = qs.Substring(0, qs.IndexOf(" ", StringComparison.Ordinal)).Trim('/').Trim('?'); string[] nvs = qs.Split('&'); foreach (string s in nvs) { string[] nv = s.Split('='); switch (nv[0].ToLower()) { case "c": cid = Convert.ToInt32(nv[1]); break; case "w": w = Convert.ToInt32(nv[1]); break; case "h": h = Convert.ToInt32(nv[1]); break; case "camid": camid = Convert.ToInt32(nv[1]); //mjpeg break; case "micid": vid = Convert.ToInt32(nv[1]); break; } } if (cid != -1) { SendLiveFeed(cid, w, h, sHttpVersion, ref mySocket); } else { if (camid != -1) { CameraWindow cw = Parent.GetCameraWindow(Convert.ToInt32(camid)); if (cw.Camobject.settings.active) { String sResponse = ""; sResponse += "HTTP/1.1 200 OK\r\n"; sResponse += "Server: iSpy\r\n"; sResponse += "Expires: 0\r\n"; sResponse += "Pragma: no-cache\r\n"; sResponse += "Content-Type: multipart/x-mixed-replace;boundary=--myboundary"; Byte[] bSendData = Encoding.ASCII.GetBytes(sResponse); SendToBrowser(bSendData, mySocket); cw.OutSockets.Add(mySocket); _socketindex++; continue; } } else { if (vid != -1) { VolumeLevel vl = Parent.GetMicrophone(Convert.ToInt32(vid)); if (vl != null) { String sResponse = ""; sResponse += "HTTP/1.1 200 OK\r\n"; sResponse += "Server: iSpy\r\n"; sResponse += "Expires: 0\r\n"; sResponse += "Pragma: no-cache\r\n"; sResponse += "Content-Type: multipart/x-mixed-replace;boundary=--myboundary"; sResponse += "\r\n\r\n"; Byte[] bSendData = Encoding.ASCII.GetBytes(sResponse); SendToBrowser(bSendData, mySocket); vl.OutSockets.Add(mySocket); _socketindex++; continue; } } else { const string resp = "iSpy server is running"; SendHeader(sHttpVersion, "", resp.Length, " 200 OK", 0, ref mySocket); SendToBrowser(resp, ref mySocket); } } } numErr = 0; } catch (SocketException ex) { System.Diagnostics.Debug.WriteLine("Server Error (socket): " + ex.Message); //MainForm.LogExceptionToFile(ex); numErr++; } mySocket.Close(); mySocket = null; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Server Error (generic): " + ex.Message); //MainForm.LogExceptionToFile(ex); numErr++; } } }