/// <summary>
        /// This method calculates the rectangle on screen where the video should be presented
        /// this depends on if we are in fullscreen mode or preview mode
        /// and on the current aspect ration settings
        /// </summary>
        /// <param name="videoSize">Size of video stream</param>
        /// <returns>
        /// true : video window is visible
        /// false: video window is not visible
        /// </returns>
        public bool SetVideoWindow(Size videoSize)
        {
            try
            {
                if (!GUIGraphicsContext.IsPlayingVideo)
                {
                    return(false);
                }

                GUIGraphicsContext.VideoSize = videoSize;
                // get the window where the video/tv should be shown
                float x  = GUIGraphicsContext.VideoWindow.X;
                float y  = GUIGraphicsContext.VideoWindow.Y;
                float nw = GUIGraphicsContext.VideoWindow.Width;
                float nh = GUIGraphicsContext.VideoWindow.Height;

                //sanity checks
                if (nw > GUIGraphicsContext.OverScanWidth)
                {
                    nw = GUIGraphicsContext.OverScanWidth;
                }
                if (nh > GUIGraphicsContext.OverScanHeight)
                {
                    nh = GUIGraphicsContext.OverScanHeight;
                }

                //are we supposed to show video in fullscreen or in a preview window?
                if (GUIGraphicsContext.IsFullScreenVideo || !GUIGraphicsContext.ShowBackground)
                {
                    //yes fullscreen, then use the entire screen
                    x  = GUIGraphicsContext.OverScanLeft;
                    y  = GUIGraphicsContext.OverScanTop;
                    nw = GUIGraphicsContext.OverScanWidth;
                    nh = GUIGraphicsContext.OverScanHeight;
                }

                //sanity check
                if (nw <= 10 || nh <= 10 || x < 0 || y < 0)
                {
                    return(false);
                }

                GUIGraphicsContext.VideoReceived();

                //did the video window,aspect ratio change? if not
                //then we dont need to recalculate and just return the previous settings
                if (!updateCrop && x == _rectPrevious.X && y == _rectPrevious.Y &&
                    nw == _rectPrevious.Width && nh == _rectPrevious.Height &&
                    GUIGraphicsContext.ARType == _aspectRatioType &&
                    GUIGraphicsContext.Overlay == _lastOverlayVisible && _shouldRenderTexture &&
                    _prevVideoWidth == videoSize.Width && _prevVideoHeight == videoSize.Height &&
                    _prevArVideoWidth == _arVideoWidth && _prevArVideoHeight == _arVideoHeight)
                {
                    //not changed, return previous settings
                    return(_shouldRenderTexture);
                }

                //settings (position,size,aspect ratio) changed.
                //Store these settings and start calucating the new video window
                _rectPrevious       = new Rectangle((int)x, (int)y, (int)nw, (int)nh);
                _subsRect           = _rectPrevious;
                _aspectRatioType    = GUIGraphicsContext.ARType;
                _lastOverlayVisible = GUIGraphicsContext.Overlay;
                _prevVideoWidth     = videoSize.Width;
                _prevVideoHeight    = videoSize.Height;
                _prevArVideoWidth   = _arVideoWidth;
                _prevArVideoHeight  = _arVideoHeight;

                //calculate the video window according to the current aspect ratio settings
                float fVideoWidth  = (float)videoSize.Width;
                float fVideoHeight = (float)videoSize.Height;
                _geometry.ImageWidth   = (int)fVideoWidth;
                _geometry.ImageHeight  = (int)fVideoHeight;
                _geometry.ScreenWidth  = (int)nw;
                _geometry.ScreenHeight = (int)nh;
                _geometry.ARType       = GUIGraphicsContext.ARType;
                _geometry.PixelRatio   = GUIGraphicsContext.PixelRatio;

                _geometry.GetWindow(_arVideoWidth, _arVideoHeight, out _sourceRect, out _destinationRect,
                                    out _useNonLinearStretch, _cropSettings);
                updateCrop          = false;
                _destinationRect.X += (int)x;
                _destinationRect.Y += (int)y;

                //sanity check
                if (_destinationRect.Width < 10)
                {
                    return(false);
                }
                if (_destinationRect.Height < 10)
                {
                    return(false);
                }
                if (_sourceRect.Width < 10)
                {
                    return(false);
                }
                if (_sourceRect.Height < 10)
                {
                    return(false);
                }

                Log.Debug("PlaneScene: crop T, B  : {0}, {1}", _cropSettings.Top, _cropSettings.Bottom);
                Log.Debug("PlaneScene: crop L, R  : {0}, {1}", _cropSettings.Left, _cropSettings.Right);

                Log.Info("PlaneScene: video WxH  : {0}x{1}", videoSize.Width, videoSize.Height);
                Log.Debug("PlaneScene: video AR   : {0}:{1}", _arVideoWidth, _arVideoHeight);
                Log.Info("PlaneScene: screen WxH : {0}x{1}", nw, nh);
                Log.Debug("PlaneScene: AR type    : {0}", GUIGraphicsContext.ARType);
                Log.Debug("PlaneScene: PixelRatio : {0}", GUIGraphicsContext.PixelRatio);
                Log.Debug("PlaneScene: src        : ({0},{1})-({2},{3})",
                          _sourceRect.X, _sourceRect.Y, _sourceRect.X + _sourceRect.Width, _sourceRect.Y + _sourceRect.Height);
                Log.Debug("PlaneScene: dst        : ({0},{1})-({2},{3})",
                          _destinationRect.X, _destinationRect.Y, _destinationRect.X + _destinationRect.Width,
                          _destinationRect.Y + _destinationRect.Height);

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }
        }