示例#1
0
        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);
            //}
        }
示例#2
0
        private void SetupEvrDisplay()
        {
            IMFGetService mfgs = evrRenderer as IMFGetService;
            if (mfgs != null)
            {
                try
                {
                    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;

                    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
                }
            }
        }
示例#3
0
        private int InitVideoWindow(int nMultiplier, int nDivider)
        {
            int hr = 0;
            int lHeight, lWidth;

            //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 > container.ClientRectangle.Width || lHeight > container.ClientRectangle.Height))
                {
                    lWidth = ps.MaxInitialWidth;
                    lHeight = ps.MaxInitialHeight;
                }
                //if (lHeight > ps.MaxInitialHeight && lHeight > ClientRectangle.Height)
                //    lHeight = ps.MaxInitialHeight;
            }
            else
            {
                lWidth = container.ClientRectangle.Width;
                lHeight = container.ClientRectangle.Height;
            }

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

            container.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();
            //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;
        }
示例#4
0
        /// <summary>
        /// Event that is raised after a DaggerNode has been created and associated to the UI element
        /// </summary>
        /// <param name="node"></param>
        void DSFilterNodeUI_DaggerNodeAttached(DaggerLib.Core.DaggerNode node)
        {
            _dsfilternode = (DSFilterNode)node;
            CaptionText   = node.ToString();

            // hook the AfterNodeRemoved event to dispose of any directshow interfaces
            node.AfterNodeRemoved += new DaggerLib.Core.AfterNodeRemoveHandler(node_AfterNodeRemoved);

            // get the IBaseFilter from the DSFilterNode
            IBaseFilter filter = _dsfilternode._filter;

            // only grab the video window or EVR if it was manually added to the graph via the UI
            if (_dsfilternode._manualAdded || (_dsfilternode.ParentGraph.ParentUIGraph as DSDaggerUIGraph)._filterGraphCreated)
            {
                // if it supports IVideoWindow create a VideoInternalWindow for it
                IVideoWindow vw = filter as IVideoWindow;
                if (vw != null)
                {
                    try
                    {
                        _videoWindow         = new VideoInternalWindow(CaptionText, filter);
                        _videoWindow.Dock    = DockStyle.Fill;
                        _videoWindow.Visible = true;
                        InternalControl.Controls.Add(_videoWindow);

                        // only nodes with video windows are resizeable
                        Resizable = true;

                        // hook the connection events to init/deinit the video window
                        node.ParentGraph.AfterPinsConnected += new DaggerLib.Core.PinAfterConnectedHandler(ParentGraph_AfterPinsConnected);
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        MessageBox.Show(ex.Message);
#endif
                        _videoWindow = null;
                    }
                }

                // if it's an Enhaced Video Renderer create a VideoInternalWindow for it
                // (see docs for Windows Media Foundation)
                IMFGetService mfgs = filter as IMFGetService;
                if (mfgs != null)
                {
                    // this is a video horse of a different color
                    // create a video clipping window for the Media Foundation Enhanced Video Renderer
                    try
                    {
                        // get the IMFVideoDisplayControl for the EVR filter
                        object o = null;
                        mfgs.GetService(MediaFoundation.MFServices.MR_VIDEO_RENDER_SERVICE,
                                        typeof(IMFVideoDisplayControl).GUID,
                                        out o
                                        );
                        m_pVideoDisplay = o as IMFVideoDisplayControl;

                        // if the Video Size is 0,0 the EVR hasn't been initialized/connected yet
                        MediaFoundation.Misc.MFSize videoSize = new MediaFoundation.Misc.MFSize();
                        MediaFoundation.Misc.MFSize ar        = new MediaFoundation.Misc.MFSize();
                        m_pVideoDisplay.GetNativeVideoSize(videoSize, ar);

                        if (videoSize.cx == 0 && videoSize.cy == 0)
                        {
                            // You only get one chance to set the number of pins in an EVR filter.
                            PinsComboBoxForm pcf = new PinsComboBoxForm();
                            if (pcf.ShowDialog() == DialogResult.OK)
                            {
                                (filter as IEVRFilterConfig).SetNumberOfStreams(pcf.Value);
                            }
                            pcf.Dispose();
                        }

                        _videoWindow         = new VideoInternalWindow(CaptionText, m_pVideoDisplay);
                        _videoWindow.Dock    = DockStyle.Fill;
                        _videoWindow.Visible = true;
                        InternalControl.Controls.Add(_videoWindow);

                        // only nodes with video windows are resizeable
                        Resizable = true;

                        // hook the connection events to init/deinit the video window
                        node.ParentGraph.AfterPinsConnected += new DaggerLib.Core.PinAfterConnectedHandler(ParentGraph_AfterPinsConnected);
                    }
                    catch (InvalidCastException)
                    {
                        m_pVideoDisplay = null;
                    }
                }
            }

            // if it's a DMO, create the DMO properties page for it
            if ((filter as IDMOWrapperFilter) != null)
            {
                // set the caption to show it's a DMO
                CaptionText           = "DMO - " + CaptionText;
                CaptionColor          = Color.Green;
                CaptionColorUnfocused = Color.LightGreen;
            }

            // remove clock button if it doesn't support IReferenceClock
            _referenceClock = filter as IReferenceClock;
            if (_referenceClock == null)
            {
                CaptionButtons.RemoveAt(CaptionButtons.AllButtons.IndexOf(_clockButton));
            }
            else
            {
                // see if this filter is the reference clock for the graph
                IReferenceClock graphClock = null;
                filter.GetSyncSource(out graphClock);
                _clockButton.Tag = false;
                _clockButton.MouseOutsideTint = Color.DarkGray;
                if (graphClock != null)
                {
                    if (graphClock == _referenceClock)
                    {
                        _clockButton.MouseOutsideTint = Color.Yellow;
                        _clockButton.Tag = true;
                    }
                    Marshal.ReleaseComObject(graphClock);
                }
            }

            // remove video window button if it's not a video window
            if (_videoWindow == null)
            {
                CaptionButtons.RemoveAt(CaptionButtons.AllButtons.IndexOf(_detachVideoWindowButton));
            }

            // Sync the pins to the Pin Property Pages
            SyncPinPropertyPages(null);

            // set it to the smallest possible size.  DaggerLib uses InternalControlMinimumSize
            // to prevent the UI node from being smaller than designated
            this.Size = new Size(1, 1);
        }