Esempio n. 1
0
        public void UICapture(object sender, EventArgs args)
        {
            if (!coreObject.IsConnected() || !coreObject.IsAtmoLightOn() || coreObject.GetCurrentEffect() != ContentEffect.MediaPortalLiveMode)
            {
                return;
            }

            // Low CPU setting.
            // Skip frame if LowCPUTime has not yet passed since last frame.
            if (settings.LowCPU)
            {
                if ((Win32API.GetTickCount() - lastFrame) < settings.LowCPUTime)
                {
                    return;
                }
                else
                {
                    lastFrame = Win32API.GetTickCount();
                }
            }

            Rectangle rectangleDestination = new Rectangle(0, 0, coreObject.GetCaptureWidth(), coreObject.GetCaptureHeight());

            try
            {
                if (surfaceDestination == null)
                {
                    surfaceDestination = SharpDX.Direct3D9.Surface.CreateRenderTarget(SkinContext.Device,
                                                                                      coreObject.GetCaptureWidth(), coreObject.GetCaptureHeight(), SharpDX.Direct3D9.Format.A8R8G8B8,
                                                                                      SharpDX.Direct3D9.MultisampleType.None, 0, true);
                }

                // Use the Player Surface if video is playing.
                // This results in lower time to calculate aswell as blackbar removal
                if (ServiceRegistration.Get <IPlayerContextManager>().IsVideoContextActive)
                {
                    player = ServiceRegistration.Get <IPlayerContextManager>().PrimaryPlayerContext.CurrentPlayer as ISharpDXVideoPlayer;

                    // player.Texture can be null even if VideoContext is active, e.g. at the start of a video
                    if (player.Texture != null)
                    {
                        surfaceSource = player.Texture.GetSurfaceLevel(0);
                    }
                }
                else
                {
                    surfaceSource = SkinContext.Device.GetRenderTarget(0);
                }

                if (surfaceSource == null)
                {
                    return;
                }

                surfaceSource.Device.StretchRectangle(surfaceSource, null, surfaceDestination, rectangleDestination, SharpDX.Direct3D9.TextureFilter.None);
                DataStream stream = SharpDX.Direct3D9.Surface.ToStream(surfaceDestination, SharpDX.Direct3D9.ImageFileFormat.Bmp);

                coreObject.CalculateBitmap(stream);

                stream.Close();
                stream.Dispose();
            }
            catch (Exception ex)
            {
                surfaceDestination.Dispose();
                surfaceDestination = null;
                Log.Error("Error in UICapture.");
                Log.Error("Exception: {0}", ex.Message);
            }
        }