public override void sendStreamResponse(NetworkStream ns, ref HTTPResponseStruct rp, int SendBufferSize) { if (command.sourceType == SourceType.File) { if (command.streamType == StreamType.File) { if (rp.fs != null) { using (rp.fs) { if (command.HTTPRequest.Args == null || command.HTTPRequest.Args.Count == 0) { sendStream(ns, SendBufferSize, LoadMemoryStreamFromFile(rp.fs)); } else { MemoryStream ms = new ffMpegFileConvert(this.vsAppPath).ConvertToWmv(rp.fs.Name, command.videoSize).VideoStream; sendStream(ns, SendBufferSize, ms);// rp.fs.Close(); // sendStream(ns, SendBufferSize, rp.fs);// } } } } else if (command.streamType == StreamType.MJpeg) { string fileName = Path.Combine(this.DataFolder, command.urlSource.Replace("/", "\\"));//command.urlSource; int framRate = command.framRate; Size videoSize = command.videoSize; int videoQuanlity = command.videoQuanlity; sendStreamMjpegFromFile(fileName, ns, SendBufferSize, framRate, videoSize, videoQuanlity); } } if (command.sourceType == SourceType.Live) { if (command.streamType == StreamType.Jpeg) { } else if (command.streamType == StreamType.MJpeg) { // string fileName = "data\\42.wmv"; string camID = command.urlSource; int framRate = command.framRate; Size videoSize = command.videoSize; int videoQuanlity = command.videoQuanlity; //sendStreamMjpegFromFile(ns, SendBufferSize, fileName, framRate, videoSize, videoQuanlity); sendStreamMjpegFromProvider(getProvider(camID), ns, SendBufferSize, framRate, videoSize, videoQuanlity); //sendStreamMjpegFromProvider(getProvider("camera-210-01.coe.psu.ac.th"), ns, SendBufferSize, framRate, videoSize, videoQuanlity); } } }
public override bool CreateHeaderResponse(ref HTTPResponseStruct rp) { string bodyStr = ""; if (command.streamType == StreamType.File && command.sourceType == SourceType.File) { string path = Path.Combine(this.DataFolder, command.urlSource.Replace("/", "\\")); if (File.Exists(path)) { RegistryKey rk = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(path), false); // Get the data from a specified item in the key. String s = (String)rk.GetValue("Content Type"); // Open the stream and read it back. rp.fs = File.OpenRead(path); if (s != "") { rp.Headers["Content-Type"] = s; rp.Headers["Content-Length"] = rp.fs.Length; } return(true); } } else if (command.streamType == StreamType.MJpeg) { //rp.Headers["Content-Length"] = "-1"; //rp.Headers["Cache-Control"] = "no-cache"; // rp.Headers["Pragma"] = "no-cache"; //rp.Headers["Connection"] = "close"; rp.Headers["Content-Type"] = "multipart/x-mixed-replace; boundary=--myboundary"; return(true); } else if (command.streamType == StreamType.Jpeg) { rp.Headers["Content-type"] = "image/jpeg"; return(true); } { bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"; bodyStr += "<HTML><HEAD>\n"; bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n"; bodyStr += "</HEAD>\n"; bodyStr += "<BODY>File not found!!</BODY></HTML>\n"; rp.BodyData = Encoding.ASCII.GetBytes(bodyStr); } return(false); }
//#region Run the process //private string RunProcess(string Parameters) //{ // //create a process info // ProcessStartInfo oInfo = new ProcessStartInfo(this._ffExe, Parameters); // oInfo.UseShellExecute = false; // oInfo.CreateNoWindow = true; // oInfo.RedirectStandardOutput = true; // oInfo.RedirectStandardError = true; // //Create the output and streamreader to get the output // string output = null; StreamReader srOutput = null; // //try the process // try // { // //run the process // Process proc = System.Diagnostics.Process.Start(oInfo); // proc.WaitForExit(); // //get the output // srOutput = proc.StandardError; // //now put it in a string // output = srOutput.ReadToEnd(); // proc.Close(); // } // catch (Exception) // { // output = string.Empty; // } // finally // { // //now, if we succeded, close out the streamreader // if (srOutput != null) // { // srOutput.Close(); // srOutput.Dispose(); // } // } // return output; //} //#endregion public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp) { throw new NotImplementedException(); }
public abstract void sendStreamResponse(NetworkStream ns, ref HTTPResponseStruct rp, int SendBufferSize);
public abstract void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp);
public abstract bool CreateHeaderResponse(ref HTTPResponseStruct rp);
public override void sendStreamResponse(NetworkStream ns, ref HTTPResponseStruct rp, int SendBufferSize) { if (command.sourceType == SourceType.File) { if (command.streamType == StreamType.File) { if (rp.fs != null) using (rp.fs) { if (command.HTTPRequest.Args == null || command.HTTPRequest.Args.Count == 0) { sendStream(ns, SendBufferSize, LoadMemoryStreamFromFile(rp.fs)); } else { MemoryStream ms = new ffMpegFileConvert(this.vsAppPath).ConvertToWmv(rp.fs.Name, command.videoSize).VideoStream; sendStream(ns, SendBufferSize, ms);// rp.fs.Close(); // sendStream(ns, SendBufferSize, rp.fs);// } } } else if (command.streamType == StreamType.MJpeg) { string fileName = Path.Combine(this.DataFolder, command.urlSource.Replace("/", "\\"));//command.urlSource; int framRate = command.framRate; Size videoSize = command.videoSize; int videoQuanlity = command.videoQuanlity; sendStreamMjpegFromFile(fileName, ns, SendBufferSize, framRate, videoSize, videoQuanlity); } } if (command.sourceType == SourceType.Live) { if (command.streamType == StreamType.Jpeg) { } else if (command.streamType == StreamType.MJpeg) { // string fileName = "data\\42.wmv"; string camID = command.urlSource; int framRate = command.framRate; Size videoSize = command.videoSize; int videoQuanlity = command.videoQuanlity; //sendStreamMjpegFromFile(ns, SendBufferSize, fileName, framRate, videoSize, videoQuanlity); sendStreamMjpegFromProvider(getProvider(camID), ns, SendBufferSize, framRate, videoSize, videoQuanlity); //sendStreamMjpegFromProvider(getProvider("camera-210-01.coe.psu.ac.th"), ns, SendBufferSize, framRate, videoSize, videoQuanlity); } } }
public override bool CreateHeaderResponse(ref HTTPResponseStruct rp) { string bodyStr = ""; if (command.streamType == StreamType.File && command.sourceType == SourceType.File) { string path = Path.Combine(this.DataFolder, command.urlSource.Replace("/", "\\")); if (File.Exists(path)) { RegistryKey rk = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(path), false); // Get the data from a specified item in the key. String s = (String)rk.GetValue("Content Type"); // Open the stream and read it back. rp.fs = File.OpenRead(path); if (s != "") { rp.Headers["Content-Type"] = s; rp.Headers["Content-Length"] = rp.fs.Length; } return true; } } else if (command.streamType == StreamType.MJpeg) { //rp.Headers["Content-Length"] = "-1"; //rp.Headers["Cache-Control"] = "no-cache"; // rp.Headers["Pragma"] = "no-cache"; //rp.Headers["Connection"] = "close"; rp.Headers["Content-Type"] = "multipart/x-mixed-replace; boundary=--myboundary"; return true; } else if (command.streamType == StreamType.Jpeg) { rp.Headers["Content-type"] = "image/jpeg"; return true; } { bodyStr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"; bodyStr += "<HTML><HEAD>\n"; bodyStr += "<META http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n"; bodyStr += "</HEAD>\n"; bodyStr += "<BODY>File not found!!</BODY></HTML>\n"; rp.BodyData = Encoding.ASCII.GetBytes(bodyStr); } return false; }