Пример #1
0
        /// <summary>
        /// Gets information from the registry about a Media Foundation transform (MFT).
        /// </summary>
        /// <param name="clsidMFT">The CLSID of the MFT to query.</param>
        /// <param name="name">Receives the name of the MFT.</param>
        /// <param name="inputTypes">Receives an array of input types supported by the MFT.</param>
        /// <param name="outputTypes">Receives an array of output types supported by the MFT.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult GetInfo(Guid clsidMFT, out string name, out MFTRegisterTypeInfo[] inputTypes, out MFTRegisterTypeInfo[] outputTypes)
        {
            ArrayList inTypes       = new ArrayList();
            ArrayList outTypes      = new ArrayList();
            MFInt     inTypesCount  = new MFInt();
            MFInt     outTypesCount = new MFInt();

            HResult hr = MFExtern.MFTGetInfo(clsidMFT, out name, inTypes, inTypesCount, outTypes, outTypesCount, IntPtr.Zero);

            inputTypes = new MFTRegisterTypeInfo[inTypesCount];

            for (int i = 0; i < inTypesCount.ToInt32(); i++)
            {
                inputTypes[i] = (MFTRegisterTypeInfo)inTypes[i];
            }

            outputTypes = new MFTRegisterTypeInfo[outTypesCount];

            for (int i = 0; i < outTypesCount.ToInt32(); i++)
            {
                outputTypes[i] = (MFTRegisterTypeInfo)outTypes[i];
            }

            return(hr);
        }
Пример #2
0
        private void TestEnum()
        {
            ArrayList a1 = new ArrayList();
            MFInt i1 = new MFInt(0);
            MFInt i2 = new MFInt(0);
            MFInt i3 = new MFInt(0);
            MFInt i4 = new MFInt(0);
            MFTRegisterTypeInfo rin = new MFTRegisterTypeInfo();
            MFTRegisterTypeInfo rout = new MFTRegisterTypeInfo();

            rin.guidMajorType = MFMediaType.Video;
            rin.guidSubtype = new FourCC("AYUV").ToMediaSubtype();

            rout.guidMajorType = MFMediaType.Video;
            rout.guidSubtype = new FourCC("NV12").ToMediaSubtype();

            int hr = MFExtern.MFTEnum(Guid.Empty, 0, null, null, null, a1, i1);
            MFError.ThrowExceptionForHR(hr);
            hr = MFExtern.MFTEnum(MFTransformCategory.MFT_CATEGORY_VIDEO_EFFECT, 0, null, null, null, a1, i2);
            MFError.ThrowExceptionForHR(hr);
            hr = MFExtern.MFTEnum(MFTransformCategory.MFT_CATEGORY_VIDEO_EFFECT, 0, rin, null, null, a1, i3);
            MFError.ThrowExceptionForHR(hr);
            hr = MFExtern.MFTEnum(MFTransformCategory.MFT_CATEGORY_VIDEO_EFFECT, 0, rin, rout, null, a1, i4);
            MFError.ThrowExceptionForHR(hr);

            Debug.Assert(i1 > 0 && i1 > i2 && i2 >= i3 && i3 >= i4 && i4 > 0);

            for (int y = 0; y < i4; y++)
            {
                MFInt itypescnt = new MFInt(0);
                MFInt otypescnt = new MFInt(0);
                ArrayList a = new ArrayList();
                ArrayList b = new ArrayList();
                Guid mft = (Guid)a1[y];
                string s;

                hr = MFExtern.MFTGetInfo(
                    mft,
                    out s,
                    a,
                    itypescnt,
                    b,
                    otypescnt,
                    IntPtr.Zero);
                MFError.ThrowExceptionForHR(hr);

                hr = MFExtern.MFTGetInfo(
                    mft,
                    out s,
                    null,
                    null,
                    null,
                    null,
                    IntPtr.Zero);
                MFError.ThrowExceptionForHR(hr);

                for (int x = 0; x < itypescnt; x++)
                {
                    MFTRegisterTypeInfo rti = a[x] as MFTRegisterTypeInfo;

                    if (FourCC.IsA4ccSubtype(rti.guidMajorType))
                    {
                        Debug.Write(new FourCC(rti.guidMajorType).ToString());
                        Debug.Write(" ");
                    }
                    Debug.WriteLine(rti.guidMajorType);
                    if (FourCC.IsA4ccSubtype(rti.guidSubtype))
                    {
                        Debug.Write(new FourCC(rti.guidSubtype).ToString());
                        Debug.Write(" ");
                    }
                    Debug.WriteLine(rti.guidSubtype);
                }

                Debug.WriteLine("----------------------");

                for (int x = 0; x < otypescnt; x++)
                {
                    MFTRegisterTypeInfo rti = b[x] as MFTRegisterTypeInfo;

                    if (FourCC.IsA4ccSubtype(rti.guidMajorType))
                    {
                        Debug.Write(new FourCC(rti.guidMajorType).ToString());
                        Debug.Write(" ");
                    }
                    Debug.WriteLine(rti.guidMajorType);
                    if (FourCC.IsA4ccSubtype(rti.guidSubtype))
                    {
                        Debug.Write(new FourCC(rti.guidSubtype).ToString());
                        Debug.Write(" ");
                    }
                    Debug.WriteLine(rti.guidSubtype);
                }

                Debug.WriteLine("===============================");
            }
        }
