コード例 #1
0
        private void SetAspectRatio(Size? ratio = null, bool setVideoWindow = true)
        {
            int screenWidth;
            int screenHeight;

            if (m_graph == null)
                return;

            if (_isInExclusiveMode)
            {
                var size = System.Windows.Forms.Screen.FromControl(_hostForm).Bounds;

                screenWidth = size.Width;
                screenHeight = size.Height;
            }
            else
            {
                var hiddenWindowContentSize = _hostForm.Bounds;

                screenWidth = hiddenWindowContentSize.Width;
                screenHeight = hiddenWindowContentSize.Height;
            }

            // Set the display position to the entire window.
            if (_mPDisplay != null)
            {
                MFRect dRect = new MFRect(0, 0, screenWidth, screenHeight);
                MFSize vSize = new MFSize(), vAR = new MFSize();
                double m_ZoomX = 1, m_ZoomY = 1, m_PosX = 0.5, m_PosY = 0.5;
                MFVideoNormalizedRect sRect = new MFVideoNormalizedRect();
                sRect.top = 0;
                sRect.left = 0;
                sRect.right = 1;
                sRect.bottom = 1;

                int hr = _mPDisplay.GetNativeVideoSize(vSize, vAR);
                if (hr > -1)
                {
                    double dVideoAR = (double)vSize.Width / vSize.Height;

                    double dWRWidth = screenWidth;
                    double dWRHeight = screenHeight;

                    double dVRWidth = dWRHeight * dVideoAR;
                    double dVRHeight;

                    _logger.Debug("Scale: {0} Video Width: {1} Video Height: {2} X-AR: {3} Y-AR: {4}", _iVideoScaling, vSize.Width, vSize.Height, vAR.cx, vAR.cy);

                    switch (_iVideoScaling)
                    {
                        case VideoScalingScheme.HALF:
                            dVRWidth = vSize.Width * 0.5;
                            dVRHeight = vSize.Height * 0.5;
                            break;
                        case VideoScalingScheme.NORMAL:
                            dVRWidth = vSize.Width;
                            dVRHeight = vSize.Height;
                            break;
                        case VideoScalingScheme.DOUBLE:
                            dVRWidth = vSize.Width * 2.0;
                            dVRHeight = vSize.Height * 2.0;
                            break;
                        case VideoScalingScheme.STRETCH:
                            dVRWidth = dWRWidth;
                            dVRHeight = dWRHeight;
                            break;
                        default:
                        //ASSERT(FALSE);
                        // Fallback to "Touch Window From Inside" if settings were corrupted.
                        case VideoScalingScheme.FROMINSIDE:
                        case VideoScalingScheme.FROMOUTSIDE:
                            if ((screenWidth < dVRWidth) != (_iVideoScaling == VideoScalingScheme.FROMOUTSIDE))
                            {
                                dVRWidth = dWRWidth;
                                dVRHeight = dVRWidth / dVideoAR;
                            }
                            else
                            {
                                dVRHeight = dWRHeight;
                            }
                            break;
                        case VideoScalingScheme.ZOOM1:
                        case VideoScalingScheme.ZOOM2:
                            {
                                double minw = dWRWidth < dVRWidth ? dWRWidth : dVRWidth;
                                double maxw = dWRWidth > dVRWidth ? dWRWidth : dVRWidth;

                                double scale = _iVideoScaling == VideoScalingScheme.ZOOM1 ? 1.0 / 3.0 : 2.0 / 3.0;
                                dVRWidth = minw + (maxw - minw) * scale;
                                dVRHeight = dVRWidth / dVideoAR;
                                break;
                            }
                    }

                    // Scale video frame
                    double dScaledVRWidth = m_ZoomX * dVRWidth;
                    double dScaledVRHeight = m_ZoomY * dVRHeight;

                    // Position video frame
                    // left and top parts are allowed to be negative
                    dRect.left = (int)Math.Round(m_PosX * (dWRWidth * 3.0 - dScaledVRWidth) - dWRWidth);
                    dRect.top = (int)Math.Round(m_PosY * (dWRHeight * 3.0 - dScaledVRHeight) - dWRHeight);
                    // right and bottom parts are always at picture center or beyond, so never negative
                    dRect.right = (int)Math.Round(dRect.left + dScaledVRWidth);
                    dRect.bottom = (int)Math.Round(dRect.top + dScaledVRHeight);

                    //apply overscan
                    //dRect.top = dRect.top - (ps.OverscanHeight / 2);
                    //dRect.left = dRect.left - (ps.OverscanWidth / 2);
                    //dRect.right = dRect.right + (ps.OverscanWidth / 2);//this.Width;
                    //dRect.bottom = dRect.bottom + (ps.OverscanHeight / 2);//this.Height;
                }

                _mPDisplay.SetVideoPosition(sRect, dRect);
            }

            // Get Aspect Ratio
            int aspectX;
            int aspectY;

            if (ratio.HasValue)
            {
                aspectX = ratio.Value.Width;
                aspectY = ratio.Value.Height;
            }
            else
            {
                var basicVideo2 = (IBasicVideo2)m_graph;
                basicVideo2.GetPreferredAspectRatio(out aspectX, out aspectY);

                var sourceHeight = 0;
                var sourceWidth = 0;

                _basicVideo.GetVideoSize(out sourceWidth, out sourceHeight);

                if (aspectX == 0 || aspectY == 0 || sourceWidth > 0 || sourceHeight > 0)
                {
                    aspectX = sourceWidth;
                    aspectY = sourceHeight;
                }
            }

            // Adjust Video Size
            var iAdjustedHeight = 0;

            if (aspectX > 0 && aspectY > 0)
            {
                double adjustedHeight = aspectY * screenWidth;
                adjustedHeight /= aspectX;

                iAdjustedHeight = Convert.ToInt32(Math.Round(adjustedHeight));
            }

            if (screenHeight > iAdjustedHeight && iAdjustedHeight > 0)
            {
                double totalMargin = (screenHeight - iAdjustedHeight);
                var topMargin = Convert.ToInt32(Math.Round(totalMargin / 2));

                _basicVideo.SetDestinationPosition(0, topMargin, screenWidth, iAdjustedHeight);
            }
            else if (iAdjustedHeight > 0)
            {
                double adjustedWidth = aspectX * screenHeight;
                adjustedWidth /= aspectY;

                var iAdjustedWidth = Convert.ToInt32(Math.Round(adjustedWidth));

                double totalMargin = (screenWidth - iAdjustedWidth);
                var leftMargin = Convert.ToInt32(Math.Round(totalMargin / 2));

                _basicVideo.SetDestinationPosition(leftMargin, 0, iAdjustedWidth, screenHeight);
            }

            if (setVideoWindow)
            {
                _videoWindow.SetWindowPosition(0, 0, screenWidth, screenHeight);
            }
        }
