예제 #1
0
        public static string Capture(string filename = null, CaptureFormat format = CaptureFormat.PNG)
        {
            if (format < CaptureFormat.Filename || format > CaptureFormat.PNG)
            {
                throw new ArgumentOutOfRangeException("format", format, "Not a supported capture format");
            }
            IntPtr result;

            if (screencapture_grab(filename, format, out result) != BPS.BPS_SUCCESS)
            {
                Errno errno = Stdlib.GetLastError();
                if (errno == Errno.ENOMEM)
                {
                    throw new OutOfMemoryException();
                }
                var errCode = BlackBerry.Camera.CameraException.ErrorCodeToCameraError(screencapture_result_get_error_code(result));
                var errMsg  = Marshal.PtrToStringAnsi(screencapture_result_get_error_message(result));
                if (screencapture_destroy_result(result) != BPS.BPS_SUCCESS)
                {
                    Util.ThrowExceptionForLastErrno();
                }
                throw new BlackBerry.Camera.CameraException(errCode, errMsg, Util.GetExceptionForErrno(errno));
            }
            var file = Marshal.PtrToStringAnsi(screencapture_result_get_filename(result));

            if (screencapture_destroy_result(result) != BPS.BPS_SUCCESS)
            {
                Util.ThrowExceptionForLastErrno();
            }
            return(file);
        }
예제 #2
0
        public void SetScreenshotConfig(Guid connectionId, int intervalSecs, CaptureFormat format, string path)
        {
            try
            {
                HttpContext.Current.Application.Lock();

                var remoteSessions = (IDictionary <Guid, RemoteSession>)HttpContext.Current.Application[HttpApplicationStateVariables.RemoteSessions.ToString()];
                if (!remoteSessions.ContainsKey(connectionId))
                {
                    throw new Exception(string.Format("connection {0} not found", connectionId));
                }
                else
                {
                    var remoteSession = remoteSessions[connectionId];
                    remoteSession.Manager.SendCommand(RemoteSessionCommand.SetScreenshotConfig, string.Format("{0}|{1}|{2}", intervalSecs, (int)format, path));
                }
            }
            catch (Exception exc)
            {
                Trace.TraceError("Failed to set screenshot config for connection {0}, interval {1} secs, format {2}, path {3} ({4})", connectionId, intervalSecs, format, path, exc);
                throw;
            }
            finally
            {
                HttpContext.Current.Application.UnLock();
            }
        }
예제 #3
0
 public static string Capture(string filename = null, CaptureFormat format = CaptureFormat.PNG)
 {
     if (format < CaptureFormat.Filename || format > CaptureFormat.PNG)
     {
         throw new ArgumentOutOfRangeException("format", format, "Not a supported capture format");
     }
     IntPtr result;
     if (screencapture_grab(filename, format, out result) != BPS.BPS_SUCCESS)
     {
         Errno errno = Stdlib.GetLastError();
         if (errno == Errno.ENOMEM)
         {
             throw new OutOfMemoryException();
         }
         var errCode = BlackBerry.Camera.CameraException.ErrorCodeToCameraError(screencapture_result_get_error_code(result));
         var errMsg = Marshal.PtrToStringAnsi(screencapture_result_get_error_message(result));
         if (screencapture_destroy_result(result) != BPS.BPS_SUCCESS)
         {
             Util.ThrowExceptionForLastErrno();
         }
         throw new BlackBerry.Camera.CameraException(errCode, errMsg, Util.GetExceptionForErrno(errno));
     }
     var file = Marshal.PtrToStringAnsi(screencapture_result_get_filename(result));
     if (screencapture_destroy_result(result) != BPS.BPS_SUCCESS)
     {
         Util.ThrowExceptionForLastErrno();
     }
     return file;
 }