Пример #3
0
        private void TestReg()
        {
            // HKEY_CLASSES_ROOT\MediaFoundation\Transforms\ffa0d1f1-da7c-49cc-91ea-484dcf94a70a

            Guid g1 = new Guid("{ffa0d1f1-da7c-49cc-91ea-484dcf94a70a}");
            string s;
            MFInt icnt = new MFInt(0);
            MFInt ocnt = new MFInt(0);
            IntPtr ip = IntPtr.Zero;
            ArrayList it = new ArrayList();
            ArrayList ot = new ArrayList();

            int hr = MFExtern.MFTRegister(
                g1,
                MFTransformCategory.MFT_CATEGORY_VIDEO_EFFECT,
                "asdf",
                0,
                0,
                null,
                0,
                null,
                null);
            MFError.ThrowExceptionForHR(hr);

            hr = MFExtern.MFTGetInfo(g1, out s, it, icnt, ot, ocnt, ip);
            MFError.ThrowExceptionForHR(hr);

            hr = MFExtern.MFTUnregister(g1);
            // Always returns an error (http://social.msdn.microsoft.com/Forums/br/mediafoundationdevelopment/thread/7d3dc70f-8eae-4ad0-ad90-6c596cf78c80)
            //MFError.ThrowExceptionForHR(hr);

            Debug.Assert(s == "asdf");

            MFTRegisterTypeInfo [] it1 = new MFTRegisterTypeInfo[2];
            MFTRegisterTypeInfo [] ot1 = new MFTRegisterTypeInfo[3];

            it1[0] = new MFTRegisterTypeInfo();
            it1[1] = new MFTRegisterTypeInfo();
            ot1[0] = new MFTRegisterTypeInfo();
            ot1[1] = new MFTRegisterTypeInfo();
            ot1[2] = new MFTRegisterTypeInfo();

            it1[0].guidMajorType = MFMediaType.Video;
            it1[1].guidSubtype = new Guid("00000000-1111-2222-3333-444444444444");
            it1[1].guidMajorType = MFMediaType.Video;

            ot1[0].guidMajorType = MFMediaType.Video;
            ot1[1].guidMajorType = MFMediaType.Video;
            ot1[2].guidMajorType = MFMediaType.Video;

            hr = MFExtern.MFTRegister(
                g1,
                MFTransformCategory.MFT_CATEGORY_VIDEO_EFFECT,
                "fdsa",
                0,
                it1.Length,
                it1,
                ot1.Length,
                ot1,
                null);
            MFError.ThrowExceptionForHR(hr);

            ArrayList it2 = new ArrayList();
            ArrayList ot2 = new ArrayList();
            hr = MFExtern.MFTGetInfo(g1, out s, it2, icnt, ot2, ocnt, IntPtr.Zero);
            MFError.ThrowExceptionForHR(hr);

            Debug.Assert(s == "fdsa");
            Debug.Assert(icnt == it1.Length && ocnt == ot1.Length);
            Debug.Assert(it2.Count == icnt &&
                it1[0].guidMajorType == ((MFTRegisterTypeInfo)it2[0]).guidMajorType &&
                it1[0].guidSubtype == ((MFTRegisterTypeInfo)it2[0]).guidSubtype &&
                it1[1].guidMajorType == ((MFTRegisterTypeInfo)it2[1]).guidMajorType &&
                it1[1].guidSubtype == ((MFTRegisterTypeInfo)it2[1]).guidSubtype
                );

            Debug.Assert(ot2.Count == ocnt &&
                ot1[0].guidMajorType == ((MFTRegisterTypeInfo)ot2[0]).guidMajorType &&
                ot1[0].guidSubtype == ((MFTRegisterTypeInfo)ot2[0]).guidSubtype &&
                ot1[1].guidMajorType == ((MFTRegisterTypeInfo)ot2[1]).guidMajorType &&
                ot1[1].guidSubtype == ((MFTRegisterTypeInfo)ot2[1]).guidSubtype &&
                ot1[2].guidMajorType == ((MFTRegisterTypeInfo)ot2[2]).guidMajorType &&
                ot1[2].guidSubtype == ((MFTRegisterTypeInfo)ot2[2]).guidSubtype
                );

            hr = MFExtern.MFTUnregister(g1);
            // Always returns an error: http://social.msdn.microsoft.com/Forums/br/mediafoundationdevelopment/thread/7d3dc70f-8eae-4ad0-ad90-6c596cf78c80
            //MFError.ThrowExceptionForHR(hr);
        }