コード例 #2
0
        void TestGetNativeVideoSize()
        {
            MFSize s1, s2;
            s1 = new MFSize(1,1);
            s2 = new MFSize(1,1);

            // Note, this call doesn't seem to do anything, but it uses the
            // same defs as GetidealVideoSize, so I'm assuming it's just cuz
            // nothing is connected.
            int hr = m_vdc.GetNativeVideoSize(s1, s2);
            MFError.ThrowExceptionForHR(hr);
        }
コード例 #3
0
        void TestGetIdealVideoSize()
        {
            MFSize s1, s2;
            s1 = new MFSize();
            s2 = new MFSize();

            int hr = m_vdc.GetIdealVideoSize(s1, s2);
            MFError.ThrowExceptionForHR(hr);

            Debug.Assert(s1.Width > 0 && s1.Height > 0 && s1.Width > 0 && s2.Height > 0);
        }
コード例 #4
0
ファイル: MFObjects.cs プロジェクト: nickluo/CameraCapture
 public MFVideoArea(float x, float y, int width, int height)
 {
     OffsetX = new MFOffset(x);
     OffsetY = new MFOffset(y);
     Area = new MFSize(width, height);
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: babgvant/EVRPlay
        private void CheckVisibility()
        {
            //int hr = 0;
            //OABool lVisible;

            if (this.evrRenderer == null)//(this.videoWindow == null) || (this.basicVideo == null))
            {
                // Audio-only files have no video interfaces.  This might also
                // be a file whose video component uses an unknown video codec.
                this.isAudioOnly = true;
                return;
            }
            else
            {
                // Clear the global flag
                this.isAudioOnly = false;
            }

            MediaFoundation.Misc.MFSize videoSize = new MediaFoundation.Misc.MFSize();
            MediaFoundation.Misc.MFSize ar = new MediaFoundation.Misc.MFSize();
            evrDisplay.GetNativeVideoSize(videoSize, ar);

            if (videoSize.cx > 0 && videoSize.cy > 0)
            {
                return;
            }
            else
            {
                this.isAudioOnly = true;
            }

            //hr = this.videoWindow.get_Visible(out lVisible);
            //if (hr < 0)
            //{
            //    // If this is an audio-only clip, get_Visible() won't work.
            //    //
            //    // Also, if this video is encoded with an unsupported codec,
            //    // we won't see any video, although the audio will work if it is
            //    // of a supported format.
            //    if (hr == unchecked((int)0x80004002)) //E_NOINTERFACE
            //    {
            //        this.isAudioOnly = true;
            //    }
            //    else
            //        DsError.ThrowExceptionForHR(hr);
            //}
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: babgvant/EVRPlay
        private void MoveVideoWindow()
        {
            int hr = 0;
            try
            {
                // Track the movement of the container window and resize as needed
                if (this.evrDisplay != null)
                {
                    MFVideoNormalizedRect sRect = new MFVideoNormalizedRect();
                    sRect.top = 0;
                    sRect.left = 0;
                    sRect.right = 1;
                    sRect.bottom = 1;
                    MediaFoundation.Misc.MFRect dRect = new MediaFoundation.Misc.MFRect();
                    MFSize vSize = new MFSize(), vAR = new MFSize();
                    double m_ZoomX = 1, m_ZoomY = 1, m_PosX = 0.5, m_PosY = 0.5;
                    //dRect.top = 0;
                    //dRect.left = 0;
                    //dRect.right = ClientRectangle.Width;//this.Width;
                    //dRect.bottom = ClientRectangle.Height;//this.Height;
                    //dRect.top = 0 - (ps.OverscanHeight / 2);
                    //dRect.left = 0 - (ps.OverscanWidth / 2);
                    //dRect.right = ClientRectangle.Width + (ps.OverscanWidth / 2);//this.Width;
                    //dRect.bottom = ClientRectangle.Height + (ps.OverscanHeight / 2);//this.Height;

                    hr = evrDisplay.GetNativeVideoSize(vSize, vAR);
                    DsError.ThrowExceptionForHR(hr);

                    double dVideoAR = (double)vSize.Width / vSize.Height;

                    double dWRWidth = ClientRectangle.Width;
                    double dWRHeight = ClientRectangle.Height;

                    double dVRWidth = dWRHeight * dVideoAR;
                    double dVRHeight;

                    switch (iVideoScaling)
                    {
                        case dvstype.HALF:
                            dVRWidth = vSize.Width * 0.5;
                            dVRHeight = vSize.Height * 0.5;
                            break;
                        case dvstype.NORMAL:
                            dVRWidth = vSize.Width;
                            dVRHeight = vSize.Height;
                            break;
                        case dvstype.DOUBLE:
                            dVRWidth = vSize.Width * 2.0;
                            dVRHeight = vSize.Height * 2.0;
                            break;
                        case dvstype.STRETCH:
                            dVRWidth = dWRWidth;
                            dVRHeight = dWRHeight;
                            break;
                        default:
                        //ASSERT(FALSE);
                        // Fallback to "Touch Window From Inside" if settings were corrupted.
                        case dvstype.FROMINSIDE:
                        case dvstype.FROMOUTSIDE:
                            if ((ClientRectangle.Width < dVRWidth) != (iVideoScaling == dvstype.FROMOUTSIDE))
                            {
                                dVRWidth = dWRWidth;
                                dVRHeight = dVRWidth / dVideoAR;
                            }
                            else
                            {
                                dVRHeight = dWRHeight;
                            }
                            break;
                        case dvstype.ZOOM1:
                        case dvstype.ZOOM2:
                            {
                                double minw = dWRWidth < dVRWidth ? dWRWidth : dVRWidth;
                                double maxw = dWRWidth > dVRWidth ? dWRWidth : dVRWidth;

                                double scale = iVideoScaling == dvstype.ZOOM1 ? 1.0 / 3.0 : 2.0 / 3.0;
                                dVRWidth = minw + (maxw - minw) * scale;
                                dVRHeight = dVRWidth / dVideoAR;
                                break;
                            }
                    }

                    // Scale video frame
                    double dScaledVRWidth = m_ZoomX * dVRWidth;
                    double dScaledVRHeight = m_ZoomY * dVRHeight;

                    // Position video frame
                    // left and top parts are allowed to be negative
                    dRect.left = (int)Math.Round(m_PosX * (dWRWidth * 3.0 - dScaledVRWidth) - dWRWidth);
                    dRect.top = (int)Math.Round(m_PosY * (dWRHeight * 3.0 - dScaledVRHeight) - dWRHeight);
                    // right and bottom parts are always at picture center or beyond, so never negative
                    dRect.right = (int)Math.Round(dRect.left + dScaledVRWidth);
                    dRect.bottom = (int)Math.Round(dRect.top + dScaledVRHeight);

                    //apply overscan
                    dRect.top = dRect.top - (ps.OverscanHeight / 2);
                    dRect.left = dRect.left - (ps.OverscanWidth / 2);
                    dRect.right = dRect.right + (ps.OverscanWidth / 2);//this.Width;
                    dRect.bottom = dRect.bottom + (ps.OverscanHeight / 2);//this.Height;

                    this.evrDisplay.SetVideoPosition(sRect, dRect);
                    Debug.Print("t: {0} l: {1} r:{2} b:{3}", dRect.top, dRect.left, dRect.right, dRect.bottom);
                }
            }
            catch (Exception ex)
            {
                FileLogger.Log("MoveVideoWindow Error: {0}", ex.Message);
            }
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: babgvant/EVRPlay
        private int InitVideoWindow()//int nMultiplier, int nDivider)
        {
            int hr = 0;
            //int lHeight = ClientRectangle.Height, lWidth = ClientRectangle.Width;

            //if (this.basicVideo == null)
            //    return 0;

            //// Read the default video size
            //hr = this.basicVideo.GetVideoSize(out lWidth, out lHeight);
            //if (hr == DsResults.E_NoInterface)
            //    return 0;

            MediaFoundation.Misc.MFSize videoSize = new MediaFoundation.Misc.MFSize();
            MediaFoundation.Misc.MFSize ar = new MediaFoundation.Misc.MFSize();
            evrDisplay.GetNativeVideoSize(videoSize, ar);

            //if (videoSize.cx > 0 && videoSize.cy > 0)
            //{
            //    return;
            //}
            //lWidth = videoSize.cx;
            //lHeight = videoSize.cy;

            EnablePlaybackMenu(true, MediaType.Video);

            //if (!this.isFullScreen && ps.MaxInitialHeight > 0 && ps.MaxInitialWidth > 0)
            //{
            //    if ((lWidth > ps.MaxInitialWidth || lHeight > ps.MaxInitialHeight) && (lWidth > ClientRectangle.Width || lHeight > ClientRectangle.Height))
            //    {
            //        lWidth = ps.MaxInitialWidth;
            //        lHeight = ps.MaxInitialHeight;
            //    }
            //    //if (lHeight > ps.MaxInitialHeight && lHeight > ClientRectangle.Height)
            //    //    lHeight = ps.MaxInitialHeight;
            //}
            //else
            //{
            //    lWidth = ClientRectangle.Width;
            //    lHeight = ClientRectangle.Height;
            //}

            //// Account for requests of normal, half, or double size
            //lWidth = lWidth * nMultiplier / nDivider;
            //lHeight = lHeight * nMultiplier / nDivider;

            //this.ClientSize = new Size(lWidth, lHeight);
            Application.DoEvents();

            //hr = this.videoWindow.SetWindowPosition(0, 0, lWidth, lHeight);
            //MFVideoNormalizedRect sRect = new MFVideoNormalizedRect();
            //sRect.top = 0;
            //sRect.left = 0;
            //sRect.right = 1;
            //sRect.bottom = 1;
            //MediaFoundation.Misc.MFRect dRect = new MediaFoundation.Misc.MFRect();
            //dRect.top = 0-(ps.OverscanHeight/2);
            //dRect.left = 0 - (ps.OverscanWidth / 2);
            //dRect.right = lWidth + (ps.OverscanWidth / 2);//this.Width;
            //dRect.bottom = lHeight + (ps.OverscanHeight / 2);//this.Height;
            //this.evrDisplay.SetVideoPosition(sRect, dRect);
            MoveVideoWindow();

            if (bf != null)
                bf.Hide();

            if (mb != null)
                mb.Hide();

            //wbSageServer.Visible = false;

            MFVideoAspectRatioMode varm;

            this.evrDisplay.GetAspectRatioMode(out varm);

            if (varm != (MFVideoAspectRatioMode)ps.VideoAspectRatioMode)
                evrDisplay.SetAspectRatioMode((MFVideoAspectRatioMode)ps.VideoAspectRatioMode);

            MFVideoRenderPrefs renderingFlags;

            evrDisplay.GetRenderingPrefs(out renderingFlags);

            if (renderingFlags != (MFVideoRenderPrefs)ps.VideoRenderingPrefs)
                evrDisplay.SetRenderingPrefs((MFVideoRenderPrefs)ps.VideoRenderingPrefs);

            int pClr;

            evrDisplay.GetBorderColor(out pClr);

            if (pClr != ps.BorderColor)
                evrDisplay.SetBorderColor(ps.BorderColor);

            return hr;
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: babgvant/EVRPlay
        private void SetupEvrDisplay()
        {
            int hr=0;
            //Guid presenterCLSID = new Guid(0xeb449d36, 0x4, 0x4ea8, 0x90, 0x74, 0x40, 0xc5, 0xf4, 0x94, 0xb5, 0xe4);
            //Guid presenterCLSID = new Guid(0x9707fc9c, 0x807b, 0x41e3, 0x98, 0xa8, 0x75, 0x17, 0x6f, 0x95, 0xa0, 0x62);
            //Guid presenterCLSID = new Guid("29FAB022-F7CC-4819-B2B8-D9B6BCFB6698");
            IMFGetService mfgs = evrRenderer as IMFGetService;
            if (mfgs != null)
            {
                IMFVideoPresenter pPresenter = null;

                try
                {
                    if (ps.CustomPresenterEnabled)
                    {
                        Guid presenterCLSID = new Guid(ps.CustomPresenter);
     
                        IMFVideoRenderer pRenderer = evrRenderer as IMFVideoRenderer;
                        Type type = Type.GetTypeFromCLSID(presenterCLSID);

                        pPresenter = (IMFVideoPresenter)Activator.CreateInstance(type);

                        if (pPresenter != null)
                        {
                            try
                            {
                                pRenderer.InitializeRenderer(null, pPresenter);
                                cpsett = pPresenter as IEVRCPConfig;
                                if (cpsett != null)
                                {
                                    int range;
                                    float alpha;
                                    bool mftime;
                                    hr = cpsett.GetInt(EVRCPSetting.NOMINAL_RANGE, out range);
                                    hr = cpsett.SetInt(EVRCPSetting.NOMINAL_RANGE, range);
                                    hr = cpsett.GetFloat(EVRCPSetting.SUBTITLE_ALPHA, out alpha);
                                    hr = cpsett.SetFloat(EVRCPSetting.SUBTITLE_ALPHA, alpha);
                                    hr = cpsett.GetBool(EVRCPSetting.USE_MF_TIME_CALC, out mftime);
                                    hr = cpsett.SetBool(EVRCPSetting.USE_MF_TIME_CALC, mftime);
                                    hr = cpsett.GetInt(EVRCPSetting.FRAME_DROP_THRESHOLD, out range);
                                    hr = cpsett.SetInt(EVRCPSetting.FRAME_DROP_THRESHOLD, range+1);
                                    hr = cpsett.GetBool(EVRCPSetting.EVRCP_SETTING_REQUEST_OVERLAY, out mftime);
                                    hr = cpsett.SetBool(EVRCPSetting.EVRCP_SETTING_REQUEST_OVERLAY, false);
                                }
                                
                            }
                            finally
                            {
                                if (pPresenter != null && cpsett == null)
                                    Marshal.ReleaseComObject(pPresenter);
                            }
                        }
                    }

                    //object objStateSink = null;
                    //mfgs.GetService(MFServices.MR_VIDEO_RENDER_SERVICE,
                    //    typeof(IMFClockStateSink).GUID,
                    //    out objStateSink);
                    //stateSink = objStateSink as IMFClockStateSink;

                    //object objRateSupp= null;
                    //mfgs.GetService(MFServices.MR_VIDEO_RENDER_SERVICE,
                    //    typeof(IMFRateSupport).GUID,
                    //    out objRateSupp);
                    //rateSupport = objRateSupp as IMFRateSupport;

                    object objMixBmp = null;
                    mfgs.GetService(MFServices.MR_VIDEO_MIXER_SERVICE,
                        typeof(IMFVideoMixerBitmap).GUID,
                        out objMixBmp);
                    mixBmp = objMixBmp as IMFVideoMixerBitmap;

                    object objDisplay = null;
                    mfgs.GetService(MFServices.MR_VIDEO_RENDER_SERVICE,
                        typeof(IMFVideoDisplayControl).GUID,
                        out objDisplay
                        );
                    FileLogger.Log("PlayMovieInWindow: MR_VIDEO_RENDER_SERVICE");
                    evrDisplay = objDisplay as IMFVideoDisplayControl;
                    this.evrDisplay.SetVideoWindow(this.Handle);

                    MediaFoundation.Misc.MFSize videoSize = new MediaFoundation.Misc.MFSize();
                    MediaFoundation.Misc.MFSize ar = new MediaFoundation.Misc.MFSize();
                    //evrDisplay.GetNativeVideoSize(videoSize, ar);

                    if ((videoSize.cx == 0 && videoSize.cy == 0) || videoSize.cx <= 0)
                    {
                        IEVRFilterConfig evrConfig = evrRenderer as IEVRFilterConfig;
                        int pdwMaxStreams;

                        evrConfig.GetNumberOfStreams(out pdwMaxStreams);
                        FileLogger.Log("NumberOfStreams: {0}", pdwMaxStreams);

                        if (pdwMaxStreams < 1)
                        {
                            evrConfig.SetNumberOfStreams(1);
                            FileLogger.Log("Set NumberOfStreams: {0}", 1);
                        }
                    }

                    //object objMemConfig = null;
                    //mfgs.GetService(MFServices.MR_VIDEO_ACCELERATION_SERVICE, typeof(IDirectXVideoMemoryConfiguration).GUID, out objMemConfig);
                }
                catch (InvalidCastException)
                {
                    //do nothing
                }
            }
        }