예제 #4
0
        public string ClipboardText;                    // clipboard text

        public RemoteSession(
            Guid id,
            string hostName,
            HostType hostType,
            SecurityProtocol securityProtocol,
            string serverAddress,
            string vmGuid,
            string vmAddress,
            bool vmEnhancedMode,
            string userDomain,
            string userName,
            string userPassword,
            int clientWidth,
            int clientHeight,
            string startProgram,
            bool allowRemoteClipboard,
            bool allowFileTransfer,
            bool allowPrintDownload,
            bool allowSessionSharing,
            bool allowAudioPlayback,
            int maxActiveGuests,
            string ownerSessionID,
            string ownerClientKey,
            bool connectionService)
        {
            Id                   = id;
            State                = RemoteSessionState.NotConnected;
            HostName             = hostName;
            HostType             = hostType;
            SecurityProtocol     = securityProtocol;
            ServerAddress        = serverAddress;
            VMGuid               = vmGuid;
            VMAddress            = vmAddress;
            VMEnhancedMode       = vmEnhancedMode;
            UserDomain           = userDomain;
            UserName             = userName;
            UserPassword         = userPassword;
            ClientWidth          = clientWidth < 100 ? 100 : clientWidth;
            ClientHeight         = clientHeight < 100 ? 100 : clientHeight;
            StartProgram         = startProgram;
            AllowRemoteClipboard = allowRemoteClipboard;
            AllowFileTransfer    = allowFileTransfer;
            AllowPrintDownload   = allowPrintDownload;
            AllowSessionSharing  = allowSessionSharing;
            AllowAudioPlayback   = allowAudioPlayback;
            ActiveGuests         = 0;
            MaxActiveGuests      = maxActiveGuests;
            OwnerSessionID       = ownerSessionID;
            OwnerClientKey       = ownerClientKey;
            ConnectionService    = connectionService;

            // default capture API config
            ScreenshotIntervalSecs = 60;
            ScreenshotFormat       = CaptureFormat.PNG;
            ScreenshotPath         = string.Empty;

            Manager = new RemoteSessionManager(this);
        }
예제 #5
0
        public void SetScreenshotConfig(Guid connectionId, int intervalSecs, CaptureFormat format, string path)
        {
            var restRequest  = new RestRequest($"SetScreenshotConfig?connectionId={connectionId}&intervalSecs={intervalSecs}&format={format}&path={path}", Method.GET);
            var restResponse = restClient.Execute(restRequest);

            if (restResponse.ResponseStatus != ResponseStatus.Completed)
            {
                throw new Exception(string.Format("Failed to set screenshot config; response status: {0}, code: {1}, message: {2}", restResponse.ResponseStatus, restResponse.StatusCode, restResponse.ErrorMessage));
            }
        }
예제 #6
0
            public override bool Equals(object obj)
            {
                if (obj == null || GetType() != obj.GetType())
                {
                    return(false);
                }
                CaptureFormat p = (CaptureFormat)obj;

                return(this.resolution == p.resolution &&
                       this.framePerSecond == p.framePerSecond &&
                       this.mediaSubType == p.mediaSubType);
            }
예제 #7
0
        public void SetScreenshotConfig(Guid connectionId, int intervalSecs, CaptureFormat format, string path)
        {
            if (connectionId == Guid.Empty)
            {
                throw new ArgumentException(nameof(connectionId));
            }

            if (intervalSecs <= 0)
            {
                throw new ArgumentException(nameof(intervalSecs));
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException(nameof(path));
            }

            _captureService.SetScreenshotConfig(connectionId, intervalSecs, format, path);
        }
