public MediaTypeManager()
        {
            _typesHolder = MediaTypesHolder.Instance;

            object comobj = null;

            try
            {
                Type type = Type.GetTypeFromCLSID(Clsid.FilterMapper2, true);
                comobj   = Activator.CreateInstance(type);
                _pMapper = (IFilterMapper2)comobj;
                comobj   = null;
            }
            catch
            {
            }
            finally
            {
                if (comobj != null)
                {
                    while (Marshal.ReleaseComObject(comobj) > 0)
                    {
                    }
                }
            }
        }
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_pMapper != null)
         {
             Marshal.FinalReleaseComObject(_pMapper);
             _pMapper = null;
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Gets a list of DirectShow filter names that accept the passed MediaType/MediaSubType and output the passed MediaType/MediaSubType.
        /// </summary>
        /// <param name="inputMediaAndSubTypes">Array of MediaType/MediaSubType</param>
        /// <param name="outputMediaAndSubTypes">Array of MediaType/MediaSubType</param>
        /// <param name="merit"></param>
        /// <returns>List of names</returns>
        public static List <CodecInfo> GetFilters(Guid[] inputMediaAndSubTypes, Guid[] outputMediaAndSubTypes, Merit merit)
        {
            List <CodecInfo> filters     = new List <CodecInfo>();
            IEnumMoniker     enumMoniker = null;

            IMoniker[]     moniker = new IMoniker[1];
            IFilterMapper2 mapper  = (IFilterMapper2) new FilterMapper2();

            try
            {
                mapper.EnumMatchingFilters(
                    out enumMoniker,
                    0,
                    true,
                    merit,
                    true,
                    inputMediaAndSubTypes.Length,
                    inputMediaAndSubTypes,
                    null,
                    null,
                    false,
                    true,
                    outputMediaAndSubTypes.Length,
                    outputMediaAndSubTypes,
                    null,
                    null);
                do
                {
                    try { enumMoniker.Next(1, moniker, IntPtr.Zero); }
                    catch { }

                    if ((moniker[0] == null))
                    {
                        break;
                    }

                    string    filterName    = FilterGraphTools.GetFriendlyName(moniker[0]);
                    Guid      filterClassId = FilterGraphTools.GetCLSID(moniker[0]);
                    CodecInfo codecInfo     = new CodecInfo(filterName, filterClassId);
                    filters.Add(codecInfo);

                    FilterGraphTools.TryRelease(ref moniker[0]);
                } while (true);
                filters.Sort();
                return(filters);
            }
            finally
            {
                FilterGraphTools.TryRelease(ref enumMoniker);
                FilterGraphTools.TryRelease(ref mapper);
            }
        }
        public static ArrayList GetFilters(Guid[] mediaType, Guid[] mediaSubType, Merit merit)
        {
            ArrayList    filters     = new ArrayList();
            IEnumMoniker enumMoniker = null;

            IMoniker[]     moniker = new IMoniker[1];
            IFilterMapper2 mapper  = (IFilterMapper2) new FilterMapper2();

            Guid[] types = new Guid[mediaType.Length * 2];
            for (int i = 0; i < mediaType.Length; i++)
            {
                types[i * 2]     = mediaType[i];
                types[i * 2 + 1] = mediaSubType[i];
            }
            if (mapper != null)
            {
                int hResult = mapper.EnumMatchingFilters(
                    out enumMoniker,
                    0,
                    true,
                    merit,
                    true,
                    mediaType.Length,
                    types,
                    null,
                    null,
                    false,
                    true,
                    0,
                    new Guid[0],
                    null,
                    null);
                IntPtr fetched = IntPtr.Zero;
                do
                {
                    hResult = enumMoniker.Next(1, moniker, fetched);
                    if ((moniker[0] == null))
                    {
                        break;
                    }
                    string filterName = DirectShowUtil.GetFriendlyName(moniker[0]);
                    filters.Add(filterName);
                    moniker[0] = null;
                } while (true);
            }
            return(filters);
        }
Пример #5
0
        private void MatchingFiltersForm_Load(object sender, EventArgs e)
        {
            List <Guid> guids = new List <Guid>();

            try {
                if (pin.Connection != null)
                {
                    AMMediaType mt = new AMMediaType();
                    pin.IPin.ConnectionMediaType(mt);
                    guids.Add(mt.majorType);
                    guids.Add(mt.subType);
                    DsUtils.FreeAMMediaType(mt);
                }
                else
                {
                    IEnumMediaTypes mtenum;
                    if (pin.IPin.EnumMediaTypes(out mtenum) >= 0)
                    {
                        AMMediaType[] mts     = new AMMediaType[1];
                        IntPtr        fetched = Marshal.AllocHGlobal(4);
                        while (mtenum.Next(1, mts, fetched) == 0)
                        {
                            guids.Add(mts[0].majorType);
                            guids.Add(mts[0].subType);
                            DsUtils.FreeAMMediaType(mts[0]);
                        }
                        Marshal.FreeHGlobal(fetched);
                    }
                }
                IFilterMapper2     fm = (IFilterMapper2) new FilterMapper2();
                IEnumMoniker       emon, emon_rend; //non-renderers, renderers
                int                hr     = 0;
                List <FilterProps> fplist = new List <FilterProps>();
                if (pin.Direction == PinDirection.Output)
                {
                    hr = fm.EnumMatchingFilters(out emon, 0, true, Merit.None, true, guids.Count / 2, guids.ToArray(),
                                                null, null, false, false, 0, null, null, null);
                    DsError.ThrowExceptionForHR(hr);
                    hr = fm.EnumMatchingFilters(out emon_rend, 0, true, Merit.None, true, guids.Count / 2, guids.ToArray(),
                                                null, null, true, false, 0, null, null, null);
                    DsError.ThrowExceptionForHR(hr);
                    fplist.AddRange(Filterz.GetFiltersFromEnum(emon, Guid.Empty));
                    fplist.AddRange(Filterz.GetFiltersFromEnum(emon_rend, Guid.Empty));
                }
                else
                {
                    hr = fm.EnumMatchingFilters(out emon, 0, true, Merit.None, false, 0, null, null, null, false,
                                                true, guids.Count / 2, guids.ToArray(), null, null);
                    DsError.ThrowExceptionForHR(hr);
                    hr = fm.EnumMatchingFilters(out emon_rend, 0, true, Merit.None, false, 0, null, null, null, true,
                                                true, guids.Count / 2, guids.ToArray(), null, null);
                    DsError.ThrowExceptionForHR(hr);
                    fplist.AddRange(Filterz.GetFiltersFromEnum(emon, Guid.Empty));
                    fplist.AddRange(Filterz.GetFiltersFromEnum(emon_rend, Guid.Empty));
                }

                //Filterz.BuildFilterTree(emon, treeView, Guid.Empty);
                Filterz.FillFilterTree(treeView, fplist);
            }
            catch (COMException ex)
            {
                Graph.ShowCOMException(ex, "Can't enumerate matching filters");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception caught while enumerating matching filters");
            }
        }
Пример #6
0
 private void Config()
 {
     m_fm2 = (IFilterMapper2) new FilterMapper2();
 }
Пример #7
0
        public static ArrayList GetFilters(Guid[] mediaType, Guid[] mediaSubType, Merit merit)
        {
            ArrayList    filters     = new ArrayList();
            IEnumMoniker enumMoniker = null;

            IMoniker[]     moniker = new IMoniker[1];
            IFilterMapper2 mapper  = (IFilterMapper2) new FilterMapper2();

            Guid[] types = new Guid[mediaType.Length * 2];
            for (int i = 0; i < mediaType.Length; i++)
            {
                types[i * 2]     = mediaType[i];
                types[i * 2 + 1] = mediaSubType[i];
            }
            try
            {
                if (mapper != null)
                {
                    int hResult = mapper.EnumMatchingFilters(
                        out enumMoniker,
                        0,
                        true,
                        merit,
                        true,
                        mediaType.Length,
                        types,
                        null,
                        null,
                        false,
                        true,
                        0,
                        new Guid[0],
                        null,
                        null);
                    IntPtr fetched = IntPtr.Zero;
                    do
                    {
                        try
                        {
                            enumMoniker.Next(1, moniker, IntPtr.Zero);
                        }
                        catch
                        {
                        }

                        if ((moniker[0] == null))
                        {
                            break;
                        }

                        string filterName = DirectShowUtil.GetFriendlyName(moniker[0]);
                        if (!String.IsNullOrEmpty(filterName))
                        {
                            filters.Add(filterName);
                        }
                        DirectShowUtil.TryRelease(ref moniker[0]);
                    } while (true);
                }
                return(filters);
            }
            finally
            {
                DirectShowUtil.ReleaseComObject(enumMoniker);
                DirectShowUtil.ReleaseComObject(mapper);
            }
        }
Пример #8
0
        public static DsDevice[] GetDevicesWithThisInPin(Guid mainType, Guid subType)
        {
            DsDevice[] devret;
            ArrayList  devs = new ArrayList();

            IFilterMapper2 pMapper = (IFilterMapper2) new FilterMapper2();

            Guid[] arrayInTypes = new Guid[2] {
                mainType, subType
            };
            IEnumMoniker pEnum = null;
            int          hr    = pMapper.EnumMatchingFilters(out pEnum,
                                                             1,                                // Reserved.
                                                             true,                             // Use exact match?
                                                             (Merit)((int)Merit.DoNotUse + 1), // Minimum merit.
                                                             true,                             // At least one input pin?
                                                             1,                                // Number of major type/subtype pairs for input.
                                                             arrayInTypes,                     // Array of major type/subtype pairs for input.
                                                             null,                             // Input medium.
                                                             null,                             // Input pin category.
                                                             false,                            // Must be a renderer?
                                                             true,                             // At least one output pin?
                                                             0,                                // Number of major type/subtype pairs for output.
                                                             null,                             // Array of major type/subtype pairs for output.
                                                             null,                             // Output medium.
                                                             null);                            // Output pin category.

            DsError.ThrowExceptionForHR(hr);

            if (hr >= 0 && pEnum != null)
            {
                try
                {
                    try
                    {
                        // Enumerate the monikers.
                        IMoniker[] pMoniker = new IMoniker[1];
                        while (pEnum.Next(1, pMoniker, 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(pMoniker[0]));
                            }
                            catch
                            {
                                Marshal.ReleaseComObject(pMoniker[0]);
                                throw;
                            }
                        }
                    }
                    finally
                    {
                        // Clean up.
                        Marshal.ReleaseComObject(pEnum);
                    }


                    // 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];
            }

            Marshal.ReleaseComObject(pMapper);

            return(devret);
        }