/// <summary>
        /// Füllt eine Liste mit Filterinformationen aus einer Auflistung.
        /// </summary>
        /// <param name="category">Die Art des Filters.</param>
        /// <param name="uniqueProp">Die Eigenschaft, die als eindeutige Kennung verwendet werden soll.</param>
        /// <param name="list">Die Informationen.</param>
        /// <param name="monikers">Die Auflistung.</param>
        public void LoadFromEnumeration(Guid category, string uniqueProp, List <FilterInformation> list, IEnumMoniker monikers)
        {
            // Nothing to do
            if (monikers == null)
            {
                return;
            }

            // With cleanup
            try
            {
                // Process all
                for (; ;)
                {
                    using (var array = new COMArray(1))
                    {
                        // Load
                        uint count;
                        if (monikers.Next(1, array.Address, out count) != 0)
                        {
                            break;
                        }

                        // Load object
                        if (count != 1)
                        {
                            continue;
                        }

                        // Load the one
                        var moniker = array.GetObject <IMoniker>(0);
                        try
                        {
                            // Remember
                            list.Add(new FilterInformation(category, moniker.ReadProperty("FriendlyName"), moniker.ReadProperty(uniqueProp), m_MediaDevices));
                        }
                        finally
                        {
                            // Cleanup
                            BDAEnvironment.Release(ref moniker);
                        }
                    }
                }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref monikers);
            }
        }
        /// <summary>
        /// Füllt eine Liste mit Filterinformationen aus einer Auflistung.
        /// </summary>
        /// <param name="category">Die Art des Filters.</param>
        /// <param name="uniqueProp">Die Eigenschaft, die als eindeutige Kennung verwendet werden soll.</param>
        /// <param name="list">Die Informationen.</param>
        /// <param name="monikers">Die Auflistung.</param>
        public void LoadFromEnumeration( Guid category, string uniqueProp, List<FilterInformation> list, IEnumMoniker monikers )
        {
            // Nothing to do
            if (monikers == null)
                return;

            // With cleanup
            try
            {
                // Process all
                for (; ; )
                    using (var array = new COMArray( 1 ))
                    {
                        // Load
                        uint count;
                        if (monikers.Next( 1, array.Address, out count ) != 0)
                            break;

                        // Load object
                        if (count != 1)
                            continue;

                        // Load the one
                        var moniker = array.GetObject<IMoniker>( 0 );
                        try
                        {
                            // Remember
                            list.Add( new FilterInformation( category, moniker.ReadProperty( "FriendlyName" ), moniker.ReadProperty( uniqueProp ), m_MediaDevices ) );
                        }
                        finally
                        {
                            // Cleanup
                            BDAEnvironment.Release( ref moniker );
                        }
                    }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release( ref monikers );
            }
        }
