Example #1
0
        public override void Initialize()
        {
            base.Initialize();
            var captureCommandLine = MazeContext.Request.Headers["capture"];
            var encoderCommandLine = MazeContext.Request.Headers[HeaderNames.AcceptEncoding];

            var captureOptions = ComponentOptions.Parse(captureCommandLine);
            var encoderOptions = ComponentOptions.Parse(encoderCommandLine);

            _captureService = ResolveService(captureOptions, _captureServices);
            _streamEncoder  = ResolveService(encoderOptions, _streamEncoders);

            var screenInfo = _captureService.Initialize(captureOptions);

            _streamEncoder.Initialize(screenInfo, this, encoderOptions);
        }
Example #2
0
        private void InitializeStreamingComponents(CaptureType captureType, int monitor, int quality,
                                                   IConnectionInfo connectionInfo, bool drawCursor, ImageCompressionType compressionType)
        {
            var oldScreenCaptureService = _screenCaptureService;

            _screenCaptureService = _screenCaptureServices[captureType]();

            try
            {
                _screenCaptureService.Initialize(monitor);
            }
            catch (Exception ex)
            {
                _screenCaptureService = oldScreenCaptureService;
                ResponseBytes((byte)RemoteDesktopCommunication.ResponseInitializationFailed,
                              Encoding.UTF8.GetBytes(ex.Message), connectionInfo);
                return;
            }

            Program.WriteLine($"InitializeStreamingComponents: oldScreenCaptureService == null: {oldScreenCaptureService == null} (else dispose)");

            oldScreenCaptureService?.Dispose();

            Program.WriteLine("Dispose other stuff in InitializeStreamingComponents");

            _unsafeCodec?.Dispose();
            _cursorStreamCodec?.Dispose();

            _unsafeCodec = new UnsafeStreamCodec(GetImageCompression(compressionType),
                                                 UnsafeStreamCodecParameters.DontDisposeImageCompressor |
                                                 UnsafeStreamCodecParameters.UpdateImageEveryTwoSeconds);

            _currentImageCompression.Quality = quality;

            if (drawCursor)
            {
                _cursorStreamCodec = new CursorStreamCodec();
            }

            _compressionType = compressionType;

            _currentMonitor = monitor;
            _drawCursor     = drawCursor;

            ResponseByte((byte)RemoteDesktopCommunication.ResponseInitializationSucceeded, connectionInfo);
            Debug.Print("Initialized");
        }