/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Gets a list of all attributes contained in a media type and displays /// them as a human readable name. More or less just for practice /// /// Adapted from /// https://msdn.microsoft.com/en-us/library/windows/desktop/ee663602(v=vs.85).aspx /// </summary> /// <returns>S_OK for success, nz for fail</returns> /// <param name="mediaTypeObj">the media type object</param> /// <param name="maxAttributes">the maximum number of attributes</param> /// <param name="outSb">The output string</param> /// <param name="ignoreMajorType">if true we ignore the major type attribute</param> /// <param name="ignoreSubType">if true we ignore the sub type attribute</param> /// <history> /// 01 Nov 18 Cynic - Started /// </history> public static HResult EnumerateAllAttributeNamesInMediaTypeAsText(IMFMediaType mediaTypeObj, bool ignoreMajorType, bool ignoreSubType, int maxAttributes, out StringBuilder outSb) { // we always return something here outSb = new StringBuilder(); // sanity check if (mediaTypeObj == null) { return(HResult.E_FAIL); } if ((mediaTypeObj is IMFAttributes) == false) { return(HResult.E_FAIL); } // set up to ignore List <string> attributesToIgnore = new List <string>(); if (ignoreMajorType == true) { attributesToIgnore.Add("MF_MT_MAJOR_TYPE"); } if (ignoreSubType == true) { attributesToIgnore.Add("MF_MT_SUBTYPE"); } // just call the generic TantaWMFUtils Attribute Enumerator return(TantaWMFUtils.EnumerateAllAttributeNamesAsText((mediaTypeObj as IMFAttributes), attributesToIgnore, maxAttributes, out outSb)); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Displays the transforms for the currently selected category. Since each /// </summary> /// <history> /// 01 Nov 18 Cynic - Started /// </history> private void DisplayTransformsForCurrentCategory() { int numResults; IMFActivate[] activatorArray; List <TantaMFTCapabilityContainer> transformList = new List <TantaMFTCapabilityContainer>(); HResult hr; try { // clear what we have now listViewAvailableTransforms.Clear(); // reset this listViewAvailableTransforms.ListViewItemSorter = null; // get the currently selected major category TantaGuidNamePair currentCategory = (TantaGuidNamePair)comboBoxTransformCategories.SelectedItem; if (currentCategory == null) { return; } // we have multiple sub-categories. These are set by specific flags on the MFTEnumX call. We iterate // through each flag and get the matching transforms. If we already have it we just set the flag on // the exisiting one to show it is in multiple sub-categories foreach (MFT_EnumFlag flagVal in Enum.GetValues(typeof(MFT_EnumFlag))) { // we do not need this one if (flagVal == MFT_EnumFlag.None) { continue; } // The documentation states that there is no way to enumerate just local MFTs and nothing else. // Setting Flags equal to MFT_ENUM_FLAG_LOCALMFT is equivalent to including the MFT_ENUM_FLAG_SYNCMFT flag // which messes us up. This also appears to be true for the FieldOfUse and transcode only flags so we // do not include them if (flagVal == MFT_EnumFlag.LocalMFT) { continue; } if (flagVal == MFT_EnumFlag.FieldOfUse) { continue; } if (flagVal == MFT_EnumFlag.TranscodeOnly) { continue; } // some of the higher flags are just for sorting the return results if (flagVal >= MFT_EnumFlag.All) { break; } hr = MFExtern.MFTEnumEx(currentCategory.GuidValue, flagVal, null, null, out activatorArray, out numResults); if (hr != HResult.S_OK) { throw new Exception("DisplayTransformsForCurrentCategory, call to MFExtern.MFTEnumEx failed. HR=" + hr.ToString()); } // now loop through the returned activators for (int i = 0; i < numResults; i++) { // extract the friendlyName and symbolicLinkName Guid outGuid = TantaWMFUtils.GetGuidForKeyFromActivator(activatorArray[i], MFAttributesClsid.MFT_TRANSFORM_CLSID_Attribute); string friendlyName = TantaWMFUtils.GetStringForKeyFromActivator(activatorArray[i], MFAttributesClsid.MFT_FRIENDLY_NAME_Attribute); // create a new TantaMFTCapabilityContainer for it TantaMFTCapabilityContainer workingMFTContainer = new TantaMFTCapabilityContainer(friendlyName, outGuid, currentCategory); // do we have this in our list yet int index = transformList.FindIndex(x => x.TransformGuidValue == workingMFTContainer.TransformGuidValue); if (index >= 0) { // yes, it does contain this transform, just record the new sub-category transformList[index].EnumFlags |= flagVal; } else { // no, it does not contain this transform yet, set the sub-category workingMFTContainer.EnumFlags = flagVal; // and add it transformList.Add(workingMFTContainer); if ((activatorArray[i] is IMFAttributes) == true) { StringBuilder outSb = null; List <string> attributesToIgnore = new List <string>(); attributesToIgnore.Add("MFT_FRIENDLY_NAME_Attribute"); attributesToIgnore.Add("MFT_TRANSFORM_CLSID_Attribute"); attributesToIgnore.Add("MF_TRANSFORM_FLAGS_Attribute"); attributesToIgnore.Add("MF_TRANSFORM_CATEGORY_Attribute"); hr = TantaWMFUtils.EnumerateAllAttributeNamesAsText((activatorArray[i] as IMFAttributes), attributesToIgnore, 100, out outSb); } } // clean up our activator Marshal.ReleaseComObject(activatorArray[i]); } } // now display the transforms foreach (TantaMFTCapabilityContainer mftCapability in transformList) { ListViewItem lvi = new ListViewItem(new[] { mftCapability.TransformFriendlyName, mftCapability.IsSyncMFT, mftCapability.IsAsyncMFT, mftCapability.IsHardware, /* mftCapability.IsFieldOfUse, mftCapability.IsLocalMFT, mftCapability.IsTranscodeOnly, */ mftCapability.TransformGuidValueAsString }); lvi.Tag = mftCapability; listViewAvailableTransforms.Items.Add(lvi); } listViewAvailableTransforms.Columns.Add("Name", 250); listViewAvailableTransforms.Columns.Add("IsSyncMFT", 70); listViewAvailableTransforms.Columns.Add("IsAsyncMFT", 90); listViewAvailableTransforms.Columns.Add("IsHardware", 90); // listViewAvailableTransforms.Columns.Add("IsFieldOfUse", 90); // listViewAvailableTransforms.Columns.Add("IsLocalMFT", 90); // listViewAvailableTransforms.Columns.Add("IsTranscodeOnly", 90); listViewAvailableTransforms.Columns.Add("Guid", 200); } finally { } }