static void Main() { try { Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion()); string user = ProcessRoutines.GetProcessUserName(); string m = "User: "******" (as administrator)"; } Log.Main.Inform(m); #if !test ServiceBase.Run(new Service()); #else MpegStream.Start(1, "-f gdigrab -framerate 10 -f rtp_mpegts -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params aMg7BqN047lFN72szkezmPyN1qSMilYCXbqP/sCt srtp://127.0.0.1:5920"); //Service.sessionChanged(1, true); //System.Threading.Thread.Sleep(1000000); //s.Stop //MpegStream.Start(1, ""); UserSessionApi.OpenApi(); UiApi.OpenApi(); ServiceControllerStatus scs = ServiceControllerStatus.Running; for (; ;) { System.Threading.Thread.Sleep(10000); UiApi.Message(MessageType.INFORM, "test"); scs = scs == ServiceControllerStatus.Running ? ServiceControllerStatus.Stopped : ServiceControllerStatus.Running; } #endif } catch (Exception e) { Log.Main.Error(e); } }
public static void Start(uint sessionId, string arguments) { lock (lockObject) { restart_count = 0; MpegStream.sessionId = sessionId; if (sessionId < 1) { throw new Exception("sessionId == " + sessionId); } //if (string.IsNullOrWhiteSpace(Settings.General.CapturedMonitorDeviceName)) //{ // Settings.General.CapturedMonitorDeviceName = MonitorRoutines.GetDefaultMonitorName(); // if (string.IsNullOrWhiteSpace(Settings.General.CapturedMonitorDeviceName)) // throw new Exception("No monitor was found."); //} //WinApi.User32.RECT? an = MonitorRoutines.GetMonitorAreaByMonitorName(Settings.General.CapturedMonitorDeviceName); //if (an == null) //{ // string defaultMonitorName = MonitorRoutines.GetDefaultMonitorName(); // Log.Main.Warning("Monitor '" + Settings.General.CapturedMonitorDeviceName + "' was not found. Using default one '" + defaultMonitorName + "'"); // Settings.General.CapturedMonitorDeviceName = defaultMonitorName; // an = MonitorRoutines.GetMonitorAreaByMonitorName(Settings.General.CapturedMonitorDeviceName); // if (an == null) // throw new Exception("Monitor '" + Settings.General.CapturedMonitorDeviceName + "' was not found."); //} string source; if (Settings.General.CapturedMonitorDeviceName == null || Settings.General.CapturedMonitorDeviceName == Settings.GeneralSettings.CapturedMonitorDeviceName_ALL_DISPLAYS) { source = " -i desktop "; } else { if (Settings.General.CapturedMonitorRectangle == null) { Log.Main.Inform("CapturedMonitorRectangle is empty. Running " + userSessionAgent); UserSessionApi.OpenApi(); WinApi.Advapi32.CreationFlags cfs = 0; cfs |= WinApi.Advapi32.CreationFlags.CREATE_NO_WINDOW; string cl = "\"" + Log.AppDir + "\\" + userSessionAgent + "\""; uint pid = ProcessRoutines.CreateProcessAsUserOfCurrentProcess(sessionId, cl, cfs); Process p = Process.GetProcessById((int)pid); if (p != null && !p.HasExited) { p.WaitForExit(); } UserSessionApi.CloseApi(); Settings.General.Reload(); if (Settings.General.CapturedMonitorRectangle == null) { throw new Exception("Could not get rectangle for monitor '" + Settings.General.CapturedMonitorDeviceName + "'"); } //if (Settings.General.CapturedMonitorRectangle == null) // throw new Exception("Could not get rectangle for monitor '" + Settings.General.CapturedMonitorDeviceName + "'. Properly edit and save monitor setting in the systray menu."); } WinApi.User32.RECT a = (WinApi.User32.RECT)Settings.General.CapturedMonitorRectangle; source = " -offset_x " + a.Left + " -offset_y " + a.Top + " -video_size " + (a.Right - a.Left) + "x" + (a.Bottom - a.Top) + " -show_region 1 -i desktop "; } arguments = Regex.Replace(arguments, @"-framerate\s+\d+", "$0" + source); commandLine = "\"" + Log.AppDir + "\\ffmpeg.exe\" " + arguments; dwCreationFlags = 0; if (!Settings.General.ShowMpegWindow) { dwCreationFlags |= WinApi.Advapi32.CreationFlags.CREATE_NO_WINDOW; //startupInfo.dwFlags |= Win32Process.STARTF_USESTDHANDLES; //startupInfo.wShowWindow = Win32Process.SW_HIDE; } if (Settings.General.WriteMpegOutput2Log) { string file0 = Log.WorkDir + "\\ffmpeg_" + DateTime.Now.ToString("yyMMddHHmmss"); string file = file0; for (int count = 1; File.Exists(file); count++) { file = file0 + "_" + count.ToString(); } file += ".log"; File.WriteAllText(file, @"STARTED AT " + DateTime.Now.ToString() + @": >" + commandLine + @" ", Encoding.UTF8); FileSecurity fileSecurity = File.GetAccessControl(file); FileSystemAccessRule fileSystemAccessRule = new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.AppendData, AccessControlType.Allow); fileSecurity.AddAccessRule(fileSystemAccessRule); File.SetAccessControl(file, fileSecurity); commandLine = Environment.SystemDirectory + "\\cmd.exe /c \"" + commandLine + " 1>>\"" + file + "\",2>&1\""; } start(); } }