Exemplo n.º 1
0
        /// <summary>
        /// Returns an array of DsDevices for a filter category.
        /// </summary>
        /// <param name="filterCategory">Any one of FilterCategory</param>
        public static DsDevice[] GetDevicesOfCat(Guid FilterCategory)
        {
            int hr;

            // Use arrayList to build the return list since it is easily resizable
            DsDevice[]   devret;
            ArrayList    devs = new ArrayList();
            IEnumMoniker enumMon;

            ICreateDevEnum enumDev = (ICreateDevEnum) new CreateDevEnum();

            hr = enumDev.CreateClassEnumerator(FilterCategory, out enumMon, 0);
            DsError.ThrowExceptionForHR(hr);

            // CreateClassEnumerator returns null for enumMon if there are no entries
            if (hr != 1)
            {
                try
                {
                    try
                    {
                        IMoniker[] mon = new IMoniker[1];

                        while ((enumMon.Next(1, mon, IntPtr.Zero) == 0))
                        {
                            try
                            {
                                // The devs array now owns this object.  Don't
                                // release it if we are going to be successfully
                                // returning the devret array
                                devs.Add(new DsDevice(mon[0]));
                            }
                            catch
                            {
                                Marshal.ReleaseComObject(mon[0]);
                                throw;
                            }
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(enumMon);
                    }

                    // Copy the ArrayList to the DsDevice[]
                    devret = new DsDevice[devs.Count];
                    devs.CopyTo(devret);
                }
                catch
                {
                    foreach (DsDevice d in devs)
                    {
                        d.Dispose();
                    }
                    throw;
                }
            }
            else
            {
                devret = new DsDevice[0];
            }

            return(devret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns an array of DsDevices for a filter category.
        /// </summary>
        /// <param name="filterCategory">Any one of FilterCategory</param>
        public static DsDevice[] GetDevicesOfCat(Guid FilterCategory)
        {
            int hr;

            // Use arrayList to build the return list since it is easily resizable
            DsDevice[] devret;
            ArrayList devs = new ArrayList();
            IEnumMoniker enumMon;

            ICreateDevEnum enumDev = (ICreateDevEnum)new CreateDevEnum();
            hr = enumDev.CreateClassEnumerator(FilterCategory, out enumMon, 0);
            DsError.ThrowExceptionForHR(hr);

            // CreateClassEnumerator returns null for enumMon if there are no entries
            if (hr != 1)
            {
                try
                {
                    try
                    {
                        IMoniker[] mon = new IMoniker[1];

                        while ((enumMon.Next(1, mon, IntPtr.Zero) == 0))
                        {
                            try
                            {
                                // The devs array now owns this object.  Don't
                                // release it if we are going to be successfully
                                // returning the devret array
                                devs.Add(new DsDevice(mon[0]));
                            }
                            catch
                            {
                                Marshal.ReleaseComObject(mon[0]);
                                throw;
                            }
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(enumMon);
                    }

                    // Copy the ArrayList to the DsDevice[]
                    devret = new DsDevice[devs.Count];
                    devs.CopyTo(devret);
                }
                catch
                {
                    foreach (DsDevice d in devs)
                    {
                        d.Dispose();
                    }
                    throw;
                }
            }
            else
            {
                devret = new DsDevice[0];
            }

            return devret;
        }
Exemplo n.º 3
0
        private static Collection<TunerNode> getTunerNodes(DsDevice device)
        {
            IFilterGraph2 graphBuilder;
            IBaseFilter tunerFilter;
            int reply;

            Collection<TunerNode> tunerNodes = new Collection<TunerNode>();

            graphBuilder = (IFilterGraph2)new FilterGraph();
            reply = graphBuilder.AddSourceFilterForMoniker(device.Moniker, null, device.Name, out tunerFilter);
            /*DsError.ThrowExceptionForHR(reply);*/
            if (reply != 0)
            {
                if (device.Name != null)
                    Logger.Instance.Write("Device " + device.Name + " ignored - source filter could not be added to graph");
                else
                    Logger.Instance.Write("Device " + device.DevicePath + " ignored - source filter could not be added to graph");
                return (tunerNodes);
            }

            IBDA_Topology topology = tunerFilter as IBDA_Topology;
            if (topology == null)
            {
                FilterGraphTools.RemoveAllFilters(graphBuilder);
                Marshal.ReleaseComObject(graphBuilder);
                Marshal.ReleaseComObject(tunerFilter);
                Logger.Instance.Write("Unable to get topology from tuner");
                return (tunerNodes);
            }

            int nodeCount;
            int[] nodeTypes = new int[256];
            reply = topology.GetNodeTypes(out nodeCount, nodeTypes.Length, nodeTypes);
            DsError.ThrowExceptionForHR(reply);

            if (nodeCount != 0)
            {
                for (int index = 0; index < nodeCount; index++)
                    Logger.Instance.Write("Tuner info: Node type " + nodeTypes[index]);
            }
            else
                Logger.Instance.Write("Tuner info: GetNodeTypes returned zero entries");

            int descriptorCount;
            BDANodeDescriptor[] descriptors = new BDANodeDescriptor[256];
            reply = topology.GetNodeDescriptors(out descriptorCount, descriptors.Length, descriptors);
            DsError.ThrowExceptionForHR(reply);

            if (descriptorCount != 0)
            {
                for (int index = 0; index < descriptorCount; index++)
                    Logger.Instance.Write("Tuner info: Descriptor " + descriptors[index].guidName.ToString() + " " + descriptors[index].guidFunction.ToString() + " " + descriptors[index].ulBdaNodeType);
            }
            else
                Logger.Instance.Write("Tuner info: GetNodeDescriptors returned zero entries");

            for (int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
            {
                int nodeType = nodeTypes[nodeIndex];

                bool found = false;

                for (int descriptorIndex = 0; descriptorIndex < descriptorCount; descriptorIndex++)
                {
                    BDANodeDescriptor descriptor = descriptors[descriptorIndex];

                    if (descriptor.ulBdaNodeType == nodeType)
                    {
                        found = true;

                        if (descriptor.guidFunction == BDANodeCategory.QPSKDemodulator)
                            tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.Satellite));
                        else
                        {
                            if (descriptor.guidFunction == BDANodeCategory.COFDMDemodulator)
                                tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.Terrestrial));
                            else
                            {
                                if (descriptor.guidFunction == BDANodeCategory.QAMDemodulator)
                                    tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.Cable));
                                else
                                {
                                    if (descriptor.guidFunction == BDANodeCategory.EightVSBDemodulator)
                                        tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.ATSC));
                                    else
                                    {
                                        if (descriptor.guidFunction == BDANodeCategory.ISDBSDemodulator)
                                            tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.ISDBS));
                                        else
                                        {
                                            if (descriptor.guidFunction == BDANodeCategory.ISDBTDemodulator)
                                                tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.ISDBT));
                                            else
                                                tunerNodes.Add(new TunerNode(nodeType, TunerNodeType.Other));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (!found)
                    Logger.Instance.Write("Tuner info: Node type " + nodeType + " ignored - no descriptor found");
            }

            FilterGraphTools.RemoveAllFilters(graphBuilder);
            Marshal.ReleaseComObject(graphBuilder);
            Marshal.ReleaseComObject(tunerFilter);

            return (tunerNodes);
        }