예제 #8
0
        /// <summary>
        /// Called once all the subscriptions are established.
        /// </summary>
        private void OnPipelineStart()
        {
            MediaCaptureDevice.Initialize();
            CaptureFormat found = null;

            foreach (var device in MediaCaptureDevice.AllDevices)
            {
                if (!device.Attach(this.configuration.UseInSharedMode))
                {
                    continue;
                }

                Trace.WriteLine($"MediaCapture - Searching for width={this.configuration.Width} height={this.configuration.Height} deviceId={this.configuration.DeviceId}");
                Trace.WriteLine($"MediaCapture - Found: Name: '{device.FriendlyName}' SymLink: {device.SymbolicLink}");
                Trace.WriteLine($"MediaCapture -   Current   - Width: {device.CurrentFormat.nWidth} Height: {device.CurrentFormat.nHeight} Type: {device.CurrentFormat.subType.Name}/{device.CurrentFormat.subType.Guid} Framerate: {device.CurrentFormat.nFrameRateNumerator}/{device.CurrentFormat.nFrameRateDenominator}");

                if (string.IsNullOrEmpty(this.configuration.DeviceId) || device.FriendlyName == this.configuration.DeviceId || device.SymbolicLink == this.configuration.DeviceId)
                {
                    foreach (var format in device.Formats)
                    {
                        Trace.WriteLine($"MediaCapture -   Supported - Width: {format.nWidth} Height: {format.nHeight} Type: {format.subType.Name}/{format.subType.Guid} Framerate: {format.nFrameRateNumerator}/{format.nFrameRateDenominator}");
                        if (this.configuration.Width == format.nWidth && this.configuration.Height == format.nHeight)
                        {
                            // found suitable width/height
                            if (this.configuration.Framerate == format.nFrameRateNumerator / format.nFrameRateDenominator)
                            {
                                // found suitable framerate
                                if (found == null || this.configuration.Framerate == found.nFrameRateNumerator / found.nFrameRateDenominator)
                                {
                                    // found first suitable or closer framerate match
                                    this.camera = device;
                                    found       = format;
                                }
                            }
                        }
                    }
                }

                if (found != null)
                {
                    Trace.WriteLine($"MediaCapture - Using - Width: {found.nWidth} Height: {found.nHeight} Type: {found.subType.Name}/{found.subType.Guid} Framerate: {found.nFrameRateNumerator}/{found.nFrameRateDenominator}");
                    break;
                }
            }

            if (found != null)
            {
                this.camera.CurrentFormat = found;
                this.deviceInfo           = new MediaCaptureInfo(this.camera);
                var width  = this.camera.CurrentFormat.nWidth;
                var height = this.camera.CurrentFormat.nHeight;

                // Get default settings for other properties.
                var currentConfig = this.GetDeviceConfiguration();
                this.configuration.BacklightCompensation = currentConfig.BacklightCompensation;
                this.configuration.Brightness            = currentConfig.Brightness;
                this.configuration.ColorEnable           = currentConfig.ColorEnable;
                this.configuration.Contrast     = currentConfig.Contrast;
                this.configuration.Gain         = currentConfig.Gain;
                this.configuration.Gamma        = currentConfig.Gamma;
                this.configuration.Hue          = currentConfig.Hue;
                this.configuration.Saturation   = currentConfig.Saturation;
                this.configuration.Sharpness    = currentConfig.Sharpness;
                this.configuration.WhiteBalance = currentConfig.WhiteBalance;
                this.configuration.Focus        = currentConfig.Focus;

                this.SetDeviceConfiguration(this.configuration);

                this.camera.CaptureSample((data, length, timestamp) =>
                {
                    var time = DateTime.FromFileTimeUtc(timestamp);
                    using (var sharedImage = ImagePool.GetOrCreate(this.configuration.Width, this.configuration.Height, Microsoft.Psi.Imaging.PixelFormat.BGR_24bpp))
                    {
                        sharedImage.Resource.CopyFrom(data);

                        var originatingTime = this.pipeline.GetCurrentTimeFromElapsedTicks(timestamp);
                        this.Out.Post(sharedImage, originatingTime);
                    }
                });
            }
            else
            {
                throw new ArgumentException("Camera specification not found");
            }
        }
예제 #9
0
 private static extern int screencapture_grab([MarshalAs(UnmanagedType.LPStr)] string filename, CaptureFormat format, out IntPtr result);
예제 #10
0
 private static extern int screencapture_grab([MarshalAs(UnmanagedType.LPStr)]string filename, CaptureFormat format, out IntPtr result);