Exemple #3
0
        /// <summary>
        /// Untersucht alle Datenformate eines Endpunktes.
        /// </summary>
        /// <param name="pin">Der zu betrachtende Endpunkt.</param>
        /// <param name="selector">Optional eine Auswahlfunktion.</param>
        /// <param name="action">Optional eine Aktion, die pro Format ausgeführt werden soll.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Endpunkt angegeben.</exception>
        public static void InspectAllMediaTypes <T>(this T pin, Predicate <MediaType> selector, Func <MediaType, bool> action) where T : IPin
        {
            // Validate
            if (pin == null)
            {
                throw new ArgumentNullException("pin");
            }

            // Attach to all pins
            var types = pin.EnumMediaTypes();

            try
            {
                // Process all
                for (; ;)
                {
                    using (var array = new COMArray(1, false))
                    {
                        // Load
                        uint count;
                        if (types.Next(1, array.Address, out count) != 0)
                        {
                            break;
                        }

                        // Load object
                        if (count != 1)
                        {
                            continue;
                        }

                        // Load the one
                        using (var type = new MediaType(array[0], false))
                        {
                            // Check predicate
                            if (selector != null)
                            {
                                if (!selector(type))
                                {
                                    continue;
                                }
                            }

                            // Execute
                            if (action != null)
                            {
                                if (!action(type))
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                // Cleanup
                BDAEnvironment.Release(ref types);
            }
        }
Exemple #4
0
        /// <summary>
        /// Erzeugt den zugehörigen Filter.
        /// </summary>
        /// <returns>Der gewünschte Filter.</returns>
        /// <exception cref="NotSupportedException">Der angeforderte Filter existiert.</exception>
        public TypedComIdentity <IBaseFilter> CreateFilter()
        {
            // Create system device enumerator
            var devEnum = (ICreateDevEnum)Activator.CreateInstance(System.Type.GetTypeFromCLSID(BDAEnvironment.SystemDeviceEnumeratorClassIdentifier));

            try
            {
                // Helper
                var category = Category;

                // Get the enumerator
                IEnumMoniker monikers;
                if (devEnum.CreateClassEnumerator(ref category, out monikers, 0) >= 0)
                {
                    if (monikers != null)
                    {
                        try
                        {
                            // Process all
                            for (; ;)
                            {
                                using (var array = new COMArray(1))
                                {
                                    // Load
                                    uint count;
                                    if (monikers.Next(1, array.Address, out count) != 0)
                                    {
                                        break;
                                    }
                                    if (count != 1)
                                    {
                                        break;
                                    }

                                    // Load object
                                    var moniker = array.GetObject <IMoniker>(0);
                                    try
                                    {
                                        // Check name
                                        if (string.Equals(Moniker, moniker.ReadProperty("DevicePath")))
                                        {
                                            // Create the instance
                                            var iid    = new Guid("56a86895-0ad4-11ce-b03a-0020af0ba770");
                                            var filter = moniker.BindToObject(null, null, ref iid);

                                            // Report safely
                                            try
                                            {
                                                // Construct
                                                return(ComIdentity.Create((IBaseFilter)filter));
                                            }
                                            catch
                                            {
                                                // Cleanup
                                                BDAEnvironment.Release(ref filter);

                                                // Forward
                                                throw;
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        // Release
                                        BDAEnvironment.Release(ref moniker);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            // Cleanup
                            BDAEnvironment.Release(ref monikers);
                        }
                    }
                }
            }
            finally
            {
                // Back to COM
                BDAEnvironment.Release(ref devEnum);
            }

            // Not found
            throw new NotSupportedException(string.Format(Properties.Resources.Exception_BadFilter, this));
        }
        /// <summary>
        /// Untersucht alle Endpunkte eines Filters.
        /// </summary>
        /// <param name="filter">Der zu betrachtende Filter.</param>
        /// <param name="selector">Optional eine Auswahlfunktion.</param>
        /// <param name="action">Optional eine Aktion, die pro Endpunkt ausgeführt werden soll.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Filter angegeben.</exception>
        public static void InspectAllPins(this TypedComIdentity <IBaseFilter> filter, Predicate <IPin> selector, Func <IPin, bool> action)
        {
            // Validate
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            // Attach to the instance
            using (var filterInstance = filter.MarshalToManaged())
            {
                // Attach to all pins
                var pins = filterInstance.Object.EnumPins();
                try
                {
                    // Process all
                    for (; ;)
                    {
                        using (var array = new COMArray(1))
                        {
                            // Load
                            uint count = 0;
                            if (pins.Next(1, array.Address, ref count) != 0)
                            {
                                break;
                            }

                            // Load object
                            if (count != 1)
                            {
                                continue;
                            }

                            // Load the one
                            var pin = array.GetObject <IPin>(0);
                            try
                            {
                                // Check predicate
                                if (selector != null)
                                {
                                    if (!selector(pin))
                                    {
                                        continue;
                                    }
                                }

                                // Execute
                                if (action != null)
                                {
                                    if (!action(pin))
                                    {
                                        return;
                                    }
                                }
                            }
                            finally
                            {
                                // Cleanup
                                BDAEnvironment.Release(ref pin);
                            }
                        }
                    }
                }
                finally
                {
                    // Cleanup
                    BDAEnvironment.Release(ref pins);
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Wertet alle Filter in einem Graphen aus.
        /// </summary>
        /// <typeparam name="T">Konkret verwendete Schnittstelle.</typeparam>
        /// <param name="graph">Der zu untersuchende Graph.</param>
        /// <param name="action">Wird für jeden gefundenen Filter aktiviert.</param>
        /// <exception cref="ArgumentNullException">Es wurde kein Graph angegeben.</exception>
        public static void InspectFilters <T>(this T graph, Func <IBaseFilter, bool> action) where T : IFilterGraph
        {
            // Validate
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            // Get enumerator
            var filters = graph.EnumFilters();

            if (filters == null)
            {
                return;
            }

            // List to process
            var process = new List <IBaseFilter>();

            try
            {
                // Process all
                for (; ;)
                {
                    using (var filterArray = new COMArray(1))
                    {
                        // Load
                        uint n;
                        if (filters.Next(1, filterArray.Address, out n) != 0)
                        {
                            break;
                        }
                        if (n != 1)
                        {
                            break;
                        }

                        // Load
                        process.Add(filterArray.GetObject <IBaseFilter>(0));
                    }
                }
            }
            catch
            {
                // Disable action
                action = null;

                // Forward
                throw;
            }
            finally
            {
                // Cleanup enumeration
                BDAEnvironment.Release(ref filters);

                // Safe process
                try
                {
                    // Test all
                    if (action != null)
                    {
                        foreach (var filter in process)
                        {
                            if (!action(filter))
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    // Cleanup collected filters
                    foreach (var filter in process)
                    {
                        if (Marshal.IsComObject(filter))
                        {
                            Marshal.ReleaseComObject(filter);
                        }
                    }
                }
            }
        }