Esempio n. 1
0
 private static void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
 {
     try
     {
         screenCapturer?.DisplaySettingsChanged();
         Try.Catch(() => { dxgiDuplicator?.Dispose(); });
         dxgiDuplicator = new DxgiOutputDuplicator(0, 0);
         desktopInfo    = DxgiOutputDuplicator.GetDesktopInfo();
     }
     catch (Exception ex)
     {
         Logger.Debug(ex);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// This is the main entry point for the SHRD streamer.
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;

            Globals.InitializeProgram(exePath, "Self Hosted Remote Desktop", true);
            PrivateAccessor.SetStaticFieldValue(typeof(Globals), "errorFilePath", Globals.WritableDirectoryBase + "SHRD_Streamer_Log.txt");

            Logger.logType = LoggingMode.File;
            Logger.Info("SHRDStreamer Startup");

            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ApplicationExit += Application_ApplicationExit;
            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;

            desktopInfo = DxgiOutputDuplicator.GetDesktopInfo();

            streamerArgs = new StreamerArgs(args);

            thrMain              = new Thread(mainThreadRunner);
            thrMain.Name         = "Streamer Main";
            thrMain.IsBackground = true;
            thrMain.Start();

            thrDesktopCapture = new Thread(desktopCaptureThreadRunner);
            thrDesktopCapture.SetApartmentState(ApartmentState.MTA);
            thrDesktopCapture.Name         = "Desktop Capture";
            thrDesktopCapture.IsBackground = true;
            // thrDesktopCapture is started by thrMain after static_sm is set.

            if (streamerArgs.ServiceProcessId != null)
            {
                service_process                = Process.GetProcessById(streamerArgs.ServiceProcessId.Value);
                thrMonitorService              = new Thread(monitoringThreadRunner);
                thrMonitorService.Name         = "Monitoring Service";
                thrMonitorService.IsBackground = true;
                thrMonitorService.Start();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
            //Application.Run();
        }
Esempio n. 3
0
        private static void mainThreadRunner()
        {
            try
            {
                screenCapturer = new AdvScreenCapture();
                dxgiDuplicator = new DxgiOutputDuplicator(0, 0);
                inputEmulator  = new InputEmulator();
                Logger.Info("Application start shared memory id " + streamerArgs.SharedMemoryId);
                int ownerPID = streamerArgs.ServiceProcessId == null ? 0 : streamerArgs.ServiceProcessId.Value;
                using (SharedMemoryStream sm = SharedMemoryStream.OpenSharedMemoryStream(streamerArgs.SharedMemoryId, ownerPID))
                {
                    try
                    {
                        static_sm = sm;
                        thrDesktopCapture.Start();
                        while (!isExiting)
                        {
                            Command commandCode = (Command)sm.ReadByte();
                            // Handle
                            switch (commandCode)
                            {
                            case Command.GetScreenCapture:
                                ImgFlags imgFlags    = (ImgFlags)sm.ReadByte();
                                byte     jpegQuality = (byte)sm.ReadByte();
                                desktopCaptureTasks.Enqueue(new DesktopCaptureTask(imgFlags, jpegQuality));
                                break;

                            //case Command.CaptureCompressedDesktopImage:
                            //	CaptureCompressedDesktopImage(sm);
                            //	break;
                            case Command.ReproduceUserInput:
                                inputEmulator.EmulateInput(sm);
                                break;

                            case Command.GetDesktopInfo:
                                lock (sm)
                                {
                                    desktopInfo.WriteToDataStream(sm);
                                }
                                break;

                            case Command.KeepAlive:
                                break;

                            default:
                                Logger.Debug("Unsupported command code received: " + commandCode);
                                lock (sm)
                                {
                                    sm.WriteByte((byte)Command.Error_CommandCodeUnknown);
                                }
                                break;
                            }
                        }
                    }
                    finally
                    {
                        static_sm = null;
                    }
                }
            }
            catch (ThreadAbortException) { }
            catch (StreamDisconnectedException ex)
            {
                Logger.Info("Exiting because: " + ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Debug(ex);
                Logger.Info("Exiting due to main thread runner exception");
            }
            finally
            {
                Try.Catch(() => { dxgiDuplicator?.Dispose(); });
                Try.Catch(() => { screenCapturer?.Dispose(); });
                //Try.Catch(() => { inputEmulator?.Dispose(); });
                RobustExit();
            }
        }