Beispiel #1
0
        /// <summary>
        /// Displays property page for crossbar if it's available.
        /// </summary>
        /// <param name="hwndOwner">The window handler for to make it parent of property page.</param>
        /// <seealso cref="CrossbarAvailable"/>
        public void DisplayPropertyPage_Crossbar(IntPtr hwndOwner)
        {
            if (DX.Crossbar == null)
                return;

            DisplayPropertyPageFilter((IBaseFilter)DX.Crossbar, hwndOwner);

            // update VideoInput - it can be changed
            _VideoInput = GetCrossbarInput(DX.Crossbar);
        }
Beispiel #2
0
        /// <summary>
        /// Gets type of input connected to video output of the crossbar.
        /// </summary>
        /// <param name="crossbar">The crossbar of device.</param>
        /// <returns>Video input of device</returns>
        /// <seealso cref="CrossbarAvailable"/>
        private static VideoInput GetCrossbarInput(IAMCrossbar crossbar)
        {
            VideoInput videoInput = VideoInput.Default;

            int inPinsCount, outPinsCount;

            // gen number of pins in the crossbar
            if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0)
            {
                int videoOutputPinIndex = -1;
                int pinIndexRelated;
                PhysicalConnectorType type;

                // find index of the video output pin
                for (int i = 0; i < outPinsCount; i++)
                {
                    if (crossbar.get_CrossbarPinInfo(false, i, out pinIndexRelated, out type) != 0)
                        continue;

                    if (type == PhysicalConnectorType.Video_VideoDecoder)
                    {
                        videoOutputPinIndex = i;
                        break;
                    }
                }

                if (videoOutputPinIndex != -1)
                {
                    int videoInputPinIndex;

                    // get index of the input pin connected to the output
                    if (crossbar.get_IsRoutedTo(videoOutputPinIndex, out videoInputPinIndex) == 0)
                    {
                        PhysicalConnectorType inputType;

                        crossbar.get_CrossbarPinInfo(true, videoInputPinIndex, out pinIndexRelated, out inputType);

                        videoInput = new VideoInput(videoInputPinIndex, inputType);
                    }
                }
            }

            return videoInput;
        }
Beispiel #3
0
        /// <summary>
        /// Sets type of input connected to video output of the crossbar.
        /// </summary>
        /// <param name="crossbar">The crossbar of device.</param>
        /// <param name="videoInput">Video input of device.</param>
        /// <seealso cref="CrossbarAvailable"/>
        private static void SetCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput)
        {
            if (videoInput.Type != VideoInput.PhysicalConnectorType_Default &&
                videoInput.Index != -1)
            {
                int inPinsCount, outPinsCount;

                // gen number of pins in the crossbar
                if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0)
                {
                    int videoOutputPinIndex = -1;
                    int videoInputPinIndex = -1;
                    int pinIndexRelated;
                    PhysicalConnectorType type;

                    // find index of the video output pin
                    for (int i = 0; i < outPinsCount; i++)
                    {
                        if (crossbar.get_CrossbarPinInfo(false, i, out pinIndexRelated, out type) != 0)
                            continue;

                        if (type == PhysicalConnectorType.Video_VideoDecoder)
                        {
                            videoOutputPinIndex = i;
                            break;
                        }
                    }

                    // find index of the required input pin
                    for (int i = 0; i < inPinsCount; i++)
                    {
                        if (crossbar.get_CrossbarPinInfo(true, i, out pinIndexRelated, out type) != 0)
                            continue;

                        if ((type == videoInput.Type) && (i == videoInput.Index))
                        {
                            videoInputPinIndex = i;
                            break;
                        }
                    }

                    // try connecting pins
                    if ((videoInputPinIndex != -1) && (videoOutputPinIndex != -1))
                    {
                        if (crossbar.CanRoute(videoOutputPinIndex, videoInputPinIndex) == 0)
                        {
                            int hr = crossbar.Route(videoOutputPinIndex, videoInputPinIndex);
                            DsError.ThrowExceptionForHR(hr);
                        }
                        else
                        {
                            throw new Exception("Can't route from selected VideoInput to VideoDecoder.");
                        }
                    }
                    else
                    {
                        throw new Exception("Can't find routing pins.");
                    }

                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Adds crossbar filter to the filter graph.
        /// </summary>
        private void AddFilter_Crossbar()
        {
            // NOTE: It's hard to add suitable crossbar manually
            // It's easy to add it by using ICaptureGraphBuilder2
            // This way seems to be ugly (and it totally is)
            // but it's Microsoft's recommended approach 
            // See http://msdn.microsoft.com/en-us/library/windows/desktop/dd390973%28v=vs.85%29.aspx
            // --------------------------------------------------

            int hr = 0;

            DX.Crossbar = null;

            ICaptureGraphBuilder2 graphBuilder = null;

            try
            {
                graphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

                // set filter graph to the capture graph builder
                hr = graphBuilder.SetFiltergraph((IGraphBuilder)DX.FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                // get crossbar object to to allows configuring pins of capture card
                object crossbarObject = null;

                graphBuilder.FindInterface(FindDirection.UpstreamOnly, Guid.Empty, DX.CaptureFilter, typeof(IAMCrossbar).GUID, out crossbarObject);
                if (crossbarObject != null)
                {
                    DX.Crossbar = (IAMCrossbar)crossbarObject;
                }

            }
            finally
            {
                SafeReleaseComObject(graphBuilder);
                graphBuilder = null;
            }

            // check is crossbar is needed
            if (DX.Crossbar != null)
            {
                hr = DX.FilterGraph.AddFilter((IBaseFilter)DX.Crossbar, "Crossbar");
                DsError.ThrowExceptionForHR(hr);

                // Route Crossbar's inputs
                SetCrossbarInput(DX.Crossbar, _VideoInput);

                _VideoInput = GetCrossbarInput(DX.Crossbar);
            }
        }