Пример #4
0
        // Called just after invoking the COM method.  The IntPtr is the same one that just got returned
        // from MarshalManagedToNative.  The return value is unused.
        public object MarshalNativeToManaged(IntPtr pNativeData)
        {
            // When we are called with pNativeData == m_ArrayPtr, do nothing.  All the
            // work is done when:
            if (pNativeData == m_MFIntPtr)
            {
                // Read the count
                int count = Marshal.ReadInt32(pNativeData);

                // If we have an array to return things in (ie MFTGetInfo wasn't passed
                // nulls)
                if (m_array != null)
                {
                    IntPtr ip2 = Marshal.ReadIntPtr(m_ArrayPtr);

                    // I don't know why this might happen, but it seems worth the check
                    if (ip2 != IntPtr.Zero)
                    {
                        try
                        {
                            int iSize = Marshal.SizeOf(typeof(MFTRegisterTypeInfo));

                            // Size the array
                            m_array.Capacity = count;

                            // Copy in the values
                            for (int x = 0; x < count; x++)
                            {
                                MFTRegisterTypeInfo rti = new MFTRegisterTypeInfo();
                                Marshal.PtrToStructure(new IntPtr(ip2.ToInt64() + (x * iSize)), rti);
                                m_array.Add(rti);
                            }
                        }
                        finally
                        {
                            // Free the array we got back
                            Marshal.FreeCoTaskMem(ip2);
                        }
                    }
                }

                // Don't forget to assign the value
                m_int.Assign(count);

                m_int = null;
                m_array = null;
            }

            // This value isn't actually used
            return null;
        }
Пример #5
0
        /// <summary>
        /// Enumerates Media Foundation transforms (MFTs) in the registry.
        /// </summary>
        /// <param name="transformCategory">Guid specifying the category of MFTs to enumerate.</param>
        /// <param name="flags">One or more members of the MFT_EnumFlag enumeration.</param>
        /// <param name="inputType">Indicate the input media type that the results must support. If null is passed, the input type is not use to filter the results.</param>
        /// <param name="outputType">Indicate the output media type that the results must support. If null is passed, the output type is not use to filter the results.</param>
        /// <param name="resultActivate">Receives an array of IMFActivate that match the parameters.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult EnumEx(Guid transformCategory, MFT_EnumFlag flags, MFTRegisterTypeInfo inputType, MFTRegisterTypeInfo outputType, out IMFActivate[] resultActivate)
        {
            int resultCount;

            return(MFExtern.MFTEnumEx(transformCategory, flags, inputType, outputType, out resultActivate, out resultCount));
        }
Пример #6
0
        /// <summary>
        /// Enumerates Media Foundation transforms (MFTs) in the registry.
        /// </summary>
        /// <param name="transformCategory">Guid specifying the category of MFTs to enumerate.</param>
        /// <param name="inputType">Indicate the input media type that the results must support. If null is passed, the input type is not use to filter the results.</param>
        /// <param name="outputType">Indicate the output media type that the results must support. If null is passed, the output type is not use to filter the results.</param>
        /// <param name="attributes">Indicate attributes that the results must support.</param>
        /// <param name="resultCLSID">Receives an array of MFT CLSIDs that match the parameters.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        /// <remarks>The parameter <paramref name="attributes"/> is ingnored on Windows 7 or higher and should be null.</remarks>
        public static HResult Enum(Guid transformCategory, MFTRegisterTypeInfo inputType, MFTRegisterTypeInfo outputType, IMFAttributes attributes, out Guid[] resultCLSID)
        {
            int resultCount;

            return(MFExtern.MFTEnum(transformCategory, 0, inputType, outputType, attributes, out resultCLSID, out resultCount));
        }