예제 #1
0
        private IImageCompression GetImageCompression(ImageCompressionType compressionType)
        {
            if (_compressionType == compressionType && _currentImageCompression != null)
            {
                return(_currentImageCompression);
            }

            _currentImageCompression?.Dispose();
            _compressionType = compressionType;

            switch (compressionType)
            {
            case ImageCompressionType.ManagedJpg:
                return(_currentImageCompression = new JpgCompression(70));

            case ImageCompressionType.TurboJpg:
                return(_currentImageCompression = new TurboJpgImageCompression(false));

            case ImageCompressionType.NoCompression:
                return(_currentImageCompression = new NoCompression());

            default:
                throw new ArgumentOutOfRangeException(nameof(compressionType), compressionType, null);
            }
        }
        private async Task InitializeRemoteComponents(CaptureType captureType, ImageCompressionType compressionType)
        {
            await ConnectionInfo.SendCommand(this, new[]
            {
                (byte)RemoteDesktopCommunication.Initialize, (byte)captureType, (byte)CurrentScreen.Number,
                (byte)ImageQuality, ShowCursor ? (byte)1 : (byte)0, (byte)compressionType
            });

            /*ConnectionInfo.Sender.UnsafeSendCommand(ConnectionInfo.ClientInformation.Id, Identifier,
             *  new WriterCall(new[]
             *  {
             *      (byte) RemoteDesktopCommunication.Initialize, (byte) captureType, (byte) CurrentScreen.Number,
             *      (byte) ImageQuality, ShowCursor ? (byte) 1 : (byte) 0, (byte) compressionType
             *  }));*/
            // ConnectionInfo.UnsafeSendCommand(this, new WriterCall(new[]
            //  {
            //     (byte) RemoteDesktopCommunication.Initialize, (byte) captureType, (byte) CurrentScreen.Number,
            //      (byte) ImageQuality, ShowCursor ? (byte) 1 : (byte) 0, (byte) compressionType
            // }));

            CaptureType = captureType;

            _currentlyStreamedMonitor = CurrentScreen.Number;

            _streamCodec?.Dispose();
            _cursorStreamCodec?.Dispose();

            _streamCodec = new UnsafeStreamCodec(GetImageCompression(compressionType),
                                                 UnsafeStreamCodecParameters.DontDisposeImageCompressor);
            _cursorStreamCodec = new CursorStreamCodec();
        }
        public async Task InitializeRemoteDesktopDirect(CaptureType captureType, ImageCompressionType compressionType)
        {
            await ConnectionInfo.SendCommand(this, (byte)RemoteDesktopCommunication.InitializeDirectConnection);

            InitializeConnection(new ServerConnection(), captureType);

            await InitializeRemoteComponents(captureType, compressionType);

            LogService.Send((string)Application.Current.Resources["InitializeRemoteDesktop"]);
        }
        public async Task InitializeRemoteDesktop(InitializedConnection initializedConnection, CaptureType captureType,
                                                  ImageCompressionType compressionType)
        {
            InitializeConnection(initializedConnection.Connection, captureType);

            await ConnectionInfo.UnsafeSendCommand(this, 17, writer =>
            {
                writer.Write((byte)RemoteDesktopCommunication.InitializeConnection);
                writer.Write(initializedConnection.RemoteConnectionGuid.ToByteArray());
            });

            await InitializeRemoteComponents(captureType, compressionType);

            LogService.Send((string)Application.Current.Resources["InitializeRemoteDesktop"]);
        }
예제 #5
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");
        }