예제 #11
0
        /// <inheritdoc/>
        public void Start(Action <DateTime> notifyCompletionTime)
        {
            // notify that this is an infinite source component
            notifyCompletionTime(DateTime.MaxValue);

            MediaCaptureDevice.Initialize();
            CaptureFormat found = null;

            foreach (var device in MediaCaptureDevice.AllDevices)
            {
                if (!device.Attach(this.configuration.UseInSharedMode))
                {
                    continue;
                }

                // Trace.WriteLine($"MediaCapture - Searching for width={this.configuration.Width} height={this.configuration.Height} deviceId={this.configuration.DeviceId}");
                // Trace.WriteLine($"MediaCapture - Found: Name: '{device.FriendlyName}' SymLink: {device.SymbolicLink}");
                // Trace.WriteLine($"MediaCapture -   Current   - Width: {device.CurrentFormat.nWidth} Height: {device.CurrentFormat.nHeight} Type: {device.CurrentFormat.subType.Name}/{device.CurrentFormat.subType.Guid} Framerate: {device.CurrentFormat.nFrameRateNumerator}/{device.CurrentFormat.nFrameRateDenominator}");
                if (string.IsNullOrEmpty(this.configuration.DeviceId) || device.FriendlyName == this.configuration.DeviceId || device.SymbolicLink == this.configuration.DeviceId)
                {
                    foreach (var format in device.Formats)
                    {
                        // Trace.WriteLine($"MediaCapture -   Supported - Width: {format.nWidth} Height: {format.nHeight} Type: {format.subType.Name}/{format.subType.Guid} Framerate: {format.nFrameRateNumerator}/{format.nFrameRateDenominator}");
                        if (this.configuration.Width == format.nWidth && this.configuration.Height == format.nHeight)
                        {
                            // found suitable width/height
                            if (this.configuration.Framerate == format.nFrameRateNumerator / format.nFrameRateDenominator)
                            {
                                // found suitable framerate
                                if (found == null || this.configuration.Framerate == found.nFrameRateNumerator / found.nFrameRateDenominator)
                                {
                                    // found first suitable or closer framerate match
                                    this.camera = device;
                                    found       = format;
                                }
                            }
                        }
                    }
                }

                if (found != null)
                {
                    // Trace.WriteLine($"MediaCapture - Using - Width: {found.nWidth} Height: {found.nHeight} Type: {found.subType.Name}/{found.subType.Guid} Framerate: {found.nFrameRateNumerator}/{found.nFrameRateDenominator}");
                    break;
                }
            }

            if (found != null)
            {
                this.camera.CurrentFormat = found;
                this.deviceInfo           = new MediaCaptureInfo(this.camera);
                var width  = this.camera.CurrentFormat.nWidth;
                var height = this.camera.CurrentFormat.nHeight;

                // Get default settings for other properties.
                var currentConfig = this.GetDeviceConfiguration();
                this.configuration.BacklightCompensation = currentConfig.BacklightCompensation;
                this.configuration.Brightness            = currentConfig.Brightness;
                this.configuration.ColorEnable           = currentConfig.ColorEnable;
                this.configuration.Contrast     = currentConfig.Contrast;
                this.configuration.Gain         = currentConfig.Gain;
                this.configuration.Gamma        = currentConfig.Gamma;
                this.configuration.Hue          = currentConfig.Hue;
                this.configuration.Saturation   = currentConfig.Saturation;
                this.configuration.Sharpness    = currentConfig.Sharpness;
                this.configuration.WhiteBalance = currentConfig.WhiteBalance;
                this.configuration.Focus        = currentConfig.Focus;

                this.SetDeviceConfiguration(this.configuration);

                this.camera.CaptureSample((data, length, timestamp) =>
                {
                    var time = DateTime.FromFileTimeUtc(timestamp);
                    using var sharedImage = ImagePool.GetOrCreate(this.configuration.Width, this.configuration.Height, PixelFormat.BGR_24bpp);
                    sharedImage.Resource.CopyFrom(data);

                    var originatingTime = this.pipeline.GetCurrentTimeFromElapsedTicks(timestamp);
                    this.Out.Post(sharedImage, originatingTime);
                });
            }
            else
            {
                // Requested camera capture format was not found. Construct an exception message with a list of supported formats.
                var exceptionMessageBuilder = new StringBuilder();

                if (string.IsNullOrEmpty(this.configuration.DeviceId))
                {
                    exceptionMessageBuilder.Append($"No cameras were found that support the requested capture format of {this.configuration.Width}x{this.configuration.Height} @ {this.configuration.Framerate} fps. ");
                }
                else
                {
                    exceptionMessageBuilder.Append($"The specified camera {this.configuration.DeviceId} does not support the requested capture format of {this.configuration.Width}x{this.configuration.Height} @ {this.configuration.Framerate} fps. ");
                }

                exceptionMessageBuilder.AppendLine("Use one of the following supported camera capture formats instead:");
                this.AppendSupportedCaptureFormats(exceptionMessageBuilder);

                throw new ArgumentException(exceptionMessageBuilder.ToString());
            }
        }
예제 #12
0
        public static bool RhTexture2dCapture(Rhino.Display.DisplayPipeline pipeline, IntPtr ptrTexture2d, CaptureFormat captureFormat)
        {
            var    fieldInfo   = pipeline.GetType().GetField("m_ptr", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            IntPtr ptrPipeline = (IntPtr)fieldInfo.GetValue(pipeline);

            if (Rhino.Runtime.HostUtils.RunningOnWindows)
            {
                return(WindowsMethods.RhTexture2dPipelineCapture(ptrPipeline, ptrTexture2d, captureFormat));
            }
            else
            {
                var viewSerialNumber = pipeline.Viewport.ParentView.RuntimeSerialNumber;
                return(MacMethods.RhTexture2dCapture(viewSerialNumber, ptrTexture2d, captureFormat));
            }
        }
예제 #13
0
 public static extern bool RhTexture2dCapture(uint viewSerialNumber, IntPtr ptrTexture2d, CaptureFormat captureFormat);
예제 #14
0
 public static extern bool RhTexture2dPipelineCapture(IntPtr ptrPipeline, IntPtr ptrTexture2d, CaptureFormat captureFormat);