public void Load() { SetupVariables(); Console.ProcessFile(FilenameSettings); Console.ProcessFile(FilenameCameras); Program.ProgramEnding += Save; }
public void CheckTask(bool LongRun) { Repeater.RunTask(); if (LongRun) { ConsoleResponseBoolean variable = Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, ID)); if (variable.State == ConsoleCommandState.Failure) { throw new LogicException(string.Format("{0} is not a boolean variable!", Variables.V_camera_stream_enabled)); } if (variable.Value) { if ((encoderProcess == null || encoderProcess.HasExited) && Program.ThreadsRunning) { StartStream(Console.GetValue(string.Format(Variables.V_camera_url, ID)).Value, hostname); } } else { if ((encoderProcess != null && !encoderProcess.HasExited) && Program.ThreadsRunning) { Console.WriteLine("Killing camera {0}", ID); Terminate(); } } } }
private void StartStream(string URL, string filename) { Debugging.DebugLog(Debugging.DebugLevel.Info, "Starting Camera " + ID); if (!new DirectoryInfo(GetDirectory(filename)).Exists) { new DirectoryInfo(GetDirectory(filename)).Create(); } Debugging.DebugLog(Debugging.DebugLevel.Debug1, "Executing: " + Console.GetValue(Variables.V_encoder_path).Value + " " + String.Format(Console.GetValue(Variables.V_encoder_stream_args).Value, URL, filename)); StreamSaveThread = new Process(); StreamSaveThread.StartInfo.FileName = Console.GetValue(Variables.V_encoder_path).Value; StreamSaveThread.StartInfo.Arguments = String.Format(Console.GetValue(Variables.V_encoder_save_args).Value, URL, filename); StreamSaveThread.StartInfo.CreateNoWindow = true; StreamSaveThread.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; StreamSaveThread.StartInfo.UseShellExecute = false; StreamSaveThread.StartInfo.RedirectStandardInput = true; StreamSaveThread.StartInfo.RedirectStandardError = true; StreamSaveThread.StartInfo.RedirectStandardOutput = true; StreamSaveThread.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { Debugging.DebugLog(Debugging.DebugLevel.Debug3, e.Data); }; StreamSaveThread.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => { Debugging.DebugLog(Debugging.DebugLevel.Debug3, e.Data); }; StreamSaveThread.Start(); StreamSaveThread.BeginErrorReadLine(); StreamSaveThread.BeginOutputReadLine(); }
public static void DebugLog(DebugLevel level, string message, params string[] format) { if (CurrentLevel(Console.GetVariable("Debugging_Level").Value) >= level) { Console.WriteLine(message, format); } }
public void CheckTask(bool LongRun) { if (!LongRun) { return; } ConsoleResponseBoolean variable = Console.GetOnOff(string.Format(Variables.V_camera_enabled, ID)); if (variable.State == ConsoleCommandState.Failure) { throw new LogicException(string.Format("{0} is not a boolean variable!", Variables.V_camera_enabled)); } if (variable.Value) { if ((StreamSaveThread == null || StreamSaveThread.HasExited) && Program.ThreadsRunning) { StartStream(Console.GetValue(string.Format(Variables.V_camera_url, ID)).Value, string.Format(Console.GetValue(Variables.V_camera_save_path).Value, ID) + Console.GetValue(string.Format(Variables.V_camera_save_format, ID)).Value); } } else { if ((StreamSaveThread != null && !StreamSaveThread.HasExited) && Program.ThreadsRunning) { Console.WriteLine("Killing camera {0}", ID); Terminate(); } } }
private void StartStream(string URL, string hostname) { Repeater?.Start(); Debugging.DebugLog(Debugging.DebugLevel.Info, "Starting Camera Sttram" + ID); Debugging.DebugLog(Debugging.DebugLevel.Debug1, "Executing: " + Console.GetValue(Variables.V_encoder_path).Value + " " + String.Format(Console.GetValue(string.Format(Variables.V_camera_stream_args, ID)).Value, URL, string.Format("{0}:{1}/camera.ogg", hostname, port))); encoderProcess = new Process(); encoderProcess.StartInfo.FileName = Console.GetValue(Variables.V_encoder_path).Value; encoderProcess.StartInfo.Arguments = String.Format(Console.GetValue(string.Format(Variables.V_camera_stream_args, ID)).Value, URL, string.Format("{0}:{1}/camera.ogg", hostname, port)); encoderProcess.StartInfo.CreateNoWindow = true; encoderProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; encoderProcess.StartInfo.UseShellExecute = false; encoderProcess.StartInfo.RedirectStandardInput = true; encoderProcess.StartInfo.RedirectStandardError = true; encoderProcess.StartInfo.RedirectStandardOutput = true; encoderProcess.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { Debugging.DebugLog(Debugging.DebugLevel.Debug3, e.Data); }; encoderProcess.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => { Debugging.DebugLog(Debugging.DebugLevel.Debug3, e.Data); }; encoderProcess.Start(); encoderProcess.BeginErrorReadLine(); encoderProcess.BeginOutputReadLine(); }
public void Load() { Console.SetFunc("Disk", new ConsoleFunction() { Function = Disk, HelpInfo = DefaultLanguage.Strings.GetString("disk_Help"), TabFunction = Disk_GetTabCompletionValues }); }
private void Save() { //We have 1 camera we are saving. List <string> VariablesToSave = new List <string>() { "Debugging_Level", }; Console.SaveToFile(Filename, VariablesToSave.ToArray()); }
internal void Terminate() { if (StreamSaveThread != null && !StreamSaveThread.HasExited) { StreamSaveThread.StandardInput.Close(); if (!StreamSaveThread.WaitForExit(5000)) { Console.WriteLine("Camera {0} did not close after 5 seconds, forcefully terminating!", ID); StreamSaveThread.Kill(); } } }
private void Save() { // We have 1 camera we are saving. List <string> VariablesToSave = new List <string>() { V_encoder_path, V_encoder_stream_args, V_camera_save_path, }; Console.SaveToFile(FilenameSettings, VariablesToSave.ToArray()); Save_cameras(); }
public void Load() { Console.SetValue("Debugging_Level", new ConsoleVarable() { ValidCheck = CheckConsoleInput, Value = "0", TabFunction = GetTabCompletionValues, HelpInfo = DefaultLanguage.Strings.GetString("Debugging_Level_Help"), }); Console.ProcessFile(Filename); Program.ProgramEnding += Save; }
public void RunTask() { bool LongRun = NextRun <= DateTime.Now; if (LongRun) { // Count is protected from having non numurical values so if this fails look elsewhere int count = int.Parse(Console.GetValue(Variables.V_camera_count).Value); if (count != knownCount) { if (count > knownCount) { Console.WriteLine("{0} new cameras detected!", count - knownCount); for (int id = knownCount; id < count; id++) { Camera camera = new Camera(id); Cameras.Add(camera); } } else { Console.WriteLine("{0} cameras removed!", knownCount - count); List <Camera> toRemove = new List <Camera>(); foreach (Camera cam in Cameras) { if (cam.ID >= count) { toRemove.Add(cam); } } foreach (Camera cam in toRemove) { Cameras.Remove(cam); } } knownCount = count; } NextRun = DateTime.Now.AddSeconds(5); } foreach (Camera cam in Cameras) { cam.CheckTask(LongRun); } }
private void SetupVariables() { Console.SetIfNotExsistValue(V_camera_count, new ConsoleVarable() { Value = "1", HelpInfo = DefaultLanguage.Strings.GetString("Camrea_Count_Help"), ValidCheck = CheckConsoleInput, }); if (Program.CurrentOS == OS.Windows) { Console.SetIfNotExsistValue(V_encoder_path, new ConsoleVarable() { Value = Environment.CurrentDirectory + "\\bin\\vlc.exe", HelpInfo = DefaultLanguage.Strings.GetString("Encoder_Path_Help"), }); Console.SetIfNotExsistValue(V_camera_save_path, new ConsoleVarable() { Value = Environment.CurrentDirectory + "\\sv\\cam{0}\\", HelpInfo = DefaultLanguage.Strings.GetString("Camera_Save_Path_Help"), }); } else { Console.SetIfNotExsistValue(V_encoder_path, new ConsoleVarable() { Value = "/usr/bin/vlc", HelpInfo = DefaultLanguage.Strings.GetString("Encoder_Path_Help"), }); Console.SetIfNotExsistValue(V_camera_save_path, new ConsoleVarable() { Value = "/media/sv/cam{0}/", HelpInfo = DefaultLanguage.Strings.GetString("Camera_Save_Path_Help"), }); } Console.SetIfNotExsistValue(V_encoder_stream_args, new ConsoleVarable() { Value = "-I dummy {0} --sout #transcode{{vcodec=theo,acodec=none,hurry-up}}:http{{dst={1}}}", HelpInfo = DefaultLanguage.Strings.GetString("Encoder_Stream_ARGS_Help"), }); SetupCamera(0); }
public void Start() { Cameras = new List <Camera>(); // Count is protected from having non numurical values so if this fails look elsewhere int count = int.Parse(Console.GetValue(Variables.V_camera_count).Value); knownCount = count; for (int id = 0; id < count; id++) { Camera camera = new Camera(id); Cameras.Add(camera); } NextRun = DateTime.Now; Program.ProgramEnding += KillCameras; }
public void CheckTask(bool LongRun) { if (!LongRun) { return; } ConsoleResponseBoolean variable = Console.GetOnOff(string.Format(Variables.V_camera_enabled, ID)); if (variable.State == ConsoleCommandState.Failure) { throw new LogicException(string.Format("{0} is not a boolean variable!", Variables.V_camera_enabled)); } if (variable.Value) { if ((stream == null || !stream.CanWrite) && Program.ThreadsRunning) { StartStream(); } else { if (DateTime.Now >= NextSegment) { StartStream(); } } if (DateTime.Now >= NextFlush && LongRun) { stream.Flush(true); NextFlush = DateTime.Now.AddMinutes(1); } } else { /* if ((StreamSaveThread != null && !StreamSaveThread.HasExited) && Program.ThreadsRunning)*/ if (stream != null) { Console.WriteLine("Killing camera {0}", ID); Terminate(); } } }
private void SetupCamera(int id) { Console.SetIfNotExsistValue(string.Format(V_camera_enabled, id), ConsoleVarable.OnOffVarable( DefaultLanguage.Strings.GetString("Camera_Enabled_Help"))); Console.SetIfNotExsistValue(string.Format(V_camera_stream_enabled, id), ConsoleVarable.OnOffVarable( DefaultLanguage.Strings.GetString("Camera_Stream_Enabled_Help"))); Console.SetIfNotExsistValue(string.Format(V_camera_url, id), new ConsoleVarable() { Value = "rtsp://10.0.0.254/live1.264", HelpInfo = DefaultLanguage.Strings.GetString("Camera_URL_Help"), }); if (Program.CurrentOS == OS.Windows) { Console.SetIfNotExsistValue(string.Format(V_camera_save_format, id), new ConsoleVarable() { Value = "yyyy-MM-dd-HH-MM-ss.ogg", HelpInfo = DefaultLanguage.Strings.GetString("Camera_SAVE_FORMAT_Help"), }); } else { Console.SetIfNotExsistValue(string.Format(V_camera_save_format, id), new ConsoleVarable() { Value = "yyyy-MM-dd-HH:MM:ss.\\o\\g\\g", HelpInfo = DefaultLanguage.Strings.GetString("Camera_SAVE_FORMAT_Help"), }); } Console.SetIfNotExsistValue(string.Format(V_camera_stream_args, id), new ConsoleVarable() { Value = Console.GetValue(V_encoder_stream_args).Value, HelpInfo = DefaultLanguage.Strings.GetString("Encoder_Stream_ARGS_Help"), }); }
internal void Terminate() { Repeater?.Stop(true); if (encoderProcess != null && !encoderProcess.HasExited) { encoderProcess.StandardInput.WriteLine("\x3"); encoderProcess.CloseMainWindow(); if (Program.CurrentOS == OS.Linux) { Syscall.kill(encoderProcess.Id, Signum.SIGTERM); if (!encoderProcess.WaitForExit(5000)) { Console.WriteLine("Camera {0} did not close after 5 seconds, forcefully terminating!", ID); Syscall.kill(encoderProcess.Id, Signum.SIGKILL); } } else if (!encoderProcess.WaitForExit(5000)) { Console.WriteLine("Camera {0} did not close after 5 seconds, forcefully terminating!", ID); encoderProcess.Kill(); } } }
private void Save_cameras() { // This should be safe, the CheckConsoleInput won't let us set non-numbers int count = int.Parse(Console.GetVariable(V_camera_count).Value); List <string> VariablesToSave = new List <string>() { V_camera_count }; for (int id = 0; id < count; id++) { VariablesToSave.AddRange(new string[] { string.Format(V_camera_url, id), string.Format(V_camera_stream_args, id), string.Format(V_camera_save_format, id), string.Format(V_camera_enabled, id), string.Format(V_camera_stream_enabled, id), }); } Console.SaveToFile(FilenameCameras, VariablesToSave.ToArray()); }
public static string GetPage(HttpListenerContext context) { string ACTION = ""; int id; if (context.Request.QueryString.Count != 0) { foreach (string key in context.Request.QueryString.AllKeys) { switch (key) { case "stops": if (int.TryParse(context.Request.QueryString[key], out id)) { if (Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, id)).Value) { ConsoleResponse cr = Console.SetValue(string.Format(Variables.V_camera_stream_enabled, id), "false"); if (cr.State == ConsoleCommandState.Sucess) { ACTION += "Sucess! Camera " + id + " disabled.<br/>"; } else { ACTION += "Failure while disabling camera " + id + ": " + cr.Value + "<br/>"; } } } break; case "starts": if (int.TryParse(context.Request.QueryString[key], out id)) { if (!Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, id)).Value) { ConsoleResponse cr = Console.SetValue(string.Format(Variables.V_camera_stream_enabled, id), "true"); if (cr.State == ConsoleCommandState.Sucess) { ACTION += "Sucess! Camera " + id + " enabled.<br/>"; } else { ACTION += "Failure while enabling camera " + id + ": " + cr.Value + "<br/>"; } } } break; } } } string camerafor = ""; // Count is protected from having non numurical values so if this fails look elsewhere int count = int.Parse(Console.GetValue(Variables.V_camera_count).Value); for (int i = 0; i < count; i++) { camerafor += TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\control.camerafor.template", new Dictionary <string, Func <string> >() { { "URI", () => { return(context.Request.Url.LocalPath); } }, { "STATUS", () => { return(Console.GetValue(string.Format(Variables.V_camera_stream_enabled, i)).Value); } }, { "ID", () => { return(i.ToString()); } }, }); } return(TemplateProcessor.Process(Environment.CurrentDirectory + "\\HTTP\\templates\\control.template", new Dictionary <string, Func <string> >() { { "URI", () => { return context.Request.Url.LocalPath; } }, { "ACTION", () => { return ACTION; } }, { "control.camerafor.template", () => { return camerafor; } }, })); }
private void StartStream() { string filename = string.Format(Console.GetValue(Variables.V_camera_save_path).Value, ID) + DateTime.Now.ToString(Console.GetValue(string.Format(Variables.V_camera_save_format, ID)).Value); Debugging.DebugLog(Debugging.DebugLevel.Info, "Starting Camera " + ID); //We need to make sure the stream task is started also so we can pull the data from it ConsoleResponseBoolean variable = Console.GetOnOff(string.Format(Variables.V_camera_stream_enabled, ID)); if (variable.State == ConsoleCommandState.Failure) { throw new LogicException(string.Format("{0} is not a boolean variable!", Variables.V_camera_stream_enabled)); } if (!variable.Value) { Console.SetValue(string.Format(Variables.V_camera_stream_enabled, ID), "True"); } try { stream?.Close(); } catch { }; File.Delete(filename); stream = File.OpenWrite(filename); Program.CameraManager.GetGamera(ID) .StreamTask.Repeater.AddStream( new StreamClient(stream, (data, offset, length) => { try { stream.Write(data, offset, length); /* string s = ASCIIEncoding.ASCII.GetString(data, 0, data.Length); * var sb = new StringBuilder(); * int i = 0; * * sb.Append(" Capture Pattern: ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append("\n"); * * sb.Append(" Version: ") * .Append(data[i++].ToString("X2")).Append("\n"); * * sb.Append(" Header Type: ") * .Append(data[i++].ToString("X2")).Append("\n"); * * sb.Append("Granule Position: ") * .Append(BitConverter.ToUInt64(new byte[] { data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13] }, 0)).Append("\n"); * * sb.Append("Granule Position: ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append("\n"); * * sb.Append("Bitstream Number: ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append("\n"); * * sb.Append(" Page Seq Number: ") * .Append(data[i++].ToString("X2")).Append(" ") // 18 * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append("\n"); * * sb.Append(" Checksum: ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append(" ") * .Append(data[i++].ToString("X2")).Append("\n"); * * * sb.Append("\n"); * Console.Write(sb.ToString());*/ return(true); } catch { } return(false); }) ); NextSegment = DateTime.Now.AddMinutes(30); NextFlush = DateTime.Now.AddMinutes(1); }