public void GetMainStreamSubtype(Action <AMMediaType> inspect)
        {
            var pPin = DsUtils.GetPin(_sourceFilter, PinDirection.Output, true);

            if (pPin != null)
            {
                IEnumMediaTypes pEnumTypes;

                var hr = pPin.EnumMediaTypes(out pEnumTypes);
                if (hr == DsHlp.S_OK)
                {
                    IntPtr ptr;
                    int    cFetched;

                    if (pEnumTypes.Next(1, out ptr, out cFetched) == DsHlp.S_OK)
                    {
                        AMMediaType mt = (AMMediaType)Marshal.PtrToStructure(ptr, typeof(AMMediaType));

                        inspect(mt);

                        DsUtils.FreeFormatBlock(ptr);
                        Marshal.FreeCoTaskMem(ptr);
                    }
                    Marshal.ReleaseComObject(pEnumTypes);
                }
                Marshal.ReleaseComObject(pPin);
            }
        }
Esempio n. 2
0
        public static void InspectStream(this IAMStreamSelect pStreamSelect, int index, Action <AMMediaType, string, bool> inspect)
        {
            IntPtr ppmt;
            AMStreamSelectInfoFlags pdwFlags;
            int    plcid;
            int    pdwGroup;
            IntPtr ppszName;
            IntPtr ppObject;
            IntPtr ppUnk;

            var hr = pStreamSelect.Info(index, out ppmt, out pdwFlags, out plcid, out pdwGroup, out ppszName, out ppObject, out ppUnk);

            if (DsHlp.SUCCEEDED(hr))
            {
                var mt      = ppmt != IntPtr.Zero ? (AMMediaType)Marshal.PtrToStructure(ppmt, typeof(AMMediaType)) : new AMMediaType();
                var name    = Marshal.PtrToStringAuto(ppszName);
                var enabled = (pdwFlags & AMStreamSelectInfoFlags.Enabled) != AMStreamSelectInfoFlags.Disabled ||
                              (pdwFlags & AMStreamSelectInfoFlags.Exclusive) != AMStreamSelectInfoFlags.Disabled;

                inspect(mt, name, enabled);

                if (ppmt != IntPtr.Zero)
                {
                    DsUtils.FreeFormatBlock(ppmt);
                    Marshal.FreeCoTaskMem(ppmt);
                }

                Marshal.FreeCoTaskMem(ppszName);
                if (ppObject != IntPtr.Zero)
                {
                    Marshal.Release(ppObject);
                }
                if (ppUnk != IntPtr.Zero)
                {
                    Marshal.Release(ppUnk);
                }
            }
        }
Esempio n. 3
0
        public static void EnumMediaTypes(this IPin pPin, Action <AMMediaType> action)
        {
            IEnumMediaTypes pEnumTypes;

            var hr = pPin.EnumMediaTypes(out pEnumTypes);

            if (hr == DsHlp.S_OK)
            {
                IntPtr ptr;
                int    cFetched;

                if (pEnumTypes.Next(1, out ptr, out cFetched) == DsHlp.S_OK)
                {
                    AMMediaType mt = (AMMediaType)Marshal.PtrToStructure(ptr, typeof(AMMediaType));

                    action(mt);

                    DsUtils.FreeFormatBlock(ptr);
                    Marshal.FreeCoTaskMem(ptr);
                }
                Marshal.ReleaseComObject(pEnumTypes);
            }
        }